// File: /workspace/github_cpp_makefile_star2_O3/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
movl %esi, %r11d
movq %rdi, %r10
movq %rcx, (%rsp)
movq $0x0, (%rcx)
movq 0x28(%rdi), %rax
xorl %r14d, %r14d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %esi, %r13d
movq %r8, 0x8(%rsp)
movl %r13d, %ebp
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
movl $0x0, %r12d
andq %r15, %rcx
je 0xaa808
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 %edi, %edi
xorl %r12d, %r12d
movl (%rax,%rdi), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r12d
addq $0x18, %rdi
cmpq %rdi, %rcx
jne 0xaa7f4
movl %r13d, (%rdx)
testq %rbx, %rbx
je 0xaa87d
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0xaa86d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r14, 0x10(%rsp)
movq %rdx, %r14
movq %r10, %rbx
movl %r11d, %r15d
callq 0x2370
movl %r15d, %r11d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %rbx, %r10
movq 0x8(%rsp), %rbx
movq %r14, %rdx
movq 0x10(%rsp), %r14
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rcx
movl %r13d, %edi
shrl %edi
leaq 0x1(%rcx), %rsi
movq %rsi, 0x38(%rbx)
movl %edi, (%rax,%rcx,4)
cmpl $0x2, %r12d
je 0xaa968
testl %r12d, %r12d
je 0xaa989
cmpl $0x2, %r12d
ja 0xaa9aa
movq 0x28(%r10), %rax
movq (%rax,%rbp,8), %rdi
testl %edi, %edi
je 0xaa8ed
movq 0x8(%r10), %rcx
movq %rdi, %rsi
shrq $0x20, %rsi
movl %edi, %edi
leaq (%rsi,%rsi,2), %r9
leaq (%rcx,%r9,8), %rsi
addq $0xc, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %r8
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdi)
jns 0xaa8da
addq $0x18, %rdi
cmpq %rdi, %r8
jne 0xaa8c9
jmp 0xaa8ed
leaq (%rcx,%r9,8), %rcx
movl (%rdi,%rcx), %esi
movl 0x8(%rdi,%rcx), %r14d
movq (%rsp), %rcx
addq %rsi, (%rcx)
movl %r14d, %ecx
xorl $0x1, %ecx
movq (%rax,%rcx,8), %rcx
movq %rcx, %rdi
andq %r15, %rdi
je 0xaa949
movq 0x8(%r10), %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 %edi, %edi
movl (%rcx,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %r9
jne 0xaa91f
movl %r14d, (%rdx)
cmpl $0x2, %edi
je 0xaa9cb
jbe 0xaa94c
jmp 0xaa9e9
movl %r14d, (%rdx)
movl %r14d, %ecx
xorl %r11d, %ecx
movl %r14d, %r13d
cmpl $0x1, %ecx
ja 0xaa7be
movl $0x7, %ebp
jmp 0xaaa4c
movq 0x20(%r10), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x2, %ebp
jmp 0xaaa4c
movq 0x20(%r10), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x5, %ebp
jmp 0xaaa4c
movq 0x20(%r10), %rax
shrl %r13d
movl (%rax,%r13,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x4, %ebp
jmp 0xaaa4c
movq 0x20(%r10), %rax
shrl %r14d
movl (%rax,%r14,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x1, %ebp
jmp 0xaaa05
movq 0x20(%r10), %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 0xaaa4c
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rax
cmpq 0x40(%rbx), %rcx
jne 0xaaa40
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %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 %r14d, (%rax,%rcx,4)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq