// File: /workspace/github_cpp_makefile_star2_O3/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 0x90f6
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 0x9132
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 0xee39(%rip), %r13      # 0x17fc8
leaq 0x842a(%rip), %rsi      # 0x115c0
movl $0xf, %edx
movq %r13, %rdi
callq 0x42d0
movq %r13, %rdi
movq %r12, %rsi
callq 0x4230
movq %rax, %r13
leaq 0x7ed5(%rip), %rsi      # 0x1108d
movl $0x2, %edx
movq %rax, %rdi
callq 0x42d0
movq %r13, %rdi
movq %r14, %rsi
callq 0x4230
movq %rax, %r14
leaq 0x83f6(%rip), %rsi      # 0x115d0
movl $0x5, %edx
movq %rax, %rdi
callq 0x42d0
movq %r14, %rdi
movl -0x2c(%rbp), %r12d
movl %r12d, %esi
callq 0x43f0
movq %rax, %r14
leaq 0x83d6(%rip), %rsi      # 0x115d6
movl $0x8, %edx
movq %rax, %rdi
callq 0x42d0
movq %r14, %rdi
movl 0x10(%rbp), %esi
callq 0x43f0
movq %rax, %r14
leaq 0x83bd(%rip), %rsi      # 0x115df
movl $0x8, %edx
movq %rax, %rdi
callq 0x42d0
movq %r14, %rdi
movl %ebx, %esi
callq 0x43f0
movq %rax, %r14
leaq 0x83a5(%rip), %rsi      # 0x115e8
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 0x9381
callq 0x4270
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x67c8
cmpl $0x0, -0x2c(%rbp)
jle 0x934d
movl -0x2c(%rbp), %r12d
movq -0x40(%rbp), %r13
movq %rbx, %rdi
callq 0xb912
xorl %edx, %edx
divq %r15
movq %rdx, -0x48(%rbp)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x933c
movq %rdx, (%rsi)
movl $0xdeadbeef, %eax       # imm = 0xDEADBEEF
movq %rax, 0x8(%rsi)
addq $0x10, %rsi
movq %rsi, 0x8(%r13)
jmp 0x9348
movq %r13, %rdi
leaq -0x48(%rbp), %rdx
callq 0xccb2
decl %r12d
jne 0x9307
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x88(%rbp)
movq %rax, -0x80(%rbp)
testq %rax, %rax
je 0x9424
movq 0xec50(%rip), %rcx      # 0x17fc0
cmpb $0x0, (%rcx)
je 0x9420
incl 0x8(%rax)
jmp 0x9424
callq 0x4270
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x67c8
cmpl $0x0, -0x2c(%rbp)
jle 0x93fa
movl -0x2c(%rbp), %r12d
movq -0x40(%rbp), %r13
leaq -0x27d8(%rbp), %rdi
callq 0xb912
xorl %edx, %edx
divq %r15
movq %rdx, -0x48(%rbp)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x93e9
movq %rdx, (%rsi)
movl $0xdeadbeef, %eax       # imm = 0xDEADBEEF
movq %rax, 0x8(%rsi)
addq $0x10, %rsi
movq %rsi, 0x8(%r13)
jmp 0x93f5
movq %r13, %rdi
leaq -0x48(%rbp), %rdx
callq 0xccb2
decl %r12d
jne 0x93b0
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq %rax, -0x70(%rbp)
testq %rax, %rax
je 0x9465
movq 0xebaa(%rip), %rcx      # 0x17fc0
cmpb $0x0, (%rcx)
je 0x9461
incl 0x8(%rax)
jmp 0x9465
lock
incl 0x8(%rax)
movq -0x58(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xb980
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
movq -0x68(%rbp), %r12
leaq -0xa8(%rbp), %r13
je 0x944d
callq 0x65c2
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x945b
callq 0x65c2
addq -0x50(%rbp), %r12
jmp 0x949d
lock
incl 0x8(%rax)
movq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xbc78
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
movq -0x68(%rbp), %r12
leaq -0xa8(%rbp), %r13
je 0x948b
callq 0x65c2
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x9499
callq 0x65c2
subq -0x50(%rbp), %r12
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4380
movq %r13, %rdi
movq %rbx, %rsi
callq 0xfce8
divsd 0x80d7(%rip), %xmm0     # 0x11598
cvttsd2si %xmm0, %ecx
movl 0x10(%rbp), %eax
subl %ecx, %eax
leaq -0x1450(%rbp), %rbx
jle 0x9513
movl %eax, %eax
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
shrq $0x26, %rcx
imulq $-0x3e8, %rcx, %rdx     # imm = 0xFC18
addq %rax, %rdx
imulq $0xf4240, %rdx, %rax    # imm = 0xF4240
movq %rcx, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq %r14, %rdi
movq %r14, %rsi
callq 0x40a0
cmpl $-0x1, %eax
jne 0x9513
callq 0x4040
cmpl $0x4, (%rax)
je 0x94f9
leaq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xfce8
movsd -0x90(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x92a5
leaq 0x80ac(%rip), %rsi      # 0x115eb
movl $0xb, %edx
movq 0xea7d(%rip), %rbx      # 0x17fc8
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 0x959c
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x95ad
callq 0x65c2
jmp 0x95ad
jmp 0x95aa
movq %rax, %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x95bb
callq 0x65c2
movq %rbx, %rdi
callq 0x4400