// File: /workspace/github_cpp_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
movq %rdx, 0x30(%rsp)
movl %esi, %ebx
movq %rdi, %rsi
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %rsi, (%rsp)
callq 0x7690
movq 0x8(%r15), %rax
movq 0x18(%r15), %rcx
cmpl $0x1, %ebx
movq %rcx, 0x28(%rsp)
jne 0x5107
cmpq %rcx, %rax
je 0x510c
leaq 0x88(%rsp), %r14
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rcx
movq 0x78(%rsp), %rdx
cmpq %rdx, %rcx
je 0x50f2
movq 0x10(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %rsi
movq %rdx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
leaq (%rcx,%rsi), %r15
movq (%rsp), %rax
cmpb $0x0, (%rax,%r15)
jne 0x50e6
movq %rcx, 0x8(%rsp)
movq $0xe1, 0x38(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebx, %ebx
movzbl %bl, %ebx
movq %r14, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x66fe
movq %r14, %rdi
callq 0x683c
testb %al, %al
jne 0x50cf
leaq 0x40(%rsp), %rdi
movq (%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
movl %ebx, %r8d
leaq 0x38(%rsp), %r9
callq 0x773e
addq 0x50(%rsp), %rbp
addq 0x48(%rsp), %r13
addq 0x40(%rsp), %r12
incb %bl
cmpb $0x4, %bl
jne 0x502b
movq %rbp, %rax
addq %r13, %rax
cmpq $0x1, %rax
ja 0x50cf
cmpq $0x1, %r12
ja 0x50cf
testq %rbp, %rbp
jne 0x5245
cmpq $0x1, %r13
jne 0x50cf
movq (%rsp), %rbx
movb $0x1, (%rbx,%r15)
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rcx
callq 0x82dc
movb $0x0, (%rbx,%r15)
testb %al, %al
jne 0x5245
leaq 0x88(%rsp), %r14
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rsi
incq %rcx
cmpq %rdx, %rcx
jne 0x5000
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
jne 0x4fd1
jmp 0x510c
cmpq %rcx, %rax
jne 0x5116
xorl %r15d, %r15d
xorl %ebx, %ebx
jmp 0x524e
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %r12
movq 0x78(%rsp), %r13
cmpq %r13, %r12
je 0x522d
movq 0x10(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %rbp
movq %r13, 0x60(%rsp)
movq %rbp, 0x58(%rsp)
leaq (%r12,%rbp), %rcx
movq (%rsp), %rax
cmpb $0x0, (%rax,%rcx)
jne 0x5221
movq %r12, 0x20(%rsp)
movq %rcx, 0x8(%rsp)
movl $0xe1, %eax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
movzbl %bpl, %ebx
leaq 0x88(%rsp), %rdi
movq (%rsp), %r15
movq %r15, %rsi
movq 0x8(%rsp), %r14
movq %r14, %rdx
movl %ebx, %ecx
callq 0x862a
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
leaq 0x88(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x8752
movq 0x48(%rsp), %rax
testq %rax, %rax
je 0x51c4
movq 0x40(%rsp), %rcx
movq %rcx, 0x18(%rsp)
addq 0x50(%rsp), %r12
addq %rax, %r13
incb %bpl
cmpb $0x4, %bpl
jne 0x5173
movb $0x1, %bl
testq %r12, %r12
jne 0x5249
cmpq $0x1, %r13
ja 0x5249
movq 0x8(%rsp), %r15
movq 0x20(%rsp), %r12
movq 0x60(%rsp), %r13
movq 0x58(%rsp), %rbp
jne 0x5221
movq (%rsp), %r14
movb $0x2, (%r14,%r15)
movq %r14, %rdi
movl $0x2, %esi
movq 0x18(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x82dc
movb $0x0, (%r14,%r15)
testb %al, %al
jne 0x524e
incq %r12
cmpq %r13, %r12
jne 0x5145
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
jne 0x5116
jmp 0x510c
movb $0x1, %bl
jmp 0x524e
movq 0x8(%rsp), %r15
movq %r15, %rax
movl %ebx, %edx
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop