// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/hts.c
// Function: hts_idx_load_core
static int hts_idx_load_core(hts_idx_t *idx, BGZF *fp, int fmt)
{
    int32_t i, n, is_be;
    is_be = ed_is_big();
    if (idx == NULL) return -4;
    for (i = 0; i < idx->n; ++i) {
        bidx_t *h;
        lidx_t *l = &idx->lidx[i];
        uint32_t key;
        int j, absent;
        bins_t *p;
        h = idx->bidx[i] = kh_init(bin);
        if (bgzf_read(fp, &n, 4) != 4) return -1;
        if (is_be) ed_swap_4p(&n);
        for (j = 0; j < n; ++j) {
            khint_t k;
            if (bgzf_read(fp, &key, 4) != 4) return -1;
            if (is_be) ed_swap_4p(&key);
            k = kh_put(bin, h, key, &absent);
            if (absent <= 0) return -3; // Duplicate bin number
            p = &kh_val(h, k);
            if (fmt == HTS_FMT_CSI) {
                if (bgzf_read(fp, &p->loff, 8) != 8) return -1;
                if (is_be) ed_swap_8p(&p->loff);
            } else p->loff = 0;
            if (bgzf_read(fp, &p->n, 4) != 4) return -1;
            if (is_be) ed_swap_4p(&p->n);
            p->m = p->n;
            p->list = (hts_pair64_t*)malloc(p->m * sizeof(hts_pair64_t));
            if (p->list == NULL) return -2;
            if (bgzf_read(fp, p->list, p->n<<4) != p->n<<4) return -1;
            if (is_be) swap_bins(p);
        }
        if (fmt != HTS_FMT_CSI) { // load linear index
            int j;
            if (bgzf_read(fp, &l->n, 4) != 4) return -1;
            if (is_be) ed_swap_4p(&l->n);
            l->m = l->n;
            l->offset = (uint64_t*)malloc(l->n * sizeof(uint64_t));
            if (l->offset == NULL) return -2;
            if (bgzf_read(fp, l->offset, l->n << 3) != l->n << 3) return -1;
            if (is_be) for (j = 0; j < l->n; ++j) ed_swap_8p(&l->offset[j]);
            for (j = 1; j < l->n; ++j) // fill missing values; may happen given older samtools and tabix
                if (l->offset[j] == 0) l->offset[j] = l->offset[j-1];
            update_loff(idx, i, 1);
        }
    }
    if (bgzf_read(fp, &idx->n_no_coor, 8) != 8) idx->n_no_coor = 0;
    if (is_be) ed_swap_8p(&idx->n_no_coor);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, 0x1c(%rsp)
movq %rsi, 0x10(%rsp)
testq %rdi, %rdi
je 0x14058
movq %rdi, %r14
cmpl $0x0, 0x14(%rdi)
jle 0x14031
xorl %r12d, %r12d
leaq 0xc(%rsp), %r13
movq %r14, 0x28(%rsp)
movq %r12, %r15
shlq $0x4, %r15
addq 0x30(%r14), %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x4360
movq %rax, %rbp
movq 0x28(%r14), %rax
movq %rbp, (%rax,%r12,8)
movl $0x4, %edx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x43873
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jne 0x14072
movq %r12, 0x30(%rsp)
cmpl $0x0, 0xc(%rsp)
movq 0x10(%rsp), %r14
jle 0x13f68
xorl %r12d, %r12d
movl $0x4, %edx
movq %r14, %rdi
leaq 0x24(%rsp), %rsi
callq 0x43873
cmpq $0x4, %rax
jne 0x1405f
movl 0x24(%rsp), %esi
movq %rbp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x139ac
cmpl $0x0, 0x20(%rsp)
jle 0x1406d
movq 0x20(%rbp), %rbx
movl %eax, %eax
leaq (%rax,%rax,2), %r13
leaq (%rbx,%r13,8), %rsi
addq $0x8, %rsi
cmpl $0x0, 0x1c(%rsp)
je 0x13ed2
movq $0x0, (%rsi)
jmp 0x13ee9
movl $0x8, %edx
movq %r14, %rdi
callq 0x43873
cmpq $0x8, %rax
jne 0x1405f
leaq (%rbx,%r13,8), %rbx
leaq 0x4(%rbx), %r13
movl $0x4, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x43873
cmpq $0x4, %rax
jne 0x1405f
movslq 0x4(%rbx), %r14
movl %r14d, (%rbx)
movq %r14, %rdi
shlq $0x4, %rdi
callq 0x4700
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x14066
shll $0x4, %r14d
movslq %r14d, %rdx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x43873
movl (%r13), %ecx
shll $0x4, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x1405f
incl %r12d
cmpl 0xc(%rsp), %r12d
leaq 0xc(%rsp), %r13
jl 0x13e78
cmpl $0x0, 0x1c(%rsp)
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %r12
je 0x14021
movl $0x4, %edx
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x43873
cmpq $0x4, %rax
jne 0x1405f
movslq (%r15), %rbx
movl %ebx, 0x4(%r15)
movq %rbx, %rdi
shlq $0x3, %rdi
callq 0x4700
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x14066
leal (,%rbx,8), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x43873
movl (%r15), %ecx
leal (,%rcx,8), %edx
movslq %edx, %rdx
cmpq %rdx, %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jne 0x14072
cmpl $0x2, %ecx
jl 0x14011
movq 0x8(%r15), %rax
movl $0x1, %edx
cmpq $0x0, (%rax,%rdx,8)
jne 0x14009
movq -0x8(%rax,%rdx,8), %rsi
movq %rsi, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x13ff9
movq %r14, %rdi
movl %r12d, %esi
movl $0x1, %edx
callq 0x115d2
incq %r12
movslq 0x14(%r14), %rax
cmpq %rax, %r12
jl 0x13e1a
addq $0x20, %r14
movl $0x8, %edx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x43873
xorl %edx, %edx
cmpq $0x8, %rax
je 0x14072
movq $0x0, (%r14)
jmp 0x14072
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
jmp 0x14072
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x14072
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
jmp 0x14072
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
movl %edx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop