// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/udc.c
// Function: udcInfoViaHttp
boolean udcInfoViaHttp(char *url, struct udcRemoteFileInfo *retInfo)
/* Gets size and last modified time of URL
 * and returns status of HEAD or GET byterange 0-0. */
{
verbose(4, "checking http remote info on %s\n", url);
// URLs passed into here should not have byterange clause.
int redirectCount = 0;
struct hash *hash;
int status;
char *sizeString = NULL;
/*
 For caching, sites should support byte-range and last-modified.
 However, several groups including ENCODE have made sites that use CGIs to 
 dynamically generate hub text files such as hub.txt, genome.txt, trackDb.txt.
 Byte-range and last-modified are difficult to support for this case,
 so they do without them, effectively defeat caching. Every 5 minutes (udcTimeout),
 they get re-downloaded, even when the data has not changed.  
*/
while (TRUE)
    {
    hash = newHash(0);
    status = netUrlHead(url, hash);
    sizeString = hashFindValUpperCase(hash, "Content-Length:");
    if (status == 200 && sizeString)
	break;
    /*
    Using HEAD with HIPPAA-compliant signed AmazonS3 URLs generates 403.
    The signed URL generated for GET cannot be used with HEAD.
    Instead call GET with byterange=0-0 in netUrlFakeHeadByGet().
    This supplies both size via Content-Range response header,
    as well as Last-Modified header which is important for caching.
    There are also sites which support byte-ranges 
    but they do not return Content-Length with HEAD.
    */
    if (status == 403 || (status==200 && !sizeString))
	{ 
	hashFree(&hash);
	hash = newHash(0);
	status = netUrlFakeHeadByGet(url, hash);
	if (status == 206) 
	    break;
	}
    if (status != 301 && status != 302)
	return FALSE;
    ++redirectCount;
    if (redirectCount > 5)
	{
	warn("code %d redirects: exceeded limit of 5 redirects, %s", status, url);
	return FALSE;
	}
    char *newUrl = hashFindValUpperCase(hash, "Location:");
    retInfo->ci.redirUrl = cloneString(newUrl);
    url = transferParamsToRedirectedUrl(url, newUrl);		
    hashFree(&hash);
    }

char *sizeHeader = NULL;
if (status == 200)
    {
    sizeHeader = "Content-Length:";
    // input pattern: Content-Length: 2738262
    }
if (status == 206)
    {
    sizeHeader = "Content-Range:";
    // input pattern: Content-Range: bytes 0-99/2738262
    }

sizeString = hashFindValUpperCase(hash, sizeHeader);
if (sizeString)
    {
    char *parseString = sizeString;
    if (status == 206)
	{
	parseString = strchr(sizeString, '/');
	if (!parseString)
	    {
	    warn("Header value %s is missing '/' in %s in response for url %s", 
		sizeString, sizeHeader, url);
	    return FALSE;
	    }
	++parseString; // skip past slash
	}
    if (parseString)
	{
	retInfo->size = atoll(parseString);
	}
    else
	{
	warn("Header value %s is missing or invalid in %s in response for url %s", 
	    sizeString, sizeHeader, url);
	return FALSE;
	}
    }
else
    {
    warn("Response is missing required header %s for url %s", sizeHeader, url);
    return FALSE;
    }

char *lastModString = hashFindValUpperCase(hash, "Last-Modified:");
if (lastModString == NULL)
    {
    // Date is a poor substitute!  It will always appear that the cache is stale.
    // But at least we can read files from dropbox.com.
    lastModString = hashFindValUpperCase(hash, "Date:");
    if (lastModString == NULL)
	{
	hashFree(&hash);
	errAbort("No Last-Modified: or Date: returned in header for %s, can't proceed, sorry", url);
	}
    }

struct tm tm;
time_t t;
// Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT
// This will always be GMT
if (strptime(lastModString, "%a, %d %b %Y %H:%M:%S %Z", &tm) == NULL)
    { /* Handle error */;
    hashFree(&hash);
    errAbort("unable to parse last-modified string [%s]", lastModString);
    }
t = mktimeFromUtc(&tm);
if (t == -1)
    { /* Handle error */;
    hashFree(&hash);
    errAbort("mktimeFromUtc failed while converting last-modified string [%s] from UTC time", lastModString);
    }
retInfo->updateTime = t;

hashFree(&hash);
return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdx
movl $0x4, %edi
leaq 0x82ab5(%rip), %rsi     # 0xde988
movb $0x0, %al
callq 0x60040
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x38(%rbp)
xorl %edi, %edi
movl $0x1, %esi
callq 0x398a0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x43b50
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x7f426(%rip), %rsi     # 0xdb33a
callq 0x396d0
movq %rax, -0x38(%rbp)
cmpl $0xc8, -0x2c(%rbp)
jne 0x5bf32
cmpq $0x0, -0x38(%rbp)
je 0x5bf32
jmp 0x5c019
cmpl $0x193, -0x2c(%rbp)     # imm = 0x193
je 0x5bf4b
cmpl $0xc8, -0x2c(%rbp)
jne 0x5bf84
cmpq $0x0, -0x38(%rbp)
jne 0x5bf84
leaq -0x28(%rbp), %rdi
callq 0x3a080
xorl %edi, %edi
movl $0x1, %esi
callq 0x398a0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x43b80
movl %eax, -0x2c(%rbp)
cmpl $0xce, -0x2c(%rbp)
jne 0x5bf82
jmp 0x5c019
jmp 0x5bf84
cmpl $0x12d, -0x2c(%rbp)     # imm = 0x12D
je 0x5bfa2
cmpl $0x12e, -0x2c(%rbp)     # imm = 0x12E
je 0x5bfa2
movl $0x0, -0x4(%rbp)
jmp 0x5c208
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x5, -0x1c(%rbp)
jle 0x5bfd2
movl -0x2c(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x829ea(%rip), %rdi     # 0xde9a9
movb $0x0, %al
callq 0x358e0
movl $0x0, -0x4(%rbp)
jmp 0x5c208
movq -0x28(%rbp), %rdi
leaq 0x82a01(%rip), %rsi     # 0xde9de
callq 0x396d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x44c60
movq %rax, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3a080
jmp 0x5bee9
movq $0x0, -0x48(%rbp)
cmpl $0xc8, -0x2c(%rbp)
jne 0x5c035
leaq 0x7f309(%rip), %rax     # 0xdb33a
movq %rax, -0x48(%rbp)
cmpl $0xce, -0x2c(%rbp)
jne 0x5c049
leaq 0x829a3(%rip), %rax     # 0xde9e8
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x396d0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5c106
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0xce, -0x2c(%rbp)
jne 0x5c0c1
movq -0x38(%rbp), %rdi
movl $0x2f, %esi
callq 0x6260
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5c0b5
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x82955(%rip), %rdi     # 0xde9f7
movb $0x0, %al
callq 0x358e0
movl $0x0, -0x4(%rbp)
jmp 0x5c208
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x5c0de
movq -0x50(%rbp), %rdi
callq 0x6520
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x5c104
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x82942(%rip), %rdi     # 0xdea33
movb $0x0, %al
callq 0x358e0
movl $0x0, -0x4(%rbp)
jmp 0x5c208
jmp 0x5c128
movq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq 0x82961(%rip), %rdi     # 0xdea76
movb $0x0, %al
callq 0x358e0
movl $0x0, -0x4(%rbp)
jmp 0x5c208
movq -0x28(%rbp), %rdi
leaq 0x82975(%rip), %rsi     # 0xdeaa8
callq 0x396d0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5c17b
movq -0x28(%rbp), %rdi
leaq 0x82969(%rip), %rsi     # 0xdeab7
callq 0x396d0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5c179
leaq -0x28(%rbp), %rdi
callq 0x3a080
movq -0x10(%rbp), %rsi
leaq 0x8294b(%rip), %rdi     # 0xdeabd
movb $0x0, %al
callq 0x35d40
jmp 0x5c17b
movq -0x58(%rbp), %rdi
leaq 0x82982(%rip), %rsi     # 0xdeb08
leaq -0x90(%rbp), %rdx
callq 0x60f0
cmpq $0x0, %rax
jne 0x5c1b3
leaq -0x28(%rbp), %rdi
callq 0x3a080
movq -0x58(%rbp), %rsi
leaq 0x82975(%rip), %rdi     # 0xdeb21
movb $0x0, %al
callq 0x35d40
leaq -0x90(%rbp), %rdi
callq 0x318f0
movq %rax, -0x98(%rbp)
cmpq $-0x1, -0x98(%rbp)
jne 0x5c1eb
leaq -0x28(%rbp), %rdi
callq 0x3a080
movq -0x58(%rbp), %rsi
leaq 0x82967(%rip), %rdi     # 0xdeb4b
movb $0x0, %al
callq 0x35d40
movq -0x98(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x28(%rbp), %rdi
callq 0x3a080
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)