// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl %esi, 0x34(%rsp)
movq %rdi, 0x58(%rsp)
cmpb $0x0, 0x15644(%rip)     # 0x1e680
je 0x9047
movq 0x13fa3(%rip), %rbx     # 0x1cfe8
jmp 0x904e
leaq 0x1563a(%rip), %rbx     # 0x1e688
leaq 0xc519(%rip), %rsi      # 0x1556e
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
leaq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rbx
movq %rbx, %rsi
callq 0x6611
movq %r14, 0xa8(%rsp)
movq (%r14), %r15
cmpl $0x0, 0x40(%rbx)
jle 0x9577
leaq 0x60(%rsp), %rbx
movl $0x0, 0x1c(%rsp)
xorl %ebp, %ebp
cmpb $0x0, (%r15)
je 0x957f
movl %ebp, 0x30(%rsp)
movl 0x34(%rsp), %eax
shrl $0x10, %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movq 0x58(%rsp), %rdi
movq 0x8(%rdi), %rcx
movq 0x10(%rdi), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rsi
xorl %edx, %edx
divq %rsi
leaq (%rdx,%rdx,4), %rax
leaq (%rcx,%rax,8), %r14
movq %r14, %rsi
callq 0x5805
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
movq %r14, 0x20(%rsp)
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x504f
testb %al, %al
je 0x957f
cmpb $0x0, 0x15545(%rip)     # 0x1e680
leaq 0x15546(%rip), %rbx     # 0x1e688
je 0x914b
movq 0x13e9d(%rip), %rbx     # 0x1cfe8
movl $0x5, %edx
movq %rbx, %rdi
leaq 0xc41c(%rip), %rsi      # 0x15576
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x5678
movl $0x0, 0x80(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x88(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rax, 0x98(%rsp)
movq %rcx, 0xa0(%rsp)
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
leaq 0x28(%rsp), %rdx
xorl %ecx, %ecx
callq 0x7046
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x12a2e
leaq 0xb8(%rsp), %rdi
callq 0xc97e
cmpb $0x0, (%r15)
je 0x9526
movq %r15, %rax
movq 0x28(%rsp), %r15
incq %rax
xorl %r12d, %r12d
movq %r15, 0x10(%rsp)
movq %rax, %r14
movb -0x1(%rax), %bpl
movsbl %bpl, %edi
callq 0x4cdd
movl %eax, %r13d
movl %r12d, %ebx
cmpl $0x5, %eax
ja 0x92a5
movq %r15, %rax
shrq $0x20, %rax
movl %r13d, %ecx
leaq 0xbf28(%rip), %rdx      # 0x15178
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leal -0x2(%r15), %eax
jmp 0x9289
leal 0x1(%r12), %eax
cltd
movq 0x20(%rsp), %rcx
idivl 0x20(%rcx)
jmp 0x92a3
leal -0x1(%r15), %ecx
jmp 0x9279
leal 0x1(%r15), %ecx
movl %ecx, 0x10(%rsp)
incl %eax
movl %eax, 0x14(%rsp)
jmp 0x928d
leal 0x2(%r15), %eax
movl %eax, 0x10(%rsp)
movl %r12d, %ebx
jmp 0x92a5
movq 0x20(%rsp), %rax
movl 0x20(%rax), %ecx
leal (%r12,%rcx), %eax
decl %eax
cltd
idivl %ecx
movl %edx, %ebx
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
movq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movl %ebx, %ecx
callq 0x7046
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x12c08
leaq 0x80(%rsp), %rcx
cmpq %rcx, %rax
jne 0x955e
leaq 0x78(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x12c72
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %ebx, %ecx
callq 0x504f
testb %al, %al
je 0x9420
movq 0x10(%rsp), %r15
movq %r15, 0x28(%rsp)
cmpb $0x0, 0x15360(%rip)     # 0x1e680
leaq 0x15361(%rip), %r12     # 0x1e688
je 0x9330
movq 0x13cb8(%rip), %r12     # 0x1cfe8
movl $0x5, %edx
movq %r12, %rdi
leaq 0xc259(%rip), %rsi      # 0x15598
callq 0x3350
leaq 0x38(%rsp), %rdi
movl %r13d, %esi
callq 0x4c55
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r12, %rdi
callq 0x3350
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc233(%rip), %rsi      # 0x155a8
callq 0x3350
movb %bpl, 0xf(%rsp)
movl $0x1, %edx
movq %r12, %rdi
leaq 0xf(%rsp), %rsi
callq 0x3350
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc4e1(%rip), %rsi      # 0x15884
callq 0x3350
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x93e4
callq 0x32f0
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %ebx, %ecx
callq 0x5678
leaq 0xb8(%rsp), %rdi
callq 0xc97e
leaq 0x1(%r14), %rax
cmpb $0x0, (%r14)
movl %ebx, %r12d
jne 0x921f
movq %r14, %r15
jmp 0x9526
cmpb $0x0, 0x15259(%rip)     # 0x1e680
leaq 0x1525a(%rip), %rbx     # 0x1e688
je 0x9437
movq 0x13bb1(%rip), %rbx     # 0x1cfe8
movl $0xb, %edx
movq %rbx, %rdi
leaq 0xc158(%rip), %rsi      # 0x1559e
callq 0x3350
movq %r14, %r15
leaq 0x38(%rsp), %rdi
movl %r13d, %esi
callq 0x4c55
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x3350
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xbeb0(%rip), %rsi      # 0x1532f
callq 0x3350
movb %bpl, 0xf(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
leaq 0xf(%rsp), %rsi
callq 0x3350
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc3d7(%rip), %rsi      # 0x15884
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x94ed
callq 0x32f0
leaq 0x60(%rsp), %r14
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x5135
movq %rax, %rbx
movq %r14, %rdi
callq 0x54ac
addl %ebx, 0x1c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xc97e
movl 0x30(%rsp), %ebp
movl 0x34(%rsp), %eax
imull $0x41c64e6d, %eax, %eax # imm = 0x41C64E6D
addl $0x3039, %eax           # imm = 0x3039
movl %eax, 0x34(%rsp)
leaq 0x78(%rsp), %rdi
callq 0xf9b4
incl %ebp
movq 0x58(%rsp), %rax
cmpl 0x40(%rax), %ebp
leaq 0x60(%rsp), %rbx
jl 0x90bf
jmp 0x957f
cmpb $0x0, 0x1511b(%rip)     # 0x1e680
je 0x96da
movq 0x13a76(%rip), %rbx     # 0x1cfe8
jmp 0x96e1
movl $0x0, 0x1c(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x6821
movl %eax, %ebx
cmpb $0x0, 0x150eb(%rip)     # 0x1e680
je 0x95a0
movq 0x13a4a(%rip), %r14     # 0x1cfe8
jmp 0x95a7
leaq 0x150e1(%rip), %r14     # 0x1e688
leaq 0xbffc(%rip), %rsi      # 0x155aa
movl $0xc, %edx
movq %r14, %rdi
callq 0x3350
movq %r14, %rdi
movl 0x1c(%rsp), %esi
callq 0x3490
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
cmpb $0x0, 0x15088(%rip)     # 0x1e680
je 0x9603
movq 0x139e7(%rip), %r14     # 0x1cfe8
jmp 0x960a
leaq 0x1507e(%rip), %r14     # 0x1e688
leaq 0xbfa6(%rip), %rsi      # 0x155b7
movl $0xd, %edx
movq %r14, %rdi
callq 0x3350
movq %r14, %rdi
movl %ebx, %esi
callq 0x3490
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
cmpb $0x0, 0x15027(%rip)     # 0x1e680
je 0x9664
movq 0x13986(%rip), %r14     # 0x1cfe8
jmp 0x966b
leaq 0x1501d(%rip), %r14     # 0x1e688
leaq 0xbf53(%rip), %rsi      # 0x155c5
movl $0xd, %edx
movq %r14, %rdi
callq 0x3350
addl 0x1c(%rsp), %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x3490
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
cmpb $0x0, (%r15)
je 0x97ed
cmpb $0x0, 0x14fb8(%rip)     # 0x1e680
je 0x97ab
movq 0x13913(%rip), %rbx     # 0x1cfe8
jmp 0x97b2
leaq 0x14fa7(%rip), %rbx     # 0x1e688
leaq 0xbe94(%rip), %rsi      # 0x1557c
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x3350
leaq 0x38(%rsp), %rdi
movl %r13d, %esi
callq 0x4c55
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x3350
movq %rax, %rbx
leaq 0xbe8a(%rip), %rsi      # 0x155a8
movl $0x1, %edx
movq %rax, %rdi
callq 0x3350
leaq 0xf(%rsp), %rsi
movb %bpl, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3350
movq %rax, %rbx
leaq 0xc13a(%rip), %rsi      # 0x15884
movl $0x1, %edx
movq %rax, %rdi
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x9792
callq 0x32f0
leaq 0xb8(%rsp), %rdi
callq 0xc97e
leaq 0x78(%rsp), %rdi
callq 0xf9b4
jmp 0x97ed
leaq 0x14ed6(%rip), %rbx     # 0x1e688
leaq 0xbe1a(%rip), %rsi      # 0x155d3
movl $0x18, %edx
movq %rbx, %rdi
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
leaq 0x60(%rsp), %rdi
callq 0xbbae
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x982b
jmp 0x982b
jmp 0x982b
jmp 0x982b
jmp 0x982b
jmp 0x982b
jmp 0x9826
jmp 0x9830
jmp 0x9830
jmp 0x981d
movq %rax, %rbx
jmp 0x985e
jmp 0x982b
jmp 0x9826
movq %rax, %rbx
jmp 0x9854
movq %rax, %rbx
jmp 0x9847
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x9847
callq 0x32f0
leaq 0xb8(%rsp), %rdi
callq 0xc97e
leaq 0x78(%rsp), %rdi
callq 0xf9b4
leaq 0x60(%rsp), %rdi
callq 0xbbae
movq %rbx, %rdi
callq 0x34a0