// File: kobanium[P]Ray/src/board/GoBoard.cpp
// Function: PutStone(game_info_t*, int, int)
void
PutStone( game_info_t *game, const int pos, const int color )
{
  const int *string_id = game->string_id;
  const int other = GetOppositeColor(color);
  char *board = game->board;
  string_t *string = game->string;
  int connection = 0, prisoner = 0;
  int neighbor[4], connect[4] = { 0 };
  int *capture_pos = game->capture_pos[color - 1];

  int tmp = capture_pos[0];
  while (tmp < CAPTURE_END) {
    const int next = capture_pos[tmp];
    capture_pos[tmp] = 0;
    tmp = next;
  }

  // この手番の着手で打ち上げた石の数を0にする
  game->capture_pos[color - 1][0] = CAPTURE_END;
  game->capture_num[color - 1] = 0;
  game->capture_dir[color - 1] = 0;

  // 着手箇所の戦術的特徴を全て消す
  ClearTacticalFeatures(&game->tactical_features[pos * ALL_MAX]);

  game->previous2_hash = game->previous1_hash;
  game->previous1_hash = game->current_hash;

  if (game->ko_move != 0 &&
      game->ko_move == game->moves - 1) {
    game->current_hash ^= hash_bit[game->ko_pos][HASH_KO];
  }

  // 着手箇所と色を記録
  if (game->moves < MAX_RECORDS) {
    game->record[game->moves].color = color;
    game->record[game->moves].pos = pos;
    game->move_hash ^= move_bit[game->moves][pos][color];
  }

  // 着手がパスなら手数を進めて終了
  if (pos == PASS) {
    if (game->moves < MAX_RECORDS) {
      game->record[game->moves].hash = game->positional_hash;
    }
    game->current_hash ^= hash_bit[game->pass_count++][HASH_PASS];
    if (game->pass_count >= BOARD_MAX) { 
      game->pass_count = 0;
    }
    game->moves++;
    return;
  }

  // 石を置く
  board[pos] = static_cast<char>(color);

  // 候補手から除外
  game->candidates[pos] = false;

  game->current_hash ^= hash_bit[pos][color];
  game->positional_hash ^= hash_bit[pos][color];

  // パターンの更新(MD5)
  UpdatePatternStone(game->pat, color, pos);

  // 着手点の上下左右の座標を導出
  GetNeighbor4(neighbor, pos);

  // 着手箇所の上下左右の確認
  // 自分の連があれば, その連の呼吸点を1つ減らし, 接続候補に入れる
  // 敵の連であれば, その連の呼吸点を1つ減らし, 呼吸点が0になったら取り除く
  for (int i = 0; i < 4; i++) {
    if (board[neighbor[i]] == color) {
      RemoveLiberty(game, &string[string_id[neighbor[i]]], pos);
      connect[connection++] = string_id[neighbor[i]];
    } else if (board[neighbor[i]] == other) {
      RemoveLiberty(game, &string[string_id[neighbor[i]]], pos);
      if (string[string_id[neighbor[i]]].libs == 0) {
        prisoner += RemoveString(game, &string[string_id[neighbor[i]]], color);
        game->capture_dir[color - 1]++;
      }
    }
  }

  // 打ち上げた石をアゲハマに追加
  game->prisoner[color] += prisoner;

  // 接続候補がなければ, 新しい連を作成して, 劫かどうかの確認をする
  // 接続候補が1つならば, その連に石を追加する
  // 接続候補が2つ以上ならば, 連同士を繋ぎ合わせて, 石を追加する
  if (connection == 0) {
    MakeString(game, pos, color);
    if (prisoner == 1 &&
        string[string_id[pos]].libs == 1) {
      game->ko_move = game->moves;
      game->ko_pos = string[string_id[pos]].lib[0];
      game->current_hash ^= hash_bit[game->ko_pos][HASH_KO];
    }
  } else if (connection == 1) {
    AddStone(game, pos, color, connect[0]);
  } else {
    ConnectString(game, pos, color, connection, connect);
  }

  // ハッシュ値の記録
  if (game->moves < MAX_RECORDS) {
    game->record[game->moves].hash = game->positional_hash;
  }
  
  // 手数を1つだけ進める
  game->moves++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $0x95720, %rax          # imm = 0x95720
movq %rax, -0x18(%rbp)
movl -0x10(%rbp), %edi
callq 0x25810
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
addq $0x43f8, %rax           # imm = 0x43F8
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $0x9620, %rax           # imm = 0x9620
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x72b0
movq -0x8(%rbp), %rax
addq $0x98738, %rax          # imm = 0x98738
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xae0, %rcx, %rcx      # imm = 0xAE0
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x2b7, -0x6c(%rbp)     # imm = 0x2B7
jge 0x9dc80
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x70(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x9dc52
movq -0x8(%rbp), %rax
addq $0x98738, %rax          # imm = 0x98738
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xae0, %rcx, %rcx      # imm = 0xAE0
addq %rcx, %rax
movl $0x2b7, (%rax)          # imm = 0x2B7
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl $0x0, 0x98728(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl $0x0, 0x98730(%rax,%rcx,4)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0xc(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movq -0x8(%rbp), %rax
movq 0x43d8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x43e0(%rax)
movq -0x8(%rbp), %rax
movq 0x43d0(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x43d8(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x43c8(%rax)
je 0x9dd6f
movq -0x8(%rbp), %rax
movl 0x43c8(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x43b0(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x9dd6f
movq -0x8(%rbp), %rax
movslq 0x43c4(%rax), %rcx
leaq 0x1c70114e(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
xorq 0x43d0(%rax), %rcx
movq %rcx, 0x43d0(%rax)
movq -0x8(%rbp), %rax
cmpl $0x43b, 0x43b0(%rax)    # imm = 0x43B
jge 0x9ddf7
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movslq 0x43b0(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movslq 0x43b0(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movslq 0x43b0(%rax), %rcx
leaq 0x1ab35678(%rip), %rax  # 0x1abd3440
imulq $0x6920, %rcx, %rcx     # imm = 0x6920
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x8(%rbp), %rax
xorq 0x43f0(%rax), %rcx
movq %rcx, 0x43f0(%rax)
cmpl $0x0, -0xc(%rbp)
jne 0x9dea7
movq -0x8(%rbp), %rax
cmpl $0x43b, 0x43b0(%rax)    # imm = 0x43B
jge 0x9de36
movq -0x8(%rbp), %rax
movq 0x43e8(%rax), %rcx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movslq 0x43b0(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rcx
movl 0x4744(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x4744(%rcx)
movslq %eax, %rcx
leaq 0x1c70104b(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
xorq 0x43d0(%rax), %rcx
movq %rcx, 0x43d0(%rax)
movq -0x8(%rbp), %rax
cmpl $0x349, 0x4744(%rax)    # imm = 0x349
jl 0x9de8f
movq -0x8(%rbp), %rax
movl $0x0, 0x4744(%rax)
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x43b0(%rax)
jmp 0x9e1c9
movl -0x10(%rbp), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb $0x0, 0x96ce0(%rax,%rcx)
movslq -0xc(%rbp), %rcx
leaq 0x1c700fce(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x8(%rbp), %rax
xorq 0x43d0(%rax), %rcx
movq %rcx, 0x43d0(%rax)
movslq -0xc(%rbp), %rcx
leaq 0x1c700fa2(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x8(%rbp), %rax
xorq 0x43e8(%rax), %rcx
movq %rcx, 0x43e8(%rax)
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x10(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x91c30
leaq -0x50(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x9bc90
movl $0x0, -0x74(%rbp)
cmpl $0x4, -0x74(%rbp)
jge 0x9e086
movq -0x28(%rbp), %rax
movslq -0x74(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x10(%rbp), %eax
jne 0x9dfb9
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movslq -0x74(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rsi
movl -0xc(%rbp), %edx
callq 0x9aaa0
movq -0x18(%rbp), %rax
movslq -0x74(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movl (%rax,%rcx,4), %ecx
movl -0x34(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x34(%rbp)
cltq
movl %ecx, -0x60(%rbp,%rax,4)
jmp 0x9e076
movq -0x28(%rbp), %rax
movslq -0x74(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x1c(%rbp), %eax
jne 0x9e074
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movslq -0x74(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rsi
movl -0xc(%rbp), %edx
callq 0x9aaa0
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x74(%rbp), %rdx
movslq -0x50(%rbp,%rdx,4), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jne 0x9e072
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movslq -0x74(%rbp), %rcx
movslq -0x50(%rbp,%rcx,4), %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rsi
movl -0x10(%rbp), %edx
callq 0x9ac80
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl 0x98730(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x98730(%rax,%rcx,4)
jmp 0x9e074
jmp 0x9e076
jmp 0x9e078
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x9df48
movl -0x38(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
addl 0x43b4(%rax,%rcx,4), %edx
movl %edx, 0x43b4(%rax,%rcx,4)
cmpl $0x0, -0x34(%rbp)
jne 0x9e14f
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x9a1c0
cmpl $0x1, -0x38(%rbp)
jne 0x9e14d
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0xc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0x9e14d
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x43c8(%rax)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0xc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x7c8, %rcx, %rcx      # imm = 0x7C8
addq %rcx, %rax
movswl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x43c4(%rax)
movq -0x8(%rbp), %rax
movslq 0x43c4(%rax), %rcx
leaq 0x1c700d70(%rip), %rax  # 0x1c79eea0
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
xorq 0x43d0(%rax), %rcx
movq %rcx, 0x43d0(%rax)
jmp 0x9e181
cmpl $0x1, -0x34(%rbp)
jne 0x9e169
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x60(%rbp), %ecx
callq 0x9a530
jmp 0x9e17f
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x34(%rbp), %ecx
leaq -0x60(%rbp), %r8
callq 0x9a760
jmp 0x9e181
movq -0x8(%rbp), %rax
cmpl $0x43b, 0x43b0(%rax)    # imm = 0x43B
jge 0x9e1b6
movq -0x8(%rbp), %rax
movq 0x43e8(%rax), %rcx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movslq 0x43b0(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x43b0(%rax)
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)