// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rdx, (%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x28(%rdi), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movsd %xmm0, 0x8(%rsp)
je 0x11534c
movl %eax, %eax
movq %rax, 0x38(%rsp)
xorl %edx, %edx
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rcx
movq 0x28(%rcx), %rax
movq %rdx, 0x40(%rsp)
movq (%rax,%rdx,8), %rax
testl %eax, %eax
je 0x115339
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r15
shlq $0x3, %r15
addq 0x8(%rcx), %r15
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %ebx, %ebx
movq %r15, 0x20(%rsp)
leaq (%rbx,%rbx,2), %rax
cmpl $0x0, 0xc(%r15,%rax,8)
js 0x1152cf
leaq (%r15,%rax,8), %r15
movq (%rsp), %rax
movq (%rax), %rax
movq (%r15), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,2), %rdx
movq (%rax,%rdx,8), %rsi
testq %rsi, %rsi
je 0x1150a3
leaq (%rax,%rdx,8), %rdx
movl 0x8(%r15), %edi
shrl %edi
movq 0x10(%rdx), %r8
movl $0x1, %edx
xorl %r9d, %r9d
shlq $0x6, %r9
cmpl %ecx, 0x24(%r8,%r9)
jne 0x115092
addq %r8, %r9
cmpl %edi, 0x28(%r9)
je 0x11509e
movl %edx, %r9d
incl %edx
cmpq %r9, %rsi
ja 0x11507e
jmp 0x1150a3
subl $0x1, %edx
jae 0x1150dc
movq 0x17ff36(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0x6, %esi
movl $0x1, %edx
leaq 0x123dc6(%rip), %rdi    # 0x238e84
callq 0x2410
movsd 0x8(%rsp), %xmm0
movq (%rsp), %rax
movq (%rax), %rax
movq (%r15), %rcx
shrq $0x21, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdi
movslq %edx, %rdx
shlq $0x6, %rdx
movl 0x24(%rdi,%rdx), %r9d
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x40(%rcx), %rcx
movl 0x4(%rcx,%r9,8), %r8d
testq %r8, %r8
movq %rdi, 0x30(%rsp)
je 0x1151bb
movl 0x4(%rdi,%rdx), %esi
movl 0x8(%rdi,%rdx), %edi
decl %edi
movl (%rcx,%r9,8), %r9d
leaq (%r9,%r9,8), %r10
leaq (%r10,%r10,2), %r10
addq %rax, %r9
addq %r10, %r9
leaq 0x180624(%rip), %r10    # 0x295758
movl 0x1bc(%r10), %r11d
leaq (%r8,%r8,8), %r10
leaq (%r10,%r10,2), %r12
addq %r8, %r12
xorl %r15d, %r15d
xorl %r8d, %r8d
xorl %r10d, %r10d
movl (%r9,%r15), %r14d
movl 0x4(%r9,%r15), %r13d
cmpl %r13d, %edi
cmovbl %edi, %r13d
cmpl %r14d, %esi
cmoval %esi, %r14d
subl %r14d, %r13d
leal 0x1(%r13), %r14d
movl $0x0, %r13d
cmovbl %r13d, %r14d
movl %r8d, %r13d
addl %r10d, %r13d
setne %r13b
testl %r14d, %r14d
sete %bpl
testb %bpl, %r13b
jne 0x1151c1
testl %r14d, %r14d
je 0x1151b0
movl 0x14(%r9,%r15), %r13d
testl %r13d, %r13d
je 0x1151a8
testb $0x2, %r13b
je 0x1151ad
cmpl $0x2, %r11d
jg 0x1151ad
addl %r14d, %r8d
jmp 0x1151b0
addl %r14d, %r10d
addq $0x1c, %r15
cmpq %r15, %r12
jne 0x11514f
jmp 0x1151c1
xorl %r10d, %r10d
xorl %r8d, %r8d
movl %r10d, %esi
xorps %xmm2, %xmm2
cvtsi2sd %rsi, %xmm2
addl %r10d, %r8d
xorps %xmm1, %xmm1
cvtsi2sd %r8, %xmm1
movq 0x30(%rsp), %r12
addq %rdx, %r12
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
jae 0x1152df
movl 0x28(%r12), %r8d
movl 0x4(%rcx,%r8,8), %edi
testq %rdi, %rdi
movq 0x20(%rsp), %r15
je 0x1152ad
movl 0xc(%r12), %edx
movl 0x10(%r12), %esi
decl %esi
movl (%rcx,%r8,8), %ecx
leaq (%rcx,%rcx,8), %r8
leaq (%r8,%r8,2), %r8
addq %rcx, %rax
addq %r8, %rax
leaq 0x18052e(%rip), %rcx    # 0x295758
movl 0x1bc(%rcx), %r8d
leaq (%rdi,%rdi,8), %rcx
leaq (%rcx,%rcx,2), %r9
addq %rdi, %r9
xorl %r10d, %r10d
xorl %ecx, %ecx
xorl %edi, %edi
movl (%rax,%r10), %r11d
movl 0x4(%rax,%r10), %r14d
cmpl %r14d, %esi
cmovbl %esi, %r14d
cmpl %r11d, %edx
cmoval %edx, %r11d
subl %r11d, %r14d
leal 0x1(%r14), %r11d
movl $0x0, %r14d
cmovbl %r14d, %r11d
movl %ecx, %ebp
addl %edi, %ebp
setne %bpl
testl %r11d, %r11d
sete %r14b
testb %r14b, %bpl
jne 0x1152b1
testl %r11d, %r11d
je 0x1152a2
movl 0x14(%rax,%r10), %r14d
testl %r14d, %r14d
je 0x11529a
testb $0x2, %r14b
je 0x11529f
cmpl $0x2, %r8d
jg 0x11529f
addl %r11d, %ecx
jmp 0x1152a2
addl %r11d, %edi
addq $0x1c, %r10
cmpq %r10, %r9
jne 0x115243
jmp 0x1152b1
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
jae 0x115324
incq %rbx
cmpq 0x28(%rsp), %rbx
jne 0x115039
jmp 0x115339
movq 0x17fcfa(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0x13, %esi
movl $0x1, %edx
leaq 0x124734(%rip), %rdi    # 0x239a2e
callq 0x2410
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x122d5
movsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x40(%rcx), %rcx
jmp 0x1151ed
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1364a
movsd 0x8(%rsp), %xmm0
jmp 0x1152cf
movq 0x40(%rsp), %rdx
incq %rdx
cmpq 0x38(%rsp), %rdx
jne 0x114ffa
movq (%rsp), %rax
movl 0x8(%rax), %ecx
testl %ecx, %ecx
je 0x1155f8
movq (%rsp), %rax
movq (%rax), %rax
xorl %esi, %esi
leaq (%rsi,%rsi,2), %r13
cmpq $0x0, (%rax,%r13,8)
je 0x1155ea
movq %rsi, 0x20(%rsp)
xorl %r14d, %r14d
xorl %ecx, %ecx
xorl %r12d, %r12d
movq %r13, 0x28(%rsp)
movq 0x10(%rax,%r13,8), %rbp
shlq $0x6, %rcx
cmpb $0x2, 0x2(%rbp,%rcx)
jne 0x115558
addq %rcx, %rbp
movl 0x24(%rbp), %edx
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x40(%rcx), %rsi
movl 0x4(%rsi,%rdx,8), %ecx
testq %rcx, %rcx
movq %rsi, 0x30(%rsp)
je 0x11545a
movl 0x4(%rbp), %edi
movl 0x8(%rbp), %r8d
decl %r8d
movl (%rsi,%rdx,8), %r9d
leaq (%r9,%r9,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %r9
addq %rdx, %r9
leaq 0x180377(%rip), %rdx    # 0x295758
movl 0x1bc(%rdx), %r10d
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %r11
addq %rcx, %r11
xorl %r15d, %r15d
xorl %ecx, %ecx
xorl %edx, %edx
movl (%r9,%r15), %ebx
movl 0x4(%r9,%r15), %r13d
cmpl %r13d, %r8d
cmovbl %r8d, %r13d
cmpl %ebx, %edi
cmoval %edi, %ebx
subl %ebx, %r13d
leal 0x1(%r13), %ebx
cmovbl %r14d, %ebx
movl %ecx, %r13d
addl %edx, %r13d
setne %r13b
testl %ebx, %ebx
sete %sil
testb %sil, %r13b
jne 0x11545e
testl %ebx, %ebx
je 0x11544f
movl 0x14(%r9,%r15), %r13d
testl %r13d, %r13d
je 0x115449
testb $0x2, %r13b
je 0x11544d
cmpl $0x2, %r10d
jg 0x11544d
addl %ebx, %ecx
jmp 0x11544f
addl %ebx, %edx
addq $0x1c, %r15
cmpq %r15, %r11
jne 0x1153fa
jmp 0x11545e
xorl %edx, %edx
xorl %ecx, %ecx
movl %edx, %esi
xorps %xmm2, %xmm2
cvtsi2sd %rsi, %xmm2
leal (%rcx,%rdx), %esi
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
movq 0x30(%rsp), %rsi
jae 0x115571
movl 0x28(%rbp), %edx
movl 0x4(%rsi,%rdx,8), %ecx
testq %rcx, %rcx
movq 0x28(%rsp), %r13
je 0x115535
movl 0xc(%rbp), %edi
movl 0x10(%rbp), %r8d
decl %r8d
movl (%rsi,%rdx,8), %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rax
addq %rsi, %rax
leaq 0x18029b(%rip), %rdx    # 0x295758
movl 0x1bc(%rdx), %esi
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %r9
addq %rcx, %r9
xorl %r10d, %r10d
xorl %ecx, %ecx
xorl %edx, %edx
movl (%rax,%r10), %r11d
movl 0x4(%rax,%r10), %ebx
cmpl %ebx, %r8d
cmovbl %r8d, %ebx
cmpl %r11d, %edi
cmoval %edi, %r11d
subl %r11d, %ebx
leal 0x1(%rbx), %r11d
cmovbl %r14d, %r11d
movl %ecx, %ebx
addl %edx, %ebx
setne %bl
testl %r11d, %r11d
sete %r15b
testb %r15b, %bl
jne 0x115539
testl %r11d, %r11d
je 0x11552a
movl 0x14(%rax,%r10), %ebx
testl %ebx, %ebx
je 0x115522
testb $0x2, %bl
je 0x115527
cmpl $0x2, %esi
jg 0x115527
addl %r11d, %ecx
jmp 0x11552a
addl %r11d, %edx
addq $0x1c, %r10
cmpq %r10, %r9
jne 0x1154d5
jmp 0x115539
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 0x1155ae
incl %r12d
movq (%rsp), %rax
movq (%rax), %rax
movq %r12, %rcx
cmpq %r12, (%rax,%r13,8)
ja 0x115385
jmp 0x1155de
movq 0x17fa68(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x1244d4(%rip), %rsi    # 0x239a56
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x122d5
movsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x40(%rcx), %rsi
jmp 0x115486
movq 0x17fa2b(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x1244c1(%rip), %rsi    # 0x239a80
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x122d5
movsd 0x8(%rsp), %xmm0
jmp 0x115558
movq (%rsp), %rcx
movl 0x8(%rcx), %ecx
movq 0x20(%rsp), %rsi
incq %rsi
movl %ecx, %edx
cmpq %rdx, %rsi
jb 0x115364
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq