A voltage divider of R4 and R5 establishes a reference voltage V1 at the non-inverting input. By making the series resistance of R1 and R2 equal to R5, the comparator will switch when VIN = 0. Diode D1 insures that V3 clamps near ground. The voltage divider of R2 and R3 then prevents V2 from going below ground. A small amount of hysteresis is setup to ensure rapid output voltage transitions.