// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r9, %r15
movq %rcx, %r10
movq %rdi, %r12
xorl %ebp, %ebp
movq %rbp, (%rcx)
movq %rbp, (%r8)
movq 0x28(%rdi), %rax
movl %esi, 0x1c(%rsp)
movl %esi, %ebx
movl $0x0, 0xc(%rsp)
xorl %r11d, %r11d
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movq %r9, 0x30(%rsp)
movl %ebx, %r13d
movq (%rax,%r13,8), %rax
movq %rax, %rcx
movl $0x0, %r14d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xaaaf5
movq 0x8(%r12), %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 %r14d, %r14d
movl (%rax,%rdi), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r14d
addq $0x18, %rdi
cmpq %rdi, %rcx
jne 0xaaae1
movl %ebx, (%rdx)
testq %r15, %r15
je 0xaab67
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0xaab58
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
movq %rbp, %r15
movq %r12, %rbp
movq %r11, %r12
callq 0x2370
movq 0x10(%rsp), %rdx
movq %r12, %r11
movq %rbp, %r12
movq %r15, %rbp
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %r10
movq 0x28(%rsp), %r8
movq %rax, 0x48(%r15)
movq 0x38(%r15), %rcx
movl %ebx, %edi
shrl %edi
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%r15)
movl %edi, (%rax,%rcx,4)
cmpl $0x2, %r14d
je 0xaac6e
testl %r14d, %r14d
je 0xaac87
cmpl $0x2, %r14d
ja 0xaaca0
movq 0x28(%r12), %rax
movq (%rax,%r13,8), %rdi
testl %edi, %edi
je 0xaabd9
movq 0x8(%r12), %rcx
movq %rdi, %rsi
shrq $0x20, %rsi
movl %edi, %edi
leaq (%rsi,%rsi,2), %rdx
leaq (%rcx,%rdx,8), %rsi
addq $0xc, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %r9
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdi)
jns 0xaabc6
addq $0x18, %rdi
cmpq %rdi, %r9
jne 0xaabb5
jmp 0xaabd4
leaq (%rcx,%rdx,8), %rcx
movl (%rdi,%rcx), %edx
movl 0x8(%rdi,%rcx), %ebp
addq %rdx, (%r10)
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rcx
movq %rcx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdi
je 0xaac54
movq 0x8(%r12), %rsi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %r9
xorl %esi, %esi
xorl %ebx, %ebx
movl (%rcx,%rsi), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %ebx
addq $0x18, %rsi
cmpq %rsi, %r9
jne 0xaac10
movl %ebp, (%rdx)
cmpl $0x2, %ebx
jb 0xaac56
movq (%r10), %r13
movq %r13, %rcx
subq %r11, %rcx
cmpq (%r8), %rcx
jle 0xaac3b
movq %rcx, (%r8)
movl 0xc(%rsp), %ecx
incl %ecx
cmpl 0x70(%rsp), %ecx
jae 0xaacd7
movl %ecx, 0xc(%rsp)
movq %r13, %r11
jmp 0xaac56
movl %ebp, (%rdx)
movl %ebp, %ecx
xorl 0x1c(%rsp), %ecx
movl %ebp, %ebx
cmpl $0x1, %ecx
ja 0xaaaa5
movl $0x7, %eax
jmp 0xaacb7
movq 0x20(%r12), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r10)
movl $0x2, %eax
jmp 0xaacb7
movq 0x20(%r12), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r10)
movl $0x5, %eax
jmp 0xaacb7
movq 0x20(%r12), %rax
shrl %ebx
movl (%rax,%rbx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r10)
movl $0x4, %eax
movq %r11, %r13
movq (%r10), %rcx
subq %r13, %rcx
cmpq (%r8), %rcx
jle 0xaacc8
movq %rcx, (%r8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r12), %rax
shrl %ebp
movl (%rax,%rbp,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r10)
testq %r15, %r15
je 0xaad39
movq 0x38(%r15), %rcx
movq 0x48(%r15), %rax
cmpq 0x40(%r15), %rcx
jne 0xaad2e
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 0x20(%rsp), %r10
movq 0x28(%rsp), %r8
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 0xaacba