Mishkat al-Masabih 1655
‘Auf b. Malik said:
God’s messenger prayed at a funeral and I have retained in my memory some of his supplication. He was saying, “O God, forgive him, show him mercy, grant him security, pardon him, grant him a noble provision and a spacious lodging, wash him with water, snow and ice, purify him from sins as Thou hast purified the white garment from filth, give him a better abode in place of his present one, a better family in place of his present one, and a better spouse in place of his present one, cause him to enter paradise and preserve him from the trial in the grave and the punishment in hell.” A version has “And guard him from the trial in the grave and the punishment in hell.” He added that the result was that he wished he had been that dead man. 

Muslim transmitted it.
وَعَنْ عَوْفِ بْنِ مَالِكٍ قَالَ: صَلَّى رَسُولِ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ عَلَى جَنَازَةٍ فَحَفِظْتُ مِنْ دُعَائِهِ وَهُوَ يَقُولُ: «اللَّهُمَّ اغْفِرْ لَهُ وَارْحَمْهُ وَعَافِهِ وَاعْفُ عَنْهُ وَأَكْرِمْ نُزُلَهُ وَوَسِّعْ مُدْخَلَهُ وَاغْسِلْهُ بِالْمَاءِ وَالثَّلْجِ وَالْبَرَدِ وَنَقِّهِ مِنَ الْخَطَايَا كَمَا نَقَّيْتَ الثَّوْبَ الْأَبْيَضَ مِنَ الدنس وأبدله دَارا خيرا من دَاره وَأهلا خَيْرًا مِنْ أَهْلِهِ وَزَوْجًا خَيْرًا مِنْ زَوْجِهِ وَأدْخلهُ الْجنَّة وأعذه من عَذَاب الْقَبْر وَمن عَذَاب النَّار» . وَفِي رِوَايَةٍ: «وَقِهِ فِتْنَةَ الْقَبْرِ وَعَذَابَ النَّارِ» قَالَ حَتَّى تَمَنَّيْتُ أَنْ أَكُونَ أَنَا ذَلِكَ الْمَيِّت. رَوَاهُ مُسلم