// File: /workspace/github_cpp_makefile_star2_O1/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 0xa7f89
movl %r8d, %r11d
movl %ecx, %r8d
movq %rsi, %r10
movq %rdi, %r15
shrl %r8d
shrl %r11d
movl %edx, %edi
leaq -0x1(%rdi), %rax
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
movl $0x1, %ebx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x0, 0x1c(%rsp)
movl %r11d, 0x18(%rsp)
movl %r8d, 0x14(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movl (%r10,%rbp,4), %r12d
movl %r12d, %r14d
shrl %r14d
cmpl %r8d, %r14d
sete %al
cmpl %r11d, %r14d
sete %cl
orb %al, %cl
jne 0xa7f7b
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rcx
cmpl $0x2, %ecx
jne 0xa7f7b
movq 0x8(%r15), %rdx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %r9
movl 0x8(%r9), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
jle 0xa785b
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl (%rsi), %edi
shrl %edi
cmpl %r14d, %edi
cmovel %ebx, %edx
addq $0x18, %rsi
decq %rcx
jne 0xa783b
testl %edx, %edx
sete %cl
cmpl $0x1, %eax
setne %bl
jmp 0xa785f
movb $0x1, %bl
movb $0x1, %cl
testb %cl, %cl
jne 0xa7af6
movl 0x20(%r9), %eax
movq 0x28(%r15), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
jle 0xa78d5
movq %r9, %r8
movl %r11d, %r9d
movq 0x8(%r15), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl $0x1, %r11d
movl (%rsi), %edi
shrl %edi
cmpl %r14d, %edi
cmovel %r11d, %edx
addq $0x18, %rsi
decq %rcx
jne 0xa78a8
testl %edx, %edx
sete %cl
cmpl $0x1, %eax
setne %r14b
movl %r9d, %r11d
movq %r8, %r9
movl 0x14(%rsp), %r8d
jmp 0xa78da
movb $0x1, %r14b
movb $0x1, %cl
testb %cl, %cl
jne 0xa7b19
orb %r14b, %bl
je 0xa78f1
movl $0x1, %ebx
jmp 0xa7f76
movl 0x8(%r9), %edx
movq %r9, 0x30(%rsp)
movl 0x20(%r9), %ecx
leaq 0x3c(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movl %r12d, %esi
leaq 0x40(%rsp), %r8
leaq 0x48(%rsp), %r9
callq 0xa7139
testl %eax, %eax
movl $0x1, %ebx
je 0xa7f67
movl 0x3c(%rsp), %eax
movl %eax, %ecx
shrl %ecx
xorl %esi, %esi
movl 0x18(%rsp), %r11d
movq 0x28(%rsp), %r10
movq 0x50(%rsp), %r8
movl (%r10,%rsi,4), %edx
shrl %edx
cmpl %ecx, %edx
je 0xa7958
leaq 0x1(%rsi), %rdi
cmpq %rsi, %r8
movq %rdi, %rsi
jne 0xa7942
cmpl %r11d, %ecx
movl 0x14(%rsp), %r8d
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %r9
je 0xa7f7b
cmpl %ecx, %edx
jne 0xa7f7b
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 0xa7a26
movl %r8d, %r14d
movl 0x8(%r9), %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 0xa7b3c
movq %rsi, %r8
xorq $0x1, %r8
movl 0x4(%rdi,%r8,8), %r8d
leaq (%r8,%r8,2), %r8
cmpb $0x0, 0x12(%rdx,%r8,8)
je 0xa7b3c
cmpq $0x4, %rcx
jl 0xa7e1f
cmpb $0x1, 0x12(%r9)
movq 0x20(%rsp), %rcx
movl %r14d, %r8d
jne 0xa7e2c
cmpb $0x1, 0x2a(%r9)
jne 0xa7e2c
movl 0x4(%rdi,%rax,8), %eax
leaq (%rax,%rax,2), %rax
cmpb $0x1, 0x12(%rdx,%rax,8)
movq %rcx, %rdi
jne 0xa7f7b
leaq (%rdx,%rax,8), %rax
jmp 0xa7ac5
cmpq $0x1, %rdx
setne %sil
cmpq $0x1, %rcx
sete %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0xa7bf1
movl %r8d, %r14d
movl 0x20(%r9), %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 0xa7d6a
movq %rsi, %r8
xorq $0x1, %r8
movl 0x4(%rdi,%r8,8), %r8d
leaq (%r8,%r8,2), %r8
cmpb $0x0, 0x12(%rcx,%r8,8)
je 0xa7d6a
cmpq $0x4, %rdx
jl 0xa7e1f
cmpb $0x1, 0x12(%r9)
movq 0x20(%rsp), %rdx
movl %r14d, %r8d
jne 0xa7f5d
cmpb $0x1, 0x2a(%r9)
jne 0xa7f5d
movl 0x4(%rdi,%rax,8), %eax
leaq (%rax,%rax,2), %rax
cmpb $0x1, 0x12(%rcx,%rax,8)
movq %rdx, %rdi
jne 0xa7f7b
leaq (%rcx,%rax,8), %rax
cmpb $0x1, 0x2a(%rax)
jne 0xa7f7b
shrl %esi
movq %r15, %rdi
callq 0xa7fa4
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %r10
movl 0x14(%rsp), %r8d
movl 0x18(%rsp), %r11d
incl 0x1c(%rsp)
jmp 0xa7f7b
movq %r9, 0x30(%rsp)
callq 0x1017c
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %r10
movl 0x14(%rsp), %r8d
movl 0x18(%rsp), %r11d
jmp 0xa7867
movq %r9, 0x30(%rsp)
callq 0x10198
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %r10
movl 0x14(%rsp), %r8d
movl 0x18(%rsp), %r11d
jmp 0xa78e2
movl %esi, %eax
shrl %eax
movq 0x20(%r15), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
andl $-0x2, %esi
xorl %eax, %eax
leaq (%rax,%rsi), %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rcx,8), %rdi
movq %rdi, %rdx
andq %r13, %rdx
je 0xa7bdc
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 %r13, %r9
je 0xa7bd4
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), %ebx
xorl %ecx, %ebx
cmpl $0x1, %ebx
jne 0xa7bcb
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xa7bb9
incq %r8
cmpq %rdx, %r8
jne 0xa7b77
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0xa7b50
jmp 0xa7f3e
cmpq $0x1, %rdx
jne 0xa7f62
cmpq $0x1, %rcx
jne 0xa7f62
movl 0x8(%r9), %eax
movl 0x20(%r9), %edx
movq 0x8(%r15), %r8
movq 0x28(%r15), %r9
movl 0x4(%r9,%rax,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movzbl 0x12(%r8,%rcx,8), %esi
movq %rax, %rcx
xorq $0x1, %rcx
movl 0x4(%r9,%rcx,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movzbl 0x12(%r8,%rcx,8), %edi
leal (%rdi,%rsi), %ecx
movl 0x4(%r9,%rdx,8), %r10d
leaq (%r10,%r10,2), %r10
movzbl 0x12(%r8,%r10,8), %r10d
xorq $0x1, %rdx
movl 0x4(%r9,%rdx,8), %edx
leaq (%rdx,%rdx,2), %rdx
movzbl 0x12(%r8,%rdx,8), %edx
addl %r10d, %edx
cmpl $0x1, %ecx
ja 0xa7e34
cmpl $0x2, %edx
movl 0x14(%rsp), %r9d
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %r14
movq 0x30(%rsp), %r8
jb 0xa7e48
testb %sil, %sil
je 0xa7c96
testb %dil, %dil
jne 0xa7e48
movl %eax, %esi
shrl %esi
movq 0x20(%r15), %rdi
orl $0x80000000, (%rdi,%rsi,8) # imm = 0x80000000
andl $-0x2, %eax
xorl %esi, %esi
leaq (%rsi,%rax), %rdi
movq 0x28(%r15), %r8
movq (%r8,%rdi,8), %r9
movq %r9, %r8
andq %r13, %r8
je 0xa7d38
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), %rbx
movq (%rbx,%r11,8), %rbx
movq %rbx, %r11
andq %r13, %r11
je 0xa7d30
movq 0x8(%r15), %r14
shrq $0x20, %rbx
shlq $0x3, %r11
leaq (%r11,%r11,2), %r11
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%rbx,8), %rbx
addq $0xc, %rbx
xorl %r14d, %r14d
movl -0x4(%rbx,%r14), %r12d
xorl %edi, %r12d
cmpl $0x1, %r12d
jne 0xa7d27
orb $-0x80, 0x3(%rbx,%r14)
addq $0x18, %r14
cmpq %r14, %r11
jne 0xa7d13
incq %r10
cmpq %r8, %r10
jne 0xa7cd1
leaq 0x1(%rsi), %rdi
testq %rsi, %rsi
movq %rdi, %rsi
je 0xa7caa
incl 0x1c(%rsp)
movl 0x18(%rsp), %r11d
movl 0x14(%rsp), %r9d
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %r14
movl $0x1, %ebx
jmp 0xa7e43
movl %esi, %eax
shrl %eax
movq 0x20(%r15), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
andl $-0x2, %esi
xorl %eax, %eax
leaq (%rax,%rsi), %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rcx,8), %rdi
movq %rdi, %rdx
andq %r13, %rdx
je 0xa7e0a
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 %r13, %r9
je 0xa7e02
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), %ebx
xorl %ecx, %ebx
cmpl $0x1, %ebx
jne 0xa7df9
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xa7de7
incq %r8
cmpq %rdx, %r8
jne 0xa7da5
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0xa7d7e
jmp 0xa7f3e
movq 0x20(%rsp), %rdi
movl %r14d, %r8d
jmp 0xa7f7b
movq %rcx, %rdi
jmp 0xa7f7b
movl 0x14(%rsp), %r9d
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %r14
movq 0x30(%rsp), %r8
cmpl $0x2, %ecx
jb 0xa7e83
cmpl $0x1, %edx
ja 0xa7e83
movl 0x20(%r8), %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 0xa7e8e
movq %rax, %rsi
xorq $0x1, %rsi
movl 0x4(%rdx,%rsi,8), %edx
leaq (%rdx,%rdx,2), %rdx
cmpb $0x0, 0x12(%rcx,%rdx,8)
je 0xa7e8e
movl %r9d, %r8d
movq %r14, %rdi
jmp 0xa7f7b
movl %eax, %ecx
shrl %ecx
movq 0x20(%r15), %rdx
orl $0x80000000, (%rdx,%rcx,8) # imm = 0x80000000
andl $-0x2, %eax
xorl %ecx, %ecx
leaq (%rcx,%rax), %rdx
movq 0x28(%r15), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
andq %r13, %rsi
je 0xa7f2e
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 %r13, %r9
je 0xa7f26
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), %ebx
xorl %edx, %ebx
cmpl $0x1, %ebx
jne 0xa7f1d
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xa7f0b
incq %r8
cmpq %rsi, %r8
jne 0xa7ec9
leaq 0x1(%rcx), %rdx
testq %rcx, %rcx
movq %rdx, %rcx
je 0xa7ea2
incl 0x1c(%rsp)
movl 0x18(%rsp), %r11d
movl 0x14(%rsp), %r8d
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %rdi
movl $0x1, %ebx
jmp 0xa7f7b
movq %rdx, %rdi
jmp 0xa7f7b
callq 0x101b4
movl 0x18(%rsp), %r11d
movl 0x14(%rsp), %r8d
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %rdi
incq %rbp
cmpq %rdi, %rbp
jne 0xa77cf
jmp 0xa7f91
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq