// File: /workspace/github_c_makefile_star2_O0/TeaInside[P]teavpn/src/teavpn/teavpn_config_parser.c
// Function: teavpn_server_config_parser
bool teavpn_server_config_parser(char *internal_buf, server_config *config)
{
	uint16_t line = 1;
	char buffer[4096];
	bool ret = true, sp;
	size_t i, j, k, l, len;

	FILE *h = fopen(config->config_file, "r");

	if (h == NULL) {
		printf("Cannot open config file: %s\n", config->config_file);
		return false;
	}

	while (fgets(buffer, 4095, h)) {

		len = strlen(buffer);
		if (buffer[len - 1] != '\n') {
			buffer[len] = '\n';
			buffer[len + 1] = '\0';
		}
		i = j = k = l = 0;

		// ltrim key
		while ((buffer[i] == ' ') || (buffer[i] == '\t') || (buffer[i] == '\r')) i++;
		j = i;

		if ((buffer[i] == '#') || (buffer[i] == '\n')) continue;

		while (buffer[i] != '=') {
			if (buffer[i] == '\n') {
				printf("Parse error on line %d: couldn't find equal separator\n", line);
				ret = false;
				goto ret;
			}
			i++;
		}
		buffer[i] = '\0';
		k = i + 1;
		i--;

		sp = false;
		// rtrim key
		while ((buffer[i] == ' ') || (buffer[i] == '\t') || (buffer[i] == '\r')) {
			i--;
			sp = true;
		}

		if (sp) buffer[i + 1] = '\0';

		// ltrim value
		while ((buffer[k] == ' ') || (buffer[k] == '\t') || (buffer[k] == '\r')) k++;

		l = k;

		if (buffer[k] == '\n') {
			buffer[k] = '\0';
		} else {
			while (buffer[l] != '\n') {
				if (buffer[l] == '#') {
					len = l + 1;
					buffer[l] = '\n';
					break;
				}
				l++;
			}
			buffer[l] = '\0';
			l--;

			sp = false;
			// rtrim key
			while ((buffer[l] == ' ') || (buffer[l] == '\t') || (buffer[l] == '\r')) {
				l--;
				sp = true;
			}
			if (sp) buffer[l + 1] = '\0';
		}

		// printf("\"%s\" = \"%s\"\n", &(buffer[j]), &(buffer[k]));
		if (!strcmp(&(buffer[j]), "dev")) {
			strcpy(internal_buf, &(buffer[k]));
			config->dev = internal_buf;
			internal_buf += strlen(internal_buf) + 1;
		} else if (!strcmp(&(buffer[j]), "mtu")) {
			config->mtu = (uint16_t)atoi(&(buffer[k]));
		} else if (!strcmp(&(buffer[j]), "inet4")) {
			strcpy(internal_buf, &(buffer[k]));
			config->inet4 = internal_buf;
			internal_buf += strlen(internal_buf) + 1;
		} else if (!strcmp(&(buffer[j]), "inet4_bcmask")) {
			strcpy(internal_buf, &(buffer[k]));
			config->inet4_broadcast = internal_buf;
			internal_buf += strlen(internal_buf) + 1;
		} else if (!strcmp(&(buffer[j]), "bind_addr")) {
			strcpy(internal_buf, &(buffer[k]));
			config->bind_addr = internal_buf;
			internal_buf += strlen(internal_buf) + 1;
		} else if (!strcmp(&(buffer[j]), "bind_port")) {
			config->bind_port = (uint16_t)atoi(&(buffer[k]));
		} else if (!strcmp(&(buffer[j]), "threads")) {
			config->threads = (uint8_t)atoi(&(buffer[k]));
		} else if (!strcmp(&(buffer[j]), "data_dir")) {
			strcpy(internal_buf, &(buffer[k]));
			config->data_dir = internal_buf;
			internal_buf += strlen(internal_buf) + 1;
		} else {
			printf("Invalid config key \"%s\" on line %d\n", &(buffer[j]), line);
		}

		line++;
	}


	ret:
	fclose(h);

	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1070, %rsp           # imm = 0x1070
movq %fs:0x28, %rax
movq %rax, -0x8(%rbp)
movq %rdi, -0x1020(%rbp)
movq %rsi, -0x1028(%rbp)
movw $0x1, -0x102a(%rbp)
movb $0x1, -0x102b(%rbp)
movq -0x1028(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7808(%rip), %rsi      # 0xa090
callq 0x2350
movq %rax, -0x1060(%rbp)
cmpq $0x0, -0x1060(%rbp)
jne 0x28c3
movq -0x1028(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x7769(%rip), %rdi      # 0xa019
movb $0x0, %al
callq 0x2150
movb $0x0, -0x1011(%rbp)
jmp 0x3050
jmp 0x28c5
leaq -0x1010(%rbp), %rdi
movq -0x1060(%rbp), %rdx
movl $0xfff, %esi            # imm = 0xFFF
callq 0x21e0
cmpq $0x0, %rax
je 0x3034
leaq -0x1010(%rbp), %rdi
callq 0x20f0
movq %rax, -0x1058(%rbp)
movq -0x1058(%rbp), %rax
subq $0x1, %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0x2930
movq -0x1058(%rbp), %rax
movb $0xa, -0x1010(%rbp,%rax)
movq -0x1058(%rbp), %rax
movb $0x0, -0x100f(%rbp,%rax)
movq $0x0, -0x1050(%rbp)
movq $0x0, -0x1048(%rbp)
movq $0x0, -0x1040(%rbp)
movq $0x0, -0x1038(%rbp)
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x1061(%rbp)
je 0x29af
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1061(%rbp)
je 0x29af
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xd, %eax
sete %al
movb %al, -0x1061(%rbp)
movb -0x1061(%rbp), %al
testb $0x1, %al
jne 0x29bb
jmp 0x29cf
movq -0x1038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1038(%rbp)
jmp 0x295c
movq -0x1038(%rbp), %rax
movq %rax, -0x1040(%rbp)
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0x23, %eax
je 0x2a05
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x2a0a
jmp 0x28c5
jmp 0x2a0c
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0x3d, %eax
je 0x2a69
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x2a55
movzwl -0x102a(%rbp), %esi
leaq 0x75f4(%rip), %rdi      # 0xa036
movb $0x0, %al
callq 0x2150
movb $0x0, -0x102b(%rbp)
jmp 0x3036
movq -0x1038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1038(%rbp)
jmp 0x2a0c
movq -0x1038(%rbp), %rax
movb $0x0, -0x1010(%rbp,%rax)
movq -0x1038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1048(%rbp)
movq -0x1038(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1038(%rbp)
movb $0x0, -0x102c(%rbp)
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x1062(%rbp)
je 0x2af6
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1062(%rbp)
je 0x2af6
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xd, %eax
sete %al
movb %al, -0x1062(%rbp)
movb -0x1062(%rbp), %al
testb $0x1, %al
jne 0x2b02
jmp 0x2b1d
movq -0x1038(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1038(%rbp)
movb $0x1, -0x102c(%rbp)
jmp 0x2aa3
testb $0x1, -0x102c(%rbp)
je 0x2b35
movq -0x1038(%rbp), %rax
movb $0x0, -0x100f(%rbp,%rax)
jmp 0x2b37
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x1063(%rbp)
je 0x2b8a
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1063(%rbp)
je 0x2b8a
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xd, %eax
sete %al
movb %al, -0x1063(%rbp)
movb -0x1063(%rbp), %al
testb $0x1, %al
jne 0x2b96
jmp 0x2baa
movq -0x1048(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1048(%rbp)
jmp 0x2b37
movq -0x1048(%rbp), %rax
movq %rax, -0x1050(%rbp)
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x2be0
movq -0x1048(%rbp), %rax
movb $0x0, -0x1010(%rbp,%rax)
jmp 0x2cfd
jmp 0x2be2
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0x2c41
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0x23, %eax
jne 0x2c2d
movq -0x1050(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1058(%rbp)
movq -0x1050(%rbp), %rax
movb $0xa, -0x1010(%rbp,%rax)
jmp 0x2c41
movq -0x1050(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1050(%rbp)
jmp 0x2be2
movq -0x1050(%rbp), %rax
movb $0x0, -0x1010(%rbp,%rax)
movq -0x1050(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1050(%rbp)
movb $0x0, -0x102c(%rbp)
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x1064(%rbp)
je 0x2cbc
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1064(%rbp)
je 0x2cbc
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xd, %eax
sete %al
movb %al, -0x1064(%rbp)
movb -0x1064(%rbp), %al
testb $0x1, %al
jne 0x2cc8
jmp 0x2ce3
movq -0x1050(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1050(%rbp)
movb $0x1, -0x102c(%rbp)
jmp 0x2c69
testb $0x1, -0x102c(%rbp)
je 0x2cfb
movq -0x1050(%rbp), %rax
movb $0x0, -0x100f(%rbp,%rax)
jmp 0x2cfd
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x735b(%rip), %rsi      # 0xa06d
callq 0x2220
cmpl $0x0, %eax
jne 0x2d6b
movq -0x1020(%rbp), %rdi
leaq -0x1010(%rbp), %rsi
addq -0x1048(%rbp), %rsi
callq 0x2070
movq -0x1020(%rbp), %rcx
movq -0x1028(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x1020(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
addq -0x1020(%rbp), %rax
movq %rax, -0x1020(%rbp)
jmp 0x301d
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x72f1(%rip), %rsi      # 0xa071
callq 0x2220
cmpl $0x0, %eax
jne 0x2db0
leaq -0x1010(%rbp), %rdi
addq -0x1048(%rbp), %rdi
callq 0x2390
movw %ax, %cx
movq -0x1028(%rbp), %rax
movw %cx, 0x38(%rax)
jmp 0x301b
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x72b0(%rip), %rsi      # 0xa075
callq 0x2220
cmpl $0x0, %eax
jne 0x2e1e
movq -0x1020(%rbp), %rdi
leaq -0x1010(%rbp), %rsi
addq -0x1048(%rbp), %rsi
callq 0x2070
movq -0x1020(%rbp), %rcx
movq -0x1028(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x1020(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
addq -0x1020(%rbp), %rax
movq %rax, -0x1020(%rbp)
jmp 0x3019
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x7248(%rip), %rsi      # 0xa07b
callq 0x2220
cmpl $0x0, %eax
jne 0x2e8c
movq -0x1020(%rbp), %rdi
leaq -0x1010(%rbp), %rsi
addq -0x1048(%rbp), %rsi
callq 0x2070
movq -0x1020(%rbp), %rcx
movq -0x1028(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x1020(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
addq -0x1020(%rbp), %rax
movq %rax, -0x1020(%rbp)
jmp 0x3017
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x71e7(%rip), %rsi      # 0xa088
callq 0x2220
cmpl $0x0, %eax
jne 0x2ef9
movq -0x1020(%rbp), %rdi
leaq -0x1010(%rbp), %rsi
addq -0x1048(%rbp), %rsi
callq 0x2070
movq -0x1020(%rbp), %rcx
movq -0x1028(%rbp), %rax
movq %rcx, (%rax)
movq -0x1020(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
addq -0x1020(%rbp), %rax
movq %rax, -0x1020(%rbp)
jmp 0x3015
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x7184(%rip), %rsi      # 0xa092
callq 0x2220
cmpl $0x0, %eax
jne 0x2f3e
leaq -0x1010(%rbp), %rdi
addq -0x1048(%rbp), %rdi
callq 0x2390
movw %ax, %cx
movq -0x1028(%rbp), %rax
movw %cx, 0x3a(%rax)
jmp 0x3013
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x7149(%rip), %rsi      # 0xa09c
callq 0x2220
cmpl $0x0, %eax
jne 0x2f81
leaq -0x1010(%rbp), %rdi
addq -0x1048(%rbp), %rdi
callq 0x2390
movb %al, %cl
movq -0x1028(%rbp), %rax
movb %cl, 0x3d(%rax)
jmp 0x3011
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x710e(%rip), %rsi      # 0xa0a4
callq 0x2220
cmpl $0x0, %eax
jne 0x2fec
movq -0x1020(%rbp), %rdi
leaq -0x1010(%rbp), %rsi
addq -0x1048(%rbp), %rsi
callq 0x2070
movq -0x1020(%rbp), %rcx
movq -0x1028(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x1020(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
addq -0x1020(%rbp), %rax
movq %rax, -0x1020(%rbp)
jmp 0x300f
leaq -0x1010(%rbp), %rsi
addq -0x1040(%rbp), %rsi
movzwl -0x102a(%rbp), %edx
leaq 0x70a5(%rip), %rdi      # 0xa0ad
movb $0x0, %al
callq 0x2150
jmp 0x3011
jmp 0x3013
jmp 0x3015
jmp 0x3017
jmp 0x3019
jmp 0x301b
jmp 0x301d
movw -0x102a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x102a(%rbp)
jmp 0x28c5
jmp 0x3036
movq -0x1060(%rbp), %rdi
callq 0x20e0
movb -0x102b(%rbp), %al
andb $0x1, %al
movb %al, -0x1011(%rbp)
movb -0x1011(%rbp), %al
movb %al, -0x1065(%rbp)
movq %fs:0x28, %rax
movq -0x8(%rbp), %rcx
cmpq %rcx, %rax
jne 0x307f
movb -0x1065(%rbp), %al
andb $0x1, %al
addq $0x1070, %rsp           # imm = 0x1070
popq %rbp
retq
callq 0x2100
nopw %cs:(%rax,%rax)