// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, 0x10(%rax)
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x10c0
movl %eax, %edi
callq 0x10e0
movq 0x2ccd(%rip), %r13      # 0x3fd0
leaq -0x34(%rbp), %r12
cmpq $0x64, %rbx
je 0x1532
movq 0x2cd8(%rip), %rdi      # 0x3ff0
callq 0x1070
movq %rax, %rdi
leaq 0xcdd(%rip), %rsi       # 0x2004
callq 0x10f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10d0
movq 0x2cb2(%rip), %rdi      # 0x3ff0
callq 0x1090
callq 0x1030
movslq %eax, %rcx
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
addq $-0x3b9aca00, %rax      # imm = 0xC4653600
cmpq %rcx, %rax
movq %rbx, -0x58(%rbp)
jge 0x142e
movb $0x69, -0x29(%rbp)
movl $0x5f5e100, -0x30(%rbp) # imm = 0x5F5E100
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x1120
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x1120
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x157a
xorl %r15d, %r15d
xorl %r14d, %r14d
leaq 0xc55(%rip), %rbx       # 0x2006
movl %r14d, %eax
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divl %ecx
cmpl -0x30(%rbp), %r14d
jge 0x150d
imull $0xf4240, %eax, %eax    # imm = 0xF4240
addl %r15d, %eax
jne 0x13f8
movq 0x2c17(%rip), %rdi      # 0x3ff0
movq %rbx, %rsi
callq 0x10f0
movq %rax, %rdi
movl %r14d, %esi
callq 0x1170
movq 0x2bfd(%rip), %rdi      # 0x3ff0
callq 0x1090
callq 0x1030
cltd
movl $0x5f5e100, %ecx        # imm = 0x5F5E100
idivl %ecx
movl %edx, -0x34(%rbp)
movq -0x48(%rbp), %rdi
addq $-0x18, %rdi
movq %r12, %rsi
callq 0x15b2
movq %r13, %rdi
movq %r12, %rsi
pushq $0x4
popq %rdx
callq 0x1120
incl %r14d
decl %r15d
jmp 0x13b1
movb $0x72, -0x29(%rbp)
movl $0x5f5e100, -0x30(%rbp) # imm = 0x5F5E100
movq %r13, %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rdx
callq 0x1120
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x1120
xorl %r15d, %r15d
xorl %r14d, %r14d
movl %r14d, %eax
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divl %ecx
cmpl -0x30(%rbp), %r14d
jge 0x1503
imull $0xf4240, %eax, %eax    # imm = 0xF4240
addl %r15d, %eax
jne 0x14a8
movq 0x2b6b(%rip), %rdi      # 0x3ff0
leaq 0xb78(%rip), %rsi       # 0x2004
callq 0x10f0
movq %rax, %rdi
movl %r14d, %esi
callq 0x1170
movq 0x2b4d(%rip), %rdi      # 0x3ff0
callq 0x1090
callq 0x1030
movslq %eax, %rcx
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rax
subq %rdi, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
movq %rax, %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movslq %edx, %rax
imulq $0x18, %rax, %rbx
movq 0x8(%rdi,%rbx), %rax
movl -0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movq %r13, %rdi
movq %r12, %rsi
pushq $0x4
popq %rdx
callq 0x1120
movq -0x50(%rbp), %rax
addq $-0x4, 0x8(%rax,%rbx)
incl %r14d
decl %r15d
jmp 0x145d
movq %r13, %rdi
callq 0x1070
jmp 0x1526
movq -0x48(%rbp), %rax
movq -0x18(%rax), %rdi
movq -0x10(%rax), %rsi
callq 0x15d7
movq %r13, %rdi
callq 0x1070
movq -0x58(%rbp), %rbx
incq %rbx
jmp 0x1307
movq 0x2ab7(%rip), %rdi      # 0x3ff0
callq 0x1070
leaq -0x50(%rbp), %rdi
callq 0x1634
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
jmp 0x1566
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1634
movq %rbx, %rdi
callq 0x1180