// File: /workspace/github_cpp_makefile_star2_O1/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
movl %esi, %r14d
movq %rdi, %r13
movq $0x0, (%rcx)
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl %esi, %ebp
movq %r8, 0x10(%rsp)
movl %esi, 0x4(%rsp)
movq %rdi, 0x8(%rsp)
incq (%rcx)
movq 0x28(%r13), %rax
movl %ebp, %r12d
movq (%rax,%r12,8), %rax
movq %rax, %rsi
movl $0x0, %r15d
andq %r11, %rsi
je 0xe7990
movq 0x8(%r13), %rdi
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rdi
xorl %r8d, %r8d
xorl %r15d, %r15d
movl (%rax,%r8), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r15d
addq $0x18, %r8
cmpq %r8, %rdi
jne 0xe797b
movl %ebp, (%rdx)
testq %rbx, %rbx
je 0xe7a00
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xe79ed
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 %r9, %r14
movq %rcx, %r13
movq %rdx, %rbx
callq 0x2370
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq %rbx, %rdx
movq 0x10(%rsp), %rbx
movq %r13, %rcx
movq 0x8(%rsp), %r13
movq %r14, %r9
movl 0x4(%rsp), %r14d
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rsi
leaq 0x1(%rax), %rdi
movq %rdi, 0x38(%rbx)
movl %ebp, (%rsi,%rax,4)
testl %r15d, %r15d
je 0xe7ada
cmpl $0x2, %r15d
je 0xe7b50
ja 0xe7ae2
movq (%rcx), %rax
cmpq %r9, %rax
jg 0xe7aea
movq 0x28(%r13), %r8
movq (%r8,%r12,8), %rsi
movq %rsi, %r10
andq %r11, %r10
je 0xe7a66
movq 0x8(%r13), %rdi
shrq $0x20, %rsi
shlq $0x3, %r10
leaq (%r10,%r10,2), %r10
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdi)
js 0xe7a5d
movl -0x4(%rsi,%rdi), %ebp
addq $0x18, %rdi
cmpq %rdi, %r10
jne 0xe7a53
movl %ebp, %esi
xorl $0x1, %esi
movq (%r8,%rsi,8), %rdi
movq %rdi, %r8
andq %r11, %r8
je 0xe7ab1
movq 0x8(%r13), %rsi
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %r10
addq $0xc, %r10
shlq $0x3, %r8
leaq (%r8,%r8,2), %rsi
xorl %edi, %edi
xorl %r11d, %r11d
movl (%r10,%rdi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %r11d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xe7a98
jmp 0xe7ab4
xorl %r11d, %r11d
movl %ebp, (%rdx)
cmpl $0x2, %r11d
je 0xe7aef
ja 0xe7afd
movl %ebp, %eax
xorl %r14d, %eax
cmpl $0x2, %eax
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
jae 0xe793d
movl $0x7, %r15d
jmp 0xe7b50
movl $0x5, %r15d
jmp 0xe7b50
movl $0x4, %r15d
jmp 0xe7b50
xorl %r15d, %r15d
jmp 0xe7b50
incq %rax
movq %rax, (%rcx)
movl $0x1, %r15d
jmp 0xe7b09
incq %rax
movq %rax, (%rcx)
movl $0x3, %r15d
testq %rbx, %rbx
je 0xe7b50
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xe7b3d
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)
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%rbx)
movl %ebp, (%rcx,%rax,4)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq