// File: /workspace/github_cpp_makefile_star2_O1/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 $0x158, %rsp            # imm = 0x158
movq %rdx, 0x60(%rsp)
movl %esi, %ebp
movq %rdi, %rsi
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x30(%rsp)
callq 0x7f28
movq 0x8(%rbx), %r12
movq 0x18(%rbx), %rbx
cmpq %rbx, %r12
sete %al
movl %ebp, 0x4c(%rsp)
cmpl $0x1, %ebp
movq %rbx, 0x50(%rsp)
jne 0x589d
cmpq %rbx, %r12
je 0x5a36
movq 0x30(%rsp), %r14
movb %al, 0xf(%rsp)
movq 0x98(%rsp), %r13
movq 0xa8(%rsp), %rbp
movb $0x1, %al
cmpq %rbp, %r13
je 0x5881
leaq (%r12,%r12,4), %rax
leaq (%rax,%rax,2), %rcx
movq %r12, 0x38(%rsp)
movq %rbp, 0x68(%rsp)
movq %rcx, 0x40(%rsp)
leaq (%rcx,%r13), %r15
movl $0x5, %eax
cmpb $0x0, (%r14,%r15)
jne 0x57b6
movq %r13, 0x70(%rsp)
movq $0xe1, 0x90(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r12d, %r12d
movzbl %r12b, %r13d
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
movl %r13d, %ecx
callq 0x6f68
movq %r14, %rdi
callq 0x70a3
movl %eax, %ebx
testb %al, %al
je 0x5721
movb $0x1, %al
movq %rax, 0x58(%rsp)
jmp 0x5772
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r15, %rcx
movl %r13d, %r8d
leaq 0x90(%rsp), %r9
callq 0x7fea
movq 0x10(%rsp), %rax
addq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rax
addq 0x78(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpb $0x3, %r12b
leal 0x1(%r12), %eax
setb %cl
xorb $0x1, %bl
movl %eax, %r12d
testb %bl, %cl
jne 0x56e8
movl $0x5, %eax
testb $0x1, 0x58(%rsp)
je 0x57d4
movq 0x38(%rsp), %r12
movq 0x50(%rsp), %rbx
movq 0x30(%rsp), %r14
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %rbp
movq 0x40(%rsp), %rcx
cmpl $0x5, %eax
je 0x57c3
testl %eax, %eax
jne 0x587c
incq %r13
cmpq %rbp, %r13
jne 0x569c
jmp 0x5877
movq 0x28(%rsp), %rcx
addq 0x10(%rsp), %rcx
cmpq $0x1, %rcx
movq 0x38(%rsp), %r12
movq 0x50(%rsp), %rbx
movq 0x30(%rsp), %r14
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %rbp
ja 0x57b1
cmpq $0x1, 0x20(%rsp)
movq 0x40(%rsp), %rcx
ja 0x57b6
movl $0x1, %eax
cmpq $0x0, 0x10(%rsp)
je 0x581e
movq %r15, 0x18(%rsp)
jmp 0x57b6
movb $0x1, (%r14,%r15)
movzbl 0x4c(%rsp), %esi
movl $0x3, %edx
movq %r14, %rdi
callq 0x519a
testb $0x1, %dl
je 0x586b
movq %r14, %rdi
movl $0x2, %esi
movq 0x60(%rsp), %rdx
callq 0x99a0
movb $0x0, (%r14,%r15)
testb %al, %al
movq 0x18(%rsp), %rcx
cmoveq %r15, %rcx
movq %rcx, 0x18(%rsp)
xorb $0x1, %al
movzbl %al, %eax
jmp 0x57b1
movb $0x0, (%r14,%r15)
xorl %eax, %eax
jmp 0x57b1
movl $0x4, %eax
testb $0x3, %al
sete %al
testb %al, %al
je 0x5a32
incq %r12
cmpq %rbx, %r12
sete %al
jne 0x5666
jmp 0x5a36
cmpq %rbx, %r12
jne 0x58a7
jmp 0x5a36
movq %r12, 0x38(%rsp)
leaq 0xb8(%rsp), %r14
movzbl 0x4c(%rsp), %ecx
movl %ecx, 0x58(%rsp)
movq 0x30(%rsp), %r12
movq 0x98(%rsp), %rdx
movq 0xa8(%rsp), %rdi
movl $0xb, %ecx
cmpq %rdi, %rdx
je 0x5a0e
movb %al, 0xf(%rsp)
movq 0x38(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %r8
movq %rdi, 0x28(%rsp)
movq %r8, 0x20(%rsp)
leaq (%rdx,%r8), %r15
movl $0xc, %eax
cmpb $0x0, (%r12,%r15)
jne 0x59f1
movq %rdx, 0x10(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %ebp, %ebp
movzbl %bl, %ebx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x902a
leaq 0x78(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
movl %ebx, %r8d
callq 0x916c
addq 0x88(%rsp), %rbp
addq 0x80(%rsp), %r13
incb %bl
cmpb $0x4, %bl
jne 0x591b
movl $0x1, %eax
testq %rbp, %rbp
jne 0x59c5
cmpq $0x1, %r13
movq 0x50(%rsp), %rbx
movq 0x30(%rsp), %r12
ja 0x59be
movb $0x2, (%r12,%r15)
movl $0x3, %edx
movq %r12, %rdi
movl 0x58(%rsp), %esi
callq 0x519a
testb $0x1, %dl
je 0x59d6
movq %r12, %rdi
movl $0x1, %esi
movq 0x60(%rsp), %rdx
callq 0x99a0
movb $0x0, (%r12,%r15)
testb %al, %al
movq 0x18(%rsp), %rcx
cmoveq %r15, %rcx
movq %rcx, 0x18(%rsp)
xorb $0x1, %al
movzbl %al, %eax
jmp 0x59dd
movq %r15, 0x18(%rsp)
jmp 0x59dd
movq %r15, 0x18(%rsp)
movq 0x50(%rsp), %rbx
movq 0x30(%rsp), %r12
jmp 0x59dd
movb $0x0, (%r12,%r15)
xorl %eax, %eax
movl $0xb, %ecx
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r8
cmpl $0xc, %eax
je 0x59fa
testl %eax, %eax
jne 0x5a08
incq %rdx
cmpq %rdi, %rdx
jne 0x58fb
jmp 0x5a0a
movl %eax, %ecx
movb 0xf(%rsp), %al
cmpl $0xb, %ecx
je 0x5a17
testl %ecx, %ecx
jne 0x5a36
movq 0x38(%rsp), %rcx
incq %rcx
movq %rcx, 0x38(%rsp)
cmpq %rbx, %rcx
sete %al
jne 0x58c2
jmp 0x5a36
movb 0xf(%rsp), %al
movb $0x1, %dl
testb $0x1, %al
movq 0x18(%rsp), %rax
je 0x5a45
xorl %eax, %eax
xorl %edx, %edx
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop