/******************************************************************************
*									      *
*  512-BIT SUBTRACT							      *
*  03/28/10 (dkc)							      *
*									      *
******************************************************************************/
unsigned int carry(unsigned int a, unsigned int b, unsigned int sum);
void sub512(unsigned int *a, unsigned int *b) {
unsigned int a0,a1,a2,a3,a4,a5,a6,a7,b0,b1,b2,b3,b4,b5,b6,b7;
unsigned int a8,a9,a10,a11,a12,a13,a14,a15,b8,b9,b10,b11,b12,b13,b14,b15;
unsigned int s0,s1,s2,s3,s4,s5,s6,s7,temp,c,c1,c2,c3,c4,c5,c6,c7;
unsigned int s8,s9,s10,s11,s12,s13,s14,s15,c8,c9,c10,c11,c12,c13,c14,c15;
a0=*a;
a1=*(a+1);
a2=*(a+2);
a3=*(a+3);
a4=*(a+4);
a5=*(a+5);
a6=*(a+6);
a7=*(a+7);
a8=*(a+8);
a9=*(a+9);
a10=*(a+10);
a11=*(a+11);
a12=*(a+12);
a13=*(a+13);
a14=*(a+14);
a15=*(a+15);

b0=*b;
b1=*(b+1);
b2=*(b+2);
b3=*(b+3);
b4=*(b+4);
b5=*(b+5);
b6=*(b+6);
b7=*(b+7);
b8=*(b+8);
b9=*(b+9);
b10=*(b+10);
b11=*(b+11);
b12=*(b+12);
b13=*(b+13);
b14=*(b+14);
b15=*(b+15);

b0=~b0;
b1=~b1;
b2=~b2;
b3=~b3;
b4=~b4;
b5=~b5;
b6=~b6;
b7=~b7;
b8=~b8;
b9=~b9;
b10=~b10;
b11=~b11;
b12=~b12;
b13=~b13;
b14=~b14;
b15=~b15;

temp=b15+1;
c=carry(b15,1,temp);
b15=temp;
temp=b14+c;
c=carry(b14,c,temp);
b14=temp;
temp=b13+c;
c=carry(b13,c,temp);
b13=temp;
temp=b12+c;
c=carry(b12,c,temp);
b12=temp;
temp=b11+c;
c=carry(b11,c,temp);
b11=temp;
temp=b10+c;
c=carry(b10,c,temp);
b10=temp;
temp=b9+c;
c=carry(b9,c,temp);
b9=temp;
temp=b8+c;
c=carry(b8,c,temp);
b8=temp;
temp=b7+c;
c=carry(b7,c,temp);
b7=temp;
temp=b6+c;
c=carry(b6,c,temp);
b6=temp;
temp=b5+c;
c=carry(b5,c,temp);
b5=temp;
temp=b4+c;
c=carry(b4,c,temp);
b4=temp;
temp=b3+c;
c=carry(b3,c,temp);
b3=temp;
temp=b2+c;
c=carry(b2,c,temp);
b2=temp;
temp=b1+c;
c=carry(b1,c,temp);
b1=temp;
b0=b0+c;

s15=a15+b15;
c15=carry(a15,b15,s15);
s14=a14+b14;
c14=carry(a14,b14,s14);
s13=a13+b13;
c13=carry(a13,b13,s13);
s12=a12+b12;
c12=carry(a12,b12,s12);
s11=a11+b11;
c11=carry(a11,b11,s11);
s10=a10+b10;
c10=carry(a10,b10,s10);
s9=a9+b9;
c9=carry(a9,b9,s9);
s8=a8+b8;
c8=carry(a8,b8,s8);
s7=a7+b7;
c7=carry(a7,b7,s7);
s6=a6+b6;
c6=carry(a6,b6,s6);
s5=a5+b5;
c5=carry(a5,b5,s5);
s4=a4+b4;
c4=carry(a4,b4,s4);
s3=a3+b3;
c3=carry(a3,b3,s3);
s2=a2+b2;
c2=carry(a2,b2,s2);
s1=a1+b1;
c1=carry(a1,b1,s1);
s0=a0+b0;

temp=s14+c15;
c14+=carry(s14,c15,temp);
s14=temp;

temp=s13+c14;
c13+=carry(s13,c14,temp);
s13=temp;

temp=s12+c13;
c12+=carry(s12,c13,temp);
s12=temp;

temp=s11+c12;
c11+=carry(s11,c12,temp);
s11=temp;

temp=s10+c11;
c10+=carry(s10,c11,temp);
s10=temp;

temp=s9+c10;
c9+=carry(s9,c10,temp);
s9=temp;

temp=s8+c9;
c8+=carry(s8,c9,temp);
s8=temp;

temp=s7+c8;
c7+=carry(s7,c8,temp);
s7=temp;

temp=s6+c7;
c6+=carry(s6,c7,temp);
s6=temp;

temp=s5+c6;
c5+=carry(s5,c6,temp);
s5=temp;

temp=s4+c5;
c4+=carry(s4,c5,temp);
s4=temp;

temp=s3+c4;
c3+=carry(s3,c4,temp);
s3=temp;

temp=s2+c3;
c2+=carry(s2,c3,temp);
s2=temp;

temp=s1+c2;
c1+=carry(s1,c2,temp);
s1=temp;

s0=s0+c1;

*b=s0;
*(b+1)=s1;
*(b+2)=s2;
*(b+3)=s3;
*(b+4)=s4;
*(b+5)=s5;
*(b+6)=s6;
*(b+7)=s7;
*(b+8)=s8;
*(b+9)=s9;
*(b+10)=s10;
*(b+11)=s11;
*(b+12)=s12;
*(b+13)=s13;
*(b+14)=s14;
*(b+15)=s15;
return;
}