// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rbx
movq %rdi, %r15
xorl %ebp, %ebp
movl %edx, 0x10(%rsp)
cmpl $0x1, %edx
setne %bpl
xorl %r14d, %r14d
movq %rdi, 0x18(%rsp)
movslq 0x18(%r15), %rax
cmpq %rax, %r14
jge 0x7a1c
movq 0x38(%r15), %rax
movq %rax, 0x28(%rsp)
callq 0x8a19
movq %r14, %rcx
movq %rax, %r14
movq 0x30(%r15), %rax
movq %rcx, 0x20(%rsp)
movq %r14, (%rax,%rcx,8)
movl %ebp, %edi
movq %rbx, %rsi
leaq 0x14(%rsp), %rdx
pushq $0x4
popq %rcx
callq 0x8a4a
xorl %r15d, %r15d
cmpl 0x14(%rsp), %r15d
jge 0x7977
movl %ebp, %edi
movq %rbx, %rsi
leaq 0xc(%rsp), %rdx
pushq $0x4
popq %rcx
callq 0x8a4a
movl 0xc(%rsp), %esi
movq %r14, %rdi
leaq 0x34(%rsp), %rdx
callq 0x861e
movq 0x20(%r14), %r13
movl %eax, %eax
imulq $0x18, %rax, %r12
leaq (%r12,%r13), %rdx
addq $0x8, %rdx
cmpl $0x0, 0x10(%rsp)
je 0x7926
andq $0x0, (%rdx)
jmp 0x7933
movl %ebp, %edi
movq %rbx, %rsi
pushq $0x8
popq %rcx
callq 0x8a4a
addq %r12, %r13
leaq 0x4(%r13), %rdx
movl %ebp, %edi
movq %rbx, %rsi
pushq $0x4
popq %rcx
callq 0x8a4a
movslq 0x4(%r13), %r12
movl %r12d, (%r13)
shlq $0x4, %r12
movq %r12, %rdi
callq 0x22e0
movq %rax, 0x10(%r13)
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0x8a4a
incl %r15d
jmp 0x78d9
cmpl $0x0, 0x10(%rsp)
movq 0x20(%rsp), %r14
je 0x7a0f
movq %r14, %r15
shlq $0x4, %r15
movq 0x28(%rsp), %r13
leaq (%r15,%r13), %r14
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
pushq $0x4
popq %rcx
callq 0x8a4a
movl (%r13,%r15), %eax
movl %eax, 0x4(%r13,%r15)
shll $0x3, %eax
movslq %eax, %r12
movq %r12, %rdi
callq 0x22e0
movq %rax, 0x8(%r13,%r15)
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0x8a4a
movslq (%r13,%r15), %rax
pushq $0x1
popq %rcx
movq 0x18(%rsp), %rdi
cmpq %rax, %rcx
jge 0x79ff
movq 0x8(%r14), %rdx
cmpq $0x0, (%rdx,%rcx,8)
jne 0x79fa
movq -0x8(%rdx,%rcx,8), %rsi
movq %rsi, (%rdx,%rcx,8)
incq %rcx
jmp 0x79e1
movq 0x20(%rsp), %r14
movl %r14d, %esi
pushq $0x1
popq %rdx
callq 0x6bfd
incq %r14
movq 0x18(%rsp), %r15
jmp 0x7896
leaq 0x20(%r15), %r14
pushq $0x8
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x8a4a
cmpq $0x8, %rax
je 0x7a3a
andq $0x0, (%r14)
leaq 0xc(%rsp), %rdx
pushq $0x4
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x8a4a
cmpq $0x4, %rax
jne 0x7abb
cmpl $0x1494e52, 0xc(%rsp)   # imm = 0x1494E52
jne 0x7abb
leaq 0x28(%r15), %rdx
pushq $0x8
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x8a4a
leaq 0x10(%r15), %rdx
pushq $0x4
popq %r14
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rcx
callq 0x8a4a
leaq 0x48(%r15), %rdx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rcx
callq 0x8a4a
movslq 0x48(%r15), %r14
movl %r14d, 0x4c(%r15)
shlq $0x3, %r14
movq %r14, %rdi
callq 0x22e0
movq %rax, 0x50(%r15)
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
movq %r14, %rcx
callq 0x8a4a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq