// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/hts.c
// Function: idx_read_core
static int idx_read_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);
        if (n < 0) return -3;
        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 -2; // No memory
            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);
            if (p->n < 0) return -3;
            if ((size_t) p->n > SIZE_MAX / sizeof(hts_pair64_t)) return -2;
            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, ((size_t) p->n)<<4) != ((size_t) p->n)<<4) return -1;
            if (is_be) swap_bins(p);
        }
        if (fmt != HTS_FMT_CSI) { // load linear index
            int j, k;
            uint32_t x;
            if (bgzf_read(fp, &x, 4) != 4) return -1;
            if (is_be) ed_swap_4p(&x);
            l->n = x;
            if (l->n < 0) return -3;
            if ((size_t) l->n > SIZE_MAX / sizeof(uint64_t)) return -2;
            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 (k = j = 0; j < l->n && l->offset[j] == 0; k = ++j); // stop at the first non-zero entry
            for (j = l->n-1; j > k; j--) // fill missing values; may happen given older samtools and tabix
                if (l->offset[j-1] == 0) l->offset[j-1] = l->offset[j];
            update_loff(idx, i, 0);
        }
    }
    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);
#ifdef DEBUG_INDEX
    idx_dump(idx);
#endif

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %r14
cmpl $0x0, 0x14(%rdi)
jle 0x1caaf
xorl %ebx, %ebx
leaq 0x14(%rsp), %rbp
movq %r14, 0x30(%rsp)
leaq (%rbx,%rbx,2), %rax
shlq $0x3, %rax
addq 0x30(%r14), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
movq %rax, %r15
movq 0x28(%r14), %rax
movq %rbx, 0x38(%rsp)
movq %r15, (%rax,%rbx,8)
movl $0x4, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0xbefc
cmpq $0x4, %rax
jne 0x1cad5
cmpl $0x0, 0x14(%rsp)
js 0x1cadf
je 0x1c9b3
xorl %ebx, %ebx
movq %r13, 0x18(%rsp)
movl $0x4, %edx
movq %r13, %rdi
leaq 0x2c(%rsp), %rsi
callq 0xbefc
cmpq $0x4, %rax
jne 0x1cad5
movl 0x2c(%rsp), %esi
movq %r15, %rdi
leaq 0x28(%rsp), %rdx
callq 0x1bfb9
cmpl $0x0, 0x28(%rsp)
js 0x1cae9
je 0x1cadf
movl %ebx, 0x20(%rsp)
movl $0xfffffffe, 0xc(%rsp)  # imm = 0xFFFFFFFE
movq 0x20(%r15), %rbx
movl %eax, %eax
leaq (%rax,%rax,2), %r13
leaq (%rbx,%r13,8), %rsi
addq $0x8, %rsi
cmpl $0x0, 0x10(%rsp)
je 0x1c90b
movq $0x0, (%rsi)
movq 0x18(%rsp), %r12
jmp 0x1c927
movl $0x8, %edx
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0xbefc
cmpq $0x8, %rax
jne 0x1cad5
movq %r15, %r14
movq %rbp, %r15
leaq (%rbx,%r13,8), %r13
leaq 0x4(%r13), %rbp
movl $0x4, %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0xbefc
cmpq $0x4, %rax
jne 0x1cad5
movslq (%rbp), %rbx
testq %rbx, %rbx
js 0x1cadf
movl %ebx, (%r13)
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x4680
movq %rax, 0x10(%r13)
testq %rax, %rax
je 0x1caf1
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xbefc
movslq (%rbp), %rcx
shlq $0x4, %rcx
cmpq %rcx, %rax
movl 0x20(%rsp), %ebx
jne 0x1cad5
incl %ebx
cmpl 0x14(%rsp), %ebx
movq %r15, %rbp
movq %r14, %r15
jl 0x1c89a
cmpl $0x0, 0x10(%rsp)
je 0x1ca51
movl $0x4, %edx
movq %r13, %rdi
leaq 0x24(%rsp), %rsi
callq 0xbefc
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x4, %rax
movq 0x30(%rsp), %r14
jne 0x1caf6
movl 0x24(%rsp), %ebx
movq 0x40(%rsp), %r15
movq %rbx, (%r15)
movq %rbx, 0x8(%r15)
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x4680
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x1cb08
movq %r13, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xbefc
movq (%r15), %rcx
leaq (,%rcx,8), %rdx
cmpq %rdx, %rax
jne 0x1caf6
movq %r15, %rdi
testq %rcx, %rcx
jle 0x1ca5d
movq 0x10(%rdi), %rdx
xorl %eax, %eax
cmpq $0x0, (%rdx,%rax,8)
jne 0x1ca5f
incq %rax
cmpq %rax, %rcx
jne 0x1ca3e
movl %ecx, %eax
jmp 0x1ca5f
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbx
jmp 0x1ca9f
xorl %eax, %eax
leal -0x1(%rcx), %esi
cmpl %eax, %esi
jle 0x1ca8e
movq 0x10(%rdi), %rdx
movslq %esi, %rsi
cltq
addl $-0x2, %ecx
movslq %ecx, %rdi
cmpq $0x0, (%rdx,%rdi,8)
jne 0x1ca84
movq (%rdx,%rsi,8), %r8
movq %r8, (%rdx,%rdi,8)
decq %rsi
decl %ecx
cmpq %rax, %rsi
jg 0x1ca72
movq %r14, %rdi
movq 0x38(%rsp), %rbx
movl %ebx, %esi
xorl %edx, %edx
callq 0x167b9
incq %rbx
movslq 0x14(%r14), %rax
cmpq %rax, %rbx
jl 0x1c838
addq $0x20, %r14
movl $0x8, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0xbefc
xorl %r12d, %r12d
cmpq $0x8, %rax
je 0x1caf6
movq $0x0, (%r14)
jmp 0x1caf6
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
jmp 0x1caf1
movl $0xfffffffd, 0xc(%rsp)  # imm = 0xFFFFFFFD
jmp 0x1caf1
movl $0xfffffffe, 0xc(%rsp)  # imm = 0xFFFFFFFE
movl 0xc(%rsp), %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
jmp 0x1caf6