// File: obliviousram[P]PathOHeap/src/OHeapReadPathEviction.cpp
// Function: OHeapReadPathEviction::updateMin(int)
void OHeapReadPathEviction::updateMin(int leaf) {
  if (leaf != -1) {
    for (int l = num_levels-1; l >= 0; l--) {
      int p = this->P(leaf, l);
      auto potential_mins = std::vector<const Block*>();

      Bucket bucket_on_path = this->storage->readBucket(p);
      const std::vector<Block>& blocks_on_path = bucket_on_path.getBlocks();
      if (blocks_on_path.size() > 0) {
        const Block& min_block_on_path =
            *std::min_element(blocks_on_path.begin(), blocks_on_path.end());
        potential_mins.push_back(&min_block_on_path);
      }
      if (l != num_levels-1) {
        Bucket child1_bucket = this->storage->readBucket(2*p+1);
        Bucket child2_bucket = this->storage->readBucket(2*p+2);
        potential_mins.push_back(&child1_bucket.subtree_min);
        potential_mins.push_back(&child2_bucket.subtree_min);
      }

      // given a vector of pointers, get the min of what those pointers reference
      if (potential_mins.size() > 0) {
        int min_index = 0;
        for (int i = 1; i < potential_mins.size(); i++) {
          if (*potential_mins.at(i) < *potential_mins.at(min_index)) {
            min_index = i;
          }
        }
        bucket_on_path.subtree_min = *potential_mins.at(min_index);
      } else {
        bucket_on_path.subtree_min = Block();
      }

      this->storage->writeBucket(p, bucket_on_path);
    }
  } else {
    // dummy ops
    leaf = this->rand_gen->getRandomLeaf();
    for (int l = num_levels-1; l >= 0; l--) {
      int p = this->P(leaf, l);
      Bucket b = this->storage->readBucket(p);
      if (l != num_levels-1) {
        this->storage->readBucket(2*p+1);
        this->storage->readBucket(2*p+2);
      }
      this->storage->writeBucket(p, b);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
cmpl $-0x1, -0xc(%rbp)
je 0x9498
movq -0x2b0(%rbp), %rax
movl 0xc(%rax), %eax
subl $0x1, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jl 0x9493
movq -0x2b0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movl %eax, -0x14(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9ea0
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x14(%rbp), %edx
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x80(%rbp), %rdi
callq *%rax
jmp 0x911f
leaq -0x80(%rbp), %rdi
callq 0x2f40
movq %rax, -0x2b8(%rbp)
jmp 0x9131
movq -0x2b8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x3080
cmpq $0x0, %rax
jbe 0x9208
movq -0x98(%rbp), %rdi
callq 0x9f00
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x9f30
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x9ec0
movq %rax, -0x2c0(%rbp)
jmp 0x9197
movq -0x2c0(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x9f60
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x9f80
jmp 0x91d8
jmp 0x9208
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x9485
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x947c
movq -0x2b0(%rbp), %rcx
movl -0x10(%rbp), %eax
movl 0xc(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x9309
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x14(%rbp), %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax), %edx
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x110(%rbp), %rdi
callq *%rax
jmp 0x9246
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x14(%rbp), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %edx
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x160(%rbp), %rdi
callq *%rax
jmp 0x926c
leaq -0x110(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x9f80
jmp 0x928c
leaq -0x160(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9f80
jmp 0x92ac
leaq -0x160(%rbp), %rdi
callq 0x9ae0
leaq -0x110(%rbp), %rdi
callq 0x9ae0
jmp 0x9309
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x92f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x9ae0
leaq -0x110(%rbp), %rdi
callq 0x9ae0
jmp 0x947c
leaq -0x30(%rbp), %rdi
callq 0x9fb0
cmpq $0x0, %rax
jbe 0x941c
movl $0x0, -0x174(%rbp)
movl $0x1, -0x178(%rbp)
movslq -0x178(%rbp), %rax
movq %rax, -0x2c8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9fb0
movq %rax, %rcx
movq -0x2c8(%rbp), %rax
cmpq %rcx, %rax
jae 0x93e9
movslq -0x178(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x9fd0
movq %rax, -0x2d0(%rbp)
jmp 0x9373
movq -0x2d0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2e0(%rbp)
movslq -0x174(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x9fd0
movq %rax, -0x2d8(%rbp)
jmp 0x939d
movq -0x2e0(%rbp), %rdi
movq -0x2d8(%rbp), %rax
movq (%rax), %rsi
callq 0x26f0
movb %al, -0x2e1(%rbp)
jmp 0x93bb
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x93c7
jmp 0x93d3
movl -0x178(%rbp), %eax
movl %eax, -0x174(%rbp)
jmp 0x93d5
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0x9330
movslq -0x174(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x9fd0
movq %rax, -0x2f0(%rbp)
jmp 0x9402
movq -0x2f0(%rbp), %rax
movq (%rax), %rsi
leaq -0x80(%rbp), %rdi
movl $0x34, %edx
callq 0x2160
jmp 0x943f
leaq -0x1b0(%rbp), %rdi
callq 0x26b0
jmp 0x942a
leaq -0x80(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
movl $0x34, %edx
callq 0x2160
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq -0x80(%rbp), %rdx
callq *%rax
jmp 0x945c
leaq -0x80(%rbp), %rdi
callq 0x9ae0
leaq -0x30(%rbp), %rdi
callq 0xa010
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x90c7
leaq -0x80(%rbp), %rdi
callq 0x9ae0
leaq -0x30(%rbp), %rdi
callq 0xa010
jmp 0x95fe
jmp 0x95f5
movq -0x2b0(%rbp), %rax
movq 0x38(%rax), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, %ecx
movq -0x2b0(%rbp), %rax
movl %ecx, -0xc(%rbp)
movl 0xc(%rax), %eax
subl $0x1, %eax
movl %eax, -0x1b4(%rbp)
cmpl $0x0, -0x1b4(%rbp)
jl 0x95f3
movq -0x2b0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x1b4(%rbp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %ecx
movq -0x2b0(%rbp), %rax
movl %ecx, -0x1b8(%rbp)
movq 0x30(%rax), %rsi
movl -0x1b8(%rbp), %edx
movq (%rsi), %rax
leaq -0x208(%rbp), %rdi
callq *0x8(%rax)
movq -0x2b0(%rbp), %rcx
movl -0x1b4(%rbp), %eax
movl 0xc(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x95b0
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x1b8(%rbp), %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax), %edx
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x258(%rbp), %rdi
callq *%rax
jmp 0x954d
leaq -0x258(%rbp), %rdi
callq 0x9ae0
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x1b8(%rbp), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %edx
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x2a8(%rbp), %rdi
callq *%rax
jmp 0x9582
leaq -0x2a8(%rbp), %rdi
callq 0x9ae0
jmp 0x95b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x9ae0
jmp 0x95fe
movq -0x2b0(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x1b8(%rbp), %esi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq -0x208(%rbp), %rdx
callq *%rax
jmp 0x95d3
leaq -0x208(%rbp), %rdi
callq 0x9ae0
movl -0x1b4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x94c0
jmp 0x95f5
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x22a0
nopw (%rax,%rax)