// File: /workspace/github_cpp_makefile_star2_O3/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 0xa0(%rsp), %r11
movq 0x8(%rsi), %r12
movq (%rdx), %rax
xorl %r10d, %r10d
movq %r10, (%r11)
movq %r10, (%r9)
leaq -0x1(%r12), %r14
cmpq %r12, %rax
cmovlq %rax, %r14
testq %r14, %r14
cmovleq %r10, %r14
testq %r12, %r12
jle 0x1cad36
movl 0xc(%rdi), %eax
movq (%rsi), %r15
leaq (%r14,%r14,8), %r10
leaq (%r10,%r10,2), %r10
addq %r14, %r10
leaq (%r15,%r10), %r11
addq $0xc, %r11
cmpl (%r11), %eax
ja 0x1cabd5
leaq -0x1(%r14), %r10
addq $-0x1c, %r11
testq %r14, %r14
movq %r10, %r14
jg 0x1cabac
movq $-0x1, %r14
cmpl 0xc(%r15), %eax
jne 0x1cad36
xorl %r14d, %r14d
cmpq %r12, %r14
jge 0x1cad36
leaq (%r14,%r14,8), %r10
leaq (%r10,%r10,2), %rbx
addq %r14, %rbx
movl 0xc(%r15,%rbx), %r10d
cmpl %r10d, %eax
jbe 0x1cac07
incq %r14
addq $0x1c, %rbx
cmpq %r14, %r12
jne 0x1cabe9
movq %r12, %r14
jmp 0x1cad36
jne 0x1cad36
cmpq %r12, %r14
jge 0x1cad28
movq %r9, (%rsp)
movq %rdx, 0x8(%rsp)
movq %rbx, %rbp
movq %r14, %rdx
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movl 0xc(%rdi), %eax
movq (%rsi), %r13
cmpl 0xc(%r13,%rbp), %eax
jne 0x1cad1c
movq %rdx, 0x30(%rsp)
movq %r13, %rsi
addq %rbp, %rsi
movq %rsi, 0x38(%rsp)
movq %rcx, %rdx
movq %r8, %rcx
movsd 0x66a00(%rip), %xmm0    # 0x231668
callq 0x1ca9e4
testq %rax, %rax
je 0x1cace3
movq 0x30(%rsp), %rdx
cmpq %r14, %rdx
movq 0x18(%rsp), %rsi
je 0x1caccb
movq 0x38(%rsp), %rcx
movups (%rcx), %xmm0
movups 0xc(%rcx), %xmm1
movups %xmm1, 0x4c(%rsp)
movaps %xmm0, 0x40(%rsp)
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movups (%r13,%rax), %xmm0
movups 0xc(%r13,%rax), %xmm1
movups %xmm1, 0xc(%rcx)
movups %xmm0, (%rcx)
movq (%rsi), %rcx
movups 0x4c(%rsp), %xmm0
movups %xmm0, 0xc(%rcx,%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rcx,%rax)
incq %r14
movq (%rsp), %rax
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %rdi
jmp 0x1cad04
movq 0xa0(%rsp), %rax
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rdx
incq (%rax)
incq %rdx
addq $0x1c, %rbp
cmpq %r12, %rdx
jl 0x1cac39
movq %r12, %r14
jmp 0x1cad1f
movq %rdx, %r14
movq 0x8(%rsp), %rdx
movq (%rsp), %r9
movq %r14, (%rdx)
cmpq $0x0, (%r9)
je 0x1cad36
addq %rbx, %r15
jmp 0x1cad3c
movq %r14, (%rdx)
xorl %r15d, %r15d
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq