// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5ccc3
callq 0x5b9a0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x4, %edi
leaq 0x81f35(%rip), %rsi     # 0xdec0c
movb $0x0, %al
callq 0x60040
cmpq $0x0, 0xad952(%rip)     # 0x10a638
je 0x5cd01
movq 0xad949(%rip), %rdi     # 0x10a638
movq -0x10(%rbp), %rdx
leaq 0x81f27(%rip), %rsi     # 0xdec21
movb $0x0, %al
callq 0x6a80
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x5ca20
cmpq $0x0, -0x30(%rbp)
jne 0x5cd6a
movq -0x20(%rbp), %rdi
callq 0x40d40
leaq 0x81ee6(%rip), %rdi     # 0xdec2a
callq 0x2a450
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rdi
callq 0x40d40
movq -0x10(%rbp), %rdi
callq 0x2a450
movq %rax, -0x28(%rbp)
movl $0x1, -0x34(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5cfe0
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
movl $0x30, %esi
callq 0x5d190
cmpl $0x0, -0x34(%rbp)
jne 0x5ce1b
callq 0x5f810
cmpb $0x0, %al
je 0x5cdd2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5d1c0
movq %rax, -0x120(%rbp)
callq 0x5ed40
movl %eax, %ecx
movq -0x120(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
setb %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x5ce19
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
jne 0x5ce17
leaq -0x40(%rbp), %rdi
callq 0x5d2d0
movq -0x20(%rbp), %rdi
callq 0x40d40
movq -0x28(%rbp), %rdi
callq 0x40d40
movq $0x0, -0x8(%rbp)
jmp 0x5cfca
jmp 0x5ce19
jmp 0x5ce1b
movl $0x168, %edi            # imm = 0x168
callq 0x40c50
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x18(%rax)
cmpl $0x0, -0x34(%rbp)
je 0x5cecb
movq -0x10(%rbp), %rdi
callq 0x30cb0
cmpl $0x0, %eax
jne 0x5ce76
movq $0x0, -0x8(%rbp)
jmp 0x5cfca
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2fc90
movq -0x80(%rbp), %rcx
movl %eax, 0x58(%rcx)
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %edi
leaq -0x118(%rbp), %rsi
callq 0x6db0
movq -0x80(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0xe8(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x80(%rbp), %rax
movq %rcx, 0x80(%rax)
jmp 0x5cfb9
movq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x5ca60
cmpl $0x0, -0x44(%rbp)
jne 0x5cf6a
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x70(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, 0x90(%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x98(%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0xa0(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0xa8(%rax)
callq 0x5ed40
cmpl $0x0, %eax
jle 0x5cf68
callq 0x5f810
movsbl %al, %eax
cmpl $0x0, %eax
je 0x5cf68
movq -0x80(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x30cb0
cmpl $0x0, %eax
je 0x5cf68
movq -0x80(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x4b8b0
jmp 0x5cf6a
callq 0x5f810
cmpb $0x0, %al
je 0x5cfb7
movq -0x80(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6e720
movq -0x80(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x5d2f0
movq -0x80(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x2, %esi
callq 0x2fc90
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x80(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x5d590
jmp 0x5cfb9
movq -0x28(%rbp), %rdi
callq 0x40d40
movq -0x80(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)