// File: /workspace/github_cpp_makefile_star2_O3/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 0x1af7c3
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
leaq 0x1(%rdx), %r12
movq 0x18(%rdi), %rax
movq %rax, (%rsp)
movq $0x0, 0x8(%rcx)
movq (%rcx), %rax
cmpq %r12, 0x10(%rcx)
jae 0x1af6bc
movq %r14, %rcx
shrq %rcx
orq %r14, %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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rbx)
leaq 0x8(,%rcx,8), %rcx
leaq (%rcx,%rcx,4), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq %r12, 0x8(%rbx)
xorps %xmm2, %xmm2
movups %xmm2, 0x10(%rax)
movups %xmm2, (%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), %r13
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
movl $0x1, %eax
cmpq $0x2, %r12
jb 0x1af7c5
addq $0x18, %r15
negq %r14
movl $0x1, %ebp
movl $0x28, %r12d
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movups %xmm2, 0x10(%r13,%r12)
movups %xmm2, (%r13,%r12)
movq $0x0, 0x20(%r13,%r12)
movl -0xc(%r15), %eax
movl (%r15), %esi
shrdl $0x1f, %eax, %esi
movq (%rbx), %r13
movl %esi, 0x8(%r13,%r12)
movl $0xffffffff, 0x20(%r13,%r12) # imm = 0xFFFFFFFF
movl -0x18(%r15), %eax
movl %eax, (%r13,%r12)
movl (%r15), %eax
andl %ecx, %eax
movl %eax, 0x1c(%r13,%r12)
movsd -0x14(%r15), %xmm0
movsd -0x8(%r15), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movups %xmm1, 0xc(%r13,%r12)
cmpq $0x2, %rbp
jb 0x1af7a0
xorl $0x1, %esi
movl -0x20(%r13,%r12), %edx
xorl $0x1, %edx
movq (%rsp), %rdi
callq 0x1af06e
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
xorps %xmm2, %xmm2
movl %eax, -0x8(%r13,%r12)
testl %eax, %eax
js 0x1af7d4
addq $0x1c, %r15
leaq (%r14,%rbp), %rax
incq %rax
incq %rbp
addq $0x28, %r12
cmpq $0x1, %rax
jne 0x1af71c
movl $0x1, %eax
jmp 0x1af7c5
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9120b(%rip), %rdi     # 0x2409e6
leaq 0x90479(%rip), %rsi     # 0x23fc5b
leaq 0x9126c(%rip), %rcx     # 0x240a55
movl $0x11f4, %edx           # imm = 0x11F4
callq 0x2110