Getting that right might be as difficult as reference counting objects in C++.
= = =
But no worries, AI can do it, right?
Major /S!
On my final project before retirement, the code base belonged to a government customer. It was never going to see refactoring using AI, but frankly that might be the only path to success with the time and budget constraints. It would need serious code reviews and very stringent testing before getting a "sign off" for production. I've seen the sloppy code generated by AI. Tons of extraneous code added that did nothing for the functionality. Worse, the outputs change on each iteration. It's not like a pure function with constrained inputs and consistent output each time. Aesthetically, it doesn't follow project coding guidelines. Metrically, it produces code with no care about cyclomatic complexity.
I used AI a few times to generate a starting template when exploring a new language implementation of a problem solved in another language e.g. generate a Rust server that consumes GET/POST operations with JSON I/O similar to a Java Spring server. You get a working first cut, then move on to doing a clean implementation that matches project guidelines for style, metric conformance and passes unit tests.