// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rcx, -0x60(%rbp)
movl %edx, -0x2c(%rbp)
movq %rsi, %r15
movq %rdi, -0x58(%rbp)
movl 0x18(%rbp), %ebx
movl %r9d, %eax
movq %rax, -0x1450(%rbp)
movl $0x1, %ecx
movq %rax, %rdx
movq %rdx, %rsi
shrq $0x1e, %rsi
xorl %edx, %esi
imull $0x6c078965, %esi, %edx # imm = 0x6C078965
addl %ecx, %edx
movq %rdx, -0x1450(%rbp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x9436
movq $0x270, -0xd0(%rbp) # imm = 0x270
movq %rax, -0x27d8(%rbp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, -0x27d8(%rbp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x9472
leaq -0x27d8(%rbp), %rax
movq $0x270, 0x1380(%rax) # imm = 0x270
movq %r14, %rax
movq -0x60(%rbp), %r12
subq %r12, %rax
movq %rax, -0x98(%rbp)
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
callq 0x4380
movq 0xfaf9(%rip), %r13      # 0x18fc8
leaq 0x81f2(%rip), %rsi      # 0x116c8
movl $0xf, %edx
movq %r13, %rdi
callq 0x42d0
movq %r13, %rdi
movq %r12, %rsi
callq 0x4230
movq %rax, %r13
leaq 0x7b9d(%rip), %rsi      # 0x11095
movl $0x2, %edx
movq %rax, %rdi
callq 0x42d0
movq %r13, %rdi
movq %r14, %rsi
callq 0x4230
movq %rax, %r14
leaq 0x81be(%rip), %rsi      # 0x116d8
movl $0x5, %edx
movq %rax, %rdi
callq 0x42d0
movq %r14, %rdi
movl -0x2c(%rbp), %r12d
movl %r12d, %esi
callq 0x43f0
movq %rax, %r14
leaq 0x819e(%rip), %rsi      # 0x116de
movl $0x8, %edx
movq %rax, %rdi
callq 0x42d0
movq %r14, %rdi
movl 0x10(%rbp), %esi
callq 0x43f0
movq %rax, %r14
leaq 0x8185(%rip), %rsi      # 0x116e7
movl $0x8, %edx
movq %rax, %rdi
callq 0x42d0
movq %r14, %rdi
movl %ebx, %esi
callq 0x43f0
movq %rax, %r14
leaq 0x816d(%rip), %rsi      # 0x116f0
movl $0x2, %edx
movq %rax, %rdi
callq 0x42d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4250
movsbl %al, %esi
movq %r14, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4190
movslq %r12d, %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
imull $0x3e8, %ebx, %eax      # imm = 0x3E8
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x90(%rbp)
leaq -0xa8(%rbp), %r13
leaq -0x1450(%rbp), %rbx
leaq -0x40(%rbp), %r14
movq %r13, %rdi
xorl %esi, %esi
callq 0x4380
callq 0x4070
cltq
cqto
idivq -0x98(%rbp)
movq %r12, -0x68(%rbp)
movq %r12, %rax
subq -0x60(%rbp), %rax
movl $0x18, %edi
cmpq %rax, %rdx
jle 0x96c1
callq 0x4270
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x6a04
cmpl $0x0, -0x2c(%rbp)
jle 0x968d
movl -0x2c(%rbp), %r12d
movq -0x40(%rbp), %r13
movq %rbx, %rdi
callq 0xbab8
xorl %edx, %edx
divq %r15
movq %rdx, -0x48(%rbp)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x967c
movq %rdx, (%rsi)
movl $0xdeadbeef, %eax       # imm = 0xDEADBEEF
movq %rax, 0x8(%rsi)
addq $0x10, %rsi
movq %rsi, 0x8(%r13)
jmp 0x9688
movq %r13, %rdi
leaq -0x48(%rbp), %rdx
callq 0xcdb4
decl %r12d
jne 0x9647
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x88(%rbp)
movq %rax, -0x80(%rbp)
testq %rax, %rax
je 0x9764
movq 0xf910(%rip), %rcx      # 0x18fc0
cmpb $0x0, (%rcx)
je 0x9760
incl 0x8(%rax)
jmp 0x9764
callq 0x4270
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x6a04
cmpl $0x0, -0x2c(%rbp)
jle 0x973a
movl -0x2c(%rbp), %r12d
movq -0x40(%rbp), %r13
leaq -0x27d8(%rbp), %rdi
callq 0xbab8
xorl %edx, %edx
divq %r15
movq %rdx, -0x48(%rbp)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x9729
movq %rdx, (%rsi)
movl $0xdeadbeef, %eax       # imm = 0xDEADBEEF
movq %rax, 0x8(%rsi)
addq $0x10, %rsi
movq %rsi, 0x8(%r13)
jmp 0x9735
movq %r13, %rdi
leaq -0x48(%rbp), %rdx
callq 0xcdb4
decl %r12d
jne 0x96f0
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq %rax, -0x70(%rbp)
testq %rax, %rax
je 0x97a5
movq 0xf86a(%rip), %rcx      # 0x18fc0
cmpb $0x0, (%rcx)
je 0x97a1
incl 0x8(%rax)
jmp 0x97a5
lock
incl 0x8(%rax)
movq -0x58(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xbb24
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
movq -0x68(%rbp), %r12
leaq -0xa8(%rbp), %r13
je 0x978d
callq 0x6810
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x979b
callq 0x6810
addq -0x50(%rbp), %r12
jmp 0x97dd
lock
incl 0x8(%rax)
movq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xbdee
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
movq -0x68(%rbp), %r12
leaq -0xa8(%rbp), %r13
je 0x97cb
callq 0x6810
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x97d9
callq 0x6810
subq -0x50(%rbp), %r12
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
movq %r13, %rdi
movq %rbx, %rsi
callq 0xfd7c
divsd 0x7e9f(%rip), %xmm0     # 0x116a0
cvttsd2si %xmm0, %ecx
movl 0x10(%rbp), %eax
subl %ecx, %eax
leaq -0x1450(%rbp), %rbx
jle 0x9858
movl %eax, %ecx
movq %rcx, %rax
movabsq $0x4189374bc6a7f0, %rdx # imm = 0x4189374BC6A7F0
mulq %rdx
imulq $-0x3e8, %rdx, %rax     # imm = 0xFC18
addq %rcx, %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq %rdx, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq %r14, %rdi
movq %r14, %rsi
callq 0x40a0
cmpl $-0x1, %eax
jne 0x9858
callq 0x4040
cmpl $0x4, (%rax)
je 0x983e
leaq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xfd7c
movsd -0x90(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x95e5
leaq 0x7e6f(%rip), %rsi      # 0x116f3
movl $0xb, %edx
movq 0xf738(%rip), %rbx      # 0x18fc8
movq %rbx, %rdi
callq 0x42d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4250
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4190
addq $0x27b8, %rsp           # imm = 0x27B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x80(%rbp), %rdi
jmp 0x98e1
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x98f2
callq 0x6810
jmp 0x98f2
jmp 0x98ef
movq %rax, %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x9900
callq 0x6810
movq %rbx, %rdi
callq 0x4400