// File: /workspace/github_cpp_makefile_star2_O1/obliviousram[P]PathOHeap/src/Job2.cpp
// Function: Job2::run()
void Job2::run() {
  int bucket_size = 3;
  int num_blocks = pow(2, 12);
  UntrustedStorageInterface* storage = new ServerStorage();
  RandForOHeapInterface* random = new RandomForOHeap();
  OHeapInterface* oheap = new OHeapReadPathEviction(storage, random, bucket_size, num_blocks, false);

  std::array<std::byte, Block::BLOCK_SIZE> sample_data;
  sample_data.fill(std::byte{0xa});

  // Sample computation: fill the heap, then start overwriting.

  // overwrite requires knowing the leaf and t of the block to be overwritten, so keep them around as the heap is filled
  auto leaves = std::vector<int>();
  auto ts = std::vector<int>();

  for (int i = 0; i < num_blocks; i++) {
    std::pair<int, int> leaf_t = oheap->insertBlock(i, sample_data);
    leaves.push_back(leaf_t.first);
    ts.push_back(leaf_t.second);
  }

  for (int i = 0; i < 300000; i++) {
    std::pair<int, int> leaf_t = oheap->increaseKey(leaves.at(i % num_blocks), ts.at(i % num_blocks));
    leaves.at(i % num_blocks) = leaf_t.first;
    ts.at(i % num_blocks) = leaf_t.second;

    if (i % 10000 == 0) {
      std::cout << "After block " << i << " stash size is " << oheap->getStashSize() << std::endl;
    }
  }

  delete oheap;
  delete random;
  delete storage;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl $0x28, %edi
callq 0x2160
movq %rax, %r14
movq %rax, %rdi
callq 0x6178
movl $0x20, %edi
callq 0x2160
movq %rax, %r12
movq %rax, %rdi
callq 0x6000
movl $0x58, %edi
callq 0x2160
movq %rax, %r15
xorl %ebx, %ebx
movq %rax, %rdi
movq %r14, 0x78(%rsp)
movq %r14, %rsi
movq %r12, 0x70(%rsp)
movq %r12, %rdx
movl $0x3, %ecx
movl $0x1000, %r8d           # imm = 0x1000
xorl %r9d, %r9d
callq 0x3c98
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %r14
movaps %xmm0, (%r14)
movq %rbx, 0x10(%r14)
leaq 0x2c(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %rbx, 0x10(%r13)
movaps %xmm0, (%r13)
leaq 0x28(%rsp), %rbp
movaps 0x42f9(%rip), %xmm0     # 0x7140
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
movq (%r15), %rax
movq 0x8(%rax), %rax
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
movl %ebx, %esi
callq *%rax
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x2ea0
movl 0x28(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x2eab
movq %r14, %rdi
movq %rbp, %rdx
callq 0x30fe
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x2ec8
movl 0x2c(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x2ed3
movq %r13, %rdi
movq %r12, %rdx
callq 0x30fe
incl %ebx
cmpl $0x1000, %ebx           # imm = 0x1000
jne 0x2e40
xorl %ebp, %ebp
movl $0xd1b71759, %r13d      # imm = 0xD1B71759
movq 0x80e0(%rip), %r12      # 0xafd0
leaq 0x4266(%rip), %rbx      # 0x715d
movl %ebp, %r14d
andl $0xfff, %r14d           # imm = 0xFFF
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r14, %rdx
jbe 0x3088
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r14, %rdx
jbe 0x3088
leal (,%r14,4), %edx
movl (%rax,%rdx), %esi
movslq (%rcx,%rdx), %rdx
movq (%r15), %rax
movq %r15, %rdi
callq *0x28(%rax)
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r14, %rdx
jbe 0x3088
movl %eax, (%rcx,%r14,4)
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r14, %rdx
jbe 0x3088
movl %ebp, %edx
imulq %r13, %rdx
shrq $0x2d, %rdx
imull $0x2710, %edx, %edx     # imm = 0x2710
shrq $0x20, %rax
movl %eax, (%rcx,%r14,4)
cmpl %ebp, %edx
jne 0x300f
movl $0xc, %edx
movq %r12, %rdi
leaq 0x41a0(%rip), %rsi      # 0x7150
callq 0x2190
movq %r12, %rdi
movl %ebp, %esi
callq 0x2240
movq %rax, %r14
movl $0xf, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2190
movq (%r15), %rax
movq %r15, %rdi
callq *0x40(%rax)
movq %r14, %rdi
movl %eax, %esi
callq 0x2240
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
incl %ebp
cmpl $0x493e0, %ebp          # imm = 0x493E0
jne 0x2ef7
movl $0x8, %esi
movq %r15, %rdi
callq 0x2170
movl $0x8, %esi
movq 0x70(%rsp), %rdi
callq 0x2170
movl $0x8, %esi
movq 0x78(%rsp), %rdi
callq 0x2170
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x305f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3076
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x400a(%rip), %rdi      # 0x7099
movq %r14, %rsi
xorl %eax, %eax
callq 0x21d0
movq %rax, %rbx
movl $0x58, %esi
movq %r15, %rdi
jmp 0x30f0
movq %rax, %rbx
movl $0x20, %esi
movq %r12, %rdi
jmp 0x30f0
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
jmp 0x30f0
jmp 0x30c4
jmp 0x30c4
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x30de
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x30f5
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2250
nop