// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x2100
movl $0x0, -0x54(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0xda4ad
movq -0x10(%rbp), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
shrl %eax
movl -0x18(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xd9d8d
movl -0x48(%rbp), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0xd9d92
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x48(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x48(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
cmpl $0x2, -0x58(%rbp)
je 0xd9dd5
jmp 0xda49f
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0xd9dea
jmp 0xda49f
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x48(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x48(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x50(%rbp)
cmpl $0x2, -0x4c(%rbp)
jne 0xd9e26
cmpl $0x2, -0x50(%rbp)
je 0xd9e2b
jmp 0xda49f
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x60(%rbp), %rax
movl 0x20(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
jne 0xd9e87
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
jne 0xd9e87
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
je 0xd9e8c
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x3c(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jne 0xd9edd
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x38(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jne 0xd9f2e
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xd9f8d
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xda00f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xd9fe9
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xda00d
movq 0x2e9ff0(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2ac444(%rip), %rsi    # 0x38643e
leaq 0x2ac8bc(%rip), %rdx    # 0x3868bd
movl $0x145a, %ecx           # imm = 0x145A
movb $0x0, %al
callq 0x22a0
jmp 0xda00f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xda06e
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xda0f0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0xda0ca
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xda0ee
movq 0x2e9f0f(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2ac363(%rip), %rsi    # 0x38643e
leaq 0x2ac7db(%rip), %rdx    # 0x3868bd
movl $0x1467, %ecx           # imm = 0x1467
movb $0x0, %al
callq 0x22a0
jmp 0xda0f0
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0xda0fd
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
jne 0xda14d
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
jne 0xda14d
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
jne 0xda14d
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x2, %eax
je 0xda152
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x40(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x2a(%rcx), %ecx
cmpl %ecx, %eax
jne 0xda1a7
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0xda1db
movl $0x0, -0x20(%rbp)
jmp 0xda1e2
movl $0x1, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x34(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x2a(%rcx), %ecx
cmpl %ecx, %eax
jne 0xda237
jmp 0xda49f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0xda26b
movl $0x0, -0x24(%rbp)
jmp 0xda272
movl $0x1, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x34(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl -0x24(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xda49d
movl -0x40(%rbp), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xda49b
movl -0x3c(%rbp), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xda49b
movl -0x38(%rbp), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xda49b
movl -0x34(%rbp), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0xda49b
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0xd6530
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0xd6530
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xda49d
jmp 0xda49f
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xd9d58
movl -0x54(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)