// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_cross(asg_t*, unsigned int*, unsigned int, unsigned int, unsigned int)
int test_cross(asg_t *g, uint32_t* nodes, uint32_t length, 
uint32_t startNode, uint32_t endNode)
{
    uint32_t a1, a2;
    uint32_t N_list[5] = {0};
    uint32_t i, v;
    int flag0, flag1;
    int n_reduced = 0;
    for (i = 0; i < length; ++i)
    {
        v = nodes[i];

        if((v>>1) == (startNode>>1) || (v>>1) == (endNode>>1))
        {
            continue;
        }

        uint32_t nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        if(nv != 2)
        {
            continue;
        }
        if(av[0].v == av[1].v)
        {
            continue;
        }
        flag0 = asg_is_single_edge(g, av[0].v, v>>1);
        flag1 = asg_is_single_edge(g, av[1].v, v>>1);

        if(flag0 != 2 || flag1 != 2)
        {
            continue;
        }
        

        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 )
        {
            continue;
        }

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

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


        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;
        }
        else
        {
            fprintf(stderr, "ERROR at %s:%d\n", __FILE__, __LINE__);
        }
        
        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;
        }
        else
        {
            fprintf(stderr, "ERROR at %s:%d\n", __FILE__, __LINE__);
        }

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

        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)
        {
            continue;
        }
        /**
        N_list[3]        N_list[0]

        N_list[2]        N_list[1]
        **/
       if(asg_arc_a(g, N_list[0])[0].el == asg_arc_a(g, N_list[0])[1].el)
       {
           continue;
       }

       if(asg_arc_a(g, N_list[0])[0].el == 1)
       {
           //a1 = asg_arc_a(g, N_list[0])[0].v >> 1;
           a1 = 0;
       }
       else
       {
           ///a1 = asg_arc_a(g, N_list[0])[1].v >> 1;
           a1 = 1;
       }





       
       if(asg_arc_a(g, N_list[3])[0].el == asg_arc_a(g, N_list[3])[1].el)
       {
           continue;
       }

       if(asg_arc_a(g, N_list[3])[0].el == 1)
       {
           //a2 = asg_arc_a(g, N_list[3])[0].v >> 1;
           a2 = 0;
       }
       else
       {
           //a2 = asg_arc_a(g, N_list[3])[1].v >> 1;
           a2 = 1;
       }

        if(
            (asg_arc_a(g, N_list[0])[a1].v >> 1)
            !=
            (asg_arc_a(g, N_list[3])[a2].v >> 1)
           )
        {
            if(((N_list[0]>>1) != (endNode>>1)) &&
               ((N_list[1]>>1) != (endNode>>1)) && 
               ((N_list[2]>>1) != (endNode>>1)) &&
               ((N_list[3]>>1) != (endNode>>1)))
            {
                asg_arc_a(g, N_list[0])[a1].del = 1;
                asg_arc_del(g, asg_arc_a(g, N_list[0])[a1].v^1, 
                asg_arc_a(g, N_list[0])[a1].ul>>32^1, 1);


                asg_arc_a(g, N_list[3])[a2].del = 1;
                asg_arc_del(g, asg_arc_a(g, N_list[3])[a2].v^1, 
                asg_arc_a(g, N_list[3])[a2].ul>>32^1, 1);
                n_reduced++;
            }
        }
    }

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
testl %edx, %edx
je 0xa9b9b
movl %r8d, %r11d
movl %ecx, %r10d
movq %rsi, %rbp
shrl %r10d
shrl %r11d
movl %edx, %r9d
movl $0x1, %r13d
xorl %r15d, %r15d
movl $0x0, 0x24(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movq %r9, 0x10(%rsp)
movl (%rbp,%r15,4), %r12d
movl %r12d, %r14d
shrl %r14d
cmpl %r10d, %r14d
sete %al
cmpl %r11d, %r14d
sete %cl
orb %al, %cl
jne 0xa9807
movq 0x28(%rdi), %rcx
movq (%rcx,%r12,8), %rdx
cmpl $0x2, %edx
jne 0xa9807
movq 0x8(%rdi), %rax
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r8
movl 0x8(%rax,%r8,8), %esi
movl 0x20(%rax,%r8,8), %edx
cmpl %edx, %esi
je 0xa9807
leaq (%rax,%r8,8), %rdi
movq %rdi, 0x30(%rsp)
xorq $0x1, %rsi
movq (%rcx,%rsi,8), %rbx
testl %ebx, %ebx
jle 0xa9818
movq %rbx, %rdi
shrq $0x20, %rdi
movl %ebx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %r8
addq $0x8, %r8
xorl %edi, %edi
movl (%r8), %r9d
shrl %r9d
cmpl %r14d, %r9d
cmovel %r13d, %edi
addq $0x18, %r8
decq %rsi
jne 0xa9707
testl %edi, %edi
movq 0x18(%rsp), %rdi
je 0xa981a
xorl $0x1, %edx
movq (%rcx,%rdx,8), %rbp
testl %ebp, %ebp
jle 0xa985f
movq %rbp, %rdx
shrq $0x20, %rdx
movl %ebp, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
addq $0x8, %rdx
xorl %eax, %eax
movq 0x10(%rsp), %r9
movl (%rdx), %esi
shrl %esi
cmpl %r14d, %esi
cmovel %r13d, %eax
addq $0x18, %rdx
decq %rcx
jne 0xa975b
testl %eax, %eax
je 0xa9861
cmpl $0x2, %ebx
jne 0xa9802
cmpl $0x2, %ebp
jne 0xa9802
movq 0x28(%rdi), %rax
cmpl $0x2, (%rax,%r12,8)
movq 0x28(%rsp), %rbp
jne 0xa9807
movq 0x30(%rsp), %rcx
movl 0x8(%rcx), %r8d
movq %r8, %rbx
xorq $0x1, %rbx
movq (%rax,%rbx,8), %rdx
cmpl $0x2, %edx
jne 0xa9807
movl 0x20(%rcx), %ecx
movq %rcx, %r14
xorq $0x1, %r14
movq (%rax,%r14,8), %rax
cmpl $0x2, %eax
jne 0xa9807
movq %rcx, 0x30(%rsp)
movq 0x8(%rdi), %rcx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rsi
movl 0x8(%rcx,%rsi,8), %edx
movl 0x20(%rcx,%rsi,8), %esi
cmpl %esi, %edx
je 0xa9807
movq %r8, 0x40(%rsp)
shrq $0x20, %rax
leaq (%rax,%rax,2), %r9
movl 0x8(%rcx,%r9,8), %r8d
cmpl 0x20(%rcx,%r9,8), %r8d
jne 0xa989b
movq 0x10(%rsp), %r9
jmp 0xa9807
movq 0x28(%rsp), %rbp
incq %r15
cmpq %r9, %r15
jne 0xa9683
jmp 0xa9ba3
xorl %ebx, %ebx
movq 0x1eb7bf(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x18f8e5(%rip), %rdi    # 0x23911a
movl %r10d, %ebp
callq 0x2410
movq 0x18(%rsp), %rdi
movl %ebp, %r10d
movl 0x20(%rsp), %r11d
movq 0x30(%rsp), %rax
movl 0x20(%rax), %edx
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
jmp 0xa972a
xorl %ebp, %ebp
movq 0x1eb778(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x18f89e(%rip), %rdi    # 0x23911a
movl %r10d, %r14d
callq 0x2410
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %r14d, %r10d
movl 0x20(%rsp), %r11d
jmp 0xa9777
movl %r12d, %ebp
xorl $0x1, %ebp
cmpl %ebp, %edx
movq 0x10(%rsp), %r9
jne 0xa98b3
xorl $0x1, %esi
movl %esi, 0xc(%rsp)
jmp 0xa98c2
cmpl %ebp, %esi
jne 0xa9955
xorl $0x1, %edx
movl %edx, 0xc(%rsp)
leaq (%rax,%rax,2), %rdx
movl 0x8(%rcx,%rdx,8), %eax
movl 0x20(%rcx,%rdx,8), %ecx
cmpl %ebp, %eax
jne 0xa98d7
xorl $0x1, %ecx
jmp 0xa98e4
cmpl %ebp, %ecx
jne 0xa99a4
xorl $0x1, %eax
movl %eax, %ecx
movl %ecx, 0x8(%rsp)
cmpl %ecx, 0xc(%rsp)
movq 0x28(%rsp), %rbp
jne 0xa9807
movq 0x28(%rdi), %rcx
movq (%rcx,%r12,8), %rdx
cmpl $0x2, %edx
jne 0xa993e
cmpl $0x2, (%rcx,%rbx,8)
jne 0xa993e
cmpl $0x2, (%rcx,%r14,8)
jne 0xa993e
movl 0xc(%rsp), %r8d
movl %r8d, %eax
movq (%rcx,%rax,8), %rsi
cmpl $0x2, %esi
jne 0xa994b
movq 0x8(%rdi), %rcx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r14
movb 0x12(%rcx,%r14,8), %r8b
cmpb 0x2a(%rcx,%r14,8), %r8b
jne 0xa99c7
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
jmp 0xa9807
movl %r8d, 0x8(%rsp)
jmp 0xa9807
movq 0x1eb684(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x18bf10(%rip), %rsi    # 0x235876
leaq 0x18c524(%rip), %rdx    # 0x235e91
movl $0x145a, %ecx           # imm = 0x145A
xorl %eax, %eax
movl %r10d, 0x3c(%rsp)
callq 0x22b0
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %rdi
movl 0x3c(%rsp), %r10d
movl 0x20(%rsp), %r11d
movq 0x8(%rdi), %rcx
movq 0x28(%rdi), %rax
movl 0x4(%rax,%r14,8), %eax
jmp 0xa98c2
movl %r10d, %ebp
callq 0x1006b
movq 0x10(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %ebp, %r10d
movl 0x20(%rsp), %r11d
movl 0x8(%rsp), %ecx
jmp 0xa98e4
movl %r10d, %ebx
xorl %edx, %edx
cmpb $0x1, %r8b
setne %r9b
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r10
movb 0x12(%rcx,%r10,8), %r8b
cmpb 0x2a(%rcx,%r10,8), %r8b
jne 0xa99fd
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movl %ebx, %r10d
movq 0x18(%rsp), %rdi
jmp 0xa97fb
leaq (%rcx,%r14,8), %rsi
movb %r9b, %dl
leaq (%rcx,%r10,8), %rdi
xorl %ecx, %ecx
cmpb $0x1, %r8b
setne %cl
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rcx,2), %r8
movl 0x8(%rdi,%r8,8), %edi
xorl 0x8(%rsi,%rdx,8), %edi
cmpl $0x2, %edi
jb 0xa99e8
movq 0x40(%rsp), %rdi
shrl %edi
cmpl %r11d, %edi
movq 0x18(%rsp), %rdi
je 0xa9b8e
movq 0x30(%rsp), %r8
shrl %r8d
cmpl %r11d, %r8d
movl 0xc(%rsp), %r9d
je 0xa9ae7
movl %r9d, %r8d
shrl %r8d
cmpl %r11d, %r8d
je 0xa9ae7
leaq (%rsi,%rdx,8), %rsi
orb $-0x80, 0xf(%rsi)
movq 0x8(%rdi), %rsi
movq 0x28(%rdi), %r14
movl 0x4(%r14,%r12,8), %r8d
leaq (%r8,%r8,2), %r8
leaq (%rsi,%r8,8), %r9
movl 0x8(%r9,%rdx,8), %r8d
xorq $0x1, %r8
movq (%r14,%r8,8), %r8
movq %r8, %r10
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %r10
je 0xa9af4
movl 0x4(%r9,%rdx,8), %edx
shrq $0x20, %r8
shlq $0x3, %r10
leaq (%r10,%r10,2), %rdi
leaq (%r8,%r8,2), %r8
leaq (%rsi,%r8,8), %rsi
addq $0xc, %rsi
xorl %r8d, %r8d
movl -0x4(%rsi,%r8), %r9d
xorl %edx, %r9d
cmpl $0x1, %r9d
jne 0xa9acc
orb $-0x80, 0x3(%rsi,%r8)
addq $0x18, %r8
cmpq %r8, %rdi
jne 0xa9ab8
movq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x28(%rdi), %r14
movl %ebx, %r10d
jmp 0xa9afc
movl %r9d, 0x8(%rsp)
movl %ebx, %r10d
jmp 0xa97fb
movl %ebx, %r10d
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r9
movl 0x4(%r14,%rax,8), %edx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rsi
shll $0x3, %ecx
leaq (%rcx,%rcx,2), %rdx
orl $0x80000000, 0xc(%rsi,%rdx) # imm = 0x80000000
movq 0x8(%rdi), %rcx
movq 0x28(%rdi), %rsi
movl 0x4(%rsi,%rax,8), %eax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
movl 0x8(%rax,%rdx), %r8d
xorq $0x1, %r8
movq (%rsi,%r8,8), %rsi
movq %rsi, %r8
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
andq %rbx, %r8
je 0xa9b85
movl 0x4(%rax,%rdx), %eax
shrq $0x20, %rsi
shlq $0x3, %r8
leaq (%r8,%r8,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %rcx
addq $0xc, %rcx
xorl %esi, %esi
movl -0x4(%rcx,%rsi), %r8d
xorl %eax, %r8d
cmpl $0x1, %r8d
jne 0xa9b7c
orb $-0x80, 0x3(%rcx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0xa9b69
incl 0x24(%rsp)
jmp 0xa993e
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
jmp 0xa9aec
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq