// File: /workspace/github_c_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rsi, %r12
movq %rdi, %r14
testq %rsi, %rsi
jne 0x405f4
movq 0x806a4(%rip), %r12     # 0xc0c98
leaq 0x5481e(%rip), %rsi     # 0x94e19
movl $0x4, %edi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x427e5
movq 0x83be4(%rip), %rdi     # 0xc41f8
testq %rdi, %rdi
je 0x4062a
leaq 0x5480e(%rip), %rsi     # 0x94e2e
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
xorl %eax, %eax
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x98(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x40250
movq (%rbx), %rbp
testq %rbp, %rbp
je 0x406e9
movq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x40d30
movq %rax, %r13
movq %rax, 0x48(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x80(%rsp)
movdqa %xmm0, 0x70(%rsp)
movdqa %xmm0, 0x60(%rsp)
cmpq $0x0, 0x80604(%rip)     # 0xc0c98
je 0x406ba
movq %r14, %rdi
movq %r12, %rsi
callq 0x40e54
movslq 0x83b58(%rip), %rcx     # 0xc4200
cmpq %rcx, %rax
jae 0x406ba
movl $0x0, 0xc(%rsp)
jmp 0x4074d
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
callq *0x10(%r13)
movb $0x1, %cl
movl %ecx, 0xc(%rsp)
testl %eax, %eax
jne 0x4074d
leaq 0x48(%rsp), %rdi
callq 0x2e0b0
movq %r15, %rdi
callq 0x2e0a0
xorl %ebx, %ebx
jmp 0x40895
movq 0x28(%rsp), %rdi
callq 0x2e0a0
leaq 0x5473d(%rip), %rdi     # 0x94e37
callq 0x1feba
movq %rax, %r15
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rdi
callq 0x2e0a0
movq %r14, %rdi
callq 0x1feba
movq %rax, 0x20(%rsp)
movq %r15, %rdi
callq 0x40d30
movq %rax, %r13
movq %rax, 0x48(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x80(%rsp)
movdqa %xmm0, 0x70(%rsp)
movdqa %xmm0, 0x60(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x168, %edi            # imm = 0x168
callq 0x2dff4
movq %rax, %rbx
movq %r14, %rdi
callq 0x1feba
movq %rax, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %r13, 0x18(%rbx)
testq %rbp, %rbp
je 0x40853
movq 0x20(%rsp), %r13
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x40420
movl 0xc(%rsp), %ebp
testb %bpl, %bpl
je 0x407ef
movaps 0x60(%rsp), %xmm0
movups %xmm0, 0x20(%rbx)
movdqa 0x70(%rsp), %xmm0
movdqa 0x80(%rsp), %xmm1
movdqu %xmm1, 0xa0(%rbx)
movdqu %xmm0, 0x90(%rbx)
cmpl $0x0, 0x83a3b(%rip)     # 0xc4200
setle %cl
movq 0x804c9(%rip), %rax     # 0xc0c98
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x407f6
movq 0x40(%rbx), %rdi
callq 0x23c5d
testl %eax, %eax
je 0x407ef
movq 0x40(%rbx), %rdi
callq 0x354ba
movq 0x804a2(%rip), %rax     # 0xc0c98
testq %rax, %rax
je 0x40d03
movq 0x38(%rbx), %rdi
callq 0x4bfb8
movq 0x40(%rbx), %rdi
callq 0x41523
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x4089f
movq %rax, %r12
testb %bpl, %bpl
je 0x408ca
movq 0x10(%r12), %rax
movl 0x20(%r12), %r14d
cmpq 0x20(%rbx), %rax
jne 0x40918
movq 0x18(%r12), %rax
cmpq 0x28(%rbx), %rax
je 0x408db
jmp 0x40918
movq %r14, %rdi
callq 0x23c5d
testl %eax, %eax
je 0x408c3
movq %r14, %rdi
xorl %esi, %esi
callq 0x233f6
movl %eax, 0x58(%rbx)
leaq 0xa8(%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)
movq 0x20(%rsp), %r13
jmp 0x40d03
movq %r13, 0x40(%rsp)
movq 0x40(%rbx), %rdx
leaq 0x54b16(%rip), %rsi     # 0x953c5
xorl %r14d, %r14d
movl $0x4, %edi
xorl %eax, %eax
callq 0x427e5
jmp 0x4098e
xorl %ebx, %ebx
jmp 0x40d0b
movdqu 0x10(%r12), %xmm0
movdqu %xmm0, 0x20(%rbx)
movl 0x20(%r12), %r14d
movq 0x48(%rbx), %rdi
callq 0x23c5d
testl %eax, %eax
je 0x40918
movq 0x48(%rbx), %rdi
callq 0x34694
testq %rax, %rax
jne 0x40b90
cmpq $0x0, 0x28(%rbx)
je 0x40b90
movq 0x40(%rbx), %rdi
callq 0x34694
cmpq $0x41, %rax
jl 0x40b90
movq 0x10(%r12), %rdx
movq 0x18(%r12), %r8
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %r9
leaq 0x54a21(%rip), %rsi     # 0x95352
movl $0x4, %edi
xorl %eax, %eax
pushq %r14
pushq 0x48(%rbx)
callq 0x427e5
addq $0x10, %rsp
leaq 0x10(%rsp), %rdi
callq 0x41195
movq 0x40(%rbx), %rdi
callq 0x6da0
movq 0x48(%rbx), %rdi
callq 0x6da0
movq 0x50(%rbx), %rdi
callq 0x23c5d
testl %eax, %eax
je 0x40978
movq 0x50(%rbx), %rdi
callq 0x6da0
movq 0x10(%rsp), %r12
testq %r12, %r12
jne 0x40b90
movq %r13, 0x40(%rsp)
incl %r14d
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %r12
leaq 0xa8(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x50(%rsp), %rax
movq %r12, (%rax)
leaq 0x3c(%rsp), %rax
movl %r14d, (%rax)
movq 0x40(%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
callq 0x233f6
movl %eax, %ebp
movl %eax, 0x38(%rsp)
leaq 0x5c(%rsp), %rsi
movl $0x4187e2f6, (%rsi)     # imm = 0x4187E2F6
leaq 0x58(%rsp), %r13
movl $0x2000, (%r13)         # imm = 0x2000
leaq 0xa0(%rsp), %r14
movq $0x0, (%r14)
leaq 0x34(%rsp), %rax
movl $0x0, (%rax)
movl $0x4, %edx
movl %ebp, %edi
callq 0x23517
movl $0x4, %edx
movl %ebp, %edi
movq %r13, %rsi
callq 0x23517
movl $0x8, %edx
movl %ebp, %edi
leaq 0xa8(%rsp), %rsi
callq 0x23517
movl $0x8, %edx
movl %ebp, %edi
leaq 0x50(%rsp), %rsi
callq 0x23517
movl $0x4, %edx
movl %ebp, %edi
leaq 0x3c(%rsp), %rsi
callq 0x23517
movl $0x4, %edx
movl %ebp, %edi
leaq 0x34(%rsp), %rsi
callq 0x23517
movl $0x8, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x23517
movl $0x8, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x23517
movl $0x8, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x23517
movl $0x8, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x23517
incq 0xb8(%rbx)
movl %ebp, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23550
cmpq $0x40, %rax
je 0x40acd
movq 0x40(%rbx), %rdx
leaq 0x5495a(%rip), %rdi     # 0x95415
movl %ebp, %esi
movq %rax, %rcx
movl $0x40, %r8d
xorl %eax, %eax
callq 0x26e94
addq $0x1fff, %r12           # imm = 0x1FFF
shrq $0xd, %r12
leal 0x7(%r12), %eax
addl $0xe, %r12d
testl %eax, %eax
cmovnsl %eax, %r12d
sarl $0x3, %r12d
leaq 0x1f(%rsp), %r14
movb $0x0, (%r14)
decl %r12d
movslq %r12d, %rsi
incq 0xb8(%rbx)
movl %ebp, %edi
movl $0x1, %edx
callq 0x23550
movdqu 0xd0(%rbx), %xmm0
pcmpeqd %xmm1, %xmm1
psubq %xmm1, %xmm0
movdqu %xmm0, 0xd0(%rbx)
movl $0x1, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x23517
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0x235bf
movq 0x48(%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
callq 0x233f6
movl %eax, (%r14)
movq %r14, %rdi
callq 0x235bf
movq 0x40(%rbx), %rdi
callq 0x41523
movq %rax, %r12
movq %rax, 0x10(%rsp)
testq %rax, %rax
movq 0x40(%rsp), %r13
movl 0xc(%rsp), %ebp
jne 0x40b90
movq 0x40(%rbx), %rsi
leaq 0x54873(%rip), %rdi     # 0x953f7
xorl %eax, %eax
callq 0x26e94
movq 0x10(%rsp), %r12
movl 0x20(%r12), %eax
movl %eax, 0x88(%rbx)
cmpq $0x0, 0x28(%rbx)
je 0x40c1f
movl 0x3c(%r12), %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x65b0
movq %rax, %r14
movq 0x10(%rsp), %rax
movl 0x3c(%rax), %edi
leaq 0xa8(%rsp), %r12
movl $0x1, %edx
movq %r12, %rsi
callq 0x234a5
movl $0x1fff, %eax           # imm = 0x1FFF
addq 0x28(%rbx), %rax
shrq $0xd, %rax
cmpl $0x8, %eax
movl $0x8, %edx
cmovll %eax, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x1be37
shll $0xd, %eax
cltq
movq %rax, 0x80(%rbx)
movq 0x10(%rsp), %rax
movl 0x3c(%rax), %edi
incq 0xb8(%rbx)
movq %r14, %rsi
xorl %edx, %edx
callq 0x23550
movq 0x10(%rsp), %r12
movq %r12, 0x70(%rbx)
movq 0x48(%rbx), %rdi
movl $0x2, %esi
callq 0x233f6
movl %eax, 0x58(%rbx)
leaq 0x51357(%rip), %rdi     # 0x91f92
movq %r15, %rsi
callq 0x21b23
testl %eax, %eax
je 0x40d03
movq $0x0, 0xa8(%rsp)
movq 0x50(%rbx), %rdi
callq 0x23c5d
testl %eax, %eax
je 0x40c77
movq 0x50(%rbx), %rdi
leaq 0xa8(%rsp), %rsi
xorl %edx, %edx
callq 0x3280a
testb %bpl, %bpl
je 0x40ce2
movq 0xa8(%rbx), %rdi
movq 0xa8(%rsp), %rsi
testq %rdi, %rdi
je 0x40d20
callq 0x21acd
testl %eax, %eax
je 0x40cf6
movq 0x50(%rbx), %rdi
leaq 0x547b0(%rip), %rsi     # 0x95458
callq 0x235ed
movq %rax, %r14
movq 0xa8(%rbx), %r15
movq %r15, %rdi
callq 0x62d0
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x327c8
movq 0x50(%rbx), %rsi
movq %r14, %rdi
callq 0x6430
movq %r14, %rdi
callq 0x2e0a0
jmp 0x40cf6
movq 0xa8(%rsp), %rdi
callq 0x1feba
movq %rax, 0xa8(%rbx)
movq 0xa8(%rsp), %rdi
callq 0x2e0a0
movq %r13, %rdi
callq 0x2e0a0
movq %rbx, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rsi, %rsi
je 0x40cf6
movq 0x50(%rbx), %rdi
callq 0x6da0
jmp 0x40cf6