// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: remove_contained_haplotig(hap_overlaps_list*, ma_ug_t*, asg_t*, asg_t*, hap_cov_t*)
void remove_contained_haplotig(hap_overlaps_list* all_ovlp, ma_ug_t *ug, asg_t* nsg, asg_t *purge_g, hap_cov_t *cov)
{
    uint32_t v, i, uId, xUid;
    hap_overlaps *p = NULL;
    for (v = 0; v < all_ovlp->num; v++)
    {
        uId = v; p = NULL;
        for (i = 0; i < all_ovlp->x[uId].a.n; i++)
        {
            if(p == NULL || p->score < all_ovlp->x[uId].a.a[i].score)
            {
                p = &(all_ovlp->x[uId].a.a[i]);
            }
        }

        for (i = 0; i < all_ovlp->x[uId].a.n; i++)
        {
            if(all_ovlp->x[uId].a.a[i].type == YCX)
            {
                if(!filter_secondary_chain(p->score, all_ovlp->x[uId].a.a[i].score, 0.95))
                {
                    continue;
                } 
                
                xUid = all_ovlp->x[uId].a.a[i].xUid;

                nsg->seq[xUid].c = ALTER_LABLE;
                purge_g->seq[xUid].c = ALTER_LABLE;
                purge_g->seq[xUid].del = 1;

                all_ovlp->x[uId].a.a[i].status = DELETE;
                ///if(cov->link) collect_reverse_unitig_pair(cov->link, ug, &(all_ovlp->x[uId].a.a[i]));
                collect_trans_purge_cov(cov, ug, &(all_ovlp->x[uId].a.a[i]), 0);
            }

            ///print_hap_paf(ug, &(all_ovlp.x[uId].a.a[i]));
        }
    }

    // for (v = 0; v < all_ovlp.num; v++)
    // {
    //     uId = v;
    //     for (i = 0; i < all_ovlp.x[uId].a.n; i++)
    //     {
    //         if(all_ovlp.x[uId].a.a[i].type == YCX)
    //         {
    //             nsg->seq[all_ovlp.x[uId].a.a[i].xUid].c = ALTER_LABLE;
    //             purge_g->seq[all_ovlp.x[uId].a.a[i].xUid].c = ALTER_LABLE;
    //             purge_g->seq[all_ovlp.x[uId].a.a[i].xUid].del = 1;
    //             all_ovlp.x[uId].a.a[i].status = DELETE;
    //             if(link) collect_reverse_unitig_pair(link, ug, &(all_ovlp.x[uId].a.a[i]));
    //             collect_trans_purge_cov(cov, ug, &(all_ovlp.x[uId].a.a[i]), 0);
    //         }

    //         if(all_ovlp.x[uId].a.a[i].type == XCY)
    //         {
    //             nsg->seq[all_ovlp.x[uId].a.a[i].yUid].c = ALTER_LABLE;
    //             purge_g->seq[all_ovlp.x[uId].a.a[i].yUid].c = ALTER_LABLE;
    //             purge_g->seq[all_ovlp.x[uId].a.a[i].yUid].del = 1;
    //             all_ovlp.x[uId].a.a[i].status = DELETE;
    //             if(link) collect_reverse_unitig_pair(link, ug, &(all_ovlp.x[uId].a.a[i]));
    //             collect_trans_purge_cov(cov, ug, &(all_ovlp.x[uId].a.a[i]), 1);
    //         }
    //         ///print_hap_paf(ug, &(all_ovlp.x[uId].a.a[i]));
    //     }
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %r12
movq %rdi, %r13
xorl %ecx, %ecx
movb $0x1, %bpl
movl 0x8(%r13), %eax
cmpq %rax, %rcx
jae 0xd245f
movq (%r13), %rax
movq %rcx, 0x8(%rsp)
imulq $0x18, %rcx, %rbx
leaq (%rax,%rbx), %rdx
leaq (%rax,%rbx), %rsi
addq $0x10, %rsi
movq -0x10(%rsi), %rcx
xorl %edi, %edi
xorl %r14d, %r14d
movl %edi, %edi
cmpq %rdi, %rcx
jbe 0xd23a3
testq %r14, %r14
je 0xd2392
movq 0x30(%r14), %r9
movq 0x10(%rdx), %r8
movq %rdi, %r10
shlq $0x6, %r10
cmpq 0x30(%r8,%r10), %r9
jl 0xd2395
jmp 0xd239f
movq (%rsi), %r8
movq %rdi, %r14
shlq $0x6, %r14
addq %r8, %r14
incl %edi
jmp 0xd236e
xorl %r15d, %r15d
movl %r15d, %r15d
cmpq %r15, %rcx
jbe 0xd2452
movq 0x10(%rax,%rbx), %rdx
movq %r15, %rsi
shlq $0x6, %rsi
cmpb $0x3, 0x1(%rdx,%rsi)
jne 0xd244a
leaq (%rdx,%rsi), %r9
movq 0x30(%r14), %rdi
movq %rdi, %r8
subq 0x30(%r9), %r8
jle 0xd23fc
movq %rdi, %r9
negq %r9
cmovsq %rdi, %r9
cvtsi2sd %r8, %xmm0
cvtsi2sd %r9, %xmm1
mulsd 0x1191c2(%rip), %xmm1   # 0x1eb5b8
ucomisd %xmm1, %xmm0
jae 0xd244a
movl 0x24(%rdx,%rsi), %eax
movq 0x10(%rsp), %rcx
movq 0x20(%rcx), %rcx
movb %bpl, 0x4(%rcx,%rax,8)
movq 0x18(%rsp), %rcx
movq 0x20(%rcx), %rcx
movb %bpl, 0x4(%rcx,%rax,8)
orb $-0x80, 0x3(%rcx,%rax,8)
movq (%r13), %rax
movq 0x10(%rax,%rbx), %rax
leaq (%rax,%rsi), %rdx
movb $0x2, 0x2(%rax,%rsi)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0xcfd0e
movq (%r13), %rax
movq (%rax,%rbx), %rcx
incl %r15d
jmp 0xd23a6
movq 0x8(%rsp), %rcx
incq %rcx
jmp 0xd233f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq