// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: check_if_diploid_aggressive(unsigned int, unsigned int, asg_t*, ma_hit_t_alloc*, long long)
long long check_if_diploid_aggressive(uint32_t v1, uint32_t v2, asg_t *g, 
ma_hit_t_alloc* reverse_sources, long long min_edge_length)
{
    buf_t b_0, b_1;
    memset(&b_0, 0, sizeof(buf_t));
    memset(&b_1, 0, sizeof(buf_t));

    uint32_t convex1, convex2;
    long long l1, l2;

    b_0.b.n = 0;
    b_1.b.n = 0;
    ///uint32_t flag1 = detect_single_path(g, v1, &convex1, &l1, &b_0);
    uint32_t flag1 = detect_single_path_with_dels(g, v1, &convex1, &l1, &b_0);
    
    ///uint32_t flag2 = detect_single_path(g, v2, &convex2, &l2, &b_1);
    uint32_t flag2 = detect_single_path_with_dels(g, v2, &convex2, &l2, &b_1);
    
    if(flag1 == LOOP || flag2 == LOOP)
    {
        return -1;
    }

    if(flag1 != END_TIPS && flag1 != LONG_TIPS)
    {
        l1--;
        b_0.b.n--;
    }

    if(flag2 != END_TIPS && flag2 != LONG_TIPS)
    {
        l2--;
        b_1.b.n--;
    }


    if(l1 <= min_edge_length || l2 <= min_edge_length)
    {
        return -1;
    }

    buf_t* b_min;
    buf_t* b_max;
    if(l1<=l2)
    {
        b_min = &b_0;
        b_max = &b_1;
    }
    else
    {
        b_min = &b_1;
        b_max = &b_0;
    }

    long long i, j, k;
    double max_count = 0;
    double min_count = 0;
    uint32_t qn, tn;
    for (i = 0; i < (long long)b_min->b.n; i++)
    {
        qn = b_min->b.a[i];
        for (j = 0; j < (long long)reverse_sources[qn].length; j++)
        {
            tn = Get_tn(reverse_sources[qn].buffer[j]);
            if(g->seq[tn].del == 1) continue;
            min_count++;
            for (k = 0; k < (long long)b_max->b.n; k++)
            {
                if(b_max->b.a[k]==tn)
                {
                    max_count++;
                    break;
                }
            }
        }
    }



    free(b_0.b.a);
    free(b_1.b.a);

    if(min_count == 0) return -1;
    if(max_count == 0) return 0;

    return 1;
    /**
    if(max_count/min_count>0.3) return 1;
    return 0;
    **/

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movq $0x0, -0x58(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0xfc(%rbp), %rdx
leaq -0x108(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0xdb140
movl %eax, -0x114(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
leaq -0x100(%rbp), %rdx
leaq -0x110(%rbp), %rcx
leaq -0xf8(%rbp), %r8
callq 0xdb140
movl %eax, -0x118(%rbp)
cmpl $0x7, -0x114(%rbp)
je 0xdcaf6
cmpl $0x7, -0x118(%rbp)
jne 0xdcb03
movq $-0x1, -0x8(%rbp)
jmp 0xdcdb0
cmpl $0x5, -0x114(%rbp)
je 0xdcb33
cmpl $0x0, -0x114(%rbp)
je 0xdcb33
movq -0x108(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x108(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
cmpl $0x5, -0x118(%rbp)
je 0xdcb69
cmpl $0x0, -0x118(%rbp)
je 0xdcb69
movq -0x110(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x110(%rbp)
movq -0xc0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xc0(%rbp)
movq -0x108(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0xdcb83
movq -0x110(%rbp), %rax
cmpq -0x28(%rbp), %rax
jg 0xdcb90
movq $-0x1, -0x8(%rbp)
jmp 0xdcdb0
movq -0x108(%rbp), %rax
cmpq -0x110(%rbp), %rax
jg 0xdcbbe
leaq -0x90(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0xf8(%rbp), %rax
movq %rax, -0x128(%rbp)
jmp 0xdcbda
leaq -0xf8(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x128(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x148(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x150(%rbp)
movq $0x0, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq -0x120(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jge 0xdcd59
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x130(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x154(%rbp)
movq $0x0, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq -0x20(%rbp), %rcx
movl -0x154(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0xdcd40
movq -0x20(%rbp), %rax
movl -0x154(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x138(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x158(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x158(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xdcca3
jmp 0xdcd29
movsd 0x2a5355(%rip), %xmm0   # 0x382000
addsd -0x150(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
movq $0x0, -0x140(%rbp)
movq -0x140(%rbp), %rax
movq -0x128(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jge 0xdcd27
movq -0x128(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x140(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x158(%rbp), %eax
jne 0xdcd11
movsd 0x2a5301(%rip), %xmm0   # 0x382000
addsd -0x148(%rbp), %xmm0
movsd %xmm0, -0x148(%rbp)
jmp 0xdcd27
jmp 0xdcd13
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x140(%rbp)
jmp 0xdccc6
jmp 0xdcd29
movq -0x138(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x138(%rbp)
jmp 0xdcc39
jmp 0xdcd42
movq -0x130(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x130(%rbp)
jmp 0xdcbfb
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0xb0(%rbp), %rdi
callq 0x2210
movsd -0x150(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdcd8b
jp 0xdcd8b
movq $-0x1, -0x8(%rbp)
jmp 0xdcdb0
movsd -0x148(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdcda8
jp 0xdcda8
movq $0x0, -0x8(%rbp)
jmp 0xdcdb0
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)