// File: /workspace/github_c_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %rsi, %r12
movq %rdi, %r14
testq %rsi, %rsi
jne 0x3a451
movq 0x7a867(%rip), %r12     # 0xb4cb8
leaq 0x498c1(%rip), %rsi     # 0x83d19
pushq $0x4
popq %rdi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x3c521
movq 0x7dda9(%rip), %rdi     # 0xb8218
testq %rdi, %rdi
je 0x3a485
leaq 0x498b3(%rip), %rsi     # 0x83d2e
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
leaq 0x20(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x90(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3a284
movq (%rbx), %rbp
testq %rbp, %rbp
je 0x3a53d
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x3ab3d
movq %rax, %r13
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
cmpq $0x0, 0x7a7d0(%rip)     # 0xb4cb8
je 0x3a50e
movq %r14, %rdi
movq %r12, %rsi
callq 0x3ac5f
movslq 0x7dd24(%rip), %rcx     # 0xb8220
cmpq %rcx, %rax
jae 0x3a50e
movl $0x0, 0x4(%rsp)
jmp 0x3a59d
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
callq *0x10(%r13)
movb $0x1, %cl
movl %ecx, 0x4(%rsp)
testl %eax, %eax
jne 0x3a59d
leaq 0x40(%rsp), %rdi
callq 0x28c3d
movq %r15, %rdi
callq 0x28c2d
xorl %ebx, %ebx
jmp 0x3a6da
movq 0x20(%rsp), %rdi
callq 0x28c2d
leaq 0x497e9(%rip), %rdi     # 0x83d37
callq 0x1c306
movq %rax, %r15
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rdi
callq 0x28c2d
movq %r14, %rdi
callq 0x1c306
movq %rax, 0x18(%rsp)
movq %r15, %rdi
callq 0x3ab3d
movq %rax, %r13
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movl $0x168, %edi            # imm = 0x168
callq 0x28bb0
movq %rax, %rbx
movq %r14, %rdi
callq 0x1c306
movq %rax, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %r13, 0x18(%rbx)
testq %rbp, %rbp
je 0x3a69b
movq 0x18(%rsp), %r13
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x3a28c
movl 0x4(%rsp), %ebp
testb %bpl, %bpl
je 0x3a63b
movaps 0x60(%rsp), %xmm0
movups %xmm0, 0x20(%rbx)
movaps 0x70(%rsp), %xmm0
movaps 0x80(%rsp), %xmm1
movups %xmm1, 0xa0(%rbx)
movups %xmm0, 0x90(%rbx)
cmpl $0x0, 0x7dc0f(%rip)     # 0xb8220
setle %cl
movq 0x7a69d(%rip), %rax     # 0xb4cb8
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x3a642
movq 0x40(%rbx), %rdi
callq 0x1f807
testl %eax, %eax
je 0x3a63b
movq 0x40(%rbx), %rdi
callq 0x2fae2
movq 0x7a676(%rip), %rax     # 0xb4cb8
testq %rax, %rax
je 0x3ab10
movq 0x38(%rbx), %rdi
callq 0x45794
movq 0x40(%rbx), %rdi
callq 0x3b30a
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3a6e4
movq %rax, %r12
testb %bpl, %bpl
je 0x3a70d
movq 0x10(%r12), %rax
movl 0x20(%r12), %r14d
cmpq 0x20(%rbx), %rax
jne 0x3a759
movq 0x18(%r12), %rax
cmpq 0x28(%rbx), %rax
je 0x3a71c
jmp 0x3a759
movq %r14, %rdi
callq 0x1f807
testl %eax, %eax
je 0x3a706
movq %r14, %rdi
xorl %esi, %esi
callq 0x1efea
movl %eax, 0x58(%rbx)
leaq 0x98(%rsp), %r14
movl %eax, %edi
movq %r14, %rsi
callq 0x6db0
andq $0x0, 0x78(%rbx)
movq 0x30(%r14), %rax
movq %rax, 0x28(%rbx)
movq %rax, 0x80(%rbx)
movq 0x18(%rsp), %r13
jmp 0x3ab10
movq %r13, 0x38(%rsp)
movq 0x40(%rbx), %rdx
leaq 0x49bd1(%rip), %rsi     # 0x842c5
xorl %r14d, %r14d
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0x3c521
jmp 0x3a7cb
xorl %ebx, %ebx
jmp 0x3ab18
movups 0x10(%r12), %xmm0
movups %xmm0, 0x20(%rbx)
movl 0x20(%r12), %r14d
movq 0x48(%rbx), %rdi
callq 0x1f807
testl %eax, %eax
je 0x3a759
movq 0x48(%rbx), %rdi
callq 0x2ed50
testq %rax, %rax
jne 0x3a9a5
cmpq $0x0, 0x28(%rbx)
je 0x3a9a5
movq 0x40(%rbx), %rdi
callq 0x2ed50
cmpq $0x41, %rax
jl 0x3a9a5
movq 0x10(%r12), %rdx
movq 0x18(%r12), %r8
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %r9
leaq 0x49ae0(%rip), %rsi     # 0x84252
pushq $0x4
popq %rdi
xorl %eax, %eax
pushq %r14
pushq 0x48(%rbx)
callq 0x3c521
popq %rax
popq %rcx
leaq 0x8(%rsp), %rdi
callq 0x3af9b
movq 0x40(%rbx), %rdi
callq 0x6da0
movq 0x48(%rbx), %rdi
callq 0x6da0
movq 0x50(%rbx), %rdi
callq 0x1f807
testl %eax, %eax
je 0x3a7b5
movq 0x50(%rbx), %rdi
callq 0x6da0
movq 0x8(%rsp), %r12
testq %r12, %r12
jne 0x3a9a5
movq %r13, 0x38(%rsp)
incl %r14d
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %r13
leaq 0x98(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x50(%rsp), %rax
movq %r13, (%rax)
leaq 0x34(%rsp), %rax
movl %r14d, (%rax)
movq 0x40(%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
callq 0x1efea
movl %eax, %r12d
movl %eax, 0x30(%rsp)
leaq 0x5c(%rsp), %rsi
movl $0x4187e2f6, (%rsi)     # imm = 0x4187E2F6
leaq 0x58(%rsp), %r14
movl $0x2000, (%r14)         # imm = 0x2000
leaq 0x48(%rsp), %rax
andq $0x0, (%rax)
leaq 0x2c(%rsp), %rax
andl $0x0, (%rax)
pushq $0x4
popq %rbp
movl %r12d, %edi
movq %rbp, %rdx
callq 0x1f108
movl %r12d, %edi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1f108
pushq $0x8
popq %r14
movl %r12d, %edi
leaq 0x98(%rsp), %rsi
movq %r14, %rdx
callq 0x1f108
movl %r12d, %edi
leaq 0x50(%rsp), %rsi
movq %r14, %rdx
callq 0x1f108
movl %r12d, %edi
leaq 0x34(%rsp), %rsi
movq %rbp, %rdx
callq 0x1f108
movl %r12d, %edi
leaq 0x2c(%rsp), %rsi
movq %rbp, %rdx
callq 0x1f108
movl %r12d, %edi
leaq 0x48(%rsp), %rbp
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1f108
movl %r12d, %edi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1f108
movl %r12d, %edi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1f108
movl %r12d, %edi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1f108
leaq 0xb8(%rbx), %rbp
pushq $0x1
popq %rcx
movq %rbp, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3b4c4
cmpq $0x40, %rax
je 0x3a904
movq 0x40(%rbx), %rdx
leaq 0x49a22(%rip), %rdi     # 0x84315
pushq $0x40
popq %r8
movl %r12d, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x223fb
addq $0x1fff, %r13           # imm = 0x1FFF
shrq $0xd, %r13
addl $0x7, %r13d
movl %r13d, %eax
cltd
pushq $0x8
popq %rcx
idivl %ecx
leaq 0x17(%rsp), %r14
movb $0x0, (%r14)
decl %eax
movslq %eax, %rdx
pushq $0x1
popq %rcx
movq %rbp, %rdi
movl %r12d, %esi
callq 0x3b4c4
pushq $0x1
popq %rcx
movq %rbp, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x3c4bc
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x1f1b0
movq 0x48(%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
callq 0x1efea
movl %eax, (%r14)
movq %r14, %rdi
callq 0x1f1b0
movq 0x40(%rbx), %rdi
callq 0x3b30a
movq %rax, %r12
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq 0x38(%rsp), %r13
movl 0x4(%rsp), %ebp
jne 0x3a9a5
movq 0x40(%rbx), %rsi
leaq 0x4995e(%rip), %rdi     # 0x842f7
xorl %eax, %eax
callq 0x223fb
movq 0x8(%rsp), %r12
movl 0x20(%r12), %eax
movl %eax, 0x88(%rbx)
cmpq $0x0, 0x28(%rbx)
je 0x3aa31
movl 0x3c(%r12), %edi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x65b0
movq %rax, %r14
movq 0x8(%rsp), %rax
movl 0x3c(%rax), %edi
leaq 0x98(%rsp), %r12
pushq $0x1
popq %rdx
movq %r12, %rsi
callq 0x1f096
movl $0x1fff, %eax           # imm = 0x1FFF
addq 0x28(%rbx), %rax
shrq $0xd, %rax
cmpl $0x8, %eax
pushq $0x8
popq %rdx
cmovll %eax, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x186dd
shll $0xd, %eax
cltq
movq %rax, 0x80(%rbx)
movq %rbx, %rdi
addq $0xb8, %rdi
movq 0x8(%rsp), %rax
movl 0x3c(%rax), %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x3b4c4
movq 0x8(%rsp), %r12
movq %r12, 0x70(%rbx)
movq 0x48(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0x1efea
movl %eax, 0x58(%rbx)
leaq 0x46447(%rip), %rdi     # 0x80e92
movq %r15, %rsi
callq 0x1db41
testl %eax, %eax
je 0x3ab10
andq $0x0, 0x98(%rsp)
movq 0x50(%rbx), %rdi
callq 0x1f807
testl %eax, %eax
je 0x3aa84
movq 0x50(%rbx), %rdi
leaq 0x98(%rsp), %rsi
xorl %edx, %edx
callq 0x2d134
testb %bpl, %bpl
je 0x3aaef
movq 0xa8(%rbx), %rdi
movq 0x98(%rsp), %rsi
testq %rdi, %rdi
je 0x3ab2d
callq 0x1daf1
testl %eax, %eax
je 0x3ab03
movq 0x50(%rbx), %rdi
leaq 0x498a3(%rip), %rsi     # 0x84358
callq 0x1f1db
movq %rax, %r14
movq 0xa8(%rbx), %r15
movq %r15, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x2d0f2
movq 0x50(%rbx), %rsi
movq %r14, %rdi
callq 0x6430
movq %r14, %rdi
callq 0x28c2d
jmp 0x3ab03
movq 0x98(%rsp), %rdi
callq 0x1c306
movq %rax, 0xa8(%rbx)
movq 0x98(%rsp), %rdi
callq 0x28c2d
movq %r13, %rdi
callq 0x28c2d
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rsi, %rsi
je 0x3ab03
movq 0x50(%rbx), %rdi
callq 0x6da0
jmp 0x3ab03