The line appears in Moliere's 1668 comedy L'Avare, where the miser Harpagon uses it to justify starving his household. The idea is much older: Socrates is reported to have said something similar, and it circulated in Latin as edere oportet ut vivas, non vivere ut edas.
Moliere's genius was to put a noble Greek sentiment in the mouth of a cheapskate, turning philosophy into punchline. The chiasmus becomes self-parody the moment Harpagon speaks it.
The structure is perfectly symmetrical: two verbs, one preposition, repeated in mirror order. It is a textbook example of why teachers reach for chiasmus examples when introducing the concept.