// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x28(%rdi), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movq %rax, 0x38(%rsp)
xorl %ebp, %ebp
xorl %edx, %edx
movsd %xmm0, (%rsp)
cmpq 0x38(%rsp), %rdx
je 0xd0a43
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x28(%rax), %rcx
movq %rdx, 0x40(%rsp)
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq %rdx, 0x28(%rsp)
shrq $0x20, %rcx
imulq $0x18, %rcx, %r12
addq 0x8(%rax), %r12
xorl %r14d, %r14d
movq %r12, 0x20(%rsp)
cmpq 0x28(%rsp), %r14
je 0xd0a36
imulq $0x18, %r14, %r15
cmpl $0x0, 0xc(%r12,%r15)
js 0xd097e
addq %r12, %r15
movq 0x18(%rsp), %rax
movq (%rax), %rbx
movq (%r15), %r12
shrq $0x21, %r12
imulq $0x18, %r12, %rdi
addq %rbx, %rdi
movl 0x8(%r15), %edx
shrl %edx
movl %r12d, %esi
callq 0xcd675
movl %eax, %r13d
cmpl $-0x1, %eax
je 0xd0986
imulq $0x18, %r12, %rax
movq 0x10(%rbx,%rax), %rax
movslq %r13d, %rcx
shlq $0x6, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x30(%rsp)
movl 0x24(%rax,%rcx), %r8d
movl 0x4(%rax,%rcx), %esi
movl 0x8(%rax,%rcx), %edi
decl %edi
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x40(%rax), %rdx
movl (%rdx,%r8,8), %eax
movl 0x4(%rdx,%r8,8), %r9d
imulq $0x1c, %rax, %r8
addq %rcx, %r8
leaq 0x182f29(%rip), %rax    # 0x253758
movl 0x1bc(%rax), %eax
imulq $0x1c, %r9, %r11
xorl %r13d, %r13d
xorl %r10d, %r10d
xorl %r9d, %r9d
movsd (%rsp), %xmm0
cmpq %r13, %r11
je 0xd08af
movl (%r8,%r13), %ebx
movl 0x4(%r8,%r13), %r15d
cmpl %r15d, %edi
cmovbl %edi, %r15d
cmpl %ebx, %esi
cmoval %esi, %ebx
subl %ebx, %r15d
leal 0x1(%r15), %r15d
cmovbl %ebp, %r15d
movl %r9d, %ebx
addl %r10d, %ebx
setne %bl
testl %r15d, %r15d
sete %r12b
testb %r12b, %bl
jne 0xd08af
testl %r15d, %r15d
je 0xd08a9
movl 0x14(%r8,%r13), %ebx
testl %ebx, %ebx
je 0xd08a6
cmpl $0x3, %eax
setge %r12b
testb $0x2, %bl
sete %bl
orb %r12b, %bl
je 0xd08a6
addl %r15d, %r10d
jmp 0xd08a9
addl %r15d, %r9d
addq $0x1c, %r13
jmp 0xd0847
movl %r10d, %esi
cvtsi2sd %rsi, %xmm2
addl %r10d, %r9d
cvtsi2sd %r9, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
movq 0x30(%rsp), %r13
jae 0xd09b6
movl 0x28(%r13), %r8d
movl 0xc(%r13), %esi
movl 0x10(%r13), %edi
decl %edi
movl (%rdx,%r8,8), %r9d
movl 0x4(%rdx,%r8,8), %r8d
imulq $0x1c, %r9, %rdx
addq %rcx, %rdx
imulq $0x1c, %r8, %r9
xorl %r10d, %r10d
xorl %r8d, %r8d
xorl %ecx, %ecx
movq 0x20(%rsp), %r12
cmpq %r10, %r9
je 0xd0960
movl (%rdx,%r10), %r11d
movl 0x4(%rdx,%r10), %ebx
cmpl %ebx, %edi
cmovbl %edi, %ebx
cmpl %r11d, %esi
cmoval %esi, %r11d
subl %r11d, %ebx
leal 0x1(%rbx), %r11d
cmovbl %ebp, %r11d
movl %ecx, %ebx
addl %r8d, %ebx
setne %bl
testl %r11d, %r11d
sete %r15b
testb %r15b, %bl
jne 0xd0960
testl %r11d, %r11d
je 0xd095a
movl 0x14(%rdx,%r10), %ebx
testl %ebx, %ebx
je 0xd0952
testb $0x2, %bl
je 0xd0957
cmpl $0x2, %eax
jg 0xd0957
addl %r11d, %ecx
jmp 0xd095a
addl %r11d, %r8d
addq $0x1c, %r10
jmp 0xd0901
movl %r8d, %eax
cvtsi2sd %rax, %xmm2
addl %r8d, %ecx
cvtsi2sd %rcx, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
jae 0xd0a03
incq %r14
jmp 0xd0795
movq 0x182653(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x11a3ed(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x18(%rsp), %rax
movq (%rax), %rbx
movq (%r15), %r12
shrq $0x21, %r12
jmp 0xd07e3
movq 0x182623(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x11af47(%rip), %rdi    # 0x1eb90e
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xccbba
movsd (%rsp), %xmm0
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x40(%rax), %rdx
leaq 0x182d60(%rip), %rax    # 0x253758
movl 0x1bc(%rax), %eax
jmp 0xd08d2
movq 0x1825d6(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x11af0e(%rip), %rdi    # 0x1eb922
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xccbba
movsd (%rsp), %xmm0
jmp 0xd097e
movq 0x40(%rsp), %rdx
incq %rdx
jmp 0xd0759
xorl %ecx, %ecx
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
cmpq %rax, %rcx
jae 0xd0ca0
movq %rcx, 0x20(%rsp)
imulq $0x18, %rcx, %r12
xorl %r13d, %r13d
movq %r12, 0x28(%rsp)
movl %r13d, %r13d
movq 0x18(%rsp), %rax
movq (%rax), %rax
cmpq %r13, (%rax,%r12)
jbe 0xd0c93
addq %r12, %rax
movq 0x10(%rax), %rbp
movq %r13, %rax
shlq $0x6, %rax
cmpb $0x2, 0x2(%rbp,%rax)
jne 0xd0c16
addq %rax, %rbp
movl 0x24(%rbp), %eax
movl 0x4(%rbp), %r8d
movl 0x8(%rbp), %r9d
decl %r9d
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rsi
movq 0x40(%rcx), %rdi
movl (%rdi,%rax,8), %ecx
movl 0x4(%rdi,%rax,8), %edx
imulq $0x1c, %rcx, %r10
movq %rsi, 0x30(%rsp)
addq %rsi, %r10
leaq 0x182c88(%rip), %rax    # 0x253758
movl 0x1bc(%rax), %eax
imulq $0x1c, %rdx, %r11
xorl %ebx, %ebx
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rbx, %r11
je 0xd0b4f
movl (%r10,%rbx), %r15d
movl 0x4(%r10,%rbx), %r12d
cmpl %r12d, %r9d
cmovbl %r9d, %r12d
cmpl %r15d, %r8d
cmoval %r8d, %r15d
subl %r15d, %r12d
leal 0x1(%r12), %r15d
cmovbl %r14d, %r15d
movl %ecx, %r12d
addl %edx, %r12d
setne %r12b
testl %r15d, %r15d
sete %sil
testb %sil, %r12b
jne 0xd0b4f
testl %r15d, %r15d
je 0xd0b49
movl 0x14(%r10,%rbx), %r12d
testl %r12d, %r12d
je 0xd0b46
cmpl $0x3, %eax
setge %sil
testb $0x2, %r12b
sete %r12b
orb %sil, %r12b
je 0xd0b46
addl %r15d, %edx
jmp 0xd0b49
addl %r15d, %ecx
addq $0x1c, %rbx
jmp 0xd0ae0
movl %edx, %esi
cvtsi2sd %rsi, %xmm2
leal (%rcx,%rdx), %esi
cvtsi2sd %rsi, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
movq 0x30(%rsp), %rsi
jae 0xd0c1e
movl 0x28(%rbp), %ecx
movl 0xc(%rbp), %r8d
movl 0x10(%rbp), %r9d
decl %r9d
movl (%rdi,%rcx,8), %edx
movl 0x4(%rdi,%rcx,8), %ecx
imulq $0x1c, %rdx, %rdi
addq %rsi, %rdi
imulq $0x1c, %rcx, %rsi
xorl %r10d, %r10d
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x28(%rsp), %r12
cmpq %r10, %rsi
je 0xd0bfd
movl (%rdi,%r10), %r11d
movl 0x4(%rdi,%r10), %ebx
cmpl %ebx, %r9d
cmovbl %r9d, %ebx
cmpl %r11d, %r8d
cmoval %r8d, %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 0xd0bfd
testl %r11d, %r11d
je 0xd0bf7
movl 0x14(%rdi,%r10), %ebx
testl %ebx, %ebx
je 0xd0bef
testb $0x2, %bl
je 0xd0bf4
cmpl $0x2, %eax
jg 0xd0bf4
addl %r11d, %ecx
jmp 0xd0bf7
addl %r11d, %edx
addq $0x1c, %r10
jmp 0xd0b9d
movl %edx, %eax
cvtsi2sd %rax, %xmm2
leal (%rcx,%rdx), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
jae 0xd0c67
incl %r13d
jmp 0xd0a6a
movq 0x1823bb(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x11ad07(%rip), %rsi    # 0x1eb936
xorl %eax, %eax
callq 0x22b0
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0xccbba
movsd (%rsp), %xmm0
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x40(%rax), %rdi
leaq 0x182afc(%rip), %rax    # 0x253758
movl 0x1bc(%rax), %eax
jmp 0xd0b71
movq 0x182372(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x11ace8(%rip), %rsi    # 0x1eb960
xorl %eax, %eax
callq 0x22b0
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0xccbba
movsd (%rsp), %xmm0
jmp 0xd0c16
movq 0x20(%rsp), %rcx
incq %rcx
jmp 0xd0a48
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq