// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %r9, %r15
movq %rcx, %r13
movq %rdx, 0x30(%rsp)
movl %esi, %r12d
andq $0x0, (%rcx)
movq %rdi, %rbx
movq %r8, 0x8(%rsp)
andq $0x0, (%r8)
xorl %r14d, %r14d
movl %esi, 0x2c(%rsp)
movq $0x0, 0x10(%rsp)
movq %rcx, 0x20(%rsp)
incq (%r13)
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0xc2e7a
movl %eax, %ebp
movq 0x30(%rsp), %rax
movl %r12d, (%rax)
testq %r15, %r15
je 0x70a57
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0x70a47
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%r15)
movq 0x38(%r15), %rcx
movl %r12d, %edx
shrl %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%r15)
movl %edx, (%rax,%rcx,4)
testl %ebp, %ebp
je 0x70ae9
cmpl $0x2, %ebp
je 0x70aec
ja 0x70af8
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x1c(%rsp), %rdx
callq 0xc2e7a
movl 0x1c(%rsp), %esi
xorl $0x1, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xc2e7a
movl %eax, %ebp
movl 0x1c(%rsp), %r12d
movq 0x30(%rsp), %rax
movl %r12d, (%rax)
cmpl $0x2, %ebp
jb 0x70ad5
movq (%r13), %r13
movq %r13, %rax
subq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
cmpq (%rcx), %rax
jle 0x70ac1
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
incl %r14d
cmpl 0x70(%rsp), %r14d
jae 0x70b07
movq %r13, 0x10(%rsp)
movq 0x20(%rsp), %r13
movl %r12d, %eax
xorl 0x2c(%rsp), %eax
cmpl $0x2, %eax
jae 0x709f3
pushq $0x7
jmp 0x70aeb
pushq $0x5
popq %rbp
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbx
jmp 0x70b6b
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbx
pushq $0x4
popq %rbp
jmp 0x70b6b
movq 0x20(%rsp), %rax
incq (%rax)
testq %r15, %r15
movq 0x8(%rsp), %rbx
je 0x70b5c
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0x70b4d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%r15)
movq 0x38(%r15), %rcx
shrl %r12d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r15)
movl %r12d, (%rax,%rcx,4)
xorl %eax, %eax
cmpl $0x2, %ebp
setne %al
leal 0x1(,%rax,2), %ebp
movq 0x20(%rsp), %rax
movq (%rax), %rax
subq %r13, %rax
cmpq (%rbx), %rax
jle 0x70b7e
movq %rax, (%rbx)
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq