// File: cfiutak1[P]HPyC-KD-Tree/./utils/filewriter/../../src/kdtree/KNNQueue.hpp
// Function: hpyc::KNNQueue<float>::siftDownRoot()
void KNNQueue<ItemT>::siftDownRoot() {
    std::size_t index = 0;
    std::size_t first_index_without_both_children = this->current_size / 2 - (this->current_size % 2 == 0);

    while (index < first_index_without_both_children) {
        std::size_t left_child = 2 * index + 1;
        std::size_t larger_child = left_child + (this->array[left_child] < this->array[left_child + 1]);
        std::size_t swap_destination = index + ((larger_child - index) & (0 - (this->array[index] < this->array[larger_child])));

        if (index == swap_destination) { return; }

        std::swap(
            this->array[index],
            this->array[swap_destination]
        );

        index = swap_destination;
    }

    // Special case for when the index only has one child.
    if (index == first_index_without_both_children && (this->current_size % 2 == 0)) {
        std::size_t left_child = 2 * index + 1;
        std::size_t swap_destination = index + ((left_child - index) & (0 - (this->array[index] < this->array[left_child])));

        std::swap(
            this->array[index],
            this->array[swap_destination]
        );
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq $0x0, -0x10(%rbp)
movq 0x20(%rcx), %rax
shrq %rax
movq 0x20(%rcx), %rcx
andq $0x1, %rcx
cmpq $0x0, %rcx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x6271
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rdi
movq 0x28(%rax), %rsi
movq -0x20(%rbp), %rax
addq $0x1, %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x5fc0
movq -0x60(%rbp), %rcx
movb %al, %dl
movq -0x48(%rbp), %rax
andb $0x1, %dl
movzbl %dl, %edx
addq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq -0x28(%rbp), %rcx
subq -0x10(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rdi
movq 0x28(%rax), %rsi
movq -0x28(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x5fc0
movq -0x58(%rbp), %rcx
movb %al, %dl
movq -0x50(%rbp), %rax
andb $0x1, %dl
movzbl %dl, %esi
xorl %edx, %edx
subl %esi, %edx
movslq %edx, %rdx
andq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x623d
jmp 0x632a
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rdi
movq 0x28(%rax), %rsi
movq -0x30(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x60a0
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x616f
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x632a
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x632a
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movq -0x38(%rbp), %rcx
subq -0x10(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rdi
movq 0x28(%rax), %rsi
movq -0x38(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x5fc0
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movb %al, %sil
movq -0x48(%rbp), %rax
andb $0x1, %sil
movzbl %sil, %edi
xorl %esi, %esi
subl %edi, %esi
movslq %esi, %rsi
andq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, -0x40(%rbp)
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rdi
movq 0x28(%rax), %rsi
movq -0x40(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x60a0
addq $0x70, %rsp
popq %rbp
retq