// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_gchain_track(void*, mg_lchain_t*, long, asg_t const*, st_mt_t*, vec_sp_node_t*, vec_mg_pathv_t*)
uint32_t gen_gchain_track(void *km, mg_lchain_t *a, int64_t a_n, const asg_t *g, 
st_mt_t *dst_done, vec_sp_node_t *out, vec_mg_pathv_t *res)
{
	int64_t k, p_n/**, trav_occ = 0**/; mg_lchain_t *l0, *l1; mg_path_dst_t dst; uint64_t dst_group; mg_pathv_t *p;
	res->n = 0; kv_pushp(mg_pathv_t, *res, &p); p->v = (uint32_t)-1; p->d = 0; p->pre = 0;
	for (k = 1; k < a_n; k++) {
		l0 = a + k - 1; l1 = a + k;
		assert(!l1->inner_pre); assert(l1->dist_pre >= 0);
		memset(&dst, 0, sizeof(dst));
		dst.v = l0->v^1; 
		assert(l1->dist_pre >= 0);
		dst.target_dist = l1->dist_pre;
		dst.target_hash = l1->hash_pre;
		dst.check_hash = 1; p_n = res->n;
		if((dst.target_hash != (__ac_Wang_hash((l1->v^1))+__ac_Wang_hash(dst.v))) || 
													(g_adjacent_dis(g, l1->v^1, dst.v) != dst.target_dist)) {
			hc_shortest_k(km, g, l1->v^1, 1, &dst, dst.target_dist*(1+SEC_LEN_DIF), MG_MAX_SHORT_K, dst_done, &dst_group, out, res, 1, 1, SEC_LEN_DIF);
			// debug_gchain2(g, res->a + p_n, res->n - p_n);
			// fprintf(stderr, "[M::%s::n->%ld]\tutg%.6dl(%c)\t->\tutg%.6dl(%c)\n", __func__, res->n - p_n, 
			// (int32_t)(l0->v>>1)+1, "+-"[l0->v&1], (int32_t)(l1->v>>1)+1, "+-"[l1->v&1]);
			
			// fprintf(stderr, "\n-[M::%s::res->n->%u::p_n->%ld] utg%.6dl(v:%u) -> utg%.6dl(v:%u)\n", 
			// 			__func__, (uint32_t)res->n, p_n, (int32_t)(l1->v>>1)+1, l1->v, (int32_t)(l0->v>>1)+1, l0->v);
			// dbg_print(res->a + p_n, res->n - p_n);
			assert(res->n - p_n > 1); assert(dst.target_hash == dst.hash); 
			res->a[p_n-1].d = res->a[res->n-1].d - res->a[res->n-2].d; res->n--; 
			reverse_track(res->a + p_n, res->n - p_n); res->n--;///reomve l1 from res
			// trav_occ++;
		} else {
			res->a[p_n-1].d = dst.target_dist;
		}

		kv_pushp(mg_pathv_t, *res, &p); p->v = (uint32_t)-1; p->pre = k; p->d = 0;
		
	}
	// fprintf(stderr, "[M::%s::]\ta_n:%ld\ttrav_occ:%ld\n", __func__, a_n, trav_occ);
	return res->n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
movq 0xa0(%rsp), %r14
movq $0x0, 0x8(%r14)
cmpq $0x0, 0x10(%r14)
jne 0x1af983
movq $0x2, 0x10(%r14)
movq (%r14), %rdi
movl $0x18, %esi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq (%rcx,%rcx,2), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, (%rax,%rcx,4)
movl $0x0, 0x8(%rax,%rcx,4)
cmpq $0x2, %rbx
jl 0x1afbad
addq $0x4c, %r13
movl $0x1, %r12d
movq %rbx, 0x28(%rsp)
cmpl $0x0, -0x20(%r13)
js 0x1afbc9
movslq -0x4(%r13), %r15
testq %r15, %r15
js 0x1afbc0
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl -0x44(%r13), %edx
xorl $0x1, %edx
movl %edx, 0x30(%rsp)
movl %r15d, 0x34(%rsp)
movl (%r13), %eax
movl %eax, 0x38(%rsp)
orb $0x40, 0x3f(%rsp)
movq 0x8(%r14), %rbp
movl -0x1c(%r13), %ebx
xorl $0x1, %ebx
movl %ebx, %ecx
shll $0xf, %ecx
notl %ecx
addl %ebx, %ecx
movl %ecx, %esi
shrl $0xa, %esi
xorl %ecx, %esi
leal (%rsi,%rsi,8), %ecx
movl %ecx, %esi
shrl $0x6, %esi
xorl %ecx, %esi
movl %esi, %edi
shll $0xb, %edi
notl %edi
addl %esi, %edi
movl %edi, %ecx
shrl $0x10, %ecx
xorl %edi, %ecx
movl %edx, %esi
shll $0xf, %esi
notl %esi
addl %edx, %esi
movl %esi, %edi
shrl $0xa, %edi
xorl %esi, %edi
leal (%rdi,%rdi,8), %esi
movl %esi, %edi
shrl $0x6, %edi
xorl %esi, %edi
movl %edi, %esi
shll $0xb, %esi
notl %esi
addl %edi, %esi
movl %esi, %edi
shrl $0x10, %edi
xorl %esi, %edi
addl %ecx, %edi
cmpl %edi, %eax
jne 0x1afa95
movq 0x8(%rsp), %rdi
movl %ebx, %esi
callq 0x1a5df0
cmpq %r15, %rax
jne 0x1afa95
movq (%r14), %rax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movl %r15d, -0x8(%rax,%rcx,4)
jmp 0x1afb46
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x83df3(%rip), %xmm0    # 0x233898
cvttsd2si %xmm0, %r9d
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movl $0x1, %ecx
leaq 0x38(%rsp), %r8
movss 0x83e30(%rip), %xmm0    # 0x2338fc
movl $0x1, %ebx
pushq %rbx
pushq %rbx
pushq %r14
pushq 0x40(%rsp)
leaq 0x88(%rsp), %rax
pushq %rax
pushq 0x48(%rsp)
pushq $0xf
callq 0x1a7dd4
addq $0x40, %rsp
movq 0x8(%r14), %rsi
movq %rsi, %rax
subq %rbp, %rax
cmpq %rbx, %rax
jbe 0x1afbe8
movl 0x38(%rsp), %eax
cmpl 0x54(%rsp), %eax
jne 0x1afbf1
movq (%r14), %rax
leaq (%rsi,%rsi,2), %rcx
movl -0x8(%rax,%rcx,4), %edx
subl -0x14(%rax,%rcx,4), %edx
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
leaq (%rax,%rcx,4), %rdi
movl %edx, -0x8(%rdi)
decq %rsi
movq %rsi, 0x8(%r14)
subq %rbp, %rsi
callq 0x1c72c6
decq 0x8(%r14)
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
movq 0x28(%rsp), %rbx
jne 0x1afb7c
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r14)
movq (%r14), %rdi
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq (%rcx,%rcx,2), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, (%rax,%rcx,4)
movl %r12d, 0x8(%rax,%rcx,4)
incq %r12
addq $0x28, %r13
cmpq %r12, %rbx
jne 0x1af9c0
movl 0x8(%r14), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x841a3(%rip), %rdi     # 0x233d6a
jmp 0x1afbd0
leaq 0x867ec(%rip), %rdi     # 0x2363bc
leaq 0x83db4(%rip), %rsi     # 0x23398b
leaq 0x867ed(%rip), %rcx     # 0x2363cb
movl $0x3955, %edx           # imm = 0x3955
callq 0x2110
leaq 0x86853(%rip), %rdi     # 0x236442
jmp 0x1afbf8
leaq 0x84256(%rip), %rdi     # 0x233e4e
leaq 0x83d8c(%rip), %rsi     # 0x23398b
leaq 0x867c5(%rip), %rcx     # 0x2363cb
movl $0x3966, %edx           # imm = 0x3966
callq 0x2110