// File: /workspace/github_cpp_makefile_star2_O3/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, 0x48(%rsp)
leaq 0x2c8b(%rip), %rsi      # 0xae4f
movq %rax, %rdi
callq 0x33e0
testq %rax, %rax
je 0x84b2
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
movl $0xa00, %esi            # imm = 0xA00
movq %rax, %rdx
callq 0x3550
testq %rax, %rax
je 0x84a6
leaq 0x30(%rsp), %r12
xorl %r15d, %r15d
leaq 0x90(%rsp), %r14
movq %rbx, 0x40(%rsp)
incl %r15d
cmpb $0x23, 0x90(%rsp)
je 0x848d
movq %r14, %rdi
callq 0x3140
testl %eax, %eax
jle 0x824e
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movzbl 0x8f(%rsp,%rax), %ecx
cmpl $0xd, %ecx
je 0x823f
cmpl $0xa, %ecx
jne 0x824e
decq %rax
leaq 0x1(%rax), %rcx
cmpq $0x1, %rcx
ja 0x822d
xorl %eax, %eax
cltq
movb $0x0, 0x90(%rsp,%rax)
movq %r14, %rdi
movl $0x23, %esi
callq 0x3110
testq %rax, %rax
je 0x826d
movb $0x0, (%rax)
leaq 0x8f(%rsp), %r13
movq %r13, %rbp
incq %r13
movb 0x1(%rbp), %r14b
movsbl %r14b, %edi
callq 0x3070
testl %eax, %eax
jne 0x8275
testb %r14b, %r14b
leaq 0x90(%rsp), %r14
je 0x848d
movq %r13, %rdi
movl $0x3d, %esi
callq 0x3110
testq %rax, %rax
je 0x84cb
movq %rax, %r13
movq %r12, %rbx
movb $0x0, (%rax)
movb 0x1(%rbp), %r14b
incq %rbp
movsbl %r14b, %edi
callq 0x3070
testl %eax, %eax
jne 0x82bc
movq %rbp, %r12
testb %r14b, %r14b
je 0x82f5
movq %rbp, %r12
movsbl %r14b, %edi
callq 0x3070
testl %eax, %eax
jne 0x82f5
movb 0x1(%r12), %r14b
incq %r12
testb %r14b, %r14b
jne 0x82db
movb $0x0, (%r12)
movb 0x1(%r13), %r14b
incq %r13
movsbl %r14b, %edi
callq 0x3070
testl %eax, %eax
jne 0x82fa
movq %r13, %r12
testb %r14b, %r14b
je 0x8333
movq %r13, %r12
movsbl %r14b, %edi
callq 0x3070
testl %eax, %eax
jne 0x8333
movb 0x1(%r12), %r14b
incq %r12
testb %r14b, %r14b
jne 0x8319
movb $0x0, (%r12)
leaq 0x10(%rsp), %r14
movq %r14, (%rsp)
movq %rbp, %rdi
callq 0x3140
leaq (%rax,%rbp), %rdx
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x47f8
movq %rbx, %r12
movq %rbx, 0x20(%rsp)
movq %r13, %rdi
callq 0x3140
leaq (%rax,%r13), %rdx
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x47f8
leaq 0x60(%rsp), %r13
movq %r13, 0x50(%rsp)
movq (%rsp), %rax
cmpq %r14, %rax
movq 0x40(%rsp), %rbx
leaq 0x80(%rsp), %rbp
je 0x83aa
movq %rax, 0x50(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x83b3
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %r14, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq %rbp, 0x70(%rsp)
movq 0x20(%rsp), %rax
cmpq %r12, %rax
je 0x83f2
movq %rax, 0x70(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x83fb
movups (%r12), %xmm0
movups %xmm0, (%rbp)
movq 0x28(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %r12, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8a8c
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x8441
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3340
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x8458
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3340
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x846f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3340
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x8485
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3340
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movl $0xa00, %esi            # imm = 0xA00
movq %rbx, %rdx
callq 0x3550
testq %rax, %rax
jne 0x820b
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x3320
jmp 0x84b7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0xa98, %rsp            # imm = 0xA98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %edi
callq 0x36de
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x84a8
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x8a56
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x8503
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3340
jmp 0x8503
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x851e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3340
movq %rbx, %rdi
callq 0x35d0