// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %edx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
xorl %r14d, %r14d
pushq $0x4
popq %rbp
pushq $-0x1
popq %r13
movq %rdi, 0x20(%rsp)
movslq 0x14(%rbx), %rax
cmpq %rax, %r14
jge 0x18c7c
imulq $0x18, %r14, %rax
addq 0x30(%rbx), %rax
movq %rax, 0x30(%rsp)
callq 0x13d64
movq %rbx, %rcx
movq %rax, %rbx
movq 0x28(%rcx), %rax
movq %r14, 0x28(%rsp)
movq %rbx, (%rax,%r14,8)
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
movq %rbp, %rdx
callq 0xab95
cmpq $0x4, %rax
jne 0x18c6a
cmpl $0x0, 0xc(%rsp)
js 0x18c62
incl %r13d
cmpl 0xc(%rsp), %r13d
jge 0x18b64
movq %r12, %rdi
leaq 0x1c(%rsp), %rsi
movq %rbp, %rdx
callq 0xab95
cmpq $0x4, %rax
jne 0x18c5e
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
leaq 0x18(%rsp), %rdx
callq 0x18097
cmpl $0x0, 0x18(%rsp)
js 0x18c66
je 0x18c62
movq 0x20(%rbx), %r15
movl %eax, %eax
imulq $0x18, %rax, %r14
leaq (%r15,%r14), %rsi
addq $0x8, %rsi
cmpl $0x0, 0x8(%rsp)
je 0x18ac9
andq $0x0, (%rsi)
jmp 0x18ade
movq %r12, %rdi
pushq $0x8
popq %rdx
callq 0xab95
cmpq $0x8, %rax
jne 0x18c5e
addq %r14, %r15
leaq 0x4(%r15), %r14
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0xab95
cmpq $0x4, %rax
jne 0x18c5e
movl %r13d, 0x10(%rsp)
movq %rbx, %r13
movq %rbp, %rbx
movq %r12, %rbp
movslq (%r14), %r12
testq %r12, %r12
js 0x18c62
movl %r12d, (%r15)
shlq $0x4, %r12
movq %r12, %rdi
callq 0x4680
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x18c66
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %rbp, %r12
callq 0xab95
movslq (%r14), %rcx
shlq $0x4, %rcx
cmpq %rcx, %rax
movq %rbx, %rbp
movq %r13, %rbx
movl 0x10(%rsp), %r13d
je 0x18a60
jmp 0x18c5e
cmpl $0x0, 0x8(%rsp)
je 0x18c05
movq %r12, %rdi
leaq 0x14(%rsp), %rsi
movq %rbp, %rdx
callq 0xab95
cmpq $0x4, %rax
pushq $-0x1
popq %r13
jne 0x18c6a
movl 0x14(%rsp), %ebx
movq 0x30(%rsp), %r14
movq %rbx, (%r14)
movq %rbx, 0x8(%r14)
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x4680
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x18c66
movq %r12, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xab95
movq 0x30(%rsp), %r9
movq (%r9), %rcx
leaq (,%rcx,8), %rdx
cmpq %rdx, %rax
jne 0x18c6a
testq %rcx, %rcx
movl $0x0, %eax
cmovgq %rcx, %rax
xorl %edx, %edx
movq 0x20(%rsp), %rbx
cmpq %rdx, %rax
je 0x18c18
movq 0x10(%r9), %rsi
cmpq $0x0, (%rsi,%rdx,8)
jne 0x18c15
incq %rdx
jmp 0x18bf0
pushq $-0x1
popq %r13
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r14
jmp 0x18c56
movq %rdx, %rax
leal -0x2(%rcx), %edx
decl %ecx
movslq %ecx, %rcx
leal 0x1(%rdx), %esi
cmpl %eax, %esi
jle 0x18c44
movq 0x10(%r9), %rsi
movslq %edx, %rdi
cmpq $0x0, (%rsi,%rdi,8)
jne 0x18c3d
movq (%rsi,%rcx,8), %r8
movq %r8, (%rsi,%rdi,8)
decl %edx
decq %rcx
jmp 0x18c20
movq %rbx, %rdi
movq 0x28(%rsp), %r14
movl %r14d, %esi
xorl %edx, %edx
callq 0x13723
incq %r14
jmp 0x18a09
pushq $-0x1
jmp 0x18c68
pushq $-0x3
jmp 0x18c68
pushq $-0x2
popq %r13
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x20, %rbx
pushq $0x8
popq %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xab95
xorl %r13d, %r13d
cmpq $0x8, %rax
je 0x18c6a
andq $0x0, (%rbx)
jmp 0x18c6a
nopl (%rax)