// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: check_if_cross(asg_t*, unsigned int)
int check_if_cross(asg_t *g, uint32_t v)
{
    uint32_t N_list[5] = {0};
    if (g->seq[v>>1].del) return 0;
    uint32_t nv = asg_arc_n(g, v);
    asg_arc_t *av = asg_arc_a(g, v);
    if(nv != 2) return 0;
    if(asg_is_single_edge(g, av[0].v, v>>1) != 2 || asg_is_single_edge(g, av[1].v, v>>1) != 2)
    {
        return 0;
    }
    if(av[0].v == av[1].v)
    {
        return 0;
    }
    N_list[0] = v;
    N_list[1] = av[0].v^1;
    N_list[2] = av[1].v^1;
    if(asg_arc_n(g, N_list[0]) != 2 || 
       asg_arc_n(g, N_list[1]) != 2 ||
       asg_arc_n(g, N_list[2]) != 2 )
    {
        return 0;
    }

    if(asg_arc_a(g, N_list[1])[0].v == asg_arc_a(g, N_list[1])[1].v)
    {
        return 0;
    }

    if(asg_arc_a(g, N_list[2])[0].v == asg_arc_a(g, N_list[2])[1].v)
    {
        return 0;
    }

    if(asg_arc_a(g, N_list[1])[0].v == (N_list[0]^1))
    {
        N_list[3] = asg_arc_a(g, N_list[1])[1].v^1;
    }
    else if(asg_arc_a(g, N_list[1])[1].v == (N_list[0]^1))
    {
        N_list[3] = asg_arc_a(g, N_list[1])[0].v^1;
    }

    if(asg_arc_a(g, N_list[2])[0].v == (N_list[0]^1))
    {
        N_list[4] = asg_arc_a(g, N_list[2])[1].v^1;
    }
    else if(asg_arc_a(g, N_list[2])[1].v == (N_list[0]^1))
    {
        N_list[4] = asg_arc_a(g, N_list[2])[0].v^1;
    }

    if(N_list[3] != N_list[4])
    {
        return 0;
    }

    if(asg_arc_n(g, N_list[0]) != 2 || 
        asg_arc_n(g, N_list[1]) != 2 ||
        asg_arc_n(g, N_list[2]) != 2 ||
        asg_arc_n(g, N_list[3]) != 2)
    {
        return 0;
    }


    uint32_t convex1, convex2, f1, f2;
    long long l1, l2;
    l1 = l2 = 0;
    int todel = 0;
    
    f1 = detect_bubble_end_with_bubbles(g, N_list[0]^1, N_list[3]^1, &convex1, &l1, NULL);
    f2 = detect_bubble_end_with_bubbles(g, N_list[1]^1, N_list[2]^1, &convex2, &l2, NULL);

    if(f1 && f2)///full bubble
    {
        if(l1 > min_thres && l2 > min_thres)
        {
            todel = 1;
        }     
    }
    else if(f1)//semi bubble
    {
        if(l1 > min_thres)
        {
            todel = 1;
        }        
    }
    else if(f2)//semi bubble
    {
        if(l2 > min_thres)
        {
            todel = 1;
        }  
    }
    

    return todel;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x20(%rdi), %rax
movl %esi, %r15d
shrl %r15d
xorl %ebp, %ebp
cmpl $0x0, (%rax,%r15,8)
js 0x6ecec
movl %esi, %r14d
movq %rdi, %rbx
movq 0x28(%rdi), %rax
movl %esi, %r13d
movq (%rax,%r13,8), %rax
cmpl $0x2, %eax
jne 0x6ecec
shrq $0x20, %rax
imulq $0x18, %rax, %r12
addq 0x8(%rbx), %r12
movl 0x8(%r12), %esi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x6c8a1
cmpl $0x2, %eax
jne 0x6ecec
movl 0x20(%r12), %esi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x6c8a1
cmpl $0x2, %eax
jne 0x6ecec
movl 0x8(%r12), %r15d
movl 0x20(%r12), %r12d
cmpl %r12d, %r15d
je 0x6ecec
movq 0x28(%rbx), %rax
cmpl $0x2, (%rax,%r13,8)
jne 0x6ecec
movq %r15, %rcx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
cmpl $0x2, %edx
jne 0x6ecec
movq %r12, %rcx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rcx
cmpl $0x2, %ecx
jne 0x6ecec
movq 0x8(%rbx), %rdi
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
movl 0x8(%rdi,%rdx), %esi
movl 0x20(%rdi,%rdx), %r8d
cmpl %r8d, %esi
je 0x6ecec
shrq $0x20, %rcx
imulq $0x18, %rcx, %rdx
movl 0x8(%rdi,%rdx), %ecx
movl 0x20(%rdi,%rdx), %edi
cmpl %edi, %ecx
je 0x6ecec
xorl $0x1, %r14d
movl %r8d, %r9d
xorl $0x1, %r9d
movl %esi, %edx
xorl $0x1, %edx
xorl %ebp, %ebp
cmpl %r14d, %r8d
cmovnel %ebp, %edx
cmpl %r14d, %esi
cmovel %r9d, %edx
movl %edi, %esi
xorl $0x1, %esi
movl %ecx, %r8d
xorl $0x1, %r8d
cmpl %r14d, %edi
cmovnel %ebp, %r8d
cmpl %r14d, %ecx
cmovel %esi, %r8d
cmpl %r8d, %edx
jne 0x6ecec
movl %edx, %ecx
cmpl $0x2, (%rax,%rcx,8)
jne 0x6ecec
movq %rsp, %r13
andq $0x0, (%r13)
leaq 0x8(%rsp), %r8
andq $0x0, (%r8)
xorl $0x1, %edx
leaq 0x14(%rsp), %rcx
movq %rbx, %rdi
movl %r14d, %esi
xorl %r9d, %r9d
callq 0x6ce93
movl %eax, %ebp
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
movq %r13, %r8
xorl %r9d, %r9d
callq 0x6ce93
testl %ebp, %ebp
je 0x6eccc
testl %eax, %eax
je 0x6eccc
movq 0x1e5767(%rip), %rax    # 0x254420
cmpq %rax, 0x8(%rsp)
setg %cl
cmpq %rax, (%rsp)
setg %al
andb %cl, %al
jmp 0x6ece9
testl %ebp, %ebp
je 0x6ecd7
movq 0x8(%rsp), %rax
jmp 0x6ecdf
testl %eax, %eax
je 0x6ecfd
movq (%rsp), %rax
cmpq 0x1e573a(%rip), %rax    # 0x254420
setg %al
movzbl %al, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x6ece9