// File: huntzhan[P]SAM-PNG/solution.cc
// Function: CreateDOTSource(std::vector<State*, std::allocator<State*>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void CreateDOTSource(const vector<State *> &nodes, const string &text) {

  // init node id.
  unordered_map<State *, string> node_id;
  for (int i = 0; i < nodes.size(); ++i) {
    node_id[nodes[i]] = "t" + to_string(i);
  }

  // head
  fout << "digraph G {" << endl;
  fout << "  rankdir=LR" << endl;
  fout << "  node[shape=\"box\"]" << endl;

  for (int i = 0; i < nodes.size(); ++i) {
    auto node = nodes[i];

    // transitions.
    vector<pair<char, State *>> ordered_trans(
        node->trans().begin(), node->trans().end()
        );
    sort(ordered_trans.begin(), ordered_trans.end());

    for (auto &tran : ordered_trans) {
      char c = tran.first;
      auto child = tran.second;

      fout << "  " << node_id[node] << " -> " << node_id[child]
           << " [label=\"" << c << "\"]"
           << endl;
    }

    // suffix link.
    if (node->link()) {
      fout << "  " << node_id[node] << " -> " << node_id[node->link()]
           << " [color=\"blue\"]"
           << endl;
    }

    // label.
    fout << "  " << node_id[node]
         << " [label=\"";
    if (i == 0) {
      fout << "empty";
    } else {

      auto longest = text.substr(
          node->first_endpos() - node->maxlen() + 1,
          node->maxlen());
      auto shortest = text.substr(
          node->first_endpos() - node->minlen() + 1,
          node->minlen());

      fout << longest << "\\n" << shortest;
    }
    fout << "\"]"
         << endl;
  }

  // tail
  fout << "}" << endl;
  fout.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3b40
movl $0x0, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3b60
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2c80
movl -0x4c(%rbp), %esi
leaq -0x90(%rbp), %rdi
callq 0x3bd0
jmp 0x2bbb
leaq 0xa4c1(%rip), %rsi      # 0xd083
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x3b80
jmp 0x2bd4
movq -0x8(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
callq 0x3d20
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x3cf0
movq %rax, -0x1e0(%rbp)
jmp 0x2bf6
movq -0x1e0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x21f0
leaq -0x70(%rbp), %rdi
callq 0x2328
leaq -0x90(%rbp), %rdi
callq 0x2328
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2b83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x345d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x2c6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2328
leaq -0x90(%rbp), %rdi
callq 0x2328
jmp 0x345d
leaq 0x11779(%rip), %rdi     # 0x14400
leaq 0xa38f(%rip), %rsi      # 0xd01d
callq 0x2140
movq %rax, -0x1e8(%rbp)
jmp 0x2c9c
movq -0x1e8(%rbp), %rdi
movq 0x11316(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x2cb1
leaq 0x11748(%rip), %rdi     # 0x14400
leaq 0xa36a(%rip), %rsi      # 0xd029
callq 0x2140
movq %rax, -0x1f0(%rbp)
jmp 0x2ccd
movq -0x1f0(%rbp), %rdi
movq 0x112e5(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x2ce2
leaq 0x11717(%rip), %rdi     # 0x14400
leaq 0xa346(%rip), %rsi      # 0xd036
callq 0x2140
movq %rax, -0x1f8(%rbp)
jmp 0x2cfe
movq -0x1f8(%rbp), %rdi
movq 0x112b4(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x2d13
movl $0x0, -0xa0(%rbp)
movslq -0xa0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3b60
movq %rax, %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
jae 0x340c
movq -0x8(%rbp), %rdi
movslq -0xa0(%rbp), %rsi
callq 0x3d20
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3880
jmp 0x2d76
leaq -0x100(%rbp), %rdi
callq 0x39e0
movq %rax, -0xc8(%rbp)
movq -0xa8(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x3880
jmp 0x2d9e
leaq -0x140(%rbp), %rdi
callq 0x3a10
movq %rax, -0x108(%rbp)
leaq -0x141(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3d40
movq -0x208(%rbp), %rcx
movq -0xc8(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x3d60
jmp 0x2de7
leaq -0x141(%rbp), %rdi
callq 0x3de0
leaq -0x140(%rbp), %rdi
callq 0x38b0
leaq -0x100(%rbp), %rdi
callq 0x38b0
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x3e40
movq -0x210(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0x3e70
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x3e00
jmp 0x2e4d
leaq -0xc0(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rdi
callq 0x3e40
movq %rax, -0x168(%rbp)
movq -0x160(%rbp), %rdi
callq 0x3e70
movq %rax, -0x170(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x3ea0
testb $0x1, %al
jne 0x2e9d
jmp 0x3055
leaq -0x168(%rbp), %rdi
callq 0x3ee0
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movb (%rax), %al
movb %al, -0x179(%rbp)
movq -0x178(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x188(%rbp)
leaq 0x11528(%rip), %rdi     # 0x14400
leaq 0xa16b(%rip), %rsi      # 0xd04a
callq 0x2140
movq %rax, -0x218(%rbp)
jmp 0x2eed
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3cf0
movq %rax, -0x220(%rbp)
jmp 0x2f06
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdi
callq 0x2120
movq %rax, -0x228(%rbp)
jmp 0x2f22
movq -0x228(%rbp), %rdi
leaq 0xa11d(%rip), %rsi      # 0xd04d
callq 0x2140
movq %rax, -0x230(%rbp)
jmp 0x2f3e
leaq -0x48(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x3cf0
movq %rax, -0x238(%rbp)
jmp 0x2f57
movq -0x238(%rbp), %rsi
movq -0x230(%rbp), %rdi
callq 0x2120
movq %rax, -0x240(%rbp)
jmp 0x2f73
movq -0x240(%rbp), %rdi
leaq 0xa0d1(%rip), %rsi      # 0xd052
callq 0x2140
movq %rax, -0x248(%rbp)
jmp 0x2f8f
movq -0x248(%rbp), %rdi
movsbl -0x179(%rbp), %esi
callq 0x21e0
movq %rax, -0x250(%rbp)
jmp 0x2fab
movq -0x250(%rbp), %rdi
leaq 0xa0b0(%rip), %rsi      # 0xd069
callq 0x2140
movq %rax, -0x258(%rbp)
jmp 0x2fc7
movq -0x258(%rbp), %rdi
movq 0x10feb(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x2fdc
jmp 0x2fde
leaq -0x168(%rbp), %rdi
callq 0x3f00
jmp 0x2e81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x302d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x141(%rbp), %rdi
callq 0x3de0
leaq -0x140(%rbp), %rdi
callq 0x38b0
leaq -0x100(%rbp), %rdi
callq 0x38b0
jmp 0x345d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x33fe
movq -0xa8(%rbp), %rdi
callq 0x37c0
movq %rax, -0x260(%rbp)
jmp 0x306a
movq -0x260(%rbp), %rax
cmpq $0x0, %rax
je 0x3173
leaq 0x1137e(%rip), %rdi     # 0x14400
leaq 0x9fc1(%rip), %rsi      # 0xd04a
callq 0x2140
movq %rax, -0x268(%rbp)
jmp 0x3097
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3cf0
movq %rax, -0x270(%rbp)
jmp 0x30b0
movq -0x270(%rbp), %rsi
movq -0x268(%rbp), %rdi
callq 0x2120
movq %rax, -0x278(%rbp)
jmp 0x30cc
movq -0x278(%rbp), %rdi
leaq 0x9f73(%rip), %rsi      # 0xd04d
callq 0x2140
movq %rax, -0x280(%rbp)
jmp 0x30e8
movq -0xa8(%rbp), %rdi
callq 0x37c0
movq %rax, -0x288(%rbp)
jmp 0x30fd
movq -0x288(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x3f20
movq %rax, -0x290(%rbp)
jmp 0x3124
movq -0x290(%rbp), %rsi
movq -0x280(%rbp), %rdi
callq 0x2120
movq %rax, -0x298(%rbp)
jmp 0x3140
movq -0x298(%rbp), %rdi
leaq 0x9f0e(%rip), %rsi      # 0xd05c
callq 0x2140
movq %rax, -0x2a0(%rbp)
jmp 0x315c
movq -0x2a0(%rbp), %rdi
movq 0x10e56(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x3171
jmp 0x3173
leaq 0x11286(%rip), %rdi     # 0x14400
leaq 0x9ec9(%rip), %rsi      # 0xd04a
callq 0x2140
movq %rax, -0x2a8(%rbp)
jmp 0x318f
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3cf0
movq %rax, -0x2b0(%rbp)
jmp 0x31a8
movq -0x2b0(%rbp), %rsi
movq -0x2a8(%rbp), %rdi
callq 0x2120
movq %rax, -0x2b8(%rbp)
jmp 0x31c4
movq -0x2b8(%rbp), %rdi
leaq 0x9e80(%rip), %rsi      # 0xd052
callq 0x2140
jmp 0x31d9
cmpl $0x0, -0xa0(%rbp)
jne 0x31fc
leaq 0x11217(%rip), %rdi     # 0x14400
leaq 0x9e7c(%rip), %rsi      # 0xd06c
callq 0x2140
jmp 0x31f7
jmp 0x33ad
movq -0x10(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x3720
movl %eax, -0x2bc(%rbp)
jmp 0x321b
movq -0xa8(%rbp), %rdi
callq 0x36f0
movl %eax, -0x2cc(%rbp)
jmp 0x322f
movl -0x2cc(%rbp), %ecx
movl -0x2bc(%rbp), %eax
subl %ecx, %eax
incl %eax
cltq
movq %rax, -0x2d8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x36f0
movl %eax, -0x2d0(%rbp)
jmp 0x325c
movq -0x2d8(%rbp), %rdx
movq -0x2c8(%rbp), %rsi
movl -0x2d0(%rbp), %eax
movslq %eax, %rcx
leaq -0x1b0(%rbp), %rdi
callq 0x2170
jmp 0x3281
movq -0x10(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x3720
movl %eax, -0x2dc(%rbp)
jmp 0x32a0
movq -0xa8(%rbp), %rdi
callq 0x3f50
movl %eax, -0x2ec(%rbp)
jmp 0x32b4
movl -0x2ec(%rbp), %ecx
movl -0x2dc(%rbp), %eax
subl %ecx, %eax
incl %eax
cltq
movq %rax, -0x2f8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x3f50
movl %eax, -0x2f0(%rbp)
jmp 0x32e1
movq -0x2f8(%rbp), %rdx
movq -0x2e8(%rbp), %rsi
movl -0x2f0(%rbp), %eax
movslq %eax, %rcx
leaq -0x1d0(%rbp), %rdi
callq 0x2170
jmp 0x3306
leaq 0x110f3(%rip), %rdi     # 0x14400
leaq -0x1b0(%rbp), %rsi
callq 0x2120
movq %rax, -0x300(%rbp)
jmp 0x3322
movq -0x300(%rbp), %rdi
leaq 0x9d42(%rip), %rsi      # 0xd072
callq 0x2140
movq %rax, -0x308(%rbp)
jmp 0x333e
movq -0x308(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x2120
jmp 0x3353
leaq -0x1d0(%rbp), %rdi
callq 0x2328
leaq -0x1b0(%rbp), %rdi
callq 0x2328
jmp 0x33ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x339f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x2328
leaq -0x1b0(%rbp), %rdi
callq 0x2328
jmp 0x33fe
leaq 0x1104c(%rip), %rdi     # 0x14400
leaq 0x9cae(%rip), %rsi      # 0xd069
callq 0x2140
movq %rax, -0x310(%rbp)
jmp 0x33c9
movq -0x310(%rbp), %rdi
movq 0x10be9(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x33de
leaq -0xc0(%rbp), %rdi
callq 0x3f70
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x2d1d
leaq -0xc0(%rbp), %rdi
callq 0x3f70
jmp 0x345d
leaq 0x10fed(%rip), %rdi     # 0x14400
leaq 0x9c5b(%rip), %rsi      # 0xd075
callq 0x2140
movq %rax, -0x318(%rbp)
jmp 0x3428
movq -0x318(%rbp), %rdi
movq 0x10b8a(%rip), %rsi     # 0x13fc0
callq 0x2180
jmp 0x343d
leaq 0x10fbc(%rip), %rdi     # 0x14400
callq 0x2240
jmp 0x344b
leaq -0x48(%rbp), %rdi
callq 0x3fd0
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x3fd0
movq -0x98(%rbp), %rdi
callq 0x22b0
nopw %cs:(%rax,%rax)