// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: l2g_res_chain_sc(ma_ug_t*, ul_ov_t*, unsigned long, vec_mg_lchain_t*)
int64_t l2g_res_chain_sc(ma_ug_t *ug, ul_ov_t *a, uint64_t a_n, vec_mg_lchain_t *gchains)
{
	// fprintf(stderr, "[M::%s::] a_n::%lu\n", __func__, a_n);
	if(a_n <= 0) return 0;
	uint64_t k, m; int64_t l; a_n++; asg_t *g = ug->g;
	gchains->n = 0; kv_resize(mg_lchain_t, *gchains, a_n); gchains->n = a_n;
	memset(&(gchains->a[0]), 0, sizeof(gchains->a[0])); 
	gchains->a[0].cnt = a_n - 1; gchains->a[0].v = (uint32_t)-1;
	for (k = 1, m = 0, l = 0; k < a_n; k++, m++) {
		memset(&(gchains->a[k]), 0, sizeof(gchains->a[k]));
		gchains->a[k].v = (a[m].tn<<1)|(a[m].rev); gchains->a[k].dist_pre = -1;
		gchains->a[k].off = a[m].qn; gchains->a[k].score = a[m].sec;
		gchains->a[k].qs = a[m].qs; gchains->a[k].qe = a[m].qe;
		gchains->a[k].rs = a[m].ts; gchains->a[k].re = a[m].te; 
		if(k > 1) {
			gchains->a[k-1].dist_pre = g_adjacent_dis(g, gchains->a[k].v^1, gchains->a[k-1].v^1);
			assert(gchains->a[k-1].dist_pre >= 0);
			l += g->seq[gchains->a[k-1].v>>1].len + gchains->a[k-1].dist_pre;
		}
		// fprintf(stderr, "[M::%s::k->%lu] utg%.6dl(%c)\n", __func__, k, (int32_t)(gchains->a[k].v>>1)+1, "+-"[gchains->a[k].v&1]);
	}

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdx, %rdx
je 0x1a656a
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
leaq 0x1(%rdx), %r12
movq 0x18(%rdi), %rax
movq %rax, (%rsp)
movq $0x0, 0x8(%rcx)
cmpq %r12, 0x10(%rcx)
jae 0x1a6453
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq 0x8(,%rax,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%rbx)
movq %r12, 0x8(%rbx)
movq (%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x20(%rax)
movq (%rbx), %rax
movl %r14d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl $0x80000000, %edx       # imm = 0x80000000
andl 0x4(%rax), %edx
orl %ecx, %edx
movl %edx, 0x4(%rax)
movq (%rbx), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl $0x1, %eax
cmpq $0x2, %r12
jb 0x1a656c
addq $0x18, %r15
negq %r14
movl $0x1, %r13d
movl $0x28, %ebp
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movq (%rbx), %rax
movups %xmm0, 0x10(%rax,%rbp)
movups %xmm0, (%rax,%rbp)
movq $0x0, 0x20(%rax,%rbp)
movl -0xc(%r15), %eax
movl (%r15), %esi
shrdl $0x1f, %eax, %esi
movq (%rbx), %r12
movl %esi, 0x8(%r12,%rbp)
movl $0xffffffff, 0x20(%r12,%rbp) # imm = 0xFFFFFFFF
movl -0x18(%r15), %eax
movl %eax, (%r12,%rbp)
movl (%r15), %eax
andl %ecx, %eax
movl %eax, 0x1c(%r12,%rbp)
movl -0x14(%r15), %eax
movl %eax, 0x14(%r12,%rbp)
movl -0x10(%r15), %eax
movl %eax, 0x18(%r12,%rbp)
movl -0x8(%r15), %eax
movl %eax, 0xc(%r12,%rbp)
movl -0x4(%r15), %eax
movl %eax, 0x10(%r12,%rbp)
cmpq $0x2, %r13
jb 0x1a6547
xorl $0x1, %esi
movl -0x20(%r12,%rbp), %edx
xorl $0x1, %edx
movq (%rsp), %rdi
callq 0x1a5df0
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
xorps %xmm0, %xmm0
movl %eax, -0x8(%r12,%rbp)
testl %eax, %eax
js 0x1a657b
addq $0x1c, %r15
leaq (%r14,%r13), %rax
incq %rax
incq %r13
addq $0x28, %rbp
cmpq $0x1, %rax
jne 0x1a64b5
movl $0x1, %eax
jmp 0x1a656c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8e194(%rip), %rdi     # 0x234716
leaq 0x8d402(%rip), %rsi     # 0x23398b
leaq 0x8e1f5(%rip), %rcx     # 0x234785
movl $0x11f4, %edx           # imm = 0x11F4
callq 0x2110