// Guidelines:
// * 'ibufX' and 'obufY' are reserved for buffers.
// * Input and output buffers must be of type INT.
// * Declare buffers separately.
// * Input buffers must be read one at a time.

#include <stdio.h>
#include <stdlib.h>

begin tap1
	// declare each buffer on separate lines
	int ibuf0;	// primary input
	int obuf0;	// connects to ibuf0 of tap2
	int obuf1;	// connects to ibuf0 of add
	int temp = 0;
	
	for (;;) {
		temp = ibuf0;	
		obuf0 = temp;
		obuf1 = temp * 2;
	}
end

begin tap2
	int ibuf0;	// connects to obuf0 of tap1
	int obuf0;	// connects to ibuf0 of tap3
	int obuf1;	// connects to ibuf1 of add
	int temp = 0;
	
	for (;;) {
		obuf0 = temp;
		obuf1 = temp * -1;
		temp = ibuf0;
	}
end

begin tap3
	int ibuf0;	// connects to obuf0 of tap2
	int obuf0;	// connects to ibuf0 of tap4
	int obuf1;	// connects to ibuf2 of add
	int temp = 0;
	
	for (;;) {
		obuf0 = temp;
		obuf1 = temp * 10;
		temp = ibuf0;
	}
end

begin tap4
	int ibuf0;	// connects to obuf0 of tap3
	int obuf0;	// connects to ibuf0 of tap5
	int obuf1;	// connects to ibuf3 of add
	int temp = 0;
	
	for (;;) {
		obuf0 = temp;
		obuf1 = temp * -1;
		temp = ibuf0;
	}
end

begin tap5
	int ibuf0;	// connects to obuf0 of tap4
	int obuf0;	// connects to ibuf4 of add
	int temp = 0;
	
	for (;;) {
		obuf0 = temp * 2;
		temp = ibuf0;
	}
end

begin add
	int ibuf0;	// connects to obuf0 of tap1
	int ibuf1;	// connects to obuf0 of tap2
	int ibuf2;	// connects to obuf0 of tap3
	int ibuf3;	// connects to obuf0 of tap4
	int ibuf4;	// connects to obuf0 of tap5
	int obuf0;	// primary output
	int temp;

	for (;;) {		
		temp = 0;
		// each input buffer must be read one at a time
		temp = ibuf0 + temp;
		temp = ibuf1 + temp;
		temp = ibuf2 + temp;
		temp = ibuf3 + temp;
		temp = ibuf4 + temp;	
		obuf0 = temp;
	}
end
