// File: /workspace/github_cpp_makefile_star2_O3/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, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
testq %rdx, %rdx
je 0x22d1cd
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
testq %rcx, %rcx
je 0x22d1d9
movq $0x0, (%rcx)
testq %r8, %r8
je 0x22d1e5
movq $0x0, (%r8)
testq %r9, %r9
je 0x22d1f1
movq $0x0, (%r9)
movq 0x60(%rsp), %r11
movq 0x10(%rsp), %rax
movq (%rax), %rbp
movl 0xc(%rsp), %r13d
movq %rdx, 0x18(%rsp)
movl %r13d, %eax
shrl %eax
movl %r13d, %esi
andl $0x1, %esi
imulq $0x78, %rax, %rbx
leaq (%rbx,%rbp), %rdi
leaq (%rsi,%rsi,2), %r15
movl 0x10(%rdi,%r15,8), %eax
movl $0x0, %r12d
testq %rax, %rax
je 0x22d253
movq 0x20(%rdi,%r15,8), %r10
shlq $0x5, %rax
xorl %esi, %esi
xorl %r12d, %r12d
movl 0xc(%r10,%rsi), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %r12d
addq $0x20, %rsi
cmpq %rsi, %rax
jne 0x22d23d
testq %rdx, %rdx
je 0x22d25b
movl %r13d, (%rdx)
testq %rcx, %rcx
je 0x22d267
movl 0x4(%rbp,%rbx), %eax
addq %rax, (%rcx)
testq %r11, %r11
je 0x22d2d4
movq (%r11), %rdi
movq 0x10(%r11), %rax
cmpq 0x8(%r11), %rdi
jne 0x22d2c6
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %edi
cmoveq %rdi, %rsi
movq %rsi, 0x8(%r11)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r8, %r14
movq %rbx, 0x20(%rsp)
movq %rcx, %rbx
movq %r9, %rbp
callq 0x2370
movq 0x60(%rsp), %r11
movq %rbp, %r9
movq %rbx, %rcx
movq 0x20(%rsp), %rbx
movq %r14, %r8
movq 0x18(%rsp), %rdx
movq %rax, 0x10(%r11)
movq (%r11), %rdi
movl %r13d, %r10d
leaq 0x1(%rdi), %rsi
movq %rsi, (%r11)
movq %r10, (%rax,%rdi,8)
testq %r9, %r9
je 0x22d2dc
incq (%r9)
testq %r8, %r8
je 0x22d2f6
cmpl $0x1, %r12d
je 0x22d2f6
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0x8(%rax,%rbx), %eax
addq %rax, (%r8)
cmpl $0x1, %r12d
jne 0x22d3d9
movq 0x10(%rsp), %rax
movq (%rax), %rbp
leaq (%rbx,%rbp), %rsi
movl 0x10(%rsi,%r15,8), %eax
movq 0x20(%rsi,%r15,8), %r14
testq %rax, %rax
je 0x22d33a
movq %rax, %rsi
shlq $0x5, %rsi
xorl %edi, %edi
cmpl $0x0, 0xc(%r14,%rdi)
js 0x22d331
movl 0x8(%r14,%rdi), %r13d
addq $0x20, %rdi
cmpq %rdi, %rsi
jne 0x22d324
movq %rbx, %r15
movl %r13d, %esi
notl %esi
movl %r13d, %edi
shrl %edi
andl $0x1, %esi
imulq $0x78, %rdi, %rdi
addq %rbp, %rdi
leaq (%rsi,%rsi,2), %r10
movl 0x10(%rdi,%r10,8), %esi
testq %rsi, %rsi
je 0x22d3ea
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 0x22d371
cmpl $0x1, %r11d
movq 0x60(%rsp), %r11
jne 0x22d3ea
testq %r8, %r8
sete %sil
testq %rax, %rax
sete %dil
orb %sil, %dil
jne 0x22d3c7
shlq $0x5, %rax
xorl %esi, %esi
cmpl $0x0, 0xc(%r14,%rsi)
jns 0x22d3c0
addq $0x20, %rsi
cmpq %rsi, %rax
jne 0x22d3ad
jmp 0x22d3c7
movl (%r14,%rsi), %eax
addq %rax, (%r8)
cmpl 0xc(%rsp), %r13d
jne 0x22d208
movl $0x7, %eax
jmp 0x22d3fc
movl $0x5, %eax
testl %r12d, %r12d
je 0x22d3fc
movl $0x4, %eax
jmp 0x22d3fc
movl $0x3, %eax
testq %r8, %r8
je 0x22d3fc
movl 0x8(%rbp,%r15), %ecx
addq %rcx, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq