// File: /workspace/github_cpp_makefile_star2_O2/YSRKEN[P]Shioi/I401/main.cpp
// Function: Board::IsShioiMove(Stone, unsigned long, unsigned long)
bool IsShioiMove(const Stone turn, const size_t block_position, const size_t depth) {
		// Block Katsu-Shi
		if (block_position >= kBoardSize * kBoardSize) {
			return true;
		}
		auto enemy_stone = EnemyTurn(turn);
		if (enemy_stone == Stone::Black && !IsValidMove(block_position)) {
			//PutBoard();
			return true;
		}
		board_[block_position] = enemy_stone;
		// If you must block enemy's Shi-ren or Katsu-shi, this Shioi's challenge is failed.
		auto result = FindGorenMove(enemy_stone);
		if (result.second) {
			board_[block_position] = Stone::None;
			return false;
		}
		//depth limit
		if (depth == 0) {
			board_[block_position] = Stone::None;
			return false;
		}
		// Find Next Shi-ren or Katsu-shi
		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;
			if (turn == Stone::Black) {
				bool cho_ren_flg = false;
				size_t sum_4_strong = 0, sum_4_normal = 0, sum_3 = 0;
				size_t block_position2 = kBoardSize * kBoardSize;
				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;
					}
					//auto ren_count = CountRenB(move_pattern, p, static_cast<Direction>(dir));
					size_t s4s, s4n, s3;
					std::tie(s4s, s4n, s3) = CountRenB2(move_pattern, p, static_cast<Direction>(dir), block_position2);
					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 > 0) {
					board_[block_position] = Stone::None;
					return true;
				}
				if (sum_4_normal == 1) {
					board_[p] = Stone::Black;
					auto score = IsShioiMove(Stone::Black, block_position2, depth - 1);
					board_[p] = Stone::None;
					if (score) {
						board_[block_position] = Stone::None;
						return true;
					}
					continue;
				}
			}
			else {
				size_t block_position2 = kBoardSize * kBoardSize;
				size_t sum_4_strong = 0, sum_4_normal = 0;
				for (uint8_t dir = 0; dir < Direction::Directions; ++dir) {
					auto move_pattern = GetPatternW(p, static_cast<Direction>(dir));
					if (Board_helper::IsChorenW(move_pattern)) return true;
					size_t s4s, s4n, blk;
					std::tie(s4s, s4n, blk) = CountRenW2(move_pattern, p, static_cast<Direction>(dir));
					sum_4_strong += s4s;
					sum_4_normal += s4n;
					if (s4n) block_position2 = blk;
				}
				if (sum_4_strong > 0 || sum_4_normal > 1) {
					board_[block_position] = Stone::None;
					return true;
				}
				if (sum_4_normal == 1) {
					board_[p] = Stone::White;
					auto score = IsShioiMove(Stone::White, block_position2, depth - 1);
					board_[p] = Stone::None;
					if (score) {
						board_[block_position] = Stone::None;
						return true;
					}
					continue;
				}
			}
		}
		}

		board_[block_position] = Stone::None;
		return false;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movb $0x1, %al
movl %eax, 0x4(%rsp)
cmpq $0xe0, %rdx
ja 0x8043
movq %rcx, %r12
movq %rdx, %r14
movl %esi, %r13d
movq %rdi, %r15
cmpb $0x1, %r13b
sete %bl
je 0x7cca
movq %r15, %rdi
movq %r14, %rsi
callq 0x4884
testb %al, %al
je 0x8043
incb %bl
movb %bl, (%r15,%r14)
movzbl %bl, %esi
movq %r15, %rdi
callq 0x439c
testb $0x1, %dl
jne 0x8013
testq %r12, %r12
je 0x8013
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7058
movq 0x8(%rbx), %rcx
movq 0x18(%rbx), %rax
movq %rax, 0x80(%rsp)
decq %r12
movq %r14, 0x18(%rsp)
movq %r15, 0x8(%rsp)
movq %r12, 0x60(%rsp)
movl %r13d, 0x14(%rsp)
cmpq 0x80(%rsp), %rcx
setne %al
movl %eax, 0x4(%rsp)
je 0x803e
movq 0xa0(%rsp), %rax
movq 0xb0(%rsp), %rdx
movq %rdx, 0x90(%rsp)
imulq $0xf, %rcx, %rdx
movq %rdx, 0x88(%rsp)
movq %rcx, %r14
movq %rcx, 0x38(%rsp)
cmpq 0x90(%rsp), %rax
je 0x8003
movq 0x88(%rsp), %rcx
addq %rax, %rcx
cmpb $0x0, (%r15,%rcx)
jne 0x7ffb
cmpb $0x1, %r13b
movq %rax, 0x28(%rsp)
jne 0x7e76
movq $0xe1, 0x30(%rsp)
xorl %ebp, %ebp
xorl %edx, %edx
xorl %esi, %esi
xorl %eax, %eax
leaq 0xd8(%rsp), %r12
cmpb $0x4, %al
je 0x7f9b
movq %rsi, 0x48(%rsp)
movq %rdx, %r14
movq %rax, 0x40(%rsp)
movzbl %al, %ebx
movq %r12, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
movq %rcx, %r13
movq %rcx, %rdx
movl %ebx, %ecx
callq 0x6124
movq %r12, %rdi
callq 0x6266
testb %al, %al
jne 0x7fe7
movq %rbp, 0x20(%rsp)
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
movl %ebx, %r8d
leaq 0x30(%rsp), %r9
callq 0x7102
leaq 0x98(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
movq %rbp, %rsi
movq 0x20(%rsp), %rbp
callq 0x6e2c
addq 0x58(%rsp), %rbp
movq %r14, %rdx
addq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rsi
addq 0x98(%rsp), %rsi
movq 0x40(%rsp), %rax
incb %al
movq %r13, %rcx
jmp 0x7db4
movl $0xe1, %edx
movq %rdx, 0x20(%rsp)
xorl %edx, %edx
xorl %esi, %esi
xorl %r14d, %r14d
cmpb $0x4, %r14b
je 0x7f40
movq %rsi, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movzbl %r14b, %r12d
leaq 0xd8(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %rcx, %r13
movq %rcx, %rdx
movl %r12d, %ecx
callq 0x805a
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rbx
movq %r13, %rcx
movl %r12d, %r8d
callq 0x8182
leaq 0x50(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x6e2c
movq 0x58(%rsp), %rax
testq %rax, %rax
je 0x7f1e
movq 0x50(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq 0x48(%rsp), %rdx
addq 0x30(%rsp), %rdx
movq 0x40(%rsp), %rsi
addq %rax, %rsi
incb %r14b
movq 0x28(%rsp), %rax
movq %rbx, %rcx
jmp 0x7e87
testq %rdx, %rdx
jne 0x8022
cmpq $0x1, %rsi
ja 0x8022
movq 0x8(%rsp), %r15
movq 0x60(%rsp), %r12
movl 0x14(%rsp), %r13d
movq 0x38(%rsp), %r14
jne 0x7ffb
movb $0x2, (%r15,%rcx)
movq %r15, %rdi
pushq $0x2
popq %rsi
movq %rcx, %rbx
movq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0x7c7e
movb $0x0, (%r15,%rbx)
testb %al, %al
movq 0x28(%rsp), %rax
je 0x7ffb
jmp 0x8032
leaq (%rdx,%rbp), %rax
cmpq $0x1, %rax
movq 0x38(%rsp), %r14
ja 0x7fec
cmpq $0x1, %rsi
ja 0x7fec
testq %rbp, %rbp
jne 0x8022
cmpq $0x1, %rdx
jne 0x7fec
movq 0x8(%rsp), %rbx
movb $0x1, (%rbx,%rcx)
movq %rcx, %r15
movq 0x30(%rsp), %rdx
movq %rbx, %rdi
pushq $0x1
popq %rsi
movq 0x60(%rsp), %rcx
callq 0x7c7e
movb $0x0, (%rbx,%r15)
testb %al, %al
je 0x7fec
jmp 0x8022
movq 0x38(%rsp), %r14
movq 0x8(%rsp), %r15
movl 0x14(%rsp), %r13d
movq 0x28(%rsp), %rax
incq %rax
jmp 0x7d68
incq %r14
movq %r14, %rcx
movq 0x18(%rsp), %r14
jmp 0x7d27
movb $0x0, (%r15,%r14)
movl $0x0, 0x4(%rsp)
jmp 0x8043
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movb $0x0, (%rcx,%rax)
jmp 0x8043
movq 0x18(%rsp), %rax
movb $0x0, (%r15,%rax)
jmp 0x8043
movb $0x0, (%r15,%r14)
movl 0x4(%rsp), %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop