// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: mcgg_optimize_local(mc_opt_t const*, mc_match_t const*, mcgg_svaux_t*, unsigned int*)
static t_w_t mcgg_optimize_local(const mc_opt_t *opt, const mc_match_t *ma, mcgg_svaux_t *b, uint32_t *n_iter)
{
	uint32_t i, n_flip = 0;
	int32_t n_iter_local = 0;
	mcg_node_t ms;
	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
			ms = get_max_m(k, b);
			if(ms != b->s[k].s)
			{
				mcgg_set_spin(ma, b, k, ms, __func__);///no need to change the score of k itself
				// debug_hapM(&(b->s[k]), "s4");
				++n_flip;
			}
		}
		++n_iter_local;
		if (n_flip == 0) break;
	}

	return mcgg_score(ma, b);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, 0x28(%rsp)
movq %rdx, %r14
movq %rsi, 0x18(%rsp)
movq %rdi, 0x30(%rsp)
xorl %eax, %eax
movq %rdx, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpl (%rax), %ecx
jge 0x12d03d
movq 0x28(%rsp), %rax
incl (%rax)
movl 0xc(%r14), %edi
movq 0x28(%r14), %rsi
movq %r14, %rdx
callq 0x12e5d4
xorl %ecx, %ecx
movl $0x0, 0xc(%rsp)
movl 0xc(%r14), %eax
cmpq %rax, %rcx
jae 0x12d02b
movq 0x28(%r14), %rax
movq 0x40(%r14), %rsi
movq %rcx, 0x40(%rsp)
movl (%rax,%rcx,4), %r9d
movq 0x50(%r14), %rdx
movq %r9, %r10
shlq $0x5, %r10
leaq (%rdx,%r10), %rax
movzwl 0x4(%rdx,%r10), %ecx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leal (%rdi,%rcx), %r8d
movb 0x8(%rsi), %cl
pushq $0x1
popq %rdi
shlq %cl, %rdi
movq 0x60(%r14), %r11
imulq $0x18, %r8, %r8
leaq (%r11,%r8), %r15
movq 0x8(%r11,%r8), %r14
movq %r9, 0x38(%rsp)
movq %r9, %r8
shlq %cl, %r8
xorl %ebp, %ebp
shlq $0x3, %r8
xorl %r12d, %r12d
movsd 0xc1c61(%rip), %xmm0    # 0x1eeb70
movapd 0xc01a9(%rip), %xmm3    # 0x1ed0c0
movl %ebp, %ebp
cmpq %rbp, %r14
jbe 0x12cf75
movq (%r15), %rcx
leaq (%rcx,%rbp,4), %rcx
movl (%rcx), %r13d
movq (%rsi), %rbx
addq %r8, %rbx
xorpd %xmm1, %xmm1
xorl %r9d, %r9d
cmpq %r9, %rdi
je 0x12cf52
movsd (%rbx,%r9,8), %xmm2
testl %r9d, %r13d
je 0x12cf49
xorpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %r9
jmp 0x12cf35
testq %r12, %r12
je 0x12cf6a
ucomisd %xmm0, %xmm1
ja 0x12cf6a
ucomisd %xmm1, %xmm0
jne 0x12cf71
jp 0x12cf71
cmpl (%rax), %r13d
jne 0x12cf71
movq %rcx, %r12
movapd %xmm1, %xmm0
incl %ebp
jmp 0x12cf17
movzwl 0x6(%rdx,%r10), %ecx
cmpq $0xffff, %rcx           # imm = 0xFFFF
je 0x12cffb
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %edx, %ecx
imulq $0x18, %rcx, %rcx
leaq (%r11,%rcx), %r9
movq 0x8(%r11,%rcx), %r10
xorl %r11d, %r11d
movq 0x20(%rsp), %r14
movl %r11d, %r11d
cmpq %r11, %r10
jbe 0x12d000
movq (%r9), %rcx
leaq (%rcx,%r11,4), %rcx
movl (%rcx), %ebp
movq (%rsi), %rbx
addq %r8, %rbx
xorpd %xmm1, %xmm1
xorl %edx, %edx
cmpq %rdx, %rdi
je 0x12cfd8
movsd (%rbx,%rdx,8), %xmm2
testl %edx, %ebp
je 0x12cfcf
xorpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %rdx
jmp 0x12cfbd
testq %r12, %r12
je 0x12cfef
ucomisd %xmm0, %xmm1
ja 0x12cfef
ucomisd %xmm1, %xmm0
jne 0x12cff6
jp 0x12cff6
cmpl (%rax), %ebp
jne 0x12cff6
movq %rcx, %r12
movapd %xmm1, %xmm0
incl %r11d
jmp 0x12cfa0
movq 0x20(%rsp), %r14
movl (%r12), %ecx
cmpl (%rax), %ecx
je 0x12d01e
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq 0x38(%rsp), %rdx
callq 0x12e808
incl 0xc(%rsp)
movq 0x40(%rsp), %rcx
incq %rcx
jmp 0x12ce9d
movq 0x10(%rsp), %rax
incl %eax
cmpl $0x0, 0xc(%rsp)
jne 0x12ce65
movq 0x18(%rsp), %rdi
movq %r14, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12c49c