// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x2, 0xc(%rax)
ja 0x21cafc
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x21cafa
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %edx
addl -0x14(%rbp), %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movb $0x0, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x21cabd
jmp 0x21cafc
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x21cb5e
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x14(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x21cb51
jmp 0x21cb5e
jmp 0x21cb53
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x21cb03
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jb 0x21cb6f
jmp 0x21cf39
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x21cd1d
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x14(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x21cd0d
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x20(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x21cc28
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x21cc49
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x21ccbc
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x21cc81
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x21cc8c
movl $0x2, %eax
movq %rax, -0x50(%rbp)
jmp 0x21cc8c
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
cvttsd2si -0x30(%rbp), %rax
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0x20(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, %eax
orq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rsi
movq 0x10(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x10(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x21ccff
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x21cbe1
jmp 0x21cd0f
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x21cb76
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x216280
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x21cf37
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x14(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x21ce5b
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x40(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x21ce5b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x21cf60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdx
andq $0x1, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x21ce31
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x54(%rbp)
jmp 0x21ce43
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movsbl (%rax,%rcx), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x40(%rbp), %ecx
movb %dl, (%rax,%rcx)
jmp 0x21cf27
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x21cec0
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x21ce99
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x40(%rbp), %ecx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
jmp 0x21ceab
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x40(%rbp), %ecx
movsbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movb %dl, (%rax,%rcx)
jmp 0x21cf25
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x40(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x21cf23
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x21cefe
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x5c(%rbp)
jmp 0x21cf10
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x3c(%rbp), %ecx
movsbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x40(%rbp), %ecx
movb %dl, (%rax,%rcx)
jmp 0x21cf25
jmp 0x21cf27
jmp 0x21cf29
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x21cd48
jmp 0x21cf39
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21c700
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21c580
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)