// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, %rbx
movl %esi, 0x10(%rsp)
cmpl $-0x1, %esi
movq %rdi, 0x8(%rsp)
je 0x480d
movl 0xc(%rbx), %r14d
leaq 0x40(%rsp), %r15
leaq 0x20(%rsp), %r12
testl %r14d, %r14d
jle 0x48d7
leal -0x1(%r14), %edx
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl %edx, 0x14(%rsp)
callq *0x30(%rax)
andq $0x0, 0x30(%rsp)
movl %eax, %edx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x30(%rbx), %rsi
movq (%rsi), %rax
movq %r15, %rdi
movq %rdx, %rbx
callq *0x8(%rax)
movq %r15, %rdi
callq 0x278c
movq (%rax), %rdi
movq 0x8(%rax), %rsi
cmpq %rdi, %rsi
je 0x4670
callq 0x4c67
movq %rax, 0x98(%rsp)
movq %r12, %rdi
leaq 0x98(%rsp), %rsi
callq 0x52b8
movq 0x8(%rsp), %rax
cmpl 0xc(%rax), %r14d
movq %rbx, %r14
je 0x470c
movq 0x8(%rsp), %r15
movq 0x30(%r15), %rsi
leal 0x1(,%r14,2), %edx
movq (%rsi), %rax
leaq 0x98(%rsp), %rdi
callq *0x8(%rax)
leal (%r14,%r14), %edx
movq 0x30(%r15), %rsi
addl $0x2, %edx
movq (%rsi), %rax
leaq 0xe8(%rsp), %rdi
callq *0x8(%rax)
leaq 0x98(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r12, %rdi
leaq 0x18(%rsp), %r14
movq %r14, %rsi
callq 0x52b8
leaq 0xe8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x52b8
leaq 0x120(%rsp), %rdi
callq 0x2898
leaq 0xd0(%rsp), %rdi
callq 0x2898
movq %rbx, %r14
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
je 0x4794
xorl %r15d, %r15d
pushq $0x1
popq %rbp
subq %rcx, %rax
sarq $0x3, %rax
movslq %r15d, %r13
cmpq %rbp, %rax
jbe 0x4772
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4c06
movq (%rax), %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0x4c06
movq (%rax), %rsi
movq %r14, %rdi
callq 0x2513
movl %ebp, %edx
testb %al, %al
jne 0x475d
movl %r15d, %edx
incq %rbp
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movl %edx, %r15d
movq %rbx, %r14
jmp 0x4721
movq %r12, %rdi
movq %r13, %rsi
callq 0x4c06
movq (%rax), %rax
movl 0x30(%rax), %ecx
movl %ecx, 0x70(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
jmp 0x47c4
leaq 0x98(%rsp), %rdi
callq 0x24f8
movl 0xc8(%rsp), %eax
movl %eax, 0x70(%rsp)
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movaps %xmm2, 0x60(%rsp)
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rdi
movq (%rdi), %rax
movl %r14d, %esi
leaq 0x40(%rsp), %rdx
callq *0x10(%rax)
leaq 0x78(%rsp), %rdi
callq 0x2898
movq %r12, %rdi
callq 0x5284
movl 0x14(%rsp), %eax
movl %eax, %r14d
leaq 0x40(%rsp), %r15
jmp 0x45fc
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, %ebp
movl 0xc(%rbx), %r14d
leaq 0x40(%rsp), %r13
testl %r14d, %r14d
jle 0x48d7
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
leal -0x1(%r14), %r15d
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq *0x30(%rax)
movl %eax, %r12d
movq 0x30(%rbx), %rsi
movq (%rsi), %rax
movq %r13, %rdi
movl %r12d, %edx
callq *0x8(%rax)
cmpl 0xc(%rbx), %r14d
je 0x48b5
movq 0x30(%rbx), %rsi
leal 0x1(,%r12,2), %edx
movq (%rsi), %rax
leaq 0x188(%rsp), %rdi
callq *0x8(%rax)
leal (%r12,%r12), %r14d
leaq 0x1c0(%rsp), %rdi
callq 0x2898
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rsi
addl $0x2, %r14d
movq (%rsi), %rax
leaq 0x138(%rsp), %rdi
movl %r14d, %edx
callq *0x8(%rax)
leaq 0x170(%rsp), %rdi
callq 0x2898
movq 0x8(%rsp), %rbx
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl %r12d, %esi
movq %r13, %rdx
callq *0x10(%rax)
leaq 0x78(%rsp), %rdi
callq 0x2898
movl %r15d, %r14d
jmp 0x4821
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x492f
movq %rax, %rbx
jmp 0x4904
jmp 0x48f4
jmp 0x492f
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x2898
leaq 0xd0(%rsp), %rdi
callq 0x2898
jmp 0x4932
jmp 0x492f
jmp 0x492f
jmp 0x492f
movq %rax, %rbx
jmp 0x493c
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2898
jmp 0x4946
jmp 0x492f
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2898
leaq 0x20(%rsp), %rdi
callq 0x5284
movq %rbx, %rdi
callq 0x2240