// File: /workspace/github_c_makefile_star2_O1/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 $0x268, %rsp            # imm = 0x268
movq %rdi, %r12
testq %rdi, %rdi
je 0x7326
leaq 0x379a(%rip), %rsi      # 0xaaa9
movq %r12, %rdi
callq 0x2340
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x732f
jmp 0x7a7a
movq $0x0, 0x8(%rsp)
leaq 0x2711a(%rip), %rdi     # 0x2e450
movl $0xe0, %edx
xorl %esi, %esi
callq 0x21a0
movl 0x5fe8(%rip), %eax      # 0xd330
testl %eax, %eax
jne 0x7352
movl 0x6056(%rip), %eax      # 0xd3a8
testl %eax, %eax
movl $0x40000000, %ecx       # imm = 0x40000000
cmovnel %eax, %ecx
movl %ecx, 0x27136(%rip)     # 0x2e498
cmpq $0x0, 0x8(%rsp)
je 0x76bf
movq $0x0, (%rsp)
leaq 0x160(%rsp), %r14
xorl %ebx, %ebx
movq %r12, 0x10(%rsp)
movl %ebx, 0x1c(%rsp)
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x8(%rsp), %rdx
callq 0x21e0
testq %rax, %rax
je 0x76b0
movq %r14, %rdi
callq 0x2130
movq %rax, %rbx
callq 0x2420
movq %rax, %rbp
movq (%rax), %rax
leaq 0x15f(%rsp), %r13
movsbq 0x1(%r13), %rcx
incq %r13
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x73c2
movq (%rsp), %rax
incl %eax
movq %rax, (%rsp)
movq %r13, 0x20(%rsp)
movb (%r13), %al
testb %al, %al
je 0x75dc
leaq (%rsp,%rbx), %r8
addq $0x160, %r8             # imm = 0x160
xorl %r12d, %r12d
cmpb $0x5c, %al
je 0x7433
movzbl %al, %ecx
cmpl $0x23, %ecx
ja 0x741c
movl %ecx, %ecx
movabsq $0x800002400, %rdx      # imm = 0x800002400
btq %rcx, %rdx
jb 0x75e1
movq (%rbp), %rcx
movsbq %al, %rax
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x746a
incq %r13
jmp 0x757d
movb 0x1(%r13), %dl
movzbl %dl, %esi
movl $0x1, %eax
movb $0x1, %cl
cmpl $0x6d, %esi
jle 0x7492
cmpl $0x73, %esi
jg 0x74bd
cmpl $0x6e, %esi
je 0x7536
movl $0x0, %r14d
cmpl $0x72, %esi
jne 0x7545
movb $0xd, %dl
jmp 0x753c
movb $0x0, (%r13)
movq (%rbp), %rax
movsbq 0x1(%r13), %rcx
incq %r13
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x7473
movslq %r12d, %rax
incl %r12d
movq %r13, 0x28(%rsp,%rax,8)
jmp 0x757d
addl $-0x20, %esi
cmpl $0x3c, %esi
ja 0x7591
movabsq $0x1000000000000009, %rdi # imm = 0x1000000000000009
btq %rsi, %rdi
movl $0x0, %r14d
jb 0x753c
jmp 0x7545
cmpl $0x74, %esi
je 0x753a
movl $0x0, %r14d
cmpl $0x78, %esi
jne 0x7545
leaq 0x3(%r13), %rax
movq %r8, %r14
cmpq %r8, %rax
jae 0x7512
movsbq 0x2(%r13), %rbx
leal -0x3a(%rbx), %ecx
cmpb $-0xb, %cl
ja 0x74f3
movl %ebx, %ecx
andb $-0x21, %cl
addb $-0x47, %cl
cmpb $-0x6, %cl
jb 0x7512
movsbq (%rax), %r15
leal -0x3a(%r15), %eax
cmpb $-0xb, %al
ja 0x7596
movl %r15d, %eax
andb $-0x21, %al
addb $-0x47, %al
cmpb $-0x6, %al
jae 0x7596
movq 0x20(%rsp), %rcx
xorl %r15d, %r15d
leaq 0x358a(%rip), %rdi      # 0xaaab
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x2a00
movq %r14, %r8
jmp 0x7574
movb $0xa, %dl
jmp 0x753c
movb $0x9, %dl
movb %dl, (%r13)
xorl %ecx, %ecx
movq %rax, %r14
leaq 0x1(%r13), %rbx
movb $0x1, %r15b
testb %cl, %cl
jne 0x7571
leaq (%rbx,%r14), %rsi
addq %r14, %r13
notq %r13
addq %r8, %r13
movq %rbx, %rdi
movq %r13, %rdx
movq %r8, %r13
callq 0x2300
movq %r13, %r8
subq %r14, %r8
movq %rbx, %r13
testb %r15b, %r15b
je 0x7a7a
movb (%r13), %al
testb %al, %al
je 0x75e6
cmpl $0x28, %r12d
jl 0x73fa
jmp 0x75e6
xorl %r14d, %r14d
jmp 0x7545
callq 0x2030
movq (%rax), %rax
movb (%rax,%rbx,4), %cl
movb (%rax,%r15,4), %al
leal -0x30(%rax), %edx
leal -0x3a(%rcx), %esi
addb $-0x37, %al
cmpb $0xa, %dl
movzbl %al, %eax
movzbl %dl, %edi
cmovael %eax, %edi
shlb $0x4, %cl
leal -0x70(%rcx), %eax
cmpb $-0xa, %sil
movzbl %cl, %ecx
movzbl %al, %edx
cmovael %ecx, %edx
addb %dil, %dl
movl $0x3, %eax
movq %r14, %r8
jmp 0x753c
xorl %r12d, %r12d
jmp 0x75e6
movb $0x0, (%r13)
movq 0x20(%rsp), %rax
cmpb $0x0, (%rax)
leaq 0x160(%rsp), %r14
je 0x7389
cmpl $0x26, %r12d
jg 0x7616
movslq %r12d, %rax
incq %rax
movq %r13, 0x20(%rsp,%rax,8)
incq %rax
cmpq $0x28, %rax
jne 0x7608
movq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0x2f56(%rip), %rsi      # 0xa57b
callq 0x2200
movl $0x2, %ebx
testl %eax, %eax
movq 0x10(%rsp), %r12
je 0x7668
movq %r13, %rdi
leaq 0x2fda(%rip), %rsi      # 0xa61c
callq 0x2200
testl %eax, %eax
je 0x7668
movq %r13, %rdi
leaq 0x2d97(%rip), %rsi      # 0xa3ec
callq 0x2200
testl %eax, %eax
movl $0x1, %eax
movl 0x1c(%rsp), %ebx
cmovel %eax, %ebx
cmpl $0x1, %ebx
je 0x7689
cmpl $0x2, %ebx
jne 0x7a97
movq %r12, %rdi
movq (%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x680e
jmp 0x769a
movq %r12, %rdi
movq (%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x644d
testl %eax, %eax
js 0x7a7a
cmpq $0x0, 0x8(%rsp)
jne 0x7385
jmp 0x76bf
movq 0x8(%rsp), %rdi
callq 0x2110
movq 0x10(%rsp), %r12
cmpq $0x0, 0x5c81(%rip)      # 0xd348
je 0x77ad
leaq 0x2ea7(%rip), %rax      # 0xa57b
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x344d(%rip), %r14      # 0xab30
movq %r14, 0x8(%rdx)
leaq 0x19e2(%rip), %rbx      # 0x90d0
movq %rbx, 0x10(%rdx)
leaq 0x342a(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x680e
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x7a7f
leaq 0x2f45(%rip), %rax      # 0xa659
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
movq 0x5c25(%rip), %rax      # 0xd348
movq %rax, 0x8(%rdx)
movq %rbx, 0x10(%rdx)
leaq 0x33f1(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x680e
testl %eax, %eax
js 0x7a7f
leaq 0x30c7(%rip), %rax      # 0xa80f
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x30f4(%rip), %rax      # 0xa84b
movq %rax, 0x8(%rdx)
movq %r14, 0x10(%rdx)
movq %rbx, 0x18(%rdx)
leaq 0x33b9(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x680e
testl %eax, %eax
js 0x7a7f
leaq 0x2f84(%rip), %rax      # 0xa704
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x33a7(%rip), %rax      # 0xab36
movq %rax, 0x8(%rdx)
movq %rbx, 0x10(%rdx)
leaq 0x3385(%rip), %rdi      # 0xab23
xorl %esi, %esi
callq 0x680e
testl %eax, %eax
js 0x7a7f
leaq 0x5c4c(%rip), %rdi      # 0xd400
xorl %esi, %esi
callq 0x2190
movq 0x5bb6(%rip), %rbx      # 0xd378
testq %rbx, %rbx
je 0x7a69
leaq 0x339a(%rip), %r14      # 0xab6c
xorl %ebp, %ebp
cmpl $0x3, 0x8(%rbx)
jne 0x77e8
movq 0x50(%rbx), %rbx
testq %rbx, %rbx
jne 0x77d4
jmp 0x7a55
cmpq $0x0, (%rbx)
jne 0x7801
movq 0x38(%rbx), %rdx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x2a00
incl %ebp
leaq 0x10(%rbx), %r15
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x7833
movq (%rcx), %rax
movq $0x0, (%rcx)
testq %rax, %rax
je 0x7835
movq %rcx, %rdx
movq %rax, %rcx
movq (%rax), %rax
movq %rdx, (%rcx)
testq %rax, %rax
jne 0x781d
movq %rcx, (%r15)
jmp 0x7835
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x7960
movb 0x10(%rcx), %al
movzbl %al, %eax
leal 0x1(%rax), %esi
movq (%rcx), %rdi
testq %rdi, %rdi
setne %dl
testb %al, %al
setne %al
andb %dl, %al
cmpb $0x1, %al
jne 0x787a
movzbl 0x10(%rdi), %edx
incl %edx
movl %esi, %eax
movl %edx, %esi
xorl %edx, %edx
divl %esi
testl %edx, %edx
jne 0x7861
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x787a
cmpl $0x1, %esi
jg 0x785b
xorl %edi, %edi
movzbl 0x10(%rcx), %eax
incl %eax
xorl %edx, %edx
divl %esi
decb %al
movb %al, 0x11(%rcx)
movzbl %al, %eax
addl %eax, %edi
incl %edi
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x787c
movl %edi, %edi
movl $0x8, %esi
callq 0x21f0
movq %rax, 0x20(%rbx)
movq $0x0, 0x18(%rbx)
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x78da
xorl %ecx, %ecx
xorl %edx, %edx
movq %rax, %rsi
incl %edx
movzbl 0x11(%rsi), %edi
addl %edi, %ecx
incl %ecx
movq (%rsi), %rsi
testq %rsi, %rsi
jne 0x78c2
movl %edx, 0x18(%rbx)
movl %ecx, 0x1c(%rbx)
movl 0x1c(%rbx), %ecx
testq %rax, %rax
je 0x78ee
movl $0x0, 0x14(%rax)
movq (%rax), %rax
jmp 0x78dd
testl %ecx, %ecx
jle 0x795d
xorl %esi, %esi
xorl %edi, %edi
movq %r15, %r8
xorl %r9d, %r9d
movq (%r8), %r8
testq %r8, %r8
je 0x794a
cmpl $0x1, %ecx
jne 0x790e
movq %r8, %rdi
jmp 0x7945
movzbl 0x11(%r8), %eax
movl 0x14(%r8), %edx
leal (%rax,%rdx), %r10d
addl %edx, %eax
incl %eax
movl %eax, 0x14(%r8)
leal (%rcx,%r10), %eax
incl %eax
xorl %edx, %edx
divl %ecx
testq %rdi, %rdi
sete %dl
cmpl %r9d, %eax
setg %r10b
orb %dl, %r10b
cmovneq %r8, %rdi
cmovnel %eax, %r9d
cmpl $0x1, %ecx
jne 0x78fc
movq 0x20(%rbx), %rax
movq %rdi, (%rax,%rsi,8)
subl %ecx, 0x14(%rdi)
incq %rsi
cmpq %rcx, %rsi
jne 0x78f4
movl %ecx, 0x28(%rbx)
cmpq $0x0, 0x70(%rbx)
jne 0x797a
movq 0x5972(%rip), %rdi      # 0xd2e0
movq %rdi, 0x70(%rbx)
callq 0x2130
movl %eax, 0x78(%rbx)
cmpq $0x0, 0x80(%rbx)
jne 0x799d
movq 0x595d(%rip), %rdi      # 0xd2e8
movq %rdi, 0x80(%rbx)
callq 0x2130
movl %eax, 0x88(%rbx)
cmpq $0x0, 0x90(%rbx)
jne 0x79c0
movq 0x5942(%rip), %rdi      # 0xd2f0
movq %rdi, 0x90(%rbx)
callq 0x2130
movl %eax, 0x98(%rbx)
cmpq $0x0, 0xa0(%rbx)
jne 0x79e3
movq 0x5927(%rip), %rdi      # 0xd2f8
movq %rdi, 0xa0(%rbx)
callq 0x2130
movl %eax, 0xa8(%rbx)
cmpq $0x0, 0xb0(%rbx)
jne 0x7a06
movq 0x590c(%rip), %rdi      # 0xd300
movq %rdi, 0xb0(%rbx)
callq 0x2130
movl %eax, 0xb8(%rbx)
cmpq $0x0, 0xc0(%rbx)
jne 0x7a29
movq 0x58f1(%rip), %rdi      # 0xd308
movq %rdi, 0xc0(%rbx)
callq 0x2130
movl %eax, 0xc8(%rbx)
cmpq $0x0, 0xd0(%rbx)
jne 0x77da
movq 0x58d2(%rip), %rdi      # 0xd310
movq %rdi, 0xd0(%rbx)
callq 0x2130
movl %eax, 0xd8(%rbx)
jmp 0x77da
testl %ebp, %ebp
jle 0x7a93
leaq 0x3194(%rip), %rdi      # 0xabf4
xorl %eax, %eax
callq 0x2a00
jmp 0x7a7a
leaq 0x30cc(%rip), %rdi      # 0xab3c
movq %r12, %rsi
xorl %eax, %eax
callq 0x2a00
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x7a7f
leaq 0x304d(%rip), %rdi      # 0xaaeb
movq %r12, %rsi
movq (%rsp), %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2a00
jmp 0x7a7a