// File: /workspace/github_c_makefile_star2_O0/wtarreau[P]httpterm/httpterm.c
// Function: init
void init(int argc, char **argv) {
    int i;
    int arg_mode = 0;	/* MODE_DEBUG, ... */
    char *old_argv = *argv;
    char *tmp;
    char *cfg_pidfile = NULL;

    if (1<<INTBITS != sizeof(int)*8) {
	fprintf(stderr,
		"Error: wrong architecture. Recompile so that sizeof(int)=%d\n",
		(int)(sizeof(int)*8));
	exit(1);
    }

#ifdef HTTPTERM_MEMMAX
    global.rlimit_memmax = HTTPTERM_MEMMAX;
#endif

    /* initialize the libc's localtime structures once for all so that we
     * won't be missing memory if we want to send alerts under OOM conditions.
     */
    tv_now(&now);
    localtime(&now.tv_sec);

    cfg_polling_mechanism = POLL_USE_SELECT;  /* select() is always available */
#if defined(ENABLE_POLL)
    cfg_polling_mechanism |= POLL_USE_POLL;
#endif
#if defined(ENABLE_EPOLL)
    cfg_polling_mechanism |= POLL_USE_EPOLL;
#endif

    pid = getpid();
    progname = *argv;
    while ((tmp = strchr(progname, '/')) != NULL)
	progname = tmp + 1;

    argc--; argv++;
    while (argc > 0) {
	char *flag;

	if (**argv == '-') {
	    flag = *argv+1;

	    /* 1 arg */
	    if (*flag == 'v') {
		display_version();
		exit(0);
	    }
#if defined(ENABLE_EPOLL)
	    else if (*flag == 'd' && flag[1] == 'e')
		cfg_polling_mechanism &= ~POLL_USE_EPOLL;
#endif
#if defined(ENABLE_POLL)
	    else if (*flag == 'd' && flag[1] == 'p')
		cfg_polling_mechanism &= ~POLL_USE_POLL;
#endif
#if defined(ENABLE_SPLICE)
	    else if (*flag == 'd' && flag[1] == 'S')
		global.flags |= GFLAGS_NO_SPLICE;
#endif
	    else if (*flag == 'V')
		arg_mode |= MODE_VERBOSE;
	    else if (*flag == 'd' && flag[1] == 'b')
		arg_mode |= MODE_FOREGROUND;
	    else if (*flag == 'd')
		arg_mode |= MODE_DEBUG;
	    else if (*flag == 'c')
		arg_mode |= MODE_CHECK;
	    else if (*flag == 'D')
		arg_mode |= MODE_DAEMON | MODE_QUIET;
	    else if (*flag == 'q')
		arg_mode |= MODE_QUIET;
	    else { /* >=2 args */
		argv++; argc--;
		if (argc == 0)
		    usage(old_argv);

		switch (*flag) {
		case 'n' : cfg_maxconn = atol(*argv); break;
		case 'm' : global.rlimit_memmax = atol(*argv); break;
		case 'N' : break; // legacy, silently ignore
		case 'f' : cfg_cfgfile = *argv; break;
		case 'p' : cfg_pidfile = *argv; break;
		case 'L' : cmdline_listen = *argv; break;
#if defined(ENABLE_SPLICE)
		case 'P' : pipesize = atol(*argv) * 1024; break;
#endif
		case 'B' : cfg_sndbuf = atoi(*argv); break;
		default: usage(old_argv);
		}
	    }
	}
	else
	    usage(old_argv);
	argv++; argc--;
    }

    global.mode = MODE_STARTING | /* during startup, we want most of the alerts */
		  (arg_mode & (MODE_DAEMON | MODE_FOREGROUND | MODE_VERBOSE
			       | MODE_QUIET | MODE_CHECK | MODE_DEBUG));

    if (!cfg_cfgfile && !cmdline_listen)
	usage(old_argv);

    gethostname(hostname, MAX_HOSTNAME_LEN);

    global.maxsock = 10; /* reserve 10 fds ; will be incremented by socket eaters */
    if (readcfgfile(cfg_cfgfile) < 0) {
	Alert("Error reading configuration file : %s\n", cfg_cfgfile);
	exit(1);
    }

    if (global.mode & MODE_CHECK) {
	qfprintf(stdout, "Configuration file is valid : %s\n", cfg_cfgfile);
	exit(0);
    }

    if (!(global.flags & GFLAGS_SEND_ZERO)) {
	/* fill the common response with human-readable data : 50 bytes per line */
	for (i = 0; i < sizeof(common_response); i++) {
	    if (i % 50 == 49)
		common_response[i] = '\n';
	    else if (i % 10 == 0)
		common_response[i] = '.';
	    else
		common_response[i] = '0' + i % 10;
	}

	/* fill the common chunked response with chunk data */
	for (i = 0; i < sizeof(common_chunk_resp); i++)
	    common_chunk_resp[i] = chunk_pattern[i % CHUNK_LEN];
    }

    random_resp = malloc(random_resp_len);
    for (i = 0; i < random_resp_len; i++)
	random_resp[i] = rand() >> 16;

    if (cfg_maxconn > 0)
	global.maxconn = cfg_maxconn;

    if (cfg_pidfile) {
	if (global.pidfile)
	    free(global.pidfile);
	global.pidfile = strdup(cfg_pidfile);
    }

    if (global.maxconn == 0) { /* try to be optimal */
	struct rlimit limit;

	if (getrlimit(RLIMIT_NOFILE, &limit) == 0) {
	    if (limit.rlim_max == RLIM_INFINITY)
		limit.rlim_max = limit.rlim_cur;

	    if (limit.rlim_max > global.maxsock)
		global.maxconn = limit.rlim_max - global.maxsock;
	}

	if (!global.maxconn)
	    global.maxconn = DEFAULT_MAXCONN;
    }

    global.maxsock += global.maxconn; /* each connection needs one sockets */

    if (arg_mode & (MODE_DEBUG | MODE_FOREGROUND)) {
	/* command line debug mode inhibits configuration mode */
	global.mode &= ~(MODE_DAEMON | MODE_QUIET);
    }
    global.mode |= (arg_mode & (MODE_DAEMON | MODE_FOREGROUND | MODE_QUIET |
				MODE_VERBOSE | MODE_DEBUG));

    if ((global.mode & MODE_DEBUG) && (global.mode & (MODE_DAEMON | MODE_QUIET))) {
	Warning("<debug> mode incompatible with <quiet> and <daemon>. Keeping <debug> only.\n");
	global.mode &= ~(MODE_DAEMON | MODE_QUIET);
    }

    if ((global.nbproc > 1) && !(global.mode & MODE_DAEMON)) {
	if (!(global.mode & (MODE_FOREGROUND | MODE_DEBUG)))
	    Warning("<nbproc> is only meaningful in daemon mode. Setting limit to 1 process.\n");
	global.nbproc = 1;
    }

    if (global.nbproc < 1)
	global.nbproc = 1;

    StaticReadEvent = (fd_set *)calloc(1,
		sizeof(fd_set) *
		(global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE);
    StaticWriteEvent = (fd_set *)calloc(1,
		sizeof(fd_set) *
		(global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE);

    fdtab = (struct fdtab *)calloc(1,
		sizeof(struct fdtab) * (global.maxsock));
    for (i = 0; i < global.maxsock; i++) {
	fdtab[i].state = FD_STCLOSE;
    }

#ifdef ENABLE_SPLICE
    if (!(global.flags & GFLAGS_NO_SPLICE)) {
	struct iovec v = { .iov_base = common_response,
			   .iov_len = sizeof(common_response) };
	int total, ret;

	if (pipe(master_pipe) < 0) {
	    Alert("Failed to create master pipe for splice\n");
	    exit(1);
	}

	fcntl(master_pipe[0], F_SETPIPE_SZ, pipesize * 5 / 4);

	total = ret = 0;
	do {
	    ret = vmsplice(master_pipe[1], &v, 1, SPLICE_F_NONBLOCK);
	    if (ret > 0)
		total += ret;
	} while (ret > 0 && total < pipesize);

	if (total < pipesize) {
	    if (total < 60*1024) {
		/* Older kernels were limited to around 60-61 kB */
		Alert("Failed to vmsplice response buffer after %d bytes, retry with '-dS'\n", total);
		exit(1);
	    } else {
		Warning("Splicing is limited to %d bytes (too old kernel), retry with '-dS'\n", total);
		pipesize = total;
	    }
	}
    }
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
leaq 0x5eb0(%rip), %rdi      # 0x11410
callq 0x8d70
leaq 0x5ea4(%rip), %rdi      # 0x11410
callq 0x2060
movl $0x1, 0x5e09(%rip)      # 0x11384
callq 0x20f0
movl %eax, 0x26fc2(%rip)     # 0x32548
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x5ddc(%rip)      # 0x11370
movq 0x5dd5(%rip), %rdi      # 0x11370
movl $0x2f, %esi
callq 0x2160
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0xb5c0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, 0x5db2(%rip)      # 0x11370
jmp 0xb594
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x4(%rbp)
jle 0xb7b8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0xb795
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x76, %eax
jne 0xb619
callq 0x2cd0
xorl %edi, %edi
callq 0x23e0
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x56, %eax
jne 0xb633
movl -0x18(%rbp), %eax
orl $0x40, %eax
movl %eax, -0x18(%rbp)
jmp 0xb791
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x64, %eax
jne 0xb65c
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x62, %eax
jne 0xb65c
movl -0x18(%rbp), %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, -0x18(%rbp)
jmp 0xb78f
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x64, %eax
jne 0xb676
movl -0x18(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb78d
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x63, %eax
jne 0xb690
movl -0x18(%rbp), %eax
orl $0x20, %eax
movl %eax, -0x18(%rbp)
jmp 0xb78b
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x44, %eax
jne 0xb6aa
movl -0x18(%rbp), %eax
orl $0x18, %eax
movl %eax, -0x18(%rbp)
jmp 0xb789
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x71, %eax
jne 0xb6c4
movl -0x18(%rbp), %eax
orl $0x10, %eax
movl %eax, -0x18(%rbp)
jmp 0xb787
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
jne 0xb6e8
movq -0x20(%rbp), %rdi
callq 0x2d00
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
addl $-0x42, %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x2e, %eax
ja 0xb77c
movq -0x50(%rbp), %rax
leaq 0x19d4(%rip), %rcx      # 0xd0dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2350
movl %eax, 0x5c3d(%rip)      # 0x11360
jmp 0xb785
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2350
movl %eax, 0x5ca1(%rip)      # 0x113d8
jmp 0xb785
jmp 0xb785
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x5c1f(%rip)      # 0x11368
jmp 0xb785
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0xb785
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x5c12(%rip)      # 0x11378
jmp 0xb785
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x23b0
movl %eax, 0x5bea(%rip)      # 0x11364
jmp 0xb785
movq -0x20(%rbp), %rdi
callq 0x2d00
jmp 0xb787
jmp 0xb789
jmp 0xb78b
jmp 0xb78d
jmp 0xb78f
jmp 0xb791
jmp 0xb793
jmp 0xb79e
movq -0x20(%rbp), %rdi
callq 0x2d00
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xb5d5
movl -0x18(%rbp), %eax
andl $0x179, %eax            # imm = 0x179
orl $0x80, %eax
movl %eax, 0x5c11(%rip)      # 0x113dc
cmpq $0x0, 0x5b95(%rip)      # 0x11368
jne 0xb7e8
cmpq $0x0, 0x5b9b(%rip)      # 0x11378
jne 0xb7e8
movq -0x20(%rbp), %rdi
callq 0x2d00
leaq 0x26d61(%rip), %rdi     # 0x32550
movl $0x20, %esi
callq 0x23c0
movl $0xa, 0x5bcd(%rip)      # 0x113d0
movq 0x5b5e(%rip), %rdi      # 0x11368
callq 0xa6c0
cmpl $0x0, %eax
jge 0xb833
movq 0x5b4d(%rip), %rsi      # 0x11368
leaq 0x3524(%rip), %rdi      # 0xed46
movb $0x0, %al
callq 0x2d40
movl $0x1, %edi
callq 0x23e0
movl 0x5ba3(%rip), %eax      # 0x113dc
andl $0x20, %eax
cmpl $0x0, %eax
je 0xb867
movq 0x5788(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
movq 0x5b16(%rip), %rdx      # 0x11368
leaq 0x3514(%rip), %rsi      # 0xed6d
movb $0x0, %al
callq 0x3020
xorl %edi, %edi
callq 0x23e0
movl 0x5b83(%rip), %eax      # 0x113f0
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xb93f
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x10000, %rax          # imm = 0x10000
jae 0xb8f9
movl -0x14(%rbp), %eax
movl $0x32, %ecx
cltd
idivl %ecx
cmpl $0x31, %edx
jne 0xb8ad
movslq -0x14(%rbp), %rcx
leaq 0x15b89(%rip), %rax     # 0x21430
movb $0xa, (%rax,%rcx)
jmp 0xb8ec
movl -0x14(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0xb8ce
movslq -0x14(%rbp), %rcx
leaq 0x15b68(%rip), %rax     # 0x21430
movb $0x2e, (%rax,%rcx)
jmp 0xb8ea
movl -0x14(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
addl $0x30, %edx
movslq -0x14(%rbp), %rcx
leaq 0x15b49(%rip), %rax     # 0x21430
movb %dl, (%rax,%rcx)
jmp 0xb8ec
jmp 0xb8ee
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb880
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x10000, %rax          # imm = 0x10000
jae 0xb93d
movslq -0x14(%rbp), %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
leaq 0x5a27(%rip), %rax      # 0x11348
movb (%rax,%rdx), %dl
movslq -0x14(%rbp), %rcx
leaq 0x5af1(%rip), %rax      # 0x11420
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb900
jmp 0xb93f
movslq 0x59fa(%rip), %rdi      # 0x11340
callq 0x22b0
movq %rax, 0x15ace(%rip)     # 0x21420
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x59de(%rip), %eax      # 0x11340
jge 0xb987
callq 0x2450
sarl $0x10, %eax
movb %al, %dl
movq 0x15aab(%rip), %rax     # 0x21420
movslq -0x14(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb959
cmpl $0x0, 0x59d2(%rip)      # 0x11360
jle 0xb99c
movl 0x59ca(%rip), %eax      # 0x11360
movl %eax, 0x5a30(%rip)      # 0x113cc
cmpq $0x0, -0x30(%rbp)
je 0xb9c9
cmpq $0x0, 0x5a3d(%rip)      # 0x113e8
je 0xb9b9
movq 0x5a34(%rip), %rdi      # 0x113e8
callq 0x2040
movq -0x30(%rbp), %rdi
callq 0x2420
movq %rax, 0x5a1f(%rip)      # 0x113e8
cmpl $0x0, 0x59fc(%rip)      # 0x113cc
jne 0xba2f
movl $0x7, %edi
leaq -0x48(%rbp), %rsi
callq 0x23f0
cmpl $0x0, %eax
jne 0xba1a
cmpq $-0x1, -0x40(%rbp)
jne 0xb9f4
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq 0x59d1(%rip), %rcx      # 0x113d0
cmpq %rcx, %rax
jbe 0xba18
movq -0x40(%rbp), %rax
movslq 0x59c1(%rip), %rcx      # 0x113d0
subq %rcx, %rax
movl %eax, 0x59b4(%rip)      # 0x113cc
jmp 0xba1a
cmpl $0x0, 0x59ab(%rip)      # 0x113cc
jne 0xba2d
movl $0x7d0, 0x599f(%rip)    # imm = 0x7D0
jmp 0xba2f
movl 0x5997(%rip), %eax      # 0x113cc
addl 0x5995(%rip), %eax      # 0x113d0
movl %eax, 0x598f(%rip)      # 0x113d0
movl -0x18(%rbp), %eax
andl $0x101, %eax            # imm = 0x101
cmpl $0x0, %eax
je 0xba5d
movl 0x5988(%rip), %eax      # 0x113dc
andl $-0x19, %eax
movl %eax, 0x597f(%rip)      # 0x113dc
movl -0x18(%rbp), %eax
andl $0x159, %eax            # imm = 0x159
orl 0x5971(%rip), %eax      # 0x113dc
movl %eax, 0x596b(%rip)      # 0x113dc
movl 0x5965(%rip), %eax      # 0x113dc
andl $0x1, %eax
cmpl $0x0, %eax
je 0xbaaa
movl 0x5957(%rip), %eax      # 0x113dc
andl $0x18, %eax
cmpl $0x0, %eax
je 0xbaaa
leaq 0x32fb(%rip), %rdi      # 0xed8f
movb $0x0, %al
callq 0x2eb0
movl 0x593b(%rip), %eax      # 0x113dc
andl $-0x19, %eax
movl %eax, 0x5932(%rip)      # 0x113dc
cmpl $0x1, 0x5917(%rip)      # 0x113c8
jle 0xbae9
movl 0x5923(%rip), %eax      # 0x113dc
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xbae9
movl 0x5915(%rip), %eax      # 0x113dc
andl $0x101, %eax            # imm = 0x101
cmpl $0x0, %eax
jne 0xbadf
leaq 0x3303(%rip), %rdi      # 0xeddb
movb $0x0, %al
callq 0x2eb0
movl $0x1, 0x58df(%rip)      # 0x113c8
cmpl $0x1, 0x58d8(%rip)      # 0x113c8
jge 0xbafc
movl $0x1, 0x58cc(%rip)      # 0x113c8
movl 0x58ce(%rip), %eax      # 0x113d0
addl $0x400, %eax            # imm = 0x400
subl $0x1, %eax
movslq %eax, %rsi
shlq $0x7, %rsi
shrq $0xa, %rsi
movl $0x1, %edi
callq 0x2210
movq %rax, 0x58e2(%rip)      # 0x11408
movl 0x58a4(%rip), %eax      # 0x113d0
addl $0x400, %eax            # imm = 0x400
subl $0x1, %eax
movslq %eax, %rsi
shlq $0x7, %rsi
shrq $0xa, %rsi
movl $0x1, %edi
callq 0x2210
movq %rax, 0x258e0(%rip)     # 0x31430
movslq 0x5879(%rip), %rsi      # 0x113d0
shlq $0x5, %rsi
movl $0x1, %edi
callq 0x2210
movq %rax, 0x5844(%rip)      # 0x113b0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x5854(%rip), %eax      # 0x113d0
jge 0xbba2
movq 0x582b(%rip), %rax      # 0x113b0
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x0, 0x18(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xbb73
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)