// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %r15
movslq 0x43b0(%rdi), %rax
shlq $0x4, %rax
movslq -0x10(%rax,%rdi), %rbx
movl -0xc(%rax,%rdi), %esi
leaq 0x1c926(%rip), %rax     # 0x758bc
movl (%rax), %eax
movl %esi, %ecx
subl %eax, %ecx
movl %ecx, 0x10(%rsp)
leal -0x1(%rsi), %ecx
movl %ecx, 0x14(%rsp)
leal 0x1(%rsi), %ecx
movl %ecx, 0x18(%rsp)
addl %esi, %eax
movl %eax, 0x1c(%rsp)
addq $0x4748, %rdi           # imm = 0x4748
callq 0x4f84b
movl %eax, %ecx
leaq 0x1c6dc8e7(%rip), %rdx  # 0x1c7358b0
leaq 0x8e90(%rip), %rax      # 0x61e60
movl -0x4(%rax,%rbx,4), %eax
movq %rcx, 0x38(%rsp)
testl %eax, (%rdx,%rcx,4)
je 0x59252
movq %rbx, %rax
decq %rax
shlq $0x4, %rax
leaq 0x8e4d(%rip), %rcx      # 0x61e40
addq %rax, %rcx
movq %rcx, 0x30(%rsp)
leaq 0x80(%rsp), %r13
leaq 0x1c6dc786(%rip), %r14  # 0x1c735790
xorl %r11d, %r11d
movq 0x30(%rsp), %rax
movl (%rax,%r11,4), %eax
movq 0x38(%rsp), %rcx
leaq 0x1c6dc88e(%rip), %rdx  # 0x1c7358b0
testl %eax, (%rdx,%rcx,4)
je 0x59245
movq %r11, 0x8(%rsp)
movslq 0x10(%rsp,%r11,4), %r12
xorl %ebp, %ebp
movl $0x349, %edx            # imm = 0x349
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
callq 0x6210
movq $0x0, 0xf8(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x59351
movb $0x1, 0x100(%rsp,%r12)
movl 0xf8(%rsp), %eax
cmpl 0xfc(%rsp), %eax
je 0x5911f
xorl %ebp, %ebp
xorl %r12d, %r12d
leal 0x1(%rax), %ecx
movl %ecx, 0xf8(%rsp)
cltq
cmpl $0x1d, %eax
movl $0x0, %edx
cmovgel %edx, %ecx
movl 0x80(%rsp,%rax,4), %esi
movl %ecx, 0xf8(%rsp)
movl %esi, 0x50(%rsp,%rbp,4)
cmpl $0x5, %r12d
jg 0x5919a
incq %rbp
leaq 0x40(%rsp), %rdi
callq 0x53e40
xorl %r14d, %r14d
movslq 0x40(%rsp,%r14,4), %rsi
cmpb $0x0, 0x100(%rsp,%rsi)
jne 0x590fb
movsbl 0x43f8(%r15,%rsi), %eax
testl %eax, %ebx
jne 0x590fb
movq %r13, %rdi
callq 0x59351
movslq 0x40(%rsp,%r14,4), %rax
movb $0x1, 0x100(%rsp,%rax)
incl %r12d
incq %r14
cmpq $0x4, %r14
jne 0x590c7
movl 0xf8(%rsp), %eax
cmpl 0xfc(%rsp), %eax
jne 0x59084
leaq 0x1c6dc671(%rip), %r14  # 0x1c735790
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x5, %ebp
ja 0x591a6
movl %ebp, %r12d
testl %ebp, %ebp
je 0x59166
leaq (%rsp,%r12,4), %r14
addq $0x50, %r14
bsrq %r12, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x593b8
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
leaq 0x1c6dc62f(%rip), %r14  # 0x1c735790
callq 0x59493
movl 0x50(%rsp), %eax
testl %ebp, %ebp
je 0x591b0
movl 0x1c764(%rip), %ecx     # 0x758d8
subl %eax, %ecx
movslq %ecx, %rdx
xorl %esi, %esi
xorl %ecx, %ecx
leaq 0x1c6da4bc(%rip), %r8   # 0x1c733640
movslq 0x50(%rsp,%rsi,4), %rdi
addq %rdx, %rdi
xorq (%r8,%rdi,8), %rcx
incq %rsi
cmpq %rsi, %r12
jne 0x59184
jmp 0x591b2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq 0x1c6dc5ea(%rip), %r14  # 0x1c735790
movq 0x8(%rsp), %r11
jmp 0x59230
xorl %ecx, %ecx
addl $-0x3, %ebp
cmpl $0x2, %ebp
movq 0x8(%rsp), %r11
ja 0x5922b
movl %ebp, %edi
leaq 0x7c58(%rip), %rdx      # 0x60e20
movslq (%rdx,%rdi,4), %rsi
cmpl $0x2, %esi
movl $0x1, %r8d
cmovgel %esi, %r8d
leaq (%rdi,%rdi,8), %rdx
cmpq %rcx, (%r14,%rdx,8)
jne 0x591e9
movb $0x1, %cl
xorl %edi, %edi
jmp 0x59211
shlq $0x3, %rdi
leaq (%rdi,%rdi,8), %r9
movl $0x1, %edi
cmpq %rdi, %r8
je 0x59221
leaq (%r9,%rdi,8), %r10
incq %rdi
cmpq %rcx, (%r14,%r10)
jne 0x591f6
decq %rdi
cmpq %rsi, %rdi
setl %cl
leaq 0x1c6dc4e8(%rip), %rsi  # 0x1c735700
leaq (%rsi,%rdx,4), %rdx
addl (%rdx,%rdi,4), %eax
jmp 0x59227
cmpq %rsi, %rdi
setl %cl
testb %cl, %cl
jne 0x59230
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x20(%rsp), %rsi
movslq (%rsi), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movq 0x28(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incq %r11
cmpq $0x4, %r11
jne 0x5900d
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq