// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: detect_single_path_with_single_bubbles(asg_t*, unsigned int, unsigned int*, long long*, buf_t*, unsigned int)
uint32_t detect_single_path_with_single_bubbles(asg_t *g, uint32_t begNode, uint32_t* endNode, 
long long* Len, buf_t* b, uint32_t max_ext)
{
    
    uint32_t v = begNode;
    uint32_t nv, rnv;
    asg_arc_t *av;
    long long bLen;
    long long pre_b_n = 0;
    (*Len) = 0;

    
    
    while (1)
    {
        nv = asg_arc_n(g, v);
        av = asg_arc_a(g, v);   
        (*endNode) = v;
        (*Len)++;


        if((*Len) > max_ext)
        {
            return LONG_TIPS_UNDER_MAX_EXT;
        }

        
        if(b) kv_push(uint32_t, b->b, v>>1);

 

        if(nv == 0)
        {
            return END_TIPS;
        }

        if(nv == 2)
        {


            if(b) pre_b_n = b->b.n;
            if(!detect_simple_bubble(g, v, &v, &bLen, b))
            {
                if(b) b->b.n = pre_b_n;
                return TWO_OUTPUT;
            }

            (*Len) = (*Len) + bLen - 2;
            continue;
        }

        if(nv > 2)
        {
            return MUL_OUTPUT;
        }

        ///up to here, nv=1
        ///rnv must >= 1
        rnv = asg_is_single_edge(g, av[0].v, v>>1);
        v = av[0].v;
        (*endNode) = v;
        if(rnv == 2)
        {
            if(b) kv_push(uint32_t, b->b, v>>1);
            (*Len)++;
            return TWO_INPUT;
        }

        if(rnv > 2)
        {
            if(b) kv_push(uint32_t, b->b, v>>1);
            (*Len)++;
            return MUL_INPUT;
        } 

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

    return LONG_TIPS;   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
cmpq %rcx, %rax
jle 0xd4ef2
movl $0x6, -0x4(%rbp)
jmp 0xd51e3
cmpq $0x0, -0x30(%rbp)
je 0xd4f8d
jmp 0xd4eff
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0xd4f68
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xd4f2d
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0xd4f38
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0xd4f38
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 -0x38(%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 0xd4f8d
cmpl $0x0, -0x3c(%rbp)
jne 0xd4f9f
movl $0x5, -0x4(%rbp)
jmp 0xd51e3
cmpl $0x2, -0x3c(%rbp)
jne 0xd500f
cmpq $0x0, -0x30(%rbp)
je 0xd4fb8
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
movq -0x30(%rbp), %r8
leaq -0x38(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0xd4c10
cmpl $0x0, %eax
jne 0xd4ff4
cmpq $0x0, -0x30(%rbp)
je 0xd4fe8
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x2, -0x4(%rbp)
jmp 0xd51e3
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq -0x50(%rbp), %rcx
subq $0x2, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0xd4e88
cmpl $0x2, -0x3c(%rbp)
jbe 0xd5021
movl $0x4, -0x4(%rbp)
jmp 0xd51e3
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x38(%rbp), %edx
shrl %edx
callq 0xd4770
movl %eax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x2, -0x40(%rbp)
jne 0xd510b
cmpq $0x0, -0x30(%rbp)
je 0xd50f1
jmp 0xd5063
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0xd50cc
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xd5091
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0xd509c
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0xd509c
movq -0x68(%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 -0x38(%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 0xd50f1
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0xd51e3
cmpl $0x2, -0x40(%rbp)
jbe 0xd51c7
cmpq $0x0, -0x30(%rbp)
je 0xd51b0
jmp 0xd5122
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0xd518b
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xd5150
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0xd515b
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0xd515b
movq -0x70(%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 -0x38(%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 0xd51b0
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl $0x3, -0x4(%rbp)
jmp 0xd51e3
movl -0x38(%rbp), %eax
shrl %eax
movl -0x14(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0xd51de
movl $0x7, -0x4(%rbp)
jmp 0xd51e3
jmp 0xd4e88
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)