>>15144156A lot of time.
For the same reasons that we have gone from simple protons to heavier atoms, from atoms to organic molecules, from molecules to peptides and lipids, from lipids to cell membranes, until arriving at oses and nucleotides to give DNA capable of reproducing. By duplicating itself, the DNA constantly alters, because the action of the ribosomes is not perfect. Except that life will increase the reproductive potential of DNA molecules that manage to survive. And it's by this principle that natural selection is established, even the largest systems find a way to mutate to give even better systems that will better manage to reduce its entropy. Things in the universe always tend to organize themselves towards thermodynamically advantageous stationary states.
Growing legs isn't more magical than atoms forming molecules, it's just a different scale