rewrite: min-safe sort