// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: print_het_ovlp(p_g_t*, ma_ug_t*, hap_overlaps_list*, double)
void print_het_ovlp(p_g_t *pg, ma_ug_t *ug, hap_overlaps_list* ha, double filter_rate)
{
    uint32_t v, i, k, n_vtx = pg->pg_h_lev->n_seq * 2, nv, qn, qs, qe, tn, ts, te, as, ae, occ, ovlp, hetLen, homLen;
    asg_arc_t *av = NULL;
    hap_overlaps *x = NULL;
    p_node_t *a = NULL;
    int index;
    for (v = 0; v < n_vtx; v++)
    {
        av = asg_arc_a(pg->pg_h_lev, v);
        nv = asg_arc_n(pg->pg_h_lev, v);
        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            index = get_specific_hap_overlap(&(ha->x[av[i].ul>>33]), av[i].ul>>33, av[i].v>>1);
            if(index == -1) fprintf(stderr, "ERROR\n");
            x = &(ha->x[av[i].ul>>33].a.a[index]);

            qn = x->xUid;
            qs = x->x_beg_pos;
            qe = x->x_end_pos - 1;
            get_p_nodes(pg, &a, &occ, qn);
            for (k = 0, hetLen = 0, homLen = 0; k < occ; k++)
            {
                as = a[k].baseBeg;
                ae = a[k].baseEnd;
                ovlp = ((MIN(qe, ae) >= MAX(qs, as))? MIN(qe, ae) - MAX(qs, as) + 1 : 0);
                if(homLen + hetLen > 0 && ovlp == 0) break;
                if(ovlp == 0) continue;
                if(a[k].h_status == N_HET)
                {
                    homLen += ovlp;
                } 
                else if(asm_opt.polyploidy <= 2 && (a[k].h_status&P_HET))
                {
                    homLen += ovlp;
                }
                else
                {
                    hetLen += ovlp;
                }  
            }

            if(hetLen <= ((hetLen + homLen) * filter_rate))
            {
                ///all_ovlp->x[uId].a.a[i].status = DELETE;
                fprintf(stderr, "********XY********\n");
                print_hap_paf(ug, x);
            }


            tn = x->yUid;
            ts = x->y_beg_pos;
            te = x->y_end_pos - 1;
            get_p_nodes(pg, &a, &occ, tn);
            for (k = 0, hetLen = 0, homLen = 0; k < occ; k++)
            {
                as = a[k].baseBeg;
                ae = a[k].baseEnd;
                ovlp = ((MIN(te, ae) >= MAX(ts, as))? MIN(te, ae) - MAX(ts, as) + 1 : 0);
                if(homLen + hetLen > 0 && ovlp == 0) break;
                if(ovlp == 0) continue;
                if(a[k].h_status == N_HET)
                {
                    homLen += ovlp;
                } 
                else if(asm_opt.polyploidy <= 2 && (a[k].h_status&P_HET))
                {
                    homLen += ovlp;
                }
                else
                {
                    hetLen += ovlp;
                }                 
            }

            if(hetLen <= ((hetLen + homLen) * filter_rate))
            {
                ///all_ovlp->x[uId].a.a[i].status = DELETE;
                fprintf(stderr, "********YX********\n");
                print_hap_paf(ug, x);
            }
        }
    }

    for (v = 0; v < ha->num; v++)
    {
        for (i = 0; i < ha->x[v].a.n; i++)
        {
            if(ha->x[v].a.a[i].status == DELETE)
            {
                x = &(ha->x[v].a.a[i]);

                qn = x->xUid;
                qs = x->x_beg_pos;
                qe = x->x_end_pos - 1;
                get_p_nodes(pg, &a, &occ, qn);
                for (k = 0, hetLen = 0, homLen = 0; k < occ; k++)
                {
                    as = a[k].baseBeg;
                    ae = a[k].baseEnd;
                    ovlp = ((MIN(qe, ae) >= MAX(qs, as))? MIN(qe, ae) - MAX(qs, as) + 1 : 0);
                    if(homLen + hetLen > 0 && ovlp == 0) break;
                    if(ovlp == 0) continue;
                    if(a[k].h_status == N_HET)
                    {
                        homLen += ovlp;
                    } 
                    else if(asm_opt.polyploidy <= 2 && (a[k].h_status&P_HET))
                    {
                        homLen += ovlp;
                    }
                    else
                    {
                        hetLen += ovlp;
                    }  
                }

                if(hetLen <= ((hetLen + homLen) * filter_rate))
                {
                    fprintf(stderr, "********C(X)********hetLen-%u, homLen-%u\n", hetLen, homLen);
                    print_hap_paf(ug, x);
                }


                tn = x->yUid;
                ts = x->y_beg_pos;
                te = x->y_end_pos - 1;
                get_p_nodes(pg, &a, &occ, tn);
                for (k = 0, hetLen = 0, homLen = 0; k < occ; k++)
                {
                    as = a[k].baseBeg;
                    ae = a[k].baseEnd;
                    ovlp = ((MIN(te, ae) >= MAX(ts, as))? MIN(te, ae) - MAX(ts, as) + 1 : 0);
                    if(homLen + hetLen > 0 && ovlp == 0) break;
                    if(ovlp == 0) continue;
                    if(a[k].h_status == N_HET)
                    {
                        homLen += ovlp;
                    } 
                    else if(asm_opt.polyploidy <= 2 && (a[k].h_status&P_HET))
                    {
                        homLen += ovlp;
                    }
                    else
                    {
                        hetLen += ovlp;
                    }                 
                }

                if(hetLen <= ((hetLen + homLen) * filter_rate))
                {
                    fprintf(stderr, "********C(Y)********hetLen-%u, homLen-%u\n", hetLen, homLen);
                    print_hap_paf(ug, x);
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r9
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
movq 0x28(%rdi), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movsd %xmm0, (%rsp)
movq %rdx, 0x8(%rsp)
je 0x10fc86
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
xorl %edx, %edx
movq 0x28(%r15), %rcx
movq 0x28(%rcx), %rax
movq %rdx, 0x30(%rsp)
movq (%rax,%rdx,8), %rax
testl %eax, %eax
je 0x10fc73
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rcx), %rdx
movl %eax, %eax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movq %rdx, 0x20(%rsp)
leaq (%r14,%r14,2), %rax
cmpl $0x0, 0xc(%rdx,%rax,8)
js 0x10fc1a
leaq (%rdx,%rax,8), %r12
movq (%r9), %rdx
movq (%r12), %rax
shrq $0x21, %rax
leaq (%rax,%rax,2), %rsi
movq (%rdx,%rsi,8), %rcx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rcx, %rcx
je 0x10fa54
leaq (%rdx,%rsi,8), %rsi
movl 0x8(%r12), %edx
shrl %edx
movq 0x10(%rsi), %rsi
xorl %r8d, %r8d
xorl %edi, %edi
shlq $0x6, %r8
cmpl %eax, 0x24(%rsi,%r8)
jne 0x10fa46
addq %rsi, %r8
cmpl %edx, 0x28(%r8)
je 0x10fa52
incl %edi
movq %rdi, %r8
cmpq %rdi, %rcx
ja 0x10fa32
jmp 0x10fa54
movl %edi, %ebx
cmpl $-0x1, %ebx
je 0x10fc2a
movq (%r9), %rax
movq (%r12), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %r12
movslq %ebx, %rax
shlq $0x6, %rax
movl 0x24(%r12,%rax), %edx
movq 0x40(%r15), %r8
movl 0x4(%r8,%rdx,8), %ecx
testl %ecx, %ecx
je 0x10fb1c
movl 0x4(%r12,%rax), %esi
movl 0x8(%r12,%rax), %edi
movl (%r8,%rdx,8), %edx
leaq (%rdx,%rdx,8), %r8
leaq (%r8,%r8,2), %r9
addq %rdx, %r9
addq 0x18(%r15), %r9
decl %edi
leaq 0x17aca4(%rip), %rdx    # 0x28a758
movl 0x1bc(%rdx), %r10d
xorl %edx, %edx
xorl %r8d, %r8d
movl (%r9), %r11d
movl 0x4(%r9), %ebx
cmpl %ebx, %edi
cmovbl %edi, %ebx
cmpl %r11d, %esi
cmoval %esi, %r11d
subl %r11d, %ebx
leal 0x1(%rbx), %r11d
cmovbl %ebp, %r11d
movl %edx, %ebx
addl %r8d, %ebx
setne %bl
testl %r11d, %r11d
sete %r13b
testb %r13b, %bl
jne 0x10fb21
testl %r11d, %r11d
je 0x10fb12
movl 0x14(%r9), %ebx
testl %ebx, %ebx
je 0x10fb0a
testb $0x2, %bl
je 0x10fb0f
cmpl $0x2, %r10d
jg 0x10fb0f
addl %r11d, %edx
jmp 0x10fb12
addl %r11d, %r8d
addq $0x1c, %r9
decl %ecx
jne 0x10fac0
jmp 0x10fb21
xorl %r8d, %r8d
xorl %edx, %edx
movl %r8d, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
addl %r8d, %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
addq %rax, %r12
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
jae 0x10fc3e
movl 0x28(%r12), %ecx
movq 0x40(%r15), %rdi
movl 0x4(%rdi,%rcx,8), %eax
testl %eax, %eax
je 0x10fbee
movl 0xc(%r12), %edx
movl 0x10(%r12), %esi
movl (%rdi,%rcx,8), %ecx
leaq (%rcx,%rcx,8), %rdi
leaq (%rdi,%rdi,2), %r8
addq %rcx, %r8
addq 0x18(%r15), %r8
decl %esi
leaq 0x17abd6(%rip), %rcx    # 0x28a758
movl 0x1bc(%rcx), %r9d
xorl %ecx, %ecx
xorl %edi, %edi
movl (%r8), %r10d
movl 0x4(%r8), %r11d
cmpl %r11d, %esi
cmovbl %esi, %r11d
cmpl %r10d, %edx
cmoval %edx, %r10d
subl %r10d, %r11d
leal 0x1(%r11), %r10d
cmovbl %ebp, %r10d
movl %ecx, %r11d
addl %edi, %r11d
setne %r11b
testl %r10d, %r10d
sete %bl
testb %bl, %r11b
jne 0x10fbf2
testl %r10d, %r10d
je 0x10fbe4
movl 0x14(%r8), %r11d
testl %r11d, %r11d
je 0x10fbdc
testb $0x2, %r11b
je 0x10fbe1
cmpl $0x2, %r9d
jg 0x10fbe1
addl %r10d, %ecx
jmp 0x10fbe4
addl %r10d, %edi
addq $0x1c, %r8
decl %eax
jne 0x10fb8d
jmp 0x10fbf2
xorl %edi, %edi
xorl %ecx, %ecx
movl %edi, %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
addl %edi, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %rdx
jae 0x10fc55
incq %r14
cmpq 0x18(%rsp), %r14
jne 0x10f9ee
jmp 0x10fc73
callq 0x13cfa
movq 0x8(%rsp), %r9
movsd (%rsp), %xmm0
jmp 0x10fa5d
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x13d16
movsd (%rsp), %xmm0
jmp 0x10fb48
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x13d4e
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %r9
movsd (%rsp), %xmm0
jmp 0x10fc1a
movq 0x30(%rsp), %rdx
incq %rdx
cmpq 0x28(%rsp), %rdx
jne 0x10f9b3
cmpl $0x0, 0x8(%r9)
je 0x10fee2
xorl %ecx, %ecx
movq (%r9), %rax
movq %rcx, 0x18(%rsp)
leaq (%rcx,%rcx,2), %r12
cmpq $0x0, (%rax,%r12,8)
je 0x10fecd
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %r14d, %r14d
movq 0x10(%rax,%r12,8), %rbp
shlq $0x6, %rcx
cmpb $0x2, 0x2(%rbp,%rcx)
jne 0x10fe58
addq %rcx, %rbp
movl 0x24(%rbp), %ecx
movq 0x40(%r15), %rdx
movl 0x4(%rdx,%rcx,8), %eax
testl %eax, %eax
je 0x10fd69
movl 0x4(%rbp), %esi
movl 0x8(%rbp), %edi
movl (%rdx,%rcx,8), %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %r8
addq %rcx, %r8
addq 0x18(%r15), %r8
decl %edi
leaq 0x17aa5b(%rip), %rcx    # 0x28a758
movl 0x1bc(%rcx), %r9d
xorl %ecx, %ecx
xorl %edx, %edx
movl (%r8), %r10d
movl 0x4(%r8), %r11d
cmpl %r11d, %edi
cmovbl %edi, %r11d
cmpl %r10d, %esi
cmoval %esi, %r10d
subl %r10d, %r11d
leal 0x1(%r11), %r10d
cmovbl %r13d, %r10d
movl %ecx, %r11d
addl %edx, %r11d
setne %r11b
testl %r10d, %r10d
sete %bl
testb %bl, %r11b
jne 0x10fd6d
testl %r10d, %r10d
je 0x10fd5f
movl 0x14(%r8), %r11d
testl %r11d, %r11d
je 0x10fd57
testb $0x2, %r11b
je 0x10fd5c
cmpl $0x2, %r9d
jg 0x10fd5c
addl %r10d, %ecx
jmp 0x10fd5f
addl %r10d, %edx
addq $0x1c, %r8
decl %eax
jne 0x10fd08
jmp 0x10fd6d
xorl %edx, %edx
xorl %ecx, %ecx
movl %edx, %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
leal (%rcx,%rdx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
jae 0x10fe6d
movl 0x28(%rbp), %ecx
movq 0x40(%r15), %rdx
movl 0x4(%rdx,%rcx,8), %eax
testl %eax, %eax
je 0x10fe30
movl 0xc(%rbp), %esi
movl 0x10(%rbp), %edi
movl (%rdx,%rcx,8), %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %r8
addq %rcx, %r8
addq 0x18(%r15), %r8
decl %edi
leaq 0x17a994(%rip), %rcx    # 0x28a758
movl 0x1bc(%rcx), %r9d
xorl %ecx, %ecx
xorl %edx, %edx
movl (%r8), %r10d
movl 0x4(%r8), %r11d
cmpl %r11d, %edi
cmovbl %edi, %r11d
cmpl %r10d, %esi
cmoval %esi, %r10d
subl %r10d, %r11d
leal 0x1(%r11), %r10d
cmovbl %r13d, %r10d
movl %ecx, %r11d
addl %edx, %r11d
setne %r11b
testl %r10d, %r10d
sete %bl
testb %bl, %r11b
jne 0x10fe34
testl %r10d, %r10d
je 0x10fe26
movl 0x14(%r8), %r11d
testl %r11d, %r11d
je 0x10fe1e
testb $0x2, %r11b
je 0x10fe23
cmpl $0x2, %r9d
jg 0x10fe23
addl %r10d, %ecx
jmp 0x10fe26
addl %r10d, %edx
addq $0x1c, %r8
decl %eax
jne 0x10fdcf
jmp 0x10fe34
xorl %edx, %edx
xorl %ecx, %ecx
movl %edx, %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
leal (%rcx,%rdx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
movq 0x8(%rsp), %r9
jae 0x10fe9c
incl %r14d
movq (%r9), %rax
movq %r14, %rcx
cmpq %r14, (%rax,%r12,8)
ja 0x10fcb2
jmp 0x10fecd
movq 0x17a16c(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x11d9c8(%rip), %rsi    # 0x22d846
xorl %eax, %eax
callq 0x22b0
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x1298d
movsd (%rsp), %xmm0
jmp 0x10fd90
movq 0x17a13d(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x11d9c3(%rip), %rsi    # 0x22d870
xorl %eax, %eax
callq 0x22b0
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x1298d
movq 0x8(%rsp), %r9
movsd (%rsp), %xmm0
jmp 0x10fe58
movq 0x18(%rsp), %rcx
incq %rcx
movl 0x8(%r9), %eax
cmpq %rax, %rcx
jb 0x10fc93
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq