// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_single_node_bubble_directly(asg_t*, unsigned int, long long, ma_hit_t_alloc*)
int test_single_node_bubble_directly(asg_t *g, uint32_t v, long long longLen_thres, ma_hit_t_alloc* sources)
{
    uint32_t w, vEnd;
    int flag0, flag1;
    int n_reduced = 0;
    long long Len[2], longLen;
    ///long long longLen_thres = 4;

    uint32_t nv = asg_arc_n(g, v);
    asg_arc_t *av = asg_arc_a(g, v);
    if(nv != 2)
    {
        return 0;
    }

    
    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)
    {
        return 0;
    }

    if(check_small_bubble(g, v, av[0].v, av[1].v, &(Len[0]), &(Len[1]), &vEnd))
    {
        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)
            if(asg_arc_a(g, w)[0].el == 0 || asg_arc_a(g, w^1)[0].el == 0 || sources[w>>1].is_abnormal == 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)
            if(asg_arc_a(g, w)[0].el == 0 || asg_arc_a(g, w^1)[0].el == 0 || sources[w>>1].is_abnormal == 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)
        {
            flag0 = sources[av[0].v>>1].is_abnormal;
            flag1 = sources[av[1].v>>1].is_abnormal;

            if(flag0 == 1 && flag1 == 0)
            {
                asg_seq_del(g, av[0].v>>1);
                n_reduced++;
            }
            else if(flag0 == 0 && flag1 == 1)
            {
                asg_seq_del(g, av[1].v>>1);
                n_reduced++;
            }
            else
            {
                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)
                    {
                        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)
                    {
                        asg_seq_del(g, w>>1);
                        n_reduced++;
                    }
                    /****************************may have bugs********************************/
                }
            }
        }
        
    }
    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq 0x28(%rdi), %rax
movl %esi, %esi
movq (%rax,%rsi,8), %rax
xorl %ebx, %ebx
cmpl $0x2, %eax
jne 0x6fb4b
movq %rdi, %r14
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
shrq $0x20, %rax
imulq $0x18, %rax, %r12
addq 0x8(%rdi), %r12
movl 0x8(%r12), %esi
movl %ebp, %r13d
shrl %r13d
movl %r13d, %edx
callq 0x6c8a1
movl %eax, %r15d
movl 0x20(%r12), %esi
movq %r14, %rdi
movl %r13d, %edx
callq 0x6c8a1
cmpl $0x1, %r15d
jne 0x6fb4b
cmpl $0x1, %eax
jne 0x6fb4b
movl 0x8(%r12), %edx
movl 0x20(%r12), %ecx
leaq 0x28(%rsp), %r9
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
leaq 0x20(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
callq 0x6f23d
testl %eax, %eax
je 0x6fb4b
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq $0x1, %rax
sete %dl
cmpq $0x1, %rcx
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x6fadd
movl 0x8(%r12), %edi
movq 0x8(%r14), %rax
movq 0x28(%r14), %rdx
movl 0x4(%rdx,%rdi,8), %esi
imulq $0x18, %rsi, %rsi
cmpb $0x0, 0x12(%rax,%rsi)
je 0x6fb3c
movq %rdi, %rsi
xorq $0x1, %rsi
movl 0x4(%rdx,%rsi,8), %esi
imulq $0x18, %rsi, %rsi
cmpb $0x0, 0x12(%rax,%rsi)
je 0x6fb3c
movl %edi, %esi
shrl %esi
imulq $0x18, %rsi, %r8
movq 0x10(%rsp), %r9
cmpb $0x1, 0x11(%r9,%r8)
je 0x6fb3c
cmpq 0x18(%rsp), %rcx
jl 0x6fb4b
cmpb $0x1, 0x12(%r12)
jne 0x6fb4b
cmpb $0x1, 0x2a(%r12)
jne 0x6fb4b
movl 0xc(%rsp), %ecx
movl 0x4(%rdx,%rcx,8), %ecx
imulq $0x18, %rcx, %rcx
cmpb $0x1, 0x12(%rax,%rcx)
jne 0x6fb4b
addq %rcx, %rax
cmpb $0x1, 0x2a(%rax)
je 0x6fb40
jmp 0x6fb4b
cmpq $0x1, %rax
setne %dl
cmpq $0x1, %rcx
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x6fb5c
movl 0x20(%r12), %edi
movq 0x8(%r14), %rcx
movq 0x28(%r14), %rdx
movl 0x4(%rdx,%rdi,8), %esi
imulq $0x18, %rsi, %rsi
cmpb $0x0, 0x12(%rcx,%rsi)
je 0x6fb3c
movq %rdi, %rsi
xorq $0x1, %rsi
movl 0x4(%rdx,%rsi,8), %esi
imulq $0x18, %rsi, %rsi
cmpb $0x0, 0x12(%rcx,%rsi)
je 0x6fb3c
movl %edi, %esi
shrl %esi
imulq $0x18, %rsi, %r8
movq 0x10(%rsp), %r9
cmpb $0x1, 0x11(%r9,%r8)
jne 0x6fbac
shrl %edi
movl %edi, %esi
movq %r14, %rdi
callq 0x6f8da
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorq $0x1, %rcx
xorq $0x1, %rax
orq %rcx, %rax
jne 0x6fb4b
movl 0x8(%r12), %edx
movl 0x20(%r12), %ecx
movl %edx, %esi
shrl %esi
imulq $0x18, %rsi, %rax
movq 0x10(%rsp), %r9
movb 0x11(%r9,%rax), %dil
movl %ecx, %eax
shrl %eax
imulq $0x18, %rax, %r8
movb 0x11(%r9,%r8), %r8b
cmpb $0x1, %dil
jne 0x6fb9d
testb %r8b, %r8b
je 0x6fb40
testb %dil, %dil
jne 0x6fbec
cmpb $0x1, %r8b
jne 0x6fbec
movl %eax, %esi
jmp 0x6fb40
cmpq 0x18(%rsp), %rax
jl 0x6fb4b
cmpb $0x1, 0x12(%r12)
jne 0x6fb4b
cmpb $0x1, 0x2a(%r12)
jne 0x6fb4b
movl 0xc(%rsp), %eax
movl 0x4(%rdx,%rax,8), %eax
imulq $0x18, %rax, %rax
cmpb $0x1, 0x12(%rcx,%rax)
jne 0x6fb4b
addq %rax, %rcx
cmpb $0x1, 0x2a(%rcx)
je 0x6fb40
jmp 0x6fb4b
movq 0x8(%r14), %rdi
movq 0x28(%r14), %r8
movl 0x4(%r8,%rdx,8), %r9d
imulq $0x18, %r9, %r9
movzbl 0x12(%rdi,%r9), %r9d
xorl $0x1, %edx
movl 0x4(%r8,%rdx,8), %edx
imulq $0x18, %rdx, %rdx
movzbl 0x12(%rdi,%rdx), %edx
addl %r9d, %edx
movl 0x4(%r8,%rcx,8), %r9d
imulq $0x18, %r9, %r9
movzbl 0x12(%rdi,%r9), %r9d
xorl $0x1, %ecx
movl 0x4(%r8,%rcx,8), %ecx
imulq $0x18, %rcx, %rcx
movzbl 0x12(%rdi,%rcx), %ecx
addl %r9d, %ecx
cmpl $0x1, %edx
ja 0x6fc48
cmpl $0x1, %ecx
ja 0x6fb40
cmpl $0x2, %edx
jb 0x6fb4b
movl %eax, %esi
cmpl $0x1, %ecx
jbe 0x6fb40
jmp 0x6fb4b