// File: 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
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movabsq $0x2540be400, %rax      # imm = 0x2540BE400
movq %rax, -0x18(%rbp)
movq $0x3b9aca00, -0x20(%rbp) # imm = 0x3B9ACA00
movl $0x5f5e100, -0x24(%rbp) # imm = 0x5F5E100
movq $0x64, -0x30(%rbp)
movl $0x5f5e100, -0x34(%rbp) # imm = 0x5F5E100
leaq -0x50(%rbp), %rdi
callq 0x1730
movq -0x18(%rbp), %rax
subq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x10b0
movl %eax, %edi
callq 0x10c0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x16f6
movq 0x5c99(%rip), %rdi      # 0x6ff0
movq 0x5c62(%rip), %rsi      # 0x6fc0
callq 0x1100
movq %rax, -0xb8(%rbp)
jmp 0x136c
movq -0xb8(%rbp), %rdi
leaq 0x2c8a(%rip), %rsi      # 0x4004
callq 0x10d0
movq %rax, -0xc0(%rbp)
jmp 0x1388
movq -0xc0(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1180
jmp 0x139a
movq 0x5c4f(%rip), %rdi      # 0x6ff0
callq 0x1080
jmp 0x13a8
callq 0x1030
cltq
cqto
idivq -0x58(%rbp)
movq %rdx, -0x78(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1750
subq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jle 0x157b
movb $0x69, -0x81(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x88(%rbp)
movq 0x5be1(%rip), %rdi      # 0x6fd0
leaq -0x81(%rbp), %rsi
movl $0x1, %edx
callq 0x1110
jmp 0x1402
movq 0x5bc7(%rip), %rdi      # 0x6fd0
leaq -0x88(%rbp), %rsi
movl $0x4, %edx
callq 0x1110
jmp 0x141c
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1780
jmp 0x142e
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0x1512
movl -0x8c(%rbp), %eax
movl $0xf4240, %ecx          # imm = 0xF4240
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x14b7
movq 0x5b8c(%rip), %rdi      # 0x6ff0
leaq 0x2b9b(%rip), %rsi      # 0x4006
callq 0x10d0
movq %rax, -0xc8(%rbp)
jmp 0x1479
movq -0xc8(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x1160
jmp 0x148d
movq 0x5b5c(%rip), %rdi      # 0x6ff0
callq 0x1080
jmp 0x149b
jmp 0x14b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1a60
jmp 0x1727
callq 0x1030
movl -0x34(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0x90(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x17f0
movq %rax, %rdi
leaq -0x90(%rbp), %rsi
callq 0x1830
jmp 0x14e2
movq 0x5ae7(%rip), %rdi      # 0x6fd0
leaq -0x90(%rbp), %rsi
movl $0x4, %edx
callq 0x1110
jmp 0x14fc
jmp 0x14fe
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1438
leaq -0x50(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x17f0
movq %rax, %rdi
callq 0x1970
movq -0xd0(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x17f0
movq %rax, %rdi
callq 0x19a0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x18a0
jmp 0x1561
movq 0x5a68(%rip), %rdi      # 0x6fd0
movq 0x5a51(%rip), %rsi      # 0x6fc0
callq 0x1100
jmp 0x1576
jmp 0x16e3
movb $0x72, -0x81(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x88(%rbp)
movq 0x5a3e(%rip), %rdi      # 0x6fd0
leaq -0x81(%rbp), %rsi
movl $0x1, %edx
callq 0x1110
jmp 0x15a5
movq 0x5a24(%rip), %rdi      # 0x6fd0
leaq -0x88(%rbp), %rsi
movl $0x4, %edx
callq 0x1110
jmp 0x15bf
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0x16cc
movl -0xa4(%rbp), %eax
movl $0xf4240, %ecx          # imm = 0xF4240
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x162e
movq 0x59fb(%rip), %rdi      # 0x6ff0
leaq 0x2a08(%rip), %rsi      # 0x4004
callq 0x10d0
movq %rax, -0xd8(%rbp)
jmp 0x160a
movq -0xd8(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x1160
jmp 0x161e
movq 0x59cb(%rip), %rdi      # 0x6ff0
callq 0x1080
jmp 0x162c
jmp 0x162e
callq 0x1030
cltq
movq %rax, -0xe0(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x1750
movq -0xe8(%rbp), %rdi
movq %rax, %rcx
movq -0xe0(%rbp), %rax
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0xa8(%rbp)
movslq -0xa8(%rbp), %rsi
callq 0x19d0
movq %rax, %rdi
callq 0x19f0
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movq 0x5943(%rip), %rdi      # 0x6fd0
leaq -0xac(%rbp), %rsi
movl $0x4, %edx
callq 0x1110
jmp 0x16a0
movslq -0xa8(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x19d0
movq %rax, %rdi
callq 0x1a30
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x15c9
movq 0x58fd(%rip), %rdi      # 0x6fd0
movq 0x58e6(%rip), %rsi      # 0x6fc0
callq 0x1100
jmp 0x16e1
jmp 0x16e3
jmp 0x16e5
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1342
movq 0x58f3(%rip), %rdi      # 0x6ff0
movq 0x58bc(%rip), %rsi      # 0x6fc0
callq 0x1100
jmp 0x170b
movl $0x0, -0x4(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1a60
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x1170