// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/https.c
// Function: netConnectHttpsThread
void *netConnectHttpsThread(void *threadParam)
/* use a thread to run socket back to user */
{
/* child */

struct netConnectHttpsParams *params = threadParam;

pthread_detach(params->thread);  // this thread will never join back with it's progenitor

int fd=0;
char *proxyUrl = getenv("https_proxy");
if (params->noProxy)
    proxyUrl = NULL;
char *connectHost;
int connectPort;

BIO *fbio=NULL;  // file descriptor bio
BIO *sbio=NULL;  // ssl bio
SSL_CTX *ctx;
SSL *ssl;

openSslInit();

ctx = SSL_CTX_new(SSLv23_client_method());

fd_set readfds;
fd_set writefds;
int err;
struct timeval tv;


/* TODO checking certificates 

char *certFile = NULL;
char *certPath = NULL;
if (certFile || certPath)
    {
    SSL_CTX_load_verify_locations(ctx,certFile,certPath);
#if (OPENSSL_VERSION_NUMBER < 0x0090600fL)
    SSL_CTX_set_verify_depth(ctx,1);
#endif
    }

// verify paths and mode.

*/



// Don't want any retries since we are non-blocking bio now
// This is available on newer versions of openssl
//SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);

// Support for Http Proxy
struct netParsedUrl pxy;
if (proxyUrl)
    {
    netParseUrl(proxyUrl, &pxy);
    if (!sameString(pxy.protocol, "http"))
	{
	char s[256];	
	safef(s, sizeof s, "Unknown proxy protocol %s in %s. Should be http.", pxy.protocol, proxyUrl);
	xerr(s);
	goto cleanup;
	}
    connectHost = pxy.host;
    connectPort = atoi(pxy.port);
    }
else
    {
    connectHost = params->hostName;
    connectPort = params->port;
    }
fd = netConnect(connectHost,connectPort);
if (fd == -1)
    {
    xerr("netConnect() failed");
    goto cleanup;
    }

if (proxyUrl)
    {
    char *logProxy = getenv("log_proxy");
    if (sameOk(logProxy,"on"))
	verbose(1, "CONNECT %s:%d HTTP/1.0 via %s:%d\n", params->hostName, params->port, connectHost,connectPort);
    struct dyString *dy = newDyString(512);
    dyStringPrintf(dy, "CONNECT %s:%d HTTP/1.0\r\n", params->hostName, params->port);
    setAuthorization(pxy, "Proxy-Authorization", dy);
    dyStringAppend(dy, "\r\n");
    mustWriteFd(fd, dy->string, dy->stringSize);
    dyStringFree(&dy);
    // verify response
    char *newUrl = NULL;
    boolean success = netSkipHttpHeaderLinesWithRedirect(fd, proxyUrl, &newUrl);
    if (!success) 
	{
	xerr("proxy server response failed");
	goto cleanup;
	}
    if (newUrl) /* no redirects */
	{
	xerr("proxy server response should not be a redirect");
	goto cleanup;
	}
    }


fbio=BIO_new_socket(fd,BIO_NOCLOSE);  
// BIO_NOCLOSE because we handle closing fd ourselves.
if (fbio == NULL)
    {
    xerr("BIO_new_socket() failed");
    goto cleanup;
    }
sbio = BIO_new_ssl(ctx, 1);
if (sbio == NULL) 
    {
    xerr("BIO_new_ssl() failed");
    goto cleanup;
    }
sbio = BIO_push(sbio, fbio);
BIO_get_ssl(sbio, &ssl);
if(!ssl) 
    {
    xerr("Can't locate SSL pointer");
    goto cleanup;
    }


/* 
Server Name Indication (SNI)
Required to complete tls ssl negotiation for systems which house multiple domains. (SNI)
This is common when serving HTTPS requests with a wildcard certificate (*.domain.tld).
This line will allow the ssl connection to send the hostname at tls negotiation time.
It tells the remote server which hostname the client is connecting to.
The hostname must not be an IP address.
*/ 
if (!internetIsDottedQuad(params->hostName))
    SSL_set_tlsext_host_name(ssl,params->hostName);

BIO_set_nbio(sbio, 1);     /* non-blocking mode */

while (1) 
    {
    if (BIO_do_handshake(sbio) == 1) 
	{
	break;  /* Connected */
	}
    if (! BIO_should_retry(sbio)) 
	{
	xerr("BIO_do_handshake() failed");
	char s[256];	
	safef(s, sizeof s, "SSL error: %s", ERR_reason_error_string(ERR_get_error()));
	xerr(s);
	goto cleanup;
	}

    fd = BIO_get_fd(sbio, NULL);
    if (fd == -1) 
	{
	xerr("unable to get BIO descriptor");
	goto cleanup;
	}
    FD_ZERO(&readfds);
    FD_ZERO(&writefds);
    if (BIO_should_read(sbio)) 
	{
	FD_SET(fd, &readfds);
	}
    else if (BIO_should_write(sbio)) 
	{
	FD_SET(fd, &writefds);
	}
    else 
	{  /* BIO_should_io_special() */
	FD_SET(fd, &readfds);
	FD_SET(fd, &writefds);
	}
    tv.tv_sec = (long) (DEFAULTCONNECTTIMEOUTMSEC/1000);  // timeout default 10 seconds
    tv.tv_usec = (long) (((DEFAULTCONNECTTIMEOUTMSEC/1000)-tv.tv_sec)*1000000);

    err = select(fd + 1, &readfds, &writefds, NULL, &tv);
    if (err < 0) 
	{
	xerr("select() error");
	goto cleanup;
	}

    if (err == 0) 
	{
	char s[256];	
	safef(s, sizeof s, "connection timeout to %s", params->hostName);
	xerr(s);
	goto cleanup;
	}
    }


/* TODO checking certificates 

if (certFile || certPath)
    if (!check_cert(ssl, host))
	return -1;

*/

/* we need to wait on both the user's socket and the BIO SSL socket 
 * to see if we need to ferry data from one to the other */


char sbuf[32768];  // socket buffer sv[1] to user
char bbuf[32768];  // bio buffer
int srd = 0;
int swt = 0;
int brd = 0;
int bwt = 0;
while (1) 
    {

    // Do NOT move this outside the while loop. 
    /* Get underlying file descriptor, needed for select call */
    fd = BIO_get_fd(sbio, NULL);
    if (fd == -1) 
	{
	xerr("BIO doesn't seem to be initialized in https, unable to get descriptor.");
	goto cleanup;
	}


    FD_ZERO(&readfds);
    FD_ZERO(&writefds);

    if (brd == 0)
	FD_SET(fd, &readfds);
    if (swt < srd)
	FD_SET(fd, &writefds);
    if (srd == 0)
	FD_SET(params->sv[1], &readfds);

    tv.tv_sec = (long) (DEFAULTCONNECTTIMEOUTMSEC/1000);  // timeout default 10 seconds
    tv.tv_usec = (long) (((DEFAULTCONNECTTIMEOUTMSEC/1000)-tv.tv_sec)*1000000);

    err = select(max(fd,params->sv[1]) + 1, &readfds, &writefds, NULL, &tv);

    /* Evaluate select() return code */
    if (err < 0) 
	{
	xerr("error during select()");
	goto cleanup;
	}
    else if (err == 0) 
	{
	/* Timed out - just quit */
	xerr("https timeout expired");
	goto cleanup;
	}

    else 
	{
	if (FD_ISSET(params->sv[1], &readfds))
	    {
	    swt = 0;
	    srd = read(params->sv[1], sbuf, 32768);
	    if (srd == -1)
		{
		if (errno != 104) // udcCache often closes causing "Connection reset by peer"
		    xerrno("error reading user pipe for https socket");
		goto cleanup;
		}
	    if (srd == 0) 
		break;  // user closed socket, we are done
	    }

	if (FD_ISSET(fd, &writefds))
	    {
	    int swtx = BIO_write(sbio, sbuf+swt, srd-swt);
	    if (swtx <= 0)
		{
		if (!BIO_should_write(sbio))
		    {
		    ERR_print_errors_fp(stderr);
		    xerr("Error writing SSL connection");
		    goto cleanup;
		    }
		}
	    else
		{
		swt += swtx;
		if (swt >= srd)
		    {
		    swt = 0;
		    srd = 0;
		    }
		}
	    }

	if (FD_ISSET(fd, &readfds))
	    {
	    bwt = 0;
	    brd = BIO_read(sbio, bbuf, 32768);

	    if (brd <= 0)
		{
		if (BIO_should_read(sbio))
		    {
		    brd = 0;
		    continue;
		    }
		else
		    {
		    if (brd == 0) break;
		    ERR_print_errors_fp(stderr);
		    xerr("Error reading SSL connection");
		    goto cleanup;
		    }
		}
	    // write the https data received immediately back on socket to user, and it's ok if it blocks.
	    while(bwt < brd)
		{
		// NOTE: Intended as a thread-specific library-safe way not to ignore SIG_PIPE for the entire application.
		// temporarily block sigpipe on this thread
		sigset_t sigpipe_mask;
		sigemptyset(&sigpipe_mask);
		sigaddset(&sigpipe_mask, SIGPIPE);
		sigset_t saved_mask;
		if (pthread_sigmask(SIG_BLOCK, &sigpipe_mask, &saved_mask) == -1) {
		    perror("pthread_sigmask");
		    exit(1);
		}
		int bwtx = write(params->sv[1], bbuf+bwt, brd-bwt);
		int saveErrno = errno;
		if ((bwtx == -1) && (saveErrno == EPIPE))
		    { // if there was a EPIPE, accept and consume the SIGPIPE now.
		    int sigErr, sig;
		    if ((sigErr = sigwait(&sigpipe_mask, &sig)) != 0) 
			{
			errno = sigErr;
			perror("sigwait");
			exit(1);
			}
		    }
		// restore signal mask on this thread
		if (pthread_sigmask(SIG_SETMASK, &saved_mask, 0) == -1) 
		    {
		    perror("pthread_sigmask");
		    exit(1);
		    }
		errno = saveErrno;
		if (bwtx == -1)
		    {
		    if ((errno != 104)  // udcCache often closes causing "Connection reset by peer"
		     && (errno !=  32)) // udcCache often closes causing "Broken pipe"
			xerrno("error writing https data back to user pipe");
		    goto cleanup;
		    }
		bwt += bwtx;
		}
	    brd = 0;
	    bwt = 0;
	    }
	}
    }

cleanup:

BIO_free_all(sbio);  // will free entire chain of bios
close(fd);     // Needed because we use BIO_NOCLOSE above. Someday might want to re-use a connection.
close(params->sv[1]);  /* we are done with it */

return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x15328, %rsp          # imm = 0x15328
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x64a0
leaq 0x4303e(%rip), %rdi     # 0x867e5
callq 0x68f0
xorl %r12d, %r12d
cmpl $0x0, 0x14(%rbx)
cmoveq %rax, %r12
callq 0x43733
callq 0x6360
movq %rax, %rdi
callq 0x6a80
movq %rax, %r15
testq %r12, %r12
je 0x43836
leaq 0x2af0(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x29839
leaq 0x3d6a7(%rip), %rsi     # 0x80e92
pushq $0x5
popq %rdx
movq %r14, %rdi
callq 0x6710
testl %eax, %eax
je 0x4383f
leaq 0x42ff0(%rip), %rdx     # 0x867f1
xorl %r15d, %r15d
leaq 0x2970(%rsp), %r14
leaq 0x2af0(%rsp), %rcx
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r12, %r8
xorl %eax, %eax
callq 0x1fab2
movq %r14, %rdi
callq 0x43fe5
xorl %r14d, %r14d
jmp 0x43b86
movq 0x8(%rbx), %r13
movl 0x10(%rbx), %ebp
jmp 0x43856
leaq 0x3b00(%rsp), %r13
leaq 0x4300(%rsp), %rdi
callq 0x6bd0
movl %eax, %ebp
movq %r13, %rdi
movl %ebp, %esi
callq 0x291f8
cmpl $-0x1, %eax
je 0x43968
movl %eax, %r14d
testq %r12, %r12
je 0x4397d
leaq 0x3d722(%rip), %rdi     # 0x80f9e
callq 0x68f0
leaq 0x38f06(%rip), %rsi     # 0x7c78e
movq %rax, %rdi
callq 0x1daf1
testl %eax, %eax
jne 0x438b2
movq 0x8(%rbx), %rdx
movl 0x10(%rbx), %ecx
leaq 0x42f94(%rip), %rsi     # 0x86836
pushq $0x1
popq %rdi
movq %r13, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x3c521
movl $0x200, %edi            # imm = 0x200
callq 0x21bcc
leaq 0x2970(%rsp), %r13
movq %rax, (%r13)
movq 0x8(%rbx), %rdx
movl 0x10(%rbx), %ecx
leaq 0x42f82(%rip), %rsi     # 0x86858
movq %rax, %rdi
xorl %eax, %eax
callq 0x21ec7
movq (%r13), %rax
leaq 0x2af0(%rsp), %rsi
movl $0x506, %ecx            # imm = 0x506
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x3d6e0(%rip), %rdi     # 0x80fde
movq %rax, %rsi
callq 0x2a34c
movq (%r13), %rdi
leaq 0x432de(%rip), %rsi     # 0x86bef
callq 0x21dda
movq (%r13), %rax
movq 0x8(%rax), %rsi
movslq 0x14(%rax), %rdx
movl %r14d, %edi
callq 0x1f108
movq %r13, %rdi
callq 0x21c07
leaq 0x2870(%rsp), %rdx
andq $0x0, (%rdx)
movl %r14d, %edi
movq %r12, %rsi
callq 0x2aebc
testl %eax, %eax
je 0x43b65
cmpq $0x0, 0x2870(%rsp)
je 0x4397d
leaq 0x42f2b(%rip), %rdi     # 0x8688e
jmp 0x43b7e
leaq 0x42eb3(%rip), %rdi     # 0x86822
callq 0x43fe5
pushq $-0x1
popq %r14
jmp 0x43b83
movl %r14d, %edi
xorl %esi, %esi
callq 0x68b0
testq %rax, %rax
je 0x43b6e
movq %rax, %r12
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x60b0
testq %rax, %rax
je 0x43b77
movq %rax, %rdi
movq %r12, %rsi
callq 0x6740
movq %rax, %r15
pushq $0x6e
popq %rsi
leaq 0x2860(%rsp), %r12
movq %rax, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0x61b0
cmpq $0x0, (%r12)
je 0x43bb2
movq 0x8(%rbx), %rdi
callq 0x440fc
testl %eax, %eax
jne 0x439fb
movq 0x2860(%rsp), %rdi
movq 0x8(%rbx), %rcx
pushq $0x37
popq %rsi
xorl %edx, %edx
callq 0x6290
pushq $0x66
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x61b0
pushq $0x65
popq %rbp
pushq $0x8
popq %r12
leaq 0x2850(%rsp), %r13
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x61b0
cmpq $0x1, %rax
je 0x43bbe
movq %r15, %rdi
movl %r12d, %esi
callq 0x6ad0
testl %eax, %eax
je 0x43ebc
movq %r15, %rdi
pushq $0x69
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x61b0
movq %rax, %r14
cmpl $-0x1, %r14d
je 0x43efb
xorl %eax, %eax
cmpq $0x10, %rax
je 0x43a77
andq $0x0, 0x2870(%rsp,%rax,8)
incq %rax
jmp 0x43a63
xorl %eax, %eax
cmpq $0x10, %rax
je 0x43a8d
andq $0x0, 0x28f0(%rsp,%rax,8)
incq %rax
jmp 0x43a79
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x6ad0
testl %eax, %eax
je 0x43ac3
movl %r14d, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %r14d, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
leaq (%rsp,%rdx,8), %rcx
addq $0x2870, %rcx           # imm = 0x2870
jmp 0x43b01
movq %r15, %rdi
pushq $0x2
popq %rsi
callq 0x6ad0
movl %eax, %esi
movl %r14d, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %r14d, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
leaq (%rsp,%rdx,8), %rcx
addq $0x28f0, %rcx           # imm = 0x28F0
testl %esi, %esi
jne 0x43b01
orq %rax, 0x2870(%rsp,%rdx,8)
orq %rax, (%rcx)
movq $0xa, 0x2850(%rsp)
andq $0x0, 0x2858(%rsp)
leal 0x1(%r14), %edi
leaq 0x2870(%rsp), %rsi
leaq 0x28f0(%rsp), %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0x66b0
testl %eax, %eax
js 0x43f10
jne 0x43a1a
movq 0x8(%rbx), %rcx
leaq 0x42e07(%rip), %rdx     # 0x86957
leaq 0x2970(%rsp), %r12
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
jmp 0x43eef
leaq 0x42d05(%rip), %rdi     # 0x86871
jmp 0x43b7e
leaq 0x42d48(%rip), %rdi     # 0x868bd
jmp 0x43b7e
leaq 0x42d57(%rip), %rdi     # 0x868d5
callq 0x43fe5
xorl %r15d, %r15d
movq %r15, %rdi
callq 0x62a0
movl %r14d, %edi
callq 0x6e80
movl 0x1c(%rbx), %edi
callq 0x6e80
xorl %eax, %eax
addq $0x15328, %rsp          # imm = 0x15328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x42d31(%rip), %rdi     # 0x868ea
jmp 0x43f17
movq $0x0, 0x2838(%rsp)
xorl %ebp, %ebp
movq %r15, 0x2848(%rsp)
movq %r15, %rdi
pushq $0x69
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x61b0
movq %rax, %r14
cmpl $-0x1, %r14d
je 0x43f46
xorl %eax, %eax
cmpq $0x10, %rax
je 0x43c06
andq $0x0, 0x2870(%rsp,%rax,8)
incq %rax
jmp 0x43bf2
xorl %eax, %eax
cmpq $0x10, %rax
je 0x43c1c
andq $0x0, 0x28f0(%rsp,%rax,8)
incq %rax
jmp 0x43c08
movl %r14d, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
movslq %eax, %r12
shll $0x6, %eax
movl %r14d, %ecx
subl %eax, %ecx
pushq $0x1
popq %r13
shlq %cl, %r13
orq %r13, 0x2870(%rsp,%r12,8)
movq 0x2838(%rsp), %rax
cmpl %eax, %ebp
jge 0x43c53
orq %r13, 0x28f0(%rsp,%r12,8)
movl 0x1c(%rbx), %edi
testl %eax, %eax
jne 0x43c7a
movl %edi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %edi, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0x2870(%rsp,%rdx,8)
movq $0xa, 0x2850(%rsp)
andq $0x0, 0x2858(%rsp)
cmpl %r14d, %edi
cmovlel %r14d, %edi
incl %edi
leaq 0x2870(%rsp), %rsi
leaq 0x28f0(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x2850(%rsp), %r8
callq 0x66b0
testl %eax, %eax
js 0x43f4f
je 0x43f58
movl 0x1c(%rbx), %edi
movl %edi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
cltq
movq 0x2870(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0x43d0d
movl $0x8000, %edx           # imm = 0x8000
leaq 0xd320(%rsp), %rsi
callq 0x6aa0
testl %eax, %eax
je 0x43b86
xorl %ebp, %ebp
movq %rax, 0x2838(%rsp)
cmpl $-0x1, %eax
je 0x43f61
testq %r13, 0x28f0(%rsp,%r12,8)
je 0x43d8a
movq %r12, 0x2830(%rsp)
movl %ebp, %eax
leaq (%rsp,%rax), %rsi
addq $0xd320, %rsi           # imm = 0xD320
movl %ebp, %r12d
movq 0x2838(%rsp), %rbp
movl %ebp, %edx
subl %r12d, %edx
movq %r15, %rdi
callq 0x67b0
testl %eax, %eax
jle 0x43d6c
addl %r12d, %eax
cmpl %ebp, %eax
movl $0x0, %ecx
cmovgel %ecx, %ebp
movq %rbp, 0x2838(%rsp)
cmovgel %ecx, %eax
movl %eax, %ebp
movq 0x2830(%rsp), %r12
jmp 0x43d8a
movq %r15, %rdi
pushq $0x2
popq %rsi
callq 0x6ad0
testl %eax, %eax
movl %r12d, %ebp
movq 0x2830(%rsp), %r12
je 0x43f80
testq %r13, 0x2870(%rsp,%r12,8)
je 0x43bd4
movq %r15, %rdi
leaq 0x5320(%rsp), %rsi
movl $0x8000, %edx           # imm = 0x8000
callq 0x6840
movl %eax, 0x2830(%rsp)
testl %eax, %eax
jle 0x43e90
movl %ebp, 0x2844(%rsp)
xorl %ebp, %ebp
movl 0x2830(%rsp), %r15d
subl %ebp, %r15d
jle 0x43ea8
leaq 0x2970(%rsp), %r12
movq %r12, %rdi
callq 0x6940
movq %r12, %rdi
pushq $0xd
popq %rsi
callq 0x6ba0
xorl %edi, %edi
movq %r12, %rsi
leaq 0x2a70(%rsp), %rdx
callq 0x61c0
cmpl $-0x1, %eax
je 0x43fc4
movl 0x1c(%rbx), %edi
movslq %ebp, %rax
leaq (%rsp,%rax), %rsi
addq $0x5320, %rsi           # imm = 0x5320
movslq %r15d, %rdx
callq 0x6260
movq %rax, %r12
callq 0x6060
movq %rax, %r13
movl (%rax), %r15d
movl %r12d, %eax
notl %eax
movl %r15d, %ecx
xorl $0x20, %ecx
orl %eax, %ecx
jne 0x43e5f
leaq 0x2970(%rsp), %rdi
leaq 0x286c(%rsp), %rsi
callq 0x6210
testl %eax, %eax
jne 0x43fcd
pushq $0x2
popq %rdi
leaq 0x2a70(%rsp), %rsi
xorl %edx, %edx
callq 0x61c0
cmpl $-0x1, %eax
je 0x43fc4
movl %r15d, (%r13)
cmpl $-0x1, %r12d
je 0x43f21
addl %r12d, %ebp
jmp 0x43dc5
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x6ad0
testl %eax, %eax
jne 0x43bd4
jmp 0x43f9b
movq 0x2848(%rsp), %r15
movl 0x2844(%rsp), %ebp
jmp 0x43bd4
leaq 0x42a40(%rip), %rdi     # 0x86903
callq 0x43fe5
callq 0x69c0
movq %rax, %rdi
callq 0x6e10
leaq 0x42a41(%rip), %rdx     # 0x8691d
leaq 0x2970(%rsp), %r12
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
xorl %eax, %eax
callq 0x1fab2
movq %r12, %rdi
jmp 0x43f17
leaq 0x42a29(%rip), %rdi     # 0x8692b
callq 0x43fe5
pushq $-0x1
popq %r14
jmp 0x43b86
leaq 0x42a31(%rip), %rdi     # 0x86948
callq 0x43fe5
jmp 0x43b86
cmpl $0x20, %r15d
je 0x43f39
cmpl $0x68, %r15d
je 0x43f39
leaq 0x42b2a(%rip), %rdi     # 0x86a5e
callq 0x4400a
movq 0x2848(%rsp), %r15
jmp 0x43b86
leaq 0x42a23(%rip), %rdi     # 0x86970
jmp 0x43f02
leaq 0x42a61(%rip), %rdi     # 0x869b7
jmp 0x43f17
leaq 0x42a6e(%rip), %rdi     # 0x869cd
jmp 0x43f17
callq 0x6060
cmpl $0x68, (%rax)
je 0x43b86
leaq 0x42a6d(%rip), %rdi     # 0x869e3
callq 0x4400a
jmp 0x43b86
movq 0x6f051(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
callq 0x6390
leaq 0x42a76(%rip), %rdi     # 0x86a0c
jmp 0x43f17
cmpl $0x0, 0x2830(%rsp)
je 0x43b86
movq 0x6f028(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
callq 0x6390
leaq 0x42a6a(%rip), %rdi     # 0x86a29
jmp 0x43f17
leaq 0x42a7b(%rip), %rdi     # 0x86a46
jmp 0x43fd8
movl %eax, (%r13)
leaq 0x42a7e(%rip), %rdi     # 0x86a56
callq 0x6590
pushq $0x1
popq %rdi
callq 0x68d0