// File: 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
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movb %sil, %al
movq %rdi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x18(%rbp), %rsi
movq %rsi, -0x358(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x126b0
movzbl -0x19(%rbp), %eax
cmpl $0x1, %eax
jne 0xb487
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x12a70
movq %rax, -0x360(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x12a70
movq -0x360(%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 0xb15c
jmp 0xb482
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, -0x368(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x12a70
movq -0x368(%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 0xb1f2
jmp 0xb472
leaq -0x98(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x3100
movq -0x358(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
callq 0x5590
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xb23f
jmp 0xb461
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 0xb37e
movq -0x358(%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 0xb2bc
jmp 0xb2c8
movb $0x1, -0xb1(%rbp)
jmp 0xb37e
movq -0x358(%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 0xb279
testb $0x1, -0xb1(%rbp)
jne 0xb3a5
movq -0xc0(%rbp), %rax
addq -0xc8(%rbp), %rax
cmpq $0x2, %rax
jae 0xb3a5
cmpq $0x2, -0xd0(%rbp)
jb 0xb3aa
jmp 0xb461
cmpq $0x0, -0xc0(%rbp)
jbe 0xb3d7
movb $0x1, -0x1c9(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1c9(%rbp), %rdx
callq 0xec80
jmp 0xb848
cmpq $0x1, -0xc8(%rbp)
jne 0xb45f
movq -0x358(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x5590
movq -0x358(%rbp), %rdi
movb $0x1, (%rax)
movq -0xd8(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x15300
movq -0x358(%rbp), %rdi
andb $0x1, %al
movb %al, -0x1ca(%rbp)
movq -0xb0(%rbp), %rsi
callq 0x5590
movb $0x0, (%rax)
testb $0x1, -0x1ca(%rbp)
je 0xb45d
movb $0x1, -0x1cb(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1cb(%rbp), %rdx
callq 0xec80
jmp 0xb848
jmp 0xb461
jmp 0xb461
leaq -0x98(%rbp), %rdi
callq 0x55c0
jmp 0xb1d6
jmp 0xb474
leaq -0x68(%rbp), %rdi
callq 0x55c0
jmp 0xb146
jmp 0xb820
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x12a70
movq %rax, -0x370(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x12a70
movq -0x370(%rbp), %rdi
movq %rax, %rsi
callq 0xec40
movq %rax, -0x1e8(%rbp)
movq %rdx, -0x1e0(%rbp)
leaq -0x1e8(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x54e0
movq %rax, -0x1f0(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x5510
movq %rax, -0x1f8(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x5550
testb $0x1, %al
jne 0xb517
jmp 0xb81e
leaq -0x1f0(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0x200(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12a70
movq %rax, -0x378(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x12a70
movq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0xec40
movq %rax, -0x218(%rbp)
movq %rdx, -0x210(%rbp)
leaq -0x218(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rdi
callq 0x54e0
movq %rax, -0x220(%rbp)
movq -0x208(%rbp), %rdi
callq 0x5510
movq %rax, -0x228(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x5550
testb $0x1, %al
jne 0xb5bc
jmp 0xb80b
leaq -0x220(%rbp), %rdi
callq 0x5580
movq (%rax), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
movq -0x200(%rbp), %rsi
callq 0x3100
movq -0x358(%rbp), %rdi
movq %rax, -0x238(%rbp)
movq -0x238(%rbp), %rsi
callq 0x5590
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xb60c
jmp 0xb7fa
movq $0xe1, -0x240(%rbp)
movq $0x0, -0x248(%rbp)
movq $0x0, -0x250(%rbp)
movb $0x0, -0x251(%rbp)
movzbl -0x251(%rbp), %eax
cmpl $0x4, %eax
jge 0xb719
movq -0x358(%rbp), %rsi
movq -0x238(%rbp), %rdx
leaq -0x2f8(%rbp), %rdi
movzbl -0x251(%rbp), %ecx
callq 0x159c0
movq -0x358(%rbp), %rsi
movq -0x238(%rbp), %rcx
leaq -0x328(%rbp), %rdi
leaq -0x2f8(%rbp), %rdx
movzbl -0x251(%rbp), %r8d
callq 0x15c00
leaq -0x340(%rbp), %rdi
leaq -0x300(%rbp), %rsi
leaq -0x308(%rbp), %rdx
leaq -0x310(%rbp), %rcx
callq 0x11390
leaq -0x340(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x113d0
movq -0x300(%rbp), %rax
addq -0x248(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x308(%rbp), %rax
addq -0x250(%rbp), %rax
movq %rax, -0x250(%rbp)
cmpq $0x0, -0x308(%rbp)
je 0xb704
movq -0x310(%rbp), %rax
movq %rax, -0x240(%rbp)
jmp 0xb706
movb -0x251(%rbp), %al
addb $0x1, %al
movb %al, -0x251(%rbp)
jmp 0xb634
cmpq $0x0, -0x248(%rbp)
jbe 0xb746
movb $0x1, -0x341(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0x341(%rbp), %rdx
callq 0xec80
jmp 0xb848
cmpq $0x1, -0x250(%rbp)
jbe 0xb773
movb $0x1, -0x342(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0x342(%rbp), %rdx
callq 0xec80
jmp 0xb848
cmpq $0x1, -0x250(%rbp)
jne 0xb7f8
movq -0x358(%rbp), %rdi
movq -0x238(%rbp), %rsi
callq 0x5590
movq -0x358(%rbp), %rdi
movb $0x2, (%rax)
movq -0x240(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x2, %esi
callq 0x15300
movq -0x358(%rbp), %rdi
andb $0x1, %al
movb %al, -0x343(%rbp)
movq -0x238(%rbp), %rsi
callq 0x5590
movb $0x0, (%rax)
testb $0x1, -0x343(%rbp)
je 0xb7f6
movb $0x1, -0x344(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0x344(%rbp), %rdx
callq 0xec80
jmp 0xb848
jmp 0xb7fa
jmp 0xb7fa
leaq -0x220(%rbp), %rdi
callq 0x55c0
jmp 0xb5a0
jmp 0xb80d
leaq -0x1f0(%rbp), %rdi
callq 0x55c0
jmp 0xb4fb
jmp 0xb820
movl $0x0, -0x348(%rbp)
movb $0x0, -0x349(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x348(%rbp), %rsi
leaq -0x349(%rbp), %rdx
callq 0xecc0
movq -0x10(%rbp), %rax
movb -0x8(%rbp), %dl
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
nopl (%rax,%rax)