// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq 0x48(%rbp), %rax
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, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movsd %xmm0, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2bb0f6
movsd 0xc6f19(%rip), %xmm0    # 0x382000
divsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x2bb103
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x2bb103
movsd -0xa8(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x40(%rbp), %rax
ja 0x2bb156
jmp 0x2bb5c0
movq -0xa0(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x70(%rbp), %rax
jae 0x2bb286
movq -0x70(%rbp), %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
shrq %rcx
movq -0x98(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x2, %rcx
movq -0x98(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x4, %rcx
movq -0x98(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x8, %rcx
movq -0x98(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x10, %rcx
movq -0x98(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq (%rax), %rdi
movq -0x98(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2bb288
movq -0x70(%rbp), %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x98(%rbp), %rax
movq (%rax), %rdi
movq -0x68(%rbp), %rsi
imulq $0x1c, -0x70(%rbp), %rdx
callq 0x2180
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
cmpq -0x70(%rbp), %rax
jae 0x2bb388
movq -0x70(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
shrq %rcx
movq -0x38(%rbp), %rax
orq 0x50(%rax), %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
shrq $0x2, %rcx
movq -0x38(%rbp), %rax
orq 0x50(%rax), %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
shrq $0x4, %rcx
movq -0x38(%rbp), %rax
orq 0x50(%rax), %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
shrq $0x8, %rcx
movq -0x38(%rbp), %rax
orq 0x50(%rax), %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
shrq $0x10, %rcx
movq -0x38(%rbp), %rax
orq 0x50(%rax), %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
jmp 0x2bb38a
movq -0x30(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xc8(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x64, 0x48(%rbp)
jle 0x2bb3f2
movq 0x48(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x2bb400
movl $0x64, %eax
movq %rax, -0xe8(%rbp)
jmp 0x2bb400
movq -0xb0(%rbp), %rax
movq -0xb8(%rbp), %r9
movq -0xc0(%rbp), %r8
movq -0xc8(%rbp), %rcx
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %rdi
movq -0xe8(%rbp), %r10
movq %r10, -0xf8(%rbp)
movq -0x48(%rbp), %r13
movq 0x28(%rbp), %r12
movq -0x38(%rbp), %r10
movq 0x58(%r10), %r15
movq -0x90(%rbp), %r14
movq 0x18(%rbp), %r11
movq 0x20(%rbp), %r10
movq 0x38(%rbp), %rbx
movq %rbx, -0xf0(%rbp)
movsd -0x58(%rbp), %xmm1
movsd 0xc3bba(%rip), %xmm0    # 0x37f030
leaq 0x109e53(%rip), %rbx    # 0x3c52d0
movq $0x10, (%rsp)
movq %rax, 0x8(%rsp)
movq -0xf8(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0xf0(%rbp), %rax
movq $0x1388, 0x18(%rsp)     # imm = 0x1388
movq $0xc350, 0x20(%rsp)     # imm = 0xC350
movq %r13, 0x28(%rsp)
movq %r12, 0x30(%rsp)
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
movq %r11, 0x50(%rsp)
movq %r10, 0x58(%rsp)
movq %rax, 0x60(%rsp)
movq $0x1, 0x68(%rsp)
callq 0x2b8260
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x98(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq 0x30(%rbp), %rcx
leaq -0x88(%rbp), %r8
callq 0x2b9b40
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x88(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x80(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x40(%rbp), %rcx
addq -0x70(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x98(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2bb5c0
movq -0x98(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %eax
subl %ecx, %eax
cvtsi2sd %rax, %xmm0
cvtsi2sdq -0x60(%rbp), %xmm1
movsd 0xc6c80(%rip), %xmm2    # 0x382220
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2bb5c0
movq 0x40(%rbp), %rax
movq 0xf0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0xf0(%rax)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)