// File: /workspace/github_cpp_makefile_star2_O3/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), %rbx
subq %rdx, %rbx
jbe 0x1c37bb
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, 0x70(%rsp)
movsd 0x6ddbe(%rip), %xmm1    # 0x231310
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm0, %xmm2
leaq (%rdx,%rdx,8), %rax
leaq (%rax,%rax,2), %r13
addq %rdx, %r13
addq 0x18(%rsi), %r13
andpd %xmm1, %xmm2
movq (%rsi), %rdi
cmpq %rbx, 0x10(%rsi)
movq %r9, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movq %r8, 0x78(%rsp)
jae 0x1c35fa
leaq -0x1(%rbx), %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)
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, %rdi
movq %rax, (%r14)
cvttsd2si %xmm2, %rbp
movq %rbx, 0x8(%r14)
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rdx
addq %rbx, %rdx
movq %r13, %rsi
callq 0x2160
cmpq %rbx, 0x50(%r14)
jae 0x1c366f
decq %rbx
movq %rbx, %rax
shrq %rax
orq %rbx, %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)
jmp 0x1c3673
movq 0x58(%r14), %rax
movsd 0x80(%rsp), %xmm1
movq 0x78(%rsp), %r8
movq 0x70(%rsp), %rdi
leaq 0x30(%r14), %rcx
movq 0x128(%rsp), %rsi
cmpq $0x65, %rsi
movl $0x64, %edx
cmovgeq %rsi, %rdx
movq 0x100(%rsp), %rsi
movq %rsi, 0x58(%rsp)
movq 0xf8(%rsp), %rsi
movq %rsi, 0x50(%rsp)
leaq 0xd2b70(%rip), %rsi     # 0x296230
movq %rsi, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movq 0x88(%rsp), %rbx
movq %rbx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq $0x1, 0x68(%rsp)
movq $0xc350, 0x20(%rsp)     # imm = 0xC350
movq $0x1388, 0x18(%rsp)     # imm = 0x1388
movq $0x10, (%rsp)
movsd 0x6deca(%rip), %xmm0    # 0x2315e8
movq %r14, %rsi
movq %r13, %rdx
movq 0xf0(%rsp), %r9
callq 0x1c1ec1
movq 0x58(%r14), %rax
leaq 0xa0(%rsp), %r12
movq %rax, 0x10(%r12)
movups 0x48(%r14), %xmm0
movaps %xmm0, (%r12)
movq %r14, %rdi
movq %r13, %rsi
movq 0x110(%rsp), %rcx
movq %r12, %r8
callq 0x1c2d16
movq 0x10(%r12), %rcx
movq %rcx, 0x58(%r14)
movapd (%r12), %xmm0
movupd %xmm0, 0x48(%r14)
addq %r15, %rax
movq %rax, 0x20(%r14)
cmpq $0x0, 0x8(%r14)
je 0x1c37bb
movq (%r14), %rax
movl 0x8(%rax), %ecx
subl 0x4(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
mulsd 0x6ddf2(%rip), %xmm1    # 0x231598
ucomisd %xmm1, %xmm0
jb 0x1c37bb
movq 0x120(%rsp), %rax
incq 0xf0(%rax)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq