// File: /workspace/github_cpp_makefile_star2_O3/YSRKEN[P]Shioi/I401/main.cpp
// Function: Board::FindOiteMove(Stone, unsigned long)
Result FindOiteMove(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);
					//p = StringToPosition("f8");
					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 (p == StringToPosition("f8")) {
						auto move_pattern1 = GetPatternB(p, Direction::Column);
						size_t block_position1 = kBoardSize * kBoardSize;
						size_t block_position2 = kBoardSize * kBoardSize;
						auto count1 = CountRenB2(move_pattern1, p, Direction::Column, block_position1);
						auto move_pattern2 = GetPatternB(p, Direction::DiagL);
						auto count2 = CountRenB2(move_pattern2, p, Direction::DiagL, block_position2);
						continue;
					}*/
					if (cho_ren_flg || sum_4_strong + sum_4_normal >= 2 || sum_3 >= 2) continue;
					// Shi-ren
					if (sum_4_strong > 0) return Result(p, true);
					// Other Oite
					board_[p] = Stone::Black;
					auto result = FindShioiMove(turn, kShioiDepth2);
					if (result.second) {
						auto flg = IsBlockMove(Stone::White, depth);
						board_[p] = Stone::None;
						if(!flg) return Result(p, true);
					}
					else {
						board_[p] = Stone::None;
					}
				}
			}
		}
		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;
					}
					// Shi-ren or Shi-Shi
					if (sum_4_strong > 0) return Result(p, true);
					if (sum_4_normal > 1) return Result(p, true);
					// Other Oite
					board_[p] = Stone::White;
					auto result = FindShioiMove(turn, kShioiDepth2);
					if (result.second) {
						auto flg = IsBlockMove(Stone::Black, depth);
						board_[p] = Stone::None;
						if (!flg) return Result(p, true);
					}
					else {
						board_[p] = Stone::None;
					}
				}
			}
		}
		return Result(0, false);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, 0x30(%rsp)
movl %esi, %ebx
movq %rdi, %r13
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x7690
movq 0x8(%r15), %rax
movq 0x18(%r15), %rcx
cmpl $0x1, %ebx
movq %rcx, 0x28(%rsp)
jne 0x53fe
cmpq %rcx, %rax
je 0x5403
movq %r13, (%rsp)
leaq 0x78(%rsp), %r14
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rcx
movq 0x68(%rsp), %rdx
cmpq %rdx, %rcx
je 0x53e9
movq 0x8(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %rsi
movq %rdx, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
leaq (%rcx,%rsi), %r15
movq (%rsp), %rax
cmpb $0x0, (%rax,%r15)
jne 0x53dd
movq %rcx, 0x18(%rsp)
movq $0xe1, 0x50(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r13d, %r13d
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 0x53c9
leaq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
movl %ebx, %r8d
leaq 0x50(%rsp), %r9
callq 0x773e
addq 0x48(%rsp), %rbp
addq 0x40(%rsp), %r12
addq 0x38(%rsp), %r13
incb %bl
cmpb $0x4, %bl
jne 0x5313
addq %rbp, %r12
cmpq $0x1, %r12
ja 0x53c9
cmpq $0x1, %r13
ja 0x53c9
testq %rbp, %rbp
jne 0x5537
movq (%rsp), %rbx
movq %r15, %r14
movb $0x1, (%rbx,%r15)
movl $0x3, %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x4f7e
testb $0x1, %dl
je 0x53c4
movq %rbx, %rdi
movl $0x2, %esi
movq 0x30(%rsp), %rdx
callq 0x8f8c
movb $0x0, (%rbx,%r14)
testb %al, %al
jne 0x53c9
jmp 0x5537
movb $0x0, (%rbx,%r14)
leaq 0x78(%rsp), %r14
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rsi
incq %rcx
cmpq %rdx, %rcx
jne 0x52e8
movq 0x8(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
jne 0x52b9
jmp 0x5403
cmpq %rcx, %rax
jne 0x540d
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x553c
leaq 0x78(%rsp), %r12
movzbl %bl, %edx
movl %edx, 0x20(%rsp)
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdx
movq 0x68(%rsp), %rsi
cmpq %rsi, %rdx
je 0x551f
movq 0x8(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %rdi
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
leaq (%rdx,%rdi), %r14
cmpb $0x0, (%r13,%r14)
jne 0x5513
movq %rdx, (%rsp)
xorl %ebx, %ebx
movq %r13, %r15
xorl %r13d, %r13d
xorl %ebp, %ebp
movzbl %bl, %ebx
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x862a
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x8752
addq 0x48(%rsp), %rbp
addq 0x40(%rsp), %r13
incb %bl
cmpb $0x4, %bl
jne 0x5466
movb $0x1, %bl
testq %rbp, %rbp
jne 0x553c
cmpq $0x1, %r13
ja 0x553c
movq %r15, %r13
movb $0x2, (%r15,%r14)
movl $0x3, %edx
movq %r15, %rdi
movl 0x20(%rsp), %esi
callq 0x4f7e
testb $0x1, %dl
je 0x54ff
movq %r13, %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
callq 0x8f8c
movb $0x0, (%r13,%r14)
testb %al, %al
movq (%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
jne 0x5513
jmp 0x553c
movb $0x0, (%r13,%r14)
movq (%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
incq %rdx
cmpq %rsi, %rdx
jne 0x5448
movq 0x8(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
jne 0x5419
jmp 0x5403
movb $0x1, %bl
movq %r15, %r14
movq %r14, %rax
movl %ebx, %edx
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop