// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdx, 0x60(%rsp)
movl %esi, %ebx
movq %rdi, %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x38(%rsp)
callq 0x7f28
movq 0x8(%r14), %r12
movq 0x18(%r14), %r13
cmpq %r13, %r12
sete %al
cmpl $0x1, %ebx
movq %r13, 0x40(%rsp)
jne 0x51f0
cmpq %r13, %r12
jne 0x53ad
jmp 0x55e6
cmpq %r13, %r12
je 0x55e6
movq 0x38(%rsp), %rdi
movq 0x88(%rsp), %rdx
movq 0x98(%rsp), %rsi
movl $0xb, %ecx
cmpq %rsi, %rdx
je 0x538c
movb %al, 0xf(%rsp)
leaq (%r12,%r12,4), %rax
leaq (%rax,%rax,2), %r8
movq %r12, 0x30(%rsp)
movq %rsi, 0x18(%rsp)
movq %r8, 0x10(%rsp)
leaq (%rdx,%r8), %r9
movl $0xc, %eax
cmpb $0x0, (%rdi,%r9)
jne 0x536f
movq %r9, 0x20(%rsp)
movq %rdx, 0x48(%rsp)
movl $0xe1, %eax
movq %rax, 0x50(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
movzbl %r12b, %ebx
leaq 0xa8(%rsp), %rdi
movq 0x38(%rsp), %r14
movq %r14, %rsi
movq 0x20(%rsp), %r15
movq %r15, %rdx
movl %ebx, %ecx
callq 0x902a
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
leaq 0xa8(%rsp), %rdx
movq %r15, %rcx
movl %ebx, %r8d
callq 0x916c
movq 0x78(%rsp), %rax
testq %rax, %rax
je 0x52b9
movq 0x70(%rsp), %rcx
movq %rcx, 0x50(%rsp)
addq 0x80(%rsp), %rbp
addq %rax, %r13
incb %r12b
cmpb $0x4, %r12b
jne 0x5267
testq %rbp, %rbp
setne %al
cmpq $0x2, %r13
setae %cl
orb %al, %cl
movl $0x1, %eax
je 0x52fe
movq 0x20(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rdi
jmp 0x535b
xorl %eax, %eax
cmpq $0x1, %r13
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %r14
jne 0x535b
movb $0x2, (%rdi,%r14)
movl $0x2, %esi
movq 0x50(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq %rdi, %rbx
callq 0x8c2e
movq %rbx, %rdi
testb %al, %al
movq 0x28(%rsp), %rax
cmovneq %r14, %rax
movq %rax, 0x28(%rsp)
movb $0x0, (%rbx,%r14)
movl $0xc, %eax
movl $0x1, %ecx
cmovnel %ecx, %eax
movl $0xb, %ecx
movq 0x48(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %r8
cmpl $0xc, %eax
je 0x5378
testl %eax, %eax
jne 0x5386
incq %rdx
cmpq %rsi, %rdx
jne 0x5237
jmp 0x5388
movl %eax, %ecx
movb 0xf(%rsp), %al
cmpl $0xb, %ecx
je 0x5399
testl %ecx, %ecx
jne 0x55e6
incq %r12
cmpq %r13, %r12
sete %al
jne 0x51fe
jmp 0x55e6
leaq 0xa8(%rsp), %rbx
movq 0x38(%rsp), %rsi
movb %al, 0xf(%rsp)
movq 0x88(%rsp), %rbp
movq 0x98(%rsp), %rcx
movb $0x1, %al
cmpq %rcx, %rbp
je 0x55cd
leaq (%r12,%r12,4), %rax
leaq (%rax,%rax,2), %rdx
movq %r12, 0x30(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x58(%rsp)
leaq (%rdx,%rbp), %r14
movl $0x5, %eax
cmpb $0x0, (%rsi,%r14)
jne 0x55ae
movq %rbp, 0x18(%rsp)
movq $0xe1, 0x68(%rsp)
movq $0x0, 0x48(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq $0x0, 0x50(%rsp)
xorl %r12d, %r12d
movzbl %r12b, %r13d
movq %rbx, %rdi
movq %r14, %rdx
movl %r13d, %ecx
movq %rsi, %rbp
callq 0x6f68
movq %rbx, %rdi
callq 0x70a3
movq %rbx, %rdx
movl %eax, %ebx
testb %al, %al
je 0x5462
movb $0x1, %al
movq %rax, 0x48(%rsp)
jmp 0x54a0
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rcx
movl %r13d, %r8d
leaq 0x68(%rsp), %r9
callq 0x7fea
addq 0x80(%rsp), %r15
movq 0x20(%rsp), %rax
addq 0x78(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rax
addq 0x70(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpb $0x3, %r12b
leal 0x1(%r12), %eax
setb %cl
xorb $0x1, %bl
movl %eax, %r12d
testb %bl, %cl
leaq 0xa8(%rsp), %rbx
movq 0x38(%rsp), %rsi
jne 0x5433
movl $0x5, %eax
testb $0x1, 0x48(%rsp)
je 0x54f1
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %r13
movq 0x18(%rsp), %rbp
movq 0x10(%rsp), %rcx
movq 0x58(%rsp), %rdx
jmp 0x55ae
movq 0x20(%rsp), %rcx
addq %r15, %rcx
cmpq $0x1, %rcx
movq 0x58(%rsp), %rdx
ja 0x5542
cmpq $0x1, 0x50(%rsp)
movq 0x10(%rsp), %rcx
ja 0x5531
movl $0x1, %eax
testq %r15, %r15
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %r13
movq 0x18(%rsp), %rbp
je 0x5558
movq %r14, 0x28(%rsp)
jmp 0x55ae
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %r13
movq 0x18(%rsp), %rbp
jmp 0x55ae
movq 0x30(%rsp), %r12
movq 0x40(%rsp), %r13
movq 0x18(%rsp), %rbp
movq 0x10(%rsp), %rcx
jmp 0x55ae
xorl %eax, %eax
cmpq $0x1, 0x20(%rsp)
jne 0x55ae
movb $0x1, (%rsi,%r14)
movq 0x68(%rsp), %rdx
movq %rsi, %rdi
movl $0x1, %esi
movq 0x60(%rsp), %rcx
callq 0x8c2e
movq 0x38(%rsp), %rsi
movq 0x58(%rsp), %rdx
testb %al, %al
movq 0x28(%rsp), %rcx
cmovneq %r14, %rcx
movq %rcx, 0x28(%rsp)
movq 0x10(%rsp), %rcx
movb $0x0, (%rsi,%r14)
xorb $0x1, %al
movzbl %al, %eax
leal 0x1(,%rax,4), %eax
cmpl $0x5, %eax
je 0x55b7
testl %eax, %eax
jne 0x55c8
incq %rbp
cmpq %rcx, %rbp
jne 0x53f0
movl $0x4, %eax
testb $0x3, %al
sete %al
testb %al, %al
je 0x55e2
incq %r12
cmpq %r13, %r12
sete %al
jne 0x53ba
jmp 0x55e6
movb 0xf(%rsp), %al
movb $0x1, %dl
testb $0x1, %al
movq 0x28(%rsp), %rax
je 0x55f5
xorl %eax, %eax
xorl %edx, %edx
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop