// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %r9, %rbx
movq %rcx, 0x30(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq 0x10(%rdx), %rax
movl %edi, %r15d
leaq (%r15,%r15,4), %rcx
leaq (%rax,%rcx,8), %r12
movl 0x10(%r12), %edx
movq %r8, 0x10(%rsp)
cmpq %rdx, 0x8(%r8)
jae 0xc7b9a
leaq -0x1(%rdx), %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 0x10(%rsp), %r14
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movl 0x10(%r12), %edx
movq %r13, 0x28(%rsp)
testl %edx, %edx
je 0xc7bcd
movq 0x18(%r12), %rax
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl %edx, %edx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
shrq $0x21, %rdi
movq (%rbx,%rdi,8), %rdi
movq %rdi, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0xc7bb5
movq 0x10(%rbp), %r8
movq 0x28(%rbp), %rax
movq (%rax,%r15,8), %r14
movq %r14, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
leaq (%r8,%rdi), %rbp
testl %r14d, %r14d
je 0xc7c79
movl %r14d, %eax
xorl %ecx, %ecx
movq %rbp, %rdx
xorl %r12d, %r12d
testb $0x3e, 0x28(%rdx)
jne 0xc7c6b
movl %r12d, %esi
cmpq %rsi, %rcx
je 0xc7c68
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movaps %xmm2, 0x70(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%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 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movaps 0x70(%rsp), %xmm2
movups %xmm2, 0x20(%rbp,%rsi)
movups %xmm1, 0x10(%rbp,%rsi)
movups %xmm0, (%rbp,%rsi)
incl %r12d
incq %rcx
addq $0x30, %rdx
cmpq %rcx, %rax
jne 0xc7c00
jmp 0xc7c7c
xorl %r12d, %r12d
subl %r12d, %r14d
jbe 0xc7db2
movq %r8, 0x38(%rsp)
movq %rdi, 0x48(%rsp)
movq %rbx, 0x20(%rsp)
movl %r12d, %eax
movq %rax, 0x18(%rsp)
cmpl $0x2, %r14d
jb 0xc7cc6
movq 0x18(%rsp), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq %rbp, %rdi
movl %r14d, %esi
leaq -0x3e9a(%rip), %rcx     # 0xc3e22
movl $0x30, %edx
callq 0x23f0
movq %r14, 0x40(%rsp)
testl %r12d, %r12d
movq 0x30(%rsp), %rbx
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %r14
je 0xc7d17
movq 0x18(%rsp), %r12
movq 0x10(%r15), %rsi
movq $-0x1, (%rsp)
movq %r14, %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %rbx, %r9
movsd 0x16992f(%rip), %xmm0   # 0x231638
callq 0xc7818
addq $0x30, %rbp
decq %r12
jne 0xc7ce9
movq 0x18(%rsp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq 0x48(%rsp), %rcx
addq %rax, %rcx
movq 0x38(%rsp), %r13
addq %rcx, %r13
movq %r14, %r12
movq 0x40(%rsp), %r15
movq 0x10(%rsp), %rbp
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r14
movq 0x10(%rbp), %rsi
movq 0xc0(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdx
movq %r13, %rcx
movq %rbx, %r8
movq %r14, %r9
movsd 0x1698d9(%rip), %xmm0   # 0x231648
callq 0xc7818
testl %eax, %eax
je 0xc7d9f
movq 0x10(%rbp), %rsi
movq $-0x1, (%rsp)
movq %r12, %rdx
movq %r13, %rcx
movq %rbx, %r8
movq %r14, %r9
movsd 0x1698a0(%rip), %xmm0   # 0x231638
callq 0xc7818
jmp 0xc7da4
orb $-0x80, 0x28(%r13)
addq $0x30, %r13
decl %r15d
movq 0x20(%rsp), %r12
jne 0xc7d4b
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq