// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, %rbx
movq %r8, 0x20(%rsp)
movq %rcx, (%rsp)
movq %rdx, %r14
movl %esi, %r15d
movl %edi, %esi
xorpd %xmm0, %xmm0
leaq 0xa0(%rsp), %r12
movapd %xmm0, (%r12)
movapd %xmm0, 0x10(%r12)
movapd %xmm0, 0x20(%r12)
movapd %xmm0, 0x30(%r12)
movapd %xmm0, 0x40(%r12)
movapd %xmm0, 0x50(%r12)
xorl %eax, %eax
movq %rax, 0x60(%r12)
leaq 0x30(%rsp), %rbp
movapd %xmm0, (%rbp)
movapd %xmm0, 0x10(%rbp)
movapd %xmm0, 0x20(%rbp)
movapd %xmm0, 0x30(%rbp)
movapd %xmm0, 0x40(%rbp)
movapd %xmm0, 0x50(%rbp)
movq %rax, 0x60(%rbp)
movq %rax, 0x38(%r12)
movq %rax, 0x38(%rbp)
leaq 0x2c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %r14, %rdi
movq %r12, %r8
callq 0xa9219
movl %eax, %r13d
leaq 0x28(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, 0x8(%rsp)
movq %r14, %rdi
movl %r15d, %esi
movq %rbp, %r8
callq 0xa9219
cmpl $0x7, %r13d
setne %cl
cmpl $0x7, %eax
setne %dl
testb %dl, %cl
je 0xa9f1b
cmpl $0x5, %r13d
je 0xa9d8d
decq 0x18(%rsp)
decq 0xd8(%rsp)
cmpl $0x5, %eax
movq 0x8(%rsp), %r14
movq (%rsp), %r13
movq 0x20(%rsp), %rax
je 0xa9daa
decq 0x10(%rsp)
decq 0x68(%rsp)
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
jle 0xa9f1b
movq 0x10(%rsp), %rdx
cmpq %rax, %rdx
jle 0xa9f1b
cmpq %rdx, %rcx
cmovgq %rbp, %r12
movq 0x38(%r12), %rax
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
testq %rax, %rax
jle 0xa9ecb
cmpq %rdx, %rcx
leaq 0x68(%rsp), %rsi
movq 0x10(%rsi), %rcx
leaq 0xd8(%rsp), %rdi
movq 0x10(%rdi), %r8
movq %r8, %rdx
cmovgq %rcx, %rdx
cmovgq %rdi, %rsi
movq (%rsi), %rsi
cmovgq %r8, %rcx
xorl %edi, %edi
movsd 0x17b459(%rip), %xmm0   # 0x225270
movl (%rdx,%rdi,4), %r8d
leaq (%r8,%r8,2), %r9
movl 0xc(%r13,%r9,8), %r8d
testq %r8, %r8
je 0xa9ebf
leaq (,%r9,8), %r9
addq %r13, %r9
movq (%r9), %r9
movq 0x20(%r14), %r10
xorl %r11d, %r11d
leaq (%r11,%r11,4), %r15
movl 0xc(%r9,%r15,8), %r15d
cmpl $0x0, (%r10,%r15,8)
movl %r15d, %ebp
js 0xa9e71
addsd %xmm0, %xmm1
testq %rsi, %rsi
jle 0xa9eb7
xorl %r15d, %r15d
cmpl %ebp, (%rcx,%r15,4)
je 0xa9eb3
incq %r15
cmpq %r15, %rsi
jne 0xa9e61
jmp 0xa9eb7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %r15, (%rbx)
jbe 0xa9e98
movq 0x8(%rbx), %r12
movl (%r12,%r15,4), %r15d
cmpl $-0x1, %r15d
je 0xa9e98
movl %r15d, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
shrl $0x1f, %r15d
jmp 0xa9e9b
xorl %r15d, %r15d
cmpl $-0x1, %ebp
sete %r12b
orb %r15b, %r12b
jne 0xa9eb7
movl %ebp, %r15d
cmpl $0x0, (%r10,%r15,8)
jns 0xa9e55
jmp 0xa9eb7
addsd %xmm0, %xmm2
incq %r11
cmpq %r8, %r11
jne 0xa9e42
incq %rdi
cmpq %rax, %rdi
jne 0xa9e17
movsd %xmm2, (%rsp)
movsd %xmm1, 0x8(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movsd 0x8(%rsp), %xmm1
movq $-0x1, %rax
ucomisd 0x17b616(%rip), %xmm1   # 0x225518
jne 0xa9f06
jnp 0xa9f39
xorpd %xmm0, %xmm0
movsd (%rsp), %xmm2
ucomisd %xmm0, %xmm2
jne 0xa9f4b
jp 0xa9f4b
xorl %eax, %eax
jmp 0xa9f39
movq 0xe8(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movq $-0x1, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
divsd %xmm1, %xmm2
xorl %eax, %eax
ucomisd 0x17ac87(%rip), %xmm2   # 0x224be0
seta %al
jmp 0xa9f39