// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/feature/Nakade.cpp
// Function: SearchNakade(game_info_t const*, int*, int*)
void
SearchNakade( const game_info_t *game, int *nakade_num, int *nakade_pos )
{
  const int last_color = game->record[game->moves - 1].color;
  const int pos = game->record[game->moves - 1].pos;
  const unsigned int mask[2][4] = {
    {0x0004, 0x0040, 0x0100, 0x1000}, {0x0008, 0x0080, 0x0200, 0x2000},
  };
  const unsigned int all_mask[2] = {
    0x1144, 0x2288
  };
  const int neighbor4[4] = { NORTH(pos), WEST(pos), EAST(pos), SOUTH(pos) };
  const unsigned int pat3 = Pat3(game->pat, pos);

  // ナカデが出現し得ないパターンなら戻る
  if ((nakade_pat3_mask[pat3] & all_mask[last_color - 1]) == 0) return;

  for (int i = 0; i < 4; i++) {
    if ((nakade_pat3_mask[pat3] & mask[last_color - 1][i]) != 0) {
      nakade_pos[(*nakade_num)++] = FindNakadePos(game, neighbor4[i], last_color);
    }
  }
  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r15
movslq 0x43b0(%rdi), %rax
shlq $0x4, %rax
movslq -0x10(%rax,%rdi), %rbx
movl -0xc(%rax,%rdi), %esi
leaq 0x21b6f(%rip), %rax     # 0x618bc
movl (%rax), %eax
movl %esi, %ecx
subl %eax, %ecx
movl %ecx, (%rsp)
movd %esi, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
paddd 0x8139(%rip), %xmm0     # 0x47ea0
movq %xmm0, 0x4(%rsp)
addl %esi, %eax
movl %eax, 0xc(%rsp)
addq $0x4748, %rdi           # imm = 0x4748
callq 0x37bc6
movl %eax, %ecx
leaq 0x1c6e1b28(%rip), %rdx  # 0x1c7218b0
leaq 0x9181(%rip), %rax      # 0x48f10
movl -0x4(%rax,%rbx,4), %eax
movq %rcx, 0x30(%rsp)
testl %eax, (%rdx,%rcx,4)
je 0x3ff9c
movq %rbx, %rax
decq %rax
shlq $0x4, %rax
leaq 0x913e(%rip), %rcx      # 0x48ef0
addq %rax, %rcx
movq %rcx, 0x28(%rsp)
xorl %esi, %esi
cmpq $0x4, %rsi
je 0x3ff9c
movq 0x28(%rsp), %rax
movl (%rax,%rsi,4), %eax
movq 0x30(%rsp), %rcx
leaq 0x1c6e1ad6(%rip), %rdx  # 0x1c7218b0
testl %eax, (%rdx,%rcx,4)
je 0x3ff94
movq %rsi, 0x38(%rsp)
movslq (%rsp,%rsi,4), %r12
xorl %r14d, %r14d
movl $0x349, %edx            # imm = 0x349
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0x61f0
andq $0x0, 0xf8(%rsp)
leaq 0x80(%rsp), %rdi
movl %r12d, %esi
callq 0x40060
movb $0x1, 0x100(%rsp,%r12)
pushq $-0x3
popq %r12
xorl %ebp, %ebp
movslq 0xf8(%rsp), %rax
cmpl 0xfc(%rsp), %eax
je 0x3fecc
leal 0x1(%rax), %ecx
movl %ecx, 0xf8(%rsp)
cmpl $0x1d, %eax
movl $0x0, %edx
cmovgel %edx, %ecx
movl 0x80(%rsp,%rax,4), %esi
movl %ecx, 0xf8(%rsp)
movl %esi, 0x50(%rsp,%r14,4)
cmpl $0x5, %ebp
jg 0x3ff77
incq %r14
leaq 0x40(%rsp), %rdi
callq 0x3b128
xorl %r13d, %r13d
cmpq $0x4, %r13
je 0x3fec4
movslq 0x40(%rsp,%r13,4), %rsi
cmpb $0x0, 0x100(%rsp,%rsi)
jne 0x3febf
movsbl 0x43f8(%r15,%rsi), %eax
testl %eax, %ebx
jne 0x3febf
leaq 0x80(%rsp), %rdi
callq 0x40060
movslq 0x40(%rsp,%r13,4), %rax
movb $0x1, 0x100(%rsp,%rax)
incl %ebp
incq %r13
jmp 0x3fe81
incl %r12d
jmp 0x3fe2b
pushq $-0x1
popq %rdx
cmpq $0x5, %r14
leaq 0x1c6e18b6(%rip), %r13  # 0x1c721790
leaq 0x1c6df75f(%rip), %rbp  # 0x1c71f640
ja 0x3ff7a
leaq (%rsp,%r14,4), %rsi
addq $0x50, %rsi
leaq 0x50(%rsp), %rdi
callq 0x4009e
movl 0x219d9(%rip), %ecx     # 0x618d8
movl 0x50(%rsp), %eax
subl %eax, %ecx
movslq %ecx, %rdx
xorl %esi, %esi
xorl %ecx, %ecx
cmpq %rsi, %r14
je 0x3ff23
movslq 0x50(%rsp,%rsi,4), %rdi
addq %rdx, %rdi
xorq (%rbp,%rdi,8), %rcx
incq %rsi
jmp 0x3ff0c
leal -0x3(%r14), %esi
pushq $-0x1
popq %rdx
cmpl $0x2, %esi
ja 0x3ff7a
movl %esi, %edx
leaq 0x7f88(%rip), %rsi      # 0x47ec0
movl (%rsi,%rdx,4), %edx
testl %edx, %edx
movl $0x0, %esi
cmovlel %esi, %edx
movl %r12d, %esi
imulq $0x48, %rsi, %r8
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x3ff77
leaq (%r8,%rdi,8), %r9
incq %rdi
cmpq %rcx, (%r13,%r9)
jne 0x3ff4e
imulq $0x24, %rsi, %rcx
leaq 0x1c6e1794(%rip), %rdx  # 0x1c721700
addq %rdx, %rcx
addl -0x4(%rcx,%rdi,4), %eax
movl %eax, %edx
jmp 0x3ff7a
pushq $-0x1
popq %rdx
movq 0x18(%rsp), %rsi
movslq (%rsi), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rsi)
movq 0x20(%rsp), %rcx
movl %edx, (%rcx,%rax,4)
movq 0x38(%rsp), %rsi
incq %rsi
jmp 0x3fdbc
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq