// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdi, %rbx
testq %rdx, %rdx
je 0x68ca2
movq %rdx, %r14
movq %r15, %rdi
callq 0x62d0
movq %rax, %rbp
movq %r14, %rdi
callq 0x62d0
movq %rax, %r13
addl %ebp, %eax
incl %eax
movslq %eax, %rdi
callq 0x69d0
testq %rax, %rax
je 0x68dde
movq %rax, %r12
movslq %ebp, %rbp
movq %rax, %rdi
movq %r15, %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 %r14, %rsi
movq %r13, %rdx
callq 0x6570
leaq 0x257b9(%rip), %rsi     # 0x8e446
movq %r12, %rdi
callq 0x6880
movq %rax, %r14
movq %r12, %rdi
callq 0x68a0
jmp 0x68cb4
leaq 0x2579d(%rip), %rsi     # 0x8e446
movq %r15, %rdi
callq 0x6880
movq %rax, %r14
testq %r14, %r14
je 0x68dde
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, %r12d      # imm = 0xFFFFFFFF
cmpq $0x8, %rax
jne 0x68de4
testl $0xc0000, (%rbx)        # imm = 0xC0000
movq 0x8(%rsp), %rax
movq %rax, %r13
bswapq %r13
cmovel %eax, %r13d
leal 0x1(%r13), %ebp
movq 0x48(%rbx), %r15
movl %ebp, 0x4(%r15)
movl %ebp, (%r15)
movslq %ebp, %rdi
shlq $0x4, %rdi
callq 0x69d0
movq %rax, 0x8(%r15)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
testb $0xc, 0x2(%rbx)
je 0x68df6
xorl %r15d, %r15d
cmpl $0x2, %ebp
jl 0x68e83
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), %r13
addq $0x10, %r12
cmpq %r13, %rbp
jl 0x68d54
jmp 0x68e77
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
cmpl $0x2, %ebp
jl 0x68e83
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), %r13
addq $0x10, %r12
cmpq %r13, %rbp
jl 0x68e0a
movslq %r15d, %r15
decl %r13d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movslq %r13d, %rax
shlq $0x4, %rax
cmpq %r15, %rax
jne 0x68de4
movq %r14, %rdi
callq 0x66e0
xorl %r12d, %r12d
jmp 0x68de4