// File: /workspace/github_cpp_makefile_star2_O3/skyshore2001[P]symfind/symfind.cpp
// Function: QuerySymbol(char*)
void QuerySymbol(char *arg)
{
	SfSymbolIter it(g_repos);

	char pat_kind[20] = {0};
	char kindlen = 0;
	vector<SfPattern> pats, pats_val, pats_path;

	char *p;
	while (p = strtok(arg, " ")) {
		arg = NULL; // make strtok continue

		if (*(p+1) == 0 && islower(*p)) { // only 1 char for pat_kind
			if (kindlen < sizeof(pat_kind))
				pat_kind[kindlen++] = *p;
			continue;
		}

		SfPatterns *ppats = &pats;
		if (*p == '#') {
			++ p;
			ppats = &pats_val;
		}
		else {
			char *p1 = strchr(p, 0)-1;
			if (*p1 == '/' || *p1 == '\\') {
				*p1 -- = 0;
				ppats = &pats_path;
			}
		}
		ppats->push_back(SfPattern(p));
	}

	g_result.Init('s');
	while (it.Next()) {
		SfSymbol *symbol = it.Value();

		char *name = symbol->name();
		bool ok = true;

		char *kind = symbol->kind();
		if (kindlen && strncmp(kind, pat_kind, kindlen) != 0)
			continue;

		for (SfPattern &pat: pats) {
			if (! pat.Match(name)) {
				ok = false;
				break;
			}
		}
		if (ok && pats_val.size() > 0) {
			ok = strcmp(kind, "macro") == 0 || strcmp(kind, "variable") == 0;
			if (ok) {
				char *extra = symbol->extra();
				for (SfPattern &pat: pats_val) {
					if (! pat.Match(extra)) {
						ok = false;
						break;
					}
				}
			}
		}
		if (ok && pats_path.size() > 0) {
			const SfContext &ctx = it.GetContext();
			for (SfPattern &pat: pats_path) {
				if (! pat.Match(ctx.file->name, ctx.folder->name)) {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			auto &items = g_result.items;
			const SfContext &ctx = it.GetContext();
			items.push_back(ctx);
			int cnt = items.size();
			char buf[1024];
			if (!g_forsvr)
				printf("%d:\t%s\t%s\t%s\t%s:%s\n", cnt, kind, symbol->name(), symbol->extra(), ctx.file->name, symbol->line());
			else
				printf("%d:\t%s\t%s\t%s\t%s:%s\t%s\n", cnt, kind, symbol->name(), symbol->extra(), ctx.file->name, symbol->line(), 
						GetFullName(buf, ctx.repo->root, ctx.folder->name));
			if (cnt >= MAX_FOUND) {
				printf("... (max %d)\n", MAX_FOUND);
				break;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movq 0x6107(%rip), %rax      # 0x9250
leaq 0x90(%rsp), %rcx
movq %rax, 0x18(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rcx)
xorl %eax, %eax
movq %rax, 0x38(%rcx)
movq %rcx, 0x20(%rcx)
movaps %xmm0, 0x70(%rsp)
movl $0x0, 0x80(%rsp)
movq %rax, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %rax, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x319e(%rip), %rsi      # 0x6339
callq 0x22a0
testq %rax, %rax
je 0x3296
movq %rax, %r15
movq $0x0, 0x8(%rsp)
leaq 0x317d(%rip), %rbx      # 0x6339
leaq 0x30(%rsp), %r13
leaq 0xd0(%rsp), %r14
leaq 0x10(%rsp), %rbp
cmpb $0x0, 0x1(%r15)
movb (%r15), %r12b
jne 0x31e9
movsbl %r12b, %edi
callq 0x2210
testl %eax, %eax
jne 0x327b
cmpb $0x23, %r12b
jne 0x31f7
incq %r15
movq %r13, %r12
jmp 0x321f
movq %r15, %rdi
callq 0x20b0
movzbl -0x1(%r15,%rax), %ecx
cmpl $0x5c, %ecx
je 0x320f
cmpl $0x2f, %ecx
jne 0x321a
movb $0x0, -0x1(%r15,%rax)
movq %rbp, %r12
jmp 0x321f
leaq 0x50(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x4478
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x3258
movups 0xd0(%rsp), %xmm0
movups 0xe0(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, %rsi
movq %rsi, 0x8(%r12)
jmp 0x3263
movq %r12, %rdi
movq %r14, %rdx
callq 0x4970
xorl %edi, %edi
movq %rbx, %rsi
callq 0x22a0
movq %rax, %r15
testq %rax, %rax
jne 0x31ce
jmp 0x329f
movq 0x8(%rsp), %rcx
cmpb $0x13, %cl
ja 0x3294
movzbl %cl, %eax
incb %cl
movq %rcx, 0x8(%rsp)
movb %r12b, 0x70(%rsp,%rax)
jmp 0x3263
movq $0x0, 0x8(%rsp)
movb $0x73, 0x5fb2(%rip)     # 0x9258
movq 0x5fb3(%rip), %rax      # 0x9260
cmpq %rax, 0x5fb4(%rip)      # 0x9268
je 0x32bd
movq %rax, 0x5fab(%rip)      # 0x9268
movl $0xffffffff, 0x5fb1(%rip) # imm = 0xFFFFFFFF
movsbq 0x8(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x45ce
testq %rax, %rax
je 0x352e
movq 0xc8(%rsp), %r14
movzwl (%r14), %ebx
movzwl 0x4(%r14), %eax
leaq (%r14,%rax), %r12
addq $0x10, %r12
cmpb $0x0, 0x8(%rsp)
je 0x331e
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0x20c0
testl %eax, %eax
jne 0x32d2
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %r13
cmpq %r13, %r15
je 0x3363
addq %r14, %rbx
addq $0x10, %rbx
movq 0x10(%r15), %rax
movq 0x18(%r15), %rdi
addq %r15, %rdi
testb $0x1, %al
je 0x334b
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
movq %rbx, %rsi
callq *%rax
cmpb %al, 0xa(%r15)
je 0x32d2
addq $0x20, %r15
cmpq %r13, %r15
jne 0x3334
leaq 0x10(%r14), %r15
movq 0x30(%rsp), %r13
movq 0x38(%rsp), %rbp
cmpq %r13, %rbp
je 0x33d7
movq %r12, %rdi
leaq 0x3062(%rip), %rsi      # 0x63e2
callq 0x2230
testl %eax, %eax
je 0x33a0
movq %r12, %rdi
leaq 0x3055(%rip), %rsi      # 0x63e8
callq 0x2230
testl %eax, %eax
jne 0x32d2
movzwl 0x6(%r14), %ebx
addq %r15, %rbx
movq 0x10(%r13), %rax
movq 0x18(%r13), %rdi
addq %r13, %rdi
testb $0x1, %al
je 0x33bf
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
movq %rbx, %rsi
callq *%rax
cmpb %al, 0xa(%r13)
je 0x32d2
addq $0x20, %r13
cmpq %rbp, %r13
jne 0x33a8
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r13
cmpq %rbx, %r13
je 0x3415
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq (%rcx), %rsi
movq (%rax), %rdx
movq %rbx, %rdi
callq 0x4568
testb %al, %al
je 0x32d2
addq $0x20, %rbx
cmpq %r13, %rbx
jne 0x33e6
movq 0x5e4c(%rip), %rsi      # 0x9268
cmpq 0x5e4d(%rip), %rsi      # 0x9270
je 0x344f
leaq 0xb0(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
movq 0x5e26(%rip), %rbx      # 0x9268
addq $0x20, %rbx
movq %rbx, 0x5e1b(%rip)      # 0x9268
jmp 0x346a
leaq 0x5e0a(%rip), %rdi      # 0x9260
leaq 0xb0(%rsp), %rdx
callq 0x4ace
movq 0x5dfe(%rip), %rbx      # 0x9268
subq 0x5def(%rip), %rbx      # 0x9260
shrq $0x5, %rbx
movzwl (%r14), %ebp
addq %r15, %rbp
movzwl 0x6(%r14), %r13d
addq %r15, %r13
movq 0xc0(%rsp), %rax
movq (%rax), %r9
movzwl 0x2(%r14), %r14d
addq %r15, %r14
cmpb $0x0, 0x5de2(%rip)      # 0x9280
je 0x34eb
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rcx
movq (%rax), %rsi
movq (%rcx), %rdx
leaq 0xd0(%rsp), %rdi
xorl %ecx, %ecx
movq %r9, %r15
callq 0x2c94
leaq 0x2f36(%rip), %rdi      # 0x6405
movl %ebx, %esi
movq %r12, %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %r15, %r9
xorl %eax, %eax
leaq 0xd0(%rsp), %r10
pushq %r10
jmp 0x3503
subq $0x8, %rsp
leaq 0x2efb(%rip), %rdi      # 0x63f1
movl %ebx, %esi
movq %r12, %rdx
movq %rbp, %rcx
movq %r13, %r8
xorl %eax, %eax
pushq %r14
callq 0x2030
addq $0x10, %rsp
movq 0x5d73(%rip), %rax      # 0x9288
movl 0x4(%rax), %esi
cmpl %ebx, %esi
jg 0x32d2
leaq 0x2ead(%rip), %rdi      # 0x63d4
xorl %eax, %eax
callq 0x2030
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3545
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x355c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3573
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x358f
jmp 0x358f
jmp 0x358f
jmp 0x358f
jmp 0x358f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x35a9
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x35c0
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x35d7
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22e0