// File: /workspace/github_cpp_makefile_star2_O1/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), %rbx
movq (%rdx), %rax
xorl %r10d, %r10d
movq %r10, (%r11)
movq %r10, (%r9)
leaq -0x1(%rbx), %r14
cmpq %rbx, %rax
cmovlq %rax, %r14
testq %r14, %r14
cmovleq %r10, %r14
testq %rbx, %rbx
jle 0x1c0d58
movl 0xc(%rdi), %eax
movq (%rsi), %r11
leaq (%r14,%r14,8), %r10
leaq (%r10,%r10,2), %r10
addq %r14, %r10
addq %r10, %r11
addq $0xc, %r11
cmpl (%r11), %eax
ja 0x1c0bda
leaq -0x1(%r14), %r10
addq $-0x1c, %r11
testq %r14, %r14
movq %r10, %r14
jg 0x1c0bbe
movq $-0x1, %r14
testq %r14, %r14
jns 0x1c0bf0
movl 0xc(%rdi), %eax
movq (%rsi), %r11
xorl %r10d, %r10d
cmpl 0xc(%r11), %eax
cmoveq %r10, %r14
cmpq %rbx, %r14
jae 0x1c0d58
movl 0xc(%rdi), %r15d
leaq 0x1(%r14), %r11
cmpq %r11, %rbx
cmovgq %rbx, %r11
movq (%rsi), %rax
leaq (%r14,%r14,8), %r10
leaq (%r10,%r10,2), %rbp
addq %r14, %rbp
cmpl 0xc(%rax,%rbp), %r15d
jbe 0x1c0c31
incq %r14
addq $0x1c, %rbp
cmpq %rbx, %r14
jl 0x1c0c16
movq %r11, %r14
jmp 0x1c0d58
cmpl 0xc(%rax,%rbp), %r15d
jne 0x1c0d58
cmpq %rbx, %r14
jge 0x1c0d4a
movq %rax, 0x8(%rsp)
movq %r9, (%rsp)
movq %rdx, 0x10(%rsp)
movq %rbp, %r13
movq %r14, %r12
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movl 0xc(%rdi), %eax
movq (%rsi), %r15
cmpl 0xc(%r15,%r13), %eax
jne 0x1c0d39
leaq (%r15,%r13), %rsi
movq %rsi, 0x38(%rsp)
movq %rcx, %rdx
movq %r8, %rcx
movsd 0x648d3(%rip), %xmm0    # 0x225568
callq 0x1c09f8
testq %rax, %rax
je 0x1c0d05
cmpq %r14, %r12
movq 0x20(%rsp), %rsi
je 0x1c0cf2
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 (%r15,%rax), %xmm0
movups 0xc(%r15,%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 0x30(%rsp), %r8
movq 0x28(%rsp), %rcx
jmp 0x1c0d1c
movq 0xa0(%rsp), %rax
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
incq (%rax)
incq %r12
addq $0x1c, %r13
cmpq %rbx, %r12
jl 0x1c0c6d
movq %rbx, %r14
jmp 0x1c0d3c
movq %r12, %r14
movq 0x10(%rsp), %rdx
movq (%rsp), %r9
movq 0x8(%rsp), %rax
movq %r14, (%rdx)
cmpq $0x0, (%r9)
je 0x1c0d58
addq %rbp, %rax
jmp 0x1c0d5d
movq %r14, (%rdx)
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq