// File: /workspace/github_c_makefile_star2_O3/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 $0x418, %rsp            # imm = 0x418
movq %rsi, -0x30(%rbp)
movq 0x8(%rdi), %rax
testq %rax, %rax
leaq 0x1091(%rip), %rdi      # 0x83bf
cmovneq %rax, %rdi
leaq 0x1091(%rip), %rsi      # 0x83ca
callq 0x2320
movq %rax, %r14
testq %rax, %rax
je 0x7500
leaq -0x440(%rbp), %r15
movq %r15, %rdi
movl $0x3ff, %esi            # imm = 0x3FF
movq %r14, %rdx
callq 0x2190
testq %rax, %rax
je 0x74f8
movq %r14, -0x38(%rbp)
movq %r15, %rdi
callq 0x2140
testq %rax, %rax
je 0x74df
movq %rax, %r12
leaq -0x43f(%rbp), %r13
xorl %ebx, %ebx
cmpb $0x3d, -0x440(%rbp,%rbx)
je 0x73a5
incq %rbx
incq %r13
cmpq %rbx, %r12
jne 0x738b
jmp 0x74df
movabsq $0x100002600, %rcx      # imm = 0x100002600
movzbl (%r15), %eax
cmpq $0x20, %rax
ja 0x73c4
btq %rax, %rcx
jae 0x73c4
incq %r15
jmp 0x73af
movq %rbx, %r14
cmpq $0x1, %rbx
je 0x73eb
movzbl -0x441(%rbp,%r14), %eax
cmpq $0x20, %rax
ja 0x73f1
btq %rax, %rcx
jae 0x73f1
decq %r14
cmpq $0x1, %r14
jne 0x73cd
movl $0x1, %r14d
movzbl (%r13), %eax
cmpq $0x20, %rax
ja 0x740a
btq %rax, %rcx
jae 0x740a
incq %r13
jmp 0x73f1
decq %r12
cmpq $0x1, %r12
je 0x7427
movzbl -0x441(%rbp,%r12), %eax
cmpq $0x20, %rax
ja 0x742d
btq %rax, %rcx
jb 0x7407
jmp 0x742d
movl $0x1, %r12d
leaq 0xf99(%rip), %rdi       # 0x83cd
movq %r15, %rsi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
je 0x749b
leaq 0xfa3(%rip), %rdi       # 0x83ed
movq %r15, %rsi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
movq -0x38(%rbp), %r14
leaq -0x440(%rbp), %r15
jne 0x74df
movl $0x5, %edx
leaq -0x3e(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2070
movq %rbx, %rdi
callq 0x20e0
movq -0x30(%rbp), %rcx
movw %ax, 0x8(%rcx)
movzwl %ax, %esi
leaq 0xf65(%rip), %rdi       # 0x83f7
xorl %eax, %eax
callq 0x2030
jmp 0x74df
subq %rbx, %r12
leaq -0x1(%r12), %rbx
movq %r12, %rdi
callq 0x2350
movq %rax, %r15
movq -0x30(%rbp), %rax
movq %r15, (%rax)
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2070
leaq 0xf0d(%rip), %rdi       # 0x83d7
movq %r15, %rsi
xorl %eax, %eax
callq 0x2030
movq -0x38(%rbp), %r14
leaq -0x440(%rbp), %r15
movq %r15, %rdi
movl $0x3ff, %esi            # imm = 0x3FF
movq %r14, %rdx
callq 0x2190
testq %rax, %rax
jne 0x736e
movq %r14, %rdi
callq 0x2160
testq %r14, %r14
setne %al
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq