Sort before generating unique function names to get stable output