// File: 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
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl $0x0, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x4, %eax
jge 0x191b6
movq -0x1b0(%rbp), %rdi
addq $0xe8, %rdi
movq -0x10(%rbp), %rsi
callq 0x56e0
movq %rax, %rdi
movzbl -0x19(%rbp), %eax
movl %eax, %esi
callq 0x5710
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5740
cmpq $0x1, (%rax)
jb 0x18dda
movq -0x1b0(%rbp), %rdi
addq $0xe8, %rdi
movq -0x10(%rbp), %rsi
callq 0x56e0
movq %rax, %rdi
movzbl -0x19(%rbp), %eax
movl %eax, %esi
callq 0x5710
movq %rax, %rdi
movl $0x1, %esi
callq 0x5740
cmpq $0x1, (%rax)
jae 0x18ddf
jmp 0x191a9
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
jne 0x18e05
movq -0x1b0(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
movzbl -0x19(%rbp), %ecx
callq 0xed20
jmp 0x18e20
movq -0x1b0(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
movzbl -0x19(%rbp), %ecx
callq 0x159c0
movq $0x0, -0xc8(%rbp)
leaq -0xca(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2130
movb $0x0, -0xea(%rbp)
movb $0x1, -0xe9(%rbp)
leaq -0xea(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq $0x2, -0xe0(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x11460
movq %rax, -0xf8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x11480
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rax
cmpq -0x100(%rbp), %rax
je 0x19141
movq -0xf8(%rbp), %rax
movb (%rax), %al
movb %al, -0x101(%rbp)
movzbl -0x101(%rbp), %eax
movl %eax, %esi
leaq -0xc0(%rbp), %rdi
callq 0x11580
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x115b0
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x117e0
leaq -0x118(%rbp), %rdi
movzbl -0x11(%rbp), %esi
callq 0x1a550
testb $0x1, %al
jne 0x18f02
jmp 0x18f58
movzbl -0x101(%rbp), %eax
movl %eax, %esi
leaq -0xc0(%rbp), %rdi
callq 0x11580
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x115b0
movq %rax, %rsi
leaq -0x128(%rbp), %rdi
callq 0x117e0
leaq -0x128(%rbp), %rdi
xorl %esi, %esi
callq 0x11a00
movb %al, %cl
movzbl -0x101(%rbp), %eax
andb $0x1, %cl
movb %cl, -0xca(%rbp,%rax)
jmp 0x1912a
leaq -0x138(%rbp), %rdi
movzbl -0x11(%rbp), %esi
callq 0x115e0
movq $0x1, -0x140(%rbp)
movq -0x1b0(%rbp), %rdi
movq -0x140(%rbp), %rax
movq %rax, -0x1b8(%rbp)
addq $0xe8, %rdi
movq -0x10(%rbp), %rsi
callq 0x56e0
movq %rax, %rdi
movzbl -0x19(%rbp), %eax
movl %eax, %esi
callq 0x5710
movq %rax, %rdi
movzbl -0x101(%rbp), %eax
movl %eax, %esi
callq 0x5740
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movq (%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x19128
movzbl -0x101(%rbp), %eax
movl %eax, %esi
leaq -0xc0(%rbp), %rdi
callq 0x11580
movq %rax, %rdi
movq -0x140(%rbp), %rsi
callq 0x115b0
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
callq 0x117e0
leaq -0x160(%rbp), %rdi
leaq -0x138(%rbp), %rsi
movzbl -0x11(%rbp), %edx
callq 0x3140
leaq -0x150(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x1a590
testb $0x1, %al
jne 0x19037
jmp 0x190c6
movzbl -0x101(%rbp), %eax
movl %eax, %esi
leaq -0xc0(%rbp), %rdi
callq 0x11580
movq %rax, %rdi
movq -0x140(%rbp), %rsi
callq 0x115b0
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
callq 0x117e0
leaq -0x180(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x117e0
leaq -0x170(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x11890
andb $0x1, %al
movzbl %al, %eax
orl $0x0, %eax
cmpl $0x0, %eax
setne %cl
movzbl -0x101(%rbp), %eax
andb $0x1, %cl
movb %cl, -0xca(%rbp,%rax)
movq -0x140(%rbp), %rax
addq -0xc8(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x19128
movb -0x11(%rbp), %al
movb %al, -0x1b9(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x117e0
movb -0x1b9(%rbp), %al
leaq -0x190(%rbp), %rdi
leaq -0x1a0(%rbp), %rdx
movzbl %al, %esi
callq 0x1a5e0
leaq -0x138(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x3200
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x140(%rbp)
jmp 0x18f73
jmp 0x1912a
movq -0xf8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf8(%rbp)
jmp 0x18e99
cmpq $0x3, -0xc8(%rbp)
jae 0x191a7
movb -0xca(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb -0xc9(%rbp), %sil
xorl %ecx, %ecx
movl $0x1, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
addl %ecx, %eax
cltq
movq %rax, -0x1a8(%rbp)
movq -0xc8(%rbp), %rcx
imulq -0xc8(%rbp), %rcx
imulq -0x1a8(%rbp), %rcx
imulq -0x1a8(%rbp), %rcx
movslq -0x18(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x18(%rbp)
jmp 0x191a9
movb -0x19(%rbp), %al
addb $0x1, %al
movb %al, -0x19(%rbp)
jmp 0x18d5e
movl -0x18(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)