// File: /workspace/github_cpp_makefile_star2_O1/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 0xa6b1d
movl %esi, %ebp
movq %rdi, %rbx
movq 0x28(%rdi), %rcx
movl %esi, %r12d
movq (%rcx,%r12,8), %rsi
cmpl $0x2, %esi
jne 0xa6b1d
movq 0x8(%rbx), %rdx
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rax
leaq (%rdx,%rax,8), %r15
movl 0x8(%r15), %eax
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %r13d, %r13d
testl %eax, %eax
jle 0xa6930
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r14d, %edi
cmovel %esi, %r13d
addq $0x18, %rdx
decq %rcx
jne 0xa690d
testl %r13d, %r13d
sete %cl
cmpl $0x2, %eax
sete %r13b
jmp 0xa6932
movb $0x1, %cl
testb %cl, %cl
jne 0xa6ae9
xorl %eax, %eax
testb %r13b, %r13b
je 0xa6b1d
movl 0x20(%r15), %eax
movq 0x28(%rbx), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %r13d, %r13d
testl %eax, %eax
jle 0xa69a3
movq 0x8(%rbx), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r14d, %edi
cmovel %esi, %r13d
addq $0x18, %rdx
decq %rcx
jne 0xa6980
testl %r13d, %r13d
sete %cl
cmpl $0x2, %eax
sete %r13b
jmp 0xa69a5
movb $0x1, %cl
testb %cl, %cl
jne 0xa6af3
xorl %eax, %eax
testb %r13b, %r13b
je 0xa6b1d
movl 0x8(%r15), %r14d
movl 0x20(%r15), %r15d
cmpl %r15d, %r14d
je 0xa6b1d
movq 0x28(%rbx), %rcx
cmpl $0x2, (%rcx,%r12,8)
jne 0xa6b1d
movq %r14, %rdx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rsi
cmpl $0x2, %esi
jne 0xa6b1d
movq %r15, %rdx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rdx
cmpl $0x2, %edx
jne 0xa6b1d
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 0xa6b1d
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%r8,%rdx,8), %esi
movl 0x20(%r8,%rdx,8), %r8d
cmpl %r8d, %esi
je 0xa6b1d
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 0xa6b1d
movl %edx, %esi
cmpl $0x2, (%rcx,%rsi,8)
jne 0xa6b1d
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 0xa3e8c
movl %eax, %ebp
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xa3e8c
testl %ebp, %ebp
je 0xa6afd
testl %eax, %eax
je 0xa6afd
movq 0x1e494a(%rip), %rax    # 0x28b420
cmpq %rax, 0x8(%rsp)
setg %cl
cmpq %rax, (%rsp)
setg %al
andb %cl, %al
jmp 0xa6b1a
callq 0x10064
jmp 0xa693a
callq 0x10080
jmp 0xa69ad
testl %ebp, %ebp
je 0xa6b08
movq 0x8(%rsp), %rax
jmp 0xa6b10
testl %eax, %eax
je 0xa6b2c
movq (%rsp), %rax
cmpq 0x1e4909(%rip), %rax    # 0x28b420
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 0xa6b1a