// File: /workspace/github_c_makefile_star2_O3/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
leaq 0x58f5(%rip), %rbx      # 0xd400
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2190
movq %rbx, %rdi
callq 0x2070
movl $0x1, 0x582d(%rip)      # 0xd354
callq 0x2100
movl %eax, 0x26a06(%rip)     # 0x2e538
movq (%r15), %rdi
movq %rdi, 0x5804(%rip)      # 0xd340
movl $0x2f, %esi
callq 0x2160
leaq 0x1(%rax), %rdi
testq %rax, %rax
jne 0x7b35
cmpl $0x2, %r12d
jl 0x7c71
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x8(%r15), %rsi
cmpb $0x2d, (%rsi)
jne 0x8162
leaq 0x8(%r15), %rdx
leal -0x1(%r12), %eax
movzbl 0x1(%rsi), %ecx
cmpl $0x63, %ecx
jg 0x7b92
cmpl $0x44, %ecx
je 0x7ba2
cmpl $0x56, %ecx
je 0x7bb7
cmpl $0x63, %ecx
jne 0x7bc6
orl $0x20, %r13d
jmp 0x7c00
cmpl $0x64, %ecx
je 0x7ba8
cmpl $0x71, %ecx
jne 0x7bbd
orl $0x10, %r13d
jmp 0x7c00
orl $0x18, %r13d
jmp 0x7c00
cmpb $0x62, 0x2(%rsi)
jne 0x7bfc
orl $0x100, %r13d           # imm = 0x100
jmp 0x7c00
orl $0x40, %r13d
jmp 0x7c00
cmpl $0x76, %ecx
je 0x816a
addl $-0x2, %r12d
je 0x8162
addq $0x10, %r15
cmpl $0x65, %ecx
jle 0x7c12
cmpl $0x6d, %ecx
jg 0x7c26
cmpl $0x66, %ecx
je 0x7c60
cmpl $0x6d, %ecx
jne 0x8162
movq (%r15), %rdi
callq 0x2320
movl %eax, 0x57c6(%rip)      # 0xd3c0
jmp 0x7c06
orl $0x1, %r13d
movq %rdx, %r15
movl %eax, %r12d
cmpl $0x1, %r12d
jg 0x7b5e
jmp 0x7c76
cmpl $0x42, %ecx
je 0x7c50
cmpl $0x4c, %ecx
je 0x7c44
cmpl $0x4e, %ecx
je 0x7c06
jmp 0x8162
cmpl $0x70, %ecx
je 0x7c6c
cmpl $0x6e, %ecx
jne 0x8162
movq (%r15), %rdi
callq 0x2320
movl %eax, 0x56ee(%rip)      # 0xd330
jmp 0x7c06
movq (%r15), %rax
movq %rax, 0x56fa(%rip)      # 0xd348
jmp 0x7c06
movq (%r15), %rdi
callq 0x2380
movl %eax, 0x56d6(%rip)      # 0xd334
jmp 0x7c06
movq (%r15), %rax
movq %rax, 0x56ce(%rip)      # 0xd338
jmp 0x7c06
movq (%r15), %rbx
jmp 0x7c06
xorl %r13d, %r13d
xorl %ebx, %ebx
movl %r13d, %eax
andl $0x179, %eax            # imm = 0x179
orl $0x80, %eax
movl %eax, 0x573f(%rip)      # 0xd3c8
movq 0x56b8(%rip), %rax      # 0xd348
orq 0x56a1(%rip), %rax      # 0xd338
je 0x8162
leaq 0x2689c(%rip), %rdi     # 0x2e540
movl $0x20, %esi
callq 0x2390
movl $0xa, 0x56f8(%rip)      # 0xd3b0
movq 0x5679(%rip), %rdi      # 0xd338
callq 0x72b9
testl %eax, %eax
js 0x8171
testb $0x20, 0x56f5(%rip)     # 0xd3c8
jne 0x8190
testb $0x1, 0x5700(%rip)      # 0xd3e0
jne 0x7e96
movdqa 0x1352(%rip), %xmm0     # 0x9040
movdqa 0x135a(%rip), %xmm1     # 0x9050
xorl %eax, %eax
movdqa 0x1360(%rip), %xmm2     # 0x9060
movdqa 0x1368(%rip), %xmm3     # 0x9070
movdqa 0x1370(%rip), %xmm4     # 0x9080
pxor %xmm5, %xmm5
movdqa 0x1374(%rip), %xmm6     # 0x9090
movdqa 0x137c(%rip), %xmm7     # 0x90a0
movdqa 0x1383(%rip), %xmm8     # 0x90b0
movdqa 0x138a(%rip), %xmm9     # 0x90c0
movdqa 0x1391(%rip), %xmm10    # 0x90d0
leaq 0x156da(%rip), %rcx     # 0x1d420
movdqa 0x1391(%rip), %xmm11    # 0x90e0
movdqa %xmm1, %xmm12
psubw %xmm2, %xmm12
pmullw %xmm3, %xmm12
movdqa %xmm12, %xmm13
psrlw $0x1, %xmm13
psllw $0xf, %xmm12
por %xmm13, %xmm12
psubusw %xmm4, %xmm12
pcmpeqw %xmm5, %xmm12
movdqa %xmm0, %xmm13
psubw %xmm2, %xmm13
pmullw %xmm3, %xmm13
movdqa %xmm13, %xmm14
psrlw $0x1, %xmm14
psllw $0xf, %xmm13
por %xmm14, %xmm13
psubusw %xmm4, %xmm13
pcmpeqw %xmm5, %xmm13
packsswb %xmm13, %xmm12
movdqa %xmm0, %xmm13
pmulhuw %xmm6, %xmm13
psrlw $0x3, %xmm13
pmullw %xmm7, %xmm13
movdqa %xmm0, %xmm14
psubw %xmm13, %xmm14
movdqa %xmm1, %xmm13
pmulhuw %xmm6, %xmm13
psrlw $0x3, %xmm13
pmullw %xmm7, %xmm13
movdqa %xmm1, %xmm15
psubw %xmm13, %xmm15
movdqa %xmm15, %xmm13
pcmpeqw %xmm5, %xmm13
packuswb %xmm14, %xmm15
pcmpeqw %xmm5, %xmm14
packsswb %xmm14, %xmm13
por %xmm8, %xmm15
movdqa %xmm13, %xmm14
pandn %xmm15, %xmm14
pand %xmm9, %xmm13
por %xmm14, %xmm13
movdqa %xmm12, %xmm14
pandn %xmm13, %xmm14
pand %xmm10, %xmm12
por %xmm14, %xmm12
movdqa %xmm12, (%rax,%rcx)
addq $0x10, %rax
paddw %xmm11, %xmm1
paddw %xmm11, %xmm0
cmpq $0x10000, %rax          # imm = 0x10000
jne 0x7d4f
leaq 0x2eff(%rip), %rsi      # 0xad5c
xorl %ecx, %ecx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x55a0(%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 0x7e70
movl $0x10000, %edi          # imm = 0x10000
callq 0x2290
movq %rax, 0x15569(%rip)     # 0x1d410
xorl %r14d, %r14d
callq 0x2410
shrl $0x10, %eax
movq 0x15557(%rip), %rcx     # 0x1d410
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x10000, %r14          # imm = 0x10000
jne 0x7eaa
movl 0x5461(%rip), %eax      # 0xd330
testl %eax, %eax
jle 0x7ed9
movl %eax, 0x54cf(%rip)      # 0xd3a8
testq %rbx, %rbx
je 0x7efe
movq 0x54f3(%rip), %rdi      # 0xd3d8
testq %rdi, %rdi
je 0x7eef
callq 0x2050
movq %rbx, %rdi
callq 0x23e0
movq %rax, 0x54da(%rip)      # 0xd3d8
movl 0x54a4(%rip), %eax      # 0xd3a8
testl %eax, %eax
jne 0x7f57
movq %rsp, %rsi
movl $0x7, %edi
callq 0x23c0
testl %eax, %eax
jne 0x7f3e
movq 0x8(%rsp), %rax
cmpq $-0x1, %rax
jne 0x7f28
movq (%rsp), %rax
movslq 0x5481(%rip), %rcx      # 0xd3b0
cmpq %rcx, %rax
jbe 0x7f3e
subl %ecx, %eax
movl %eax, 0x546c(%rip)      # 0xd3a8
jmp 0x7f44
movl 0x5464(%rip), %eax      # 0xd3a8
testl %eax, %eax
jne 0x7f57
movl $0x7d0, 0x5456(%rip)    # imm = 0x7D0
movl $0x7d0, %eax            # imm = 0x7D0
addl %eax, 0x5453(%rip)      # 0xd3b0
movl 0x5465(%rip), %eax      # 0xd3c8
movl %eax, %ecx
andl $-0x19, %ecx
testl $0x101, %r13d           # imm = 0x101
cmovel %eax, %ecx
andl $0x159, %r13d           # imm = 0x159
orl %ecx, %r13d
movl %r13d, 0x5445(%rip)     # 0xd3c8
testb $0x1, %r13b
sete %al
testb $0x18, %r13b
sete %cl
orb %al, %cl
jne 0x7fb5
leaq 0x2dc4(%rip), %rdi      # 0xad60
xorl %eax, %eax
callq 0x2b2f
movl 0x541e(%rip), %r13d     # 0xd3c8
andl $-0x19, %r13d
movl %r13d, 0x5413(%rip)     # 0xd3c8
movl 0x53e5(%rip), %eax      # 0xd3a0
cmpl $0x2, %eax
jl 0x7fdf
testb $0x8, %r13b
jne 0x7fee
testl $0x101, %r13d           # imm = 0x101
jne 0x7fe4
leaq 0x2dd6(%rip), %rdi      # 0xadac
xorl %eax, %eax
callq 0x2b2f
jmp 0x7fe4
cmpl $0x1, %eax
je 0x7fee
movl $0x1, 0x53b2(%rip)      # 0xd3a0
movslq 0x53bb(%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, 0x53d7(%rip)      # 0xd3f8
movl $0x1, %edi
movq %rbx, %rsi
callq 0x21f0
movq %rax, 0x253eb(%rip)     # 0x2d420
movq %r14, %rsi
shlq $0x5, %rsi
movl $0x1, %edi
callq 0x21f0
movq %rax, 0x5333(%rip)      # 0xd380
testq %r14, %r14
jle 0x8154
leal 0x3(%r14), %ecx
decq %r14
movq %r14, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ecx
shlq $0x7, %rcx
movdqa 0x107a(%rip), %xmm1     # 0x90f0
movdqa 0xfa2(%rip), %xmm2      # 0x9020
xorl %edx, %edx
movdqa 0xfa8(%rip), %xmm3      # 0x9030
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x1068(%rip), %xmm5     # 0x9100
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x80d5
movl $0x0, 0x18(%rax,%rdx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x80ec
movl $0x0, 0x38(%rax,%rdx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0x812c
movl $0x0, 0x58(%rax,%rdx)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x813f
movl $0x0, 0x78(%rax,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
subq $-0x80, %rdx
cmpq %rdx, %rcx
jne 0x8098
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x29cc
callq 0x29b2
jmp 0x81af
movq 0x51c0(%rip), %rsi      # 0xd338
leaq 0x2b94(%rip), %rdi      # 0xad13
xorl %eax, %eax
callq 0x29fa
movl $0x1, %edi
callq 0x23b0
movq 0x4e39(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movq 0x5197(%rip), %rdx      # 0xd338
leaq 0x2b92(%rip), %rsi      # 0xad3a
xorl %eax, %eax
callq 0x2c64
xorl %edi, %edi
callq 0x23b0