// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
testq %rdx, %rdx
je 0x45bde
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 0x45d5e
movq %rax, %r13
movslq %ebp, %rbp
movq %rax, %rdi
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
jmp 0x45be1
xorl %r13d, %r13d
testq %r13, %r13
movq %r13, %rdi
cmoveq %r14, %rdi
leaq 0xd408(%rip), %rsi      # 0x52ffa
callq 0x4600
movq %rax, %r12
testq %r13, %r13
je 0x45c07
movq %r13, %rdi
callq 0x4610
testq %r12, %r12
je 0x45d37
movl $0x1, %edi
movl $0x18, %esi
callq 0x4360
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x45cf9
movq %rsp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x47d0
cmpq $0x1, %rax
jne 0x45cf9
movl (%rsp), %eax
incl %eax
movq 0x48(%rbx), %r13
movl %eax, 0x4(%r13)
movl %eax, (%r13)
movslq %eax, %rdi
shlq $0x4, %rdi
callq 0x4700
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x45cf9
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x48(%rbx), %rax
cmpl $0x2, (%rax)
jl 0x45ce9
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 0x47d0
cmpq $0x1, %rax
jne 0x45cf9
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 0x45cf9
incq %r13
movq 0x48(%rbx), %rax
movslq (%rax), %rcx
addq $0x10, %rbp
cmpq %rcx, %r13
jl 0x45c8f
movq %r12, %rdi
callq 0x4530
testl %eax, %eax
je 0x45d8d
leaq 0x1e850(%rip), %rax     # 0x64550
cmpl $0x2, (%rax)
jge 0x45d74
movq %r12, %rdi
callq 0x4530
movq 0x48(%rbx), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x45d63
movq 0x8(%rax), %rdi
callq 0x4610
movq 0x48(%rbx), %rdi
callq 0x4610
movq $0x0, 0x48(%rbx)
jmp 0x45d63
leaq 0x1e812(%rip), %rax     # 0x64550
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, (%rax)
jl 0x45d63
xorl %edi, %edi
testq %r15, %r15
sete %dil
movq %r15, %rsi
movq %r14, %rdx
callq 0x5eac
jmp 0x45d63
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 0x5e59
jmp 0x45d05
xorl %ebp, %ebp
jmp 0x45d63