// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x44cc4
movq %r14, %rdi
callq 0x4230
movq %rax, %rbp
movq %r15, %rdi
callq 0x4230
movq %rax, %r12
addl %ebp, %eax
incl %eax
movslq %eax, %rdi
callq 0x4700
testq %rax, %rax
je 0x44e32
movq %rax, %r13
movslq %ebp, %rbp
movq %rax, %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4420
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 0x4420
leaq 0xc37d(%rip), %rsi      # 0x5102c
movq %r13, %rdi
callq 0x4600
movq %rax, %r12
movq %r13, %rdi
callq 0x4610
jmp 0x44cdb
leaq 0xc361(%rip), %rsi      # 0x5102c
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x4600
movq %rax, %r12
testq %r12, %r12
je 0x44e09
movl $0x1, %edi
movl $0x18, %esi
callq 0x4360
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x44dcb
leaq 0x10(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x47d0
cmpq $0x1, %rax
jne 0x44dcb
movl 0x10(%rsp), %ebp
incl %ebp
movq 0x48(%rbx), %r14
movl %ebp, 0x4(%r14)
movl %ebp, (%r14)
movslq %ebp, %rdi
shlq $0x4, %rdi
callq 0x4700
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x44dcb
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
cmpl $0x2, %ebp
jl 0x44dbb
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 0x47d0
cmpq $0x1, %rax
jne 0x44dcb
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rdi
addq %rbp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x47d0
cmpq $0x1, %rax
jne 0x44dcb
incq %r13
movq 0x48(%rbx), %r14
movslq (%r14), %rax
addq $0x10, %rbp
cmpq %rax, %r13
jl 0x44d61
movq %r12, %rdi
callq 0x4530
testl %eax, %eax
je 0x44e63
leaq 0x1d77e(%rip), %rax     # 0x62550
cmpl $0x2, (%rax)
jge 0x44e48
movq %r12, %rdi
callq 0x4530
movq 0x48(%rbx), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x44e37
movq 0x8(%rax), %rdi
callq 0x4610
movq 0x48(%rbx), %rdi
callq 0x4610
movq $0x0, 0x48(%rbx)
jmp 0x44e37
leaq 0x1d740(%rip), %rax     # 0x62550
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, (%rax)
jl 0x44e37
xorl %edi, %edi
testq %r15, %r15
sete %dil
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x5e0a
jmp 0x44e37
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 0x5db7
jmp 0x44dd7
xorl %ebp, %ebp
jmp 0x44e37