// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/rcut.cpp
// Function: mcgg_init_spin(mc_match_t const*, mcgg_svaux_t*)
t_w_t mcgg_init_spin(const mc_match_t *ma, mcgg_svaux_t *b)
{
	uint32_t i;
	b->cc_edge.n = 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].s == 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].s == 0 && b->s[n2].s == 0) {
			b->s[n1].s = kr_drand_node(n1, b, &(b->s[n1].hc));
			// debug_hapM(&(b->s[n1]), "s0");
			b->s[n2].s = kr_drand_node_ref(n2, b, &(b->s[n2].hc), b->s[n1].s, e->w>0?1:0);
			// debug_hapM(&(b->s[n2]), "s1");
		}
		else if(b->s[n1].s == 0)
		{
			b->s[n1].s = kr_drand_node_ref(n1, b, &(b->s[n1].hc), b->s[n2].s, e->w>0?1:0);	
			// debug_hapM(&(b->s[n1]), "s2");	
		}
		else if(b->s[n2].s == 0)
		{
			b->s[n2].s = kr_drand_node_ref(n2, b, &(b->s[n2].hc), b->s[n1].s, e->w>0?1:0);
			// debug_hapM(&(b->s[n2]), "s3");
		}
	}

	passed:
	mcgg_reset_z(ma, b);
	return mcgg_score(ma, b);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq $0x0, 0x10(%rsi)
