// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0xd6bca
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x20(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpl $0x1, -0x50(%rbp)
je 0xd6800
jmp 0xd6bbc
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x20(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
je 0xd6823
jmp 0xd6bbc
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x18(%rbp), %edx
leaq -0x24(%rbp), %rcx
callq 0xd65e0
cmpl $0x0, %eax
jne 0xd6840
jmp 0xd6bbc
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x20(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpl $0x2, -0x50(%rbp)
jne 0xd68c9
cmpl $0x2, -0x64(%rbp)
je 0xd68e1
movq 0x2ed710(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2abd0b(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x20(%rbp), %edx
shrl %edx
callq 0xd45f0
cmpl $0x0, %eax
jne 0xd68fc
jmp 0xd6bbc
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x24(%rbp), %edx
shrl %edx
callq 0xd45f0
cmpl $0x0, %eax
jne 0xd6917
jmp 0xd6bbc
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x20(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x20(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jne 0xd6954
jmp 0xd6bbc
cmpl $0x1, -0x2c(%rbp)
jl 0xd6960
cmpl $0x2, -0x2c(%rbp)
jle 0xd6965
jmp 0xd6bbc
cmpl $0x1, -0x30(%rbp)
jl 0xd6971
cmpl $0x2, -0x30(%rbp)
jle 0xd6976
jmp 0xd6bbc
cmpl $0x2, -0x2c(%rbp)
jne 0xd6992
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
jmp 0xd69a6
movq -0x58(%rbp), %rax
movl 0x20(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x1, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x40(%rbp), %edx
shrl %edx
callq 0xd45f0
cmpl $0x0, %eax
jne 0xd69c1
jmp 0xd6bbc
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x24(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x24(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0xd69fe
jmp 0xd6bbc
cmpl $0x1, -0x34(%rbp)
jl 0xd6a0a
cmpl $0x2, -0x34(%rbp)
jle 0xd6a0f
jmp 0xd6bbc
cmpl $0x1, -0x38(%rbp)
jl 0xd6a1b
cmpl $0x2, -0x38(%rbp)
jle 0xd6a20
jmp 0xd6bbc
cmpl $0x2, -0x34(%rbp)
jne 0xd6a3c
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x4c(%rbp)
jmp 0xd6a50
movq -0x60(%rbp), %rax
movl 0x20(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x44(%rbp), %edx
shrl %edx
callq 0xd45f0
cmpl $0x0, %eax
jne 0xd6a6b
jmp 0xd6bbc
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
movl -0x40(%rbp), %edx
shrl %edx
callq 0xd6720
cmpl $0x0, %eax
jne 0xd6ab2
jmp 0xd6bbc
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
movl -0x44(%rbp), %edx
shrl %edx
callq 0xd6720
cmpl $0x0, %eax
jne 0xd6af9
jmp 0xd6bbc
movq -0x58(%rbp), %rax
movl -0x48(%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 -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x58(%rbp), %rax
movl -0x48(%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 -0x60(%rbp), %rax
movl -0x4c(%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 -0x60(%rbp), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x60(%rbp), %rax
movl -0x4c(%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 -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd67a4
movl -0x3c(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)