// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, %r14
movq %rdi, %rbx
testq %rdx, %rdx
je 0x29478
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 0x295e6
movq %rax, %r13
movslq %ebp, %rbp
movq %rax, %rdi
movq %r14, 0x8(%rsp)
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
leaq 0x2439f(%rip), %rsi     # 0x4d802
movq %r13, %rdi
callq 0x3250
movq %rax, %r12
movq %r13, %rdi
callq 0x3370
jmp 0x2948f
leaq 0x24383(%rip), %rsi     # 0x4d802
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x3250
movq %rax, %r12
testq %r12, %r12
je 0x295bd
movl $0x1, %edi
movl $0x18, %esi
callq 0x36a0
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x2957f
leaq 0x10(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x35b0
cmpq $0x1, %rax
jne 0x2957f
movl 0x10(%rsp), %ebp
incl %ebp
movq 0x48(%rbx), %r14
movl %ebp, 0x4(%r14)
movl %ebp, (%r14)
movslq %ebp, %rdi
shlq $0x4, %rdi
callq 0x3240
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x2957f
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
cmpl $0x2, %ebp
jl 0x2956f
movl $0x1, %r13d
movl $0x10, %ebp
movq 0x8(%r14), %rax
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x35b0
cmpq $0x1, %rax
jne 0x2957f
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 0x2957f
incq %r13
movq 0x48(%rbx), %r14
movslq (%r14), %rax
addq $0x10, %rbp
cmpq %rax, %r13
jl 0x29515
movq %r12, %rdi
callq 0x36c0
testl %eax, %eax
je 0x29617
leaq 0x35f02(%rip), %rax     # 0x5f488
cmpl $0x2, (%rax)
jge 0x295fc
movq %r12, %rdi
callq 0x36c0
movq 0x48(%rbx), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x295eb
movq 0x8(%rax), %rdi
callq 0x3370
movq 0x48(%rbx), %rdi
callq 0x3370
movq $0x0, 0x48(%rbx)
jmp 0x295eb
leaq 0x35ec4(%rip), %rax     # 0x5f488
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, (%rax)
jl 0x295eb
xorl %edi, %edi
testq %r15, %r15
sete %dil
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x4a24
jmp 0x295eb
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 %edi, %edi
testq %r15, %r15
sete %dil
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x49d1
jmp 0x2958b
xorl %ebp, %ebp
jmp 0x295eb