// File: /workspace/github_c_makefile_star2_O2/lucvoo[P]sparse-dev/semind.c
// Function: command_search
static void command_search(int argc, char **argv)
{
	char *sql;
	char *dberr = NULL;
	sqlite3_str *query = sqlite3_str_new(semind_db);

	if (chdir(cwd) < 0)
		semind_error(1, errno, "unable to change directory: %s", cwd);

	if (query_appendf(query,
	                  "SELECT"
	                  " file.name,"
	                  " semind.line,"
	                  " semind.column,"
	                  " semind.context,"
	                  " semind.symbol,"
	                  " semind.mode,"
	                  " semind.kind "
	                  "FROM semind, file "
	                  "WHERE semind.file == file.id") < 0)
		goto fail;

	if (semind_search_kind) {
		if (query_appendf(query, " AND semind.kind == %d", semind_search_kind) < 0)
			goto fail;
	}

	if (semind_search_symbol) {
		int ret;

		if (query_appendf(query, " AND ") < 0)
			goto fail;

		if (strpbrk(semind_search_symbol, "*?[]"))
			ret = query_appendf(query, "semind.symbol GLOB %Q", semind_search_symbol);
		else
			ret = query_appendf(query, "semind.symbol == %Q", semind_search_symbol);

		if (ret < 0)
			goto fail;
	}

	if (semind_search_modmask_defined) {
		if (!semind_search_modmask) {
			if (query_appendf(query, " AND semind.mode == %d", semind_search_modmask) < 0)
				goto fail;
		} else if (query_appendf(query, " AND (semind.mode & %d) != 0", semind_search_modmask) < 0)
			goto fail;
	}

	if (semind_search_path) {
		if (query_appendf(query, " AND file.name GLOB %Q", semind_search_path) < 0)
			goto fail;
	}

	if (semind_search_by_location == EXPLAIN_LOCATION) {
		if (query_appendf(query, " AND file.name == %Q", semind_search_filename) < 0)
			goto fail;
		if (semind_search_line &&
		    query_appendf(query, " AND semind.line == %d", semind_search_line) < 0)
			goto fail;
		if (semind_search_column &&
		    query_appendf(query, " AND semind.column == %d", semind_search_column) < 0)
			goto fail;
	} else if (semind_search_by_location == USAGE_BY_LOCATION) {
		if (query_appendf(query, " AND semind.symbol IN (") < 0)
			goto fail;
		if (query_appendf(query,
		                 "SELECT semind.symbol FROM semind, file WHERE"
				 " semind.file == file.id AND"
		                 " file.name == %Q", semind_search_filename) < 0)
			goto fail;
		if (semind_search_line &&
		    query_appendf(query, " AND semind.line == %d", semind_search_line) < 0)
			goto fail;
		if (semind_search_column &&
		    query_appendf(query, " AND semind.column == %d", semind_search_column) < 0)
			goto fail;
		if (query_appendf(query, ")") < 0)
			goto fail;
	}

	if (query_appendf(query, " ORDER BY file.name, semind.line, semind.column ASC", semind_search_path) < 0)
		goto fail;

	sql = sqlite3_str_value(query);

	if (semind_verbose > 1)
		message("SQL: %s", sql);

	sqlite3_exec(semind_db, sql, search_query_callback, NULL, &dberr);
	if (dberr)
		semind_error(1, 0, "sql query failed: %s", dberr);
fail:
	sql = sqlite3_str_finish(query);
	sqlite3_free(sql);

	if (semind_file_fd) {
		fclose(semind_file_fd);
		free(semind_file_name);
	}
	free(semind_line);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
andq $0x0, 0x8(%rsp)
movq 0x56677(%rip), %rdi     # 0x666f0
callq 0xf330
movq %rax, %rbx
leaq 0x55658(%rip), %rdi     # 0x656e0
callq 0xf040
testl %eax, %eax
jns 0x100b0
callq 0xf390
movl (%rax), %esi
leaq 0x2da9a(%rip), %rdx     # 0x3db39
leaq 0x5563a(%rip), %rcx     # 0x656e0
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10384
leaq 0x2daa1(%rip), %rsi     # 0x3db58
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movl 0x56ab5(%rip), %edx     # 0x66b84
testl %edx, %edx
je 0x100ec
leaq 0x2db13(%rip), %rsi     # 0x3dbed
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
cmpq $0x0, 0x56aac(%rip)     # 0x66ba0
je 0x1014f
leaq 0x2db07(%rip), %rsi     # 0x3dc04
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movq 0x56a8a(%rip), %r14     # 0x66ba0
leaq 0x2daed(%rip), %rsi     # 0x3dc0a
movq %r14, %rdi
callq 0xf170
testq %rax, %rax
leaq 0x2daf6(%rip), %rax     # 0x3dc25
leaq 0x2dad9(%rip), %rsi     # 0x3dc0f
cmoveq %rax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
cmpb $0x1, 0x56a52(%rip)     # 0x66ba8
jne 0x10189
movl 0x56a4e(%rip), %edx     # 0x66bac
testl %edx, %edx
je 0x1016e
leaq 0x2dae7(%rip), %rsi     # 0x3dc50
movq %rbx, %rdi
jmp 0x1017a
leaq 0x2dac4(%rip), %rsi     # 0x3dc39
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movq 0x569f8(%rip), %rdx     # 0x66b88
testq %rdx, %rdx
je 0x101ae
leaq 0x2dad1(%rip), %rsi     # 0x3dc6d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movl 0x569cc(%rip), %eax     # 0x66b80
cmpl $0x2, %eax
je 0x10229
cmpl $0x1, %eax
jne 0x102c1
movq 0x569c7(%rip), %rdx     # 0x66b90
leaq 0x2db3f(%rip), %rsi     # 0x3dd0f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movl 0x569b0(%rip), %edx     # 0x66b98
testl %edx, %edx
je 0x10205
leaq 0x2da91(%rip), %rsi     # 0x3dc84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movl 0x56991(%rip), %edx     # 0x66b9c
testl %edx, %edx
je 0x102c1
leaq 0x2da81(%rip), %rsi     # 0x3dc9b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
jmp 0x102b9
leaq 0x2da84(%rip), %rsi     # 0x3dcb4
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movq 0x56947(%rip), %rdx     # 0x66b90
leaq 0x2da7c(%rip), %rsi     # 0x3dccc
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movl 0x56930(%rip), %edx     # 0x66b98
testl %edx, %edx
je 0x10285
leaq 0x2da11(%rip), %rsi     # 0x3dc84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movl 0x56911(%rip), %edx     # 0x66b9c
testl %edx, %edx
je 0x102a8
leaq 0x2da05(%rip), %rsi     # 0x3dc9b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
leaq 0x331d3(%rip), %rsi     # 0x43482
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movq 0x568c0(%rip), %rdx     # 0x66b88
leaq 0x2da55(%rip), %rsi     # 0x3dd24
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d1e
testl %eax, %eax
js 0x10341
movq %rbx, %rdi
callq 0xf1c0
movq %rax, %r14
cmpl $0x2, 0x5640d(%rip)     # 0x666fc
jl 0x10306
leaq 0x2d41e(%rip), %rdx     # 0x3d716
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x10384
movq 0x563e3(%rip), %rdi     # 0x666f0
leaq 0xaca(%rip), %rdx       # 0x10dde
leaq 0x8(%rsp), %r15
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
callq 0xf160
movq (%r15), %rcx
testq %rcx, %rcx
je 0x10341
leaq 0x2da23(%rip), %rdx     # 0x3dd58
pushq $0x1
popq %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x10384
movq %rbx, %rdi
callq 0xf2c0
movq %rax, %rdi
callq 0xf1d0
movq 0x56858(%rip), %rdi     # 0x66bb0
testq %rdi, %rdi
je 0x1036e
callq 0xf440
movq 0x5684f(%rip), %rdi     # 0x66bb8
callq 0xf210
movq 0x5684b(%rip), %rdi     # 0x66bc0
callq 0xf210
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq