// File: 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
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movl $0x0, -0x4(%rbp)
leaq 0x891e(%rip), %rsi      # 0xb037
leaq -0x210(%rbp), %rdi
movl $0x8, %edx
callq 0x2270
leaq -0x230(%rbp), %rdi
callq 0x21e0
movl $0x0, -0x234(%rbp)
movq 0xe889(%rip), %rdi      # 0x10fd0
leaq 0x88f7(%rip), %rsi      # 0xb045
callq 0x2180
jmp 0x2755
jmp 0x2757
jmp 0x2759
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x2050
movq %rax, -0x4e0(%rbp)
jmp 0x2775
movq -0x4e0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20d0
movb %al, -0x4e1(%rbp)
jmp 0x2793
movb -0x4e1(%rbp), %al
testb $0x1, %al
jne 0x279f
jmp 0x27bb
jmp 0x2970
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x2c11
leaq -0x260(%rbp), %rdi
callq 0x2db0
leaq -0x3e0(%rbp), %rdi
leaq -0x230(%rbp), %rsi
movl $0x8, %edx
callq 0x2240
jmp 0x27e1
leaq -0x400(%rbp), %rdi
callq 0x21e0
leaq -0x3e0(%rbp), %rdi
leaq -0x400(%rbp), %rsi
movl $0x9, %edx
callq 0x2280
movq %rax, -0x4f0(%rbp)
jmp 0x280e
movq -0x4f0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21c0
movb %al, -0x4f1(%rbp)
jmp 0x282c
movb -0x4f1(%rbp), %al
testb $0x1, %al
jne 0x2838
jmp 0x287d
leaq -0x260(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x2dd0
jmp 0x284d
jmp 0x27ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x295f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x2947
leaq -0x260(%rbp), %rdi
movl $0x1, %esi
callq 0x2e80
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2e40
movq %rax, -0x500(%rbp)
jmp 0x28a8
xorl %eax, %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x2e80
movq %rax, %rsi
leaq -0x420(%rbp), %rdi
callq 0x20c0
jmp 0x28c9
movq -0x500(%rbp), %rsi
leaq 0xe8a1(%rip), %rdi      # 0x11178
leaq -0x420(%rbp), %rdx
callq 0x76e0
jmp 0x28e5
leaq -0x420(%rbp), %rdi
callq 0x2130
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x2130
leaq -0x3e0(%rbp), %rdi
callq 0x20e0
leaq -0x260(%rbp), %rdi
callq 0x2ea0
jmp 0x2757
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x2130
leaq -0x400(%rbp), %rdi
callq 0x2130
leaq -0x3e0(%rbp), %rdi
callq 0x20e0
leaq -0x260(%rbp), %rdi
callq 0x2ea0
jmp 0x2c11
movq 0xe659(%rip), %rdi      # 0x10fd0
leaq 0x86e3(%rip), %rsi      # 0xb061
callq 0x2180
movq %rax, -0x508(%rbp)
jmp 0x298c
movq -0x508(%rbp), %rdi
movl -0x234(%rbp), %esi
callq 0x2250
movq %rax, -0x510(%rbp)
jmp 0x29a7
movq -0x510(%rbp), %rdi
leaq 0x86b4(%rip), %rsi      # 0xb069
callq 0x2180
jmp 0x29bc
movq 0xe60d(%rip), %rdi      # 0x10fd0
leaq 0x86aa(%rip), %rsi      # 0xb074
callq 0x2180
jmp 0x29d1
leaq 0xe7a0(%rip), %rdi      # 0x11178
xorl %esi, %esi
callq 0x77a0
jmp 0x29e1
movq 0xe5e8(%rip), %rdi      # 0x10fd0
leaq 0x8695(%rip), %rsi      # 0xb084
callq 0x2180
jmp 0x29f6
leaq -0x438(%rbp), %rdi
callq 0x2f00
movl $0x0, -0x43c(%rbp)
movslq -0x43c(%rbp), %rax
movq %rax, -0x518(%rbp)
leaq 0xe757(%rip), %rdi      # 0x11178
callq 0x2c80
movq %rax, %rcx
movq -0x518(%rbp), %rax
cmpq %rcx, %rax
jae 0x2a8f
movslq -0x43c(%rbp), %rsi
leaq 0xe735(%rip), %rdi      # 0x11178
callq 0x2d30
movl (%rax), %eax
movl %eax, -0x440(%rbp)
leaq -0x438(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x2f20
jmp 0x2a65
jmp 0x2a67
movl -0x43c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x43c(%rbp)
jmp 0x2a0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x2c05
leaq -0x458(%rbp), %rdi
leaq -0x438(%rbp), %rsi
callq 0x2f50
jmp 0x2aa4
leaq 0xe6e5(%rip), %rdi      # 0x11190
leaq -0x458(%rbp), %rsi
callq 0x9930
jmp 0x2ab9
leaq -0x458(%rbp), %rdi
callq 0x3040
movq 0xe504(%rip), %rdi      # 0x10fd0
leaq 0x85cd(%rip), %rsi      # 0xb0a0
callq 0x2180
jmp 0x2ada
leaq -0x478(%rbp), %rdi
callq 0x21e0
leaq -0x498(%rbp), %rdi
callq 0x21e0
jmp 0x2af4
movq 0xe4d5(%rip), %rdi      # 0x10fd0
leaq 0x85a5(%rip), %rsi      # 0xb0a7
callq 0x2180
jmp 0x2b09
movq 0xe4d0(%rip), %rdi      # 0x10fe0
leaq -0x478(%rbp), %rsi
callq 0x2050
jmp 0x2b1e
leaq -0x4d8(%rbp), %rdi
leaq -0x478(%rbp), %rsi
callq 0x20c0
jmp 0x2b33
leaq -0x4b8(%rbp), %rdi
leaq -0x4d8(%rbp), %rsi
callq 0x2520
jmp 0x2b48
leaq -0x498(%rbp), %rdi
movq %rdi, -0x520(%rbp)
leaq -0x4b8(%rbp), %rsi
movq %rsi, -0x528(%rbp)
callq 0x21b0
movq -0x528(%rbp), %rdi
callq 0x2130
leaq -0x4d8(%rbp), %rdi
callq 0x2130
movq -0x520(%rbp), %rsi
movq 0xe441(%rip), %rdi      # 0x10fd0
callq 0x2170
jmp 0x2b96
jmp 0x2af2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x458(%rbp), %rdi
callq 0x3040
jmp 0x2c05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x2bed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x4d8(%rbp), %rdi
callq 0x2130
leaq -0x498(%rbp), %rdi
callq 0x2130
leaq -0x478(%rbp), %rdi
callq 0x2130
leaq -0x438(%rbp), %rdi
callq 0x3040
leaq -0x230(%rbp), %rdi
callq 0x2130
leaq -0x210(%rbp), %rdi
callq 0x2070
movq -0x240(%rbp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)
nop