// File: /workspace/github_cpp_makefile_star2_O2/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 $0x168, %rsp            # imm = 0x168
movq %rdx, 0x58(%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, 0x50(%rsp)
cmpl $0x1, %ebx
movq %r14, 0x18(%rsp)
jne 0x4f00
movq %rax, %r15
cmpq 0x50(%rsp), %r15
je 0x5091
movq 0x90(%rsp), %rcx
movq 0xa0(%rsp), %rdx
imulq $0xf, %r15, %rsi
movq %r15, 0x8(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, 0x80(%rsp)
cmpq %rdx, %rcx
je 0x4ef8
leaq (%rcx,%rsi), %rax
cmpb $0x0, (%r14,%rax)
jne 0x4ee9
movq %rcx, 0x10(%rsp)
movq %rax, (%rsp)
movq $0xe1, 0x48(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r13d, %r13d
leaq 0xc8(%rsp), %rbp
cmpb $0x4, %r15b
je 0x4e76
movq %rcx, 0x28(%rsp)
movq %rax, 0x38(%rsp)
movzbl %r15b, %r12d
movq %rbp, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movq (%rsp), %rbx
movq %rbx, %rdx
movl %r12d, %ecx
callq 0x6124
movq %rbp, %rdi
callq 0x6266
testb %al, %al
jne 0x4ed2
movq %r15, 0x20(%rsp)
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movl %r12d, %r8d
leaq 0x48(%rsp), %r9
callq 0x7102
leaq 0x88(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
movq 0x20(%rsp), %r15
callq 0x6e2c
addq 0x40(%rsp), %r13
movq 0x28(%rsp), %rcx
addq 0x60(%rsp), %rcx
movq 0x38(%rsp), %rax
addq 0x88(%rsp), %rax
incb %r15b
jmp 0x4db7
addq %r13, %rcx
cmpq $0x1, %rcx
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %r15
ja 0x4ed7
cmpq $0x1, %rax
ja 0x4ed7
testq %r13, %r13
jne 0x5089
movq (%rsp), %rbx
movb $0x1, (%r14,%rbx)
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0x3
popq %rdx
callq 0x4974
testb $0x1, %dl
je 0x4ef1
movq %r14, %rdi
pushq $0x2
popq %rsi
movq 0x58(%rsp), %rdx
callq 0x89b2
movb $0x0, (%r14,%rbx)
testb %al, %al
jne 0x4ed7
jmp 0x5089
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq 0x80(%rsp), %rsi
incq %rcx
jmp 0x4d7b
movb $0x0, (%r14,%rbx)
jmp 0x4ed7
incq %r15
jmp 0x4d4a
movzbl %bl, %ecx
movl %ecx, 0x30(%rsp)
movq %rax, %rcx
movq 0x18(%rsp), %rbp
cmpq 0x50(%rsp), %rcx
je 0x5091
movq 0x90(%rsp), %rdx
movq 0xa0(%rsp), %rsi
imulq $0xf, %rcx, %rdi
movq %rcx, 0x8(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
cmpq %rsi, %rdx
je 0x5081
leaq (%rdx,%rdi), %rax
cmpb $0x0, (%r14,%rax)
jne 0x5079
movq %rdx, 0x28(%rsp)
movq %rax, (%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r13d, %r13d
cmpb $0x4, %r13b
je 0x4ffa
movzbl %r13b, %ebx
leaq 0xc8(%rsp), %rdi
movq %rbp, %rsi
movq (%rsp), %r15
movq %r15, %rdx
movq %rcx, 0x38(%rsp)
movl %ebx, %ecx
movq %rax, %r14
callq 0x805a
leaq 0xb0(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xc8(%rsp), %rdx
movq %r15, %rcx
movl %ebx, %r8d
callq 0x8182
leaq 0x60(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x6e2c
movq 0x38(%rsp), %rcx
movq %r14, %rax
addq 0x48(%rsp), %rax
addq 0x40(%rsp), %rcx
incb %r13b
jmp 0x4f65
movb $0x1, %bl
testq %rax, %rax
jne 0x508b
cmpq $0x1, %rcx
movq (%rsp), %r12
ja 0x5096
movq 0x18(%rsp), %r14
movb $0x2, (%r14,%r12)
movq %r14, %rdi
movl 0x30(%rsp), %esi
pushq $0x3
popq %rdx
callq 0x4974
testb $0x1, %dl
je 0x5060
movq %r14, %rdi
pushq $0x1
popq %rsi
movq 0x58(%rsp), %rdx
callq 0x89b2
movb $0x0, (%r14,%r12)
testb %al, %al
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
jne 0x5079
jmp 0x5096
movb $0x0, (%r14,%r12)
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
incq %rdx
jmp 0x4f3d
incq %rcx
jmp 0x4f0f
movb $0x1, %bl
movq (%rsp), %r12
jmp 0x5096
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %r12, %rax
movl %ebx, %edx
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop