// File: /workspace/github_cpp_makefile_star2_O1/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 0x392d(%rip), %rsi      # 0x6053
leaq 0x270(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2230
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x6877(%rip), %rdi      # 0x8fd0
leaq 0x3901(%rip), %rsi      # 0x6061
movl $0x1b, %edx
callq 0x2160
xorl %r15d, %r15d
leaq 0xf0(%rsp), %r12
leaq 0x8(%rsp), %r13
leaq 0x50(%rsp), %r14
movq 0x270(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %rbx, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x2240
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2937
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq %r12, %rdi
leaq 0xd0(%rsp), %rsi
movl $0x8, %edx
callq 0x21f0
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movl $0x9, %edx
callq 0x2240
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2826
movq %r14, %rdi
movq %r13, %rsi
callq 0x2dac
jmp 0x27fb
movl %r15d, 0x2c(%rsp)
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rbp
callq 0x2040
movq %rax, %r15
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movl $0x0, (%r15)
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x2050
cmpq %rbp, 0x30(%rsp)
je 0x2ba9
movq %rax, %rcx
movl (%r15), %eax
testl %eax, %eax
je 0x287a
cmpl $0x22, %eax
jne 0x2881
jmp 0x2bb5
movl 0x4(%rsp), %eax
movl %eax, (%r15)
movq %rcx, %rbp
movq 0x50(%rsp), %rax
leaq 0xc0(%rsp), %r15
movq %r15, 0xb0(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2ed2
leaq 0x689e(%rip), %rdi      # 0x9158
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3c76
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x28e2
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
leaq 0x270(%rsp), %rbx
movl 0x2c(%rsp), %r15d
je 0x290b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2150
incl %r15d
movq %r12, %rdi
movq 0x66b0(%rip), %rsi      # 0x8fc8
callq 0x2190
leaq 0x168(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x2dea
jmp 0x277f
movq 0x6692(%rip), %rdi      # 0x8fd0
leaq 0x3738(%rip), %rsi      # 0x607d
movl $0x7, %edx
callq 0x2160
movq 0x667a(%rip), %rdi      # 0x8fd0
movl %r15d, %esi
callq 0x2200
leaq 0x3720(%rip), %rsi      # 0x6085
movl $0xa, %edx
movq %rax, %rdi
callq 0x2160
movq 0x6657(%rip), %rdi      # 0x8fd0
leaq 0x3710(%rip), %rsi      # 0x6090
movl $0xf, %edx
callq 0x2160
leaq 0x67c7(%rip), %rdi      # 0x9158
xorl %esi, %esi
callq 0x3d42
movq 0x6631(%rip), %rdi      # 0x8fd0
leaq 0x36fa(%rip), %rsi      # 0x60a0
movl $0x1b, %edx
callq 0x2160
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x6790(%rip), %rax      # 0x9158
cmpq %rax, 0x6791(%rip)      # 0x9160
je 0x2a42
xorl %r15d, %r15d
leaq 0x30(%rsp), %rbx
leaq 0xf0(%rsp), %r14
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
xorl %r13d, %r13d
movl (%rax,%r15), %eax
movl %eax, 0xf0(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x2a12
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x2a1d
movq %rbx, %rdi
movq %r14, %rdx
callq 0x31a6
incq %r13
movq 0x6739(%rip), %rcx      # 0x9160
movq 0x672a(%rip), %rax      # 0x9158
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
addq $0x28, %r15
cmpq %r13, %rcx
ja 0x29ee
leaq 0x78(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2e46
leaq 0x6718(%rip), %rdi      # 0x9170
leaq 0x78(%rsp), %rsi
callq 0x4fca
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2a7c
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x654d(%rip), %rdi      # 0x8fd0
leaq 0x3632(%rip), %rsi      # 0x60bc
movl $0x6, %edx
callq 0x2160
leaq 0x100(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x8(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %rcx, (%rdx)
movq %rax, 0x8(%rdx)
movb %al, 0x10(%rdx)
leaq 0xa0(%rsp), %r15
movq 0x6505(%rip), %r14      # 0x8fd0
movq 0x650e(%rip), %r12      # 0x8fe0
leaq 0xf0(%rsp), %r13
leaq 0x90(%rsp), %rbp
leaq 0x50(%rsp), %rbx
movl $0x8, %edx
movq %r14, %rdi
leaq 0x35cd(%rip), %rsi      # 0x60c3
callq 0x2160
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2240
movq %r15, 0x90(%rsp)
movq 0xf0(%rsp), %rsi
movq 0xf8(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x2ed2
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x250c
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x2170
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2b75
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b92
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x2160
jmp 0x2ae7
leaq 0x351c(%rip), %rdi      # 0x60cc
callq 0x20d0
leaq 0x3510(%rip), %rdi      # 0x60cc
callq 0x21a0
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x2be8
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2be8
jmp 0x2be5
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2c04
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x2c4a
movq 0x100(%rsp), %rsi
incq %rsi
jmp 0x2c40
jmp 0x2c47
movq %rax, %rbx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2c4a
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
jmp 0x2c4a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2cf6
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
jmp 0x2cf6
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2caa
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2caa
jmp 0x2ca7
movq %rax, %rbx
jmp 0x2ce7
movq %rax, %rbx
cmpl $0x0, (%r15)
jne 0x2caa
movl 0x4(%rsp), %eax
movl %eax, (%r15)
jmp 0x2caa
jmp 0x2cf3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2cc6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x62fb(%rip), %rsi      # 0x8fc8
leaq 0xf0(%rsp), %rdi
callq 0x2190
leaq 0x168(%rsp), %rdi
callq 0x2080
leaq 0x50(%rsp), %rdi
callq 0x2dea
jmp 0x2cf6
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d1b
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0x270(%rsp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2210