// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/net.c
// Function: netParseUrl
void netParseUrl(char *url, struct netParsedUrl *parsed)
/* Parse a URL into components.   A full URL is made up as so:
 *   http://user:password@hostName:port/file;byterange=0-499
 * User and password may be cgi-encoded.
 * This is set up so that the http:// and the port are optional. 
 */
{
char *s, *t, *u, *v, *w;
char buf[MAXURLSIZE];

/* Make local copy of URL. */
if (strlen(url) >= sizeof(buf))
    errAbort("Url too long: '%s'", url);
strcpy(buf, url);
url = buf;

/* Find out protocol - default to http. */
s = trimSpaces(url);
s = stringIn("://", url);
if (s == NULL)
    {
    strcpy(parsed->protocol, "http");
    s = url;
    }
else
    {
    *s = 0;
    tolowers(url);
    safecpy(parsed->protocol, sizeof(parsed->protocol), url);
    s += 3;
    }

/* Split off file part. */
parsed->byteRangeStart = -1;  /* default to no byte range specified */
parsed->byteRangeEnd = -1;
u = strchr(s, '/');
if (u == NULL)
    strcpy(parsed->file, "/");
else
    {

    parseByteRange(u, &parsed->byteRangeStart, &parsed->byteRangeEnd, TRUE);

    if (sameWord(parsed->protocol,"http") ||
        sameWord(parsed->protocol,"https"))
	{
	// http servers expect the URL request to be URL-encoded already.
	/* need to encode spaces, but not ! other characters */
	char *t=replaceChars(u," ","%20");
	safecpy(parsed->file, sizeof(parsed->file), t);
	freeMem(t);
	}

    *u = 0; // terminate the host:port string

    if (sameWord(parsed->protocol,"ftp"))
	{
	++u; // that first slash is not considered part of the ftp path 
	// decode now because the FTP server does NOT expect URL-encoding.
	cgiDecodeFull(u,parsed->file,strlen(u));  // decodes %FF but not +
	}

    }

/* Split off user part */
v = strchr(s, '@');
if (v == NULL)
    {
    if (sameWord(parsed->protocol,"http") ||
        sameWord(parsed->protocol,"https"))
	{
	strcpy(parsed->user, "");
	strcpy(parsed->password, "");
	}
    if (sameWord(parsed->protocol,"ftp"))
	{
	strcpy(parsed->user, "anonymous");
	strcpy(parsed->password, "x@genome.ucsc.edu");
	}
    }
else
    {
    *v = 0;
    /* split off password part */
    w = strchr(s, ':');
    if (w == NULL)
	{
	safecpy(parsed->user, sizeof(parsed->user), s);
	strcpy(parsed->password, "");
	}
    else
	{
	*w = 0;
	safecpy(parsed->user, sizeof(parsed->user), s);
	safecpy(parsed->password, sizeof(parsed->password), w+1);
	}
    
    cgiDecode(parsed->user,parsed->user,strlen(parsed->user));
    cgiDecode(parsed->password,parsed->password,strlen(parsed->password));
    s = v+1;
    }


/* Save port if it's there.  If not default to 80. */
t = strchr(s, ':');
if (t == NULL)
    {
    if (sameWord(parsed->protocol,"http"))
	strcpy(parsed->port, "80");
    if (sameWord(parsed->protocol,"https"))
	strcpy(parsed->port, "443");
    if (sameWord(parsed->protocol,"ftp"))
	strcpy(parsed->port, "21");
    }
else
    {
    *t++ = 0;
    if (!isdigit(t[0]))
	errAbort("Non-numeric port name %s", t);
    safecpy(parsed->port, sizeof(parsed->port), t);
    }

/* What's left is the host. */
safecpy(parsed->host, sizeof(parsed->host), s);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq %rsi, %rbx
movq %rdi, %r15
callq 0x62d0
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x2edab
leaq 0x631de(%rip), %rdi     # 0x91f7f
movq %r15, %rsi
xorl %eax, %eax
callq 0x26e94
movq %rsp, %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x6680
movq %r14, %rdi
callq 0x22a74
leaq 0x628f4(%rip), %rsi     # 0x916bc
movq %r14, %rdi
callq 0x6180
testq %rax, %rax
je 0x2edff
movq %rax, %r15
movb $0x0, (%rax)
movq %rsp, %r14
movq %r14, %rdi
callq 0x22305
movl $0x10, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x21600
addq $0x3, %r15
movq %r15, %r14
jmp 0x2ee09
movb $0x0, 0x4(%rbx)
movl $0x70747468, (%rbx)     # imm = 0x70747468
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x2820(%rbx)
movq %r14, %rdi
movl $0x2f, %esi
callq 0x6270
testq %rax, %rax
je 0x2eedc
movq %rax, %r15
leaq 0x2820(%rbx), %rsi
leaq 0x2828(%rbx), %rdx
movq %rax, %rdi
movl $0x1, %ecx
callq 0x2f0f3
leaq 0x63142(%rip), %rsi     # 0x91f92
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
je 0x2ee6f
leaq 0x63134(%rip), %rsi     # 0x91f97
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2eea4
leaq 0x5f5bc(%rip), %rsi     # 0x8e432
leaq 0x63120(%rip), %rdx     # 0x91f9d
movq %r15, %rdi
callq 0x220c3
movq %rax, %r12
leaq 0x1820(%rbx), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rax, %rdx
callq 0x21600
movq %r12, %rdi
callq 0x2e0a0
movb $0x0, (%r15)
leaq 0x6618e(%rip), %rsi     # 0x9503d
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2eee5
incq %r15
leaq 0x1820(%rbx), %r12
movq %r15, %rdi
callq 0x62d0
movq %r15, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x4505f
jmp 0x2eee5
movw $0x2f, 0x1820(%rbx)
movq %r14, %rdi
movl $0x40, %esi
callq 0x6270
testq %rax, %rax
je 0x2ef46
movq %rax, %r15
movb $0x0, (%rax)
movq %r14, %rdi
movl $0x3a, %esi
callq 0x6270
testq %rax, %rax
je 0x2efbd
movq %rax, %r12
movb $0x0, (%rax)
leaq 0x10(%rbx), %rdi
movl $0x800, %esi            # imm = 0x800
movq %r14, %rdx
callq 0x21600
leaq 0x810(%rbx), %rdi
incq %r12
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdx
callq 0x21600
jmp 0x2efd5
leaq 0x63045(%rip), %rsi     # 0x91f92
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
je 0x2ef6c
leaq 0x63037(%rip), %rsi     # 0x91f97
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2ef77
xorl %eax, %eax
movb %al, 0x10(%rbx)
movb %al, 0x810(%rbx)
leaq 0x660bf(%rip), %rsi     # 0x9503d
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2f010
movabsq $0x756f6d796e6f6e61, %rax # imm = 0x756F6D796E6F6E61
movq %rax, 0x10(%rbx)
movw $0x73, 0x18(%rbx)
movdqu 0x63001(%rip), %xmm0    # 0x91fab
movdqu %xmm0, 0x810(%rbx)
movw $0x75, 0x820(%rbx)
jmp 0x2f010
leaq 0x10(%rbx), %rdi
movl $0x800, %esi            # imm = 0x800
movq %r14, %rdx
callq 0x21600
movb $0x0, 0x810(%rbx)
leaq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x44c6c
leaq 0x810(%rbx), %r14
movq %r14, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x44c6c
incq %r15
movq %r15, %r14
movq %r14, %rdi
movl $0x3a, %esi
callq 0x6270
testq %rax, %rax
je 0x2f06a
movq %rax, %r15
movq %rax, %r12
incq %r15
movb $0x0, (%rax)
callq 0x6790
movq (%rax), %rax
movsbq 0x1(%r12), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x2f054
leaq 0x62f7d(%rip), %rdi     # 0x91fc7
movq %r15, %rsi
xorl %eax, %eax
callq 0x26e94
leaq 0x1810(%rbx), %rdi
movl $0x10, %esi
movq %r15, %rdx
callq 0x21600
jmp 0x2f0cd
leaq 0x62f21(%rip), %rsi     # 0x91f92
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2f08d
movb $0x0, 0x1812(%rbx)
movw $0x3038, 0x1810(%rbx)   # imm = 0x3038
leaq 0x62f03(%rip), %rsi     # 0x91f97
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2f0aa
movl $0x333434, 0x1810(%rbx) # imm = 0x333434
leaq 0x65f8c(%rip), %rsi     # 0x9503d
movq %rbx, %rdi
callq 0x209d6
testl %eax, %eax
jne 0x2f0cd
movb $0x0, 0x1812(%rbx)
movw $0x3132, 0x1810(%rbx)   # imm = 0x3132
addq $0x1010, %rbx           # imm = 0x1010
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdi
movq %r14, %rdx
callq 0x21600
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
retq