// File: /workspace/github_cpp_makefile_star2_O1/kobanium[P]Ray/src/board/SearchBoard.cpp
// Function: PutStoneForSearch(search_game_info_t*, int, int)
void
PutStoneForSearch( search_game_info_t *game, const int pos, const int color )
{
  int *string_id = game->string_id;
  char *board = game->board;
  string_t *string = game->string;
  int other = GetOppositeColor(color);
  int connection = 0;
  int connect[4] = { 0 };
  int prisoner = 0;
  int neighbor[4];

  // 着手箇所と色を記録
  if (game->moves < MAX_RECORDS) {
    game->record[game->moves].color = color;
    game->record[game->moves].pos = pos;
    game->undo[game->moves].strings = 0;
  }

  // 着手がパスなら手数を進めて終了
  if (pos == PASS) {
    game->moves++;
    return;
  }

  // 石を置く
  board[pos] = (char)color;

  // 候補手から除外
  game->candidates[pos] = false;

  // パターンの更新(MD5)
  UpdateMD2Stone(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) {
        RecordString(game, string_id[neighbor[i]]);
        prisoner += RemoveString(game, &string[string_id[neighbor[i]]]);
      }
    }
  }

  // 打ち上げた石をアゲハマに追加
  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];
    }
  } else if (connection == 1) {
    RecordString(game, connect[0]);
    AddStone(game, pos, color, connect[0]);
  } else {
    ConnectString(game, pos, color, connection, connect);
  }

  // 手数を1つだけ進める
  game->moves++;
  memset(&game->undo[game->moves], 0, sizeof(undo_record_t));
  game->undo[game->moves].ko_move_record = game->ko_move;
  game->undo[game->moves].ko_pos_record = game->ko_pos;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %r8d
movl %esi, %r14d
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movslq 0x43b0(%rdi), %rax
cmpq $0x43a, %rax            # imm = 0x43A
jg 0x51c0c
movq %rax, %rcx
shlq $0x4, %rcx
movl %r8d, (%rbx,%rcx)
movl %r14d, 0x4(%rbx,%rcx)
imulq $0x16c0, %rax, %rcx     # imm = 0x16C0
movl $0x0, 0x986ac(%rbx,%rcx)
testl %r14d, %r14d
je 0x51dea
leaq 0x95f0(%rbx), %r12
movslq %r14d, %r15
movb %r8b, 0x43cc(%rbx,%r15)
movb $0x0, 0x96cb0(%rbx,%r15)
leaq 0x4718(%rbx), %rdi
movl %r8d, %esi
movl %r14d, %edx
movl %r8d, 0x8(%rsp)
callq 0x4e058
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
callq 0x53e40
movq %r15, %r8
movl 0x8(%rsp), %edi
xorl %r15d, %r15d
xorl %r9d, %r9d
xorl %r13d, %r13d
movq %r8, 0x18(%rsp)
movslq 0x70(%rsp,%r15,4), %rbp
movsbl 0x43cc(%rbx,%rbp), %eax
cmpl %edi, %eax
jne 0x51ce9
movslq 0x956f0(%rbx,%rbp,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %r12, %rax
cmpw $0x0, 0x8(%rax,%r8,2)
je 0x51cd3
xorl %ecx, %ecx
movslq %ecx, %rdx
movswl 0x8(%rax,%rdx,2), %ecx
cmpl %r14d, %ecx
jne 0x51c97
movslq %ecx, %rcx
movzwl 0x8(%rax,%rcx,2), %ecx
movw %cx, 0x8(%rax,%rdx,2)
movw $0x0, 0x8(%rax,%r8,2)
movl 0x4(%rax), %ecx
decl %ecx
movl %ecx, 0x4(%rax)
cmpl $0x1, %ecx
jne 0x51cd3
movswq 0x8(%rax), %rax
movb $0x1, 0x96cb0(%rbx,%rax)
movl 0x956f0(%rbx,%rbp,4), %eax
movslq %r13d, %rcx
incl %r13d
movl %eax, 0x20(%rsp,%rcx,4)
jmp 0x51d9c
xorl %edi, %eax
cmpl $0x3, %eax
jne 0x51d9c
movslq 0x956f0(%rbx,%rbp,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %r12, %rax
cmpw $0x0, 0x8(%rax,%r8,2)
je 0x51d4d
xorl %ecx, %ecx
movslq %ecx, %rdx
movswl 0x8(%rax,%rdx,2), %ecx
cmpl %r14d, %ecx
jne 0x51d11
movslq %ecx, %rcx
movzwl 0x8(%rax,%rcx,2), %ecx
movw %cx, 0x8(%rax,%rdx,2)
movw $0x0, 0x8(%rax,%r8,2)
movl 0x4(%rax), %ecx
decl %ecx
movl %ecx, 0x4(%rax)
cmpl $0x1, %ecx
jne 0x51d4d
movswq 0x8(%rax), %rax
movb $0x1, 0x96cb0(%rbx,%rax)
movslq 0x956f0(%rbx,%rbp,4), %rsi
imulq $0x7c8, %rsi, %rax      # imm = 0x7C8
cmpl $0x0, 0x4(%r12,%rax)
jne 0x51d9c
movq %rbx, %rdi
movl %r9d, 0x10(%rsp)
callq 0x52395
movslq 0x956f0(%rbx,%rbp,4), %rax
imulq $0x7c8, %rax, %rsi      # imm = 0x7C8
addq %r12, %rsi
movq %rbx, %rdi
callq 0x52432
movl 0x10(%rsp), %r9d
movq 0x18(%rsp), %r8
movl 0x8(%rsp), %edi
addl %eax, %r9d
incq %r15
cmpq $0x4, %r15
jne 0x51c69
movslq %edi, %rax
addl %r9d, 0x43b4(%rbx,%rax,4)
testl %r13d, %r13d
je 0x51df7
cmpl $0x1, %r13d
jne 0x5201f
movl 0x20(%rsp), %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x52395
movq %rbx, %rdi
movl %r14d, %esi
movl 0x8(%rsp), %edx
movl %r15d, %ecx
callq 0x52666
jmp 0x5232d
incl %eax
movl %eax, 0x43b0(%rbx)
jmp 0x52383
movl %r9d, 0x10(%rsp)
xorl %r13d, %r13d
movq %rbx, %r15
incq %r13
cmpb $0x0, 0xa57c(%r15)
leaq 0x7c8(%r15), %r15
jne 0x51e02
leaq 0x95f8(%r15), %rdi
xorl %ebp, %ebp
movl $0x570, %edx            # imm = 0x570
xorl %esi, %esi
callq 0x6210
leaq 0x9b6c(%r15), %rdi
movl $0x240, %edx            # imm = 0x240
xorl %esi, %esi
callq 0x6210
movl 0x8(%rsp), %eax
movb %al, 0x95f0(%r15)
movw $0x2b7, 0x95f8(%r15)    # imm = 0x2B7
movw $0x11f, 0x9b6c(%r15)    # imm = 0x11F
leaq 0x95f4(%r15), %rcx
movl %ebp, 0x95f4(%r15)
movl %r14d, 0x9dac(%r15)
movl $0x1, 0x9db0(%r15)
leaq 0x9b68(%r15), %rax
movq %rax, 0x38(%rsp)
movl %ebp, 0x9b68(%r15)
movq 0x18(%rsp), %rax
movl %r13d, 0x956f0(%rbx,%rax,4)
movl $0x2b7, 0x961d0(%rbx,%rax,4) # imm = 0x2B7
leaq 0x50(%rsp), %rdi
movl %r14d, %esi
movq %rcx, %r14
callq 0x53e40
movl 0x8(%rsp), %r11d
movl %r13d, %eax
xorl %ecx, %ecx
movl 0x50(%rsp,%rbp,4), %edx
movslq %edx, %rsi
movsbl 0x43cc(%rbx,%rsi), %edi
testl %edi, %edi
je 0x51f71
xorl %r11d, %edi
cmpl $0x3, %edi
jne 0x51fb3
movl 0x956f0(%rbx,%rsi,4), %edx
movslq %edx, %rsi
imulq $0x7c8, %rsi, %rdi      # imm = 0x7C8
addq %r12, %rdi
cmpw $0x0, 0x57c(%rdi,%rax,2)
jne 0x51f34
xorl %r9d, %r9d
movslq %r9d, %r8
movzwl 0x57c(%rdi,%r8,2), %r10d
movswl %r10w, %r9d
cmpl %r9d, %r13d
jg 0x51f07
movw %r10w, 0x57c(%rdi,%rax,2)
movw %r13w, 0x57c(%rdi,%r8,2)
incl 0x578(%rdi)
cmpw $0x0, 0x9b6c(%r15,%rsi,2)
jne 0x51fb3
xorl %edi, %edi
movslq %edi, %r9
movzwl 0x9b6c(%r15,%r9,2), %r8d
movswl %r8w, %edi
cmpl %edi, %edx
jg 0x51f42
leaq (%r15,%r9,2), %rdi
addq $0x9b6c, %rdi           # imm = 0x9B6C
movw %r8w, 0x9b6c(%r15,%rsi,2)
movq 0x38(%rsp), %rsi
jmp 0x51fae
cmpw $0x0, 0x95f8(%r15,%rsi,2)
je 0x51f81
movl %edx, %ecx
jmp 0x51fb3
movslq %ecx, %rdi
movzwl 0x95f8(%r15,%rdi,2), %r8d
movswl %r8w, %ecx
cmpl %ecx, %edx
jg 0x51f81
leaq (%r15,%rdi,2), %rdi
addq $0x95f8, %rdi           # imm = 0x95F8
movw %r8w, 0x95f8(%r15,%rsi,2)
movq %r14, %rsi
movl %edx, %ecx
movw %dx, (%rdi)
incl (%rsi)
incq %rbp
cmpq $0x4, %rbp
jne 0x51ec2
movb $0x1, 0x9db4(%r15)
cmpl $0x1, 0x10(%rsp)
movq 0x18(%rsp), %rcx
jne 0x5232d
movslq 0x956f0(%rbx,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rax)
jne 0x5232d
movl 0x43b0(%rbx), %eax
movl %eax, 0x43c8(%rbx)
movslq 0x956f0(%rbx,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movswl 0x8(%r12,%rax), %eax
movl %eax, 0x43c4(%rbx)
jmp 0x5232d
movl 0x20(%rsp), %eax
xorl %ebp, %ebp
movl %eax, %r8d
cmpl $0x2, %r13d
jl 0x5207f
movl %r13d, %ecx
xorl %ebp, %ebp
movl $0x1, %edx
movl %eax, %r8d
movl 0x20(%rsp,%rdx,4), %esi
xorl %edi, %edi
cmpl %esi, 0x20(%rsp,%rdi,4)
je 0x52077
incq %rdi
cmpq %rdi, %rdx
jne 0x52041
movslq %ebp, %rbp
cmpl %esi, %r8d
movl %esi, %edi
cmovgl %r8d, %edi
cmovgel %esi, %r8d
movslq %edi, %rdi
imulq $0x7c8, %rdi, %rdi      # imm = 0x7C8
addq %r12, %rdi
movq %rdi, 0x50(%rsp,%rbp,8)
movl %esi, 0x40(%rsp,%rbp,4)
incl %ebp
incq %rdx
cmpq %rcx, %rdx
jne 0x5203b
movl %r8d, 0x10(%rsp)
movslq %ebp, %rcx
movl %eax, 0x40(%rsp,%rcx,4)
testl %ecx, %ecx
js 0x520ab
leal 0x1(%rbp), %r13d
xorl %r15d, %r15d
movl 0x40(%rsp,%r15,4), %esi
movq %rbx, %rdi
callq 0x52395
incq %r15
cmpq %r15, %r13
jne 0x52096
movq %rbx, %rdi
movl %r14d, %esi
movl 0x8(%rsp), %edx
movl 0x10(%rsp), %r14d
movl %r14d, %ecx
callq 0x52666
testl %ebp, %ebp
jle 0x5232d
movslq %r14d, %rax
imulq $0x7c8, %rax, %rcx      # imm = 0x7C8
leaq (%r12,%rcx), %rax
movslq 0x7bc(%r12,%rcx), %rcx
movl 0x956f0(%rbx,%rcx,4), %ecx
movslq %ecx, %rdx
imulq $0x7c8, %rdx, %rsi      # imm = 0x7C8
addq %r12, %rsi
movq %rsi, 0x10(%rsp)
movl %ebp, %esi
movq %rsi, 0x8(%rsp)
xorl %r8d, %r8d
movq 0x50(%rsp,%r8,8), %r9
movslq 0x7bc(%r9), %rsi
movslq 0x956f0(%rbx,%rsi,4), %r10
xorl %ebp, %ebp
xorl %r11d, %r11d
movslq %ebp, %r14
cmpw $0x0, 0x8(%rax,%r14,2)
jne 0x5214f
movl %r11d, %r15d
movslq %r11d, %r13
movzwl 0x8(%rax,%r13,2), %esi
movswl %si, %r11d
cmpl %r11d, %ebp
jg 0x52128
movw %si, 0x8(%rax,%r14,2)
movw %r14w, 0x8(%rax,%r13,2)
incl 0x4(%rax)
movl %r15d, %r11d
movswl 0x8(%r9,%r14,2), %ebp
cmpl $0x2b7, %ebp            # imm = 0x2B7
jne 0x5211c
movq 0x10(%rsp), %r14
movl 0x7bc(%r14), %ebp
imulq $0x7c8, %r10, %r11      # imm = 0x7C8
movl 0x7bc(%r12,%r11), %r15d
cmpl %r15d, %ebp
jle 0x521a2
movslq %r15d, %rsi
movl 0x961d0(%rbx,%rsi,4), %edi
movl %ebp, 0x961d0(%rbx,%rsi,4)
movl %ecx, 0x956f0(%rbx,%rsi,4)
movl %r15d, 0x7bc(%r14)
movl %r15d, %ebp
movl %edi, %r15d
cmpl $0x2b7, %r15d           # imm = 0x2B7
je 0x521ef
movslq %r15d, %r13
movl %ecx, 0x956f0(%rbx,%r13,4)
movl 0x961d0(%rbx,%r13,4), %esi
movl %ebp, %r14d
movl %r14d, %ebp
movslq %r14d, %rdi
movl 0x961d0(%rbx,%rdi,4), %r14d
cmpl %r15d, %r14d
jl 0x521c1
movl %r14d, 0x961d0(%rbx,%r13,4)
movl %r15d, 0x961d0(%rbx,%rdi,4)
movl %esi, %r15d
cmpl $0x2b7, %esi            # imm = 0x2B7
jne 0x521ab
addq %r12, %r11
movl 0x7c0(%r11), %esi
movq 0x10(%rsp), %rdi
addl %esi, 0x7c0(%rdi)
movzwl 0x57c(%r9), %r11d
xorl %ebp, %ebp
xorl %r15d, %r15d
movslq %r15d, %r14
cmpw $0x0, 0x57c(%rax,%r14,2)
jne 0x52251
movl %ebp, %r13d
movslq %ebp, %rdi
movzwl 0x57c(%rax,%rdi,2), %esi
movswl %si, %ebp
cmpl %ebp, %r15d
jg 0x52220
movw %si, 0x57c(%rax,%r14,2)
movw %r14w, 0x57c(%rax,%rdi,2)
incl 0x578(%rax)
movl %r13d, %ebp
movswl 0x57c(%r9,%r14,2), %r15d
cmpl $0x11f, %r15d           # imm = 0x11F
jne 0x52211
movzwl %r11w, %esi
cmpl $0x11f, %esi            # imm = 0x11F
je 0x52317
movswq %r11w, %r11
imulq $0x7c8, %r11, %r14      # imm = 0x7C8
addq %r12, %r14
cmpw $0x0, 0x57c(%r14,%r10,2)
je 0x522c7
xorl %ebp, %ebp
movslq %ebp, %rdi
movswl 0x57c(%r14,%rdi,2), %ebp
cmpl %ebp, %r10d
jne 0x5228f
movslq %ebp, %rsi
movzwl 0x57c(%r14,%rsi,2), %esi
movw %si, 0x57c(%r14,%rdi,2)
movw $0x0, 0x57c(%r14,%r10,2)
decl 0x578(%r14)
cmpw $0x0, 0x57c(%r14,%rdx,2)
jne 0x52301
xorl %ebp, %ebp
movslq %ebp, %rdi
movzwl 0x57c(%r14,%rdi,2), %esi
movswl %si, %ebp
cmpl %ebp, %ecx
jg 0x522d5
movw %si, 0x57c(%r14,%rdx,2)
movw %dx, 0x57c(%r14,%rdi,2)
incl 0x578(%r14)
movzwl 0x57c(%r9,%r11,2), %r11d
cmpl $0x11f, %r11d           # imm = 0x11F
jne 0x52273
movb $0x0, 0x7c4(%r9)
incq %r8
cmpq 0x8(%rsp), %r8
jne 0x52103
movslq 0x43b0(%rbx), %rax
incq %rax
movl %eax, 0x43b0(%rbx)
imulq $0x16c0, %rax, %rax     # imm = 0x16C0
leaq (%rbx,%rax), %rdi
addq $0x96ffc, %rdi          # imm = 0x96FFC
movl $0x16c0, %edx           # imm = 0x16C0
xorl %esi, %esi
callq 0x6210
movl 0x43c8(%rbx), %eax
movslq 0x43b0(%rbx), %rcx
imulq $0x16c0, %rcx, %rcx     # imm = 0x16C0
movl %eax, 0x986b4(%rbx,%rcx)
movl 0x43c4(%rbx), %eax
movl %eax, 0x986b8(%rbx,%rcx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq