// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2253f3
jmp 0x22559a
callq 0x1b7ca0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x2185b0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x21b680
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x21ba30
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x224630
movq -0x48(%rbp), %rdi
callq 0x21bc30
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x30(%rax), %rdi
callq 0x2210
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq $0x0, 0x30(%rax)
movq -0x38(%rbp), %rdi
callq 0x2250e0
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x21bcd0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x38(%rcx), %eax
ja 0x225535
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x38(%rcx), %eax
je 0x225503
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x30(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x225525
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
subl -0x2c(%rbp), %r8d
callq 0x223660
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x225527
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2254b0
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x8(%rbp), %rax
subl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x225110
leaq -0x38(%rbp), %rdi
callq 0x218fd0
movq -0x40(%rbp), %rdi
callq 0x21be90
movq 0x19ea70(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x1b7ca0
movq -0x50(%rbp), %rdi
subsd -0x28(%rbp), %xmm0
leaq 0x168960(%rip), %rsi    # 0x38deec
leaq 0x168976(%rip), %rdx    # 0x38df09
movb $0x1, %al
callq 0x22a0
addq $0x50, %rsp
popq %rbp
retq