// File: /workspace/github_c_makefile_star2_O3/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
movl $0x2, %esi
xorl %eax, %eax
callq 0x6d10
movl %eax, %ebx
testl %eax, %eax
jns 0x41560
callq 0x6060
cmpl $0x2, (%rax)
je 0x4157d
leaq 0x53f56(%rip), %rdi     # 0x954ac
movq %r14, %rsi
xorl %eax, %eax
callq 0x26fc7
leaq 0x8(%rsp), %r15
movl %ebx, %edi
movq %r15, %rsi
callq 0x6db0
cmpq $0x3f, 0x30(%r15)
jg 0x41585
movl %ebx, %edi
callq 0x6e80
xorl %r14d, %r14d
jmp 0x41654
leaq 0x4(%rsp), %r15
movl $0x4, %edx
movl %ebx, %edi
movq %r15, %rsi
callq 0x234a5
movl (%r15), %edi
xorl %ebp, %ebp
cmpl $0x4187e2f6, %edi       # imm = 0x4187E2F6
je 0x415cc
callq 0x239ea
movl %eax, 0x4(%rsp)
movl $0x1, %ebp
cmpl $0x4187e2f6, %eax       # imm = 0x4187E2F6
je 0x415cc
leaq 0x53f01(%rip), %rdi     # 0x954c3
movq %r14, %rsi
xorl %eax, %eax
callq 0x26e94
movl $0x40, %edi
callq 0x2dff4
movq %rax, %r14
movl %ebx, %edi
movl %ebp, %esi
callq 0x23a1b
movl %eax, 0x8(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x239a3
movq %rax, 0x10(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x239a3
movq %rax, 0x18(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x23a1b
movl %eax, 0x20(%r14)
movl %ebx, %edi
movl %ebp, %esi
callq 0x23a1b
movl %ebx, %edi
movl %ebp, %esi
callq 0x239a3
movl %ebx, %edi
movl %ebp, %esi
callq 0x239a3
movl %ebx, %edi
movl %ebp, %esi
callq 0x239a3
movl %ebx, %edi
movl %ebp, %esi
callq 0x239a3
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