// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %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, 0x10(%rsp)
leaq 0x95f0(%rdi), %rax
movq %rax, 0x38(%rsp)
leaq (%rcx,%rdi), %r15
addq $0x9593c, %r15          # imm = 0x9593C
movslq 0x956f0(%rdi,%rdx,4), %rax
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
leaq (%rdi,%rax), %rsi
addq $0x95f0, %rsi           # imm = 0x95F0
callq 0x39c00
leaq 0x4718(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x95f8(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0x9b6c(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %r15, 0x8(%rsp)
xorl %edx, %edx
movq %r15, 0x18(%rsp)
movslq 0x16b0(%r15), %rax
cmpq %rax, %rdx
jge 0x3a17b
movsbl 0x16b4(%r15,%rdx), %eax
movl %eax, (%rsp)
xorl 0x10(%rsp), %eax
cmpl $0x3, %eax
jne 0x39f63
movl 0x1690(%r15,%rdx,4), %eax
movq 0x10(%rsp), %rcx
subl %eax, 0x43b4(%rbx,%rcx,4)
movb 0x16b4(%r15,%rdx), %al
movl %eax, (%rsp)
movl 0x1690(%r15,%rdx,4), %r14d
movq %rdx, 0x20(%rsp)
movl 0x16a0(%r15,%rdx,4), %eax
movslq %r14d, %r15
movl %eax, 0x4(%rsp)
cltq
imulq $0x7c8, %rax, %rax      # imm = 0x7C8
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax), %r12
movq 0x48(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
cmpq $0x570, %rdx            # imm = 0x570
je 0x39faf
andw $0x0, (%rcx,%rdx)
addq $0x2, %rdx
jmp 0x39f9b
movsbl (%rsp), %r13d
addq 0x40(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x240, %rcx            # imm = 0x240
je 0x39fcf
andw $0x0, (%rax,%rcx)
addq $0x2, %rcx
jmp 0x39fbb
imulq $0x5a4, 0x20(%rsp), %rax # imm = 0x5A4
movl (%rsp), %ecx
movb %cl, (%r12)
movw $0x2b7, 0x8(%r12)       # imm = 0x2B7
movw $0x11f, 0x57c(%r12) # imm = 0x11F
andl $0x0, 0x4(%r12)
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, 0x28(%rsp)
movl (%rcx,%rax), %eax
movl %eax, 0x7bc(%r12)
movl %r14d, 0x7c0(%r12)
andl $0x0, 0x578(%r12)
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
cmpq %rbp, 0x30(%rsp)
je 0x3a06c
movq 0x8(%rsp), %rax
movslq (%rax,%rbp,4), %rdx
movl (%rsp), %eax
movb %al, 0x43cc(%rbx,%rdx)
movl 0x4(%rsp), %eax
movl %eax, 0x956f0(%rbx,%rdx,4)
movq 0x50(%rsp), %rdi
movl %r13d, %esi
callq 0x36625
incq %rbp
jmp 0x3a035
decl %r14d
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
xorl %eax, %eax
cmpq %rax, %r14
je 0x3a09b
movq 0x8(%rsp), %rdx
movl 0x4(%rdx,%rax,4), %ecx
movslq (%rdx,%rax,4), %rdx
incq %rax
movl %ecx, 0x961d0(%rbx,%rdx,4)
jmp 0x3a07d
movq 0x28(%rsp), %rax
movslq -0x4(%rax,%r15,4), %rax
movl $0x2b7, 0x961d0(%rbx,%rax,4) # imm = 0x2B7
xorl %ecx, %ecx
cmpq 0x30(%rsp), %rcx
je 0x3a14e
movq 0x28(%rsp), %rax
movq %rcx, 0x58(%rsp)
movl (%rax,%rcx,4), %r13d
leaq 0x60(%rsp), %rdi
movl %r13d, %esi
callq 0x3b128
xorl %ebp, %ebp
cmpq $0x4, %rbp
je 0x3a141
movslq 0x60(%rsp,%rbp,4), %rsi
movb 0x43cc(%rbx,%rsi), %al
testb %al, %al
je 0x3a132
xorb (%rsp), %al
cmpb $0x3, %al
jne 0x3a13c
movslq 0x956f0(%rbx,%rsi,4), %r15
imulq $0x7c8, %r15, %r14      # imm = 0x7C8
addq 0x38(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x39b16
movq %r14, %rdi
movl 0x4(%rsp), %esi
callq 0x3a1dc
movq %r12, %rdi
movl %r15d, %esi
callq 0x3a1dc
jmp 0x3a13c
movq %r12, %rdi
xorl %edx, %edx
callq 0x3a1ae
incq %rbp
jmp 0x3a0da
movq 0x58(%rsp), %rcx
incq %rcx
jmp 0x3a0b2
movb $0x1, 0x7c4(%r12)
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rdx
andl $0x0, 0x1690(%r15,%rdx,4)
incq %rdx
addq $0x5a4, 0x8(%rsp)       # imm = 0x5A4
jmp 0x39f1f
andl $0x0, 0x16b0(%r15)
movq 0x16b8(%r15), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x43c4(%rbx)
decl 0x43b0(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq