// File: ef-gy[P]libefgy/include/ef.gy/markov.h
// Function: efgy::markov::chain<char, 1u, std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>, unsigned long>::operator()()
output operator()(void) {
    output rv;
    memory m;

    for (typename std::map<memory, transition>::iterator it =
             transitions.find(m);
         it != transitions.end(); it = transitions.find(m)) {
      counter c = std::accumulate(
          it->second.begin(), it->second.end(), 0,
          [](const counter &v, const std::pair<std::optional<T>, counter> &t)
              -> counter { return v + t.second; });

      c = RNG() % c;

      for (const std::pair<std::optional<T>, counter> &t : it->second) {
        if (c > t.second) {
          c -= t.second;
        } else if (t.first) {
          rv.push_back(*t.first);

          std::transform(
              m.begin() + 1, m.end(), m.begin(),
              [](std::optional<T> &i) -> std::optional<T> { return i; });

          *(m.end() - 1) = t.first;
          break;
        } else {
          return rv;
        }
      }
    }

    throw std::runtime_error("impossible memory state in markov chain.");

    return output();
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0xd8(%rbp)
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x15490
leaq -0x2a(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x35140
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
addq $0x1388, %rdi           # imm = 0x1388
callq 0x38650
movq %rax, -0xb8(%rbp)
jmp 0x3831b
movq -0xb8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x1388, %rdi           # imm = 0x1388
callq 0x35670
movq %rax, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x38680
testb $0x1, %al
jne 0x38353
jmp 0x385a7
leaq -0x38(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x38720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x38740
movq -0xe8(%rbp), %rdi
movq %rax, -0x60(%rbp)
callq 0x38720
movq %rax, %rdi
addq $0x8, %rdi
callq 0x37100
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
xorl %edx, %edx
callq 0x386b0
movl %eax, -0xdc(%rbp)
jmp 0x383a6
movq -0xc8(%rbp), %rdi
movl -0xdc(%rbp), %eax
cltq
movq %rax, -0x58(%rbp)
callq 0x38770
movq %rax, -0xf0(%rbp)
jmp 0x383c7
movq -0xf0(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x58(%rbp)
movq %rdx, -0x58(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x38720
addq $0x8, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x38740
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x37100
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x38830
testb $0x1, %al
jne 0x38421
jmp 0x38567
leaq -0x80(%rbp), %rdi
callq 0x37180
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x38860
jmp 0x3843b
leaq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rax
movq -0x90(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x38486
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x58(%rbp)
jmp 0x38557
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x38600
movq -0x90(%rbp), %rdi
callq 0x35f40
testb $0x1, %al
jne 0x3849b
jmp 0x3852e
movq -0x90(%rbp), %rdi
callq 0x35f60
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x38890
jmp 0x384b5
leaq -0x2a(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x354d0
movq -0x108(%rbp), %rdi
addq $0x2, %rax
movq %rax, -0x100(%rbp)
callq 0x354f0
movq -0x108(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x354d0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
movq %rax, %rdx
callq 0x38900
jmp 0x38507
movq -0x90(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x2a(%rbp), %rdi
callq 0x354f0
movq -0x110(%rbp), %rcx
movw (%rcx), %cx
movw %cx, -0x2(%rax)
jmp 0x38567
movq -0xd8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1a660
leaq -0x28(%rbp), %rdi
callq 0x15680
movq -0xd0(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
jmp 0x38559
leaq -0x80(%rbp), %rdi
callq 0x37eb0
jmp 0x38408
jmp 0x38569
movq -0xc8(%rbp), %rdi
addq $0x1388, %rdi           # imm = 0x1388
leaq -0x2a(%rbp), %rsi
callq 0x38650
movq %rax, -0x118(%rbp)
jmp 0x38589
movq -0x118(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x38326
movl $0x10, %edi
callq 0x5190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x120(%rbp)
leaq 0x65c0(%rip), %rsi      # 0x3eb85
callq 0x5120
jmp 0x385cc
movq -0x120(%rbp), %rdi
movq 0x24a0e(%rip), %rsi     # 0x5cfe8
movq 0x249af(%rip), %rdx     # 0x5cf90
callq 0x5570
jmp 0x38612
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x52c0
leaq -0x28(%rbp), %rdi
callq 0x15680
movq -0x40(%rbp), %rdi
callq 0x55b0
nopw %cs:(%rax,%rax)
nopl (%rax)