// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, 0x30(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
xorl %ebp, %ebp
leaq 0x40(%rsp), %rbx
leaq 0x29b8(%rip), %r14      # 0x507f
leaq 0x78(%rsp), %r15
leaq 0xb0(%rsp), %r12
xorl %r13d, %r13d
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x3, %rax
cmpq %r13, %rax
jbe 0x273c
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2d0f
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2ceb
movq 0x10(%rsp), %rax
movq (%rax), %rsi
addq %rbp, %rsi
movq %r12, %rdi
callq 0x3d1c
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movq %r15, %rdi
callq 0x2248
movq %rbx, %rdi
callq 0x2248
incq %r13
addq $0x8, %rbp
jmp 0x26d7
leaq 0x5c4d(%rip), %rdi      # 0x8390
leaq 0x28cf(%rip), %rsi      # 0x5019
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x5c32(%rip), %rdi      # 0x8390
leaq 0x28c0(%rip), %rsi      # 0x5025
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x5c17(%rip), %rdi      # 0x8390
leaq 0x28b2(%rip), %rsi      # 0x5032
callq 0x2100
movq %rax, %rdi
callq 0x2080
xorl %r12d, %r12d
leaq 0x78(%rsp), %r15
leaq 0xb0(%rsp), %r13
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x2a56
movq (%rax,%r12,8), %rsi
movq %rsi, (%rsp)
addq $0x18, %rsi
movq %r15, %rdi
callq 0x3480
movq 0x88(%rsp), %r14
movq (%rsp), %rsi
addq $0x18, %rsi
leaq 0x40(%rsp), %rdi
callq 0x3480
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
leaq 0xf(%rsp), %rcx
callq 0x2d68
leaq 0x40(%rsp), %rdi
callq 0x359a
movq %r15, %rdi
callq 0x359a
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x4195
movq %r12, 0x38(%rsp)
movq 0x18(%rsp), %rbx
movq 0x20(%rsp), %r12
cmpq %r12, %rbx
je 0x28cf
movb (%rbx), %bpl
movq 0x8(%rbx), %rax
movq %rax, 0x78(%rsp)
leaq 0x5b49(%rip), %rdi      # 0x8390
leaq 0x27f8(%rip), %rsi      # 0x5046
callq 0x2100
movq %rax, %r14
movq %r13, %rdi
movq %rsp, %rsi
callq 0x3d1c
movq %r14, %rdi
movq %rax, %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x27d3(%rip), %rsi      # 0x5049
callq 0x2100
movq %rax, %r14
movq %r13, %rdi
movq %r15, %rsi
callq 0x3d1c
movq %r14, %rdi
movq %rax, %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x27b0(%rip), %rsi      # 0x504e
callq 0x2100
movsbl %bpl, %esi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
leaq 0x27ac(%rip), %rsi      # 0x5065
callq 0x2100
movq %rax, %rdi
callq 0x2080
addq $0x10, %rbx
jmp 0x282b
movq (%rsp), %rax
cmpq $0x0, 0x10(%rax)
movq 0x38(%rsp), %r12
je 0x2957
leaq 0x5aaa(%rip), %rdi      # 0x8390
leaq 0x2759(%rip), %rsi      # 0x5046
callq 0x2100
movq %rax, %r14
movq %r13, %rdi
movq %rsp, %rsi
callq 0x3d1c
movq %r14, %rdi
movq %rax, %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x2734(%rip), %rsi      # 0x5049
callq 0x2100
movq %rax, %r14
movq (%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x78(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x47a8
movq %r14, %rdi
movq %rax, %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x270e(%rip), %rsi      # 0x5058
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x5a32(%rip), %rdi      # 0x8390
leaq 0x26e1(%rip), %rsi      # 0x5046
callq 0x2100
movq %rax, %r14
movq %r13, %rdi
movq %rsp, %rsi
callq 0x3d1c
movq %r14, %rdi
movq %rax, %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x26c1(%rip), %rsi      # 0x504e
callq 0x2100
testq %r12, %r12
je 0x2a16
movq (%rsp), %rax
movl 0x8(%rax), %edx
movslq (%rax), %rcx
subl %ecx, %edx
incl %edx
movslq %edx, %rdx
movq %r15, %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0x2130
movq (%rsp), %rax
movl 0x8(%rax), %edx
movslq 0x4(%rax), %rcx
subl %ecx, %edx
incl %edx
movslq %edx, %rdx
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x2130
leaq 0x59b2(%rip), %rdi      # 0x8390
movq %r15, %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x267e(%rip), %rsi      # 0x506e
callq 0x2100
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x20f0
leaq 0x40(%rsp), %rdi
callq 0x2248
movq %r15, %rdi
callq 0x2248
jmp 0x2a29
leaq 0x5973(%rip), %rdi      # 0x8390
leaq 0x2644(%rip), %rsi      # 0x5068
callq 0x2100
leaq 0x5960(%rip), %rdi      # 0x8390
leaq 0x262e(%rip), %rsi      # 0x5065
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x18(%rsp), %rdi
callq 0x40dc
incq %r12
jmp 0x279d
leaq 0x5933(%rip), %rdi      # 0x8390
leaq 0x260d(%rip), %rsi      # 0x5071
callq 0x2100
movq %rax, %rdi
callq 0x2080
leaq 0x5918(%rip), %rdi      # 0x8390
callq 0x21a0
leaq 0xb0(%rsp), %rdi
callq 0x364e
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ae3
movq %rax, %rbx
jmp 0x2af5
jmp 0x2b05
movq %rax, %rbx
jmp 0x2ab9
jmp 0x2ae3
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x359a
leaq 0x78(%rsp), %rdi
callq 0x359a
jmp 0x2b12
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2248
jmp 0x2ad7
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2248
jmp 0x2b12
movq %rax, %rbx
jmp 0x2b12
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2248
leaq 0x78(%rsp), %rdi
callq 0x2248
jmp 0x2b08
jmp 0x2b05
jmp 0x2b05
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x40dc
leaq 0xb0(%rsp), %rdi
callq 0x364e
movq %rbx, %rdi
callq 0x2210