// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movq %r9, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, (%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %r15
movq 0xb0(%rsp), %r14
andq $0x0, 0x8(%r14)
movq %rdi, 0x18(%rsp)
cmpq $0x0, 0x10(%r14)
movq (%r14), %rdi
je 0x16f033
xorl %eax, %eax
jmp 0x16f04d
movq $0x2, 0x10(%r14)
pushq $0x18
popq %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r14)
movq 0x8(%r14), %rax
leaq 0x1(%rax), %rbx
movq %rbx, 0x8(%r14)
imulq $0xc, %rax, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, (%rdi,%rax)
andl $0x0, 0x8(%rdi,%rax)
addq $0x4c, %r15
pushq $0x1
popq %rdx
cmpq 0x30(%rsp), %rdx
jge 0x16f237
cmpl $0x0, -0x20(%r15)
js 0x16f248
movq %rdi, 0x38(%rsp)
movq %rdx, 0x10(%rsp)
movslq -0x4(%r15), %r14
testq %r14, %r14
js 0x16f251
leaq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movl -0x44(%r15), %r12d
xorl $0x1, %r12d
movl %r12d, 0x40(%rsp)
movl %r14d, 0x44(%rsp)
movl (%r15), %r13d
movl %r13d, 0x48(%rsp)
movl $0x40000000, 0x4c(%rsp) # imm = 0x40000000
movq %r15, 0x8(%rsp)
movl -0x1c(%r15), %ebp
xorl $0x1, %ebp
movl %ebp, %edi
callq 0x15cdd5
movl %eax, %r15d
movl %r12d, %edi
callq 0x15cdd5
addl %r15d, %eax
cmpl %eax, %r13d
jne 0x16f125
movq (%rsp), %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x1664de
cmpq %r14, %rax
jne 0x16f125
imulq $0xc, %rbx, %rax
movq 0x38(%rsp), %rdi
movl %r14d, -0x8(%rdi,%rax)
movq 0x8(%rsp), %r15
movq 0xb0(%rsp), %r14
jmp 0x16f1e3
cvtsi2sd %r14d, %xmm0
mulsd 0x82906(%rip), %xmm0    # 0x1f1a38
cvttsd2si %xmm0, %r9d
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
pushq $0x1
popq %rcx
leaq 0x48(%rsp), %r8
movss 0x82931(%rip), %xmm0    # 0x1f1a88
pushq $0x1
popq %r15
pushq %r15
pushq %r15
movq 0xc8(%rsp), %r14
pushq %r14
pushq 0x48(%rsp)
leaq 0x98(%rsp), %rax
pushq %rax
pushq 0x50(%rsp)
pushq $0xf
callq 0x168290
addq $0x40, %rsp
movq 0x8(%r14), %rsi
movq %rsi, %rax
subq %rbx, %rax
cmpq %r15, %rax
jbe 0x16f270
movl 0x48(%rsp), %eax
cmpl 0x64(%rsp), %eax
movq 0x8(%rsp), %r15
jne 0x16f279
movq (%r14), %rax
imulq $0xc, %rsi, %rcx
movl -0x8(%rax,%rcx), %edx
subl -0x14(%rax,%rcx), %edx
imulq $0xc, %rbx, %rcx
leaq (%rax,%rcx), %rdi
movl %edx, -0x8(%rax,%rcx)
decq %rsi
movq %rsi, 0x8(%r14)
subq %rbx, %rsi
callq 0x1850ec
movq (%r14), %rdi
movq 0x8(%r14), %rbx
decq %rbx
movq %rbx, 0x8(%r14)
cmpq 0x10(%r14), %rbx
jne 0x16f20e
leaq (%rbx,%rbx), %rax
testq %rbx, %rbx
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x10(%r14)
imulq $0xc, %rax, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r14)
movq 0x8(%r14), %rbx
movq 0x10(%rsp), %rdx
imulq $0xc, %rbx, %rax
incq %rbx
movq %rbx, 0x8(%r14)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, (%rdi,%rax)
movl %edx, 0x8(%rdi,%rax)
incq %rdx
addq $0x28, %r15
jmp 0x16f06e
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x85305(%rip), %rdi     # 0x1f4554
jmp 0x16f258
leaq 0x82caa(%rip), %rdi     # 0x1f1f02
leaq 0x828c4(%rip), %rsi     # 0x1f1b23
leaq 0x852fd(%rip), %rcx     # 0x1f4563
movl $0x3955, %edx           # imm = 0x3955
callq 0x2110
leaq 0x85363(%rip), %rdi     # 0x1f45da
jmp 0x16f280
leaq 0x82d66(%rip), %rdi     # 0x1f1fe6
leaq 0x8289c(%rip), %rsi     # 0x1f1b23
leaq 0x852d5(%rip), %rcx     # 0x1f4563
movl $0x3966, %edx           # imm = 0x3966
callq 0x2110