// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78b8, %rsp           # imm = 0x78B8
movq %r8, 0x2848(%rsp)
movq %rcx, 0x2840(%rsp)
movq %rdx, 0x2838(%rsp)
movq %rsi, 0x2830(%rsp)
movq %rdi, %r14
movl $0x200, %edi            # imm = 0x200
callq 0x264e0
movq %rax, %rbx
movq %rax, 0x2850(%rsp)
leaq 0x2858(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2ed79
leaq 0x3868(%rsp), %rdi
callq 0x2f978
movl %eax, %ebp
leaq 0x6261a(%rip), %rdi     # 0x92072
callq 0x68f0
movl $0x70747468, %r15d      # imm = 0x70747468
movl (%r12), %ecx
xorl %r15d, %ecx
movzwl 0x4(%r12), %edx
xorl $0x73, %edx
xorl %r12d, %r12d
orl %ecx, %edx
cmovneq %rax, %r12
testl %ebp, %ebp
setne %al
testq %r12, %r12
sete %r13b
orb %al, %r13b
je 0x2fabc
leaq 0x2858(%rsp), %rsi
movl $0x506, %ecx            # imm = 0x506
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movl %ebp, %esi
callq 0x2f85c
testl %eax, %eax
js 0x2fc51
movl %eax, %ebp
xorl %r14d, %r14d
jmp 0x2fb8c
leaq 0x5088(%rsp), %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2ed79
xorl (%rbp), %r15d
movzbl 0x4(%rbp), %eax
orl %r15d, %eax
je 0x2faf5
leaq 0x6259a(%rip), %rdi     # 0x9207d
leaq 0x5088(%rsp), %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x26e94
leaq 0x5088(%rsp), %rsi
movl $0x506, %ecx            # imm = 0x506
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
xorl %esi, %esi
callq 0x2f85c
movl %eax, %ebp
leaq 0x62583(%rip), %rdi     # 0x9209e
callq 0x68f0
leaq 0x5dc67(%rip), %rsi     # 0x8d78e
movq %rax, %rdi
callq 0x21acd
testl %eax, %eax
jne 0x2fb4c
leaq 0x62f8b(%rip), %rsi     # 0x92ac5
movl $0x1, %edi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x427e5
testl %ebp, %ebp
js 0x2fc51
movq %r14, %rdi
callq 0x1feba
movq %rax, %r14
movq %rax, %rdi
movl $0x3b, %esi
callq 0x67c0
testq %rax, %rax
je 0x2fb8c
movq %rax, %r12
leaq 0x6252d(%rip), %rdi     # 0x920a8
movq %rax, %rsi
callq 0x21b23
testl %eax, %eax
je 0x2fb8c
movb $0x0, (%r12)
leaq 0x4078(%rsp), %r15
testb %r13b, %r13b
movq %r14, %rcx
cmovneq %r15, %rcx
leaq 0x6250f(%rip), %rsi     # 0x920b4
movq %rbx, %rdi
movq 0x2830(%rsp), %rdx
movq 0x2838(%rsp), %r8
xorl %eax, %eax
callq 0x26883
movq %r14, %rdi
callq 0x2e0a0
leaq 0x624f1(%rip), %rsi     # 0x920bf
movq %rbx, %rdi
movq 0x2840(%rsp), %rdx
xorl %eax, %eax
callq 0x26883
movl $0x70747468, %eax       # imm = 0x70747468
movl -0x1820(%r15), %ecx
xorl %eax, %ecx
movzbl -0x181c(%r15), %edx
orl %ecx, %edx
jne 0x2fc13
movl $0x3038, %ecx           # imm = 0x3038
xorl 0x4068(%rsp), %ecx
movzbl 0x406a(%rsp), %edx
orw %cx, %dx
je 0x2fc36
xorl 0x2858(%rsp), %eax
movzwl 0x285c(%rsp), %ecx
xorl $0x73, %ecx
orl %eax, %ecx
jne 0x2fc5b
cmpl $0x333434, 0x4068(%rsp) # imm = 0x333434
jne 0x2fc5b
leaq 0x6bd75(%rip), %rsi     # 0x9b9b2
movq %rbx, %rdi
leaq 0x3868(%rsp), %rdx
xorl %eax, %eax
callq 0x26883
jmp 0x2fc7c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2fd54
leaq 0x4068(%rsp), %rcx
leaq 0x62466(%rip), %rsi     # 0x920d0
movq %rbx, %rdi
leaq 0x3868(%rsp), %rdx
xorl %eax, %eax
callq 0x26883
leaq 0x2858(%rsp), %rsi
movl $0x506, %ecx            # imm = 0x506
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x6244e(%rip), %rdi     # 0x920e4
movq %rbx, %rsi
callq 0x2f8e3
testb %r13b, %r13b
jne 0x2fcc5
leaq 0x5088(%rsp), %rsi
movl $0x506, %ecx            # imm = 0x506
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x62421(%rip), %rdi     # 0x920de
movq %rbx, %rsi
callq 0x2f8e3
leaq 0x62426(%rip), %rsi     # 0x920f2
movq %rbx, %rdi
callq 0x2674f
movq 0x5078(%rsp), %rdx
cmpq $-0x1, %rdx
je 0x2fd14
movq 0x5080(%rsp), %rcx
cmpq $-0x1, %rcx
je 0x2fd03
leaq 0x62409(%rip), %rsi     # 0x92100
movq %rbx, %rdi
xorl %eax, %eax
callq 0x26883
jmp 0x2fd14
leaq 0x6240f(%rip), %rsi     # 0x92119
movq %rbx, %rdi
xorl %eax, %eax
callq 0x26883
movq 0x2848(%rsp), %rsi
testq %rsi, %rsi
je 0x2fd29
movq %rbx, %rdi
callq 0x2674f
leaq 0x67fbf(%rip), %rsi     # 0x97cef
movq %rbx, %rdi
callq 0x2674f
movq 0x8(%rbx), %rsi
movslq 0x14(%rbx), %rdx
movl %ebp, %edi
callq 0x23517
leaq 0x2850(%rsp), %rdi
callq 0x2651d
movl %ebp, %eax
addq $0x78b8, %rsp           # imm = 0x78B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq