// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/./Overlaps.h
// Function: get_unitig(asg_t*, ma_ug_t*, unsigned int, unsigned int*, long long*, long long*, long long*, long long*, unsigned int, buf_t*)
inline uint32_t get_unitig(asg_t *sg, ma_ug_t *ug, uint32_t begNode, uint32_t* endNode, 
long long* nodeLen, long long* baseLen, long long* max_stop_nodeLen, long long* max_stop_baseLen, 
uint32_t stops_threshold, buf_t* b)
{
	ma_utg_v* u = NULL; 
    uint32_t v = begNode, w, k;
    uint32_t kv, return_flag, n_stops = 0;
	long long pre_baseLen = 0, pre_nodeLen = 0;
	long long cur_baseLen = 0, cur_nodeLen = 0;
	(*max_stop_nodeLen) = (*max_stop_baseLen) = (*nodeLen) = (*baseLen) = 0;
    (*endNode) = (uint32_t)-1;
	if(ug!=NULL) u = &(ug->u);

    while (1)
    {
        kv = get_real_length(sg, v, NULL);
        (*endNode) = v;
		if(u == NULL) 
		{
			(*nodeLen)++;
		}
		else
		{
			(*nodeLen) += EvaluateLen((*u), v>>1);
		}
        if(b) kv_push(uint32_t, b->b, v);
		///means reach the end of a unitig
		if(kv!=1) (*baseLen) += sg->seq[v>>1].len;
		if(kv==0)
		{
			return_flag = END_TIPS;
			break;
			///return END_TIPS;
		} 
		if(kv>1)
		{
			return_flag = MUL_OUTPUT;
			break;
			///return MUL_OUTPUT;
		}
        ///kv must be 1 here
        kv = get_real_length(sg, v, &w);
		///means reach the end of a unitig
        if(get_real_length(sg, w^1, NULL)!=1)
		{

			n_stops++;
			if(n_stops >= stops_threshold)
			{
				(*baseLen) += sg->seq[v>>1].len;
				return_flag = MUL_INPUT;
				break;
				///return MUL_INPUT;
			}
			else
			{
				for (k = 0; k < asg_arc_n(sg, v); k++)
				{
					if(asg_arc_a(sg, v)[k].del) continue;
					///here is just one undeleted edge
					(*baseLen) += asg_arc_len(asg_arc_a(sg, v)[k]);
					break;
				}
			}

			cur_baseLen = (*baseLen) - pre_baseLen;
			pre_baseLen = (*baseLen);
			if(cur_baseLen > (*max_stop_baseLen))
			{
				(*max_stop_baseLen) = cur_baseLen;
			}


			cur_nodeLen = (*nodeLen) - pre_nodeLen;
			pre_nodeLen = (*nodeLen);
			if(cur_nodeLen > (*max_stop_nodeLen))
			{
				(*max_stop_nodeLen) = cur_nodeLen;
			}
		}
		else
		{
			for (k = 0; k < asg_arc_n(sg, v); k++)
			{
				if(asg_arc_a(sg, v)[k].del) continue;
				///here is just one undeleted edge
				(*baseLen) += asg_arc_len(asg_arc_a(sg, v)[k]);
				break;
			}
		}
		

        v = w;
        if(v == begNode)
		{
			return_flag = LOOP;
			break;
			///return LOOP;
		} 
    }




	cur_baseLen = (*baseLen) - pre_baseLen;
	pre_baseLen = (*baseLen);
	if(cur_baseLen > (*max_stop_baseLen))
	{
		(*max_stop_baseLen) = cur_baseLen;
	}


	cur_nodeLen = (*nodeLen) - pre_nodeLen;
	pre_nodeLen = (*nodeLen);
	if(cur_nodeLen > (*max_stop_nodeLen))
	{
		(*max_stop_nodeLen) = cur_nodeLen;
	}

	return return_flag;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, 0x38(%rsp)
movq 0x98(%rsp), %r11
movq 0x88(%rsp), %rbx
movq 0x80(%rsp), %r10
xorl %eax, %eax
movq %rax, (%r9)
movq %rax, (%r8)
movq %rax, (%rbx)
movq $0x0, 0x20(%rsp)
movq %rax, (%r10)
movq %rcx, 0x40(%rsp)
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
movl %edx, 0x14(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rdi, 0x18(%rsp)
movl %ebp, %ecx
movq 0x28(%rdi), %rax
movq %rcx, 0x8(%rsp)
movl %ecx, %r13d
movq (%rax,%r13,8), %rax
movq %rax, %rcx
movl $0x0, %r15d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x101157
movq 0x8(%rdi), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %r15d, %r15d
movl (%rax,%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %r15d
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x101143
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rsi
movl %esi, (%rax)
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x10117f
movq 0x10(%rax), %rax
movl %esi, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x4(%rax,%rcx,8), %eax
jmp 0x101184
movl $0x1, %eax
addq %rax, (%r8)
testq %r11, %r11
je 0x101212
movq 0x40(%r11), %rax
cmpq %rax, 0x38(%r11)
jne 0x1011ff
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x40(%r11)
movq 0x48(%r11), %rdi
shlq $0x2, %rsi
movq %r12, 0x28(%rsp)
movq %r8, %r12
movq %r14, 0x30(%rsp)
movq %r10, %r14
movq %r9, %rbx
callq 0x2370
movq 0x8(%rsp), %rsi
movq 0x98(%rsp), %r11
movq 0x18(%rsp), %rdi
movq %rbx, %r9
movq 0x88(%rsp), %rbx
movq %r14, %r10
movq 0x30(%rsp), %r14
movq %r12, %r8
movq 0x28(%rsp), %r12
movq %rax, 0x48(%r11)
movq 0x38(%r11), %rax
movq 0x48(%r11), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x38(%r11)
movl %esi, (%rcx,%rax,4)
cmpl $0x1, %r15d
jne 0x101388
movq 0x28(%rdi), %rcx
movq (%rcx,%r13,8), %rax
movq %rax, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0x101268
movq 0x8(%rdi), %rsi
movq %rax, %r11
shrq $0x20, %r11
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%r11,%r11,2), %r11
leaq (%rsi,%r11,8), %rsi
addq $0xc, %rsi
xorl %r11d, %r11d
cmpl $0x0, (%rsi,%r11)
js 0x10125f
movl -0x4(%rsi,%r11), %ebp
addq $0x18, %r11
cmpq %r11, %rdx
jne 0x101253
movl %ebp, %edx
xorl $0x1, %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0x1012f6
movq 0x8(%rdi), %rsi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
xorl %edi, %edi
movl (%rcx,%rsi), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %edi
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0x10129e
cmpl $0x1, %edi
movq 0x18(%rsp), %rdi
jne 0x1012f6
testl %eax, %eax
je 0x101377
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%rdi), %rcx
movq 0x98(%rsp), %r11
cmpl $0x0, 0xc(%rcx)
jns 0x101381
addq $0x18, %rcx
decl %eax
jne 0x1012e2
jmp 0x10136b
movq 0x20(%rsp), %rcx
incl %ecx
cmpl 0x90(%rsp), %ecx
jae 0x1013ab
movq %rcx, 0x20(%rsp)
testl %eax, %eax
movq 0x98(%rsp), %r11
je 0x101343
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%rdi), %rcx
cmpl $0x0, 0xc(%rcx)
jns 0x10133e
addq $0x18, %rcx
decl %eax
jne 0x10132e
jmp 0x101343
movl (%rcx), %eax
addq %rax, (%r9)
movq (%r9), %rax
movq %rax, %rcx
subq %r12, %rcx
cmpq (%rbx), %rcx
jle 0x101354
movq %rcx, (%rbx)
movq (%r8), %rcx
movq %rcx, %rdx
subq %r14, %rdx
cmpq (%r10), %rdx
jle 0x101365
movq %rdx, (%r10)
movq %rax, %r12
movq %rcx, %r14
cmpl 0x14(%rsp), %ebp
jne 0x1010fd
jmp 0x1013a4
movq 0x98(%rsp), %r11
jmp 0x10136b
movl (%rcx), %eax
addq %rax, (%r9)
jmp 0x10136b
movq 0x20(%rdi), %rax
shrl %esi
movl (%rax,%rsi,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r9)
xorl %eax, %eax
cmpl $0x1, %r15d
adcl $0x4, %eax
jmp 0x1013c6
movl $0x7, %eax
jmp 0x1013c6
movq 0x20(%rdi), %rax
movq 0x8(%rsp), %rcx
shrl %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, (%r9)
movl $0x3, %eax
movq (%r9), %rcx
subq %r12, %rcx
cmpq (%rbx), %rcx
jle 0x1013d4
movq %rcx, (%rbx)
movq (%r8), %rcx
subq %r14, %rcx
cmpq (%r10), %rcx
jle 0x1013e2
movq %rcx, (%r10)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq