In general to avoid IP legal problems in the USA you can't do all of that yourself. Generally one party has to do all of the reverse engineering and write a specification based on that. Then another party can take that specification and write a "clean room" implementation.
https://www.allaboutcircuits.com/news/how-compaqs-clone-comp...
I've been thinking about this recently. What if one of the parties is an LLM?
So... I ask Gemini to write a technical spec and Claude Code to implement it?
Basically a week-end project...
Are there examples where a single person doing it gets successfully sued? It could just be that those companies were extra risk adverse so they came up with monetarily inefficient ways to defend themselves.