// File: /workspace/github_cpp_makefile_star2_O2/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 $0x448, %rsp            # imm = 0x448
movq %rdi, %r15
callq 0x2100
movq %rax, 0x38(%rsp)
leaq 0x6bfd(%rip), %rax      # 0x9260
movq %rax, %rbp
movq (%rax), %rcx
leaq 0x18(%rcx), %rax
testq %rcx, %rcx
jne 0x2663
leaq 0x41(%rsp), %r12
xorl %ecx, %ecx
leaq 0x40(%rsp), %rbx
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
xorl %r14d, %r14d
movq %rbx, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x22e0
testq %rax, %rax
je 0x294e
movb 0x40(%rsp), %al
cmpb $0x21, %al
jne 0x27f9
movq %r12, %rdi
leaq 0x3c1a(%rip), %rsi      # 0x62f4
pushq $0x5
popq %rdx
callq 0x21c0
testl %eax, %eax
je 0x2724
movq %r12, %rdi
leaq 0x3c3e(%rip), %rsi      # 0x632e
pushq $0xc
popq %rdx
callq 0x21c0
testl %eax, %eax
jne 0x26ab
testq %r13, %r13
je 0x27f1
leaq 0x4d(%rsp), %rdi
leaq 0x3be9(%rip), %rsi      # 0x62fa
callq 0x22d0
movq %rax, %rdi
callq 0x2340
movq %rax, 0x8(%r13)
jmp 0x26ab
testb $0x1, %r14b
movb $0x1, %r14b
jne 0x26ab
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x20f0
movq %rax, %r13
leaq 0x46(%rsp), %rdi
leaq 0x3baf(%rip), %rsi      # 0x62fa
callq 0x22d0
movq %rax, %rdi
callq 0x2340
movq %rax, %r14
movq %rax, (%r13)
movq %rax, %rdi
callq 0x25f1
testb %al, %al
jne 0x292c
movq %r14, %rdi
pushq $0x2f
popq %rsi
callq 0x2090
movb $0x2f, %cl
testq %rax, %rax
jne 0x2793
movq %r14, %rdi
pushq $0x5c
popq %rsi
callq 0x2090
movb $0x5c, %cl
testq %rax, %rax
je 0x2799
movb %cl, 0x6aa7(%rip)       # 0x9240
movq %r13, (%rbp)
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x27ab
andq $0x0, (%rax)
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x10(%rsp), %rcx
je 0x27be
andq $0x0, (%rax)
testq %rcx, %rcx
je 0x27c7
andq $0x0, (%rcx)
leaq 0x18(%r13), %rbp
movq %r13, %rax
addq $0x10, %rax
movq %rax, 0x18(%rsp)
movb $0x1, %r14b
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x26ab
xorl %r13d, %r13d
jmp 0x26ab
cmpb $0x9, %al
jne 0x28a7
cmpb $0x9, 0x42(%rsp)
jne 0x28a7
leaq 0x43(%rsp), %rdi
leaq 0x3b23(%rip), %rsi      # 0x633b
callq 0x22d0
movzbl 0x41(%rsp), %ecx
cmpl $0x64, %ecx
je 0x2835
cmpl $0x66, %ecx
jne 0x26a8
jmp 0x28d0
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x29c3
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x20f0
movq %rax, %r14
movq 0x28(%rsp), %rdi
callq 0x2340
movq %rax, (%r14)
movq %r14, (%rbx)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x2874
andq $0x0, (%rax)
movq 0x10(%rsp), %rax
testq %rax, %rax
leaq 0x40(%rsp), %rbx
je 0x2887
andq $0x0, (%rax)
leaq 0x10(%r14), %rax
movq %rax, 0x18(%rsp)
addq $0x8, %r14
movq $0x0, 0x10(%rsp)
movq %r14, 0x8(%rsp)
jmp 0x26a8
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x29d7
movq %rbx, %rdi
callq 0x2573
movq %rax, %rcx
movq %rax, (%r14)
addq $0x8, %rcx
incl 0x24(%rsp)
jmp 0x26a3
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x29e0
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x20f0
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rdi
callq 0x2340
movq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq %rcx, (%r14)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x2916
andq $0x0, (%rax)
leaq 0x10(%rcx), %rax
movq %rax, 0x8(%rsp)
incl 0x20(%rsp)
addq $0x8, %rcx
jmp 0x26a3
leaq 0x39cb(%rip), %rdi      # 0x62fe
movq %r14, %rsi
xorl %eax, %eax
callq 0x2030
movq (%r13), %rdi
callq 0x2200
movq %r13, %rdi
callq 0x2200
testq %rbp, %rbp
je 0x2958
andq $0x0, (%rbp)
movq 0x18(%rsp), %rax
testq %rax, %rax
movq 0x8(%rsp), %rcx
je 0x296b
andq $0x0, (%rax)
testq %rcx, %rcx
je 0x2974
andq $0x0, (%rcx)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x2982
andq $0x0, (%rax)
callq 0x2100
subq 0x38(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x366f(%rip), %xmm0     # 0x6008
leaq 0x399d(%rip), %rdi      # 0x633d
movl 0x20(%rsp), %esi
movl 0x24(%rsp), %edx
movb $0x1, %al
callq 0x2030
xorl %eax, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3cba(%rip), %rdi      # 0x6684
callq 0x22b0
pushq $-0x1
popq %rdi
callq 0x2210
leaq 0x3c56(%rip), %rdi      # 0x6634
jmp 0x29ca
leaq 0x3c75(%rip), %rdi      # 0x665c
jmp 0x29ca