// File: /workspace/github_cpp_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
movl %r9d, %r13d
movq %r8, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r15
movl %esi, 0x10(%rsp)
movl %edi, %esi
xorpd %xmm0, %xmm0
leaq 0xc0(%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 0x50(%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)
movl %r9d, (%rsp)
leaq 0x44(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0x48(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %r8
movq %r12, %r9
callq 0xa9452
movl %eax, %r14d
movl %r13d, (%rsp)
leaq 0x40(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r15, 0x18(%rsp)
movq %r15, %rdi
movl 0x10(%rsp), %esi
movq %rbx, %r8
movq %rbp, %r9
callq 0xa9452
cmpl $0x7, %r14d
sete %cl
cmpl $0x7, %eax
sete %dl
orb %cl, %dl
movq $-0x1, %r15
jne 0xaa27d
testl %r14d, %r14d
je 0xaa06e
cmpl $0x5, %r14d
je 0xaa06e
decq 0x28(%rsp)
decq 0xf8(%rsp)
testl %eax, %eax
movq 0x38(%rsp), %r13
je 0xaa089
cmpl $0x5, %eax
je 0xaa089
decq 0x20(%rsp)
decq 0x88(%rsp)
movq 0x168(%rsp), %rax
movq 0xf8(%rsp), %r8
movq 0x108(%rsp), %rcx
movq 0x88(%rsp), %r9
movq 0x98(%rsp), %rdi
movq %r9, %rdx
movq %r8, %rsi
testq %r8, %r8
jle 0xaa0d5
testq %rdx, %rdx
jle 0xaa0d5
leaq -0x1(%rsi), %r8
leaq -0x1(%rdx), %r9
movl -0x4(%rcx,%rsi,4), %r10d
cmpl -0x4(%rdi,%rdx,4), %r10d
je 0xaa0b1
movq %rsi, 0xf8(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x88(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x30(%rsp), %rdi
cmpq %rdi, %rsi
setg %cl
cmpq %rdi, %rdx
setg %dil
andb %cl, %dil
cmpb $0x1, %dil
jne 0xaa27d
cmpq %rdx, %rsi
cmovgq %rbp, %r12
movq 0x38(%r12), %rcx
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
testq %rcx, %rcx
jle 0xaa21b
cmpq %rdx, %rsi
leaq 0x88(%rsp), %rdi
movq 0x10(%rdi), %rdx
leaq 0xf8(%rsp), %r8
movq 0x10(%r8), %r9
movq %r9, %rsi
cmovgq %rdx, %rsi
cmovgq %r8, %rdi
movq (%rdi), %rdi
cmovgq %r9, %rdx
xorl %r8d, %r8d
movsd 0x17b10d(%rip), %xmm0   # 0x225270
movl (%rsi,%r8,4), %r9d
leaq (%r9,%r9,2), %r10
movl 0xc(%r13,%r10,8), %r9d
testq %r9, %r9
je 0xaa20f
leaq (,%r10,8), %r10
addq %r13, %r10
movq (%r10), %r10
movq 0x18(%rsp), %r11
movq 0x20(%r11), %r11
xorl %ebx, %ebx
leaq (%rbx,%rbx,4), %r14
movl 0xc(%r10,%r14,8), %r14d
cmpl $0x0, (%r11,%r14,8)
movl %r14d, %ebp
js 0xaa1c1
addsd %xmm0, %xmm1
testq %rdi, %rdi
jle 0xaa207
xorl %r14d, %r14d
cmpl %ebp, (%rdx,%r14,4)
je 0xaa203
incq %r14
cmpq %r14, %rdi
jne 0xaa1b1
jmp 0xaa207
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %r14, (%rax)
jbe 0xaa1e8
movq 0x8(%rax), %r12
movl (%r12,%r14,4), %r14d
cmpl $-0x1, %r14d
je 0xaa1e8
movl %r14d, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
shrl $0x1f, %r14d
jmp 0xaa1eb
xorl %r14d, %r14d
cmpl $-0x1, %ebp
sete %r12b
orb %r14b, %r12b
jne 0xaa207
movl %ebp, %r14d
cmpl $0x0, (%r11,%r14,8)
jns 0xaa1a5
jmp 0xaa207
addsd %xmm0, %xmm2
incq %rbx
cmpq %r9, %rbx
jne 0xaa192
incq %r8
cmpq %rcx, %r8
jne 0xaa163
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
movq 0x108(%rsp), %rdi
callq 0x2220
movq 0x98(%rsp), %rdi
callq 0x2220
movsd 0x18(%rsp), %xmm1
ucomisd 0x17b2c9(%rip), %xmm1   # 0x225518
jne 0xaa253
jnp 0xaa27d
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jne 0xaa26a
jp 0xaa26a
xorl %r15d, %r15d
jmp 0xaa27d
divsd %xmm1, %xmm2
xorl %r15d, %r15d
ucomisd 0x17a967(%rip), %xmm2   # 0x224be0
seta %r15b
movq %r15, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq