// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: mc_solve(hap_overlaps_list*, trans_chain*, kv_u_trans_t*, ma_ug_t*, asg_t*, double, unsigned char*, unsigned int, signed char*, unsigned int, bubble_type*, kv_u_trans_t*, int, int)
void mc_solve(hap_overlaps_list* ovlp, trans_chain* t_ch, kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g, double f_rate, uint8_t* trio_flag, uint32_t renew_s, int8_t *s, uint32_t is_sys, bubble_type* bub, kv_u_trans_t *ref, int clean_ov, int is_dump)
{
	if(is_dump) {
		dump_debug_phasing(MC_NAME, ta, ug, read_g, f_rate, renew_s, s, is_sys, bub, ref);
		// bub = NULL;
	}
	
	mc_opt_t opt;
	mc_opt_init(&opt, asm_opt.n_perturb, asm_opt.f_perturb, asm_opt.seed);
	mc_g_t *mg = init_mc_g_t(ug, read_g, s, renew_s);
	update_mc_edges(mg, ovlp, ta, t_ch, f_rate, is_sys);

	fprintf(stderr, "[M::%s:: # edges: %u]\n", __func__, (uint32_t)mg->e->ma.n);
	
	mb_solve_core(&opt, mg, ref, is_sys);
	///debug_mc_g_t(mg);
	// if(renew_s == 0) write_mc_g_t(&opt, mg, MC_NAME);
	// mc_solve_core(&opt, mg, bub);
	mc_solve_core_adv(&opt, mg, bub, ref);

	if((asm_opt.flag & HA_F_PARTITION) && t_ch)
	{
		p_nodes(mg, t_ch, trio_flag);
	}

	if(clean_ov){
		if(ovlp) clean_ovlp_by_mc(mg, ovlp);
		if(ta) clean_ta_by_mc(mg, ta);
	}
	// print_hap_s(s, ug->u.n);

	destory_mc_g_t(&mg);	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movq 0x88(%rsp), %r9
movl 0x80(%rsp), %r14d
cmpl $0x0, 0xb0(%rsp)
je 0x12b88e
subq $0x8, %rsp
leaq 0xc39ef(%rip), %rdi     # 0x1ef246
movq %rbx, %rsi
movq %r15, %rdx
movq %rbp, %rcx
movsd 0x10(%rsp), %xmm0
movl %r14d, %r8d
movq %r9, %r13
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
movl 0xa8(%rsp), %eax
pushq %rax
callq 0x12b9de
movq %r13, %r9
addq $0x20, %rsp
leaq 0x127ec3(%rip), %rcx    # 0x253758
movl 0x1d0(%rcx), %eax
movsd 0x1d8(%rcx), %xmm0
movq 0x1c8(%rcx), %rcx
leaq 0x28(%rsp), %r13
movl %eax, 0x4(%r13)
movsd %xmm0, 0x10(%r13)
movl $0x3e8, (%r13)          # imm = 0x3E8
movq %rcx, 0x18(%r13)
cvtsi2sd %eax, %xmm0
mulsd 0xb7c77(%rip), %xmm0    # 0x1e3548
movl %eax, 0xc(%r13)
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%r13)
movq %r15, %rdi
movq %rbp, %rsi
movq %r9, %rdx
movl %r14d, %ecx
callq 0x122898
movq %rax, %rbp
movq %rax, 0x20(%rsp)
movq %rax, %rdi
movq 0x18(%rsp), %r15
movq %r15, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movsd 0x8(%rsp), %xmm0
movl 0x90(%rsp), %r14d
movq %r14, %r8
callq 0x124425
movq 0x1276bc(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq 0x28(%rbp), %rax
movl 0x18(%rax), %ecx
leaq 0xc391e(%rip), %rsi     # 0x1ef253
leaq 0xc392e(%rip), %rdx     # 0x1ef26a
xorl %eax, %eax
callq 0x22b0
movq %r13, %rdi
movq %rbp, %rsi
movq 0xa0(%rsp), %r14
movq %r14, %rdx
movl 0x90(%rsp), %ecx
callq 0x12a457
movq %r13, %rdi
movq %rbp, %rsi
movq 0x98(%rsp), %rdx
movq %r14, %rcx
callq 0x12ae56
testq %r12, %r12
je 0x12b99b
movl $0x800, %eax            # imm = 0x800
leaq 0x127dd1(%rip), %rcx    # 0x253758
andl (%rcx), %eax
je 0x12b99b
movq %rbp, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
callq 0x12b4c2
cmpl $0x0, 0xa8(%rsp)
je 0x12b9c5
testq %r15, %r15
je 0x12b9b5
movq %rbp, %rdi
movq %r15, %rsi
callq 0x12b0f8
testq %rbx, %rbx
je 0x12b9c5
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x12b370
leaq 0x20(%rsp), %rdi
callq 0x123cde
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq