// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
testq %rdx, %rdx
je 0x2958e
movq %r14, %rdi
callq 0x3380
movq %rax, %rbp
movq %r15, %rdi
callq 0x3380
movq %rax, %r12
addl %ebp, %eax
incl %eax
movslq %eax, %rdi
callq 0x3240
testq %rax, %rax
je 0x2970e
movq %rax, %r13
movslq %ebp, %rbp
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x3850
movq %r13, %rdi
addq %rbp, %rdi
shlq $0x20, %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
sarq $0x20, %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x3850
jmp 0x29591
xorl %r13d, %r13d
testq %r13, %r13
movq %r13, %rdi
cmoveq %r14, %rdi
leaq 0x2425c(%rip), %rsi     # 0x4d7fe
callq 0x3250
movq %rax, %r12
testq %r13, %r13
je 0x295b7
movq %r13, %rdi
callq 0x3370
testq %r12, %r12
je 0x296e7
movl $0x1, %edi
movl $0x18, %esi
callq 0x36a0
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x296a9
movq %rsp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x35b0
cmpq $0x1, %rax
jne 0x296a9
movl (%rsp), %eax
incl %eax
movq 0x48(%rbx), %r13
movl %eax, 0x4(%r13)
movl %eax, (%r13)
movslq %eax, %rdi
shlq $0x4, %rdi
callq 0x3240
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x296a9
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x48(%rbx), %rax
cmpl $0x2, (%rax)
jl 0x29699
movl $0x1, %r13d
movl $0x10, %ebp
movq 0x8(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x35b0
cmpq $0x1, %rax
jne 0x296a9
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rdi
addq %rbp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x35b0
cmpq $0x1, %rax
jne 0x296a9
incq %r13
movq 0x48(%rbx), %rax
movslq (%rax), %rcx
addq $0x10, %rbp
cmpq %rcx, %r13
jl 0x2963f
movq %r12, %rdi
callq 0x36c0
testl %eax, %eax
je 0x2973d
leaq 0x34dd8(%rip), %rax     # 0x5e488
cmpl $0x2, (%rax)
jge 0x29724
movq %r12, %rdi
callq 0x36c0
movq 0x48(%rbx), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x29713
movq 0x8(%rax), %rdi
callq 0x3370
movq 0x48(%rbx), %rdi
callq 0x3370
movq $0x0, 0x48(%rbx)
jmp 0x29713
leaq 0x34d9a(%rip), %rax     # 0x5e488
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, (%rax)
jl 0x29713
xorl %edi, %edi
testq %r15, %r15
sete %dil
movq %r15, %rsi
movq %r14, %rdx
callq 0x4ade
jmp 0x29713
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
testq %r15, %r15
sete %dil
movq %r15, %rsi
movq %r14, %rdx
callq 0x4a8b
jmp 0x296b5
xorl %ebp, %ebp
jmp 0x29713