General rule
The amount of any charitable contribution of property otherwise taken into account under this section shall be reduced by the sum of—
(A) the amount of gain which would not have been long-term capital gain (determined without regard to section 1221(b)(3)) if the property contributed had been sold by the taxpayer at its fair market value (determined at the time of such contribution), and
(B) in the case of a charitable contribution— (i) of tangible personal property— (I) if the use by the donee is unrelated to the purpose or function constituting the basis for its exemption under section 501 (or, in the case of a governmental unit, to any purpose or function described in subsection (c)), or (II) which is applicable property (as defined in paragraph (7)(C), but without regard to clause (ii) thereof) which is sold, exchanged, or otherwise disposed of by the donee before the last day of the taxable year in which the contribution was made and with respect to which the donee has not made a certification in accordance with paragraph (7)(D), (ii) to or for the use of a private foundation (as defined in section 509(a)), other than a private foundation described in subsection (b)(1)(F), (iii) of any patent, copyright (other than a copyright described in section 1221(a)(3) or 1231(b)(1)(C)), trademark, trade name, trade secret, know-how, software (other than software described in section 197(e)(3)(A)(i)), or similar property, or applications or registrations of such property, or (iv) of any taxidermy property which is contributed by the person who prepared, stuffed, or mounted the property or by any person who paid or incurred the cost of such preparation, stuffing, or mounting, the amount of gain which would have been long-term capital gain if the property contributed had been sold by the taxpayer at its fair market value (determined at the time of such contribution).
For purposes of applying this paragraph (other than in the case of gain to which section 617(d)(1), 1245(a), 1250(a), 1252(a), or 1254(a) applies), property which is property used in the trade or business (as defined in section 1231(b)) shall be treated as a capital asset. For purposes of applying this paragraph in the case of a charitable contribution of stock in an S corporation, rules similar to the rules of section 751 shall apply in determining whether gain on such stock would have been long-term capital gain if such stock were sold by the taxpayer.