// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: dump_linear_chain(ma_ug_t*, kv_ul_ov_t*, vec_mg_lchain_t*, long, long)
void dump_linear_chain(ma_ug_t *ug, kv_ul_ov_t *lidx, vec_mg_lchain_t *res, int64_t qlen, int64_t ulid)
{
	uint64_t i; int64_t iqs, iqe, its, ite; mg_lchain_t *p;
	kv_resize(mg_lchain_t, *res, lidx->n);
	for (i = 0, res->n = 0; i < lidx->n; i++) {
		kv_pushp(mg_lchain_t, *res, &p); memset(p, 0, sizeof((*p)));
		// res->a[k].v = (autom->a[lidx->a[k].tn].tn<<1)|lidx->a[k].rev;
		p->v = (lidx->a[i].tn<<1)|(lidx->a[i].rev);
		///.off -> idx of original chain; cnt -> score of the chain
		p->off = i; p->score = lidx->a[i].sec;
		p->qs = lidx->a[i].qs; p->qe = lidx->a[i].qe;
		p->rs = lidx->a[i].ts; p->re = lidx->a[i].te; 
		// if(ulid == 123) {
		// 	fprintf(stderr, "+[M::%s::]\tutg%.6dl(%c)\tq::[%d, %d)\tqlen::%ld\tt::[%d, %d)\ttlen::%u\tsc::%d\n", __func__, 
        //                     (int32_t)(p->v>>1)+1, "+-"[p->v&1], p->qs, p->qe, qlen, 
		// 					p->rs, p->re, ug->g->seq[p->v>>1].len, p->score);
		// }
		extend_end_coord(p, NULL, qlen, ug->g->seq[p->v>>1].len, &iqs, &iqe, &its, &ite);
		p->qs = iqs; p->qe = iqe; p->rs = its; p->re = ite;
		// if(!ugl_cover_check(p->rs, p->re, &(ug->u.a[p->v>>1]))) res->n--;
		// fprintf(stderr, "chain_id:%d\t%u\t%u\t%c\tutg%.6dl(%u)\t%u\t%u\n", 
		// res->a[k].off, res->a[k].qs, res->a[k].qe, "+-"[res->a[k].v&1], (int32_t)(res->a[k].v>>1)+1, 
		// g->seq[res->a[k].v>>1].len, res->a[k].rs, res->a[k].re);
		// if(ulid == 14714) {
		// 	fprintf(stderr, "-[M::%s::]\tutg%.6dl(%c)\tq::[%d, %d)\tt::[%d, %d)\n", __func__, 
        //                     (int32_t)(p->v>>1)+1, "+-"[p->v&1], p->qs, p->qe, p->rs, p->re);
		// }
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movq 0x8(%rsi), %rax
cmpq %rax, 0x10(%rdx)
jae 0x184383
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x10(%r14)
movq (%r14), %rdi
imulq $0x28, %rcx, %rsi
callq 0x2370
movq %rax, (%r14)
andq $0x0, 0x8(%r14)
pushq $0x18
popq %rbp
xorl %ebx, %ebx
cmpq 0x8(%r15), %rbx
jae 0x184499
movq (%r14), %r13
movq 0x8(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0x1843cc
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r14)
imulq $0x28, %rcx, %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
movq %rax, (%r14)
movq 0x8(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r14)
imulq $0x28, %rax, %r12
leaq (%r12,%r13), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13,%r12)
andq $0x0, 0x20(%r13,%r12)
movups %xmm0, (%r13,%r12)
movq (%r15), %rax
movl -0xc(%rax,%rbp), %ecx
movl (%rax,%rbp), %edx
shrdl $0x1f, %ecx, %edx
movl %edx, 0x8(%r13,%r12)
movl %ebx, (%r13,%r12)
movl (%rax,%rbp), %ecx
movl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
andl %esi, %ecx
movl %ecx, 0x1c(%r13,%r12)
movsd -0x14(%rax,%rbp), %xmm0
movsd -0x8(%rax,%rbp), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movups %xmm1, 0xc(%r13,%r12)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
shrl %edx
movl (%rax,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %r8
leaq 0x28(%rsp), %r9
leaq 0x18(%rsp), %rax
pushq %rax
leaq 0x28(%rsp), %rax
pushq %rax
callq 0x184214
popq %rax
popq %rcx
movl 0x30(%rsp), %eax
movl %eax, 0x14(%r13,%r12)
movl 0x28(%rsp), %eax
movl %eax, 0x18(%r13,%r12)
movl 0x20(%rsp), %eax
movl %eax, 0xc(%r13,%r12)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%r13,%r12)
incq %rbx
addq $0x1c, %rbp
jmp 0x18438d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq