// File: /workspace/github_cpp_makefile_star2_O1/roberty65[P]bServer/common/src/ConfigProperty.cpp
// Function: ConfigProperty::parse(char const*)
int ConfigProperty::parse(const char *file)
{
	FILE *fp = fopen(file, "r");
	if (fp == NULL) return -1;
	
	int lineno = 0;
	char buf[(CP_NAME_MAX + CP_VALUE_MAX) * 2];

	while (fgets(buf, sizeof buf, fp) != NULL) {
		++lineno;
		if (*buf == '#') continue;

		int slen = strlen(buf);	
		while (slen > 0 && (buf[slen - 1] == '\n' || buf[slen - 1] == '\r'))
			--slen;
		buf[slen] = 0;

		char *endptr = buf + slen;
		if ((endptr = strchr(buf, '#')) != NULL) {
			*endptr = 0;
		}

#define SKIP_SPACE(p)	do { while (isspace(*(p))) (p)++; } while (0)
#define SKIP_CHARS(p)	do { while (*(p) && !isspace(*(p))) (p)++; } while (0)

		char *nptr = buf;
		SKIP_SPACE(nptr);
		if (*nptr == 0) continue; // empty-line

		char *vptr = strchr(nptr, '=');
		if (vptr == NULL) {
			fprintf(stderr, "No '=' found at line: %d\n", lineno);
			errno = EINVAL;
			fclose(fp);
			return -1;
		}
		else {
			*vptr++ = 0;
		}

		SKIP_SPACE(nptr); endptr = nptr; SKIP_CHARS(endptr); *endptr = 0;
		SKIP_SPACE(vptr); endptr = vptr; SKIP_CHARS(endptr); *endptr = 0;
#undef SKIP_SPACE
#undef SKIP_CHARS
		properties.insert(std::make_pair(std::string(nptr), std::string(vptr)));
	}

	fclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa98, %rsp            # imm = 0xA98
movq %rsi, %rax
movq %rdi, 0x88(%rsp)
leaq 0x2b88(%rip), %rsi      # 0xae4f
movq %rax, %rdi
callq 0x33e0
testq %rax, %rax
je 0x85c6
movq %rax, %r13
leaq 0x90(%rsp), %rdi
movl $0xa00, %esi            # imm = 0xA00
movq %rax, %rdx
callq 0x3550
testq %rax, %rax
je 0x85ba
leaq 0x38(%rsp), %rbp
xorl %r15d, %r15d
leaq 0x90(%rsp), %rbx
incl %r15d
cmpb $0x23, 0x90(%rsp)
je 0x8587
movq %rbx, %rdi
callq 0x3140
testl %eax, %eax
jle 0x834c
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movzbl 0x8f(%rsp,%rax), %ecx
cmpl $0xd, %ecx
je 0x833d
cmpl $0xa, %ecx
jne 0x834c
decq %rax
leaq 0x1(%rax), %rcx
cmpq $0x1, %rcx
jg 0x832b
xorl %eax, %eax
movq %r13, %r12
movq %rbp, %r14
cltq
movb $0x0, 0x90(%rsp,%rax)
movq %rbx, %rdi
movl $0x23, %esi
callq 0x3110
testq %rax, %rax
je 0x8371
movb $0x0, (%rax)
leaq 0x8f(%rsp), %r13
movq %r13, %rbp
incq %r13
movb 0x1(%rbp), %bl
movsbl %bl, %edi
callq 0x3070
testl %eax, %eax
jne 0x8379
testb %bl, %bl
je 0x848c
movq %r13, %rdi
movl $0x3d, %esi
callq 0x3110
testq %rax, %rax
je 0x85a2
movq %rax, %r13
movb $0x0, (%rax)
movsbl 0x1(%rbp), %edi
incq %rbp
callq 0x3070
testl %eax, %eax
jne 0x83b2
movb (%rbp), %al
movq %rbp, %rbx
testb %al, %al
je 0x83e5
movq %rbp, %rbx
movsbl %al, %edi
callq 0x3070
testl %eax, %eax
jne 0x83e5
movb 0x1(%rbx), %al
incq %rbx
testb %al, %al
jne 0x83cf
movb $0x0, (%rbx)
movsbl 0x1(%r13), %edi
incq %r13
callq 0x3070
testl %eax, %eax
jne 0x83e8
movb (%r13), %al
movq %r13, %rbx
testb %al, %al
je 0x841d
movq %r13, %rbx
movsbl %al, %edi
callq 0x3070
testl %eax, %eax
jne 0x841d
movb 0x1(%rbx), %al
incq %rbx
testb %al, %al
jne 0x8407
movb $0x0, (%rbx)
leaq 0x18(%rsp), %rbx
movq %rbx, 0x8(%rsp)
movq %rbp, %rdi
callq 0x3140
leaq (%rax,%rbp), %rdx
leaq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x4820
movq %r14, %rbp
movq %r14, 0x28(%rsp)
movq %r13, %rdi
callq 0x3140
leaq (%rax,%r13), %rdx
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x4820
leaq 0x58(%rsp), %r14
movq %r14, 0x48(%rsp)
movq 0x8(%rsp), %rax
cmpq %rbx, %rax
movq %r12, %r13
je 0x849c
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
jmp 0x84a3
movl $0x2, %eax
movq %r14, %rbp
movq %r12, %r13
jmp 0x857b
movups (%rbx), %xmm0
movups %xmm0, (%r14)
leaq 0x78(%rsp), %r12
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %rbx, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq %r12, 0x68(%rsp)
movq 0x28(%rsp), %rax
cmpq %rbp, %rax
je 0x84e5
movq %rax, 0x68(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x78(%rsp)
jmp 0x84ee
movups (%rbp), %xmm0
movups %xmm0, (%r12)
movq 0x30(%rsp), %rax
movq %rax, 0x70(%rsp)
movq %rbp, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq 0x88(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8b90
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
je 0x8534
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3340
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x854b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3340
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x8562
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3340
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8579
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3340
xorl %eax, %eax
leaq 0x90(%rsp), %rbx
testb $0x1, %al
jne 0x85c6
movq %rbx, %rdi
movl $0xa00, %esi            # imm = 0xA00
movq %r13, %rdx
callq 0x3550
testq %rax, %rax
jne 0x8309
jmp 0x85ba
movl %r15d, %edi
movq %r12, %r13
movq %r12, %rsi
callq 0x36de
movl $0x1, %eax
movq %r14, %rbp
jmp 0x857b
movq %r13, %rdi
callq 0x3320
xorl %eax, %eax
jmp 0x85cb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xa98, %rsp            # imm = 0xA98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x8b5a
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x8606
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3340
jmp 0x8606
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8622
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3340
movq %r14, %rdi
callq 0x35d0