// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, 0x30(%rsp)
xorl %r14d, %r14d
movq %rdx, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpl (%rax), %r14d
jge 0x16acdb
movq 0x28(%rsp), %rax
incl (%rax)
movl 0xc(%rbx), %edi
movq 0x28(%rbx), %rsi
movq %rbx, %rdx
callq 0x16ba4c
cmpl $0x0, 0xc(%rbx)
je 0x16acce
movq %r14, 0x38(%rsp)
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movapd 0xc44b3(%rip), %xmm3    # 0x22efc0
movq 0x28(%rbx), %rax
movq 0x40(%rbx), %r12
movl (%rax,%r14,4), %r8d
movq 0x50(%rbx), %rax
movq %r8, %rsi
shlq $0x5, %rsi
movzwl 0x4(%rax,%rsi), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %ecx, %edx
movl 0x8(%r12), %ecx
movl $0x1, %r9d
shlq %cl, %r9
movq 0x60(%rbx), %r10
leaq (%rdx,%rdx,2), %rdx
movq 0x8(%r10,%rdx,8), %r11
testq %r11, %r11
movq %r8, 0x20(%rsp)
movq %r12, 0x40(%rsp)
je 0x16abd2
leaq (%r10,%rdx,8), %rdi
movq %r8, %rdx
shlq %cl, %rdx
movq (%rdi), %r15
shlq $0x3, %rdx
addq (%r12), %rdx
leaq (%rax,%rsi), %rbp
xorl %r12d, %r12d
movsd 0xc5efa(%rip), %xmm0    # 0x230a78
xorl %r13d, %r13d
leaq (%r15,%r12,4), %rdi
movl (%rdi), %ebx
xorpd %xmm1, %xmm1
xorl %r8d, %r8d
movsd (%rdx,%r8,8), %xmm2
testl %r8d, %ebx
je 0x16ab9d
xorpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %r8
cmpq %r8, %r9
jne 0x16ab8e
testq %r13, %r13
je 0x16abc1
ucomisd %xmm0, %xmm1
ja 0x16abc1
ucomisd %xmm1, %xmm0
jne 0x16abc8
jp 0x16abc8
cmpl (%rbp), %ebx
jne 0x16abc8
movq %rdi, %r13
movapd %xmm1, %xmm0
incl %r12d
cmpq %r12, %r11
ja 0x16ab81
jmp 0x16abdd
xorl %r13d, %r13d
movsd 0xc5e9b(%rip), %xmm0    # 0x230a78
movzwl 0x6(%rax,%rsi), %edx
cmpq $0xffff, %rdx           # imm = 0xFFFF
je 0x16ac7d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
addl %edi, %edx
leaq (%rdx,%rdx,2), %rdi
movq 0x8(%r10,%rdi,8), %r11
testq %r11, %r11
movq 0x20(%rsp), %rdx
je 0x16ac82
movq %rdx, %r12
shlq %cl, %r12
leaq (%r10,%rdi,8), %rcx
movq (%rcx), %rcx
leaq (%rax,%rsi), %r10
movl %r9d, %r9d
shlq $0x3, %r12
movq 0x40(%rsp), %rdi
addq (%rdi), %r12
xorl %r8d, %r8d
leaq (%rcx,%r8,4), %rdi
movl (%rdi), %ebx
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
movsd (%r12,%r15,8), %xmm2
testl %r15d, %ebx
je 0x16ac48
xorpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %r15
cmpq %r15, %r9
jne 0x16ac39
testq %r13, %r13
je 0x16ac6c
ucomisd %xmm0, %xmm1
ja 0x16ac6c
ucomisd %xmm1, %xmm0
jne 0x16ac73
jp 0x16ac73
cmpl (%r10), %ebx
jne 0x16ac73
movq %rdi, %r13
movapd %xmm1, %xmm0
incl %r8d
cmpq %r8, %r11
ja 0x16ac2c
jmp 0x16ac82
movq 0x20(%rsp), %rdx
movl (%r13), %ecx
cmpl (%rax,%rsi), %ecx
jne 0x16ac92
movq 0x18(%rsp), %rbx
jmp 0x16acb0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x16bca8
movapd 0xc4314(%rip), %xmm3    # 0x22efc0
incl 0xc(%rsp)
incq %r14
movl 0xc(%rbx), %eax
cmpq %rax, %r14
jb 0x16ab0d
cmpl $0x0, 0xc(%rsp)
sete %al
movq 0x38(%rsp), %r14
jmp 0x16acd0
movb $0x1, %al
incl %r14d
testb %al, %al
je 0x16aac7
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1699e2