I did read the other question for background. Yes, this can get a bit complex.
The S Corp loss on the asset sale will flow to the shareholder.
This does not have to do anything in relation to the loan to shareholder.
I am presuming this is a corporate asset loan to shareholder (and not a loan form shareholder which would be a corporate liability)
Let me know if that is not a valid presumption.
Since the shareholder is declaring bankruptcy the best action may be include that loan from the corporation in the bankruptcy. He should check with the bankruptcy attorney to see if that loan can be included.
Even if the loan can not be included in the bankruptcy the shareholder does not have to include canceled debt in taxable income
to the extent he is insolvent at the time of the debt forgiveness.
The issue behind the question is if these were actually loans to the shareholder or were distributions to the shareholder (returns of capital).
"A loan by a corporation to a corporate officer should include the characteristics of a loan made at arm's length. That is, there should be a contract with a stated interest rate, a specified length of time for repayment, and a consequence for failure to repay the loan. Collateral would also be an indication of a loan. A below-market loan is a loan which provides for no interest or interest at a rate below the federal rate that applies. If a corporation issues you, as a shareholder or an employee, a below-market loan, the lender's payment to the borrower is treated as a gift, dividend, contribution to capital, payment of wages, or other payment, depending on the substance of the transaction
The primary determination as to whether or not the debt is bona fide hinges on a key question: When the loan was made,was there a genuine intent that the borrowed funds would be repaid?
See http://www.unclefed.com/SurviveIRS/MSSP/a8shloan.pdf for the IRS audit guide for Shareholder loans that lists the determinative factors.
So the determination if this is a valid loan to the shareholder will be made the loan can be discharged in the bankruptcy or forgiven when the taxpayer is insolvent and will not be included in income of the taxpayer.
Please ask if you need discussion or clarification.