// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %esi
xorpd %xmm0, %xmm0
leaq 0x90(%rsp), %r8
movapd %xmm0, (%r8)
movapd %xmm0, 0x10(%r8)
movapd %xmm0, 0x20(%r8)
movapd %xmm0, 0x30(%r8)
movapd %xmm0, 0x40(%r8)
movapd %xmm0, 0x50(%r8)
xorl %eax, %eax
movq %rax, 0x60(%r8)
leaq 0x20(%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)
movq %rax, 0x60(%r12)
movq %rax, 0x38(%r8)
movq %rax, 0x38(%r12)
leaq 0x1c(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
callq 0xaa2c3
movl %eax, %r13d
leaq 0x18(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %r12, %r8
callq 0xaa2c3
cmpl $0x7, %r13d
sete %cl
cmpl $0x7, %eax
sete %dl
orb %cl, %dl
movq $-0x1, %r12
jne 0xab51e
cmpl $0x5, %r13d
je 0xab404
decq 0x10(%rsp)
decq 0xc8(%rsp)
cmpl $0x5, %eax
je 0xab413
decq 0x8(%rsp)
decq 0x58(%rsp)
movq 0x10(%rsp), %rdx
cmpq %r15, %rdx
jle 0xab51e
movq 0x8(%rsp), %rsi
cmpq %r15, %rsi
jle 0xab51e
cmpq %rsi, %rdx
movq 0x58(%rsp), %rax
movq 0xc8(%rsp), %r8
movq %r8, %rcx
cmovgq %rax, %rcx
testq %rcx, %rcx
jle 0xab507
cmpq %rsi, %rdx
movq 0x68(%rsp), %rdx
movq 0xd8(%rsp), %rdi
movq %rdi, %rsi
cmovgq %rdx, %rsi
cmovgq %r8, %rax
cmovgq %rdi, %rdx
xorpd %xmm0, %xmm0
xorl %r8d, %r8d
movsd 0x185e93(%rip), %xmm2   # 0x231310
xorpd %xmm1, %xmm1
movl (%rsi,%r8,4), %r9d
leaq (%r9,%r9,2), %r10
movl 0xc(%rbx,%r10,8), %r9d
testq %r9, %r9
je 0xab4d9
leaq (%rbx,%r10,8), %r10
movq (%r10), %r10
movq 0x20(%r14), %r11
xorl %r15d, %r15d
leaq (%r15,%r15,4), %r12
movl 0xc(%r10,%r12,8), %r12d
cmpl $0x0, (%r11,%r12,8)
js 0xab4d1
addsd %xmm2, %xmm0
testq %rax, %rax
jle 0xab4d1
xorl %r13d, %r13d
cmpl %r12d, (%rdx,%r13,4)
je 0xab4cd
incq %r13
cmpq %r13, %rax
jne 0xab4bd
jmp 0xab4d1
addsd %xmm2, %xmm1
incq %r15
cmpq %r9, %r15
jne 0xab4a1
incq %r8
cmpq %rcx, %r8
jne 0xab481
xorpd %xmm2, %xmm2
cmpneqsd %xmm2, %xmm1
movq %xmm1, %rax
andl $0x1, %eax
ucomisd %xmm2, %xmm0
movq $-0x1, %r12
cmovneq %rax, %r12
cmovpq %rax, %r12
jmp 0xab50f
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0x68(%rsp), %rdi
callq 0x2220
movq %r12, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq