// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x21b0
cmpl $0x0, -0x14(%rbp)
jge 0xab86
movq $-0x1, -0x70(%rbp)
cmpl $-0x3, -0x14(%rbp)
jne 0xaaa0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jle 0xaa8e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
callq 0xb090
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xaa6f
movq $0x0, -0x8(%rbp)
jmp 0xb083
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x74(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0xaa9b
movq $0x0, -0x8(%rbp)
jmp 0xb083
jmp 0xab38
cmpl $-0x2, -0x14(%rbp)
jne 0xab2e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jle 0xab1f
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
callq 0xb090
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xaaff
movq $0x0, -0x8(%rbp)
jmp 0xb083
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x74(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0xab2c
movq $0x0, -0x8(%rbp)
jmp 0xb083
jmp 0xab36
movq $0x0, -0x70(%rbp)
jmp 0xab38
cmpq $-0x1, -0x70(%rbp)
je 0xab79
movl $0x1, %edi
movl $0x28, %esi
callq 0x2200
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %ecx
andl $-0x2, %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x70(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb083
movq $0x0, -0x8(%rbp)
jmp 0xb083
cmpl $0x0, -0x18(%rbp)
jge 0xab93
movl $0x0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xaba8
movq $0x0, -0x8(%rbp)
jmp 0xb083
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0xabcf
movq $0x0, -0x8(%rbp)
jmp 0xb083
movl $0x1, %edi
movl $0x28, %esi
callq 0x2200
movq %rax, -0x58(%rbp)
movl -0x14(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x18(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl $0x7, %ecx
cltd
idivl %ecx
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
sarl %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xb090
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0xac5c
jmp 0xac95
movl -0x2c(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
shll $0x3, %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x78(%rbp), %eax
jle 0xac81
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xac8d
movl -0x2c(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
movl %eax, -0x2c(%rbp)
jmp 0xac8f
cmpl $0x0, -0x2c(%rbp)
jne 0xac40
cmpl $0x0, -0x2c(%rbp)
jne 0xacaa
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xb090
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0xacd4
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0xacdf
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0xacdf
movq -0x90(%rbp), %rax
movq %rax, -0x50(%rbp)
movslq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %r8d
leaq -0x68(%rbp), %r9
callq 0xb1d0
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0xad6b
movq -0x48(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0xb090
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0xad5e
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0xad60
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xad1c
cmpl $0x0, -0x24(%rbp)
jne 0xad7e
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb083
movslq -0x24(%rbp), %rdi
movl $0x10, %esi
callq 0x2200
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0xae78
movq -0x48(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0xb090
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0xae68
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x88(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0xae66
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
cmpq -0x50(%rbp), %rax
jbe 0xae59
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x24(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x88(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x7c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0xae5b
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xaded
jmp 0xae68
jmp 0xae6a
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xad9e
cmpl $0x0, -0x24(%rbp)
jne 0xae94
movq -0x38(%rbp), %rdi
callq 0x2040
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb083
movslq -0x24(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x8070
movl $0x1, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xaf20
movq -0x38(%rbp), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jae 0xaf13
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x28(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x38(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0xaf15
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xaeaf
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x1, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xaf9b
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jb 0xaf8e
movq -0x38(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0xaf90
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xaf30
movl $0x1, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xb053
movq -0x38(%rbp), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x10, %rax
movq -0x38(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x10, %rcx
cmpq %rcx, %rax
jne 0xb00f
movq -0x38(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0xb043
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x28(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x38(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0xb045
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xafa9
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x60(%rbp), %rdi
callq 0x2040
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq