// File: kobanium[P]Ray/src/feature/Semeai.cpp
// Function: IsCapturableAtari(game_info_t const*, int, int, int)
bool
IsCapturableAtari( const game_info_t *game, const int pos, const int color, const int opponent_pos )
{
  const int other = GetOppositeColor(color);

  if (!IsLegal(game, pos, color)) {
    return false;
  }

  std::unique_ptr<search_game_info_t> search_game(new search_game_info_t(game));
  search_game_info_t *capturable_game = search_game.get();

  // とりあえず石を置く
  PutStoneForSearch(capturable_game, pos, color);

  const string_t *string = capturable_game->string;
  const int *string_id = capturable_game->string_id;
  const int id = string_id[opponent_pos];

  // 周囲に取り返せる石があれば安全
  int neighbor = string[id].neighbor[0];
  while (neighbor != NEIGHBOR_END) {
    if (string[neighbor].libs == 1) {
      return false;
    }
    neighbor = string[id].neighbor[neighbor];
  }

  if (!IsLegalForSearch(capturable_game, string[string_id[opponent_pos]].lib[0], other)) {
    return true;
  }
  // 逃げるつもりでダメに打つ
  PutStoneForSearch(capturable_game, string[string_id[opponent_pos]].lib[0], other);

  // 逃げても呼吸点が1つなら捕獲可能と判定
  if (string[string_id[opponent_pos]].libs == 1) {
    return true;
  } else {
    return false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl -0x18(%rbp), %edi
callq 0x25810
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x9d0b0
testb $0x1, %al
jne 0xa7dff
movb $0x0, -0x1(%rbp)
jmp 0xa7fd5
movl $0x69ae40, %edi         # imm = 0x69AE40
callq 0x7550
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rsi
callq 0x98300
jmp 0xa7e1e
movq -0x68(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0xaa250
movq -0x70(%rbp), %rdi
callq 0xaa280
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x98700
jmp 0xa7e4d
movq -0x40(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addq $0x956f0, %rax          # imm = 0x956F0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x58(%rbp)
cmpl $0x11f, -0x58(%rbp)     # imm = 0x11F
je 0xa7f27
movq -0x48(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa7f01
movb $0x0, -0x1(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0xa7fcc
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x69ae40, %esi         # imm = 0x69AE40
callq 0x7560
jmp 0xa7fe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xaa2b0
jmp 0xa7fe3
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x58(%rbp)
jmp 0xa7e93
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movswl 0x8(%rax,%rcx), %esi
movl -0x20(%rbp), %edx
callq 0x98540
movb %al, -0x71(%rbp)
jmp 0xa7f54
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0xa7f6a
jmp 0xa7f5d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0xa7fcc
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
movswl 0x8(%rax,%rcx), %esi
movl -0x20(%rbp), %edx
callq 0x98700
jmp 0xa7f94
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa7fc1
movb $0x1, -0x1(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0xa7fcc
movb $0x0, -0x1(%rbp)
movl $0x1, -0x5c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xaa2b0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x79b0
nopl (%rax)