You’re not expected to sniff it for evidence of moldiness. That’s rare in this day and age.
Moreover, when a small amount of the wine is poured for monsieur or madame’s approval, a couple of swirls and sniffs will tell all that one needs to know. If the wine smells and tastes fine, who cares what the cork smells like?
If you have an unquenchable urge to sniff something, sniff the glass before the wine is poured. If it smells like disinfectant or soap or anything else, for that matter, clean glass has no odor, ask for another glass, that is, unless you’ve ordered a bottle of plonk, in which case a little soap might be an improvement.
You might, however, glance casually at the cork to see if it is wet (and stained, if it’s a red wine) partway up. That means that the bottle has been properly stored on its side, with the cork being constantly wet for a tight seal.
Historically, a restaurateur’s presentation of the cork to the patron was for an entirely different reason than sniffing for taint. It’s a practice that began in the nineteenth century when unscrupulous merchants developed the habit of passing off cheap wines as expensive ones.
Wine producers began to combat this practice by printing their names on the corks to prove authenticity. And, of course, the bottle was and still is always opened in the patron’s presence.
Today, rather than risk insulting a good restaurant by either sniffing the cork or putting on your reading glasses to scrutinize it, the best advice is just to ignore it. I like to fiddle with it during the breaks between courses, when in olden times I used to light a cigarette.