Another Shareholder Basis-REG questions!!!

Gain in the Shareholder Basis in a Corporation Calculation.... I understand that if the liability assumed exceeds the basis then it creates a gain...however, I have also read that the gain recognized is the lower of realized gain (FMV of property - Adjusted Basis of Property) or Boot Recieved (Which includes assumed liabilities)..and I also read that if 80% ownership is not property given ownership then there is a gain of the (FMV of the interest of the ownership - adjusted basis)...My question is which one to use if they all or at least more than one scenario exist? Thanks