// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r12
cmpl $0x0, 0x18(%rdi)
jle 0x8898
xorl %r15d, %r15d
movq %rbx, 0x8(%rsp)
movl %ebp, 0x14(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, %r13
shlq $0x4, %r13
addq 0x38(%r12), %r13
movl $0x1, %edi
movl $0x28, %esi
callq 0x2220
movq %rax, %r14
movq 0x30(%r12), %rax
movq %r14, (%rax,%r15,8)
cmpl $0x1, %ebp
movq %r15, 0x28(%rsp)
movq %r13, 0x18(%rsp)
jne 0x869f
movl $0x1, %esi
movl $0x4, %edx
leaq 0x4(%rsp), %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x86b1
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x4dc0
cmpl $0x0, 0x4(%rsp)
jle 0x87c2
xorl %r13d, %r13d
cmpl $0x1, %ebp
jne 0x86db
movl $0x1, %esi
movl $0x4, %edx
movq %rsp, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x86eb
movl $0x4, %edx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4dc0
movl (%rsp), %esi
movq %r14, %rdi
leaq 0x34(%rsp), %rdx
callq 0x98a2
movq 0x20(%r14), %r12
movl %eax, %eax
leaq (%rax,%rax,2), %rbx
leaq (%r12,%rbx,8), %rsi
addq $0x8, %rsi
leaq (%r12,%rbx,8), %r15
addq $0x4, %r15
testl %ebp, %ebp
je 0x8741
movq $0x0, (%rsi)
cmpl $0x1, %ebp
movq 0x8(%rsp), %rbp
jne 0x8753
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %rbp, %rcx
callq 0x20f0
jmp 0x8763
movl $0x8, %edx
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x4dc0
movl $0x4, %edx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x4dc0
leaq (%r12,%rbx,8), %rbx
movslq 0x4(%rbx), %r15
movl %r15d, (%rbx)
shlq $0x4, %r15
movq %r15, %rdi
callq 0x22e0
movq %rax, 0x10(%rbx)
movl 0x14(%rsp), %ebp
cmpl $0x1, %ebp
jne 0x87a1
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x20f0
jmp 0x87b4
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x4dc0
incl %r13d
cmpl 0x4(%rsp), %r13d
jl 0x86bf
testl %ebp, %ebp
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r15
je 0x8887
cmpl $0x1, %ebp
jne 0x87f5
movl $0x1, %esi
movl $0x4, %edx
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x880a
movl $0x4, %edx
movq %rbx, %rdi
movq 0x18(%rsp), %r13
movq %r13, %rsi
callq 0x4dc0
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 0x883e
movl $0x1, %esi
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x20f0
jmp 0x884c
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4dc0
movslq (%r13), %rax
cmpq $0x2, %rax
jl 0x8877
movq 0x8(%r13), %rcx
movl $0x1, %edx
cmpq $0x0, (%rcx,%rdx,8)
jne 0x886f
movq -0x8(%rcx,%rdx,8), %rsi
movq %rsi, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x885f
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x7617
incq %r15
movslq 0x18(%r12), %rax
cmpq %rax, %r15
jl 0x8650
leaq 0x20(%r12), %r14
cmpl $0x1, %ebp
jne 0x88b9
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x88c9
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4dc0
cmpq $0x8, %rax
je 0x88d6
movq $0x0, (%r14)
cmpl $0x1, %ebp
jne 0x88f2
movq %rsp, %rdi
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rcx
callq 0x20f0
jmp 0x8902
movq %rsp, %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x4dc0
cmpq $0x4, %rax
jne 0x89e1
cmpl $0x1494e52, (%rsp)      # imm = 0x1494E52
jne 0x89e1
leaq 0x28(%r12), %rax
leaq 0x10(%r12), %r15
leaq 0x48(%r12), %r14
cmpl $0x1, %ebp
jne 0x896e
movl $0x1, %esi
movl $0x8, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x20f0
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x20f0
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x20f0
jmp 0x899e
movl $0x8, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4dc0
movl $0x4, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4dc0
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4dc0
movslq 0x48(%r12), %r14
movl %r14d, 0x4c(%r12)
shlq $0x3, %r14
movq %r14, %rdi
callq 0x22e0
movq %rax, 0x50(%r12)
cmpl $0x1, %ebp
jne 0x89d3
movl $0x1, %esi
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x20f0
jmp 0x89e1
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4dc0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq