// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: follow_limit_path(asg_t*, unsigned int, unsigned int*, unsigned int*, asg64_v*, unsigned int)
uint32_t follow_limit_path(asg_t *g, uint32_t s, uint32_t *e, uint32_t *occ, asg64_v *b, uint32_t lim)
{
    
    uint32_t v = s, w = 0;
    uint32_t kv, kw;
    (*occ) = 0;


    while (1) {
        (*occ)++;
        kv = get_arcs(g, v, &w, 1);        
        (*e) = v;

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

        if(kv == 0) return END_TIPS;
        if(kv == 2) return TWO_OUTPUT;
        if(kv > 2) return MUL_OUTPUT;
        if((*occ) > lim) return LONG_TIPS;
        w = g->arc[w].v;
        ///up to here, kv=1
        ///kw must >= 1
        kw = get_arcs(g, w^1, NULL, 0);
        v = w;

        if(kw == 2) return TWO_INPUT;
        if(kw > 2) return MUL_INPUT;
        if(v == s) return LOOP;
    }

    return LONG_TIPS;   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %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)
movl $0x0, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
leaq -0x3c(%rbp), %rdx
movl $0x1, %ecx
callq 0x311ba0
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x311e9b
jmp 0x311e0f
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x311e77
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x311e3c
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x311e47
movl $0x2, %eax
movq %rax, -0x50(%rbp)
jmp 0x311e47
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x38(%rbp), %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x311e9b
cmpl $0x0, -0x40(%rbp)
jne 0x311ead
movl $0x5, -0x4(%rbp)
jmp 0x311f4c
cmpl $0x2, -0x40(%rbp)
jne 0x311ebf
movl $0x2, -0x4(%rbp)
jmp 0x311f4c
cmpl $0x2, -0x40(%rbp)
jbe 0x311ece
movl $0x4, -0x4(%rbp)
jmp 0x311f4c
movq -0x28(%rbp), %rax
movl (%rax), %eax
cmpl -0x34(%rbp), %eax
jbe 0x311ee2
movl $0x0, -0x4(%rbp)
jmp 0x311f4c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x2, -0x44(%rbp)
jne 0x311f27
movl $0x1, -0x4(%rbp)
jmp 0x311f4c
cmpl $0x2, -0x44(%rbp)
jbe 0x311f36
movl $0x3, -0x4(%rbp)
jmp 0x311f4c
movl -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x311f47
movl $0x7, -0x4(%rbp)
jmp 0x311f4c
jmp 0x311dd6
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)