// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, 0x40(%rsp)
testl %edx, %edx
je 0xa8b34
movl %ecx, %r10d
shrl %r10d
shrl %r8d
movl %edx, %r9d
xorl %r12d, %r12d
movl $0x1, %r13d
movl $0x0, 0x2c(%rsp)
xorl %esi, %esi
movl $0x0, 0x28(%rsp)
movq %r9, 0x18(%rsp)
movq 0x40(%rsp), %rax
movl (%rax,%r12,4), %r14d
movl %r14d, %r15d
shrl %r15d
cmpl %r10d, %r15d
sete %al
cmpl %r8d, %r15d
sete %cl
orb %al, %cl
jne 0xa8831
movq 0x28(%rdi), %rax
movq (%rax,%r14,8), %rcx
cmpl $0x2, %ecx
jne 0xa8831
movq 0x8(%rdi), %rbp
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rbx
movl 0x8(%rbp,%rbx,8), %ecx
cmpl 0x20(%rbp,%rbx,8), %ecx
je 0xa8831
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
movl %esi, 0x24(%rsp)
jle 0xa873f
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq 0x8(,%rdx,8), %rsi
addq %rbp, %rsi
xorl %edx, %edx
movl (%rsi), %r9d
shrl %r9d
cmpl %r15d, %r9d
cmovel %r13d, %edx
addq $0x18, %rsi
decq %rcx
jne 0xa8712
testl %edx, %edx
sete %cl
cmpl $0x2, %eax
setne %r11b
movq 0x18(%rsp), %r9
movl 0x24(%rsp), %esi
jmp 0xa8744
movb $0x1, %r11b
movb $0x1, %cl
testb %cl, %cl
jne 0xa8842
leaq (%rbp,%rbx,8), %rbp
movl 0x20(%rbp), %eax
movq 0x28(%rdi), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
jle 0xa87b1
movq 0x8(%rdi), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl (%rsi), %r9d
shrl %r9d
cmpl %r15d, %r9d
cmovel %r13d, %edx
addq $0x18, %rsi
decq %rcx
jne 0xa8785
testl %edx, %edx
sete %cl
cmpl $0x2, %eax
setne %bl
movq 0x18(%rsp), %r9
movl 0x24(%rsp), %esi
jmp 0xa87b5
movb $0x1, %bl
movb $0x1, %cl
testb %cl, %cl
jne 0xa887d
orb %bl, %r11b
jne 0xa8831
movq 0x28(%rdi), %rax
cmpl $0x2, (%rax,%r14,8)
jne 0xa8831
movl 0x8(%rbp), %ebx
movq %rbx, %r15
xorq $0x1, %r15
movq (%rax,%r15,8), %rcx
cmpl $0x2, %ecx
jne 0xa8831
movl 0x20(%rbp), %ebp
movq %rbp, %rdx
xorq $0x1, %rdx
movq %rdx, 0x30(%rsp)
movq (%rax,%rdx,8), %rdx
cmpl $0x2, %edx
jne 0xa8831
movq 0x8(%rdi), %rsi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rsi,%rcx,8), %eax
movl 0x20(%rsi,%rcx,8), %ecx
cmpl %ecx, %eax
je 0xa882d
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rsi,%rdx,8), %r9d
cmpl 0x20(%rsi,%rdx,8), %r9d
jne 0xa88b4
movq 0x18(%rsp), %r9
movl 0x24(%rsp), %esi
incq %r12
cmpq %r9, %r12
jne 0xa8694
jmp 0xa8b3c
movl %r8d, 0xc(%rsp)
movl %r10d, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
movb %r11b, 0x30(%rsp)
callq 0x10208
movb 0x30(%rsp), %r11b
movl 0x24(%rsp), %esi
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdi
movl 0x20(%rsp), %r10d
movl 0xc(%rsp), %r8d
jmp 0xa874c
movl %r8d, 0xc(%rsp)
movl %r10d, %r15d
movq %rdi, 0x10(%rsp)
movb %r11b, 0x30(%rsp)
callq 0x10224
movb 0x30(%rsp), %r11b
movl 0x24(%rsp), %esi
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdi
movl %r15d, %r10d
movl 0xc(%rsp), %r8d
jmp 0xa87bd
movq %rbp, 0x38(%rsp)
movq %rbx, %rbp
movl %r14d, %ebx
xorl $0x1, %ebx
cmpl %ebx, %eax
movq 0x18(%rsp), %r9
jne 0xa88d4
xorl $0x1, %ecx
movl %ecx, 0x28(%rsp)
jmp 0xa88e3
cmpl %ebx, %ecx
jne 0xa89aa
xorl $0x1, %eax
movl %eax, 0x28(%rsp)
movq 0x8(%rdi), %rcx
movq 0x28(%rdi), %rax
movq 0x30(%rsp), %rdx
movl 0x4(%rax,%rdx,8), %eax
leaq (%rax,%rax,2), %rdx
movl 0x8(%rcx,%rdx,8), %eax
movl 0x20(%rcx,%rdx,8), %ecx
cmpl %ebx, %eax
jne 0xa890b
xorl $0x1, %ecx
movl %ecx, %esi
jmp 0xa8918
cmpl %ebx, %ecx
jne 0xa89d7
xorl $0x1, %eax
movl %eax, %esi
cmpl %esi, 0x28(%rsp)
jne 0xa8831
movq 0x28(%rdi), %rcx
movq (%rcx,%r14,8), %rax
cmpl $0x2, %eax
jne 0xa8831
cmpl $0x2, (%rcx,%r15,8)
jne 0xa8831
movq 0x30(%rsp), %rdx
cmpl $0x2, (%rcx,%rdx,8)
jne 0xa8831
movl %esi, %ebx
movl 0x28(%rsp), %r15d
movq (%rcx,%r15,8), %rsi
cmpl $0x2, %esi
jne 0xa8b2d
movq 0x8(%rdi), %rcx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
movb 0x12(%rcx,%rax,8), %r9b
cmpb 0x2a(%rcx,%rax,8), %r9b
je 0xa8b28
movq %rdi, 0x10(%rsp)
xorl %edx, %edx
cmpb $0x1, %r9b
setne %dil
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r9
movb 0x12(%rcx,%r9,8), %sil
cmpb 0x2a(%rcx,%r9,8), %sil
jne 0xa8a04
movq 0x10(%rsp), %rdi
jmp 0xa8b28
movl %r8d, 0xc(%rsp)
movl %r10d, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
callq 0x10240
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdi
movl 0x20(%rsp), %r10d
movl 0xc(%rsp), %r8d
jmp 0xa88e3
movl %r8d, 0xc(%rsp)
movl %r10d, 0x20(%rsp)
movq %rdi, %rbx
callq 0x10264
movq 0x18(%rsp), %r9
movq %rbx, %rdi
movl 0x20(%rsp), %r10d
movl 0xc(%rsp), %r8d
movl 0x24(%rsp), %esi
jmp 0xa8918
leaq (%rcx,%rax,8), %rax
movb %dil, %dl
leaq (%rcx,%r9,8), %rdi
xorl %r9d, %r9d
cmpb $0x1, %sil
setne %r9b
leaq (%rdx,%rdx,2), %rcx
leaq (%r9,%r9,2), %rdx
movl 0x8(%rdi,%rdx,8), %edx
xorl 0x8(%rax,%rcx,8), %edx
cmpl $0x2, %edx
jb 0xa89a0
shrl %ebp
cmpl %r8d, %ebp
movq 0x10(%rsp), %rdi
je 0xa8b28
movq 0x38(%rsp), %rdx
shrl %edx
cmpl %r8d, %edx
je 0xa8b28
movl 0x28(%rsp), %edx
shrl %edx
cmpl %r8d, %edx
je 0xa8b28
movq %r9, %rbp
leaq (%rax,%rcx,8), %rax
orb $-0x80, 0xf(%rax)
movq 0x28(%rdi), %rax
movl 0x4(%rax,%r14,8), %eax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x8(%rdi), %rax
movl 0x4(%rax,%rcx,8), %edx
movl 0x8(%rax,%rcx,8), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movl $0x1, %ecx
movl %r8d, 0xc(%rsp)
movl %r10d, 0x20(%rsp)
callq 0xa5255
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movl 0x4(%rax,%r15,8), %eax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
movq 0x10(%rsp), %rcx
addq 0x8(%rcx), %rax
shll $0x3, %ebp
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
orl $0x80000000, 0xc(%rax,%rcx) # imm = 0x80000000
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movl 0x4(%rax,%r15,8), %eax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
movq 0x10(%rsp), %rdx
addq 0x8(%rdx), %rax
movl 0x4(%rax,%rcx), %edx
movl 0x8(%rax,%rcx), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq 0x10(%rsp), %rdi
movl $0x1, %ecx
callq 0xa5255
movq 0x10(%rsp), %rdi
movl 0x20(%rsp), %r10d
movl 0xc(%rsp), %r8d
incl 0x2c(%rsp)
movq 0x18(%rsp), %r9
movl %ebx, %esi
jmp 0xa8831
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq