The third dredge-up and the carbon star luminosity functions in the Magellanic Clouds