// File: /workspace/github_c_makefile_star2_O1/lh3[P]bgt/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;
	char magic[4];
	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);
	// FIXME: NOT WORKING ON BIG ENDIAN!!!
	if (idx_read(is_bgzf, fp, magic, 4) == 4 && strncmp(magic, "RNI\1", 4) == 0) {
		idx_read(is_bgzf, fp, &idx->n_rec, 8);
		idx_read(is_bgzf, fp, &idx->rec_shift, 4);
		idx_read(is_bgzf, fp, &idx->ridx.n, 4);
		idx->ridx.m = idx->ridx.n;
		idx->ridx.offset = (uint64_t*)malloc(idx->ridx.m * 8);
		idx_read(is_bgzf, fp, idx->ridx.offset, idx->ridx.n * 8);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
cmpl $0x0, 0x18(%rdi)
jle 0x85d4
xorl %r12d, %r12d
movq %r15, 0x10(%rsp)
movq %r12, %r13
shlq $0x4, %r13
addq 0x38(%r15), %r13
movl $0x1, %edi
movl $0x28, %esi
callq 0x2220
movq %rax, %r14
movq 0x30(%r15), %rax
movq %r14, (%rax,%r12,8)
cmpl $0x1, %ebp
movq %r12, 0x18(%rsp)
movq %r13, 0x8(%rsp)
jne 0x83f2
movl $0x1, %esi
movl $0x4, %edx
leaq 0x4(%rsp), %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x8404
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x4a9f
cmpl $0x0, 0x4(%rsp)
jle 0x84ff
xorl %r13d, %r13d
cmpl $0x1, %ebp
jne 0x842e
movl $0x1, %esi
movl $0x4, %edx
movq %rsp, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x843e
movl $0x4, %edx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4a9f
movl (%rsp), %esi
movq %r14, %rdi
leaq 0x24(%rsp), %rdx
callq 0x9606
movq 0x20(%r14), %r15
movl %eax, %eax
leaq (%rax,%rax,2), %r12
leaq (%r15,%r12,8), %rsi
addq $0x8, %rsi
testl %ebp, %ebp
je 0x846d
movq $0x0, (%rsi)
jmp 0x847a
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4a9f
leaq (%r15,%r12,8), %r12
leaq 0x4(%r12), %rax
cmpl $0x1, %ebp
jne 0x849f
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x84af
movl $0x4, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4a9f
movslq 0x4(%r12), %r15
movl %r15d, (%r12)
shlq $0x4, %r15
movq %r15, %rdi
callq 0x22e0
movq %rax, 0x10(%r12)
cmpl $0x1, %ebp
jne 0x84e3
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x20f0
jmp 0x84f1
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x4a9f
incl %r13d
cmpl 0x4(%rsp), %r13d
jl 0x8412
testl %ebp, %ebp
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
je 0x85c4
cmpl $0x1, %ebp
jne 0x8532
movl $0x1, %esi
movl $0x4, %edx
movq 0x8(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x8547
movl $0x4, %edx
movq %rbx, %rdi
movq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0x4a9f
movl (%r13), %eax
movl %eax, 0x4(%r13)
shll $0x3, %eax
movslq %eax, %r14
movq %r14, %rdi
callq 0x22e0
movq %rax, 0x8(%r13)
cmpl $0x1, %ebp
jne 0x857b
movl $0x1, %esi
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x20f0
jmp 0x8589
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4a9f
movslq (%r13), %rax
cmpq $0x2, %rax
jl 0x85b4
movq 0x8(%r13), %rcx
movl $0x1, %edx
cmpq $0x0, (%rcx,%rdx,8)
jne 0x85ac
movq -0x8(%rcx,%rdx,8), %rsi
movq %rsi, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x859c
movq %r15, %rdi
movl %r12d, %esi
movl $0x1, %edx
callq 0x73c7
incq %r12
movslq 0x18(%r15), %rax
cmpq %rax, %r12
jl 0x83a5
leaq 0x20(%r15), %r14
cmpl $0x1, %ebp
jne 0x85f4
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x8604
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a9f
cmpq $0x8, %rax
je 0x8611
movq $0x0, (%r14)
cmpl $0x1, %ebp
jne 0x862d
movq %rsp, %rdi
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rcx
callq 0x20f0
jmp 0x863d
movq %rsp, %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x4a9f
cmpq $0x4, %rax
jne 0x8724
cmpl $0x1494e52, (%rsp)      # imm = 0x1494E52
jne 0x8724
leaq 0x28(%r15), %rax
cmpl $0x1, %ebp
jne 0x8674
movl $0x1, %esi
movl $0x8, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x8684
movl $0x8, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4a9f
leaq 0x10(%r15), %rax
cmpl $0x1, %ebp
jne 0x86a4
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x86b4
movl $0x4, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4a9f
leaq 0x48(%r15), %rax
cmpl $0x1, %ebp
jne 0x86d4
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x86e4
movl $0x4, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4a9f
movslq 0x48(%r15), %r14
movl %r14d, 0x4c(%r15)
shlq $0x3, %r14
movq %r14, %rdi
callq 0x22e0
movq %rax, 0x50(%r15)
cmpl $0x1, %ebp
jne 0x8716
movl $0x1, %esi
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x20f0
jmp 0x8724
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4a9f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq