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


    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;
            return END_TIPS;
        }

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

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

        ///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)
        {
            (*baseLen) += g->seq[v>>1].len;
            if(b) kv_push(uint32_t, b->b, v>>1);
            return TWO_INPUT;
        }

        if(kw > 2)
        {
            (*baseLen) += g->seq[v>>1].len;
            if(b) kv_push(uint32_t, b->b, v>>1);
            return MUL_INPUT;
        }   


        if((v>>1) == (begNode>>1))
        {
            return LOOP;
        } 
    }

    return LONG_TIPS;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rdx, %r8
movl %esi, %r15d
movq %rdi, %r9
movq %rcx, (%rsp)
movq $0x0, (%rcx)
xorl %r14d, %r14d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl %esi, %r13d
movq %rbx, 0x8(%rsp)
movq 0x28(%r9), %rax
movl %r13d, %ebp
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
movl $0x0, %r12d
andq %r11, %rcx
je 0xa977a
movq 0x8(%r9), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %r12d, %r12d
movl (%rax,%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r12d
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xa9766
movl %r13d, (%r8)
testq %rbx, %rbx
je 0xa97ea
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa97d2
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x2, %rsi
movq %r14, 0x10(%rsp)
movq %r8, %r14
movq %r9, %rbx
callq 0x2370
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq %rbx, %r9
movq 0x8(%rsp), %rbx
movq %r14, %r8
movq 0x10(%rsp), %r14
movq %rax, 0x48(%rbx)
movl %r13d, %eax
shrl %eax
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%rbx)
movl %eax, (%rdx,%rcx,4)
cmpl $0x2, %r12d
je 0xa98be
testl %r12d, %r12d
je 0xa98df
cmpl $0x2, %r12d
ja 0xa9900
movq 0x28(%r9), %rax
movq (%rax,%rbp,8), %rcx
testl %ecx, %ecx
je 0xa9847
movq 0x8(%r9), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
cmpl $0x0, (%rdx)
jns 0xa9839
addq $0x18, %rdx
decl %ecx
jne 0xa982a
jmp 0xa9847
movl -0xc(%rdx), %ecx
movl -0x4(%rdx), %r14d
movq (%rsp), %rdx
addq %rcx, (%rdx)
movl %r14d, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
andq %r11, %rcx
je 0xa988e
movq 0x8(%r9), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movl (%rax,%rsi), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %ecx
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0xa9879
jmp 0xa9890
xorl %ecx, %ecx
movl %r14d, (%r8)
cmpl $0x2, %ecx
je 0xa9921
ja 0xa993f
movl %r14d, %eax
xorl %r15d, %eax
movl %r14d, %r13d
cmpl $0x1, %eax
ja 0xa972c
movl $0x7, %ebp
jmp 0xa99a3
movq 0x20(%r9), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x2, %ebp
jmp 0xa99a3
movq 0x20(%r9), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x5, %ebp
jmp 0xa99a3
movq 0x20(%r9), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x4, %ebp
jmp 0xa99a3
movq 0x20(%r9), %rax
shrl %r14d
movl (%rax,%r14,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x1, %ebp
jmp 0xa995b
movq 0x20(%r9), %rax
shrl %r14d
movl (%rax,%r14,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x3, %ebp
testq %rbx, %rbx
je 0xa99a3
movq 0x40(%rbx), %rax
cmpq %rax, 0x38(%rbx)
jne 0xa998f
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%rbx)
movl %r14d, (%rcx,%rax,4)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq