// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_usg_tig(usg_t*, unsigned int, unsigned int*, long*, buf_t*)
inline uint32_t gen_usg_tig(usg_t *g, uint32_t sid, uint32_t *eid, int64_t *baseLen, buf_t* b)
{
    uint32_t v = sid, w, k, kv, nv, return_flag;
    usg_arc_t *av;
    (*baseLen) = 0; (*eid) = (uint32_t)-1;
    while (1) {
        kv = usg_arc_occ(g, v, NULL);
        (*eid) = v;
        if(b) kv_push(uint32_t, b->b, v);
        ///means reach the end of a unitig
        if(kv!=1) (*baseLen) += g->a[v>>1].len;
        if(kv==0) {
            return_flag = END_TIPS;
            break;
        } else if(kv>1) {
            return_flag = MUL_OUTPUT;
            break;
        }

        ///kv must be 1 here
        kv = usg_arc_occ(g, v, &w);
        if(usg_arc_occ(g, w^1, NULL)!=1) {
            (*baseLen) += g->a[v>>1].len;
            return_flag = MUL_INPUT;
            break;
        } else {
            av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
            for (k = 0; k < nv; k++) {
                if(av[k].del) continue;
                ///here is just one undeleted edge
                (*baseLen) += asg_arc_len(av[k]);
                break;
            }
        }

        v = w;
        if(v == sid) {
            return_flag = LOOP;
            break;
        } 
    }
    return return_flag;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x37db40
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x28(%rbp)
je 0x37d9ab
jmp 0x37d91f
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0x37d988
movq -0x28(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x37d94d
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x37d958
movl $0x2, %eax
movq %rax, -0x50(%rbp)
jmp 0x37d958
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x2c(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rsi
movq 0x38(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x38(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x37d9ab
cmpl $0x1, -0x38(%rbp)
je 0x37d9d5
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
cmpl $0x0, -0x38(%rbp)
jne 0x37d9e7
movl $0x5, -0x40(%rbp)
jmp 0x37db28
cmpl $0x1, -0x38(%rbp)
jbe 0x37d9f9
movl $0x4, -0x40(%rbp)
jmp 0x37db28
jmp 0x37d9fb
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
leaq -0x30(%rbp), %rdx
callq 0x37db40
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x37db40
cmpl $0x1, %eax
je 0x37da56
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x3, -0x40(%rbp)
jmp 0x37db28
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x2c(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x2c(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x37db0a
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x37dade
jmp 0x37daff
movq -0x48(%rbp), %rax
movl -0x34(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x37db0a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x37dabb
jmp 0x37db0c
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x37db23
movl $0x7, -0x40(%rbp)
jmp 0x37db28
jmp 0x37d8f6
movl -0x40(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)