I think the same copyright concerns apply when working with binaries, which is why clean-room reverse-engineering was invented in the first place. So that no disassembled/decompiled code could be copied into the newly created codebase.
https://en.wikipedia.org/wiki/Clean-room_design
It would be a combination of reverse engineering and clean rooming, assisted with FOSS tools and LLMs; run NSA Ghidra to decompile the binary, LLM-clean the output code, LLM-generate the clean-room spec, LLM-verify the clean-room spec is not copyright infringing, LLM-generate code from the clean-room spec.