// File: chhylp123[P]hifiasm/inter.cpp
// Function: gen_linear_rchains(kv_ul_ov_t*, kv_ul_ov_t*, asg_t const*, ug_opt_t const*, long, double, long, Chain_Data*, long)
void gen_linear_rchains(kv_ul_ov_t *res, kv_ul_ov_t *buf, const asg_t *rg, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, int64_t qlen, Chain_Data* dp, int64_t ulid)
{
	uint64_t k, l, z, an, m, bn = buf->n; 
    radix_sort_ul_ov_srt_tn(res->a, res->a + res->n);
    ///after this function, res keeps unitig alignment, while buf keeps read alignments
    for (k = 1, l = m = 0; k <= res->n; k++) {
        if(k == res->n || res->a[k].tn != res->a[l].tn) {///qn <- (tn|rev)
			for (z = l; z < k; z++) res->a[z].tn>>=1;
			kv_resize(ul_ov_t, *buf, bn+k-l); 
			an = l + linear_rchain_dp_adv(res->a+l, k-l, buf->a+bn, uopt, bw, diff_ec_ul, qlen, 
			UG_SKIP_N, UG_ITER_N, UG_DIS_N, dp, rg, ulid);
			for (z = l; z < an; z++) res->a[m++] = res->a[z];
			l = k;
		}
    }
    res->n = m; 
	// kv_resize(ul_ov_t, *buf, bn+res->n);
	// int64_t iqs, iqe, its, ite;
	// for (k = 0, z = bn; k < res->n; k++) {
	// 	buf->a[z] = res->a[k]; res->a[k].qn = z; 
	// 	extend_end_coord(NULL, &(res->a[k]), qlen, rg->seq[res->a[k].tn].len, &iqs, &iqe, &its, &ite);
	// 	res->a[k].qs = iqs; res->a[k].qe = iqe; res->a[k].ts = its; res->a[k].te = ite;
	// 	z++;
	// }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27bdd0
movq $0x1, -0x40(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
ja 0x2e6e09
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x2e6bdd
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x48(%rbp), %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
je 0x2e6df6
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x2e6c14
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x50(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
shrl %ecx
movl %ecx, 0xc(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2e6be5
jmp 0x2e6c16
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
addq -0x40(%rbp), %rcx
subq -0x48(%rbp), %rcx
cmpq %rcx, %rax
jae 0x2e6cfd
movq -0x68(%rbp), %rcx
addq -0x40(%rbp), %rcx
subq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2e6cff
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
imulq $0x1c, -0x48(%rbp), %rax
addq %rax, %rdi
movq -0x40(%rbp), %rsi
subq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
imulq $0x1c, -0x68(%rbp), %rax
addq %rax, %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movsd -0x30(%rbp), %xmm0
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %r11
movq -0x18(%rbp), %r10
movq 0x18(%rbp), %rax
movq $0x64, (%rsp)
movq $0x1388, 0x8(%rsp)      # imm = 0x1388
movq $0xc350, 0x10(%rsp)     # imm = 0xC350
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x2e6040
movq %rax, %rcx
movq -0x70(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x2e6dee
movq -0x8(%rbp), %rax
movq (%rax), %rcx
imulq $0x1c, -0x50(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2e6d8e
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x2e6df8
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2e6b93
movq -0x60(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nop