// File: /workspace/github_cpp_makefile_star2_O3/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 $0x468, %rsp            # imm = 0x468
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r15
movslq 0x43b0(%rdi), %rax
shlq $0x4, %rax
movslq -0x10(%rax,%rdi), %rbx
movl -0xc(%rax,%rdi), %esi
leaq 0x1d038(%rip), %rax     # 0x768bc
movl (%rax), %eax
movl %esi, %ecx
subl %eax, %ecx
movl %ecx, 0x30(%rsp)
movd %esi, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
paddd 0x77f1(%rip), %xmm0     # 0x61090
movq %xmm0, 0x34(%rsp)
addl %esi, %eax
movl %eax, 0x3c(%rsp)
addq $0x4748, %rdi           # imm = 0x4748
callq 0x4fc2a
movl %eax, %ebp
leaq 0x1c6dcff0(%rip), %rcx  # 0x1c7368b0
leaq 0x8839(%rip), %rax      # 0x62100
movl -0x4(%rax,%rbx,4), %eax
testl %eax, (%rcx,%rbp,4)
je 0x59b50
movq %rbx, %rax
decq %rax
shlq $0x4, %rax
leaq 0x87fb(%rip), %rcx      # 0x620e0
addq %rax, %rcx
movq %rcx, 0x48(%rsp)
xorl %r11d, %r11d
movq %r14, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
movq 0x48(%rsp), %rax
movl (%rax,%r11,4), %eax
leaq 0x1c6dcfa1(%rip), %rcx  # 0x1c7368b0
testl %eax, (%rcx,%rbp,4)
je 0x59b2b
movq %r11, 0x8(%rsp)
movslq 0x30(%rsp,%r11,4), %r12
movl $0x349, %edx            # imm = 0x349
leaq 0x110(%rsp), %rdi
xorl %esi, %esi
callq 0x6200
movq $0x0, 0x108(%rsp)
leaq 0x90(%rsp), %rdi
movl %r12d, %esi
callq 0x59c31
movb $0x1, 0x110(%rsp,%r12)
movl 0x108(%rsp), %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl 0x10c(%rsp), %eax
jne 0x5997a
movq 0x8(%rsp), %r11
jmp 0x59b1c
xorl %ecx, %ecx
movl $0xfffffffd, %r12d      # imm = 0xFFFFFFFD
xorl %r13d, %r13d
movq %rcx, %rbp
leal 0x1(%rax), %ecx
movl %ecx, 0x108(%rsp)
cltq
cmpl $0x1d, %eax
movl $0x0, %edx
cmovgel %edx, %ecx
movl 0x90(%rsp,%rax,4), %esi
movl %ecx, 0x108(%rsp)
movl %esi, 0x60(%rsp,%rbp,4)
cmpl $0x5, %r13d
jg 0x59b03
leaq 0x1(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x54386
xorl %r14d, %r14d
movslq 0x50(%rsp,%r14,4), %rsi
cmpb $0x0, 0x110(%rsp,%rsi)
jne 0x59a0a
movsbl 0x43f8(%r15,%rsi), %eax
testl %eax, %ebx
jne 0x59a0a
leaq 0x90(%rsp), %rdi
callq 0x59c31
movslq 0x50(%rsp,%r14,4), %rax
movb $0x1, 0x110(%rsp,%rax)
incl %r13d
incq %r14
cmpq $0x4, %r14
jne 0x599d1
movl 0x108(%rsp), %eax
incl %r12d
cmpl 0x10c(%rsp), %eax
movq 0x28(%rsp), %rcx
jne 0x59985
cmpq $0x4, %rbp
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
ja 0x59b0d
leaq (%rsp,%rcx,4), %rsi
addq $0x60, %rsi
movq %rsi, 0x40(%rsp)
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq 0x60(%rsp), %rdi
callq 0x59c99
leaq 0x60(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x59d74
movl 0x1ce5c(%rip), %ecx     # 0x768d8
movl 0x60(%rsp), %eax
subl %eax, %ecx
movq $-0x1, %rdx
movslq %ecx, %rsi
xorl %ecx, %ecx
leaq 0x1c6dabab(%rip), %r8   # 0x1c734640
movslq 0x64(%rsp,%rdx,4), %rdi
addq %rsi, %rdi
xorq (%r8,%rdi,8), %rcx
incq %rdx
cmpq %rdx, %rbp
jne 0x59a95
movq 0x28(%rsp), %rdx
addl $-0x3, %edx
cmpl $0x2, %edx
movq 0x10(%rsp), %rbp
ja 0x59b12
movl %edx, %edx
leaq 0x75fc(%rip), %rsi      # 0x610c0
movl (%rsi,%rdx,4), %edx
cmpl $0x2, %edx
movl $0x1, %esi
cmovll %esi, %edx
movl %r12d, %esi
leaq (,%rsi,8), %rdi
leaq (%rdi,%rdi,8), %r8
xorl %edi, %edi
movq 0x8(%rsp), %r11
leaq (%r8,%rdi,8), %r9
leaq 0x1c6dcc9d(%rip), %r10  # 0x1c736790
cmpq %rcx, (%r10,%r9)
je 0x59b3a
incq %rdi
cmpq %rdi, %rdx
jne 0x59ae8
jmp 0x59b17
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r11
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movslq (%r13), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r13)
movl %edx, (%r14,%rax,4)
incq %r11
cmpq $0x4, %r11
jne 0x598ff
jmp 0x59b50
leaq (%rsi,%rsi,8), %rcx
leaq 0x1c6dcbbb(%rip), %rdx  # 0x1c736700
leaq (%rdx,%rcx,4), %rcx
addl (%rcx,%rdi,4), %eax
movl %eax, %edx
jmp 0x59b1c
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq