// File: /workspace/github_c_makefile_star2_O2/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, %r15
movl %edi, %r12d
movq (%rsi), %r14
callq 0x5f46
leaq 0x6e79(%rip), %rdi      # 0xe400
callq 0x2070
movl $0x1, 0x6dbe(%rip)      # 0xe354
callq 0x2100
movl %eax, 0x27f97(%rip)     # 0x2f538
movq (%r15), %rdi
pushq $0x2f
popq %rbx
movq %rdi, 0x6d92(%rip)      # 0xe340
movl %ebx, %esi
callq 0x2160
leaq 0x1(%rax), %rdi
testq %rax, %rax
jne 0x75a7
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpl $0x2, %r12d
jl 0x76de
leaq 0x8(%r15), %rdx
movq (%rdx), %rsi
cmpb $0x2d, (%rsi)
jne 0x79c6
leal -0x1(%r12), %eax
movzbl 0x1(%rsi), %ecx
cmpl $0x44, %ecx
je 0x767d
cmpl $0x56, %ecx
je 0x7662
cmpl $0x63, %ecx
je 0x7668
cmpl $0x64, %ecx
je 0x766e
cmpl $0x71, %ecx
je 0x765c
cmpl $0x76, %ecx
je 0x79ce
addl $-0x2, %r12d
je 0x79c6
addq $0x10, %r15
cmpl $0x42, %ecx
je 0x76cb
cmpl $0x4c, %ecx
je 0x76bc
cmpl $0x4e, %ecx
je 0x75c3
cmpl $0x66, %ecx
je 0x7692
cmpl $0x6d, %ecx
je 0x76a1
cmpl $0x70, %ecx
je 0x76b4
cmpl $0x6e, %ecx
jne 0x79c6
movq (%r15), %rdi
callq 0x2320
movl %eax, 0x6cd9(%rip)      # 0xe330
jmp 0x75c3
orl $0x10, %r13d
jmp 0x7687
orl $0x40, %r13d
jmp 0x7687
orl $0x20, %r13d
jmp 0x7687
cmpb $0x62, 0x2(%rsi)
jne 0x7683
orl $0x100, %r13d           # imm = 0x100
jmp 0x7687
orl $0x18, %r13d
jmp 0x7687
orl $0x1, %r13d
movq %rdx, %r15
movl %eax, %r12d
jmp 0x75c3
movq (%r15), %rax
movq %rax, 0x6c9c(%rip)      # 0xe338
jmp 0x75c3
movq (%r15), %rdi
callq 0x2320
movl %eax, 0x6d11(%rip)      # 0xe3c0
jmp 0x75c3
movq (%r15), %rbx
jmp 0x75c3
movq (%r15), %rax
movq %rax, 0x6c82(%rip)      # 0xe348
jmp 0x75c3
movq (%r15), %rdi
callq 0x2380
movl %eax, 0x6c5b(%rip)      # 0xe334
jmp 0x75c3
movl %r13d, %eax
andl $0x179, %eax            # imm = 0x179
orl $0x80, %eax
movl %eax, 0x6cd7(%rip)      # 0xe3c8
movq 0x6c50(%rip), %rax      # 0xe348
orq 0x6c39(%rip), %rax      # 0xe338
je 0x79c6
leaq 0x27e34(%rip), %rdi     # 0x2f540
pushq $0x20
popq %rsi
callq 0x2390
movl $0xa, 0x6c92(%rip)      # 0xe3b0
movq 0x6c13(%rip), %rdi      # 0xe338
callq 0x6e60
testl %eax, %eax
js 0x79da
testb $0x20, 0x6c8f(%rip)     # 0xe3c8
jne 0x79f7
testb $0x1, 0x6c9a(%rip)      # 0xe3e0
jne 0x77e8
movw $0x32, %di
movl $0xffff, %r8d           # imm = 0xFFFF
movw $0xa, %r9w
leaq 0x16cbe(%rip), %r10     # 0x1e420
xorl %ecx, %ecx
movl %ecx, %eax
xorl %edx, %edx
divw %di
movl %eax, %esi
movl %ecx, %eax
xorl %edx, %edx
divw %r9w
cmpq $0x10000, %rcx          # imm = 0x10000
je 0x77b5
imull $0x32, %esi, %esi
addl $0x30, %esi
andl %r8d, %esi
incq %rsi
movb $0xa, %dl
cmpw %cx, %si
je 0x77ac
imull $-0xa, %eax, %edx
andl %r8d, %edx
addw %cx, %dx
je 0x77aa
imull $0xa, %eax, %eax
movb $0x30, %dl
subb %al, %dl
movzbl %dl, %edx
addl %ecx, %edx
jmp 0x77ac
movb $0x2e, %dl
movb %dl, (%rcx,%r10)
incq %rcx
jmp 0x7764
movw $0x3, %si
leaq 0x34ac(%rip), %rdi      # 0xac6c
leaq 0x6c49(%rip), %r8       # 0xe410
xorl %ecx, %ecx
movl %ecx, %eax
xorl %edx, %edx
divw %si
cmpq $0x10000, %rcx          # imm = 0x10000
je 0x77e8
movzwl %dx, %eax
movb (%rax,%rdi), %al
movb %al, (%rcx,%r8)
incq %rcx
jmp 0x77c9
movl $0x10000, %edi          # imm = 0x10000
callq 0x2290
movq %rax, 0x16c17(%rip)     # 0x1e410
xorl %r14d, %r14d
cmpq $0x10000, %r14          # imm = 0x10000
je 0x781d
callq 0x2410
shrl $0x10, %eax
movq 0x16bfc(%rip), %rcx     # 0x1e410
movb %al, (%rcx,%r14)
incq %r14
jmp 0x77fc
movl 0x6b0d(%rip), %eax      # 0xe330
testl %eax, %eax
jle 0x782d
movl %eax, 0x6b7b(%rip)      # 0xe3a8
testq %rbx, %rbx
je 0x784d
movq 0x6b9f(%rip), %rdi      # 0xe3d8
callq 0x2050
movq %rbx, %rdi
callq 0x23e0
movq %rax, 0x6b8b(%rip)      # 0xe3d8
movl 0x6b55(%rip), %eax      # 0xe3a8
testl %eax, %eax
jne 0x78a4
pushq $0x7
popq %rdi
movq %rsp, %rsi
callq 0x23c0
testl %eax, %eax
jne 0x788b
movq 0x8(%rsp), %rax
cmpq $-0x1, %rax
jne 0x7875
movq (%rsp), %rax
movslq 0x6b34(%rip), %rcx      # 0xe3b0
cmpq %rcx, %rax
jbe 0x788b
subl %ecx, %eax
movl %eax, 0x6b1f(%rip)      # 0xe3a8
jmp 0x7891
movl 0x6b17(%rip), %eax      # 0xe3a8
testl %eax, %eax
jne 0x78a4
movl $0x7d0, 0x6b09(%rip)    # imm = 0x7D0
movl $0x7d0, %eax            # imm = 0x7D0
addl %eax, 0x6b06(%rip)      # 0xe3b0
movl 0x6b18(%rip), %eax      # 0xe3c8
movl %eax, %ecx
andl $-0x19, %ecx
testw $0x101, %r13w           # imm = 0x101
cmovel %eax, %ecx
andl $0x159, %r13d           # imm = 0x159
orl %ecx, %r13d
movl %r13d, 0x6af9(%rip)     # 0xe3c8
testb $0x1, %r13b
sete %al
testb $0x18, %r13b
sete %cl
orb %al, %cl
jne 0x7901
leaq 0x3388(%rip), %rdi      # 0xac70
xorl %eax, %eax
callq 0x2adf
movl 0x6ad2(%rip), %r13d     # 0xe3c8
andl $-0x19, %r13d
movl %r13d, 0x6ac7(%rip)     # 0xe3c8
movl 0x6a99(%rip), %eax      # 0xe3a0
cmpl $0x2, %eax
jl 0x792a
testb $0x8, %r13b
jne 0x7939
testw $0x101, %r13w           # imm = 0x101
jne 0x792f
leaq 0x339b(%rip), %rdi      # 0xacbc
xorl %eax, %eax
callq 0x2adf
jmp 0x792f
cmpl $0x1, %eax
je 0x7939
movl $0x1, 0x6a67(%rip)      # 0xe3a0
movslq 0x6a70(%rip), %r15      # 0xe3b0
leaq 0x3ff(%r15), %rax
shrq $0x3, %rax
movabsq $0x3fffffffffffff, %rbx # imm = 0x3FFFFFFFFFFFFF
andq %rax, %rbx
pushq $0x1
popq %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21f0
movq %rax, 0x6a8a(%rip)      # 0xe3f8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21f0
movq %rax, 0x26aa0(%rip)     # 0x2e420
movq %r15, %rsi
shlq $0x5, %rsi
movq %r14, %rdi
callq 0x21f0
movq %rax, 0x69ea(%rip)      # 0xe380
xorl %ecx, %ecx
testl %r15d, %r15d
movl $0x0, %edx
cmovgl %r15d, %edx
shlq $0x5, %rdx
cmpq %rcx, %rdx
je 0x79b8
andl $0x0, 0x18(%rax,%rcx)
addq $0x20, %rcx
jmp 0x79a8
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x297e
callq 0x2964
xorl %edi, %edi
callq 0x23b0
movq 0x6957(%rip), %rsi      # 0xe338
leaq 0x323b(%rip), %rdi      # 0xac23
xorl %eax, %eax
callq 0x29aa
pushq $0x1
popq %rdi
callq 0x23b0
movq 0x65d2(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
movq 0x6930(%rip), %rdx      # 0xe338
leaq 0x323b(%rip), %rsi      # 0xac4a
xorl %eax, %eax
callq 0x2c14
jmp 0x79d3