// File: /workspace/github_cpp_makefile_star2_O1/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
movl %esi, %r12d
movq %rdi, %rbx
movq %rcx, (%rsp)
movq $0x0, (%rcx)
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
movl %esi, %ebp
movq %r8, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movl %ebp, %eax
shrl %eax
movl %ebp, %esi
andl $0x1, %esi
imulq $0x78, %rax, %r14
movq (%rbx), %rcx
addq %r14, %rcx
leaq (%rsi,%rsi,2), %r13
movl 0x10(%rcx,%r13,8), %eax
movl $0x0, %r15d
testq %rax, %rax
je 0x221ddf
movq 0x20(%rcx,%r13,8), %rcx
shlq $0x5, %rax
xorl %edi, %edi
xorl %r15d, %r15d
movl 0xc(%rcx,%rdi), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r15d
addq $0x20, %rdi
cmpq %rdi, %rax
jne 0x221dca
movl %ebp, (%rdx)
testq %r8, %r8
je 0x221e3e
movq 0x40(%r8), %rax
cmpq %rax, 0x38(%r8)
jne 0x221e2b
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%r8)
movq 0x48(%r8), %rdi
shlq $0x2, %rsi
movl %r12d, %ebx
movq %rdx, %r12
callq 0x2370
movq %r12, %rdx
movl %ebx, %r12d
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r8
movq %rax, 0x48(%r8)
movq 0x38(%r8), %rax
movq 0x48(%r8), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, 0x38(%r8)
movl %ebp, (%rcx,%rax,4)
movq (%rbx), %r11
cmpl $0x1, %r15d
jne 0x221f0c
leaq (%r11,%r14), %rcx
movl 0x10(%rcx,%r13,8), %eax
movq 0x20(%rcx,%r13,8), %rcx
movq %r14, %r15
testq %rax, %rax
je 0x221e7e
movq %rax, %rsi
shlq $0x5, %rsi
xorl %edi, %edi
cmpl $0x0, 0xc(%rcx,%rdi)
js 0x221e75
movl 0x8(%rcx,%rdi), %ebp
addq $0x20, %rdi
cmpq %rdi, %rsi
jne 0x221e6a
movl %ebp, %esi
notl %esi
movl %ebp, %edi
shrl %edi
andl $0x1, %esi
imulq $0x78, %rdi, %rdi
addq %r11, %rdi
leaq (%rsi,%rsi,2), %r9
movl 0x10(%rdi,%r9,8), %esi
testq %rsi, %rsi
je 0x221ef9
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 0x221ead
cmpl $0x1, %r9d
jne 0x221ef9
testq %rax, %rax
je 0x221ee9
cmpl $0x0, 0xc(%rcx)
jns 0x221ee0
addq $0x20, %rcx
decl %eax
jne 0x221ed0
jmp 0x221ee9
movl (%rcx), %eax
movq (%rsp), %rcx
addq %rax, (%rcx)
cmpl %r12d, %ebp
jne 0x221d95
movl $0x7, %eax
jmp 0x221f21
movl 0x8(%r11,%r15), %eax
movq (%rsp), %rcx
addq %rax, (%rcx)
movl $0x3, %eax
jmp 0x221f21
movl 0x8(%r11,%r14), %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