// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movslq 0x43b0(%rdi), %rax
imulq $0x16c0, %rax, %r14     # imm = 0x16C0
shlq $0x4, %rax
movslq -0xc(%rax,%rdi), %rcx
movslq -0x10(%rax,%rdi), %rax
movq %rax, 0x28(%rsp)
leaq (%r14,%rdi), %rbp
addq $0x9593c, %rbp          # imm = 0x9593C
movslq 0x956f0(%rdi,%rcx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
leaq (%rdi,%rax), %rsi
addq $0x95f0, %rsi           # imm = 0x95F0
callq 0x52810
cmpl $0x0, 0x16b0(%rbp)
jle 0x53009
leaq 0x95f0(%rbx), %r11
leaq 0x4718(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq (%r14,%rbx), %rcx
addq $0x95940, %rcx          # imm = 0x95940
movq %rbp, %rsi
xorl %edi, %edi
movq %rbp, 0x48(%rsp)
movq %r11, 0x38(%rsp)
movq %rsi, 0x40(%rsp)
movq %rcx, 0x30(%rsp)
movb 0x16b4(%rbp,%rdi), %r12b
movsbl %r12b, %ecx
movq 0x28(%rsp), %rax
xorl %ecx, %eax
cmpl $0x3, %eax
jne 0x52cc5
movl 0x1690(%rbp,%rdi,4), %eax
movq 0x28(%rsp), %rcx
subl %eax, 0x43b4(%rbx,%rcx,4)
movb 0x16b4(%rbp,%rdi), %r12b
movsbl %r12b, %ecx
movl %ecx, 0x18(%rsp)
movl 0x16a0(%rbp,%rdi,4), %r15d
imulq $0x5a4, %rdi, %rax      # imm = 0x5A4
movq %rax, 0x20(%rsp)
addq %rbp, %rax
movq %rax, 0x10(%rsp)
movq %rdi, 0x58(%rsp)
movslq 0x1690(%rbp,%rdi,4), %rax
movq %rax, 0x8(%rsp)
movslq %r15d, %r14
imulq $0x7c8, %r14, %r13      # imm = 0x7C8
leaq (%rbx,%r13), %rdi
addq $0x95f8, %rdi           # imm = 0x95F8
movl $0x570, %edx            # imm = 0x570
xorl %esi, %esi
callq 0x6200
leaq (%rbx,%r13), %rdi
addq $0x9b6c, %rdi           # imm = 0x9B6C
movl $0x240, %edx            # imm = 0x240
xorl %esi, %esi
callq 0x6200
movq 0x38(%rsp), %r11
movb %r12b, (%r11,%r13)
movw $0x2b7, 0x8(%r11,%r13)  # imm = 0x2B7
movw $0x11f, 0x57c(%r11,%r13) # imm = 0x11F
xorl %ecx, %ecx
movl %ecx, 0x4(%r11,%r13)
movq 0x20(%rsp), %rax
movl (%rbp,%rax), %eax
movq 0x8(%rsp), %rdx
movl %eax, 0x7bc(%r11,%r13)
movl %edx, 0x7c0(%r11,%r13)
movl %ecx, 0x578(%r11,%r13)
testq %rdx, %rdx
movq %r13, 0x50(%rsp)
jle 0x52fa4
movq %r13, %rax
addq %r11, %r13
addq $0x8, %r13
leaq 0x4(%r11,%rax), %rcx
movq %rcx, 0x20(%rsp)
addq %r11, %rax
addq $0x578, %rax            # imm = 0x578
movq %rax, 0x68(%rsp)
xorl %ebp, %ebp
movq 0x40(%rsp), %rax
movslq (%rax,%rbp,4), %rdx
movb %r12b, 0x43cc(%rbx,%rdx)
movl %r15d, 0x956f0(%rbx,%rdx,4)
movq 0x60(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x4e395
incq %rbp
cmpq %rbp, 0x8(%rsp)
jne 0x52daa
movq 0x8(%rsp), %r9
cmpl $0x1, %r9d
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %r8
je 0x52e12
leal -0x1(%r9), %eax
movl %eax, %eax
movl (%r8), %edx
xorl %ecx, %ecx
movslq %edx, %rdx
movl (%rdi,%rcx,4), %esi
incq %rcx
movl %esi, 0x961d0(%rbx,%rdx,4)
movl %esi, %edx
cmpq %rcx, %rax
jne 0x52dfb
movslq -0x4(%r8,%r9,4), %rax
movl $0x2b7, 0x961d0(%rbx,%rax,4) # imm = 0x2B7
xorl %eax, %eax
movq %rax, 0x18(%rsp)
movl (%r8,%rax,4), %ebp
leaq 0x70(%rsp), %rdi
movl %ebp, %esi
callq 0x54386
movq 0x38(%rsp), %r11
movslq %ebp, %rax
xorl %ecx, %ecx
movl 0x70(%rsp,%rcx,4), %edx
movslq %edx, %rsi
movb 0x43cc(%rbx,%rsi), %dil
testb %dil, %dil
je 0x52f43
xorb %r12b, %dil
cmpb $0x3, %dil
jne 0x52f7a
movl 0x956f0(%rbx,%rsi,4), %edx
movslq %edx, %rsi
imulq $0x7c8, %rsi, %rdi      # imm = 0x7C8
addq %r11, %rdi
cmpw $0x0, 0x8(%rdi,%rax,2)
je 0x52eca
xorl %r8d, %r8d
movslq %r8d, %r9
movswl 0x8(%rdi,%r9,2), %r8d
cmpl %r8d, %ebp
jne 0x52e87
movslq %r8d, %r8
movzwl 0x8(%rdi,%r8,2), %r8d
movw %r8w, 0x8(%rdi,%r9,2)
movw $0x0, 0x8(%rdi,%rax,2)
movl 0x4(%rdi), %r8d
decl %r8d
movl %r8d, 0x4(%rdi)
cmpl $0x1, %r8d
jne 0x52eca
movswq 0x8(%rdi), %r8
movb $0x1, 0x96cb0(%rbx,%r8)
cmpw $0x0, 0x57c(%rdi,%r14,2)
jne 0x52f06
xorl %r9d, %r9d
movslq %r9d, %r8
movzwl 0x57c(%rdi,%r8,2), %r10d
movswl %r10w, %r9d
cmpl %r9d, %r15d
jg 0x52ed9
movw %r10w, 0x57c(%rdi,%r14,2)
movw %r15w, 0x57c(%rdi,%r8,2)
incl 0x578(%rdi)
cmpw $0x0, 0x574(%r13,%rsi,2)
jne 0x52f7a
xorl %edi, %edi
movslq %edi, %r8
movzwl 0x574(%r13,%r8,2), %r9d
movswl %r9w, %edi
cmpl %edi, %edx
jg 0x52f14
leaq 0x574(,%r8,2), %rdi
addq %r13, %rdi
movw %r9w, 0x574(%r13,%rsi,2)
movq 0x68(%rsp), %rsi
jmp 0x52f75
cmpw $0x0, (%r13,%rsi,2)
jne 0x52f7a
xorl %edi, %edi
movslq %edi, %r8
movzwl (%r13,%r8,2), %r9d
movswl %r9w, %edi
cmpl %edi, %edx
jg 0x52f4e
leaq (,%r8,2), %rdi
addq %r13, %rdi
movw %r9w, (%r13,%rsi,2)
movq 0x20(%rsp), %rsi
movw %dx, (%rdi)
incl (%rsi)
incq %rcx
cmpq $0x4, %rcx
jne 0x52e43
movq 0x18(%rsp), %rax
incq %rax
movq 0x8(%rsp), %r9
cmpq %r9, %rax
movq 0x10(%rsp), %r8
jne 0x52e24
jmp 0x52fbd
decl %edx
movslq %edx, %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
movl $0x2b7, 0x961d0(%rbx,%rax,4) # imm = 0x2B7
movq 0x50(%rsp), %rax
addq %r11, %rax
movb $0x1, 0x7c4(%rax)
movq 0x48(%rsp), %rbp
movq 0x58(%rsp), %rdi
movl $0x0, 0x1690(%rbp,%rdi,4)
incq %rdi
movslq 0x16b0(%rbp), %rax
movl $0x5a4, %edx            # imm = 0x5A4
movq 0x40(%rsp), %rsi
addq %rdx, %rsi
movq 0x30(%rsp), %rcx
addq %rdx, %rcx
cmpq %rax, %rdi
jl 0x52c84
movl $0x0, 0x16b0(%rbp)
movq 0x16b8(%rbp), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x43c4(%rbx)
decl 0x43b0(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq