FreeBSD version of heapsort