// File: /workspace/github_cpp_makefile_star2_O3/YSRKEN[P]Shioi/I401/main.cpp
// Function: Board::NegaMax(Stone, unsigned long, int, int)
int NegaMax(const Stone turn, const size_t depth, int /*alpha*/, int beta) {
		if (FindGorenMove(turn).second) return beta;
		int max_score = -kScoreInf2;
		if (depth == 0) {
			// Find enemy's Shioi(Pre-search)
			if (turn == Stone::Black) {
				auto range = GetRange();
				for (size_t y : rep(range[1], range[3])) {
					for (size_t x : rep(range[0], range[2])) {
						size_t p = ToPosition(x, y);
						if (board_[p] != Stone::None) continue;
						// Judge valid move
						bool cho_ren_flg = false;
						size_t sum_4_strong = 0, sum_4_normal = 0, sum_3 = 0;
						for (uint8_t dir = 0; dir < Direction::Directions; ++dir) {
							auto move_pattern = GetPatternB(p, static_cast<Direction>(dir));
							if (Board_helper::IsChorenB(move_pattern)) {
								cho_ren_flg = true;
								break;
							}
							size_t s4s, s4n, s3;
							std::tie(s4s, s4n, s3) = CountRenB(move_pattern, p, static_cast<Direction>(dir));
							sum_4_strong += s4s;
							sum_4_normal += s4n;
							sum_3 += s3;
						}
						if (cho_ren_flg || sum_4_strong + sum_4_normal >= 2 || sum_3 >= 2) continue;
						if (sum_4_strong == 1) return beta;
						int score;
						/* // Find enemy's Shioi
						board_[p] = turn;
						auto result = FindShioiMove(EnemyTurn(turn), kShioiDepth3);
						board_[p] = Stone::None;
						if (result.second) {
							// Don't block Shioi
							score = -kScoreInf;
						}
						else {*/
							// Normal Score
							score = CalcScore(p, turn);
						//}
						if (max_score < score) {
							max_score = score;
							if (max_score >= beta) {
								return beta;
							}
						}
					}
				}
			}
			else {
				auto range = GetRange();
				for (size_t y : rep(range[1], range[3])) {
					for (size_t x : rep(range[0], range[2])) {
						size_t p = ToPosition(x, y);
						if (board_[p] != Stone::None) continue;
						size_t sum_4_strong = 0, sum_4_normal = 0, sum_3 = 0;
						for (uint8_t dir = 0; dir < Direction::Directions; ++dir) {
							auto move_pattern = GetPatternB(p, static_cast<Direction>(dir));
							if (Board_helper::IsChorenB(move_pattern)) return beta;
							size_t s4s, s4n, s3;
							std::tie(s4s, s4n, s3) = CountRenB(move_pattern, p, static_cast<Direction>(dir));
							sum_4_strong += s4s;
							sum_4_normal += s4n;
							sum_3 += s3;
						}
						if (sum_4_strong >= 1 || sum_4_normal >= 2) return beta;
						int score;
						/*// Find enemy's Shioi
						board_[p] = turn;
						auto result = FindShioiMove(EnemyTurn(turn), kShioiDepth3);
						board_[p] = Stone::None;
						if (result.second) {
							// Don't block Shioi
							score = -kScoreInf;
						}
						else {*/
							// Normal Score
							score = CalcScore(p, turn);
						//}
						if (max_score < score) {
							max_score = score;
							if (max_score >= beta) {
								return beta;
							}
						}
					}
				}
			}
			return max_score;
		}
		else {
			vector<Score> next_move2;
			auto range = GetRange();
			if (turn == Stone::Black) {
				for (size_t y : rep(range[1], range[3])) {
					for (size_t x : rep(range[0], range[2])) {
						size_t p = ToPosition(x, y);
						if (board_[p] != Stone::None) continue;
						// Judge valid move
						bool cho_ren_flg = false;
						size_t sum_4_strong = 0, sum_4_normal = 0, sum_3 = 0;
						for (uint8_t dir = 0; dir < Direction::Directions; ++dir) {
							auto move_pattern = GetPatternB(p, static_cast<Direction>(dir));
							if (Board_helper::IsChorenB(move_pattern)) {
								cho_ren_flg = true;
								break;
							}
							size_t s4s, s4n, s3;
							std::tie(s4s, s4n, s3) = CountRenB(move_pattern, p, static_cast<Direction>(dir));
							sum_4_strong += s4s;
							sum_4_normal += s4n;
							sum_3 += s3;
						}
						if (cho_ren_flg || sum_4_strong + sum_4_normal >= 2 || sum_3 >= 2) continue;
						if (sum_4_strong == 1) return kScoreInf;
						/*// Find enemy's Shioi
						board_[p] = Stone::Black;
						auto result = FindShioiMove(Stone::White, kShioiDepth3);
						board_[p] = Stone::None;
						if (result.second) {
							// Don't block Shioi
							next_move2.emplace_back(p, -kScoreInf);
						}
						else {*/
							// Normal Score
							next_move2.emplace_back(p, kTenGenDist[p]);
						//}
					}
				}
			}
			else {
				for (size_t y : rep(range[1], range[3])) {
					for (size_t x : rep(range[0], range[2])) {
						size_t p = ToPosition(x, y);
						if (board_[p] != Stone::None) continue;
						size_t sum_4_strong = 0, sum_4_normal = 0, sum_3 = 0;
						for (uint8_t dir = 0; dir < Direction::Directions; ++dir) {
							auto move_pattern = GetPatternB(p, static_cast<Direction>(dir));
							if (Board_helper::IsChorenB(move_pattern)) return kScoreInf;
							size_t s4s, s4n, s3;
							std::tie(s4s, s4n, s3) = CountRenB(move_pattern, p, static_cast<Direction>(dir));
							sum_4_strong += s4s;
							sum_4_normal += s4n;
							sum_3 += s3;
						}
						if (sum_4_strong >= 1 || sum_4_normal >= 2) return kScoreInf;
						/*// Find enemy's Shioi
						board_[p] = Stone::White;
						auto result = FindShioiMove(Stone::Black, kShioiDepth3);
						board_[p] = Stone::None;
						if (result.second) {
							// Don't block Shioi
							next_move2.emplace_back(p, -kScoreInf);
						}
						else {*/
							// Normal Score
							next_move2.emplace_back(p, kTenGenDist[p]);
						//}
					}
				}
			}
			std::sort(next_move2.begin(), next_move2.end(), [](const Score &a, const Score &b) {return a.second > b.second; });
			for (auto &it : next_move2) {
				board_[it.first] = turn;
				auto score = -NegaMax(EnemyTurn(turn), depth - 1, -kScoreInf2, kScoreInf2) + CalcScore(it.first, turn);
				board_[it.first] = Stone::None;
				if (max_score < score) {
					max_score = score;
					if (max_score >= beta) {
						return beta;
					}
				}
			}
			return max_score;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %r8d, %r14d
movq %rdx, %rbx
movq %rdi, 0x8(%rsp)
movl %esi, 0x20(%rsp)
callq 0x4990
testb $0x1, %dl
jne 0x9d69
testq %rbx, %rbx
movl %r14d, 0x1c(%rsp)
je 0x9845
movq %rbx, 0xb0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x7690
movq 0x8(%rbx), %rcx
movq 0x18(%rbx), %rdx
cmpb $0x1, 0x20(%rsp)
jne 0x99d1
cmpq %rdx, %rcx
movq 0x8(%rsp), %rsi
je 0x99df
leaq 0x3928(%rsi), %rax
movq %rax, 0x70(%rsp)
leaq 0xb8(%rsp), %r12
movq %rdx, 0x48(%rsp)
movq %rcx, 0x28(%rsp)
movq 0x78(%rsp), %rbx
movq 0x88(%rsp), %r14
cmpq %r14, %rbx
je 0x982a
movq 0x28(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %rbp
movq %r14, 0x10(%rsp)
movq %rbp, 0x30(%rsp)
leaq (%rbx,%rbp), %rax
movq %rax, 0x40(%rsp)
cmpb $0x0, (%rsi,%rax)
jne 0x981e
movq %rbx, 0x38(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x40(%rsp), %rdx
movzbl %r14b, %ebx
movq %r12, %rdi
movl %ebx, %ecx
callq 0x66fe
movq %r12, %rdi
callq 0x683c
testb %al, %al
jne 0x980a
movq 0x40(%rsp), %rcx
leaq 0x98(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movl %ebx, %r8d
callq 0x69e0
addq 0xa8(%rsp), %r15
addq 0xa0(%rsp), %rbp
addq 0x98(%rsp), %r13
incb %r14b
cmpb $0x4, %r14b
movq 0x8(%rsp), %rsi
jne 0x9758
addq %r15, %rbp
cmpq $0x1, %rbp
movq 0x38(%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %rbp
ja 0x981e
cmpq $0x1, %r13
ja 0x981e
cmpq $0x1, %r15
je 0x9c10
movq 0x40(%rsp), %rax
movq 0x70(%rsp), %rcx
leaq (%rcx,%rax,8), %rdx
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x963a
movq 0x8(%rsp), %rsi
jmp 0x981e
movq 0x8(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %rbp
incq %rbx
cmpq %r14, %rbx
jne 0x9735
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x48(%rsp), %rdx
cmpq %rdx, %rcx
jne 0x9703
jmp 0x99df
cmpb $0x1, 0x20(%rsp)
movq 0x8(%rsp), %rsi
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
jne 0x9ad2
movq 0x8(%rsp), %rsi
callq 0x7690
movq 0x8(%rsp), %r13
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdx
movl $0xfffffc17, 0x28(%rsp) # imm = 0xFFFFFC17
movq %rdx, 0x48(%rsp)
cmpq %rdx, %rax
je 0x99c7
movl $0xfffffc17, 0x28(%rsp) # imm = 0xFFFFFC17
movq 0x78(%rsp), %r14
movq 0x88(%rsp), %r15
cmpq %r15, %r14
movq %rax, 0x70(%rsp)
je 0x99b4
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %r12
movq %r15, 0x30(%rsp)
movq %r12, 0x20(%rsp)
leaq (%r14,%r12), %rbx
cmpb $0x0, (%r13,%rbx)
jne 0x99a8
movq %r14, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %esi, %esi
xorl %ebp, %ebp
movq %rsi, 0x38(%rsp)
movzbl %bpl, %ebp
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
callq 0x66fe
movq %r14, %rdi
callq 0x683c
testb %al, %al
jne 0x9999
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
leaq 0xb8(%rsp), %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x69e0
addq 0x60(%rsp), %r12
addq 0x58(%rsp), %r15
movq 0x38(%rsp), %rsi
addq 0x50(%rsp), %rsi
incb %bpl
cmpb $0x4, %bpl
jne 0x98de
addq %r12, %r15
cmpq $0x1, %r15
ja 0x9999
cmpq $0x1, %rsi
ja 0x9999
cmpq $0x1, %r12
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %r12
je 0x9d64
movq %r13, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x9432
movq 0x8(%rsp), %r13
cmpl %eax, 0x28(%rsp)
jge 0x99a8
movl %eax, 0x28(%rsp)
cmpl 0x1c(%rsp), %eax
jl 0x99a8
jmp 0x9d64
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %r12
incq %r14
cmpq %r15, %r14
jne 0x98bf
movq 0x70(%rsp), %rax
incq %rax
cmpq 0x48(%rsp), %rax
jne 0x9892
movl 0x28(%rsp), %r14d
jmp 0x9d69
cmpq %rdx, %rcx
movq 0x8(%rsp), %rsi
jne 0x9af5
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r12
cmpq %r12, %rbx
je 0x9ac7
movq %r12, %rax
subq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa568
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa66c
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq %rax, %rbx
movq 0x8(%rsp), %r14
movq 0xb0(%rsp), %rdx
je 0x9ac7
movl 0x20(%rsp), %ecx
cmpb $0x1, %cl
sete %al
incb %al
decq %rdx
movl $0xfffffc17, %ebp       # imm = 0xFFFFFC17
movzbl %al, %eax
movl %eax, 0x10(%rsp)
movzbl %cl, %r13d
movq (%rbx), %rax
movl 0x20(%rsp), %ecx
movb %cl, (%r14,%rax)
movq %r14, %rdi
movl 0x10(%rsp), %esi
movq %rdx, %r12
movl $0xfffffc17, %ecx       # imm = 0xFFFFFC17
movl $0x3e9, %r8d            # imm = 0x3E9
callq 0x9662
movl %eax, %r15d
movq (%rbx), %rsi
movq %r14, %rdi
movl %r13d, %edx
callq 0x9432
subl %r15d, %eax
movq (%rbx), %rcx
movb $0x0, (%r14,%rcx)
cmpl %eax, %ebp
jge 0x9ab4
movl %eax, %ebp
cmpl 0x1c(%rsp), %eax
jge 0x9d7e
addq $0x10, %rbx
cmpq 0x38(%rsp), %rbx
movq %r12, %rdx
jne 0x9a63
jmp 0x9c15
movl $0xfffffc17, %r14d      # imm = 0xFFFFFC17
jmp 0x9c1d
callq 0x7690
movq 0x8(%rbx), %r13
movq 0x18(%rbx), %rbp
movl $0xfffffc17, %edx       # imm = 0xFFFFFC17
cmpq %rbp, %r13
jne 0x9c3b
movl %edx, %r14d
jmp 0x9d69
leaq 0x3928(%rsi), %rax
movq %rax, 0x30(%rsp)
leaq 0xb8(%rsp), %rbx
movq %rdx, 0x48(%rsp)
movq 0x78(%rsp), %r15
movq 0x88(%rsp), %rdi
cmpq %rdi, %r15
jne 0x9b2d
incq %rcx
cmpq %rdx, %rcx
jne 0x9b0e
jmp 0x99df
leaq (%rcx,%rcx,4), %rax
leaq (%rax,%rax,2), %r8
movq %rcx, 0x28(%rsp)
movq %rdi, 0x38(%rsp)
movq %r8, 0x10(%rsp)
leaq (%r15,%r8), %rax
movq %rax, 0x40(%rsp)
cmpb $0x0, (%rsi,%rax)
jne 0x9bff
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x40(%rsp), %rdx
movzbl %bpl, %r13d
movq %rbx, %rdi
movl %r13d, %ecx
callq 0x66fe
movq %rbx, %rdi
callq 0x683c
testb %al, %al
jne 0x9c10
movq 0x40(%rsp), %rcx
leaq 0x98(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movl %r13d, %r8d
callq 0x69e0
addq 0xa8(%rsp), %r12
addq 0xa0(%rsp), %r14
incb %bpl
cmpb $0x4, %bpl
movq 0x8(%rsp), %rsi
jne 0x9b5f
testq %r12, %r12
jne 0x9c10
cmpq $0x1, %r14
ja 0x9c10
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %rdx
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x963a
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %r8
incq %r15
cmpq %rdi, %r15
jne 0x9b44
jmp 0x9b20
movl $0x3e8, %ebp            # imm = 0x3E8
movq 0x50(%rsp), %rbx
movl %ebp, %r14d
testq %rbx, %rbx
je 0x9d69
movq 0x60(%rsp), %rsi
subq %rbx, %rsi
movq %rbx, %rdi
callq 0x21f0
jmp 0x9d69
leaq 0xb8(%rsp), %rbx
movzbl 0x20(%rsp), %eax
movl %eax, 0x48(%rsp)
movq %rbp, 0x70(%rsp)
movq 0x78(%rsp), %rsi
movq 0x88(%rsp), %rdi
cmpq %rdi, %rsi
jne 0x9c70
incq %r13
cmpq %rbp, %r13
jne 0x9c51
jmp 0x9aed
leaq (,%r13,4), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %r8
movq 0x8(%rsp), %rcx
movq %r13, 0x30(%rsp)
movq %rdi, 0x20(%rsp)
movq %r8, 0x28(%rsp)
leaq (%rsi,%r8), %r12
cmpb $0x0, (%rcx,%r12)
je 0x9ca8
incq %rsi
cmpq %rdi, %rsi
jne 0x9c93
jmp 0x9c63
movq %rsi, 0x10(%rsp)
movl %edx, 0x38(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r13d, %r13d
movzbl %r13b, %r13d
movq %rbx, %rdi
movq %rcx, %rbp
movq %rcx, %rsi
movq %r12, %rdx
movl %r13d, %ecx
callq 0x66fe
movq %rbx, %rdi
callq 0x683c
testb %al, %al
jne 0x9d64
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movl %r13d, %r8d
callq 0x69e0
addq 0x60(%rsp), %r14
addq 0x58(%rsp), %r15
incb %r13b
cmpb $0x4, %r13b
movq %rbp, %rcx
jne 0x9cba
testq %r14, %r14
movl 0x1c(%rsp), %r14d
movq 0x30(%rsp), %r13
movq 0x70(%rsp), %rbp
jne 0x9d69
cmpq $0x1, %r15
ja 0x9d69
movq %rcx, %rdi
movq %r12, %rsi
movl 0x48(%rsp), %edx
callq 0x9432
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x38(%rsp), %edx
movq 0x8(%rsp), %rcx
cmpl %eax, %edx
jge 0x9c9e
movl %eax, %edx
cmpl %r14d, %eax
jl 0x9c9e
jmp 0x9d69
movl 0x1c(%rsp), %r14d
movl %r14d, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x1c(%rsp), %ebp
jmp 0x9c15
jmp 0x9d95
jmp 0x9d95
jmp 0x9d95
jmp 0x9d95
jmp 0x9d95
jmp 0x9d95
jmp 0x9d95
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9daf
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330
nop