// File: /workspace/github_cpp_makefile_star2_O2/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 $0x108, %rsp            # imm = 0x108
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %esi
xorpd %xmm0, %xmm0
leaq 0xa0(%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)
andq $0x0, 0x60(%r8)
leaq 0x30(%rsp), %r13
movapd %xmm0, (%r13)
movapd %xmm0, 0x10(%r13)
movapd %xmm0, 0x20(%r13)
movapd %xmm0, 0x30(%r13)
andq $0x0, 0x60(%r13)
movapd %xmm0, 0x40(%r13)
andq $0x0, 0x38(%r8)
movapd %xmm0, 0x50(%r13)
andq $0x0, 0x38(%r13)
leaq 0x2c(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
callq 0x70874
movl %eax, %r12d
leaq 0x28(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %r8
callq 0x70874
movl %eax, %ecx
cmpl $0x7, %r12d
sete %al
cmpl $0x7, %ecx
sete %dl
orb %al, %dl
pushq $-0x1
popq %rax
jne 0x71788
cmpl $0x5, %r12d
je 0x71665
decq 0x10(%rsp)
decq 0xd8(%rsp)
cmpl $0x5, %ecx
je 0x71674
decq 0x8(%rsp)
decq 0x68(%rsp)
movq 0x10(%rsp), %rcx
cmpq %r15, %rcx
jle 0x71788
movq 0x8(%rsp), %rdx
cmpq %r15, %rdx
jle 0x71788
cmpq %rdx, %rcx
movq 0x68(%rsp), %rax
movq 0x78(%rsp), %rcx
movq 0xd8(%rsp), %r8
movq %r8, %rdx
cmovgq %rax, %rdx
movq 0xe8(%rsp), %rdi
movq %rdi, %rsi
cmovgq %rcx, %rsi
cmovgq %r8, %rax
cmovgq %rdi, %rcx
xorl %r8d, %r8d
testq %rax, %rax
cmovleq %r8, %rax
testq %rdx, %rdx
cmovleq %r8, %rdx
xorpd %xmm1, %xmm1
movsd 0x171bc0(%rip), %xmm0   # 0x1e32a0
xorpd %xmm2, %xmm2
cmpq %rdx, %r8
je 0x71741
movl (%rsi,%r8,4), %r9d
imulq $0x18, %r9, %r10
leaq (%rbx,%r10), %r9
movl 0xc(%rbx,%r10), %r10d
xorl %r11d, %r11d
cmpq %r10, %r11
je 0x7173c
movq (%r9), %r15
imulq $0x28, %r11, %r12
movl 0xc(%r15,%r12), %r15d
movq 0x20(%r14), %r12
cmpl $0x0, (%r12,%r15,8)
js 0x71737
addsd %xmm0, %xmm2
xorl %r12d, %r12d
cmpq %r12, %rax
je 0x71737
leaq 0x1(%r12), %r13
cmpl %r15d, (%rcx,%r12,4)
movq %r13, %r12
jne 0x71720
addsd %xmm0, %xmm1
incq %r11
jmp 0x716fd
incq %r8
jmp 0x716e4
movsd %xmm1, 0x18(%rsp)
movsd %xmm2, 0x20(%rsp)
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
xorpd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
cmpneqsd %xmm0, %xmm1
movq %xmm1, %rcx
andl $0x1, %ecx
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
pushq $-0x1
popq %rax
cmovneq %rcx, %rax
cmovpq %rcx, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq