// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: dedup_sort_ul_ov_t(ul_ov_t*, long)
int64_t dedup_sort_ul_ov_t(ul_ov_t *a, int64_t a_n)
{
	int64_t k, l, z, r, i, qo, to; float rr = 0.9;
	for (k = 1, l = i = 0; k <= a_n; k++) {
		if(k == a_n || a[k].tn != a[l].tn) {///remove the duplicated contained alignments
			for (z = l; z < k; z++) {
				for (r = i-1; r >= 0 && a[r].tn == a[z].tn; r--){
					/**
                	if(a[z].qn == a[r].qn && a[z].qs == a[r].qs && a[z].qe == a[r].qe && 
					   a[z].tn == a[r].tn && a[z].ts == a[r].ts && a[z].te == a[r].te && 
					   a[z].sec == a[r].sec && a[z].el == a[r].el && a[z].rev == a[r].rev) {
						   break;
					}
					**/
					if(a[z].qn == a[r].qn && a[z].tn == a[r].tn && a[z].rev == a[r].rev) {
						qo = ((MIN(a[z].qe, a[r].qe) > MAX(a[z].qs, a[r].qs))? 
															MIN(a[z].qe, a[r].qe) - MAX(a[z].qs, a[r].qs):0);
						to = ((MIN(a[z].te, a[r].te) > MAX(a[z].ts, a[r].ts))?
															MIN(a[z].te, a[r].te) - MAX(a[z].ts, a[r].ts):0);
						if(qo >= ((a[r].qe - a[r].qs)*rr) && qo >= ((a[z].qe - a[z].qs)*rr) && 
						   to >= ((a[r].te - a[r].ts)*rr) && to >= ((a[z].te - a[z].ts)*rr)) {
							break;
						}
					}
				}
				if(r >= 0 && a[r].tn == a[z].tn) {
					if(a[z].el) a[r].el = 1;
					continue;
				}
				a[i++] = a[z];
			}
			l = k;
		}
	}
	return i;
}

// Assembly:
testq %rsi, %rsi
jle 0x1a1263
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq -0x4(%rdi), %rax
movq %rax, -0x8(%rsp)
movl $0x1, %r8d
xorl %r9d, %r9d
movss 0x88b79(%rip), %xmm0    # 0x229bbc
xorl %eax, %eax
movq %rsi, -0x20(%rsp)
movq %rdi, -0x38(%rsp)
cmpq %rsi, %r8
je 0x1a1078
leaq (%r8,%r8,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r8, %rcx
movl 0xc(%rdi,%rcx), %ecx
leaq (%r9,%r9,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %r9, %rdx
cmpl 0xc(%rdi,%rdx), %ecx
je 0x1a1248
cmpq %r8, %r9
jge 0x1a1245
movq %r8, -0x18(%rsp)
movq %r9, -0x30(%rsp)
leaq (%r9,%r9,8), %rcx
movq %rcx, -0x10(%rsp)
movq %rax, -0x28(%rsp)
testq %rax, %rax
jle 0x1a11c4
movq -0x10(%rsp), %rax
leaq (%rax,%rax,2), %rcx
addq -0x30(%rsp), %rcx
movq -0x38(%rsp), %rax
leaq (%rax,%rcx), %r10
movl 0xc(%rax,%rcx), %ebx
movq -0x28(%rsp), %rdx
leaq 0x1(%rdx), %r14
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %r11
movq -0x8(%rsp), %rax
addq %rax, %r11
addq %rdx, %r11
movl -0xc(%r11), %ebp
cmpl %ebx, %ebp
jne 0x1a11c4
movl (%r10), %ecx
cmpl -0x18(%r11), %ecx
jne 0x1a11b3
movl (%r11), %ecx
xorl 0x18(%r10), %ecx
js 0x1a11b3
movl 0x4(%r10), %r12d
movl 0x8(%r10), %r15d
movl -0x14(%r11), %edx
movl -0x10(%r11), %esi
cmpl %esi, %r15d
movl %esi, %ecx
cmovbl %r15d, %ecx
cmpl %edx, %r12d
movl %edx, %edi
cmoval %r12d, %edi
xorps %xmm1, %xmm1
subl %edi, %ecx
ja 0x1a112d
xorps %xmm2, %xmm2
jmp 0x1a1135
xorps %xmm2, %xmm2
cvtsi2ss %rcx, %xmm2
movl 0x14(%r10), %r13d
movl -0x4(%r11), %edi
cmpl %edi, %r13d
movl %edi, %r9d
cmovbl %r13d, %r9d
movl 0x10(%r10), %ecx
movl -0x8(%r11), %eax
cmpl %eax, %ecx
movl %eax, %r8d
cmoval %ecx, %r8d
subl %r8d, %r9d
jbe 0x1a1165
xorps %xmm1, %xmm1
cvtsi2ss %r9, %xmm1
subl %edx, %esi
xorps %xmm3, %xmm3
cvtsi2ss %rsi, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0x1a11b3
subl %r12d, %r15d
xorps %xmm3, %xmm3
cvtsi2ss %r15, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0x1a11b3
subl %eax, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jb 0x1a11b3
subl %ecx, %r13d
xorps %xmm2, %xmm2
cvtsi2ss %r13, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jae 0x1a121a
decq %r14
addq $-0x1c, %r11
cmpq $0x1, %r14
jg 0x1a10d9
movq -0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq -0x30(%rsp), %r9
addq %r9, %rax
movq -0x28(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
incq %rdx
movq -0x38(%rsp), %rdi
movups (%rdi,%rax), %xmm1
movups 0xc(%rdi,%rax), %xmm2
movups %xmm2, 0xc(%rdi,%rcx)
movups %xmm1, (%rdi,%rcx)
movq %rdx, %rax
movq -0x20(%rsp), %rsi
movq -0x18(%rsp), %r8
incq %r9
cmpq %r8, %r9
jne 0x1a1086
jmp 0x1a1245
cmpl %ebx, %ebp
jne 0x1a11c4
testb $0x40, 0x1b(%r10)
je 0x1a122a
orb $0x40, 0x3(%r11)
movq -0x20(%rsp), %rsi
movq -0x38(%rsp), %rdi
movq -0x18(%rsp), %r8
movq -0x28(%rsp), %rax
movq -0x30(%rsp), %r9
jmp 0x1a120c
movq %r8, %r9
leaq 0x1(%r8), %rcx
cmpq %rsi, %r8
movq %rcx, %r8
jne 0x1a104f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq