// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movl 0x8(%rdi), %edx
testl %edx, %edx
je 0x117a82
movq %rdi, %r13
movq (%rdi), %rax
xorl %ebp, %ebp
movb $0x1, %bl
leaq (,%rbp,2), %r14
addq %rbp, %r14
movq (%rax,%r14,8), %rcx
testq %rcx, %rcx
je 0x117a74
leaq (%rax,%r14,8), %rdx
movl $0x1, %esi
xorl %edi, %edi
xorl %r15d, %r15d
testq %r15, %r15
je 0x1179a9
movq 0x30(%r15), %r9
movq 0x10(%rdx), %r8
cmpq 0x30(%r8,%rdi), %r9
jl 0x1179ad
jmp 0x1179b3
movq 0x10(%rdx), %r8
addq %rdi, %r8
movq %r8, %r15
movl %esi, %r8d
addq $0x40, %rdi
incl %esi
cmpq %r8, %rcx
ja 0x117993
movl $0x1, %r12d
xorl %ecx, %ecx
movq 0x10(%rax,%r14,8), %rdx
shlq $0x6, %rcx
cmpb $0x3, 0x1(%rdx,%rcx)
jne 0x117a60
leaq (%rdx,%rcx), %r8
movq 0x30(%r15), %rsi
movq %rsi, %rdi
subq 0x30(%r8), %rdi
jle 0x117a16
movq %rsi, %r8
negq %r8
cmovsq %rsi, %r8
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r8, %xmm1
mulsd 0x121cc8(%rip), %xmm1   # 0x2396d8
ucomisd %xmm1, %xmm0
jae 0x117a60
movl 0x24(%rdx,%rcx), %eax
movq 0x10(%rsp), %rdx
movq 0x20(%rdx), %rdx
movb %bl, 0x4(%rdx,%rax,8)
movq 0x18(%rsp), %rdx
movq 0x20(%rdx), %rdx
movb %bl, 0x4(%rdx,%rax,8)
orb $-0x80, 0x3(%rdx,%rax,8)
movq (%r13), %rax
movq 0x10(%rax,%r14,8), %rax
leaq (%rax,%rcx), %rdx
movb $0x2, 0x2(%rax,%rcx)
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
xorl %ecx, %ecx
callq 0x1142b4
movq (%r13), %rax
movl %r12d, %ecx
incl %r12d
cmpq %rcx, (%rax,%r14,8)
ja 0x1179c9
movl 0x8(%r13), %edx
incq %rbp
movl %edx, %ecx
cmpq %rcx, %rbp
jb 0x11796d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq