// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_single_path_with_dels_contigLen_complex(asg_t*, unsigned int, unsigned int*, long long*, long long*, buf_t*, unsigned int)
uint32_t detect_single_path_with_dels_contigLen_complex(asg_t *g, uint32_t begNode, uint32_t* endNode, 
long long* baseLen, long long* max_stop_base_Len, buf_t* b, uint32_t stops_threshold)
{
    
    uint32_t v = begNode, w = 0;
    uint32_t kv, kw, k, n_stops = 0, flag = LONG_TIPS;
    (*baseLen) = 0;
    (*max_stop_base_Len) = 0;
    long long preBaseLen = 0, currentBaseLen;


    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)
        {
            (*baseLen) += g->seq[v>>1].len;
            flag = END_TIPS;
            break;
        }

        if(kv == 2)
        {
            (*baseLen) += g->seq[v>>1].len;
            flag = TWO_OUTPUT;
            break;
        }

        if(kv > 2)
        {
            (*baseLen) += g->seq[v>>1].len;
            flag = MUL_OUTPUT;
            break;
        }

        ///kv must be 1
        for (k = 0; k < asg_arc_n(g, v); k++)
        {
            if(!asg_arc_a(g, v)[k].del)
            {
                w = asg_arc_a(g, v)[k].v;
                (*baseLen) += ((uint32_t)(asg_arc_a(g, v)[k].ul));
                break;
            }
        }

        ///up to here, kv=1
        ///kw must >= 1
        kw = get_real_length(g, w^1, NULL);
        v = w;
        (*endNode) = v;

        if(kw >= 2)
        {
            n_stops++;
            currentBaseLen = (*baseLen) - preBaseLen;
            preBaseLen = (*baseLen);
            if(currentBaseLen > (*max_stop_base_Len))
            {
                (*max_stop_base_Len) = currentBaseLen;
            }
        }

        if(kw >= 2 && n_stops >= stops_threshold)
        {
            (*baseLen) += g->seq[v>>1].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;
        } 
    }

    currentBaseLen = (*baseLen) - preBaseLen;
    preBaseLen = (*baseLen);
    if(currentBaseLen > (*max_stop_base_Len))
    {
        (*max_stop_base_Len) = currentBaseLen;
    }

    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, %r12d
movq %rdi, %r10
xorl %ebp, %ebp
movq %rbp, (%rcx)
movq %rbp, (%r8)
movl %esi, %ebx
xorl %esi, %esi
xorl %edi, %edi
movq %r8, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movl %r12d, 0x4(%rsp)
movl %esi, (%rsp)
movq 0x28(%r10), %rax
movl %ebx, %r14d
movq (%rax,%r14,8), %rax
movq %rax, %rcx
movl $0x0, %r13d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa9a43
movq 0x8(%r10), %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 %r11d, %r11d
xorl %r13d, %r13d
movl (%rax,%r11), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r13d
addq $0x18, %r11
cmpq %r11, %rcx
jne 0xa9a2e
movl %ebx, (%rdx)
testq %r15, %r15
je 0xa9ac6
movq 0x40(%r15), %rax
cmpq %rax, 0x38(%r15)
jne 0xa9aae
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%r15)
movq %rbp, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x48(%r15), %rdi
shlq $0x2, %rsi
movq %r15, %r12
movq %r10, %r15
movq %rdx, %rbp
callq 0x2370
movq %rbp, %rdx
movq %r15, %r10
movq %r12, %r15
movl 0x4(%rsp), %r12d
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rbp
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rax, 0x48(%r15)
movl %ebx, %eax
shrl %eax
movq 0x38(%r15), %rcx
movq 0x48(%r15), %r11
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%r15)
movl %eax, (%r11,%rcx,4)
cmpl $0x2, %r13d
je 0xa9bbd
testl %r13d, %r13d
je 0xa9bd8
cmpl $0x2, %r13d
ja 0xa9bf3
movq 0x28(%r10), %rax
movq (%rax,%r14,8), %rcx
testl %ecx, %ecx
je 0xa9b1e
movq 0x8(%r10), %r11
movq %rcx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r11,%rsi,8), %rsi
addq $0xc, %rsi
cmpl $0x0, (%rsi)
jns 0xa9b15
addq $0x18, %rsi
decl %ecx
jne 0xa9b06
jmp 0xa9b1e
movl -0xc(%rsi), %ecx
movl -0x4(%rsi), %ebp
addq %rcx, (%r9)
movl %ebp, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa9b6b
movq 0x8(%r10), %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 %r11d, %r11d
xorl %ebx, %ebx
movl (%rax,%r11), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ebx
addq $0x18, %r11
cmpq %r11, %rcx
jne 0xa9b55
jmp 0xa9b6d
xorl %ebx, %ebx
movl %ebp, (%rdx)
cmpl $0x2, %ebx
jae 0xa9b79
movl (%rsp), %esi
jmp 0xa9b92
movl (%rsp), %esi
incl %esi
movq (%r9), %rax
movq %rax, %rcx
subq %rdi, %rcx
cmpq (%r8), %rcx
jle 0xa9b8f
movq %rcx, (%r8)
movq %rax, %rdi
cmpl $0x2, %ebx
setb %al
cmpl 0x60(%rsp), %esi
setb %cl
orb %al, %cl
je 0xa9c0b
movl %ebp, %eax
xorl %r12d, %eax
movl %ebp, %ebx
cmpl $0x1, %eax
ja 0xa99eb
movl $0x7, %eax
jmp 0xa9c82
movq 0x20(%r10), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r9)
movl $0x2, %eax
jmp 0xa9c82
movq 0x20(%r10), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r9)
movl $0x5, %eax
jmp 0xa9c82
movq 0x20(%r10), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r9)
movl $0x4, %eax
jmp 0xa9c82
movq 0x20(%r10), %rax
shrl %ebp
movl (%rax,%rbp,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r9)
testq %r15, %r15
je 0xa9c73
movq 0x40(%r15), %rax
cmpq %rax, 0x38(%r15)
jne 0xa9c60
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 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rax, 0x48(%r15)
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), %eax
movq (%r9), %rcx
subq %rdi, %rcx
cmpq (%r8), %rcx
jle 0xa9c90
movq %rcx, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq