// File: /workspace/github_c_makefile_star2_O0/TeaInside[P]teavpn/src/teavpn/teavpn_config_parser.c
// Function: teavpn_client_config_parser
bool teavpn_client_config_parser(char *internal_buf, client_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]), "server_ip")) {
			strcpy(internal_buf, &(buffer[k]));
			config->server_ip = internal_buf;
			internal_buf += strlen(internal_buf) + 1;
		} else if (!strcmp(&(buffer[j]), "server_port")) {
			config->server_port = (uint16_t)atoi(&(buffer[k]));
		} else if (!strcmp(&(buffer[j]), "username")) {
			strcpy(internal_buf, &(buffer[k]));
			config->username = internal_buf;
			config->username_len = strlen(internal_buf);
			internal_buf +=  config->username_len + 1;
		} else if (!strcmp(&(buffer[j]), "password")) {
			strcpy(internal_buf, &(buffer[k]));
			config->password = internal_buf;
			config->password_len = strlen(internal_buf);
			internal_buf += config->password_len;
		}

		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 0x6fb8(%rip), %rsi      # 0xa090
callq 0x2350
movq %rax, -0x1060(%rbp)
cmpq $0x0, -0x1060(%rbp)
jne 0x3113
movq -0x1028(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x6f19(%rip), %rdi      # 0xa019
movb $0x0, %al
callq 0x2150
movb $0x0, -0x1011(%rbp)
jmp 0x37fb
jmp 0x3115
leaq -0x1010(%rbp), %rdi
movq -0x1060(%rbp), %rdx
movl $0xfff, %esi            # imm = 0xFFF
callq 0x21e0
cmpq $0x0, %rax
je 0x37df
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 0x3180
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 0x31ff
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1061(%rbp)
je 0x31ff
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 0x320b
jmp 0x321f
movq -0x1038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1038(%rbp)
jmp 0x31ac
movq -0x1038(%rbp), %rax
movq %rax, -0x1040(%rbp)
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0x23, %eax
je 0x3255
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x325a
jmp 0x3115
jmp 0x325c
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0x3d, %eax
je 0x32b9
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x32a5
movzwl -0x102a(%rbp), %esi
leaq 0x6da4(%rip), %rdi      # 0xa036
movb $0x0, %al
callq 0x2150
movb $0x0, -0x102b(%rbp)
jmp 0x37e1
movq -0x1038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1038(%rbp)
jmp 0x325c
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 0x3346
movq -0x1038(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1062(%rbp)
je 0x3346
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 0x3352
jmp 0x336d
movq -0x1038(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1038(%rbp)
movb $0x1, -0x102c(%rbp)
jmp 0x32f3
testb $0x1, -0x102c(%rbp)
je 0x3385
movq -0x1038(%rbp), %rax
movb $0x0, -0x100f(%rbp,%rax)
jmp 0x3387
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x1063(%rbp)
je 0x33da
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1063(%rbp)
je 0x33da
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 0x33e6
jmp 0x33fa
movq -0x1048(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1048(%rbp)
jmp 0x3387
movq -0x1048(%rbp), %rax
movq %rax, -0x1050(%rbp)
movq -0x1048(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x3430
movq -0x1048(%rbp), %rax
movb $0x0, -0x1010(%rbp,%rax)
jmp 0x354d
jmp 0x3432
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0x3491
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %eax
cmpl $0x23, %eax
jne 0x347d
movq -0x1050(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1058(%rbp)
movq -0x1050(%rbp), %rax
movb $0xa, -0x1010(%rbp,%rax)
jmp 0x3491
movq -0x1050(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1050(%rbp)
jmp 0x3432
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 0x350c
movq -0x1050(%rbp), %rax
movsbl -0x1010(%rbp,%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x1064(%rbp)
je 0x350c
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 0x3518
jmp 0x3533
movq -0x1050(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1050(%rbp)
movb $0x1, -0x102c(%rbp)
jmp 0x34b9
testb $0x1, -0x102c(%rbp)
je 0x354b
movq -0x1050(%rbp), %rax
movb $0x0, -0x100f(%rbp,%rax)
jmp 0x354d
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x6b0b(%rip), %rsi      # 0xa06d
callq 0x2220
cmpl $0x0, %eax
jne 0x35bb
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 0x37c8
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x6aa1(%rip), %rsi      # 0xa071
callq 0x2220
cmpl $0x0, %eax
jne 0x3600
leaq -0x1010(%rbp), %rdi
addq -0x1048(%rbp), %rdi
callq 0x2390
movw %ax, %cx
movq -0x1028(%rbp), %rax
movw %cx, 0x20(%rax)
jmp 0x37c6
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x6abc(%rip), %rsi      # 0xa0d1
callq 0x2220
cmpl $0x0, %eax
jne 0x366d
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 0x37c4
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x6a59(%rip), %rsi      # 0xa0db
callq 0x2220
cmpl $0x0, %eax
jne 0x36b2
leaq -0x1010(%rbp), %rdi
addq -0x1048(%rbp), %rdi
callq 0x2390
movw %ax, %cx
movq -0x1028(%rbp), %rax
movw %cx, 0x3a(%rax)
jmp 0x37c2
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x6a20(%rip), %rsi      # 0xa0e7
callq 0x2220
cmpl $0x0, %eax
jne 0x373c
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
movb %al, %cl
movq -0x1028(%rbp), %rax
movb %cl, 0x38(%rax)
movq -0x1028(%rbp), %rax
movzbl 0x38(%rax), %ecx
addl $0x1, %ecx
movq -0x1020(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x1020(%rbp)
jmp 0x37c0
leaq -0x1010(%rbp), %rdi
addq -0x1040(%rbp), %rdi
leaq 0x7161(%rip), %rsi      # 0xa8b2
callq 0x2220
cmpl $0x0, %eax
jne 0x37be
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
movb %al, %cl
movq -0x1028(%rbp), %rax
movb %cl, 0x39(%rax)
movq -0x1028(%rbp), %rax
movzbl 0x39(%rax), %ecx
movq -0x1020(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x1020(%rbp)
jmp 0x37c0
jmp 0x37c2
jmp 0x37c4
jmp 0x37c6
jmp 0x37c8
movw -0x102a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x102a(%rbp)
jmp 0x3115
jmp 0x37e1
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 0x382a
movb -0x1065(%rbp), %al
andb $0x1, %al
addq $0x1070, %rsp           # imm = 0x1070
popq %rbp
retq
callq 0x2100
nop