// File: /workspace/github_cpp_makefile_star2_O2/onfe[P]Completionist/src/completionist.cpp
// Function: main
int main() {
  ifstream infile("txt/words.txt");
  string line;
  int pcount = 0;

  cout << "Loading phrases from file.\n";

  while (true) {
      if (!getline(infile, line)) break;
      std::vector<string> tokens;
      std::istringstream iss(line);
      string token;
      while(getline(iss, token, '\t')) {
        tokens.push_back(token);
      }
      // cout << tokens[1] << " : " << tokens[0] << "\n";
      pl.insert(std::stoll(tokens[1]), tokens[0]);
      pcount++;
  }

  cout << "Loaded " << pcount << " phrases.\n";
  cout << "Sorting words.\n";

  pl.finish();

  cout << "Constructing Segment Tree.\n";

  vector<uint32_t> weights;
  for (int i = 0; i < pl.pl.size(); ++i) {
    weights.push_back(pl.pl[i].weight);
  }

  st.init(weights);

  cout << "Done.\n";

  string inp;
  string out;
  while (true) {
    cout << "\nQuery: ";
    getline(cin, inp);
    out = complete(inp);
    cout << out;
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
leaq 0x2a9f(%rip), %rsi      # 0x5053
leaq 0x270(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2210
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x59f1(%rip), %rdi      # 0x7fd0
leaq 0x2a7b(%rip), %rsi      # 0x5061
callq 0x2120
movq $0x0, 0x8(%rsp)
leaq 0xf0(%rsp), %r12
leaq 0x10(%rsp), %r13
pushq $0x9
popq %r14
leaq 0x30(%rsp), %rbp
leaq 0xd0(%rsp), %r15
leaq 0x270(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x26fe
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq %r12, %rdi
leaq 0x90(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x21e0
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2698
movq %rbp, %rdi
movq %r13, %rsi
callq 0x29c0
jmp 0x266f
movq 0x30(%rsp), %rdi
addq $0x20, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x29ec
movq %rax, %rbx
movq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x2180
leaq 0x5a86(%rip), %rdi      # 0x8148
movq %rbx, %rsi
movq %r15, %rdx
callq 0x38ae
movq %r15, %rdi
callq 0x20a0
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq %r13, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x20b0
movq %rbp, %rdi
callq 0x2a08
jmp 0x2612
movq 0x58cb(%rip), %rdi      # 0x7fd0
leaq 0x2971(%rip), %rsi      # 0x507d
callq 0x2120
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x21f0
leaq 0x2960(%rip), %rsi      # 0x5085
movq %rax, %rdi
callq 0x2120
movq 0x589c(%rip), %rdi      # 0x7fd0
leaq 0x2955(%rip), %rsi      # 0x5090
callq 0x2120
leaq 0x5a01(%rip), %rdi      # 0x8148
xorl %esi, %esi
callq 0x392c
movq 0x587b(%rip), %rdi      # 0x7fd0
leaq 0x2944(%rip), %rsi      # 0x50a0
callq 0x2120
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
xorl %r15d, %r15d
pushq $0x28
popq %r12
leaq 0xf0(%rsp), %r14
xorl %r13d, %r13d
movq 0x59c6(%rip), %rax      # 0x8150
movq 0x59b7(%rip), %rcx      # 0x8148
subq %rcx, %rax
cqto
idivq %r12
cmpq %r13, %rax
jbe 0x27bd
movl (%rcx,%r15), %eax
movl %eax, 0xf0(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2e3a
incq %r13
addq $0x28, %r15
jmp 0x2783
leaq 0x58(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2a2a
leaq 0x598d(%rip), %rdi      # 0x8160
leaq 0x58(%rsp), %rsi
callq 0x448a
leaq 0x58(%rsp), %rdi
callq 0x2e06
movq 0x57e2(%rip), %rdi      # 0x7fd0
leaq 0x28c7(%rip), %rsi      # 0x50bc
callq 0x2120
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x10(%rsp), %rbx
leaq 0x20(%rsp), %rdx
movq %rdx, (%rbx)
andq $0x0, 0x8(%rbx)
movb %cl, (%rax)
movb %cl, 0x10(%rbx)
movq 0x57a5(%rip), %r14      # 0x7fd0
movq 0x57ae(%rip), %r12      # 0x7fe0
leaq 0xf0(%rsp), %r13
leaq 0xb0(%rsp), %rbp
leaq 0x30(%rsp), %r15
movq %r14, %rdi
leaq 0x2872(%rip), %rsi      # 0x50c3
callq 0x2120
movq %r12, %rdi
movq %r13, %rsi
callq 0x2050
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2180
movq %r15, %rdi
movq %rbp, %rsi
callq 0x243c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2150
movq %r15, %rdi
callq 0x20a0
movq %rbp, %rdi
callq 0x20a0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2110
jmp 0x2847
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x20a0
jmp 0x28b6
jmp 0x28b3
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20a0
leaq 0xf0(%rsp), %rdi
callq 0x20a0
jmp 0x28e3
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x2e06
jmp 0x28e3
jmp 0x28e0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2e06
jmp 0x2933
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x20a0
jmp 0x290d
movq %rax, %rbx
jmp 0x2924
jmp 0x2930
jmp 0x290a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20a0
leaq 0xf0(%rsp), %rdi
callq 0x20b0
leaq 0x30(%rsp), %rdi
callq 0x2a08
jmp 0x2933
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x20a0
leaq 0x270(%rsp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2200
nop