// File: /workspace/github_cpp_makefile_star2_O1/UBOdin[P]jitd-cpp/src/workload.cpp
// Function: main
int main(int argc, char** argv)
{
  long int high_mark = 1000L*1000*1000*10;
  long int low_mark = 1000*1000*1000*1;
  int batch_size = 1000*1000*100;
  long int op_count = 100;
  int max_key = 1000*1000*100;
  vector< vector<int> > values;
  
  long int diff_mark = high_mark - low_mark;
  long int op;
  
  srand(time(NULL));
  
  for(op = 0; op < op_count; op++)
  {
//    if(op % 10 == 0){ 
      cerr <<endl<< ":" << op; cerr.flush(); 
//      }
    long int choice = rand() % diff_mark;
    long int threshold = values.size() - low_mark;
    char cmd;
    int cnt;
    if(choice > threshold){
      int i;
      cmd = 'i';
      cnt = batch_size;
      cout.write((char *)&cmd, sizeof(cmd));
      cout.write((char *)&cnt, sizeof(cnt));
      
      values.emplace_back(cnt);
      
      for(i = 0; i < cnt; i++){
        if(i % (1000*1000) == 0){
          cerr << "." << i; cerr.flush();
        }
        int k = rand() % max_key;
        values.back().push_back(k);
        cout.write((char *)&k, sizeof(k));
      }
      random_shuffle(values.back().begin(), values.back().end());
      cout << endl;
    } else {
      int i;
      cmd = 'r';
      cnt = batch_size;
      cout.write((char *)&cmd, sizeof(cmd));
      cout.write((char *)&cnt, sizeof(cnt));
      for(i = 0; i < cnt; i++){
        if(i % (1000*1000) == 0){
          cerr << ":" << i; cerr.flush();
        }
        int id = rand() % values.size();
        int k = values[id].back();
        cout.write((char *)&k, sizeof(k));
        values[id].pop_back();
      }
      cout << endl;
    }
  }
  cerr << endl;
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x10d0
movl %eax, %edi
callq 0x10f0
movq 0x2c99(%rip), %r15      # 0x3ff0
movq 0x2c72(%rip), %r13      # 0x3fd0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc6d(%rip), %rsi       # 0x2004
callq 0x1130
movq %r12, %rdi
movq %r14, %rsi
callq 0x10e0
movq %r15, %rdi
callq 0x10a0
callq 0x1040
cltq
movq -0x48(%rbp), %rcx
subq -0x50(%rbp), %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $-0x3b9aca00, %rcx      # imm = 0xC4653600
cmpq %rax, %rcx
jge 0x156b
movb $0x69, -0x29(%rbp)
movl $0x5f5e100, -0x30(%rbp) # imm = 0x5F5E100
movl $0x1, %edx
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
callq 0x1140
movl $0x4, %edx
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1140
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x16e4
cmpl $0x0, -0x30(%rbp)
jle 0x14d2
xorl %r12d, %r12d
movl %r12d, %eax
imulq $0x431bde83, %rax, %rax # imm = 0x431BDE83
shrq $0x32, %rax
imull $0xf4240, %eax, %eax    # imm = 0xF4240
cmpl %r12d, %eax
jne 0x1467
movl $0x1, %edx
movq %r15, %rdi
leaq 0xbb7(%rip), %rsi       # 0x2006
callq 0x1130
movq %r15, %rdi
movl %r12d, %esi
callq 0x1190
movq %r15, %rdi
callq 0x10a0
callq 0x1040
cltq
imulq $0x55e63b89, %rax, %rcx # imm = 0x55E63B89
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x39, %rcx
addl %edx, %ecx
imull $0x5f5e100, %ecx, %ecx  # imm = 0x5F5E100
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rdi), %rsi
cmpq -0x8(%rdi), %rsi
je 0x14a7
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0x14b4
addq $-0x18, %rdi
leaq -0x34(%rbp), %rdx
callq 0x1a52
movl $0x4, %edx
movq %r13, %rdi
leaq -0x34(%rbp), %rsi
callq 0x1140
incl %r12d
cmpl -0x30(%rbp), %r12d
jl 0x1427
movq %r14, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rax), %r12
movq -0x10(%rax), %r14
cmpq %r14, %r12
je 0x153a
leaq 0x4(%r12), %rax
cmpq %r14, %rax
je 0x153a
movl $0x4, %ebx
callq 0x1040
cltq
movq %rbx, %rcx
sarq $0x2, %rcx
incq %rcx
cqto
idivq %rcx
leaq (,%rdx,4), %rax
cmpq %rax, %rbx
je 0x1529
leaq (%r12,%rbx), %rax
leaq (%r12,%rdx,4), %rcx
movl (%rax), %edx
movl (%rcx), %esi
movl %esi, (%rax)
movl %edx, (%rcx)
leaq (%r12,%rbx), %rax
addq $0x4, %rax
addq $0x4, %rbx
cmpq %r14, %rax
jne 0x14f6
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x1100
movq -0x58(%rbp), %r14
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
jmp 0x1670
movb $0x72, -0x29(%rbp)
movl $0x5f5e100, -0x30(%rbp) # imm = 0x5F5E100
movl $0x1, %edx
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
callq 0x1140
movl $0x4, %edx
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1140
cmpl $0x0, -0x30(%rbp)
jle 0x1648
xorl %r12d, %r12d
movl %r12d, %eax
imulq $0x431bde83, %rax, %rax # imm = 0x431BDE83
shrq $0x32, %rax
imull $0xf4240, %eax, %eax    # imm = 0xF4240
cmpl %r12d, %eax
jne 0x15e5
movl $0x1, %edx
movq %r15, %rdi
leaq 0xa37(%rip), %rsi       # 0x2004
callq 0x1130
movq %r15, %rdi
movl %r12d, %esi
callq 0x1190
movq %r15, %rdi
callq 0x10a0
callq 0x1040
cltq
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rsi
xorl %edx, %edx
divq %rsi
movslq %edx, %rax
leaq (%rax,%rax,2), %rbx
movq 0x8(%rcx,%rbx,8), %rax
movl -0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x4, %edx
movq %r13, %rdi
leaq -0x34(%rbp), %rsi
callq 0x1140
movq -0x50(%rbp), %rax
addq $-0x4, 0x8(%rax,%rbx,8)
incl %r12d
cmpl -0x30(%rbp), %r12d
jl 0x15a5
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
incq %r14
cmpq $0x64, %r14
jne 0x135e
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x2955(%rip), %rdi      # 0x3ff0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
leaq -0x50(%rbp), %rdi
callq 0x1726
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16d0
jmp 0x16d0
jmp 0x16d0
jmp 0x16d0
jmp 0x16d0
jmp 0x16d0
jmp 0x16d0
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1726
movq %rbx, %rdi
callq 0x11a0