A provision in the contract that the IP is not a work-made-for-hire (WFH) might be effective. But just because something is not a WFH does not mean that the programmer owns the copyright. There are several ways for the purchaser (client) to wind up owning the copyright(s) involved.
If the work qualifies as a WFH, either because the creator is in fact an employee and the creation is within the scope of employment, or because there is a contract explicitly saying so, under US copyright law (17 USC 101) the employer/client is legally the author, and the creator never owns the copyright.
If the work does not qualify as a WFH, but there is a valid contract provision saying that the client owns "all IP", then the creator is the author, but has assigned the copyright as part of the deal. The legal effect is the same as if the author had later separately sold the copyright to the client. The author's life is used to measure the duration of copyright (not the 95 years for corporate authorship). The author may retain the right to assert authorship. But the client owns the copyright.
If the client, in a separate later transaction, explicitly buys the copyright, the client will thereafter own it. The legal effect is essentially the same as 2 above.
If the programmer wants to retain the copyright, it is not enough to include a provision saying that the work is not a WFH. There should ideally be a provision saying that the author (programmer) will retain the copyright(s). At least there should not be a provision saying that the client will own "all IP".
When the programmer agrees to a contract with a "client owns all IP" provision, the programmer is, in effect, selling the copyright as part of the deal. When there are two apparently conflicting provisions in a contract, courts normally try to find a way to honor both. In the case described in the question, this would most likely mean determining that the work was not a WFH, but that the copyright had been transferred by the author to the client.
By the way, all copyright law in the US is now Federal, and does not vary from state to state. State law may affect when a person is considered a bona-fide employee, but once that decision is made, the copyright law (17 USC) takes over. An employment contract can specify that the employee retains copyrights, but this is almost never done. Works created by a bona-fide employee, in the course of the employment, are almost always treated as WFH.