// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_usg_unitig(usg_t*, unsigned int, unsigned int*, unsigned long*, unsigned long*, unsigned long*, asg64_v*)
inline uint32_t get_usg_unitig(usg_t *g, uint32_t begNode, uint32_t* endNode, 
uint64_t* nodeLen, uint64_t* baseLen, uint64_t *occ, asg64_v* b)
{
    uint32_t v = begNode, w, k; usg_arc_t *av;
    uint32_t nv, kv, return_flag;
    if(endNode) (*endNode) = (uint32_t)-1;
    if(nodeLen) (*nodeLen) = 0;
    if(baseLen) (*baseLen) = 0;
    if(occ) (*occ) = 0;

    while (1) {
        kv = undel_arcs(g, v, NULL);
        if(endNode) (*endNode) = v; 
        if(nodeLen) (*nodeLen) += g->a[v>>1].occ;
		
        if(b) kv_push(uint64_t, *b, v);
        if(occ) (*occ)++;
		///means reach the end of a unitig
		if(kv!=1 && baseLen) (*baseLen) += g->a[v>>1].len;
		if(kv==0) {
			return_flag = END_TIPS; break;
		} 
		if(kv>1) {
			return_flag = MUL_OUTPUT; break;
		}
        ///kv must be 1 here
        kv = undel_arcs(g, v, &w);
        ///means reach the end of a unitig
        if(undel_arcs(g, w^1, NULL)!=1) {
            if(baseLen) (*baseLen) += g->a[v>>1].len;
            return_flag = MUL_INPUT; break;
        } else if(baseLen) {
            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 == begNode){
			return_flag = LOOP; break;
		} 
    }

	return return_flag;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
testq %rdx, %rdx
je 0x221b26
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
testq %rcx, %rcx
je 0x221b32
movq $0x0, (%rcx)
testq %r8, %r8
je 0x221b3e
movq $0x0, (%r8)
testq %r9, %r9
je 0x221b4a
movq $0x0, (%r9)
movq 0x60(%rsp), %r15
movl %ebp, %r14d
movq %rdi, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq (%rdi), %rax
movl %r14d, %r10d
shrl %r10d
movl %r14d, %esi
andl $0x1, %esi
imulq $0x78, %r10, %r10
movq %r10, 0x8(%rsp)
leaq (%rax,%r10), %r11
leaq (%rsi,%rsi,2), %r12
movl 0x10(%r11,%r12,8), %r10d
movl $0x0, %r13d
testq %r10, %r10
je 0x221bb5
movq 0x20(%r11,%r12,8), %r11
shlq $0x5, %r10
xorl %esi, %esi
xorl %r13d, %r13d
movl 0xc(%r11,%rsi), %ebx
notl %ebx
shrl $0x1f, %ebx
addl %ebx, %r13d
addq $0x20, %rsi
cmpq %rsi, %r10
jne 0x221b9f
testq %rdx, %rdx
je 0x221bbd
movl %r14d, (%rdx)
testq %rcx, %rcx
je 0x221bce
movq 0x8(%rsp), %rsi
movl 0x4(%rax,%rsi), %eax
addq %rax, (%rcx)
testq %r15, %r15
je 0x221c3c
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x221c27
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rsi
movq %rcx, %rbx
movl %ebp, %r15d
movq %r9, %rbp
callq 0x2370
movq %rbp, %r9
movl %r15d, %ebp
movq 0x60(%rsp), %r15
movq %rbx, %rcx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %rdx
movq %rax, 0x10(%r15)
movl %r14d, %eax
movq (%r15), %r11
movq 0x10(%r15), %r10
leaq 0x1(%r11), %rsi
movq %rsi, (%r15)
movq %rax, (%r10,%r11,8)
testq %r9, %r9
je 0x221c44
incq (%r9)
testq %r8, %r8
je 0x221c5e
cmpl $0x1, %r13d
je 0x221c5e
movq (%rdi), %rax
movq 0x8(%rsp), %rsi
movl 0x8(%rax,%rsi), %eax
addq %rax, (%r8)
cmpl $0x1, %r13d
jne 0x221d2d
movq (%rdi), %r15
movq 0x8(%rsp), %rax
leaq (%r15,%rax), %rsi
movl 0x10(%rsi,%r12,8), %eax
movq 0x20(%rsi,%r12,8), %r12
testq %rax, %rax
je 0x221ca2
movq %rax, %rsi
shlq $0x5, %rsi
xorl %edi, %edi
cmpl $0x0, 0xc(%r12,%rdi)
js 0x221c99
movl 0x8(%r12,%rdi), %r14d
addq $0x20, %rdi
cmpq %rdi, %rsi
jne 0x221c8c
movl %r14d, %esi
notl %esi
movl %r14d, %edi
shrl %edi
andl $0x1, %esi
imulq $0x78, %rdi, %rdi
addq %r15, %rdi
leaq (%rsi,%rsi,2), %r10
movl 0x10(%rdi,%r10,8), %esi
testq %rsi, %rsi
je 0x221d3e
movq 0x20(%rdi,%r10,8), %rdi
shlq $0x5, %rsi
xorl %ebx, %ebx
xorl %r11d, %r11d
movl 0xc(%rdi,%rbx), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r11d
addq $0x20, %rbx
cmpq %rbx, %rsi
jne 0x221cd2
cmpl $0x1, %r11d
movq 0x10(%rsp), %rdi
jne 0x221d3e
testq %r8, %r8
movq 0x60(%rsp), %r15
je 0x221d1d
testq %rax, %rax
je 0x221d1d
cmpl $0x0, 0xc(%r12)
jns 0x221d16
addq $0x20, %r12
decl %eax
jne 0x221d04
jmp 0x221d1d
movl (%r12), %eax
addq %rax, (%r8)
cmpl %ebp, %r14d
jne 0x221b61
movl $0x7, %eax
jmp 0x221d55
movl $0x4, %eax
testl %r13d, %r13d
jne 0x221d55
movl $0x5, %eax
jmp 0x221d55
movl $0x3, %eax
testq %r8, %r8
je 0x221d55
movq 0x8(%rsp), %rcx
movl 0x8(%r15,%rcx), %ecx
addq %rcx, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq