// File: kobanium[P]Ray/src/feature/Semeai.cpp
// Function: IsCapturableAtariForSimulation(game_info_t const*, int, int, int)
bool
IsCapturableAtariForSimulation( const game_info_t *game, const int pos, const int color, const int id )
{
  const char *board = game->board;
  const string_t *string = game->string;
  const int *string_id = game->string_id;
  const int other = GetOppositeColor(color);
  int lib;
  bool neighbor = false;
  int index_distance;
  int pat3;
  int empty;
  int connect_libs = 0;
  int tmp_id;

  lib = string[id].lib[0];

  if (lib == pos) {
    lib = string[id].lib[lib];
  }

  index_distance = lib - pos;

  // 詰める方とは逆のダメの周囲の空点数を調べる
  pat3 = Pat3(game->pat, lib);
  empty = nb4_empty[pat3];

  // 逆のダメの周囲の空点数が3なら取れないのでfalse
  if (empty == 3) {
    return false;
  }

  if (index_distance ==           1) neighbor = true;
  if (index_distance ==          -1) neighbor = true;
  if (index_distance ==  board_size) neighbor = true;
  if (index_distance == -board_size) neighbor = true;

  // ダメが隣り合っている時と
  // ダメが離れている時の分岐
  if (( neighbor && empty >= 3) ||
      (!neighbor && empty >= 2)) {
    return false;
  }

  // 隣接する連がlib以外に持つ呼吸点の合計数が
  // 2以上なら無条件で1手で取れるアタリではないのでfalse

  // 上の確認
  if (board[NORTH(lib)] == other && 
      string_id[NORTH(lib)] != id) {
    tmp_id = string_id[NORTH(lib)];
    if (string[tmp_id].libs > 2) {
      return false;
    } else {
      connect_libs += string[tmp_id].libs - 1;
    }
  } 

  // 左の確認
  if (board[WEST(lib)] == other && 
      string_id[WEST(lib)] != id) {
    tmp_id = string_id[WEST(lib)];
    if (string[tmp_id].libs > 2) {
      return false;
    } else {
      connect_libs += string[tmp_id].libs - 1;
    }
  }

  // 右の確認
  if (board[EAST(lib)] == other && 
      string_id[EAST(lib)] != id) {
    tmp_id = string_id[EAST(lib)];
    if (string[tmp_id].libs > 2) {
      return false;
    } else {
      connect_libs += string[tmp_id].libs - 1;
    }
  }

  // 下の確認
  if (board[SOUTH(lib)] == other && 
      string_id[SOUTH(lib)] != id) {
    tmp_id = string_id[SOUTH(lib)];
    if (string[tmp_id].libs > 2) {
      return false;
    } else {
      connect_libs += string[tmp_id].libs - 1;
    }
  }

  // ダメに打っても増える呼吸点数が1以下なら
  // 1手で取れるアタリ
  if (( neighbor && connect_libs < 2) ||
      (!neighbor && connect_libs < 1)) {
    return true;
  } else {
    return false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x38(%rbp)
movl -0x18(%rbp), %edi
callq 0x25810
movl %eax, -0x3c(%rbp)
movb $0x0, -0x41(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xa8824
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movswl 0x8(%rax,%rcx,2), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x40(%rbp), %esi
callq 0x93d30
movl %eax, -0x4c(%rbp)
movslq -0x4c(%rbp), %rcx
leaq 0x1ab08012(%rip), %rax  # 0x1abb0860
movzbl (%rax,%rcx), %eax
movl %eax, -0x50(%rbp)
cmpl $0x3, -0x50(%rbp)
jne 0xa8864
movb $0x0, -0x1(%rbp)
jmp 0xa8b00
cmpl $0x1, -0x48(%rbp)
jne 0xa886e
movb $0x1, -0x41(%rbp)
cmpl $-0x1, -0x48(%rbp)
jne 0xa8878
movb $0x1, -0x41(%rbp)
movl -0x48(%rbp), %eax
leaq 0x3f1ca(%rip), %rcx     # 0xe7a4c
cmpl (%rcx), %eax
jne 0xa888a
movb $0x1, -0x41(%rbp)
movl -0x48(%rbp), %eax
xorl %ecx, %ecx
leaq 0x3f1b6(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
cmpl %ecx, %eax
jne 0xa88a0
movb $0x1, -0x41(%rbp)
testb $0x1, -0x41(%rbp)
je 0xa88ac
cmpl $0x3, -0x50(%rbp)
jge 0xa88b8
testb $0x1, -0x41(%rbp)
jne 0xa88c1
cmpl $0x2, -0x50(%rbp)
jl 0xa88c1
movb $0x0, -0x1(%rbp)
jmp 0xa8b00
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x3f17d(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa8952
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x3f161(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
je 0xa8952
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x3f146(%rip), %rdx     # 0xe7a4c
subl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa8932
movb $0x0, -0x1(%rbp)
jmp 0xa8b00
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0xa8952
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa89d1
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
je 0xa89d1
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa89b1
movb $0x0, -0x1(%rbp)
jmp 0xa8b00
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0xa89d1
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa8a50
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
je 0xa8a50
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa8a30
movb $0x0, -0x1(%rbp)
jmp 0xa8b00
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0xa8a50
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x3efee(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa8ade
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x3efd2(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
je 0xa8ade
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
leaq 0x3efb7(%rip), %rdx     # 0xe7a4c
addl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jle 0xa8abe
movb $0x0, -0x1(%rbp)
jmp 0xa8b00
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0xa8ade
testb $0x1, -0x41(%rbp)
je 0xa8aea
cmpl $0x2, -0x54(%rbp)
jl 0xa8af6
testb $0x1, -0x41(%rbp)
jne 0xa8afc
cmpl $0x1, -0x54(%rbp)
jge 0xa8afc
movb $0x1, -0x1(%rbp)
jmp 0xa8b00
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)