// File: /workspace/github_c_makefile_star2_O1/ammarfaizi2[P]riyuu/src/riyuu/server/riyuu_server.c
// Function: riyuu_server_config_parse(_riyuu_run*, _riyuu_server_config*)
bool riyuu_server_config_parse(riyuu_run *run, riyuu_server_config *config)
{
	FILE *h;
	char stream[1024];
	char *strptr = stream;
	char *strptr2 = stream;
	size_t len, i, oft, oft_a, oft_b;
	bool got_oft;

	if (run->config_file == NULL) {
		h = fopen("riyuu.conf", "rb");
	} else {
		h = fopen(run->config_file, "rb");
	}

	if (h == NULL) return false;

	while (fgets(stream, 1023, h)) {

		got_oft = false;
		len = strlen(stream);

		oft_a = oft_b = 0;

		for (i = 0; i < len; i++) {
			if ((*strptr2) == '=') {
				oft = i;
				oft_b = i + 1;
				got_oft = true;
				break;
			}
			strptr2++;
		}

		if (got_oft) {
			oft_a = oft - 1;
			while (
				((*strptr) == ' ') || ((*strptr) == '\t') || 
				((*strptr) == '\r') || ((*strptr) == '\n')
			) {
				strptr++;
			}
			while (
				(oft_a > 0) && 
				((stream[oft_a] == ' ') || (stream[oft_a] == '\t') || 
				(stream[oft_a] == '\r') || (stream[oft_a] == '\n'))
			) {
				oft_a--;
			}
			oft_a++;

			strptr2++;
			while (
				((*strptr2) == ' ') || ((*strptr2) == '\t') ||
				((*strptr2) == '\r') || ((*strptr2) == '\n')
			) {
				strptr2++;
			}

			len--;
			while ((len > 0) && 
				((stream[len] == ' ') || (stream[len] == '\t') ||
				(stream[len] == '\r') || (stream[len] == '\n'))
			) {
				len--;
			}
			len = len - oft_b + 1;

			RIYUU_CONFIG_ACT("bind_addr", {
				config->bind_addr = (char *)malloc(len + 1);
				strncpy(config->bind_addr, strptr2, len);
				PRINTF_DEBUG("Parsed bind_addr: %s\n", config->bind_addr);
			}) else
			RIYUU_CONFIG_ACT("bind_port", {
				char tmp[6];
				strncpy(tmp, strptr2, 5);
				config->bind_port = (uint16_t)atoi(tmp);
				PRINTF_DEBUG("Parsed bind_port: %d\n", config->bind_port);
			})
		}

		strptr = stream;
		strptr2 = stream;
	}

	fclose(h);
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, -0x30(%rbp)
movq 0x8(%rdi), %rax
testq %rax, %rax
leaq 0xf09(%rip), %rdi       # 0x83c7
cmovneq %rax, %rdi
leaq 0xf09(%rip), %rsi       # 0x83d2
callq 0x2320
movq %rax, %r14
testq %rax, %rax
je 0x76e0
leaq -0x450(%rbp), %r13
movq %r13, %rdi
movl $0x3ff, %esi            # imm = 0x3FF
movq %r14, %rdx
callq 0x2190
testq %rax, %rax
je 0x76d8
movabsq $0x100002600, %rbx      # imm = 0x100002600
movq %r14, -0x38(%rbp)
movq %r13, %rdi
callq 0x2140
movq %rax, %r12
testq %rax, %rax
setne %al
je 0x752b
cmpb $0x3d, -0x450(%rbp)
jne 0x7530
xorl %ecx, %ecx
movq %r13, %r15
jmp 0x7569
movq %r13, %r15
jmp 0x7577
leaq (%r12,%rbp), %r15
addq $-0x450, %r15           # imm = 0xFBB0
leaq -0x1(%r12), %rax
xorl %edx, %edx
cmpq %rdx, %rax
je 0x7575
leaq 0x1(%rdx), %rcx
cmpb $0x3d, -0x44f(%rbp,%rdx)
movq %rcx, %rdx
jne 0x7542
cmpq %r12, %rcx
setb %al
leaq (%rcx,%rbp), %r15
addq $-0x450, %r15           # imm = 0xFBB0
movq %rcx, %rdx
notq %rdx
movq %rcx, -0x48(%rbp)
jmp 0x7579
xorl %eax, %eax
xorl %edx, %edx
testb %al, %al
je 0x76bf
movzbl (%r13), %eax
cmpq $0x20, %rax
ja 0x7597
btq %rax, %rbx
jae 0x7597
incq %r13
jmp 0x7581
movq -0x48(%rbp), %rax
movq %rax, %r14
cmpq $0x1, %rax
je 0x75c8
movzbl -0x451(%rbp,%r14), %eax
cmpq $0x20, %rax
ja 0x75c8
btq %rax, %rbx
jae 0x75c8
decq %r14
cmpq $0x1, %r14
jne 0x75a4
movl $0x1, %r14d
incq %r15
movzbl (%r15), %eax
cmpq $0x20, %rax
ja 0x75db
btq %rax, %rbx
jb 0x75c8
cmpq $0x1, %r12
movq %rdx, -0x40(%rbp)
je 0x7609
movzbl -0x451(%rbp,%r12), %eax
cmpq $0x20, %rax
ja 0x7609
btq %rax, %rbx
jae 0x7609
decq %r12
cmpq $0x1, %r12
jne 0x75e5
movl $0x1, %r12d
leaq 0xdc5(%rip), %rdi       # 0x83d5
movq %r13, %rsi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
je 0x7677
leaq 0xdcf(%rip), %rdi       # 0x83f5
movq %r13, %rsi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
movq -0x38(%rbp), %r14
leaq -0x450(%rbp), %r13
jne 0x76bf
movl $0x5, %edx
leaq -0x4e(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x2070
movq %r12, %rdi
callq 0x20e0
movq -0x30(%rbp), %rcx
movw %ax, 0x8(%rcx)
movzwl %ax, %esi
leaq 0xd91(%rip), %rdi       # 0x83ff
xorl %eax, %eax
callq 0x2030
jmp 0x76bf
movq -0x40(%rbp), %rax
leaq (%r12,%rax), %r14
leaq (%r12,%rax), %rdi
incq %rdi
callq 0x2350
movq %rax, %r12
movq -0x30(%rbp), %rax
movq %r12, (%rax)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2070
leaq 0xd35(%rip), %rdi       # 0x83df
movq %r12, %rsi
xorl %eax, %eax
callq 0x2030
movq -0x38(%rbp), %r14
leaq -0x450(%rbp), %r13
movq %r13, %rdi
movl $0x3ff, %esi            # imm = 0x3FF
movq %r14, %rdx
callq 0x2190
testq %rax, %rax
jne 0x7508
movq %r14, %rdi
callq 0x2160
testq %r14, %r14
setne %al
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq