// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: check_small_bubble(asg_t*, unsigned int, unsigned int, unsigned int, long long*, long long*, unsigned int*)
int check_small_bubble(asg_t *g, uint32_t begNode, uint32_t v, uint32_t w, 
long long* vLen, long long* wLen, uint32_t* endNode)
{
    uint32_t nv = asg_arc_n(g, v);
    uint32_t nw = asg_arc_n(g, w);

    asg_arc_t *av = asg_arc_a(g, v);
    asg_arc_t *aw = asg_arc_a(g, w);
    if(nv != 1 || nw != 1)
    {
        return 0;
    }

    ///first node
    ///nv must be 1
    if(asg_is_single_edge(g, av[0].v, v>>1) == 2)
    {
        uint32_t vv;
        vv = av[0].v^1;

        if(
            asg_is_single_edge(g, asg_arc_a(g, vv)[0].v, vv>>1) == 1
            &&
            asg_is_single_edge(g, asg_arc_a(g, vv)[1].v, vv>>1) == 1
            )
        {
            ///walk along first path
            long long pLen1;
            pLen1 = single_edge_length(g, asg_arc_a(g, vv)[0].v, begNode>>1, 1000);

            ///walk along first path
            long long pLen2;
            pLen2 = single_edge_length(g, asg_arc_a(g, vv)[1].v, begNode>>1, 1000);



            if(pLen1 >= 0 && pLen2 >= 0)
            {
                if(((asg_arc_a(g, vv)[0].v) == (v^1)) && pLen1 == 1)
                {
                    (*vLen) = pLen1;
                    (*wLen) = pLen2;
                }
                else if(((asg_arc_a(g, vv)[1].v) == (v^1)) && pLen2 == 1)
                {
                    (*vLen) = pLen2;
                    (*wLen) = pLen1;
                }
                else
                {
                    fprintf(stderr, "error\n");
                }
                ///(*endNode) = vv>>1;
                (*endNode) = vv;
                return 1;
            }

        }
    }


    ///second node
    ///nw must be 1
    if(asg_is_single_edge(g, aw[0].v, w>>1) == 2)
    {
        uint32_t ww;
        ww = aw[0].v^1;

        if(
            asg_is_single_edge(g, asg_arc_a(g, ww)[0].v, ww>>1) == 1
            &&
            asg_is_single_edge(g, asg_arc_a(g, ww)[1].v, ww>>1) == 1
            )
        {
            ///walk along first path
            long long pLen1;
            pLen1 = single_edge_length(g, asg_arc_a(g, ww)[0].v, begNode>>1, 1000);

            ///walk along first path
            long long pLen2;
            pLen2 = single_edge_length(g, asg_arc_a(g, ww)[1].v, begNode>>1, 1000);

            if(pLen1 >= 0 && pLen2 >= 0)
            {
                if(((asg_arc_a(g, ww)[0].v) == (w^1)) && pLen1 == 1)
                {
                    (*wLen) = pLen1;
                    (*vLen) = pLen2;
                }
                else if(((asg_arc_a(g, ww)[1].v) == (w^1)) && pLen2 == 1)
                {
                    (*wLen) = pLen2;
                    (*vLen) = pLen1;
                }
                else
                {
                    fprintf(stderr, "error\n");
                }

                //(*endNode) = ww>>1;
                (*endNode) = ww;

                return 1;
            }
       }
    }

    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebp
movl %edx, %r13d
movl %esi, %r10d
movq 0x28(%rdi), %rax
movl %edx, %ecx
movq (%rax,%rcx,8), %rcx
movl %ebp, %edx
movq (%rax,%rdx,8), %r14
movl %ecx, %edx
xorq $0x1, %rdx
movl %r14d, %esi
xorq $0x1, %rsi
orq %rdx, %rsi
jne 0xa751f
movq %rdi, %r15
movq 0x8(%rdi), %r11
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r12
movl 0x8(%r11,%r12,8), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %ebx, %ebx
testl %eax, %eax
movq %r11, 0x20(%rsp)
jle 0xa71dd
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%r11,%rdx,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
xorl %r13d, %edi
cmpl $0x2, %edi
cmovbl %esi, %ebx
addq $0x18, %rdx
decq %rcx
jne 0xa71bc
testl %ebx, %ebx
sete %cl
cmpl $0x2, %eax
sete %bl
jmp 0xa71df
movb $0x1, %cl
testb %cl, %cl
jne 0xa75f6
testb %bl, %bl
je 0xa73b2
movq 0x20(%rsp), %rax
leaq (%rax,%r12,8), %rax
addq $0x8, %rax
movl (%rax), %r12d
movq %r12, %r11
xorq $0x1, %r11
movq 0x8(%r15), %rdx
movq 0x28(%r15), %rax
movl 0x4(%rax,%r11,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rdx,%rcx,8), %ecx
shrl %r12d
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %ebx, %ebx
testl %eax, %eax
jle 0xa726c
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r12d, %edi
cmovel %esi, %ebx
addq $0x18, %rdx
decq %rcx
jne 0xa724c
testl %ebx, %ebx
sete %cl
cmpl $0x1, %eax
sete %bl
jmp 0xa726e
movb $0x1, %cl
testb %cl, %cl
jne 0xa76a4
testb %bl, %bl
je 0xa73b2
movq 0x8(%r15), %rdx
movq 0x28(%r15), %rax
movl 0x4(%rax,%r11,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x20(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %ebx, %ebx
testl %eax, %eax
jle 0xa72e1
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r12d, %edi
cmovel %esi, %ebx
addq $0x18, %rdx
decq %rcx
jne 0xa72c1
testl %ebx, %ebx
sete %cl
cmpl $0x1, %eax
sete %bl
jmp 0xa72e3
movb $0x1, %cl
testb %cl, %cl
jne 0xa7700
testb %bl, %bl
je 0xa73b2
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r11,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
movl %r10d, %r12d
shrl %r12d
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r12d, %edx
movq %r9, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl %r10d, 0x4(%rsp)
movq %r11, 0x18(%rsp)
callq 0xa35b2
movq %rax, %rbx
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movq 0x18(%rsp), %rdx
movl 0x4(%rcx,%rdx,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x20(%rax,%rcx,8), %esi
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r12d, %edx
callq 0xa35b2
movq 0x18(%rsp), %rsi
movl 0x4(%rsp), %r10d
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
movq %rax, %rcx
orq %rbx, %rcx
js 0xa73b2
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdx
movl 0x4(%rdx,%rsi,8), %edx
leaq (%rdx,%rdx,2), %rdx
xorl $0x1, %r13d
cmpq $0x1, %rbx
jne 0xa7642
cmpl %r13d, 0x8(%rcx,%rdx,8)
jne 0xa7642
movq $0x1, (%r8)
movq %rax, (%r9)
jmp 0xa7692
shrq $0x20, %r14
leaq (%r14,%r14,2), %r14
movq 0x20(%rsp), %rbx
movl 0x8(%rbx,%r14,8), %eax
movq 0x28(%r15), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %r12d, %r12d
testl %eax, %eax
jle 0xa741e
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), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
xorl %ebp, %edi
cmpl $0x2, %edi
cmovbl %esi, %r12d
addq $0x18, %rdx
decq %rcx
jne 0xa73fb
testl %r12d, %r12d
sete %cl
cmpl $0x2, %eax
sete %r12b
jmp 0xa7420
movb $0x1, %cl
testb %cl, %cl
jne 0xa761e
testb %r12b, %r12b
je 0xa751f
leaq (%rbx,%r14,8), %rax
addq $0x8, %rax
movl (%rax), %ebx
movq %rbx, %r11
xorq $0x1, %r11
movq 0x8(%r15), %rdx
movq 0x28(%r15), %rax
movl 0x4(%rax,%r11,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rdx,%rcx,8), %ecx
shrl %ebx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %r14d, %r14d
testl %eax, %eax
jle 0xa74aa
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebx, %edi
cmovel %esi, %r14d
addq $0x18, %rdx
decq %rcx
jne 0xa7488
testl %r14d, %r14d
sete %cl
cmpl $0x1, %eax
sete %r14b
jmp 0xa74ac
movb $0x1, %cl
testb %cl, %cl
jne 0xa76d6
testb %r14b, %r14b
je 0xa751f
movq 0x8(%r15), %rdx
movq 0x28(%r15), %rax
movl 0x4(%rax,%r11,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x20(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %r14d, %r14d
testl %eax, %eax
jle 0xa7534
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebx, %edi
cmovel %esi, %r14d
addq $0x18, %rdx
decq %rcx
jne 0xa74fd
testl %r14d, %r14d
sete %cl
cmpl $0x1, %eax
sete %r14b
jmp 0xa7536
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %cl
testb %cl, %cl
jne 0xa772e
xorl %r13d, %r13d
testb %r14b, %r14b
je 0xa7522
movq %r8, 0x10(%rsp)
movq %r9, 0x8(%rsp)
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r11,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
shrl %r10d
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r10d, %edx
movl %r10d, %r12d
movq %r11, %r14
callq 0xa35b2
movq %rax, %rbx
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r14,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x20(%rax,%rcx,8), %esi
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r12d, %edx
callq 0xa35b2
movq %rax, %rcx
orq %rbx, %rcx
js 0xa7522
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdx
movl 0x4(%rdx,%r14,8), %edx
leaq (%rdx,%rdx,2), %rdx
xorl $0x1, %ebp
cmpq $0x1, %rbx
movq %r14, %rsi
jne 0xa7666
cmpl %ebp, 0x8(%rcx,%rdx,8)
jne 0xa7666
movq 0x8(%rsp), %rcx
movq $0x1, (%rcx)
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
jmp 0xa7692
movq %r9, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl %r10d, 0x4(%rsp)
callq 0x1009c
movl 0x4(%rsp), %r10d
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
jmp 0xa71e7
movq %r9, 0x8(%rsp)
movq %r8, %r13
movl %r10d, 0x4(%rsp)
callq 0x1010c
movl 0x4(%rsp), %r10d
movq %r13, %r8
movq 0x8(%rsp), %r9
jmp 0xa7428
cmpq $0x1, %rax
jne 0xa7754
leaq (%rcx,%rdx,8), %rax
cmpl %r13d, 0x20(%rax)
jne 0xa7754
movq $0x1, (%r8)
movq %rbx, (%r9)
jmp 0xa7692
cmpq $0x1, %rax
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r12
jne 0xa7763
leaq (%rcx,%rdx,8), %rax
cmpl %ebp, 0x20(%rax)
jne 0xa7763
movq $0x1, (%r14)
movq %rbx, (%r12)
movq 0x60(%rsp), %rax
movl %esi, (%rax)
movl $0x1, %r13d
jmp 0xa7522
movq %r9, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl %r10d, 0x4(%rsp)
movq %r11, 0x18(%rsp)
callq 0x100b8
movq 0x18(%rsp), %r11
movl 0x4(%rsp), %r10d
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
jmp 0xa7276
movq %r9, 0x8(%rsp)
movq %r8, %r13
movl %r10d, 0x4(%rsp)
movq %r11, %r12
callq 0x10128
movq %r12, %r11
movl 0x4(%rsp), %r10d
movq %r13, %r8
movq 0x8(%rsp), %r9
jmp 0xa74b4
movq %r9, 0x8(%rsp)
movq %r8, %r12
movl %r10d, 0x4(%rsp)
movq %r11, 0x18(%rsp)
callq 0x100d4
movq 0x18(%rsp), %r11
movl 0x4(%rsp), %r10d
movq %r12, %r8
movq 0x8(%rsp), %r9
jmp 0xa72eb
movq %r9, 0x8(%rsp)
movq %r8, %r12
movl %r10d, %r13d
movq %r11, %rbx
callq 0x10144
movq %rbx, %r11
movl %r13d, %r10d
movq %r12, %r8
movq 0x8(%rsp), %r9
jmp 0xa753e
callq 0x100f0
movq 0x18(%rsp), %rsi
jmp 0xa7692
movq %rsi, %rbx
callq 0x10160
movq %rbx, %rsi
jmp 0xa7692