Code:

#include <stdio.h>
void swap(unsigned long &a,unsigned long &b)
{
unsigned long temp = a;
a = b;
b = temp;
}
void swap(__int64 &a,__int64 &b)
{
__int64 temp = a;
a = b;
b = temp;
}
/**/
unsigned int hcf(unsigned long x,unsigned long y)
{
if (x == y || !y)
return x;
if (!x)
return y;
for (;;)
{
if (x > y)
{
x = x % y;
if (!x)
return y;
}
else
{
y = y % x;
if (!y)
return x;
}
}
}
int main()
{
unsigned long height;
unsigned long a,b,c,d,e,f,g,h;
__int64 sum;
__int64 diff;
double cond2_1,cond2_2;
for (height = 3;height <= 65535; height += 2)
{
for (a = 1; a <= height; a += 2)
{
b = height - a;
if (hcf(a,b) > 1)
continue;
sum = (__int64) a * (__int64) a + (__int64) b * (__int64) b;
d = b;
for (c = a+2;; c += 2)
{
diff = (__int64) c * (__int64) c;
if (diff > sum)
break;
diff = sum - diff;
while ( (__int64) d * (__int64) d > diff)
d -= 2;
if ( (__int64) d * (__int64) d == diff)
{
f = d;
for (e = c+2;; e += 2)
{
diff = (__int64) e * (__int64) e;
if (diff > sum)
break;
diff = sum - diff;
while ( (__int64) f * (__int64) f > diff)
f -= 2;
if ( (__int64) f * (__int64) f == diff)
{
h = f;
for (g = e+2;; g += 2)
{
diff = (__int64) g * (__int64) g;
if (diff > sum)
break;
diff = sum - diff;
while ( (__int64) h * (__int64) h > diff)
h -= 2;
if ( (__int64) h * (__int64) h == diff)
{
unsigned long a1,b1,c1,d1,e1,f1,g1,h1;
__int64 ab,cd,ef,gh;
__int64 wanted;
a1 = a;
b1 = b;
ab = (__int64) a * (__int64) b;
c1 = c;
d1 = d;
cd = (__int64) c * (__int64) d;
e1 = e;
f1 = f;
ef = (__int64) e * (__int64) f;
g1 = g;
h1 = h;
gh = (__int64) g * (__int64) h;
/* Make ab the smallest and cd the largest value
by first ensuring that ab <= cd and ef <= gh
and then putting the smaller of ab and ef in ab
and the larger of cd and gh in cd */
if (cd < ab)
{
swap(a1,c1);
swap(b1,d1);
swap(ab,cd);
}
if (gh < ef)
{
swap(e1,g1);
swap(f1,h1);
swap(ef,gh);
}
if (ef < ab)
{
swap(a1,e1);
swap(b1,f1);
swap(ab,ef);
}
if (cd < gh)
{
swap(c1,g1);
swap(d1,h1);
swap(cd,gh);
}
wanted = (cd-ef)*(cd+ef);
if ((gh-ab)*(gh+ab) == wanted)
{
printf("Hurray we have an answer! %d %d %d %d %d %d %d %d\n",a1,b1,c1,d1,e1,f1,g1,h1);
printf("%I64d %I64d %I64d %I64d %I64d %I64d\n",
(__int64) a1 * (__int64) a1 +
(__int64) b1 * (__int64) b1,
(__int64) c1 * (__int64) c1 +
(__int64) d1 * (__int64) d1,
(__int64) e1 * (__int64) e1 +
(__int64) f1 * (__int64) f1,
(__int64) g1 * (__int64) g1 +
(__int64) h1 * (__int64) h1,
(__int64) a1*(__int64) a1*(__int64) b1*(__int64) b1+
(__int64) c1*(__int64) c1*(__int64) d1*(__int64) d1,
(__int64) e1*(__int64) e1*(__int64) f1*(__int64) f1+
(__int64) g1*(__int64) g1*(__int64) h1*(__int64) h1);
}
}
}
}
}
}
}
}
}
return 0;
}