// File: /workspace/github_cpp_makefile_star2_O3/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), %r14
movq %r14, %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), %rbx
movq 0x270(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %edx
movq %r14, %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 %rbx, %rdi
movq %r13, %rsi
callq 0x2db4
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 0x2baf
movq %rax, %rcx
movl (%r15), %eax
testl %eax, %eax
je 0x287a
cmpl $0x22, %eax
jne 0x2881
jmp 0x2bbb
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), %r14
movq %r14, %rdi
callq 0x2edc
leaq 0x689e(%rip), %rdi      # 0x9158
movq %rbp, %rsi
movq %r14, %rdx
callq 0x3c3a
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), %r14
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 %rbx, %rdi
callq 0x2df2
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 0x3d06
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 0x6798(%rip), %rax      # 0x9160
movq 0x6789(%rip), %rcx      # 0x9158
cmpq %rcx, %rax
je 0x2a48
xorl %r15d, %r15d
leaq 0x30(%rsp), %rbx
leaq 0xf0(%rsp), %r14
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
xorl %r13d, %r13d
movl (%rcx,%r15), %edx
movl %edx, 0xf0(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x2a15
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x2a2e
movq %rbx, %rdi
movq %r14, %rdx
callq 0x317e
movq 0x6739(%rip), %rax      # 0x9160
movq 0x672a(%rip), %rcx      # 0x9158
incq %r13
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
addq $0x28, %r15
cmpq %r13, %rdx
ja 0x29f1
leaq 0x78(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2e50
leaq 0x6712(%rip), %rdi      # 0x9170
leaq 0x78(%rsp), %rsi
callq 0x4f5e
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2a82
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x6547(%rip), %rdi      # 0x8fd0
leaq 0x362c(%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 0x64ff(%rip), %r14      # 0x8fd0
movq 0x6508(%rip), %r12      # 0x8fe0
leaq 0xf0(%rsp), %r13
leaq 0x90(%rsp), %rbp
leaq 0x50(%rsp), %rbx
movl $0x8, %edx
movq %r14, %rdi
leaq 0x35c7(%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 0x2edc
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 0x2b7b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b98
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x2160
jmp 0x2aed
leaq 0x3516(%rip), %rdi      # 0x60cc
callq 0x20d0
leaq 0x350a(%rip), %rdi      # 0x60cc
callq 0x21a0
movq %rax, %r14
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bee
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2bee
jmp 0x2beb
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2c0a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x2c50
movq 0x100(%rsp), %rsi
incq %rsi
jmp 0x2c46
jmp 0x2c4d
movq %rax, %r14
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2c50
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
jmp 0x2c50
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2cfc
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2150
jmp 0x2cfc
movq %rax, %r14
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2cb0
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2cb0
jmp 0x2cad
movq %rax, %r14
jmp 0x2ced
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x2cb0
movl 0x4(%rsp), %eax
movl %eax, (%r15)
jmp 0x2cb0
jmp 0x2cf9
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2ccc
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x62f5(%rip), %rsi      # 0x8fc8
leaq 0xf0(%rsp), %rdi
callq 0x2190
leaq 0x168(%rsp), %rdi
callq 0x2080
leaq 0x50(%rsp), %rdi
callq 0x2df2
jmp 0x2cfc
movq %rax, %r14
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d21
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0x270(%rsp), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x2210