// File: kobanium[P]Ray/src/feature/Nakade.cpp
// Function: CheckRemovedStoneNakade(game_info_t const*, int)
int
CheckRemovedStoneNakade( const game_info_t *game, const int color )
{
  const int capture_num = game->capture_num[GetOppositeColor(color) - 1];
  const int *capture_pos = game->capture_pos[GetOppositeColor(color) - 1];
  unsigned long long hash = 0;
  int reviser;

  // 捕獲した石の数が3個以上6個以下なら確認し
  // それ以外なら何もしないで終了
  if (capture_num > 6 ||
      capture_num < 3) {
    return NOT_NAKADE;
  }

  // 座標の補正項の算出
  reviser = start - capture_pos[0];

  // ハッシュ値の計算
  int pos = capture_pos[0];
  while (pos < CAPTURE_END) {
    hash ^= shape_bit[pos + reviser];
    pos = capture_pos[pos];
  }

  // ナカデになっていれば, その座標を返す
  switch (capture_num) {
    case 3:
    case 4:
    case 5:
      for (int i = 0; i < NAKADE_PATTERNS[capture_num - 3]; i++) {
        if (nakade_hash[capture_num - 3][i] == hash) {
          return capture_pos[0] + nakade_pos[capture_num - 3][i];
        }
      }
      break;
  }

  return NOT_NAKADE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x14(%rbp), %edi
callq 0x25810
movl %eax, %ecx
movq -0x48(%rbp), %rax
subl $0x1, %ecx
movslq %ecx, %rcx
movl 0x98728(%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x98738, %rax          # imm = 0x98738
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %edi
callq 0x25810
movl %eax, %ecx
movq -0x40(%rbp), %rax
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xae0, %rcx, %rcx      # imm = 0xAE0
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
cmpl $0x6, -0x18(%rbp)
jg 0xa4ff9
cmpl $0x3, -0x18(%rbp)
jge 0xa5005
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa50e2
movl 0x42a5d(%rip), %eax     # 0xe7a68
movq -0x20(%rbp), %rcx
subl (%rcx), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x2b7, -0x30(%rbp)     # imm = 0x2B7
jge 0xa5052
movl -0x30(%rbp), %eax
addl -0x2c(%rbp), %eax
movslq %eax, %rcx
leaq 0x1c70078a(%rip), %rax  # 0x1c7a57c0
movq (%rax,%rcx,8), %rax
xorq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
jmp 0xa501d
movl -0x18(%rbp), %eax
addl $-0x3, %eax
subl $0x2, %eax
ja 0xa50db
jmp 0xa505f
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rdx
leaq 0xbd97(%rip), %rcx      # 0xb0e10
cmpl (%rcx,%rdx,4), %eax
jge 0xa50d9
movl -0x18(%rbp), %eax
subl $0x3, %eax
movslq %eax, %rcx
leaq 0x1c702882(%rip), %rax  # 0x1c7a7910
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x28(%rbp), %rax
jne 0xa50cc
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl -0x18(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rdx
leaq 0x1c7027c7(%rip), %rcx  # 0x1c7a7880
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movslq -0x34(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x4(%rbp)
jmp 0xa50e2
jmp 0xa50ce
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xa5066
jmp 0xa50db
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)