// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_single_path_with_single_bubbles(asg_t*, unsigned int, unsigned int*, long long*, buf_t*, unsigned int)
uint32_t detect_single_path_with_single_bubbles(asg_t *g, uint32_t begNode, uint32_t* endNode, 
long long* Len, buf_t* b, uint32_t max_ext)
{
    
    uint32_t v = begNode;
    uint32_t nv, rnv;
    asg_arc_t *av;
    long long bLen;
    long long pre_b_n = 0;
    (*Len) = 0;

    
    
    while (1)
    {
        nv = asg_arc_n(g, v);
        av = asg_arc_a(g, v);   
        (*endNode) = v;
        (*Len)++;


        if((*Len) > max_ext)
        {
            return LONG_TIPS_UNDER_MAX_EXT;
        }

        
        if(b) kv_push(uint32_t, b->b, v>>1);

 

        if(nv == 0)
        {
            return END_TIPS;
        }

        if(nv == 2)
        {


            if(b) pre_b_n = b->b.n;
            if(!detect_simple_bubble(g, v, &v, &bLen, b))
            {
                if(b) b->b.n = pre_b_n;
                return TWO_OUTPUT;
            }

            (*Len) = (*Len) + bLen - 2;
            continue;
        }

        if(nv > 2)
        {
            return MUL_OUTPUT;
        }

        ///up to here, nv=1
        ///rnv must >= 1
        rnv = asg_is_single_edge(g, av[0].v, v>>1);
        v = av[0].v;
        (*endNode) = v;
        if(rnv == 2)
        {
            if(b) kv_push(uint32_t, b->b, v>>1);
            (*Len)++;
            return TWO_INPUT;
        }

        if(rnv > 2)
        {
            if(b) kv_push(uint32_t, b->b, v>>1);
            (*Len)++;
            return MUL_INPUT;
        } 

        if((v>>1) == (begNode>>1))
        {
            return LOOP;
        }  
    }

    return LONG_TIPS;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movq %rdx, 0x20(%rsp)
movl %esi, %ebp
movq %rdi, %r12
movq $0x0, (%rcx)
movl %r9d, %eax
movq %rax, 0x30(%rsp)
movl $0x1, %r13d
movl %esi, 0x1c(%rsp)
movq %rcx, 0x10(%rsp)
movq 0x8(%r12), %rbx
movq 0x28(%r12), %rax
movl %ebp, %edx
movq (%rax,%rdx,8), %r15
movq 0x20(%rsp), %rax
movl %ebp, (%rax)
movq (%rcx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rcx)
cmpq 0x30(%rsp), %rax
jge 0xa4e21
testq %r14, %r14
je 0xa4cca
movq 0x38(%r14), %rdi
movq 0x48(%r14), %rax
cmpq 0x40(%r14), %rdi
jne 0xa4cbb
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%r14)
movq 0x38(%r14), %rdi
movl %ebp, %edx
shrl %edx
leaq 0x1(%rdi), %rsi
movq %rsi, 0x38(%r14)
movl %edx, (%rax,%rdi,4)
cmpl $0x2, %r15d
je 0xa4d7d
testl %r15d, %r15d
je 0xa4e2b
cmpl $0x2, %r15d
ja 0xa4e35
shrq $0x20, %r15
leaq (%r15,%r15,2), %rax
movl 0x8(%rbx,%rax,8), %r9d
movq 0x28(%r12), %rsi
movq %r9, %rdx
xorq $0x1, %rdx
movq (%rsi,%rdx,8), %r15
testl %r15d, %r15d
jle 0xa4de9
movq 0x8(%r12), %rdx
movq %r15, %rsi
shrq $0x20, %rsi
movl %r15d, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl (%rsi), %edi
xorl %ebp, %edi
cmpl $0x2, %edi
cmovbl %r13d, %edx
addq $0x18, %rsi
decq %r8
jne 0xa4d31
testl %edx, %edx
je 0xa4dec
movq 0x20(%rsp), %rax
movl %r9d, (%rax)
cmpl $0x2, %r15d
je 0xa4e3f
ja 0xa4e9e
movl %r9d, %eax
xorl 0x1c(%rsp), %eax
movl %r9d, %ebp
cmpl $0x1, %eax
ja 0xa4c4f
jmp 0xa4efd
movl %ebp, 0xc(%rsp)
testq %r14, %r14
je 0xa4daa
movq 0x38(%r14), %rbx
movq %r12, %rdi
movl %ebp, %esi
leaq 0xc(%rsp), %rdx
leaq 0x28(%rsp), %rcx
movq %r14, %r8
callq 0xa49ad
testl %eax, %eax
jne 0xa4dc9
jmp 0xa4f04
movq %r12, %rdi
movl %ebp, %esi
leaq 0xc(%rsp), %rdx
leaq 0x28(%rsp), %rcx
xorl %r8d, %r8d
callq 0xa49ad
testl %eax, %eax
je 0xa4f08
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x28(%rsp), %rdx
addq %rdx, %rax
addq $-0x2, %rax
movq %rax, (%rcx)
movl 0xc(%rsp), %ebp
jmp 0xa4c4f
xorl %r15d, %r15d
leaq (%rbx,%rax,8), %rbx
addq $0x8, %rbx
movq 0x1f01e5(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x19430b(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x10(%rsp), %rcx
movl (%rbx), %r9d
jmp 0xa4d4d
movl $0x6, %eax
jmp 0xa4f0d
movl $0x5, %eax
jmp 0xa4f0d
movl $0x4, %eax
jmp 0xa4f0d
testq %r14, %r14
je 0xa4e94
movq 0x38(%r14), %rsi
movq 0x48(%r14), %rax
cmpq 0x40(%r14), %rsi
jne 0xa4e85
leaq (%rsi,%rsi), %rdx
testq %rsi, %rsi
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x40(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r9, %rbx
callq 0x2370
movq %rbx, %r9
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%r14)
movq 0x38(%r14), %rsi
shrl %r9d
leaq 0x1(%rsi), %rdx
movq %rdx, 0x38(%r14)
movl %r9d, (%rax,%rsi,4)
incq (%rcx)
movl $0x1, %eax
jmp 0xa4f0d
testq %r14, %r14
je 0xa4ef3
movq 0x38(%r14), %rsi
movq 0x48(%r14), %rax
cmpq 0x40(%r14), %rsi
jne 0xa4ee4
leaq (%rsi,%rsi), %rdx
testq %rsi, %rsi
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x40(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r9, %rbx
callq 0x2370
movq %rbx, %r9
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%r14)
movq 0x38(%r14), %rsi
shrl %r9d
leaq 0x1(%rsi), %rdx
movq %rdx, 0x38(%r14)
movl %r9d, (%rax,%rsi,4)
incq (%rcx)
movl $0x3, %eax
jmp 0xa4f0d
movl $0x7, %eax
jmp 0xa4f0d
movq %rbx, 0x38(%r14)
movl $0x2, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq