// File: /workspace/github_cpp_makefile_star2_O1/skyshore2001[P]symfind/symfind.cpp
// Function: GrepSymbol(char*)
void GrepSymbol(char *arg)
{
	char gcmd[2048], *p = gcmd, *p1;
	p += sprintf(p, "grep --line-buffered -Hn -R");
	char *pat = strtok(arg, " ");
	// begin with "-": as grep option. e.g. "g -w hello"
	while (pat[0] == '-') { 
		p += sprintf(p, " %s", pat);
		pat = strtok(NULL, " ");
	}
	// ignore case if contains upper letter
	if (!ContainsUpper(pat))
		p += sprintf(p, " -i");
	p += sprintf(p, " -e \"%s\"", pat);
	vector<string> incs;
	while (p1 = strtok(NULL, " ")) {
		if (p1[0] == '-') {
			++ p1;
			p += sprintf(p, " --exclude \"%s\"", p1);
		}
		else {
			incs.push_back(p1);
// 			p += sprintf(p, " --include \"%s\"", p1);
		}
	}
	if (incs.size() == 0) { // use the default patterns when scanning
		GetTagscanPats(incs);
	}
	for (const string &inc: incs) {
		p += sprintf(p, " --include \"%s\"", inc.c_str());
	}

	SfRepoIter it(g_repos);
	while (it.Next()) {
		const char *root = g_rootsubs.Substitue(it.Value()->root);
		p += sprintf(p, " \"%s\"", root);
	}
	if (g_forsvr) {
		printf("%s\n", gcmd);
	}
	else {
		p += sprintf(p, " | tee %s", TMP_OUT);
		printf("%s\n", gcmd);
		system(gcmd);
		struct stat st;
		if (stat(TMP_OUT, &st) == 0 && st.st_size > 0)
		{
			printf("(Search results are saved in %s)\n", TMP_OUT);

			const char *ed = "vi";
			if (strstr(EDITOR, "vi")) { // vi/vim/gvim
				ed = EDITOR;
			}
			sprintf(gcmd, "%s -q %s -c copen", ed, TMP_OUT);
			system(gcmd);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8f8, %rsp            # imm = 0x8F8
movups 0x2b36(%rip), %xmm0     # 0x6438
leaq 0x10b(%rsp), %r14
movups %xmm0, -0xf(%r14)
movups 0x2b16(%rip), %xmm0     # 0x642c
movaps %xmm0, -0x1b(%r14)
leaq 0x2a17(%rip), %rsi      # 0x6339
callq 0x22a0
movq %rax, %rbx
movb (%rax), %al
cmpb $0x2d, %al
jne 0x3966
leaq 0x2b40(%rip), %r15      # 0x6477
leaq 0x29fb(%rip), %r12      # 0x6339
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %r14
xorl %edi, %edi
movq %r12, %rsi
callq 0x22a0
movq %rax, %rbx
movb (%rax), %al
cmpb $0x2d, %al
je 0x393e
testb %al, %al
setne %bpl
je 0x3996
movsbl %al, %edi
callq 0x2110
testl %eax, %eax
jne 0x3996
leaq 0x1(%rbx), %r15
movsbl (%r15), %edi
testl %edi, %edi
setne %bpl
je 0x3996
callq 0x2110
incq %r15
testl %eax, %eax
je 0x397e
testb %bpl, %bpl
jne 0x39a6
movl $0x692d20, (%r14)       # imm = 0x692D20
addq $0x3, %r14
leaq 0x2a9b(%rip), %rsi      # 0x6448
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
movslq %eax, %rbx
addq %r14, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x2962(%rip), %rsi      # 0x6339
xorl %edi, %edi
callq 0x22a0
testq %rax, %rax
je 0x3a72
movq %rax, %rbp
leaq 0x30(%rsp), %r14
leaq 0x2943(%rip), %r15      # 0x6339
leaq 0x20(%rsp), %r12
movq %rsp, %r13
cmpb $0x2d, (%rbp)
jne 0x3a22
incq %rbp
movq %rbx, %rdi
leaq 0x2a40(%rip), %rsi      # 0x6451
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %rbx
jmp 0x3a60
movq %r14, 0x20(%rsp)
movq %rbp, %rdi
callq 0x20b0
leaq (%rax,%rbp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4d96
movq %r13, %rdi
movq %r12, %rsi
callq 0x4e26
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x3a60
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21a0
xorl %edi, %edi
movq %r15, %rsi
callq 0x22a0
movq %rax, %rbp
testq %rax, %rax
jne 0x39fe
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
jne 0x3a85
movq %rsp, %rdi
callq 0x3776
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x3abf
leaq 0x29c7(%rip), %r15      # 0x6461
movq (%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2040
movslq %eax, %r14
addq %rbx, %r14
addq $0x20, %r12
movq %r14, %rbx
cmpq %r13, %r12
jne 0x3a9a
jmp 0x3ac2
movq %rbx, %r14
movq 0x5787(%rip), %rax      # 0x9250
leaq 0xb0(%rsp), %rcx
movq %rax, 0x18(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rcx)
movups %xmm0, 0x30(%rcx)
movq %rcx, 0x20(%rcx)
leaq 0x2883(%rip), %rbx      # 0x636e
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0x3b04
movq 0x18(%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0x3b3b
movq 0x5770(%rip), %rdi      # 0x9288
addq $0x8, %rdi
movq (%rax), %rsi
callq 0x2d90
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2040
cltq
addq %rax, %r14
jmp 0x3aeb
cmpb $0x1, 0x573e(%rip)      # 0x9280
jne 0x3b56
leaq 0xf0(%rsp), %rdi
callq 0x2280
jmp 0x3c03
movq 0x56cb(%rip), %rdx      # 0x9228
leaq 0x290d(%rip), %rsi      # 0x6471
movq %r14, %rdi
xorl %eax, %eax
callq 0x2040
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2280
movq %rbx, %rdi
callq 0x2140
movq 0x569b(%rip), %rdi      # 0x9228
leaq 0x20(%rsp), %rsi
callq 0x2160
testl %eax, %eax
jne 0x3c03
cmpq $0x0, 0x50(%rsp)
jle 0x3c03
movq 0x567e(%rip), %rsi      # 0x9228
leaq 0x28ca(%rip), %rdi      # 0x647b
xorl %eax, %eax
callq 0x2030
leaq 0x5601(%rip), %rbx      # 0x91c0
leaq 0x28d7(%rip), %r14      # 0x649d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2050
testq %rax, %rax
cmoveq %r14, %rbx
movq 0x5649(%rip), %rcx      # 0x9228
leaq 0x28ba(%rip), %rsi      # 0x64a0
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2040
movq %r14, %rdi
callq 0x2140
movq %rsp, %rdi
callq 0x4784
addq $0x8f8, %rsp            # imm = 0x8F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c23
jmp 0x3c23
jmp 0x3c23
movq %rax, %rbx
jmp 0x3c42
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x3c42
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rsp, %rdi
callq 0x4784
movq %rbx, %rdi
callq 0x22e0