// File: chhylp123[P]hifiasm/rcut.cpp
// Function: mb_optimize_local(mc_opt_t const*, mb_g_t*, mb_svaux_t*, unsigned int*)
static t_w_t mb_optimize_local(const mc_opt_t *opt, mb_g_t *mbg, mb_svaux_t *b, uint32_t *n_iter)
{
	uint32_t i, n_flip = 0;
	int32_t n_iter_local = 0;
	mb_node_t *u = NULL;
	t_w_t z = 0;
	while (n_iter_local < opt->max_iter) {
		++(*n_iter);
		ks_shuffle_uint32_t(b->cc_size, b->cc_node, &b->x);
		for (i = n_flip = 0; i < b->cc_size; ++i) {
			uint32_t k = b->cc_node[i];///uid
			u = &(mbg->u->u.a[k]);
			if(u->z[0] == u->z[1] && u->z[2] == u->z[3]) continue;
			z = 0;
			///a[0]
			z += -(t_w_t)(u->s[0]) * (u->z[0] - u->z[1]);
			///a[1]
			z += -(t_w_t)(u->s[1]) * (u->z[2] - u->z[3]);
			if(z >= 0) continue;

			mb_flip_spin(mbg, b, k);///no need to change the score of k itself
			++n_flip;
		}
		++n_iter_local;
		if (n_flip == 0) break;
	}

	// if(n_flip != 0) mc_best_flip(ma, b);
	return mb_score(mbg, b);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x223eeb
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x18(%rbp), %rdx
callq 0x22c0c0
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x223ed5
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x40(%rax), %rax
movl -0x44(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq -0x38(%rbp), %rax
ucomisd 0x20(%rax), %xmm0
jne 0x223e23
jp 0x223e23
movq -0x38(%rbp), %rax
movsd 0x28(%rax), %xmm0
movq -0x38(%rbp), %rax
ucomisd 0x30(%rax), %xmm0
jne 0x223e23
jp 0x223e23
jmp 0x223ec7
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movsbl 0x10(%rax), %ecx
cvtsi2sd %ecx, %xmm1
movsd 0x18(%rax), %xmm2
movsd 0x20(%rax), %xmm0
subsd %xmm0, %xmm2
movsd -0x40(%rbp), %xmm0
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movsbl 0x11(%rax), %eax
cvtsi2sd %eax, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x38(%rbp), %rax
movsd 0x28(%rax), %xmm2
movq -0x38(%rbp), %rax
subsd 0x30(%rax), %xmm2
movsd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x223eae
jmp 0x223ec7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x22c370
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x223db8
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x223ee6
jmp 0x223eeb
jmp 0x223d76
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x21c460
addq $0x50, %rsp
popq %rbp
retq
nop