// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x37d50a
movq -0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
cmpq $0x0, -0x20(%rbp)
je 0x37d51c
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x28(%rbp)
je 0x37d52e
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x37d540
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
jmp 0x37d542
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x37d7e0
movl %eax, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x37d565
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x37d590
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0x37d629
jmp 0x37d59d
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x37d605
movq 0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x37d5ca
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x37d5d5
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x37d5d5
movq -0x60(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %eax
movl %eax, %edx
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x37d629
cmpq $0x0, -0x30(%rbp)
je 0x37d63e
movq -0x30(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
cmpl $0x1, -0x50(%rbp)
je 0x37d66f
cmpq $0x0, -0x28(%rbp)
je 0x37d66f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
cmpl $0x0, -0x50(%rbp)
jne 0x37d681
movl $0x5, -0x54(%rbp)
jmp 0x37d7d4
cmpl $0x1, -0x50(%rbp)
jbe 0x37d693
movl $0x4, -0x54(%rbp)
jmp 0x37d7d4
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x38(%rbp), %rdx
callq 0x37d7e0
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x37d7e0
cmpl $0x1, %eax
je 0x37d6f5
cmpq $0x0, -0x28(%rbp)
je 0x37d6e9
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x3, -0x54(%rbp)
jmp 0x37d7d4
cmpq $0x0, -0x28(%rbp)
je 0x37d7b6
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x34(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x34(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x37d7b4
movq -0x48(%rbp), %rax
movl -0x3c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x37d788
jmp 0x37d7a9
movq -0x48(%rbp), %rax
movl -0x3c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x37d7b4
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x37d765
jmp 0x37d7b6
jmp 0x37d7b8
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x37d7cf
movl $0x7, -0x54(%rbp)
jmp 0x37d7d4
jmp 0x37d542
movl -0x54(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)