// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
movq %rdi, 0x30(%rsp)
movq 0x8(%rdi), %rcx
xorl %edx, %edx
testq %rcx, %rcx
movq %rcx, 0x20(%rsp)
cmovgq %rcx, %rdx
movq %rax, (%rsp)
addq $0xc, %rax
movq %rdx, 0x28(%rsp)
movq %rdx, %rcx
subq $0x1, %rcx
jb 0x4f798
movl 0xc(%rax), %edx
shldl $0x1, %edx, (%rax)
addq $0x1c, %rax
jmp 0x4f785
imulq $0x1c, 0x20(%rsp), %rsi
movq (%rsp), %rbx
addq %rbx, %rsi
movq %rbx, %rdi
callq 0x1aa87
incq 0x28(%rsp)
leaq -0x4(%rbx), %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rsi
xorl %r11d, %r11d
movsd 0x193d1f(%rip), %xmm0   # 0x1e34e8
xorl %edi, %edi
cmpq 0x28(%rsp), %rsi
je 0x4f97f
cmpq 0x20(%rsp), %rsi
je 0x4f7f7
imulq $0x1c, %rsi, %rax
movq (%rsp), %rdx
movl 0xc(%rdx,%rax), %eax
imulq $0x1c, %rdi, %rcx
cmpl 0xc(%rdx,%rcx), %eax
je 0x4f977
movq %rsi, 0x8(%rsp)
cmpq %rsi, %rdi
jge 0x4f974
movq %rdi, 0x10(%rsp)
imulq $0x1c, %rdi, %r8
addq (%rsp), %r8
imulq $0x1c, %r11, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x40(%rsp)
leaq (%rax,%rcx), %r9
movq %r11, 0x18(%rsp)
testq %r11, %r11
jle 0x4f905
movl 0xc(%r8), %eax
shrl %eax
cmpl %eax, -0xc(%r9)
jne 0x4f905
movl (%r9), %ebp
movl 0x18(%r8), %r13d
movl %r13d, %eax
xorl %ebp, %eax
js 0x4f905
movl 0x4(%r8), %esi
movl 0x8(%r8), %ebx
movl -0x14(%r9), %edx
movl -0x10(%r9), %eax
cmpl %eax, %ebx
movl %eax, %ecx
cmovbl %ebx, %ecx
cmpl %edx, %esi
movl %edx, %edi
cmoval %esi, %edi
xorpd %xmm1, %xmm1
subl %edi, %ecx
ja 0x4f880
xorpd %xmm2, %xmm2
jmp 0x4f885
cvtsi2sd %rcx, %xmm2
movl 0x14(%r8), %r15d
movl -0x4(%r9), %edi
cmpl %edi, %r15d
movl %edi, %r14d
cmovbl %r15d, %r14d
movl 0x10(%r8), %r12d
movl -0x8(%r9), %r10d
cmpl %r10d, %r12d
movl %r10d, %ecx
cmoval %r12d, %ecx
subl %ecx, %r14d
jbe 0x4f8b3
cvtsi2sd %r14, %xmm1
subl %edx, %eax
cvtsi2sd %rax, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jb 0x4f8f9
subl %esi, %ebx
cvtsi2sd %rbx, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jb 0x4f8f9
subl %r10d, %edi
cvtsi2sd %rdi, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0x4f8f9
subl %r12d, %r15d
cvtsi2sd %r15, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x4f942
addq $-0x1c, %r9
decq %r11
jmp 0x4f829
movupd (%r8), %xmm1
movupd 0xc(%r8), %xmm2
movq (%rsp), %rax
movq 0x40(%rsp), %rcx
movupd %xmm2, 0xc(%rax,%rcx)
movupd %xmm1, (%rax,%rcx)
shrl 0xc(%rax,%rcx)
movq 0x18(%rsp), %r11
incq %r11
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
incq %rdi
jmp 0x4f7fc
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl %eax, %r13d
andl %eax, %ebp
cmpl %ebp, %r13d
jae 0x4f96d
leaq -0x18(%r9), %rax
movupd (%r8), %xmm1
movupd 0xc(%r8), %xmm2
movupd %xmm2, 0xc(%rax)
movupd %xmm1, (%rax)
shrl -0xc(%r9)
movq 0x18(%rsp), %r11
jmp 0x4f930
movq %rsi, %rdi
incq %rsi
jmp 0x4f7cb
movq 0x30(%rsp), %rax
movq %r11, 0x8(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq