// File: /workspace/github_c_makefile_star2_O2/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, %r14
pushq $-0x1
popq %rbx
testq %rdx, %rdx
je 0x5d970
movq %rdx, %r12
movq %r15, %rdi
callq 0x62d0
movq %rax, %rbx
movq %r12, %rdi
callq 0x62d0
movq %rax, %rbp
addl %ebx, %eax
incl %eax
movslq %eax, %rdi
callq 0x69d0
testq %rax, %rax
je 0x5da9b
movq %rax, %r13
movslq %ebx, %rbx
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x6570
movq %r13, %rdi
addq %rbx, %rdi
shlq $0x20, %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbp
sarq $0x20, %rbp
movq %r12, %rsi
movq %rbp, %rdx
callq 0x6570
pushq $-0x1
popq %rbx
jmp 0x5d973
xorl %r13d, %r13d
testq %r13, %r13
cmovneq %r13, %r15
leaq 0x1fa65(%rip), %rsi     # 0x7d3e6
movq %r15, %rdi
callq 0x6880
movq %rax, %r15
movq %r13, %rdi
callq 0x68a0
movq %r15, 0x8(%rsp)
testq %r15, %r15
je 0x5db35
pushq $0x1
popq %rbx
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x6470
movq %rax, 0x48(%r14)
movq %rsp, %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
movq 0x8(%rsp), %rcx
callq 0x6b20
pushq $-0x1
popq %rbx
cmpq $0x8, %rax
jne 0x5db35
testl $0xc0000, (%r14)        # imm = 0xC0000
movq (%rsp), %rax
movq %rax, %rbx
bswapq %rbx
cmovel %eax, %ebx
incl %ebx
movq 0x48(%r14), %r12
movl %ebx, 0x4(%r12)
movl %ebx, (%r12)
movslq %ebx, %rdi
shlq $0x4, %rdi
callq 0x69d0
movq %rax, 0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
testb $0xc, 0x2(%r14)
movq %r14, 0x10(%rsp)
je 0x5daa3
xorl %r12d, %r12d
pushq $0x1
popq %r13
xorl %ebp, %ebp
movq 0x10(%rsp), %r15
movslq %ebx, %rax
cmpq %rax, %r13
jge 0x5db16
movq %rsp, %r14
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x6b20
movq (%rsp), %rdx
bswapq %rdx
addl %eax, %ebp
movq 0x48(%r15), %rax
movq 0x8(%rax), %rax
movq %rdx, 0x18(%rax,%r12)
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
movq %rbx, %rcx
callq 0x6b20
movq (%rsp), %rcx
bswapq %rcx
addl %ebp, %eax
movq 0x48(%r15), %rdx
movq 0x8(%rdx), %rsi
movq %rcx, 0x10(%rsi,%r12)
incq %r13
movl (%rdx), %ebx
addq $0x10, %r12
movl %eax, %ebp
jmp 0x5da2c
pushq $-0x1
popq %rbx
jmp 0x5db35
xorl %r12d, %r12d
pushq $0x1
popq %r13
xorl %ebp, %ebp
movq 0x10(%rsp), %r15
movslq %ebx, %rax
cmpq %rax, %r13
jge 0x5db16
movq %rsp, %r14
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x6b20
addl %eax, %ebp
movq (%rsp), %rax
movq 0x48(%r15), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x18(%rcx,%r12)
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
movq %rbx, %rcx
callq 0x6b20
addl %ebp, %eax
movq (%rsp), %rcx
movq 0x48(%r15), %rdx
movq 0x8(%rdx), %rsi
movq %rcx, 0x10(%rsi,%r12)
incq %r13
movl (%rdx), %ebx
addq $0x10, %r12
movl %eax, %ebp
jmp 0x5dab1
movslq %ebp, %rcx
shlq $0x4, %rax
addq $-0x10, %rax
cmpq %rcx, %rax
pushq $-0x1
popq %rbx
jne 0x5db35
movq 0x8(%rsp), %rdi
callq 0x66e0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq