// File: /workspace/github_c_makefile_star2_O2/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, %r13d
movq %rsi, %r12
movq 0x70(%rdi), %rbx
movq %rdi, 0x10(%rsp)
movq 0x78(%rdi), %r15
leaq 0xe3bc(%rip), %rsi      # 0x20a45
movq %r12, %rdi
callq 0x3440
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x12e42
movq %rax, %r14
testq %r15, %r15
setne %cl
testq %rbx, %rbx
setne %dl
testl %r13d, %r13d
sete %al
andb %al, %cl
movb %cl, 0x1e(%rsp)
andb %al, %dl
movb %dl, 0x1f(%rsp)
xorl %ebx, %ebx
leaq 0x20(%rsp), %r12
movq %r14, %rdi
callq 0x3570
testl %eax, %eax
jne 0x12e36
movl $0x800, %edx            # imm = 0x800
movq %r12, %rdi
xorl %esi, %esi
callq 0x31f0
movq %r12, %rdi
movl $0x7ff, %esi            # imm = 0x7FF
movq %r14, %rdx
callq 0x3590
movq %r12, %rdi
callq 0x1c7ac
movq %rax, %rdi
callq 0x1c7e5
movzbl (%rax), %r15d
testl %r15d, %r15d
je 0x126c5
cmpl $0x23, %r15d
je 0x126c5
movq %rax, %rbp
movl %r13d, 0xc(%rsp)
movq %rax, %rdi
leaq 0xf280(%rip), %rsi      # 0x219a5
pushq $0x6
popq %rdx
callq 0x3190
testl %eax, %eax
jne 0x1278b
callq 0x33e0
movq %rax, %r13
movq (%rax), %rax
movsbq 0x6(%rbp), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x1278b
addq $0x6, %rbp
movq %rbp, %rdi
callq 0x1c7ac
movq %rax, %rbp
movb (%rax), %r15b
cmpb $0x63, %r15b
jne 0x1278b
movb $0x63, %r15b
cmpb $0x66, 0x1(%rbp)
jne 0x1278b
cmpb $0x67, 0x2(%rbp)
jne 0x1278b
movzbl 0x3(%rbp), %eax
testq %rax, %rax
je 0x12b61
movq (%r13), %rcx
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x12b61
testb $0x1, %bl
movl $0x0, %ebx
movl 0xc(%rsp), %r13d
je 0x126c5
leaq 0x1(%rbp), %r13
testb %r15b, %r15b
je 0x127c6
callq 0x33e0
movq %rax, %rbx
movq (%rax), %rax
movzbl %r15b, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x127ce
movb (%r13), %r15b
incq %r13
jmp 0x127a2
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x1280b
movb $0x0, -0x1(%r13)
movq %r13, %rdi
callq 0x1c7ac
movq %rax, %r13
movq %rax, %rdi
incq %rdi
movzbl -0x1(%rdi), %eax
testq %rax, %rax
je 0x127c9
movq (%rbx), %rcx
testb $0x20, 0x1(%rcx,%rax,2)
je 0x127e1
movb $0x0, -0x1(%rdi)
callq 0x1c7ac
movq %rax, %rdi
callq 0x1c824
movq %rax, %r15
movq %rbp, %rdi
leaq 0xf38e(%rip), %rsi      # 0x21ba3
callq 0x34f0
testl %eax, %eax
jne 0x12e89
testq %r13, %r13
je 0x12e89
testq %r15, %r15
je 0x12e89
cmpb $0x0, (%r13)
je 0x12e89
cmpb $0x0, (%r15)
je 0x12e89
movq %r13, %rdi
leaq 0xf371(%rip), %rsi      # 0x21bc4
callq 0x34f0
testl %eax, %eax
je 0x12a26
movq %r13, %rdi
leaq 0xf364(%rip), %rsi      # 0x21bce
callq 0x34f0
testl %eax, %eax
je 0x12a63
movq %r13, %rdi
leaq 0xf15c(%rip), %rsi      # 0x219dd
callq 0x34f0
testl %eax, %eax
je 0x12aa2
movq %r13, %rdi
leaq 0xf340(%rip), %rsi      # 0x21bd8
callq 0x34f0
testl %eax, %eax
je 0x12aca
movq %r13, %rdi
leaq 0xf332(%rip), %rsi      # 0x21be1
callq 0x34f0
testl %eax, %eax
je 0x12b09
movq %r13, %rdi
leaq 0xf324(%rip), %rsi      # 0x21bea
callq 0x34f0
testl %eax, %eax
je 0x12b76
movq %r13, %rdi
leaq 0xf0da(%rip), %rsi      # 0x219b7
callq 0x34f0
testl %eax, %eax
je 0x12bae
movq %r13, %rdi
leaq 0xf0d9(%rip), %rsi      # 0x219cd
callq 0x34f0
testl %eax, %eax
je 0x12bed
movq %r13, %rdi
leaq 0xdcd3(%rip), %rsi      # 0x205de
callq 0x34f0
testl %eax, %eax
je 0x12c2c
movq %r13, %rdi
leaq 0xe1eb(%rip), %rsi      # 0x20b0d
callq 0x34f0
testl %eax, %eax
je 0x12c6b
movq %r13, %rdi
leaq 0xe249(%rip), %rsi      # 0x20b82
callq 0x34f0
testl %eax, %eax
je 0x12caa
movq %r13, %rdi
leaq 0xf2ee(%rip), %rsi      # 0x21c3e
callq 0x34f0
testl %eax, %eax
je 0x12ccb
movq %r13, %rdi
leaq 0xf28d(%rip), %rsi      # 0x21bf4
callq 0x34f0
testl %eax, %eax
je 0x12cf7
movq %r13, %rdi
leaq 0xf067(%rip), %rsi      # 0x219e5
callq 0x34f0
testl %eax, %eax
je 0x12d1f
movq %r13, %rdi
leaq 0xf26d(%rip), %rsi      # 0x21c02
callq 0x34f0
testl %eax, %eax
je 0x12d47
movq %r13, %rdi
leaq 0xf260(%rip), %rsi      # 0x21c0c
callq 0x34f0
testl %eax, %eax
je 0x12d9f
movq %r13, %rdi
leaq 0xf252(%rip), %rsi      # 0x21c15
callq 0x34f0
testl %eax, %eax
je 0x12df7
movq %r13, %rdi
leaq 0xf032(%rip), %rsi      # 0x21a0c
callq 0x34f0
movb $0x1, %bl
testl %eax, %eax
movl 0xc(%rsp), %r13d
jne 0x126c5
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x50(%rcx), %rdi
testq %rdi, %rdi
setne %cl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x50(%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x8(%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
je 0x12b48
movq %r15, %rdi
callq 0x3580
movq 0x10(%rsp), %rcx
movl %eax, 0x88(%rcx)
movb $0x1, %bl
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x18(%rcx)
jmp 0x126c5
movb $0x1, %bl
movq 0x10(%rsp), %rax
cmpl $0x0, 0x88(%rax)
jg 0x126c5
jmp 0x12ab0
testb $0x1, %bl
movb $0x1, %bl
movl 0xc(%rsp), %r13d
je 0x126c5
jmp 0x12e36
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
jne 0x12b94
movb $0x1, %bl
movq 0x10(%rsp), %rax
cmpl $0x5, 0x90(%rax)
jne 0x126c5
movq %r15, %rdi
callq 0x3580
movq 0x10(%rsp), %rcx
movl %eax, 0x90(%rcx)
movb $0x1, %bl
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x38(%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x40(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x40(%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x48(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%rcx)
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x30(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x30(%rcx)
jmp 0x126c5
movb $0x1, %bl
cmpb $0x0, 0x1f(%rsp)
movl 0xc(%rsp), %r13d
jne 0x126c5
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x11fdd
jmp 0x12cea
movb $0x1, %bl
cmpb $0x0, 0x1e(%rsp)
movl 0xc(%rsp), %r13d
jne 0x126c5
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x12071
testl %eax, %eax
je 0x126c5
jmp 0x12eca
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
je 0x12d86
movq %r15, %rdi
callq 0x3580
movq 0x10(%rsp), %rcx
movl %eax, 0x8c(%rcx)
movb $0x1, %bl
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
je 0x12dde
movq %r15, %rdi
callq 0x3580
movq 0x10(%rsp), %rcx
movl %eax, 0x80(%rcx)
movb $0x1, %bl
jmp 0x126c5
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x68(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x68(%rcx)
jmp 0x126c5
movb $0x1, %bl
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8c(%rax)
jns 0x126c5
jmp 0x12d05
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x58(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x58(%rcx)
jmp 0x126c5
movb $0x1, %bl
movq 0x10(%rsp), %rax
cmpl $0x0, 0x80(%rax)
jns 0x126c5
jmp 0x12d2d
movl 0xc(%rsp), %r13d
testl %r13d, %r13d
sete %al
movq 0x10(%rsp), %rcx
movq 0x60(%rcx), %rdi
testq %rdi, %rdi
setne %cl
movb $0x1, %bl
testb %cl, %al
jne 0x126c5
callq 0x3460
movq %r15, %rdi
callq 0x3620
movq 0x10(%rsp), %rcx
movq %rax, 0x60(%rcx)
jmp 0x126c5
movq %r14, %rdi
callq 0x3390
xorl %ebp, %ebp
jmp 0x12e75
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x12e75
leaq 0xec28(%rip), %rsi      # 0x21a7d
leaq 0xed20(%rip), %rdx      # 0x21b7c
leaq 0xed2d(%rip), %r8       # 0x21b90
pushq $0x3
popq %rdi
movl $0x14d, %ecx            # imm = 0x14D
movq %r12, %r9
xorl %eax, %eax
callq 0x1662e
movl %ebp, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x12ec2
leaq 0xebe1(%rip), %rsi      # 0x21a7d
leaq 0xecd9(%rip), %rdx      # 0x21b7c
leaq 0xed00(%rip), %r8       # 0x21baa
pushq $0x3
popq %rdi
movl $0x171, %ecx            # imm = 0x171
movq %rbp, %r9
xorl %eax, %eax
pushq %r15
pushq %r13
callq 0x1662e
popq %rax
popq %rcx
movq %r14, %rdi
callq 0x3390
pushq $-0x1
popq %rbp
jmp 0x12e75