// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rdx, %r12
movq %rcx, 0x10(%rsp)
andq $0x0, (%rcx)
movl %esi, %ebp
movq %rdi, %r15
movl %r9d, %eax
movq %rax, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movq 0x8(%r15), %r13
movq 0x28(%r15), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %r14
movl %ebp, (%r12)
movq 0x10(%rsp), %rdx
movq (%rdx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rdx)
cmpq 0x28(%rsp), %rax
jge 0x6cdb5
testq %rbx, %rbx
je 0x6cd07
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0x6ccf8
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
movl %ebp, %edx
shrl %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%rbx)
movl %edx, (%rax,%rcx,4)
testl %r14d, %r14d
je 0x6cdbc
movq %r14, %rax
shrq $0x20, %rax
cmpl $0x2, %r14d
je 0x6cd64
ja 0x6cdc3
imulq $0x18, %rax, %r14
movl 0x8(%r13,%r14), %esi
shrl %ebp
movq %r15, %rdi
movl %ebp, %edx
callq 0x6c8a1
movl 0x8(%r13,%r14), %ebp
movl %ebp, (%r12)
cmpl $0x2, %eax
je 0x6cdca
ja 0x6ce1c
movl %ebp, %eax
xorl 0x1c(%rsp), %eax
cmpl $0x1, %eax
ja 0x6cc93
jmp 0x6ce6e
movl %ebp, 0xc(%rsp)
testq %rbx, %rbx
je 0x6cd76
movq 0x38(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %r15, %rdi
movl %ebp, %esi
leaq 0xc(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %rbx, %r8
callq 0x6caf4
testl %eax, %eax
je 0x6ce80
movq 0x10(%rsp), %rdx
movq (%rdx), %rax
movq 0x30(%rsp), %rcx
addq %rcx, %rax
addq $-0x2, %rax
movq %rax, (%rdx)
movl 0xc(%rsp), %ebp
jmp 0x6cc93
pushq $0x6
jmp 0x6ce70
pushq $0x5
jmp 0x6ce70
pushq $0x4
jmp 0x6ce70
testq %rbx, %rbx
je 0x6ce10
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0x6ce03
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
shrl %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
incq (%rax)
pushq $0x1
jmp 0x6ce70
testq %rbx, %rbx
je 0x6ce62
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0x6ce55
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
shrl %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
incq (%rax)
pushq $0x3
jmp 0x6ce70
pushq $0x7
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rax
testq %rbx, %rbx
je 0x6ce71
movq 0x20(%rsp), %rcx
movq %rcx, 0x38(%rbx)
jmp 0x6ce71