// File: /workspace/github_cpp_makefile_star2_O2/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
movl %r8d, %ebp
movl %ecx, %ebx
movq %rdi, %r12
shrl %ebx
shrl %ebp
movl %edx, 0x38(%rsp)
movl %edx, %edx
xorl %r15d, %r15d
movl $0x0, 0x24(%rsp)
movl %ebx, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x28(%rsp)
movl %ebp, 0x34(%rsp)
movq %rdx, 0x18(%rsp)
cmpq %r15, %rdx
je 0x6f8c7
movl (%rsi,%r15,4), %r13d
movl %r13d, %r14d
shrl %r14d
cmpl %ebx, %r14d
sete %al
cmpl %ebp, %r14d
sete %cl
orb %al, %cl
jne 0x6f73c
movq 0x28(%r12), %rax
movq (%rax,%r13,8), %rax
cmpl $0x2, %eax
jne 0x6f73c
shrq $0x20, %rax
imulq $0x18, %rax, %rbx
addq 0x8(%r12), %rbx
movl 0x8(%rbx), %esi
movq %r12, %rdi
movl %r14d, %edx
callq 0x6c8a1
movl %eax, %ebp
movl 0x20(%rbx), %esi
movq %r12, %rdi
movl %r14d, %edx
callq 0x6c8a1
cmpl $0x1, %ebp
jne 0x6f725
cmpl $0x1, %eax
jne 0x6f725
movl 0x8(%rbx), %edx
movl 0x20(%rbx), %ecx
leaq 0x3c(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movl %r13d, %esi
leaq 0x40(%rsp), %r8
leaq 0x48(%rsp), %r9
callq 0x6f23d
testl %eax, %eax
je 0x6f725
movl 0x3c(%rsp), %r14d
movl %r14d, %ebp
shrl %ebp
movq 0x10(%rsp), %rdi
movl 0x38(%rsp), %esi
movl %ebp, %edx
callq 0x6c7f0
testl %eax, %eax
sete %al
movl 0x34(%rsp), %r12d
cmpl %r12d, %ebp
movl %r12d, %ebp
sete %cl
orb %al, %cl
jne 0x6f729
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
cmpq $0x1, %rcx
sete %dl
cmpq $0x1, %rax
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
movq 0x28(%rsp), %r12
jne 0x6f744
movl 0x8(%rbx), %esi
movq 0x8(%r12), %rcx
movq 0x28(%r12), %rdx
movl 0x4(%rdx,%rsi,8), %edi
imulq $0x18, %rdi, %rdi
cmpb $0x0, 0x12(%rcx,%rdi)
je 0x6f7da
movq %rsi, %rdi
xorq $0x1, %rdi
movl 0x4(%rdx,%rdi,8), %edi
imulq $0x18, %rdi, %rdi
cmpb $0x0, 0x12(%rcx,%rdi)
je 0x6f7da
cmpq $0x4, %rax
jl 0x6f873
cmpb $0x1, 0x12(%rbx)
jne 0x6f873
cmpb $0x1, 0x2a(%rbx)
jne 0x6f873
movl 0x4(%rdx,%r14,8), %eax
imulq $0x18, %rax, %rax
cmpb $0x1, 0x12(%rcx,%rax)
movl 0xc(%rsp), %ebx
jne 0x6f877
addq %rax, %rcx
cmpb $0x1, 0x2a(%rcx)
jne 0x6f877
jmp 0x6f88f
movl 0x34(%rsp), %ebp
movl 0xc(%rsp), %ebx
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %r12
movq 0x18(%rsp), %rdx
incq %r15
jmp 0x6f59f
cmpq $0x1, %rcx
setne %dl
cmpq $0x1, %rax
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x6f7e4
movl 0x20(%rbx), %esi
movq 0x8(%r12), %rax
movq 0x28(%r12), %rdx
movl 0x4(%rdx,%rsi,8), %edi
imulq $0x18, %rdi, %rdi
cmpb $0x0, 0x12(%rax,%rdi)
je 0x6f7da
movq %rsi, %rdi
xorq $0x1, %rdi
movl 0x4(%rdx,%rdi,8), %edi
imulq $0x18, %rdi, %rdi
cmpb $0x0, 0x12(%rax,%rdi)
je 0x6f7da
cmpq $0x4, %rcx
jl 0x6f873
cmpb $0x1, 0x12(%rbx)
jne 0x6f873
cmpb $0x1, 0x2a(%rbx)
jne 0x6f873
movl 0x4(%rdx,%r14,8), %ecx
imulq $0x18, %rcx, %rcx
cmpb $0x1, 0x12(%rax,%rcx)
movl 0xc(%rsp), %ebx
jne 0x6f877
addq %rcx, %rax
cmpb $0x1, 0x2a(%rax)
jne 0x6f877
jmp 0x6f88f
shrl %esi
movq %r12, %rdi
jmp 0x6f865
cmpq $0x1, %rcx
jne 0x6f8a4
cmpq $0x1, %rax
jne 0x6f8a4
movl 0x8(%rbx), %eax
movl 0x20(%rbx), %esi
movq 0x8(%r12), %rdx
movq 0x28(%r12), %rdi
movl 0x4(%rdi,%rax,8), %ecx
imulq $0x18, %rcx, %rcx
movzbl 0x12(%rdx,%rcx), %r8d
movq %rax, %rcx
xorq $0x1, %rcx
movl 0x4(%rdi,%rcx,8), %ecx
imulq $0x18, %rcx, %rcx
movzbl 0x12(%rdx,%rcx), %ecx
addl %r8d, %ecx
movl 0x4(%rdi,%rsi,8), %r8d
imulq $0x18, %r8, %r8
movzbl 0x12(%rdx,%r8), %r8d
movq %rsi, %r9
xorq $0x1, %r9
movl 0x4(%rdi,%r9,8), %edi
imulq $0x18, %rdi, %rdi
movzbl 0x12(%rdx,%rdi), %edx
addl %r8d, %edx
cmpl $0x1, %ecx
ja 0x6f881
cmpl $0x2, %edx
jb 0x6f881
shrl %eax
movq %r12, %rdi
movl %eax, %esi
callq 0x6f8da
movq 0x28(%rsp), %r12
incl 0x24(%rsp)
movl 0xc(%rsp), %ebx
movq 0x10(%rsp), %rsi
jmp 0x6f737
cmpl $0x2, %ecx
movl 0xc(%rsp), %ebx
jb 0x6f877
cmpl $0x1, %edx
ja 0x6f877
shrl %esi
movq %r12, %rdi
callq 0x6f8da
movq 0x28(%rsp), %r12
incl 0x24(%rsp)
jmp 0x6f877
movq 0x1e3735(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1740b8(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x28(%rsp), %r12
jmp 0x6f873
movl 0x24(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq