// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: get_mask_interval(ul_ov_t*, kv_ul_ov_t*, unsigned long*, long, long, unsigned long*, unsigned long*)
ul_ov_t* get_mask_interval(ul_ov_t *in, kv_ul_ov_t *idx, uint64_t *ii, int64_t ql, int64_t tl, uint64_t *n, uint64_t *n_skip)
{
	int64_t idx_n = idx->n, i = (*ii), m; ul_ov_t *a, z;
	(*n) = (*n_skip) = 0;
	if(i >= idx_n) i = idx_n-1;
	if(i < 0) i = 0;
	// if(in->qn == 101 && in->tn == 102) {
	// 	fprintf(stderr, "-0-[M::%s]\tutg%.6ul\t%c\tutg%.6ul\ti::%ld\tidx_n::%ld\n", __func__, 
	// 		in->qn+1, "+-"[in->rev], in->tn+1, i, idx_n);
	// }
	if(i >= 0 && i < idx_n) {
		while (i >= 0 && in->tn <= idx->a[i].tn) i--;
		if(i < 0 && idx_n > 0 && in->tn == idx->a[0].tn) i = 0;
		// if(in->qn == 101 && in->tn == 102) {
		// 	fprintf(stderr, "-1-[M::%s]\tutg%.6ul\t%c\tutg%.6ul\ti::%ld\tidx_n::%ld\n", __func__, 
		// 		in->qn+1, "+-"[in->rev], in->tn+1, i, idx_n);
		// }
		if(i >= 0) {
			while (i < idx_n && in->tn > idx->a[i].tn) i++;
			// if(in->qn == 101 && in->tn == 102) {
			// 	fprintf(stderr, "-2-[M::%s]\tutg%.6ul\t%c\tutg%.6ul\ti::%ld\tidx_n::%ld\n", __func__, 
			// 		in->qn+1, "+-"[in->rev], in->tn+1, i, idx_n);
			// }
			if(i < idx_n && in->tn == idx->a[i].tn) {
				for (m = i, a = idx->a + i; i < idx_n && in->tn == idx->a[i].tn; i++) {
					if(!check_ul_ov_t_consist(in, &(idx->a[i]), ql, tl, 0.06)) {
						(*n_skip)++; continue;
					}
					if(m != i) {
						z = idx->a[i]; idx->a[i] = idx->a[m]; idx->a[m] = z;
					}
					m++; (*n)++;
				}
				// if(in->qn == 101 && in->tn == 102) {
				// 	fprintf(stderr, "-3-[M::%s]\tutg%.6ul\t%c\tutg%.6ul\ti::%ld\tidx_n::%ld\n", __func__, 
				// 		in->qn+1, "+-"[in->rev], in->tn+1, i, idx_n);
				// }
				(*ii) = i;
				if((*n)) return a;
			}
		}
	}
	(*ii) = i; 
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq 0xa0(%rsp), %rcx
movq 0x8(%rsi), %r14
movq (%rdx), %rax
andq $0x0, (%rcx)
movq %r9, 0x10(%rsp)
andq $0x0, (%r9)
leaq -0x1(%r14), %rcx
cmpq %r14, %rax
cmovlq %rax, %rcx
xorl %r12d, %r12d
testq %rcx, %rcx
cmovgq %rcx, %r12
testq %r14, %r14
jle 0x17ee5a
movq %rsi, %rbx
movl 0xc(%rdi), %eax
movq (%rsi), %r9
imulq $0x1c, %r12, %rcx
addq %r9, %rcx
addq $0xc, %rcx
testq %r12, %r12
js 0x17ed30
cmpl (%rcx), %eax
ja 0x17ed3d
decq %r12
addq $-0x1c, %rcx
jmp 0x17ed1e
cmpl 0xc(%r9), %eax
jne 0x17ee3c
xorl %r12d, %r12d
cmpq %r14, %r12
movq %r14, %rcx
cmovgq %r12, %rcx
imulq $0x1c, %r12, %r13
cmpq %r14, %r12
jge 0x17ed63
movl 0xc(%r9,%r13), %r8d
cmpl %r8d, %eax
jbe 0x17ed6b
incq %r12
addq $0x1c, %r13
jmp 0x17ed4b
movq %rcx, %r12
jmp 0x17ee5a
jne 0x17ee5a
movq %rdx, 0x28(%rsp)
addq %r13, %r9
movq %r9, 0x20(%rsp)
movq %r12, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
cmpq %r14, %r12
jge 0x17ee42
movl 0xc(%rdi), %eax
movq (%rbx), %rbp
cmpl 0xc(%rbp,%r13), %eax
jne 0x17ee42
movq %rbp, %r15
addq %r13, %r15
movq %r15, %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movsd 0x647fb(%rip), %xmm0    # 0x1e35b8
callq 0x17eb54
testq %rax, %rax
je 0x17ee20
movq 0x18(%rsp), %rdx
cmpq %rdx, %r12
je 0x17ee11
movups (%r15), %xmm0
movups 0xc(%r15), %xmm1
movups %xmm1, 0x4c(%rsp)
movaps %xmm0, 0x40(%rsp)
imulq $0x1c, %rdx, %rax
movups (%rbp,%rax), %xmm0
movups 0xc(%rbp,%rax), %xmm1
movups %xmm1, 0xc(%r15)
movups %xmm0, (%r15)
movq (%rbx), %rcx
movups 0x4c(%rsp), %xmm0
movups %xmm0, 0xc(%rcx,%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rcx,%rax)
incq %rdx
movq %rdx, 0x18(%rsp)
movq 0x10(%rsp), %rax
jmp 0x17ee28
movq 0xa0(%rsp), %rax
movq 0x8(%rsp), %rdi
incq (%rax)
incq %r12
addq $0x1c, %r13
jmp 0x17ed88
pushq $-0x1
popq %r12
jmp 0x17ee5a
movq 0x28(%rsp), %rdx
movq %r12, (%rdx)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
movq 0x20(%rsp), %rax
jne 0x17ee5f
movq %r12, (%rdx)
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq