// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movl %ecx, 0x38(%rsp)
testl %edx, %edx
je 0xa59c7
movq %rsi, %r14
movq %rdi, %r11
movl %edx, %r9d
leaq -0x1(%r9), %r12
xorl %r10d, %r10d
movl $0x1, %r8d
movl $0x0, 0x1c(%rsp)
movq %rdi, 0x20(%rsp)
movq %r9, 0x10(%rsp)
movl (%r14,%r10,4), %r13d
movq 0x28(%r11), %rax
movq (%rax,%r13,8), %rcx
cmpl $0x1, %ecx
jne 0xa5538
movq 0x8(%r11), %r15
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rbp
movl 0x8(%r15,%rbp,8), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %ebx, %ebx
testl %eax, %eax
jle 0xa53e4
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%r15,%rdx,8), %rdx
addq $0x8, %rdx
movl (%rdx), %esi
xorl %r13d, %esi
cmpl $0x2, %esi
cmovbl %r8d, %ebx
addq $0x18, %rdx
decq %rcx
jne 0xa53c2
testl %ebx, %ebx
sete %cl
cmpl $0x2, %eax
sete %bl
jmp 0xa53e6
movb $0x1, %cl
testb %cl, %cl
jne 0xa5549
testb %bl, %bl
je 0xa5538
movq %r10, 0x8(%rsp)
movq %r11, %rdi
movl %r13d, %esi
movl 0x38(%rsp), %edx
leaq 0x3c(%rsp), %rcx
movq %r11, %r13
callq 0xa52b4
testl %eax, %eax
je 0xa5525
leaq (%r15,%rbp,8), %rax
addq $0x8, %rax
movl (%rax), %r15d
movq %r15, %rax
xorq $0x1, %rax
movq 0x8(%r13), %rdx
movq 0x28(%r13), %rcx
movl 0x3c(%rsp), %edi
movq (%rcx,%rdi,8), %rbx
movq (%rcx,%rax,8), %rbp
cmpl $0x2, %ebp
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
movl $0x1, %r8d
jne 0xa5699
movq %r13, %r11
movl %ebx, %eax
cmpl $0x2, %eax
jne 0xa5699
shrq $0x20, %rbx
leaq (%rbx,%rbx,2), %rax
leaq (%rdx,%rax,8), %rsi
shrq $0x20, %rbp
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq (%rdx,%rax,8), %r13
shrl %r15d
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
shrl %ecx
cmpl %r15d, %ecx
je 0xa54a2
leaq 0x1(%rax), %rdx
cmpq %rax, %r12
movq %rdx, %rax
jne 0xa548b
cmpl %r15d, %ecx
jne 0xa5538
shrl %edi
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
shrl %ecx
cmpl %edi, %ecx
je 0xa54c5
leaq 0x1(%rax), %rdx
cmpq %rax, %r12
movq %rdx, %rax
jne 0xa54af
cmpl %edi, %ecx
jne 0xa5538
movl 0x8(%r13), %eax
movq 0x28(%r11), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
movq %rsi, 0x28(%rsp)
jle 0xa556d
movq 0x8(%r11), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movq %rax, %rbx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %r15d, %esi
cmovel %r8d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa5507
testl %ecx, %ecx
sete %al
movq %rbx, %rdx
jmp 0xa5571
movq %r13, %r11
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
movl $0x1, %r8d
incq %r10
cmpq %r9, %r10
jne 0xa5373
jmp 0xa59cf
movq %r10, 0x8(%rsp)
callq 0xff84
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
jmp 0xa53ee
movb $0x1, %al
xorl %edx, %edx
testb %al, %al
jne 0xa57fb
movl 0x20(%r13), %eax
movq 0x28(%r11), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rbp
testl %ebp, %ebp
jle 0xa55ce
movq %rdx, %rbx
movq 0x8(%r11), %rcx
movq %rbp, %rdx
shrq $0x20, %rdx
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %r15d, %esi
cmovel %r8d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa55b0
testl %ecx, %ecx
sete %al
movq %rbx, %rdx
jmp 0xa55d2
movb $0x1, %al
xorl %ebp, %ebp
testb %al, %al
jne 0xa5826
leal -0x3(%rdx), %eax
cmpl $-0x2, %eax
jb 0xa5538
cmpl %ebp, %edx
je 0xa5538
addl $-0x3, %ebp
cmpl $-0x2, %ebp
jb 0xa5538
leaq 0x8(%r13), %rax
leaq 0x20(%r13), %rcx
movq %rdx, %rbx
cmpl $0x2, %edx
cmovneq %rcx, %rax
movl (%rax), %ebp
movl %ebp, %esi
shrl %esi
xorl %ecx, %ecx
movl (%r14,%rcx,4), %eax
shrl %eax
cmpl %esi, %eax
je 0xa562a
leaq 0x1(%rcx), %rdx
cmpq %rcx, %r12
movq %rdx, %rcx
jne 0xa5614
cmpl $0x2, %ebx
setne %cl
cmpl %esi, %eax
jne 0xa5538
movb %cl, 0x7(%rsp)
movl %esi, 0x34(%rsp)
movq 0x28(%rsp), %rbx
movl 0x8(%rbx), %eax
movq 0x28(%r11), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r15
testl %r15d, %r15d
movq %rbp, 0x40(%rsp)
jle 0xa56c8
movq 0x8(%r11), %rcx
movq %r15, %rdx
shrq $0x20, %rdx
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %edi, %esi
cmovel %r8d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa567f
testl %ecx, %ecx
sete %al
jmp 0xa56cd
movq %rdi, 0x28(%rsp)
movq %rdx, %r13
callq 0xffa0
movq %r13, %rdx
movq 0x28(%rsp), %rdi
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
jmp 0xa5467
movb $0x1, %al
xorl %r15d, %r15d
testb %al, %al
jne 0xa58a5
movl 0x20(%rbx), %eax
movq 0x28(%r11), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rbp
testl %ebp, %ebp
jle 0xa5722
movq 0x8(%r11), %rcx
movq %rbp, %rdx
shrq $0x20, %rdx
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %edi, %esi
cmovel %r8d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa5708
testl %ecx, %ecx
sete %al
jmp 0xa5726
movb $0x1, %al
xorl %ebp, %ebp
testb %al, %al
jne 0xa58ca
leal -0x3(%r15), %eax
cmpl $-0x2, %eax
jb 0xa5538
cmpl %ebp, %r15d
je 0xa5538
addl $-0x3, %ebp
cmpl $-0x2, %ebp
jb 0xa5538
xorq $0x1, 0x40(%rsp)
xorl %ebp, %ebp
movb 0x7(%rsp), %al
movb %al, %bpl
leaq 0x8(%rbx), %rax
leaq 0x20(%rbx), %rcx
cmpl $0x2, %r15d
cmovneq %rcx, %rax
movl (%rax), %edx
movl %edx, %ecx
shrl %ecx
xorl %eax, %eax
movl (%r14,%rax,4), %esi
shrl %esi
cmpl %ecx, %esi
je 0xa578d
leaq 0x1(%rax), %rdi
cmpq %rax, %r12
movq %rdi, %rax
jne 0xa5777
xorl %eax, %eax
cmpl $0x2, %r15d
setne %dil
cmpl %ecx, %esi
jne 0xa5538
xorq $0x1, %rdx
movq 0x28(%r11), %rsi
movq (%rsi,%rdx,8), %r8
testl %r8d, %r8d
je 0xa5532
movb %dil, %al
movq 0x8(%r11), %rdx
movq %r8, %rdi
shrq $0x20, %rdi
movl %r8d, %r8d
leaq (%rdi,%rdi,2), %rdi
leaq (%rdx,%rdi,8), %rdi
addq $0x8, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
movl 0x34(%rsp), %r15d
movl (%rdi,%r9), %r10d
shrl %r10d
cmpl %r15d, %r10d
je 0xa5851
addq $0x18, %r9
cmpq %r9, %r8
jne 0xa57e1
jmp 0xa5528
movq %rdi, %rbp
movq %rdx, %rbx
callq 0xffbc
movq %rbx, %rdx
movq %rbp, %rdi
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
jmp 0xa5579
movq %rdi, %r15
movq %rdx, %rbx
callq 0xffd8
movq %rbx, %rdx
movq %r15, %rdi
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
jmp 0xa55da
movq 0x40(%rsp), %rdi
movq (%rsi,%rdi,8), %rsi
testl %esi, %esi
je 0xa5528
movq %rsi, %rdi
shrq $0x20, %rdi
movl %esi, %esi
leaq (%rdi,%rdi,2), %rdi
leaq (%rdx,%rdi,8), %rdx
addq $0x8, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
movl (%rdx,%rdi), %r8d
shrl %r8d
cmpl %ecx, %r8d
je 0xa58e9
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xa588b
jmp 0xa5532
movq %rdi, %rbp
callq 0xfff4
movq %rbp, %rdi
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
jmp 0xa56d5
callq 0x10010
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
jmp 0xa572e
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
orb $-0x80, 0xf(%r13,%rcx,8)
movl 0x8(%r13,%rcx,8), %edx
xorq $0x1, %rdx
movq 0x28(%r11), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rdx
je 0xa5957
movl 0x4(%r13,%rcx,8), %ecx
movq 0x8(%r11), %rdi
shrq $0x20, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
movl -0x4(%rsi,%rdi), %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
jne 0xa594e
orb $-0x80, 0x3(%rsi,%rdi)
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0xa593b
leaq (%rax,%rax,2), %rax
orb $-0x80, 0xf(%rbx,%rax,8)
movl 0x8(%rbx,%rax,8), %ecx
xorq $0x1, %rcx
movq 0x28(%r11), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
movl $0x1, %r8d
je 0xa59be
movl 0x4(%rbx,%rax,8), %eax
movq 0x8(%r11), %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), %edi
xorl %eax, %edi
cmpl $0x1, %edi
jne 0xa59b5
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xa59a5
incl 0x1c(%rsp)
jmp 0xa5538
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq