// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r11
movl %esi, %r12d
movq %rdi, %rbx
movq %rcx, (%rsp)
movq $0x0, (%rcx)
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
movq (%rdi), %rax
movl %esi, %ebp
movq %r8, 0x8(%rsp)
movl %ebp, %ecx
shrl %ecx
movl %ebp, %edx
andl $0x1, %edx
imulq $0x78, %rcx, %rdi
addq %rdi, %rax
leaq (%rdx,%rdx,2), %r13
movl 0x10(%rax,%r13,8), %ecx
movl $0x0, %r15d
testq %rcx, %rcx
je 0x22d484
movq 0x20(%rax,%r13,8), %rax
shlq $0x5, %rcx
xorl %edx, %edx
xorl %r15d, %r15d
movl 0xc(%rax,%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r15d
addq $0x20, %rdx
cmpq %rdx, %rcx
jne 0x22d46f
movl %ebp, (%r11)
testq %r8, %r8
je 0x22d4ee
movq 0x38(%r8), %rcx
movq 0x48(%r8), %rax
cmpq 0x40(%r8), %rcx
jne 0x22d4e3
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r8)
shlq $0x2, %rsi
movq %rdi, 0x10(%rsp)
movq %rax, %rdi
movq %rbx, %r14
movl %r12d, %ebx
movq %r11, %r12
callq 0x2370
movq 0x10(%rsp), %rdi
movq %r12, %r11
movl %ebx, %r12d
movq %r14, %rbx
movq 0x8(%rsp), %r8
movq %rax, 0x48(%r8)
movq 0x38(%r8), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r8)
movl %ebp, (%rax,%rcx,4)
movq (%rbx), %rax
cmpl $0x1, %r15d
jne 0x22d5c5
movq %rdi, %r15
leaq (%rax,%rdi), %rdx
movl 0x10(%rdx,%r13,8), %ecx
movq 0x20(%rdx,%r13,8), %rdx
testq %rcx, %rcx
je 0x22d52e
movq %rcx, %rsi
shlq $0x5, %rsi
xorl %edi, %edi
cmpl $0x0, 0xc(%rdx,%rdi)
js 0x22d525
movl 0x8(%rdx,%rdi), %ebp
addq $0x20, %rdi
cmpq %rdi, %rsi
jne 0x22d51a
movl %ebp, %esi
notl %esi
movl %ebp, %edi
shrl %edi
andl $0x1, %esi
imulq $0x78, %rdi, %rdi
addq %rax, %rdi
leaq (%rsi,%rsi,2), %r9
movl 0x10(%rdi,%r9,8), %esi
testq %rsi, %rsi
je 0x22d5b2
movq 0x20(%rdi,%r9,8), %rdi
shlq $0x5, %rsi
xorl %r14d, %r14d
xorl %r9d, %r9d
movl 0xc(%rdi,%r14), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x20, %r14
cmpq %r14, %rsi
jne 0x22d55d
cmpl $0x1, %r9d
jne 0x22d5b2
testq %rcx, %rcx
je 0x22d5a2
shlq $0x5, %rcx
xorl %esi, %esi
cmpl $0x0, 0xc(%rdx,%rsi)
jns 0x22d598
addq $0x20, %rsi
cmpq %rsi, %rcx
jne 0x22d586
jmp 0x22d5a2
movl (%rdx,%rsi), %ecx
movq (%rsp), %rdx
addq %rcx, (%rdx)
cmpl %r12d, %ebp
jne 0x22d43d
movl $0x7, %eax
jmp 0x22d5d9
movl 0x8(%rax,%r15), %eax
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x3, %eax
jmp 0x22d5d9
movl 0x8(%rax,%rdi), %eax
movq (%rsp), %rcx
addq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x1, %r15d
adcl $0x4, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq