// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: filter_secondary_ovlp(kvec_hap_overlaps*, kvec_t_u64_warp*, float, float)
void filter_secondary_ovlp(kvec_hap_overlaps *x, kvec_t_u64_warp *a, float sim_flt, float ovlp_flt)
{
    if(sim_flt == 0 || ovlp_flt == 0 || x->a.n == 0) return;
    #define f_ovlp(s_0, e_0, s_1, e_1) ((MIN((e_0), (e_1)) > MAX((s_0), (s_1)))? MIN((e_0), (e_1)) - MAX((s_0), (s_1)):0)
    uint32_t i, m, k;
    uint64_t t, ovlp;
    hap_overlaps *p = NULL;
    a->a.n = 0;
    for (i = 0; i < x->a.n; i++)
    {
        if(x->a.a[i].s < sim_flt) continue;
        t = x->a.a[i].x_beg_pos; t<<=32; t |= x->a.a[i].x_end_pos;
        kv_push(uint64_t, a->a, t);
    }

    if(a->a.n == 0) return;
    ks_introsort_uint64_t(a->a.n, a->a.a);

    for (i = m = 1; i < a->a.n; ++i) 
    {
        t = a->a.a[m-1];
        ovlp = f_ovlp(t>>32, (uint32_t)t, a->a.a[i]>>32, (uint32_t)a->a.a[i]);
        if(ovlp == 0)
        {
            a->a.a[m] = a->a.a[i];
            m++;
        } 
        else
        {
            t = MIN(a->a.a[m-1]>>32, a->a.a[i]>>32);
            t<<=32;
            t |= MAX((uint32_t)a->a.a[m-1], (uint32_t)a->a.a[i]);
            a->a.a[m-1] = t;
        }
    }
    a->a.n = m;

    for (i = m = 0; i < x->a.n; i++)
    {
        p = &(x->a.a[i]);
        if(p->s < sim_flt)
        {
            for (k = ovlp = 0; k < a->a.n; k++)
            {
                ovlp += f_ovlp(p->x_beg_pos, p->x_end_pos, a->a.a[k]>>32, (uint32_t)a->a.a[k]);
                if(ovlp >= ovlp_flt*(p->x_end_pos-p->x_beg_pos)) break;
            }
            if(k < a->a.n) continue;
            if(ovlp >= ovlp_flt*(p->x_end_pos-p->x_beg_pos)) continue;
        } 
        x->a.a[m] = x->a.a[i];
        m++;
    }
    x->a.n = m;
}

// Assembly:
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jne 0xcd413
jnp 0xcd674
ucomiss %xmm2, %xmm1
jne 0xcd41e
jnp 0xcd674
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0xcd666
movq %rsi, %r14
andq $0x0, (%rsi)
xorl %r15d, %r15d
pushq $0x2
popq %r12
movss %xmm1, 0x4(%rsp)
movss %xmm0, (%rsp)
movl %r15d, %r15d
cmpq %r15, %rax
jbe 0xcd4c3
movq 0x10(%rbx), %rcx
movq %r15, %rdx
shlq $0x6, %rdx
ucomiss 0x38(%rcx,%rdx), %xmm0
ja 0xcd4be
addq %rdx, %rcx
movl 0x4(%rcx), %ebp
movl 0x8(%rcx), %r13d
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0xcd4a9
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movss (%rsp), %xmm0
movq %rax, 0x10(%r14)
movq (%r14), %rcx
shlq $0x20, %rbp
orq %rbp, %r13
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq %r13, (%rax,%rcx,8)
movq (%rbx), %rax
incl %r15d
jmp 0xcd451
movq (%r14), %rdi
testq %rdi, %rdi
je 0xcd666
movq 0x10(%r14), %rsi
callq 0xc6d8b
pushq $0x1
popq %rax
movl %eax, %ecx
movl %eax, %eax
movl %ecx, %edi
cmpq %rax, (%r14)
jbe 0xcd544
movq 0x10(%r14), %rdx
leal -0x1(%rcx), %esi
movq (%rdx,%rsi,8), %r8
movq (%rdx,%rax,8), %r9
cmpl %r9d, %r8d
movq %r8, %r15
cmovaq %r9, %r15
movq %r8, %r11
shrq $0x20, %r11
movq %r9, %r10
shrq $0x20, %r10
cmpq %r10, %r11
movq %r10, %r12
cmovaq %r11, %r12
cmpl %r12d, %r15d
jbe 0xcd53a
cmpq %r10, %r11
cmovbq %r11, %r10
shlq $0x20, %r10
cmpl %r9d, %r8d
cmovbq %r9, %r8
movl %r8d, %edi
orq %r10, %rdi
movq %rdi, (%rdx,%rsi,8)
jmp 0xcd540
movq %r9, (%rdx,%rdi,8)
incl %ecx
incl %eax
jmp 0xcd4dd
movq %rdi, (%r14)
xorl %eax, %eax
xorl %ecx, %ecx
movss 0x4(%rsp), %xmm4
movss (%rsp), %xmm5
movl %eax, %eax
movl %ecx, %edx
cmpq %rax, (%rbx)
jbe 0xcd663
movq 0x10(%rbx), %rsi
movq %rax, %r8
shlq $0x6, %r8
leaq (%rsi,%r8), %rdi
ucomiss 0x38(%rsi,%r8), %xmm5
jbe 0xcd634
movq (%r14), %r9
xorl %r10d, %r10d
xorl %r8d, %r8d
movl %r10d, %r10d
cmpq %r10, %r9
jbe 0xcd5fc
movl 0x4(%rdi), %r15d
movl 0x8(%rdi), %r11d
movq 0x10(%r14), %r12
movq (%r12,%r10,8), %r12
cmpl %r12d, %r11d
movl %r12d, %r13d
cmovbl %r11d, %r13d
shrq $0x20, %r12
cmpq %r15, %r12
cmovbeq %r15, %r12
subq %r12, %r13
movl $0x0, %r12d
cmovaeq %r13, %r12
addq %r12, %r8
js 0xcd5cd
cvtsi2ss %r8, %xmm0
jmp 0xcd5e6
movq %r8, %r12
shrq %r12
movl %r8d, %r13d
andl $0x1, %r13d
orq %r12, %r13
cvtsi2ss %r13, %xmm0
addss %xmm0, %xmm0
subl %r15d, %r11d
cvtsi2ss %r11, %xmm1
mulss %xmm4, %xmm1
incl %r10d
ucomiss %xmm1, %xmm0
jb 0xcd587
jmp 0xcd65c
testq %r8, %r8
js 0xcd608
cvtsi2ss %r8, %xmm0
jmp 0xcd61e
movq %r8, %r9
shrq %r9
andl $0x1, %r8d
orq %r9, %r8
cvtsi2ss %r8, %xmm0
addss %xmm0, %xmm0
movl 0x8(%rdi), %r8d
subl 0x4(%rdi), %r8d
cvtsi2ss %r8, %xmm1
mulss %xmm4, %xmm1
ucomiss %xmm1, %xmm0
jae 0xcd65c
shlq $0x6, %rdx
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movups 0x30(%rdi), %xmm3
movups %xmm3, 0x30(%rsi,%rdx)
movups %xmm2, 0x20(%rsi,%rdx)
movups %xmm1, 0x10(%rsi,%rdx)
movups %xmm0, (%rsi,%rdx)
incl %ecx
incl %eax
jmp 0xcd556
movq %rdx, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq