// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movss %xmm1, (%rsp)
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jne 0x110f58
jnp 0x1111e5
movss (%rsp), %xmm1
ucomiss %xmm2, %xmm1
jne 0x110f68
jnp 0x1111e5
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0x1111e5
movq %rsi, %r14
movq $0x0, (%rsi)
movl $0x1, %ebp
xorl %ecx, %ecx
movl $0x2, %r15d
movss %xmm0, 0x4(%rsp)
movq 0x10(%rbx), %rdx
shlq $0x6, %rcx
ucomiss 0x38(%rdx,%rcx), %xmm0
ja 0x110ff8
addq %rcx, %rdx
movl 0x4(%rdx), %r13d
movl 0x8(%rdx), %r12d
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x110fe3
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r15, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movss 0x4(%rsp), %xmm0
movq %rax, 0x10(%r14)
movq (%r14), %rcx
shlq $0x20, %r13
orq %r13, %r12
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq %r12, (%rax,%rcx,8)
movq (%rbx), %rax
movl %ebp, %ecx
incl %ebp
cmpq %rcx, %rax
ja 0x110f94
movq (%r14), %rdi
testq %rdi, %rdi
je 0x1111e5
movq 0x10(%r14), %rsi
callq 0x10952d
movl $0x1, %eax
cmpq $0x2, (%r14)
jb 0x111098
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 0x111084
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 0x11108c
movl %eax, %esi
movq %r8, (%rcx,%rsi,8)
incl %eax
movl %edx, %r8d
incl %edx
cmpq %r8, (%r14)
ja 0x111035
movl %eax, %eax
movq %rax, (%r14)
movq (%rbx), %rdx
xorl %eax, %eax
testq %rdx, %rdx
je 0x1111e2
xorl %r8d, %r8d
xorl %ecx, %ecx
movss 0x4(%rsp), %xmm4
movq 0x10(%rbx), %rsi
shlq $0x6, %r8
leaq (%rsi,%r8), %rdi
ucomiss 0x38(%rsi,%r8), %xmm4
jbe 0x1111a5
movq (%r14), %r9
movl 0x8(%rdi), %r8d
testq %r9, %r9
je 0x111177
movq 0x10(%r14), %r10
movl 0x4(%rdi), %r11d
movl %r8d, %r15d
subl %r11d, %r15d
xorps %xmm0, %xmm0
cvtsi2ss %r15, %xmm0
mulss (%rsp), %xmm0
movl $0x1, %ebp
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r15, %r12
movq (%r10,%r13,8), %r15
cmpl %r15d, %r8d
movl %r15d, %r13d
cmovbl %r8d, %r13d
shrq $0x20, %r15
cmpq %r11, %r15
cmovbeq %r11, %r15
subq %r15, %r13
movl $0x0, %r15d
cmovaeq %r13, %r15
addq %r12, %r15
movq %r15, %r12
shrq %r12
testq %r15, %r15
js 0x111143
xorps %xmm1, %xmm1
cvtsi2ss %r15, %xmm1
jmp 0x111159
movl %r15d, %r13d
andl $0x1, %r13d
orq %r12, %r13
xorps %xmm1, %xmm1
cvtsi2ss %r13, %xmm1
addss %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jae 0x1111d2
movl %ebp, %r13d
incl %ebp
cmpq %r13, %r9
ja 0x111102
testq %r15, %r15
js 0x11118d
xorps %xmm1, %xmm1
cvtsi2ss %r15, %xmm1
jmp 0x1111a0
subl 0x4(%rdi), %r8d
xorps %xmm0, %xmm0
cvtsi2ss %r8, %xmm0
mulss (%rsp), %xmm0
xorps %xmm1, %xmm1
jmp 0x1111a0
andl $0x1, %r15d
orq %r12, %r15
xorps %xmm1, %xmm1
cvtsi2ss %r15, %xmm1
addss %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jae 0x1111d2
movl %eax, %edx
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 %eax
movq (%rbx), %rdx
incl %ecx
movq %rcx, %r8
cmpq %rcx, %rdx
ja 0x1110b4
movl %eax, %eax
movq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq