// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/udc.c
// Function: udcBitmapOpen
static struct udcBitmap *udcBitmapOpen(char *fileName)
/* Open up a bitmap file and read and verify header.  Return NULL if file doesn't
 * exist, abort on error. */
{
/* Open file, returning NULL if can't. */
int fd = open(fileName, O_RDWR);
if (fd < 0)
    {
    if (errno == ENOENT)
	return NULL;
    else
	errnoAbort("Can't open(%s, O_RDWR)", fileName);
    }

/* Get status info from file. */
struct stat status;
fstat(fd, &status);
if (status.st_size < udcBitmapHeaderSize) // check for truncated invalid bitmap files.
    {
    close(fd);
    return NULL;  // returning NULL will cause the fresh creation of bitmap and sparseData files.
    }  

/* Read signature and decide if byte-swapping is needed. */
// TODO: maybe buffer the I/O for performance?  Don't read past header - 
// fd offset needs to point to first data block when we return.
bits32 magic;
boolean isSwapped = FALSE;
mustReadOneFd(fd, magic);
if (magic != udcBitmapSig)
    {
    magic = byteSwap32(magic);
    isSwapped = TRUE;
    if (magic != udcBitmapSig)
       errAbort("%s is not a udcBitmap file", fileName);
    }

/* Allocate bitmap object, fill it in, and return it. */
struct udcBitmap *bits;
AllocVar(bits);
bits->blockSize = fdReadBits32(fd, isSwapped);
bits->remoteUpdate = fdReadBits64(fd, isSwapped);
bits->fileSize = fdReadBits64(fd, isSwapped);
bits->version = fdReadBits32(fd, isSwapped);
fdReadBits32(fd, isSwapped); // ignore result
fdReadBits64(fd, isSwapped); // ignore result
fdReadBits64(fd, isSwapped); // ignore result
fdReadBits64(fd, isSwapped); // ignore result
fdReadBits64(fd, isSwapped); // ignore result
bits->localUpdate = status.st_mtime;
bits->localAccess = status.st_atime;
bits->isSwapped = isSwapped;
bits->fd = fd;

return bits;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x6d10
movl %eax, %ebx
testl %eax, %eax
jns 0x3b345
callq 0x6060
cmpl $0x2, (%rax)
je 0x3b362
leaq 0x49071(%rip), %rdi     # 0x843ac
movq %r14, %rsi
xorl %eax, %eax
callq 0x22504
leaq 0x8(%rsp), %r15
movl %ebx, %edi
movq %r15, %rsi
callq 0x6db0
cmpq $0x3f, 0x30(%r15)
jg 0x3b36a
movl %ebx, %edi
callq 0x6e80
xorl %r14d, %r14d
jmp 0x3b433
leaq 0x4(%rsp), %r15
pushq $0x4
popq %rdx
movl %ebx, %edi
movq %r15, %rsi
callq 0x1f096
movl (%r15), %edi
xorl %ebp, %ebp
cmpl $0x4187e2f6, %edi       # imm = 0x4187E2F6
je 0x3b3ad
callq 0x1f5a0
movl %eax, 0x4(%rsp)
pushq $0x1
popq %rbp
cmpl $0x4187e2f6, %eax       # imm = 0x4187E2F6
je 0x3b3ad
leaq 0x49020(%rip), %rdi     # 0x843c3
movq %r14, %rsi
xorl %eax, %eax
callq 0x223fb
pushq $0x40
popq %rdi
callq 0x28bb0
movq %rax, %r14
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f5cf
movl %eax, 0x8(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f55b
movq %rax, 0x10(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f55b
movq %rax, 0x18(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f5cf
movl %eax, 0x20(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f5cf
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f55b
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f55b
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f55b
movl %ebx, %edi
movl %ebp, %esi
callq 0x1f55b
movq 0x60(%rsp), %rax
movq %rax, 0x28(%r14)
movq 0x50(%rsp), %rax
movq %rax, 0x30(%r14)
movl %ebp, 0x38(%r14)
movl %ebx, 0x3c(%r14)
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq