// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: dedup_ul_ov_t(kv_ul_ov_t*)
void dedup_ul_ov_t(kv_ul_ov_t *in)
{
    ul_ov_t *a = in->a; int64_t k, l, m, z, r, a_n = in->n; uint64_t qo, to; double rr = 0.95;
    for (k = 0; k < a_n; k++) a[k].tn = ((uint32_t)(a[k].tn<<1))|((uint32_t)(a[k].rev));
    radix_sort_ul_ov_srt_tn1(a, a + a_n);
    for (k = 1, l = m = 0; k <= a_n; k++) {
        if(k == a_n || a[k].tn != a[l].tn) {
            for (z = l; z < k; z++) {
                for (r=m-1; (r>=0) && (a[r].tn==(a[z].tn>>1)) && (a[r].rev==a[z].rev); r--) {
                    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>>1)) && (a[r].rev==a[z].rev)) {
                    if(a[z].sec < a[r].sec) {
                        a[r] = a[z]; a[r].tn >>= 1; 
                    }
                    continue;
                }
                a[m] = a[z]; a[m].tn >>= 1; m++;
            }
            l = k;
        }
    }
    // fprintf(stderr, "[M::%s::] in->n0::%ld, in->n::%ld\n", __func__, (int64_t)in->n, m);
    in->n = m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq (%rdi), %rbx
movq %rdi, 0x38(%rsp)
movq 0x8(%rdi), %r14
testq %r14, %r14
jle 0x83471
leaq 0xc(%rbx), %rax
movq %r14, %rcx
movl 0xc(%rax), %edx
shldl $0x1, %edx, (%rax)
addq $0x1c, %rax
decq %rcx
jne 0x83461
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rbx, %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x4781a
testq %r14, %r14
jle 0x836eb
leaq -0x4(%rbx), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %esi
xorl %edi, %edi
movsd 0x1a1ff0(%rip), %xmm0   # 0x225498
xorl %edx, %edx
movq %rbx, 0x8(%rsp)
movq %r14, 0x20(%rsp)
cmpq %r14, %rsi
je 0x834dd
leaq (%rsi,%rsi,8), %rax
leaq (%rax,%rax,2), %rax
addq %rsi, %rax
movl 0xc(%rbx,%rax), %eax
leaq (%rdi,%rdi,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdi, %rcx
cmpl 0xc(%rbx,%rcx), %eax
je 0x836d9
cmpq %rsi, %rdi
jge 0x836d6
movq %rsi, 0x28(%rsp)
movq %rdi, 0x10(%rsp)
leaq (%rdi,%rdi,8), %rax
movq %rax, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
testq %rdx, %rdx
jle 0x8367d
movq 0x30(%rsp), %rax
leaq (%rax,%rax,2), %rax
addq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r8
movl 0xc(%rcx,%rax), %r11d
shrl %r11d
movq 0x18(%rsp), %rcx
leaq 0x1(%rcx), %r12
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %r10
movq 0x40(%rsp), %rax
addq %rcx, %rax
addq %rax, %r10
movl -0xc(%r10), %ebp
cmpl %r11d, %ebp
jne 0x8367d
movl 0x18(%r8), %eax
xorl (%r10), %eax
js 0x83627
movl 0x4(%r8), %ebx
movl 0x8(%r8), %r13d
movl -0x14(%r10), %edx
movl -0x10(%r10), %eax
cmpl %eax, %r13d
movl %eax, %esi
cmovbl %r13d, %esi
cmpl %edx, %ebx
movl %edx, %ecx
cmoval %ebx, %ecx
xorpd %xmm1, %xmm1
subl %ecx, %esi
ja 0x8358a
xorpd %xmm2, %xmm2
jmp 0x83592
xorps %xmm2, %xmm2
cvtsi2sd %rsi, %xmm2
movl 0x14(%r8), %esi
movl -0x4(%r10), %ecx
cmpl %ecx, %esi
movl %ecx, %r9d
cmovbl %esi, %r9d
movl 0x10(%r8), %r15d
movl -0x8(%r10), %edi
cmpl %edi, %r15d
movl %edi, %r14d
cmoval %r15d, %r14d
subl %r14d, %r9d
jbe 0x835c2
xorps %xmm1, %xmm1
cvtsi2sd %r9, %xmm1
subl %edx, %eax
xorps %xmm3, %xmm3
cvtsi2sd %rax, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jb 0x83614
subl %ebx, %r13d
xorps %xmm3, %xmm3
cvtsi2sd %r13, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jb 0x83614
subl %edi, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0x83614
subl %r15d, %esi
xorps %xmm2, %xmm2
cvtsi2sd %rsi, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x83627
decq %r12
addq $-0x1c, %r10
cmpq $0x1, %r12
jg 0x83542
jmp 0x8367d
cmpl %r11d, %ebp
jne 0x8367d
movl (%r10), %eax
movl 0x18(%r8), %ecx
movl %ecx, %edx
xorl %eax, %edx
js 0x8367d
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl %edx, %ecx
andl %edx, %eax
cmpl %eax, %ecx
jae 0x83662
leaq -0x18(%r10), %rax
movupd (%r8), %xmm1
movupd 0xc(%r8), %xmm2
movupd %xmm2, 0xc(%rax)
movupd %xmm1, (%rax)
shrl -0xc(%r10)
movq 0x8(%rsp), %rbx
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdi
jmp 0x836ca
movq 0x30(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %rdi
addq %rdi, %rax
movq 0x18(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movq 0x8(%rsp), %rbx
movupd (%rbx,%rax), %xmm1
movupd 0xc(%rbx,%rax), %xmm2
movupd %xmm2, 0xc(%rbx,%rcx)
movupd %xmm1, (%rbx,%rcx)
shrl 0xc(%rbx,%rcx)
incq %rdx
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %rsi
incq %rdi
cmpq %rsi, %rdi
jne 0x834eb
movq %rsi, %rdi
leaq 0x1(%rsi), %rax
cmpq %r14, %rsi
movq %rax, %rsi
jne 0x834b4
jmp 0x836ed
xorl %edx, %edx
movq 0x38(%rsp), %rax
movq %rdx, 0x8(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq