// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x1, %r15d
movl $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %rcx, %rbx
shlq $0x4, %rbx
cmpq $0x0, (%rax,%rbx)
je 0xa166
addq %rax, %rbx
cmpq $0x0, 0x8(%rbx)
je 0xa166
movq %rcx, 0x30(%rsp)
movzbl %cl, %ecx
cmpb $0x1, 0x14(%rsp)
jne 0xa036
leaq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x6f68
jmp 0xa04a
leaq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x902a
movw $0x0, 0xc(%rsp)
movw $0x100, 0xe(%rsp)       # imm = 0x100
xorl %edx, %edx
xorl %eax, %eax
movzbl 0xe(%rsp,%rdx), %esi
leaq (%rsi,%rsi,4), %rdi
movl %edi, %r8d
shll $0x4, %r8d
movq 0x38(%rsp,%r8), %rcx
movq 0x40(%rsp,%r8), %r8
xorq $0x1, %r8
movq %rcx, %r9
xorq %r12, %r9
orq %r8, %r9
je 0xa092
orq %rcx, %r8
sete 0xc(%rsp,%rsi)
jmp 0xa133
movq (%rbx,%rsi,8), %rcx
leaq -0x1(%rcx), %r8
cmpq $0x2, %r8
jb 0xa133
movl $0x2, %r8d
subq %rcx, %r8
shll $0x4, %edi
leaq 0x50(%rsp), %rcx
addq %rcx, %rdi
movl $0x1, %ebp
xorl %r9d, %r9d
movq %r12, %r11
movq -0x8(%rdi), %rcx
movq (%rdi), %r14
leaq (,%r11,4), %r13
orq %r12, %r13
cmpq $0x20, %rbp
cmovaeq %r11, %r13
movq %rbp, %r10
adcq $0x0, %r10
cmpq %r10, %r14
jne 0xa11f
cmpq %r13, %rcx
jne 0xa11f
leal (,%rbp,2), %ecx
movq %r12, %r10
shlq %cl, %r10
orq %r11, %r10
cmpq $0x20, %rbp
cmovaeq %r12, %r10
leaq 0x1(%rbp), %rbp
cmovaeq %r15, %rbp
decq %r9
addq $0x10, %rdi
movq %r10, %r11
cmpq %r9, %r8
jne 0xa0c3
jmp 0xa133
xorq %rbp, %r14
xorq %r11, %rcx
orq %r14, %rcx
sete 0xc(%rsp,%rsi)
subq %r9, %rax
incq %rax
incq %rdx
cmpq $0x2, %rdx
jne 0xa05c
cmpq $0x3, %rax
jae 0xa15c
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
cmpq $0x4, %rcx
jne 0x9ff1
movl 0x10(%rsp), %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop