// File: /workspace/github_c_makefile_star2_O2/zhou-lab[P]tbmate/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 ) {
        if (hts_verbose > 1) {
            fprintf(stderr, "[E::%s] Error opening %s%s : %s\n",
                    __func__, bname, suffix ? suffix : "", strerror(errno));
        }
        return -1;
    }

    fp->idx = (bgzidx_t*) calloc(1,sizeof(bgzidx_t));
    if (fp->idx == NULL) goto fail;
    uint64_t x;
    if (fread_uint64(&x, idx) < 0) goto fail;

    fp->idx->noffs = fp->idx->moffs = x + 1;
    fp->idx->offs  = (bgzidx1_t*) malloc(fp->idx->moffs*sizeof(bgzidx1_t));
    if (fp->idx->offs == NULL) goto fail;
    fp->idx->offs[0].caddr = fp->idx->offs[0].uaddr = 0;

    int i;
    for (i=1; i<fp->idx->noffs; i++)
    {
        if (fread_uint64(&fp->idx->offs[i].caddr, idx) < 0) goto fail;
        if (fread_uint64(&fp->idx->offs[i].uaddr, idx) < 0) goto fail;
    }

    if (fclose(idx) != 0) goto fail;
    return 0;

 fail:
    if (hts_verbose > 1)
    {
        fprintf(stderr, "[E::%s] Error reading %s%s : %s\n",
                __func__, bname, suffix ? suffix : "", strerror(errno));
    }
    fclose(idx);
    if (fp->idx) {
        free(fp->idx->offs);
        free(fp->idx);
        fp->idx = NULL;
    }
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x22087
movq %r14, %rdi
callq 0x3380
movq %rax, %rbx
movq %r12, %rdi
callq 0x3380
movq %rax, %r13
addl %ebx, %eax
incl %eax
movslq %eax, %rdi
callq 0x3240
testq %rax, %rax
je 0x22202
movq %rax, %rbp
movslq %ebx, %rbx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x3860
movq %rbp, %rdi
addq %rbx, %rdi
shlq $0x20, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
sarq $0x20, %r13
movq %r12, %rsi
movq %r13, %rdx
callq 0x3860
jmp 0x22089
xorl %ebp, %ebp
testq %rbp, %rbp
movq %rbp, %rdi
cmoveq %r14, %rdi
leaq 0x1d768(%rip), %rsi     # 0x3f802
callq 0x3250
movq %rax, %r13
movq %rbp, %rdi
callq 0x3370
testq %r13, %r13
je 0x22167
movq %r14, 0x8(%rsp)
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x36b0
movq %rax, 0x48(%r15)
testq %rax, %rax
je 0x221ce
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x22264
testl %eax, %eax
js 0x221ce
movl 0x10(%rsp), %eax
incl %eax
movq 0x48(%r15), %rbx
movl %eax, 0x4(%rbx)
movl %eax, (%rbx)
movslq %eax, %rdi
shlq $0x4, %rdi
callq 0x3240
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x221ce
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
pushq $0x10
popq %rbp
xorl %ebx, %ebx
movq 0x48(%r15), %rax
movslq (%rax), %rcx
incq %rbx
cmpq %rcx, %rbx
jge 0x221be
movq 0x8(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
movq %r13, %rsi
callq 0x22264
testl %eax, %eax
js 0x221ce
leaq 0x10(%rbp), %r14
movq 0x48(%r15), %rax
addq 0x8(%rax), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x22264
movq %r14, %rbp
testl %eax, %eax
jns 0x22118
jmp 0x221ce
leaq 0x31322(%rip), %rax     # 0x53490
cmpl $0x2, (%rax)
jl 0x22202
testq %r12, %r12
movq 0x30e67(%rip), %rax     # 0x52fe8
movq (%rax), %rbx
leaq 0x1e1b4(%rip), %r15     # 0x4033f
cmovneq %r12, %r15
callq 0x35e0
movl (%rax), %edi
callq 0x34e0
leaq 0x1fd86(%rip), %rsi     # 0x41f28
leaq 0x1fdf8(%rip), %rdx     # 0x41fa1
movq %rbx, %rdi
movq %r14, %rcx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x37f0
jmp 0x22202
movq %r13, %rdi
callq 0x36d0
testl %eax, %eax
je 0x22260
leaq 0x312bb(%rip), %rax     # 0x53490
cmpl $0x2, (%rax)
jge 0x22214
movq %r13, %rdi
callq 0x36d0
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x22202
movq 0x8(%rax), %rdi
callq 0x3370
movq 0x48(%r15), %rdi
callq 0x3370
andq $0x0, 0x48(%r15)
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r12, %r12
movq 0x30dca(%rip), %rax     # 0x52fe8
movq (%rax), %rbx
leaq 0x1e117(%rip), %rbp     # 0x4033f
cmovneq %r12, %rbp
callq 0x35e0
movl (%rax), %edi
callq 0x34e0
leaq 0x1fd72(%rip), %rsi     # 0x41fb1
leaq 0x1fd5b(%rip), %rdx     # 0x41fa1
movq %rbx, %rdi
movq 0x8(%rsp), %rcx
movq %rbp, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x37f0
jmp 0x221da
xorl %eax, %eax
jmp 0x22205