// File: /workspace/github_cpp_makefile_star2_O1/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 $0x148, %rsp            # imm = 0x148
movq %rcx, 0x30(%rsp)
movb $0x1, %al
movl %eax, (%rsp)
cmpq $0xe0, %rdx
ja 0x9012
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r12
cmpb $0x1, %r15b
sete %bl
je 0x8c7b
movq %r12, %rdi
movq %r14, %rsi
callq 0x509e
testb %al, %al
je 0x9012
incb %bl
movb %bl, (%r12,%r14)
movzbl %bl, %esi
movq %r12, %rdi
callq 0x49f8
testb $0x1, %dl
jne 0x8ff9
cmpq $0x0, 0x30(%rsp)
je 0x8ff9
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7f28
movq 0x8(%rbx), %rcx
movq 0x18(%rbx), %rdx
cmpq %rdx, %rcx
setne %al
movl %eax, (%rsp)
je 0x900d
decq 0x30(%rsp)
movq %r12, 0x18(%rsp)
movq %r14, 0x40(%rsp)
movl %r15d, 0x4(%rsp)
movq %rdx, 0x78(%rsp)
movq 0x88(%rsp), %r13
movq 0x98(%rsp), %rbp
cmpq %rbp, %r13
je 0x8fe5
movq %rcx, 0x80(%rsp)
leaq (%rcx,%rcx,4), %rax
leaq (%rax,%rax,2), %rax
movq %rbp, 0x20(%rsp)
movq %rax, 0x48(%rsp)
leaq (%rax,%r13), %rcx
movl $0x5, %ebx
cmpb $0x0, (%r12,%rcx)
jne 0x8f71
movq %rcx, 0x38(%rsp)
movq %r13, 0x28(%rsp)
cmpb $0x1, %r15b
jne 0x8e26
movq $0xe1, 0x58(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x50(%rsp)
movzbl %r15b, %ebx
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rbp
movq %rbp, %rdx
movl %ebx, %ecx
callq 0x6f68
movq %r14, %rdi
callq 0x70a3
movq %r12, %rsi
movl %eax, %r12d
testb %al, %al
je 0x8da5
movb $0x1, %al
movq %rax, 0x50(%rsp)
jmp 0x8de0
leaq 0x60(%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
movl %ebx, %r8d
leaq 0x58(%rsp), %r9
callq 0x7fea
addq 0x70(%rsp), %r13
movq 0x10(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpb $0x3, %r15b
leal 0x1(%r15), %eax
setb %cl
xorb $0x1, %r12b
movl %eax, %r15d
testb %r12b, %cl
movq 0x18(%rsp), %r12
jne 0x8d69
movl $0x5, %ebx
testb $0x1, 0x50(%rsp)
je 0x8ecf
xorl %eax, %eax
movl 0x4(%rsp), %r15d
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rbp
jmp 0x8f66
movl $0xe1, %eax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
xorl %edx, %edx
xorl %r13d, %r13d
movq %rdx, 0x10(%rsp)
movzbl %r15b, %ebx
leaq 0xa8(%rsp), %rbp
movq %rbp, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movq 0x38(%rsp), %r14
movq %r14, %rdx
movl %ebx, %ecx
callq 0x902a
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x916c
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x8e8d
movq 0x60(%rsp), %rcx
movq %rcx, 0x8(%rsp)
addq 0x70(%rsp), %r13
movq 0x10(%rsp), %rdx
addq %rax, %rdx
incb %r15b
cmpb $0x4, %r15b
jne 0x8e38
testq %r13, %r13
setne %al
cmpq $0x2, %rdx
setae %cl
orb %al, %cl
movl 0x4(%rsp), %r15d
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rbp
je 0x8f1b
movq 0x40(%rsp), %rax
movq 0x18(%rsp), %r12
jmp 0x8f0d
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rcx
xorl %eax, %eax
cmpq $0x1, %rcx
movl 0x4(%rsp), %r15d
ja 0x8e17
cmpq $0x1, 0x8(%rsp)
ja 0x8e17
testq %r13, %r13
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rbp
je 0x8f88
movq 0x40(%rsp), %rax
movb $0x0, (%r12,%rax)
movl $0x1, %ebx
xorl %eax, %eax
jmp 0x8f66
cmpq $0x1, %rdx
jne 0x8f5d
movq 0x18(%rsp), %rbx
movq 0x38(%rsp), %r14
movb $0x2, (%rbx,%r14)
movq %rbx, %rdi
movl $0x2, %esi
movq 0x8(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x8c2e
movb $0x0, (%rbx,%r14)
testb %al, %al
jne 0x8ec3
movl $0x5, %ebx
xorl %eax, %eax
jmp 0x8f61
xorl %ebx, %ebx
movb $0x1, %al
movq 0x18(%rsp), %r12
testb %al, %al
movq 0x48(%rsp), %rax
je 0x8f71
xorl %ebx, %ebx
cmpl $0x5, %ebx
je 0x8f7a
testl %ebx, %ebx
jne 0x8fce
incq %r13
cmpq %rbp, %r13
jne 0x8d17
jmp 0x8fc9
cmpq $0x1, 0x10(%rsp)
jne 0x8fc3
movq 0x38(%rsp), %r14
movb $0x1, (%r12,%r14)
movq 0x58(%rsp), %rdx
movq %r12, %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rcx
callq 0x8c2e
movb $0x0, (%r12,%r14)
testb %al, %al
jne 0x8f08
jmp 0x8f17
xorl %ebx, %ebx
movb $0x1, %al
jmp 0x8f66
movl $0x4, %ebx
testb $0x3, %bl
movq 0x40(%rsp), %r14
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %rdx
jne 0x9007
incq %rcx
cmpq %rdx, %rcx
setne %al
movl %eax, (%rsp)
jne 0x8ce4
jmp 0x900d
movb $0x0, (%r12,%r14)
movl $0x0, (%rsp)
jmp 0x9012
testb $0x1, (%rsp)
jne 0x9012
movb $0x0, (%r12,%r14)
movl (%rsp), %eax
andb $0x1, %al
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop