// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
cmpl (%rax), %r14d
jge 0x17172e
movq 0x28(%rsp), %rax
incl (%rax)
movq 0x8(%rsp), %rbx
movl 0xc(%rbx), %edi
movq 0x28(%rbx), %rsi
movq %rbx, %rdx
callq 0x17249e
movapd 0xc9c8d(%rip), %xmm3    # 0x23b1d0
movl 0xc(%rbx), %ecx
testl %ecx, %ecx
je 0x17172e
movq %r14, 0x38(%rsp)
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
movl %ecx, 0x14(%rsp)
movq 0x8(%rsp), %rdx
movq 0x28(%rdx), %rax
movq 0x40(%rdx), %r9
movl (%rax,%r14,4), %r8d
movq 0x50(%rdx), %rsi
movq %r8, %rdi
shlq $0x5, %rdi
movzwl 0x4(%rsi,%rdi), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addl %ecx, %eax
movl 0x8(%r9), %ecx
movl $0x1, %r10d
shlq %cl, %r10
movq 0x60(%rdx), %r11
leaq (%rax,%rax,2), %rax
movq 0x8(%r11,%rax,8), %r13
testq %r13, %r13
movq %r8, 0x20(%rsp)
movq %r9, 0x40(%rsp)
je 0x171631
leaq (%r11,%rax,8), %rax
movq %r8, %rdx
shlq %cl, %rdx
movq (%rax), %rbp
shlq $0x3, %rdx
addq (%r9), %rdx
leaq (%rsi,%rdi), %r12
xorl %eax, %eax
movsd 0xcb6a3(%rip), %xmm0    # 0x23cc78
xorl %r15d, %r15d
leaq (,%rax,4), %r8
addq %rbp, %r8
movl (%r8), %ebx
xorpd %xmm1, %xmm1
xorl %r9d, %r9d
movsd (%rdx,%r9,8), %xmm2
testl %r9d, %ebx
je 0x1715fc
xorpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %r9
cmpq %r9, %r10
jne 0x1715ed
testq %r15, %r15
je 0x171621
ucomisd %xmm0, %xmm1
ja 0x171621
ucomisd %xmm1, %xmm0
jne 0x171628
jp 0x171628
cmpl (%r12), %ebx
jne 0x171628
movq %r8, %r15
movapd %xmm1, %xmm0
incl %eax
cmpq %rax, %r13
ja 0x1715d8
jmp 0x17163c
xorl %r15d, %r15d
movsd 0xcb63c(%rip), %xmm0    # 0x23cc78
movzwl 0x6(%rsi,%rdi), %eax
cmpq $0xffff, %rax           # imm = 0xFFFF
je 0x1716d9
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %edx, %eax
leaq (%rax,%rax,2), %rax
movq 0x8(%r11,%rax,8), %r13
testq %r13, %r13
movq 0x20(%rsp), %rdx
je 0x1716de
movq %rdx, %r12
shlq %cl, %r12
leaq (%r11,%rax,8), %rax
movq (%rax), %rcx
leaq (%rsi,%rdi), %r11
movl %r10d, %r10d
shlq $0x3, %r12
movq 0x40(%rsp), %rax
addq (%rax), %r12
xorl %eax, %eax
leaq (%rcx,%rax,4), %r8
movl (%r8), %r9d
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
movsd (%r12,%rbx,8), %xmm2
testl %ebx, %r9d
je 0x1716a5
xorpd %xmm3, %xmm2
addsd %xmm2, %xmm1
incq %rbx
cmpq %rbx, %r10
jne 0x171696
testq %r15, %r15
je 0x1716c9
ucomisd %xmm0, %xmm1
ja 0x1716c9
ucomisd %xmm1, %xmm0
jne 0x1716d0
jp 0x1716d0
cmpl (%r11), %r9d
jne 0x1716d0
movq %r8, %r15
movapd %xmm1, %xmm0
incl %eax
cmpq %rax, %r13
ja 0x171689
jmp 0x1716de
movq 0x20(%rsp), %rdx
movl (%r15), %ecx
cmpl (%rsi,%rdi), %ecx
jne 0x1716ec
movl 0x14(%rsp), %ecx
jmp 0x17170d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x1726fa
movapd 0xc9aca(%rip), %xmm3    # 0x23b1d0
incl 0x4(%rsp)
movl 0xc(%rbx), %ecx
incq %r14
movl %ecx, %eax
cmpq %rax, %r14
jb 0x17155e
movq 0x38(%rsp), %r14
incl %r14d
cmpl $0x0, 0x4(%rsp)
jne 0x171512
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1704b0