// File: chhylp123[P]hifiasm/inter.cpp
// Function: gen_rovlp_chain_by_ul(asg_t const*, ul_vec_t*, ul_idx_t const*, kv_ul_ov_t*, kv_ul_ov_t*, mg_lchain_t*, long, vec_mg_lchain_t*, Chain_Data*, long, long, long, long)
void gen_rovlp_chain_by_ul(const asg_t *rg, ul_vec_t *rch, const ul_idx_t *uref, kv_ul_ov_t *raw_idx, kv_ul_ov_t *raw_chn, mg_lchain_t *a, int64_t a_n, vec_mg_lchain_t *res, Chain_Data* dp, 
int64_t dp_max_skip, int64_t dp_max_iter, int64_t dp_max_dis, int64_t ulid)
{
	if(a_n == 0) return;
	int64_t k, l, res_n0 = res->n, tt = 0; ma_ug_t *ug = uref->ug;
	// fprintf(stderr, "***[M::%s::a_n->%ld]\n", __func__, a_n);
	///a[0, a_n) is a gchain of untigs
	for (k = 0, l = ug->g->seq[a[0].v>>1].len; k < a_n; k++) {
		// fprintf(stderr, ">k->%ld, ls->%ld, le->%ld, rev->%c\n", k, l - ug->g->seq[a[k].v>>1].len, l, "+-"[a[k].v&1]);
		l -= ug->g->seq[a[k].v>>1].len;
		gl_ug2rg_gen(rg, rch, ug, &(a[k]), res, l, ulid, raw_idx, raw_chn);
		l += ug->g->seq[a[k].v>>1].len + a[k].dist_pre;
	}
	mg_lchain_t *x = res->a + res_n0; int64_t x_n = res->n - res_n0, fn;
	fn = flat_rovlp_chain(ug, x, x_n, dp, dp_max_skip, dp_max_iter, dp_max_dis);
	// fprintf(stderr, "***[M::%s::x_n->%ld] fn::%ld\n", __func__, x_n, fn);
	if(fn) {
		for (l = -1, k = 0; k <= x_n; k++) {
			if(k < x_n) {
				if(k > 0) x[k].hash_pre = k-1+res_n0;
				else x[k].hash_pre = (uint32_t)-1;
				if(x[k].qs >= 0) tt++;
			}
			if(k == x_n || x[k].qs >=0) { ///x[k] and x[l] are anchors
				if(k-l>1) {
					update_rovlp_chain_qse(ug, l, k, x, x_n, rch->rlen);
					// update_rovlp_chain_qse_back(ug, l, k, x, x_n);
				}
				l = k;
			}
		}
		assert(tt > 0);
	} else {
		res->n = res_n0;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
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)
movq %r9, -0x30(%rbp)
cmpq $0x0, 0x10(%rbp)
jne 0x2da76b
jmp 0x2daa01
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq 0x10(%rbp), %rax
jge 0x2da88b
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x30(%rbp), %rcx
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rcx
movq 0x18(%rbp), %r8
movq -0x40(%rbp), %r9
movq 0x40(%rbp), %r11
movq -0x20(%rbp), %r10
movq -0x28(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x2d8cb0
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
addl 0x20(%rcx), %eax
cltq
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2da7b7
movq 0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq 0x20(%rbp), %rcx
movq 0x28(%rbp), %r8
movq 0x30(%rbp), %r9
movq 0x38(%rbp), %rax
movq %rax, (%rsp)
callq 0x2d9e70
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x2da9f5
movq $-0x1, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x68(%rbp), %rax
jg 0x2da9cb
movq -0x38(%rbp), %rax
cmpq -0x68(%rbp), %rax
jge 0x2da963
cmpq $0x0, -0x38(%rbp)
jle 0x2da930
movq -0x38(%rbp), %rax
subq $0x1, %rax
addq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x24(%rax)
jmp 0x2da943
movq -0x60(%rbp), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x24(%rax) # imm = 0xFFFFFFFF
movq -0x60(%rbp), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
jl 0x2da961
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2da963
movq -0x38(%rbp), %rax
cmpq -0x68(%rbp), %rax
je 0x2da97f
movq -0x60(%rbp), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
jl 0x2da9b8
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x1, %rax
jle 0x2da9b0
movq -0x58(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %r9d
callq 0x2d94d0
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x2da9ba
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2da8f2
cmpq $0x0, -0x50(%rbp)
jle 0x2da9d4
jmp 0x2da9f3
leaq 0xb9149(%rip), %rdi     # 0x393b24
leaq 0xb5e4d(%rip), %rsi     # 0x39082f
movl $0x3d5a, %edx           # imm = 0x3D5A
leaq 0xb913d(%rip), %rcx     # 0x393b2b
callq 0x2130
jmp 0x2daa01
movq -0x48(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)