// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gl_chain_refine_advance_combine_with_trans(mg_tbuf_s*, ul_vec_t*, overlap_region_alloc*, Correct_dumy*, haplotype_evdience_alloc*, st_mt_t*, glchain_t*, gdpchain_t*, ul_idx_t const*, double, long, long, ug_opt_t const*, long, long, void*)
int64_t gl_chain_refine_advance_combine_with_trans(mg_tbuf_t *b, ul_vec_t *rch, overlap_region_alloc* olist, Correct_dumy* dumy, haplotype_evdience_alloc *hap, st_mt_t *sps, glchain_t *ll, gdpchain_t *gdp, const ul_idx_t *uref, double diff_ec_ul, int64_t winLen, int64_t qlen, const ug_opt_t *uopt, 
int64_t debug_i, int64_t tid, void *km)
{
	ll->tk.n = ll->lo.n = 0;
	kv_ul_ov_t *idx = &(ll->lo);
	uint64_t o2 = gl_chain_gen(olist, uref, idx, 0, hap, km);
	if(idx->n == 0) return 0;
	// fprintf(stderr, "(beg0) [M::%s::tid:%ld] debug_i:%ld, qlen:%ld, # cis:%lu, # trans:%lu\n", __func__, tid, debug_i, qlen, (uint64_t)idx->n, o2);
	int64_t max_idx, occ = 0, f = 0;

	kv_resize_km(km, uint64_t, ll->srt.a, idx->n);
    kv_resize_km(km, uint64_t, hap->snp_srt, idx->n);
	kv_resize_km(km, ul_ov_t, ll->tk, idx->n);
	///chain exact U-matches
	occ = gl_chain_advance(idx, ll->tk.a, uref, uopt, G_CHAIN_BW, /**diff_ec_ul**/N_GCHAIN_RATE, qlen, UG_SKIP, dumy->overlapID, ll->srt.a.a, hap->snp_srt.a, G_CHAIN_TRANS_WEIGHT, 0, NULL, uref->ug, debug_i, km);
	if(occ) {
		if(ff_chain(idx, qlen, 0.99/**P_CHAIN_COV**/, -1/**G_CHAIN_TRANS_RATE**/, ll->tk.a, NULL, NULL, NULL, diff_ec_ul, winLen, km)) {
			f = l2g_res_chain(uref->ug, ll->tk.a+idx->a[idx->n-1].ts, idx->a[idx->n-1].te-idx->a[idx->n-1].ts, &(gdp->swap), -1/**N_GCHAIN_RATE**/);
		} else if(o2) {///means there are trans overlaps
			gl_chain_gen(olist, uref, idx, 1, hap, km);
			kv_resize_km(km, uint64_t, ll->srt.a, idx->n);
    		kv_resize_km(km, uint64_t, hap->snp_srt, idx->n);
			kv_resize_km(km, ul_ov_t, ll->tk, idx->n);
			///chain all U-matches
			occ = gl_chain_advance(idx, ll->tk.a, uref, uopt, G_CHAIN_BW, /**diff_ec_ul**/N_GCHAIN_RATE, qlen, UG_SKIP, dumy->overlapID, ll->srt.a.a, hap->snp_srt.a, G_CHAIN_TRANS_WEIGHT, 0, NULL, uref->ug, debug_i, km);
			if(ff_chain(idx, qlen, 0.99/**P_CHAIN_COV**/, G_CHAIN_TRANS_RATE, ll->tk.a, olist, hap, uref, diff_ec_ul, winLen, km)) {
				f = l2g_res_chain(uref->ug, ll->tk.a+idx->a[idx->n-1].ts, idx->a[idx->n-1].te-idx->a[idx->n-1].ts, &(gdp->swap), -1/**N_GCHAIN_RATE**/);
			}
		}
	}
	// fprintf(stderr, "(beg1) [M::%s] debug_i:%ld, qlen:%ld\n", __func__, debug_i, qlen);
	if(!f) {
		gl_chain_gen(olist, uref, idx, 1, hap, km);
		l2g_chain(uref, idx, &(gdp->l)); ll->tk.n = 0;
		///buffer
		kv_resize(uint64_t, ll->srt.a, gdp->l.n); kv_resize(uint64_t, hap->snp_srt, gdp->l.n);
		kv_resize(uint64_t, gdp->v, gdp->l.n); kv_resize(int64_t, gdp->f, gdp->l.n);
		max_idx = hc_gchain1_dp(b->km, uref, uref->ug, &(gdp->l), &(gdp->swap), &(gdp->dst), &(gdp->out), &(gdp->path), rch->rlen,
		uopt, G_CHAIN_BW, diff_ec_ul, -1, ll->srt.a.a, sps, gdp->f.a, hap->snp_srt.a, gdp->v.a);
		if(max_idx >= 0 && gen_max_gchain_adv(b->km, uref, debug_i, sps, &(gdp->l), &(ll->tk), NULL, rch->rlen, P_CHAIN_COV, 0.3/**P_FRAGEMENT_PRIMARY_CHAIN_COV**/, 
			0.1/**P_FRAGEMENT_PRIMARY_SECOND_COV**/, PRIMARY_UL_CHAIN_MIN, uref->ug->g, &(gdp->dst_done), &(gdp->out), &(gdp->path), ll->srt.a.a, &(gdp->swap))) {
			// print_raw_chains(&(gdp->swap), debug_i);
			f = check_trans_rate_gap(&(gdp->swap), &(ll->tk), olist, hap, uref, diff_ec_ul, winLen, G_CHAIN_TRANS_RATE);
		}
	}
	// if(debug_i == 1756) fprintf(stderr, "[M::%s] ulid:%ld, qlen:%ld, f:%ld\n", __func__, debug_i, qlen, f);
	if(f) update_ul_vec_t_ug(uref, rch, &(gdp->swap), debug_i);
	// debug_ul_vec_t_chain(km, uref->ug->g, rch, &(gdp->dst_done), &(gdp->out));
	// fprintf(stderr, "(beg3) [M::%s::tid:%ld] debug_i:%ld, qlen:%ld\n", __func__, tid, debug_i, qlen);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x20(%rsp)
movq %r9, 0x40(%rsp)
movq %rcx, %r12
movq %rsi, 0x28(%rsp)
movq %rdi, 0x10(%rsp)
movq 0xc0(%rsp), %r9
movq 0x90(%rsp), %rsi
movq 0x80(%rsp), %rbx
xorl %r14d, %r14d
movq %r14, 0x8(%rbx)
movq %r14, 0x20(%rbx)
movq %rdx, 0x18(%rsp)
movq %rdx, %rdi
movq %rbx, %rdx
xorl %ecx, %ecx
movq %r8, 0x8(%rsp)
movq %r9, %rbp
callq 0x19f426
movq %rax, %r15
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1a935a
cmpq %rax, 0x50(%rbx)
movq %rbx, %r14
jae 0x1a8bc2
decq %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, 0x50(%r14)
movq 0x58(%r14), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1e3800
movq %rax, 0x58(%r14)
movq 0x8(%r14), %rax
movq 0x8(%rsp), %rcx
cmpq %rax, 0x240(%rcx)
movq 0x90(%rsp), %rbx
jae 0x1a8c3e
decq %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 0x8(%rsp), %r13
movq %rax, 0x240(%r13)
movq 0x248(%r13), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1e3800
movq %rax, 0x248(%r13)
movq 0x8(%r14), %rax
cmpq %rax, 0x28(%r14)
jae 0x1a8ca3
decq %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, 0x28(%r14)
movq 0x18(%r14), %rsi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rdx
incq %rdx
movq %rbp, %rdi
callq 0x1e3800
movq %rax, 0x18(%r14)
movq 0x88(%rsp), %r13
leaq 0x18(%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%r12), %rax
movq 0x18(%r14), %rsi
movq 0x58(%r14), %rcx
movq 0x8(%rsp), %rdx
movq 0x248(%rdx), %rdx
movq (%rbx), %rdi
subq $0x50, %rsp
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq $-0x1, 0x20(%rsp)
movsd 0x7c7e7(%rip), %xmm0    # 0x2254e8
movl $0x10, %r8d
movq %r14, %rdi
movq %rbx, %rdx
movq 0xf8(%rsp), %rcx
movq 0xf0(%rsp), %r9
callq 0x1a2b62
addq $0x50, %rsp
testq %rax, %rax
je 0x1a8fed
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0x1a8d71
movq (%r14), %rdx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
movl -0x14(%rdx,%rax), %ecx
subl -0x18(%rdx,%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
cvtsi2ssq 0xa0(%rsp), %xmm1
mulss 0x8ab8c(%rip), %xmm1    # 0x2338f4
ucomiss %xmm0, %xmm1
jb 0x1a8fa2
testq %r15, %r15
movq 0x90(%rsp), %rbx
je 0x1a8fed
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x1, %ecx
movq 0x8(%rsp), %r8
movq %rbp, %r9
callq 0x19f426
movq 0x8(%r14), %rax
cmpq %rax, 0x50(%r14)
jae 0x1a8dfd
decq %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, 0x50(%r14)
movq 0x58(%r14), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1e3800
movq %rax, 0x58(%r14)
movq 0x8(%r14), %rax
movq 0x8(%rsp), %rcx
cmpq %rax, 0x240(%rcx)
jae 0x1a8e71
decq %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 0x8(%rsp), %r15
movq %rax, 0x240(%r15)
movq 0x248(%r15), %rsi
leaq 0x8(,%rcx,8), %rdx
movq %rbp, %rdi
callq 0x1e3800
movq %rax, 0x248(%r15)
movq 0x80(%rsp), %r14
movq 0x8(%r14), %rax
cmpq %rax, 0x28(%r14)
jae 0x1a8ede
decq %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, 0x28(%r14)
movq 0x18(%r14), %rsi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rdx
incq %rdx
movq %rbp, %rdi
callq 0x1e3800
movq %rax, 0x18(%r14)
movq 0x28(%r12), %rax
movq 0x18(%r14), %rsi
movq 0x58(%r14), %rcx
movq 0x8(%rsp), %r15
movq 0x248(%r15), %rdx
movq (%rbx), %rdi
subq $0x50, %rsp
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq $-0x1, 0x20(%rsp)
movsd 0x7c5bd(%rip), %xmm0    # 0x2254e8
movl $0x10, %r8d
movq %r14, %rdi
movq %rbx, %rdx
movq 0xf8(%rsp), %rcx
movq 0xf0(%rsp), %r12
movq %r12, %r9
callq 0x1a2b62
addq $0x50, %rsp
movq 0x18(%r14), %rdx
movss 0x8a995(%rip), %xmm0    # 0x2338f4
movss 0x8a985(%rip), %xmm1    # 0x2338ec
movq %r14, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rcx
movq %r15, %r8
movq %rbx, %r9
movsd 0x20(%rsp), %xmm2
pushq %rbp
pushq 0xa0(%rsp)
callq 0x1a3cd7
addq $0x10, %rsp
testl %eax, %eax
je 0x1a8fed
movq 0x8(%r14), %rcx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
addq (%r14), %rax
movq 0x90(%rsp), %rbx
movq (%rbx), %rdi
movl -0xc(%rax), %ecx
movl -0x8(%rax), %edx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
movq 0x30(%rsp), %rax
addq (%rax), %rsi
subl %ecx, %edx
leaq 0x18(%r13), %rcx
movsd 0x7c561(%rip), %xmm0    # 0x225538
callq 0x1a60bd
testq %rax, %rax
movq 0x80(%rsp), %r14
jne 0x1a9340
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x1, %ecx
movq 0x8(%rsp), %r8
movq %rbp, %r9
callq 0x19f426
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1a5f64
movq $0x0, 0x20(%r14)
movq 0x8(%r13), %rax
cmpq %rax, 0x50(%r14)
movq %rbx, %r14
jae 0x1a9086
decq %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 0x80(%rsp), %rbx
movq %rax, 0x50(%rbx)
movq 0x58(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x58(%rbx)
movq 0x8(%r13), %rax
movq 0x8(%rsp), %rcx
cmpq %rax, 0x240(%rcx)
movq 0x10(%rsp), %r15
jae 0x1a90fc
decq %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 0x8(%rsp), %rbx
movq %rax, 0x240(%rbx)
movq 0x248(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x248(%rbx)
movq 0x8(%r13), %rax
cmpq %rax, 0x80(%r13)
movq 0x40(%rsp), %rbx
jae 0x1a9168
decq %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, 0x80(%r13)
movq 0x88(%r13), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x88(%r13)
movq 0x8(%r13), %rax
cmpq %rax, 0x98(%r13)
jae 0x1a91cf
decq %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, 0x98(%r13)
movq 0xa0(%r13), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0xa0(%r13)
movq (%r15), %rdi
movq (%r14), %rdx
leaq 0x18(%r13), %r15
leaq 0x30(%r13), %r9
leaq 0x48(%r13), %r12
movq 0x28(%rsp), %rax
movl 0x18(%rax), %eax
movq 0x80(%rsp), %rcx
movq 0x58(%rcx), %rcx
movq 0x88(%r13), %rsi
movq 0xa0(%r13), %r8
movq 0x8(%rsp), %r10
movq 0x248(%r10), %r10
subq $0x50, %rsp
movq %rsi, 0x48(%rsp)
movq %r10, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq 0xf8(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %r12, (%rsp)
movq $0x10, 0x20(%rsp)
movsd 0x7c2e5(%rip), %xmm1    # 0x225538
movq %r14, %rsi
movq %r13, %rcx
movq %r15, %r8
movsd 0x70(%rsp), %xmm0
callq 0x1a936c
addq $0x50, %rsp
movq %rbx, %rcx
movq %r14, %rbx
movl $0x1, %r14d
testq %rax, %rax
js 0x1a935a
movq 0xb0(%rsp), %rdx
leaq 0x60(%r13), %r10
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0x28(%rsp), %rax
movl 0x18(%rax), %eax
movq %rax, 0x10(%rsp)
movq (%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0xa8(%r13), %rax
subq $0x8, %rsp
movss 0x8a62c(%rip), %xmm0    # 0x2338e8
movss 0x8a634(%rip), %xmm1    # 0x2338f8
movss 0x808ec(%rip), %xmm2    # 0x229bb8
movq %rbx, %rsi
movq %r13, %r8
movq 0x38(%rsp), %rbp
movq %rbp, %r9
pushq %r15
movq 0x90(%rsp), %r11
pushq 0x58(%r11)
pushq %r10
pushq %r12
pushq %rax
movq 0x68(%rsp), %rax
pushq 0x18(%rax)
pushq $0x124f8                # imm = 0x124F8
pushq 0x50(%rsp)
pushq $0x0
callq 0x1aa367
addq $0x50, %rsp
testl %eax, %eax
je 0x1a935a
movss 0x8a5d7(%rip), %xmm1    # 0x2338ec
movq %r15, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %rbx, %r8
movsd 0x20(%rsp), %xmm0
movq 0x98(%rsp), %r9
callq 0x1a6949
testq %rax, %rax
je 0x1a935a
addq $0x18, %r13
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq %r13, %rdx
callq 0x1a7661
movl $0x1, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq