// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
xorl %eax, %eax
testq %rsi, %rsi
movl $0x0, %ecx
movq %rsi, -0x30(%rsp)
cmovgq %rsi, %rcx
incq %rcx
movq %rcx, -0x28(%rsp)
leaq -0x4(%rdi), %rcx
movq %rcx, -0x20(%rsp)
movabsq $0x1, %rsi
movss 0x85e2a(%rip), %xmm0    # 0x1e7cb4
xorl %r8d, %r8d
movq %rdi, -0x40(%rsp)
cmpq -0x28(%rsp), %rsi
je 0x16202a
cmpq -0x30(%rsp), %rsi
je 0x161eba
imulq $0x1c, %rsi, %rcx
movl 0xc(%rdi,%rcx), %edx
imulq $0x1c, %r8, %rcx
cmpl 0xc(%rdi,%rcx), %edx
je 0x162022
movq %rsi, -0x18(%rsp)
cmpq %rsi, %r8
jge 0x16201f
movq %r8, -0x8(%rsp)
imulq $0x1c, %r8, %r10
addq %rdi, %r10
imulq $0x1c, %rax, %rdx
movq -0x20(%rsp), %rcx
movq %rdx, -0x10(%rsp)
leaq (%rcx,%rdx), %rbx
movq %rax, -0x38(%rsp)
movq %rax, %r14
testq %r14, %r14
jle 0x161fce
movl -0xc(%rbx), %eax
cmpl 0xc(%r10), %eax
jne 0x161fce
movl (%r10), %eax
cmpl -0x18(%rbx), %eax
jne 0x161fc2
movl 0x18(%r10), %r15d
movl (%rbx), %ebp
movl %ebp, %eax
xorl %r15d, %eax
js 0x161fc2
movl 0x4(%r10), %r13d
movl 0x8(%r10), %r12d
movl -0x14(%rbx), %r8d
movl -0x10(%rbx), %edx
cmpl %edx, %r12d
movl %edx, %ecx
cmovbl %r12d, %ecx
cmpl %r8d, %r13d
movl %r8d, %eax
cmoval %r13d, %eax
xorps %xmm1, %xmm1
subl %eax, %ecx
ja 0x161f4f
xorps %xmm2, %xmm2
jmp 0x161f54
cvtsi2ss %rcx, %xmm2
movl 0x14(%r10), %ecx
movl -0x4(%rbx), %eax
cmpl %eax, %ecx
movl %eax, %r9d
cmovbl %ecx, %r9d
movl 0x10(%r10), %esi
movl -0x8(%rbx), %r11d
cmpl %r11d, %esi
movl %r11d, %edi
cmoval %esi, %edi
subl %edi, %r9d
jbe 0x161f7f
cvtsi2ss %r9, %xmm1
subl %r8d, %edx
cvtsi2ss %rdx, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0x161fc2
subl %r13d, %r12d
cvtsi2ss %r12, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jb 0x161fc2
subl %r11d, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jb 0x161fc2
subl %esi, %ecx
cvtsi2ss %rcx, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jae 0x162004
addq $-0x1c, %rbx
decq %r14
jmp 0x161eee
movq -0x38(%rsp), %rax
incq %rax
movups (%r10), %xmm1
movups 0xc(%r10), %xmm2
movq -0x40(%rsp), %rdi
movq -0x10(%rsp), %rcx
movups %xmm2, 0xc(%rdi,%rcx)
movups %xmm1, (%rdi,%rcx)
movq -0x8(%rsp), %r8
incq %r8
movq -0x18(%rsp), %rsi
jmp 0x161ebf
btl $0x1e, %r15d
jae 0x162013
orl $0x40000000, %ebp       # imm = 0x40000000
movl %ebp, (%rbx)
movq -0x38(%rsp), %rax
movq -0x40(%rsp), %rdi
jmp 0x161ff2
movq %rsi, %r8
incq %rsi
jmp 0x161e92
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq