Reapply r12489: Add pure, const and malloc attributes to proper functions