#include <stdio.h>

void main (void) {
	int a, b; 			/* Input values must be int, the */
	char a1, b1, a2, b2;		/* for loop is an infinite */
	char A, D;


        for(a = 0; a <= 255; a++) {
        for(b = 0; b <= 255; b++) {

	a1 = a; b2 = b;			/* Copy input values to a char */

	A = (a1 + b1) / 2;		/* Low-pass (average) filter */
	D = a1 - b1;			/* High-pass (difference) filter */
	if(((a1 + b1) < 0) && (D & 1))	/* Use floor function if A was */
		A--; 	  		/* Rounded off */
	if(((a1 - b1) < -128) || ((a1 - b1) > 127))
		A += 128;   		/* See if the difference is out of */
					/* range */

	a2 = A + (D / 2);   		/* Calculate the first value */
	b2 = A - (D / 2);   		/* Calculate the second value */
	if (D & 1)    			/* Test to see if D is odd */
	if (D < 0) b2++; else a2++; 	/* Increment the larger value */

	if((a1 != a2) || (b1 != b2)) {
		puts("Lossy data pair found!");
		printf("a1 = %d, a2 = %d\nb1 = %d, b2 = %d", a1, a2, b1, b2);
	}

	}
	}
}
