// File: /workspace/github_cpp_makefile_star2_O2/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 0x166bb1
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r14
movq 0x18(%rdi), %rax
movq %rax, (%rsp)
andq $0x0, 0x8(%rcx)
leaq 0x1(%rdx), %r13
movq (%rcx), %rax
cmpq %r13, 0x10(%rcx)
jae 0x166ad3
movq %r12, %rcx
shrq %rcx
orq %r12, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
incq %rcx
movq %rcx, 0x10(%rbx)
imulq $0x28, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq %r13, 0x8(%rbx)
xorps %xmm2, %xmm2
movups %xmm2, 0x10(%rax)
movups %xmm2, (%rax)
andq $0x0, 0x20(%rax)
movq (%rbx), %rax
movl $0x80000000, %ecx       # imm = 0x80000000
andl 0x4(%rax), %ecx
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
orl %r12d, %ecx
movl %ecx, 0x4(%rax)
movq (%rbx), %r12
orl $-0x1, 0x8(%r12)
addq $0x18, %r14
pushq $0x1
popq %r15
pushq $0x28
popq %rbp
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
cmpq %r13, %r15
jae 0x166bac
movups %xmm2, 0x10(%r12,%rbp)
movups %xmm2, (%r12,%rbp)
andq $0x0, 0x20(%r12,%rbp)
movl -0xc(%r14), %eax
movl (%r14), %esi
shrdl $0x1f, %eax, %esi
movq (%rbx), %r12
movl %esi, 0x8(%r12,%rbp)
orl $-0x1, 0x20(%r12,%rbp)
movl -0x18(%r14), %eax
movl %eax, (%r12,%rbp)
movl (%r14), %eax
andl %ecx, %eax
movl %eax, 0x1c(%r12,%rbp)
movsd -0x14(%r14), %xmm0
movsd -0x8(%r14), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movups %xmm1, 0xc(%r12,%rbp)
cmpq $0x2, %r15
jb 0x166b9c
xorl $0x1, %esi
movl -0x20(%r12,%rbp), %edx
xorl $0x1, %edx
movq (%rsp), %rdi
callq 0x1664de
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
xorps %xmm2, %xmm2
movl %eax, -0x8(%r12,%rbp)
testl %eax, %eax
js 0x166bc2
incq %r15
addq $0x28, %rbp
addq $0x1c, %r14
jmp 0x166b17
pushq $0x1
popq %rax
jmp 0x166bb3
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8bce5(%rip), %rdi     # 0x1f28ae
leaq 0x8af53(%rip), %rsi     # 0x1f1b23
leaq 0x8bd46(%rip), %rcx     # 0x1f291d
movl $0x11f4, %edx           # imm = 0x11F4
callq 0x2110