// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movl %ecx, 0x50(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %r13d
xorl %ebp, %ebp
movl $0x0, 0x34(%rsp)
movl %edx, 0x1c(%rsp)
movq %rsi, 0x38(%rsp)
movq %r13, 0x10(%rsp)
cmpq %rbp, %r13
je 0x6df88
movl (%r14,%rbp,4), %r12d
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rax
cmpl $0x1, %eax
jne 0x6df58
movq 0x8(%r15), %rbx
shrq $0x20, %rax
imulq $0x18, %rax, %r13
movl 0x8(%rbx,%r13), %esi
movl %r12d, %edx
shrl %edx
movq %r15, %rdi
callq 0x6c8a1
cmpl $0x2, %eax
jne 0x6df53
movq %r15, %rdi
movl %r12d, %esi
movl 0x50(%rsp), %edx
leaq 0x54(%rsp), %rcx
callq 0x6dba8
testl %eax, %eax
je 0x6df53
leaq (%rbx,%r13), %rax
addq $0x8, %rax
movl (%rax), %r12d
movq %r12, %rax
xorq $0x1, %rax
movq 0x8(%r15), %rcx
movq %rcx, 0x20(%rsp)
movq 0x28(%r15), %rcx
movl 0x54(%rsp), %edx
movq %rdx, 0x28(%rsp)
movq (%rcx,%rdx,8), %r13
movq (%rcx,%rax,8), %rbx
cmpl $0x2, %ebx
jne 0x6df60
movl %r13d, %eax
cmpl $0x2, %eax
jne 0x6df60
movq %r13, 0x40(%rsp)
shrl %r12d
movq %r14, %rdi
movq %r14, %r13
movl 0x1c(%rsp), %r14d
movl %r14d, %esi
movl %r12d, %edx
callq 0x6c7f0
testl %eax, %eax
je 0x6df49
movq 0x28(%rsp), %rdx
shrl %edx
movq %r13, %rdi
movl %r14d, %esi
movq %rdx, 0x28(%rsp)
callq 0x6c7f0
testl %eax, %eax
je 0x6df4e
shrq $0x20, %rbx
imulq $0x18, %rbx, %r14
addq 0x20(%rsp), %r14
movl 0x8(%r14), %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x6c8a1
movl %eax, %ebx
movq %r14, 0x58(%rsp)
movl 0x20(%r14), %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x6c8a1
leal -0x3(%rbx), %ecx
cmpl $-0x2, %ecx
movq 0x10(%rsp), %r13
jb 0x6df81
cmpl %eax, %ebx
movq 0x38(%rsp), %r14
je 0x6df58
addl $-0x3, %eax
cmpl $-0x2, %eax
jb 0x6df58
movq 0x58(%rsp), %rcx
leaq 0x8(%rcx), %rax
addq $0x20, %rcx
cmpl $0x2, %ebx
cmovneq %rcx, %rax
setne %r12b
movl (%rax), %eax
movq %rax, 0x60(%rsp)
movl %eax, %edx
shrl %edx
movq %r14, %rdi
movl 0x1c(%rsp), %esi
movl %edx, 0x4c(%rsp)
callq 0x6c7f0
testl %eax, %eax
je 0x6df58
movb %r12b, 0xf(%rsp)
movq 0x40(%rsp), %rax
shrq $0x20, %rax
imulq $0x18, %rax, %rax
movq 0x20(%rsp), %r12
addq %rax, %r12
movl 0x8(%r12), %esi
movq %r15, %rdi
movq 0x28(%rsp), %rbx
movl %ebx, %edx
callq 0x6c8a1
movq %rax, 0x40(%rsp)
movq %r12, 0x20(%rsp)
movl 0x20(%r12), %esi
movq %r15, %rdi
movl %ebx, %edx
callq 0x6c8a1
movq 0x40(%rsp), %rdx
leal -0x3(%rdx), %ecx
cmpl $-0x2, %ecx
jb 0x6df58
cmpl %eax, %edx
je 0x6df58
addl $-0x3, %eax
cmpl $-0x2, %eax
jb 0x6df58
movq 0x20(%rsp), %rcx
leaq 0x8(%rcx), %rax
addq $0x20, %rcx
cmpl $0x2, %edx
cmovneq %rcx, %rax
setne 0x28(%rsp)
movl (%rax), %ebx
movl %ebx, %r13d
shrl %r13d
movq %r14, %rdi
movl 0x1c(%rsp), %esi
movl %r13d, %edx
callq 0x6c7f0
testl %eax, %eax
je 0x6df53
xorq $0x1, %rbx
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movq %rcx, %r12
movq (%rcx,%rbx,8), %rsi
movq %rax, %rbx
movq %rsi, %rax
shrq $0x20, %rax
imulq $0x18, %rax, %rdi
addq %rbx, %rdi
movl 0x4c(%rsp), %edx
callq 0x6dbf9
testl %eax, %eax
je 0x6df53
movq 0x60(%rsp), %rax
xorq $0x1, %rax
movq (%r12,%rax,8), %rsi
movq %rsi, %rax
shrq $0x20, %rax
imulq $0x18, %rax, %rax
addq %rax, %rbx
movq %rbx, %rdi
movl %r13d, %edx
callq 0x6dbf9
testl %eax, %eax
je 0x6df53
xorl %eax, %eax
movb 0xf(%rsp), %cl
movb %cl, %al
movb 0x28(%rsp), %cl
xorl %r13d, %r13d
movb %cl, %r13b
imulq $0x18, %rax, %rax
movq 0x58(%rsp), %rcx
orb $-0x80, 0xf(%rcx,%rax)
movl 0x4(%rcx,%rax), %edx
movl 0x8(%rcx,%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
pushq $0x1
popq %r12
movl %r12d, %ecx
callq 0x6db50
imulq $0x18, %r13, %rax
movq 0x20(%rsp), %rcx
orb $-0x80, 0xf(%rcx,%rax)
movl 0x4(%rcx,%rax), %edx
movl 0x8(%rcx,%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
movl %r12d, %ecx
callq 0x6db50
incl 0x34(%rsp)
jmp 0x6df53
movq %r13, %r14
jmp 0x6df53
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %r13
incq %rbp
jmp 0x6dc5a
movq 0x1e5079(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1759fc(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0x6dd00
movq 0x38(%rsp), %r14
jmp 0x6df58
movl 0x34(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq