If I pray 4 or 3 rak'ah prayer what do I have to say in a sitting position after second rakat?

Do I say only attahiyat and than go to 3rd rakat or do I say both attahiyyat+allahumma (+rabbana) and than go to 3rd rakat or do I have to say all of them attahiyyat+allahumma+rabbana+salam and than go to 3rd rakat?

1.) Al-Tahiyyaatu Lillaahi wa’l-salawaatu wa’l-tayyibaat. Al-salaamu ‘alayka ayyuha’l-Nabiyyu wa rahmat-Allaahi wa barakaatuhu. Al-salaamu ‘alaynaa wa ‘ala ‘ibaad-illaah il-saaliheen. Ash-hadu an laa ilaaha ill-Allaah wa ash-hadu anna Muhammadan ‘abduhu wa rasooluh.

2.) “Allaahumma salli ‘ala Muhammad wa ‘ala aali Muhammad kama salayta ‘ala Ibraaheem wa ‘ala aali Ibraaheem, innaka hameedun majeed. Allaahumma baarika ‘ala Muhammad wa ‘ala aali Muhammad kama baarakta ‘ala Ibraaheem wa ‘ala aali Ibraaheem, innaka hameedun majeed. Rabbana atina fid-dunya hasanatan wa fil 'akhirati hasanatan waqina 'adhaban-nar. Rabbana-gh-firli Waliwalidayya-Walilmu'mineena-Yawma-Yaqoom-ol-hisab.

3.) salam to both sides