// File: UBOdin[P]jitd-cpp/src/jitd_tester.cpp
// Function: run_update_thread(JITD<Record, PureLocalPolicy<Record>>*, long, int, long, long, int, int, int)
void run_update_thread(
  JITD<Record,JITD_TEST_POLICY> *jitd, 
  Key max_key,
  int size, 
  long int low_mark, 
  long int high_mark, 
  int seed, 
  int per_op_sleep_ms,
  int runtime_ms
){
  timeval global_start, start, end;
  long int del_step = 0;
  mt19937 ins_rand(seed);
  mt19937 del_rand(seed);
  int i;
  long int tot_cnt = 0;
  long int delta_mark = high_mark - low_mark;
    
  gettimeofday(&global_start, NULL);
  cout << "Start Updates [" << low_mark << "--" << high_mark << "] by " << size
       << "; every " << per_op_sleep_ms << " ms for " << runtime_ms << "ms" << endl;
  do {
    
    gettimeofday(&start, NULL);
    if((rand() % delta_mark) > (tot_cnt - low_mark)){
      // insert
      RecordBuffer buff = RecordBuffer(new vector<Record>);
      for(i = 0; i < size; i++){
        buff->emplace_back(ins_rand() % max_key);
      }
      jitd->insert(buff);
      tot_cnt += size;
      
    } else {
      // delete
      RecordBuffer buff = RecordBuffer(new vector<Record>);
      for(i = 0; i < size; i++){
        buff->emplace_back(del_rand() % max_key);
      }
      jitd->remove(buff);
      tot_cnt -= size;
      
    }
    
    gettimeofday(&end, NULL);
    this_thread::sleep_for(chrono::milliseconds(
      per_op_sleep_ms - int(total_time(start, end) / 1000)
    ));
  } while(total_time(global_start, end) < 1000 * runtime_ms);
  cout << "End Updates" << endl;
  
  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2860, %rsp           # imm = 0x2860
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq $0x0, -0x68(%rbp)
movslq -0x2c(%rbp), %rsi
leaq -0x13f0(%rbp), %rdi
callq 0x124f0
movslq -0x2c(%rbp), %rsi
leaq -0x2778(%rbp), %rdi
callq 0x124f0
movq $0x0, -0x2788(%rbp)
movq -0x28(%rbp), %rax
subq -0x20(%rbp), %rax
movq %rax, -0x2790(%rbp)
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x43b0
movq 0x20aba(%rip), %rdi     # 0x2ffc8
leaq 0x11273(%rip), %rsi     # 0x20788
callq 0x4280
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x4440
movq %rax, %rdi
leaq 0x10bc5(%rip), %rsi     # 0x200f5
callq 0x4280
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x4440
movq %rax, %rdi
leaq 0x1124d(%rip), %rsi     # 0x20798
callq 0x4280
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x4410
movq %rax, %rdi
leaq 0x11239(%rip), %rsi     # 0x2079e
callq 0x4280
movq %rax, %rdi
movl 0x10(%rbp), %esi
callq 0x4410
movq %rax, %rdi
leaq 0x11228(%rip), %rsi     # 0x207a7
callq 0x4280
movq %rax, %rdi
movl 0x18(%rbp), %esi
callq 0x4410
movq %rax, %rdi
leaq 0x11217(%rip), %rsi     # 0x207b0
callq 0x4280
movq %rax, %rdi
movq 0x209f8(%rip), %rsi     # 0x2ffa0
callq 0x42c0
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x43b0
callq 0x4070
cltq
cqto
idivq -0x2790(%rbp)
movq -0x2788(%rbp), %rax
subq -0x20(%rbp), %rax
cmpq %rax, %rdx
jle 0xf735
movl $0x18, %edi
callq 0x4290
movq %rax, %rdi
movq %rdi, -0x2808(%rbp)
callq 0x72d0
movq -0x2808(%rbp), %rsi
leaq -0x27a0(%rbp), %rdi
callq 0x7210
movl $0x0, -0x277c(%rbp)
movl -0x277c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf69d
leaq -0x27a0(%rbp), %rdi
callq 0x7310
movq %rax, -0x2818(%rbp)
leaq -0x13f0(%rbp), %rdi
callq 0x12590
movq %rax, -0x2810(%rbp)
jmp 0xf647
movq -0x2818(%rbp), %rdi
movq -0x2810(%rbp), %rax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, -0x27a8(%rbp)
leaq -0x27a8(%rbp), %rsi
callq 0x12520
jmp 0xf673
jmp 0xf675
movl -0x277c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x277c(%rbp)
jmp 0xf614
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x27b0(%rbp)
movl %eax, -0x27b4(%rbp)
jmp 0xf724
movq -0x8(%rbp), %rax
movq %rax, -0x2828(%rbp)
leaq -0x27c8(%rbp), %rdi
movq %rdi, -0x2820(%rbp)
leaq -0x27a0(%rbp), %rsi
callq 0x73a0
movq -0x2828(%rbp), %rdi
movq -0x2820(%rbp), %rsi
callq 0x12650
jmp 0xf6d7
leaq -0x27c8(%rbp), %rdi
callq 0x72b0
movslq -0x14(%rbp), %rax
addq -0x2788(%rbp), %rax
movq %rax, -0x2788(%rbp)
leaq -0x27a0(%rbp), %rdi
callq 0x72b0
jmp 0xf88c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x27b0(%rbp)
movl %eax, -0x27b4(%rbp)
leaq -0x27c8(%rbp), %rdi
callq 0x72b0
leaq -0x27a0(%rbp), %rdi
callq 0x72b0
jmp 0xf93c
movl $0x18, %edi
callq 0x4290
movq %rax, %rdi
movq %rdi, -0x2830(%rbp)
callq 0x72d0
movq -0x2830(%rbp), %rsi
leaq -0x27d8(%rbp), %rdi
callq 0x7210
movl $0x0, -0x277c(%rbp)
movl -0x277c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf7f4
leaq -0x27d8(%rbp), %rdi
callq 0x7310
movq %rax, -0x2840(%rbp)
leaq -0x2778(%rbp), %rdi
callq 0x12590
movq %rax, -0x2838(%rbp)
jmp 0xf79e
movq -0x2840(%rbp), %rdi
movq -0x2838(%rbp), %rax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, -0x27e0(%rbp)
leaq -0x27e0(%rbp), %rsi
callq 0x12520
jmp 0xf7ca
jmp 0xf7cc
movl -0x277c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x277c(%rbp)
jmp 0xf76b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x27b0(%rbp)
movl %eax, -0x27b4(%rbp)
jmp 0xf87b
movq -0x8(%rbp), %rax
movq %rax, -0x2850(%rbp)
leaq -0x27f0(%rbp), %rdi
movq %rdi, -0x2848(%rbp)
leaq -0x27d8(%rbp), %rsi
callq 0x73a0
movq -0x2850(%rbp), %rdi
movq -0x2848(%rbp), %rsi
callq 0x12930
jmp 0xf82e
leaq -0x27f0(%rbp), %rdi
callq 0x72b0
movslq -0x14(%rbp), %rcx
movq -0x2788(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x2788(%rbp)
leaq -0x27d8(%rbp), %rdi
callq 0x72b0
jmp 0xf88c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x27b0(%rbp)
movl %eax, -0x27b4(%rbp)
leaq -0x27f0(%rbp), %rdi
callq 0x72b0
leaq -0x27d8(%rbp), %rdi
callq 0x72b0
jmp 0xf93c
leaq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x43b0
movl 0x10(%rbp), %eax
movl %eax, -0x2854(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1e520
movl -0x2854(%rbp), %eax
movsd 0x10e93(%rip), %xmm1    # 0x20750
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
subl %ecx, %eax
movl %eax, -0x27fc(%rbp)
leaq -0x27f8(%rbp), %rdi
leaq -0x27fc(%rbp), %rsi
callq 0x12cc0
leaq -0x27f8(%rbp), %rdi
callq 0x12c10
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1e520
movaps %xmm0, %xmm1
imull $0x3e8, 0x18(%rbp), %eax # imm = 0x3E8
cvtsi2sd %eax, %xmm0
ucomisd %xmm1, %xmm0
ja 0xf5ad
movq 0x206b0(%rip), %rdi     # 0x2ffc8
leaq 0x10e94(%rip), %rsi     # 0x207b3
callq 0x4280
movq %rax, %rdi
movq 0x20672(%rip), %rsi     # 0x2ffa0
callq 0x42c0
addq $0x2860, %rsp           # imm = 0x2860
popq %rbp
retq
movq -0x27b0(%rbp), %rdi
callq 0x4420
nopl (%rax,%rax)