// File: /workspace/github_cpp_makefile_star2_O1/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)
cmpl $0x0, 0x8(%rdi)
je 0x111f77
movq %rdi, %r13
xorl %ebp, %ebp
movq (%r13), %rcx
leaq (,%rbp,2), %r14
addq %rbp, %r14
movq (%rcx,%r14,8), %rax
testq %rax, %rax
je 0x111e91
leaq (%rcx,%r14,8), %rcx
movl $0x1, %edx
xorl %esi, %esi
xorl %r15d, %r15d
testq %r15, %r15
je 0x111e7b
movq 0x30(%r15), %rdi
movq 0x10(%rcx), %r8
cmpq 0x30(%r8,%rsi), %rdi
jge 0x111e82
movq 0x10(%rcx), %r15
addq %rsi, %r15
movl %edx, %edi
addq $0x40, %rsi
incl %edx
cmpq %rdi, %rax
ja 0x111e67
jmp 0x111e94
xorl %r15d, %r15d
movq (%r13), %rcx
cmpq $0x0, (%rcx,%r14,8)
je 0x111f67
movl $0x1, %r12d
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %rbx
xorl %eax, %eax
movq 0x10(%rcx,%r14,8), %rdx
shlq $0x6, %rax
cmpb $0x3, 0x1(%rdx,%rax)
jne 0x111f53
addq %rax, %rdx
movq 0x30(%r15), %rsi
movq %rsi, %rdi
subq 0x30(%rdx), %rdi
jle 0x111f03
movq %rsi, %rdx
negq %rdx
cmovsq %rsi, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
mulsd 0x11b5cb(%rip), %xmm1   # 0x22d4c8
ucomisd %xmm1, %xmm0
jae 0x111f53
movq 0x10(%rcx,%rbx), %rcx
movl 0x24(%rcx,%rax), %ecx
movq 0x10(%rsp), %rdx
movq 0x20(%rdx), %rdx
movb $0x1, %sil
movb %sil, 0x4(%rdx,%rcx,8)
movq 0x18(%rsp), %rdx
movq 0x20(%rdx), %rdx
movb %sil, 0x4(%rdx,%rcx,8)
orb $-0x80, 0x3(%rdx,%rcx,8)
movq (%r13), %rcx
movq 0x10(%rcx,%rbx), %rcx
leaq (%rcx,%rax), %rdx
movb $0x2, 0x2(%rcx,%rax)
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
xorl %ecx, %ecx
callq 0x10ecd0
movl %r12d, %eax
movq (%r13), %rcx
incl %r12d
cmpq %rax, (%rcx,%r14,8)
ja 0x111eb7
incq %rbp
movl 0x8(%r13), %eax
cmpq %rax, %rbp
jb 0x111e41
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq