// File: /workspace/github_cpp_makefile_star2_O1/skyshore2001[P]symfind/symfind.cpp
// Function: ExecCmd(char*, char const*)
int ExecCmd(char *buf, const char *prompt = "> ")
{
	char defaultCmd[20] = "?\n";
	if (buf[0] == '\n' || buf[0] == '\r')
		buf = defaultCmd;
	// shell cmd
	if (buf[0] == '!') {
		system(buf+1);
		goto nx;
	}

	char *cmd, *arg;
	int ses;
	cmd = strtok(buf, " \r\n");
	arg = strtok(NULL, "\r\n");
	ses = 0;
	while (*cmd && isdigit(*cmd)) {
		ses = ses * 10 + (*cmd - '0');
		++ cmd;
	}
// 		printf("### ses=%d, cmd='%s'\n", ses, cmd);
	InitSession(ses);
	if (STR_EQ(cmd, "f") || STR_EQ(cmd, "s")) {
		clock_t t0 = clock();
		if (cmd[0] == 'f')
			QueryFile(arg);
		else // 's'
			QuerySymbol(arg);
		printf("(Total %d result(s) in %.3fs.)\n", g_result.items.size(), (double)(clock()-t0)/CLOCKS_PER_SEC);
	}
	else if (STR_EQ(cmd, "g")) { // grep
		if (arg) {
			GrepSymbol(arg);
		}
	}
	else if (STR_EQ(cmd, "q")) {
		return 1;
	}
	else if (STR_EQ(cmd, "?")) {
		Help();
	}
	else if (!g_forsvr && (STR_EQ(cmd, "go") || STR_EQ(cmd, "n") || STR_EQ(cmd, "N"))) {
		GotoResult(cmd, arg);
	}
	else if (!g_forsvr && STR_EQ(cmd, "editor")) {
		if (arg) {
			strcpy(EDITOR, arg);
		}
		printf("editor %s\n", EDITOR);
	}
	else if (STR_EQ(cmd, "max")) {
		if (arg) {
			int n = atoi(arg);
			if (n > 0) {
				MAX_FOUND = n;
			}
		}
		printf("max %d\n", MAX_FOUND);
	}
	else if (STR_EQ(cmd, "root")) {
		if (arg) {
			g_rootsubs.Set(arg);
		}
		printf("root %s\n", g_rootsubs.pattern);
	}
	else if (STR_EQ(cmd, "add")) {
		if (arg) {
			int cnt = 0;
			const char *args[10];
			args[cnt++] = strtok(arg, " ");
			while ((args[cnt] = strtok(NULL, " ")) != NULL) {
				++ cnt;
			}
			LoadRepofiles(cnt, args);
		}
	}
	else {
		printf("*** unknown command: '%s'. Type '?' for help.\n", cmd);
	}
nx:
	if (ses != 0) {
		printf("(session %d)\n", ses);
	}
// 	printf("> ");
	printf("%s", prompt);
	if (g_forsvr)
		fputs("\n", stdout);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movapd 0x264c(%rip), %xmm0     # 0x6700
movapd %xmm0, (%rsp)
movl $0x0, 0x10(%rsp)
movzbl (%rdi), %eax
cmpl $0xd, %eax
je 0x40ce
cmpl $0xa, %eax
jne 0x40d1
movq %rsp, %rdi
cmpb $0x21, (%rdi)
jne 0x40e3
incq %rdi
callq 0x2140
jmp 0x426b
leaq 0x2210(%rip), %rsi      # 0x62fa
callq 0x22a0
movq %rax, %r12
leaq 0x21f8(%rip), %rsi      # 0x62f1
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x22a0
movq %rax, %r15
movb (%r12), %al
testb %al, %al
je 0x4130
xorl %r14d, %r14d
movsbl %al, %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x4130
leal (%r14,%r14,4), %ecx
leal (%rax,%rcx,2), %r14d
movb 0x1(%r12), %al
incq %r12
testb %al, %al
jne 0x4111
movl %r14d, %edi
callq 0x3f84
leaq 0x2390(%rip), %rsi      # 0x64cf
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x420f
leaq 0x2323(%rip), %rsi      # 0x6479
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x420f
leaq 0x2384(%rip), %rsi      # 0x64f1
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x42c4
leaq 0x236f(%rip), %rsi      # 0x64f3
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x42d3
leaq 0x235a(%rip), %rsi      # 0x64f5
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x42da
movb 0x50ce(%rip), %bpl      # 0x9280
testb %bpl, %bpl
je 0x42f5
leaq 0x234c(%rip), %rsi      # 0x650e
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x4382
leaq 0x2341(%rip), %rsi      # 0x651a
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x43ba
leaq 0x2338(%rip), %rsi      # 0x6528
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x43f0
leaq 0x2325(%rip), %rdi      # 0x652c
movq %r12, %rsi
jmp 0x43e4
callq 0x20f0
movq %rax, %r13
cmpb $0x66, (%r12)
jne 0x4228
movq %r15, %rdi
callq 0x2e15
jmp 0x4230
movq %r15, %rdi
callq 0x3132
movq 0x5031(%rip), %r15      # 0x9268
subq 0x5022(%rip), %r15      # 0x9260
sarq $0x5, %r15
callq 0x20f0
subq %r13, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1dae(%rip), %xmm0     # 0x6008
leaq 0x2270(%rip), %rdi      # 0x64d1
movq %r15, %rsi
movb $0x1, %al
callq 0x2030
testl %r14d, %r14d
je 0x4281
leaq 0x22e4(%rip), %rdi      # 0x655b
movl %r14d, %esi
xorl %eax, %eax
callq 0x2030
leaq 0x21f0(%rip), %rdi      # 0x6478
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
cmpb $0x1, 0x4fe5(%rip)      # 0x9280
jne 0x42b3
movq 0x4d24(%rip), %rax      # 0x8fc8
movq (%rax), %rsi
leaq 0x2044(%rip), %rdi      # 0x62f2
callq 0x21c0
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r15, %r15
je 0x426b
movq %r15, %rdi
callq 0x38ea
jmp 0x426b
movl $0x1, %ebp
jmp 0x42b3
movq 0x4ce7(%rip), %rax      # 0x8fc8
movq (%rax), %rsi
leaq 0x1d43(%rip), %rdi      # 0x602e
callq 0x21c0
jmp 0x426b
leaq 0x21fb(%rip), %rsi      # 0x64f7
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x4372
leaq 0x21a1(%rip), %rsi      # 0x64b0
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x4372
leaq 0x21d8(%rip), %rsi      # 0x64fa
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
je 0x4372
testb %bpl, %bpl
jne 0x41bb
leaq 0x21be(%rip), %rsi      # 0x64fc
movq %r12, %rdi
callq 0x2230
testl %eax, %eax
jne 0x41bb
testq %r15, %r15
je 0x4362
leaq 0x4e66(%rip), %rdi      # 0x91c0
movq %r15, %rsi
callq 0x2170
leaq 0x219a(%rip), %rdi      # 0x6503
leaq 0x4e50(%rip), %rsi      # 0x91c0
jmp 0x43e4
movq %r12, %rdi
movq %r15, %rsi
callq 0x3661
jmp 0x426b
testq %r15, %r15
je 0x439d
movq %r15, %rdi
callq 0x2290
testl %eax, %eax
jle 0x439d
movq 0x4eee(%rip), %rcx      # 0x9288
movl %eax, 0x4(%rcx)
movq 0x4ee4(%rip), %rax      # 0x9288
movl 0x4(%rax), %esi
leaq 0x2164(%rip), %rdi      # 0x6512
xorl %eax, %eax
callq 0x2030
jmp 0x426b
testq %r15, %r15
je 0x43d2
movq 0x4ec2(%rip), %rdi      # 0x9288
addq $0x8, %rdi
movq %r15, %rsi
callq 0x3e82
movq 0x4eaf(%rip), %rsi      # 0x9288
addq $0x8, %rsi
leaq 0x213b(%rip), %rdi      # 0x651f
xorl %eax, %eax
callq 0x2030
jmp 0x426b
testq %r15, %r15
je 0x426b
leaq 0x1f39(%rip), %rbx      # 0x6339
movq %r15, %rdi
movq %rbx, %rsi
callq 0x22a0
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorl %edi, %edi
movq %rbx, %rsi
callq 0x22a0
movq %rax, 0x28(%rsp,%r14,8)
incq %r14
testq %rax, %rax
jne 0x4413
leaq 0x20(%rsp), %rsi
movl %r14d, %edi
callq 0x2ace