// File: /workspace/github_cpp_makefile_star2_O2/tanakh[P]icfpc2015/main.cpp
// Function: replay(problem const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void replay(const problem &prob, int seed, const string &moves)
{
  vlog() << "replay:" << endl;
  auto bd = make_board(prob);
  rng r(seed);

  const char *p = moves.c_str();
  int move_score = 0;

  for (int turn = 0; turn < prob.source_length && *p; turn++) {
    const unit &u = prob.units[r.get() % prob.units.size()];
    pt pos = get_init_pos(prob, u);
    int rot = 0;
    if (!check(bd, pos, u, rot))
      break;
    vlog() << "*POP*" << endl;
    print_board_(bd, pos, u, rot);

    set<pair<pair<int,int>, set<pair<int,int>>>> prevs;
    prevs.insert(uposs(u, pos, rot));

    for (;*p;) {
      pt npos = pos;
      int nrot = rot;
      char c = *p++;
      command mov = to_command(c);
      switch(mov) {
      case W:   npos += pt(-2, 0); break;
      case E:   npos += pt(2, 0); break;
      case SW:  npos += pt(-1, 1); break;
      case SE:  npos += pt(1, 1); break;
      case CW:  nrot = (nrot + 1) % u.rot_max; break;
      case CCW: nrot = (nrot + u.rot_max - 1) % u.rot_max; break;
      }

      auto tt = uposs(u, npos, nrot);
      if (prevs.count(tt)) {
        vlog() << "ERROR: duplicate positions " << show_command(mov) << "(" << c << ")" << endl;
        return;
      }
      prevs.insert(tt);

      if (check(bd, npos, u, nrot)) {
        pos = npos;
        rot = nrot;
        vlog() << "cmd: " << show_command(mov) << "(" << c << ")" << endl;
        print_board_(bd, pos, u, rot);
      }
      else {
        vlog() << "cmd: LOCK (" << show_command(mov) << ", " << c << ")" << endl;
        move_score += put_unit(bd, pos, u, rot, 0).first;
        print_board(bd);
        break;
      }
    }
  }

  auto psc = power_score(moves);

  vlog() << "move score: " << move_score << endl;
  vlog() << "power score: " << psc << endl;
  vlog() << "total score: " << move_score + psc << endl;

  if (*p)
    vlog() << "ERROR: sequence remains." << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, 0x38(%rsp)
movl %esi, 0x2c(%rsp)
movq %rdi, 0x30(%rsp)
leaq 0x15ca0(%rip), %rdi     # 0x1d698
cmpb $0x0, 0x15c91(%rip)     # 0x1d690
je 0x7a08
movq 0x145e0(%rip), %rdi     # 0x1bfe8
leaq 0xab57(%rip), %rsi      # 0x12566
callq 0x32f0
movq %rax, %rdi
callq 0x3130
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x5a80
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x28(%rsp)
movq 0x30(%rsp), %rax
cmpl 0x40(%rax), %ecx
jge 0x7eb8
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax)
je 0x7eb8
movq %rcx, 0x58(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, %ecx
shrl $0x10, %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %r8
movq 0x10(%rdi), %rax
subq %r8, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
movq %rax, %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
imulq $0x28, %rdx, %r14
addq %r8, %r14
movq %r14, %rsi
callq 0x4d3c
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
movq %r14, 0x10(%rsp)
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x481a
testb %al, %al
je 0x7eb8
cmpb $0x0, 0x15bbe(%rip)     # 0x1d690
leaq 0x15bbf(%rip), %rdi     # 0x1d698
je 0x7ae2
movq 0x14506(%rip), %rdi     # 0x1bfe8
leaq 0xaa85(%rip), %rsi      # 0x1256e
callq 0x32f0
movq %rax, %rdi
callq 0x3130
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x4bc9
andl $0x0, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %rax, 0x80(%rsp)
andq $0x0, 0x88(%rsp)
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x609e
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x10132
movl 0x2c(%rsp), %eax
imull $0x41c64e6d, %eax, %eax # imm = 0x41C64E6D
addl $0x3039, %eax           # imm = 0x3039
movl %eax, 0x2c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xa452
xorl %r13d, %r13d
movq 0x18(%rsp), %r14
movb $0x1, %bl
cmpb $0x0, (%r14)
movq %r14, 0x18(%rsp)
je 0x7e95
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movsbl (%r14), %r14d
movl %r14d, %edi
callq 0x44ae
movl %eax, %r12d
movl %r13d, %ebp
cmpl $0x5, %eax
ja 0x7c1f
movl %r12d, %eax
leaq 0xa59b(%rip), %rcx      # 0x12158
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $-0x2, 0x8(%rsp)
jmp 0x7c07
leal 0x1(%r13), %eax
cltd
movq 0x10(%rsp), %rcx
idivl 0x20(%rcx)
jmp 0x7c1d
movq 0x8(%rsp), %xmm0
paddd 0xa446(%rip), %xmm0     # 0x12030
jmp 0x7bfa
movq 0x8(%rsp), %xmm0
psubd 0xa446(%rip), %xmm0     # 0x12040
movq %xmm0, 0x8(%rsp)
jmp 0x7c07
addl $0x2, 0x8(%rsp)
movl %r13d, %ebp
jmp 0x7c1f
movq 0x10(%rsp), %rax
movl 0x20(%rax), %ecx
leal (%rcx,%r13), %eax
decl %eax
cltd
idivl %ecx
movl %edx, %ebp
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movl %ebp, %ecx
callq 0x609e
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0xa204
testq %rax, %rax
jne 0x7d3e
leaq 0x60(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x10400
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
callq 0x481a
testb %al, %al
je 0x7dd4
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpb $0x0, 0x159fe(%rip)     # 0x1d690
leaq 0x159ff(%rip), %rdi     # 0x1d698
je 0x7ca2
movq 0x14346(%rip), %rdi     # 0x1bfe8
leaq 0xa8e7(%rip), %rsi      # 0x12590
callq 0x32f0
movq %rax, %r13
leaq 0x90(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
callq 0x4431
movq %r13, %rdi
movq %r15, %rsi
callq 0x32c0
leaq 0x40(%rsp), %rbx
movq %rax, %rdi
leaq 0xa8c2(%rip), %rsi      # 0x125a0
callq 0x32f0
movq %rax, %rdi
movl %r14d, %esi
callq 0x3350
movq %rax, %rdi
leaq 0xab84(%rip), %rsi      # 0x1287c
callq 0x32f0
movq %rax, %rdi
callq 0x3130
movq %r15, %rdi
callq 0x3550
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
callq 0x4bc9
movq 0x18(%rsp), %r14
incq %r14
leaq 0xb8(%rsp), %rdi
callq 0xa452
movl %ebp, %r13d
jmp 0x7b81
cmpb $0x0, 0x1594b(%rip)     # 0x1d690
leaq 0x1594c(%rip), %rdi     # 0x1d698
je 0x7d55
movq 0x14293(%rip), %rdi     # 0x1bfe8
leaq 0xa818(%rip), %rsi      # 0x12574
callq 0x32f0
movq %rax, %r15
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4431
movq %r15, %rdi
movq %rbx, %rsi
callq 0x32c0
movq %rax, %rdi
leaq 0xa814(%rip), %rsi      # 0x125a0
callq 0x32f0
movq %rax, %rdi
movl %r14d, %esi
callq 0x3350
movq %rax, %rdi
leaq 0xaad6(%rip), %rsi      # 0x1287c
callq 0x32f0
movq %rax, %rdi
callq 0x3130
incq 0x18(%rsp)
movq %rbx, %rdi
callq 0x3550
leaq 0xb8(%rsp), %rdi
callq 0xa452
xorl %ebx, %ebx
jmp 0x7e95
cmpb $0x0, 0x158b5(%rip)     # 0x1d690
leaq 0x158b6(%rip), %rdi     # 0x1d698
je 0x7deb
movq 0x141fd(%rip), %rdi     # 0x1bfe8
leaq 0xa7a4(%rip), %rsi      # 0x12596
callq 0x32f0
movq %rax, %rbp
leaq 0x90(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
callq 0x4431
movq %rbp, %rdi
movq %r15, %rsi
callq 0x32c0
movq %rax, %rdi
leaq 0xa505(%rip), %rsi      # 0x12327
callq 0x32f0
movq %rax, %rdi
movl %r14d, %esi
callq 0x3350
movq %rax, %rdi
leaq 0xaa40(%rip), %rsi      # 0x1287c
callq 0x32f0
movq %rax, %rdi
callq 0x3130
leaq 0x90(%rsp), %rdi
callq 0x3550
leaq 0x40(%rsp), %r12
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x4874
movq %rax, %r14
movq %r12, %rdi
callq 0x4a6c
incq 0x18(%rsp)
addl %r14d, 0x28(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xa452
leaq 0x60(%rsp), %rdi
callq 0xd03c
movq 0x58(%rsp), %rcx
incl %ecx
testb %bl, %bl
leaq 0x40(%rsp), %rbx
jne 0x7a45
jmp 0x7fa6
movq 0x38(%rsp), %rdi
callq 0x5c2e
movl %eax, %ebp
cmpb $0x0, 0x157c5(%rip)     # 0x1d690
je 0x7ed6
movq 0x14114(%rip), %rdi     # 0x1bfe8
jmp 0x7edd
leaq 0x157bb(%rip), %rdi     # 0x1d698
leaq 0xa6be(%rip), %rsi      # 0x125a2
callq 0x32f0
movq %rax, %rdi
movl 0x28(%rsp), %esi
callq 0x3490
movq %rax, %rdi
callq 0x3130
cmpb $0x0, 0x1578c(%rip)     # 0x1d690
je 0x7f0f
movq 0x140db(%rip), %rdi     # 0x1bfe8
jmp 0x7f16
leaq 0x15782(%rip), %rdi     # 0x1d698
leaq 0xa692(%rip), %rsi      # 0x125af
callq 0x32f0
movq %rax, %rdi
movl %ebp, %esi
callq 0x3490
movq %rax, %rdi
callq 0x3130
cmpb $0x0, 0x15755(%rip)     # 0x1d690
je 0x7f46
movq 0x140a4(%rip), %rdi     # 0x1bfe8
jmp 0x7f4d
leaq 0x1574b(%rip), %rdi     # 0x1d698
leaq 0xa669(%rip), %rsi      # 0x125bd
callq 0x32f0
addl 0x28(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x3490
movq %rax, %rdi
callq 0x3130
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax)
je 0x7fa6
cmpb $0x0, 0x15710(%rip)     # 0x1d690
je 0x7f8b
movq 0x1405f(%rip), %rdi     # 0x1bfe8
jmp 0x7f92
leaq 0x15706(%rip), %rdi     # 0x1d698
leaq 0xa632(%rip), %rsi      # 0x125cb
callq 0x32f0
movq %rax, %rdi
callq 0x3130
leaq 0x40(%rsp), %rdi
callq 0x9958
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7ff4
jmp 0x7ff4
jmp 0x7ff4
jmp 0x7ff4
jmp 0x7ff4
jmp 0x7fdd
jmp 0x7fd4
jmp 0x7fe2
jmp 0x7fe2
movq %rax, %rbx
jmp 0x800e
jmp 0x7ff4
jmp 0x7fdd
movq %rax, %rbx
jmp 0x8004
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x3550
jmp 0x7ff7
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0xa452
leaq 0x60(%rsp), %rdi
callq 0xd03c
leaq 0x40(%rsp), %rdi
callq 0x9958
movq %rbx, %rdi
callq 0x34a0