// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/htslib/bgzf.c
// Function: bgzf_index_load
int bgzf_index_load(BGZF *fp, const char *bname, const char *suffix)
{
    char *tmp = NULL;
    if ( suffix )
    {
        int blen = strlen(bname);
        int slen = strlen(suffix);
        tmp = (char*) malloc(blen + slen + 1);
        if ( !tmp ) return -1;
        memcpy(tmp,bname,blen);
        memcpy(tmp+blen,suffix,slen+1);
    }

    FILE *idx = fopen(tmp?tmp:bname,"rb");
    if ( tmp ) free(tmp);
    if ( !idx ) return -1;

    fp->idx = (bgzidx_t*) calloc(1,sizeof(bgzidx_t));
    uint64_t x;
    if ( fread(&x, 1, sizeof(x), idx) != sizeof(x) ) return -1;

    fp->idx->noffs = fp->idx->moffs = 1 + (fp->is_be ? ed_swap_8(x) : x);
    fp->idx->offs  = (bgzidx1_t*) malloc(fp->idx->moffs*sizeof(bgzidx1_t));
    fp->idx->offs[0].caddr = fp->idx->offs[0].uaddr = 0;

    int i;
    if ( fp->is_be )
    {
        int ret = 0;
        for (i=1; i<fp->idx->noffs; i++)
        {
            ret += fread(&x, 1, sizeof(x), idx); fp->idx->offs[i].caddr = ed_swap_8(x);
            ret += fread(&x, 1, sizeof(x), idx); fp->idx->offs[i].uaddr = ed_swap_8(x);
        }
        if ( ret != sizeof(x)*2*(fp->idx->noffs-1) ) return -1;
    }
    else
    {
        int ret = 0;
        for (i=1; i<fp->idx->noffs; i++)
        {
            ret += fread(&x, 1, sizeof(x), idx); fp->idx->offs[i].caddr = x;
            ret += fread(&x, 1, sizeof(x), idx); fp->idx->offs[i].uaddr = x;
        }
        if ( ret != sizeof(x)*2*(fp->idx->noffs-1) ) return -1;
    }
    fclose(idx);
    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
testq %rdx, %rdx
je 0x68b93
movq %rdx, %r15
movq %r14, %rdi
callq 0x62d0
movq %rax, %rbp
movq %r15, %rdi
callq 0x62d0
movq %rax, %r13
addl %ebp, %eax
incl %eax
movslq %eax, %rdi
callq 0x69d0
testq %rax, %rax
je 0x68ce8
movq %rax, %r12
movslq %ebp, %rbp
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x6570
movq %r12, %rdi
addq %rbp, %rdi
shlq $0x20, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
sarq $0x20, %r13
movq %r15, %rsi
movq %r13, %rdx
callq 0x6570
jmp 0x68b96
xorl %r12d, %r12d
testq %r12, %r12
cmovneq %r12, %r14
leaq 0x25862(%rip), %rsi     # 0x8e406
movq %r14, %rdi
callq 0x6880
movq %rax, %r14
testq %r12, %r12
je 0x68bbc
movq %r12, %rdi
callq 0x68a0
testq %r14, %r14
je 0x68ce8
movl $0x1, %edi
movl $0x18, %esi
callq 0x6470
movq %rax, 0x48(%rbx)
leaq 0x8(%rsp), %rdi
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rcx
callq 0x6b20
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x8, %rax
jne 0x68ced
testl $0xc0000, (%rbx)        # imm = 0xC0000
movq 0x8(%rsp), %rax
movq %rax, %rcx
bswapq %rcx
cmovel %eax, %ecx
incl %ecx
movq 0x48(%rbx), %r15
movl %ecx, 0x4(%r15)
movl %ecx, (%r15)
movslq %ecx, %rdi
shlq $0x4, %rdi
callq 0x69d0
movq %rax, 0x8(%r15)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
testb $0xc, 0x2(%rbx)
movq 0x48(%rbx), %rax
movl (%rax), %eax
je 0x68cfe
xorl %r15d, %r15d
cmpl $0x2, %eax
jl 0x68d83
movl $0x1, %ebp
xorl %r12d, %r12d
movq %r14, 0x10(%rsp)
movl $0x1, %esi
movl $0x8, %edx
movq %rbx, %r14
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rcx
callq 0x6b20
movq %rax, %r13
movq 0x8(%rsp), %rax
bswapq %rax
addl %r15d, %r13d
movq 0x48(%r14), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x18(%rcx,%r12)
movl $0x1, %esi
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rbx
movq 0x10(%rsp), %r14
movq %r14, %rcx
callq 0x6b20
movq %rax, %r15
movq 0x8(%rsp), %rax
bswapq %rax
addl %r13d, %r15d
movq 0x48(%rbx), %rcx
movq 0x8(%rcx), %rdx
movq %rax, 0x10(%rdx,%r12)
incq %rbp
movslq (%rcx), %rax
addq $0x10, %r12
cmpq %rax, %rbp
jl 0x68c5e
jmp 0x68d7b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
cmpl $0x2, %eax
jl 0x68d83
movl $0x1, %ebp
xorl %r12d, %r12d
movl $0x1, %esi
movl $0x8, %edx
leaq 0x8(%rsp), %rdi
movq %r14, %rcx
callq 0x6b20
movq %rax, %r13
addl %r15d, %r13d
movq 0x8(%rsp), %rax
movq 0x48(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x18(%rcx,%r12)
movl $0x1, %esi
movl $0x8, %edx
leaq 0x8(%rsp), %rdi
movq %r14, %rcx
callq 0x6b20
movq %rax, %r15
addl %r13d, %r15d
movq 0x8(%rsp), %rax
movq 0x48(%rbx), %rcx
movq 0x8(%rcx), %rdx
movq %rax, 0x10(%rdx,%r12)
incq %rbp
movslq (%rcx), %rax
addq $0x10, %r12
cmpq %rax, %rbp
jl 0x68d0e
movslq %r15d, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cltq
shlq $0x4, %rax
addq $-0x10, %rax
cmpq %r15, %rax
jne 0x68ced
movq %r14, %rdi
callq 0x66e0
xorl %ebp, %ebp
jmp 0x68ced