// File: /workspace/github_cpp_makefile_star2_O2/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
andq $0x0, 0x8(%rsi)
movq 0x20(%rsi), %r12
subq %rdx, %r12
jbe 0x17852c
movq %rcx, %rbx
movq %rsi, %r14
movq %rdx, %r15
movq %rdi, 0x70(%rsp)
movsd 0x6afb6(%rip), %xmm1    # 0x1e32a0
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm0, %xmm2
imulq $0x1c, %rdx, %r13
addq 0x18(%rsi), %r13
andpd %xmm1, %xmm2
movq (%rsi), %rdi
cmpq %r12, 0x10(%rsi)
movq %r9, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movq %r8, 0x78(%rsp)
jae 0x178380
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
incq %rcx
movq %rcx, 0x10(%r14)
imulq $0x1c, %rcx, %rsi
movapd %xmm2, 0x90(%rsp)
callq 0x2370
movapd 0x90(%rsp), %xmm2
movq %rax, %rdi
movq %rax, (%r14)
cvttsd2si %xmm2, %rbp
movq %r12, 0x8(%r14)
imulq $0x1c, %r12, %rdx
movq %r13, %rsi
callq 0x2160
cmpq %r12, 0x50(%r14)
jae 0x1783ee
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)
jmp 0x1783f2
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
pushq $0x64
popq %rdx
cmovgeq %rsi, %rdx
movq 0x100(%rsp), %rsi
movq %rsi, 0x58(%rsp)
movq 0xf8(%rsp), %rsi
movq %rsi, 0x50(%rsp)
leaq 0xdbdf3(%rip), %rsi     # 0x254230
movq %rsi, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq 0x88(%rsp), %r12
movq %r12, 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 0x6b09d(%rip), %xmm0    # 0x1e3538
movq %r14, %rsi
movq %r13, %rdx
movq 0xf0(%rsp), %r9
callq 0x176dd1
movq 0x58(%r14), %rax
leaq 0xa0(%rsp), %rbx
movq %rax, 0x10(%rbx)
movups 0x48(%r14), %xmm0
movaps %xmm0, (%rbx)
movq %r14, %rdi
movq %r13, %rsi
movq 0x110(%rsp), %rcx
movq %rbx, %r8
callq 0x177a83
movq 0x10(%rbx), %rcx
movq %rcx, 0x58(%r14)
movapd (%rbx), %xmm0
movupd %xmm0, 0x48(%r14)
addq %r15, %rax
movq %rax, 0x20(%r14)
cmpq $0x0, 0x8(%r14)
je 0x17852c
movq (%r14), %rax
movl 0x8(%rax), %ecx
subl 0x4(%rax), %ecx
cvtsi2sd %rcx, %xmm0
cvtsi2sd %r12, %xmm1
mulsd 0x6afd1(%rip), %xmm1    # 0x1e34e8
ucomisd %xmm1, %xmm0
jb 0x17852c
movq 0x120(%rsp), %rax
incq 0xf0(%rax)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq