// File: 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
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movb %sil, %al
movq %rdi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x18(%rbp), %rsi
movq %rsi, -0x3a8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x126b0
movzbl -0x19(%rbp), %eax
cmpl $0x1, %eax
jne 0xbc81
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x12a70
movq %rax, -0x3b0(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x12a70
movq -0x3b0(%rbp), %rdi
movq %rax, %rsi
callq 0xec40
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x54e0
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rdi
callq 0x5510
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5550
testb $0x1, %al
jne 0xb90c
jmp 0xbc7c
leaq -0x68(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0x78(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12a70
movq %rax, -0x3b8(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x12a70
movq -0x3b8(%rbp), %rdi
movq %rax, %rsi
callq 0xec40
movq %rax, -0x90(%rbp)
movq %rdx, -0x88(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x54e0
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rdi
callq 0x5510
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x5550
testb $0x1, %al
jne 0xb9a2
jmp 0xbc6c
leaq -0x98(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x3100
movq -0x3a8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
callq 0x5590
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xb9ef
jmp 0xbc5b
movb $0x0, -0xb1(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movq $0xe1, -0xd8(%rbp)
movb $0x0, -0xd9(%rbp)
movzbl -0xd9(%rbp), %eax
cmpl $0x4, %eax
jge 0xbb2e
movq -0x3a8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
leaq -0x180(%rbp), %rdi
movzbl -0xd9(%rbp), %ecx
callq 0xed20
leaq -0x180(%rbp), %rdi
callq 0xef70
testb $0x1, %al
jne 0xba6c
jmp 0xba78
movb $0x1, -0xb1(%rbp)
jmp 0xbb2e
movq -0x3a8(%rbp), %rsi
movq -0xb0(%rbp), %rcx
leaq -0x1b0(%rbp), %rdi
leaq -0x180(%rbp), %rdx
leaq -0xd8(%rbp), %r9
movzbl -0xd9(%rbp), %r8d
callq 0x12aa0
leaq -0x1c8(%rbp), %rdi
leaq -0x188(%rbp), %rsi
leaq -0x190(%rbp), %rdx
leaq -0x198(%rbp), %rcx
callq 0x11390
leaq -0x1c8(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x113d0
movq -0x188(%rbp), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x190(%rbp), %rax
addq -0xc8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x198(%rbp), %rax
addq -0xd0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movb -0xd9(%rbp), %al
addb $0x1, %al
movb %al, -0xd9(%rbp)
jmp 0xba29
testb $0x1, -0xb1(%rbp)
jne 0xbb55
movq -0xc0(%rbp), %rax
addq -0xc8(%rbp), %rax
cmpq $0x2, %rax
jae 0xbb55
cmpq $0x2, -0xd0(%rbp)
jb 0xbb5a
jmp 0xbc5b
cmpq $0x0, -0xc0(%rbp)
jbe 0xbb87
movb $0x1, -0x1c9(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1c9(%rbp), %rdx
callq 0xec80
jmp 0xc08c
movq -0x3a8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x5590
movq -0x3a8(%rbp), %rdi
movb $0x1, (%rax)
movzbl -0x19(%rbp), %esi
movl $0x3, %edx
callq 0xb0b0
movb %dl, -0x1e8(%rbp)
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movb -0x1e8(%rbp), %al
movb %al, -0x1d8(%rbp)
testb $0x1, -0x1d8(%rbp)
je 0xbc43
movq -0x3a8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x2, %esi
callq 0x180d0
movq -0x3a8(%rbp), %rdi
andb $0x1, %al
movb %al, -0x1f1(%rbp)
movq -0xb0(%rbp), %rsi
callq 0x5590
movb $0x0, (%rax)
testb $0x1, -0x1f1(%rbp)
jne 0xbc41
movb $0x1, -0x1f2(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1f2(%rbp), %rdx
callq 0xec80
jmp 0xc08c
jmp 0xbc59
movq -0x3a8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x5590
movb $0x0, (%rax)
jmp 0xbc5b
leaq -0x98(%rbp), %rdi
callq 0x55c0
jmp 0xb986
jmp 0xbc6e
leaq -0x68(%rbp), %rdi
callq 0x55c0
jmp 0xb8f6
jmp 0xc064
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x12a70
movq %rax, -0x3c0(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x12a70
movq -0x3c0(%rbp), %rdi
movq %rax, %rsi
callq 0xec40
movq %rax, -0x210(%rbp)
movq %rdx, -0x208(%rbp)
leaq -0x210(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rdi
callq 0x54e0
movq %rax, -0x218(%rbp)
movq -0x200(%rbp), %rdi
callq 0x5510
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x5550
testb $0x1, %al
jne 0xbd11
jmp 0xc062
leaq -0x218(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0x228(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12a70
movq %rax, -0x3c8(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x12a70
movq -0x3c8(%rbp), %rdi
movq %rax, %rsi
callq 0xec40
movq %rax, -0x240(%rbp)
movq %rdx, -0x238(%rbp)
leaq -0x240(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
callq 0x54e0
movq %rax, -0x248(%rbp)
movq -0x230(%rbp), %rdi
callq 0x5510
movq %rax, -0x250(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x5550
testb $0x1, %al
jne 0xbdb6
jmp 0xc04f
leaq -0x248(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rdi
movq -0x228(%rbp), %rsi
callq 0x3100
movq -0x3a8(%rbp), %rdi
movq %rax, -0x260(%rbp)
movq -0x260(%rbp), %rsi
callq 0x5590
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xbe06
jmp 0xc03e
movq $0xe1, -0x268(%rbp)
movq $0x0, -0x270(%rbp)
movq $0x0, -0x278(%rbp)
movb $0x0, -0x279(%rbp)
movzbl -0x279(%rbp), %eax
cmpl $0x4, %eax
jge 0xbf13
movq -0x3a8(%rbp), %rsi
movq -0x260(%rbp), %rdx
leaq -0x320(%rbp), %rdi
movzbl -0x279(%rbp), %ecx
callq 0x159c0
movq -0x3a8(%rbp), %rsi
movq -0x260(%rbp), %rcx
leaq -0x350(%rbp), %rdi
leaq -0x320(%rbp), %rdx
movzbl -0x279(%rbp), %r8d
callq 0x15c00
leaq -0x368(%rbp), %rdi
leaq -0x328(%rbp), %rsi
leaq -0x330(%rbp), %rdx
leaq -0x338(%rbp), %rcx
callq 0x11390
leaq -0x368(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x113d0
movq -0x328(%rbp), %rax
addq -0x270(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x330(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, -0x330(%rbp)
je 0xbefe
movq -0x338(%rbp), %rax
movq %rax, -0x268(%rbp)
jmp 0xbf00
movb -0x279(%rbp), %al
addb $0x1, %al
movb %al, -0x279(%rbp)
jmp 0xbe2e
cmpq $0x0, -0x270(%rbp)
jbe 0xbf40
movb $0x1, -0x369(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x369(%rbp), %rdx
callq 0xec80
jmp 0xc08c
cmpq $0x1, -0x278(%rbp)
jbe 0xbf6d
movb $0x1, -0x36a(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x36a(%rbp), %rdx
callq 0xec80
jmp 0xc08c
movq -0x3a8(%rbp), %rdi
movq -0x260(%rbp), %rsi
callq 0x5590
movq -0x3a8(%rbp), %rdi
movb $0x2, (%rax)
movzbl -0x19(%rbp), %esi
movl $0x3, %edx
callq 0xb0b0
movb %dl, -0x388(%rbp)
movq %rax, -0x390(%rbp)
movq -0x390(%rbp), %rax
movq %rax, -0x380(%rbp)
movb -0x388(%rbp), %al
movb %al, -0x378(%rbp)
testb $0x1, -0x378(%rbp)
je 0xc026
movq -0x3a8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x1, %esi
callq 0x180d0
movq -0x3a8(%rbp), %rdi
andb $0x1, %al
movb %al, -0x391(%rbp)
movq -0x260(%rbp), %rsi
callq 0x5590
movb $0x0, (%rax)
testb $0x1, -0x391(%rbp)
jne 0xc024
movb $0x1, -0x392(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x392(%rbp), %rdx
callq 0xec80
jmp 0xc08c
jmp 0xc03c
movq -0x3a8(%rbp), %rdi
movq -0x260(%rbp), %rsi
callq 0x5590
movb $0x0, (%rax)
jmp 0xc03e
leaq -0x248(%rbp), %rdi
callq 0x55c0
jmp 0xbd9a
jmp 0xc051
leaq -0x218(%rbp), %rdi
callq 0x55c0
jmp 0xbcf5
jmp 0xc064
movl $0x0, -0x398(%rbp)
movb $0x0, -0x399(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x398(%rbp), %rsi
leaq -0x399(%rbp), %rdx
callq 0xecc0
movq -0x10(%rbp), %rax
movb -0x8(%rbp), %dl
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
nopl (%rax)