// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/rcut.cpp
// Function: mb_solve_core(mc_opt_t*, mc_g_t*, kv_u_trans_t*, unsigned int)
void mb_solve_core(mc_opt_t *opt, mc_g_t *mg, kv_u_trans_t *ref, uint32_t is_sys)
{
	if(!ref) return;
	double index_time = yak_realtime();
	uint32_t st, i;
	mb_g_t *mbg = init_mb_g_t(mg->e, ref, is_sys);
	mb_svaux_t *bb;
	/**************************init**************************/
	if(VERBOSE_CUT)
	{
		fprintf(stderr, "\n\n\n\n\n*************beg-[M::%s::score->%f] ==> Partition\n", __func__, mc_score_all_advance(mg->e, mg->s.a));
	} 
	
	mc_svaux_t *b;
	mc_g_cc(mg->e);
	b = mc_svaux_init(mg, opt->seed);
	mc_init_spin_all(opt, mg, mbg, b);
	mc_svaux_destroy(b);
	free(mg->e->cc); 
	mg->e->cc = NULL;
	/**************************init**************************/
	mb_g_cc(mbg);
	bb = mb_svaux_init(mbg, opt->seed);
	
	if(VERBOSE_CUT)
	{
		fprintf(stderr, "*********before-[M::%s::mc_score->%f] ==> Partition\n", __func__, mc_score_all_advance(mg->e, mg->s.a));
		fprintf(stderr, "*********before-[M::%s::mb_score->%f] ==> Partition\n", __func__, mb_score_all_advance(mg->e, mbg));
		/*******************************for debug************************************/
		// print_mb_g_blcok(mbg);
		/*******************************for debug************************************/
	}
	
	
	opt->n_perturb = opt->n_b_perturb;
	for (st = 0, i = 1; i <= mbg->e->n_seq; ++i) {
		if (i == mbg->e->n_seq || mbg->e->cc[st]>>32 != mbg->e->cc[i]>>32) {
			mb_solve_cc(opt, mbg, bb, st, i - st);
			st = i;
		}
	}
	opt->n_perturb = opt->n_s_perturb - opt->n_b_perturb;
	
	mc_set_by_mbg(mg, mbg);
	if(VERBOSE_CUT)
	{
		/*******************************for debug************************************/
		// debug_mb_solve_core(mbg);
		/*******************************for debug************************************/
		fprintf(stderr, "##############end-[M::%s::score->%f] ==> Partition\n", __func__, mc_score_all_advance(mg->e, mg->s.a));
	}
	destory_mb_g_t(&mbg);
	mb_svaux_destroy(bb);
	fprintf(stderr, "[M::%s::%.3f] ==> Partition\n", __func__, yak_realtime()-index_time);
}

// Assembly:
testq %rdx, %rdx
jne 0x168003
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
callq 0x1303c7
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rbx), %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x16193c
movq %rax, 0x8(%rsp)
movq 0x28(%rbx), %r15
movq %r15, %rdi
callq 0x162d3f
movq %rax, 0x30(%r15)
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x162f9b
movq %rax, %r15
movq 0x8(%rsp), %rdx
movq %rbx, %rsi
movq %rax, %rcx
callq 0x1677d5
movq %r15, %rdi
callq 0x1630bd
movq 0x28(%rbx), %rax
movq 0x30(%rax), %rdi
callq 0x2220
movq 0x28(%rbx), %rax
movq $0x0, 0x30(%rax)
movq 0x8(%rsp), %r15
movq 0x8(%r15), %rdi
callq 0x167cbd
movq 0x8(%r15), %rcx
movq %rax, 0x30(%rcx)
movq 0x8(%rsp), %rdi
movq 0x18(%r14), %rsi
callq 0x163123
movq %rax, %r15
movl 0x8(%r14), %eax
movl %eax, 0x4(%r14)
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rax
movl 0x38(%rax), %edx
testl %edx, %edx
je 0x16810b
movl $0x1, %ebp
xorl %ecx, %ecx
cmpl %edx, %ebp
je 0x1680e6
movq 0x30(%rax), %rax
movl %ecx, %edx
movl %ebp, %edi
movq (%rax,%rdi,8), %rdi
xorq (%rax,%rdx,8), %rdi
shrq $0x20, %rdi
je 0x1680f9
movl %ebp, %r8d
subl %ecx, %r8d
movq %r14, %rdi
movq %r15, %rdx
callq 0x166fb5
movl %ebp, %ecx
incl %ebp
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rax
movl 0x38(%rax), %edx
cmpl %edx, %ebp
jbe 0x1680cc
movl 0xc(%r14), %eax
subl 0x8(%r14), %eax
movl %eax, 0x4(%r14)
movq %rbx, %rdi
callq 0x167ec3
leaq 0x8(%rsp), %rdi
callq 0x161fc6
movq %r15, %rdi
callq 0x163223
movq 0x121ea8(%rip), %rax    # 0x289fe0
movq (%rax), %rbx
callq 0x1303c7
subsd 0x10(%rsp), %xmm0
leaq 0xc8f2f(%rip), %rsi     # 0x23107c
leaq 0xc8f45(%rip), %rdx     # 0x231099
movq %rbx, %rdi
movb $0x1, %al
callq 0x22b0
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq