// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %r14d
movq %rdi, %r12
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %r10
movq 0x70(%rsp), %r11
xorl %ebp, %ebp
movq %r9, (%rsp)
movq %rbp, (%r9)
movq %rsi, %r9
movq %r8, 0x18(%rsp)
movq %rbp, (%r8)
movq %rbp, (%r10)
movq %rbp, (%r11)
movq %rcx, 0x30(%rsp)
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
movq 0x28(%r12), %rax
movl %edx, 0x24(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movl %r14d, %ebx
movl %r14d, %r13d
movq (%rax,%r13,8), %rax
movq %rax, %rcx
movl $0x0, %r15d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x105465
movq 0x8(%r12), %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 0x105451
movq 0x30(%rsp), %rax
movl %ebx, (%rax)
testq %r9, %r9
je 0x105483
movq 0x10(%r9), %rax
movl %ebx, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x4(%rax,%rcx,8), %eax
jmp 0x105488
movl $0x1, %eax
movq 0x18(%rsp), %rcx
addq %rax, (%rcx)
testq %rdi, %rdi
je 0x1054ed
movq 0x38(%rdi), %rcx
movq 0x48(%rdi), %rax
cmpq 0x40(%rdi), %rcx
jne 0x1054e2
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%rdi)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %r10
movq 0x70(%rsp), %r11
movq 0x28(%rsp), %r9
movq %rax, 0x48(%rdi)
movq 0x38(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%rdi)
movl %ebx, (%rax,%rcx,4)
cmpl $0x1, %r15d
jne 0x1056a0
movq 0x28(%r12), %rax
movq (%rax,%r13,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0x105549
movq 0x8(%r12), %rdi
movq %rdx, %r8
shrq $0x20, %r8
leaq (,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%r8,2), %r8
leaq (%rdi,%r8,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
cmpl $0x0, (%rdi,%r8)
js 0x105540
movl -0x4(%rdi,%r8), %r14d
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x105534
movl %r14d, %esi
xorl $0x1, %esi
movq (%rax,%rsi,8), %rdi
movq %rdi, %r8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %r8
je 0x1055f2
movq 0x8(%r12), %rsi
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %rdi
addq $0xc, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl (%rdi,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x18, %r9
cmpq %r9, %r8
jne 0x105587
cmpl $0x1, %r10d
movq 0x70(%rsp), %r11
movq 0x78(%rsp), %r10
movq 0x28(%rsp), %r9
jne 0x1055f2
testl %edx, %edx
je 0x10568a
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %esi, %esi
movq 0x88(%rsp), %rdi
cmpl $0x0, 0xc(%rdx,%rsi)
jns 0x105694
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x1055d9
jmp 0x10567d
incl %ebp
cmpl 0x80(%rsp), %ebp
jae 0x1056d3
testl %edx, %edx
movq 0x88(%rsp), %rdi
je 0x105644
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%r12), %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %esi, %esi
cmpl $0x0, 0xc(%rdx,%rsi)
jns 0x10563a
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x105628
jmp 0x105644
movl (%rdx,%rsi), %ecx
movq (%rsp), %rdx
addq %rcx, (%rdx)
movq (%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, %rdx
subq 0x8(%rsp), %rdx
cmpq (%r10), %rdx
jle 0x10565b
movq %rdx, (%r10)
movq 0x18(%rsp), %rdx
movq (%rdx), %rdx
movq %rdx, %rsi
subq 0x10(%rsp), %rsi
cmpq (%r11), %rsi
jle 0x105673
movq %rsi, (%r11)
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
cmpl 0x24(%rsp), %r14d
jne 0x105412
jmp 0x1056c5
movq 0x88(%rsp), %rdi
jmp 0x10567d
movl (%rdx,%rsi), %ecx
movq (%rsp), %rdx
addq %rcx, (%rdx)
jmp 0x10567d
movq 0x20(%r12), %rax
shrl %ebx
movl (%rax,%rbx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq (%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
xorl %eax, %eax
cmpl $0x1, %r15d
adcl $0x4, %eax
jmp 0x1056f2
movq (%rsp), %rax
movq (%rax), %rcx
movl $0x7, %eax
jmp 0x1056f2
movq 0x20(%r12), %rax
shrl %ebx
movl (%rax,%rbx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq (%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x3, %eax
subq 0x8(%rsp), %rcx
cmpq (%r10), %rcx
jle 0x1056ff
movq %rcx, (%r10)
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
subq 0x10(%rsp), %rcx
cmpq (%r11), %rcx
jle 0x105714
movq %rcx, (%r11)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq