I've heard multiple stories from people who can't even look at the Linux source before they do something in their company's kernel because the act of just looking at it compromises them legally. So which is it?
Clean room implementation only happens for very special codes, like codecs or efficient matrix multmul that took billions of trials to develop with AI. Not for 2-3 lines of code snippets that do one simple thing and are already covered online in hundreds of places.
One of the canonical examples of software reverse engineering is Phoenix Technologies producing a compatible BIOS for IBM PC. They did exactly what OP described - had one person look at (public but copyrighted) IBM source and produce an extremely detailed design document, then another team went and wrote a new BIOS from scratch following that document. The issue at hand was copyright, not patents.
That's for patents not for copyrights. All you need to do is make it a little different, generate until satisfied for patent safe code. Another model can also do the patent checking.