// File: /workspace/github_cpp_makefile_star2_O3/YSRKEN[P]Shioi/I401/main.cpp
// Function: Board::CountRenW2(std::array<std::array<PackedStone, 5ul>, 2ul> const&, unsigned long, Direction)
RenCount CountRenW2(const Pattern &pattern, const size_t position, const Direction dir) {
		/* Count "Straight Shi-Shi"
		* 1. BO|BBB|OB   "Ryoutou-no-ShiShi"
		* 2. BBO|BB|OBB  "Chouda-no-ShiShi"
		* 3. BBBO|B|OBBB "Souryu-no-ShiShi"
		* 一直線上に出来る四々で、両頭の四々・長蛇の四々・双龍の四々
		*/
		namespace p = packed_stone;
		{
			//BO|BBB|OB
			if (MatchPatternW(pattern, position, dir, {{ p::nw, p::wwnw }})) return RenCount(0, 2, 0);
			if (MatchPatternW(pattern, position, dir, {{ p::wnw, p::wnw }})) return RenCount(0, 2, 0);
			if (MatchPatternW(pattern, position, dir, {{ p::wwnw, p::nw }})) return RenCount(0, 2, 0);
			//BBO|BB|OBB
			if (MatchPatternW(pattern, position, dir, {{ p::nww, p::wnww }})) return RenCount(0, 2, 0);
			if (MatchPatternW(pattern, position, dir, {{ p::wnww, p::nww }})) return RenCount(0, 2, 0);
			//BBBO|B|OBBB
			if (MatchPatternW(pattern, position, dir, {{ p::nwww, p::nwww }})) return RenCount(0, 2, 0);
		}
		// Count Shi-ren
		{
			if (MatchPatternW(pattern, position, dir, {{ p::n, p::wwwn }})) return RenCount(1, 0, 0);
			if (MatchPatternW(pattern, position, dir, {{ p::wn, p::wwn }})) return RenCount(1, 0, 0);
			if (MatchPatternW(pattern, position, dir, {{ p::wwwn, p::n }})) return RenCount(1, 0, 0);
			if (MatchPatternW(pattern, position, dir, {{ p::wwn, p::wn }})) return RenCount(1, 0, 0);
		}
		// Count Katsu-Shi
		{
			auto GetPosition = [&position, &dir](int count) -> int {return position + kPositionoffset[dir] * count; };
			//11110
			if (MatchPatternW(pattern, position, dir, {{ p::www, p::n }})) {
				return RenCount(0, 1, GetPosition(1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::ww, p::wn }})) {
				return RenCount(0, 1, GetPosition(2) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::w, p::wwn }})) {
				return RenCount(0, 1, GetPosition(3) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, Side::Right, p::wwwn)) {
				return RenCount(0, 1, GetPosition(4) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			//11101
			if (MatchPatternW(pattern, position, dir, Side::Left, p::nwww)) {
				return RenCount(0, 1, GetPosition(-1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::ww, p::nw }})) {
				return RenCount(0, 1, GetPosition(1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::w, p::wnw }})) {
				return RenCount(0, 1, GetPosition(2) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, Side::Right, p::wwnw)) {
				return RenCount(0, 1, GetPosition(3) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			//11011
			if (MatchPatternW(pattern, position, dir, Side::Left, p::wnww)) {
				return RenCount(0, 1, GetPosition(-2) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::nww, p::w }})) {
				return RenCount(0, 1, GetPosition(-1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, Side::Right, p::wnww)) {
				return RenCount(0, 1, GetPosition(2) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::w, p::nww }})) {
				return RenCount(0, 1, GetPosition(1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			//10111
			if (MatchPatternW(pattern, position, dir, Side::Right, p::nwww)) {
				return RenCount(0, 1, GetPosition(1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::nw, p::ww }})) {
				return RenCount(0, 1, GetPosition(-1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::wnw, p::w }})) {
				return RenCount(0, 1, GetPosition(-2) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, Side::Left, p::wwnw)) {
				return RenCount(0, 1, GetPosition(-3) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			//01111
			if (MatchPatternW(pattern, position, dir, {{ p::n, p::www }})) {
				return RenCount(0, 1, GetPosition(-1) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::wn, p::ww }})) {
				return RenCount(0, 1, GetPosition(-2) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, {{ p::wwn, p::w }})) {
				return RenCount(0, 1, GetPosition(-3) | limit2(0_sz, kBoardSize * kBoardSize));
			}
			if (MatchPatternW(pattern, position, dir, Side::Left, p::wwwn)) {
				return RenCount(0, 1, GetPosition(-4) | limit2(0_sz, kBoardSize * kBoardSize));
			}
		}
		return RenCount(0, 0, 0);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movl $0x2, %eax
leaq 0x8(%rsp), %r8
movq %rax, (%r8)
movq %rax, 0x8(%r8)
movq $0xa2, 0x10(%r8)
movq $0x4, 0x18(%r8)
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movl %ebp, %ecx
callq 0x8f22
testb %al, %al
jne 0x88c2
movl $0x22, %eax
leaq 0x8(%rsp), %r8
movq %rax, (%r8)
movl $0x3, %ecx
movq %rcx, 0x8(%r8)
movq %rax, 0x10(%r8)
movq %rcx, 0x18(%r8)
movzbl %bpl, %r15d
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x88c2
leaq 0x8(%rsp), %r8
movq $0xa2, (%r8)
movq $0x4, 0x8(%r8)
movl $0x2, %eax
movq %rax, 0x10(%r8)
movq %rax, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x88c2
leaq 0x8(%rsp), %r8
movq $0xa, (%r8)
movq $0x3, 0x8(%r8)
movq $0x8a, 0x10(%r8)
movq $0x4, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x88c2
leaq 0x8(%rsp), %r8
movq $0x8a, (%r8)
movq $0x4, 0x8(%r8)
movq $0xa, 0x10(%r8)
movq $0x3, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x88c2
movl $0x2a, %eax
leaq 0x8(%rsp), %r8
movq %rax, (%r8)
movl $0x4, %ecx
movq %rcx, 0x8(%r8)
movq %rax, 0x10(%r8)
movq %rcx, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
je 0x88e5
xorl %eax, %eax
movq %rax, (%rbx)
movq $0x2, 0x8(%rbx)
movq %rax, 0x10(%rbx)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %r8
movq $0x0, (%r8)
movq $0x1, 0x8(%r8)
movq $0xa8, 0x10(%r8)
movq $0x4, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x89cd
leaq 0x8(%rsp), %r8
movq $0x8, (%r8)
movq $0x2, 0x8(%r8)
movq $0x28, 0x10(%r8)
movq $0x3, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x89cd
leaq 0x8(%rsp), %r8
movq $0xa8, (%r8)
movq $0x4, 0x8(%r8)
movq $0x0, 0x10(%r8)
movq $0x1, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x89cd
leaq 0x8(%rsp), %r8
movq $0x28, (%r8)
movq $0x3, 0x8(%r8)
movq $0x8, 0x10(%r8)
movq $0x2, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
je 0x89e0
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x1, 0x10(%rbx)
jmp 0x88d3
leaq 0x8(%rsp), %r8
movq $0x2a, (%r8)
movq $0x3, 0x8(%r8)
movq $0x0, 0x10(%r8)
movq $0x1, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
je 0x8a54
leaq 0x29e0(%rip), %rax      # 0xb400
addq (%rax,%r15,8), %r14
movl %r14d, %eax
movl $0xe1, %ecx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
xorl %edx, %edx
testl %r14d, %r14d
cmoveq %rdx, %rax
cmovsq %rcx, %rax
movq %rax, (%rbx)
movq $0x1, 0x8(%rbx)
movq %rdx, 0x10(%rbx)
jmp 0x88d3
leaq 0x8(%rsp), %r8
movq $0xa, (%r8)
movl $0x2, %eax
movq %rax, 0x8(%r8)
movq $0x8, 0x10(%r8)
movq %rax, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
je 0x8a9b
leaq 0x296f(%rip), %rax      # 0xb400
movq (%rax,%r15,8), %rax
leaq (%r14,%rax,2), %rax
jmp 0x8ae6
leaq 0x8(%rsp), %r8
movq $0x2, (%r8)
movq $0x1, 0x8(%r8)
movq $0x28, 0x10(%r8)
movq $0x3, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
je 0x8b14
leaq 0x2925(%rip), %rax      # 0xb400
movq (%rax,%r15,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movl %eax, %ecx
movl $0xe1, %edx
cmpq %rdx, %rcx
cmovaeq %rdx, %rcx
xorl %esi, %esi
testl %eax, %eax
cmoveq %rsi, %rcx
cmovsq %rdx, %rcx
movq %rcx, (%rbx)
movq $0x1, 0x8(%rbx)
movq %rsi, 0x10(%rbx)
jmp 0x88d3
movq %r14, %rax
shlq $0x6, %rax
addq %r13, %rax
movl %r15d, %ecx
shll $0x4, %ecx
cmpq $0x4, 0xf0(%rcx,%rax)
jae 0x8dbc
leaq (%rcx,%rax), %rbp
addq $0xe8, %rbp
cmpq $0x4, (%rbp)
jae 0x8df1
leaq 0x8(%rsp), %r8
movq $0xa, (%r8)
movl $0x2, %eax
movq %rax, 0x8(%r8)
movq %rax, 0x10(%r8)
movq %rax, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8a19
leaq 0x8(%rsp), %r8
movq $0x2, (%r8)
movq $0x1, 0x8(%r8)
movq $0x22, 0x10(%r8)
movq $0x3, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8a8a
cmpq $0x4, 0x8(%rbp)
jae 0x8e43
cmpq $0x4, (%rbp)
jae 0x8e69
leaq 0x8(%rsp), %r8
movq $0xa, (%r8)
movq $0x3, 0x8(%r8)
movq $0x2, 0x10(%r8)
movq $0x1, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8e09
cmpq $0x4, 0x8(%rbp)
jae 0x8e9a
leaq 0x8(%rsp), %r8
movq $0x2, (%r8)
movq $0x1, 0x8(%r8)
movq $0xa, 0x10(%r8)
movq $0x3, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8a19
cmpq $0x4, 0x8(%rbp)
jae 0x8ec0
movl $0x2, %eax
leaq 0x8(%rsp), %r8
movq %rax, (%r8)
movq %rax, 0x8(%r8)
movq $0xa, 0x10(%r8)
movq %rax, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8e09
leaq 0x8(%rsp), %r8
movq $0x22, (%r8)
movq $0x3, 0x8(%r8)
movq $0x2, 0x10(%r8)
movq $0x1, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8e84
cmpq $0x4, (%rbp)
jb 0x8cf3
cmpq $0x4, 0x38(%r12)
jne 0x8cf3
cmpq $0xa2, 0x30(%r12)
je 0x8da7
leaq 0x8(%rsp), %r8
movq $0x0, (%r8)
movq $0x1, 0x8(%r8)
movq $0x2a, 0x10(%r8)
movq $0x3, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8e09
leaq 0x8(%rsp), %r8
movq $0x8, (%r8)
movl $0x2, %eax
movq %rax, 0x8(%r8)
movq $0xa, 0x10(%r8)
movq %rax, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
jne 0x8e84
leaq 0x8(%rsp), %r8
movq $0x28, (%r8)
movq $0x3, 0x8(%r8)
movq $0x2, 0x10(%r8)
movq $0x1, 0x18(%r8)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x8f22
testb %al, %al
je 0x8ee3
leaq 0x2652(%rip), %rax      # 0xb400
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addq $-0x2, %rcx
jmp 0x8e93
cmpq $0x4, 0x88(%r12)
jne 0x8b33
cmpq $0xa8, 0x80(%r12)
jne 0x8b33
leaq 0x261c(%rip), %rax      # 0xb400
movq (%rax,%r15,8), %rax
leaq (%r14,%rax,4), %rax
jmp 0x8ae6
cmpq $0x4, 0x38(%r12)
jne 0x8b49
cmpq $0x2a, 0x30(%r12)
jne 0x8b49
leaq 0x25f0(%rip), %rax      # 0xb400
movq (%rax,%r15,8), %rax
movq %rax, %rcx
shlq $0x20, %rcx
subq %rax, %rcx
addq %r14, %rcx
movl %ecx, %eax
movl $0xe1, %edx
cmpq %rdx, %rax
cmovaeq %rdx, %rax
xorl %esi, %esi
testl %ecx, %ecx
cmoveq %rsi, %rax
cmovsq %rdx, %rax
movq %rax, (%rbx)
jmp 0x8b03
cmpq $0x4, 0x88(%r12)
jne 0x8bc7
cmpq $0xa2, 0x80(%r12)
je 0x8ad4
jmp 0x8bc7
cmpq $0x4, 0x38(%r12)
jne 0x8bd2
cmpq $0x8a, 0x30(%r12)
jne 0x8bd2
leaq 0x2575(%rip), %rax      # 0xb400
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
decq %rcx
imulq (%rax,%r15,8), %rcx
jmp 0x8e1e
cmpq $0x4, 0x88(%r12)
jne 0x8c1a
cmpq $0x8a, 0x80(%r12)
je 0x8a8a
jmp 0x8c1a
cmpq $0x4, 0x88(%r12)
jne 0x8c62
cmpq $0x2a, 0x80(%r12)
je 0x8a19
jmp 0x8c62
cmpq $0x4, (%rbp)
jb 0x8f0f
cmpq $0x4, 0x38(%r12)
jne 0x8f0f
cmpq $0xa8, 0x30(%r12)
jne 0x8f0f
leaq 0x24fc(%rip), %rax      # 0xb400
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addq $-0x3, %rcx
jmp 0x8e93
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
jmp 0x88d3