// File: /workspace/github_cpp_makefile_star2_O3/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 0x82eb4
leaq 0xc(%rbx), %rax
movq %r14, %rcx
movl 0xc(%rax), %edx
shldl $0x1, %edx, (%rax)
addq $0x1c, %rax
decq %rcx
jne 0x82c3e
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %r14, %rsi
addq %rbx, %rsi
movq %rbx, %rdi
callq 0x46e1e
leaq -0x4(%rbx), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %esi
xorl %edi, %edi
movsd 0x1ae91c(%rip), %xmm0   # 0x231598
xorl %edx, %edx
movq %rbx, (%rsp)
movq %r14, 0x10(%rsp)
cmpq %r14, %rsi
je 0x82cb0
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 0x82ea2
cmpq %rsi, %rdi
jge 0x82e9f
movq %rsi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
leaq (%rdi,%rdi,8), %rax
movq %rax, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
testq %rdx, %rdx
jle 0x82e00
movq 0x30(%rsp), %rax
leaq (%rax,%rax,2), %rax
addq 0x8(%rsp), %rax
movq (%rsp), %rcx
leaq (%rcx,%rax), %r8
movl 0xc(%rcx,%rax), %eax
shrl %eax
movl %eax, 0x2c(%rsp)
movq 0x20(%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 0x2c(%rsp), %eax
cmpl %eax, -0xc(%r10)
jne 0x82e00
movl (%r10), %ebp
movl 0x18(%r8), %r13d
movl %r13d, %eax
xorl %ebp, %eax
js 0x82e00
movl 0x4(%r8), %esi
movl 0x8(%r8), %ebx
movl -0x14(%r10), %r9d
movl -0x10(%r10), %edx
cmpl %edx, %ebx
movl %edx, %eax
cmovbl %ebx, %eax
cmpl %r9d, %esi
movl %r9d, %ecx
cmoval %esi, %ecx
xorpd %xmm1, %xmm1
subl %ecx, %eax
ja 0x82d64
xorpd %xmm2, %xmm2
jmp 0x82d6c
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movl 0x14(%r8), %r15d
movl -0x4(%r10), %edi
cmpl %edi, %r15d
movl %edi, %r14d
cmovbl %r15d, %r14d
movl 0x10(%r8), %eax
movl -0x8(%r10), %r11d
cmpl %r11d, %eax
movl %r11d, %ecx
cmoval %eax, %ecx
subl %ecx, %r14d
jbe 0x82d9c
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
subl %r9d, %edx
xorps %xmm3, %xmm3
cvtsi2sd %rdx, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jb 0x82def
subl %esi, %ebx
xorps %xmm3, %xmm3
cvtsi2sd %rbx, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jb 0x82def
subl %r11d, %edi
xorps %xmm2, %xmm2
cvtsi2sd %rdi, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0x82def
subl %eax, %r15d
xorps %xmm2, %xmm2
cvtsi2sd %r15, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x82e5a
decq %r12
addq $-0x1c, %r10
cmpq $0x1, %r12
ja 0x82d16
movq 0x30(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0x8(%rsp), %rdi
addq %rdi, %rax
movq 0x20(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movq (%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 0x10(%rsp), %r14
movq 0x18(%rsp), %rsi
incq %rdi
cmpq %rsi, %rdi
jne 0x82cbe
jmp 0x82e9f
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl %eax, %r13d
andl %eax, %ebp
cmpl %ebp, %r13d
movq 0x20(%rsp), %rdx
jae 0x82e8a
leaq -0x18(%r10), %rax
movupd (%r8), %xmm1
movupd 0xc(%r8), %xmm2
movupd %xmm2, 0xc(%rax)
movupd %xmm1, (%rax)
shrl -0xc(%r10)
movq (%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdi
jmp 0x82e4c
movq %rsi, %rdi
leaq 0x1(%rsi), %rax
cmpq %r14, %rsi
movq %rax, %rsi
jne 0x82c87
jmp 0x82ecf
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %rbx, %r14
addq %rax, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x46e1e
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