// File: /workspace/github_c_makefile_star2_O3/DReichLab[P]adna/hts.c
// Function: hts_itr_query
hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end)
{
	int i, n_off, l, bin;
	hts_pair64_t *off;
	khint_t k;
	bidx_t *bidx;
	uint64_t min_off;
	hts_itr_t *iter = 0;
	cand_bins_t bins = {0,0,0};

	if (tid < 0) {
		uint64_t off0 = (uint64_t)-1;
		khint_t k;
		if (tid == HTS_IDX_START) {
			if (idx->n > 0) {
				bidx = idx->bidx[0];
				k = kh_get(bin, bidx, idx->n_bins + 1);
				if (k == kh_end(bidx)) return 0;
				off0 = kh_val(bidx, k).list[0].u;
			} else return 0;
		} else if (tid == HTS_IDX_NOCOOR) {
			if (idx->n > 0) {
				bidx = idx->bidx[idx->n - 1];
				k = kh_get(bin, bidx, idx->n_bins + 1);
				if (k == kh_end(bidx)) return 0;
				off0 = kh_val(bidx, k).list[0].v;
			} else return 0;
		} else off0 = 0;
		if (off0 != (uint64_t)-1) {
			iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t));
			iter->read_rest = 1;
			iter->curr_off = off0;
			return iter;
		} else return 0;
	}
	if (beg < 0) beg = 0;
	if (end < beg) return 0;
	if ((bidx = idx->bidx[tid]) == 0) return 0;

	iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t));
	iter->tid = tid, iter->beg = beg, iter->end = end; iter->i = -1;

	// compute min_off
	bin = hts_bin_first(idx->n_lvls) + (beg>>idx->min_shift);
	do {
		int first;
		k = kh_get(bin, bidx, bin);
		if (k != kh_end(bidx)) break;
		first = (hts_bin_parent(bin)<<3) + 1;
		if (bin > first) --bin;
		else bin = hts_bin_parent(bin);
	} while (bin);
	if (bin == 0) k = kh_get(bin, bidx, bin);
	min_off = k != kh_end(bidx)? kh_val(bidx, k).loff : 0;
	// retrieve bins
	reg2bins(beg, end, iter, idx->min_shift, idx->n_lvls, &bins);
	for (i = n_off = 0; i < bins.n; ++i)
		if ((k = kh_get(bin, bidx, bins.a[i])) != kh_end(bidx))
			n_off += kh_value(bidx, k).n;
	if (n_off == 0) return iter;
	off = (hts_pair64_t*)calloc(n_off, 16);
	for (i = n_off = 0; i < bins.n; ++i) {
		if ((k = kh_get(bin, bidx, bins.a[i])) != kh_end(bidx)) {
			int j;
			hts_bin_t *p = &kh_value(bidx, k);
			for (j = 0; j < p->n; ++j)
				if (p->list[j].v > min_off) off[n_off++] = p->list[j];
		}
	}
	if (n_off == 0) {
		free(off); return iter;
	}
	ks_introsort(_off, n_off, off);
	// resolve completely contained adjacent blocks
	for (i = 1, l = 0; i < n_off; ++i)
		if (off[l].v < off[i].v) off[++l] = off[i];
	n_off = l + 1;
	// resolve overlaps between adjacent blocks; this may happen due to the merge in indexing
	for (i = 1; i < n_off; ++i)
		if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u;
	// merge adjacent blocks
	for (i = 1, l = 0; i < n_off; ++i) {
		if (off[l].v>>16 == off[i].u>>16) off[l].v = off[i].v;
		else off[++l] = off[i];
	}
	n_off = l + 1;
	iter->n_off = n_off; iter->off = off;
	free(bins.a);
	return iter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %r12d
movq %rdi, %r15
testl %esi, %esi
js 0x7a7e
movl %ecx, %r14d
movl %edx, %ebp
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %ebp
cmpl %ecx, %ebp
jg 0x80d6
movq 0x28(%r15), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %r13
testq %r13, %r13
je 0x80d6
movl $0x1, %edi
movl $0x28, %esi
callq 0x21f0
movl %r12d, 0x4(%rax)
movl %ebp, 0x8(%rax)
movl %r14d, 0xc(%rax)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rax, (%rsp)
movl %edx, 0x14(%rax)
movl 0x4(%r15), %eax
movl 0x8(%r15), %ecx
movq %rcx, 0x10(%rsp)
leal (%rcx,%rcx,2), %ecx
shll %cl, %edx
notl %edx
movl $0x92492493, %esi       # imm = 0x92492493
imulq %rdx, %rsi
movl %ebp, %r8d
movl %eax, %ecx
shrl %cl, %r8d
shrq $0x22, %rsi
addl %esi, %r8d
movl (%r13), %edx
leal -0x1(%rdx), %esi
testl %edx, %edx
je 0x7a40
movl %esi, %r9d
andl %r8d, %r9d
movl %r8d, %ecx
shrl $0x3, %ecx
leal (,%r8,8), %r10d
xorl %ecx, %r10d
orl $0x1, %r10d
andl %esi, %r10d
movq 0x10(%r13), %r11
movl %r9d, %edi
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %ebx
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %ebx, %r15d
shrl %cl, %r15d
testb $0x2, %r15b
jne 0x7a36
testb $0x1, %r15b
jne 0x7a2a
movq 0x18(%r13), %r15
movl %edi, %r12d
cmpl %r8d, (%r15,%r12,4)
je 0x7a36
addl %r10d, %edi
andl %esi, %edi
cmpl %r9d, %edi
jne 0x79fc
jmp 0x7a4a
shrl %cl, %ebx
testb $0x3, %bl
cmovnel %edx, %edi
jmp 0x7a42
xorl %edi, %edi
cmpl %edx, %edi
jne 0x7bcd
leal -0x1(%r8), %ecx
movl %ecx, %edi
andl $-0x8, %edi
incl %edi
movl %ecx, %r9d
sarl $0x3, %r9d
cmpl %edi, %r8d
cmovgl %ecx, %r9d
movl %r9d, %r8d
testl %r9d, %r9d
jne 0x79d3
testl %edx, %edx
jne 0x7bda
xorl %edi, %edi
jmp 0x7c31
cmpl $-0x2, %r12d
je 0x7b2a
cmpl $-0x3, %r12d
jne 0x7bc6
xorl %esi, %esi
cmpl $0x0, 0x14(%r15)
jle 0x80d6
movq 0x28(%r15), %rax
movq (%rax), %rax
movl (%rax), %edx
testl %edx, %edx
je 0x807a
movl 0xc(%r15), %edi
incl %edi
leal -0x1(%rdx), %r8d
movl %r8d, %r9d
andl %edi, %r9d
movl %edi, %ecx
shrl $0x3, %ecx
leal (,%rdi,8), %r10d
xorl %ecx, %r10d
orl $0x1, %r10d
andl %r8d, %r10d
movq 0x10(%rax), %r11
movq $0x0, (%rsp)
movl %r9d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %ebx
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %ebx, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x8072
testb $0x1, %bpl
jne 0x7b1a
movq 0x18(%rax), %r14
movl %esi, %r15d
cmpl %edi, (%r14,%r15,4)
je 0x8072
addl %r10d, %esi
andl %r8d, %esi
cmpl %r9d, %esi
jne 0x7ae6
jmp 0x80de
movslq 0x14(%r15), %rax
xorl %esi, %esi
testq %rax, %rax
jle 0x80d6
movq 0x28(%r15), %rcx
movq -0x8(%rcx,%rax,8), %rax
movl (%rax), %edx
testl %edx, %edx
je 0x8097
movl 0xc(%r15), %edi
incl %edi
leal -0x1(%rdx), %r8d
movl %r8d, %r9d
andl %edi, %r9d
movl %edi, %ecx
shrl $0x3, %ecx
leal (,%rdi,8), %r10d
xorl %ecx, %r10d
orl $0x1, %r10d
andl %r8d, %r10d
movq 0x10(%rax), %r11
movq $0x0, (%rsp)
movl %r9d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %ebx
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %ebx, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x808f
testb $0x1, %bpl
jne 0x7bb6
movq 0x18(%rax), %r14
movl %esi, %r15d
cmpl %edi, (%r14,%r15,4)
je 0x808f
addl %r10d, %esi
andl %r8d, %esi
cmpl %r9d, %esi
jne 0x7b82
jmp 0x80de
xorl %ebx, %ebx
jmp 0x80b7
testl %r8d, %r8d
cmovel %r8d, %edi
jne 0x7c31
testl %edx, %edx
je 0x7c31
movl %esi, %r8d
andl $0x1, %r8d
movq 0x10(%r13), %r9
movq $0x0, 0x8(%rsp)
xorl %edi, %edi
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r9,%rcx,4), %r10d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x7c27
testb $0x1, %r11b
jne 0x7c1e
movq 0x18(%r13), %r11
movl %edi, %ebx
cmpl $0x0, (%r11,%rbx,4)
je 0x7c27
addl %r8d, %edi
andl %esi, %edi
jne 0x7bf0
jmp 0x7c54
shrl %cl, %r10d
testb $0x3, %r10b
cmovnel %edx, %edi
cmpl %edx, %edi
jne 0x7c40
movq $0x0, 0x8(%rsp)
jmp 0x7c54
movq 0x20(%r13), %rcx
movl %edi, %edx
leaq (%rdx,%rdx,2), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
movq %rcx, 0x8(%rsp)
cmpl %r14d, %ebp
jge 0x80de
movslq %r14d, %rdx
movq 0x10(%rsp), %rsi
addl %esi, %eax
leal (%rax,%rsi,2), %r15d
movl $0x1, %r9d
movl %r15d, %ecx
shlq %cl, %r9
cmpq %rdx, %r9
cmovgeq %rdx, %r9
testl %esi, %esi
js 0x80de
movl %ebp, %r10d
decq %r9
xorl %r8d, %r8d
xorl %r14d, %r14d
xorl %edi, %edi
xorl %r11d, %r11d
xorl %ebx, %ebx
movq %r13, 0x20(%rsp)
movq %r9, 0x30(%rsp)
movq %r10, %r13
movl %r15d, %ecx
shrq %cl, %r13
leal (%rbx,%r13), %r12d
movq %r9, %rbp
sarq %cl, %rbp
leal (%rbx,%rbp), %esi
movl %esi, %eax
subl %r12d, %eax
leal (%rax,%r8), %ecx
incl %ecx
cmpl %r14d, %ecx
movq %r8, 0x18(%rsp)
jle 0x7d33
addl %r8d, %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %r14d
sarl $0x10, %r14d
orl %eax, %r14d
movslq %r14d, %rax
incl %r14d
movl %esi, 0x2c(%rsp)
leaq 0x4(,%rax,4), %rsi
movq %rbx, 0x38(%rsp)
movq %r10, %rbx
movq %r11, 0x40(%rsp)
callq 0x22e0
movl 0x2c(%rsp), %esi
movq 0x40(%rsp), %r11
movq %rbx, %r10
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r9
movq %rax, %rdi
cmpl %r12d, %esi
jge 0x7d44
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %r8
jmp 0x7d6f
movq 0x18(%rsp), %r8
movslq %r8d, %rax
leaq (%rdi,%rax,4), %rax
subl %r13d, %ebp
incl %ebp
movl %r12d, %ecx
xorl %edx, %edx
leal (%rcx,%rdx), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpl %edx, %ebp
jne 0x7d5a
addl %edx, %r8d
movq 0x20(%rsp), %r13
addl $-0x3, %r15d
leal (%r11,%r11,2), %ecx
movl $0x1, %eax
shll %cl, %eax
addl %ebx, %eax
leal 0x1(%r11), %ecx
movl %eax, %ebx
cmpl 0x10(%rsp), %r11d
movl %ecx, %r11d
jne 0x7ca3
testl %r8d, %r8d
jle 0x80de
movq %rdi, 0x10(%rsp)
movl (%r13), %eax
leal -0x1(%rax), %edx
movq %r8, 0x18(%rsp)
movl %r8d, %ebx
xorl %edi, %edi
xorl %esi, %esi
movq 0x8(%rsp), %r14
movl $0x0, %r8d
testl %eax, %eax
je 0x7e43
movq 0x10(%rsp), %rcx
movl (%rcx,%rdi,4), %r9d
movl %edx, %r10d
andl %r9d, %r10d
movl %r9d, %ecx
shrl $0x3, %ecx
leal (,%r9,8), %r11d
xorl %ecx, %r11d
orl $0x1, %r11d
andl %edx, %r11d
movq 0x10(%r13), %r14
movl %r10d, %r8d
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%r14,%rcx,4), %ebp
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %ebp, %r15d
shrl %cl, %r15d
testb $0x2, %r15b
jne 0x7e34
testb $0x1, %r15b
jne 0x7e22
movq 0x18(%r13), %r15
movl %r8d, %r12d
cmpl %r9d, (%r15,%r12,4)
je 0x7e34
addl %r11d, %r8d
andl %edx, %r8d
cmpl %r10d, %r8d
jne 0x7df2
movq 0x8(%rsp), %r14
jmp 0x7e58
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %eax, %r8d
movq 0x8(%rsp), %r14
cmpl %eax, %r8d
je 0x7e58
movq 0x20(%r13), %rcx
movl %r8d, %r8d
leaq (%r8,%r8,2), %r8
addl 0x4(%rcx,%r8,8), %esi
incq %rdi
cmpq %rbx, %rdi
jne 0x7dba
testl %esi, %esi
je 0x80de
movslq %esi, %rdi
movl $0x10, %esi
callq 0x21f0
movq %rax, %r15
cmpl $0x0, 0x18(%rsp)
jle 0x80f1
movl (%r13), %eax
leal -0x1(%rax), %edx
xorl %esi, %esi
xorl %ebp, %ebp
movl $0x0, %edi
testl %eax, %eax
je 0x7f20
movq 0x10(%rsp), %rcx
movl (%rcx,%rsi,4), %r8d
movl %edx, %r9d
andl %r8d, %r9d
movl %r8d, %ecx
shrl $0x3, %ecx
leal (,%r8,8), %r10d
xorl %ecx, %r10d
orl $0x1, %r10d
andl %edx, %r10d
movq 0x10(%r13), %r11
movl %r9d, %edi
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %r14d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r14d, %r12d
shrl %cl, %r12d
testb $0x2, %r12b
jne 0x7f11
testb $0x1, %r12b
jne 0x7f00
movq 0x18(%r13), %r12
movl %edi, %r13d
cmpl %r8d, (%r12,%r13,4)
movq 0x20(%rsp), %r13
je 0x7f11
addl %r10d, %edi
andl %edx, %edi
cmpl %r9d, %edi
jne 0x7ecd
movq 0x8(%rsp), %r14
jmp 0x7f6e
shrl %cl, %r14d
testb $0x3, %r14b
cmovnel %eax, %edi
movq 0x8(%rsp), %r14
cmpl %eax, %edi
je 0x7f6e
movq 0x20(%r13), %r8
movl %edi, %ecx
leaq (%rcx,%rcx,2), %rdi
movslq 0x4(%r8,%rdi,8), %rcx
testq %rcx, %rcx
jle 0x7f6e
leaq (%r8,%rdi,8), %rdi
movq 0x10(%rdi), %rdi
addq $0x8, %rdi
xorl %r8d, %r8d
cmpq %r14, (%rdi)
jbe 0x7f62
leaq -0x8(%rdi), %r9
movslq %ebp, %r10
incl %ebp
shlq $0x4, %r10
movups (%r9), %xmm0
movups %xmm0, (%r15,%r10)
incq %r8
addq $0x10, %rdi
cmpq %rcx, %r8
jb 0x7f47
incq %rsi
cmpq %rbx, %rsi
jne 0x7e92
testl %ebp, %ebp
je 0x80f1
movslq %ebp, %rdi
movq %r15, %rsi
callq 0x5b6a
movl $0x1, %eax
cmpl $0x2, %ebp
jl 0x805d
movl %ebp, %ecx
leaq 0x18(%r15), %rsi
shlq $0x4, %rcx
addq $-0x10, %rcx
xorl %edi, %edi
xorl %edx, %edx
movslq %edx, %r8
shlq $0x4, %r8
movq 0x8(%r15,%r8), %r9
cmpq 0x18(%r15,%rdi), %r9
jae 0x7fd4
leaq (%rsi,%rdi), %r9
addq $-0x8, %r9
incl %edx
movups (%r9), %xmm0
movups %xmm0, 0x10(%r8,%r15)
addq $0x10, %rdi
cmpq %rdi, %rcx
jne 0x7fad
testl %edx, %edx
jle 0x805d
movl %edx, %ecx
movq %rcx, %rsi
shlq $0x4, %rsi
xorl %edi, %edi
movq 0x10(%r15,%rdi), %r8
cmpq %r8, 0x8(%r15,%rdi)
jb 0x7ffd
movq %r8, 0x8(%r15,%rdi)
addq $0x10, %rdi
cmpq %rdi, %rsi
jne 0x7fec
testl %edx, %edx
jle 0x805d
shlq $0x4, %rcx
addq $0x10, %rcx
xorl %eax, %eax
movl $0x10, %edx
movslq %eax, %rsi
shlq $0x4, %rsi
movq (%r15,%rdx), %rdi
xorq 0x8(%r15,%rsi), %rdi
cmpq $0xffff, %rdi           # imm = 0xFFFF
ja 0x8043
addq %r15, %rsi
addq $0x8, %rsi
movq 0x8(%r15,%rdx), %rdi
movq %rdi, (%rsi)
jmp 0x8052
leaq (%r15,%rdx), %rdi
incl %eax
movups (%rdi), %xmm0
movups %xmm0, 0x10(%rsi,%r15)
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x8019
incl %eax
movq (%rsp), %rcx
movl %eax, 0x10(%rcx)
movq %r15, 0x20(%rcx)
movq 0x10(%rsp), %rdi
jmp 0x80f4
shrl %cl, %ebx
testb $0x3, %bl
cmovnel %edx, %esi
cmpl %edx, %esi
je 0x80d6
movq 0x20(%rax), %rax
movl %esi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rax
jmp 0x80ae
shrl %cl, %ebx
testb $0x3, %bl
cmovnel %edx, %esi
cmpl %edx, %esi
je 0x80d6
movq 0x20(%rax), %rax
movl %esi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rax
addq $0x8, %rax
movq (%rax), %rbx
cmpq $-0x1, %rbx
je 0x80d6
movl $0x1, %edi
movl $0x28, %esi
callq 0x21f0
movl $0x1, (%rax)
movq %rax, (%rsp)
movq %rbx, 0x18(%rax)
jmp 0x80de
movq $0x0, (%rsp)
movq (%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2050
jmp 0x80de