Port bam_sort.c completely to new API.