>Though if heroin was legal it could be manufactured in a sterile environment where you could probably get like 99% purity or something ridiculous like that.
This already happens. Diamorphine (heroin) is commonly used as a painkiller in hospitals. If you've ever been seriously injured and wound up in hospital with a tube going into your arm attached to a button which gives you a dose of painkiller, limited to something like 3 presses an hour, then you've probably taken heroin, likely in large amounts. The nurse may well have called it "morphine" to avoid scaring you.
Famously, "Heroin" was originally a trademark of the Bayer company.
EDIT: apparently this is only true in the UK. This might be why we don't have the fancy modern opiates here, oxycontin etc.