// File: /workspace/github_cpp_makefile_star2_O1/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
movl 0x60(%rsp), %r13d
xorl %esi, %esi
movq %rsi, (%rcx)
movq %rsi, (%r8)
movl %r11d, %ebp
xorl %edi, %edi
movq %r8, 0x8(%rsp)
movq %rcx, (%rsp)
movq %r14, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
incq (%r9)
movq 0x28(%r14), %rax
movl %ebp, %r12d
movq (%rax,%r12,8), %rax
movq %rax, %rcx
movl $0x0, %ebx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa94e6
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 %r10d, %r10d
xorl %ebx, %ebx
movl (%rax,%r10), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ebx
addq $0x18, %r10
cmpq %r10, %rcx
jne 0xa94d2
movl %ebp, (%rdx)
testq %r15, %r15
je 0xa9563
movq 0x40(%r15), %rax
cmpq %rax, 0x38(%r15)
jne 0xa954b
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%r15)
movq %rdi, 0x20(%rsp)
movq 0x48(%r15), %rdi
shlq $0x2, %rsi
movq %rdx, %r13
movq %r15, %r14
movl %r11d, %r15d
callq 0x2370
movl %r15d, %r11d
movq %r14, %r15
movq 0x18(%rsp), %r14
movq %r13, %rdx
movl 0x60(%rsp), %r13d
movq 0x20(%rsp), %rdi
movq (%rsp), %r9
movq 0x8(%rsp), %r8
movq %rax, 0x48(%r15)
movl %ebp, %eax
shrl %eax
movq 0x38(%r15), %rcx
movq 0x48(%r15), %r10
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%r15)
movl %eax, (%r10,%rcx,4)
testl %ebx, %ebx
je 0xa965f
cmpl $0x2, %ebx
je 0xa96d7
ja 0xa9666
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %r10
movq %r10, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa95c2
movq 0x8(%r14), %rsi
shrq $0x20, %r10
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%r10,%r10,2), %r10
leaq (%rsi,%r10,8), %r10
addq $0xc, %r10
xorl %esi, %esi
cmpl $0x0, (%r10,%rsi)
js 0xa95b9
movl -0x4(%r10,%rsi), %ebp
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xa95ad
movl %ebp, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa960f
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 %r10d, %r10d
xorl %ebx, %ebx
movl (%rax,%r10), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ebx
addq $0x18, %r10
cmpq %r10, %rcx
jne 0xa95f9
jmp 0xa9611
xorl %ebx, %ebx
movl %ebp, (%rdx)
cmpl $0x2, %ebx
jae 0xa961f
movq 0x10(%rsp), %rsi
jmp 0xa963a
movq 0x10(%rsp), %rsi
incl %esi
movq (%r9), %rax
movq %rax, %rcx
subq %rdi, %rcx
cmpq (%r8), %rcx
jle 0xa9637
movq %rcx, (%r8)
movq %rax, %rdi
cmpl $0x2, %ebx
setb %al
cmpl %r13d, %esi
setb %cl
orb %al, %cl
je 0xa966d
movl %ebp, %eax
xorl %r11d, %eax
cmpl $0x2, %eax
jae 0xa948c
movl $0x7, %ebx
jmp 0xa96d7
movl $0x5, %ebx
jmp 0xa96d7
movl $0x4, %ebx
jmp 0xa96d7
incq (%r9)
testq %r15, %r15
je 0xa96c8
movq 0x40(%r15), %rax
cmpq %rax, 0x38(%r15)
jne 0xa96b3
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x40(%r15)
movq %rdi, %r14
movq 0x48(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %r14, %rdi
movq (%rsp), %r9
movq 0x8(%rsp), %r8
movq %rax, 0x48(%r15)
shrl %ebp
movq 0x38(%r15), %rax
movq 0x48(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%r15)
movl %ebp, (%rcx,%rax,4)
xorl %eax, %eax
cmpl $0x2, %ebx
setne %al
leal 0x1(,%rax,2), %ebx
movq (%r9), %rax
subq %rdi, %rax
cmpq (%r8), %rax
jle 0xa96e5
movq %rax, (%r8)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq