// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_rid_raw_chain(overlap_region_alloc*, glchain_t*, unsigned long, Chain_Data*, ul_idx_t const*, double, long, ug_opt_t const*, char*, UC_Read*, bit_extz_t*, long, long, ha_ovec_buf_t*, long)
void gen_rid_raw_chain(overlap_region_alloc* ol, glchain_t *ll, uint64_t cha_idx, Chain_Data* dp, const ul_idx_t *uref, double diff_ec_ul, int64_t qlen, const ug_opt_t *uopt, char* qstr, UC_Read *tu, bit_extz_t *exz, int64_t ulid_local, 
int64_t rid, ha_ovec_buf_t *bb, int64_t max_chain)
{
	ul_ov_t *res_a; uint64_t res_n; asg64_v b64;
	int64_t tran_sc = ((diff_ec_ul>0)?(((double)1)/(diff_ec_ul)):(0));
	kv_ul_ov_t *idx = &(ll->lo), *res = &(ll->tk);
	idx->n = 0; if(res->n <= cha_idx) return;

	res_a = res->a + cha_idx; res_n = res->n - cha_idx;
	kv_resize(ul_ov_t, *idx, res_n); idx->n = res_n;
	memcpy(idx->a, res_a, res_n*sizeof(*(res->a)));
	kv_resize(uint64_t, ll->srt.a, res_n);
	// fprintf(stderr, "\n+[M::%s] rid::%ld, name::%.*s\n", __func__, rid, 
    //      (int32_t)UL_INF.nid.a[rid].n, UL_INF.nid.a[rid].a);
	// res_n = gl_rchain_lin_contain(ol, idx, res_a, &(ll->tc), uref, uopt, G_CHAIN_BW, N_GCHAIN_RATE, qlen, ((max_chain>UG_SKIP_N)?max_chain:UG_SKIP_N), UG_ITER_N, UG_DIS_N, dp, exz, ll->srt.a.a, tran_sc, &R_INF, qstr, tu, rid, diff_ec_ul, 1);
	res_n = gl_rchain_lin_contain_adv(ol, idx, res_a, &(ll->tc), uref, uopt, G_CHAIN_BW, N_GCHAIN_RATE, qlen, ((max_chain>UG_SKIP_N)?max_chain:UG_SKIP_N), UG_ITER_N, UG_DIS_N, dp, exz, ll->srt.a.a, tran_sc, &R_INF, qstr, tu, rid, diff_ec_ul, 1);
	// fprintf(stderr, "-[M::%s] rid::%ld, name::%.*s\n", __func__, rid, 
    //      (int32_t)UL_INF.nid.a[rid].n, UL_INF.nid.a[rid].a);

	// prt_all_chain(idx, res_a, qlen);
	
	copy_asg_arr(b64, ll->srt.a);
	res_n = select_clean_chain(idx, res_a, res_n, ulid_local, &b64);
	copy_asg_arr(ll->srt.a, b64);
	res->n = cha_idx + res_n;

	if((idx->n) && (idx->a[0].qe - idx->a[0].qs) >= (qlen*0.95)) {
		bb->num_read_base++;
	} 
	
	// else {
	// 	// idx->n = 1;
	// 	prt_rid_raw_chain(idx, rid, qlen);
	// }
	// prt_rid_raw_chain(idx, rid, qlen);
		
	// //debug
	// ll->lo.n = ll->tk.n = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq $0x0, 0x8(%rsi)
movq 0x20(%rsi), %r12
subq %rdx, %r12
jbe 0x1b9a48
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, 0x70(%rsp)
movq %r8, 0x78(%rsp)
movq %r9, 0x88(%rsp)
movsd 0x6ba89(%rip), %xmm1    # 0x225270
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
movsd %xmm0, 0x80(%rsp)
cmpltsd %xmm0, %xmm2
andpd %xmm1, %xmm2
leaq (%rdx,%rdx,8), %rax
leaq (%rax,%rax,2), %r13
addq %rdx, %r13
addq 0x18(%rsi), %r13
cmpq %r12, 0x10(%rsi)
jae 0x1b9880
leaq -0x1(%r12), %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 (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
movapd %xmm2, 0x90(%rsp)
callq 0x2370
movapd 0x90(%rsp), %xmm2
movq %rax, (%r14)
cvttsd2si %xmm2, %rbp
movq %r12, 0x8(%r14)
movq (%r14), %rdi
leaq (%r12,%r12,8), %rax
leaq (%rax,%rax,2), %rdx
addq %r12, %rdx
movq %r13, %rsi
callq 0x2160
cmpq %r12, 0x50(%r14)
jae 0x1b98f6
decq %r12
movq %r12, %rax
shrq %rax
orq %r12, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x50(%r14)
movq 0x58(%r14), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, 0x58(%r14)
leaq 0x30(%r14), %rcx
movq 0x128(%rsp), %rdx
cmpq $0x65, %rdx
movl $0x64, %eax
cmovgeq %rdx, %rax
movq 0x58(%r14), %rdx
movq 0x100(%rsp), %rsi
movq %rsi, 0x58(%rsp)
movq 0xf8(%rsp), %rsi
movq %rsi, 0x50(%rsp)
leaq 0xd18fc(%rip), %rsi     # 0x28b230
movq %rsi, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x108(%rsp), %rdx
movq %rdx, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %r12
movq %r12, 0x8(%rsp)
movq $0x1, 0x68(%rsp)
movq $0xc350, 0x20(%rsp)     # imm = 0xC350
movq $0x1388, 0x18(%rsp)     # imm = 0x1388
movq $0x10, (%rsp)
movsd 0x6bb56(%rip), %xmm0    # 0x2254e8
movq 0x70(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq 0x78(%rsp), %r8
movq 0xf0(%rsp), %r9
movsd 0x80(%rsp), %xmm1
callq 0x1b8233
movq 0x58(%r14), %rax
leaq 0xa0(%rsp), %rbx
movq %rax, 0x10(%rbx)
movq 0x48(%r14), %rax
movq %rax, (%rbx)
movq 0x50(%r14), %rax
movq %rax, 0x8(%rbx)
movq %r14, %rdi
movq %r13, %rsi
movq 0x110(%rsp), %rcx
movq %rbx, %r8
callq 0x1b8fb8
movq 0x10(%rbx), %rcx
movq %rcx, 0x58(%r14)
movq (%rbx), %rcx
movq %rcx, 0x48(%r14)
movq 0x8(%rbx), %rcx
movq %rcx, 0x50(%r14)
addq %r15, %rax
movq %rax, 0x20(%r14)
cmpq $0x0, 0x8(%r14)
je 0x1b9a48
movq (%r14), %rax
movl 0x8(%rax), %ecx
subl 0x4(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x6ba65(%rip), %xmm1    # 0x225498
ucomisd %xmm1, %xmm0
jb 0x1b9a48
movq 0x120(%rsp), %rax
incq 0xf0(%rax)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq