// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x14(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpl $0x2, -0x5c(%rbp)
je 0xd9678
movl $0x0, -0x4(%rbp)
jmp 0xd9c3d
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x14(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x14(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x38(%rbp)
cmpl $0x1, -0x34(%rbp)
jne 0xd96b4
cmpl $0x1, -0x38(%rbp)
je 0xd96c0
movl $0x0, -0x4(%rbp)
jmp 0xd9c3d
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x68(%rbp), %rax
movl 0x20(%rax), %ecx
leaq -0x50(%rbp), %r8
leaq -0x50(%rbp), %r9
addq $0x8, %r9
leaq -0x30(%rbp), %rax
movq %rax, (%rsp)
callq 0xd8a50
cmpl $0x0, %eax
je 0xd9c37
cmpq $0x1, -0x50(%rbp)
jne 0xd984f
cmpq $0x1, -0x48(%rbp)
je 0xd984f
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
je 0xd9795
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
je 0xd9795
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x11(%rax), %eax
cmpl $0x1, %eax
jne 0xd97b1
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd984a
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0xd9848
movq -0x68(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0xd9846
movq -0x68(%rbp), %rax
movzbl 0x2a(%rax), %eax
cmpl $0x1, %eax
jne 0xd9846
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0xd9846
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2a(%rax), %eax
cmpl $0x1, %eax
jne 0xd9846
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd9848
jmp 0xd984a
jmp 0xd9c35
cmpq $0x1, -0x50(%rbp)
je 0xd99a7
cmpq $0x1, -0x48(%rbp)
jne 0xd99a7
movq -0x68(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
je 0xd98ed
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
je 0xd98ed
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x11(%rax), %eax
cmpl $0x1, %eax
jne 0xd9909
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd99a2
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0xd99a0
movq -0x68(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0xd999e
movq -0x68(%rbp), %rax
movzbl 0x2a(%rax), %eax
cmpl $0x1, %eax
jne 0xd999e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0xd999e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2a(%rax), %eax
cmpl $0x1, %eax
jne 0xd999e
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd99a0
jmp 0xd99a2
jmp 0xd9c33
cmpq $0x1, -0x50(%rbp)
jne 0xd9c31
cmpq $0x1, -0x48(%rbp)
jne 0xd9c31
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x11(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movl 0x20(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x11(%rax), %eax
movl %eax, -0x38(%rbp)
cmpl $0x1, -0x34(%rbp)
jne 0xd9a23
cmpl $0x0, -0x38(%rbp)
jne 0xd9a23
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd9c2f
cmpl $0x0, -0x34(%rbp)
jne 0xd9a4f
cmpl $0x1, -0x38(%rbp)
jne 0xd9a4f
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x20(%rax), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd9c2d
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x2c(%rbp), %esi
xorl $0x1, %esi
movl %esi, %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x12(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x68(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x2c(%rbp), %esi
xorl $0x1, %esi
movl %esi, %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x12(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
cmpl $0x2, -0x34(%rbp)
jge 0xd9b9d
cmpl $0x2, -0x38(%rbp)
jl 0xd9b9d
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
je 0xd9b84
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
jne 0xd9b9b
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd9b9d
cmpl $0x2, -0x34(%rbp)
jl 0xd9c2b
cmpl $0x2, -0x38(%rbp)
jge 0xd9c2b
movq -0x68(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
je 0xd9c12
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
jne 0xd9c29
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
shrl %esi
callq 0xd9510
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd9c2b
jmp 0xd9c2d
jmp 0xd9c2f
jmp 0xd9c31
jmp 0xd9c33
jmp 0xd9c35
jmp 0xd9c37
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)