Right, so if company finds out that you have code written on company time meant to be used to do company work, company can then say that all employs must be able to use that code. OR they could say that you can no longer use that code. No longer abiding by either mandate could be cause for dismissal.
Legal construct or not, it is a work product that would be owned by the company. Using that code at a new company would be wrong as well.