// File: /workspace/github_cpp_makefile_star2_O3/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
pxor %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movslq 0x43b0(%rdi), %rax
cmpq $0x43a, %rax            # imm = 0x43A
jg 0x51fda
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 0x521b4
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, 0x10(%rsp)
callq 0x4e395
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
callq 0x54386
movq %r15, %rdi
movl 0x10(%rsp), %edx
xorl %r15d, %r15d
xorl %r8d, %r8d
xorl %r13d, %r13d
movq %rdi, 0x18(%rsp)
movslq 0x70(%rsp,%r15,4), %rbp
movsbl 0x43cc(%rbx,%rbp), %eax
cmpl %edx, %eax
jne 0x520b5
movslq 0x956f0(%rbx,%rbp,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %r12, %rax
cmpw $0x0, 0x8(%rax,%rdi,2)
je 0x5209f
xorl %ecx, %ecx
movslq %ecx, %rsi
movswl 0x8(%rax,%rsi,2), %ecx
cmpl %r14d, %ecx
jne 0x52064
movslq %ecx, %rcx
movzwl 0x8(%rax,%rcx,2), %ecx
movw %cx, 0x8(%rax,%rsi,2)
movw $0x0, 0x8(%rax,%rdi,2)
movl 0x4(%rax), %ecx
decl %ecx
movl %ecx, 0x4(%rax)
cmpl $0x1, %ecx
jne 0x5209f
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 0x52166
xorl %edx, %eax
cmpl $0x3, %eax
jne 0x52166
movslq 0x956f0(%rbx,%rbp,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %r12, %rax
cmpw $0x0, 0x8(%rax,%rdi,2)
je 0x52117
xorl %ecx, %ecx
movslq %ecx, %rsi
movswl 0x8(%rax,%rsi,2), %ecx
cmpl %r14d, %ecx
jne 0x520dc
movslq %ecx, %rcx
movzwl 0x8(%rax,%rcx,2), %ecx
movw %cx, 0x8(%rax,%rsi,2)
movw $0x0, 0x8(%rax,%rdi,2)
movl 0x4(%rax), %ecx
decl %ecx
movl %ecx, 0x4(%rax)
cmpl $0x1, %ecx
jne 0x52117
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 0x52166
movq %rbx, %rdi
movl %r8d, 0x8(%rsp)
callq 0x52773
movslq 0x956f0(%rbx,%rbp,4), %rax
imulq $0x7c8, %rax, %rsi      # imm = 0x7C8
addq %r12, %rsi
movq %rbx, %rdi
callq 0x52810
movl 0x8(%rsp), %r8d
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %edx
addl %eax, %r8d
incq %r15
cmpq $0x4, %r15
jne 0x52037
movslq %edx, %rax
addl %r8d, 0x43b4(%rbx,%rax,4)
testl %r13d, %r13d
je 0x521c1
cmpl $0x1, %r13d
jne 0x523e9
movl 0x20(%rsp), %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %edx, %ebp
callq 0x52773
movq %rbx, %rdi
movl %r14d, %esi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x52a44
jmp 0x52704
incl %eax
movl %eax, 0x43b0(%rbx)
jmp 0x52756
movl %r8d, 0x8(%rsp)
xorl %r13d, %r13d
movq %rbx, %r15
incq %r13
cmpb $0x0, 0xa57c(%r15)
leaq 0x7c8(%r15), %r15
jne 0x521cc
leaq 0x95f8(%r15), %rdi
xorl %ebp, %ebp
movl $0x570, %edx            # imm = 0x570
xorl %esi, %esi
callq 0x6200
leaq 0x9b6c(%r15), %rdi
movl $0x240, %edx            # imm = 0x240
xorl %esi, %esi
callq 0x6200
movl 0x10(%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, 0x48(%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 0x54386
movl 0x10(%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 0x5233b
xorl %r11d, %edi
cmpl $0x3, %edi
jne 0x5237d
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 0x522fe
xorl %r9d, %r9d
movslq %r9d, %r8
movzwl 0x57c(%rdi,%r8,2), %r10d
movswl %r10w, %r9d
cmpl %r9d, %r13d
jg 0x522d1
movw %r10w, 0x57c(%rdi,%rax,2)
movw %r13w, 0x57c(%rdi,%r8,2)
incl 0x578(%rdi)
cmpw $0x0, 0x9b6c(%r15,%rsi,2)
jne 0x5237d
xorl %edi, %edi
movslq %edi, %r9
movzwl 0x9b6c(%r15,%r9,2), %r8d
movswl %r8w, %edi
cmpl %edi, %edx
jg 0x5230c
leaq (%r15,%r9,2), %rdi
addq $0x9b6c, %rdi           # imm = 0x9B6C
movw %r8w, 0x9b6c(%r15,%rsi,2)
movq 0x48(%rsp), %rsi
jmp 0x52378
cmpw $0x0, 0x95f8(%r15,%rsi,2)
je 0x5234b
movl %edx, %ecx
jmp 0x5237d
movslq %ecx, %rdi
movzwl 0x95f8(%r15,%rdi,2), %r8d
movswl %r8w, %ecx
cmpl %ecx, %edx
jg 0x5234b
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 0x5228c
movb $0x1, 0x9db4(%r15)
cmpl $0x1, 0x8(%rsp)
movq 0x18(%rsp), %rcx
jne 0x52704
movslq 0x956f0(%rbx,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
cmpl $0x1, 0x4(%r12,%rax)
jne 0x52704
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 0x52704
movl 0x20(%rsp), %r9d
jle 0x52459
movl %r13d, %eax
xorl %r13d, %r13d
movl $0x1, %r8d
movl %r9d, %ecx
movl 0x20(%rsp,%r8,4), %esi
xorl %edi, %edi
cmpl %esi, 0x20(%rsp,%rdi,4)
je 0x5243b
incq %rdi
cmpq %rdi, %r8
jne 0x52406
movslq %r13d, %r13
cmpl %esi, %ecx
movl %esi, %edi
cmovgl %ecx, %edi
cmovgel %esi, %ecx
movslq %edi, %rdi
imulq $0x7c8, %rdi, %rdi      # imm = 0x7C8
addq %r12, %rdi
movq %rdi, 0x50(%rsp,%r13,8)
movl %esi, 0x30(%rsp,%r13,4)
incl %r13d
incq %r8
cmpq %rax, %r8
jne 0x523ff
movslq %r13d, %rax
movl %r9d, 0x30(%rsp,%rax,4)
testl %eax, %eax
js 0x52768
movl %ecx, 0x8(%rsp)
jmp 0x52466
movl %r9d, 0x8(%rsp)
movl %r9d, 0x30(%rsp)
xorl %r13d, %r13d
leal 0x1(%r13), %ebp
xorl %r15d, %r15d
movl 0x30(%rsp,%r15,4), %esi
movq %rbx, %rdi
callq 0x52773
incq %r15
cmpq %r15, %rbp
jne 0x5246d
movq %rbx, %rdi
movl %r14d, %esi
movl 0x10(%rsp), %edx
movl 0x8(%rsp), %ebp
movl %ebp, %ecx
callq 0x52a44
testl %r13d, %r13d
je 0x52704
movslq %ebp, %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, 0x8(%rsp)
movl %r13d, %esi
movq %rsi, 0x10(%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 0x52526
movl %r11d, %r15d
movslq %r11d, %r13
movzwl 0x8(%rax,%r13,2), %esi
movswl %si, %r11d
cmpl %r11d, %ebp
jg 0x524ff
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 0x524f3
movq 0x8(%rsp), %r14
movl 0x7bc(%r14), %ebp
imulq $0x7c8, %r10, %r11      # imm = 0x7C8
movl 0x7bc(%r12,%r11), %r15d
cmpl %r15d, %ebp
jle 0x52579
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 0x525c6
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 0x52598
movl %r14d, 0x961d0(%rbx,%r13,4)
movl %r15d, 0x961d0(%rbx,%rdi,4)
movl %esi, %r15d
cmpl $0x2b7, %esi            # imm = 0x2B7
jne 0x52582
addq %r12, %r11
movl 0x7c0(%r11), %esi
movq 0x8(%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 0x52628
movl %ebp, %r13d
movslq %ebp, %rdi
movzwl 0x57c(%rax,%rdi,2), %esi
movswl %si, %ebp
cmpl %ebp, %r15d
jg 0x525f7
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 0x525e8
movzwl %r11w, %esi
cmpl $0x11f, %esi            # imm = 0x11F
je 0x526ee
movswq %r11w, %r11
imulq $0x7c8, %r11, %r14      # imm = 0x7C8
addq %r12, %r14
cmpw $0x0, 0x57c(%r14,%r10,2)
je 0x5269e
xorl %ebp, %ebp
movslq %ebp, %rdi
movswl 0x57c(%r14,%rdi,2), %ebp
cmpl %ebp, %r10d
jne 0x52666
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 0x526d8
xorl %ebp, %ebp
movslq %ebp, %rdi
movzwl 0x57c(%r14,%rdi,2), %esi
movswl %si, %ebp
cmpl %ebp, %ecx
jg 0x526ac
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 0x5264a
movb $0x0, 0x7c4(%r9)
incq %r8
cmpq 0x10(%rsp), %r8
jne 0x524da
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 0x6200
movslq 0x43b0(%rbx), %rax
imulq $0x16c0, %rax, %rax     # imm = 0x16C0
movq 0x43c4(%rbx), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x986b4(%rbx,%rax)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl %r14d, %esi
jmp 0x521aa