// File: /workspace/github_cpp_makefile_star2_O2/YSRKEN[P]Shioi/I401/main.cpp
// Function: Board::CalcScore(unsigned long, Stone)
int CalcScore(const size_t position, const Stone turn) {
		int score = 0;
		for (uint8_t dir = 0; dir < Direction::Directions; ++dir) {
			if (kIterateTable[position][dir][Side::Left] < 1 || kIterateTable[position][dir][Side::Right] < 1) continue;
			Pattern move_pattern = (turn == Stone::Black ? GetPatternB(position, static_cast<Direction>(dir)) : GetPatternW(position, static_cast<Direction>(dir)));
			size_t length = 0;
			bool flg1[] = { false, false };
			for (auto it : { Side::Left, Side::Right }) {
				if (move_pattern[it][0] != turn) {
					flg1[it] = (move_pattern[it][0] == Stone::None);
					continue;
				}
				PackedStone match = turn;
				for (size_t k = 1; k < kIterateTable[position][dir][it] - 1; ++k) {
					if (move_pattern[it][k] != (match | turn)) {
						flg1[it] = (move_pattern[it][k] == match | Stone::None);
						length += k;
						break;
					}
					match = turn | match;
				}
			}
			if (length < 3) {
				size_t cnt = ((flg1[Side::Left] ? 1 : 0) + (flg1[Side::Right] ? 1 : 0));
				score += length * length * cnt * cnt;
			}
		}
		return score;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, 0x28(%rsp)
movq %rsi, %rax
shlq $0x6, %rax
movq %rdi, 0x20(%rsp)
addq %rdi, %rax
addq $0xe8, %rax
movl %edx, 0x14(%rsp)
movl %edx, %r12d
xorl %ecx, %ecx
pushq $0x1
popq %rbp
movl $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
cmpq $0x4, %rcx
je 0x90c1
movq %rcx, %rbx
shlq $0x4, %rbx
cmpq $0x0, (%rax,%rbx)
je 0x90b9
addq %rax, %rbx
cmpq $0x0, 0x8(%rbx)
je 0x90b9
movq %rcx, 0x30(%rsp)
movzbl %cl, %ecx
cmpb $0x1, 0x14(%rsp)
jne 0x8fab
leaq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x6124
jmp 0x8fbf
leaq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x805a
andw $0x0, 0xc(%rsp)
movw $0x100, 0xe(%rsp)       # imm = 0x100
xorl %eax, %eax
xorl %edx, %edx
cmpq $0x2, %rdx
je 0x9093
movzbl 0xe(%rsp,%rdx), %esi
imulq $0x50, %rsi, %rdi
movq 0x38(%rsp,%rdi), %rcx
movq 0x40(%rsp,%rdi), %r8
xorq $0x1, %r8
movq %rcx, %r9
xorq %r12, %r9
orq %r8, %r9
je 0x9009
orq %rcx, %r8
sete 0xc(%rsp,%rsi)
jmp 0x908b
movq (%rbx,%rsi,8), %r9
decq %r9
leaq 0x50(%rsp), %rcx
addq %rcx, %rdi
movq %r12, %r10
movq %rbp, %r15
movq %rbp, %r8
cmpq %r9, %r8
jae 0x908b
movq -0x8(%rdi), %rcx
movq (%rdi), %r13
leaq (,%r10,4), %r14
orq %r12, %r14
cmpq $0x20, %r15
cmovaeq %r10, %r14
movq %r15, %r11
adcq $0x0, %r11
cmpq %r11, %r13
jne 0x907a
cmpq %r14, %rcx
jne 0x907a
leal (%r15,%r15), %ecx
movq %r12, %r11
shlq %cl, %r11
orq %r10, %r11
cmpq $0x20, %r15
leaq 0x1(%r15), %r15
cmovaeq %r12, %r11
cmovaeq %rbp, %r15
incq %r8
addq $0x10, %rdi
movq %r11, %r10
jmp 0x9021
xorq %r15, %r13
xorq %r10, %rcx
orq %r13, %rcx
sete 0xc(%rsp,%rsi)
addq %r8, %rax
incq %rdx
jmp 0x8fd0
cmpq $0x3, %rax
jae 0x90af
movzbl 0xc(%rsp), %ecx
movzbl 0xd(%rsp), %edx
addl %ecx, %edx
imull %edx, %eax
imull %eax, %eax
addl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
incq %rcx
jmp 0x8f5c
movl 0x10(%rsp), %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop