// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_single_path_with_dels_by_length(asg_t*, unsigned int, unsigned int*, long long*, buf_t*, long long)
uint32_t detect_single_path_with_dels_by_length
(asg_t *g, uint32_t begNode, uint32_t* endNode, long long* Len, buf_t* b, long long maxLen)
{
    
    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(b) kv_push(uint32_t, b->b, v);

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

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

        if(kv > 2)
        {
            return MUL_OUTPUT;
        }

        if((*Len) > maxLen)
        {
            return LONG_TIPS;
        }

        ///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);
            if(b) kv_push(uint32_t, b->b, v);
            return TWO_INPUT;
        }

        if(kw > 2)
        {
            (*Len)++;
            ///if(b) kv_push(uint32_t, b->b, v>>1);
            if(b) kv_push(uint32_t, b->b, v);
            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 %rdx, %r12
movl %esi, %r13d
movq %rdi, %r14
movq 0x28(%rdi), %r10
xorl %eax, %eax
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %esi, %ebp
movq %rbx, 0x8(%rsp)
movq %rdi, (%rsp)
incq %rax
movq %rax, (%rcx)
movl %ebp, %r11d
movq (%r10,%r11,8), %rax
movq %rax, %rsi
movl $0x0, %r15d
andq %r8, %rsi
je 0xe91a6
movq 0x8(%r14), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rdi
xorl %edx, %edx
xorl %r15d, %r15d
movl (%rax,%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r15d
addq $0x18, %rdx
cmpq %rdx, %rdi
jne 0xe9192
movl %ebp, (%r12)
testq %rbx, %rbx
je 0xe9221
movq 0x38(%rbx), %rdi
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rdi
jne 0xe9216
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %edx
cmoveq %rdx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r12, %rbx
movq %rcx, %r12
movl %r13d, %r14d
movq %r9, %r13
movq %r11, 0x10(%rsp)
callq 0x2370
movq 0x10(%rsp), %r11
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq %r13, %r9
movl %r14d, %r13d
movq (%rsp), %r14
movq %r12, %rcx
movq %rbx, %r12
movq 0x8(%rsp), %rbx
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rdi
leaq 0x1(%rdi), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rax,%rdi,4)
testl %r15d, %r15d
je 0xe92fe
cmpl $0x2, %r15d
je 0xe9373
ja 0xe9306
movq (%rcx), %rax
cmpq %r9, %rax
jg 0xe930e
movq 0x28(%r14), %r10
movq (%r10,%r11,8), %rsi
movq %rsi, %rdx
andq %r8, %rdx
je 0xe9287
movq 0x8(%r14), %rdi
shrq $0x20, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdi)
js 0xe927e
movl -0x4(%rsi,%rdi), %ebp
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0xe9274
movl %ebp, %edx
xorl $0x1, %edx
movq (%r10,%rdx,8), %rdx
movq %rdx, %rsi
andq %r8, %rsi
je 0xe92e4
movq 0x8(%r14), %rdi
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rdx,%rdi), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r8d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xe92b9
movl %ebp, (%r12)
cmpl $0x2, %r8d
je 0xe9313
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
jbe 0xe92e8
jmp 0xe9321
movl %ebp, (%r12)
movl %ebp, %edx
xorl %r13d, %edx
cmpl $0x2, %edx
jae 0xe9156
movl $0x7, %r15d
jmp 0xe9373
movl $0x5, %r15d
jmp 0xe9373
movl $0x4, %r15d
jmp 0xe9373
xorl %r15d, %r15d
jmp 0xe9373
incq %rax
movq %rax, (%rcx)
movl $0x1, %r15d
jmp 0xe932d
incq %rax
movq %rax, (%rcx)
movl $0x3, %r15d
testq %rbx, %rbx
je 0xe9373
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0xe9368
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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rax,%rcx,4)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq