// File: kobanium[P]Ray/src/board/SearchBoard.cpp
// Function: Undo(search_game_info_t*)
void
Undo( search_game_info_t *game )
{
  const int pm_count = game->moves - 1;
  const int previous_move = game->record[pm_count].pos;
  const int played_color = game->record[pm_count].color;
  const int opponent_color = GetOppositeColor(played_color);
  string_t *string = game->string;
  int *string_id = game->string_id;
  undo_record_t* rec = &game->undo[pm_count];

  // 連を取り除く
  RemoveString(game, &string[string_id[previous_move]]);

  // 連を1手前の状態に戻す
  for (int i = 0; i < rec->strings; i++) {
    if (rec->string_color[i] == opponent_color) {
      game->prisoner[played_color] -= rec->stones[i];
    }
    RestoreChain(game, rec->strings_id[i], rec->stone[i], rec->stones[i], rec->string_color[i]);
    rec->stones[i] = 0;
  }

  rec->strings = 0;

  game->ko_move = rec->ko_move_record;
  game->ko_pos = rec->ko_pos_record;

  game->moves--;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edi
callq 0x25810
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x95f0, %rax           # imm = 0x95F0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x956f0, %rax          # imm = 0x956F0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $0x96ffc, %rax          # imm = 0x96FFC
movslq -0xc(%rbp), %rcx
imulq $0x16c0, %rcx, %rcx     # imm = 0x16C0
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movslq -0x10(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
addq %rax, %rsi
callq 0x98cf0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x16b0(%rcx), %eax
jge 0x9961c
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl 0x16b4(%rax,%rcx), %eax
cmpl -0x18(%rbp), %eax
jne 0x995b1
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x1690(%rax,%rcx,4), %esi
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x43b4(%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, 0x43b4(%rax,%rcx,4)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x16a0(%rax,%rcx,4), %esi
movq -0x30(%rbp), %rdx
movslq -0x34(%rbp), %rax
imulq $0x5a4, %rax, %rax      # imm = 0x5A4
addq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x1690(%rax,%rcx,4), %ecx
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %r8
movsbl 0x16b4(%rax,%r8), %r8d
callq 0x99670
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0x0, 0x1690(%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x99562
movq -0x30(%rbp), %rax
movl $0x0, 0x16b0(%rax)
movq -0x30(%rbp), %rax
movl 0x16b8(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x43c8(%rax)
movq -0x30(%rbp), %rax
movl 0x16bc(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x43c4(%rax)
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x43b0(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)