// File: /workspace/github_cpp_makefile_star2_O1/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, %rcx     # imm = 0x16C0
shlq $0x4, %rax
movslq -0xc(%rax,%rdi), %rdx
movslq -0x10(%rax,%rdi), %rax
movq %rax, 0x20(%rsp)
leaq (%rcx,%rdi), %r13
addq $0x9593c, %r13          # imm = 0x9593C
movslq 0x956f0(%rdi,%rdx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
leaq (%rdi,%rax), %rsi
addq $0x95f0, %rsi           # imm = 0x95F0
callq 0x52432
cmpl $0x0, 0x16b0(%r13)
jle 0x52c04
leaq 0x95f0(%rbx), %r11
leaq 0x4718(%rbx), %rax
movq %rax, 0x48(%rsp)
movq %r13, %rcx
xorl %edx, %edx
movq %r13, 0x28(%rsp)
movq %r11, 0x10(%rsp)
movq %rcx, 0x38(%rsp)
movsbl 0x16b4(%r13,%rdx), %eax
xorl 0x20(%rsp), %eax
cmpl $0x3, %eax
jne 0x528c7
movl 0x1690(%r13,%rdx,4), %eax
movq 0x20(%rsp), %rcx
subl %eax, 0x43b4(%rbx,%rcx,4)
movl 0x16a0(%r13,%rdx,4), %r15d
imulq $0x5a4, %rdx, %rax      # imm = 0x5A4
movq %rax, 0x8(%rsp)
movslq 0x1690(%r13,%rdx,4), %r12
movq %rdx, 0x58(%rsp)
movb 0x16b4(%r13,%rdx), %r14b
movslq %r15d, %rax
movq %rax, 0x50(%rsp)
imulq $0x7c8, %rax, %rbp      # imm = 0x7C8
leaq (%rbx,%rbp), %rdi
addq $0x95f8, %rdi           # imm = 0x95F8
movl $0x570, %edx            # imm = 0x570
xorl %esi, %esi
callq 0x6210
leaq (%rbx,%rbp), %rdi
addq $0x9b6c, %rdi           # imm = 0x9B6C
movl $0x240, %edx            # imm = 0x240
xorl %esi, %esi
callq 0x6210
movq %r12, %r10
movq 0x10(%rsp), %rcx
movb %r14b, (%rcx,%rbp)
movw $0x2b7, 0x8(%rcx,%rbp)  # imm = 0x2B7
movw $0x11f, 0x57c(%rcx,%rbp) # imm = 0x11F
xorl %edx, %edx
movl %edx, 0x4(%rcx,%rbp)
movq 0x8(%rsp), %rax
movl (%r13,%rax), %eax
movl %eax, 0x7bc(%rcx,%rbp)
movl %r10d, 0x7c0(%rcx,%rbp)
movq %rbp, 0x30(%rsp)
movl %edx, 0x578(%rcx,%rbp)
testq %r12, %r12
movq 0x48(%rsp), %r12
movq 0x38(%rsp), %rbp
movq %r10, 0x40(%rsp)
jle 0x529c2
movsbl %r14b, %eax
movl %eax, 0x18(%rsp)
xorl %r13d, %r13d
movslq (%rbp,%r13,4), %rdx
movb %r14b, 0x43cc(%rbx,%rdx)
movl %r15d, 0x956f0(%rbx,%rdx,4)
movq %r12, %rdi
movl 0x18(%rsp), %esi
callq 0x4e058
movq 0x40(%rsp), %r10
incq %r13
cmpq %r13, %r10
jne 0x52994
leal -0x1(%r10), %eax
cmpl $0x2, %r10d
jl 0x529ec
movl %eax, %ecx
xorl %edx, %edx
movl 0x4(%rbp,%rdx,4), %esi
movslq (%rbp,%rdx,4), %rdi
leaq 0x1(%rdx), %r8
movl %esi, 0x961d0(%rbx,%rdi,4)
movq %r8, %rdx
cmpq %r8, %rcx
jne 0x529d0
movq 0x8(%rsp), %rcx
addq 0x28(%rsp), %rcx
cltq
movq %rcx, 0x8(%rsp)
movslq (%rcx,%rax,4), %rax
movl $0x2b7, 0x961d0(%rbx,%rax,4) # imm = 0x2B7
testl %r10d, %r10d
movq 0x10(%rsp), %r11
movq 0x50(%rsp), %r12
jle 0x52bc0
movq 0x30(%rsp), %rax
leaq (%r11,%rax), %r13
addq $0x8, %r13
leaq 0x4(%r11,%rax), %rcx
movq %rcx, 0x18(%rsp)
addq %r11, %rax
addq $0x578, %rax            # imm = 0x578
movq %rax, 0x68(%rsp)
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movq %rcx, 0x60(%rsp)
movl (%rax,%rcx,4), %ebp
leaq 0x70(%rsp), %rdi
movl %ebp, %esi
callq 0x53e40
movq 0x10(%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 0x52b69
xorb %r14b, %dil
cmpb $0x3, %dil
jne 0x52ba0
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 0x52af0
xorl %r8d, %r8d
movslq %r8d, %r9
movswl 0x8(%rdi,%r9,2), %r8d
cmpl %r8d, %ebp
jne 0x52aad
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 0x52af0
movswq 0x8(%rdi), %r8
movb $0x1, 0x96cb0(%rbx,%r8)
cmpw $0x0, 0x57c(%rdi,%r12,2)
jne 0x52b2c
xorl %r9d, %r9d
movslq %r9d, %r8
movzwl 0x57c(%rdi,%r8,2), %r10d
movswl %r10w, %r9d
cmpl %r9d, %r15d
jg 0x52aff
movw %r10w, 0x57c(%rdi,%r12,2)
movw %r15w, 0x57c(%rdi,%r8,2)
incl 0x578(%rdi)
cmpw $0x0, 0x574(%r13,%rsi,2)
jne 0x52ba0
xorl %edi, %edi
movslq %edi, %r8
movzwl 0x574(%r13,%r8,2), %r9d
movswl %r9w, %edi
cmpl %edi, %edx
jg 0x52b3a
leaq 0x574(,%r8,2), %rdi
addq %r13, %rdi
movw %r9w, 0x574(%r13,%rsi,2)
movq 0x68(%rsp), %rsi
jmp 0x52b9b
cmpw $0x0, (%r13,%rsi,2)
jne 0x52ba0
xorl %edi, %edi
movslq %edi, %r8
movzwl (%r13,%r8,2), %r9d
movswl %r9w, %edi
cmpl %edi, %edx
jg 0x52b74
leaq (,%r8,2), %rdi
addq %r13, %rdi
movw %r9w, (%r13,%rsi,2)
movq 0x18(%rsp), %rsi
movw %dx, (%rdi)
incl (%rsi)
incq %rcx
cmpq $0x4, %rcx
jne 0x52a69
movq 0x60(%rsp), %rcx
incq %rcx
cmpq 0x40(%rsp), %rcx
jne 0x52a46
movq 0x30(%rsp), %rax
addq %r11, %rax
movb $0x1, 0x7c4(%rax)
movq 0x28(%rsp), %r13
movq 0x58(%rsp), %rdx
movl $0x0, 0x1690(%r13,%rdx,4)
incq %rdx
movslq 0x16b0(%r13), %rax
movq 0x38(%rsp), %rcx
addq $0x5a4, %rcx            # imm = 0x5A4
cmpq %rax, %rdx
jl 0x5289c
movl $0x0, 0x16b0(%r13)
movl 0x16b8(%r13), %eax
movl %eax, 0x43c8(%rbx)
movl 0x16bc(%r13), %eax
movl %eax, 0x43c4(%rbx)
decl 0x43b0(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)