// File: /workspace/github_c_makefile_star2_O3/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 0xf7ed(%rip), %rsi      # 0x22a45
movq %r15, %rdi
callq 0x3430
testq %rax, %rax
je 0x13289
movq %rax, %rbx
movq %r14, 0x10(%rsp)
movl %ebp, 0x18(%rsp)
movq %rax, %rdi
callq 0x3560
testl %eax, %eax
je 0x132d7
movq %rbx, %rdi
callq 0x3380
xorl %ebx, %ebx
jmp 0x132c3
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x132c3
leaq 0x107dc(%rip), %rsi     # 0x23a7d
leaq 0x108d4(%rip), %rdx     # 0x23b7c
leaq 0x108e1(%rip), %r8      # 0x23b90
movl $0x3, %edi
movl $0x14d, %ecx            # imm = 0x14D
movq %r15, %r9
xorl %eax, %eax
callq 0x1771e
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, 0x18(%rsp)
sete %al
andb %al, %cl
movb %cl, 0x1e(%rsp)
andb %al, %dl
movb %dl, 0x1f(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %r15
leaq 0x1069c(%rip), %r12     # 0x239a5
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 0x1ddaa
movq %rax, %rdi
callq 0x1ddea
movzbl (%rax), %ebp
cmpl $0x23, %ebp
je 0x13344
testl %ebp, %ebp
jne 0x13355
movq %rbx, %rdi
callq 0x3560
testl %eax, %eax
je 0x13309
jmp 0x1327d
movq %rax, %r13
movl $0x6, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3180
testl %eax, %eax
jne 0x133c9
callq 0x33d0
movq %rax, %r12
movq (%rax), %rax
movsbq 0x6(%r13), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x133c9
addq $0x6, %r13
movq %r13, %rdi
callq 0x1ddaa
movq %rax, %r13
movb (%rax), %bpl
cmpb $0x63, %bpl
jne 0x133c9
movb $0x63, %bpl
cmpb $0x66, 0x1(%r13)
jne 0x133c9
cmpb $0x67, 0x2(%r13)
jne 0x133c9
movzbl 0x3(%r13), %eax
testq %rax, %rax
je 0x137e3
movq (%r12), %rcx
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x137e3
testl %r14d, %r14d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x105cc(%rip), %r12     # 0x239a5
jne 0x13344
testb %bpl, %bpl
je 0x13425
callq 0x33d0
movq %rax, %r12
movq (%rax), %rax
leaq 0x1(%r13), %rdi
movzbl %bpl, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x13437
movb (%rdi), %bpl
incq %rdi
testb %bpl, %bpl
jne 0x133f3
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
movl 0x18(%rsp), %ebp
leaq 0x10585(%rip), %r12     # 0x239a5
jmp 0x134a7
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
movl 0x18(%rsp), %ebp
jmp 0x134a7
movb $0x0, -0x1(%rdi)
callq 0x1ddaa
movb (%rax), %cl
testb %cl, %cl
movl 0x18(%rsp), %ebp
je 0x13479
movq (%r12), %rdx
movq %rax, %rdi
incq %rdi
leaq 0x1054a(%rip), %r12     # 0x239a5
movzbl %cl, %ecx
testb $0x20, 0x1(%rdx,%rcx,2)
jne 0x1348e
movb (%rdi), %cl
incq %rdi
testb %cl, %cl
jne 0x1345b
movq $0x0, 0x8(%rsp)
jmp 0x13489
movq $0x0, 0x8(%rsp)
leaq 0x1051c(%rip), %r12     # 0x239a5
movq %rax, %r14
jmp 0x134a7
movb $0x0, -0x1(%rdi)
movq %rax, %r14
callq 0x1ddaa
movq %rax, %rdi
callq 0x1de2c
movq %rax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x106f2(%rip), %rsi     # 0x23ba3
callq 0x34e0
testq %r14, %r14
je 0x13a87
testl %eax, %eax
jne 0x13a87
cmpq $0x0, 0x8(%rsp)
je 0x13a87
cmpb $0x0, (%r14)
je 0x13a87
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x13a87
movq %r14, %rdi
leaq 0x106cf(%rip), %rsi     # 0x23bc4
movq %r14, %r13
callq 0x34e0
testl %eax, %eax
je 0x136cb
movq %r13, %rdi
leaq 0x106bf(%rip), %rsi     # 0x23bce
callq 0x34e0
testl %eax, %eax
je 0x13705
movq %r13, %rdi
leaq 0x104b7(%rip), %rsi     # 0x239dd
callq 0x34e0
testl %eax, %eax
je 0x1373f
movq %r13, %rdi
leaq 0x1069b(%rip), %rsi     # 0x23bd8
callq 0x34e0
testl %eax, %eax
je 0x13761
movq %r13, %rdi
leaq 0x1068d(%rip), %rsi     # 0x23be1
callq 0x34e0
testl %eax, %eax
je 0x1379b
movq %r13, %rdi
leaq 0x1067f(%rip), %rsi     # 0x23bea
callq 0x34e0
testl %eax, %eax
je 0x137f4
movq %r13, %rdi
leaq 0x10435(%rip), %rsi     # 0x239b7
callq 0x34e0
testl %eax, %eax
je 0x1381e
movq %r13, %rdi
leaq 0x10434(%rip), %rsi     # 0x239cd
callq 0x34e0
testl %eax, %eax
je 0x13858
movq %r13, %rdi
leaq 0xf02e(%rip), %rsi      # 0x225de
callq 0x34e0
testl %eax, %eax
je 0x13892
movq %r13, %rdi
leaq 0xf546(%rip), %rsi      # 0x22b0d
callq 0x34e0
testl %eax, %eax
je 0x138cc
movq %r13, %rdi
leaq 0xf5a4(%rip), %rsi      # 0x22b82
callq 0x34e0
testl %eax, %eax
je 0x13906
movq %r13, %rdi
leaq 0x10649(%rip), %rsi     # 0x23c3e
callq 0x34e0
testl %eax, %eax
je 0x13933
movq %r13, %rdi
leaq 0x105e8(%rip), %rsi     # 0x23bf4
callq 0x34e0
testl %eax, %eax
je 0x13960
movq %r13, %rdi
leaq 0x103c2(%rip), %rsi     # 0x239e5
callq 0x34e0
testl %eax, %eax
je 0x1397e
movq %r13, %r14
movq %r13, %rdi
leaq 0x105c5(%rip), %rsi     # 0x23c02
callq 0x34e0
testl %eax, %eax
je 0x139a3
movq %r14, %rdi
leaq 0x105b8(%rip), %rsi     # 0x23c0c
callq 0x34e0
testl %eax, %eax
je 0x139f2
movq %r14, %rdi
leaq 0x105aa(%rip), %rsi     # 0x23c15
callq 0x34e0
testl %eax, %eax
je 0x13a48
movq %r14, %rdi
leaq 0x1038a(%rip), %rsi     # 0x23a0c
callq 0x34e0
testl %eax, %eax
jne 0x13a7b
cmpl $0x0, 0x18(%rsp)
sete %al
movq 0x10(%rsp), %rcx
movq 0x50(%rcx), %rdi
testq %rdi, %rdi
setne %cl
testb %cl, %al
jne 0x13a7b
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq 0x10(%rsp), %rcx
movq %rax, 0x50(%rcx)
jmp 0x13a7b
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq (%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, (%rbp)
jmp 0x13344
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x8(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x8(%rbp)
jmp 0x13344
testl %ebp, %ebp
movq 0x10(%rsp), %rbp
je 0x137d5
movq 0x8(%rsp), %rdi
callq 0x3570
movl %eax, 0x88(%rbp)
jmp 0x13816
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x10(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x10(%rbp)
jmp 0x13344
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x18(%rbp)
jmp 0x13344
cmpl $0x0, 0x88(%rbp)
jg 0x13816
jmp 0x1374c
testl %r14d, %r14d
leaq 0x101b8(%rip), %r12     # 0x239a5
js 0x13816
jmp 0x1327d
testl %ebp, %ebp
movq 0x10(%rsp), %rbp
jne 0x13806
cmpl $0x5, 0x90(%rbp)
jne 0x13816
movq 0x8(%rsp), %rdi
callq 0x3570
movl %eax, 0x90(%rbp)
xorl %r14d, %r14d
jmp 0x13344
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x38(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x38(%rbp)
jmp 0x13344
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x40(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x40(%rbp)
jmp 0x13344
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x48(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x48(%rbp)
jmp 0x13344
testl %ebp, %ebp
sete %al
movq 0x10(%rsp), %rbp
movq 0x30(%rbp), %rdi
testq %rdi, %rdi
setne %cl
xorl %r14d, %r14d
testb %cl, %al
jne 0x13344
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
xorl %r14d, %r14d
movq %rax, 0x30(%rbp)
jmp 0x13344
xorl %r14d, %r14d
cmpb $0x0, 0x1f(%rsp)
jne 0x13344
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x12b3b
xorl %r14d, %r14d
testl %eax, %eax
je 0x13344
jmp 0x13ace
cmpb $0x0, 0x1e(%rsp)
jne 0x13816
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x12be2
testl %eax, %eax
movl $0x0, %r14d
je 0x13344
jmp 0x13ace
testl %ebp, %ebp
je 0x139df
movq 0x8(%rsp), %rdi
callq 0x3570
movq 0x10(%rsp), %rcx
movl %eax, 0x8c(%rcx)
jmp 0x13a39
cmpl $0x0, 0x18(%rsp)
je 0x13a27
movq 0x8(%rsp), %rdi
callq 0x3570
movq 0x10(%rsp), %rcx
movl %eax, 0x80(%rcx)
jmp 0x13a39
cmpl $0x0, 0x18(%rsp)
sete %al
movq 0x10(%rsp), %rcx
movq 0x68(%rcx), %rdi
testq %rdi, %rdi
setne %cl
testb %cl, %al
jne 0x13a7b
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq 0x10(%rsp), %rcx
movq %rax, 0x68(%rcx)
jmp 0x13a7b
movq 0x10(%rsp), %rax
cmpl $0x0, 0x8c(%rax)
jns 0x13a39
jmp 0x13964
cmpl $0x0, 0x18(%rsp)
sete %al
movq 0x10(%rsp), %rcx
movq 0x58(%rcx), %rdi
testq %rdi, %rdi
setne %cl
testb %cl, %al
jne 0x13a7b
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq 0x10(%rsp), %rcx
movq %rax, 0x58(%rcx)
jmp 0x13a7b
movq 0x10(%rsp), %rax
cmpl $0x0, 0x80(%rax)
js 0x13989
xorl %r14d, %r14d
leaq 0xff62(%rip), %r12      # 0x239a5
jmp 0x13344
cmpl $0x0, 0x18(%rsp)
sete %al
movq 0x10(%rsp), %rcx
movq 0x60(%rcx), %rdi
testq %rdi, %rdi
setne %cl
testb %cl, %al
jne 0x13a7b
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3610
movq 0x10(%rsp), %rcx
movq %rax, 0x60(%rcx)
leaq 0xff23(%rip), %r12      # 0x239a5
jmp 0x13816
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x13ac6
leaq 0xffe3(%rip), %rsi      # 0x23a7d
leaq 0x100db(%rip), %rdx     # 0x23b7c
leaq 0x10102(%rip), %r8      # 0x23baa
movl $0x3, %edi
movl $0x171, %ecx            # imm = 0x171
movq %r13, %r9
xorl %eax, %eax
pushq 0x8(%rsp)
pushq %r14
callq 0x1771e
addq $0x10, %rsp
movq %rbx, %rdi
callq 0x3380
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x132c3