D. If

Your task is to optimize the input source code for size. The source code will run on an 8-bit architecture.

There are 256 variables (numbered from 0 to 255), at most 2 inputs (numbered 0 and 1) and 8 outputs (numbered from 0 to 7). All values are 8-bit unsigned integers: values stored in variables, read from input, written to output and existing as constants in the source code. All arithmetics are evaluated modulo 256.

Inputs don't change until the program executes the END instruction. Before running a program, variables and outputs are set to 0.

Input of this task is a source file; output is an optimized version of the source. A submission is not accepted, if:

  • it does not give the same output as the original program would, for arbitrary input; or
  • it executes more than 10^7 instructions for any input; or
  • it references an address out of boundary.
   diagram
source:
http://en.wikipedia.org/wiki/File:FlowchartExample.png)

Language

R, A and B are any of the variables, const is a constant integer; input(N) fetches the Nth input; output(N) is the Nth output; label is a jump destination point in the source code marked by an unique integer.
description syntax in input/output files
expressions
R = const n,const,R
R = A + B +,A,B,R
R = A - B -,A,B,R
R = A > B >,A,B,R
R = A < B <,A,B,R
R = A == B =,A,B,R
R = A != B !,A,B,R
R = input(A) i,A,R
conditional jump:
IF R != 0 GOTO label
c,R,label
unconditional jump:
GOTO label
g,label
generating output:
output(A) = R
o,A,R
jump label (destination of jumps) l,label
end of execution e
comment (whole line ignored): #,text

Scoring

Score is calculated based on the number of instructions of the submission, compared to other teams' submissions - shorter outputs get higher scores.

Example

Original Optimized
l,1
n,0,2
i,2,4
n,1,1
i,1,3
n,3,2
+,4,2,4
n,4,1
+,3,1,3
n,2,2
+,3,2,6
n,0,1
o,1,6
n,6,2
+,4,2,5
n,1,1
o,1,5
e
n,0,2
n,1,4
n,6,5
n,9,6
i,2,1
i,4,3
+,3,5,0
o,2,0
+,1,6,0
o,4,0
e