// File: /workspace/github_cpp_makefile_star2_O3/skyshore2001[P]symfind/symfind.cpp
// Function: LoadRepofile(_IO_FILE*)
int LoadRepofile(FILE *fp)
{
	clock_t t0 = clock();
	char buf[1024];
	bool ismeta = false;
	SfRepo **pRepo = &g_repos;
	SfFolder **pFolder = NULL;
	SfFile **pFile = NULL;
	SfSymbol **pSymbol = NULL;

	// goto repo link end.
	while (*pRepo) {
		pRepo = &((*pRepo)->next);
	}
	int scnt = 0, fcnt = 0;
	SfRepo *repo = NULL;
	while (fgets(buf, 1024, fp)) {
		if (buf[0] == '!') {
			char *p = buf+1;
			if (strncmp(p, "ROOT ", 5) == 0) {
				if (!ismeta) {
					p += 5;
					repo = CALLOC_T(SfRepo);
					repo->root = strdup(strtok(p, " \r\n"));
					if (RootExists(repo->root)) {
						printf("!!! ignore repo loading as root dir exists: %s\n", repo->root);
						FREE(repo->root);
						FREE(repo);
						break;
					}
					if (strchr(repo->root, '/') != NULL) {
						SEP = '/';
					}
					else if (strchr(repo->root, '\\') != NULL) {
						SEP = '\\';
					}

					*pRepo = repo;
					pRepo = &repo->next;

					EndFolder();
					pFolder = &repo->folders;
				}
				ismeta = true;
			}
			else if (strncmp(p, "TAGSCAN_PAT ", 12) == 0) {
				p += 12;
				if (repo) {
					repo->tagscan_pat = strdup(strtok(p, " \r\n"));
				}
			}
			continue;
		}
		ismeta = false;

		// "  d/f  <name>  <time>"
		if (buf[0] == '\t' && buf[2] == '\t') {
			char *value = strtok(buf+3, "\t");
			if (buf[1] == 'd') {
				if (pFolder == NULL) {
					printf("*** bad format (no repo before folder)!\n");
					exit(-1);
				}
				SfFolder *folder = CALLOC_T(SfFolder);
				folder->name = strdup(value);

				*pFolder = folder;
				pFolder = &folder->next;

				EndFile();
				pFile = &folder->files;
			}
			else if (buf[1] == 'f') {
				if (pFile == NULL) {
					printf("*** bad format! (no folder before file)\n");
					exit(-1);
				}

				SfFile *file = CALLOC_T(SfFile);
				file->name = strdup(value);

				*pFile = file;
				pFile = &file->next;
				++ fcnt;

				EndSymbol();
				pSymbol = &file->symbols;
			}
		}
		else { // symbol
			if (pSymbol == NULL) {
				printf("*** bad format! (no file before symbol)\n");
				exit(-1);
			}

			SfSymbol *symbol = NewSymbol(buf);

			*pSymbol = symbol;
			pSymbol = &symbol->next;
			++ scnt;
		}
	}
	EndRepo();
	printf("load %d files, %d symbols in %.3fs.\n", fcnt, scnt, (double)(clock()-t0)/CLOCKS_PER_SEC);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rdi, %r15
callq 0x20f0
movq %rax, %rbx
leaq 0x6b57(%rip), %rax      # 0x9250
movq %rax, %r12
movq (%rax), %rcx
leaq 0x18(%rcx), %rax
testq %rcx, %rcx
jne 0x26f9
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x22b0
testq %rax, %rax
je 0x2a24
movq %rbx, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x30(%rsp), %r13
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
movq $0x0, (%rsp)
movq %r13, %r14
xorl %r13d, %r13d
movb 0x30(%rsp), %al
cmpb $0x21, %al
jne 0x28d1
movl 0x31(%rsp), %eax
movl $0x544f4f52, %ecx       # imm = 0x544F4F52
xorl %ecx, %eax
movzbl 0x35(%rsp), %ecx
xorl $0x20, %ecx
orl %eax, %ecx
je 0x27d3
movq 0x31(%rsp), %rax
movabsq $0x5f4e414353474154, %rcx # imm = 0x5F4E414353474154
xorq %rcx, %rax
movl 0x39(%rsp), %ecx
xorq $0x20544150, %rcx       # imm = 0x20544150
orq %rax, %rcx
jne 0x28ad
testq %rbp, %rbp
je 0x28ab
leaq 0x3d(%rsp), %rdi
leaq 0x3b3d(%rip), %rsi      # 0x62fa
callq 0x22a0
movq %rax, %rdi
callq 0x2310
movq %rax, 0x8(%rbp)
jmp 0x28ad
movb $0x1, %bl
testb $0x1, %r13b
jne 0x28b0
movl $0x1, %edi
movl $0x20, %esi
callq 0x20e0
movq %rax, %rbp
leaq 0x36(%rsp), %rdi
leaq 0x3afd(%rip), %rsi      # 0x62fa
callq 0x22a0
movq %rax, %rdi
callq 0x2310
movq %rax, %r13
movq %rax, (%rbp)
movq %rax, %rdi
callq 0x2686
testb %al, %al
jne 0x2a31
movq %r13, %rdi
movl $0x2f, %esi
callq 0x2090
movb $0x2f, %cl
testq %rax, %rax
jne 0x2849
movq %r13, %rdi
movl $0x5c, %esi
callq 0x2090
movb $0x5c, %cl
testq %rax, %rax
je 0x284f
movb %cl, 0x69e1(%rip)       # 0x9230
movq %rbp, (%r12)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x2864
movq $0x0, (%rax)
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
movq (%rsp), %rax
movq %r14, %rdi
je 0x287c
movq $0x0, (%rcx)
testq %rax, %rax
je 0x2888
movq $0x0, (%rax)
leaq 0x18(%rbp), %r12
movq %rbp, %rax
addq $0x10, %rax
movq %rax, 0x10(%rsp)
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
jmp 0x28b3
xorl %ebp, %ebp
movl %r13d, %ebx
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x22b0
movl %ebx, %r13d
testq %rax, %rax
jne 0x275f
jmp 0x2a53
cmpb $0x9, %al
jne 0x2982
cmpb $0x9, 0x32(%rsp)
jne 0x2982
leaq 0x33(%rsp), %rdi
leaq 0x3a4b(%rip), %rsi      # 0x633b
callq 0x22a0
movzbl 0x31(%rsp), %ecx
cmpl $0x66, %ecx
je 0x29ab
cmpl $0x64, %ecx
jne 0x2a06
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x2ae5
movl $0x1, %edi
movl $0x18, %esi
callq 0x20e0
movq %rax, %r13
movq 0x20(%rsp), %rdi
callq 0x2310
movq %rax, (%r13)
movq %r13, (%rbx)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x2953
movq $0x0, (%rax)
movq (%rsp), %rax
testq %rax, %rax
je 0x2963
movq $0x0, (%rax)
leaq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
addq $0x8, %r13
movq $0x0, (%rsp)
movq %r13, 0x8(%rsp)
jmp 0x2a06
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x2adc
movq %r14, %r13
movq %r14, %rdi
callq 0x25c0
movq %rax, (%rbx)
addq $0x8, %rax
incl 0x1c(%rsp)
movq %rax, (%rsp)
jmp 0x2a09
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rbx
testq %rbx, %rbx
je 0x2aee
movl $0x1, %edi
movl $0x18, %esi
callq 0x20e0
movq %rax, %r13
movq 0x20(%rsp), %rdi
callq 0x2310
movq %rax, (%r13)
movq %r13, (%rbx)
movq (%rsp), %rax
testq %rax, %rax
je 0x29f1
movq $0x0, (%rax)
leaq 0x10(%r13), %rax
movq %rax, 0x8(%rsp)
incl 0x18(%rsp)
addq $0x8, %r13
movq %r13, (%rsp)
movq %r14, %r13
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x22b0
testq %rax, %rax
jne 0x2759
jmp 0x2a53
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
xorl %ebp, %ebp
xorl %r15d, %r15d
jmp 0x2a74
leaq 0x38c6(%rip), %rdi      # 0x62fe
movq %r13, %rsi
xorl %eax, %eax
callq 0x2030
movq (%rbp), %rdi
callq 0x21e0
movq %rbp, %rdi
callq 0x21e0
testq %r12, %r12
movq 0x28(%rsp), %rbx
movl 0x18(%rsp), %ebp
movl 0x1c(%rsp), %r15d
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdx
je 0x2a7c
movq $0x0, (%r12)
testq %rdx, %rdx
je 0x2a88
movq $0x0, (%rdx)
testq %rcx, %rcx
je 0x2a94
movq $0x0, (%rcx)
testq %rax, %rax
je 0x2aa0
movq $0x0, (%rax)
callq 0x20f0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x3553(%rip), %xmm0     # 0x6008
leaq 0x3881(%rip), %rdi      # 0x633d
movl %ebp, %esi
movl %r15d, %edx
movb $0x1, %al
callq 0x2030
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3b51(%rip), %rdi      # 0x6634
jmp 0x2af5
leaq 0x3b98(%rip), %rdi      # 0x6684
jmp 0x2af5
leaq 0x3b67(%rip), %rdi      # 0x665c
callq 0x2280
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21f0