// File: /workspace/github_cpp_makefile_star2_O1/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, %r9d
movq %rdi, %r11
movq $0x0, (%rcx)
movl $0x1, %r14d
movl %esi, %ebp
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdi, (%rsp)
incq (%rcx)
movq 0x8(%r11), %r12
movq 0x28(%r11), %rax
movl %ebp, %esi
movq (%rax,%rsi,8), %r13
movl %ebp, (%rdx)
testq %rbx, %rbx
je 0xa3771
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa3759
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x2, %rsi
movl %r9d, %r15d
callq 0x2370
movq (%rsp), %r11
movl %r15d, %r9d
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%rbx)
movl %ebp, %eax
shrl %eax
movq 0x38(%rbx), %rdi
movq 0x48(%rbx), %r8
leaq 0x1(%rdi), %rsi
movq %rsi, 0x38(%rbx)
movl %eax, (%r8,%rdi,4)
testl %r13d, %r13d
je 0xa3833
movq %r13, %rax
shrq $0x20, %rax
cmpl $0x2, %r13d
je 0xa38a8
ja 0xa383b
leaq (%rax,%rax,2), %r13
movl 0x8(%r12,%r13,8), %eax
movq 0x28(%r11), %rsi
xorq $0x1, %rax
movq (%rsi,%rax,8), %r15
testl %r15d, %r15d
jle 0xa37e8
movq 0x8(%r11), %rsi
movq %r15, %rdi
shrq $0x20, %rdi
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %r8
addq $0x8, %r8
xorl %edi, %edi
movl (%r8), %esi
xorl %ebp, %esi
cmpl $0x2, %esi
cmovbl %r14d, %edi
addq $0x18, %r8
decq %rax
jne 0xa37cc
testl %edi, %edi
sete %al
jmp 0xa37ed
movb $0x1, %al
xorl %r15d, %r15d
testb %al, %al
jne 0xa3818
leaq (%r12,%r13,8), %rax
addq $0x8, %rax
movl (%rax), %ebp
movl %ebp, (%rdx)
cmpl $0x2, %r15d
je 0xa3843
ja 0xa384e
movl %ebp, %eax
xorl %r9d, %eax
cmpl $0x2, %eax
jae 0xa36fe
jmp 0xa38a2
movl %r9d, %ebp
callq 0xfde0
movq (%rsp), %r11
movl %ebp, %r9d
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
jmp 0xa37f1
movl $0x5, %r13d
jmp 0xa38a8
movl $0x4, %r13d
jmp 0xa38a8
incq (%rcx)
movl $0x1, %r13d
jmp 0xa3857
incq (%rcx)
movl $0x3, %r13d
testq %rbx, %rbx
je 0xa38a8
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa388b
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 %rax, 0x48(%rbx)
shrl %ebp
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rcx,%rax,4)
jmp 0xa38a8
movl $0x7, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq