// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x1080, %rsp           # imm = 0x1080
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x62c0
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x42196
movq -0x8(%rbp), %rsi
leaq 0x99ba8(%rip), %rdi     # 0xdbd37
movb $0x0, %al
callq 0x35d40
leaq -0x1040(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x6680
leaq -0x1040(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2ef90
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x992ab(%rip), %rsi     # 0xdb474
callq 0x6170
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x421f3
movq -0x10(%rbp), %rdi
leaq 0x99b66(%rip), %rsi     # 0xdbd4a
callq 0x6680
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x42221
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
callq 0x2e1c0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl $0x10, %esi
callq 0x2caf0
movq -0x18(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq $-0x1, 0x2820(%rax)
movq -0x10(%rbp), %rax
movq $-0x1, 0x2828(%rax)
movq -0x18(%rbp), %rdi
movl $0x2f, %esi
callq 0x6260
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x42274
movq -0x10(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
leaq 0x9ce15(%rip), %rsi     # 0xdf07f
callq 0x6680
jmp 0x4236c
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x2820, %rsi           # imm = 0x2820
movq -0x10(%rbp), %rdx
addq $0x2828, %rdx           # imm = 0x2828
movl $0x1, %ecx
callq 0x42670
movq -0x10(%rbp), %rdi
leaq 0x99aa7(%rip), %rsi     # 0xdbd4a
callq 0x2b9f0
cmpl $0x0, %eax
je 0x422c2
movq -0x10(%rbp), %rdi
leaq 0x99a97(%rip), %rsi     # 0xdbd4f
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x42308
movq -0x28(%rbp), %rdi
leaq 0x9605d(%rip), %rsi     # 0xd832a
leaq 0x99a81(%rip), %rdx     # 0xdbd55
callq 0x2de30
movq %rax, -0x1048(%rbp)
movq -0x10(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
movq -0x1048(%rbp), %rdx
movl $0x1000, %esi           # imm = 0x1000
callq 0x2caf0
movq -0x1048(%rbp), %rdi
callq 0x40d40
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
leaq 0x9cb16(%rip), %rsi     # 0xdee30
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x4236a
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x1058(%rbp)
movq -0x10(%rbp), %rax
addq $0x1820, %rax           # imm = 0x1820
movq %rax, -0x1050(%rbp)
movq -0x28(%rbp), %rdi
callq 0x62c0
movq -0x1058(%rbp), %rdi
movq -0x1050(%rbp), %rsi
movl %eax, %edx
callq 0x63dc0
jmp 0x4236c
movq -0x18(%rbp), %rdi
movl $0x40, %esi
callq 0x6260
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x42423
movq -0x10(%rbp), %rdi
leaq 0x999b6(%rip), %rsi     # 0xdbd4a
callq 0x2b9f0
cmpl $0x0, %eax
je 0x423b3
movq -0x10(%rbp), %rdi
leaq 0x999a6(%rip), %rsi     # 0xdbd4f
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x423de
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
leaq 0xa3044(%rip), %rsi     # 0xe5406
callq 0x6680
movq -0x10(%rbp), %rdi
addq $0x810, %rdi            # imm = 0x810
leaq 0xa302d(%rip), %rsi     # 0xe5406
callq 0x6680
movq -0x10(%rbp), %rdi
leaq 0x9ca47(%rip), %rsi     # 0xdee30
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x4241e
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
leaq 0x99957(%rip), %rsi     # 0xdbd59
callq 0x6680
movq -0x10(%rbp), %rdi
addq $0x810, %rdi            # imm = 0x810
leaq 0x9994a(%rip), %rsi     # 0xdbd63
callq 0x6680
jmp 0x4253f
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
movl $0x3a, %esi
callq 0x6260
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x42472
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rdx
movl $0x800, %esi            # imm = 0x800
callq 0x2caf0
movq -0x10(%rbp), %rdi
addq $0x810, %rdi            # imm = 0x810
leaq 0xa2f9b(%rip), %rsi     # 0xe5406
callq 0x6680
jmp 0x424ac
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rdx
movl $0x800, %esi            # imm = 0x800
callq 0x2caf0
movq -0x10(%rbp), %rdi
addq $0x810, %rdi            # imm = 0x810
movq -0x38(%rbp), %rdx
addq $0x1, %rdx
movl $0x800, %esi            # imm = 0x800
callq 0x2caf0
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x1078(%rbp)
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x1070(%rbp)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x62c0
movq -0x1078(%rbp), %rdi
movq -0x1070(%rbp), %rsi
movl %eax, %edx
callq 0x63670
movq -0x10(%rbp), %rax
addq $0x810, %rax            # imm = 0x810
movq %rax, -0x1068(%rbp)
movq -0x10(%rbp), %rax
addq $0x810, %rax            # imm = 0x810
movq %rax, -0x1060(%rbp)
movq -0x10(%rbp), %rdi
addq $0x810, %rdi            # imm = 0x810
callq 0x62c0
movq -0x1068(%rbp), %rdi
movq -0x1060(%rbp), %rsi
movl %eax, %edx
callq 0x63670
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x3a, %esi
callq 0x6260
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x425e2
movq -0x10(%rbp), %rdi
leaq 0x997e3(%rip), %rsi     # 0xdbd4a
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x42588
movq -0x10(%rbp), %rdi
addq $0x1810, %rdi           # imm = 0x1810
leaq 0x997f2(%rip), %rsi     # 0xdbd75
callq 0x6680
movq -0x10(%rbp), %rdi
leaq 0x997bc(%rip), %rsi     # 0xdbd4f
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x425b4
movq -0x10(%rbp), %rdi
addq $0x1810, %rdi           # imm = 0x1810
leaq 0x997c9(%rip), %rsi     # 0xdbd78
callq 0x6680
movq -0x10(%rbp), %rdi
leaq 0x9c871(%rip), %rsi     # 0xdee30
callq 0x2b9f0
cmpl $0x0, %eax
jne 0x425e0
movq -0x10(%rbp), %rdi
addq $0x1810, %rdi           # imm = 0x1810
leaq 0x997a1(%rip), %rsi     # 0xdbd7c
callq 0x6680
jmp 0x4263f
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb $0x0, (%rax)
callq 0x6780
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x42626
movq -0x20(%rbp), %rsi
leaq 0x99760(%rip), %rdi     # 0xdbd7f
movb $0x0, %al
callq 0x35d40
movq -0x10(%rbp), %rdi
addq $0x1810, %rdi           # imm = 0x1810
movq -0x20(%rbp), %rdx
movl $0x10, %esi
callq 0x2caf0
movq -0x10(%rbp), %rdi
addq $0x1010, %rdi           # imm = 0x1010
movq -0x18(%rbp), %rdx
movl $0x800, %esi            # imm = 0x800
callq 0x2caf0
addq $0x1080, %rsp           # imm = 0x1080
popq %rbp
retq
nopw %cs:(%rax,%rax)