// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_single_path_with_dels(asg_t*, unsigned int, unsigned int*, long long*, buf_t*)
uint32_t detect_single_path_with_dels(asg_t *g, uint32_t begNode, uint32_t* endNode, long long* Len, buf_t* b)
{
    uint32_t v = begNode, w;
    uint32_t kv, kw;
    (*Len) = 0;

    while (1)
    {
        (*Len)++;
        kv = get_real_length(g, v, NULL);
        (*endNode) = v;

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

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

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

        if(kv > 2)
        {
            return MUL_OUTPUT;
        }

        ///up to here, kv=1
        ///kw must >= 1
        get_real_length(g, v, &w);
        kw = get_real_length(g, w^1, NULL);
        v = w;
        (*endNode) = v;


        if(kw == 2)
        {
            (*Len)++;
            if(b) kv_push(uint32_t, b->b, v>>1);
            return TWO_INPUT;
        }

        if(kw > 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
movq %rcx, %r9
movl %esi, %r11d
movq %rdi, %r15
movq $0x0, (%rcx)
movq 0x28(%rdi), %rax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %esi, %ebp
movq %r8, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
incq (%r9)
movl %ebp, %r14d
movq (%rax,%r14,8), %rax
movq %rax, %rcx
movl $0x0, %r13d
andq %r12, %rcx
je 0xaa347
movq 0x8(%r15), %rsi
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsi,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edi, %edi
xorl %r13d, %r13d
movl (%rax,%rdi), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r13d
addq $0x18, %rdi
cmpq %rdi, %rcx
jne 0xaa333
movl %ebp, (%rdx)
testq %rbx, %rbx
je 0xaa3b5
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0xaa3a6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r9, %r15
movq %rdx, %r12
movl %r11d, %ebx
callq 0x2370
movl %ebx, %r11d
movq 0x10(%rsp), %rbx
movq %r12, %rdx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %r15, %r9
movq 0x8(%rsp), %r15
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
movl %ebp, %edi
shrl %edi
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%rbx)
movl %edi, (%rax,%rcx,4)
testl %r13d, %r13d
je 0xaa47a
cmpl $0x2, %r13d
je 0xaa4e6
ja 0xaa482
movq 0x28(%r15), %rax
movq (%rax,%r14,8), %rdi
movq %rdi, %rcx
andq %r12, %rcx
je 0xaa40f
movq 0x8(%r15), %rsi
shrq $0x20, %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %rdi
addq $0xc, %rdi
xorl %esi, %esi
cmpl $0x0, (%rdi,%rsi)
js 0xaa406
movl -0x4(%rdi,%rsi), %ebp
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xaa3fc
movl %ebp, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rcx
movq %rcx, %rdi
andq %r12, %rdi
je 0xaa462
movq 0x8(%r15), %rsi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %r10
xorl %esi, %esi
xorl %edi, %edi
movl (%rcx,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %r10
jne 0xaa440
movl %ebp, (%rdx)
cmpl $0x2, %edi
je 0xaa48a
jbe 0xaa464
jmp 0xaa495
movl %ebp, (%rdx)
movl %ebp, %ecx
xorl %r11d, %ecx
cmpl $0x2, %ecx
jae 0xaa2fa
movl $0x7, %r13d
jmp 0xaa4e6
movl $0x5, %r13d
jmp 0xaa4e6
movl $0x4, %r13d
jmp 0xaa4e6
incq (%r9)
movl $0x1, %r13d
jmp 0xaa49e
incq (%r9)
movl $0x3, %r13d
testq %rbx, %rbx
je 0xaa4e6
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0xaa4d9
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 %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rax,%rcx,4)
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq