// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, 0x20(%rsp)
movq %rcx, 0x8(%rsp)
andq $0x0, (%rcx)
movq %r8, (%rsp)
andq $0x0, (%r8)
movq %rdi, %r13
xorl %ebp, %ebp
movl %esi, 0x1c(%rsp)
movl %esi, %ebx
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movq %r13, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0xc2e7a
movl %eax, %r14d
movq 0x20(%rsp), %rax
movl %ebx, (%rax)
testq %r15, %r15
je 0x70e1d
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0x70e0e
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 %ebx, %edx
shrl %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%r15)
movl %edx, (%rax,%rcx,4)
cmpl $0x2, %r14d
je 0x70eec
testl %r14d, %r14d
je 0x70f07
cmpl $0x2, %r14d
ja 0x70f22
movq 0x28(%r13), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rcx
movl %ecx, %eax
shrq $0x20, %rcx
incq %rax
imulq $0x18, %rcx, %rcx
decq %rax
je 0x70e78
leaq 0x18(%rcx), %rdx
movq 0x8(%r13), %rsi
cmpl $0x0, 0xc(%rsi,%rcx)
movq %rdx, %rcx
js 0x70e51
movl -0x18(%rsi,%rdx), %eax
movl -0x10(%rsi,%rdx), %ebp
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
movl %ebp, %esi
xorl $0x1, %esi
movq %r13, %rdi
xorl %edx, %edx
callq 0xc2e7a
movl %eax, %ebx
movq 0x20(%rsp), %rax
movl %ebp, (%rax)
cmpl $0x2, %ebx
jb 0x70ec8
movq 0x8(%rsp), %rax
movq (%rax), %r14
movq %r14, %rax
subq 0x10(%rsp), %rax
movq (%rsp), %rcx
cmpq (%rcx), %rax
jle 0x70eb5
movq (%rsp), %rcx
movq %rax, (%rcx)
incl %r12d
cmpl 0x60(%rsp), %r12d
jae 0x70f65
movq %r14, 0x10(%rsp)
movl %ebp, %eax
xorl 0x1c(%rsp), %eax
movl %ebp, %ebx
cmpl $0x1, %eax
ja 0x70dbf
movq 0x10(%rsp), %r14
movq (%rsp), %r12
movq 0x8(%rsp), %r13
pushq $0x7
popq %rax
jmp 0x70f45
movq 0x20(%r13), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r13
addq %rax, (%r13)
pushq $0x2
jmp 0x70f3b
movq 0x20(%r13), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r13
addq %rax, (%r13)
pushq $0x5
jmp 0x70f3b
movq 0x20(%r13), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r13
addq %rax, (%r13)
pushq $0x4
popq %rax
movq 0x10(%rsp), %r14
movq (%rsp), %r12
movq (%r13), %rcx
subq %r14, %rcx
cmpq (%r12), %rcx
jle 0x70f56
movq %rcx, (%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r13), %rax
shrl %ebp
movl (%rax,%rbp,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r13
addq %rax, (%r13)
testq %r15, %r15
movq (%rsp), %r12
je 0x70fc4
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0x70fb9
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
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), %eax
jmp 0x70f45