// File: /workspace/github_cpp_makefile_star2_O1/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 0x10bdd9
jnp 0x10c0b8
ucomiss %xmm2, %xmm1
jne 0x10bde4
jnp 0x10c0b8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpq $0x0, (%rdi)
je 0x10c0aa
movq %rsi, %r14
movq $0x0, (%rsi)
cmpq $0x0, (%rbx)
movss %xmm1, 0x4(%rsp)
movss %xmm0, (%rsp)
je 0x10be8e
movl $0x1, %ebp
xorl %eax, %eax
movl $0x2, %r15d
movq 0x10(%rbx), %rcx
shlq $0x6, %rax
ucomiss 0x38(%rcx,%rax), %xmm0
ja 0x10be85
addq %rax, %rcx
movl 0x4(%rcx), %r13d
movl 0x8(%rcx), %r12d
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x10be6c
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
movss (%rsp), %xmm0
movq %rax, 0x10(%r14)
shlq $0x20, %r13
orq %r13, %r12
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %r12, (%rcx,%rax,8)
movl %ebp, %eax
incl %ebp
cmpq %rax, (%rbx)
ja 0x10be24
movq (%r14), %rdi
testq %rdi, %rdi
je 0x10c0aa
movq 0x10(%r14), %rsi
callq 0x104db6
movl $0x1, %eax
cmpq $0x2, (%r14)
jb 0x10bf25
movq 0x10(%r14), %rcx
movl $0x1, %eax
movl $0x1, %r8d
movl $0x2, %edx
leal -0x1(%rax), %esi
movq (%rcx,%rsi,8), %rdi
movq (%rcx,%r8,8), %r8
cmpl %r8d, %edi
movq %rdi, %r11
cmovaq %r8, %r11
movq %rdi, %r10
shrq $0x20, %r10
movq %r8, %r9
shrq $0x20, %r9
cmpq %r9, %r10
movq %r9, %r15
cmovaq %r10, %r15
cmpl %r15d, %r11d
jbe 0x10bf11
cmpq %r9, %r10
cmovbq %r10, %r9
shlq $0x20, %r9
cmpl %r8d, %edi
cmovbq %r8, %rdi
movl %edi, %edi
orq %r9, %rdi
movq %rdi, (%rcx,%rsi,8)
jmp 0x10bf19
movl %eax, %esi
movq %r8, (%rcx,%rsi,8)
incl %eax
movl %edx, %r8d
incl %edx
cmpq %r8, (%r14)
ja 0x10bec2
movl %eax, %eax
movq %rax, (%r14)
xorl %eax, %eax
cmpq $0x0, (%rbx)
je 0x10c0a7
xorl %edi, %edi
xorl %ecx, %ecx
movss 0x4(%rsp), %xmm4
movss (%rsp), %xmm5
movq 0x10(%rbx), %rdx
shlq $0x6, %rdi
leaq (%rdx,%rdi), %rsi
ucomiss 0x38(%rdx,%rdi), %xmm5
jbe 0x10c06d
movq (%r14), %r8
testq %r8, %r8
setne %dil
je 0x10c033
movl 0x4(%rsi), %r9d
movl 0x8(%rsi), %r10d
movl %r10d, %r11d
subl %r9d, %r11d
xorps %xmm0, %xmm0
cvtsi2ss %r11, %xmm0
movq 0x10(%r14), %r15
movq (%r15), %r11
cmpl %r11d, %r10d
movl %r11d, %r12d
cmovbl %r10d, %r12d
shrq $0x20, %r11
cmpq %r9, %r11
cmovbeq %r9, %r11
subq %r11, %r12
movl $0x0, %r11d
cmovaeq %r12, %r11
xorps %xmm1, %xmm1
cvtsi2ss %r11, %xmm1
mulss %xmm4, %xmm0
ucomiss %xmm0, %xmm1
jae 0x10c024
movl $0x1, %r12d
movl %r12d, %r12d
cmpq %r12, %r8
seta %dil
jbe 0x10c024
movq (%r15,%r12,8), %r13
cmpl %r13d, %r10d
movl %r13d, %ebp
cmovbl %r10d, %ebp
shrq $0x20, %r13
cmpq %r9, %r13
cmovbeq %r9, %r13
subq %r13, %rbp
movl $0x0, %r13d
cmovaeq %rbp, %r13
addq %r13, %r11
js 0x10c001
xorps %xmm1, %xmm1
cvtsi2ss %r11, %xmm1
jmp 0x10c01c
movq %r11, %r13
shrq %r13
movl %r11d, %ebp
andl $0x1, %ebp
orq %r13, %rbp
xorps %xmm1, %xmm1
cvtsi2ss %rbp, %xmm1
addss %xmm1, %xmm1
incl %r12d
ucomiss %xmm0, %xmm1
jb 0x10bfc0
testq %r11, %r11
js 0x10c038
xorps %xmm0, %xmm0
cvtsi2ss %r11, %xmm0
jmp 0x10c051
xorps %xmm0, %xmm0
jmp 0x10c051
movq %r11, %r8
shrq %r8
andl $0x1, %r11d
orq %r8, %r11
xorps %xmm0, %xmm0
cvtsi2ss %r11, %xmm0
addss %xmm0, %xmm0
testb %dil, %dil
jne 0x10c097
movl 0x8(%rsi), %edi
subl 0x4(%rsi), %edi
xorps %xmm1, %xmm1
cvtsi2ss %rdi, %xmm1
mulss %xmm4, %xmm1
ucomiss %xmm1, %xmm0
jae 0x10c097
movl %eax, %edi
shlq $0x6, %rdi
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups 0x30(%rsi), %xmm3
movups %xmm3, 0x30(%rdx,%rdi)
movups %xmm2, 0x20(%rdx,%rdi)
movups %xmm1, 0x10(%rdx,%rdi)
movups %xmm0, (%rdx,%rdi)
incl %eax
incl %ecx
movq %rcx, %rdi
cmpq %rcx, (%rbx)
ja 0x10bf43
movl %eax, %eax
movq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq