// File: /workspace/github_c_makefile_star2_O1/GangZhuo[P]dohclient/src/config.c
// Function: conf_load_from_file
int conf_load_from_file(config_t* conf, const char* config_file, int force)
{
	FILE* pf;
	char line[2048], * ln;
	char* option, * name, * value;
	int len = 0, cnf_index = -1;
    int have_channel = !!conf->channels;
    int have_channel_args = !!conf->channel_args;

	pf = fopen(config_file, "r");
	if (!pf) {
		loge("failed to open %s\n", config_file);
		return -1;
	}

#define is_true_val(s) \
   (strcmp((s), "1") == 0 || \
    strcmp((s), "on") == 0 || \
	strcmp((s), "true") == 0 || \
	strcmp((s), "yes") == 0 || \
	strcmp((s), "enabled") == 0)

	while (!feof(pf)) {
		memset(line, 0, sizeof(line));
		fgets(line, sizeof(line) - 1, pf);
		ln = line;
		ln = ltrim(ln);
		ln = rtrim(ln);
		if (*ln == '\0' || *ln == '#')
			continue;

		if (strncmp(ln, "config", 6) == 0 &&
			isspace(ln[6]) &&
			strncmp((ln = ltrim(ln + 6)), "cfg", 3) == 0 &&
			(ln[3] == '\0' || isspace((int)(*((unsigned char*)ln + 3))))) {
			cnf_index++;
			if (cnf_index > 0) /*only parse first 'config cfg'*/
				break;
			continue;
		}

		if (cnf_index != 0)
			continue;

		parse_option(ln, &option, &name, &value);

		if (strcmp(option, "option") != 0 || !name || !value || !(*name) || !(*value)) {
			loge("invalid option: %s %s %s\n", option, name, value);
			fclose(pf);
			return -1;
		}

		if (strcmp(name, "bind_addr") == 0 && strlen(value)) {
			if (force || !conf->listen_addr) {
				free(conf->listen_addr);
				conf->listen_addr = strdup(value);
			}
		}
		else if (strcmp(name, "bind_port") == 0 && strlen(value)) {
			if (force || !conf->listen_port) {
				free(conf->listen_port);
				conf->listen_port = strdup(value);
			}
		}
		else if (strcmp(name, "timeout") == 0 && strlen(value)) {
			if (force || conf->timeout <= 0) {
				conf->timeout = atoi(value);
			}
		}
		else if (strcmp(name, "pid_file") == 0 && strlen(value)) {
			if (force || !conf->pid_file) {
				free(conf->pid_file);
				conf->pid_file = strdup(value);
			}
		}
		else if (strcmp(name, "log_file") == 0 && strlen(value)) {
			if (force || !conf->log_file) {
				free(conf->log_file);
				conf->log_file = strdup(value);
			}
		}
		else if (strcmp(name, "log_level") == 0 && strlen(value)) {
			if (force || conf->log_level == LOG_DEFAULT_LEVEL) {
				conf->log_level = atoi(value);
			}
		}
		else if (strcmp(name, "chnroute") == 0 && strlen(value)) {
			if (force || !conf->chnroute) {
				free(conf->chnroute);
				conf->chnroute = strdup(value);
			}
		}
		else if (strcmp(name, "blacklist") == 0 && strlen(value)) {
			if (force || !conf->blacklist) {
				free(conf->blacklist);
				conf->blacklist = strdup(value);
			}
		}
		else if (strcmp(name, "hosts") == 0 && strlen(value)) {
			if (force || !conf->hosts) {
				free(conf->hosts);
				conf->hosts = strdup(value);
			}
		}
		else if (strcmp(name, "proxy") == 0 && strlen(value)) {
			if (force || !conf->proxy) {
				free(conf->proxy);
				conf->proxy = strdup(value);
			}
		}
		else if (strcmp(name, "channel") == 0 && strlen(value)) {
			if (force || !have_channel) {
				if (conf_add_channel(conf, value)) {
					return -1;
				}
			}
		}
		else if (strcmp(name, "channel_args") == 0 && strlen(value)) {
			if (force || !have_channel_args) {
				if (conf_add_channel_args(conf, value)) {
					return -1;
				}
			}
		}
		else if (strcmp(name, "cache_timeout") == 0 && strlen(value)) {
			if (force || conf->cache_timeout < 0) {
				conf->cache_timeout = atoi(value);
			}
		}
		else if (strcmp(name, "mode") == 0 && strlen(value)) {
			if (force || conf->channel_choose_mode < 0) {
				conf->channel_choose_mode = atoi(value);
			}
		}
		else if (strcmp(name, "cache_api") == 0 && strlen(value)) {
			if (force || !conf->cache_api) {
				free(conf->cache_api);
				conf->cache_api = strdup(value);
			}
		}
		else if (strcmp(name, "cache_db") == 0 && strlen(value)) {
			if (force || !conf->cachedb) {
				free(conf->cachedb);
				conf->cachedb = strdup(value);
			}
		}
		else if (strcmp(name, "cache_autosave") == 0 && strlen(value)) {
			if (force || !conf->cachedb_autosave) {
				free(conf->cachedb_autosave);
				conf->cachedb_autosave = strdup(value);
			}
		}
		else if (strcmp(name, "wwwroot") == 0 && strlen(value)) {
			if (force || !conf->wwwroot) {
				free(conf->wwwroot);
				conf->wwwroot = strdup(value);
			}
		}
		else {
			/*do nothing*/
		}
	}

	fclose(pf);

#undef is_true_val

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x828, %rsp            # imm = 0x828
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movq 0x70(%rdi), %r12
movq 0x78(%rdi), %r13
leaq 0xf279(%rip), %rsi      # 0x22a3d
movq %r15, %rdi
callq 0x3430
testq %rax, %rax
je 0x137f0
movq %rax, %rbx
movl %ebp, 0x4(%rsp)
movq %rax, %rdi
callq 0x3560
testl %eax, %eax
je 0x1383e
movq %rbx, %rdi
callq 0x3380
xorl %ebx, %ebx
jmp 0x1382a
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x1382a
leaq 0x10265(%rip), %rsi     # 0x23a6d
leaq 0x1035d(%rip), %rdx     # 0x23b6c
leaq 0x1036a(%rip), %r8      # 0x23b80
movl $0x3, %edi
movl $0x14d, %ecx            # imm = 0x14D
movq %r15, %r9
xorl %eax, %eax
callq 0x17d92
movl %ebx, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r13, %r13
setne %cl
testq %r12, %r12
setne %dl
cmpl $0x0, 0x4(%rsp)
sete %al
andb %al, %cl
movb %cl, 0x16(%rsp)
andb %al, %dl
movb %dl, 0x17(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %r15
leaq 0x10126(%rip), %r12     # 0x23995
movl $0x800, %edx            # imm = 0x800
movq %r15, %rdi
xorl %esi, %esi
callq 0x31e0
movq %r15, %rdi
movl $0x7ff, %esi            # imm = 0x7FF
movq %rbx, %rdx
callq 0x3580
movq %r15, %rdi
callq 0x1e59e
movq %rax, %rdi
callq 0x1e5da
movq %rax, %r13
movzbl (%rax), %eax
cmpl $0x23, %eax
je 0x138ad
testl %eax, %eax
jne 0x138be
movq %rbx, %rdi
callq 0x3560
testl %eax, %eax
je 0x1386f
jmp 0x137e4
movl $0x6, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x3180
testl %eax, %eax
jne 0x13914
callq 0x33d0
movq %rax, %r12
movq (%rax), %rax
movsbq 0x6(%r13), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x13914
addq $0x6, %r13
movq %r13, %rdi
callq 0x1e59e
movq %rax, %r13
movl $0x3, %edx
movq %rax, %rdi
leaq 0x1028c(%rip), %rsi     # 0x23b93
callq 0x3180
testl %eax, %eax
je 0x139cf
testl %ebp, %ebp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x10073(%rip), %r12     # 0x23995
jne 0x138ad
movzbl (%r13), %ebp
testq %rbp, %rbp
je 0x1395b
callq 0x33d0
movq %rax, %r12
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbp,2)
movq %r13, %rdi
jne 0x1396b
movzbl 0x1(%rdi), %edx
testq %rdx, %rdx
sete %cl
je 0x13974
incq %rdi
testb $0x20, 0x1(%rax,%rdx,2)
je 0x13943
jmp 0x13970
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
jmp 0x13a52
xorl %ecx, %ecx
movq %r13, %rdi
testb %cl, %cl
je 0x1398b
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
leaq 0x1000f(%rip), %r12     # 0x23995
jmp 0x13a52
movb $0x0, (%rdi)
incq %rdi
callq 0x1e59e
movzbl (%rax), %ecx
testq %rcx, %rcx
je 0x139fc
movq (%r12), %rsi
testb $0x20, 0x1(%rsi,%rcx,2)
movq %rax, %rdi
leaq 0xffe4(%rip), %r12      # 0x23995
jne 0x13a0e
movzbl 0x1(%rdi), %edx
testq %rdx, %rdx
sete %cl
je 0x13a46
incq %rdi
testb $0x20, 0x1(%rsi,%rdx,2)
je 0x139b3
jmp 0x13a13
movzbl 0x3(%r13), %eax
testq %rax, %rax
je 0x139e8
movq (%r12), %rcx
testb $0x20, 0x1(%rcx,%rax,2)
je 0x13914
testl %ebp, %ebp
leaq 0xffa4(%rip), %r12      # 0x23995
js 0x13e74
jmp 0x137e4
movq $0x0, 0x8(%rsp)
leaq 0xff89(%rip), %r12      # 0x23995
jmp 0x13a4f
xorl %ecx, %ecx
movq %rax, %rdi
movq %rax, 0x18(%rsp)
testb %cl, %cl
je 0x13a27
movq $0x0, 0x8(%rsp)
jmp 0x13a3f
movb $0x0, (%rdi)
incq %rdi
callq 0x1e59e
movq %rax, %rdi
callq 0x1e61c
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rbp
jmp 0x13a52
movq $0x0, 0x8(%rsp)
movq %rax, %rbp
movq %r13, %rdi
leaq 0x1013b(%rip), %rsi     # 0x23b97
callq 0x34e0
testq %rbp, %rbp
je 0x13f60
testl %eax, %eax
jne 0x13f60
cmpq $0x0, 0x8(%rsp)
je 0x13f60
cmpb $0x0, (%rbp)
je 0x13f60
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x13f60
movq %rbp, %rdi
leaq 0x10118(%rip), %rsi     # 0x23bb8
callq 0x34e0
testl %eax, %eax
je 0x13c60
movq %rbp, %rdi
leaq 0x1010b(%rip), %rsi     # 0x23bc2
callq 0x34e0
testl %eax, %eax
je 0x13c81
movq %rbp, %rdi
leaq 0xfeff(%rip), %rsi      # 0x239cd
callq 0x34e0
testl %eax, %eax
je 0x13ca4
movq %rbp, %rdi
leaq 0x100e7(%rip), %rsi     # 0x23bcc
callq 0x34e0
testl %eax, %eax
je 0x13ccd
movq %rbp, %rdi
leaq 0x100d9(%rip), %rsi     # 0x23bd5
callq 0x34e0
testl %eax, %eax
je 0x13d01
movq %rbp, %rdi
leaq 0x100cb(%rip), %rsi     # 0x23bde
callq 0x34e0
testl %eax, %eax
je 0x13d3b
movq %rbp, %rdi
leaq 0xfe7d(%rip), %rsi      # 0x239a7
callq 0x34e0
testl %eax, %eax
je 0x13d76
movq %rbp, %rdi
leaq 0xfe7c(%rip), %rsi      # 0x239bd
callq 0x34e0
testl %eax, %eax
je 0x13da9
movq %rbp, %rdi
leaq 0xeaa6(%rip), %rsi      # 0x225fe
callq 0x34e0
testl %eax, %eax
je 0x13dcc
movq %rbp, %rdi
leaq 0xef96(%rip), %rsi      # 0x22b05
callq 0x34e0
testl %eax, %eax
je 0x13df8
movq %rbp, %rdi
leaq 0xeff4(%rip), %rsi      # 0x22b7a
callq 0x34e0
testl %eax, %eax
je 0x13e21
movq %rbp, %rdi
leaq 0x10095(%rip), %rsi     # 0x23c32
callq 0x34e0
testl %eax, %eax
je 0x13e46
movq %rbp, %rdi
leaq 0x10034(%rip), %rsi     # 0x23be8
callq 0x34e0
testl %eax, %eax
je 0x13e7b
movq %rbp, %rdi
leaq 0xfe0a(%rip), %rsi      # 0x239d5
callq 0x34e0
testl %eax, %eax
je 0x13e98
movq %rbp, %r12
movq %rbp, %rdi
leaq 0x10011(%rip), %rsi     # 0x23bf6
callq 0x34e0
testl %eax, %eax
je 0x13eb5
movq %r12, %rdi
leaq 0x10004(%rip), %rsi     # 0x23c00
callq 0x34e0
testl %eax, %eax
je 0x13ee1
movq %r12, %rdi
leaq 0xfff6(%rip), %rsi      # 0x23c09
callq 0x34e0
testl %eax, %eax
je 0x13f0d
movq %r12, %rdi
leaq 0xfdd2(%rip), %rsi      # 0x239fc
callq 0x34e0
xorl %ebp, %ebp
testl %eax, %eax
jne 0x13f48
cmpl $0x0, 0x4(%rsp)
je 0x13f54
movq 0x50(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x50(%r14)
jmp 0x13f48
cmpl $0x0, 0x4(%rsp)
je 0x13cc1
movq (%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, (%r14)
jmp 0x13e74
cmpl $0x0, 0x4(%rsp)
je 0x13cf4
movq 0x8(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x8(%r14)
jmp 0x13e74
cmpl $0x0, 0x4(%rsp)
je 0x13d28
movq 0x8(%rsp), %rdi
callq 0x3570
movl %eax, 0x88(%r14)
jmp 0x13e74
cmpq $0x0, (%r14)
jne 0x13e74
jmp 0x13c67
cmpl $0x0, 0x4(%rsp)
je 0x13d66
movq 0x10(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x10(%r14)
jmp 0x13e74
cmpq $0x0, 0x8(%r14)
jne 0x13e74
jmp 0x13c88
cmpl $0x0, 0x4(%rsp)
je 0x13d99
movq 0x18(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x18(%r14)
jmp 0x13e74
cmpl $0x0, 0x88(%r14)
jg 0x13e74
jmp 0x13cab
cmpl $0x0, 0x4(%rsp)
jne 0x13d50
cmpl $0x5, 0x90(%r14)
jne 0x13e74
movq 0x8(%rsp), %rdi
callq 0x3570
movl %eax, 0x90(%r14)
jmp 0x13e74
cmpq $0x0, 0x10(%r14)
jne 0x13e74
jmp 0x13cd8
cmpl $0x0, 0x4(%rsp)
je 0x13def
movq 0x38(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x38(%r14)
jmp 0x13e74
cmpq $0x0, 0x18(%r14)
jne 0x13e74
jmp 0x13d0c
cmpl $0x0, 0x4(%rsp)
je 0x13e18
movq 0x40(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x40(%r14)
jmp 0x13e74
cmpl $0x0, 0x4(%rsp)
je 0x13e3d
movq 0x48(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x48(%r14)
jmp 0x13e74
cmpq $0x0, 0x38(%r14)
jne 0x13e74
jmp 0x13d7d
cmpl $0x0, 0x4(%rsp)
je 0x13e6d
movq 0x30(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x30(%r14)
jmp 0x13e74
cmpq $0x0, 0x40(%r14)
jne 0x13e74
jmp 0x13db0
xorl %ebp, %ebp
cmpb $0x0, 0x17(%rsp)
jne 0x138ad
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x130a7
jmp 0x13e60
cmpq $0x0, 0x48(%r14)
jne 0x13e74
jmp 0x13dd3
xorl %ebp, %ebp
cmpb $0x0, 0x16(%rsp)
jne 0x138ad
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x1314e
testl %eax, %eax
je 0x138ad
jmp 0x13fa6
cmpq $0x0, 0x30(%r14)
je 0x13dff
xorl %ebp, %ebp
jmp 0x138ad
cmpl $0x0, 0x4(%rsp)
je 0x13ed5
movq 0x8(%rsp), %rdi
callq 0x3570
movl %eax, 0x8c(%r14)
jmp 0x13f46
cmpl $0x0, 0x4(%rsp)
je 0x13f01
movq 0x8(%rsp), %rdi
callq 0x3570
movl %eax, 0x80(%r14)
jmp 0x13f46
cmpl $0x0, 0x4(%rsp)
je 0x13f2d
movq 0x68(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x68(%r14)
jmp 0x13f46
cmpl $0x0, 0x8c(%r14)
jns 0x13f46
jmp 0x13e82
cmpl $0x0, 0x4(%rsp)
je 0x13f36
movq 0x58(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x58(%r14)
jmp 0x13f46
cmpl $0x0, 0x80(%r14)
jns 0x13f46
jmp 0x13e9f
cmpl $0x0, 0x4(%rsp)
je 0x13f3f
movq 0x60(%r14), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq %rax, 0x60(%r14)
jmp 0x13f46
cmpq $0x0, 0x68(%r14)
jne 0x13f46
jmp 0x13ebc
cmpq $0x0, 0x58(%r14)
jne 0x13f46
jmp 0x13ee8
cmpq $0x0, 0x60(%r14)
je 0x13f14
xorl %ebp, %ebp
leaq 0xfa46(%rip), %r12      # 0x23995
jmp 0x138ad
cmpq $0x0, 0x50(%r14)
jne 0x13f48
jmp 0x13c44
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x13f9e
leaq 0xfafa(%rip), %rsi      # 0x23a6d
leaq 0xfbf2(%rip), %rdx      # 0x23b6c
leaq 0xfc1d(%rip), %r8       # 0x23b9e
movl $0x3, %edi
movl $0x171, %ecx            # imm = 0x171
movq %r13, %r9
xorl %eax, %eax
pushq 0x8(%rsp)
pushq %rbp
callq 0x17d92
addq $0x10, %rsp
movq %rbx, %rdi
callq 0x3380
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1382a