// File: /workspace/github_cpp_makefile_star2_O3/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, %r11d
movq 0x28(%rdi), %rcx
movl %edx, %eax
movq (%rcx,%rax,8), %rax
movl %ebp, %edx
movq (%rcx,%rdx,8), %r14
movl %eax, %edx
xorq $0x1, %rdx
movl %r14d, %esi
xorq $0x1, %rsi
orq %rdx, %rsi
jne 0xa8620
movq %rdi, %r10
movq %r8, 0x18(%rsp)
movq %r9, 0x20(%rsp)
movq 0x8(%rdi), %rbx
shrq $0x20, %rax
leaq (%rax,%rax,2), %r12
movl 0x8(%rbx,%r12,8), %eax
xorq $0x1, %rax
movq (%rcx,%rax,8), %r15
testl %r15d, %r15d
jle 0xa83e2
movq %r15, %rax
shrq $0x20, %rax
movl %r15d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax,8), %rsi
addq $0x8, %rsi
xorl %eax, %eax
movl $0x1, %edi
movl (%rsi), %r8d
xorl %r13d, %r8d
cmpl $0x2, %r8d
cmovbl %edi, %eax
addq $0x18, %rsi
decq %rdx
jne 0xa8215
movq %rbx, %rdx
testl %eax, %eax
je 0xa83e5
cmpl $0x2, %r15d
jne 0xa842e
leaq (%rbx,%r12,8), %rax
addq $0x8, %rax
movl (%rax), %r12d
movq %r12, %rax
xorq $0x1, %rax
movq %rax, 0x10(%rsp)
movl 0x4(%rcx,%rax,8), %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%rdx,%rax,8), %eax
shrl %r12d
xorq $0x1, %rax
movq (%rcx,%rax,8), %r15
testl %r15d, %r15d
jle 0xa86d5
movq %r15, %rsi
shrq $0x20, %rsi
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdi
addq $0x8, %rdi
xorl %esi, %esi
movl $0x1, %r8d
movl (%rdi), %r9d
shrl %r9d
cmpl %r12d, %r9d
cmovel %r8d, %esi
addq $0x18, %rdi
decq %rax
jne 0xa829a
testl %esi, %esi
je 0xa86d8
cmpl $0x1, %r15d
jne 0xa842e
movq 0x10(%rsp), %rax
movl 0x4(%rcx,%rax,8), %eax
leaq (%rax,%rax,2), %rax
movl 0x20(%rdx,%rax,8), %eax
xorq $0x1, %rax
movq (%rcx,%rax,8), %r15
testl %r15d, %r15d
jle 0xa8753
movq %r15, %rsi
shrq $0x20, %rsi
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdi
addq $0x8, %rdi
xorl %esi, %esi
movl $0x1, %r8d
movl (%rdi), %r9d
shrl %r9d
cmpl %r12d, %r9d
cmovel %r8d, %esi
addq $0x18, %rdi
decq %rax
jne 0xa8307
testl %esi, %esi
je 0xa8756
cmpl $0x1, %r15d
jne 0xa842e
movq 0x10(%rsp), %rax
movl 0x4(%rcx,%rax,8), %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%rdx,%rax,8), %esi
movl %r11d, %r12d
shrl %r12d
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r10, %rdi
movl %r12d, %edx
movq %r10, %r15
movl %r11d, 0x4(%rsp)
callq 0xa45ed
movq %rax, 0x8(%rsp)
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movq 0x10(%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 0xa45ed
movq 0x8(%rsp), %r8
movq %rax, %rcx
orq %r8, %rcx
movq 0x8(%r15), %rdx
movq 0x28(%r15), %rcx
js 0xa8426
movq 0x10(%rsp), %r12
movl 0x4(%rcx,%r12,8), %ecx
leaq (%rcx,%rcx,2), %rcx
xorl $0x1, %r13d
cmpq $0x1, %r8
jne 0xa8669
cmpl %r13d, 0x8(%rdx,%rcx,8)
jne 0xa8669
movq 0x18(%rsp), %rcx
movq $0x1, (%rcx)
movq 0x20(%rsp), %rcx
jmp 0xa8618
xorl %r15d, %r15d
movq 0x1ecbf4(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x190d24(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, 0x8(%rsp)
movl %r11d, 0x4(%rsp)
callq 0x2410
movl 0x4(%rsp), %r11d
movq 0x8(%rsp), %r10
movq 0x8(%r10), %rdx
movq 0x28(%r10), %rcx
jmp 0xa8236
movq %r15, %r10
movl 0x4(%rsp), %r11d
shrq $0x20, %r14
leaq (%r14,%r14,2), %r14
movl 0x8(%rbx,%r14,8), %eax
xorq $0x1, %rax
movq (%rcx,%rax,8), %r15
testl %r15d, %r15d
jle 0xa8635
movq %r15, %rcx
shrq $0x20, %rcx
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
xorl %ebp, %edi
cmpl $0x2, %edi
cmovbl %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa846e
testl %ecx, %ecx
je 0xa8638
cmpl $0x2, %r15d
jne 0xa8620
leaq (%rbx,%r14,8), %rax
addq $0x8, %rax
movl (%rax), %ebx
movq %rbx, %r12
xorq $0x1, %r12
movq 0x8(%r10), %rcx
movq 0x28(%r10), %rax
movl 0x4(%rax,%r12,8), %edx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rcx,%rdx,8), %edx
shrl %ebx
xorq $0x1, %rdx
movq (%rax,%rdx,8), %r14
testl %r14d, %r14d
jle 0xa8719
movq %r14, %rdx
shrq $0x20, %rdx
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebx, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa84ee
testl %ecx, %ecx
je 0xa871c
cmpl $0x1, %r14d
jne 0xa8620
movq 0x8(%r10), %rcx
movq 0x28(%r10), %rax
movl 0x4(%rax,%r12,8), %edx
leaq (%rdx,%rdx,2), %rdx
movl 0x20(%rcx,%rdx,8), %edx
xorq $0x1, %rdx
movq (%rax,%rdx,8), %r14
testl %r14d, %r14d
jle 0xa8793
movq %r14, %rdx
shrq $0x20, %rdx
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebx, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa855a
testl %ecx, %ecx
je 0xa8796
xorl %r13d, %r13d
cmpl $0x1, %r14d
jne 0xa8623
movq 0x8(%r10), %rax
movq 0x28(%r10), %rcx
movl 0x4(%rcx,%r12,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
shrl %r11d
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r10, %rdi
movl %r11d, %edx
movq %r10, %r14
movl %r11d, %r15d
callq 0xa45ed
movq %rax, %rbx
movq 0x8(%r14), %rax
movq 0x28(%r14), %rcx
movl 0x4(%rcx,%r12,8), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x20(%rax,%rcx,8), %esi
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r14, %rdi
movl %r15d, %edx
callq 0xa45ed
movq %rax, %rcx
orq %rbx, %rcx
js 0xa8623
movq 0x8(%r14), %rcx
movq 0x28(%r14), %rdx
movl 0x4(%rdx,%r12,8), %edx
leaq (%rdx,%rdx,2), %rdx
xorl $0x1, %ebp
cmpq $0x1, %rbx
jne 0xa8697
cmpl %ebp, 0x8(%rcx,%rdx,8)
jne 0xa8697
movq 0x20(%rsp), %rcx
movq $0x1, (%rcx)
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
jmp 0xa86c2
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movq 0x1ec9a1(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x190ad1(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, %r12
movl %r11d, %r13d
callq 0x2410
movl %r13d, %r11d
movq %r12, %r10
jmp 0xa8489
cmpq $0x1, %rax
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
jne 0xa87c7
leaq (%rdx,%rcx,8), %rax
cmpl %r13d, 0x20(%rax)
jne 0xa87c7
movq $0x1, (%rdi)
movq %r8, (%rsi)
jmp 0xa86c2
cmpq $0x1, %rax
jne 0xa87d1
leaq (%rcx,%rdx,8), %rax
cmpl %ebp, 0x20(%rax)
jne 0xa87d1
movq 0x20(%rsp), %rax
movq $0x1, (%rax)
movq 0x18(%rsp), %rax
movq %rbx, (%rax)
movq 0x60(%rsp), %rax
movl %r12d, (%rax)
movl $0x1, %r13d
jmp 0xa8623
xorl %r15d, %r15d
movq 0x1ec901(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x190a31(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, 0x8(%rsp)
movl %r11d, 0x4(%rsp)
callq 0x2410
movl 0x4(%rsp), %r11d
movq 0x8(%rsp), %r10
movq 0x8(%r10), %rdx
movq 0x28(%r10), %rcx
jmp 0xa82b8
xorl %r14d, %r14d
movq 0x1ec8bd(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1909ed(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, %r15
movq %r12, %r13
movl %r11d, %r12d
callq 0x2410
movl %r12d, %r11d
movq %r13, %r12
movq %r15, %r10
jmp 0xa8508
xorl %r15d, %r15d
movq 0x1ec883(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1909b3(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, 0x8(%rsp)
movl %r11d, %r12d
callq 0x2410
movl %r12d, %r11d
movq 0x8(%rsp), %r10
movq 0x8(%r10), %rdx
movq 0x28(%r10), %rcx
jmp 0xa8325
xorl %r14d, %r14d
movq 0x1ec843(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x190973(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, %rbx
movl %r11d, %r15d
callq 0x2410
movl %r15d, %r11d
movq %rbx, %r10
jmp 0xa8574
callq 0x10017
jmp 0xa86c2
callq 0x10033
jmp 0xa86c2