// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rsi, %r11
movq %rdi, %r15
shrl %ecx
shrl %r8d
movl %edx, %r9d
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
xorl %edi, %edi
movl $0x0, 0x28(%rsp)
movl %r8d, 0x18(%rsp)
movl %ecx, 0x14(%rsp)
movq %rsi, 0x20(%rsp)
movq %r9, 0x8(%rsp)
cmpq %r14, %r9
je 0x7009a
movl (%r11,%r14,4), %ebx
movl %ebx, %r12d
shrl %r12d
cmpl %ecx, %r12d
sete %al
cmpl %r8d, %r12d
sete %dl
orb %al, %dl
jne 0x6fe5e
movq 0x28(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpl $0x2, %eax
jne 0x6fe5e
movq 0x8(%r15), %rbp
shrq $0x20, %rax
imulq $0x18, %rax, %rax
movl 0x8(%rbp,%rax), %esi
cmpl 0x20(%rbp,%rax), %esi
je 0x6fe5e
movl %edi, 0x1c(%rsp)
addq %rax, %rbp
movq %r15, %rdi
movl %r12d, %edx
callq 0x6c8a1
movl %eax, %r13d
movl 0x20(%rbp), %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x6c8a1
cmpl $0x2, %r13d
jne 0x6fe47
cmpl $0x2, %eax
movl 0x18(%rsp), %r8d
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %r11
movq 0x8(%rsp), %r9
movl 0x1c(%rsp), %edi
jne 0x6fe5e
movq 0x28(%r15), %rax
cmpl $0x2, (%rax,%rbx,8)
jne 0x6fe5e
movl 0x8(%rbp), %esi
movq %rsi, %r12
xorq $0x1, %r12
movq (%rax,%r12,8), %rdx
cmpl $0x2, %edx
jne 0x6fe5e
movl 0x20(%rbp), %r10d
movq %r10, %r13
xorq $0x1, %r13
movq (%rax,%r13,8), %rax
cmpl $0x2, %eax
jne 0x6fe5e
movq %r10, 0x30(%rsp)
movq %rsi, %rbp
movq 0x8(%r15), %r10
shrq $0x20, %rdx
imulq $0x18, %rdx, %rsi
movl 0x8(%r10,%rsi), %edx
movl 0x20(%r10,%rsi), %esi
cmpl %esi, %edx
je 0x6fe5e
shrq $0x20, %rax
imulq $0x18, %rax, %rdi
movl 0x8(%r10,%rdi), %r9d
cmpl 0x20(%r10,%rdi), %r9d
je 0x6fe55
movl %ebx, %edi
xorl $0x1, %edi
cmpl %edi, %edx
movq 0x8(%rsp), %r9
jne 0x6fe66
xorl $0x1, %esi
movl %esi, 0x4(%rsp)
jmp 0x6fe75
movl 0x18(%rsp), %r8d
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %r11
movq 0x8(%rsp), %r9
movl 0x1c(%rsp), %edi
incq %r14
jmp 0x6fd26
cmpl %edi, %esi
jne 0x6fef1
xorl $0x1, %edx
movl %edx, 0x4(%rsp)
imulq $0x18, %rax, %rdx
movl 0x8(%r10,%rdx), %eax
movl 0x20(%r10,%rdx), %edx
cmpl %edi, %eax
jne 0x6fe8e
xorl $0x1, %edx
movl %edx, %edi
jmp 0x6fe9b
cmpl %edi, %edx
jne 0x6ff42
xorl $0x1, %eax
movl %eax, %edi
cmpl %edi, 0x4(%rsp)
jne 0x6fe5e
movq 0x28(%r15), %rdx
movq (%rdx,%rbx,8), %rax
cmpl $0x2, %eax
jne 0x6fee8
cmpl $0x2, (%rdx,%r12,8)
jne 0x6fee8
cmpl $0x2, (%rdx,%r13,8)
jne 0x6fee8
movl 0x4(%rsp), %edi
movl %edi, %r12d
movq (%rdx,%r12,8), %rsi
cmpl $0x2, %esi
jne 0x6fe5e
movq 0x8(%r15), %r10
shrq $0x20, %rax
imulq $0x18, %rax, %rax
movb 0x12(%r10,%rax), %dil
cmpb 0x2a(%r10,%rax), %dil
jne 0x6ff82
movl 0x4(%rsp), %edi
jmp 0x6fe5e
movq 0x1e30e8(%rip), %rax    # 0x252fe0
movl %edi, 0x2c(%rsp)
movq (%rax), %rdi
leaq 0x1778c0(%rip), %rsi    # 0x1e77c6
leaq 0x177e84(%rip), %rdx    # 0x1e7d91
movl $0x145a, %ecx           # imm = 0x145A
xorl %eax, %eax
callq 0x22b0
movl 0x2c(%rsp), %edi
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %r11
movl 0x14(%rsp), %ecx
movl 0x18(%rsp), %r8d
movq 0x8(%r15), %r10
movq 0x28(%r15), %rax
movl 0x4(%rax,%r13,8), %eax
jmp 0x6fe75
movq 0x1e3097(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x177873(%rip), %rsi    # 0x1e77c6
leaq 0x177e37(%rip), %rdx    # 0x1e7d91
movl $0x1467, %ecx           # imm = 0x1467
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %r11
movl 0x14(%rsp), %ecx
movl 0x18(%rsp), %r8d
movl 0x1c(%rsp), %edi
jmp 0x6fe9b
xorl %edx, %edx
cmpb $0x1, %dil
setne %r9b
shrq $0x20, %rsi
imulq $0x18, %rsi, %rsi
movb 0x12(%r10,%rsi), %dil
cmpb 0x2a(%r10,%rsi), %dil
jne 0x6ffa9
movl 0x4(%rsp), %edi
jmp 0x70090
addq %r10, %rax
movb %r9b, %dl
addq %r10, %rsi
xorl %r9d, %r9d
cmpb $0x1, %dil
setne %r9b
imulq $0x18, %rdx, %rdi
imulq $0x18, %r9, %r13
movl 0x8(%rsi,%r13), %edx
xorl 0x8(%rax,%rdi), %edx
cmpl $0x2, %edx
jb 0x6ffa0
shrl %ebp
cmpl %r8d, %ebp
je 0x6ffa0
movq 0x30(%rsp), %rdx
shrl %edx
cmpl %r8d, %edx
movl 0x4(%rsp), %r9d
je 0x7008d
movl %r9d, %edx
shrl %edx
cmpl %r8d, %edx
je 0x7008d
addq %rdi, %rax
orb $-0x80, 0xf(%rax)
movq 0x28(%r15), %rax
movl 0x4(%rax,%rbx,8), %eax
imulq $0x18, %rax, %rax
addq 0x8(%r15), %rax
movl 0x4(%rdi,%rax), %edx
movl 0x8(%rdi,%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
pushq $0x1
popq %rbx
movl %ebx, %ecx
movl %r9d, %ebp
callq 0x6db50
movq 0x28(%r15), %rax
movl 0x4(%rax,%r12,8), %eax
imulq $0x18, %rax, %rax
addq 0x8(%r15), %rax
orl $0x80000000, 0xc(%r13,%rax) # imm = 0x80000000
movq 0x28(%r15), %rax
movl 0x4(%rax,%r12,8), %eax
imulq $0x18, %rax, %rax
addq 0x8(%r15), %rax
movl 0x4(%r13,%rax), %edx
movl 0x8(%r13,%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
movl %ebx, %ecx
callq 0x6db50
movq 0x20(%rsp), %r11
movl 0x14(%rsp), %ecx
movl 0x18(%rsp), %r8d
incl 0x28(%rsp)
movl %ebp, %edi
jmp 0x70090
movl %r9d, %edi
movq 0x8(%rsp), %r9
jmp 0x6fe5e
movl 0x28(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq