// File: /workspace/github_c_makefile_star2_O3/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 0x5b915(%rip), %rdi     # 0x6c6e0
callq 0xf320
movq %rax, %rbx
leaq 0x5a8f6(%rip), %rdi     # 0x6b6d0
callq 0xf040
testl %eax, %eax
js 0x10ea5
leaq 0x33d6a(%rip), %rsi     # 0x44b58
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movl 0x5bd6e(%rip), %edx     # 0x6cb74
testl %edx, %edx
je 0x10e23
leaq 0x33ddc(%rip), %rsi     # 0x44bed
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
cmpq $0x0, 0x5bd65(%rip)     # 0x6cb90
je 0x10e86
leaq 0x33dd0(%rip), %rsi     # 0x44c04
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movq 0x5bd43(%rip), %r14     # 0x6cb90
leaq 0x33db6(%rip), %rsi     # 0x44c0a
movq %r14, %rdi
callq 0xf170
testq %rax, %rax
leaq 0x33dbf(%rip), %rax     # 0x44c25
leaq 0x33da2(%rip), %rsi     # 0x44c0f
cmoveq %rax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
cmpb $0x1, 0x5bd0b(%rip)     # 0x6cb98
jne 0x10ee6
movl 0x5bd07(%rip), %edx     # 0x6cb9c
testl %edx, %edx
je 0x10ecb
leaq 0x33db0(%rip), %rsi     # 0x44c50
movq %rbx, %rdi
jmp 0x10ed7
callq 0xf380
movl (%rax), %esi
leaq 0x33c86(%rip), %rdx     # 0x44b39
leaq 0x5a816(%rip), %rcx     # 0x6b6d0
movl $0x1, %edi
xorl %eax, %eax
callq 0xf570
jmp 0x10de7
leaq 0x33d67(%rip), %rsi     # 0x44c39
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movq 0x5bc8b(%rip), %rdx     # 0x6cb78
testq %rdx, %rdx
je 0x10f0b
leaq 0x33d74(%rip), %rsi     # 0x44c6d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movl 0x5bc5f(%rip), %eax     # 0x6cb70
cmpl $0x2, %eax
je 0x10f86
cmpl $0x1, %eax
jne 0x11016
movq 0x5bc5a(%rip), %rdx     # 0x6cb80
leaq 0x33de2(%rip), %rsi     # 0x44d0f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movl 0x5bc43(%rip), %edx     # 0x6cb88
testl %edx, %edx
je 0x10f62
leaq 0x33d34(%rip), %rsi     # 0x44c84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movl 0x5bc24(%rip), %edx     # 0x6cb8c
testl %edx, %edx
je 0x11016
leaq 0x33d24(%rip), %rsi     # 0x44c9b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
jmp 0x11012
leaq 0x33d27(%rip), %rsi     # 0x44cb4
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movq 0x5bbda(%rip), %rdx     # 0x6cb80
leaq 0x33d1f(%rip), %rsi     # 0x44ccc
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movl 0x5bbc3(%rip), %edx     # 0x6cb88
testl %edx, %edx
je 0x10fe2
leaq 0x33cb4(%rip), %rsi     # 0x44c84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movl 0x5bba4(%rip), %edx     # 0x6cb8c
testl %edx, %edx
je 0x11001
leaq 0x33ca8(%rip), %rsi     # 0x44c9b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
leaq 0x3947a(%rip), %rsi     # 0x4a482
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movq 0x5bb5b(%rip), %rdx     # 0x6cb78
leaq 0x33d00(%rip), %rsi     # 0x44d24
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1196a
testl %eax, %eax
js 0x1106e
movq %rbx, %rdi
callq 0xf1c0
movq %rax, %r14
cmpl $0x2, 0x5b6a8(%rip)     # 0x6c6ec
jge 0x110b1
movq 0x5b693(%rip), %rdi     # 0x6c6e0
leaq 0x9d4(%rip), %rdx       # 0x11a28
leaq 0x8(%rsp), %r15
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
callq 0xf160
movq (%r15), %rcx
testq %rcx, %rcx
jne 0x110cb
movq %rbx, %rdi
callq 0xf2c0
movq %rax, %rdi
callq 0xf1d0
movq 0x5bb1b(%rip), %rdi     # 0x6cba0
testq %rdi, %rdi
je 0x1109b
callq 0xf430
movq 0x5bb12(%rip), %rdi     # 0x6cba8
callq 0xf210
movq 0x5bb0e(%rip), %rdi     # 0x6cbb0
callq 0xf210
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3365e(%rip), %rdx     # 0x44716
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0xf570
jmp 0x11046
leaq 0x33c86(%rip), %rdx     # 0x44d58
movl $0x1, %edi
xorl %esi, %esi
xorl %eax, %eax
callq 0xf570
jmp 0x1106e