Replace this...
IF PORTC.2 = 1 THEN IOUT = IOUT - 1

...with this...
IF PORTC.2 = 1 THEN if IOUT > 0 then
IOUT = IOUT - 1
endif