// File: Manca[P]algorithms1/./lib/Heap.hpp
// Function: DataStructures::Heap::bubbleDown(bool)
void bubbleDown(bool minHeap)
        {
            if (_heap.size() > 1)
            {
                int rootIndex = 0;
                int leftChildIdx = leftChild(rootIndex);
                int rightChildIdx = rightChild(rootIndex);
                
                if (_minHeap)
                {
                    size_t minChild = (_heap[leftChildIdx] < _heap[rightChildIdx]) ? leftChildIdx : rightChildIdx;
                    while (minChild < _heap.size() && _heap[rootIndex] > _heap[minChild])
                    {
                        // exchange
                        int tmp = _heap[minChild];
                        _heap[minChild] = _heap[rootIndex];
                        _heap[rootIndex] = tmp;
                        
                        // bubble down
                        rootIndex = minChild;
                        leftChildIdx = leftChild(rootIndex);
                        rightChildIdx = rightChild(rootIndex);
                        
                        minChild = (_heap[leftChildIdx] < _heap[rightChildIdx]) ? leftChildIdx : rightChildIdx;
                    }
                }
                else
                {
                    size_t maxChild = (_heap[leftChildIdx] > _heap[rightChildIdx]) ? leftChildIdx : rightChildIdx;
                    while (maxChild < _heap.size() && _heap[rootIndex] < _heap[maxChild])
                    {
                        // exchange
                        int tmp = _heap[maxChild];
                        _heap[maxChild] = _heap[rootIndex];
                        _heap[rootIndex] = tmp;
                        
                        // bubble down
                        rootIndex = maxChild;
                        leftChildIdx = leftChild(rootIndex);
                        rightChildIdx = rightChild(rootIndex);
                        
                        maxChild = (_heap[leftChildIdx] > _heap[rightChildIdx]) ? leftChildIdx : rightChildIdx;
                    }
                }
            }
        }

// Assembly:
subq $0x98, %rsp
movb %sil, %al
movq %rdi, 0x90(%rsp)
andb $0x1, %al
movb %al, 0x8f(%rsp)
movq 0x90(%rsp), %rdi
movq %rdi, 0x58(%rsp)
addq $0x8, %rdi
callq 0x7f90
cmpq $0x1, %rax
jbe 0xc8c3
movq 0x58(%rsp), %rdi
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %esi
callq 0xc910
movq 0x58(%rsp), %rdi
movl %eax, 0x84(%rsp)
movl 0x88(%rsp), %esi
callq 0xc970
movl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x80(%rsp)
testb $0x1, (%rax)
je 0xc6d5
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movslq 0x84(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x54(%rsp)
addq $0x8, %rdi
movslq 0x80(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x54(%rsp), %eax
cmpl (%rcx), %eax
jge 0xc530
movl 0x84(%rsp), %eax
movl %eax, 0x50(%rsp)
jmp 0xc53b
movl 0x80(%rsp), %eax
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %eax
cltq
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %rdi
movq 0x78(%rsp), %rax
movq %rax, 0x40(%rsp)
addq $0x8, %rdi
callq 0x7f90
movq 0x40(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x4f(%rsp)
jae 0xc5b0
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movslq 0x88(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x3c(%rsp)
addq $0x8, %rdi
movq 0x78(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x3c(%rsp), %eax
cmpl (%rcx), %eax
setg %al
movb %al, 0x4f(%rsp)
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0xc5bd
jmp 0xc6d0
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movq 0x78(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x74(%rsp)
addq $0x8, %rdi
movslq 0x88(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x30(%rsp)
addq $0x8, %rdi
movq 0x78(%rsp), %rsi
callq 0x84b0
movl 0x30(%rsp), %ecx
movq 0x58(%rsp), %rdi
movl %ecx, (%rax)
movl 0x74(%rsp), %eax
movl %eax, 0x34(%rsp)
addq $0x8, %rdi
movslq 0x88(%rsp), %rsi
callq 0x84b0
movl 0x34(%rsp), %ecx
movq 0x58(%rsp), %rdi
movl %ecx, (%rax)
movq 0x78(%rsp), %rax
movl %eax, 0x88(%rsp)
movl 0x88(%rsp), %esi
callq 0xc910
movq 0x58(%rsp), %rdi
movl %eax, 0x84(%rsp)
movl 0x88(%rsp), %esi
callq 0xc970
movq 0x58(%rsp), %rdi
movl %eax, 0x80(%rsp)
addq $0x8, %rdi
movslq 0x84(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x38(%rsp)
addq $0x8, %rdi
movslq 0x80(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x38(%rsp), %eax
cmpl (%rcx), %eax
jge 0xc6b5
movl 0x84(%rsp), %eax
movl %eax, 0x2c(%rsp)
jmp 0xc6c0
movl 0x80(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cltq
movq %rax, 0x78(%rsp)
jmp 0xc546
jmp 0xc8c1
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movslq 0x84(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x28(%rsp)
addq $0x8, %rdi
movslq 0x80(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x28(%rsp), %eax
cmpl (%rcx), %eax
jle 0xc71f
movl 0x84(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0xc72a
movl 0x80(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cltq
movq %rax, 0x68(%rsp)
movq 0x58(%rsp), %rdi
movq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
addq $0x8, %rdi
callq 0x7f90
movq 0x18(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x23(%rsp)
jae 0xc79f
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movslq 0x88(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x14(%rsp)
addq $0x8, %rdi
movq 0x68(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl (%rcx), %eax
setl %al
movb %al, 0x23(%rsp)
movb 0x23(%rsp), %al
testb $0x1, %al
jne 0xc7ac
jmp 0xc8bf
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movq 0x68(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x64(%rsp)
addq $0x8, %rdi
movslq 0x88(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x8(%rsp)
addq $0x8, %rdi
movq 0x68(%rsp), %rsi
callq 0x84b0
movl 0x8(%rsp), %ecx
movq 0x58(%rsp), %rdi
movl %ecx, (%rax)
movl 0x64(%rsp), %eax
movl %eax, 0xc(%rsp)
addq $0x8, %rdi
movslq 0x88(%rsp), %rsi
callq 0x84b0
movl 0xc(%rsp), %ecx
movq 0x58(%rsp), %rdi
movl %ecx, (%rax)
movq 0x68(%rsp), %rax
movl %eax, 0x88(%rsp)
movl 0x88(%rsp), %esi
callq 0xc910
movq 0x58(%rsp), %rdi
movl %eax, 0x84(%rsp)
movl 0x88(%rsp), %esi
callq 0xc970
movq 0x58(%rsp), %rdi
movl %eax, 0x80(%rsp)
addq $0x8, %rdi
movslq 0x84(%rsp), %rsi
callq 0x84b0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x10(%rsp)
addq $0x8, %rdi
movslq 0x80(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x10(%rsp), %eax
cmpl (%rcx), %eax
jle 0xc8a4
movl 0x84(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0xc8af
movl 0x80(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
cltq
movq %rax, 0x68(%rsp)
jmp 0xc735
jmp 0xc8c1
jmp 0xc8c3
addq $0x98, %rsp
retq
nopl (%rax,%rax)