// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/nib.c
// Function: nibOpenVerify
void nibOpenVerify(char *fileName, FILE **retFile, int *retSize)
/* Open file and verify it's in good nibble format. */
{
bits32 size;
bits32 sig;
FILE *f = fopen(fileName, "rb");
char buffer[512];
char buffer2[512];
char buffer3[512];

if (f == NULL)
    {
    /* see if nib is down a few directories ala faSplit -outDirDepth */
    char *ptr = NULL;
    char *dir, *file;
    struct stat statBuf;

    /* divide fileName into file and directory components */
    safef(buffer, sizeof(buffer), "%s", fileName);
    if ((ptr = strrchr(buffer, '/')) != NULL)
	{
	*ptr++ = 0;
	dir = buffer;
	file = ptr;
	}
    else
	{
	dir = "";
	file = buffer;
	}
    
    buffer3[0] = 0;
    /* start at the end of the fileName (minus .nib) */
    for(ptr = &file[strlen(file) - 5]; ; )
	{
	strcpy(buffer2, buffer3);
	if (isdigit(*ptr))
	    {
	    /* if we have a digit in the fileName, see if there is a directory with this name */
	    safef(buffer3, sizeof(buffer3), "%c/%s",*ptr,buffer2);
	    ptr--;
	    }
	else
	    /* we've run out of digits in the fileName, just add 0's */
	    safef(buffer3, sizeof(buffer3), "0/%s",buffer2);

	/* check to see if this directory exists */
	safef(buffer2, sizeof(buffer2), "%s/%s", dir, buffer3);
	if (stat(buffer2, &statBuf) < 0)
	    break;

	/* directory exists, see if our file is down there */
	safef(buffer2, sizeof(buffer2), "%s/%s/%s", dir, buffer3, file);
	if  ((f = fopen(buffer2, "rb")) != NULL)
	    break;
	}
    if (f == NULL)
	errAbort("Can't open %s to read: %s", fileName,  strerror(errno));
    }
dnaUtilOpen();
mustReadOne(f, sig);
mustReadOne(f, size);
if (sig != nibSig)
    {
    sig = byteSwap32(sig);
    size = byteSwap32(size);
    if (sig != nibSig)
	errAbort("%s is not a good .nib file.",  fileName);
    }
*retSize = size;
*retFile = f;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6f0, %rsp            # imm = 0x6F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x91d7c(%rip), %rsi     # 0xd833e
callq 0x67e0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4680b
movq $0x0, -0x638(%rbp)
leaq -0x230(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x200, %esi            # imm = 0x200
leaq 0x93a19(%rip), %rdx     # 0xda011
movb $0x0, %al
callq 0x31090
leaq -0x230(%rbp), %rdi
movl $0x2f, %esi
callq 0x67b0
movq %rax, -0x638(%rbp)
cmpq $0x0, %rax
je 0x46653
movq -0x638(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x638(%rbp)
movb $0x0, (%rax)
leaq -0x230(%rbp), %rax
movq %rax, -0x640(%rbp)
movq -0x638(%rbp), %rax
movq %rax, -0x648(%rbp)
jmp 0x4666f
leaq 0x9edac(%rip), %rax     # 0xe5406
movq %rax, -0x640(%rbp)
leaq -0x230(%rbp), %rax
movq %rax, -0x648(%rbp)
movb $0x0, -0x630(%rbp)
movq -0x648(%rbp), %rax
movq %rax, -0x6e0(%rbp)
movq -0x648(%rbp), %rdi
callq 0x62c0
movq %rax, %rcx
movq -0x6e0(%rbp), %rax
subq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x638(%rbp)
leaq -0x430(%rbp), %rdi
leaq -0x630(%rbp), %rsi
callq 0x6680
callq 0x6780
movq (%rax), %rax
movq -0x638(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x4671d
leaq -0x630(%rbp), %rdi
movq -0x638(%rbp), %rax
movsbl (%rax), %ecx
leaq -0x430(%rbp), %r8
movl $0x200, %esi            # imm = 0x200
leaq 0x962c9(%rip), %rdx     # 0xdc9cb
movb $0x0, %al
callq 0x31090
movq -0x638(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x638(%rbp)
jmp 0x4673e
leaq -0x630(%rbp), %rdi
leaq -0x430(%rbp), %rcx
movl $0x200, %esi            # imm = 0x200
leaq 0x9629a(%rip), %rdx     # 0xdc9d1
movb $0x0, %al
callq 0x31090
leaq -0x430(%rbp), %rdi
movq -0x640(%rbp), %rcx
leaq -0x630(%rbp), %r8
movl $0x200, %esi            # imm = 0x200
leaq 0x9627a(%rip), %rdx     # 0xdc9d9
movb $0x0, %al
callq 0x31090
leaq -0x430(%rbp), %rdi
leaq -0x6d8(%rbp), %rsi
callq 0x6d00
cmpl $0x0, %eax
jge 0x46780
jmp 0x467d3
leaq -0x430(%rbp), %rdi
movq -0x640(%rbp), %rcx
leaq -0x630(%rbp), %r8
movq -0x648(%rbp), %r9
movl $0x200, %esi            # imm = 0x200
leaq 0x9622e(%rip), %rdx     # 0xdc9d6
movb $0x0, %al
callq 0x31090
leaq -0x430(%rbp), %rdi
leaq 0x91b81(%rip), %rsi     # 0xd833e
callq 0x67e0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x467ce
jmp 0x467d3
jmp 0x466a8
cmpq $0x0, -0x28(%rbp)
jne 0x46809
movq -0x8(%rbp), %rax
movq %rax, -0x6e8(%rbp)
callq 0x6060
movl (%rax), %edi
callq 0x6220
movq -0x6e8(%rbp), %rsi
movq %rax, %rdx
leaq 0x961dd(%rip), %rdi     # 0xdc9df
movb $0x0, %al
callq 0x35d40
jmp 0x4680b
movb $0x0, %al
callq 0x34580
movq -0x28(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x2f920
movq -0x28(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0x4, %edx
callq 0x2f920
cmpl $0x6be93d3a, -0x20(%rbp) # imm = 0x6BE93D3A
je 0x46872
movl -0x20(%rbp), %edi
callq 0x30770
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %edi
callq 0x30770
movl %eax, -0x1c(%rbp)
cmpl $0x6be93d3a, -0x20(%rbp) # imm = 0x6BE93D3A
je 0x46870
movq -0x8(%rbp), %rsi
leaq 0x96190(%rip), %rdi     # 0xdc9f9
movb $0x0, %al
callq 0x35d40
jmp 0x46872
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
addq $0x6f0, %rsp            # imm = 0x6F0
popq %rbp
retq
nop