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

    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)
        {
            flag = END_TIPS;
            break;
        }

        if(kv == 2)
        {
            flag = TWO_OUTPUT;
            break;
        }

        if(kv > 2)
        {
            flag = MUL_OUTPUT;
            break;
        }

        ///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)
        {
            n_stops++;
            currentLen = (*Len) - preLen;
            preLen = (*Len);
            if(currentLen > (*max_stop_Len))
            {
                (*max_stop_Len) = currentLen;
            }
        }
        if(kw >= 2 && n_stops >= stops_threshold)
        {
            (*Len)++;
            if(b) kv_push(uint32_t, b->b, v>>1);
            if(kw == 2) flag = TWO_INPUT;
            if(kw > 2) flag = MUL_INPUT;
            break;
        }
        
        if((v>>1) == (begNode>>1))
        {
            flag = LOOP;
            break;
        } 
    }


    currentLen = (*Len) - preLen;
    preLen = (*Len);
    if(currentLen > (*max_stop_Len))
    {
        (*max_stop_Len) = currentLen;
    }
    return flag;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r15
movq %rcx, %r9
movl %esi, %r11d
movq %rdi, %r14
xorl %r13d, %r13d
movq %r13, (%rcx)
movq %r13, (%r8)
movq 0x28(%rdi), %rax
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %esi, %ebp
movq $0x0, (%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %r15, 0x18(%rsp)
incq (%r9)
movl %ebp, %r12d
movq (%rax,%r12,8), %rax
movq %rax, %rcx
movl $0x0, %ebx
andq %r10, %rcx
je 0xaa588
movq 0x8(%r14), %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 %ebx, %ebx
movl (%rax,%rdi), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ebx
addq $0x18, %rdi
cmpq %rdi, %rcx
jne 0xaa575
movl %ebp, (%rdx)
testq %r15, %r15
je 0xaa605
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0xaa5f6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r14, %r15
movq %rdx, %r14
movq %r13, 0x20(%rsp)
movl %r11d, %r13d
callq 0x2370
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %r13d, %r11d
movq 0x20(%rsp), %r13
movq %r14, %rdx
movq %r15, %r14
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rax, 0x48(%r15)
movq 0x38(%r15), %rcx
movl %ebp, %edi
shrl %edi
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%r15)
movl %edi, (%rax,%rcx,4)
testl %ebx, %ebx
je 0xaa6ef
cmpl $0x2, %ebx
je 0xaa6fb
ja 0xaa6f6
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %rdi
movq %rdi, %rcx
andq %r10, %rcx
je 0xaa65d
movq 0x8(%r14), %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 0xaa654
movl -0x4(%rdi,%rsi), %ebp
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xaa64a
movl %ebp, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rcx
movq %rcx, %rdi
andq %r10, %rdi
je 0xaa6d0
movq 0x8(%r14), %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 %ebx, %ebx
movl (%rcx,%rsi), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %ebx
addq $0x18, %rsi
cmpq %rsi, %r10
jne 0xaa68e
movl %ebp, (%rdx)
cmpl $0x2, %ebx
jb 0xaa6d4
movq (%r9), %r12
movq %r12, %rcx
subq (%rsp), %rcx
cmpq (%r8), %rcx
jle 0xaa6ba
movq %rcx, (%r8)
incl %r13d
cmpl 0x60(%rsp), %r13d
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
jae 0xaa71e
movq %r12, (%rsp)
jmp 0xaa6da
movl %ebp, (%rdx)
jmp 0xaa6da
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %ebp, %ecx
xorl %r11d, %ecx
cmpl $0x2, %ecx
jae 0xaa53e
movl $0x7, %ebx
jmp 0xaa6fb
movl $0x5, %ebx
jmp 0xaa6fb
movl $0x4, %ebx
movq (%rsp), %r12
movq (%r9), %rax
subq %r12, %rax
cmpq (%r8), %rax
jle 0xaa70d
movq %rax, (%r8)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq (%r9)
testq %r15, %r15
je 0xaa773
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0xaa766
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x40(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rax, 0x48(%r15)
movq 0x38(%r15), %rcx
shrl %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r15)
movl %ebp, (%rax,%rcx,4)
xorl %eax, %eax
cmpl $0x2, %ebx
setne %al
leal 0x1(,%rax,2), %ebx
jmp 0xaa6ff