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

int main(int argc, char *argv[])
{
  
  FILE  *rh,*wh;
  unsigned long	*l,filesize,i;
  
  char *infile  = argv[1];
  char *outfile = argv[2];
  
  if(infile==NULL || outfile==NULL)
  {
  	puts("arg: infile outfile");
  	return -1;
  }
  
  rh=fopen(infile,"rb");
  if(rh==NULL)
  {
  	printf("Cant open %s\n",infile);
  	return -1;
  }
  
  wh=fopen(outfile,"wb");
  if(wh==NULL)
  {
  	printf("Cant write to %s\n",outfile);
  	fclose(rh);
  	return -1;
  }
  
 
  fseek(rh,0,SEEK_END);
  filesize = ftell(rh);
  fseek(rh,0,SEEK_SET);
  
  printf("filesize %d -> ",filesize);
  if(filesize&4 != 0) filesize=(filesize+4) - (filesize&3);
  printf("%d\n",filesize);
  
  l=(unsigned long*)malloc(filesize);
  fread(l,1,filesize,rh);
  
  for(i=0;i<filesize/4;i++)
  {
  	l[i]=(l[i]>>24) | ((l[i] >> 8)&0x0000ff00) | ((l[i] << 8)&0x00ff0000) | (l[i]<<24);
  }

  fwrite(l,1,filesize,wh);

  free(l);
  fclose(rh);
  fclose(wh);
  	
  return 0;
}
