// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %r8, %rbx
movq %rdx, %r13
movl %esi, (%rsp)
movq %rdi, %r14
testq %rdx, %rdx
je 0x1dee96
orl $-0x1, (%r13)
testq %rcx, %rcx
je 0x1dee9f
andq $0x0, (%rcx)
testq %rbx, %rbx
je 0x1deea8
andq $0x0, (%rbx)
movq %rcx, 0x8(%rsp)
testq %r9, %r9
je 0x1deeb6
andq $0x0, (%r9)
movq %r9, 0x10(%rsp)
movq 0x50(%rsp), %r12
movl (%rsp), %eax
movl %eax, %ebp
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x1df024
movl %eax, %r15d
testq %r13, %r13
je 0x1deedd
movl %ebp, (%r13)
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
je 0x1deef9
movq (%r14), %rax
movl %ebp, %ecx
shrl %ecx
imulq $0x78, %rcx, %rcx
movl 0x4(%rax,%rcx), %eax
addq %rax, (%rdx)
testq %r12, %r12
je 0x1def44
movq (%r12), %rcx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x1def36
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movl %ebp, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x1def51
incq (%rax)
testq %rbx, %rbx
sete %al
cmpl $0x1, %r15d
sete %cl
orb %al, %cl
jne 0x1def74
movq (%r14), %rax
movl %ebp, %ecx
shrl %ecx
imulq $0x78, %rcx, %rcx
movl 0x8(%rax,%rcx), %eax
addq %rax, (%rbx)
cmpl $0x1, %r15d
jne 0x1deff0
movq %r14, %rdi
movl %ebp, %esi
leaq 0x4(%rsp), %rdx
callq 0x1df024
movl 0x4(%rsp), %esi
xorl $0x1, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x1df024
cmpl $0x1, %eax
jne 0x1deffd
testq %rbx, %rbx
je 0x1defdf
movl %ebp, %eax
shrl %eax
andl $0x1, %ebp
imulq $0x78, %rax, %rcx
addq (%r14), %rcx
imulq $0x18, %rbp, %rdx
movq 0x20(%rdx,%rcx), %rax
movl 0x10(%rdx,%rcx), %ecx
shlq $0x5, %rcx
pushq $-0x20
popq %rdx
leaq 0x20(%rdx), %rsi
cmpq %rsi, %rcx
je 0x1defdf
cmpl $0x0, 0x2c(%rax,%rdx)
movq %rsi, %rdx
js 0x1defc6
movl (%rax,%rsi), %eax
addq %rax, (%rbx)
movl 0x4(%rsp), %ebp
cmpl (%rsp), %ebp
jne 0x1deec5
pushq $0x7
jmp 0x1deffa
testl %r15d, %r15d
pushq $0x4
popq %rax
jne 0x1df015
pushq $0x5
popq %rax
jmp 0x1df015
pushq $0x3
popq %rax
testq %rbx, %rbx
je 0x1df015
movq (%r14), %rdx
shrl %ebp
imulq $0x78, %rbp, %rcx
movl 0x8(%rdx,%rcx), %ecx
addq %rcx, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq