// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: check_if_diploid(unsigned int, unsigned int, asg_t*, ma_hit_t_alloc*, long long, R_to_U*)
long long check_if_diploid(uint32_t v1, uint32_t v2, asg_t *g, 
ma_hit_t_alloc* reverse_sources, long long min_edge_length, R_to_U* ruIndex)
{
    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)
    {
		free(b_0.b.a); free(b_1.b.a);
        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)
    {
		free(b_0.b.a); free(b_1.b.a);
        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, is_Unitig;
    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]);
            /****************************may have bugs********************************/
            ///if(g->seq[tn].del == 1) continue;
            if(g->seq[tn].del == 1)
            {
                get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
                if(tn == (uint32_t)-1 || is_Unitig == 1 || g->seq[tn].del == 1) continue;
            }
            /****************************may have bugs********************************/
            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;
    if(max_count/min_count>0.3) return 1;
    return 0;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movq $0x0, -0x60(%rbp)
movq $0x0, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0x104(%rbp), %rdx
leaq -0x110(%rbp), %rcx
leaq -0x98(%rbp), %r8
callq 0xdb140
movl %eax, -0x11c(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
leaq -0x108(%rbp), %rdx
leaq -0x118(%rbp), %rcx
leaq -0x100(%rbp), %r8
callq 0xdb140
movl %eax, -0x120(%rbp)
cmpl $0x7, -0x11c(%rbp)
je 0xdc0aa
cmpl $0x7, -0x120(%rbp)
jne 0xdc0cc
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0xb8(%rbp), %rdi
callq 0x2210
movq $-0x1, -0x8(%rbp)
jmp 0xdc400
cmpl $0x5, -0x11c(%rbp)
je 0xdc0fc
cmpl $0x0, -0x11c(%rbp)
je 0xdc0fc
movq -0x110(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x110(%rbp)
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
cmpl $0x5, -0x120(%rbp)
je 0xdc132
cmpl $0x0, -0x120(%rbp)
je 0xdc132
movq -0x118(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x118(%rbp)
movq -0xc8(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xc8(%rbp)
movq -0x110(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0xdc14c
movq -0x118(%rbp), %rax
cmpq -0x28(%rbp), %rax
jg 0xdc16e
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0xb8(%rbp), %rdi
callq 0x2210
movq $-0x1, -0x8(%rbp)
jmp 0xdc400
movq -0x110(%rbp), %rax
cmpq -0x118(%rbp), %rax
jg 0xdc19c
leaq -0x98(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x130(%rbp)
jmp 0xdc1b8
leaq -0x100(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, -0x130(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x150(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x158(%rbp)
movq $0x0, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq -0x128(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jge 0xdc381
movq -0x128(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x138(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x15c(%rbp)
movq $0x0, -0x140(%rbp)
movq -0x140(%rbp), %rax
movq -0x20(%rbp), %rcx
movl -0x15c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0xdc368
movq -0x20(%rbp), %rax
movl -0x15c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x140(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x160(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x160(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xdc2cb
movq -0x30(%rbp), %rdi
movl -0x160(%rbp), %esi
leaq -0x160(%rbp), %rdx
leaq -0x164(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x160(%rbp)
je 0xdc2c4
cmpl $0x1, -0x164(%rbp)
je 0xdc2c4
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x160(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xdc2c9
jmp 0xdc351
jmp 0xdc2cb
movsd 0x2a5d2d(%rip), %xmm0   # 0x382000
addsd -0x158(%rbp), %xmm0
movsd %xmm0, -0x158(%rbp)
movq $0x0, -0x148(%rbp)
movq -0x148(%rbp), %rax
movq -0x130(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jge 0xdc34f
movq -0x130(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x148(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x160(%rbp), %eax
jne 0xdc339
movsd 0x2a5cd9(%rip), %xmm0   # 0x382000
addsd -0x150(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
jmp 0xdc34f
jmp 0xdc33b
movq -0x148(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x148(%rbp)
jmp 0xdc2ee
jmp 0xdc351
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x140(%rbp)
jmp 0xdc217
jmp 0xdc36a
movq -0x138(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x138(%rbp)
jmp 0xdc1d9
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0xb8(%rbp), %rdi
callq 0x2210
movsd -0x158(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdc3b3
jp 0xdc3b3
movq $-0x1, -0x8(%rbp)
jmp 0xdc400
movsd -0x150(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdc3d0
jp 0xdc3d0
movq $0x0, -0x8(%rbp)
jmp 0xdc400
movsd -0x150(%rbp), %xmm0
divsd -0x158(%rbp), %xmm0
movsd 0x2a5560(%rip), %xmm1   # 0x381948
ucomisd %xmm1, %xmm0
jbe 0xdc3f8
movq $0x1, -0x8(%rbp)
jmp 0xdc400
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax)