// File: /workspace/github_cpp_makefile_star2_O2/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 %edx, %ebx
movq %rdi, %r15
movq 0x28(%rdi), %rdi
movl %edx, %eax
movq (%rdi,%rax,8), %rax
movl %ecx, %edx
movq (%rdi,%rdx,8), %r12
movl %eax, %r10d
xorq $0x1, %r10
movl %r12d, %edx
xorq $0x1, %rdx
xorl %edi, %edi
orq %r10, %rdx
jne 0x6f4db
movl %esi, 0x4(%rsp)
movl %ecx, 0x1c(%rsp)
movq %r8, 0x8(%rsp)
movq %r9, 0x10(%rsp)
movq 0x8(%r15), %r13
shrq $0x20, %rax
imulq $0x18, %rax, %r14
movl 0x8(%r13,%r14), %esi
movl %ebx, %edx
shrl %edx
movq %r15, %rdi
callq 0x6c8a1
cmpl $0x2, %eax
jne 0x6f3b8
leaq (%r14,%r13), %rax
addq $0x8, %rax
movl (%rax), %r14d
movq %r14, %rbp
xorq $0x1, %rbp
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%rbp,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
shrl %r14d
movq %r15, %rdi
movl %r14d, %edx
callq 0x6c8a1
cmpl $0x1, %eax
jne 0x6f3b8
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%rbp,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x20(%rax,%rcx), %esi
movq %r15, %rdi
movl %r14d, %edx
callq 0x6c8a1
cmpl $0x1, %eax
jne 0x6f3b8
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%rbp,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
movl 0x4(%rsp), %r14d
shrl %r14d
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r14d, %edx
callq 0x6c811
movq %rax, 0x20(%rsp)
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%rbp,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x20(%rax,%rcx), %esi
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r14d, %edx
callq 0x6c811
movq 0x20(%rsp), %rdi
movq %rax, %rcx
orq %rdi, %rcx
js 0x6f3b8
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdx
movl 0x4(%rdx,%rbp,8), %edx
imulq $0x18, %rdx, %rdx
xorl $0x1, %ebx
cmpq $0x1, %rdi
movq %rbp, %r14
jne 0x6f4ec
cmpl %ebx, 0x8(%rcx,%rdx)
jne 0x6f4ec
movq 0x8(%rsp), %rcx
movq $0x1, (%rcx)
movq 0x10(%rsp), %rcx
jmp 0x6f4d4
shrq $0x20, %r12
imulq $0x18, %r12, %rbx
movl 0x8(%r13,%rbx), %esi
movl 0x1c(%rsp), %ebp
movl %ebp, %edx
shrl %edx
movq %r15, %rdi
callq 0x6c8a1
cmpl $0x2, %eax
jne 0x6f4d9
leaq (%rbx,%r13), %rax
addq $0x8, %rax
movl (%rax), %ebx
movq %rbx, %r14
xorq $0x1, %r14
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r14,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
shrl %ebx
movq %r15, %rdi
movl %ebx, %edx
callq 0x6c8a1
cmpl $0x1, %eax
jne 0x6f4d9
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r14,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x20(%rax,%rcx), %esi
movq %r15, %rdi
movl %ebx, %edx
callq 0x6c8a1
cmpl $0x1, %eax
jne 0x6f4d9
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r14,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
movl 0x4(%rsp), %r12d
shrl %r12d
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r12d, %edx
callq 0x6c811
movq %rax, %rbx
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movl 0x4(%rcx,%r14,8), %ecx
imulq $0x18, %rcx, %rcx
movl 0x20(%rax,%rcx), %esi
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdi
movl %r12d, %edx
callq 0x6c811
movq %rax, %rcx
orq %rbx, %rcx
movl $0x0, %edi
js 0x6f4db
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdx
movl 0x4(%rdx,%r14,8), %edx
imulq $0x18, %rdx, %rdx
xorl $0x1, %ebp
cmpq $0x1, %rbx
jne 0x6f510
cmpl %ebp, 0x8(%rcx,%rdx)
jne 0x6f510
movq 0x10(%rsp), %rcx
movq $0x1, (%rcx)
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x6f532
xorl %edi, %edi
movl %edi, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x1, %rax
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rsi
jne 0x6f53f
addq %rdx, %rcx
cmpl %ebx, 0x20(%rcx)
jne 0x6f53f
movq $0x1, (%rsi)
movq %rdi, (%rax)
jmp 0x6f532
cmpq $0x1, %rax
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rsi
jne 0x6f53f
addq %rdx, %rcx
cmpl %ebp, 0x20(%rcx)
jne 0x6f53f
movq $0x1, (%rax)
movq %rbx, (%rsi)
movq 0x60(%rsp), %rax
movl %r14d, (%rax)
pushq $0x1
popq %rdi
jmp 0x6f4db
movq 0x1e3a9a(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x17441d(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0x6f532