// File: kobanium[P]Ray/src/feature/Semeai.cpp
// Function: CheckOiotoshi(game_info_t const*, int, int, int)
int
CheckOiotoshi( const game_info_t *game, const int pos, const int color, const int opponent_pos )
{
  const int other = GetOppositeColor(color);
  int num = -1;

  if (!IsLegal(game, pos, color)) {
    return -1;
  }

  std::unique_ptr<search_game_info_t> search_game(new search_game_info_t(game));
  search_game_info_t *oiotoshi_game = search_game.get();
  
  PutStoneForSearch(oiotoshi_game, pos, color);

  const string_t *string = oiotoshi_game->string;
  const int *string_id = oiotoshi_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 -1;
    }
    neighbor = string[id].neighbor[neighbor];
  }

  if (!IsLegalForSearch(oiotoshi_game, string[string_id[opponent_pos]].lib[0], other)) {
    return -1;
  }
  PutStoneForSearch(oiotoshi_game, string[string_id[opponent_pos]].lib[0], other);

  if (string[string_id[opponent_pos]].libs == 1) {
    num = string[string_id[opponent_pos]].size;
  }

  return num;
}

// 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)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x9d0b0
testb $0x1, %al
jne 0xa8039
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa822d
movl $0x69ae40, %edi         # imm = 0x69AE40
callq 0x7550
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rsi
callq 0x98300
jmp 0xa8058
movq -0x70(%rbp), %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0xaa250
movq -0x78(%rbp), %rdi
callq 0xaa280
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x98700
jmp 0xa8087
movq -0x48(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
addq $0x956f0, %rax          # imm = 0x956F0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
movq -0x50(%rbp), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x57c(%rax), %eax
movl %eax, -0x60(%rbp)
cmpl $0x11f, -0x60(%rbp)     # imm = 0x11F
je 0xa8164
movq -0x50(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0xa813e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x64(%rbp)
jmp 0xa8224
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x69ae40, %esi         # imm = 0x69AE40
callq 0x7560
jmp 0xa8239
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xaa2b0
jmp 0xa8239
movq -0x50(%rbp), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movslq -0x60(%rbp), %rcx
movswl 0x57c(%rax,%rcx,2), %eax
movl %eax, -0x60(%rbp)
jmp 0xa80cd
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movq -0x58(%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, -0x79(%rbp)
jmp 0xa8191
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0xa81aa
jmp 0xa819a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x64(%rbp)
jmp 0xa8224
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movq -0x58(%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 0xa81d4
movq -0x50(%rbp), %rax
movq -0x58(%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 0xa8217
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movl 0x7c0(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xaa2b0
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x79b0
nopw %cs:(%rax,%rax)