// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %rsi, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x38177
movq %r14, %rdi
callq 0x4210
movq %rax, %rbx
movq %r12, %rdi
callq 0x4210
movq %rax, %r13
addl %ebx, %eax
incl %eax
movslq %eax, %rdi
callq 0x46f0
testq %rax, %rax
je 0x382f2
movq %rax, %rbp
movslq %ebx, %rbx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4420
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 0x4420
jmp 0x38179
xorl %ebp, %ebp
testq %rbp, %rbp
movq %rbp, %rdi
cmoveq %r14, %rdi
leaq 0xbee0(%rip), %rsi      # 0x4406a
callq 0x45f0
movq %rax, %r13
movq %rbp, %rdi
callq 0x4600
testq %r13, %r13
je 0x38257
movq %r14, 0x8(%rsp)
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x4370
movq %rax, 0x48(%r15)
testq %rax, %rax
je 0x382be
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x38354
testl %eax, %eax
js 0x382be
movl 0x10(%rsp), %eax
incl %eax
movq 0x48(%r15), %rbx
movl %eax, 0x4(%rbx)
movl %eax, (%rbx)
movslq %eax, %rdi
shlq $0x4, %rdi
callq 0x46f0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x382be
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 0x382ae
movq 0x8(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
movq %r13, %rsi
callq 0x38354
testl %eax, %eax
js 0x382be
leaq 0x10(%rbp), %r14
movq 0x48(%r15), %rax
addq 0x8(%rax), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x38354
movq %r14, %rbp
testl %eax, %eax
jns 0x38208
jmp 0x382be
leaq 0x1f2ea(%rip), %rax     # 0x57548
cmpl $0x2, (%rax)
jl 0x382f2
testq %r12, %r12
movq 0x1ed5f(%rip), %rax     # 0x56fd0
movq (%rax), %rbx
leaq 0xb971(%rip), %r15      # 0x43bec
cmovneq %r12, %r15
callq 0x4060
movl (%rax), %edi
callq 0x4190
leaq 0xe999(%rip), %rsi      # 0x46c2b
leaq 0xea0b(%rip), %rdx      # 0x46ca4
movq %rbx, %rdi
movq %r14, %rcx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x4770
jmp 0x382f2
movq %r13, %rdi
callq 0x4530
testl %eax, %eax
je 0x38350
leaq 0x1f283(%rip), %rax     # 0x57548
cmpl $0x2, (%rax)
jge 0x38304
movq %r13, %rdi
callq 0x4530
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x382f2
movq 0x8(%rax), %rdi
callq 0x4600
movq 0x48(%r15), %rdi
callq 0x4600
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 0x1ecc2(%rip), %rax     # 0x56fd0
movq (%rax), %rbx
leaq 0xb8d4(%rip), %rbp      # 0x43bec
cmovneq %r12, %rbp
callq 0x4060
movl (%rax), %edi
callq 0x4190
leaq 0xe985(%rip), %rsi      # 0x46cb4
leaq 0xe96e(%rip), %rdx      # 0x46ca4
movq %rbx, %rdi
movq 0x8(%rsp), %rcx
movq %rbp, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x4770
jmp 0x382ca
xorl %eax, %eax
jmp 0x382f5