// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r12
movl %edi, %r15d
movq (%rsi), %r14
leaq 0x5932(%rip), %rbx      # 0xd400
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2190
movq %rbx, %rdi
callq 0x2070
movl $0x1, 0x586a(%rip)      # 0xd354
callq 0x2100
movl %eax, 0x26a43(%rip)     # 0x2e538
movq (%r12), %rdi
movq %rdi, 0x5840(%rip)      # 0xd340
movl $0x2f, %esi
callq 0x2160
leaq 0x1(%rax), %rdi
testq %rax, %rax
jne 0x7af9
cmpl $0x2, %r15d
jl 0x7c85
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x8(%r12), %rdx
cmpb $0x2d, (%rdx)
jne 0x7f83
leaq 0x8(%r12), %rax
leal -0x1(%r15), %ecx
movzbl 0x1(%rdx), %esi
cmpl $0x63, %esi
jg 0x7b5e
cmpl $0x44, %esi
je 0x7be5
cmpl $0x56, %esi
je 0x7b83
cmpl $0x63, %esi
jne 0x7b95
orl $0x20, %r13d
jmp 0x7c74
cmpl $0x64, %esi
je 0x7b71
cmpl $0x71, %esi
jne 0x7b8c
orl $0x10, %r13d
jmp 0x7c74
cmpb $0x62, 0x2(%rdx)
jne 0x7bd7
orl $0x100, %r13d           # imm = 0x100
jmp 0x7c74
orl $0x40, %r13d
jmp 0x7c74
cmpl $0x76, %esi
je 0x7f8b
addl $-0x2, %r15d
je 0x7f83
addq $0x10, %r12
movzbl 0x1(%rdx), %edx
cmpl $0x65, %edx
jle 0x7bee
cmpl $0x6d, %edx
jg 0x7c08
cmpl $0x66, %edx
je 0x7c5d
cmpl $0x6d, %edx
jne 0x7f83
movq (%r12), %rdi
callq 0x2320
movl %eax, 0x57ee(%rip)      # 0xd3c0
jmp 0x7c6e
cmpl $0x63, %esi
jg 0x7c27
cmpl $0x44, %esi
jne 0x7b50
orl $0x18, %r13d
jmp 0x7c74
cmpl $0x42, %edx
je 0x7c4c
cmpl $0x4c, %edx
je 0x7c3f
movq %r12, %rax
movl %r15d, %ecx
cmpl $0x4e, %edx
je 0x7c74
jmp 0x7f83
cmpl $0x70, %edx
je 0x7c6a
cmpl $0x6e, %edx
jne 0x7f83
movq (%r12), %rdi
callq 0x2320
movl %eax, 0x570b(%rip)      # 0xd330
jmp 0x7c6e
cmpl $0x71, %esi
je 0x7b68
cmpl $0x64, %esi
jne 0x7b95
orl $0x1, %r13d
jmp 0x7c74
movq (%r12), %rax
movq %rax, 0x56fe(%rip)      # 0xd348
jmp 0x7c6e
movq (%r12), %rdi
callq 0x2380
movl %eax, 0x56d9(%rip)      # 0xd334
jmp 0x7c6e
movq (%r12), %rax
movq %rax, 0x56d0(%rip)      # 0xd338
jmp 0x7c6e
movq (%r12), %rbx
movq %r12, %rax
movl %r15d, %ecx
movl %ecx, %r15d
movq %rax, %r12
cmpl $0x1, %ecx
jg 0x7b22
jmp 0x7c8a
xorl %r13d, %r13d
xorl %ebx, %ebx
movl %r13d, %eax
andl $0x179, %eax            # imm = 0x179
orl $0x80, %eax
movl %eax, 0x572b(%rip)      # 0xd3c8
movq 0x56a4(%rip), %rax      # 0xd348
orq 0x568d(%rip), %rax      # 0xd338
je 0x7f83
leaq 0x26888(%rip), %rdi     # 0x2e540
movl $0x20, %esi
callq 0x2390
movl $0xa, 0x56e4(%rip)      # 0xd3b0
movq 0x5665(%rip), %rdi      # 0xd338
callq 0x72ef
testl %eax, %eax
js 0x7f92
testb $0x20, 0x56e1(%rip)     # 0xd3c8
jne 0x7fb1
testb $0x1, 0x56ec(%rip)      # 0xd3e0
jne 0x7d9f
xorl %ecx, %ecx
movabsq $-0x5c28f5c28f5c28f5, %rsi # imm = 0xA3D70A3D70A3D70B
movl $0xcccccccd, %edi       # imm = 0xCCCCCCCD
leaq 0x1570e(%rip), %r8      # 0x1d420
movq %rcx, %rax
shrq %rax
mulq %rsi
shrq $0x4, %rdx
imull $0x32, %edx, %edx
addl $0x31, %edx
movb $0xa, %al
cmpl %ecx, %edx
je 0x7d4f
movl %ecx, %eax
imulq %rdi, %rax
shrq $0x23, %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
movl %eax, %edx
negl %edx
addl %ecx, %edx
je 0x7d4d
movb $0x30, %dl
subb %al, %dl
movzbl %dl, %eax
addl %ecx, %eax
jmp 0x7d4f
movb $0x2e, %al
movb %al, (%rcx,%r8)
incq %rcx
cmpq $0x10000, %rcx          # imm = 0x10000
jne 0x7d12
leaq 0x2f06(%rip), %rsi      # 0xac6c
xorl %ecx, %ecx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x5697(%rip), %r8       # 0xd410
movq %rcx, %rax
mulq %rdi
shrq %rdx
leaq (%rdx,%rdx,2), %rax
negq %rax
movb (%rsi,%rax), %al
movb %al, (%rcx,%r8)
incq %rcx
incq %rsi
cmpq $0x10000, %rcx          # imm = 0x10000
jne 0x7d79
movl $0x10000, %edi          # imm = 0x10000
callq 0x2290
movq %rax, 0x15660(%rip)     # 0x1d410
xorl %r14d, %r14d
callq 0x2410
shrl $0x10, %eax
movq 0x1564e(%rip), %rcx     # 0x1d410
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x10000, %r14          # imm = 0x10000
jne 0x7db3
movl 0x5558(%rip), %eax      # 0xd330
testl %eax, %eax
jle 0x7de2
movl %eax, 0x55c6(%rip)      # 0xd3a8
testq %rbx, %rbx
je 0x7e07
movq 0x55ea(%rip), %rdi      # 0xd3d8
testq %rdi, %rdi
je 0x7df8
callq 0x2050
movq %rbx, %rdi
callq 0x23e0
movq %rax, 0x55d1(%rip)      # 0xd3d8
cmpl $0x0, 0x559a(%rip)      # 0xd3a8
jne 0x7e5e
movq %rsp, %rsi
movl $0x7, %edi
callq 0x23c0
testl %eax, %eax
jne 0x7e4b
cmpq $-0x1, 0x8(%rsp)
jne 0x7e32
movq (%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movslq 0x5572(%rip), %rcx      # 0xd3b0
cmpq %rcx, %rax
jbe 0x7e4b
subl %ecx, %eax
movl %eax, 0x555d(%rip)      # 0xd3a8
cmpl $0x0, 0x5556(%rip)      # 0xd3a8
jne 0x7e5e
movl $0x7d0, 0x554a(%rip)    # imm = 0x7D0
movl 0x5544(%rip), %eax      # 0xd3a8
addl %eax, 0x5546(%rip)      # 0xd3b0
testl $0x101, %r13d           # imm = 0x101
je 0x7e7a
andb $-0x19, 0x554e(%rip)    # 0xd3c8
andl $0x159, %r13d           # imm = 0x159
orl 0x5540(%rip), %r13d     # 0xd3c8
movl %r13d, 0x5539(%rip)     # 0xd3c8
testb $0x1, %r13b
sete %al
testb $0x18, %r13b
sete %cl
orb %al, %cl
jne 0x7eb6
leaq 0x2dc8(%rip), %rdi      # 0xac70
xorl %eax, %eax
callq 0x2b35
andb $-0x19, 0x5512(%rip)    # 0xd3c8
cmpl $0x2, 0x54e3(%rip)      # 0xd3a0
jl 0x7ee8
movl 0x5503(%rip), %eax      # 0xd3c8
testb $0x8, %al
jne 0x7ee8
testl $0x101, %eax            # imm = 0x101
jne 0x7ede
leaq 0x2de5(%rip), %rdi      # 0xacbc
xorl %eax, %eax
callq 0x2b35
movl $0x1, 0x54b8(%rip)      # 0xd3a0
cmpl $0x0, 0x54b1(%rip)      # 0xd3a0
jg 0x7efb
movl $0x1, 0x54a5(%rip)      # 0xd3a0
movslq 0x54ae(%rip), %r14      # 0xd3b0
leaq 0x3ff(%r14), %rax
shrq $0x3, %rax
movabsq $0x3fffffffffffff, %rbx # imm = 0x3FFFFFFFFFFFFF
andq %rax, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x21f0
movq %rax, 0x54ca(%rip)      # 0xd3f8
movl $0x1, %edi
movq %rbx, %rsi
callq 0x21f0
movq %rax, 0x254de(%rip)     # 0x2d420
movq %r14, %rbx
shlq $0x5, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x21f0
movq %rax, 0x5423(%rip)      # 0xd380
testq %r14, %r14
jle 0x7f75
xorl %ecx, %ecx
movl $0x0, 0x18(%rax,%rcx)
addq $0x20, %rcx
cmpq %rcx, %rbx
jne 0x7f64
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x29d2
callq 0x29b8
jmp 0x7fd0
movq 0x539f(%rip), %rsi      # 0xd338
leaq 0x2c83(%rip), %rdi      # 0xac23
xorl %eax, %eax
callq 0x2a00
movl $0x1, %edi
callq 0x23b0
movq 0x5018(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movq 0x5376(%rip), %rdx      # 0xd338
leaq 0x2c81(%rip), %rsi      # 0xac4a
xorl %eax, %eax
callq 0x2c6a
xorl %edi, %edi
callq 0x23b0