cmpl $0x0, 0xc(%rsi)
movq %rdi, (%rsp)
je 0x169abd
movq 0x30(%rdi), %rcx
movq 0x28(%rbx), %rdx
movq 0x50(%rbx), %rsi
xorl %eax, %eax
movl 0x8(%rbx), %edi
addl %eax, %edi
movq (%rcx,%rdi,8), %rdi
movl %edi, %r8d
movl %edi, (%rdx,%rax,4)
shlq $0x5, %r8
cmpl $0x0, (%rsi,%r8)
je 0x169abf
incq %rax
movl 0xc(%rbx), %edi
cmpq %rdi, %rax
jb 0x169a96
jmp 0x169abf
xorl %eax, %eax
cmpl 0xc(%rbx), %eax
jae 0x16a10e
cmpl $0x0, 0xc(%rbx)
movq (%rsp), %rdi
je 0x169bb7
xorl %r15d, %r15d
movapd 0xc54df(%rip), %xmm1    # 0x22efc0
movl $0x2, %r12d
movq 0x10(%rdi), %rax
movq 0x30(%rdi), %rcx
movl 0x8(%rbx), %edx
addl %r15d, %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq (%rax,%rdx,8), %rax
movq 0x28(%rbx), %rdx
movl %ecx, (%rdx,%r15,4)
testl %eax, %eax
je 0x169ba8
movq %rax, %r13
shrq $0x20, %r13
movl %eax, %ebp
movq 0x28(%rdi), %rax
movl %r13d, %r14d
movq %r14, %rcx
shlq $0x4, %rcx
movsd 0x8(%rax,%rcx), %xmm2
movq 0x18(%rbx), %rax
cmpq %rax, 0x10(%rbx)
jne 0x169b6e
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r12, %rsi
movq %rsi, 0x18(%rbx)
movq 0x20(%rbx), %rdi
shlq $0x3, %rsi
movapd %xmm2, 0x10(%rsp)
callq 0x2370
movapd 0x10(%rsp), %xmm2
movapd 0xc545a(%rip), %xmm1    # 0x22efc0
movq (%rsp), %rdi
movq %rax, 0x20(%rbx)
movapd %xmm2, %xmm0
xorpd %xmm1, %xmm0
maxsd %xmm0, %xmm2
cvttsd2si %xmm2, %rax
notl %eax
shlq $0x20, %rax
orq %r14, %rax
movq 0x10(%rbx), %rcx
movq 0x20(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x10(%rbx)
movq %rax, (%rdx,%rcx,8)
incq %r13
decq %rbp
jne 0x169b18
incq %r15
movl 0xc(%rbx), %eax
cmpq %rax, %r15
jb 0x169ae7
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1604f0
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
je 0x16a10e
movq (%rsp), %rax
movq 0x28(%rax), %r11
movq 0x20(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rbx), %r12
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movsd 0xbb93f(%rip), %xmm1    # 0x225538
movq %rdx, 0x8(%rsp)
movq 0x10(%rsp), %rax
movl (%rax,%r13,8), %eax
shlq $0x4, %rax
leaq (%r11,%rax), %r9
movq (%r11,%rax), %rcx
movq %rcx, %rax
shrq $0x20, %rax
shlq $0x5, %rax
movl (%r12,%rax), %r10d
testl %r10d, %r10d
je 0x169cdb
movl %ecx, %eax
shlq $0x5, %rax
cmpl $0x0, (%r12,%rax)
jne 0x16a102
leaq (%r12,%rax), %rdi
movsd 0x8(%r9), %xmm2
movzwl 0x4(%r12,%rax), %edx
movw $0x0, 0x8(%rdi)
movq (%rbx), %rax
movabsq $-0x61c8864680b583eb, %rcx # imm = 0x9E3779B97F4A7C15
addq %rcx, %rax
movq %rax, %rcx
shrq $0x1e, %rcx
xorq %rax, %rcx
movabsq $-0x40a7b892e31b1a47, %rax # imm = 0xBF58476D1CE4E5B9
imulq %rax, %rcx
movq %rcx, %rax
shrq $0x1b, %rax
xorq %rcx, %rax
movabsq $-0x6b2fb644ecceee15, %rcx # imm = 0x94D049BB133111EB
imulq %rcx, %rax
movq %rax, %rcx
shrq $0x1f, %rcx
xorq %rax, %rcx
movq %rcx, (%rbx)
movzwl 0x6(%rdi), %eax
cmpw $-0x1, %ax
je 0x169cd4
movq %rcx, %rsi
shrq $0xc, %rsi
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
orq %r8, %rsi
movq %rsi, %xmm3
addsd %xmm1, %xmm3
ucomisd 0x10(%rdi), %xmm3
cmoval %eax, %edx
ja 0x169e34
movl %edx, %eax
jmp 0x169e3a
leaq (%r12,%rax), %rbp
movl %ecx, %r8d
shlq $0x5, %r8
cmpl $0x0, (%r12,%r8)
je 0x169d9f
testl %r10d, %r10d
jne 0x169c2b
movl %ecx, %ecx
shlq $0x5, %rcx
movl (%r12,%rcx), %edi
movsd 0x8(%r9), %xmm2
movzwl 0x4(%r12,%rax), %edx
movw $0x0, 0x8(%rbp)
movq (%rbx), %rax
movabsq $-0x61c8864680b583eb, %rcx # imm = 0x9E3779B97F4A7C15
addq %rcx, %rax
movq %rax, %rcx
shrq $0x1e, %rcx
xorq %rax, %rcx
movabsq $-0x40a7b892e31b1a47, %rax # imm = 0xBF58476D1CE4E5B9
imulq %rax, %rcx
movq %rcx, %rax
shrq $0x1b, %rax
xorq %rcx, %rax
movabsq $-0x6b2fb644ecceee15, %rcx # imm = 0x94D049BB133111EB
imulq %rcx, %rax
movq %rax, %rcx
shrq $0x1f, %rcx
xorq %rax, %rcx
movq %rcx, (%rbx)
movzwl 0x6(%rbp), %eax
cmpw $-0x1, %ax
je 0x169d98
movq %rcx, %rsi
shrq $0xc, %rsi
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
orq %r8, %rsi
movq %rsi, %xmm3
addsd %xmm1, %xmm3
ucomisd 0x10(%rbp), %xmm3
cmoval %eax, %edx
ja 0x16a056
movl %edx, %eax
jmp 0x16a05c
movzwl 0x4(%r12,%rax), %eax
movw $0x0, 0x8(%rbp)
movq (%rbx), %rcx
movabsq $-0x61c8864680b583eb, %rdx # imm = 0x9E3779B97F4A7C15
addq %rdx, %rcx
movq %rcx, %rdx
shrq $0x1e, %rdx
xorq %rcx, %rdx
movabsq $-0x40a7b892e31b1a47, %rcx # imm = 0xBF58476D1CE4E5B9
imulq %rcx, %rdx
movq %rdx, %rsi
shrq $0x1b, %rsi
xorq %rdx, %rsi
movabsq $-0x6b2fb644ecceee15, %rcx # imm = 0x94D049BB133111EB
imulq %rcx, %rsi
movq %rsi, %rcx
shrq $0x1f, %rcx
xorq %rsi, %rcx
movq %rcx, (%rbx)
movzwl 0x6(%rbp), %edx
cmpw $-0x1, %dx
je 0x169e2d
movq %rcx, %rsi
shrq $0xc, %rsi
movabsq $0x3ff0000000000000, %rdi # imm = 0x3FF0000000000000
orq %rdi, %rsi
movq %rsi, %xmm2
addsd %xmm1, %xmm2
ucomisd 0x10(%rbp), %xmm2
cmoval %edx, %eax
ja 0x169ee4
movl %eax, %edx
jmp 0x169eea
movw $0x1, 0x8(%rdi)
xorl %edx, %edx
ucomisd %xmm0, %xmm2
seta %dl
negl %edx
xorl %edx, %r10d
andl 0x68(%rbx), %r10d
je 0x169e6b
movl %r10d, %edx
xorl %ebp, %ebp
movl %r10d, %esi
movl %edx, %r8d
andl $0x1, %r8d
addq %r8, %rbp
shrl %esi
cmpl $0x1, %edx
movl %esi, %edx
ja 0x169e56
jmp 0x169e6d
xorl %ebp, %ebp
movzwl %ax, %eax
movq %rbp, %r8
subq %rax, %r8
je 0x169edc
jae 0x169e8e
movl 0x6c(%rbx), %edx
subq %rbp, %rdx
subq %rbp, %rax
xorl %r9d, %r9d
movq %rdx, %rbp
movq %rax, %r8
jmp 0x169e94
movl $0x1, %r9d
testq %r8, %r8
je 0x169edc
movl 0x6c(%rbx), %r15d
xorl %esi, %esi
testq %r15, %r15
je 0x169ed1
movq %rcx, %rax
xorl %edx, %edx
divq %rbp
xorl %eax, %eax
btl %eax, %r10d
movl %r9d, %r14d
sbbl $0x0, %r14d
jne 0x169ec3
testq %rdx, %rdx
je 0x169ecd
decq %rdx
incq %rax
cmpq %rax, %r15
jne 0x169eae
jmp 0x169ed1
btcl %eax, %r10d
decq %rbp
incq %rsi
cmpq %r8, %rsi
jne 0x169e9f
movl %r10d, (%rdi)
jmp 0x16a0fd
movw $0x1, 0x8(%rbp)
leaq (%r12,%r8), %r10
decl %edx
movq 0x60(%rbx), %rsi
movzwl %dx, %eax
leaq (%rax,%rax,2), %rdi
movq (%rsi,%rdi,8), %r14
movq %rcx, %rax
xorl %edx, %edx
divq 0x8(%rsi,%rdi,8)
movl (%r14,%rdx,4), %edi
movl %edi, (%rbp)
movsd 0x8(%r9), %xmm2
movzwl 0x4(%r12,%r8), %edx
movw $0x0, 0x8(%r12,%r8)
movabsq $-0x61c8864680b583eb, %rax # imm = 0x9E3779B97F4A7C15
addq %rax, %rcx
movq %rcx, %rax
shrq $0x1e, %rax
xorq %rcx, %rax
movabsq $-0x40a7b892e31b1a47, %rcx # imm = 0xBF58476D1CE4E5B9
imulq %rcx, %rax
movq %rax, %rsi
shrq $0x1b, %rsi
xorq %rax, %rsi
movabsq $-0x6b2fb644ecceee15, %rax # imm = 0x94D049BB133111EB
imulq %rax, %rsi
movq %rsi, %rcx
shrq $0x1f, %rcx
xorq %rsi, %rcx
movq %rcx, (%rbx)
movzwl 0x6(%r10), %eax
cmpw $-0x1, %ax
je 0x169fa1
movq %rcx, %rsi
shrq $0xc, %rsi
movabsq $0x3ff0000000000000, %r9 # imm = 0x3FF0000000000000
orq %r9, %rsi
movq %rsi, %xmm3
addsd %xmm1, %xmm3
ucomisd 0x10(%r10), %xmm3
cmoval %eax, %edx
ja 0x169fa5
movl %edx, %eax
jmp 0x169fb2
leaq (%r12,%r8), %rdx
addq $0x8, %rdx
movw $0x1, (%rdx)
xorl %edx, %edx
ucomisd %xmm0, %xmm2
seta %dl
negl %edx
xorl %edx, %edi
andl 0x68(%rbx), %edi
je 0x169fdf
movl %edi, %edx
xorl %ebp, %ebp
movl %edi, %esi
movl %edx, %r8d
andl $0x1, %r8d
addq %r8, %rbp
shrl %esi
cmpl $0x1, %edx
movl %esi, %edx
ja 0x169fca
jmp 0x169fe1
xorl %ebp, %ebp
movzwl %ax, %eax
movq %rbp, %r8
subq %rax, %r8
je 0x16a04e
jae 0x16a002
movl 0x6c(%rbx), %edx
subq %rbp, %rdx
subq %rbp, %rax
xorl %r9d, %r9d
movq %rdx, %rbp
movq %rax, %r8
jmp 0x16a008
movl $0x1, %r9d
testq %r8, %r8
je 0x16a04e
movl 0x6c(%rbx), %r15d
xorl %esi, %esi
testq %r15, %r15
je 0x16a043
movq %rcx, %rax
xorl %edx, %edx
divq %rbp
xorl %eax, %eax
btl %eax, %edi
movl %r9d, %r14d
sbbl $0x0, %r14d
jne 0x16a036
testq %rdx, %rdx
je 0x16a040
decq %rdx
incq %rax
cmpq %rax, %r15
jne 0x16a022
jmp 0x16a043
btcl %eax, %edi
decq %rbp
incq %rsi
cmpq %r8, %rsi
jne 0x16a013
movl %edi, (%r10)
jmp 0x16a0fd
movw $0x1, 0x8(%rbp)
xorl %edx, %edx
ucomisd %xmm0, %xmm2
seta %dl
negl %edx
xorl %edx, %edi
andl 0x68(%rbx), %edi
je 0x16a08a
movl %edi, %edx
xorl %r10d, %r10d
movl %edi, %esi
movl %edx, %r8d
andl $0x1, %r8d
addq %r8, %r10
shrl %esi
cmpl $0x1, %edx
movl %esi, %edx
ja 0x16a075
jmp 0x16a08d
xorl %r10d, %r10d
movzwl %ax, %eax
movq %r10, %r8
subq %rax, %r8
je 0x16a0fa
jae 0x16a0ae
movl 0x6c(%rbx), %edx
subq %r10, %rdx
subq %r10, %rax
xorl %r9d, %r9d
movq %rdx, %r10
movq %rax, %r8
jmp 0x16a0b4
movl $0x1, %r9d
testq %r8, %r8
je 0x16a0fa
movl 0x6c(%rbx), %r15d
xorl %esi, %esi
testq %r15, %r15
je 0x16a0ef
movq %rcx, %rax
xorl %edx, %edx
divq %r10
xorl %eax, %eax
btl %eax, %edi
movl %r9d, %r14d
sbbl $0x0, %r14d
jne 0x16a0e2
testq %rdx, %rdx
je 0x16a0ec
decq %rdx
incq %rax
cmpq %rax, %r15
jne 0x16a0ce
jmp 0x16a0ef
btcl %eax, %edi
decq %r10
incq %rsi
cmpq %r8, %rsi
jne 0x16a0bf
movl %edi, (%rbp)
movq 0x8(%rsp), %rdx
incl %r13d
cmpq %r13, %rdx
ja 0x169bfe
movq (%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1698f1
movq %r14, %rdi
movq %rbx, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1699e2