// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/net.c
// Function: netHttpConnect
int netHttpConnect(char *url, char *method, char *protocol, char *agent, char *optionalHeader)
/* Parse URL, connect to associated server on port, and send most of
 * the request to the server.  If specified in the url send user name
 * and password too.  Typically the "method" will be "GET" or "POST"
 * and the agent will be the name of your program or
 * library. optionalHeader may be NULL or contain additional header
 * lines such as cookie info. 
 * Proxy support via hg.conf httpProxy or env var http_proxy
 * Return data socket, or -1 if error.*/
{
struct netParsedUrl npu;
struct netParsedUrl pxy;
struct dyString *dy = newDyString(512);
int sd = -1;
/* Parse the URL and connect. */
netParseUrl(url, &npu);

boolean noProxy = checkNoProxy(npu.host);
char *proxyUrl = getenv("http_proxy");
if (sameString(npu.protocol, "https"))
    proxyUrl = NULL;
if (noProxy)
    proxyUrl = NULL;
if (proxyUrl)
    {
    netParseUrl(proxyUrl, &pxy);
    if (!sameString(pxy.protocol, "http"))
	errAbort("Unknown proxy protocol %s in %s.", pxy.protocol, proxyUrl);
    sd = connectNpu(pxy, url, noProxy);
    char *logProxy = getenv("log_proxy");
    if (sameOk(logProxy,"on"))
	verbose(1, "%s via proxy %s\n", url, proxyUrl);
    }
else
    {
    sd = connectNpu(npu, url, noProxy);
    }
if (sd < 0)
    return -1;

/* Ask remote server for a file. */
char *urlForProxy = NULL;
if (proxyUrl)
    {
    /* trim off the byterange part at the end of url because proxy does not understand it. */
    urlForProxy = cloneString(url);
    char *x = strrchr(urlForProxy, ';');
    if (x && startsWith(";byterange=", x))
	*x = 0;
    }
dyStringPrintf(dy, "%s %s %s\r\n", method, proxyUrl ? urlForProxy : npu.file, protocol);
freeMem(urlForProxy);
dyStringPrintf(dy, "User-Agent: %s\r\n", agent);
/* do not need the 80 since it is the default */
if ((sameString(npu.protocol, "http" ) && sameString("80", npu.port)) ||
    (sameString(npu.protocol, "https") && sameString("443",npu.port)))
    dyStringPrintf(dy, "Host: %s\r\n", npu.host);
else
    dyStringPrintf(dy, "Host: %s:%s\r\n", npu.host, npu.port);
setAuthorization(npu, "Authorization", dy);
if (proxyUrl)
    setAuthorization(pxy, "Proxy-Authorization", dy);
dyStringAppend(dy, "Accept: */*\r\n");
if (npu.byteRangeStart != -1)
    {
    if (npu.byteRangeEnd != -1)
	dyStringPrintf(dy, "Range: bytes=%lld-%lld\r\n"
		       , (long long)npu.byteRangeStart
		       , (long long)npu.byteRangeEnd);
    else
	dyStringPrintf(dy, "Range: bytes=%lld-\r\n"
		       , (long long)npu.byteRangeStart);
    }

if (optionalHeader)
    dyStringAppend(dy, optionalHeader);

/* finish off the header with final blank line */
dyStringAppend(dy, "\r\n");

mustWriteFd(sd, dy->string, dy->stringSize);

/* Clean up and return handle. */
dyStringFree(&dy);
return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x7940, %rsp           # imm = 0x7940
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl $0x200, %edi            # imm = 0x200
callq 0x35020
movq %rax, -0x5098(%rbp)
movl $0xffffffff, -0x509c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
leaq -0x2860(%rbp), %rsi
callq 0x42160
leaq -0x2860(%rbp), %rdi
addq $0x1010, %rdi           # imm = 0x1010
callq 0x43430
movl %eax, -0x50a0(%rbp)
leaq 0x98900(%rip), %rdi     # 0xdbe2a
callq 0x68d0
movq %rax, -0x50a8(%rbp)
leaq -0x2860(%rbp), %rdi
leaq 0x9880b(%rip), %rsi     # 0xdbd4f
callq 0x6a40
cmpl $0x0, %eax
jne 0x43559
movq $0x0, -0x50a8(%rbp)
cmpl $0x0, -0x50a0(%rbp)
je 0x4356d
movq $0x0, -0x50a8(%rbp)
cmpq $0x0, -0x50a8(%rbp)
je 0x4364e
movq -0x50a8(%rbp), %rdi
leaq -0x5090(%rbp), %rsi
callq 0x42160
leaq -0x5090(%rbp), %rdi
leaq 0x987ae(%rip), %rsi     # 0xdbd4a
callq 0x6a40
cmpl $0x0, %eax
je 0x435c2
leaq -0x5090(%rbp), %rsi
movq -0x50a8(%rbp), %rdx
leaq 0x9887a(%rip), %rdi     # 0xdbe35
movb $0x0, %al
callq 0x35d40
movq -0x10(%rbp), %rax
movq %rax, -0x50c8(%rbp)
movl -0x50a0(%rbp), %eax
movl %eax, -0x50cc(%rbp)
movq %rsp, %rdi
movl $0x506, %ecx            # imm = 0x506
leaq -0x5090(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl -0x50cc(%rbp), %esi
movq -0x50c8(%rbp), %rdi
callq 0x43280
movl %eax, -0x509c(%rbp)
leaq 0x9884c(%rip), %rdi     # 0xdbe56
callq 0x68d0
movq %rax, -0x50b0(%rbp)
movq -0x50b0(%rbp), %rdi
leaq 0x94194(%rip), %rsi     # 0xd77b8
callq 0x2d310
cmpl $0x0, %eax
jne 0x4364c
movq -0x10(%rbp), %rdx
movq -0x50a8(%rbp), %rcx
movl $0x1, %edi
leaq 0x99238(%rip), %rsi     # 0xdc87d
movb $0x0, %al
callq 0x60040
jmp 0x4368f
movq -0x10(%rbp), %rax
movq %rax, -0x50d8(%rbp)
movl -0x50a0(%rbp), %eax
movl %eax, -0x50dc(%rbp)
movq %rsp, %rdi
movl $0x506, %ecx            # imm = 0x506
leaq -0x2860(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl -0x50dc(%rbp), %esi
movq -0x50d8(%rbp), %rdi
callq 0x43280
movl %eax, -0x509c(%rbp)
cmpl $0x0, -0x509c(%rbp)
jge 0x436a4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43991
movq $0x0, -0x50b8(%rbp)
cmpq $0x0, -0x50a8(%rbp)
je 0x4370f
movq -0x10(%rbp), %rdi
callq 0x2a450
movq %rax, -0x50b8(%rbp)
movq -0x50b8(%rbp), %rdi
movl $0x3b, %esi
callq 0x67b0
movq %rax, -0x50c0(%rbp)
cmpq $0x0, -0x50c0(%rbp)
je 0x4370d
movq -0x50c0(%rbp), %rsi
leaq 0x98767(%rip), %rdi     # 0xdbe60
callq 0x2d3d0
cmpl $0x0, %eax
je 0x4370d
movq -0x50c0(%rbp), %rax
movb $0x0, (%rax)
jmp 0x4370f
movq -0x5098(%rbp), %rax
movq %rax, -0x50f0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50e8(%rbp)
cmpq $0x0, -0x50a8(%rbp)
je 0x43742
movq -0x50b8(%rbp), %rax
movq %rax, -0x50f8(%rbp)
jmp 0x43756
leaq -0x2860(%rbp), %rax
addq $0x1820, %rax           # imm = 0x1820
movq %rax, -0x50f8(%rbp)
movq -0x50e8(%rbp), %rdx
movq -0x50f0(%rbp), %rdi
movq -0x50f8(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq 0x986f6(%rip), %rsi     # 0xdbe6c
movb $0x0, %al
callq 0x35540
movq -0x50b8(%rbp), %rdi
callq 0x40d40
movq -0x5098(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x986dc(%rip), %rsi     # 0xdbe77
movb $0x0, %al
callq 0x35540
leaq -0x2860(%rbp), %rdi
leaq 0x9859a(%rip), %rsi     # 0xdbd4a
callq 0x6a40
cmpl $0x0, %eax
jne 0x437d9
leaq -0x2860(%rbp), %rsi
addq $0x1810, %rsi           # imm = 0x1810
leaq 0x985a6(%rip), %rdi     # 0xdbd75
callq 0x6a40
cmpl $0x0, %eax
je 0x43810
leaq -0x2860(%rbp), %rdi
leaq 0x98568(%rip), %rsi     # 0xdbd4f
callq 0x6a40
cmpl $0x0, %eax
jne 0x43835
leaq -0x2860(%rbp), %rsi
addq $0x1810, %rsi           # imm = 0x1810
leaq 0x98572(%rip), %rdi     # 0xdbd78
callq 0x6a40
cmpl $0x0, %eax
jne 0x43835
movq -0x5098(%rbp), %rdi
leaq -0x2860(%rbp), %rdx
addq $0x1010, %rdx           # imm = 0x1010
leaq 0xa20ae(%rip), %rsi     # 0xe58da
movb $0x0, %al
callq 0x35540
jmp 0x43866
movq -0x5098(%rbp), %rdi
leaq -0x2860(%rbp), %rdx
addq $0x1010, %rdx           # imm = 0x1010
leaq -0x2860(%rbp), %rcx
addq $0x1810, %rcx           # imm = 0x1810
leaq 0x98629(%rip), %rsi     # 0xdbe88
movb $0x0, %al
callq 0x35540
movq -0x5098(%rbp), %rax
movq %rax, -0x5100(%rbp)
movq %rsp, %rdi
movl $0x506, %ecx            # imm = 0x506
leaq -0x2860(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x5100(%rbp), %rsi
leaq 0x98608(%rip), %rdi     # 0xdbe9c
callq 0x43350
cmpq $0x0, -0x50a8(%rbp)
je 0x438d6
movq -0x5098(%rbp), %rax
movq %rax, -0x5108(%rbp)
movq %rsp, %rdi
movl $0x506, %ecx            # imm = 0x506
leaq -0x5090(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x5108(%rbp), %rsi
leaq 0x985c5(%rip), %rdi     # 0xdbe96
callq 0x43350
movq -0x5098(%rbp), %rdi
leaq 0x985c6(%rip), %rsi     # 0xdbeaa
callq 0x353b0
cmpq $-0x1, -0x40(%rbp)
je 0x43931
cmpq $-0x1, -0x38(%rbp)
je 0x43916
movq -0x5098(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x985ab(%rip), %rsi     # 0xdbeb8
movb $0x0, %al
callq 0x35540
jmp 0x4392f
movq -0x5098(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x985a9(%rip), %rsi     # 0xdbed1
movb $0x0, %al
callq 0x35540
jmp 0x43931
cmpq $0x0, -0x30(%rbp)
je 0x43948
movq -0x5098(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x353b0
movq -0x5098(%rbp), %rdi
leaq 0x9e21e(%rip), %rsi     # 0xe1b74
callq 0x353b0
movl -0x509c(%rbp), %edi
movq -0x5098(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x5098(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x2fe40
leaq -0x5098(%rbp), %rdi
callq 0x35080
movl -0x509c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x7940, %rsp           # imm = 0x7940
popq %rbp
retq
nopl (%rax)