// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/../../pkgs/RNBasics/RNHeap.cpp
// Function: gaps::RNHeap<gaps::R3MeshEdge*>::Push(gaps::R3MeshEdge*)
void RNHeap<PtrType>::
Push(PtrType entry)
{
  // Allocate space for entry
  if (nentries == nallocated) {
    nallocated = (nallocated == 0) ? 1 : 2 * nallocated;
    PtrType *newentries = new PtrType [nallocated];
    for (int i = 0; i < nentries; i++) {
      newentries[i] = entries[i];
      if (entry_offset >= 0) *((PtrType **) ((unsigned char *) newentries[i] + entry_offset)) = &newentries[i];
      if (entry_callback) *((PtrType **) (*entry_callback)(newentries[i], callback_data)) = &newentries[i];
    }
    if (entries) delete [] entries;
    entries = newentries;
  }

  // Put entry into tail
  entries[nentries] = entry;

  // Update entry backpointer
  if (entry_offset >= 0) *((PtrType **) ((unsigned char *) entries[nentries] + entry_offset)) = &entries[nentries];
  if (entry_callback) *((PtrType **) (*entry_callback)(entries[nentries], callback_data)) = &entries[nentries];

  // Increment number of entries
  nentries++;

  // Bubble tail entry up to its rightful spot
  BubbleUp(nentries-1);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movl 0x8(%rcx), %eax
cmpl 0xc(%rcx), %eax
jne 0x37d99
movq 0x20(%rsp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x37c5a
movl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x37c68
movq 0x20(%rsp), %rax
movl 0xc(%rax), %eax
shll %eax
movl %eax, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movl 0x1c(%rsp), %ecx
movl %ecx, 0xc(%rax)
movslq 0xc(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xf030
movq %rax, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movq 0x20(%rsp), %rcx
movl 0x2c(%rsp), %eax
cmpl 0x8(%rcx), %eax
jge 0x37d62
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movslq 0x2c(%rsp), %rdx
movq (%rcx,%rdx,8), %rsi
movq 0x30(%rsp), %rcx
movslq 0x2c(%rsp), %rdx
movq %rsi, (%rcx,%rdx,8)
cmpl $0x0, 0x14(%rax)
jl 0x37d09
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rdx
movslq 0x2c(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq 0x30(%rsp), %rax
movslq 0x2c(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movslq 0x14(%rcx), %rcx
movq %rdx, (%rax,%rcx)
movq 0x20(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x37d50
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rax
movslq 0x2c(%rsp), %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rcx), %rax
movq 0x30(%rsp), %rdx
movslq 0x2c(%rsp), %rsi
movq (%rdx,%rsi,8), %rdi
movq 0x28(%rcx), %rsi
callq *%rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
jmp 0x37d52
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x37ca6
movq 0x20(%rsp), %rax
cmpq $0x0, (%rax)
je 0x37d8c
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x37d8a
movq 0x8(%rsp), %rdi
callq 0xf670
jmp 0x37d8c
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rsi
movq (%rax), %rcx
movslq 0x8(%rax), %rdx
movq %rsi, (%rcx,%rdx,8)
cmpl $0x0, 0x14(%rax)
jl 0x37dda
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movslq 0x8(%rcx), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq (%rcx), %rax
movslq 0x8(%rcx), %rsi
movq (%rax,%rsi,8), %rax
movslq 0x14(%rcx), %rcx
movq %rdx, (%rax,%rcx)
movq 0x20(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x37e19
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movslq 0x8(%rcx), %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movq %rax, (%rsp)
movq 0x20(%rcx), %rax
movq (%rcx), %rdx
movslq 0x8(%rcx), %rsi
movq (%rdx,%rsi,8), %rdi
movq 0x28(%rcx), %rsi
callq *%rax
movq (%rsp), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rdi
movl 0x8(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x8(%rdi)
movl 0x8(%rdi), %esi
subl $0x1, %esi
callq 0x3c810
addq $0x48, %rsp
retq
nopw (%rax,%rax)