// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, %rbx
movl %esi, 0x18(%rsp)
cmpl $-0x1, %esi
je 0x4eff
movl 0xc(%rbx), %r14d
testl %r14d, %r14d
jle 0x4feb
leaq 0x30(%rsp), %r12
leal -0x1(%r14), %edx
movq (%rbx), %rax
movq %rbx, %rdi
movl 0x18(%rsp), %esi
movl %edx, 0x1c(%rsp)
callq *0x30(%rax)
movl %eax, %r13d
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x30(%rbx), %rsi
movq (%rsi), %rax
movq %r12, %rdi
movl %r13d, %edx
callq *0x8(%rax)
movq %r12, %rdi
callq 0x2946
movq %r14, 0x20(%rsp)
movq %r12, %r14
movq (%rax), %r15
movq 0x8(%rax), %r12
cmpq %r15, %r12
je 0x4d1c
leaq 0x38(%r15), %rbp
cmpq %r12, %rbp
je 0x4d01
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2609
movq %rbp, %rcx
testb %al, %al
jne 0x4cf3
movq %r15, %rcx
addq $0x38, %rbp
movq %rcx, %r15
cmpq %r12, %rbp
jne 0x4cde
jmp 0x4d04
movq %r15, %rcx
movq %rcx, 0x88(%rsp)
movq %rsp, %rdi
leaq 0x88(%rsp), %rsi
callq 0x59fa
movq 0x20(%rsp), %r15
cmpl 0xc(%rbx), %r15d
movq %r14, %r12
je 0x4dd7
movq 0x30(%rbx), %rsi
leal 0x1(,%r13,2), %edx
movq (%rsi), %rax
leaq 0x88(%rsp), %rdi
callq *0x8(%rax)
leal (,%r13,2), %edx
movq 0x30(%rbx), %rsi
addl $0x2, %edx
movq (%rsi), %rax
leaq 0xd8(%rsp), %rdi
callq *0x8(%rax)
leaq 0x88(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rsp, %r14
movq %r14, %rdi
leaq 0x28(%rsp), %rbp
movq %rbp, %rsi
callq 0x59fa
leaq 0xd8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x59fa
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x4dba
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x4dd7
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0x4e4a
movq (%rsp), %rax
movq 0x8(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq $0x2, %rdx
jb 0x4e7c
xorl %ebp, %ebp
movl $0x1, %r15d
movslq %ebp, %rsi
cmpq %rsi, %rdx
jbe 0x4ffd
movq (%rax,%r15,8), %rdi
movq (%rax,%rsi,8), %rsi
callq 0x2609
movl %r15d, %ecx
testb %al, %al
jne 0x4e26
movl %ebp, %ecx
incq %r15
movq (%rsp), %rax
movq 0x8(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movl %ecx, %ebp
cmpq %r15, %rdx
ja 0x4e04
movslq %ecx, %rsi
movq 0x20(%rsp), %r15
jmp 0x4e7e
leaq 0x88(%rsp), %rdi
callq 0x25e8
movl 0xb8(%rsp), %eax
movl %eax, 0x60(%rsp)
movups 0x88(%rsp), %xmm0
movups 0x98(%rsp), %xmm1
movups 0xa8(%rsp), %xmm2
jmp 0x4e9d
xorl %esi, %esi
cmpq %rsi, %rdx
jbe 0x500b
movq (%rax,%rsi,8), %rax
movl 0x30(%rax), %ecx
movl %ecx, 0x60(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl %r13d, %esi
movq %r12, %rdx
callq *0x10(%rax)
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x4ed3
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4ee9
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
cmpl $0x1, %r15d
movl 0x1c(%rsp), %eax
movl %eax, %r14d
jg 0x4c81
jmp 0x4feb
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movl 0xc(%rbx), %r13d
testl %r13d, %r13d
jle 0x4feb
movl %eax, %ebp
leaq 0x30(%rsp), %r15
movl %r13d, %r14d
leal -0x1(%r14), %r13d
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq *0x30(%rax)
movl %eax, %r12d
movq 0x30(%rbx), %rsi
movq (%rsi), %rax
movq %r15, %rdi
movl %r12d, %edx
callq *0x8(%rax)
cmpl 0xc(%rbx), %r14d
je 0x4fb7
movq 0x30(%rbx), %rsi
leal 0x1(,%r12,2), %edx
movq (%rsi), %rax
leaq 0x178(%rsp), %rdi
callq *0x8(%rax)
movq 0x1b0(%rsp), %rdi
testq %rdi, %rdi
je 0x4f81
movq 0x1c0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
leal (%r12,%r12), %edx
movq 0x30(%rbx), %rsi
addl $0x2, %edx
movq (%rsi), %rax
leaq 0x128(%rsp), %rdi
callq *0x8(%rax)
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x4fb7
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl %r12d, %esi
movq %r15, %rdx
callq *0x10(%rax)
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x4fde
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
leal 0x1(%r13), %eax
cmpl $0x1, %eax
jg 0x4f1c
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2095(%rip), %rdi      # 0x7099
xorl %eax, %eax
callq 0x21d0
leaq 0x2087(%rip), %rdi      # 0x7099
xorl %eax, %eax
callq 0x21d0
jmp 0x5086
jmp 0x5086
jmp 0x5024
movq %rax, %rbx
jmp 0x5044
movq %rax, %rbx
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x5044
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x5089
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x5089
jmp 0x5086
jmp 0x5086
movq %rax, %rbx
jmp 0x50a0
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x50b6
movq 0x78(%rsp), %rsi
jmp 0x50ae
jmp 0x5086
jmp 0x5086
jmp 0x5086
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x50a0
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x50b6
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2250