// File: /workspace/github_c_makefile_star2_O2/wtarreau[P]httpterm/httpterm.c
// Function: readcfgfile
int readcfgfile(char *file) {
    char thisline[256];
    char *line;
    FILE *f = NULL;
    int linenum = 0;
    char *end;
    char *args[MAX_LINE_ARGS];
    int arg;
    int cfgerr = 0;
    int confsect = CFG_NONE;

    struct proxy *curproxy = NULL;
    struct server *newsrv = NULL;

    if (file && (f=fopen(file,"r")) == NULL)
	return -1;

    init_default_instance();

    while (f && fgets(line = thisline, sizeof(thisline), f) != NULL) {
	linenum++;

	end = line + strlen(line);

	/* skip leading spaces */
	while (isspace((int)*line))
	    line++;
	
	arg = 0;
	args[arg] = line;

	while (*line && arg < MAX_LINE_ARGS) {
	    /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
	     * C equivalent value. Other combinations left unchanged (eg: \1).
	     */
	    if (*line == '\\') {
		int skip = 0;
		if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
		    *line = line[1];
		    skip = 1;
		}
		else if (line[1] == 'r') {
		    *line = '\r';
		    skip = 1;
		} 
		else if (line[1] == 'n') {
		    *line = '\n';
		    skip = 1;
		}
		else if (line[1] == 't') {
		    *line = '\t';
		    skip = 1;
		}
		else if (line[1] == 'x') {
		    if ((line + 3 < end ) && ishex(line[2]) && ishex(line[3])) {
			unsigned char hex1, hex2;
			hex1 = toupper(line[2]) - '0';
			hex2 = toupper(line[3]) - '0';
			if (hex1 > 9) hex1 -= 'A' - '9' - 1;
			if (hex2 > 9) hex2 -= 'A' - '9' - 1;
			*line = (hex1<<4) + hex2;
			skip = 3;
		    }
		    else {
			Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
			return -1;
		    }
		}
		if (skip) {
		    memmove(line + 1, line + 1 + skip, end - (line + skip + 1));
		    end -= skip;
		}
		line++;
	    }
	    else if (*line == '#' || *line == '\n' || *line == '\r') {
		/* end of string, end of loop */
		*line = 0;
		break;
	    }
	    else if (isspace((int)*line)) {
		/* a non-escaped space is an argument separator */
		*line++ = 0;
		while (isspace((int)*line))
		    line++;
		args[++arg] = line;
	    }
	    else {
		line++;
	    }
	}

	/* empty line */
	if (!**args)
	    continue;

	/* zero out remaining args */
	while (++arg < MAX_LINE_ARGS) {
	    args[arg] = line;
	}

	if (!strcmp(args[0], "listen") || !strcmp(args[0], "defaults"))  /* new proxy */
	    confsect = CFG_LISTEN;
	else if (!strcmp(args[0], "global"))  /* global config */
	    confsect = CFG_GLOBAL;
	/* else it's a section keyword */

	switch (confsect) {
	case CFG_LISTEN:
	    if (cfg_parse_listen(file, linenum, args) < 0)
		return -1;
	    break;
	case CFG_GLOBAL:
	    if (cfg_parse_global(file, linenum, args) < 0)
		return -1;
	    break;
	default:
	    Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]);
	    return -1;
	}
	    
	    
    }
    if (f)
	fclose(f);

    /* Maybe the user has specified a listener on the command line */
    if (cmdline_listen) {
	const char *name = "command line";
	args[0] = "listen";
	args[1] = "dummy";
	args[2] = "\0";
	if (cfg_parse_listen(name, 0, args) < 0)
	    return -1;

	args[0] = "bind";
	args[1] = cmdline_listen;
	args[2] = "\0";
	if (cfg_parse_listen(name, 0, args) < 0)
	    return -1;

	args[0] = "object";
	args[1] = "name";
	args[2] = "dummy";
	args[3] = "\0";
	if (cfg_parse_listen(name, 0, args) < 0)
	    return -1;

	args[0] = "clitimeout";
	args[1] = "10000";
	args[2] = "\0";
	if (cfg_parse_listen(name, 0, args) < 0)
	    return -1;
    }

    /*
     * Now, check for the integrity of all that we have collected.
     */

    /* will be needed further to delay some tasks */
    tv_now(&now);

    if ((curproxy = proxy) == NULL) {
	Alert("parsing %s : no <listen> line. Nothing to do !\n",
	      file);
	return -1;
    }

    while (curproxy != NULL) {
	if (curproxy->state == PR_STSTOPPED) {
	    curproxy = curproxy->next;
	    continue;
	}

	if (curproxy->listen == NULL) {
	    Alert("parsing %s : listener %s has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n", file, curproxy->id);
	    cfgerr++;
	}

	/* first, we will invert the servers list order */
	newsrv = NULL;
	while (curproxy->srv) {
	    struct server *next;

	    next = curproxy->srv->next;
	    curproxy->srv->next = newsrv;
	    newsrv = curproxy->srv;
	    if (!next)
		break;
	    curproxy->srv = next;
	}

	/* now, newsrv == curproxy->srv */
	if (newsrv) {
	    struct server *srv;
	    int pgcd;
	    int act;

	    /* We will factor the weights to reduce the table,
	     * using Euclide's largest common divisor algorithm
	     */
	    pgcd = newsrv->uweight + 1;
	    for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) {
		int t, w;
		
		w = srv->uweight + 1;
		while (w) {
		    t = pgcd % w;
		    pgcd = w;
		    w = t;
		}
	    }

	    act = 0;
	    for (srv = newsrv; srv; srv = srv->next) {
		srv->eweight = ((srv->uweight + 1) / pgcd) - 1;
		act += srv->eweight + 1;
	    }

	    curproxy->srv_map = (struct server **)calloc(act, sizeof(struct server *));
	    /* recounts servers and their weights */
	    recount_servers(curproxy);
	    recalc_server_map(curproxy);
	}

	if (curproxy->errmsg.msg400 == NULL) {
	    curproxy->errmsg.msg400 = (char *)HTTP_400;
	    curproxy->errmsg.len400 = strlen(HTTP_400);
	}
	if (curproxy->errmsg.msg403 == NULL) {
	    curproxy->errmsg.msg403 = (char *)HTTP_403;
	    curproxy->errmsg.len403 = strlen(HTTP_403);
	}
	if (curproxy->errmsg.msg408 == NULL) {
	    curproxy->errmsg.msg408 = (char *)HTTP_408;
	    curproxy->errmsg.len408 = strlen(HTTP_408);
	}
	if (curproxy->errmsg.msg500 == NULL) {
	    curproxy->errmsg.msg500 = (char *)HTTP_500;
	    curproxy->errmsg.len500 = strlen(HTTP_500);
	}
	if (curproxy->errmsg.msg502 == NULL) {
	    curproxy->errmsg.msg502 = (char *)HTTP_502;
	    curproxy->errmsg.len502 = strlen(HTTP_502);
	}
	if (curproxy->errmsg.msg503 == NULL) {
	    curproxy->errmsg.msg503 = (char *)HTTP_503;
	    curproxy->errmsg.len503 = strlen(HTTP_503);
	}
	if (curproxy->errmsg.msg504 == NULL) {
	    curproxy->errmsg.msg504 = (char *)HTTP_504;
	    curproxy->errmsg.len504 = strlen(HTTP_504);
	}
	curproxy = curproxy->next;
    }
    if (cfgerr > 0) {
	Alert("Errors found in configuration file, aborting.\n");
	return -1;
    }
    else
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
pushq $-0x1
popq %r15
testq %rdi, %rdi
movq %rdi, 0x10(%rsp)
je 0x6e98
leaq 0x3c23(%rip), %rsi      # 0xaaa9
callq 0x2340
movq %rax, %r14
testq %rax, %rax
jne 0x6e9b
jmp 0x7536
xorl %r14d, %r14d
callq 0x63c9
testq %r14, %r14
je 0x7192
movl $0x0, 0xc(%rsp)
leaq 0x170(%rsp), %r12
xorl %ebp, %ebp
movq %r14, 0x20(%rsp)
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x21e0
testq %rax, %rax
je 0x7186
movq %r12, %rdi
callq 0x2130
movq %rax, %r14
callq 0x2420
movq %rax, %r13
movq (%rax), %rcx
leaq 0x16f(%rsp), %rbx
movsbq 0x1(%rbx), %rax
incq %rbx
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x6ef7
incl %ebp
movl %ebp, 0x1c(%rsp)
leaq (%rsp,%r14), %rbp
addq $0x170, %rbp            # imm = 0x170
movq %rbx, 0x30(%rsp)
xorl %r15d, %r15d
testb %al, %al
je 0x70a1
cmpl $0x27, %r15d
jg 0x70a1
cmpb $0x5c, %al
je 0x6f67
movzbl %al, %ecx
cmpl $0x23, %ecx
ja 0x6f53
movl %ecx, %ecx
movabsq $0x800002400, %rdx      # imm = 0x800002400
btq %rcx, %rdx
jb 0x709e
movq (%r13), %rcx
movsbq %al, %rax
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x6f95
incq %rbx
jmp 0x6fb6
leaq 0x1(%rbx), %r14
movb 0x1(%rbx), %al
movzbl %al, %ecx
leal -0x20(%rcx), %edx
cmpl $0x3c, %edx
jbe 0x6fbe
cmpl $0x6e, %ecx
je 0x6fd8
cmpl $0x78, %ecx
je 0x6fe5
cmpl $0x74, %ecx
je 0x6fdc
cmpl $0x72, %ecx
jne 0x7093
movb $0xd, %al
jmp 0x6fde
movb $0x0, (%rbx)
movq (%r13), %rax
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x6f9c
movslq %r15d, %rax
incl %r15d
movq %rbx, 0x38(%rsp,%rax,8)
movq %rbx, %r14
jmp 0x7093
movabsq $0x1000000000000009, %rsi # imm = 0x1000000000000009
btq %rdx, %rsi
pushq $0x1
popq %r12
jb 0x7076
jmp 0x6f79
movb $0xa, %al
jmp 0x6fde
movb $0x9, %al
pushq $0x1
jmp 0x7074
leaq 0x3(%rbx), %rax
cmpq %rbp, %rax
jae 0x7161
movsbq 0x2(%rbx), %rdx
leal -0x3a(%rdx), %ecx
cmpb $-0xb, %cl
ja 0x7010
movl %edx, %ecx
andb $-0x21, %cl
addb $-0x47, %cl
cmpb $-0x6, %cl
jb 0x7161
movsbq (%rax), %r12
leal -0x3a(%r12), %eax
cmpb $-0xb, %al
ja 0x702c
movl %r12d, %eax
andb $-0x21, %al
addb $-0x47, %al
cmpb $-0x6, %al
jb 0x7161
movq %r13, 0x28(%rsp)
movq %rdx, %r13
callq 0x2030
movq (%rax), %rax
movb (%rax,%r13,4), %cl
movq 0x28(%rsp), %r13
movb (%rax,%r12,4), %al
leal -0x30(%rax), %edx
leal -0x3a(%rcx), %esi
addb $-0x37, %al
cmpb $0xa, %dl
movzbl %al, %eax
movzbl %dl, %edx
cmovael %eax, %edx
shlb $0x4, %cl
leal -0x70(%rcx), %eax
cmpb $-0xa, %sil
movzbl %cl, %ecx
movzbl %al, %eax
cmovael %ecx, %eax
addb %dl, %al
pushq $0x3
popq %r12
movb %al, (%rbx)
leaq (%r14,%r12), %rsi
addq %r12, %rbx
notq %rbx
addq %rbp, %rbx
movq %r14, %rdi
movq %rbx, %rdx
callq 0x2300
subq %r12, %rbp
movb (%r14), %al
movq %r14, %rbx
jmp 0x6f1f
movb $0x0, (%rbx)
movq 0x30(%rsp), %rax
cmpb $0x0, (%rax)
movq 0x20(%rsp), %r14
movl 0x1c(%rsp), %ebp
leaq 0x170(%rsp), %r12
je 0x6ec0
movslq %r15d, %rax
pushq $-0x1
popq %r15
cmpq $0x26, %rax
jg 0x70d7
movq %rbx, 0x38(%rsp,%rax,8)
incq %rax
jmp 0x70c7
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
leaq 0x3495(%rip), %rsi      # 0xa57b
callq 0x2200
testl %eax, %eax
je 0x7127
movq %rbx, %rdi
leaq 0x3523(%rip), %rsi      # 0xa61c
callq 0x2200
testl %eax, %eax
je 0x7127
movq %rbx, %rdi
leaq 0x32e0(%rip), %rsi      # 0xa3ec
callq 0x2200
testl %eax, %eax
je 0x713c
cmpl $0x1, 0xc(%rsp)
je 0x713c
cmpl $0x2, 0xc(%rsp)
jne 0x754b
movq 0x10(%rsp), %rdi
movl %ebp, %esi
leaq 0x30(%rsp), %rdx
callq 0x63ff
pushq $0x2
jmp 0x714f
movq 0x10(%rsp), %rdi
movl %ebp, %esi
leaq 0x30(%rsp), %rdx
callq 0x6040
pushq $0x1
popq %rcx
movl %ecx, 0xc(%rsp)
testl %eax, %eax
jns 0x6ec0
jmp 0x7536
movq 0x30(%rsp), %rcx
leaq 0x393e(%rip), %rdi      # 0xaaab
movq 0x10(%rsp), %rsi
movl 0x1c(%rsp), %edx
xorl %eax, %eax
callq 0x29aa
pushq $-0x1
popq %r15
jmp 0x7536
movq %r14, %rdi
callq 0x2110
pushq $-0x1
popq %r15
cmpq $0x0, 0x71ae(%rip)      # 0xe348
je 0x727b
leaq 0x33d4(%rip), %rax      # 0xa57b
leaq 0x30(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x397a(%rip), %r14      # 0xab30
movq %r14, 0x8(%rdx)
leaq 0x1f0f(%rip), %rbx      # 0x90d0
movq %rbx, 0x10(%rdx)
leaq 0x3957(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x63ff
testl %eax, %eax
js 0x7536
leaq 0x3477(%rip), %rax      # 0xa659
leaq 0x30(%rsp), %rdx
movq %rax, (%rdx)
movq 0x7157(%rip), %rax      # 0xe348
movq %rax, 0x8(%rdx)
movq %rbx, 0x10(%rdx)
leaq 0x3923(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x63ff
testl %eax, %eax
js 0x7536
leaq 0x35f9(%rip), %rax      # 0xa80f
leaq 0x30(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x3626(%rip), %rax      # 0xa84b
movq %rax, 0x8(%rdx)
movq %r14, 0x10(%rdx)
movq %rbx, 0x18(%rdx)
leaq 0x38eb(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x63ff
testl %eax, %eax
js 0x7536
leaq 0x34b6(%rip), %rax      # 0xa704
leaq 0x30(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x38d9(%rip), %rax      # 0xab36
movq %rax, 0x8(%rdx)
movq %rbx, 0x10(%rdx)
leaq 0x38b7(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x63ff
testl %eax, %eax
js 0x7536
callq 0x5f46
movq 0x70f1(%rip), %rbx      # 0xe378
testq %rbx, %rbx
je 0x751e
pushq $0x8
popq %r12
pushq $0x1
popq %r14
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x750a
cmpl $0x3, 0x8(%rbx)
jne 0x72af
movq 0x50(%rbx), %rbx
jmp 0x729a
cmpq $0x0, (%rbx)
jne 0x72ce
movq 0x38(%rbx), %rdx
leaq 0x38ac(%rip), %rdi      # 0xab6c
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x29aa
incl %ebp
leaq 0x10(%rbx), %r13
movq 0x10(%rbx), %rax
xorl %esi, %esi
testq %rax, %rax
je 0x72f4
movq %rax, %rcx
movq (%rax), %rax
movq %rsi, (%rcx)
testq %rax, %rax
je 0x72fe
movq %rax, (%r13)
movq %rcx, %rsi
jmp 0x72d8
testq %rsi, %rsi
jne 0x7301
jmp 0x7415
movq %rcx, %rsi
movzbl 0x10(%rsi), %ecx
incl %ecx
movq %rsi, %rdi
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x7333
cmpl $0x1, %ecx
jle 0x7333
movzbl 0x10(%rdi), %r8d
incl %r8d
testl %r8d, %r8d
je 0x730a
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
movl %r8d, %ecx
movl %edx, %r8d
jmp 0x731f
xorl %edi, %edi
testq %rsi, %rsi
je 0x7355
movzbl 0x10(%rsi), %eax
incl %eax
xorl %edx, %edx
divl %ecx
decb %al
movb %al, 0x11(%rsi)
movzbl %al, %eax
addl %eax, %edi
incl %edi
movq (%rsi), %rsi
jmp 0x7335
movl %edi, %edi
movq %r12, %rsi
callq 0x21f0
movq %rax, 0x20(%rbx)
andl $0x0, 0x18(%rbx)
xorl %ecx, %ecx
movl %r14d, %eax
movq %r13, %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x7386
movl %eax, 0x18(%rbx)
movzbl 0x11(%rdx), %esi
addl %esi, %ecx
incl %ecx
incl %eax
jmp 0x736f
movl %ecx, 0x1c(%rbx)
movq %r13, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x739a
andl $0x0, 0x14(%rax)
jmp 0x738c
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %ecx, %esi
xorl %edi, %edi
cmpq %rsi, %rdi
je 0x7412
xorl %r8d, %r8d
movq %r13, %r9
xorl %r10d, %r10d
movq (%r9), %r9
testq %r9, %r9
je 0x73fa
cmpl $0x1, %ecx
je 0x73fa
movzbl 0x11(%r9), %eax
movl 0x14(%r9), %edx
leal (%rax,%rdx), %r11d
addl %edx, %eax
incl %eax
movl %eax, 0x14(%r9)
leal (%rcx,%r11), %eax
incl %eax
xorl %edx, %edx
divl %ecx
testq %r8, %r8
sete %dl
cmpl %r10d, %eax
setg %r11b
orb %dl, %r11b
cmovneq %r9, %r8
cmovnel %eax, %r10d
jmp 0x73b4
testq %r9, %r9
cmovneq %r9, %r8
movq 0x20(%rbx), %rax
movq %r8, (%rax,%rdi,8)
subl %ecx, 0x14(%r8)
incq %rdi
jmp 0x73a6
movl %ecx, 0x28(%rbx)
cmpq $0x0, 0x70(%rbx)
jne 0x742f
movq 0x6ebd(%rip), %rdi      # 0xe2e0
movq %rdi, 0x70(%rbx)
callq 0x2130
movl %eax, 0x78(%rbx)
cmpq $0x0, 0x80(%rbx)
jne 0x7452
movq 0x6ea8(%rip), %rdi      # 0xe2e8
movq %rdi, 0x80(%rbx)
callq 0x2130
movl %eax, 0x88(%rbx)
cmpq $0x0, 0x90(%rbx)
jne 0x7475
movq 0x6e8d(%rip), %rdi      # 0xe2f0
movq %rdi, 0x90(%rbx)
callq 0x2130
movl %eax, 0x98(%rbx)
cmpq $0x0, 0xa0(%rbx)
jne 0x7498
movq 0x6e72(%rip), %rdi      # 0xe2f8
movq %rdi, 0xa0(%rbx)
callq 0x2130
movl %eax, 0xa8(%rbx)
cmpq $0x0, 0xb0(%rbx)
jne 0x74bb
movq 0x6e57(%rip), %rdi      # 0xe300
movq %rdi, 0xb0(%rbx)
callq 0x2130
movl %eax, 0xb8(%rbx)
cmpq $0x0, 0xc0(%rbx)
jne 0x74de
movq 0x6e3c(%rip), %rdi      # 0xe308
movq %rdi, 0xc0(%rbx)
callq 0x2130
movl %eax, 0xc8(%rbx)
cmpq $0x0, 0xd0(%rbx)
jne 0x72a9
movq 0x6e1d(%rip), %rdi      # 0xe310
movq %rdi, 0xd0(%rbx)
callq 0x2130
movl %eax, 0xd8(%rbx)
jmp 0x72a9
testl %ebp, %ebp
jle 0x7533
leaq 0x36df(%rip), %rdi      # 0xabf4
xorl %eax, %eax
callq 0x29aa
jmp 0x7536
leaq 0x3617(%rip), %rdi      # 0xab3c
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x29aa
jmp 0x7536
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3599(%rip), %rdi      # 0xaaeb
movq 0x10(%rsp), %rsi
movl %ebp, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x29aa
jmp 0x7536