// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/udc.c
// Function: udcFileMayOpen
struct udcFile *udcFileMayOpen(char *url, char *cacheDir)
/* Open up a cached file. cacheDir may be null in which case udcDefaultDir() will be
 * used.  Return NULL if file doesn't exist. 
 * Caching is inactive if defaultDir is NULL or the protocol is "transparent".
 * */
{
if (cacheDir == NULL)
    cacheDir = udcDefaultDir();
verbose(4, "udcfileOpen(%s, %s)\n", url, cacheDir);
if (udcLogStream)
    fprintf(udcLogStream, "Open %s\n", url);
/* Parse out protocol.  Make it "transparent" if none specified. */
char *protocol = NULL, *afterProtocol = NULL, *colon;
boolean isTransparent = FALSE;
udcParseUrl(url, &protocol, &afterProtocol, &colon);
if (!colon)
    {
    freeMem(protocol);
    protocol = cloneString("transparent");
    freeMem(afterProtocol);
    afterProtocol = cloneString(url);
    isTransparent = TRUE;
    }
struct udcProtocol *prot;
prot = udcProtocolNew(protocol);

/* Figure out if anything exists. */
boolean useCacheInfo = FALSE;
struct udcRemoteFileInfo info;
ZeroVar(&info);
if (!isTransparent)
    {
    if (udcCacheEnabled())
        useCacheInfo = (udcCacheAge(url, cacheDir) < udcCacheTimeout());
    if (!useCacheInfo)
	{
	if (!prot->fetchInfo(url, &info))
	    {
	    udcProtocolFree(&prot);
	    freeMem(protocol);
	    freeMem(afterProtocol);
	    return NULL;
	    }
	}
    }

/* Allocate file object and start filling it in. */
struct udcFile *file;
AllocVar(file);
file->url = cloneString(url);
file->protocol = protocol;
file->prot = prot;
if (isTransparent)
    {
    /* If transparent dummy up things so that the "sparse" file pointer is actually
     * the file itself, which appears to be completely loaded in cache. */
    if (!fileExists(url))
	return NULL;
    int fd = file->fdSparse = mustOpenFd(url, O_RDONLY);
    struct stat status;
    fstat(fd, &status);
    file->startData = 0;
    file->endData = file->size = status.st_size;
    }
else 
    {
    udcPathAndFileNames(file, cacheDir, protocol, afterProtocol);
    if (!useCacheInfo)
	{
	file->updateTime = info.updateTime;
	file->size = info.size;
	memcpy(&(file->connInfo), &(info.ci), sizeof(struct connInfo));
	// update cache file mod times, so if we're caching we won't do this again
	// until the timeout has expired again:
    	if (udcCacheTimeout() > 0 && udcCacheEnabled() && fileExists(file->bitmapFileName))
	    (void)maybeTouchFile(file->bitmapFileName);

	}

    if (udcCacheEnabled())
        {
        /* Make directory. */
        makeDirsOnPath(file->cacheDir);

        /* Figure out a little bit about the extent of the good cached data if any. Open bits bitmap. */
        setInitialCachedDataBounds(file, useCacheInfo);

        file->fdSparse = mustOpenFd(file->sparseFileName, O_RDWR);

	// update redir with latest redirect status	
	udcTestAndSetRedirect(file, protocol, useCacheInfo);
	
        }

    }
freeMem(afterProtocol);
return file;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movq %rdi, %r14
testq %rsi, %rsi
jne 0x402cd
movq 0x809cb(%rip), %r15     # 0xc0c98
leaq 0x54a5d(%rip), %rsi     # 0x94d31
movl $0x4, %edi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x4246e
movq 0x83f0b(%rip), %rdi     # 0xc41f8
testq %rdi, %rdi
je 0x40303
leaq 0x54a4d(%rip), %rsi     # 0x94d46
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
xorl %eax, %eax
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x28(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x70(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x3ff2f
movq (%rbx), %r12
testq %r12, %r12
je 0x403ad
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x409b4
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
cmpq $0x0, 0x8093c(%rip)     # 0xc0c98
je 0x4037d
movq %r14, %rdi
movq %r15, %rsi
callq 0x40ad8
movslq 0x83e90(%rip), %rcx     # 0xc4200
cmpq %rcx, %rax
jae 0x4037d
xorl %r13d, %r13d
jmp 0x40404
movq 0x20(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq *0x10(%rax)
movb $0x1, %r13b
testl %eax, %eax
jne 0x40404
leaq 0x20(%rsp), %rdi
callq 0x2dd51
movq %rbx, %rdi
callq 0x2dd41
xorl %ebx, %ebx
jmp 0x40985
movq 0x18(%rsp), %rdi
callq 0x2dd41
leaq 0x54991(%rip), %rdi     # 0x94d4f
callq 0x1f9f6
movq %rax, %rbx
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rdi
callq 0x2dd41
movq %r14, %rdi
callq 0x1f9f6
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
callq 0x409b4
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movb $0x1, %r13b
movl $0x168, %edi            # imm = 0x168
callq 0x2dc95
movq %rax, %rbx
movq %r14, %rdi
callq 0x1f9f6
movq %rax, 0x8(%rbx)
movq 0x18(%rsp), %rdx
movq %rdx, 0x10(%rbx)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rbx)
testq %r12, %r12
je 0x405a1
movq 0x28(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x40104
testb %r13b, %r13b
je 0x404a0
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rbx)
movq 0x48(%rsp), %rax
movq %rax, 0x28(%rbx)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movups %xmm1, 0xa0(%rbx)
movups %xmm0, 0x90(%rbx)
cmpl $0x0, 0x83d82(%rip)     # 0xc4200
jle 0x404a0
cmpq $0x0, 0x80810(%rip)     # 0xc0c98
je 0x404a0
movq 0x40(%rbx), %rdi
callq 0x23942
testl %eax, %eax
je 0x404a0
movq 0x40(%rbx), %rdi
callq 0x35211
cmpq $0x0, 0x807f0(%rip)     # 0xc0c98
je 0x40985
movq 0x38(%rbx), %rdi
callq 0x4bd78
movq 0x40(%rbx), %rdi
callq 0x411b6
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x405ec
testb %r13b, %r13b
jne 0x404e3
movq 0x18(%rax), %rcx
movq %rcx, 0x28(%rbx)
movq 0x10(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl 0x20(%rax), %r15d
movq 0x10(%rax), %rcx
cmpq 0x20(%rbx), %rcx
jne 0x40538
movq 0x18(%rax), %rax
cmpq 0x28(%rbx), %rax
jne 0x40538
movq 0x48(%rbx), %rdi
callq 0x23942
testl %eax, %eax
je 0x40538
movq 0x48(%rbx), %rdi
callq 0x34368
testq %rax, %rax
jne 0x40606
cmpq $0x0, 0x28(%rbx)
je 0x40606
movq 0x40(%rbx), %rdi
callq 0x34368
cmpq $0x41, %rax
jl 0x40606
leaq 0x8(%rsp), %r14
movq (%r14), %rax
movq 0x10(%rax), %rdx
movq 0x18(%rax), %r8
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %r9
leaq 0x54d13(%rip), %rsi     # 0x9526a
movl $0x4, %edi
xorl %eax, %eax
pushq %r15
pushq 0x48(%rbx)
callq 0x4246e
addq $0x10, %rsp
movq %r14, %rdi
callq 0x40e28
movq 0x40(%rbx), %rdi
callq 0x6da0
movq 0x48(%rbx), %rdi
callq 0x6da0
movq 0x50(%rbx), %rdi
callq 0x23942
testl %eax, %eax
je 0x4059c
movq 0x50(%rbx), %rdi
callq 0x6da0
incl %r15d
jmp 0x40606
movq %r14, %rdi
callq 0x23942
testl %eax, %eax
je 0x40960
movq %r14, %rdi
xorl %esi, %esi
callq 0x230d7
movl %eax, 0x58(%rbx)
leaq 0x88(%rsp), %r14
movl %eax, %edi
movq %r14, %rsi
callq 0x6db0
movq $0x0, 0x78(%rbx)
movq 0x30(%r14), %rax
movq %rax, 0x28(%rbx)
movq %rax, 0x80(%rbx)
jmp 0x40985
movq 0x40(%rbx), %rdx
leaq 0x54ce6(%rip), %rsi     # 0x952dd
xorl %r15d, %r15d
movl $0x4, %edi
xorl %eax, %eax
callq 0x4246e
cmpq $0x0, 0x8(%rsp)
jne 0x4080b
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq 0x88(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x80(%rsp), %r12
movq %rcx, (%r12)
leaq 0x34(%rsp), %rax
movl %r15d, (%rax)
movq 0x40(%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
callq 0x230d7
movl %eax, 0x4(%rsp)
leaq 0x3c(%rsp), %rsi
movl $0x4187e2f6, (%rsi)     # imm = 0x4187E2F6
leaq 0x38(%rsp), %r15
movl $0x2000, (%r15)         # imm = 0x2000
leaq 0x78(%rsp), %r14
movq $0x0, (%r14)
leaq 0x30(%rsp), %rcx
movl $0x0, (%rcx)
movq (%r12), %rbp
movl $0x4, %edx
movl %eax, %edi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x4, %edx
movq %r15, %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x8, %edx
leaq 0x88(%rsp), %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x8, %edx
movq %r12, %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x4, %edx
leaq 0x34(%rsp), %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x4, %edx
leaq 0x30(%rsp), %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x231f9
movl 0x4(%rsp), %edi
incq 0xb8(%rbx)
xorl %esi, %esi
movl $0x1, %edx
callq 0x23232
cmpq $0x40, %rax
je 0x40767
movl 0x4(%rsp), %esi
movq 0x40(%rbx), %rdx
leaq 0x54bd6(%rip), %rdi     # 0x9532d
movq %rax, %rcx
movl $0x40, %r8d
xorl %eax, %eax
callq 0x26b6f
addq $0x1fff, %rbp           # imm = 0x1FFF
shrq $0xd, %rbp
leal 0x7(%rbp), %eax
addl $0xe, %ebp
testl %eax, %eax
cmovnsl %eax, %ebp
sarl $0x3, %ebp
leaq 0x17(%rsp), %r15
movb $0x0, (%r15)
leaq 0x4(%rsp), %r14
movl (%r14), %edi
decl %ebp
movslq %ebp, %rsi
incq 0xb8(%rbx)
movl $0x1, %edx
callq 0x23232
movl (%r14), %edi
incq 0xd0(%rbx)
incq 0xd8(%rbx)
movl $0x1, %edx
movq %r15, %rsi
callq 0x231f9
movq %r14, %rdi
callq 0x232a1
movq 0x48(%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
callq 0x230d7
movl %eax, (%r14)
movq %r14, %rdi
callq 0x232a1
movq 0x40(%rbx), %rdi
callq 0x411b6
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x4080b
movq 0x40(%rbx), %rsi
leaq 0x54b0b(%rip), %rdi     # 0x9530f
xorl %eax, %eax
callq 0x26b6f
movq 0x8(%rsp), %rax
movl 0x20(%rax), %ecx
movl %ecx, 0x88(%rbx)
cmpq $0x0, 0x28(%rbx)
je 0x40896
movl 0x3c(%rax), %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x65b0
movq %rax, %r14
movq 0x8(%rsp), %rax
movl 0x3c(%rax), %edi
leaq 0x88(%rsp), %r15
movl $0x1, %edx
movq %r15, %rsi
callq 0x23186
movl $0x1fff, %eax           # imm = 0x1FFF
addq 0x28(%rbx), %rax
shrq $0xd, %rax
cmpl $0x8, %eax
movl $0x8, %edx
cmovll %eax, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x1bad0
shll $0xd, %eax
cltq
movq %rax, 0x80(%rbx)
movq 0x8(%rsp), %rax
movl 0x3c(%rax), %edi
incq 0xb8(%rbx)
movq %r14, %rsi
xorl %edx, %edx
callq 0x23232
movq 0x8(%rsp), %rax
movq %rax, 0x70(%rbx)
movq 0x48(%rbx), %rdi
movl $0x2, %esi
callq 0x230d7
movl %eax, 0x58(%rbx)
movq 0x18(%rsp), %rsi
leaq 0x515e6(%rip), %rdi     # 0x91ea2
callq 0x217c8
testl %eax, %eax
je 0x40985
movq $0x0, 0x88(%rsp)
movq 0x50(%rbx), %rdi
callq 0x23942
testl %eax, %eax
je 0x408f5
movq 0x50(%rbx), %rdi
leaq 0x88(%rsp), %rsi
xorl %edx, %edx
callq 0x32524
testb %r13b, %r13b
je 0x40964
movq 0xa8(%rbx), %rdi
movq 0x88(%rsp), %rsi
testq %rdi, %rdi
je 0x409a4
callq 0x21769
testl %eax, %eax
je 0x40978
movq 0x50(%rbx), %rdi
leaq 0x54a4a(%rip), %rsi     # 0x95370
callq 0x232cf
movq %rax, %r14
movq 0xa8(%rbx), %r15
movq %r15, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x324e2
movq 0x50(%rbx), %rsi
movq %r14, %rdi
callq 0x6430
movq %r14, %rdi
callq 0x2dd41
jmp 0x40978
xorl %ebx, %ebx
jmp 0x4098f
movq 0x88(%rsp), %rdi
callq 0x1f9f6
movq %rax, 0xa8(%rbx)
movq 0x88(%rsp), %rdi
callq 0x2dd41
movq 0x28(%rsp), %rdi
callq 0x2dd41
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rsi, %rsi
je 0x40978
movq 0x50(%rbx), %rdi
callq 0x6da0
jmp 0x40978