// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: gl_chain_refine_advance_combine(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(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);
	gl_chain_gen(olist, uref, idx, 0, hap, km);///no trans
	// fprintf(stderr, "0-[M::%s] idx->n::%lu\n", __func__, (uint64_t)idx->n);
	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**/);
		}
	}
	// fprintf(stderr, "1-[M::%s] f::%ld\n", __func__, f);
	// fprintf(stderr, "(beg1) [M::%s] debug_i:%ld, qlen:%ld\n", __func__, debug_i, qlen);
	if(!f) {
		gl_chain_gen(olist, uref, idx, 0, hap, km);///no trans
		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);
			f = 1;
		}
	}
	// 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 $0x38, %rsp
movsd %xmm0, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
movq 0xb0(%rsp), %r9
movq 0x80(%rsp), %rbp
movq 0x70(%rsp), %r12
xorl %r13d, %r13d
movq %r13, 0x8(%r12)
movq %r13, 0x20(%r12)
movq %rdx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r8, 0x8(%rsp)
callq 0x1a8167
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x1b4228
cmpq %rax, 0x50(%r12)
jae 0x1b3d2d
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(%r12)
movq 0x58(%r12), %rsi
leaq 0x8(,%rcx,8), %rdx
movq 0xb0(%rsp), %rdi
callq 0x1ee21d
movq %rax, 0x58(%r12)
movq 0x8(%r12), %rax
movq 0x8(%rsp), %r13
cmpq %rax, 0x240(%r13)
jae 0x1b3da2
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, 0x240(%r13)
movq 0x248(%r13), %rsi
leaq 0x8(,%rcx,8), %rdx
movq 0xb0(%rsp), %rdi
callq 0x1ee21d
movq %rax, 0x248(%r13)
movq 0x8(%r12), %rax
movq 0x18(%r12), %rsi
cmpq %rax, 0x28(%r12)
jae 0x1b3e0f
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(%r12)
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rdx
incq %rdx
movq 0xb0(%rsp), %rdi
callq 0x1ee21d
movq %rax, %rsi
movq %rax, 0x18(%r12)
movq 0x78(%rsp), %r15
leaq 0x18(%r12), %rax
movq %rax, 0x18(%rsp)
movq 0x28(%r14), %rax
movq 0x58(%r12), %rcx
movq 0x248(%r13), %rdx
movq (%rbp), %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 0x7d785(%rip), %xmm0    # 0x2315e8
movl $0x10, %r8d
movq %r12, %rdi
movq %rbp, %rdx
movq 0xe8(%rsp), %rcx
movq 0xe0(%rsp), %r14
movq %r14, %r9
callq 0x1abd88
addq $0x50, %rsp
testq %rax, %rax
je 0x1b3f07
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0x1b3f07
movq (%r12), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movl -0x14(%rax,%rcx), %edx
subl -0x18(%rax,%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
cvtsi2ss %r14, %xmm1
mulss 0x8bcfe(%rip), %xmm1    # 0x23fbc4
ucomiss %xmm0, %xmm1
jae 0x1b3f07
addq %rcx, %rax
movq (%rbp), %rdi
movl -0xc(%rax), %ecx
movl -0x8(%rax), %edx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
movq 0x18(%rsp), %rax
addq (%rax), %rsi
subl %ecx, %edx
leaq 0x18(%r15), %rcx
movsd 0x7d73f(%rip), %xmm0    # 0x231638
callq 0x1af334
testq %rax, %rax
jne 0x1b420e
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq 0x8(%rsp), %rbx
movq %rbx, %r8
movq 0xb0(%rsp), %r9
callq 0x1a8167
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1af1e2
movq $0x0, 0x20(%r12)
movq 0x8(%r15), %rax
cmpq %rax, 0x50(%r12)
jae 0x1b3fa1
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(%r12)
movq 0x58(%r12), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x58(%r12)
movq 0x8(%r15), %rax
cmpq %rax, 0x240(%rbx)
jae 0x1b4008
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, 0x240(%rbx)
movq 0x248(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x248(%rbx)
movq 0x8(%r15), %rax
cmpq %rax, 0x80(%r15)
jae 0x1b406f
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(%r15)
movq 0x88(%r15), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x88(%r15)
movq 0x8(%r15), %rax
movq %rbp, %rbx
cmpq %rax, 0x98(%r15)
jae 0x1b40d7
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(%r15)
movq 0xa0(%r15), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0xa0(%r15)
jmp 0x1b40de
movq 0xa0(%r15), %rax
movq 0x10(%rsp), %rbp
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r14
movq (%r14), %rdi
movq %rbx, %rsi
movq (%rbx), %rdx
leaq 0x18(%r15), %rbx
leaq 0x30(%r15), %r9
leaq 0x48(%r15), %r13
movl 0x18(%rbp), %ecx
movq 0x70(%rsp), %r8
movq 0x58(%r8), %r11
movq 0x8(%rsp), %r8
movq 0x248(%r8), %r8
movq 0x88(%r15), %r10
subq $0x50, %rsp
movq %r10, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq %r12, 0x30(%rsp)
movq %r11, 0x28(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %r13, 0x58(%rsp)
movq %r13, (%rsp)
movq $0x10, 0x20(%rsp)
movsd 0x7d4ce(%rip), %xmm1    # 0x231638
movq %r15, %rcx
movq %rbx, %r8
movsd 0x80(%rsp), %xmm0
callq 0x1b2517
addq $0x50, %rsp
movl $0x1, %r13d
testq %rax, %rax
js 0x1b4228
movq 0xa0(%rsp), %rdx
leaq 0x60(%r15), %r10
movq (%r14), %rdi
movl 0x18(%rbp), %eax
movq 0x80(%rsp), %r14
movq (%r14), %r11
leaq 0xa8(%r15), %rbp
subq $0x8, %rsp
movss 0x8b9f7(%rip), %xmm0    # 0x23fbb8
movss 0x8b9ff(%rip), %xmm1    # 0x23fbc8
movss 0x81bdf(%rip), %xmm2    # 0x235db0
movq %r14, %rsi
movq %r12, %rcx
movq %r15, %r8
movq 0x20(%rsp), %r9
pushq %rbx
movq 0x80(%rsp), %rbx
pushq 0x58(%rbx)
pushq %r10
pushq 0x28(%rsp)
pushq %rbp
pushq 0x18(%r11)
pushq $0x124f8                # imm = 0x124F8
pushq %rax
pushq $0x0
callq 0x1b3553
addq $0x50, %rsp
testl %eax, %eax
movq %r14, %rbp
je 0x1b4228
addq $0x18, %r15
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x1b08af
movl $0x1, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq