decompiled_code:
int SKY_PrintHelp()
{
return puts("TODO.");
}

canonical_decompiled_code:
int func0()
{
return puts("TODO.");
}

original_code:
void SKY_PrintHelp( void ) {
 printf( "TODO.\n" );
}

canonical_original_code:
void SKY_PrintHelp() {
 printf( "TODO.\n" );
}


decompiled_code:
int __fastcall SKY_MeanRM(char *a1)
{
char v1; // si

v1 = *a1;
if ( *a1 == 97 )
return COM_MeanRM(a1 + 1);
if ( v1 == 110 )
return COM_MeanRM_NN(a1 + 1);
return printf("Unknown RM method %c.\n", (unsigned int)v1);
}

canonical_decompiled_code:
int __fastcall func1(char *a1)
{
char v1; // si

v1 = *a1;
if ( *a1 == 97 )
return COM_MeanRM(a1 + 1);
if ( v1 == 110 )
return COM_MeanRM_NN(a1 + 1);
return printf("Unknown RM method %c.\n", (unsigned int)v1);
}

original_code:
void SKY_MeanRM( const char *cmdLine ) {
 char subcommand;
 subcommand = cmdLine[0];
 switch ( subcommand ) {
  case 'a':
  COM_MeanRM( cmdLine+1 );
  break;
  case 'n':
  COM_MeanRM_NN( cmdLine+1 );
  break;
  default:
  printf( "Unknown RM method %c.\n", subcommand );
  return;
 }
}

canonical_original_code:
void SKY_MeanRM(char *cmdLine) {
 char subcommand;
 subcommand = cmdLine[0];
 switch ( subcommand ) {
  case 'a':
  COM_MeanRM( cmdLine+1 );
  break;
  case 'n':
  COM_MeanRM_NN( cmdLine+1 );
  break;
  default:
  printf( "Unknown RM method %c.\n", subcommand );
  return;
 }
}

variable_types:
cmdLine
char *

variable_types: subcommand char

return_type: void


original_code:
void SKY_CmdLoop( void ) {
 char lineBuffer[128];
 printf( "Interactive mode.\n" );
 while ( 1 ) {
  printf( ": " );
  if ( fgets(lineBuffer,sizeof(lineBuffer),stdin) == 0 )
   printf( "read stdin error.\n" );
  if ( SKY_ExecCmd(lineBuffer) == 0 )
   return;
  printf( "----------------------------------------" );
  printf( "----------------------------------------\n" );
 }
}

canonical_original_code:
void SKY_CmdLoop() {
 char lineBuffer[128];
 printf( "Interactive mode.\n" );
 while ( 1 ) {
  printf( ": " );
  if ( fgets(lineBuffer,sizeof(lineBuffer),stdin) == 0 )
   printf( "read stdin error.\n" );
  if ( SKY_ExecCmd(lineBuffer) == 0 )
   return;
  printf( "----------------------------------------" );
  printf( "----------------------------------------\n" );
 }
}

variable_types:
lineBuffer
char [128]


decompiled_code:
__int64 __fastcall SKY_ScriptLoop(const char *a1)
{
__int64 result; // rax
int v2; // ebp
unsigned int v3; // ebx
struct tm *v4; // rax
time_t timer; // [rsp+8h] [rbp-70h] BYREF
char s[16]; // [rsp+10h] [rbp-68h] BYREF
char v7[88]; // [rsp+20h] [rbp-58h] BYREF

printf("Executing script %s\n", a1);
result = FIO_OpenScriptFile(a1);
v2 = 1;
v3 = 0;
if ( (_DWORD)result )
{
while ( (unsigned int)FIO_ReadScript(v7, 64LL) )
{
++v3;
if ( v7[0] != 35 && v7[0] != 10 )
{
time(&timer);
v4 = localtime(&timer);
strftime(s, 0x10uLL, "%X", v4);
printf("| Script line %i (%s): %s", v3, s, v7);
printf("----------------------------------------");
puts("----------------------------------------");
v2 = SKY_ExecCmd(v7);
if ( !v2 )
return FIO_CloseScriptFile();
printf("----------------------------------------");
puts("----------------------------------------");
}
}
result = FIO_CloseScriptFile();
if ( v2 == 1 )
{
scripted = 0;
result = SKY_CmdLoop();
}
}
return result;
}

original_code:
void SKY_ScriptLoop( const char *fileName ) {
 char cmdBuffer[64];
 int n;
 int fin;
 printf( "Executing script %s\n", fileName );
 if ( FIO_OpenScriptFile(fileName) == 0 )
  return;
 n = 0;
 fin = 1;
 while ( FIO_ReadScript( cmdBuffer, sizeof(cmdBuffer) ) != 0 ) {
  time_t tic;
  struct tm *ltime;
  char clocktime[16];
  n++;
  if ( cmdBuffer[0] == '#' || cmdBuffer[0] == '\n' )
   continue;
  time( &tic );
  ltime = localtime( &tic );
  strftime( clocktime, 16, "%X", ltime );
  printf( "| Script line %i (%s): %s", n, clocktime, cmdBuffer );
  printf( "----------------------------------------" );
  printf( "----------------------------------------\n" );
  fin = SKY_ExecCmd(cmdBuffer);
  if ( fin == 0 )
   break;
  printf( "----------------------------------------" );
  printf( "----------------------------------------\n" );
 }
 FIO_CloseScriptFile();
 if ( fin == 1 ) {
  scripted = 0;
  SKY_CmdLoop();
 }
}

canonical_original_code:
void SKY_ScriptLoop(char *fileName) {
 char cmdBuffer[64];
 int n;
 int fin;
 printf( "Executing script %s\n", fileName );
 if ( FIO_OpenScriptFile(fileName) == 0 )
  return;
 n = 0;
 fin = 1;
 while ( FIO_ReadScript( cmdBuffer, sizeof(cmdBuffer) ) != 0 ) {
  long tic;
  struct tm *ltime;
  char clocktime[16];
  n++;
  if ( cmdBuffer[0] == '#' || cmdBuffer[0] == '\n' )
   continue;
  time( &tic );
  ltime = localtime( &tic );
  strftime( clocktime, 16, "%X", ltime );
  printf( "| Script line %i (%s): %s", n, clocktime, cmdBuffer );
  printf( "----------------------------------------" );
  printf( "----------------------------------------\n" );
  fin = SKY_ExecCmd(cmdBuffer);
  if ( fin == 0 )
   break;
  printf( "----------------------------------------" );
  printf( "----------------------------------------\n" );
 }
 FIO_CloseScriptFile();
 if ( fin == 1 ) {
  scripted = 0;
  SKY_CmdLoop();
 }
}

variable_types:
fileName
char *

variable_types:
cmdBuffer
char [64]

variable_types: n int

variable_types: fin int

variable_types: tic long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
clocktime
char [16]


decompiled_code:
__int64 __fastcall SKY_ExecCmd(_BYTE *a1)
{
if ( *a1 != 10 )
printf("Command '%c' not recognized.\n", (unsigned int)(char)*a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
if ( *a1 != 10 )
printf("Command '%c' not recognized.\n", (unsigned int)(char)*a1);
return 1LL;
}

original_code:
int SKY_ExecCmd( const char *line ){
 char command;
 command = line[0];
 switch ( command ) {
 case '\n':
 case '#':
  break;
 case 'm':
  SKY_MeanRM( line+1 );
  break;
 case 'p':
  VIS_DrawPlot( line+1 );
  break;
 case 'l':
  MEM_LoadCulled();
  break;
 case 's':
  MEM_SaveCulled();
  break;
 case 'r':
  MEM_ResetCulled();
  break;
 case 'c':
  if ( CUL_CullCancel(line+1) == 1 )
   return 1;
  break;
 case 'd':
  if ( STAT_DivideCancel(line+1) == 1 )
   return 1;
  break;
 case 'w':
  STAT_WriteToDisk( line+1 );
  break;
 case 'h':
  SKY_PrintHelp();
  break;
 case 'e':
  if ( scripted == 0 && strlen(line) > 2 ) {
   char fname[64];
   scripted = 1;
   strncpy( fname, line+2, 64 );
   fname[strlen(fname)-1] = 0;
   SKY_ScriptLoop( fname );
  }
  break;
 case 'q':
  return 0;
 default:
  printf("Command '%c' not recognized.\n",line[0]);
  break;
 }
 return 1;
}

canonical_original_code:
int SKY_ExecCmd(char *line){
 char command;
 command = line[0];
 switch ( command ) {
 case '\n':
 case '#':
  break;
 case 'm':
  SKY_MeanRM( line+1 );
  break;
 case 'p':
  VIS_DrawPlot( line+1 );
  break;
 case 'l':
  MEM_LoadCulled();
  break;
 case 's':
  MEM_SaveCulled();
  break;
 case 'r':
  MEM_ResetCulled();
  break;
 case 'c':
  if ( CUL_CullCancel(line+1) == 1 )
   return 1;
  break;
 case 'd':
  if ( STAT_DivideCancel(line+1) == 1 )
   return 1;
  break;
 case 'w':
  STAT_WriteToDisk( line+1 );
  break;
 case 'h':
  SKY_PrintHelp();
  break;
 case 'e':
  if ( scripted == 0 && strlen(line) > 2 ) {
   char fname[64];
   scripted = 1;
   strncpy( fname, line+2, 64 );
   fname[strlen(fname)-1] = 0;
   SKY_ScriptLoop( fname );
  }
  break;
 case 'q':
  return 0;
 default:
  printf("Command '%c' not recognized.\n",line[0]);
  break;
 }
 return 1;
}

variable_types:
line
char *

variable_types: command char

variable_types:
fname
char [64]

return_type: int


decompiled_code:
double __fastcall MAT_GreatCircD(double a1, double a2, double a3, double a4)
{
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v10; // [rsp+8h] [rbp-20h]

v10 = sin(0.5 * a2);
v5 = sin(0.5 * a1);
v6 = a3 * a4 * v5 * v5 + v10 * v10;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = asin(v7);
return v8 + v8;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4)
{
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v10; // [rsp+8h] [rbp-20h]

v10 = sin(0.5 * a2);
v5 = sin(0.5 * a1);
v6 = a3 * a4 * v5 * v5 + v10 * v10;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = asin(v7);
return v8 + v8;
}

original_code:
double MAT_GreatCircD(double dra,double ddec,double cosdec1,double cosdec2) {
 double a, b, c;
 a = sin(ddec/2);
 b = sin(dra/2);
 c = sqrt(a*a + cosdec1*cosdec2*b*b);
 return 2*asin(c);
}

canonical_original_code:
double MAT_GreatCircD(double dra, double ddec, double cosdec1, double cosdec2) {
 double a; double b; double c;
 a = sin(ddec/2);
 b = sin(dra/2);
 c = sqrt(a*a + cosdec1*cosdec2*b*b);
 return 2*asin(c);
}

variable_types: dra double

variable_types: ddec double

variable_types: a double

variable_types: b double

variable_types: c double

return_type: double


original_code:
double MAT_AngDiamD( double z, double comovD ) {
 double a;
 a = comovD / (1+z);
 return a;
}

canonical_original_code:
double MAT_AngDiamD(double z, double comovD) {
 double a;
 a = comovD / (1+z);
 return a;
}

variable_types: z double

variable_types: comovD double


variable_types: dec double

variable_types:
result
double *

variable_types: theta double

variable_types: delta double


decompiled_code:
_BOOL8 __fastcall COM_ImpLThreshold(double *a1, double *a2, double a3)
{
double v3; // xmm1_8
_BOOL8 result; // rax

v3 = (a1[1] - a2[1]) * 0.0174532925199433;
result = 0LL;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC1) * a2[18] <= a3 )
result = a3 > MAT_GreatCircD((*a1 - *a2) * 0.0174532925199433, v3, a1[21], a2[21]) * a2[18];
return result;
}

original_code:
int COM_ImpLThreshold( catdata_t *cdn, catdata_t *cds, double threshold ) {
 double delta;
 double impact;
 double dra;
 double ddec;
 dra = 3.14159265358979323846/180.0*(cdn->ra - cds->ra);
 ddec = 3.14159265358979323846/180.0*(cdn->dec - cds->dec);
 if (fabs(ddec)*cds->angDiamD > threshold)
  return 0;
 delta = MAT_GreatCircD( dra, ddec, cdn->cosdec, cds->cosdec );
 impact = delta * cds->angDiamD;
 if ( impact < threshold )
  return 1;
 else
  return 0;
}

canonical_original_code:
int COM_ImpLThreshold(struct catdata_s *cdn, struct catdata_s *cds, double threshold) {
 double delta;
 double impact;
 double dra;
 double ddec;
 dra = 3.14159265358979323846/180.0*(cdn->ra - cds->ra);
 ddec = 3.14159265358979323846/180.0*(cdn->dec - cds->dec);
 if (fabs(ddec)*cds->angDiamD > threshold)
  return 0;
 delta = MAT_GreatCircD( dra, ddec, cdn->cosdec, cds->cosdec );
 impact = delta * cds->angDiamD;
 if ( impact < threshold )
  return 1;
 else
  return 0;
}

variable_types: struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *

variable_types:
cds
struct catdata_s *

variable_types: threshold double

variable_types: impact double


original_code:
int COM_AngLThreshold( catdata_t *a, catdata_t *b,
    double threshold, double *delta ) {
 double result;
 double dra;
 double ddec;
 dra = a->ra - b->ra;
 ddec = a->dec - b->dec;
 if (fabs(ddec) > threshold)
  return 0;
 result = 180.0/3.14159265358979323846*MAT_GreatCircD( 3.14159265358979323846/180.0*dra, 3.14159265358979323846/180.0*ddec, a->cosdec, b->cosdec );
 if ( result < threshold ) {
  *delta = result;
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
int COM_AngLThreshold(struct catdata_s *a, struct catdata_s *b, double threshold, double *delta) {
 double result;
 double dra;
 double ddec;
 dra = a->ra - b->ra;
 ddec = a->dec - b->dec;
 if (fabs(ddec) > threshold)
  return 0;
 result = 180.0/3.14159265358979323846*MAT_GreatCircD( 3.14159265358979323846/180.0*dra, 3.14159265358979323846/180.0*ddec, a->cosdec, b->cosdec );
 if ( result < threshold ) {
  *delta = result;
  return 1;
 }
 else
  return 0;
}

variable_types:
b
struct catdata_s *

variable_types:
delta
double *

variable_types: result double

user_defined_types: struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; }


original_code:
void COM_MeanRM( const char *cmdLine ) {
 double threshold;
 int i;
 catalog_t *cat;
 if ( sscanf( cmdLine, "%lf", &threshold ) != 1 ) {
  threshold = 2.0;
 }
 printf( "Computing mean RM...\n" );
 printf( "Threshold is %lf deg\n", threshold );
 cat = nvss_culled;
 for (i=0;i<cat->number;i++) {
  int k;
  catdata_t *a;
  double sum;
  int sourcesFound;
  a = cat->data + i;
  sum = 0.0;
  sourcesFound = 0;
  if ( i%2000 == 0 ) {
   printf( "%i %%\n", (int)(100.0*i/cat->number) );
  }
  for ( k=0; k<cat->number; k++ ) {
   catdata_t *b;
   int result;
   double delta;
   if ( k==i )
    continue;
   b = cat->data + k;
   result = COM_AngLThreshold( a,b,threshold,&delta );
   if ( result == 1 ) {
    sourcesFound++;
    sum += b->rot_measure;
   }
  }
  a->rot_measure_mean = sum / sourcesFound;
  a->rot_measure_delta = a->rot_measure - a->rot_measure_mean;
  a->sourcesNum = sourcesFound;
 }
 printf( "\nDone.\n" );
}

canonical_original_code:
void COM_MeanRM(char *cmdLine) {
 double threshold;
 int i;
 struct catalog_s *cat;
 if ( sscanf( cmdLine, "%lf", &threshold ) != 1 ) {
  threshold = 2.0;
 }
 printf( "Computing mean RM...\n" );
 printf( "Threshold is %lf deg\n", threshold );
 cat = nvss_culled;
 for (i=0;i<cat->number;i++) {
  int k;
  struct catdata_s *a;
  double sum;
  int sourcesFound;
  a = cat->data + i;
  sum = 0.0;
  sourcesFound = 0;
  if ( i%2000 == 0 ) {
   printf( "%i %%\n", (int)(100.0*i/cat->number) );
  }
  for ( k=0; k<cat->number; k++ ) {
   struct catdata_s *b;
   int result;
   double delta;
   if ( k==i )
    continue;
   b = cat->data + k;
   result = COM_AngLThreshold( a,b,threshold,&delta );
   if ( result == 1 ) {
    sourcesFound++;
    sum += b->rot_measure;
   }
  }
  a->rot_measure_mean = sum / sourcesFound;
  a->rot_measure_delta = a->rot_measure - a->rot_measure_mean;
  a->sourcesNum = sourcesFound;
 }
 printf( "\nDone.\n" );
}

variable_types:
cmdLine
char *

variable_types: i int

variable_types: struct catalog_s { enum cattype_s { CT_SDSS=0, CT_NVSS=1 } type; int number; double threshold; struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *data; } *

variable_types: k int

variable_types: sum double

variable_types: sourcesFound int

variable_types: result int

user_defined_types: struct catalog_s { enum cattype_s type; int number; double threshold; struct catdata_s *data; }


original_code:
void COM_SwapNN( sortNN_t *a, sortNN_t *b ) {
 sortNN_t tmp;
 memcpy( &tmp, a, sizeof(sortNN_t) );
 memcpy( a, b, sizeof(sortNN_t) );
 memcpy( b, &tmp, sizeof(sortNN_t) );
}

canonical_original_code:
void COM_SwapNN(struct sortNN_s *a, struct sortNN_s *b) {
 struct sortNN_s tmp;
 memcpy( &tmp, a, sizeof(sortNN_t) );
 memcpy( a, b, sizeof(sortNN_t) );
 memcpy( b, &tmp, sizeof(sortNN_t) );
}

variable_types: struct sortNN_s { double dist; double rot_measure; } *

variable_types:
b
struct sortNN_s *


original_code:
void COM_SortNN( sortNN_t *neighbors, int num ) {
 int k;
 k = num;
 do {
  int i, l;
  l = 1;
  for (i=0; i<k-1; ++i) {
   if (neighbors[i].dist > neighbors[i+1].dist) {
    COM_SwapNN( neighbors+i, neighbors+i+1 );
    l = i+1;
   }
  }
  k = l;
 } while ( k > 1 );
}

canonical_original_code:
void COM_SortNN(struct sortNN_s *neighbors, int num) {
 int k;
 k = num;
 do {
  int i; int l;
  l = 1;
  for (i=0; i<k-1; ++i) {
   if (neighbors[i].dist > neighbors[i+1].dist) {
    COM_SwapNN( neighbors+i, neighbors+i+1 );
    l = i+1;
   }
  }
  k = l;
 } while ( k > 1 );
}

variable_types: num int

variable_types: l int

user_defined_types: struct sortNN_s { double dist; double rot_measure; }


original_code:
void COM_MeanRM_NN( const char *cmdLine ) {
 int nn_number;
 int i;
 catalog_t *cat;
 double threshold;
 sortNN_t *neighbors;
 int sortSize;
 if ( sscanf( cmdLine, "%i", &nn_number ) != 1 ) {
  nn_number = 20;
 }
 printf( "Computing mean RM nearest neighbor...\n" );
 printf( "NN number is %i.\n", nn_number );
 sortSize = nn_number * 15;
 neighbors = malloc( sortSize * sizeof(sortNN_t) );
 cat = nvss_culled;
 threshold = 1.5*sqrt( (double)nn_number );
 for (i=0;i<cat->number;i++) {
  int k;
  catdata_t *a;
  double sum;
  int sourcesFound;
  a = cat->data + i;
  sum = 0.0;
  sourcesFound = 0;
  if ( i%2000 == 0 ) {
   printf( "%i %%\n", (int)(100.0*i/cat->number) );
  }
  for ( k=0; k<cat->number; k++ ) {
   catdata_t *b;
   int result;
   sortNN_t *nn;
   double delta;
   if ( k==i )
    continue;
   b = cat->data + k;
   result = COM_AngLThreshold( a,b,threshold,&delta );
   if ( result == 1 ) {
    if ( sourcesFound == sortSize ) {
     printf( "neighbor overrun.\n" );
     free(neighbors);
     return;
    }
    nn = neighbors + sourcesFound;
    nn->dist = delta;
    nn->rot_measure = b->rot_measure;
    sourcesFound++;
   }
  }
  if ( sourcesFound < nn_number ) {
   printf("Not enough neighbors found in annulus. (%i).\n",
     sourcesFound );
   free( neighbors );
   return;
  }
  COM_SortNN( neighbors, sourcesFound );
  for ( k=0; k<nn_number; k++ )
   sum += neighbors[k].rot_measure;
  a->rot_measure_mean_nn = sum / nn_number;
  a->rot_measure_delta_nn = a->rot_measure-a->rot_measure_mean_nn;
  if ( nn_number%2 == 1 )
   a->rot_measure_median = neighbors[nn_number/2].rot_measure;
  else
   a->rot_measure_median = (neighbors[nn_number/2].rot_measure
      +neighbors[(nn_number/2)-1].rot_measure)/2;
  a->rot_measure_median_delta = a->rot_measure-a->rot_measure_median;
  sum = 0;
  for ( k=0; k<nn_number; k++ )
   sum += (neighbors[k].rot_measure-a->rot_measure_mean_nn)
    *(neighbors[k].rot_measure-a->rot_measure_mean_nn);
  a->rot_measure_sd_nn = sqrt( sum / (nn_number-1) );
 }
 free( neighbors );
 printf( "\nDone.\n" );
}

canonical_original_code:
void COM_MeanRM_NN(char *cmdLine) {
 int nn_number;
 int i;
 struct catalog_s *cat;
 double threshold;
 struct sortNN_s *neighbors;
 int sortSize;
 if ( sscanf( cmdLine, "%i", &nn_number ) != 1 ) {
  nn_number = 20;
 }
 printf( "Computing mean RM nearest neighbor...\n" );
 printf( "NN number is %i.\n", nn_number );
 sortSize = nn_number * 15;
 neighbors = malloc( sortSize * sizeof(sortNN_t) );
 cat = nvss_culled;
 threshold = 1.5*sqrt( (double)nn_number );
 for (i=0;i<cat->number;i++) {
  int k;
  struct catdata_s *a;
  double sum;
  int sourcesFound;
  a = cat->data + i;
  sum = 0.0;
  sourcesFound = 0;
  if ( i%2000 == 0 ) {
   printf( "%i %%\n", (int)(100.0*i/cat->number) );
  }
  for ( k=0; k<cat->number; k++ ) {
   struct catdata_s *b;
   int result;
   struct sortNN_s *nn;
   double delta;
   if ( k==i )
    continue;
   b = cat->data + k;
   result = COM_AngLThreshold( a,b,threshold,&delta );
   if ( result == 1 ) {
    if ( sourcesFound == sortSize ) {
     printf( "neighbor overrun.\n" );
     free(neighbors);
     return;
    }
    nn = neighbors + sourcesFound;
    nn->dist = delta;
    nn->rot_measure = b->rot_measure;
    sourcesFound++;
   }
  }
  if ( sourcesFound < nn_number ) {
   printf("Not enough neighbors found in annulus. (%i).\n",
     sourcesFound );
   free( neighbors );
   return;
  }
  COM_SortNN( neighbors, sourcesFound );
  for ( k=0; k<nn_number; k++ )
   sum += neighbors[k].rot_measure;
  a->rot_measure_mean_nn = sum / nn_number;
  a->rot_measure_delta_nn = a->rot_measure-a->rot_measure_mean_nn;
  if ( nn_number%2 == 1 )
   a->rot_measure_median = neighbors[nn_number/2].rot_measure;
  else
   a->rot_measure_median = (neighbors[nn_number/2].rot_measure
      +neighbors[(nn_number/2)-1].rot_measure)/2;
  a->rot_measure_median_delta = a->rot_measure-a->rot_measure_median;
  sum = 0;
  for ( k=0; k<nn_number; k++ )
   sum += (neighbors[k].rot_measure-a->rot_measure_mean_nn)
    *(neighbors[k].rot_measure-a->rot_measure_mean_nn);
  a->rot_measure_sd_nn = sqrt( sum / (nn_number-1) );
 }
 free( neighbors );
 printf( "\nDone.\n" );
}

variable_types: sortSize int

variable_types: struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *

variable_types: delta double


decompiled_code:
void *__fastcall MEM_AllocCatData(int a1)
{
return calloc(a1, 0xB0uLL);
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
return calloc(a1, 0xB0uLL);
}

original_code:
catdata_t* MEM_AllocCatData( int n ) {
 catdata_t *ptr;
 ptr = calloc( n, sizeof(catdata_t) );
 return ptr;
}

canonical_original_code:
struct catdata_s *MEM_AllocCatData(int n) {
 struct catdata_s *ptr;
 ptr = calloc( n, sizeof(catdata_t) );
 return ptr;
}

variable_types: n int

return_type: struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *


decompiled_code:
void *__fastcall MEM_CopyCat(__int64 a1, __int64 a2)
{
void *result; // rax

result = memcpy(*(void **)(a2 + 16), *(const void **)(a1 + 16), 176 * *(_DWORD *)(a1 + 4));
*(__m128i *)a2 = _mm_loadu_si128((const __m128i *)a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2)
{
void *result; // rax

result = memcpy(*(void **)(a2 + 16), *(const void **)(a1 + 16), 176 * *(_DWORD *)(a1 + 4));
*(__m128i *)a2 = _mm_loadu_si128((const __m128i *)a1);
return result;
}

original_code:
void MEM_CopyCat( catalog_t *from, catalog_t *to ) {
 int size;
 catdata_t *dat;
 size = from->number * sizeof(catdata_t);
 memcpy( to->data, from->data, size );
 dat = to->data;
 memcpy( to, from, sizeof(catalog_t) );
 to->data = dat;
}

canonical_original_code:
void MEM_CopyCat(struct catalog_s *from, struct catalog_s *to) {
 int size;
 struct catdata_s *dat;
 size = from->number * sizeof(catdata_t);
 memcpy( to->data, from->data, size );
 dat = to->data;
 memcpy( to, from, sizeof(catalog_t) );
 to->data = dat;
}

variable_types:
to
struct catalog_s *

variable_types: size int


decompiled_code:
void *__fastcall MEM_CloneCatA(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 16) = MEM_AllocCatData(*(_DWORD *)(a1 + 4));
return MEM_CopyCat(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 16) = func0(*(_DWORD *)(a1 + 4));
return func1(a1, a2);
}

original_code:
void MEM_CloneCatA( catalog_t *old, catalog_t *new ) {
 new->data = MEM_AllocCatData( old->number );
 MEM_CopyCat( old, new );
}

canonical_original_code:
void MEM_CloneCatA(struct catalog_s *old, struct catalog_s *new) {
 new->data = MEM_AllocCatData( old->number );
 MEM_CopyCat( old, new );
}

variable_types:
new
struct catalog_s *


decompiled_code:
__int64 __fastcall MEM_CloneCatB(unsigned int *a1, __int64 a2)
{
__int64 result; // rax

*(_QWORD *)(a2 + 16) = MEM_AllocCatData(a1[1]);
result = *a1;
*(_DWORD *)a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, __int64 a2)
{
__int64 result; // rax

*(_QWORD *)(a2 + 16) = func0(a1[1]);
result = *a1;
*(_DWORD *)a2 = result;
return result;
}

original_code:
void MEM_CloneCatB( catalog_t *old, catalog_t *new ) {
 new->data = MEM_AllocCatData( old->number );
 new->type = old->type;
}

canonical_original_code:
void MEM_CloneCatB(struct catalog_s *old, struct catalog_s *new) {
 new->data = MEM_AllocCatData( old->number );
 new->type = old->type;
}


decompiled_code:
void *MEM_SwitchSDSSBuffer()
{
void *result; // rax

result = &sdss_culled2;
if ( (_UNKNOWN *)sdss_culled != &sdss_culled1 )
result = &sdss_culled1;
sdss_culled = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func4()
{
void *result; // rax

result = &sdss_culled2;
if ( (_UNKNOWN *)sdss_culled != &sdss_culled1 )
result = &sdss_culled1;
sdss_culled = (__int64)result;
return result;
}

original_code:
void MEM_SwitchSDSSBuffer( void ) {
 if ( sdss_culled == &sdss_culled1 )
  sdss_culled = &sdss_culled2;
 else
  sdss_culled = &sdss_culled1;
}

canonical_original_code:
void MEM_SwitchSDSSBuffer() {
 if ( sdss_culled == &sdss_culled1 )
  sdss_culled = &sdss_culled2;
 else
  sdss_culled = &sdss_culled1;
}


decompiled_code:
void *MEM_SwitchNVSSBuffer()
{
void *result; // rax

result = &nvss_culled2;
if ( (_UNKNOWN *)nvss_culled != &nvss_culled1 )
result = &nvss_culled1;
nvss_culled = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func5()
{
void *result; // rax

result = &nvss_culled2;
if ( (_UNKNOWN *)nvss_culled != &nvss_culled1 )
result = &nvss_culled1;
nvss_culled = (__int64)result;
return result;
}

original_code:
void MEM_SwitchNVSSBuffer( void ) {
 if ( nvss_culled == &nvss_culled1 )
  nvss_culled = &nvss_culled2;
 else
  nvss_culled = &nvss_culled1;
}

canonical_original_code:
void MEM_SwitchNVSSBuffer() {
 if ( nvss_culled == &nvss_culled1 )
  nvss_culled = &nvss_culled2;
 else
  nvss_culled = &nvss_culled1;
}


decompiled_code:
int __fastcall MEM_GrabCatFile(__int64 a1)
{
int result; // eax
int v3; // edi
void *v4; // rax

if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 1 )
FIO_OpenDataFile(&fp, "./data/RMCatalogue.txt", a1);
}
else
{
FIO_OpenDataFile(&fp, "./data/SDSS_galaxies.dat", a1);
}
result = printf("found %i sources.\n", *(unsigned int *)(a1 + 4));
v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
v4 = MEM_AllocCatData(v3);
*(_QWORD *)(a1 + 16) = v4;
if ( v4 )
{
printf("allocated %i cat sets for data.\n", *(unsigned int *)(a1 + 4));
FIO_ReadCatFile(fp, a1);
}
else
{
printf("allocation failed for %i cat data sets.\n", *(unsigned int *)(a1 + 4));
}
FIO_CloseFile(fp);
result = puts("--------------------------------");
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax
int v3; // edi
void *v4; // rax

if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 1 )
FIO_OpenDataFile(&fp, "./data/RMCatalogue.txt", a1);
}
else
{
FIO_OpenDataFile(&fp, "./data/SDSS_galaxies.dat", a1);
}
result = printf("found %i sources.\n", *(unsigned int *)(a1 + 4));
v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
v4 = func0(v3);
*(_QWORD *)(a1 + 16) = v4;
if ( v4 )
{
printf("allocated %i cat sets for data.\n", *(unsigned int *)(a1 + 4));
FIO_ReadCatFile(fp, a1);
}
else
{
printf("allocation failed for %i cat data sets.\n", *(unsigned int *)(a1 + 4));
}
FIO_CloseFile(fp);
result = puts("--------------------------------");
}
return result;
}

original_code:
void MEM_GrabCatFile( catalog_t *cat ) {
 switch ( cat->type ) {
  case CT_SDSS:
  FIO_OpenDataFile( &fp, "./data/SDSS_galaxies.dat", cat );
  break;
  case CT_NVSS:
  FIO_OpenDataFile( &fp, "./data/RMCatalogue.txt", cat );
  break;
 }
 printf( "found %i sources.\n", cat->number );
 if ( cat->number == 0 )
  return;
 cat->data = MEM_AllocCatData( cat->number );
 if ( cat->data ) {
  printf( "allocated %i cat sets for data.\n", cat->number );
  FIO_ReadCatFile( fp, cat );
 }
 else
  printf("allocation failed for %i cat data sets.\n",cat->number);
 FIO_CloseFile( fp );
 printf( "--------------------------------\n" );
}

canonical_original_code:
void MEM_GrabCatFile(struct catalog_s *cat) {
 switch ( cat->type ) {
  case CT_SDSS:
  FIO_OpenDataFile( &fp, "./data/SDSS_galaxies.dat", cat );
  break;
  case CT_NVSS:
  FIO_OpenDataFile( &fp, "./data/RMCatalogue.txt", cat );
  break;
 }
 printf( "found %i sources.\n", cat->number );
 if ( cat->number == 0 )
  return;
 cat->data = MEM_AllocCatData( cat->number );
 if ( cat->data ) {
  printf( "allocated %i cat sets for data.\n", cat->number );
  FIO_ReadCatFile( fp, cat );
 }
 else
  printf("allocation failed for %i cat data sets.\n",cat->number);
 FIO_CloseFile( fp );
 printf( "--------------------------------\n" );
}


original_code:
void MEM_ProcessCatData( catalog_t *cat ) {
 int i;
 for ( i=0; i< cat->number; i++ ) {
  catdata_t *cd;
  cd = cat->data + i;
  MAT_Mollweide( cd->dec, &cd->mollw_angle );
  cd->cosdec = cos(3.14159265358979323846/180.0*cd->dec);
 }
 if ( cat->type == CT_NVSS ) {
  for ( i=0; i< cat->number; i++ ) {
   catdata_t *cd;
   cd = cat->data + i;
   MAT_Mollweide( cd->latitude, &cd->mollw_angle_gal );
  }
 }
}

canonical_original_code:
void MEM_ProcessCatData(struct catalog_s *cat) {
 int i;
 for ( i=0; i< cat->number; i++ ) {
  struct catdata_s *cd;
  cd = cat->data + i;
  MAT_Mollweide( cd->dec, &cd->mollw_angle );
  cd->cosdec = cos(3.14159265358979323846/180.0*cd->dec);
 }
 if ( cat->type == CT_NVSS ) {
  for ( i=0; i< cat->number; i++ ) {
   struct catdata_s *cd;
   cd = cat->data + i;
   MAT_Mollweide( cd->latitude, &cd->mollw_angle_gal );
  }
 }
}

variable_types: i int


decompiled_code:
int MEM_LoadCulled()
{
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/SDSS_culled.dat", sdss_culled) )
return puts("loading culled SDSS failed.");
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/NVSS_culled.dat", nvss_culled) )
return puts("loading culled NVSS failed.");
printf(
"successfully loaded: %i NVSS, %i SDSS.\n",
*(unsigned int *)(nvss_culled + 4),
*(unsigned int *)(sdss_culled + 4));
return printf("NVSS threshold is %lf Kiloparsecs.\n", *(double *)(nvss_culled + 8));
}

canonical_decompiled_code:
int func8()
{
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/SDSS_culled.dat", sdss_culled) )
return puts("loading culled SDSS failed.");
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/NVSS_culled.dat", nvss_culled) )
return puts("loading culled NVSS failed.");
printf(
"successfully loaded: %i NVSS, %i SDSS.\n",
*(unsigned int *)(nvss_culled + 4),
*(unsigned int *)(sdss_culled + 4));
return printf("NVSS threshold is %lf Kiloparsecs.\n", *(double *)(nvss_culled + 8));
}

original_code:
void MEM_LoadCulled( void ) {
 int err;
 err = FIO_FileToMemory("/dev/shm/skyplot/SDSS_culled.dat",sdss_culled);
 if ( err == 0 ) {
  printf( "loading culled SDSS failed.\n" );
  return;
 }
 err = FIO_FileToMemory("/dev/shm/skyplot/NVSS_culled.dat",nvss_culled);
 if ( err == 0 ) {
  printf( "loading culled NVSS failed.\n" );
  return;
 }
 printf( "successfully loaded: %i NVSS, %i SDSS.\n",
    nvss_culled->number, sdss_culled->number );
 printf( "NVSS threshold is %lf Kiloparsecs.\n",nvss_culled->threshold );
}

canonical_original_code:
void MEM_LoadCulled() {
 int err;
 err = FIO_FileToMemory("/dev/shm/skyplot/SDSS_culled.dat",sdss_culled);
 if ( err == 0 ) {
  printf( "loading culled SDSS failed.\n" );
  return;
 }
 err = FIO_FileToMemory("/dev/shm/skyplot/NVSS_culled.dat",nvss_culled);
 if ( err == 0 ) {
  printf( "loading culled NVSS failed.\n" );
  return;
 }
 printf( "successfully loaded: %i NVSS, %i SDSS.\n",
    nvss_culled->number, sdss_culled->number );
 printf( "NVSS threshold is %lf Kiloparsecs.\n",nvss_culled->threshold );
}

variable_types: err int


decompiled_code:
int MEM_SaveCulled()
{
FIO_MemoryToFile("/dev/shm/skyplot/SDSS_culled.dat", sdss_culled);
FIO_MemoryToFile("/dev/shm/skyplot/NVSS_culled.dat", nvss_culled);
return puts("saved.");
}

canonical_decompiled_code:
int func9()
{
FIO_MemoryToFile("/dev/shm/skyplot/SDSS_culled.dat", sdss_culled);
FIO_MemoryToFile("/dev/shm/skyplot/NVSS_culled.dat", nvss_culled);
return puts("saved.");
}

original_code:
void MEM_SaveCulled( void ) {
 FIO_MemoryToFile( "/dev/shm/skyplot/SDSS_culled.dat", sdss_culled );
 FIO_MemoryToFile( "/dev/shm/skyplot/NVSS_culled.dat", nvss_culled );
 printf( "saved.\n");
}

canonical_original_code:
void MEM_SaveCulled() {
 FIO_MemoryToFile( "/dev/shm/skyplot/SDSS_culled.dat", sdss_culled );
 FIO_MemoryToFile( "/dev/shm/skyplot/NVSS_culled.dat", nvss_culled );
 printf( "saved.\n");
}


decompiled_code:
int MEM_ResetCulled()
{
MEM_CopyCat((__int64)&sdss_full, sdss_culled);
MEM_CopyCat((__int64)&nvss_full, nvss_culled);
return puts("catalogs reset.");
}

canonical_decompiled_code:
int func10()
{
func1((__int64)&sdss_full, sdss_culled);
func1((__int64)&nvss_full, nvss_culled);
return puts("catalogs reset.");
}

original_code:
void MEM_ResetCulled( void ) {
 MEM_CopyCat( &sdss_full, sdss_culled );
 MEM_CopyCat( &nvss_full, nvss_culled );
 printf( "catalogs reset.\n" );
}

canonical_original_code:
void MEM_ResetCulled() {
 MEM_CopyCat( &sdss_full, sdss_culled );
 MEM_CopyCat( &nvss_full, nvss_culled );
 printf( "catalogs reset.\n" );
}


decompiled_code:
int MEM_Init()
{
mkdir("/dev/shm/skyplot", 0x1FFu);
sdss_culled = (__int64)&sdss_culled1;
nvss_culled = (__int64)&nvss_culled1;
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/NVSS.dat", nvss_full) )
{
nvss_full[0] = 1;
MEM_GrabCatFile((__int64)nvss_full);
MEM_ProcessCatData((__int64)nvss_full);
FIO_MemoryToFile("/dev/shm/skyplot/NVSS.dat", nvss_full);
}
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/SDSS.dat", sdss_full) )
{
sdss_full[0] = 0;
MEM_GrabCatFile((__int64)sdss_full);
MEM_ProcessCatData((__int64)sdss_full);
if ( sdss_full[1] != (unsigned int)FIO_OpenDataFile(&fp, "./data/comovD.dat", 0LL) )
puts("SDSS line mismatch.");
FIO_ReadDistFile(fp, sdss_full);
FIO_CloseFile(fp);
FIO_MemoryToFile("/dev/shm/skyplot/SDSS.dat", sdss_full);
}
MEM_CloneCatA((__int64)sdss_full, (__int64)&sdss_culled1);
MEM_CloneCatA((__int64)nvss_full, (__int64)&nvss_culled1);
MEM_CloneCatB(sdss_full, (__int64)&sdss_culled2);
MEM_CloneCatB(nvss_full, (__int64)&nvss_culled2);
MEM_CloneCatB(sdss_full, (__int64)&sdss_A);
MEM_CloneCatB(sdss_full, (__int64)&sdss_B);
MEM_CloneCatB(nvss_full, (__int64)&nvss_A);
MEM_CloneCatB(nvss_full, (__int64)&nvss_B);
printf("----------------------------------------");
return puts("----------------------------------------");
}

canonical_decompiled_code:
int func11()
{
mkdir("/dev/shm/skyplot", 0x1FFu);
sdss_culled = (__int64)&sdss_culled1;
nvss_culled = (__int64)&nvss_culled1;
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/NVSS.dat", nvss_full) )
{
nvss_full[0] = 1;
func6((__int64)nvss_full);
func7((__int64)nvss_full);
FIO_MemoryToFile("/dev/shm/skyplot/NVSS.dat", nvss_full);
}
if ( !(unsigned int)FIO_FileToMemory("/dev/shm/skyplot/SDSS.dat", sdss_full) )
{
sdss_full[0] = 0;
func6((__int64)sdss_full);
func7((__int64)sdss_full);
if ( sdss_full[1] != (unsigned int)FIO_OpenDataFile(&fp, "./data/comovD.dat", 0LL) )
puts("SDSS line mismatch.");
FIO_ReadDistFile(fp, sdss_full);
FIO_CloseFile(fp);
FIO_MemoryToFile("/dev/shm/skyplot/SDSS.dat", sdss_full);
}
func2((__int64)sdss_full, (__int64)&sdss_culled1);
func2((__int64)nvss_full, (__int64)&nvss_culled1);
func3(sdss_full, (__int64)&sdss_culled2);
func3(nvss_full, (__int64)&nvss_culled2);
func3(sdss_full, (__int64)&sdss_A);
func3(sdss_full, (__int64)&sdss_B);
func3(nvss_full, (__int64)&nvss_A);
func3(nvss_full, (__int64)&nvss_B);
printf("----------------------------------------");
return puts("----------------------------------------");
}

original_code:
void MEM_Init( void ) {
 mkdir( "/dev/shm/skyplot", 0777 );
 sdss_culled = &sdss_culled1;
 nvss_culled = &nvss_culled1;
 if ( FIO_FileToMemory("/dev/shm/skyplot/NVSS.dat", &nvss_full) == 0 ) {
  nvss_full.type = CT_NVSS;
  MEM_GrabCatFile( &nvss_full );
  MEM_ProcessCatData( &nvss_full );
  FIO_MemoryToFile( "/dev/shm/skyplot/NVSS.dat", &nvss_full );
 }
 if ( FIO_FileToMemory("/dev/shm/skyplot/SDSS.dat", &sdss_full) == 0 ) {
  int lines;
  sdss_full.type = CT_SDSS;
  MEM_GrabCatFile( &sdss_full );
  MEM_ProcessCatData( &sdss_full );
  lines = FIO_OpenDataFile( &fp, "./data/comovD.dat", ((void *)0) );
  if ( lines != sdss_full.number )
   printf( "SDSS line mismatch.\n" );
  FIO_ReadDistFile( fp, &sdss_full );
  FIO_CloseFile( fp );
  FIO_MemoryToFile( "/dev/shm/skyplot/SDSS.dat", &sdss_full );
 }
 MEM_CloneCatA( &sdss_full, &sdss_culled1 );
 MEM_CloneCatA( &nvss_full, &nvss_culled1 );
 MEM_CloneCatB( &sdss_full, &sdss_culled2 );
 MEM_CloneCatB( &nvss_full, &nvss_culled2 );
 MEM_CloneCatB( &sdss_full, &sdss_A );
 MEM_CloneCatB( &sdss_full, &sdss_B );
 MEM_CloneCatB( &nvss_full, &nvss_A );
 MEM_CloneCatB( &nvss_full, &nvss_B );
 printf( "----------------------------------------" );
 printf( "----------------------------------------\n" );
}

canonical_original_code:
void MEM_Init() {
 mkdir( "/dev/shm/skyplot", 0777 );
 sdss_culled = &sdss_culled1;
 nvss_culled = &nvss_culled1;
 if ( FIO_FileToMemory("/dev/shm/skyplot/NVSS.dat", &nvss_full) == 0 ) {
  nvss_full.type = CT_NVSS;
  MEM_GrabCatFile( &nvss_full );
  MEM_ProcessCatData( &nvss_full );
  FIO_MemoryToFile( "/dev/shm/skyplot/NVSS.dat", &nvss_full );
 }
 if ( FIO_FileToMemory("/dev/shm/skyplot/SDSS.dat", &sdss_full) == 0 ) {
  int lines;
  sdss_full.type = CT_SDSS;
  MEM_GrabCatFile( &sdss_full );
  MEM_ProcessCatData( &sdss_full );
  lines = FIO_OpenDataFile( &fp, "./data/comovD.dat", ((void *)0) );
  if ( lines != sdss_full.number )
   printf( "SDSS line mismatch.\n" );
  FIO_ReadDistFile( fp, &sdss_full );
  FIO_CloseFile( fp );
  FIO_MemoryToFile( "/dev/shm/skyplot/SDSS.dat", &sdss_full );
 }
 MEM_CloneCatA( &sdss_full, &sdss_culled1 );
 MEM_CloneCatA( &nvss_full, &nvss_culled1 );
 MEM_CloneCatB( &sdss_full, &sdss_culled2 );
 MEM_CloneCatB( &nvss_full, &nvss_culled2 );
 MEM_CloneCatB( &sdss_full, &sdss_A );
 MEM_CloneCatB( &sdss_full, &sdss_B );
 MEM_CloneCatB( &nvss_full, &nvss_A );
 MEM_CloneCatB( &nvss_full, &nvss_B );
 printf( "----------------------------------------" );
 printf( "----------------------------------------\n" );
}

variable_types: lines int


decompiled_code:
void __fastcall MEM_FreeDataBuffer(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void MEM_FreeDataBuffer( catalog_t *cat ) {
 free( cat->data );
}

canonical_original_code:
void MEM_FreeDataBuffer(struct catalog_s *cat) {
 free( cat->data );
}

variable_types: struct catalog_s { enum cattype_s { CT_SDSS=0, CT_NVSS=1 } type; int number; double threshold; struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *data; } *


decompiled_code:
void MEM_FreeAllBuffers()
{
MEM_FreeDataBuffer((__int64)nvss_full);
MEM_FreeDataBuffer((__int64)sdss_full);
MEM_FreeDataBuffer((__int64)&nvss_culled1);
MEM_FreeDataBuffer((__int64)&sdss_culled1);
MEM_FreeDataBuffer((__int64)&nvss_culled2);
MEM_FreeDataBuffer((__int64)&sdss_culled2);
MEM_FreeDataBuffer((__int64)&sdss_A);
MEM_FreeDataBuffer((__int64)&sdss_B);
MEM_FreeDataBuffer((__int64)&nvss_A);
MEM_FreeDataBuffer((__int64)&nvss_B);
}

canonical_decompiled_code:
void func13()
{
func12((__int64)nvss_full);
func12((__int64)sdss_full);
func12((__int64)&nvss_culled1);
func12((__int64)&sdss_culled1);
func12((__int64)&nvss_culled2);
func12((__int64)&sdss_culled2);
func12((__int64)&sdss_A);
func12((__int64)&sdss_B);
func12((__int64)&nvss_A);
func12((__int64)&nvss_B);
}

original_code:
void MEM_FreeAllBuffers( void ) {
 MEM_FreeDataBuffer( &nvss_full );
 MEM_FreeDataBuffer( &sdss_full );
 MEM_FreeDataBuffer( &nvss_culled1 );
 MEM_FreeDataBuffer( &sdss_culled1 );
 MEM_FreeDataBuffer( &nvss_culled2 );
 MEM_FreeDataBuffer( &sdss_culled2 );
 MEM_FreeDataBuffer( &sdss_A );
 MEM_FreeDataBuffer( &sdss_B );
 MEM_FreeDataBuffer( &nvss_A );
 MEM_FreeDataBuffer( &nvss_B );
}

canonical_original_code:
void MEM_FreeAllBuffers() {
 MEM_FreeDataBuffer( &nvss_full );
 MEM_FreeDataBuffer( &sdss_full );
 MEM_FreeDataBuffer( &nvss_culled1 );
 MEM_FreeDataBuffer( &sdss_culled1 );
 MEM_FreeDataBuffer( &nvss_culled2 );
 MEM_FreeDataBuffer( &sdss_culled2 );
 MEM_FreeDataBuffer( &sdss_A );
 MEM_FreeDataBuffer( &sdss_B );
 MEM_FreeDataBuffer( &nvss_A );
 MEM_FreeDataBuffer( &nvss_B );
}


decompiled_code:
int __fastcall CUL_CullbyCrit(int a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // r14
unsigned int l; // er12
int result; // eax
__int64 v7; // r14
unsigned int k; // er12
__int64 v9; // r14
unsigned int j; // er12
__int64 v11; // r14
unsigned int i; // er12
__int64 v13; // r14
unsigned int v14; // er12
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // [rsp+8h] [rbp-40h] BYREF
double v18; // [rsp+10h] [rbp-38h] BYREF
char v19; // [rsp+1Fh] [rbp-29h] BYREF

if ( a1 == 1 )
{
v2 = nvss_culled;
MEM_SwitchNVSSBuffer();
v3 = nvss_culled;
_isoc99_sscanf(a2, "%c %lf", &v19, &v18);
}
else
{
v2 = sdss_culled;
MEM_SwitchSDSSBuffer();
v3 = sdss_culled;
_isoc99_sscanf(a2, "%c %lf %lf", &v19, &v18, &v17);
}
*(_DWORD *)(v3 + 4) = 0;
switch ( v19 )
{
case 'c':
if ( *(int *)(v2 + 4) > 0 )
{
v13 = 0LL;
v14 = 0;
do
{
if ( v18 >= COERCE_DOUBLE(*(_QWORD *)(*(_QWORD *)(v2 + 16) + v13 + 72) & LC2) )
MEM_AppendCat(v2, v3, v14);
++v14;
v13 += 176LL;
}
while ( *(_DWORD *)(v2 + 4) > (signed int)v14 );
}
goto LABEL_6;
case 'd':
v11 = 0LL;
for ( i = 0; *(_DWORD *)(v2 + 4) > (signed int)i; v11 += 176LL )
{
v15 = *(double *)(*(_QWORD *)(v2 + 16) + v11 + 8);
if ( v15 >= v18 && v17 >= v15 )
MEM_AppendCat(v2, v3, i);
++i;
}
goto LABEL_6;
case 'l':
v9 = 0LL;
for ( j = 0; *(_DWORD *)(v2 + 4) > (signed int)j; v9 += 176LL )
{
if ( COERCE_DOUBLE(*(_QWORD *)(*(_QWORD *)(v2 + 16) + v9 + 56) & LC2) >= v18 )
MEM_AppendCat(v2, v3, j);
++j;
}
goto LABEL_6;
case 'n':
v7 = 0LL;
for ( k = 0; *(_DWORD *)(v2 + 4) > (signed int)k; v7 += 176LL )
{
if ( v18 >= COERCE_DOUBLE(*(_QWORD *)(*(_QWORD *)(v2 + 16) + v7 + 96) & LC2) )
MEM_AppendCat(v2, v3, k);
++k;
}
goto LABEL_6;
case 'z':
v4 = 0LL;
for ( l = 0; *(_DWORD *)(v2 + 4) > (signed int)l; v4 += 176LL )
{
v16 = *(double *)(*(_QWORD *)(v2 + 16) + v4 + 16);
if ( v16 >= v18 && v17 >= v16 )
MEM_AppendCat(v2, v3, l);
++l;
}
LABEL_6:
if ( a1 )
result = printf(
"Culled NVSS by %c from/to %lf (%i sources)\n",
(unsigned int)v19,
v18,
*(unsigned int *)(v3 + 4));
else
result = printf(
"Culled SDSS by %c from %lf to %lf (%i sources)\n",
(unsigned int)v19,
v18,
v17,
*(unsigned int *)(v3 + 4));
break;
default:
printf("Did not recognize cull command '%c'\n", (unsigned int)v19);
result = MEM_SwitchSDSSBuffer();
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // r14
unsigned int l; // er12
int result; // eax
__int64 v7; // r14
unsigned int k; // er12
__int64 v9; // r14
unsigned int j; // er12
__int64 v11; // r14
unsigned int i; // er12
__int64 v13; // r14
unsigned int v14; // er12
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // [rsp+8h] [rbp-40h] BYREF
double v18; // [rsp+10h] [rbp-38h] BYREF
char v19; // [rsp+1Fh] [rbp-29h] BYREF

if ( a1 == 1 )
{
v2 = nvss_culled;
MEM_SwitchNVSSBuffer();
v3 = nvss_culled;
_isoc99_sscanf(a2, "%c %lf", &v19, &v18);
}
else
{
v2 = sdss_culled;
MEM_SwitchSDSSBuffer();
v3 = sdss_culled;
_isoc99_sscanf(a2, "%c %lf %lf", &v19, &v18, &v17);
}
*(_DWORD *)(v3 + 4) = 0;
switch ( v19 )
{
case 'c':
if ( *(int *)(v2 + 4) > 0 )
{
v13 = 0LL;
v14 = 0;
do
{
if ( v18 >= COERCE_DOUBLE(*(_QWORD *)(*(_QWORD *)(v2 + 16) + v13 + 72) & LC2) )
MEM_AppendCat(v2, v3, v14);
++v14;
v13 += 176LL;
}
while ( *(_DWORD *)(v2 + 4) > (signed int)v14 );
}
goto LABEL_6;
case 'd':
v11 = 0LL;
for ( i = 0; *(_DWORD *)(v2 + 4) > (signed int)i; v11 += 176LL )
{
v15 = *(double *)(*(_QWORD *)(v2 + 16) + v11 + 8);
if ( v15 >= v18 && v17 >= v15 )
MEM_AppendCat(v2, v3, i);
++i;
}
goto LABEL_6;
case 'l':
v9 = 0LL;
for ( j = 0; *(_DWORD *)(v2 + 4) > (signed int)j; v9 += 176LL )
{
if ( COERCE_DOUBLE(*(_QWORD *)(*(_QWORD *)(v2 + 16) + v9 + 56) & LC2) >= v18 )
MEM_AppendCat(v2, v3, j);
++j;
}
goto LABEL_6;
case 'n':
v7 = 0LL;
for ( k = 0; *(_DWORD *)(v2 + 4) > (signed int)k; v7 += 176LL )
{
if ( v18 >= COERCE_DOUBLE(*(_QWORD *)(*(_QWORD *)(v2 + 16) + v7 + 96) & LC2) )
MEM_AppendCat(v2, v3, k);
++k;
}
goto LABEL_6;
case 'z':
v4 = 0LL;
for ( l = 0; *(_DWORD *)(v2 + 4) > (signed int)l; v4 += 176LL )
{
v16 = *(double *)(*(_QWORD *)(v2 + 16) + v4 + 16);
if ( v16 >= v18 && v17 >= v16 )
MEM_AppendCat(v2, v3, l);
++l;
}
LABEL_6:
if ( a1 )
result = printf(
"Culled NVSS by %c from/to %lf (%i sources)\n",
(unsigned int)v19,
v18,
*(unsigned int *)(v3 + 4));
else
result = printf(
"Culled SDSS by %c from %lf to %lf (%i sources)\n",
(unsigned int)v19,
v18,
v17,
*(unsigned int *)(v3 + 4));
break;
default:
printf("Did not recognize cull command '%c'\n", (unsigned int)v19);
result = MEM_SwitchSDSSBuffer();
break;
}
return result;
}

original_code:
void CUL_CullbyCrit( cattype_t cType, const char *buf ) {
 int i;
 char type;
 double a, b;
 catalog_t *old;
 catalog_t *new;
 switch ( cType ) {
  default:
  case CT_SDSS:
  old = sdss_culled;
  MEM_SwitchSDSSBuffer();
  new = sdss_culled;
  sscanf( buf, "%c %lf %lf", &type, &a, &b );
  break;
  case CT_NVSS:
  old = nvss_culled;
  MEM_SwitchNVSSBuffer();
  new = nvss_culled;
  sscanf( buf, "%c %lf", &type, &a );
  break;
 }
 new->number = 0;
 switch (type) {
  case 'c':
  for ( i=0; i<old->number; i++ ) {
   if ( fabs((old->data+i)->rot_measure_mean) <= a ) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'n':
  for ( i=0; i<old->number; i++ ) {
   if ( fabs((old->data+i)->rot_measure_mean_nn) <= a ) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'l':
  for ( i=0; i<old->number; i++ ) {
   if ( fabs((old->data+i)->latitude) >= a ) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'd':
  for ( i=0; i<old->number; i++ ) {
   if ( (old->data+i)->dec >= a && (old->data+i)->dec <= b) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'z':
  for ( i=0; i<old->number; i++ ) {
   if ( (old->data+i)->z >= a && (old->data+i)->z <= b) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  default:
  printf( "Did not recognize cull command '%c'\n", type );
  MEM_SwitchSDSSBuffer();
  return;
 }
 if (cType==CT_SDSS)
  printf( "Culled SDSS by %c from %lf to %lf (%i sources)\n",
      type, a, b, new->number );
 else
  printf( "Culled NVSS by %c from/to %lf (%i sources)\n",
      type, a, new->number );
}

canonical_original_code:
void CUL_CullbyCrit(enum cattype_s cType, char *buf) {
 int i;
 char type;
 double a; double b;
 struct catalog_s *old;
 struct catalog_s *new;
 switch ( cType ) {
  default:
  case CT_SDSS:
  old = sdss_culled;
  MEM_SwitchSDSSBuffer();
  new = sdss_culled;
  sscanf( buf, "%c %lf %lf", &type, &a, &b );
  break;
  case CT_NVSS:
  old = nvss_culled;
  MEM_SwitchNVSSBuffer();
  new = nvss_culled;
  sscanf( buf, "%c %lf", &type, &a );
  break;
 }
 new->number = 0;
 switch (type) {
  case 'c':
  for ( i=0; i<old->number; i++ ) {
   if ( fabs((old->data+i)->rot_measure_mean) <= a ) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'n':
  for ( i=0; i<old->number; i++ ) {
   if ( fabs((old->data+i)->rot_measure_mean_nn) <= a ) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'l':
  for ( i=0; i<old->number; i++ ) {
   if ( fabs((old->data+i)->latitude) >= a ) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'd':
  for ( i=0; i<old->number; i++ ) {
   if ( (old->data+i)->dec >= a && (old->data+i)->dec <= b) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  case 'z':
  for ( i=0; i<old->number; i++ ) {
   if ( (old->data+i)->z >= a && (old->data+i)->z <= b) {
    MEM_AppendCat( old, new, i );
   }
  }
  break;
  default:
  printf( "Did not recognize cull command '%c'\n", type );
  MEM_SwitchSDSSBuffer();
  return;
 }
 if (cType==CT_SDSS)
  printf( "Culled SDSS by %c from %lf to %lf (%i sources)\n",
      type, a, b, new->number );
 else
  printf( "Culled NVSS by %c from/to %lf (%i sources)\n",
      type, a, new->number );
}

variable_types:
cType
enum cattype_s { CT_SDSS=0, CT_NVSS=1 }

variable_types:
buf
char *

variable_types: type char

variable_types: a double

variable_types: b double


decompiled_code:
int CUL_ThreadFinished()
{
int result; // eax

pthread_mutex_lock(&cull_mutex);
++culThreadsFin;
pthread_mutex_unlock(&cull_mutex);
result = culThreadsFin;
if ( numCulThreads < culThreadsFin )
{
if ( !scripted )
{
free(cpThreads);
free(cThreadData);
}
printf("Got %i sources after culling.\n", *(unsigned int *)(nvss_culled + 4LL));
printf("----------------------------------------");
result = puts("----------------------------------------");
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

pthread_mutex_lock(&cull_mutex);
++culThreadsFin;
pthread_mutex_unlock(&cull_mutex);
result = culThreadsFin;
if ( numCulThreads < culThreadsFin )
{
if ( !scripted )
{
free(cpThreads);
free(cThreadData);
}
printf("Got %i sources after culling.\n", *(unsigned int *)(nvss_culled + 4LL));
printf("----------------------------------------");
result = puts("----------------------------------------");
}
return result;
}

original_code:
void CUL_ThreadFinished( void ) {
 pthread_mutex_lock( &cull_mutex );
 culThreadsFin++;
 pthread_mutex_unlock( &cull_mutex );
 if ( culThreadsFin < numCulThreads + 1 )
  return;
 if ( scripted == 0 ) {
  free( cpThreads );
  free( cThreadData );
 }
 printf( "Got %i sources after culling.\n", nvss_culled->number );
 printf( "----------------------------------------" );
 printf( "----------------------------------------\n" );
}

canonical_original_code:
void CUL_ThreadFinished() {
 pthread_mutex_lock( &cull_mutex );
 culThreadsFin++;
 pthread_mutex_unlock( &cull_mutex );
 if ( culThreadsFin < numCulThreads + 1 )
  return;
 if ( scripted == 0 ) {
  free( cpThreads );
  free( cThreadData );
 }
 printf( "Got %i sources after culling.\n", nvss_culled->number );
 printf( "----------------------------------------" );
 printf( "----------------------------------------\n" );
}


decompiled_code:
void *__fastcall CUL_CullThread(void *a1)
{
__int64 v1; // r12
__int64 v2; // r14
int v3; // eax
int v4; // er15
int v5; // edx
int v6; // ebx
double v7; // xmm0_8
__int64 v8; // r13
__int64 v9; // rbx
int v10; // ebp
double v12; // [rsp+0h] [rbp-68h]
__int64 v13; // [rsp+8h] [rbp-60h]
int v14; // [rsp+10h] [rbp-58h]
int v15; // [rsp+14h] [rbp-54h]
time_t time0; // [rsp+18h] [rbp-50h]
time_t timer; // [rsp+20h] [rbp-48h] BYREF
int oldtype[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

pthread_setcanceltype(1, oldtype);
v1 = sdss_culled;
v2 = *(_QWORD *)a1;
v13 = *((_QWORD *)a1 + 1);
v3 = *((_DWORD *)a1 + 6);
v15 = v3;
v4 = *((_DWORD *)a1 + 7);
v12 = *((double *)a1 + 4);
time0 = *((_QWORD *)a1 + 5);
oldtype[0] = v3;
if ( v3 < v4 )
{
v5 = v3;
v14 = 0;
do
{
if ( v5 == 500 * (v5 / 500) )
{
pthread_mutex_lock(&cull_mutex);
v6 = oldtype[0] - v15;
cull_completed += oldtype[0] - v15 - v14;
pthread_mutex_unlock(&cull_mutex);
time(&timer);
v7 = difftime(timer, time0);
printf(
"%i%% time: %.1lf / %.1lf minutes\n",
(unsigned int)(100 * cull_completed / *(_DWORD *)(v2 + 4)),
v7 / 60.0,
(double)*(int *)(v2 + 4) * v7 / (double)cull_completed / 60.0);
v14 = v6;
}
v8 = *(_QWORD *)(v2 + 16) + 176LL * oldtype[0];
if ( *(int *)(v1 + 4) > 0 )
{
v9 = 0LL;
v10 = 0;
while ( (unsigned int)COM_ImpLThreshold(v8, *(_QWORD *)(v1 + 16) + v9, v12) != 1 )
{
++v10;
v9 += 176LL;
if ( *(_DWORD *)(v1 + 4) <= v10 )
goto LABEL_4;
}
pthread_mutex_lock(&cull_mutex);
MEM_AppendCat(v2, v13, (unsigned int)oldtype[0]);
pthread_mutex_unlock(&cull_mutex);
}
LABEL_4:
v5 = oldtype[0] + 1;
oldtype[0] = v5;
}
while ( v5 < v4 );
}
CUL_ThreadFinished();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
__int64 v1; // r12
__int64 v2; // r14
int v3; // eax
int v4; // er15
int v5; // edx
int v6; // ebx
double v7; // xmm0_8
__int64 v8; // r13
__int64 v9; // rbx
int v10; // ebp
double v12; // [rsp+0h] [rbp-68h]
__int64 v13; // [rsp+8h] [rbp-60h]
int v14; // [rsp+10h] [rbp-58h]
int v15; // [rsp+14h] [rbp-54h]
time_t time0; // [rsp+18h] [rbp-50h]
time_t timer; // [rsp+20h] [rbp-48h] BYREF
int oldtype[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

pthread_setcanceltype(1, oldtype);
v1 = sdss_culled;
v2 = *(_QWORD *)a1;
v13 = *((_QWORD *)a1 + 1);
v3 = *((_DWORD *)a1 + 6);
v15 = v3;
v4 = *((_DWORD *)a1 + 7);
v12 = *((double *)a1 + 4);
time0 = *((_QWORD *)a1 + 5);
oldtype[0] = v3;
if ( v3 < v4 )
{
v5 = v3;
v14 = 0;
do
{
if ( v5 == 500 * (v5 / 500) )
{
pthread_mutex_lock(&cull_mutex);
v6 = oldtype[0] - v15;
cull_completed += oldtype[0] - v15 - v14;
pthread_mutex_unlock(&cull_mutex);
time(&timer);
v7 = difftime(timer, time0);
printf(
"%i%% time: %.1lf / %.1lf minutes\n",
(unsigned int)(100 * cull_completed / *(_DWORD *)(v2 + 4)),
v7 / 60.0,
(double)*(int *)(v2 + 4) * v7 / (double)cull_completed / 60.0);
v14 = v6;
}
v8 = *(_QWORD *)(v2 + 16) + 176LL * oldtype[0];
if ( *(int *)(v1 + 4) > 0 )
{
v9 = 0LL;
v10 = 0;
while ( (unsigned int)COM_ImpLThreshold(v8, *(_QWORD *)(v1 + 16) + v9, v12) != 1 )
{
++v10;
v9 += 176LL;
if ( *(_DWORD *)(v1 + 4) <= v10 )
goto LABEL_4;
}
pthread_mutex_lock(&cull_mutex);
MEM_AppendCat(v2, v13, (unsigned int)oldtype[0]);
pthread_mutex_unlock(&cull_mutex);
}
LABEL_4:
v5 = oldtype[0] + 1;
oldtype[0] = v5;
}
while ( v5 < v4 );
}
func1();
return 0LL;
}

original_code:
void* CUL_CullThread( void *arg ) {
 threadData_t *threadData;
 int i, k, j;
 catalog_t *from, *to;
 catalog_t *sdss;
 time_t toc;
 int start;
 int end;
 double threshold;
 time_t tic;
 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, &i );
 threadData = arg;
 sdss = sdss_culled;
 from = threadData->from;
 to = threadData->toA;
 start = threadData->start;
 end = threadData->end;
 threshold = threadData->threshold;
 tic = threadData->tic;
 j = 0;
 for ( i=start; i<end; i++ ){
  catdata_t *cdn;
  if ( i%500 == 0 ) {
   double difft;
   pthread_mutex_lock( &cull_mutex );
   cull_completed += i - start;
   cull_completed -= j;
   j = i - start;
   pthread_mutex_unlock( &cull_mutex );
   time( &toc );
   difft = difftime(toc,tic);
   printf( "%i%% time: %.1lf / %.1lf minutes\n",
     100 * cull_completed / from->number,
     difft/60,
     difft*from->number/cull_completed/60 );
  }
  cdn = from->data + i;
  for ( k=0; k<sdss->number; k++ ) {
   catdata_t *cds;
   int result;
   cds = sdss->data + k;
   result = COM_ImpLThreshold( cdn,cds,threshold );
   if ( result == 1 ) {
    pthread_mutex_lock( &cull_mutex );
    MEM_AppendCat( from, to, i );
    pthread_mutex_unlock( &cull_mutex );
    break;
   }
  }
 }
 CUL_ThreadFinished();
 return ((void *)0);
}

canonical_original_code:
void *CUL_CullThread(void *arg) {
 struct cullthread_s *threadData;
 int i; int k; int j;
 struct catalog_s *from; struct catalog_s *to;
 struct catalog_s *sdss;
 long toc;
 int start;
 int end;
 double threshold;
 long tic;
 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, &i );
 threadData = arg;
 sdss = sdss_culled;
 from = threadData->from;
 to = threadData->toA;
 start = threadData->start;
 end = threadData->end;
 threshold = threadData->threshold;
 tic = threadData->tic;
 j = 0;
 for ( i=start; i<end; i++ ){
  struct catdata_s *cdn;
  if ( i%500 == 0 ) {
   double difft;
   pthread_mutex_lock( &cull_mutex );
   cull_completed += i - start;
   cull_completed -= j;
   j = i - start;
   pthread_mutex_unlock( &cull_mutex );
   time( &toc );
   difft = difftime(toc,tic);
   printf( "%i%% time: %.1lf / %.1lf minutes\n",
     100 * cull_completed / from->number,
     difft/60,
     difft*from->number/cull_completed/60 );
  }
  cdn = from->data + i;
  for ( k=0; k<sdss->number; k++ ) {
   struct catdata_s *cds;
   int result;
   cds = sdss->data + k;
   result = COM_ImpLThreshold( cdn,cds,threshold );
   if ( result == 1 ) {
    pthread_mutex_lock( &cull_mutex );
    MEM_AppendCat( from, to, i );
    pthread_mutex_unlock( &cull_mutex );
    break;
   }
  }
 }
 CUL_ThreadFinished();
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct cullthread_s { struct catalog_s { enum cattype_s { CT_SDSS=0, CT_NVSS=1 } type; int number; double threshold; struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *data; } *from; struct catalog_s *toA; struct catalog_s *toB; int start; int end; double threshold; long tic; } *

variable_types: k int

variable_types: j int

variable_types: toc long

variable_types: start int

variable_types: end int

variable_types: threshold double

variable_types: tic long

variable_types: difft double

variable_types: result int

return_type: void *

user_defined_types: struct cullthread_s { struct catalog_s *from; struct catalog_s *toA; struct catalog_s *toB; int start; int end; double threshold; long tic; }


decompiled_code:
int __fastcall CUL_CullNVSS(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // er12
__int64 v4; // r13
__int64 v5; // rdi
int v6; // ecx
char *v7; // rsi
char *v8; // rcx
int v9; // edx
char *v10; // rax
__int64 v11; // rbp
__int64 v12; // rbx
double v14; // [rsp+8h] [rbp-30h] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "%lf %i", &v14, &numCulThreads) != 2 )
{
v14 = *(double *)&LC11;
numCulThreads = 2;
}
printf("Culling NVSS data (%i threads)...\n", (unsigned int)numCulThreads);
printf("Threshold is %lf Kiloparsecs\n", v14);
v1 = nvss_culled;
MEM_SwitchNVSSBuffer();
v2 = nvss_culled;
*(double *)(nvss_culled + 8LL) = v14;
*(_DWORD *)(v2 + 4) = 0;
cull_completed = 0;
culThreadsFin = 0;
v3 = numCulThreads;
v4 = numCulThreads + 1;
cpThreads = malloc(8 * v4);
cThreadData = malloc(48 * v4);
if ( v3 > 0 )
{
v5 = 0LL;
v6 = 0;
do
{
v7 = (char *)cThreadData + v5;
*((_DWORD *)v7 + 6) = v6 * (*(_DWORD *)(v1 + 4) / v3);
*((_DWORD *)v7 + 7) = ++v6 * (*(_DWORD *)(v1 + 4) / v3);
*((double *)v7 + 4) = v14;
*(_QWORD *)v7 = v1;
*(_QWORD *)((char *)cThreadData + v5 + 8) = v2;
v3 = numCulThreads;
v5 += 48LL;
}
while ( v6 < numCulThreads );
}
v8 = (char *)cThreadData + 48 * v3;
*((_DWORD *)v8 + 6) = *(_DWORD *)(v1 + 4) - *(_DWORD *)(v1 + 4) % v3;
*((_DWORD *)v8 + 7) = *(_DWORD *)(v1 + 4);
*((double *)v8 + 4) = v14;
*(_QWORD *)v8 = v1;
v9 = numCulThreads;
v10 = (char *)cThreadData + 48 * numCulThreads;
*((_QWORD *)v10 + 1) = v2;
if ( v9 >= 0 )
{
v11 = 0LL;
v12 = 0LL;
do
{
time((time_t *)((char *)cThreadData + v11 + 40));
LODWORD(v10) = pthread_create((pthread_t *)cpThreads + v12, 0LL, CUL_CullThread, (char *)cThreadData + v11);
if ( (_DWORD)v10 )
LODWORD(v10) = printf("Error creating thread %i of %i.\n", (unsigned int)v12, (unsigned int)numCulThreads);
++v12;
v11 += 48LL;
}
while ( numCulThreads >= (int)v12 );
}
return (int)v10;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // er12
__int64 v4; // r13
__int64 v5; // rdi
int v6; // ecx
char *v7; // rsi
char *v8; // rcx
int v9; // edx
char *v10; // rax
__int64 v11; // rbp
__int64 v12; // rbx
double v14; // [rsp+8h] [rbp-30h] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "%lf %i", &v14, &numCulThreads) != 2 )
{
v14 = *(double *)&LC11;
numCulThreads = 2;
}
printf("Culling NVSS data (%i threads)...\n", (unsigned int)numCulThreads);
printf("Threshold is %lf Kiloparsecs\n", v14);
v1 = nvss_culled;
MEM_SwitchNVSSBuffer();
v2 = nvss_culled;
*(double *)(nvss_culled + 8LL) = v14;
*(_DWORD *)(v2 + 4) = 0;
cull_completed = 0;
culThreadsFin = 0;
v3 = numCulThreads;
v4 = numCulThreads + 1;
cpThreads = malloc(8 * v4);
cThreadData = malloc(48 * v4);
if ( v3 > 0 )
{
v5 = 0LL;
v6 = 0;
do
{
v7 = (char *)cThreadData + v5;
*((_DWORD *)v7 + 6) = v6 * (*(_DWORD *)(v1 + 4) / v3);
*((_DWORD *)v7 + 7) = ++v6 * (*(_DWORD *)(v1 + 4) / v3);
*((double *)v7 + 4) = v14;
*(_QWORD *)v7 = v1;
*(_QWORD *)((char *)cThreadData + v5 + 8) = v2;
v3 = numCulThreads;
v5 += 48LL;
}
while ( v6 < numCulThreads );
}
v8 = (char *)cThreadData + 48 * v3;
*((_DWORD *)v8 + 6) = *(_DWORD *)(v1 + 4) - *(_DWORD *)(v1 + 4) % v3;
*((_DWORD *)v8 + 7) = *(_DWORD *)(v1 + 4);
*((double *)v8 + 4) = v14;
*(_QWORD *)v8 = v1;
v9 = numCulThreads;
v10 = (char *)cThreadData + 48 * numCulThreads;
*((_QWORD *)v10 + 1) = v2;
if ( v9 >= 0 )
{
v11 = 0LL;
v12 = 0LL;
do
{
time((time_t *)((char *)cThreadData + v11 + 40));
LODWORD(v10) = pthread_create((pthread_t *)cpThreads + v12, 0LL, CUL_CullThread, (char *)cThreadData + v11);
if ( (_DWORD)v10 )
LODWORD(v10) = printf("Error creating thread %i of %i.\n", (unsigned int)v12, (unsigned int)numCulThreads);
++v12;
v11 += 48LL;
}
while ( numCulThreads >= (int)v12 );
}
return (int)v10;
}

original_code:
void CUL_CullNVSS( const char *cmdLine ) {
 double threshold;
 int i;
 catalog_t *from;
 catalog_t *to;
 if ( sscanf( cmdLine, "%lf %i", &threshold, &numCulThreads ) != 2 ) {
  threshold = 1000.0;
  numCulThreads = 2;
 }
 printf( "Culling NVSS data (%i threads)...\n", numCulThreads );
 printf( "Threshold is %lf Kiloparsecs\n", threshold );
 from = nvss_culled;
 MEM_SwitchNVSSBuffer();
 to = nvss_culled;
 to->threshold = threshold;
 to->number = 0;
 cull_completed = 0;
 culThreadsFin = 0;
 cpThreads = malloc( (numCulThreads+1) * sizeof(pthread_t) );
 cThreadData = malloc( (numCulThreads+1) * sizeof(threadData_t) );
 for ( i=0; i<numCulThreads; i++ ){
  (cThreadData+i)->start = i*(from->number/numCulThreads);
  (cThreadData+i)->end = (i+1)*(from->number/numCulThreads);
  (cThreadData+i)->threshold = threshold;
  (cThreadData+i)->from = from;
  (cThreadData+i)->toA = to;
 }
 (cThreadData+numCulThreads)->start = from->number-(from->number%numCulThreads);
 (cThreadData+numCulThreads)->end = from->number;
 (cThreadData+numCulThreads)->threshold = threshold;
 (cThreadData+numCulThreads)->from = from;
 (cThreadData+numCulThreads)->toA = to;
 for ( i=0; i<=numCulThreads; i++ ){
  int err;
  time(&(cThreadData+i)->tic);
  err = pthread_create(cpThreads+i,((void *)0),
     CUL_CullThread,cThreadData+i);
  if ( err != 0 )
   printf( "Error creating thread %i of %i.\n",
     i, numCulThreads );
 }
}

canonical_original_code:
void CUL_CullNVSS(char *cmdLine) {
 double threshold;
 int i;
 struct catalog_s *from;
 struct catalog_s *to;
 if ( sscanf( cmdLine, "%lf %i", &threshold, &numCulThreads ) != 2 ) {
  threshold = 1000.0;
  numCulThreads = 2;
 }
 printf( "Culling NVSS data (%i threads)...\n", numCulThreads );
 printf( "Threshold is %lf Kiloparsecs\n", threshold );
 from = nvss_culled;
 MEM_SwitchNVSSBuffer();
 to = nvss_culled;
 to->threshold = threshold;
 to->number = 0;
 cull_completed = 0;
 culThreadsFin = 0;
 cpThreads = malloc( (numCulThreads+1) * sizeof(pthread_t) );
 cThreadData = malloc( (numCulThreads+1) * sizeof(threadData_t) );
 for ( i=0; i<numCulThreads; i++ ){
  (cThreadData+i)->start = i*(from->number/numCulThreads);
  (cThreadData+i)->end = (i+1)*(from->number/numCulThreads);
  (cThreadData+i)->threshold = threshold;
  (cThreadData+i)->from = from;
  (cThreadData+i)->toA = to;
 }
 (cThreadData+numCulThreads)->start = from->number-(from->number%numCulThreads);
 (cThreadData+numCulThreads)->end = from->number;
 (cThreadData+numCulThreads)->threshold = threshold;
 (cThreadData+numCulThreads)->from = from;
 (cThreadData+numCulThreads)->toA = to;
 for ( i=0; i<=numCulThreads; i++ ){
  int err;
  time(&(cThreadData+i)->tic);
  err = pthread_create(cpThreads+i,((void *)0),
     CUL_CullThread,cThreadData+i);
  if ( err != 0 )
   printf( "Error creating thread %i of %i.\n",
     i, numCulThreads );
 }
}

variable_types:
cmdLine
char *

variable_types: i int

variable_types: struct catalog_s { enum cattype_s { CT_SDSS=0, CT_NVSS=1 } type; int number; double threshold; struct catdata_s { double ra; double dec; double z; double abs_petro_r_mag; double u_b_color; double stellar_mass; double longitude; double latitude; double rot_measure; double rot_measure_mean; double rot_measure_delta; int sourcesNum; double rot_measure_mean_nn; double rot_measure_delta_nn; double rot_measure_sd_nn; double rot_measure_median; double rot_measure_median_delta; double comovD; double angDiamD; double mollw_angle; double mollw_angle_gal; double cosdec; } *data; } *

variable_types: err int


decompiled_code:
int CUL_CancelNVSS()
{
int v0; // eax
__int64 v1; // rbx

if ( numCulThreads + 1 == culThreadsFin )
return puts("Threads already finished.");
puts("Stopping threads...");
v0 = numCulThreads;
if ( numCulThreads > 0 )
{
v1 = 0LL;
do
{
if ( pthread_cancel(*((_QWORD *)cpThreads + v1)) )
printf("Error stopping thread %i of %i.\n", (unsigned int)(v1 + 1), (unsigned int)numCulThreads);
v0 = numCulThreads;
++v1;
}
while ( numCulThreads > (int)v1 );
}
pthread_join(*((_QWORD *)cpThreads + v0), 0LL);
return puts("done.");
}

canonical_decompiled_code:
int func4()
{
int v0; // eax
__int64 v1; // rbx

if ( numCulThreads + 1 == culThreadsFin )
return puts("Threads already finished.");
puts("Stopping threads...");
v0 = numCulThreads;
if ( numCulThreads > 0 )
{
v1 = 0LL;
do
{
if ( pthread_cancel(*((_QWORD *)cpThreads + v1)) )
printf("Error stopping thread %i of %i.\n", (unsigned int)(v1 + 1), (unsigned int)numCulThreads);
v0 = numCulThreads;
++v1;
}
while ( numCulThreads > (int)v1 );
}
pthread_join(*((_QWORD *)cpThreads + v0), 0LL);
return puts("done.");
}

original_code:
void CUL_CancelNVSS( void ) {
 int i;
 if ( culThreadsFin == numCulThreads + 1 ) {
  printf( "Threads already finished.\n" );
  return;
 }
 printf( "Stopping threads...\n" );
 for ( i=0; i<numCulThreads; i++ ){
  int err;
  err = pthread_cancel( *(cpThreads+i) );
  if ( err != 0 )
   printf( "Error stopping thread %i of %i.\n",
     i+1, numCulThreads );
 }
 pthread_join( *(cpThreads+numCulThreads), ((void *)0) );
 printf( "done.\n" );
}

canonical_original_code:
void CUL_CancelNVSS() {
 int i;
 if ( culThreadsFin == numCulThreads + 1 ) {
  printf( "Threads already finished.\n" );
  return;
 }
 printf( "Stopping threads...\n" );
 for ( i=0; i<numCulThreads; i++ ){
  int err;
  err = pthread_cancel( *(cpThreads+i) );
  if ( err != 0 )
   printf( "Error stopping thread %i of %i.\n",
     i+1, numCulThreads );
 }
 pthread_join( *(cpThreads+numCulThreads), ((void *)0) );
 printf( "done.\n" );
}


decompiled_code:
void CUL_WaitForThreads()
{
__int64 v0; // rbx

if ( numCulThreads >= 0 )
{
v0 = 0LL;
do
{
if ( pthread_join(*((_QWORD *)cpThreads + v0), 0LL) )
printf("Error joining thread %i of %i.\n", (unsigned int)v0, (unsigned int)numCulThreads);
++v0;
}
while ( numCulThreads >= (int)v0 );
}
}

canonical_decompiled_code:
void func5()
{
__int64 v0; // rbx

if ( numCulThreads >= 0 )
{
v0 = 0LL;
do
{
if ( pthread_join(*((_QWORD *)cpThreads + v0), 0LL) )
printf("Error joining thread %i of %i.\n", (unsigned int)v0, (unsigned int)numCulThreads);
++v0;
}
while ( numCulThreads >= (int)v0 );
}
}

original_code:
void CUL_WaitForThreads( void ) {
 int i;
 for ( i=0; i<numCulThreads+1; i++ ){
  if ( pthread_join( *(cpThreads+i), ((void *)0) ) != 0 )
   printf( "Error joining thread %i of %i.\n",
       i, numCulThreads );
 }
}

canonical_original_code:
void CUL_WaitForThreads() {
 int i;
 for ( i=0; i<numCulThreads+1; i++ ){
  if ( pthread_join( *(cpThreads+i), ((void *)0) ) != 0 )
   printf( "Error joining thread %i of %i.\n",
       i, numCulThreads );
 }
}


decompiled_code:
__int64 __fastcall CUL_CullCancel(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( *a1 == 115 )
{
CUL_CullbyCrit(0, (__int64)(a1 + 1));
v2 = 0;
}
else if ( v1 == 110 )
{
if ( a1[1] == 32 )
{
CUL_CullNVSS((__int64)(a1 + 1));
v2 = 1;
if ( scripted )
{
CUL_WaitForThreads();
free(cpThreads);
free(cThreadData);
v2 = 0;
}
}
else
{
CUL_CullbyCrit(1, (__int64)(a1 + 1));
v2 = 0;
}
}
else
{
v2 = 0;
if ( v1 == 99 )
{
CUL_CancelNVSS();
v2 = 0;
}
}
return v2;
}

original_code:
int CUL_CullCancel( const char *cmdLine ) {
 char subcommand;
 char subsub;
 subcommand = cmdLine[0];
 subsub = cmdLine[1];
 if ( subcommand == 's' )
  CUL_CullbyCrit( CT_SDSS, cmdLine+1 );
 else if ( subcommand == 'n' ) {
  if ( subsub == ' ' ) {
   CUL_CullNVSS( cmdLine+1 );
   if ( scripted == 0 )
    return 1;
   else {
    CUL_WaitForThreads();
    free( cpThreads );
    free( cThreadData );
   }
  }
  else CUL_CullbyCrit( CT_NVSS, cmdLine+1 );
 }
 else if ( subcommand == 'c' )
  CUL_CancelNVSS();
 return 0;
}

canonical_original_code:
int CUL_CullCancel(char *cmdLine) {
 char subcommand;
 char subsub;
 subcommand = cmdLine[0];
 subsub = cmdLine[1];
 if ( subcommand == 's' )
  CUL_CullbyCrit( CT_SDSS, cmdLine+1 );
 else if ( subcommand == 'n' ) {
  if ( subsub == ' ' ) {
   CUL_CullNVSS( cmdLine+1 );
   if ( scripted == 0 )
    return 1;
   else {
    CUL_WaitForThreads();
    free( cpThreads );
    free( cThreadData );
   }
  }
  else CUL_CullbyCrit( CT_NVSS, cmdLine+1 );
 }
 else if ( subcommand == 'c' )
  CUL_CancelNVSS();
 return 0;
}

variable_types: subcommand char

variable_types: subsub char


original_code:
char * gnuplot_get_program_path(char * pname)
{
    int i, j, lg;
    char * path;
    static char buf[4096];
    sprintf(buf, "./%s", pname) ;
    if (access(buf, 1)==0) {
        sprintf(buf, ".");
        return buf ;
    }
    buf[0] = 0;
    path = getenv("PATH") ;
    if (path!=((void *)0)) {
        for (i=0; path[i]; ) {
            for (j=i ; (path[j]) && (path[j]!=':') ; j++);
            lg = j - i;
            strncpy(buf, path + i, lg);
            if (lg == 0) buf[lg++] = '.';
            buf[lg++] = '/';
            strcpy(buf + lg, pname);
            if (access(buf, 1) == 0) {
                break ;
            }
            buf[0] = 0;
            i = j;
            if (path[i] == ':') i++ ;
        }
    } else {
  fprintf(stderr, "PATH variable not set\n");
 }
    if (buf[0] == 0) return ((void *)0) ;
    lg = strlen(buf) - 1 ;
    while (buf[lg]!='/') {
        buf[lg]=0 ;
        lg -- ;
    }
    buf[lg] = 0;
    return buf ;
}

canonical_original_code:
char *gnuplot_get_program_path(char *pname)
{
    int i; int j; int lg;
    char *path;
    static char buf[4096];
    sprintf(buf, "./%s", pname) ;
    if (access(buf, 1)==0) {
        sprintf(buf, ".");
        return buf ;
    }
    buf[0] = 0;
    path = getenv("PATH") ;
    if (path!=((void *)0)) {
        for (i=0; path[i]; ) {
            for (j=i ; (path[j]) && (path[j]!=':') ; j++);
            lg = j - i;
            strncpy(buf, path + i, lg);
            if (lg == 0) buf[lg++] = '.';
            buf[lg++] = '/';
            strcpy(buf + lg, pname);
            if (access(buf, 1) == 0) {
                break ;
            }
            buf[0] = 0;
            i = j;
            if (path[i] == ':') i++ ;
        }
    } else {
  fprintf(stderr, "PATH variable not set\n");
 }
    if (buf[0] == 0) return ((void *)0) ;
    lg = strlen(buf) - 1 ;
    while (buf[lg]!='/') {
        buf[lg]=0 ;
        lg -- ;
    }
    buf[lg] = 0;
    return buf ;
}

variable_types:
pname
char *

variable_types: lg int

variable_types:
path
char *

variable_types:
buf
char [4096]

return_type: char *


decompiled_code:
__int64 __fastcall FIO_OpenScriptFile(const char *a1)
{
unsigned int v1; // edx

script_file = fopen(a1, "rt");
v1 = 1;
if ( !script_file )
{
printf("script file %s could not be opened.\n", a1);
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned int v1; // edx

script_file = fopen(a1, "rt");
v1 = 1;
if ( !script_file )
{
printf("script file %s could not be opened.\n", a1);
v1 = 0;
}
return v1;
}

original_code:
int FIO_OpenScriptFile( const char *name ) {
 script_file = fopen( name, "rt" );
 if ( script_file == ((void *)0) ) {
  printf( "script file %s could not be opened.\n", name );
  return 0;
 }
 return 1;
}

canonical_original_code:
int FIO_OpenScriptFile(char *name) {
 script_file = fopen( name, "rt" );
 if ( script_file == ((void *)0) ) {
  printf( "script file %s could not be opened.\n", name );
  return 0;
 }
 return 1;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall FIO_ReadScript(char *a1, int a2)
{
__int64 result; // rax

if ( fgets(a1, a2, script_file) )
result = (unsigned int)(*a1 == 10) + 1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, int a2)
{
__int64 result; // rax

if ( fgets(a1, a2, script_file) )
result = (unsigned int)(*a1 == 10) + 1;
else
result = 0LL;
return result;
}

original_code:
int FIO_ReadScript( char *cmdLine, int length ) {
 if ( fgets(cmdLine,length,script_file) == ((void *)0) )
  return 0;
 if ( cmdLine[0] == '\n' )
  return 2;
 return 1;
}

canonical_original_code:
int FIO_ReadScript(char *cmdLine, int length) {
 if ( fgets(cmdLine,length,script_file) == ((void *)0) )
  return 0;
 if ( cmdLine[0] == '\n' )
  return 2;
 return 1;
}

variable_types: length int


decompiled_code:
int FIO_CloseScriptFile()
{
return FIO_CloseFile(script_file);
}

canonical_decompiled_code:
int func9()
{
return func3(script_file);
}

original_code:
void FIO_CloseScriptFile( void ) {
 FIO_CloseFile( script_file );
}

canonical_original_code:
void FIO_CloseScriptFile() {
 FIO_CloseFile( script_file );
}


getch

repo: woodcarver/my-homework

decompiled_code:
int getch()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getchar();
--bufp;
return buf[v0 - 1];
}

canonical_decompiled_code:
int func0()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getchar();
--bufp;
return buf[v0 - 1];
}

original_code:
int getch(void)
{
 return (bufp>0)?buf[--bufp]:getchar();
}

canonical_original_code:
int getch()
{
 return (bufp>0)?buf[--bufp]:getchar();
}


ungetch

decompiled_code:
int __fastcall ungetch(char a1)
{
int result; // eax

result = bufp;
if ( bufp > 99 )
return puts("ungetch:too many characters");
++bufp;
buf[result] = a1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(char a1)
{
int result; // eax

result = bufp;
if ( bufp > 99 )
return puts("ungetch:too many characters");
++bufp;
buf[result] = a1;
return result;
}

original_code:
void ungetch(int c)
{
 if(bufp>=100)
  printf("ungetch:too many characters\n");
 else
  buf[bufp++] = c;
}

variable_types: c int


getop

original_code:
int getop(char s[])
{
 int i,c;
 while((s[0] = c = getch()) == ' ' || c=='\t')
 s[1] = '\0';
 if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) && c!='.' && c!='\n')
  return '1';
 if(c == '\n')
  return '\n';
 i=0;
 if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
  while(((*__ctype_b_loc ())[(int) ((s[++i]=c=getch()))] & (unsigned short int) _ISdigit))
   ;
 if(c=='.')
  while(((*__ctype_b_loc ())[(int) ((s[++i]=c=getch()))] & (unsigned short int) _ISdigit))
   ;
 s[i]='\0';
 if(c != (-1))
  ungetch(c);
 return '0';
}

canonical_original_code:
int getop(char s[])
{
 int i; int c;
 while((s[0] = c = getch()) == ' ' || c=='\t')
 s[1] = '\0';
 if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) && c!='.' && c!='\n')
  return '1';
 if(c == '\n')
  return '\n';
 i=0;
 if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
  while(((*__ctype_b_loc ())[(int) ((s[++i]=c=getch()))] & (unsigned short) _ISdigit))
   ;
 if(c=='.')
  while(((*__ctype_b_loc ())[(int) ((s[++i]=c=getch()))] & (unsigned short) _ISdigit))
   ;
 s[i]='\0';
 if(c != (-1))
  ungetch(c);
 return '0';
}

variable_types:
s
char []


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
double v4; // rbx
double v5; // rbx
double v6; // rbx
int v7; // eax
char v9[120]; // [rsp+0h] [rbp-78h] BYREF

while ( 1 )
{
v7 = getop(v9, argv, envp);
if ( v7 == -1 )
return 0;
switch ( v7 )
{
case 10:
goto LABEL_9;
case 42:
v5 = pop();
v3 = pop() * v5;
push(v3);
break;
case 43:
v4 = pop();
v3 = pop() + v4;
push(v3);
break;
case 45:
v6 = pop();
v3 = pop() - v6;
push(v3);
break;
case 47:
v3 = pop();
if ( v3 == 0.0 )
{
puts("error:zero divisor");
}
else
{
v3 = pop() / v3;
push(v3);
}
LABEL_9:
pop();
printf("\t%.8g\n", v3);
break;
case 48:
v3 = atof(v9);
push(v3);
break;
default:
argv = (const char **)v9;
printf("error:unknow command %s\n", v9);
break;
}
}
}

original_code:
int main()
{
 int type;
 double op2;
 char s[100];
 while((type = getop(s)) != (-1))
 {
  switch(type){
   case '0':
    push(atof(s));
    break;
   case '+':
    push(pop()+pop());
    break;
   case '*':
    push(pop()*pop());
    break;
   case '-':
    op2 = pop();
    push(pop()-op2);
    break;
   case '/':
    op2 = pop();
    if(op2 != 0.0)
     push(pop()/op2);
    else
     printf("error:zero divisor\n");
   case '\n':
    printf("\t%.8g\n",pop());
    break;
   default:
    printf("error:unknow command %s\n",s);
    break;
  }
 }
 return 0;
}

variable_types: type int

variable_types:
s
char [100]


decompiled_code:
__int64 __fastcall irclist_append(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rcx
__int64 result; // rax
__int64 v4; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
v2[1] = 0LL;
*v2 = a2;
result = *a1;
if ( *a1 )
{
do
{
v4 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
*(_QWORD *)(v4 + 8) = v2;
}
else
{
*a1 = (__int64)v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rcx
__int64 result; // rax
__int64 v4; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
v2[1] = 0LL;
*v2 = a2;
result = *a1;
if ( *a1 )
{
do
{
v4 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
*(_QWORD *)(v4 + 8) = v2;
}
else
{
*a1 = (__int64)v2;
}
return result;
}

original_code:
int irclist_append(IRCLIST ** first, void * item) {
    IRCLIST * node, *iterator;
    if (first == ((void *)0)) return -1;
    node = malloc(sizeof (IRCLIST));
    memset(node, 0, sizeof (IRCLIST));
    if (node == ((void *)0)) return -1;
    node->item = item;
    if (*first == ((void *)0)) *first = node;
    else {
        iterator = *first;
        while (iterator->next != ((void *)0)) iterator = iterator->next;
        iterator->next = node;
    }
    return 0;
}

canonical_original_code:
int irclist_append(struct __irclist **first, void *item) {
    struct __irclist *node; struct __irclist *iterator;
    if (first == ((void *)0)) return -1;
    node = malloc(sizeof (IRCLIST));
    memset(node, 0, sizeof (IRCLIST));
    if (node == ((void *)0)) return -1;
    node->item = item;
    if (*first == ((void *)0)) *first = node;
    else {
        iterator = *first;
        while (iterator->next != ((void *)0)) iterator = iterator->next;
        iterator->next = node;
    }
    return 0;
}

variable_types: struct __irclist { void *item; struct __irclist *next; } **

variable_types:
item
void *


decompiled_code:
__int64 __fastcall irclist_clear(__int64 *a1)
{
__int64 v1; // rbx
void **v2; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0LL;
*a1 = 0LL;
do
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 v1; // rbx
void **v2; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0LL;
*a1 = 0LL;
do
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
while ( v1 );
return 0LL;
}

original_code:
int irclist_clear(IRCLIST ** first) {
    IRCLIST *tmp, * iterator;
    if (first == ((void *)0)) return -1;
    if (*first == ((void *)0)) return 0;
    iterator = *first;
    *first = ((void *)0);
    tmp = iterator;
    while (iterator != ((void *)0)) {
        tmp = iterator;
        iterator = iterator->next;
        free(tmp->item);
        free(tmp);
    }
    return 0;
}

canonical_original_code:
int irclist_clear(struct __irclist **first) {
    struct __irclist *tmp; struct __irclist *iterator;
    if (first == ((void *)0)) return -1;
    if (*first == ((void *)0)) return 0;
    iterator = *first;
    *first = ((void *)0);
    tmp = iterator;
    while (iterator != ((void *)0)) {
        tmp = iterator;
        iterator = iterator->next;
        free(tmp->item);
        free(tmp);
    }
    return 0;
}

variable_types: struct __irclist { void *item; struct __irclist *next; } *


decompiled_code:
__int64 __fastcall irclist_size(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !a1 )
return (unsigned int)-1;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v1 = *(_QWORD *)(v1 + 8);
++v2;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !a1 )
return (unsigned int)-1;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v1 = *(_QWORD *)(v1 + 8);
++v2;
}
while ( v1 );
return v2;
}

original_code:
int irclist_size(IRCLIST ** first) {
    IRCLIST * iterator;
    int i;
    if (first == ((void *)0)) return -1;
    i = 0;
    iterator = *first;
    while (iterator != ((void *)0)) {
        iterator = iterator->next;
        i++;
    }
    return i;
}

canonical_original_code:
int irclist_size(struct __irclist **first) {
    struct __irclist *iterator;
    int i;
    if (first == ((void *)0)) return -1;
    i = 0;
    iterator = *first;
    while (iterator != ((void *)0)) {
        iterator = iterator->next;
        i++;
    }
    return i;
}

variable_types: i int

user_defined_types: struct __irclist { void *item; struct __irclist *next; }


decompiled_code:
__int64 __fastcall irclist_insert(__int64 *a1, __int64 a2, int a3)
{
int v4; // eax
_QWORD *v5; // rax
_QWORD *v6; // rcx
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rax
int v10; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = irclist_size(a1);
if ( a3 < 0 || v4 < a3 )
return 0xFFFFFFFFLL;
v5 = malloc(0x10uLL);
v6 = v5;
v5[1] = 0LL;
*v5 = a2;
if ( a3 )
{
v8 = *a1;
v9 = *(_QWORD *)(*a1 + 8);
if ( a3 > 1 )
{
v10 = 1;
do
{
v8 = v9;
v9 = *(_QWORD *)(v9 + 8);
++v10;
}
while ( a3 != v10 );
}
*(_QWORD *)(v8 + 8) = v6;
v6[1] = v9;
result = 0LL;
}
else
{
v5[1] = *a1;
*a1 = (__int64)v5;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 a2, int a3)
{
int v4; // eax
_QWORD *v5; // rax
_QWORD *v6; // rcx
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rax
int v10; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = func2(a1);
if ( a3 < 0 || v4 < a3 )
return 0xFFFFFFFFLL;
v5 = malloc(0x10uLL);
v6 = v5;
v5[1] = 0LL;
*v5 = a2;
if ( a3 )
{
v8 = *a1;
v9 = *(_QWORD *)(*a1 + 8);
if ( a3 > 1 )
{
v10 = 1;
do
{
v8 = v9;
v9 = *(_QWORD *)(v9 + 8);
++v10;
}
while ( a3 != v10 );
}
*(_QWORD *)(v8 + 8) = v6;
v6[1] = v9;
result = 0LL;
}
else
{
v5[1] = *a1;
*a1 = (__int64)v5;
result = 0LL;
}
return result;
}

original_code:
int irclist_insert(IRCLIST ** first, void * item, int location) {
    IRCLIST * node, *n_iterator, *p_iterator;
    int i;
    if (first == ((void *)0)) return -1;
    if (location > irclist_size(first) || location < 0) return -1;
    node = malloc(sizeof (IRCLIST));
    memset(node, 0, sizeof (IRCLIST));
    if (node == ((void *)0)) return -1;
    node->item = item;
    if (location == 0) {
        node->next = *first;
        *first = node;
    } else {
        i = 1;
        n_iterator = (*first)->next;
        p_iterator = *first;
        while (i < location) {
            p_iterator = n_iterator;
            n_iterator = n_iterator->next;
            i++;
        }
        p_iterator->next = node;
        node->next = n_iterator;
    }
    return 0;
}

canonical_original_code:
int irclist_insert(struct __irclist **first, void *item, int location) {
    struct __irclist *node; struct __irclist *n_iterator; struct __irclist *p_iterator;
    int i;
    if (first == ((void *)0)) return -1;
    if (location > irclist_size(first) || location < 0) return -1;
    node = malloc(sizeof (IRCLIST));
    memset(node, 0, sizeof (IRCLIST));
    if (node == ((void *)0)) return -1;
    node->item = item;
    if (location == 0) {
        node->next = *first;
        *first = node;
    } else {
        i = 1;
        n_iterator = (*first)->next;
        p_iterator = *first;
        while (i < location) {
            p_iterator = n_iterator;
            n_iterator = n_iterator->next;
            i++;
        }
        p_iterator->next = node;
        node->next = n_iterator;
    }
    return 0;
}

variable_types: location int


decompiled_code:
__int64 __fastcall irclist_remove(__int64 *a1, int a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rbx
int i; // eax
__int64 result; // rax
void **v7; // r12

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = irclist_size(a1);
if ( a2 < 0 || v2 <= a2 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v3 = *a1;
v4 = *(_QWORD *)(*a1 + 8);
if ( a2 > 1 )
{
for ( i = 1; i != a2; ++i )
{
v3 = v4;
v4 = *(_QWORD *)(v4 + 8);
}
}
*(_QWORD *)(v3 + 8) = *(_QWORD *)(v4 + 8);
free(*(void **)v4);
free((void *)v4);
result = 0LL;
}
else
{
v7 = (void **)*a1;
*a1 = *(_QWORD *)(*a1 + 8);
free(*v7);
free(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, int a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rbx
int i; // eax
__int64 result; // rax
void **v7; // r12

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = func2(a1);
if ( a2 < 0 || v2 <= a2 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v3 = *a1;
v4 = *(_QWORD *)(*a1 + 8);
if ( a2 > 1 )
{
for ( i = 1; i != a2; ++i )
{
v3 = v4;
v4 = *(_QWORD *)(v4 + 8);
}
}
*(_QWORD *)(v3 + 8) = *(_QWORD *)(v4 + 8);
free(*(void **)v4);
free((void *)v4);
result = 0LL;
}
else
{
v7 = (void **)*a1;
*a1 = *(_QWORD *)(*a1 + 8);
free(*v7);
free(v7);
result = 0LL;
}
return result;
}

original_code:
int irclist_remove(IRCLIST ** first, int location) {
    IRCLIST * node, *tmp, * n_iterator, * p_iterator;
    int i;
    if (first == ((void *)0)) return -1;
    if (location > irclist_size(first) - 1 || location < 0) return -1;
    if (location == 0) {
        node = (*first)->next;
        tmp = *first;
        *first = node;
        free(tmp->item);
        free(tmp);
    } else {
        i = 1;
        n_iterator = (*first)->next;
        p_iterator = *first;
        while (i < location) {
            p_iterator = n_iterator;
            n_iterator = n_iterator->next;
            i++;
        }
        tmp = n_iterator;
        p_iterator->next = n_iterator->next;
        free(tmp->item);
        free(tmp);
    }
    return 0;
}

canonical_original_code:
int irclist_remove(struct __irclist **first, int location) {
    struct __irclist *node; struct __irclist *tmp; struct __irclist *n_iterator; struct __irclist *p_iterator;
    int i;
    if (first == ((void *)0)) return -1;
    if (location > irclist_size(first) - 1 || location < 0) return -1;
    if (location == 0) {
        node = (*first)->next;
        tmp = *first;
        *first = node;
        free(tmp->item);
        free(tmp);
    } else {
        i = 1;
        n_iterator = (*first)->next;
        p_iterator = *first;
        while (i < location) {
            p_iterator = n_iterator;
            n_iterator = n_iterator->next;
            i++;
        }
        tmp = n_iterator;
        p_iterator->next = n_iterator->next;
        free(tmp->item);
        free(tmp);
    }
    return 0;
}


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(stderr, "Usage: %s <training directory> <test directory> <output directory>", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "Usage: %s <training directory> <test directory> <output directory>", a1);
}

original_code:
void print_usage(char * argv0) {
    fprintf(stderr, "Usage: %s <training directory> <test directory> <output directory>", argv0);
}

canonical_original_code:
void print_usage(char *argv0) {
    fprintf(stderr, "Usage: %s <training directory> <test directory> <output directory>", argv0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rbp
__off_t v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
double v7[4]; // [rsp+18h] [rbp-20h] BYREF

if ( argc == 4 )
{
v7[0] = 0.0;
v6 = 0LL;
v5 = 0LL;
v4 = train(argv[1], &v5, v7, (double *)&v6);
test(argv[2], argv[3], v4);
trie_destroy(v4);
result = 0;
}
else
{
print_usage(*argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rbp
__off_t v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
double v7[4]; // [rsp+18h] [rbp-20h] BYREF

if ( argc == 4 )
{
v7[0] = 0.0;
v6 = 0LL;
v5 = 0LL;
v4 = func1(argv[1], &v5, v7, (double *)&v6);
func2(argv[2], argv[3], v4);
trie_destroy(v4);
result = 0;
}
else
{
func0(*argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv) {
    if (argc != 4) {
        print_usage(argv[0]);
        return 1;
    }
    double train_bits = 0, train_ent = 0;
    size_t corpus_size = 0;
    trie_t * trie = ((void *)0);
    trie = train(argv[1], &corpus_size, &train_bits, &train_ent);
    test(argv[2], argv[3], trie);
    trie_destroy(trie);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc != 4) {
        print_usage(argv[0]);
        return 1;
    }
    double train_bits = 0; double train_ent = 0;
    unsigned long corpus_size = 0;
    struct __trie_struct__ *trie = ((void *)0);
    trie = train(argv[1], &corpus_size, &train_bits, &train_ent);
    test(argv[2], argv[3], trie);
    trie_destroy(trie);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct __trie_struct__ { unsigned int order; unsigned int root; unsigned int base_ptr; struct __nodelist_struct__ { struct __node_struct__ { unsigned char symbol; unsigned long count; unsigned int down; unsigned int right; unsigned int vine; unsigned int parent; unsigned long child_escape_count; } *data; unsigned int ptr; unsigned long size; } *list; struct __context_struct__ { struct __context_entry_struct__ { unsigned char symbol; struct __fraction_struct__ { unsigned long numerator; unsigned long denominator; } probability; unsigned char escape; } *entries; unsigned long *escape_counts; struct __fraction_struct__ avg_escape_count; } context; struct __fraction_struct__ character_probability; } *

user_defined_types: struct __trie_struct__ { unsigned int order; unsigned int root; unsigned int base_ptr; struct __nodelist_struct__ *list; struct __context_struct__ context; struct __fraction_struct__ character_probability; }

user_defined_types: struct __context_struct__ { struct __context_entry_struct__ *entries; unsigned long *escape_counts; struct __fraction_struct__ avg_escape_count; }

user_defined_types: struct __nodelist_struct__ { struct __node_struct__ *data; unsigned int ptr; unsigned long size; }

user_defined_types: struct __context_entry_struct__ { unsigned char symbol; struct __fraction_struct__ probability; unsigned char escape; }


decompiled_code:
__int64 __fastcall calculate_char_probability(_BYTE *a1)
{
_BYTE *v1; // rdx
bool v2; // zf
char *v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx
char v7[256]; // [rsp+10h] [rbp-118h] BYREF
char v8; // [rsp+110h] [rbp-18h] BYREF
unsigned __int64 v9; // [rsp+118h] [rbp-10h]

v1 = a1;
v9 = __readfsqword(0x28u);
v2 = *a1 == 0;
memset(v7, 0, sizeof(v7));
if ( !v2 )
{
do
++v1;
while ( *v1 );
v7[1] = 1;
}
v3 = &v7[1];
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v5 += v4;
if ( &v8 == v3 )
break;
v4 = (unsigned __int8)*v3++;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
_BYTE *v1; // rdx
bool v2; // zf
char *v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx
char v7[256]; // [rsp+10h] [rbp-118h] BYREF
char v8; // [rsp+110h] [rbp-18h] BYREF
unsigned __int64 v9; // [rsp+118h] [rbp-10h]

v1 = a1;
v9 = __readfsqword(0x28u);
v2 = *a1 == 0;
memset(v7, 0, sizeof(v7));
if ( !v2 )
{
do
++v1;
while ( *v1 );
v7[1] = 1;
}
v3 = &v7[1];
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v5 += v4;
if ( &v8 == v3 )
break;
v4 = (unsigned __int8)*v3++;
}
return 1LL;
}

original_code:
fraction_t calculate_char_probability(char * text) {
    unsigned char test[256];
    fraction_t probability;
    int i;
    memset(test, 0, sizeof(char)*256);
    memset(&probability, 0, sizeof(fraction_t));
    while ((*text) != '\0') {
        i = 0x00FF && (*text);
        test[i] = 1;
        text++;
    }
    for (i = 0; i < 256; i++) {
        probability.denominator += test[i];
    }
    probability.numerator = 1;
    return probability;
}

canonical_original_code:
struct __fraction_struct__ calculate_char_probability(char *text) {
    unsigned char test[256];
    struct __fraction_struct__ probability;
    int i;
    memset(test, 0, sizeof(char)*256);
    memset(&probability, 0, sizeof(fraction_t));
    while ((*text) != '\0') {
        i = 0x00FF && (*text);
        test[i] = 1;
        text++;
    }
    for (i = 0; i < 256; i++) {
        probability.denominator += test[i];
    }
    probability.numerator = 1;
    return probability;
}

variable_types:
text
char *

variable_types:
test
unsigned char [256]

variable_types: struct __fraction_struct__ { unsigned long numerator; unsigned long denominator; }


repo: wowsoso/mqtts

decompiled_code:
void __fastcall free_fixed_header(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void free_fixed_header(fixed_header_t* fixed_header)
{
    free (fixed_header);
}

canonical_original_code:
void free_fixed_header(struct fixed_header_s *fixed_header)
{
    free (fixed_header);
}

variable_types: struct fixed_header_s { unsigned char message_type; unsigned char dup; unsigned char qos; unsigned char retain; unsigned int remaining_length; } *


decompiled_code:
void __fastcall free_variable_header_connect(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_variable_header_connect(variable_header_connect_t* variable_header)
{
    free (variable_header->protocol_name);
    free (variable_header);
}

canonical_original_code:
void free_variable_header_connect(struct variable_header_connect_s *variable_header)
{
    free (variable_header->protocol_name);
    free (variable_header);
}

variable_types: struct variable_header_connect_s { unsigned char *protocol_name; unsigned char protocol_version_number; unsigned char username_flag; unsigned char password_flag; unsigned char will_retain; unsigned short will_qos; unsigned char will_flag; unsigned char clean_session; unsigned char reserved; unsigned short keep_alive_timer; } *


decompiled_code:
void __fastcall free_payload_connect(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void free_payload_connect(payload_connect_t* payload)
{
    free (payload);
}

canonical_original_code:
void free_payload_connect(struct payload_connect_s *payload)
{
    free (payload);
}

variable_types: struct payload_connect_s { struct string_s { unsigned char msb; unsigned char lsb; unsigned char *str; } client_id; struct string_s will_topic; struct string_s will_message; struct string_s username; struct string_s password; } *

user_defined_types: struct payload_connect_s { struct string_s client_id; struct string_s will_topic; struct string_s will_message; struct string_s username; struct string_s password; }


decompiled_code:
void __fastcall free_variable_header_publish(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
free(a1);
}

original_code:
void free_variable_header_publish(variable_header_publish_t* variable_header)
{
    free (variable_header);
}

canonical_original_code:
void free_variable_header_publish(struct variable_header_publish_s *variable_header)
{
    free (variable_header);
}

variable_types: struct variable_header_publish_s { unsigned char topic_name_msb; unsigned char topic_name_lsb; unsigned char *topic_name; unsigned short message_id; } *


decompiled_code:
void __fastcall free_payload_publish(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_payload_publish(payload_publish_t* payload)
{
    free (payload->data);
    free (payload);
}

canonical_original_code:
void free_payload_publish(struct payload_publish_s *payload)
{
    free (payload->data);
    free (payload);
}

variable_types: struct payload_publish_s { unsigned char *data; } *


decompiled_code:
void __fastcall free_variable_header_subscribe(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(void *a1)
{
free(a1);
}

original_code:
void free_variable_header_subscribe(variable_header_subscribe_t* variable_header)
{
    free (variable_header);
}

canonical_original_code:
void free_variable_header_subscribe(struct variable_header_subscribe_s *variable_header)
{
    free (variable_header);
}

variable_types: struct variable_header_subscribe_s { unsigned short message_id; } *