// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rcx, (%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq 0x8(%rsi), %rax
cmpq %rax, 0x10(%rdx)
jae 0x1c640f
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
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%r14)
movq (%r14), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%r14)
movq $0x0, 0x8(%r14)
cmpq $0x0, 0x8(%r15)
je 0x1c6537
movl $0x18, %ebp
xorl %ebx, %ebx
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0x1c645a
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r14)
movq (%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
movq $0x0, 0x20(%r13)
movq (%r15), %rax
movl -0xc(%rax,%rbp), %ecx
movl (%rax,%rbp), %edx
shrdl $0x1f, %ecx, %edx
movl %edx, 0x8(%r13)
movl %ebx, (%r13)
movl (%rax,%rbp), %ecx
movl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
andl %esi, %ecx
movl %ecx, 0x1c(%r13)
movl -0x14(%rax,%rbp), %ecx
movl %ecx, 0x14(%r13)
movl -0x10(%rax,%rbp), %ecx
movl %ecx, 0x18(%r13)
movl -0x8(%rax,%rbp), %ecx
movl %ecx, 0xc(%r13)
movl -0x4(%rax,%rbp), %eax
movl %eax, 0x10(%r13)
movq 0x18(%r12), %rax
movq 0x20(%rax), %rax
shrl %edx
movl (%rax,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %r13, %rdi
xorl %esi, %esi
movq (%rsp), %rdx
leaq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
leaq 0x8(%rsp), %rax
pushq %rax
leaq 0x18(%rsp), %rax
pushq %rax
callq 0x1c62a4
addq $0x10, %rsp
movl 0x20(%rsp), %eax
movl %eax, 0x14(%r13)
movl 0x18(%rsp), %eax
movl %eax, 0x18(%r13)
movl 0x10(%rsp), %eax
movl %eax, 0xc(%r13)
movl 0x8(%rsp), %eax
movl %eax, 0x10(%r13)
incq %rbx
addq $0x1c, %rbp
cmpq 0x8(%r15), %rbx
jb 0x1c6429
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq