// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %rdi, %r15
movq %rcx, 0x8(%rsp)
andq $0x0, (%rcx)
xorl %r13d, %r13d
movl %esi, 0x14(%rsp)
movl %esi, %ebp
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xc2e7a
movl %eax, %r14d
movl %ebp, (%r12)
testq %rbx, %rbx
je 0x70c13
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0x70c04
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
movl %ebp, %edx
shrl %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%rbx)
movl %edx, (%rax,%rcx,4)
cmpl $0x2, %r14d
je 0x70ca5
testl %r14d, %r14d
je 0x70cbf
cmpl $0x2, %r14d
ja 0x70cd9
movq 0x28(%r15), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rcx
movl %ecx, %eax
shrq $0x20, %rcx
incq %rax
imulq $0x18, %rcx, %rcx
decq %rax
je 0x70c6f
leaq 0x18(%rcx), %rdx
movq 0x8(%r15), %rsi
cmpl $0x0, 0xc(%rsi,%rcx)
movq %rdx, %rcx
js 0x70c47
movl -0x18(%rsi,%rdx), %eax
movl -0x10(%rsi,%rdx), %r13d
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
movl %r13d, %esi
xorl $0x1, %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0xc2e7a
movl %r13d, (%r12)
cmpl $0x2, %eax
je 0x70cf4
ja 0x70d10
movl %r13d, %eax
xorl 0x14(%rsp), %eax
movl %r13d, %ebp
cmpl $0x1, %eax
ja 0x70bb8
pushq $0x7
jmp 0x70cf1
movq 0x20(%r15), %rax
shrl %ebp
movl (%rax,%rbp,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
pushq $0x2
jmp 0x70cf1
movq 0x20(%r15), %rax
shrl %ebp
movl (%rax,%rbp,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
pushq $0x5
jmp 0x70cf1
movq 0x20(%r15), %rax
shrl %ebp
movl (%rax,%rbp,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
pushq $0x4
popq %rbp
jmp 0x70d70
movq 0x20(%r15), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
pushq $0x1
jmp 0x70d2a
movq 0x20(%r15), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rcx
addq %rax, (%rcx)
pushq $0x3
popq %rbp
testq %rbx, %rbx
je 0x70d70
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0x70d64
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rbx)
movl %r13d, (%rax,%rcx,4)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq