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


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

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

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

        if(nv == 2)
        {
            return TWO_OUTPUT;
        }

        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)
        {
            (*Len)++;
            if(b) kv_push(uint32_t, b->b, v>>1);
            return TWO_INPUT;
        }

        if(rnv > 2)
        {
            (*Len)++;
            if(b) kv_push(uint32_t, b->b, v>>1);
            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 $0x18, %rsp
movq %r8, %rbx
movl %esi, %r10d
movq %rdi, %r12
movq $0x0, (%rcx)
movl $0x1, %ebp
movl %esi, %r15d
movq %rcx, 0x8(%rsp)
movq %rdx, (%rsp)
movq %rdi, 0x10(%rsp)
incq (%rcx)
movq 0x8(%r12), %r11
movq 0x28(%r12), %rax
movl %r15d, %esi
movq (%rax,%rsi,8), %r13
movl %r15d, (%rdx)
testq %rbx, %rbx
je 0xa47c0
movq 0x38(%rbx), %rdi
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rdi
jne 0xa47ae
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movl %r10d, %r14d
movq %rbx, %r12
movq %r11, %rbx
callq 0x2370
movq %rbx, %r11
movq %r12, %rbx
movq 0x10(%rsp), %r12
movl %r14d, %r10d
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rdi
movl %r15d, %r8d
shrl %r8d
leaq 0x1(%rdi), %rsi
movq %rsi, 0x38(%rbx)
movl %r8d, (%rax,%rdi,4)
testl %r13d, %r13d
je 0xa489e
movq %r13, %rax
shrq $0x20, %rax
cmpl $0x2, %r13d
je 0xa4914
ja 0xa48a6
leaq (%rax,%rax,2), %rax
movl 0x8(%r11,%rax,8), %r14d
movq 0x28(%r12), %rsi
movq %r14, %rdi
xorq $0x1, %rdi
movq (%rsi,%rdi,8), %r13
testl %r13d, %r13d
jle 0xa485f
movq 0x8(%r12), %rdi
movq %r13, %rsi
shrq $0x20, %rsi
movl %r13d, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0x8, %rsi
xorl %r9d, %r9d
movl (%rsi), %edi
xorl %r15d, %edi
cmpl $0x2, %edi
cmovbl %ebp, %r9d
addq $0x18, %rsi
decq %r8
jne 0xa4823
testl %r9d, %r9d
je 0xa4862
movl %r14d, (%rdx)
cmpl $0x2, %r13d
je 0xa48ae
ja 0xa48b9
movl %r14d, %eax
xorl %r10d, %eax
movl %r14d, %r15d
cmpl $0x2, %eax
jae 0xa473c
jmp 0xa490e
xorl %r13d, %r13d
leaq (%r11,%rax,8), %r14
addq $0x8, %r14
movq 0x1f076f(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x194895(%rip), %rdi    # 0x23911a
movl %r10d, %r15d
callq 0x2410
movl %r15d, %r10d
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movl (%r14), %r14d
jmp 0xa483d
movl $0x5, %r13d
jmp 0xa4914
movl $0x4, %r13d
jmp 0xa4914
incq (%rcx)
movl $0x1, %r13d
jmp 0xa48c2
incq (%rcx)
movl $0x3, %r13d
testq %rbx, %rbx
je 0xa4914
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0xa48fd
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
shrl %r14d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rbx)
movl %r14d, (%rax,%rcx,4)
jmp 0xa4914
movl $0x7, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq