// File: /workspace/github_cpp_makefile_star2_O2/tewalds[P]morat/havannah/board.cpp
// Function: Morat::Havannah::Board::checkring_o1(Morat::MoveValid const&, Morat::Side) const
bool Board::checkring_o1(const MoveValid & pos, const Side turn) const {
	static const unsigned char ringdata[64][10] = {
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //000000
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //000001
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //000010
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //000011
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //000100
		{1, 3, 5, 0, 0, 0, 0, 0, 0, 0}, //000101
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //000110
		{3,16,10, 9, 0, 0, 0, 0, 0, 0}, //000111
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //001000
		{1, 2, 5, 0, 0, 0, 0, 0, 0, 0}, //001001
		{1, 2, 4, 0, 0, 0, 0, 0, 0, 0}, //001010
		{1, 2, 4, 0, 0, 0, 0, 0, 0, 0}, //001011
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //001100
		{1, 2, 5, 0, 0, 0, 0, 0, 0, 0}, //001101
		{3,15, 9, 8, 0, 0, 0, 0, 0, 0}, //001110
		{4,16,10, 9,15, 8, 9, 0, 0, 0}, //001111
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //010000
		{1, 1, 5, 0, 0, 0, 0, 0, 0, 0}, //010001
		{1, 1, 4, 0, 0, 0, 0, 0, 0, 0}, //010010
		{1, 1, 4, 0, 0, 0, 0, 0, 0, 0}, //010011
		{1, 1, 3, 0, 0, 0, 0, 0, 0, 0}, //010100
		{2, 1, 3, 5, 0, 0, 0, 0, 0, 0}, //010101
		{1, 1, 3, 0, 0, 0, 0, 0, 0, 0}, //010110
		{7,16,10, 9, 1, 3, 0, 0, 0, 0}, //010111
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //011000
		{1, 1, 5, 0, 0, 0, 0, 0, 0, 0}, //011001
		{1, 1, 4, 0, 0, 0, 0, 0, 0, 0}, //011010
		{1, 1, 4, 0, 0, 0, 0, 0, 0, 0}, //011011
		{3,14, 8, 7, 0, 0, 0, 0, 0, 0}, //011100
		{7,14, 8, 7, 1, 5, 0, 0, 0, 0}, //011101
		{4,15, 9, 8,14, 7, 8, 0, 0, 0}, //011110
		{5,16,10, 9,15, 8, 9,14, 8, 7}, //011111
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //100000
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //100001
		{1, 0, 4, 0, 0, 0, 0, 0, 0, 0}, //100010
		{3,17,11,10, 0, 0, 0, 0, 0, 0}, //100011
		{1, 0, 3, 0, 0, 0, 0, 0, 0, 0}, //100100
		{1, 0, 3, 0, 0, 0, 0, 0, 0, 0}, //100101
		{1, 0, 3, 0, 0, 0, 0, 0, 0, 0}, //100110
		{4,17,11,10,16, 9,10, 0, 0, 0}, //100111
		{1, 0, 2, 0, 0, 0, 0, 0, 0, 0}, //101000
		{1, 0, 2, 0, 0, 0, 0, 0, 0, 0}, //101001
		{2, 0, 2, 4, 0, 0, 0, 0, 0, 0}, //101010
		{7,17,11,10, 0, 2, 0, 0, 0, 0}, //101011
		{1, 0, 2, 0, 0, 0, 0, 0, 0, 0}, //101100
		{1, 0, 2, 0, 0, 0, 0, 0, 0, 0}, //101101
		{7,15, 9, 8, 0, 2, 0, 0, 0, 0}, //101110
		{5,17,11,10,16, 9,10,15, 9, 8}, //101111
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //110000
		{3,12, 6,11, 0, 0, 0, 0, 0, 0}, //110001
		{1, 0, 4, 0, 0, 0, 0, 0, 0, 0}, //110010
		{4,12, 6,11,17,10,11, 0, 0, 0}, //110011
		{1, 0, 3, 0, 0, 0, 0, 0, 0, 0}, //110100
		{7,12, 6,11, 0, 3, 0, 0, 0, 0}, //110101
		{1, 0, 3, 0, 0, 0, 0, 0, 0, 0}, //110110
		{5,12, 6,11,17,10,11,16,10, 9}, //110111
		{3,13, 7, 6, 0, 0, 0, 0, 0, 0}, //111000
		{4,13, 7, 6,12,11, 6, 0, 0, 0}, //111001
		{7,13, 7, 6, 0, 4, 0, 0, 0, 0}, //111010
		{5,13, 7, 6,12,11, 6,17,11,10}, //111011
		{4,14, 8, 7,13, 6, 7, 0, 0, 0}, //111100
		{5,14, 8, 7,13, 6, 7,12, 6,11}, //111101
		{5,15, 9, 8,14, 7, 8,13, 7, 6}, //111110
		{6, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //111111
	};

	int bitpattern = 0;
	const MoveValid * s = neighbors(pos);
	for (auto m : neighbors_small(pos)) {
		bitpattern <<= 1;
		if(m.on_board() && turn == get(m.xy))
			bitpattern |= 1;
	}

	const unsigned char * d = ringdata[bitpattern];

	switch(d[0]){
		case 0: //no ring (000000, 000001, 000011)
			return false;

		case 1: //simple case (000101, 001101, 001011, 011011)
			return (find_group(s[d[1]]) == find_group(s[d[2]]));

		case 2:{ //3 non-neighbors (010101)
			int a = find_group(s[d[1]]), b = find_group(s[d[2]]), c = find_group(s[d[3]]);
			return (a == b || a == c || b == c);
		}

		case 7: //case 1 and 3 (010111)
			if(find_group(s[d[4]]) == find_group(s[d[5]]))
				return true;
			//fall through

		case 3: // 3 neighbors (000111)
			return checkring_back(s[d[1]], s[d[2]], s[d[3]], turn);

		case 4: // 4 neighbors (001111)
			return checkring_back(s[d[1]], s[d[2]], s[d[3]], turn) ||
			       checkring_back(s[d[4]], s[d[5]], s[d[6]], turn);

		case 5: // 5 neighbors (011111)
			return checkring_back(s[d[1]], s[d[2]], s[d[3]], turn) ||
			       checkring_back(s[d[4]], s[d[5]], s[d[6]], turn) ||
			       checkring_back(s[d[7]], s[d[8]], s[d[9]], turn);

		case 6: // 6 neighbors (111111)
			return true; //a ring around this position? how'd that happen

		default:
			return false;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movswq 0x2(%rsi), %rax
movl %edx, %ebp
movq %rdi, %rbx
xorl %ecx, %ecx
xorl %edx, %edx
imulq $0x48, %rax, %r12
addq 0x88(%rdi), %r12
movq 0x10(%rdi), %rax
cmpq $0x18, %rcx
je 0x19614
movl (%r12,%rcx), %esi
addl %edx, %edx
cmpl $0xfffeffff, %esi       # imm = 0xFFFEFFFF
ja 0x1960e
sarl $0x10, %esi
xorl %edi, %edi
movslq %esi, %rsi
shlq $0x4, %rsi
cmpb %bpl, (%rax,%rsi)
sete %dil
orl %edi, %edx
addq $0x4, %rcx
jmp 0x195e4
movslq %edx, %rax
leaq 0xe342(%rip), %r13      # 0x27960
imulq $0xa, %rax, %rcx
movzbl (%rcx,%r13), %eax
decl %eax
cmpl $0x6, %eax
ja 0x1974b
leaq 0xe2b7(%rip), %rdx      # 0x278f0
addq %rcx, %r13
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movzbl 0x1(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
movl %eax, %ebp
movzbl 0x2(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
cmpl %eax, %ebp
sete %r14b
jmp 0x197d6
movzbl 0x1(%r13), %eax
movzbl %bpl, %ebp
movq %rbx, %rdi
movl %ebp, %r8d
leaq (%r12,%rax,4), %rsi
movzbl 0x2(%r13), %eax
leaq (%r12,%rax,4), %rdx
movzbl 0x3(%r13), %eax
leaq (%r12,%rax,4), %rcx
callq 0x1981e
movb $0x1, %r14b
testb %al, %al
jne 0x197d6
movzbl 0x4(%r13), %eax
movq %rbx, %rdi
movl %ebp, %r8d
leaq (%r12,%rax,4), %rsi
movzbl 0x5(%r13), %eax
leaq (%r12,%rax,4), %rdx
movzbl 0x6(%r13), %eax
leaq (%r12,%rax,4), %rcx
callq 0x1981e
testb %al, %al
jne 0x197d6
movzbl 0x7(%r13), %eax
leaq (%r12,%rax,4), %rsi
movzbl 0x8(%r13), %eax
leaq (%r12,%rax,4), %rdx
movzbl 0x9(%r13), %eax
jmp 0x1973c
movzbl 0x1(%r13), %eax
movzbl %bpl, %ebp
movq %rbx, %rdi
movl %ebp, %r8d
leaq (%r12,%rax,4), %rsi
movzbl 0x2(%r13), %eax
leaq (%r12,%rax,4), %rdx
movzbl 0x3(%r13), %eax
leaq (%r12,%rax,4), %rcx
callq 0x1981e
movb $0x1, %r14b
testb %al, %al
jne 0x197d6
movzbl 0x4(%r13), %eax
leaq (%r12,%rax,4), %rsi
movzbl 0x5(%r13), %eax
leaq (%r12,%rax,4), %rdx
movzbl 0x6(%r13), %eax
leaq (%r12,%rax,4), %rcx
movq %rbx, %rdi
movl %ebp, %r8d
jmp 0x1980a
xorl %r14d, %r14d
jmp 0x197d6
movzbl 0x1(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
movl %eax, %ebp
movzbl 0x2(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
movl %eax, %r14d
movzbl 0x3(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
cmpl %r14d, %ebp
sete %cl
cmpl %eax, %ebp
sete %dl
orb %cl, %dl
cmpl %eax, %r14d
sete %r14b
orb %dl, %r14b
jmp 0x197d6
movb $0x1, %r14b
jmp 0x197d6
movzbl 0x4(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
movl %eax, %r15d
movzbl 0x5(%r13), %eax
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
callq 0x19974
movb $0x1, %r14b
cmpl %eax, %r15d
jne 0x197e8
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl 0x1(%r13), %eax
movzbl %bpl, %r8d
movq %rbx, %rdi
leaq (%r12,%rax,4), %rsi
movzbl 0x2(%r13), %eax
leaq (%r12,%rax,4), %rdx
movzbl 0x3(%r13), %eax
leaq (%r12,%rax,4), %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1981e
nop