// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: check_if_diploid_primary_complex(unsigned int, unsigned int, asg_t*, ma_hit_t_alloc*, long long, unsigned int, int, R_to_U*)
long long check_if_diploid_primary_complex(uint32_t v1, uint32_t v2, asg_t *g, 
ma_hit_t_alloc* reverse_sources, long long min_edge_length, uint32_t stops_threshold,
int if_drop, 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, max_stop_Len;

    b_0.b.n = 0;
    b_1.b.n = 0;
    uint32_t flag1 = detect_single_path_with_dels_n_stops(g, v1, &convex1, &l1, 
    &max_stop_Len, &b_0, stops_threshold);
    
    uint32_t flag2 = detect_single_path_with_dels_n_stops(g, v2, &convex2, &l2, 
    &max_stop_Len, &b_1, stops_threshold);
    
    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--;
    }


    long long i, j, k;
    i = b_0.b.n; i--;
    j = b_1.b.n; j--;
    while (i>=0 && j>=0)
    {
        if(b_0.b.a[i] == b_1.b.a[j])
        {
            i--;
            j--;
        }
        else
        {
            break;
        }
        
    }
    b_0.b.n = i+1; l1 = i+1;
    b_1.b.n = j+1; l2 = j+1;


    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;
    }

    
    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 || (if_drop == 1 && g->seq[tn].c == ALTER_LABLE)) 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 $0x118, %rsp            # imm = 0x118
movl %r9d, %r15d
movq %r8, 0x10(%rsp)
movq %rcx, %rbx
movq %rdx, %rbp
movl %esi, 0x18(%rsp)
movl %edi, %esi
xorpd %xmm0, %xmm0
leaq 0xb0(%rsp), %r9
movapd %xmm0, (%r9)
movapd %xmm0, 0x10(%r9)
movapd %xmm0, 0x20(%r9)
movapd %xmm0, 0x30(%r9)
movapd %xmm0, 0x40(%r9)
movapd %xmm0, 0x50(%r9)
xorl %eax, %eax
movq %rax, 0x60(%r9)
leaq 0x40(%rsp), %r13
movapd %xmm0, (%r13)
movapd %xmm0, 0x10(%r13)
movapd %xmm0, 0x20(%r13)
movapd %xmm0, 0x30(%r13)
movapd %xmm0, 0x40(%r13)
movapd %xmm0, 0x50(%r13)
movq %rax, 0x60(%r13)
movq %rax, 0x38(%r9)
movq %rax, 0x38(%r13)
movl %r15d, (%rsp)
leaq 0x24(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x28(%rsp), %r14
movq %rbp, %rdi
movq %r14, %r8
callq 0xaa4f8
movl %eax, %r12d
movl %r15d, (%rsp)
leaq 0x20(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %rbp, %r15
movq %rbp, %rdi
movl 0x18(%rsp), %esi
movq %r14, %r8
movq %r13, %r9
callq 0xaa4f8
cmpl $0x7, %r12d
sete %cl
cmpl $0x7, %eax
sete %dl
orb %cl, %dl
movq $-0x1, %r11
jne 0xab26a
testl %r12d, %r12d
je 0xab0d7
cmpl $0x5, %r12d
je 0xab0d7
decq 0xe8(%rsp)
testl %eax, %eax
je 0xab0e5
cmpl $0x5, %eax
je 0xab0e5
decq 0x78(%rsp)
movq 0x158(%rsp), %rax
movq 0xe8(%rsp), %rsi
movq 0xf8(%rsp), %rdi
movq 0x78(%rsp), %r8
movq 0x88(%rsp), %rcx
movq %r8, %r9
movq %rsi, %rdx
testq %rsi, %rsi
jle 0xab12e
testq %r9, %r9
jle 0xab12e
leaq -0x1(%rdx), %rsi
leaq -0x1(%r9), %r8
movl -0x4(%rdi,%rdx,4), %r10d
cmpl -0x4(%rcx,%r9,4), %r10d
je 0xab10a
movq %rdx, 0xe8(%rsp)
movq %r9, 0x78(%rsp)
movq 0x10(%rsp), %r8
cmpq %r8, %rdx
setg %sil
cmpq %r8, %r9
setg %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
jne 0xab26a
cmpq %r9, %rdx
movq %r9, %rsi
cmovlq %rdx, %rsi
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
testq %rsi, %rsi
jle 0xab209
cmpq %r9, %rdx
movq %rdi, %r8
cmovgq %rcx, %r8
cmovgq %rdi, %rcx
cmovlq %r9, %rdx
xorl %r9d, %r9d
movsd 0x18617d(%rip), %xmm0   # 0x231310
movl (%r8,%r9,4), %r10d
leaq (%r10,%r10,2), %r11
movl 0xc(%rbx,%r11,8), %r10d
testq %r10, %r10
je 0xab201
leaq (%rbx,%r11,8), %r11
movq (%r11), %r11
movq 0x20(%r15), %r14
xorl %r12d, %r12d
leaq (%r12,%r12,4), %r13
movl 0xc(%r11,%r13,8), %r13d
cmpl $0x0, (%r14,%r13,8)
js 0xab1d9
addsd %xmm0, %xmm1
xorl %ebp, %ebp
cmpl %r13d, (%rcx,%rbp,4)
je 0xab1f5
incq %rbp
cmpq %rbp, %rdx
jne 0xab1c9
jmp 0xab1f9
cmpq %r13, (%rax)
jbe 0xab1f9
movq 0x8(%rax), %rbp
movslq (%rbp,%r13,4), %r13
testq %r13, %r13
js 0xab1f9
cmpl $0x0, (%r14,%r13,8)
jns 0xab1c3
jmp 0xab1f9
addsd %xmm0, %xmm2
incq %r12
cmpq %r10, %r12
jne 0xab1b3
incq %r9
cmpq %rsi, %r9
jne 0xab193
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
callq 0x2220
movq 0x88(%rsp), %rdi
callq 0x2220
movsd 0x18(%rsp), %xmm1
ucomisd 0x1863e3(%rip), %xmm1   # 0x231618
movq $-0x1, %r11
jne 0xab240
jnp 0xab26a
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jne 0xab257
jp 0xab257
xorl %r11d, %r11d
jmp 0xab26a
divsd %xmm1, %xmm2
xorl %r11d, %r11d
ucomisd 0x1859ba(%rip), %xmm2   # 0x230c20
seta %r11b
movq %r11, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq