... can a man be a freemason and be a legitmate, if terrible, pope?
No.
Nomen dantes sectae massonicae aliisve eiusdem generis associationibus quae contra Ecclesiam vel legitimas civiles potestates machinantur, contrahunt ipso facto excommunicationem Sedi Apostolicae simpliciter reservatam."Affiliation With Masonic or Similar Societies. Those who join a Masonic sect or other societies of the same sort, which plot against the Church or legitimate civil authority, incur ipso facto an excommunication simply reserved to the Holy See (c. 2335)."
- CANON LAW, A Text and Commentary, by Bouscaren and Ellis, pg. 925