// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x27b8, %rsp           # imm = 0x27B8
movq %r8, %r15
movq %rcx, %r13
movl %edx, -0x48(%rbp)
movq %rsi, %r14
movq %rdi, -0x58(%rbp)
movslq %r9d, %rbx
leaq -0x27d8(%rbp), %rdi
movq %rbx, %rsi
callq 0xa2fa
leaq -0x1450(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa2fa
movq %r15, %rax
subq %r13, %rax
movq %rax, -0x70(%rbp)
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq 0xe039(%rip), %rdi      # 0x15fc8
leaq 0x65fa(%rip), %rsi      # 0xe590
callq 0x4260
movq %rax, %rdi
movq %r13, -0x78(%rbp)
movq %r13, %rsi
xorl %ebx, %ebx
callq 0x4240
leaq 0x60da(%rip), %rsi      # 0xe08d
movq %rax, %rdi
callq 0x4260
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
leaq 0x65d3(%rip), %rsi      # 0xe5a0
movq %rax, %rdi
callq 0x4260
movq %rax, %rdi
movl -0x48(%rbp), %r15d
movl %r15d, %esi
callq 0x43d0
leaq 0x65bb(%rip), %rsi      # 0xe5a6
movq %rax, %rdi
callq 0x4260
movq %rax, %rdi
movl 0x10(%rbp), %esi
callq 0x43d0
leaq 0x65aa(%rip), %rsi      # 0xe5af
movq %rax, %rdi
callq 0x4260
movq %rax, %rdi
movl 0x18(%rbp), %r13d
movl %r13d, %esi
callq 0x43d0
leaq 0x6595(%rip), %rsi      # 0xe5b8
movq %rax, %rdi
callq 0x4260
movq %rax, %rdi
callq 0x4140
movslq %r15d, %rcx
imull $0x3e8, %r13d, %eax     # imm = 0x3E8
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x68(%rbp)
testl %ecx, %ecx
movl $0x0, %eax
movq %rcx, -0x50(%rbp)
cmovgl %ecx, %eax
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %r13
leaq -0x60(%rbp), %r15
movq %r13, %rdi
xorl %esi, %esi
callq 0x4370
callq 0x4070
cltq
cqto
idivq -0x70(%rbp)
movq %rbx, -0x48(%rbp)
movq %rbx, %rax
subq -0x78(%rbp), %rax
pushq $0x18
popq %rdi
cmpq %rax, %rdx
jle 0x80da
callq 0x4270
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x5d74
movl -0x3c(%rbp), %r13d
subl $0x1, %r13d
jb 0x8124
movq -0x38(%rbp), %rbx
leaq -0x27d8(%rbp), %rdi
callq 0x9830
xorl %edx, %edx
divq %r14
movq %rdx, -0x60(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9800
jmp 0x80ae
callq 0x4270
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x5d74
movl -0x3c(%rbp), %r13d
subl $0x1, %r13d
jb 0x8159
movq -0x38(%rbp), %rbx
movq %r12, %rdi
callq 0x9830
xorl %edx, %edx
divq %r14
movq %rdx, -0x60(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9800
jmp 0x80fc
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
callq 0x5a64
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x989e
leaq -0x90(%rbp), %rdi
callq 0x59d4
movq -0x48(%rbp), %rbx
addq -0x50(%rbp), %rbx
jmp 0x8189
leaq -0x88(%rbp), %rbx
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
callq 0x5a64
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x9a58
leaq -0x80(%rbp), %rdi
callq 0x59d4
movq -0x48(%rbp), %rbx
subq -0x50(%rbp), %rbx
leaq -0x30(%rbp), %rdi
callq 0x59d4
leaq -0xa8(%rbp), %r13
leaq -0xc8(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x4370
movq %r13, %rdi
movq %r12, %rsi
callq 0xd074
divsd 0x63ab(%rip), %xmm0     # 0xe568
cvttsd2si %xmm0, %eax
movl 0x10(%rbp), %ecx
subl %eax, %ecx
movslq %ecx, %rax
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x9c12
leaq -0xb8(%rbp), %rdi
movq %r12, %rsi
callq 0xd074
movsd -0x68(%rbp), %xmm1
ucomisd %xmm0, %xmm1
leaq -0x1450(%rbp), %r12
ja 0x8062
movq 0xddc6(%rip), %rdi      # 0x15fc8
leaq 0x63b2(%rip), %rsi      # 0xe5bb
callq 0x4260
movq %rax, %rdi
callq 0x4140
addq $0x27b8, %rsp           # imm = 0x27B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x823b
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x59d4
jmp 0x8247
jmp 0x8244
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x59d4
movq %rbx, %rdi
callq 0x43e0