Hmm, IANAL, though I seem to believe there tends to be a question of "have you seen the original code before writing your clone" - which presumes that you still risk copying some code - or are you doing a "cleanroom reimplementation" without ever at all seeing the original code, just basing purely on a specification of the original, ideally written by someone else. As long as it's not pristine cleanroom, I think it's potentially murky territory.