// File: /workspace/github_cpp_makefile_star2_O2/YSRKEN[P]Shioi/I401/main.cpp
// Function: Board::FindShioiMove(Stone, unsigned long)
Result FindShioiMove(const Stone turn, const size_t depth) {
		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;
					bool cho_ren_flg = false;
					size_t sum_4_strong = 0, sum_4_normal = 0, sum_3 = 0;
					size_t block_position = 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;
						}
						size_t s4s, s4n, s3;
						std::tie(s4s, s4n, s3) = CountRenB2(move_pattern, p, static_cast<Direction>(dir), block_position);
						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) return Result(p, true);
					if (sum_4_normal == 1) {
						board_[p] = Stone::Black;
						auto score = IsShioiMove(Stone::Black, block_position, depth);
						board_[p] = Stone::None;
						if (score) return Result(p, true);
						continue;
					}
				}
			}
		}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 block_position = 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 Result(p, 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_position = blk;
					}
					if (sum_4_strong > 0) return Result(p, true);
					if (sum_4_normal > 1) return Result(p, true);
					if (sum_4_normal == 1) {
						board_[p] = Stone::White;
						auto score = IsShioiMove(Stone::White, block_position, depth);
						board_[p] = Stone::None;
						if (score) return Result(p, true);
						continue;
					}
				}
			}
		}
		return Result(0, false);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, 0x68(%rsp)
movl %esi, %ebx
movq %rdi, %r14
leaq 0x90(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7058
movq 0x8(%r15), %rax
movq 0x18(%r15), %rcx
movq %rcx, 0x60(%rsp)
cmpl $0x1, %ebx
movq %r14, 0x10(%rsp)
jne 0x4b64
cmpq 0x60(%rsp), %rax
je 0x4ce0
movq 0x90(%rsp), %rdx
movq 0xa0(%rsp), %rsi
imulq $0xf, %rax, %rdi
movq %rax, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
cmpq %rsi, %rdx
je 0x4b5c
leaq (%rdx,%rdi), %rcx
cmpb $0x0, (%r14,%rcx)
jne 0x4b54
movq %rdx, 0x40(%rsp)
movq %rcx, (%rsp)
movq $0xe1, 0x20(%rsp)
xorl %eax, %eax
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0xc8(%rsp), %r13
cmpb $0x4, %al
je 0x4aeb
movq %rax, 0x48(%rsp)
movzbl %al, %ebp
movq %r13, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq (%rsp), %rbx
movq %rbx, %rdx
movl %ebp, %ecx
callq 0x6124
movq %r13, %rdi
callq 0x6266
testb %al, %al
jne 0x4b40
movq %r12, 0x18(%rsp)
leaq 0xb0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
leaq 0x20(%rsp), %r9
callq 0x7102
leaq 0x88(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
movq 0x18(%rsp), %r12
callq 0x6e2c
addq 0x58(%rsp), %r12
movq 0x8(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
addq 0x88(%rsp), %r15
movq 0x48(%rsp), %rax
incb %al
jmp 0x4a2e
movq 0x8(%rsp), %rax
addq %r12, %rax
cmpq $0x1, %rax
movq 0x10(%rsp), %r14
ja 0x4b40
cmpq $0x1, %r15
ja 0x4b40
testq %r12, %r12
jne 0x4cd7
cmpq $0x1, 0x8(%rsp)
jne 0x4b40
movq (%rsp), %rbx
movb $0x1, (%r14,%rbx)
movq 0x20(%rsp), %rdx
movq %r14, %rdi
pushq $0x1
popq %rsi
movq 0x68(%rsp), %rcx
callq 0x7c7e
movb $0x0, (%r14,%rbx)
testb %al, %al
jne 0x4cd7
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rdx
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
incq %rdx
jmp 0x49eb
incq %rax
jmp 0x49bd
movq %rax, %r15
cmpq 0x60(%rsp), %r15
je 0x4ce0
movq 0x90(%rsp), %r12
movq 0xa0(%rsp), %rax
movq %rax, 0x40(%rsp)
imulq $0xf, %r15, %rax
movq %rax, 0x30(%rsp)
movq %r15, 0x38(%rsp)
cmpq 0x40(%rsp), %r12
je 0x4ccf
movq 0x30(%rsp), %rax
addq %r12, %rax
cmpb $0x0, (%r14,%rax)
jne 0x4cc7
movq %r12, 0x28(%rsp)
movq %rax, (%rsp)
movl $0xe1, %eax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
xorl %eax, %eax
xorl %r12d, %r12d
cmpb $0x4, %r12b
je 0x4c81
movq %rax, 0x48(%rsp)
movq %rcx, 0x8(%rsp)
movzbl %r12b, %ebp
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %r13
movq %r13, %rsi
movq (%rsp), %r15
movq %r15, %rdx
movl %ebp, %ecx
callq 0x805a
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x8182
leaq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x6e2c
movq 0x58(%rsp), %rax
testq %rax, %rax
je 0x4c64
movq 0x50(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rsp), %rcx
addq 0x20(%rsp), %rcx
movq 0x48(%rsp), %rdx
addq %rax, %rdx
movq %rdx, %rax
incb %r12b
jmp 0x4bcd
movb $0x1, %r13b
testq %rcx, %rcx
jne 0x4cda
cmpq $0x1, %rax
movq (%rsp), %rbx
ja 0x4ce5
movq 0x10(%rsp), %r14
movq 0x38(%rsp), %r15
movq 0x28(%rsp), %r12
jne 0x4cc7
movb $0x2, (%r14,%rbx)
movq %r14, %rdi
pushq $0x2
popq %rsi
movq 0x18(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x7c7e
movb $0x0, (%r14,%rbx)
testb %al, %al
jne 0x4ce5
incq %r12
jmp 0x4b95
incq %r15
jmp 0x4b67
movb $0x1, %r13b
movq (%rsp), %rbx
jmp 0x4ce5
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %rbx, %rax
movl %r13d, %edx
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop