// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: mc_init_spin(mc_match_t const*, mc_svaux_t*)
t_w_t mc_init_spin(const mc_match_t *ma, mc_svaux_t *b)
{
	uint32_t i;
	b->cc_edge.n = 0;
	if(b->cc_size <= 2)//mannually clear
	{
		for (i = 0; i < b->cc_size; ++i) {///how many nodes
			b->s[(uint32_t)ma->cc[b->cc_off + i]] = 0;
		}
	}

	for (i = 0; i < b->cc_size; ++i) {///how many nodes
		uint32_t k = (uint32_t)ma->cc[b->cc_off + i];///node id
		b->cc_node[i] = k;
		if(b->s[k] == 0) break;
	}
	if(i >= b->cc_size) goto passed;

	for (i = 0; i < b->cc_size; ++i) {///how many nodes
		uint32_t k = (uint32_t)ma->cc[b->cc_off + i];///node id
		uint32_t o = ma->idx.a[k] >> 32;///cc group id
		uint32_t n = (uint32_t)ma->idx.a[k], j;
		b->cc_node[i] = k;
		for (j = 0; j < n; ++j) {
			w_t w = ma->ma.a[o + j].w;
			w = w > 0? w : -w;
			kv_push(uint64_t, b->cc_edge, (uint64_t)((uint32_t)-1 - ((uint32_t)w)) << 32 | (o + j));
		}
	}
	radix_sort_mc64(b->cc_edge.a, b->cc_edge.a + b->cc_edge.n);
	for (i = 0; i < b->cc_edge.n; ++i) { // from the strongest edge to the weakest
		const mc_edge_t *e = &ma->ma.a[(uint32_t)b->cc_edge.a[i]];
		uint32_t n1 = ma_x(*e), n2 = ma_y(*e);
		if (b->s[n1] == 0 && b->s[n2] == 0) {
			b->x = kr_splitmix64(b->x);
			b->s[n1] = b->x&1? 1 : -1;
			b->s[n2] = e->w > 0? -b->s[n1] : b->s[n1];
		}/****************************may have bugs********************************/
		else if(b->s[n1] == 0)
		{
			b->s[n1] = e->w > 0? -b->s[n2] : b->s[n2];
		}
		else if(b->s[n2] == 0)
		{
			b->s[n2] = e->w > 0? -b->s[n1] : b->s[n1];
		}
		/****************************may have bugs********************************/
	}

	passed:
	mc_reset_z(ma, b);
	return mc_score(ma, b);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
andq $0x0, 0x10(%rsi)
movq %rdi, %r14
movl 0xc(%rsi), %eax
cmpl $0x2, %eax
ja 0x125ae1
xorl %ecx, %ecx
cmpl %eax, %ecx
jae 0x125ae1
movq 0x50(%rbx), %rax
movq 0x30(%r14), %rdx
movl 0x8(%rbx), %esi
addl %ecx, %esi
movl (%rdx,%rsi,8), %edx
movb $0x0, (%rax,%rdx)
incl %ecx
movl 0xc(%rbx), %eax
jmp 0x125ac2
xorl %edx, %edx
movq %rdx, %rcx
movl %eax, %edx
cmpq %rdx, %rcx
jae 0x125b14
movq 0x30(%r14), %rax
movl 0x8(%rbx), %edx
addl %ecx, %edx
movq (%rax,%rdx,8), %rax
movl %eax, %esi
movq 0x28(%rbx), %rdx
movl %eax, (%rdx,%rcx,4)
movq 0x50(%rbx), %rax
leaq 0x1(%rcx), %rdx
cmpb $0x0, (%rax,%rsi)
movl 0xc(%rbx), %eax
jne 0x125ae3
cmpl %ecx, %eax
jbe 0x125ce4
xorl %esi, %esi
movapd 0xc759a(%rip), %xmm1    # 0x1ed0c0
pushq $0x2
popq %r12
movl %eax, %eax
cmpq %rax, %rsi
jae 0x125bfe
movq 0x10(%r14), %rax
movq 0x30(%r14), %rcx
movl 0x8(%rbx), %edx
addl %esi, %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq (%rax,%rdx,8), %rbp
movl %ebp, %r13d
shrq $0x20, %rbp
movq 0x28(%rbx), %rax
movq %rsi, 0x10(%rsp)
movl %ecx, (%rax,%rsi,4)
subq $0x1, %r13
jb 0x125bee
movq 0x28(%r14), %rax
movl %ebp, %r15d
movq %r15, %rcx
shlq $0x4, %rcx
movsd 0x8(%rax,%rcx), %xmm2
movq 0x10(%rbx), %rcx
movq 0x20(%rbx), %rax
cmpq 0x18(%rbx), %rcx
jne 0x125bc0
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0x18(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
movapd %xmm2, (%rsp)
callq 0x2370
movapd (%rsp), %xmm2
movapd 0xc7508(%rip), %xmm1    # 0x1ed0c0
movq %rax, 0x20(%rbx)
movq 0x10(%rbx), %rcx
movapd %xmm2, %xmm0
xorpd %xmm1, %xmm0
maxsd %xmm0, %xmm2
cvttsd2si %xmm2, %rdx
notl %edx
shlq $0x20, %rdx
orq %r15, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x10(%rbx)
movq %rdx, (%rax,%rcx,8)
incq %rbp
jmp 0x125b5f
movq 0x10(%rsp), %rsi
incq %rsi
movl 0xc(%rbx), %eax
jmp 0x125b2a
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1224a9
xorl %r15d, %r15d
xorpd %xmm1, %xmm1
movl %r15d, %r15d
cmpq %r15, 0x10(%rbx)
jbe 0x125ce4
movq 0x28(%r14), %rax
movq 0x20(%rbx), %rcx
movq 0x50(%rbx), %r12
movl (%rcx,%r15,8), %ecx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movq (%rax,%rcx), %rbp
movl %ebp, %r13d
shrq $0x20, %rbp
movb (%r12,%rbp), %al
movb (%r12,%r13), %cl
testb %al, %al
je 0x125c74
testb %cl, %cl
jne 0x125cdc
movsd 0x8(%rdx), %xmm0
movzbl %al, %ecx
negb %al
ucomisd %xmm1, %xmm0
movzbl %al, %eax
cmovbel %ecx, %eax
movb %al, (%r12,%r13)
jmp 0x125cdc
testb %cl, %cl
je 0x125c92
movsd 0x8(%rdx), %xmm0
movzbl %cl, %eax
negb %cl
ucomisd %xmm1, %xmm0
movzbl %cl, %ecx
cmovbel %eax, %ecx
movb %cl, (%r12,%rbp)
jmp 0x125cdc
movq (%rbx), %rdi
movq %rdx, (%rsp)
callq 0x125d08
xorpd %xmm1, %xmm1
movq %rax, (%rbx)
andl $0x1, %eax
cmpq $0x1, %rax
movl $0x0, %eax
sbbl %eax, %eax
orb $0x1, %al
movb %al, (%r12,%rbp)
movq (%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x50(%rbx), %rax
movzbl (%rax,%rbp), %ecx
movl %ecx, %edx
negb %dl
ucomisd %xmm1, %xmm0
movzbl %dl, %edx
cmovbel %ecx, %edx
movb %dl, (%rax,%r13)
incl %r15d
jmp 0x125c16
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1258d9
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12584f