// File: /workspace/github_c_makefile_star2_O1/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 0x2ea72
leaq 0x63427(%rip), %rdi     # 0x91e8f
movq %r15, %rsi
xorl %eax, %eax
callq 0x26b6f
movq %rsp, %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x6680
movq %r14, %rdi
callq 0x22732
leaq 0x62b3d(%rip), %rsi     # 0x915cc
movq %r14, %rdi
callq 0x6180
testq %rax, %rax
je 0x2eac6
movq %rax, %r15
movb $0x0, (%rax)
movq %rsp, %r14
movq %r14, %rdi
callq 0x21fb5
movl $0x10, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x21264
addq $0x3, %r15
movq %r15, %r14
jmp 0x2ead0
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 0x2eba3
movq %rax, %r15
leaq 0x2820(%rbx), %rsi
leaq 0x2828(%rbx), %rdx
movq %rax, %rdi
movl $0x1, %ecx
callq 0x2edba
leaq 0x6338b(%rip), %rsi     # 0x91ea2
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
je 0x2eb36
leaq 0x6337d(%rip), %rsi     # 0x91ea7
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2eb6b
leaq 0x5f8b5(%rip), %rsi     # 0x8e3f2
leaq 0x63369(%rip), %rdx     # 0x91ead
movq %r15, %rdi
callq 0x21d64
movq %rax, %r12
leaq 0x1820(%rbx), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rax, %rdx
callq 0x21264
movq %r12, %rdi
callq 0x2dd41
movb $0x0, (%r15)
leaq 0x663df(%rip), %rsi     # 0x94f55
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2ebac
incq %r15
leaq 0x1820(%rbx), %r12
movq %r15, %rdi
callq 0x62d0
movq %r15, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x44ca8
jmp 0x2ebac
movw $0x2f, 0x1820(%rbx)
movq %r14, %rdi
movl $0x40, %esi
callq 0x6270
testq %rax, %rax
je 0x2ec0d
movq %rax, %r15
movb $0x0, (%rax)
movq %r14, %rdi
movl $0x3a, %esi
callq 0x6270
testq %rax, %rax
je 0x2ec84
movq %rax, %r12
movb $0x0, (%rax)
leaq 0x10(%rbx), %rdi
movl $0x800, %esi            # imm = 0x800
movq %r14, %rdx
callq 0x21264
leaq 0x810(%rbx), %rdi
incq %r12
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdx
callq 0x21264
jmp 0x2ec9c
leaq 0x6328e(%rip), %rsi     # 0x91ea2
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
je 0x2ec33
leaq 0x63280(%rip), %rsi     # 0x91ea7
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2ec3e
xorl %eax, %eax
movb %al, 0x10(%rbx)
movb %al, 0x810(%rbx)
leaq 0x66310(%rip), %rsi     # 0x94f55
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2ecd7
movabsq $0x756f6d796e6f6e61, %rax # imm = 0x756F6D796E6F6E61
movq %rax, 0x10(%rbx)
movw $0x73, 0x18(%rbx)
movdqu 0x6324a(%rip), %xmm0    # 0x91ebb
movdqu %xmm0, 0x810(%rbx)
movw $0x75, 0x820(%rbx)
jmp 0x2ecd7
leaq 0x10(%rbx), %rdi
movl $0x800, %esi            # imm = 0x800
movq %r14, %rdx
callq 0x21264
movb $0x0, 0x810(%rbx)
leaq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x448ce
leaq 0x810(%rbx), %r14
movq %r14, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x448ce
incq %r15
movq %r15, %r14
movq %r14, %rdi
movl $0x3a, %esi
callq 0x6270
testq %rax, %rax
je 0x2ed31
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 0x2ed1b
leaq 0x631c6(%rip), %rdi     # 0x91ed7
movq %r15, %rsi
xorl %eax, %eax
callq 0x26b6f
leaq 0x1810(%rbx), %rdi
movl $0x10, %esi
movq %r15, %rdx
callq 0x21264
jmp 0x2ed94
leaq 0x6316a(%rip), %rsi     # 0x91ea2
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2ed54
movb $0x0, 0x1812(%rbx)
movw $0x3038, 0x1810(%rbx)   # imm = 0x3038
leaq 0x6314c(%rip), %rsi     # 0x91ea7
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2ed71
movl $0x333434, 0x1810(%rbx) # imm = 0x333434
leaq 0x661dd(%rip), %rsi     # 0x94f55
movq %rbx, %rdi
callq 0x2054a
testl %eax, %eax
jne 0x2ed94
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 0x21264
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
retq