I expect I'm not giving you a full picture of what a Legendre transformation is, but here's a systematic way to generate potentials, H, F and G...
Start with dU = TdS pdV.
From the product rule: dU = TdS {d(pV)  Vdp}
We can write this as: d{U + pV} = TdS + Vdp
U + pV is usually designated as H. It is the enthalpy potential. Its 'natural variables' are S and P.
We can producttransform TdS instead of pdV, and obtain the Helmholtz function U  TS, with natural variables T and V.
Finally we can transform both TdS and pdV,obtaining the Gibbs function G = U + pV – TS, with natural variables p and T.
