// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_single_node_bubble(asg_t*, unsigned int*, unsigned int, unsigned int, unsigned int)
int test_single_node_bubble(asg_t *g, uint32_t* nodes, uint32_t length, 
uint32_t startNode, uint32_t endNode)
{
    
    uint32_t i, v, w;
    uint32_t vEnd;
    int flag0, flag1;
    int n_reduced = 0;
    long long Len[2], longLen;
    long long longLen_thres = 4;
    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;
        }

        
        flag0 = asg_is_single_edge(g, av[0].v, v>>1);
        flag1 = asg_is_single_edge(g, av[1].v, v>>1);
        if(flag0 != 1 || flag1 != 1)
        {
            continue;
        }

        if(check_small_bubble(g, v, av[0].v, av[1].v, &(Len[0]), &(Len[1]), &vEnd))
        {

            if(if_node_exist(nodes, length, vEnd>>1) && ((vEnd>>1) != (endNode>>1)))
           {
               
               if(Len[0] == 1 && Len[1] != 1)
               {
                   w = av[0].v;
                   longLen = Len[1];
                    
                  /****************************may have bugs********************************/
                  if(asg_arc_a(g, w)[0].el == 0 || asg_arc_a(g, w^1)[0].el == 0)
                   {
                    //    fprintf(stderr, "w>>1: %u, beg: %u, end: %u\n", 
                    //    w>>1, startNode>>1, endNode>>1);
                       asg_seq_del(g, w>>1);
                       n_reduced++;
                   }///up to here w is exactly overlapped in both directions
                   else if(longLen >= longLen_thres)
                   {
                       if(av[0].el == 1 && av[1].el == 1
                          &&
                          asg_arc_a(g, vEnd)[0].el == 1 && asg_arc_a(g, vEnd)[1].el == 1)
                       {
                           asg_seq_del(g, w>>1);
                           n_reduced++;
                       }
                   }
                   
                  /****************************may have bugs********************************/
                   
               }
               else if(Len[0] != 1 && Len[1] == 1)
               {
                   w = av[1].v;
                   longLen = Len[0];
                   
                  /****************************may have bugs********************************/
                  if(asg_arc_a(g, w)[0].el == 0 || asg_arc_a(g, w^1)[0].el == 0)
                   {
                    //    fprintf(stderr, "w>>1: %u, beg: %u, end: %u\n", 
                    //    w>>1, startNode>>1, endNode>>1);
                       asg_seq_del(g, w>>1);
                       n_reduced++;
                   }///up to here w is exactly overlapped in both directions
                   else if(longLen >= longLen_thres)
                   {
                       if(av[0].el == 1 && av[1].el == 1
                          &&
                          asg_arc_a(g, vEnd)[0].el == 1 && asg_arc_a(g, vEnd)[1].el == 1)
                       {
                           asg_seq_del(g, w>>1);
                           n_reduced++;
                       }
                   }
                  /****************************may have bugs********************************/
               }
               else if(Len[0] == 1 && Len[1] == 1)
               {
                   w = av[0].v;
                   flag0 = asg_arc_a(g, w)[0].el + asg_arc_a(g, w^1)[0].el;
                   w = av[1].v;
                   flag1 = asg_arc_a(g, w)[0].el + asg_arc_a(g, w^1)[0].el;
                    ///>=2 means this is an exact overlap
                   if(flag0 < 2 && flag1 >= 2)
                   {
                       w = av[0].v;
                       
                       /****************************may have bugs********************************/
                        if(asg_arc_a(g, w)[0].el == 0 || asg_arc_a(g, w^1)[0].el == 0)
                        {
                            // fprintf(stderr, "w>>1: %u, beg: %u, end: %u\n", 
                            // w>>1, startNode>>1, endNode>>1);
                            asg_seq_del(g, w>>1);
                            n_reduced++;
                        }
                        /****************************may have bugs********************************/
                   }

                   if(flag0 >= 2 && flag1 < 2)
                   {
                       w = av[1].v;
                      
                       /****************************may have bugs********************************/
                        if(asg_arc_a(g, w)[0].el == 0 || asg_arc_a(g, w^1)[0].el == 0)
                        {
                            // fprintf(stderr, "w>>1: %u, beg: %u, end: %u\n", 
                            // w>>1, startNode>>1, endNode>>1);
                            asg_seq_del(g, w>>1);
                            n_reduced++;
                        }
                        /****************************may have bugs********************************/
                   }
               }
               else
               {
                   fprintf(stderr, "error\n");
               }
               
           }
        }

    }

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testl %edx, %edx
je 0xa8f86
movl %r8d, %r9d
movl %ecx, %r10d
movq %rsi, %r11
movq %rdi, %r15
shrl %r10d
shrl %r9d
movl %edx, %r13d
xorl %ebp, %ebp
movl $0x1, %ebx
movl $0x0, 0x14(%rsp)
movl %r9d, 0x10(%rsp)
movl %r10d, 0xc(%rsp)
movq %rsi, 0x18(%rsp)
movq %r13, 0x28(%rsp)
movl (%r11,%rbp,4), %r12d
movl %r12d, %r14d
shrl %r14d
cmpl %r10d, %r14d
sete %al
cmpl %r9d, %r14d
sete %cl
orb %al, %cl
jne 0xa8f62
movq 0x28(%r15), %rcx
movq (%rcx,%r12,8), %rdx
cmpl $0x2, %edx
jne 0xa8f62
movq 0x8(%r15), %rax
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r13
movl 0x8(%r13), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rdx
testl %edx, %edx
jle 0xa8a3f
movq %rdx, %rsi
shrq $0x20, %rsi
movq %rdx, 0x38(%rsp)
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rdi
addq $0x8, %rdi
xorl %esi, %esi
movl (%rdi), %r8d
shrl %r8d
cmpl %r14d, %r8d
cmovel %ebx, %esi
addq $0x18, %rdi
decq %rdx
jne 0xa889c
testl %esi, %esi
je 0xa8a48
movq %r13, 0x20(%rsp)
movl 0x20(%r13), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %r13
testl %r13d, %r13d
jle 0xa8a84
movq %r13, %rdx
shrq $0x20, %rdx
movl %r13d, %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 %r14d, %esi
cmovel %ebx, %eax
addq $0x18, %rdx
decq %rcx
jne 0xa88f1
testl %eax, %eax
je 0xa8a87
cmpl $0x1, 0x38(%rsp)
jne 0xa8985
cmpl $0x1, %r13d
jne 0xa8985
movq 0x20(%rsp), %rax
movl 0x8(%rax), %edx
movl 0x20(%rax), %ecx
leaq 0x34(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movl %r12d, %esi
leaq 0x40(%rsp), %r8
leaq 0x48(%rsp), %r9
callq 0xa8187
testl %eax, %eax
movq 0x28(%rsp), %r13
je 0xa8f53
movl 0x34(%rsp), %eax
movl %eax, %ecx
shrl %ecx
xorl %edx, %edx
movl 0x10(%rsp), %r9d
movl 0xc(%rsp), %r10d
movq 0x18(%rsp), %r11
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl (%r11,%rdx,4), %esi
shrl %esi
cmpl %ecx, %esi
je 0xa898f
incq %rdx
cmpq %rdx, %r13
jne 0xa896e
jmp 0xa8f62
movq 0x28(%rsp), %r13
jmp 0xa8f62
cmpl %r9d, %ecx
je 0xa8f62
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
cmpq $0x1, %rdx
sete %sil
cmpq $0x1, %rcx
setne %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0xa8abb
movq 0x20(%rsp), %rdx
movl 0x8(%rdx), %esi
movq 0x8(%r15), %rdx
movq 0x28(%r15), %rdi
movl 0x4(%rdi,%rsi,8), %r8d
leaq (%r8,%r8,2), %r8
cmpb $0x0, 0x12(%rdx,%r8,8)
je 0xa8b7f
movq %rsi, %r8
xorq $0x1, %r8
movl 0x4(%rdi,%r8,8), %r8d
leaq (%r8,%r8,2), %r8
cmpb $0x0, 0x12(%rdx,%r8,8)
je 0xa8b7f
cmpq $0x4, %rcx
jl 0xa8f62
movq 0x20(%rsp), %rcx
cmpb $0x1, 0x12(%rcx)
jne 0xa8f62
cmpb $0x1, 0x2a(%rcx)
jne 0xa8f62
movl 0x4(%rdi,%rax,8), %eax
leaq (%rax,%rax,2), %rax
cmpb $0x1, 0x12(%rdx,%rax,8)
jne 0xa8f62
leaq (%rdx,%rax,8), %rax
jmp 0xa8b53
movq $0x0, 0x38(%rsp)
movq 0x1ec591(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x1906b7(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x18(%rsp), %r11
movl 0xc(%rsp), %r10d
movl 0x10(%rsp), %r9d
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
jmp 0xa88b9
xorl %r13d, %r13d
movq 0x1ec552(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x190678(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x18(%rsp), %r11
movl 0xc(%rsp), %r10d
movl 0x10(%rsp), %r9d
jmp 0xa890c
cmpq $0x1, %rdx
setne %sil
cmpq $0x1, %rcx
sete %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0xa8c39
movq 0x20(%rsp), %rcx
movl 0x20(%rcx), %esi
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdi
movl 0x4(%rdi,%rsi,8), %r8d
leaq (%r8,%r8,2), %r8
cmpb $0x0, 0x12(%rcx,%r8,8)
je 0xa8e9a
movq %rsi, %r8
xorq $0x1, %r8
movl 0x4(%rdi,%r8,8), %r8d
leaq (%r8,%r8,2), %r8
cmpb $0x0, 0x12(%rcx,%r8,8)
je 0xa8e9a
cmpq $0x4, %rdx
jl 0xa8f62
movq 0x20(%rsp), %rdx
cmpb $0x1, 0x12(%rdx)
jne 0xa8f62
cmpb $0x1, 0x2a(%rdx)
jne 0xa8f62
movl 0x4(%rdi,%rax,8), %eax
leaq (%rax,%rax,2), %rax
cmpb $0x1, 0x12(%rcx,%rax,8)
jne 0xa8f62
leaq (%rcx,%rax,8), %rax
cmpb $0x1, 0x2a(%rax)
jne 0xa8f62
shrl %esi
movq %r15, %rdi
callq 0xa8fa1
movq 0x18(%rsp), %r11
movl 0xc(%rsp), %r10d
movl 0x10(%rsp), %r9d
incl 0x14(%rsp)
jmp 0xa8f62
movl %esi, %eax
shrl %eax
movq 0x20(%r15), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
andl $-0x2, %esi
movb $0x1, %al
xorl %ecx, %ecx
orq %rsi, %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rcx,8), %rdi
movq %rdi, %rdx
andq %r12, %rdx
je 0xa8c22
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x3, %rdi
addq 0x8(%r15), %rdi
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r9
orb $-0x80, 0xf(%rdi,%r9,8)
movl 0x8(%rdi,%r9,8), %r9d
xorq $0x1, %r9
movq 0x28(%r15), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
andq %r12, %r9
je 0xa8c1a
movq 0x8(%r15), %r11
shrq $0x20, %r10
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
leaq (%r10,%r10,2), %r10
leaq (%r11,%r10,8), %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %r14d
xorl %ecx, %r14d
cmpl $0x1, %r14d
jne 0xa8c11
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xa8bfd
incq %r8
cmpq %rdx, %r8
jne 0xa8bbb
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0xa8b95
jmp 0xa8f4f
cmpq $0x1, %rdx
jne 0xa8f70
cmpq $0x1, %rcx
jne 0xa8f70
movq 0x20(%rsp), %rcx
movl 0x8(%rcx), %eax
movl 0x20(%rcx), %edx
movq 0x8(%r15), %rsi
movq 0x28(%r15), %rdi
movl 0x4(%rdi,%rax,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movzbl 0x12(%rsi,%rcx,8), %r8d
movq %rax, %rcx
xorq $0x1, %rcx
movl 0x4(%rdi,%rcx,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movzbl 0x12(%rsi,%rcx,8), %ecx
addl %r8d, %ecx
movl 0x4(%rdi,%rdx,8), %r8d
leaq (%r8,%r8,2), %r8
movzbl 0x12(%rsi,%r8,8), %r8d
xorq $0x1, %rdx
movl 0x4(%rdi,%rdx,8), %edx
leaq (%rdx,%rdx,2), %rdx
movzbl 0x12(%rsi,%rdx,8), %edx
addl %r8d, %edx
cmpl $0x1, %ecx
ja 0xa8d94
cmpl $0x2, %edx
jb 0xa8d94
movl %eax, %esi
shrl %esi
movq 0x20(%r15), %rdi
orl $0x80000000, (%rdi,%rsi,8) # imm = 0x80000000
andl $-0x2, %eax
movb $0x1, %sil
xorl %edi, %edi
orq %rax, %rdi
movq 0x28(%r15), %r8
movq (%r8,%rdi,8), %r9
movq %r9, %r8
andq %r12, %r8
je 0xa8d68
shrq $0x20, %r9
leaq (%r9,%r9,2), %r9
shlq $0x3, %r9
addq 0x8(%r15), %r9
xorl %r10d, %r10d
leaq (%r10,%r10,2), %r11
orb $-0x80, 0xf(%r9,%r11,8)
movl 0x8(%r9,%r11,8), %r11d
xorq $0x1, %r11
movq 0x28(%r15), %r14
movq (%r14,%r11,8), %r14
movq %r14, %r11
andq %r12, %r11
je 0xa8d5a
movq 0x8(%r15), %r12
shrq $0x20, %r14
shlq $0x3, %r11
leaq (%r11,%r11,2), %r11
leaq (%r14,%r14,2), %r14
leaq (%r12,%r14,8), %r14
addq $0xc, %r14
xorl %r12d, %r12d
movl -0x4(%r14,%r12), %r13d
xorl %edi, %r13d
cmpl $0x1, %r13d
jne 0xa8d51
orb $-0x80, 0x3(%r14,%r12)
addq $0x18, %r12
cmpq %r12, %r11
jne 0xa8d3d
incq %r10
cmpq %r8, %r10
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jne 0xa8cfb
movl $0x1, %edi
testb $0x1, %sil
movl $0x0, %esi
jne 0xa8cd1
incl 0x14(%rsp)
movl 0x10(%rsp), %r9d
movl 0xc(%rsp), %r10d
movq 0x18(%rsp), %r11
movq 0x28(%rsp), %r13
cmpl $0x2, %ecx
jb 0xa8f62
cmpl $0x1, %edx
ja 0xa8f62
movq 0x20(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdx
movl 0x4(%rdx,%rax,8), %esi
leaq (%rsi,%rsi,2), %rsi
cmpb $0x0, 0x12(%rcx,%rsi,8)
je 0xa8ddf
movq %rax, %rsi
xorq $0x1, %rsi
movl 0x4(%rdx,%rsi,8), %edx
leaq (%rdx,%rdx,2), %rdx
cmpb $0x0, 0x12(%rcx,%rdx,8)
jne 0xa8f62
movl %eax, %ecx
shrl %ecx
movq 0x20(%r15), %rdx
orl $0x80000000, (%rdx,%rcx,8) # imm = 0x80000000
andl $-0x2, %eax
movb $0x1, %cl
xorl %edx, %edx
orq %rax, %rdx
movq 0x28(%r15), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
andq %r12, %rsi
je 0xa8e82
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x3, %rdi
addq 0x8(%r15), %rdi
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r9
orb $-0x80, 0xf(%rdi,%r9,8)
movl 0x8(%rdi,%r9,8), %r9d
xorq $0x1, %r9
movq 0x28(%r15), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
andq %r12, %r9
je 0xa8e7a
movq 0x8(%r15), %r11
shrq $0x20, %r10
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
leaq (%r10,%r10,2), %r10
leaq (%r11,%r10,8), %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %r14d
xorl %edx, %r14d
cmpl $0x1, %r14d
jne 0xa8e71
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xa8e5d
incq %r8
cmpq %rsi, %r8
jne 0xa8e1b
movl $0x1, %edx
testb $0x1, %cl
movl $0x0, %ecx
jne 0xa8df5
jmp 0xa8f4f
movl %esi, %eax
shrl %eax
movq 0x20(%r15), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
andl $-0x2, %esi
movb $0x1, %al
xorl %ecx, %ecx
orq %rsi, %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rcx,8), %rdi
movq %rdi, %rdx
andq %r12, %rdx
je 0xa8f3d
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x3, %rdi
addq 0x8(%r15), %rdi
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r9
orb $-0x80, 0xf(%rdi,%r9,8)
movl 0x8(%rdi,%r9,8), %r9d
xorq $0x1, %r9
movq 0x28(%r15), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
andq %r12, %r9
je 0xa8f35
movq 0x8(%r15), %r11
shrq $0x20, %r10
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
leaq (%r10,%r10,2), %r10
leaq (%r11,%r10,8), %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %r14d
xorl %ecx, %r14d
cmpl $0x1, %r14d
jne 0xa8f2c
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xa8f18
incq %r8
cmpq %rdx, %r8
jne 0xa8ed6
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0xa8eb0
incl 0x14(%rsp)
movl 0x10(%rsp), %r9d
movl 0xc(%rsp), %r10d
movq 0x18(%rsp), %r11
incq %rbp
cmpq %r13, %rbp
jne 0xa8829
jmp 0xa8f8e
callq 0x1004f
movq 0x18(%rsp), %r11
movl 0xc(%rsp), %r10d
movl 0x10(%rsp), %r9d
jmp 0xa8f62
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq