// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_quadangular_with_addition_node(asg_t*, unsigned int*, unsigned int, unsigned int)
int test_quadangular_with_addition_node(asg_t *g, uint32_t* nodes, uint32_t length, 
uint32_t addition_node_length)
{
    
    uint32_t i, v, w;
    int flag, occ_v_0, occ_v_1, occ_w_0, occ_w_1;
    int n_reduced = 0;
    uint32_t v_out2_node, w_out2_node;
    uint32_t cut_edge_v, cut_edge_w;
    for (i = 0; i < length; ++i)
    {
        v = nodes[i];
        uint32_t nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        if(nv != 1)
        {
            continue;
        }
        /**********************test first node************************/
        flag = asg_is_single_edge(g, av[0].v, v>>1);
        if(flag != 2)
        {
            continue;
        }
       /**********************test first node************************/

        if(!find_single_link(g, v, addition_node_length, &w))
        {
            continue;
        }
        v = av[0].v^1;
        ///up to now, v and w is the node what we want
        asg_arc_t *aw = asg_arc_a(g, w);
        uint32_t nw = asg_arc_n(g, w);
        nv = asg_arc_n(g, v);
        av = asg_arc_a(g, v);
        if(nv!=2 || nw != 2)
        {
            fprintf(stderr, "error\n");
        }

        if(!if_node_exist(nodes, length, (v>>1)))
        {
            continue;
        }
        if(!if_node_exist(nodes, length, (w>>1)))
        {
            continue;
        }
        /**********************for v************************/
        occ_v_0 = asg_is_single_edge(g, av[0].v, v>>1);
        occ_v_1 = asg_is_single_edge(g, av[1].v, v>>1);
        if(occ_v_0 == occ_v_1)
        {
            continue;
        }
        if(occ_v_0 < 1 || occ_v_0 > 2)
        {
            continue;
        }
        if(occ_v_1 < 1 || occ_v_1 > 2)
        {
            continue;
        }

        if(occ_v_0 == 2)
        {
            v_out2_node = av[0].v^1;
            cut_edge_v = 0;
        }
        else
        {
            v_out2_node = av[1].v^1;
            cut_edge_v = 1;
        }
        if(!if_node_exist(nodes, length, (v_out2_node>>1)))
        {
            continue;
        }
        /**********************for v************************/

        /**********************for w************************/
        occ_w_0 = asg_is_single_edge(g, aw[0].v, w>>1);
        occ_w_1 = asg_is_single_edge(g, aw[1].v, w>>1);
        if(occ_w_0 == occ_w_1)
        {
            continue;
        }
        if(occ_w_0 < 1 || occ_w_0 > 2)
        {
            continue;
        }
        if(occ_w_1 < 1 || occ_w_1 > 2)
        {
            continue;
        }

        if(occ_w_0 == 2)
        {
            w_out2_node = aw[0].v^1;
            cut_edge_w = 0;
        }
        else
        {
            w_out2_node = aw[1].v^1;
            cut_edge_w = 1;
        }
        if(!if_node_exist(nodes, length, (w_out2_node>>1)))
        {
            continue;
        }
        /**********************for w************************/

        
        if(!if_edge_exist(asg_arc_a(g, w_out2_node), asg_arc_n(g, w_out2_node), (v_out2_node>>1)))
        {
            continue;
        }

        if(!if_edge_exist(asg_arc_a(g, v_out2_node), asg_arc_n(g, v_out2_node), (w_out2_node>>1)))
        {
            continue;
        }


        av[cut_edge_v].del = 1;
        ///remove the reverse direction
        asg_arc_del(g, av[cut_edge_v].v^1, av[cut_edge_v].ul>>32^1, 1);

        aw[cut_edge_w].del = 1;
        ///remove the reverse direction
        asg_arc_del(g, aw[cut_edge_w].v^1, aw[cut_edge_w].ul>>32^1, 1);


        n_reduced++;
    }

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, 0x30(%rsp)
testl %edx, %edx
je 0xa6a1a
movq %rsi, %r11
movl %edx, %r10d
xorl %r13d, %r13d
movl $0x1, %ebx
movl $0x0, 0x24(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %r10, 0x8(%rsp)
movl (%r11,%r13,4), %r12d
movq 0x28(%rdi), %rax
movq (%rax,%r12,8), %rcx
cmpl $0x1, %ecx
jne 0xa6a0c
movq 0x8(%rdi), %r15
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rbp
movl 0x8(%r15,%rbp,8), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %r14
testl %r14d, %r14d
jle 0xa660d
movq %r14, %rcx
shrq $0x20, %rcx
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rcx,%rcx,2), %rcx
leaq (%r15,%rcx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
xorl %r12d, %esi
cmpl $0x2, %esi
cmovbl %ebx, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa6409
testl %ecx, %ecx
je 0xa6610
cmpl $0x2, %r14d
jne 0xa6a0c
movl %r12d, %esi
movl 0x30(%rsp), %edx
leaq 0x34(%rsp), %rcx
movq %rdi, %r14
callq 0xa62ee
testl %eax, %eax
je 0xa64cf
leaq (%r15,%rbp,8), %rax
addq $0x8, %rax
movl (%rax), %r15d
movq %r15, %rax
xorq $0x1, %rax
movq 0x8(%r14), %r8
movq 0x28(%r14), %rcx
movl 0x34(%rsp), %edx
movq (%rcx,%rdx,8), %r12
movq (%rcx,%rax,8), %rbp
cmpl $0x2, %ebp
movq 0x18(%rsp), %r11
movq 0x8(%rsp), %r10
jne 0xa675e
movq %r14, %rdi
movl %r12d, %eax
cmpl $0x2, %eax
jne 0xa675e
shrq $0x20, %r12
leaq (%r12,%r12,2), %rax
leaq (%r8,%rax,8), %rsi
shrq $0x20, %rbp
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq (%r8,%rax,8), %r12
shrl %r15d
xorl %eax, %eax
movl (%r11,%rax,4), %ecx
shrl %ecx
cmpl %r15d, %ecx
je 0xa64e1
incq %rax
cmpq %rax, %r10
jne 0xa64b7
jmp 0xa6a0c
movq 0x18(%rsp), %r11
movq %r14, %rdi
movq 0x8(%rsp), %r10
jmp 0xa6a0c
shrl %edx
xorl %eax, %eax
movl (%r11,%rax,4), %ecx
shrl %ecx
cmpl %edx, %ecx
je 0xa64fc
incq %rax
cmpq %rax, %r10
jne 0xa64e5
jmp 0xa6a0c
movq %rsi, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
movl 0x8(%r12), %eax
movq 0x28(%rdi), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rdx
testl %edx, %edx
jle 0xa67e1
movq 0x8(%rdi), %rax
movq %rdx, %rsi
shrq $0x20, %rsi
movq %rdx, %r14
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %r9
addq $0x8, %r9
xorl %esi, %esi
movl (%r9), %r8d
shrl %r8d
cmpl %r15d, %r8d
cmovel %ebx, %esi
addq $0x18, %r9
decq %rdx
jne 0xa6541
testl %esi, %esi
je 0xa67e4
movl 0x20(%r12), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rbp
testl %ebp, %ebp
jle 0xa6820
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
movl (%rdx), %esi
shrl %esi
cmpl %r15d, %esi
cmovel %ebx, %eax
addq $0x18, %rdx
decq %rcx
jne 0xa6590
testl %eax, %eax
movq %r14, %rsi
je 0xa6822
leal -0x3(%rsi), %eax
cmpl $-0x2, %eax
jb 0xa6a0c
cmpl %ebp, %esi
je 0xa6a0c
addl $-0x3, %ebp
cmpl $-0x2, %ebp
jb 0xa6a0c
leaq 0x8(%r12), %rax
leaq 0x20(%r12), %rcx
xorl %edx, %edx
cmpl $0x2, %esi
setne %dl
cmovneq %rcx, %rax
movl (%rax), %esi
movq %rsi, %r8
xorq $0x1, %r8
shrl %esi
xorl %eax, %eax
movq 0x28(%rsp), %r14
movl (%r11,%rax,4), %ecx
shrl %ecx
cmpl %esi, %ecx
je 0xa6644
incq %rax
cmpq %rax, %r10
jne 0xa65f6
jmp 0xa6a0c
xorl %r14d, %r14d
movq 0x1ee9c9(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x192aef(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
jmp 0xa6425
movq %r8, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x40(%rsp)
movl 0x8(%r14), %eax
movq 0x28(%rdi), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r15
testl %r15d, %r15d
jle 0xa68bd
movq 0x8(%rdi), %rax
movq %r15, %rsi
shrq $0x20, %rsi
movl %r15d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %r9
addq $0x8, %r9
xorl %esi, %esi
movq 0x38(%rsp), %rbp
movl (%r9), %r8d
shrl %r8d
cmpl %ebp, %r8d
cmovel %ebx, %esi
addq $0x18, %r9
decq %rdx
jne 0xa6693
testl %esi, %esi
je 0xa68c0
movl 0x20(%r14), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rbp
testl %ebp, %ebp
jle 0xa68fc
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 0x38(%rsp), %r8
movl (%rdx), %esi
shrl %esi
cmpl %r8d, %esi
cmovel %ebx, %eax
addq $0x18, %rdx
decq %rcx
jne 0xa66e6
testl %eax, %eax
je 0xa68fe
leal -0x3(%r15), %eax
cmpl $-0x2, %eax
jb 0xa6a0c
cmpl %ebp, %r15d
je 0xa6a0c
addl $-0x3, %ebp
cmpl $-0x2, %ebp
jb 0xa6a0c
leaq 0x8(%r14), %rcx
leaq 0x20(%r14), %rdx
xorl %eax, %eax
cmpl $0x2, %r15d
setne %al
cmovneq %rdx, %rcx
movl (%rcx), %edx
movl %edx, %ecx
shrl %ecx
xorl %esi, %esi
movq 0x50(%rsp), %r15
movl (%r11,%rsi,4), %r8d
shrl %r8d
cmpl %ecx, %r8d
je 0xa6787
incq %rsi
cmpq %rsi, %r10
jne 0xa6745
jmp 0xa6a0c
movq %rdx, %r14
movq %r8, 0x28(%rsp)
callq 0xfffb
movq 0x28(%rsp), %r8
movq %r14, %rdx
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
jmp 0xa6493
xorq $0x1, %rdx
movq 0x28(%rdi), %rsi
movq (%rsi,%rdx,8), %r8
movq %r8, %r9
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %r9
je 0xa6a0c
movq 0x8(%rdi), %rdx
shrq $0x20, %r8
shlq $0x3, %r9
leaq (%r9,%r9,2), %rdi
leaq (%r8,%r8,2), %r8
leaq (%rdx,%r8,8), %r8
addq $0x8, %r8
xorl %r9d, %r9d
movl (%r8,%r9), %r10d
shrl %r10d
cmpl %r15d, %r10d
je 0xa6859
addq $0x18, %r9
cmpq %r9, %rdi
jne 0xa67c3
jmp 0xa68b3
xorl %r14d, %r14d
movq 0x1ee7f5(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x19291b(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
jmp 0xa655e
xorl %ebp, %ebp
movq 0x1ee7b7(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x1928dd(%rip), %rdi    # 0x23911a
callq 0x2410
movq %r14, %rsi
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
jmp 0xa65ae
movq 0x48(%rsp), %rdi
movq (%rsi,%rdi,8), %rdi
movq %rdi, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0xa68b3
shrq $0x20, %rdi
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%rdx,%rdi,8), %rdx
addq $0x8, %rdx
xorl %r9d, %r9d
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r10
movl (%rdx,%r9), %r8d
shrl %r8d
cmpl %ecx, %r8d
je 0xa6932
addq $0x18, %r9
cmpq %r9, %rsi
jne 0xa6895
jmp 0xa6a0c
movq 0x10(%rsp), %rdi
jmp 0xa64d7
xorl %r15d, %r15d
movq 0x1ee719(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x19283f(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
jmp 0xa66b0
xorl %ebp, %ebp
movq 0x1ee6db(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x192801(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
jmp 0xa6701
movq 0x40(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
orb $-0x80, 0xf(%r12,%rcx,8)
movl 0x8(%r12,%rcx,8), %edx
xorq $0x1, %rdx
movq 0x28(%rdi), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rdx
je 0xa69a1
movl 0x4(%r12,%rcx,8), %ecx
movq 0x8(%rdi), %r8
shrq $0x20, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
addq $0xc, %rsi
xorl %r9d, %r9d
movl -0x4(%rsi,%r9), %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
jne 0xa6998
orb $-0x80, 0x3(%rsi,%r9)
addq $0x18, %r9
cmpq %r9, %rdx
jne 0xa6984
leaq (%rax,%rax,2), %rax
orb $-0x80, 0xf(%r14,%rax,8)
movl 0x8(%r14,%rax,8), %ecx
xorq $0x1, %rcx
movq 0x28(%rdi), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa6a08
movl 0x4(%r14,%rax,8), %eax
movq 0x8(%rdi), %rsi
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
movl -0x4(%rdx,%rsi), %r8d
xorl %eax, %r8d
cmpl $0x1, %r8d
jne 0xa69ff
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xa69ec
incl 0x24(%rsp)
incq %r13
cmpq %r10, %r13
jne 0xa63b5
jmp 0xa6a22
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq