// File: /workspace/github_c_makefile_star2_O2/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 0xafd(%rip), %rdi       # 0x73bf
cmovneq %rax, %rdi
leaq 0xafd(%rip), %rsi       # 0x73ca
callq 0x2330
movq %rax, %r14
testq %rax, %rax
je 0x6a72
leaq -0x43f(%rbp), %r15
movq %r14, -0x38(%rbp)
leaq -0x440(%rbp), %rbx
movq %rbx, %rdi
movl $0x3ff, %esi            # imm = 0x3FF
movq %r14, %rdx
callq 0x2190
testq %rax, %rax
je 0x6a6a
movq %rbx, %rdi
callq 0x2140
movq %rax, %r12
movq %r15, %r13
movq %rbx, %rax
xorl %ebx, %ebx
movabsq $0x100002600, %rcx      # imm = 0x100002600
cmpq %r12, %rbx
je 0x68e9
cmpb $0x3d, (%rax)
je 0x693b
incq %rax
incq %rbx
incq %r13
jmp 0x6926
leaq -0x440(%rbp), %r15
movzbl (%r15), %eax
cmpq $0x20, %rax
ja 0x6957
btq %rax, %rcx
jae 0x6957
incq %r15
jmp 0x6942
movq %rbx, %r14
cmpq $0x1, %r14
je 0x697d
movzbl -0x441(%rbp,%r14), %eax
cmpq $0x20, %rax
ja 0x697d
btq %rax, %rcx
jae 0x697d
decq %r14
jmp 0x695a
incq %r13
movzbl (%r13), %eax
cmpq $0x20, %rax
ja 0x6993
btq %rax, %rcx
jb 0x697a
jmp 0x6993
decq %r12
cmpq $0x1, %r12
je 0x69ae
movzbl -0x441(%rbp,%r12), %eax
cmpq $0x20, %rax
ja 0x69ae
btq %rax, %rcx
jb 0x6990
leaq 0xa18(%rip), %rdi       # 0x73cd
movq %r15, %rsi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
je 0x6a21
leaq 0xa22(%rip), %rdi       # 0x73ed
movq %r15, %rsi
movq %r14, %rdx
callq 0x2090
testl %eax, %eax
movq -0x38(%rbp), %r14
leaq -0x43f(%rbp), %r15
jne 0x68e9
leaq -0x3e(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
pushq $0x5
popq %rdx
callq 0x2070
movq %rbx, %rdi
callq 0x20e0
movq -0x30(%rbp), %rcx
movw %ax, 0x8(%rcx)
movzwl %ax, %esi
leaq 0x9e2(%rip), %rdi       # 0x73f7
xorl %eax, %eax
callq 0x2030
jmp 0x68e9
subq %rbx, %r12
leaq -0x1(%r12), %r14
movq %r12, %rdi
callq 0x2360
movq %rax, %r15
movq -0x30(%rbp), %rax
movq %r15, (%rax)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2070
leaq 0x987(%rip), %rdi       # 0x73d7
movq %r15, %rsi
xorl %eax, %eax
callq 0x2030
movq -0x38(%rbp), %r14
leaq -0x43f(%rbp), %r15
jmp 0x68e9
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