// File: /workspace/github_cpp_makefile_star2_O1/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
leaq 0x8(%rsp), %rax
movl %esi, (%rax)
movq $0x0, (%rcx)
movl %r9d, %r11d
movq $0x0, 0x28(%rsp)
movl $0x1, %r12d
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, 0x18(%rsp)
movl 0x8(%rsp), %ebp
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %rax
movl %ebp, %r8d
movq (%rax,%r8,8), %r15
movl %ebp, (%rdx)
movq (%rcx), %rax
leaq 0x1(%rax), %r8
movq %r8, (%rcx)
cmpq %r11, %rax
jge 0xa3d89
testq %rbx, %rbx
je 0xa3c59
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa3c41
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x2, %rsi
movq %r11, %r13
callq 0x2370
movq %r13, %r11
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%rbx)
movl %ebp, %eax
shrl %eax
movq 0x38(%rbx), %r10
movq 0x48(%rbx), %r8
leaq 0x1(%r10), %r9
movq %r9, 0x38(%rbx)
movl %eax, (%r8,%r10,4)
testl %r15d, %r15d
je 0xa3d93
movq %r15, %rax
shrq $0x20, %rax
cmpl $0x2, %r15d
je 0xa3d2b
ja 0xa3d9d
leaq (%rax,%rax,2), %r15
movl 0x8(%r14,%r15,8), %eax
movq 0x28(%rdi), %r8
xorq $0x1, %rax
movq (%r8,%rax,8), %r13
testl %r13d, %r13d
jle 0xa3cd4
movq 0x8(%rdi), %r8
movq %r13, %r9
shrq $0x20, %r9
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%r9,%r9,2), %r9
leaq (%r8,%r9,8), %r8
addq $0x8, %r8
xorl %r10d, %r10d
movl (%r8), %r9d
xorl %ebp, %r9d
cmpl $0x2, %r9d
cmovbl %r12d, %r10d
addq $0x18, %r8
decq %rax
jne 0xa3cb5
testl %r10d, %r10d
sete %al
jmp 0xa3cd9
movb $0x1, %al
xorl %r13d, %r13d
testb %al, %al
jne 0xa3d0b
leaq (%r14,%r15,8), %rax
addq $0x8, %rax
movl (%rax), %ebp
movl %ebp, (%rdx)
cmpl $0x2, %r13d
je 0xa3da7
ja 0xa3e03
movl %ebp, %eax
xorl %esi, %eax
cmpl $0x1, %eax
ja 0xa3bd0
jmp 0xa3e5f
movq %r11, %rbp
callq 0xfe34
movq %rbp, %r11
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
jmp 0xa3cdd
movq %r11, %r14
movl %ebp, 0x8(%rsp)
testq %rbx, %rbx
je 0xa3d40
movq 0x38(%rbx), %rax
movq %rax, 0x28(%rsp)
movl %ebp, %esi
leaq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %rbx, %r8
callq 0xa3941
testl %eax, %eax
je 0xa3e77
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x30(%rsp), %rdx
addq %rdx, %rax
addq $-0x2, %rax
movq %rax, (%rcx)
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %rdi
movq %r14, %r11
jmp 0xa3bcc
movl $0x6, %eax
jmp 0xa3e64
movl $0x5, %eax
jmp 0xa3e64
movl $0x4, %eax
jmp 0xa3e64
movl %ebp, 0x8(%rsp)
testq %rbx, %rbx
je 0xa3df9
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa3de4
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%rbx)
shrl %ebp
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rsi
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rsi,%rax,4)
incq (%rcx)
movl $0x1, %eax
jmp 0xa3e68
movl %ebp, 0x8(%rsp)
testq %rbx, %rbx
je 0xa3e55
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa3e40
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%rbx)
shrl %ebp
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rsi
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rsi,%rax,4)
incq (%rcx)
movl $0x3, %eax
jmp 0xa3e68
movl $0x7, %eax
movl %ebp, 0x8(%rsp)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, %eax
testq %rbx, %rbx
je 0xa3e68
movq 0x28(%rsp), %rcx
movq %rcx, 0x38(%rbx)
jmp 0xa3e68