Joe: I think you mean, "If Bucket 3 is more than Bucket 1..." (not "more than Bucket 2"). At least that is what your ealier step analysis leads me to conclude.
Also, I want to fully inderstand what TurboTax says about claiming the AOTC: "You cannot claim expenses that you paid with tax-free money from an education savings account (ESA) or qualified tuition program (QTP), such as a Section 529 Plan. When you take a distribution form an ESA or QTP, part of it is from your original contribution and part of it is from earnings on the account. You cannot claim expenses paid with the tax-free earnings." I think we can all agree on this so far. But, the next line seems to contradict your bucket/step analysis: "But you can claim expenses paid with money from your original contribution."
Example: I take a qualified distribution from my child's 529 this year of $20,000, which is also the amount of qualified college expenses for the year. Let's say my contribution basis of this $20,000 is $12,000, so 60% of every dollar of this distribution is return of basis.
Assume, of the $20,000 taken from the 529, that $10,000 is for tuition and books. So 60%, or $6,000, of that is return of basis. Therefore, I can say I incurred $4,000 (the maximum for AOTC use) of qualified AOTC expenses that came from return of my basis when I claim my maximum $2,500 AOTC for the year. So this should not subject any part of my 529 withdrawal to tax.
Under your bucket analysis, my Bucket 1 started out at $20,000, but then got reduced by $10,000 (the amount in Bucket 2) to $10,000. Bucket 3 is $20,000, which is more than Bucket 2 (which, again, I don't think is relevant) and greater than the reduced Bucket 1 (if one is matching expenses with distributions and taking their AOTC credit, how can Bucket 3 ever be less than Bucket 1?). So, using your method, I have some taxes to pay from my 529 withdrawal.
So, which is correct? Sorry to get so wordy, but this is probably way more complicated than the legislative authors intended. You are right that one does need a drink.