// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
movl %esi, %r14d
shrl %r14d
xorl %eax, %eax
cmpl $0x0, (%rcx,%r14,8)
js 0xa7b57
movl %esi, %ebp
movq %rdi, %rbx
movq 0x28(%rdi), %rdx
movl %esi, %r12d
movq (%rdx,%r12,8), %rsi
cmpl $0x2, %esi
jne 0xa7b57
movq 0x8(%rbx), %rcx
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rax
leaq (%rcx,%rax,8), %r15
movl 0x8(%r15), %eax
xorq $0x1, %rax
movq (%rdx,%rax,8), %r13
testl %r13d, %r13d
jle 0xa7ae7
movq %r13, %rdx
shrq $0x20, %rdx
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r14d, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa7929
testl %ecx, %ecx
je 0xa7aea
xorl %eax, %eax
cmpl $0x2, %r13d
jne 0xa7b57
movl 0x20(%r15), %eax
movq 0x28(%rbx), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r13
testl %r13d, %r13d
jle 0xa7b0f
movq 0x8(%rbx), %rcx
movq %r13, %rdx
shrq $0x20, %rdx
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r14d, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa798f
testl %ecx, %ecx
je 0xa7b12
xorl %eax, %eax
cmpl $0x2, %r13d
jne 0xa7b57
movl 0x8(%r15), %r14d
movl 0x20(%r15), %r15d
cmpl %r15d, %r14d
je 0xa7b57
movq 0x28(%rbx), %rcx
cmpl $0x2, (%rcx,%r12,8)
jne 0xa7b57
movq %r14, %rdx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rsi
cmpl $0x2, %esi
jne 0xa7b57
movq %r15, %rdx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rdx
cmpl $0x2, %edx
jne 0xa7b57
movq 0x8(%rbx), %r8
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
movl 0x8(%r8,%rsi,8), %edi
movl 0x20(%r8,%rsi,8), %r9d
cmpl %r9d, %edi
je 0xa7b57
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%r8,%rdx,8), %esi
movl 0x20(%r8,%rdx,8), %r8d
cmpl %r8d, %esi
je 0xa7b57
xorl $0x1, %ebp
movl %r9d, %r10d
xorl $0x1, %r10d
movl %edi, %edx
xorl $0x1, %edx
xorl %eax, %eax
cmpl %ebp, %r9d
cmovnel %eax, %edx
cmpl %ebp, %edi
cmovel %r10d, %edx
movl %r8d, %edi
xorl $0x1, %edi
movl %esi, %r9d
xorl $0x1, %r9d
cmpl %ebp, %r8d
cmovnel %eax, %r9d
cmpl %ebp, %esi
cmovel %edi, %r9d
cmpl %r9d, %edx
jne 0xa7b57
movl %edx, %esi
cmpl $0x2, (%rcx,%rsi,8)
jne 0xa7b57
xorl %eax, %eax
movq %rsp, %r12
movq %rax, (%r12)
leaq 0x8(%rsp), %r8
movq %rax, (%r8)
xorl $0x1, %edx
leaq 0x14(%rsp), %rcx
movq %rbx, %rdi
movl %ebp, %esi
xorl %r9d, %r9d
callq 0xa4f1c
movl %eax, %ebp
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xa4f1c
testl %ebp, %ebp
je 0xa7b37
testl %eax, %eax
je 0xa7b37
movq 0x1ee94c(%rip), %rax    # 0x296420
cmpq %rax, 0x8(%rsp)
setg %cl
cmpq %rax, (%rsp)
setg %al
andb %cl, %al
jmp 0xa7b54
xorl %r13d, %r13d
movq 0x1ed4ef(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x19161f(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
callq 0x2410
jmp 0xa7944
xorl %r13d, %r13d
movq 0x1ed4c7(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1915f7(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
callq 0x2410
jmp 0xa79aa
testl %ebp, %ebp
je 0xa7b42
movq 0x8(%rsp), %rax
jmp 0xa7b4a
testl %eax, %eax
je 0xa7b66
movq (%rsp), %rax
cmpq 0x1ee8cf(%rip), %rax    # 0x296420
setg %al
movzbl %al, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0xa7b54