// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0xdb82a
jmp 0xdb79c
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0xdb805
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xdb7ca
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0xdb7d5
movl $0x2, %eax
movq %rax, -0x50(%rbp)
jmp 0xdb7d5
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x34(%rbp), %edx
shrl %edx
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x38(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x38(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0xdb82a
cmpl $0x0, -0x3c(%rbp)
jne 0xdb861
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0xdbb92
cmpl $0x2, -0x3c(%rbp)
jne 0xdb898
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x2, -0x4(%rbp)
jmp 0xdbb92
cmpl $0x2, -0x3c(%rbp)
jbe 0xdb8cf
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x4, -0x4(%rbp)
jmp 0xdbb92
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jae 0xdb9a8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xdb998
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0xdb9a8
jmp 0xdb99a
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xdb8d6
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x2, -0x40(%rbp)
jne 0xdbaa3
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0xdba97
jmp 0xdba09
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0xdba72
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xdba37
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x58(%rbp)
jmp 0xdba42
movl $0x2, %eax
movq %rax, -0x58(%rbp)
jmp 0xdba42
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x34(%rbp), %edx
shrl %edx
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x38(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x38(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0xdba97
movl $0x1, -0x4(%rbp)
jmp 0xdbb92
cmpl $0x2, -0x40(%rbp)
jbe 0xdbb76
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0xdbb6d
jmp 0xdbadf
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0xdbb48
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xdbb0d
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0xdbb18
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0xdbb18
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x34(%rbp), %edx
shrl %edx
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rsi
movq 0x38(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x38(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0xdbb6d
movl $0x3, -0x4(%rbp)
jmp 0xdbb92
movl -0x34(%rbp), %eax
shrl %eax
movl -0x14(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0xdbb8d
movl $0x7, -0x4(%rbp)
jmp 0xdbb92
jmp 0xdb773
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)