// File: /workspace/github_cpp_makefile_star2_O3/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, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, 0x18(%rsp)
movq 0xa0(%rsp), %rbx
movq $0x0, 0x8(%rbx)
cmpq $0x0, 0x10(%rbx)
movq (%rbx), %r8
je 0x1b8bd4
xorl %eax, %eax
jmp 0x1b8bf3
movq $0x2, 0x10(%rbx)
movl $0x18, %esi
movq %r8, %rdi
callq 0x2370
movq %rax, %r8
movq %rax, (%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %r12
movq %r12, 0x8(%rbx)
leaq (%rax,%rax,2), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, (%r8,%rax,4)
movl $0x0, 0x8(%r8,%rax,4)
cmpq $0x2, 0x8(%rsp)
jl 0x1b8e1f
addq $0x4c, %r13
movl $0x1, %r15d
cmpl $0x0, -0x20(%r13)
js 0x1b8e3a
movslq -0x4(%r13), %rbp
testq %rbp, %rbp
js 0x1b8e31
leaq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movl -0x44(%r13), %edx
xorl $0x1, %edx
movl %edx, 0x30(%rsp)
movl %ebp, 0x34(%rsp)
movl (%r13), %eax
movl %eax, 0x38(%rsp)
movl $0x40000000, 0x3c(%rsp) # imm = 0x40000000
movl -0x1c(%r13), %r14d
xorl $0x1, %r14d
movl %r14d, %ecx
shll $0xf, %ecx
notl %ecx
addl %r14d, %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 0x1b8cfe
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq %r8, %rbx
callq 0x1af06e
cmpq %rbp, %rax
jne 0x1b8cfe
movq %rbx, %r8
leaq (%r12,%r12,2), %rax
movl %ebp, -0x8(%rbx,%rax,4)
movq 0xa0(%rsp), %rbx
jmp 0x1b8db9
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x86e5b(%rip), %xmm0    # 0x23fb68
cvttsd2si %xmm0, %r9d
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %r14d, %edx
movl $0x1, %ecx
leaq 0x38(%rsp), %r8
movss 0x86e97(%rip), %xmm0    # 0x23fbcc
movl $0x1, %ebp
pushq %rbp
pushq %rbp
movq 0xb8(%rsp), %rbx
pushq %rbx
pushq 0x48(%rsp)
leaq 0x88(%rsp), %rax
pushq %rax
pushq 0x50(%rsp)
pushq $0xf
callq 0x1b100b
addq $0x40, %rsp
movq 0x8(%rbx), %rsi
movq %rsi, %rax
subq %r12, %rax
cmpq %rbp, %rax
jbe 0x1b8e59
movl 0x38(%rsp), %eax
cmpl 0x54(%rsp), %eax
jne 0x1b8e62
movq (%rbx), %rax
leaq (%rsi,%rsi,2), %rcx
movl -0x8(%rax,%rcx,4), %edx
subl -0x14(%rax,%rcx,4), %edx
leaq (%r12,%r12,2), %rcx
leaq (%rax,%rcx,4), %rdi
movl %edx, -0x8(%rdi)
decq %rsi
movq %rsi, 0x8(%rbx)
subq %r12, %rsi
callq 0x1d12a5
movq (%rbx), %r8
movq 0x8(%rbx), %r12
decq %r12
movq %r12, 0x8(%rbx)
cmpq 0x10(%rbx), %r12
jne 0x1b8ded
leaq (%r12,%r12), %rax
testq %r12, %r12
movl $0x2, %ecx
cmoveq %rcx, %rax
movq %rax, 0x10(%rbx)
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
movq %r8, %rdi
callq 0x2370
movq %rax, %r8
movq %rax, (%rbx)
movq 0x8(%rbx), %r12
leaq 0x1(%r12), %rax
movq %rax, 0x8(%rbx)
leaq (%r12,%r12,2), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, (%r8,%rcx,4)
movl %r15d, 0x8(%r8,%rcx,4)
incq %r15
addq $0x28, %r13
movq %rax, %r12
cmpq %r15, 0x8(%rsp)
jne 0x1b8c27
jmp 0x1b8e22
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x87202(%rip), %rdi     # 0x24003a
jmp 0x1b8e41
leaq 0x8984b(%rip), %rdi     # 0x24268c
leaq 0x86e13(%rip), %rsi     # 0x23fc5b
leaq 0x8984c(%rip), %rcx     # 0x24269b
movl $0x3955, %edx           # imm = 0x3955
callq 0x2110
leaq 0x898b2(%rip), %rdi     # 0x242712
jmp 0x1b8e69
leaq 0x872b5(%rip), %rdi     # 0x24011e
leaq 0x86deb(%rip), %rsi     # 0x23fc5b
leaq 0x89824(%rip), %rcx     # 0x24269b
movl $0x3966, %edx           # imm = 0x3966
callq 0x2110