// File: /workspace/github_c_makefile_star2_O1/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
movq $0x0, 0x8(%rsp)
movq 0x5d91a(%rip), %rdi     # 0x6e6e0
callq 0xf320
movq %rax, %rbx
leaq 0x5c8fb(%rip), %rdi     # 0x6d6d0
callq 0xf040
testl %eax, %eax
js 0x10ea0
leaq 0x34d6f(%rip), %rsi     # 0x45b58
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movl 0x5dd73(%rip), %edx     # 0x6eb74
testl %edx, %edx
je 0x10e1e
leaq 0x34de1(%rip), %rsi     # 0x45bed
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
cmpq $0x0, 0x5dd6a(%rip)     # 0x6eb90
je 0x10e81
leaq 0x34dd5(%rip), %rsi     # 0x45c04
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movq 0x5dd48(%rip), %r14     # 0x6eb90
leaq 0x34dbb(%rip), %rsi     # 0x45c0a
movq %r14, %rdi
callq 0xf170
testq %rax, %rax
leaq 0x34dc4(%rip), %rax     # 0x45c25
leaq 0x34da7(%rip), %rsi     # 0x45c0f
cmoveq %rax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
cmpb $0x1, 0x5dd10(%rip)     # 0x6eb98
jne 0x10ee1
movl 0x5dd0c(%rip), %edx     # 0x6eb9c
testl %edx, %edx
je 0x10ec6
leaq 0x34db5(%rip), %rsi     # 0x45c50
movq %rbx, %rdi
jmp 0x10ed2
callq 0xf380
movl (%rax), %esi
leaq 0x34c8b(%rip), %rdx     # 0x45b39
leaq 0x5c81b(%rip), %rcx     # 0x6d6d0
movl $0x1, %edi
xorl %eax, %eax
callq 0xf570
jmp 0x10de2
leaq 0x34d6c(%rip), %rsi     # 0x45c39
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movq 0x5dc90(%rip), %rdx     # 0x6eb78
testq %rdx, %rdx
je 0x10f06
leaq 0x34d79(%rip), %rsi     # 0x45c6d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movl 0x5dc64(%rip), %eax     # 0x6eb70
cmpl $0x2, %eax
je 0x10f81
cmpl $0x1, %eax
jne 0x11011
movq 0x5dc5f(%rip), %rdx     # 0x6eb80
leaq 0x34de7(%rip), %rsi     # 0x45d0f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movl 0x5dc48(%rip), %edx     # 0x6eb88
testl %edx, %edx
je 0x10f5d
leaq 0x34d39(%rip), %rsi     # 0x45c84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movl 0x5dc29(%rip), %edx     # 0x6eb8c
testl %edx, %edx
je 0x11011
leaq 0x34d29(%rip), %rsi     # 0x45c9b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
jmp 0x1100d
leaq 0x34d2c(%rip), %rsi     # 0x45cb4
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movq 0x5dbdf(%rip), %rdx     # 0x6eb80
leaq 0x34d24(%rip), %rsi     # 0x45ccc
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movl 0x5dbc8(%rip), %edx     # 0x6eb88
testl %edx, %edx
je 0x10fdd
leaq 0x34cb9(%rip), %rsi     # 0x45c84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movl 0x5dba9(%rip), %edx     # 0x6eb8c
testl %edx, %edx
je 0x10ffc
leaq 0x34cad(%rip), %rsi     # 0x45c9b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
leaq 0x3a4cf(%rip), %rsi     # 0x4b4d2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movq 0x5db60(%rip), %rdx     # 0x6eb78
leaq 0x34d05(%rip), %rsi     # 0x45d24
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11965
testl %eax, %eax
js 0x11069
movq %rbx, %rdi
callq 0xf1c0
movq %rax, %r14
cmpl $0x2, 0x5d6ad(%rip)     # 0x6e6ec
jge 0x110ac
movq 0x5d698(%rip), %rdi     # 0x6e6e0
leaq 0x9d4(%rip), %rdx       # 0x11a23
leaq 0x8(%rsp), %r15
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
callq 0xf160
movq (%r15), %rcx
testq %rcx, %rcx
jne 0x110c6
movq %rbx, %rdi
callq 0xf2c0
movq %rax, %rdi
callq 0xf1d0
movq 0x5db20(%rip), %rdi     # 0x6eba0
testq %rdi, %rdi
je 0x11096
callq 0xf430
movq 0x5db17(%rip), %rdi     # 0x6eba8
callq 0xf210
movq 0x5db13(%rip), %rdi     # 0x6ebb0
callq 0xf210
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x34663(%rip), %rdx     # 0x45716
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0xf570
jmp 0x11041
leaq 0x34c8b(%rip), %rdx     # 0x45d58
movl $0x1, %edi
xorl %esi, %esi
xorl %eax, %eax
callq 0xf570
jmp 0x11069