// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/hts.c
// Function: hts_idx_load_core
static void hts_idx_load_core(hts_idx_t *idx, void *fp, int fmt)
{
	int32_t i, n, is_be;
	int is_bgzf = (fmt != HTS_FMT_BAI);
	is_be = ed_is_big();
	for (i = 0; i < idx->n; ++i) {
		bidx_t *h;
		lidx_t *l = &idx->lidx[i];
		uint32_t key;
		int j, absent;
		hts_bin_t *p;
		h = idx->bidx[i] = kh_init(bin);
		idx_read(is_bgzf, fp, &n, 4);
		if (is_be) ed_swap_4p(&n);
		for (j = 0; j < n; ++j) {
			khint_t k;
			idx_read(is_bgzf, fp, &key, 4);
			if (is_be) ed_swap_4p(&key);
			k = kh_put(bin, h, key, &absent);
			p = &kh_val(h, k);
			if (fmt == HTS_FMT_CSI) {
				idx_read(is_bgzf, fp, &p->loff, 8);
				if (is_be) ed_swap_8p(&p->loff);
			} else p->loff = 0;
			idx_read(is_bgzf, fp, &p->n, 4);
			if (is_be) ed_swap_4p(&p->n);
			p->m = p->n;
			p->list = (hts_pair64_t*)malloc(p->m * 16);
			idx_read(is_bgzf, fp, p->list, p->n<<4);
			if (is_be) swap_bins(p);
		}
		if (fmt != HTS_FMT_CSI) { // load linear index
			int j;
			idx_read(is_bgzf, fp, &l->n, 4);
			if (is_be) ed_swap_4p(&l->n);
			l->m = l->n;
			l->offset = (uint64_t*)malloc(l->n << 3);
			idx_read(is_bgzf, fp, l->offset, l->n << 3);
			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 (idx_read(is_bgzf, fp, &idx->n_no_coor, 8) != 8) idx->n_no_coor = 0;
	if (is_be) ed_swap_8p(&idx->n_no_coor);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %r15
xorl %ebp, %ebp
movl %edx, 0xc(%rsp)
cmpl $0x1, %edx
setne %bpl
xorl %ebx, %ebx
movq %rdi, 0x18(%rsp)
movslq 0x14(%r15), %rax
cmpq %rax, %rbx
jge 0x6b4b
movq 0x30(%r15), %rax
movq %rax, 0x28(%rsp)
callq 0x7a7e
movq %rbx, %rcx
movq %rax, %rbx
movq 0x28(%r15), %rax
movq %rcx, 0x20(%rsp)
movq %rbx, (%rax,%rcx,8)
movl %ebp, %edi
movq %r14, %rsi
leaq 0x14(%rsp), %rdx
pushq $0x4
popq %rcx
callq 0x7aaf
xorl %r15d, %r15d
cmpl 0x14(%rsp), %r15d
jge 0x6aa7
movl %ebp, %edi
movq %r14, %rsi
leaq 0x10(%rsp), %rdx
pushq $0x4
popq %rcx
callq 0x7aaf
movl 0x10(%rsp), %esi
movq %rbx, %rdi
leaq 0x34(%rsp), %rdx
callq 0x7683
movq 0x20(%rbx), %r13
movl %eax, %eax
imulq $0x18, %rax, %r12
leaq (%r12,%r13), %rdx
addq $0x8, %rdx
cmpl $0x0, 0xc(%rsp)
je 0x6a56
andq $0x0, (%rdx)
jmp 0x6a63
movl %ebp, %edi
movq %r14, %rsi
pushq $0x8
popq %rcx
callq 0x7aaf
addq %r12, %r13
leaq 0x4(%r13), %rdx
movl %ebp, %edi
movq %r14, %rsi
pushq $0x4
popq %rcx
callq 0x7aaf
movslq 0x4(%r13), %r12
movl %r12d, (%r13)
shlq $0x4, %r12
movq %r12, %rdi
callq 0x22a0
movq %rax, 0x10(%r13)
movl %ebp, %edi
movq %r14, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0x7aaf
incl %r15d
jmp 0x6a09
cmpl $0x0, 0xc(%rsp)
movq 0x20(%rsp), %rbx
je 0x6b3e
movq %rbx, %r15
shlq $0x4, %r15
movq 0x28(%rsp), %r13
leaq (%r15,%r13), %rbx
movl %ebp, %edi
movq %r14, %rsi
movq %rbx, %rdx
pushq $0x4
popq %rcx
callq 0x7aaf
movl (%r13,%r15), %eax
movl %eax, 0x4(%r13,%r15)
shll $0x3, %eax
movslq %eax, %r12
movq %r12, %rdi
callq 0x22a0
movq %rax, 0x8(%r13,%r15)
movl %ebp, %edi
movq %r14, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0x7aaf
movslq (%r13,%r15), %rax
pushq $0x1
popq %rcx
movq 0x18(%rsp), %rdi
cmpq %rax, %rcx
jge 0x6b2f
movq 0x8(%rbx), %rdx
cmpq $0x0, (%rdx,%rcx,8)
jne 0x6b2a
movq -0x8(%rdx,%rcx,8), %rsi
movq %rsi, (%rdx,%rcx,8)
incq %rcx
jmp 0x6b11
movq 0x20(%rsp), %rbx
movl %ebx, %esi
pushq $0x1
popq %rdx
callq 0x5e18
incq %rbx
movq 0x18(%rsp), %r15
jmp 0x69c6
addq $0x20, %r15
pushq $0x8
popq %rcx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7aaf
cmpq $0x8, %rax
je 0x6b69
andq $0x0, (%r15)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq