// File: /workspace/github_cpp_makefile_star2_O2/UBOdin[P]jitd-cpp/src/jitd_tester.cpp
// Function: jitd_test(JITD<Record, PureLocalPolicy<Record>>&, std::istream&, bool, int)
int jitd_test(
  JITD<Record, JITD_TEST_POLICY> &jitd, 
  istream &input, 
  bool interactive, 
  int per_op_sleep_ms
) {
  string line;
  vector<std::thread> threads;
  
  timeval global_start, global_end;
  gettimeofday(&global_start, NULL);
  
  if(interactive) { cout << "jitd> "; cout.flush(); }
  while(getline(input, line)){
    istringstream toks(line);
    string op;
    
    CASE_1("--") {
      // comment, ignore
      
    ///////////////// MUTATOR OPERATIONS /////////////////
    } CASE("init") {
      timeval start, end;
      RecordBuffer data = buffer_cmd(toks);
      gettimeofday(&start, NULL);
      jitd.init(data);
      gettimeofday(&end, NULL);
      cout << "Init JITD: " << total_time(start, end) << " us" << endl;
    } CASE("insert") {
      timeval start, end;
      RecordBuffer data = buffer_cmd(toks);
      gettimeofday(&start, NULL);
      jitd.insert(data);
      gettimeofday(&end, NULL);
      cout << "Insert into JITD: " << total_time(start, end) << " us" << endl;
    } CASE("remove") {
      timeval start, end;
      RecordBuffer data = buffer_cmd(toks);
      gettimeofday(&start, NULL);
      jitd.remove(data);
      gettimeofday(&end, NULL);
      cout << "Delete from JITD: " << total_time(start, end) << " us" << endl;

    ///////////////// POLICY OPERATIONS /////////////////    
    } CASE("policy_set") {
      
      CASE_1("cracksort"){
        int threshold;
        toks >> threshold;
        cout << "Switching to Crack/Sort Policy with Threshold of " << threshold << endl;
        jitd.getPolicy()->setScoreFunction(
          std::bind(CrackOrSortArraysBigFirst<Record>, threshold, std::placeholders::_1)
        );
        jitd.reinitPolicy();
      } else {
        cerr << "Invalid Policy " << op << endl;
        exit(-1);
      }

    } CASE("policy_act_once") {
      timeval start, end;
      jitd.getPolicy()->describeNext();
      JITD_TEST_POLICY *policy = jitd.getPolicy();
      gettimeofday(&start, NULL);
      policy->act();
      gettimeofday(&end, NULL);
      cout << "Policy Action: " << total_time(start, end) << " us" << endl;

    } CASE("policy_act_for") {
      int target_steps;
      double used_microseconds = 0;
      timeval start, end;
      JITD_TEST_POLICY *policy = jitd.getPolicy();

      toks >> target_steps;

      for(int x = 0; x < target_steps; x++){
        gettimeofday(&start, NULL);
        policy->act();
        gettimeofday(&end, NULL);
        used_microseconds += total_time(start, end);
      }

      cout << "Policy " << target_steps << " Actions: " << used_microseconds << " us" << endl;

    } CASE("policy_act_until_done") {
      bool more_work_to_do = true;
      int steps_taken;
      timeval start, end;
      JITD_TEST_POLICY *policy = jitd.getPolicy();

      gettimeofday(&start, NULL);
      while(more_work_to_do){
        steps_taken++;
        more_work_to_do = policy->act();
      }
      gettimeofday(&end, NULL);
      cout << "Policy " << steps_taken << " Actions: " << total_time(start, end) << " us" << endl;


    ///////////////// ACCESS OPERATIONS /////////////////    
    } CASE("scan") {
      Iterator<Record> iter = jitd.iterator();
      timeval start, end;
      int idx = 0;
      
      while(!toks.eof() && !iter->atEnd()){
        CASE_1("flush") { // no argument
          int startidx = idx;
          gettimeofday(&start, NULL);
          while(!iter->atEnd()){ iter->next(); idx++; }
          gettimeofday(&end, NULL);
          cout << "Records Flushed: " << (idx - startidx) << endl;
          cout << "Flush Time: " << total_time(start, end) << " us" << endl;
        } CASE("full") { // no argument
          while(!iter->atEnd()){ 
            cout << idx << " -> " << iter->get()->key << endl;
            iter->next(); 
            idx++; 
          }
        } CASE("step") { // no argument
          cout << idx << " -> " << iter->get()->key << endl;
          idx++;
          iter->next();
        } CASE("next") { // [CNT]
          int cnt;
          for(toks >> cnt; (cnt > 0) && !iter->atEnd(); cnt--){
            cout << idx << " -> " << iter->get()->key << endl;
            idx++;
            iter->next();
          }
        } CASE("quiet_next") { // [CNT]
          int cnt, startidx = idx;
          for(toks >> cnt; (cnt > 0) && !iter->atEnd(); cnt--){ 
            idx++;
            iter->next();
          }
        } CASE("seek") { // [TARGET]
          Record target;
          toks >> target.key;
          target.value = NULL;
          gettimeofday(&start, NULL);
          iter->seek(target);
          gettimeofday(&end, NULL);
          cout << "Seek Time: " << total_time(start, end) << " us" << endl;
        } CASE("quiet_seek") { // [TARGET]
          Record target;
          toks >> target.key;
          target.value = NULL;
          iter->seek(target);
        }
      }
    } CASE("random_scan") {
      int time_in_ms, max_key, key_cnt;
      long int scan_count = 0;
      timeval start, end;
      Record target;
      target.value = NULL;
      toks >> time_in_ms >> max_key >> key_cnt;
      gettimeofday(&start, NULL);
      gettimeofday(&end, NULL);
      
      cout << "Scanning for " << time_in_ms << " s in [0,"
           << max_key << ") -> " << key_cnt << " keys/read" << endl;
      while(total_time(start, end) < time_in_ms*1000){
        Iterator<Record> iter = jitd.iterator();
        target.key = rand() % max_key;
        iter->seek(target);
        for(; key_cnt > 0; key_cnt--) { iter->next(); }
        scan_count++;
        
        gettimeofday(&end, NULL);
      }
      cout << "Random Scan: " << scan_count << " scans over "
           << total_time(start, end)/(1000*1000) << " s" << endl 
           << "Rate: " 
             << ((1000*1000*scan_count) / total_time(start, end))
             << " scans/sec" << endl;
    
    } CASE("spawn") {
      string file;
      toks >> file;
      threads.emplace_back(run_test_thread, &jitd, file, 0);

    } CASE("spawn_slow") {
      int delay_ms;
      string file;
      toks >> delay_ms >> file;
      threads.emplace_back(run_test_thread, &jitd, file, delay_ms);
    
    } CASE("spawn_updates") {
      Key max_key;
      int size;
      long int low_mark;
      long int high_mark;
      int seed = 42;
      int per_op_sleep_ms;
      int runtime_ms;
      
      toks >> max_key >> size >> low_mark >> high_mark >> per_op_sleep_ms >> runtime_ms;
      
      threads.emplace_back(run_update_thread, &jitd, max_key, size, low_mark, high_mark, seed, per_op_sleep_ms, runtime_ms);

    } CASE("run") {
      string file;
      toks >> file;
      run_test_thread(&jitd, file, per_op_sleep_ms);

    } CASE("time") {
      timeval end; 
      gettimeofday(&end, NULL);
      cout << "Time now: " << total_time(global_start, end)/(1000*1000) << endl;
    
    } CASE("sleep") {
      int ms;
      toks >> ms;
      this_thread::sleep_for(chrono::milliseconds(ms));
      
    } CASE("size") {
      cout << jitd.size() << " records" << endl;
    } CASE("dump") {
      jitd.printDebug();
      
    ///////////////// OOOPS /////////////////
    } else {
      cerr << "Invalid Test Operation: " << op << endl;
      exit(-1);
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movl %ecx, -0x68(%rbp)
movl %edx, %ebx
leaq -0x168(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, -0xf8(%rbp)
movq %rdi, -0x48(%rbp)
movb $0x0, (%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, -0xe0(%rbp)
andq $0x0, -0xd0(%rbp)
leaq -0x158(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movl %ebx, -0xb8(%rbp)
testl %ebx, %ebx
je 0x83e6
movq 0xdbfa(%rip), %rdi      # 0x15fc8
leaq 0x6206(%rip), %rsi      # 0xe5db
callq 0x4260
movq 0xdbe7(%rip), %rdi      # 0x15fc8
callq 0x41a0
movq -0x48(%rbp), %rax
leaq 0x10(%rax), %rcx
movq %rcx, -0xa8(%rbp)
addq $0x30, %rax
movq %rax, -0xe8(%rbp)
movl -0x68(%rbp), %eax
movq %rax, -0xf0(%rbp)
leaq -0x118(%rbp), %r14
leaq -0x90(%rbp), %r15
movq 0xdba9(%rip), %r13      # 0x15fc8
movq -0xf8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x4050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x9549
leaq -0x348(%rbp), %rbx
movq %rbx, %rdi
leaq -0x178(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x43a0
leaq -0x108(%rbp), %rax
movq %rax, -0x118(%rbp)
andq $0x0, -0x110(%rbp)
movb $0x0, -0x108(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x42e0
movq %r15, %rdi
leaq 0x5bfe(%rip), %rsi      # 0xe08d
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
jne 0x8705
movq %r15, %rdi
leaq 0x6123(%rip), %rsi      # 0xe5e2
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x8579
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
leaq -0x348(%rbp), %rsi
callq 0xd09e
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
leaq -0x148(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5a64
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x9c6e
leaq -0x140(%rbp), %rdi
callq 0x59d4
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x60a6(%rip), %rsi      # 0xe5e7
callq 0x4260
movq %rax, %rbx
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
movq %rbx, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x5b52(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x86fc
movq %r15, %rdi
leaq 0x5ba5(%rip), %rsi      # 0xe128
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x863d
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
leaq -0x348(%rbp), %rsi
callq 0xd09e
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
leaq -0x138(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5a64
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x989e
leaq -0x130(%rbp), %rdi
callq 0x59d4
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x5fee(%rip), %rsi      # 0xe5f3
callq 0x4260
movq %rax, %rbx
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
movq %rbx, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x5a8e(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x86fc
movq %r15, %rdi
leaq 0x5fbf(%rip), %rsi      # 0xe606
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x875a
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
leaq -0x348(%rbp), %rsi
callq 0xd09e
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
leaq -0x128(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5a64
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x9a58
leaq -0x120(%rbp), %rdi
callq 0x59d4
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x5f44(%rip), %rsi      # 0xe60d
callq 0x4260
movq %rax, %rbx
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
movq %rbx, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x59ca(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
leaq -0x58(%rbp), %rdi
callq 0x59d4
cmpb $0x0, -0xb8(%rbp)
je 0x8725
movq %r13, %rdi
leaq 0x5ec3(%rip), %rsi      # 0xe5db
callq 0x4260
movq %r13, %rdi
callq 0x41a0
cmpl $0x0, -0x68(%rbp)
jle 0x8741
movq -0xf0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq %r15, %rdi
callq 0x9c12
movq %r14, %rdi
callq 0x4110
leaq -0x348(%rbp), %rdi
callq 0x4130
jmp 0x841f
movq %r15, %rdi
leaq 0x5ebc(%rip), %rsi      # 0xe620
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x8849
leaq -0x348(%rbp), %rdi
movq %r14, %rsi
callq 0x42e0
movq %r15, %rdi
leaq 0x5e88(%rip), %rsi      # 0xe62b
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x95c0
leaq -0x348(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4160
movq %r13, %rdi
leaq 0x5e52(%rip), %rsi      # 0xe635
callq 0x4260
movl -0x38(%rbp), %esi
movq %rax, %rdi
callq 0x43d0
movq %rax, %rdi
callq 0x4140
leaq 0x1554(%rip), %rax      # 0x9d56
movq %rax, -0x90(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0x1c8(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9dee
movq -0xe8(%rbp), %rdi
movq %rbx, %rsi
callq 0xb68a
movq %rbx, %rdi
callq 0xb06c
movq -0x48(%rbp), %rdi
callq 0x9e36
jmp 0x8705
movq %r15, %rdi
leaq 0x5e24(%rip), %rsi      # 0xe677
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x88e3
movq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x9e86
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
movq %rbx, %rdi
callq 0x9ef4
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x5ddc(%rip), %rsi      # 0xe687
callq 0x4260
movq %rax, %rbx
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
movq %rbx, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x57e8(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x8705
movq %r15, %rdi
leaq 0x5daa(%rip), %rsi      # 0xe697
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x897d
leaq -0x348(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4160
xorpd %xmm0, %xmm0
movsd %xmm0, -0xb0(%rbp)
xorl %ebx, %ebx
cmpl -0x60(%rbp), %ebx
jge 0x89d1
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
movq -0xa8(%rbp), %rdi
callq 0x9ef4
leaq -0x38(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x4370
movq %r15, %rdi
movq %r12, %rsi
callq 0xd074
movsd -0xb0(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0xb0(%rbp)
incl %ebx
jmp 0x892d
movq %r15, %rdi
leaq 0x5d2a(%rip), %rsi      # 0xe6b1
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x8a26
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
movb $0x1, %al
testb $0x1, %al
je 0x8ed7
movq -0xa8(%rbp), %rdi
callq 0x9ef4
incl -0xb4(%rbp)
jmp 0x89b5
movq %r13, %rdi
leaq 0x5c94(%rip), %rsi      # 0xe66f
callq 0x4260
movl -0x60(%rbp), %esi
movq %rax, %rdi
callq 0x43d0
movq %rax, %rdi
leaq 0x5cb1(%rip), %rsi      # 0xe6a6
callq 0x4260
movq %rax, %rdi
movsd -0xb0(%rbp), %xmm0
callq 0x4350
movq %rax, %rdi
leaq 0x56a5(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x8705
movq %r15, %rdi
leaq 0x5665(%rip), %rsi      # 0xe095
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x8f41
leaq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xa092
xorl %ebx, %ebx
movq -0x348(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x328(%rbp,%rax)
jne 0x90b3
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x90b3
leaq -0x348(%rbp), %rdi
movq %r14, %rsi
callq 0x42e0
movq %r15, %rdi
leaq 0x5c1e(%rip), %rsi      # 0xe6c7
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
movq 0xd4f6(%rip), %r13      # 0x15fc8
je 0x8b03
xorl %r12d, %r12d
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x8b8d
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
incl %r12d
jmp 0x8ae2
movq %r15, %rdi
leaq 0x5bdf(%rip), %rsi      # 0xe6ec
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
je 0x8c0a
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x8a65
movq %r13, %rdi
movl %ebx, %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x5be2(%rip), %rsi      # 0xe73d
callq 0x4260
movq %rax, %r12
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq (%rax), %rsi
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4140
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebx
jmp 0x8b35
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x5b28(%rip), %rsi      # 0xe6cd
callq 0x4260
movq %rax, %rdi
movl %r12d, %esi
callq 0x43d0
movq %rax, %rdi
callq 0x4140
movq 0xd404(%rip), %rdi      # 0x15fc8
leaq 0x5b14(%rip), %rsi      # 0xe6df
callq 0x4260
movq %rax, %r13
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xd074
movq %r13, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x54c4(%rip), %rsi      # 0xe0b9
callq 0x4260
addl %r12d, %ebx
movq %rax, %rdi
callq 0x4140
jmp 0x8a65
movq %r15, %rdi
leaq 0x5add(%rip), %rsi      # 0xe6f1
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
je 0x8c81
movq %r13, %rdi
movl %ebx, %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x5af1(%rip), %rsi      # 0xe73d
callq 0x4260
movq %rax, %r12
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq (%rax), %rsi
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4140
incl %ebx
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8a65
movq %r15, %rdi
leaq 0x5a71(%rip), %rsi      # 0xe6fc
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
je 0x8d36
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x4160
movl -0x90(%rbp), %eax
testl %eax, %eax
jle 0x8a65
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x8a65
movq %r13, %rdi
movl %ebx, %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x5a47(%rip), %rsi      # 0xe73d
callq 0x4260
movq %rax, %r12
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq (%rax), %rsi
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4140
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebx
movl -0x90(%rbp), %eax
decl %eax
movl %eax, -0x90(%rbp)
jmp 0x8cc8
movq %r15, %rdi
leaq 0x59b6(%rip), %rsi      # 0xe6f6
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
je 0x8daf
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x4160
movl -0x90(%rbp), %eax
testl %eax, %eax
jle 0x8a65
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x8a65
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebx
movl -0x90(%rbp), %eax
decl %eax
movl %eax, -0x90(%rbp)
jmp 0x8d79
movq %r15, %rdi
leaq 0x595a(%rip), %rsi      # 0xe713
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
je 0x8e70
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x4290
andq $0x0, -0x88(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x58cd(%rip), %rsi      # 0xe701
callq 0x4260
movq %rax, %r12
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xd074
movq %r12, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x525b(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x8a65
movq %r15, %rdi
leaq 0x5893(%rip), %rsi      # 0xe70d
leaq -0x3c(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %r12d
movq %r15, %rdi
callq 0x4110
testb %r12b, %r12b
je 0x8a65
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x4290
andq $0x0, -0x88(%rbp)
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
jmp 0x8a65
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x5783(%rip), %rsi      # 0xe66f
callq 0x4260
movq %rax, %rdi
movl -0xb4(%rbp), %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x579d(%rip), %rsi      # 0xe6a6
callq 0x4260
movq %rax, %rbx
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
movq %rbx, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x518a(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x8705
movq %r15, %rdi
leaq 0x57cd(%rip), %rsi      # 0xe718
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x90c8
xorpd %xmm0, %xmm0
movapd %xmm0, -0x60(%rbp)
leaq -0x348(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x4160
movq %rax, %rdi
leaq -0x64(%rbp), %rsi
callq 0x4160
movq %rax, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x4160
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x5763(%rip), %rsi      # 0xe724
callq 0x4260
movl -0x3c(%rbp), %esi
movq %rax, %rdi
callq 0x43d0
movq %rax, %rdi
leaq 0x5757(%rip), %rsi      # 0xe732
callq 0x4260
movl -0x64(%rbp), %esi
movq %rax, %rdi
callq 0x43d0
movq %rax, %rdi
leaq 0x5747(%rip), %rsi      # 0xe73c
callq 0x4260
movl -0x4c(%rbp), %esi
movq %rax, %rdi
callq 0x43d0
movq %rax, %rdi
leaq 0x5733(%rip), %rsi      # 0xe742
callq 0x4260
movq %rax, %rdi
callq 0x4140
xorl %ebx, %ebx
leaq -0x38(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xd074
imull $0x3e8, -0x3c(%rbp), %eax # imm = 0x3E8
cvtsi2sd %eax, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x914d
leaq -0xa0(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xa092
callq 0x4070
cltd
idivl -0x64(%rbp)
movslq %edx, %rax
movq %rax, -0x60(%rbp)
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
leaq -0x60(%rbp), %rsi
callq *0x10(%rax)
movl -0x4c(%rbp), %eax
testl %eax, %eax
jle 0x9091
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl -0x4c(%rbp), %eax
decl %eax
movl %eax, -0x4c(%rbp)
jmp 0x9076
incq %rbx
leaq -0x38(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x4370
leaq -0x98(%rbp), %rdi
callq 0x59d4
jmp 0x9022
leaq -0x30(%rbp), %rdi
callq 0x59d4
movq 0xcf05(%rip), %r13      # 0x15fc8
jmp 0x8705
movq %r15, %rdi
leaq 0x56a8(%rip), %rsi      # 0xe77a
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x9202
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x42e0
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
andl $0x0, -0x60(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xee0(%rip), %rsi      # 0x8258
leaq -0x38(%rbp), %rdx
movq %r15, %rcx
leaq -0x60(%rbp), %r8
callq 0xa0e0
jmp 0x9286
movq %r13, %rdi
leaq 0x55f6(%rip), %rsi      # 0xe74d
callq 0x4260
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4240
movq %rax, %rdi
leaq 0x55ea(%rip), %rsi      # 0xe75b
callq 0x4260
movq %rax, %r12
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
divsd 0x4e7b(%rip), %xmm0     # 0xe008
movq %r12, %rdi
callq 0x4350
movq %rax, %rdi
leaq 0x5439(%rip), %rsi      # 0xe5d8
callq 0x4260
movq %rax, %rdi
callq 0x4140
movq %rax, %rdi
leaq 0x55b2(%rip), %rsi      # 0xe768
callq 0x4260
movq %rax, %r12
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0xd074
imulq $0xf4240, %rbx, %rax    # imm = 0xF4240
cvtsi2sd %rax, %xmm1
divsd %xmm0, %xmm1
movq %r12, %rdi
movapd %xmm1, %xmm0
callq 0x4350
movq %rax, %rdi
leaq 0x557f(%rip), %rsi      # 0xe76f
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x8705
movq %r15, %rdi
leaq 0x5574(%rip), %rsi      # 0xe780
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x9293
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
leaq -0x348(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4160
movq %rax, %rdi
movq %r15, %rsi
callq 0x42e0
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x101e(%rip), %rsi     # 0x8258
leaq -0x38(%rbp), %rdx
movq %r15, %rcx
leaq -0x60(%rbp), %r8
callq 0xa12e
movq %r15, %rdi
callq 0x4110
jmp 0x8705
movq %r15, %rdi
leaq 0x54ee(%rip), %rsi      # 0xe78b
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x9368
movl $0x2a, -0x64(%rbp)
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x4290
movq %rax, %rdi
leaq -0x3c(%rbp), %rsi
callq 0x4160
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
callq 0x4290
movq %rax, %rdi
leaq -0x60(%rbp), %rsi
callq 0x4290
movq %rax, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x4160
movq %rax, %rdi
leaq -0xbc(%rbp), %rsi
callq 0x4160
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x1409(%rip), %rsi     # 0x7f28
leaq -0xa0(%rbp), %rdx
movq %r15, %rcx
leaq -0x3c(%rbp), %r8
leaq -0x38(%rbp), %r9
leaq -0xbc(%rbp), %rax
pushq %rax
leaq -0x4c(%rbp), %rax
pushq %rax
leaq -0x64(%rbp), %rax
pushq %rax
leaq -0x60(%rbp), %rax
pushq %rax
callq 0xa17c
addq $0x20, %rsp
jmp 0x8705
movq %r15, %rdi
leaq 0x5427(%rip), %rsi      # 0xe799
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x93e8
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
leaq -0x348(%rbp), %rdi
movq %r15, %rsi
callq 0x42e0
leaq -0x1a8(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4300
movq -0x48(%rbp), %rdi
movq %rbx, %rsi
movl -0x68(%rbp), %edx
callq 0x8258
movq %rbx, %rdi
callq 0x4110
jmp 0x9286
movq %r15, %rdi
leaq 0x53ab(%rip), %rsi      # 0xe79d
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x945c
movq %r15, %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
leaq 0x537a(%rip), %rsi      # 0xe7a2
callq 0x4260
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
movq %r15, %rsi
callq 0xd074
divsd 0x4bc1(%rip), %xmm0     # 0xe008
movq %rbx, %rdi
callq 0x4350
movq %rax, %rdi
callq 0x4140
jmp 0x8705
movq %r15, %rdi
leaq 0x5347(%rip), %rsi      # 0xe7ad
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x94b0
leaq -0x348(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4160
movslq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movq %r15, %rdi
callq 0x9c12
jmp 0x8705
movq %r15, %rdi
leaq 0x4ba6(%rip), %rsi      # 0xe060
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x950b
movq -0x48(%rbp), %rdi
callq 0xa200
movq %r13, %rdi
movl %eax, %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x4b73(%rip), %rsi      # 0xe06c
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x8705
movq %r15, %rdi
leaq 0x4b60(%rip), %rsi      # 0xe075
leaq -0x38(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x95f2
movq -0x48(%rbp), %rdi
callq 0xa248
jmp 0x8705
leaq -0x188(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq -0xe0(%rbp), %rbx
cmpq -0xd8(%rbp), %rbx
jae 0x9575
movq %rbx, %rdi
callq 0x43c0
addq $0x8, %rbx
jmp 0x955e
leaq -0x158(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0xd074
divsd 0x4a78(%rip), %xmm0     # 0xe008
cvttsd2si %xmm0, %ebx
leaq -0xe0(%rbp), %rdi
callq 0xa2ce
leaq -0x178(%rbp), %rdi
callq 0x4110
movl %ebx, %eax
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xca29(%rip), %rdi      # 0x15ff0
leaq 0x5099(%rip), %rsi      # 0xe667
callq 0x4260
leaq -0x118(%rbp), %rsi
movq %rax, %rdi
callq 0x4210
movq %rax, %rdi
callq 0x4140
pushq $-0x1
popq %rdi
callq 0x42d0
movq 0xc9f7(%rip), %rdi      # 0x15ff0
leaq 0x4acb(%rip), %rsi      # 0xe0cb
callq 0x4260
leaq -0x118(%rbp), %rsi
movq %rax, %rdi
callq 0x4210
movq %rax, %rdi
callq 0x4140
jmp 0x95ea
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
callq 0x4110
jmp 0x967b
jmp 0x97c5
jmp 0x9678
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x9678
jmp 0x9797
jmp 0x9678
jmp 0x97c5
jmp 0x9797
jmp 0x9678
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x4110
jmp 0x97c8
jmp 0x97c5
jmp 0x9797
jmp 0x9797
jmp 0x97c5
jmp 0x9797
jmp 0x9797
jmp 0x97c5
jmp 0x97c5
jmp 0x9797
jmp 0x9797
jmp 0x97c5
jmp 0x9797
jmp 0x97c5
jmp 0x9797
jmp 0x9797
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x9797
jmp 0x9797
jmp 0x97a0
jmp 0x97c5
jmp 0x97c5
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
callq 0xb06c
jmp 0x97c8
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97b2
jmp 0x97b2
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
jmp 0x9764
jmp 0x9797
jmp 0x9797
jmp 0x97c5
jmp 0x9797
jmp 0x9797
jmp 0x97c5
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x59d4
jmp 0x97ba
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x59d4
jmp 0x97ba
jmp 0x97c5
jmp 0x978e
jmp 0x97c5
jmp 0x97c5
jmp 0x97c5
movq %rax, %rbx
jmp 0x97ba
jmp 0x9797
jmp 0x9797
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
jmp 0x97be
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
jmp 0x97be
jmp 0x97b2
jmp 0x97c5
jmp 0x97b2
movq %rax, %rbx
jmp 0x97e0
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x59d4
jmp 0x97c8
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x4110
leaq -0x348(%rbp), %rdi
callq 0x4130
leaq -0xe0(%rbp), %rdi
callq 0xa2ce
leaq -0x178(%rbp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x43e0