// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
testq %rdi, %rdi
je 0x14054
movq %rsi, %r14
movq %rdi, %r12
cmpl $0x0, 0x14(%rdi)
jle 0x1402e
xorl %r15d, %r15d
leaq 0x24(%rsp), %rbp
movq %r12, 0x28(%rsp)
movq %r14, 0x10(%rsp)
movq %r15, %rax
shlq $0x4, %rax
addq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x4360
movq %rax, %r13
movq 0x28(%r12), %rax
movq %r15, 0x18(%rsp)
movq %r13, (%rax,%r15,8)
movl $0x4, %edx
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x4489c
cmpq $0x4, %rax
jne 0x13fda
cmpl $0x0, 0xc(%rsp)
jle 0x13f16
xorl %r12d, %r12d
movl $0x4, %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4489c
cmpq $0x4, %rax
jne 0x13e4f
movl 0x24(%rsp), %esi
movq %r13, %rdi
leaq 0x20(%rsp), %rdx
callq 0x138fc
cmpl $0x0, 0x20(%rsp)
jle 0x13e5b
movl %ebx, 0x4(%rsp)
movq %rbp, %r15
movq 0x20(%r13), %rbx
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
leaq (%rbx,%rbp,8), %rsi
addq $0x8, %rsi
cmpl $0x0, 0x8(%rsp)
je 0x13e67
movq $0x0, (%rsi)
jmp 0x13e7a
xorl %eax, %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x13f00
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
xorl %eax, %eax
jmp 0x13f00
movl $0x8, %edx
movq %r14, %rdi
callq 0x4489c
cmpq $0x8, %rax
jne 0x13ee8
leaq (%rbx,%rbp,8), %rbp
leaq 0x4(%rbp), %rbx
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4489c
cmpq $0x4, %rax
jne 0x13ee8
movslq 0x4(%rbp), %r14
movl %r14d, (%rbp)
movq %r14, %rdi
shlq $0x4, %rdi
callq 0x4700
movq %rax, 0x10(%rbp)
testq %rax, %rax
je 0x13ef1
shll $0x4, %r14d
movslq %r14d, %rdx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4489c
movl (%rbx), %ecx
shll $0x4, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
sete %al
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl 0x4(%rsp), %ebx
cmovnel %ecx, %ebx
jmp 0x13efd
xorl %eax, %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x13efd
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
xorl %eax, %eax
movq 0x10(%rsp), %r14
movq %r15, %rbp
testb %al, %al
je 0x13fe6
incl %r12d
cmpl 0xc(%rsp), %r12d
jl 0x13df8
movl %ebx, 0x4(%rsp)
movb $0x1, %bl
cmpl $0x0, 0x8(%rsp)
movq 0x28(%rsp), %r12
movq 0x18(%rsp), %r15
je 0x13ff6
movl $0x4, %edx
movq %r14, %rdi
movq 0x30(%rsp), %r13
movq %r13, %rsi
callq 0x4489c
cmpq $0x4, %rax
jne 0x14011
movslq (%r13), %r14
movl %r14d, 0x4(%r13)
movq %r14, %rdi
shlq $0x3, %rdi
callq 0x4700
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x1401d
leal (,%r14,8), %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4489c
movq 0x30(%rsp), %rsi
movl (%rsi), %ecx
leal (,%rcx,8), %edx
movslq %edx, %rdx
cmpq %rdx, %rax
jne 0x14011
cmpl $0x2, %ecx
jl 0x13fc8
movq 0x8(%rsi), %rax
movl $0x1, %edx
cmpq $0x0, (%rax,%rdx,8)
jne 0x13fc0
movq -0x8(%rax,%rdx,8), %rsi
movq %rsi, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x13fb0
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x11546
jmp 0x13ff6
xorl %ebx, %ebx
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
jmp 0x13ff1
movl %ebx, 0x4(%rsp)
xorl %ebx, %ebx
movq 0x28(%rsp), %r12
movq 0x18(%rsp), %r15
testb %bl, %bl
je 0x1405b
incq %r15
movslq 0x14(%r12), %rax
cmpq %rax, %r15
movl 0x4(%rsp), %ebx
jl 0x13d9d
jmp 0x1402e
xorl %ebx, %ebx
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
jmp 0x13ff6
movl $0xfffffffe, 0x4(%rsp)  # imm = 0xFFFFFFFE
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
jmp 0x13ff6
addq $0x20, %r12
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4489c
xorl %ecx, %ecx
cmpq $0x8, %rax
je 0x1405f
movq $0x0, (%r12)
jmp 0x1405f
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
jmp 0x1405f
movl 0x4(%rsp), %ecx
movl %ecx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq