// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: purge_ovlp_cov(unsigned int, kv_u_trans_t*, ma_ug_t*, asg_t*, asg64_v*, unsigned long*, unsigned long)
void purge_ovlp_cov(uint32_t id, kv_u_trans_t *ta, ma_ug_t *ug, asg_t *sg, asg64_v *b64, uint64_t *cc, uint64_t hom_cut)
{
    ma_utg_t *u = &(ug->u.a[id]); uint32_t k, n, cn;
    u_trans_t *a = NULL, t; 
    kv_resize(uint64_t, *b64, u->n);
    for (k = 0; k < u->n; k++) b64->a[k] = cc[u->a[k]>>33];
    a = u_trans_a(*ta, id); n = u_trans_n(*ta, id); 
    // if(id == 315 || id == 1055)  {
    //     fprintf(stderr, "\n[M::%s]\tutg%.6u%c\tn::%u\n", __func__, id+1, "lc"[ug->u.a[id].circ], n);
    // }
    for (k = cn = 0; k < n; k++) {///RC_0/RC_1 to a[0, r_n)
        // if(id == 315 || id == 1055)  {
        //     fprintf(stderr, "-0-[M::%s]\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tis_reliable::%u\tw::%f\n", __func__, 
        //     a[k].qn+1, "lc"[ug->u.a[a[k].qn].circ], ug->u.a[a[k].qn].len, a[k].qs, a[k].qe, "+-"[a[k].rev],
        //     a[k].tn+1, "lc"[ug->u.a[a[k].tn].circ], ug->u.a[a[k].tn].len, a[k].ts, a[k].te, 
        //     ((a[k].f == RC_0) || (a[k].f == RC_1))?1:0, a[k].nw);
        // }
        if((a[k].f == RC_0) || (a[k].f == RC_1)) {
            if(k != cn) {
                t = a[k]; a[k] = a[cn]; a[cn] = t;
            }
            cn++;
        }
    }
    // if(id == 315 || id == 1055)  {
    //     fprintf(stderr, "[M::%s]\tutg%.6u%c\tn::%u\tcn::%u\n", __func__, 
    //         id+1, "lc"[ug->u.a[id].circ], n, cn);
    // }
    if(cn >= n) return;
    if(n-cn > 1) qsort(a+cn, n-cn, sizeof((*a)), cmp_u_trans_weight);
    for (k = 0; k < cn; k++) {///calculate coverage for 
        append_cov_line(id, b64->a, cc, &(a[k]), ug, sg, ((uint64_t)-1), -1);
    }

    for (k = cn; k < n; k++) {
        if(append_cov_line(id, b64->a, cc, &(a[k]), ug, sg, hom_cut, 0.51)) {
            append_cov_line(id, b64->a, cc, &(a[k]), ug, sg, ((uint64_t)-1), -1);
            continue;
        }
        a[k].del = 1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r12
movq %rdx, %r8
movq %rsi, %rbp
movq 0x10(%rdx), %rax
movl %edi, %r15d
leaq (%r15,%r15,4), %rcx
leaq (%rax,%rcx,8), %r13
movl 0x10(%r13), %eax
cmpq %rax, 0x8(%r14)
movq %rdx, 0x8(%rsp)
jae 0xc6dda
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x10(%r14)
movl 0x10(%r13), %eax
testq %rax, %rax
je 0xc6e05
movq 0x18(%r13), %rcx
movq 0x10(%r14), %rdx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
shrq $0x21, %rdi
movq (%rbx,%rdi,8), %rdi
movq %rdi, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0xc6ded
movq 0x10(%rbp), %r13
movq 0x28(%rbp), %rax
movq (%rax,%r15,8), %r9
movq %r9, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
leaq (%rdi,%r13), %rbp
testl %r9d, %r9d
je 0xc6eb1
movl %r9d, %eax
xorl %ecx, %ecx
movq %rbp, %rdx
xorl %r10d, %r10d
testb $0x3e, 0x28(%rdx)
jne 0xc6ea3
movl %r10d, %esi
cmpq %rsi, %rcx
je 0xc6ea0
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movups (%rbp,%rsi), %xmm0
movups 0x10(%rbp,%rsi), %xmm1
movups 0x20(%rbp,%rsi), %xmm2
movups %xmm2, 0x20(%rdx)
movups %xmm1, 0x10(%rdx)
movups %xmm0, (%rdx)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rbp,%rsi)
movups %xmm1, 0x10(%rbp,%rsi)
movups %xmm0, (%rbp,%rsi)
incl %r10d
incq %rcx
addq $0x30, %rdx
cmpq %rcx, %rax
jne 0xc6e38
jmp 0xc6eb4
xorl %r10d, %r10d
movl %r9d, %eax
subl %r10d, %eax
jbe 0xc6fee
movq %r9, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movq %rbx, %r15
movq %r14, %rbx
movl %r10d, %ecx
movq %rcx, 0x10(%rsp)
cmpl $0x2, %eax
jb 0xc6f0b
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x4, %rdi
addq %rbp, %rdi
movl %eax, %esi
leaq -0x3fd9(%rip), %rcx     # 0xc2f1d
movl $0x30, %edx
movl %r10d, %r14d
callq 0x23f0
movl %r14d, %r10d
movq 0x8(%rsp), %r8
movl %r10d, 0x1c(%rsp)
testl %r10d, %r10d
movq %r12, %r14
je 0xc6f52
movq 0x10(%rsp), %r12
movq 0x10(%rbx), %rsi
movq $-0x1, (%rsp)
movq %r15, %rdx
movq %rbp, %rcx
movq 0x8(%rsp), %r8
movq %r14, %r9
movsd 0x15e5f9(%rip), %xmm0   # 0x225538
callq 0xc6a47
movq 0x8(%rsp), %r8
addq $0x30, %rbp
decq %r12
jne 0xc6f1d
movq 0x20(%rsp), %rax
cmpl 0x1c(%rsp), %eax
movq 0x28(%rsp), %rcx
jbe 0xc6fee
movq %r14, %r12
movq %rbx, %r14
movq %r15, %rbx
movl %eax, %ebp
movq 0x10(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
shlq $0x4, %rax
addq %rax, %rcx
addq %rcx, %r13
subq %rdx, %rbp
movq 0x10(%r14), %rsi
movq 0xa0(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdx
movq %r13, %rcx
movq %r8, %r15
movq %r12, %r9
movsd 0x15e59d(%rip), %xmm0   # 0x225548
callq 0xc6a47
testl %eax, %eax
je 0xc6fdb
movq 0x10(%r14), %rsi
movq $-0x1, (%rsp)
movq %rbx, %rdx
movq %r13, %rcx
movq %r15, %r8
movq %r12, %r9
movsd 0x15e564(%rip), %xmm0   # 0x225538
callq 0xc6a47
jmp 0xc6fe0
orb $-0x80, 0x28(%r13)
addq $0x30, %r13
decq %rbp
movq 0x8(%rsp), %r8
jne 0xc6f87
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq