decompiled_code:
_QWORD *create_list_klfits_header()
{
_QWORD *result; // rax

result = malloc(0xC0uLL);
if ( !result )
{
fwrite("create_list_element: malloc failed.\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result[23] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax

result = malloc(0xC0uLL);
if ( !result )
{
fwrite("create_list_element: malloc failed.\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result[23] = 0LL;
return result;
}

original_code:
KLFITS_HEADER *create_list_klfits_header()
{
 KLFITS_HEADER *p;
 p = (KLFITS_HEADER *) malloc( sizeof( KLFITS_HEADER ) );
 if (p==((void *)0)) {
  fprintf(stderr,"create_list_element: malloc failed.\n");
 exit(1);
 }
 p->next = ((void *)0);
 return p;
}

canonical_original_code:
struct klfits_header *create_list_klfits_header()
{
 struct klfits_header *p;
 p = (struct klfits_header *) malloc( sizeof( KLFITS_HEADER ) );
 if (p==((void *)0)) {
  fprintf(stderr,"create_list_element: malloc failed.\n");
 exit(1);
 }
 p->next = ((void *)0);
 return p;
}

return_type: struct klfits_header { char keyword[9]; char value_str[71]; char value_byte; long value_lint; double value_double; int datatype; char comment[71]; struct klfits_header *next; } *


printerror

repo: KathleenLabrie/KLlibc

decompiled_code:
void __fastcall printerror(int status)
{
if ( status )
{
ffrprt(stderr, (unsigned int)status);
exit(status);
}
}

canonical_decompiled_code:
void __fastcall func0(int status)
{
if ( status )
{
ffrprt(stderr, (unsigned int)status);
exit(status);
}
}

original_code:
void printerror( int status)
{
    if (status)
    {
       ffrprt(stderr, status);
       exit( status );
    }
    return;
}

canonical_original_code:
void printerror(int status)
{
    if (status)
    {
       ffrprt(stderr, status);
       exit( status );
    }
    return;
}

variable_types: status int

return_type: void


findindex

decompiled_code:
__int64 __fastcall findindex(__int64 a1, __int64 a2, _QWORD *a3, double a4)
{
__int64 v5; // rbx
__int64 result; // rax

if ( a2 <= 0 )
{
LABEL_5:
fprintf(stderr, "Index of %f not found\n", a4);
fwrite("ERROR: Internal error\n", 1uLL, 0x16uLL, stderr);
result = 99LL;
}
else
{
v5 = 0LL;
while ( !(unsigned int)equals(a4, *(double *)(a1 + 8 * v5)) )
{
if ( a2 == ++v5 )
goto LABEL_5;
}
*a3 = v5;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3, double a4)
{
__int64 v5; // rbx
__int64 result; // rax

if ( a2 <= 0 )
{
LABEL_5:
fprintf(stderr, "Index of %f not found\n", a4);
fwrite("ERROR: Internal error\n", 1uLL, 0x16uLL, stderr);
result = 99LL;
}
else
{
v5 = 0LL;
while ( !(unsigned int)equals(a4, *(double *)(a1 + 8 * v5)) )
{
if ( a2 == ++v5 )
goto LABEL_5;
}
*a3 = v5;
result = 0LL;
}
return result;
}

original_code:
int findindex(double value, double *vec, long int n, long int *index)
{
 int status=0;
 long int i;
 for (i=0; i<n; i++ ) {
   if ( equals(value,*(vec+i)) ) {
     *index=i;
     return(status);
   }
 }
 fprintf(stderr,"Index of %f not found\n",value);
 fprintf(stderr,"ERROR: Internal error\n");
 return(99);
}

canonical_original_code:
int findindex(double value, double *vec, long n, long *index)
{
 int status = 0;
 long i;
 for (i=0; i<n; i++ ) {
   if ( equals(value,*(vec+i)) ) {
     *index=i;
     return(status);
   }
 }
 fprintf(stderr,"Index of %f not found\n",value);
 fprintf(stderr,"ERROR: Internal error\n");
 return(99);
}

variable_types: value double

variable_types:
vec
double *

variable_types: n long

variable_types:
index
long *

variable_types: i long

return_type: int


gasdev

decompiled_code:
float __fastcall gasdev(__int64 a1)
{
float v1; // xmm0_4
float v2; // xmm0_4
float v3; // xmm0_4
float v4; // xmm3_4
float v5; // xmm0_4
double v6; // xmm0_8
double v7; // xmm0_8
float v8; // xmm0_4
float result; // xmm0_4
float v10; // [rsp+0h] [rbp-18h]

if ( iset_1 )
{
iset_1 = 0;
result = *(float *)&gset_0;
}
else
{
do
{
do
{
v1 = ran1(a1);
v2 = v1 + v1 - 1.0;
v10 = v2;
v3 = ran1(a1);
v4 = v3 + v3 - 1.0;
v5 = (float)(v10 * v10) + (float)(v4 * v4);
}
while ( v5 >= 1.0 );
}
while ( v5 == 0.0 );
v6 = log(v5) * -2.0 / v5;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = v7;
*(float *)&gset_0 = v10 * v8;
iset_1 = 1;
result = v8 * v4;
}
return result;
}

canonical_decompiled_code:
float __fastcall func0(__int64 a1)
{
float v1; // xmm0_4
float v2; // xmm0_4
float v3; // xmm0_4
float v4; // xmm3_4
float v5; // xmm0_4
double v6; // xmm0_8
double v7; // xmm0_8
float v8; // xmm0_4
float result; // xmm0_4
float v10; // [rsp+0h] [rbp-18h]

if ( iset_1 )
{
iset_1 = 0;
result = *(float *)&gset_0;
}
else
{
do
{
do
{
v1 = ran1(a1);
v2 = v1 + v1 - 1.0;
v10 = v2;
v3 = ran1(a1);
v4 = v3 + v3 - 1.0;
v5 = (float)(v10 * v10) + (float)(v4 * v4);
}
while ( v5 >= 1.0 );
}
while ( v5 == 0.0 );
v6 = log(v5) * -2.0 / v5;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = v7;
*(float *)&gset_0 = v10 * v8;
iset_1 = 1;
result = v8 * v4;
}
return result;
}

original_code:
float gasdev(long *idum)
{
 static int iset=0;
 static float gset;
 float fac,rsq,v1,v2;
 if (iset == 0) {
     do {
    v1=2.0*ran1(idum)-1.0;
 v2=2.0*ran1(idum)-1.0;
 rsq=v1*v1+v2*v2;
     } while (rsq >= 1.0 || rsq == 0.0);
     fac=sqrt(-2.0*log(rsq)/rsq);
     gset=v1*fac;
     iset=1;
     return v2*fac;
 } else {
     iset=0;
     return gset;
 }
}

canonical_original_code:
float gasdev(long *idum)
{
 static int iset = 0;
 static float gset;
 float fac; float rsq; float v1; float v2;
 if (iset == 0) {
     do {
    v1=2.0*ran1(idum)-1.0;
 v2=2.0*ran1(idum)-1.0;
 rsq=v1*v1+v2*v2;
     } while (rsq >= 1.0 || rsq == 0.0);
     fac=sqrt(-2.0*log(rsq)/rsq);
     gset=v1*fac;
     iset=1;
     return v2*fac;
 } else {
     iset=0;
     return gset;
 }
}

variable_types:
idum
long *

variable_types: iset int

variable_types: gset float

variable_types: fac float

variable_types: rsq float

return_type: float


fgauss

original_code:
void fgauss(double x[], double a[], double *y, double dyda[], int na)
{
 double ex, arg;
 arg=x[0]-a[2];
 ex=exp( -0.5*( (arg*arg)/(a[3]*a[3]) ) );
 *y=a[1]*ex + a[0];
 dyda[0]=1;
 dyda[1]=ex;
 dyda[2]=a[1]*ex*arg/(a[3]*a[3]);
 dyda[3]=a[1]*ex*(arg*arg)/pow(a[3],3);
 return;
}

canonical_original_code:
void fgauss(double x[], double a[], double *y, double dyda[], int na)
{
 double ex; double arg;
 arg=x[0]-a[2];
 ex=exp( -0.5*( (arg*arg)/(a[3]*a[3]) ) );
 *y=a[1]*ex + a[0];
 dyda[0]=1;
 dyda[1]=ex;
 dyda[2]=a[1]*ex*arg/(a[3]*a[3]);
 dyda[3]=a[1]*ex*(arg*arg)/pow(a[3],3);
 return;
}

variable_types:
x
double []

variable_types:
a
double []

variable_types:
y
double *

variable_types:
dyda
double []

variable_types: ex double

variable_types: arg double


equals

decompiled_code:
_BOOL8 __fastcall equals(double a1, double a2)
{
double v2; // xmm1_8
_BOOL8 result; // rax
bool v4; // zf
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = a2 / a1;
sprintf(s, "%f", v2);
result = 1LL;
if ( memcmp("nan", s, 3uLL) )
{
v4 = memcmp("inf", s, 3uLL) == 0;
result = !v4;
if ( !v4 )
{
result = 0LL;
if ( v2 >= 0.9999999999999998 )
result = v2 <= 1.0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(double a1, double a2)
{
double v2; // xmm1_8
_BOOL8 result; // rax
bool v4; // zf
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = a2 / a1;
sprintf(s, "%f", v2);
result = 1LL;
if ( memcmp("nan", s, 3uLL) )
{
v4 = memcmp("inf", s, 3uLL) == 0;
result = !v4;
if ( !v4 )
{
result = 0LL;
if ( v2 >= 0.9999999999999998 )
result = v2 <= 1.0;
}
}
return result;
}

original_code:
int equals(double val1, double val2)
{
 double ratio;
 char strratio[80];
 ratio = val2/val1;
 sprintf(strratio,"%f",ratio);
 if ( !strncmp("nan",strratio,3) ) {
  return(1);
 } else if ( !strncmp("inf",strratio,3) ) {
  return(0);
 } else {
  if ( (ratio >= 1.-((double)2.22044604925031308084726333618164062e-16L)) && (ratio <= 1.+((double)2.22044604925031308084726333618164062e-16L)) ) {
  return(1);
 }
 }
 return(0);
}

variable_types: ratio double

variable_types:
strratio
char [80]


decompiled_code:
__int64 __fastcall translate_tm_zone(const char *a1)
{
if ( !strcmp(a1, "EDT") )
return 4294967292LL;
if ( !strcmp(a1, "EST") )
return 4294967291LL;
if ( !strcmp(a1, "PDT") )
return 4294967289LL;
if ( !strcmp(a1, "PST") )
return 4294967288LL;
if ( !strcmp(a1, "HST") )
return 4294967286LL;
printf("ERROR: Unsupported local time zone (%s).\n", a1);
return 99LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
if ( !strcmp(a1, "EDT") )
return 4294967292LL;
if ( !strcmp(a1, "EST") )
return 4294967291LL;
if ( !strcmp(a1, "PDT") )
return 4294967289LL;
if ( !strcmp(a1, "PST") )
return 4294967288LL;
if ( !strcmp(a1, "HST") )
return 4294967286LL;
printf("ERROR: Unsupported local time zone (%s).\n", a1);
return 99LL;
}

original_code:
int translate_tm_zone( char tm_zone_str[] )
{
 if (!strcmp(tm_zone_str,"EDT")) { return(-4); }
 else if (!strcmp(tm_zone_str,"EST")) { return(-5); }
 else if (!strcmp(tm_zone_str,"PDT")) { return(-7); }
 else if (!strcmp(tm_zone_str,"PST")) { return(-8); }
 else if (!strcmp(tm_zone_str,"HST")) { return(-10); }
 else {
    printf("ERROR:  Unsupported local time zone (%s).\n",tm_zone_str);
    return(99);
 }
}

canonical_original_code:
int translate_tm_zone(char tm_zone_str[])
{
 if (!strcmp(tm_zone_str,"EDT")) { return(-4); }
 else if (!strcmp(tm_zone_str,"EST")) { return(-5); }
 else if (!strcmp(tm_zone_str,"PDT")) { return(-7); }
 else if (!strcmp(tm_zone_str,"PST")) { return(-8); }
 else if (!strcmp(tm_zone_str,"HST")) { return(-10); }
 else {
    printf("ERROR:  Unsupported local time zone (%s).\n",tm_zone_str);
    return(99);
 }
}


decompiled_code:
__int64 __fastcall utc2local(char *s, const char *a2)
{
struct tm *v2; // rax
unsigned int v3; // eax
unsigned int v4; // ebx
__int64 v5; // r12
bool v6; // zf
struct tm *v7; // rax
time_t v9; // [rsp+0h] [rbp-88h] BYREF
time_t timer; // [rsp+8h] [rbp-80h] BYREF
struct tm tp; // [rsp+10h] [rbp-78h] BYREF
int v12; // [rsp+48h] [rbp-40h] BYREF
int v13; // [rsp+4Ch] [rbp-3Ch] BYREF
int v14; // [rsp+50h] [rbp-38h] BYREF
int v15; // [rsp+54h] [rbp-34h] BYREF
int v16; // [rsp+58h] [rbp-30h] BYREF
int v17; // [rsp+5Ch] [rbp-2Ch] BYREF

time(&timer);
v2 = localtime(&timer);
v3 = translate_tm_zone(v2->tm_zone);
v4 = v3;
if ( v3 != 99 )
{
v5 = (int)(3600 * v3);
v6 = strcmp(a2, "YYYY-MM-DDThh:mm:ss") == 0;
v4 = !v6;
if ( v6 )
{
_isoc99_sscanf(s, "%4d-%2d-%2dT%2d:%2d:%2d", &v17, &v16, &v15, &v14, &v13, &v12);
tp.tm_sec = v12;
tp.tm_min = v13;
tp.tm_hour = v14;
tp.tm_mday = v15;
tp.tm_mon = v16 - 1;
tp.tm_year = v17 - 1900;
v9 = mktime(&tp) + v5;
v7 = localtime(&v9);
strftime(s, 0x32uLL, "%Y-%m-%dT%H:%M:%S", v7);
}
else
{
puts("This date format is not supported.");
v4 = 99;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, const char *a2)
{
struct tm *v2; // rax
unsigned int v3; // eax
unsigned int v4; // ebx
__int64 v5; // r12
bool v6; // zf
struct tm *v7; // rax
time_t v9; // [rsp+0h] [rbp-88h] BYREF
time_t timer; // [rsp+8h] [rbp-80h] BYREF
struct tm tp; // [rsp+10h] [rbp-78h] BYREF
int v12; // [rsp+48h] [rbp-40h] BYREF
int v13; // [rsp+4Ch] [rbp-3Ch] BYREF
int v14; // [rsp+50h] [rbp-38h] BYREF
int v15; // [rsp+54h] [rbp-34h] BYREF
int v16; // [rsp+58h] [rbp-30h] BYREF
int v17; // [rsp+5Ch] [rbp-2Ch] BYREF

time(&timer);
v2 = localtime(&timer);
v3 = func0(v2->tm_zone);
v4 = v3;
if ( v3 != 99 )
{
v5 = (int)(3600 * v3);
v6 = strcmp(a2, "YYYY-MM-DDThh:mm:ss") == 0;
v4 = !v6;
if ( v6 )
{
_isoc99_sscanf(s, "%4d-%2d-%2dT%2d:%2d:%2d", &v17, &v16, &v15, &v14, &v13, &v12);
tp.tm_sec = v12;
tp.tm_min = v13;
tp.tm_hour = v14;
tp.tm_mday = v15;
tp.tm_mon = v16 - 1;
tp.tm_year = v17 - 1900;
v9 = mktime(&tp) + v5;
v7 = localtime(&v9);
strftime(s, 0x32uLL, "%Y-%m-%dT%H:%M:%S", v7);
}
else
{
puts("This date format is not supported.");
v4 = 99;
}
}
return v4;
}

original_code:
int utc2local( char timestr[], char format[] )
{
 int status=0;
 int YYYY,MM,DD,hh,mm,ss;
 int tm_zone;
 long deltasec = 0;
 struct tm utctm, nowtm, *loctm;
 time_t utc, now, local;
 time( &now );
 nowtm = *localtime( &now );
 if ((tm_zone = translate_tm_zone((char *)nowtm.tm_zone)) == 99) {
    return(99);
 }
 deltasec = tm_zone * 3600;
 if (strcmp(format,"YYYY-MM-DDThh:mm:ss") == 0) {
   sscanf(timestr,"%4d-%2d-%2dT%2d:%2d:%2d",&YYYY,&MM,&DD,&hh,&mm,&ss);
   utctm.tm_sec = ss;
   utctm.tm_min = mm;
   utctm.tm_hour = hh;
   utctm.tm_mday = DD;
   utctm.tm_mon = MM - 1;
   utctm.tm_year = YYYY - 1900;
   utc = mktime( &utctm );
   local = utc + deltasec;
   loctm = localtime( &local );
   strftime( timestr, 50, "%Y-%m-%dT%H:%M:%S", loctm );
 }
 else {
   printf("This date format is not supported.\n");
   return(99);
 }
 return(status);
}

canonical_original_code:
int utc2local(char timestr[], char format[])
{
 int status = 0;
 int YYYY; int MM; int DD; int hh; int mm; int ss;
 int tm_zone;
 long deltasec = 0;
 struct tm utctm; struct tm nowtm; struct tm *loctm;
 long utc; long now; long local;
 time( &now );
 nowtm = *localtime( &now );
 if ((tm_zone = translate_tm_zone((char *)nowtm.tm_zone)) == 99) {
    return(99);
 }
 deltasec = tm_zone * 3600;
 if (strcmp(format,"YYYY-MM-DDThh:mm:ss") == 0) {
   sscanf(timestr,"%4d-%2d-%2dT%2d:%2d:%2d",&YYYY,&MM,&DD,&hh,&mm,&ss);
   utctm.tm_sec = ss;
   utctm.tm_min = mm;
   utctm.tm_hour = hh;
   utctm.tm_mday = DD;
   utctm.tm_mon = MM - 1;
   utctm.tm_year = YYYY - 1900;
   utc = mktime( &utctm );
   local = utc + deltasec;
   loctm = localtime( &local );
   strftime( timestr, 50, "%Y-%m-%dT%H:%M:%S", loctm );
 }
 else {
   printf("This date format is not supported.\n");
   return(99);
 }
 return(status);
}

variable_types:
timestr
char []

variable_types:
format
char []

variable_types: status int

variable_types: YYYY int

variable_types: MM int

variable_types: DD int

variable_types: hh int

variable_types: mm int

variable_types: ss int

variable_types: deltasec 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: utc long

variable_types: now long

variable_types: local long


delspace

decompiled_code:
size_t __fastcall delspace(char *s)
{
unsigned __int64 v1; // rbx
int v2; // er12
size_t result; // rax
char v4; // al

v1 = 0LL;
v2 = 0;
do
{
v4 = s[v1];
if ( v4 != 32 && v4 != 9 )
s[v2++] = v4;
++v1;
result = strlen(s) + 1;
}
while ( result > v1 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *s)
{
unsigned __int64 v1; // rbx
int v2; // er12
size_t result; // rax
char v4; // al

v1 = 0LL;
v2 = 0;
do
{
v4 = s[v1];
if ( v4 != 32 && v4 != 9 )
s[v2++] = v4;
++v1;
result = strlen(s) + 1;
}
while ( result > v1 );
return result;
}

original_code:
void delspace(char line[])
{
 int i,j;
 for (i=0,j=0; i<strlen(line)+1; i++) {
   if (((int)line[i] != 32) && ((int)line[i] != 9)) {line[j++] = line[i];}
 }
 return;
}

canonical_original_code:
void delspace(char line[])
{
 int i; int j;
 for (i=0,j=0; i<strlen(line)+1; i++) {
   if (((int)line[i] != 32) && ((int)line[i] != 9)) {line[j++] = line[i];}
 }
 return;
}

variable_types:
line
char []

variable_types: i int

variable_types: j int


cnvtimefmt

decompiled_code:
_BOOL8 __fastcall cnvtimefmt(char *s, const char *a2, const char *a3)
{
bool v4; // zf
_BOOL4 v5; // ebx
unsigned int v7; // [rsp+8h] [rbp-30h] BYREF
unsigned int v8; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v9; // [rsp+10h] [rbp-28h] BYREF
unsigned int v10; // [rsp+14h] [rbp-24h] BYREF
unsigned int v11; // [rsp+18h] [rbp-20h] BYREF
unsigned int v12; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( !strcmp(a2, "YYYY-MM-DDThh:mm:ss") )
{
_isoc99_sscanf(s, "%4d-%02d-%02dT%02d:%02d:%02d", &v12, &v11, &v10, &v9, &v8, &v7);
}
else
{
if ( strcmp(a2, "hh:mm:ss (DD/MM/YYYY)") )
{
printf("Error : Unknown time-date format - %s.\n", a2);
return 1;
}
_isoc99_sscanf(s, "%02d:%02d:%02d (%02d/%02d/%4d)", &v9, &v8, &v7, &v10, &v11, &v12);
}
v4 = strcmp(a3, "YYYY-MM-DDThh:mm:ss") == 0;
v5 = !v4;
if ( v4 )
{
sprintf(s, "%4d-%02d-%02dT%02d:%02d:%02d", v12, v11, v10, v9, v8, v7);
}
else
{
v4 = strcmp(a3, "hh:mm:ss (DD/MM/YYYY)") == 0;
v5 = !v4;
if ( v4 )
{
sprintf(s, "%02d:%02d:%02d (%02d/%02d/%4d)", v9, v8, v7, v10, v11, v12);
}
else
{
printf("Error : Unknown time-date format - %s.\n", a3);
v5 = 1;
}
}
return v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *s, const char *a2, const char *a3)
{
bool v4; // zf
_BOOL4 v5; // ebx
unsigned int v7; // [rsp+8h] [rbp-30h] BYREF
unsigned int v8; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v9; // [rsp+10h] [rbp-28h] BYREF
unsigned int v10; // [rsp+14h] [rbp-24h] BYREF
unsigned int v11; // [rsp+18h] [rbp-20h] BYREF
unsigned int v12; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( !strcmp(a2, "YYYY-MM-DDThh:mm:ss") )
{
_isoc99_sscanf(s, "%4d-%02d-%02dT%02d:%02d:%02d", &v12, &v11, &v10, &v9, &v8, &v7);
}
else
{
if ( strcmp(a2, "hh:mm:ss (DD/MM/YYYY)") )
{
printf("Error : Unknown time-date format - %s.\n", a2);
return 1;
}
_isoc99_sscanf(s, "%02d:%02d:%02d (%02d/%02d/%4d)", &v9, &v8, &v7, &v10, &v11, &v12);
}
v4 = strcmp(a3, "YYYY-MM-DDThh:mm:ss") == 0;
v5 = !v4;
if ( v4 )
{
sprintf(s, "%4d-%02d-%02dT%02d:%02d:%02d", v12, v11, v10, v9, v8, v7);
}
else
{
v4 = strcmp(a3, "hh:mm:ss (DD/MM/YYYY)") == 0;
v5 = !v4;
if ( v4 )
{
sprintf(s, "%02d:%02d:%02d (%02d/%02d/%4d)", v9, v8, v7, v10, v11, v12);
}
else
{
printf("Error : Unknown time-date format - %s.\n", a3);
v5 = 1;
}
}
return v5;
}

original_code:
int cnvtimefmt( char timestr[], char oldfmt[], char newfmt[] )
{
 int YYYY,MM,DD,hh,mm,ss;
 if (strcmp(oldfmt,"YYYY-MM-DDThh:mm:ss") == 0) {
   sscanf(timestr, "%4d-%02d-%02dT%02d:%02d:%02d", &YYYY,&MM,&DD,&hh,&mm,&ss);
 }
 else if (strcmp(oldfmt,"hh:mm:ss (DD/MM/YYYY)") == 0) {
   sscanf(timestr, "%02d:%02d:%02d (%02d/%02d/%4d)", &hh,&mm,&ss,&DD,&MM,&YYYY);
 }
 else {
   printf("Error : Unknown time-date format - %s.\n", oldfmt);
   return(1);
 }
 if (strcmp(newfmt,"YYYY-MM-DDThh:mm:ss") == 0) {
   sprintf(timestr, "%4d-%02d-%02dT%02d:%02d:%02d", YYYY,MM,DD,hh,mm,ss);
 }
 else if (strcmp(newfmt,"hh:mm:ss (DD/MM/YYYY)") == 0) {
   sprintf(timestr, "%02d:%02d:%02d (%02d/%02d/%4d)", hh,mm,ss,DD,MM,YYYY);
 }
 else {
   printf("Error : Unknown time-date format - %s.\n", newfmt);
   return(1);
 }
 return(0);
}

canonical_original_code:
int cnvtimefmt(char timestr[], char oldfmt[], char newfmt[])
{
 int YYYY; int MM; int DD; int hh; int mm; int ss;
 if (strcmp(oldfmt,"YYYY-MM-DDThh:mm:ss") == 0) {
   sscanf(timestr, "%4d-%02d-%02dT%02d:%02d:%02d", &YYYY,&MM,&DD,&hh,&mm,&ss);
 }
 else if (strcmp(oldfmt,"hh:mm:ss (DD/MM/YYYY)") == 0) {
   sscanf(timestr, "%02d:%02d:%02d (%02d/%02d/%4d)", &hh,&mm,&ss,&DD,&MM,&YYYY);
 }
 else {
   printf("Error : Unknown time-date format - %s.\n", oldfmt);
   return(1);
 }
 if (strcmp(newfmt,"YYYY-MM-DDThh:mm:ss") == 0) {
   sprintf(timestr, "%4d-%02d-%02dT%02d:%02d:%02d", YYYY,MM,DD,hh,mm,ss);
 }
 else if (strcmp(newfmt,"hh:mm:ss (DD/MM/YYYY)") == 0) {
   sprintf(timestr, "%02d:%02d:%02d (%02d/%02d/%4d)", hh,mm,ss,DD,MM,YYYY);
 }
 else {
   printf("Error : Unknown time-date format - %s.\n", newfmt);
   return(1);
 }
 return(0);
}

variable_types:
timestr
char []

variable_types:
oldfmt
char []

variable_types:
newfmt
char []


decompiled_code:
__int64 __fastcall img_or_value(char *s)
{
__int64 v1; // rbx

v1 = 0LL;
while ( !isalpha(s[v1]) )
{
if ( strlen(s) + 1 <= ++v1 )
return 2LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
__int64 v1; // rbx

v1 = 0LL;
while ( !isalpha(s[v1]) )
{
if ( strlen(s) + 1 <= ++v1 )
return 2LL;
}
return 1LL;
}

original_code:
int img_or_value(char string[])
{
 int i;
 for (i=0; i<strlen(string)+1; i++) {
   if ( isalpha(string[i]) ) { return(1); }
 }
 return(2);
}

variable_types:
string
char []


dfourn

original_code:
void dfourn(double data[], unsigned long nn[], int ndim, int isign)
{
 int idim;
 unsigned long i1,i2,i3,i2rev,i3rev,ip1,ip2,ip3,ifp1,ifp2;
 unsigned long ibit,k1,k2,n,nprev,nrem,ntot;
 double tempi,tempr;
 double theta,wi,wpi,wpr,wr,wtemp;
 for (ntot=1,idim=0;idim<ndim;idim++)
    ntot *= nn[idim];
 nprev=1;
 for (idim=ndim-1;idim>=0;idim--) {
    n=nn[idim];
    nrem=ntot/(n*nprev);
    ip1=nprev << 1;
    ip2=ip1*n;
    ip3=ip2*nrem;
    i2rev=0;
    for (i2=0;i2<ip2;i2+=ip1) {
       if (i2 < i2rev) {
          for (i1=i2;i1<=i2+ip1-2;i1+=2) {
      for (i3=i1;i3<ip3;i3+=ip2) {
         i3rev=i2rev+i3-i2;
  tempr=(data[i3]);(data[i3])=(data[i3rev]);(data[i3rev])=tempr;
  tempr=(data[i3+1]);(data[i3+1])=(data[i3rev+1]);(data[i3rev+1])=tempr;
      }
   }
       }
       ibit=ip2 >> 1;
       while (ibit >= ip1 && i2rev+1 > ibit) {
          i2rev -= ibit;
   ibit >>= 1;
       }
       i2rev += ibit;
    }
    ifp1=ip1;
    while (ifp1 < ip2) {
       ifp2=ifp1 << 1;
       theta=isign*6.28318530717959/(ifp2/ip1);
       wtemp=sin(0.5*theta);
       wpr = -2.0*wtemp*wtemp;
       wpi=sin(theta);
       wr=1.0;
       wi=0.0;
       for (i3=0;i3<ifp1;i3+=ip1) {
          for (i1=i3;i1<=i3+ip1-2;i1+=2) {
      for (i2=i1;i2<ip3;i2+=ifp2) {
         k1=i2;
  k2=k1+ifp1;
  tempr=(double)wr*data[k2]-(double)wi*data[k2+1];
  tempi=(double)wr*data[k2+1]+(double)wi*data[k2];
  data[k2]=data[k1]-tempr;
  data[k2+1]=data[k1+1]-tempi;
  data[k1] += tempr;
  data[k1+1] += tempi;
      }
   }
   wr=(wtemp=wr)*wpr-wi*wpi+wr;
   wi=wi*wpr+wtemp*wpi+wi;
       }
       ifp1=ifp2;
    }
    nprev *= n;
 }
}

canonical_original_code:
void dfourn(double data[], unsigned long nn[], int ndim, int isign)
{
 int idim;
 unsigned long i1; unsigned long i2; unsigned long i3; unsigned long i2rev; unsigned long i3rev; unsigned long ip1; unsigned long ip2; unsigned long ip3; unsigned long ifp1; unsigned long ifp2;
 unsigned long ibit; unsigned long k1; unsigned long k2; unsigned long n; unsigned long nprev; unsigned long nrem; unsigned long ntot;
 double tempi; double tempr;
 double theta; double wi; double wpi; double wpr; double wr; double wtemp;
 for (ntot=1,idim=0;idim<ndim;idim++)
    ntot *= nn[idim];
 nprev=1;
 for (idim=ndim-1;idim>=0;idim--) {
    n=nn[idim];
    nrem=ntot/(n*nprev);
    ip1=nprev << 1;
    ip2=ip1*n;
    ip3=ip2*nrem;
    i2rev=0;
    for (i2=0;i2<ip2;i2+=ip1) {
       if (i2 < i2rev) {
          for (i1=i2;i1<=i2+ip1-2;i1+=2) {
      for (i3=i1;i3<ip3;i3+=ip2) {
         i3rev=i2rev+i3-i2;
  tempr=(data[i3]);(data[i3])=(data[i3rev]);(data[i3rev])=tempr;
  tempr=(data[i3+1]);(data[i3+1])=(data[i3rev+1]);(data[i3rev+1])=tempr;
      }
   }
       }
       ibit=ip2 >> 1;
       while (ibit >= ip1 && i2rev+1 > ibit) {
          i2rev -= ibit;
   ibit >>= 1;
       }
       i2rev += ibit;
    }
    ifp1=ip1;
    while (ifp1 < ip2) {
       ifp2=ifp1 << 1;
       theta=isign*6.28318530717959/(ifp2/ip1);
       wtemp=sin(0.5*theta);
       wpr = -2.0*wtemp*wtemp;
       wpi=sin(theta);
       wr=1.0;
       wi=0.0;
       for (i3=0;i3<ifp1;i3+=ip1) {
          for (i1=i3;i1<=i3+ip1-2;i1+=2) {
      for (i2=i1;i2<ip3;i2+=ifp2) {
         k1=i2;
  k2=k1+ifp1;
  tempr=(double)wr*data[k2]-(double)wi*data[k2+1];
  tempi=(double)wr*data[k2+1]+(double)wi*data[k2];
  data[k2]=data[k1]-tempr;
  data[k2+1]=data[k1+1]-tempi;
  data[k1] += tempr;
  data[k1+1] += tempi;
      }
   }
   wr=(wtemp=wr)*wpr-wi*wpi+wr;
   wi=wi*wpr+wtemp*wpi+wi;
       }
       ifp1=ifp2;
    }
    nprev *= n;
 }
}

variable_types:
data
double []

variable_types:
nn
unsigned long []

variable_types: ndim int

variable_types: isign int

variable_types: idim int

variable_types:
ibit
unsigned long

variable_types:
n
unsigned long

variable_types:
nprev
unsigned long

variable_types:
nrem
unsigned long

variable_types:
ntot
unsigned long

variable_types: tempi double

variable_types: tempr double

variable_types: theta double

variable_types: wi double

variable_types: wpi double

variable_types: wpr double

variable_types: wr double

variable_types: wtemp double


gammln

variable_types: xx float

variable_types: x double

variable_types: y double

variable_types: tmp double

variable_types: ser double

variable_types:
cof
double [6]

variable_types: j int


repo: KelvinL/disttasks

decompiled_code:
int __fastcall watcher_fn_create_taskroot(unsigned int a1, const char *a2, const char *a3)
{
int result; // eax

if ( !a3 )
a3 = "null";
result = fprintf(stderr, "[%s]: rc = %d\n", a3, a1);
if ( !a1 )
result = fprintf(stderr, "\tname = %s\n", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, const char *a2, const char *a3)
{
int result; // eax

if ( !a3 )
a3 = "null";
result = fprintf(stderr, "[%s]: rc = %d\n", a3, a1);
if ( !a1 )
result = fprintf(stderr, "\tname = %s\n", a2);
return result;
}

original_code:
void watcher_fn_create_taskroot(int rc, const char* name, const void* data)
{
 fprintf(stderr, "[%s]: rc = %d\n", (char*)(data==0?"null":data), rc);
 if (!rc) {
  fprintf(stderr, "\tname = %s\n", name);
 }
}

canonical_original_code:
void watcher_fn_create_taskroot(int rc, char *name, void *data)
{
 fprintf(stderr, "[%s]: rc = %d\n", (char *)(data==0?"null":data), rc);
 if (!rc) {
  fprintf(stderr, "\tname = %s\n", name);
 }
}

variable_types: rc int

variable_types:
name
char *

variable_types:
data
void *


decompiled_code:
int __fastcall watcher_fn_create_child(unsigned int a1, const char *a2, const char *a3)
{
int result; // eax

if ( !a3 )
a3 = "null";
result = fprintf(stderr, "[%s]: rc = %d\n", a3, a1);
if ( !a1 )
{
fprintf(stderr, "\tname = %s\n", a2);
strcpy(childnode_fullname, a2);
result = fprintf(stderr, "\tname = %s\n", childnode_fullname);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, const char *a2, const char *a3)
{
int result; // eax

if ( !a3 )
a3 = "null";
result = fprintf(stderr, "[%s]: rc = %d\n", a3, a1);
if ( !a1 )
{
fprintf(stderr, "\tname = %s\n", a2);
strcpy(childnode_fullname, a2);
result = fprintf(stderr, "\tname = %s\n", childnode_fullname);
}
return result;
}

original_code:
void watcher_fn_create_child(int rc, const char* name, const void* data)
{
 fprintf(stderr, "[%s]: rc = %d\n", (char*)(data==0?"null":data), rc);
 if (!rc) {
  fprintf(stderr, "\tname = %s\n", name);
  strcpy(childnode_fullname, name);
  fprintf(stderr, "\tname = %s\n", childnode_fullname);
 }
}

canonical_original_code:
void watcher_fn_create_child(int rc, char *name, void *data)
{
 fprintf(stderr, "[%s]: rc = %d\n", (char *)(data==0?"null":data), rc);
 if (!rc) {
  fprintf(stderr, "\tname = %s\n", name);
  strcpy(childnode_fullname, name);
  fprintf(stderr, "\tname = %s\n", childnode_fullname);
 }
}


decompiled_code:
int __fastcall completion_fn_enter(__int64 a1, unsigned int *a2)
{
__int64 v2; // rbx
_DWORD *v3; // rax

printf("completion_fn_enter count: %d\n", *a2);
v2 = 0LL;
if ( (int)*a2 <= 2 )
{
puts("completion_fn_enter set watcher");
LODWORD(v3) = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode, 0LL, 0LL);
if ( (_DWORD)v3 )
LODWORD(v3) = puts("completion_fn_enter set watcher error");
}
else
{
do
printf("completion_fn_enter node: %s\n", *(const char **)(*((_QWORD *)a2 + 1) + 8 * v2++));
while ( (int)*a2 > (int)v2 );
v3 = g_enterFlag;
g_enterFlag[0] = 0;
}
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, unsigned int *a2)
{
__int64 v2; // rbx
_DWORD *v3; // rax

printf("completion_fn_enter count: %d\n", *a2);
v2 = 0LL;
if ( (int)*a2 <= 2 )
{
puts("completion_fn_enter set watcher");
LODWORD(v3) = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode, 0LL, 0LL);
if ( (_DWORD)v3 )
LODWORD(v3) = puts("completion_fn_enter set watcher error");
}
else
{
do
printf("completion_fn_enter node: %s\n", *(const char **)(*((_QWORD *)a2 + 1) + 8 * v2++));
while ( (int)*a2 > (int)v2 );
v3 = g_enterFlag;
g_enterFlag[0] = 0;
}
return (int)v3;
}

original_code:
void completion_fn_enter(int rc, const struct String_vector *strings, const void* data)
{
 int ret = 0;
 int i = 0;
 struct String_vector *strNew;
 printf("completion_fn_enter count: %d\n", strings->count);
 if(strings->count < 3)
 {
  printf("completion_fn_enter set watcher\n");
  ret = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode, ((void *)0), strNew);
  if(ret != ZOK)
  {
   printf("completion_fn_enter set watcher error\n");
  }
 }
 else
 {
  for(i = 0; i < strings->count; i++)
  {
   printf("completion_fn_enter node: %s\n", strings->data[i]);
  }
  g_enterFlag = 0;
 }
}

canonical_original_code:
void completion_fn_enter(int rc, struct String_vector *strings, void *data)
{
 int ret = 0;
 int i = 0;
 struct String_vector *strNew;
 printf("completion_fn_enter count: %d\n", strings->count);
 if(strings->count < 3)
 {
  printf("completion_fn_enter set watcher\n");
  ret = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode, ((void *)0), strNew);
  if(ret != ZOK)
  {
   printf("completion_fn_enter set watcher error\n");
  }
 }
 else
 {
  for(i = 0; i < strings->count; i++)
  {
   printf("completion_fn_enter node: %s\n", strings->data[i]);
  }
  g_enterFlag = 0;
 }
}

variable_types: struct String_vector { int count; char **data; } *

variable_types: ret int

variable_types: i int


decompiled_code:
int __fastcall completion_fn_leave(__int64 a1, unsigned int *a2)
{
_DWORD *v2; // rax

printf("completion_fn_leave count: %d\n", *a2);
if ( (int)*a2 > 0 )
{
LODWORD(v2) = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode_leave, 0LL, 0LL);
if ( (_DWORD)v2 )
LODWORD(v2) = puts("completion_fn_leave set watcher error");
}
else
{
v2 = &g_leaveFlag;
g_leaveFlag = 0;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, unsigned int *a2)
{
_DWORD *v2; // rax

printf("completion_fn_leave count: %d\n", *a2);
if ( (int)*a2 > 0 )
{
LODWORD(v2) = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode_leave, 0LL, 0LL);
if ( (_DWORD)v2 )
LODWORD(v2) = puts("completion_fn_leave set watcher error");
}
else
{
v2 = &g_leaveFlag;
g_leaveFlag = 0;
}
return (int)v2;
}

original_code:
void completion_fn_leave(int rc, const struct String_vector *strings, const void* data)
{
 int ret = 0;
 struct String_vector *strNew;
 printf("completion_fn_leave count: %d\n", strings->count);
 if(strings->count > 0)
 {
  ret = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode_leave, ((void *)0), strNew);
  if(ret != ZOK)
  {
   printf("completion_fn_leave set watcher error\n");
  }
 }
 else
 {
  g_leaveFlag = 0;
 }
}

canonical_original_code:
void completion_fn_leave(int rc, struct String_vector *strings, void *data)
{
 int ret = 0;
 struct String_vector *strNew;
 printf("completion_fn_leave count: %d\n", strings->count);
 if(strings->count > 0)
 {
  ret = zoo_wget_children(g_zhdl, g_root, watcher_fn_znode_leave, ((void *)0), strNew);
  if(ret != ZOK)
  {
   printf("completion_fn_leave set watcher error\n");
  }
 }
 else
 {
  g_leaveFlag = 0;
 }
}

user_defined_types: struct String_vector { int count; char **data; }


decompiled_code:
__int64 __fastcall create_root(const char *a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
size_t v5; // rax
__int64 v6; // [rsp+0h] [rbp-68h] BYREF

v2 = zoo_exists(g_zhdl, a1, 1LL, &v6);
v3 = v2;
if ( v2 )
{
if ( v2 == -101 )
{
v5 = strlen(a2);
v3 = zoo_acreate(g_zhdl, a1, a2, v5, &ZOO_OPEN_ACL_UNSAFE, 0LL, watcher_fn_create_root, "root node create");
if ( v3 )
printf("create_root %s error", a1);
}
else
{
puts("create_root error");
}
}
else
{
printf("create_root %s already create\n", a1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
size_t v5; // rax
__int64 v6; // [rsp+0h] [rbp-68h] BYREF

v2 = zoo_exists(g_zhdl, a1, 1LL, &v6);
v3 = v2;
if ( v2 )
{
if ( v2 == -101 )
{
v5 = strlen(a2);
v3 = zoo_acreate(g_zhdl, a1, a2, v5, &ZOO_OPEN_ACL_UNSAFE, 0LL, watcher_fn_create_root, "root node create");
if ( v3 )
printf("create_root %s error", a1);
}
else
{
puts("create_root error");
}
}
else
{
printf("create_root %s already create\n", a1);
}
return v3;
}

original_code:
int create_root(const char* node_name, const char* data)
{
 int ret = 0;
 struct Stat stat;
 ret = zoo_exists(g_zhdl, node_name, 1, &stat);
 if(ret == ZOK)
 {
  printf("create_root %s already create\n", node_name);
 }
 else if(ret == ZNONODE)
 {
  ret = zoo_acreate(g_zhdl, node_name, data, strlen(data),
   &ZOO_OPEN_ACL_UNSAFE, 0, watcher_fn_create_root, "root node create");
  if(ret)
  {
   printf("create_root %s error", node_name);
  }
 }
 else
 {
  printf("create_root error\n");
 }
 return ret;
}

canonical_original_code:
int create_root(char *node_name, char *data)
{
 int ret = 0;
 struct Stat stat;
 ret = zoo_exists(g_zhdl, node_name, 1, &stat);
 if(ret == ZOK)
 {
  printf("create_root %s already create\n", node_name);
 }
 else if(ret == ZNONODE)
 {
  ret = zoo_acreate(g_zhdl, node_name, data, strlen(data),
   &ZOO_OPEN_ACL_UNSAFE, 0, watcher_fn_create_root, "root node create");
  if(ret)
  {
   printf("create_root %s error", node_name);
  }
 }
 else
 {
  printf("create_root error\n");
 }
 return ret;
}

variable_types:
data
char *

variable_types: struct Stat { long czxid; long mzxid; long ctime; long mtime; int version; int cversion; int aversion; long ephemeralOwner; int dataLength; int numChildren; long pzxid; }


enter

decompiled_code:
__int64 enter()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v3[17]; // [rsp+0h] [rbp-88h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
v3[4] = 0LL;
v3[5] = 0LL;
v3[6] = 0LL;
v3[7] = 0LL;
v3[8] = 0LL;
v3[9] = 0LL;
v3[10] = 0LL;
v3[11] = 0LL;
v3[12] = 0LL;
v3[13] = 0LL;
v3[14] = 0LL;
v3[15] = 0LL;
sprintf((char *)v3, "%s/hello", g_root);
v0 = zoo_acreate(
g_zhdl,
v3,
"child",
5LL,
&ZOO_OPEN_ACL_UNSAFE,
(unsigned int)(ZOO_SEQUENCE | ZOO_EPHEMERAL),
watcher_fn_create_child,
"child node create");
if ( v0 )
{
v1 = v0;
printf("enter create child node %s error", (const char *)v3);
}
else
{
g_enterFlag[0] = 1;
v1 = zoo_aget_children(g_zhdl, g_root, 0LL, completion_fn_enter, "root child node");
if ( v1 )
{
v1 = -1;
}
else
{
while ( g_enterFlag[0] == 1 )
usleep(0xAu);
puts("enter finish");
}
}
return v1;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v3[17]; // [rsp+0h] [rbp-88h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
v3[4] = 0LL;
v3[5] = 0LL;
v3[6] = 0LL;
v3[7] = 0LL;
v3[8] = 0LL;
v3[9] = 0LL;
v3[10] = 0LL;
v3[11] = 0LL;
v3[12] = 0LL;
v3[13] = 0LL;
v3[14] = 0LL;
v3[15] = 0LL;
sprintf((char *)v3, "%s/hello", g_root);
v0 = zoo_acreate(
g_zhdl,
v3,
"child",
5LL,
&ZOO_OPEN_ACL_UNSAFE,
(unsigned int)(ZOO_SEQUENCE | ZOO_EPHEMERAL),
watcher_fn_create_child,
"child node create");
if ( v0 )
{
v1 = v0;
printf("enter create child node %s error", (const char *)v3);
}
else
{
g_enterFlag[0] = 1;
v1 = zoo_aget_children(g_zhdl, g_root, 0LL, completion_fn_enter, "root child node");
if ( v1 )
{
v1 = -1;
}
else
{
while ( g_enterFlag[0] == 1 )
usleep(0xAu);
puts("enter finish");
}
}
return v1;
}

original_code:
int enter()
{
 int ret = 0;
 char childNode[128] = {0};
 struct String_vector *strings;
 sprintf(childNode, "%s/hello", g_root);
 ret = zoo_acreate(g_zhdl, childNode, "child", strlen("child"),
  &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL|ZOO_SEQUENCE, watcher_fn_create_child,
  "child node create");
 if(ret)
 {
  printf("enter create child node %s error", childNode);
  return ret;
 }
 g_enterFlag = 1;
 ret = zoo_aget_children(g_zhdl, g_root, 0, completion_fn_enter, "root child node");
 if(ret != ZOK)
 {
  return -1;
 }
 while(g_enterFlag == 1)
 {
  usleep(10);
 }
 printf("enter finish\n");
 return ret;
}

variable_types:
childNode
char [128]


leave

decompiled_code:
__int64 leave()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = zoo_delete(g_zhdl, childnode_fullname, 0xFFFFFFFFLL);
if ( v0 )
{
v1 = v0;
printf("leave delete child node %s error\n", childnode_fullname);
}
else
{
g_leaveFlag = 1;
v1 = zoo_aget_children(g_zhdl, g_root, 0LL, completion_fn_leave, "root child node");
while ( g_leaveFlag == 1 )
usleep(0xAu);
}
return v1;
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = zoo_delete(g_zhdl, childnode_fullname, 0xFFFFFFFFLL);
if ( v0 )
{
v1 = v0;
printf("leave delete child node %s error\n", childnode_fullname);
}
else
{
g_leaveFlag = 1;
v1 = zoo_aget_children(g_zhdl, g_root, 0LL, completion_fn_leave, "root child node");
while ( g_leaveFlag == 1 )
usleep(0xAu);
}
return v1;
}

original_code:
int leave()
{
 int ret = 0;
 ret = zoo_delete(g_zhdl, childnode_fullname, -1);
 if(ret)
 {
  printf("leave delete child node %s error\n", childnode_fullname);
  return ret;
 }
 g_leaveFlag = 1;
 ret = zoo_aget_children(g_zhdl, g_root, 0, completion_fn_leave, "root child node");
 while(g_leaveFlag == 1)
 {
  usleep(10);
 }
 return ret;
}


decompiled_code:
__int64 __fastcall create_ephemeral_node(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebx
int v7; // [rsp+Ch] [rbp-6Ch] BYREF
char v8[104]; // [rsp+10h] [rbp-68h] BYREF

v7 = 4096;
v3 = zoo_create(g_zhdl, a1, a2, a3, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, 0LL, 0LL);
if ( v3 )
{
v5 = v3;
puts("create_ephemeral_node error");
}
else
{
v4 = zoo_wget(g_zhdl, a1, watcher_fn_znode, 0LL, g_pBuffer, &v7, v8);
v5 = v4;
if ( v4 )
printf("wget error: %d\n", v4);
printf("create_ephemeral_node data: %s\n", g_pBuffer);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebx
int v7; // [rsp+Ch] [rbp-6Ch] BYREF
char v8[104]; // [rsp+10h] [rbp-68h] BYREF

v7 = 4096;
v3 = zoo_create(g_zhdl, a1, a2, a3, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, 0LL, 0LL);
if ( v3 )
{
v5 = v3;
puts("create_ephemeral_node error");
}
else
{
v4 = zoo_wget(g_zhdl, a1, watcher_fn_znode, 0LL, g_pBuffer, &v7, v8);
v5 = v4;
if ( v4 )
printf("wget error: %d\n", v4);
printf("create_ephemeral_node data: %s\n", g_pBuffer);
}
return v5;
}

original_code:
int create_ephemeral_node(const char* pNodePath, const char* pData, int nDataLen)
{
 int ret = 0;
 struct Stat MyStat;
 int bufLen = 4*1024;
 ret = zoo_create(g_zhdl, pNodePath, pData, nDataLen, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, ((void *)0), 0);
 if(ret)
 {
  printf("create_ephemeral_node error\n");
  return ret;
 }
 ret = zoo_wget(g_zhdl, pNodePath, watcher_fn_znode, ((void *)0), g_pBuffer, &bufLen, &MyStat);
 if(ret)
 {
  printf("wget error: %d\n", ret);
 }
 printf("create_ephemeral_node data: %s\n", g_pBuffer);
 return ret;
}

canonical_original_code:
int create_ephemeral_node(char *pNodePath, char *pData, int nDataLen)
{
 int ret = 0;
 struct Stat MyStat;
 int bufLen = 4*1024;
 ret = zoo_create(g_zhdl, pNodePath, pData, nDataLen, &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, ((void *)0), 0);
 if(ret)
 {
  printf("create_ephemeral_node error\n");
  return ret;
 }
 ret = zoo_wget(g_zhdl, pNodePath, watcher_fn_znode, ((void *)0), g_pBuffer, &bufLen, &MyStat);
 if(ret)
 {
  printf("wget error: %d\n", ret);
 }
 printf("create_ephemeral_node data: %s\n", g_pBuffer);
 return ret;
}

variable_types:
pNodePath
char *

variable_types:
pData
char *

variable_types: nDataLen int

variable_types: bufLen int

user_defined_types: struct Stat { long czxid; long mzxid; long ctime; long mtime; int version; int cversion; int aversion; long ephemeralOwner; int dataLength; int numChildren; long pzxid; }


decompiled_code:
__int64 fini_zkhandle()
{
zookeeper_close(g_zhdl);
g_zhdl = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
zookeeper_close(g_zhdl);
g_zhdl = 0LL;
return 0LL;
}

original_code:
int fini_zkhandle()
{
 int ret = 0;
 zookeeper_close(g_zhdl);
 g_zhdl = ((void *)0);
 return ret;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
size_t v4; // rax
int v5; // ebx
char v7; // al

v3 = (char *)malloc(0x1000uLL);
g_pBuffer = v3;
v4 = strlen(v3);
memset(v3, 0, v4);
v5 = init_zkhandle((__int64)"127.0.0.1:2181", 0x7530u, (__int64)watcher_fn_g, (__int64)"ConfigMgr");
while ( 1 )
{
v7 = getchar();
if ( v7 == 99 )
break;
switch ( v7 )
{
case 'q':
fini_zkhandle();
return v5;
case 'r':
v5 = init_zkhandle((__int64)"127.0.0.1:2181", 0x7530u, (__int64)watcher_fn_g, (__int64)"ConfigMgr");
break;
case 'n':
create_ephemeral_node((__int64)"/ConfigMgr", (__int64)"CMS:10.82.13.107", 0x11u);
break;
}
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
size_t v4; // rax
int v5; // ebx
char v7; // al

v3 = (char *)malloc(0x1000uLL);
g_pBuffer = v3;
v4 = strlen(v3);
memset(v3, 0, v4);
v5 = func2((__int64)"127.0.0.1:2181", 0x7530u, (__int64)watcher_fn_g, (__int64)"ConfigMgr");
while ( 1 )
{
v7 = getchar();
if ( v7 == 99 )
break;
switch ( v7 )
{
case 'q':
func3();
return v5;
case 'r':
v5 = func2((__int64)"127.0.0.1:2181", 0x7530u, (__int64)watcher_fn_g, (__int64)"ConfigMgr");
break;
case 'n':
func4((__int64)"/ConfigMgr", (__int64)"CMS:10.82.13.107", 0x11u);
break;
}
}
return v5;
}

original_code:
int main(int argc, char* argv[])
{
 int ret = 0;
 const char* host = "127.0.0.1:2181";
 int timeout = 30000;
 char c = '0';
 g_pBuffer = malloc(1024*4);
 memset(g_pBuffer, 0x0, strlen(g_pBuffer));
 ret = init_zkhandle(host, timeout, watcher_fn_g, "ConfigMgr");
 while(1)
 {
  c = getchar();
  if(c == 'c')
  {
   break;
  }
  else if(c == 'q')
  {
   fini_zkhandle();
   break;
  }
  else if(c == 'r')
  {
   ret = init_zkhandle(host, timeout, watcher_fn_g, "ConfigMgr");
  }
  else if(c == 'n')
  {
   create_ephemeral_node("/ConfigMgr", "CMS:10.82.13.107", sizeof("CMS:10.82.13.107"));
  }
 }
 return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret = 0;
 char *host = "127.0.0.1:2181";
 int timeout = 30000;
 char c = '0';
 g_pBuffer = malloc(1024*4);
 memset(g_pBuffer, 0x0, strlen(g_pBuffer));
 ret = init_zkhandle(host, timeout, watcher_fn_g, "ConfigMgr");
 while(1)
 {
  c = getchar();
  if(c == 'c')
  {
   break;
  }
  else if(c == 'q')
  {
   fini_zkhandle();
   break;
  }
  else if(c == 'r')
  {
   ret = init_zkhandle(host, timeout, watcher_fn_g, "ConfigMgr");
  }
  else if(c == 'n')
  {
   create_ephemeral_node("/ConfigMgr", "CMS:10.82.13.107", sizeof("CMS:10.82.13.107"));
  }
 }
 return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
host
char *

variable_types: timeout int

variable_types: c char


canonical_decompiled_code:
int __fastcall func1(unsigned int a1, const char *a2, const char *a3)
{
int result; // eax

if ( !a3 )
a3 = "null";
result = fprintf(stderr, "[%s]: rc = %d\n", a3, a1);
if ( !a1 )
result = fprintf(stderr, "\tname = %s\n", a2);
return result;
}

variable_types: rc int

variable_types:
name
char *


decompiled_code:
__int64 __fastcall completion_fn_aget(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4[17]; // [rsp+0h] [rbp-88h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
v4[8] = 0LL;
v4[9] = 0LL;
v4[10] = 0LL;
v4[11] = 0LL;
v4[12] = 0LL;
v4[13] = 0LL;
v4[14] = 0LL;
v4[15] = 0LL;
if ( *(int *)a2 <= 0 )
{
usleep(0x2710u);
result = zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}
else
{
sprintf((char *)v4, "%s/%s", g_tasksRoot, **(const char ***)(a2 + 8));
v2 = zoo_delete(g_zhdl, v4, 0xFFFFFFFFLL);
if ( v2 )
{
if ( v2 == -101 )
printf("completion_fn_aget node %s already delete\n", (const char *)v4);
result = zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}
else
{
printf("completion_fn_aget node %s delete successfully\n", (const char *)v4);
result = zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4[17]; // [rsp+0h] [rbp-88h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
v4[8] = 0LL;
v4[9] = 0LL;
v4[10] = 0LL;
v4[11] = 0LL;
v4[12] = 0LL;
v4[13] = 0LL;
v4[14] = 0LL;
v4[15] = 0LL;
if ( *(int *)a2 <= 0 )
{
usleep(0x2710u);
result = zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}
else
{
sprintf((char *)v4, "%s/%s", g_tasksRoot, **(const char ***)(a2 + 8));
v2 = zoo_delete(g_zhdl, v4, 0xFFFFFFFFLL);
if ( v2 )
{
if ( v2 == -101 )
printf("completion_fn_aget node %s already delete\n", (const char *)v4);
result = zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}
else
{
printf("completion_fn_aget node %s delete successfully\n", (const char *)v4);
result = zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}
}
return result;
}

original_code:
void completion_fn_aget(int rc, const struct String_vector *strings, const void* data)
{
 int ret = 0;
 int i = 0;
 char children[128] = {0};
 if(strings->count > 0)
 {
  sprintf(children, "%s/%s", g_tasksRoot, strings->data[0]);
  ret = zoo_delete(g_zhdl, children, -1);
  if(ret)
  {
   if(ret == ZNONODE)
   {
    printf("completion_fn_aget node %s already delete\n", children);
   }
   ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
  }
  else
  {
   printf("completion_fn_aget node %s delete successfully\n", children);
   ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
  }
 }
 else
 {
  usleep(10000);
  ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
 }
}

canonical_original_code:
void completion_fn_aget(int rc, struct String_vector *strings, void *data)
{
 int ret = 0;
 int i = 0;
 char children[128] = {0};
 if(strings->count > 0)
 {
  sprintf(children, "%s/%s", g_tasksRoot, strings->data[0]);
  ret = zoo_delete(g_zhdl, children, -1);
  if(ret)
  {
   if(ret == ZNONODE)
   {
    printf("completion_fn_aget node %s already delete\n", children);
   }
   ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
  }
  else
  {
   printf("completion_fn_aget node %s delete successfully\n", children);
   ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
  }
 }
 else
 {
  usleep(10000);
  ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
 }
}

variable_types: struct String_vector { int count; char **data; } *

variable_types:
data
void *

variable_types:
children
char [128]


agetChildren

decompiled_code:
__int64 agetChildren()
{
return zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}

canonical_decompiled_code:
__int64 func6()
{
return zoo_aget_children(g_zhdl, g_tasksRoot, 0LL, completion_fn_aget, "root child node");
}

original_code:
int agetChildren()
{
 int ret = 0;
 ret = zoo_aget_children(g_zhdl, g_tasksRoot, 0, completion_fn_aget, "root child node");
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 create_tasks()
{
unsigned int v0; // ebp
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 v4[19]; // [rsp+0h] [rbp-98h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
v4[8] = 0LL;
v4[9] = 0LL;
v4[10] = 0LL;
v4[11] = 0LL;
v4[12] = 0LL;
v4[13] = 0LL;
v4[14] = 0LL;
v4[15] = 0LL;
sprintf((char *)v4, "%s/Task", tasksRoot);
v0 = ZOO_SEQUENCE;
v1 = zoo_create(g_zhdl, v4, "Task1", 5LL, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0LL, 0LL);
if ( v1 )
{
v2 = v1;
puts("create_tasks create error");
}
else
{
v2 = zoo_create(g_zhdl, v4, "Task2", 5LL, &ZOO_OPEN_ACL_UNSAFE, v0, 0LL, 0LL);
if ( v2 )
puts("create_tasks create error");
}
return v2;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebp
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 v4[19]; // [rsp+0h] [rbp-98h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
v4[8] = 0LL;
v4[9] = 0LL;
v4[10] = 0LL;
v4[11] = 0LL;
v4[12] = 0LL;
v4[13] = 0LL;
v4[14] = 0LL;
v4[15] = 0LL;
sprintf((char *)v4, "%s/Task", tasksRoot);
v0 = ZOO_SEQUENCE;
v1 = zoo_create(g_zhdl, v4, "Task1", 5LL, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0LL, 0LL);
if ( v1 )
{
v2 = v1;
puts("create_tasks create error");
}
else
{
v2 = zoo_create(g_zhdl, v4, "Task2", 5LL, &ZOO_OPEN_ACL_UNSAFE, v0, 0LL, 0LL);
if ( v2 )
puts("create_tasks create error");
}
return v2;
}

original_code:
int create_tasks()
{
 int ret = 0;
 char tasksNode[128] = {0};
 sprintf(tasksNode, "%s/Task", tasksRoot);
 ret = zoo_create(g_zhdl, tasksNode, "Task1", strlen("Task1"), &ZOO_OPEN_ACL_UNSAFE,
  ZOO_SEQUENCE, ((void *)0), 0);
 if(ret)
 {
  printf("create_tasks create error\n");
  return ret;
 }
 ret = zoo_create(g_zhdl, tasksNode, "Task2", strlen("Task2"), &ZOO_OPEN_ACL_UNSAFE,
  ZOO_SEQUENCE, ((void *)0), 0);
 if(ret)
 {
  printf("create_tasks create error\n");
  return ret;
 }
 return ret;
}

variable_types:
tasksNode
char [128]


repo: KelvinLi/C-tutorial

decompiled_code:
__int64 __fastcall count_dozens(int a1)
{
return (unsigned int)((a1 - 1) / 12 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)((a1 - 1) / 12 + 1);
}

original_code:
int
count_dozens (egg_count c)
{
    return (c - 1) / 12 + 1;
}

canonical_original_code:
int count_dozens(int c)
{
    return (c - 1) / 12 + 1;
}

variable_types: c int


decompiled_code:
__int64 __fastcall count_weird(int a1)
{
return (unsigned int)((3 - a1) * (3 - a1));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)((3 - a1) * (3 - a1));
}

original_code:
int
count_weird (egg_count c)
{
    return (3 - c) * (3 - c);
}

canonical_original_code:
int count_weird(int c)
{
    return (3 - c) * (3 - c);
}


decompiled_code:
int __fastcall display_veggie(unsigned int *a1, __int64 (__fastcall *a2)(_QWORD))
{
unsigned int v2; // eax

v2 = a2(*a1);
return printf("Got %d groups\n", v2);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1, __int64 (__fastcall *a2)(_QWORD))
{
unsigned int v2; // eax

v2 = a2(*a1);
return printf("Got %d groups\n", v2);
}

original_code:
void
display_veggie (veggie *v, count_fn f)
{
    printf ("Got %d groups\n", f (v->eggs));
}

canonical_original_code:
void display_veggie(struct tomato *v, int (*f)(int))
{
    printf ("Got %d groups\n", f (v->eggs));
}

variable_types:
v
struct tomato { int eggs; } *

variable_types:
f
int (*)(int)


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 85;
display_veggie(v4, (__int64 (__fastcall *)(_QWORD))count_dozens);
display_veggie(v4, (__int64 (__fastcall *)(_QWORD))count_weird);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 85;
func9(v4, (__int64 (__fastcall *)(_QWORD))count_dozens);
func9(v4, (__int64 (__fastcall *)(_QWORD))count_weird);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
    veggie tom;
    tom.eggs = 85;
    display_veggie (&tom, count_dozens);
    display_veggie (&tom, count_weird);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct tomato tom;
    tom.eggs = 85;
    display_veggie (&tom, count_dozens);
    display_veggie (&tom, count_weird);
    return 0;
}

variable_types:
argv
char **

variable_types:
tom
struct tomato { int eggs; }


decompiled_code:
int __fastcall tomato_print(const char *a1)
{
return printf("%s tomato with %d spots", a1 + 4, *(unsigned int *)a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("%s tomato with %d spots", a1 + 4, *(unsigned int *)a1);
}

original_code:
int
tomato_print (struct tomato *t)
{
    return printf("%s tomato with %d spots", t->name, t->spots);
}

canonical_original_code:
int tomato_print(struct tomato *t)
{
    return printf("%s tomato with %d spots", t->name, t->spots);
}

variable_types: struct tomato { int spots; char name[10]; } *


fry

decompiled_code:
int __fastcall fry(int a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]

v4 = a2;
LODWORD(v3) = a1 + 100;
HIDWORD(v3) = 1162433094;
LOWORD(v4) = 68;
fwrite("mutated by fry(): ", 1uLL, 0x12uLL, _bss_start);
tomato_print((const char *)&v3);
return fputc(10, _bss_start);
}

canonical_decompiled_code:
int __fastcall func8(int a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]

v4 = a2;
LODWORD(v3) = a1 + 100;
HIDWORD(v3) = 1162433094;
LOWORD(v4) = 68;
fwrite("mutated by fry(): ", 1uLL, 0x12uLL, _bss_start);
func7((const char *)&v3);
return fputc(10, _bss_start);
}

original_code:
void
fry (struct tomato t)
{
    const char fried_name[] = "FRIED";
    t.spots = t.spots + 100;
    memcpy (t.name, fried_name, sizeof (fried_name) / sizeof (*fried_name));
    fputs ("mutated by fry(): ", stdout);
    tomato_print (&t);
    fputs ("\n", stdout);
}

canonical_original_code:
void fry(struct tomato t)
{
    char fried_name[] = "FRIED";
    t.spots = t.spots + 100;
    memcpy (t.name, fried_name, sizeof (fried_name) / sizeof (*fried_name));
    fputs ("mutated by fry(): ", stdout);
    tomato_print (&t);
    fputs ("\n", stdout);
}

variable_types: struct tomato { int spots; char name[10]; }


boil

decompiled_code:
int __fastcall boil(__int64 a1)
{
*(_DWORD *)a1 += 10;
strcpy((char *)(a1 + 4), "BOILED");
fwrite("mutated by boil(): ", 1uLL, 0x13uLL, _bss_start);
tomato_print((const char *)a1);
return fputc(10, _bss_start);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
*(_DWORD *)a1 += 10;
strcpy((char *)(a1 + 4), "BOILED");
fwrite("mutated by boil(): ", 1uLL, 0x13uLL, _bss_start);
func7((const char *)a1);
return fputc(10, _bss_start);
}

original_code:
void
boil (struct tomato *t)
{
    const char boiled_name[] = "BOILED";
    t->spots = t->spots + 10;
    memcpy (t->name,
            boiled_name,
            sizeof (boiled_name) / sizeof (*boiled_name));
    fputs ("mutated by boil(): ", stdout);
    tomato_print (t);
    fputs ("\n", stdout);
}

canonical_original_code:
void boil(struct tomato *t)
{
    char boiled_name[] = "BOILED";
    t->spots = t->spots + 10;
    memcpy (t->name,
            boiled_name,
            sizeof (boiled_name) / sizeof (*boiled_name));
    fputs ("mutated by boil(): ", stdout);
    tomato_print (t);
    fputs ("\n", stdout);
}

user_defined_types: struct tomato { int spots; char name[10]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+0h] [rbp-18h] BYREF
_BYTE v5[12]; // [rsp+4h] [rbp-14h]

v4 = 2;
*(_QWORD *)v5 = 5718354LL;
*(_WORD *)&v5[8] = 0;
fwrite("I have a ", 1uLL, 9uLL, _bss_start);
tomato_print((const char *)&v4);
fwrite(".\n\n", 1uLL, 3uLL, _bss_start);
fry(v4, *(__int64 *)&v5[4]);
fwrite("I still have a ", 1uLL, 0xFuLL, _bss_start);
tomato_print((const char *)&v4);
fwrite(".\n\n", 1uLL, 3uLL, _bss_start);
boil((__int64)&v4);
fwrite(&unk_402057, 1uLL, 0xDuLL, _bss_start);
tomato_print((const char *)&v4);
fwrite(".\n", 1uLL, 2uLL, _bss_start);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+0h] [rbp-18h] BYREF
_BYTE v5[12]; // [rsp+4h] [rbp-14h]

v4 = 2;
*(_QWORD *)v5 = 5718354LL;
*(_WORD *)&v5[8] = 0;
fwrite("I have a ", 1uLL, 9uLL, _bss_start);
func7((const char *)&v4);
fwrite(".\n\n", 1uLL, 3uLL, _bss_start);
func8(v4, *(__int64 *)&v5[4]);
fwrite("I still have a ", 1uLL, 0xFuLL, _bss_start);
func7((const char *)&v4);
fwrite(".\n\n", 1uLL, 3uLL, _bss_start);
func9((__int64)&v4);
fwrite(&unk_402057, 1uLL, 0xDuLL, _bss_start);
func7((const char *)&v4);
fwrite(".\n", 1uLL, 2uLL, _bss_start);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
    struct tomato thom = {2, "RAW"};
    fputs ("I have a ", stdout);
    tomato_print (&thom);
    fputs (".\n\n", stdout);
    fry (thom);
    fputs ("I still have a ", stdout);
    tomato_print (&thom);
    fputs (".\n\n", stdout);
    boil (&thom);
    fputs ("Now I have a ", stdout);
    tomato_print (&thom);
    fputs (".\n", stdout);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct tomato thom = {2, "RAW"};
    fputs ("I have a ", stdout);
    tomato_print (&thom);
    fputs (".\n\n", stdout);
    fry (thom);
    fputs ("I still have a ", stdout);
    tomato_print (&thom);
    fputs (".\n\n", stdout);
    boil (&thom);
    fputs ("Now I have a ", stdout);
    tomato_print (&thom);
    fputs (".\n", stdout);
    return 0;
}

variable_types: argc int


decompiled_code:
void *read_all_stdin()
{
char *v0; // rax
int v1; // eax
char v2; // bl
char *v3; // rax
char *v4; // rbp
size_t v5; // rbx
char *v6; // rax
void *v7; // rax
void *v8; // rbx
struct obstack v10; // [rsp+0h] [rbp-78h] BYREF

_obstack_begin(&v10, 0, 0, (void *(*)(__int64))xmalloc, free);
flockfile(stdin);
while ( 1 )
{
v1 = getchar_unlocked();
v2 = v1;
if ( v1 == -1 )
break;
if ( v10.chunk_limit < v10.next_free + 1 )
_obstack_newchunk(&v10, 1);
v0 = v10.next_free++;
*v0 = v2;
}
funlockfile(stdin);
if ( v10.chunk_limit < v10.next_free + 1 )
_obstack_newchunk(&v10, 1);
v3 = v10.next_free++;
*v3 = 0;
v4 = v10.object_base;
v5 = LODWORD(v10.next_free) - LODWORD(v10.object_base);
if ( v10.next_free == v10.object_base )
*((_BYTE *)&v10 + 80) |= 2u;
v6 = (char *)(~v10.alignment_mask & (__int64)&v10.next_free[v10.alignment_mask]);
if ( v6 > v10.chunk_limit )
v6 = v10.chunk_limit;
v10.next_free = v6;
v10.object_base = v6;
v7 = xmalloc(v5);
v8 = memcpy(v7, v4, v5);
obstack_free(&v10, 0LL);
return v8;
}

canonical_decompiled_code:
void *func8()
{
char *v0; // rax
int v1; // eax
char v2; // bl
char *v3; // rax
char *v4; // rbp
size_t v5; // rbx
char *v6; // rax
void *v7; // rax
void *v8; // rbx
struct obstack v10; // [rsp+0h] [rbp-78h] BYREF

_obstack_begin(&v10, 0, 0, (void *(*)(__int64))xmalloc, free);
flockfile(stdin);
while ( 1 )
{
v1 = getchar_unlocked();
v2 = v1;
if ( v1 == -1 )
break;
if ( v10.chunk_limit < v10.next_free + 1 )
_obstack_newchunk(&v10, 1);
v0 = v10.next_free++;
*v0 = v2;
}
funlockfile(stdin);
if ( v10.chunk_limit < v10.next_free + 1 )
_obstack_newchunk(&v10, 1);
v3 = v10.next_free++;
*v3 = 0;
v4 = v10.object_base;
v5 = LODWORD(v10.next_free) - LODWORD(v10.object_base);
if ( v10.next_free == v10.object_base )
*((_BYTE *)&v10 + 80) |= 2u;
v6 = (char *)(~v10.alignment_mask & (__int64)&v10.next_free[v10.alignment_mask]);
if ( v6 > v10.chunk_limit )
v6 = v10.chunk_limit;
v10.next_free = v6;
v10.object_base = v6;
v7 = func7(v5);
v8 = memcpy(v7, v4, v5);
obstack_free(&v10, 0LL);
return v8;
}

original_code:
char *
read_all_stdin (void)
{
    struct obstack buffer;
    int c;
    int ret_size;
    char *ret;
    _obstack_begin ((&buffer), 0, 0, (void *(*)(long))xmalloc, (void (*)(void *))free);
    flockfile (stdin);
    while (1) {
        c = getchar_unlocked ();
        if (c == (-1))
            break;
        __extension__ ({ struct obstack *__o = (&buffer); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (c)); (void) 0; });
    }
    funlockfile (stdin);
    __extension__ ({ struct obstack *__o = (&buffer); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = ('\0')); (void) 0; });
    ret_size = __extension__ ({ struct obstack const *__o = (&buffer); (unsigned) (__o->next_free - __o->object_base); });
    ret = memcpy (xmalloc (ret_size),
                  __extension__ ({ struct obstack *__o1 = (&buffer); void *__value = (void *) __o1->object_base; if (__o1->next_free == __value) __o1->maybe_empty_object = 1; __o1->next_free = ((sizeof (long int) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (((__o1->next_free) - (sizeof (long int) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (__o1->alignment_mask)) & ~(__o1->alignment_mask))); if (__o1->next_free - (char *) __o1->chunk > __o1->chunk_limit - (char *) __o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free; __value; }),
                  ret_size);
    __extension__ ({ struct obstack *__o = (&buffer); void *__obj = (((void *)0)); if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit) __o->next_free = __o->object_base = (char *) __obj; else (obstack_free) (__o, __obj); });
    return ret;
}

canonical_original_code:
char *read_all_stdin()
{
    struct obstack buffer;
    int c;
    int ret_size;
    char *ret;
    _obstack_begin ((&buffer), 0, 0, (void *(*)(long))xmalloc, (void (*)(void *))free);
    flockfile (stdin);
    while (1) {
        c = getchar_unlocked ();
        if (c == (-1))
            break;
        __extension__ ({ struct obstack *__o = (&buffer); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (c)); (void) 0; });
    }
    funlockfile (stdin);
    __extension__ ({ struct obstack *__o = (&buffer); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = ('\0')); (void) 0; });
    ret_size = __extension__ ({ struct obstack *__o = (&buffer); (unsigned int) (__o->next_free - __o->object_base); });
    ret = memcpy (xmalloc (ret_size),
                  __extension__ ({ struct obstack *__o1 = (&buffer); void *__value = (void *) __o1->object_base; if (__o1->next_free == __value) __o1->maybe_empty_object = 1; __o1->next_free = ((sizeof (long) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (((__o1->next_free) - (sizeof (long) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (__o1->alignment_mask)) & ~(__o1->alignment_mask))); if (__o1->next_free - (char *) __o1->chunk > __o1->chunk_limit - (char *) __o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free; __value; }),
                  ret_size);
    __extension__ ({ struct obstack *__o = (&buffer); void *__obj = (((void *)0)); if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit) __o->next_free = __o->object_base = (char *) __obj; else (obstack_free) (__o, __obj); });
    return ret;
}

variable_types:
ret
char *

variable_types: struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } *

return_type: char *

user_defined_types: struct obstack { long chunk_size; struct _obstack_chunk *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; }


decompiled_code:
double *__fastcall plot_data_create(double a1)
{
double *result; // rax

result = (double *)xmalloc(0x10uLL);
*result = 0.0;
result[1] = a1;
return result;
}

canonical_decompiled_code:
double *__fastcall func9(double a1)
{
double *result; // rax

result = (double *)func7(0x10uLL);
*result = 0.0;
result[1] = a1;
return result;
}

original_code:
struct plot_data *
plot_data_create (double value)
{
    struct plot_data *data;
    data = xmalloc (sizeof (*data));
    data->next = ((void *)0);
    data->value = value;
    return data;
}

canonical_original_code:
struct plot_data *plot_data_create(double value)
{
    struct plot_data *data;
    data = xmalloc (sizeof (*data));
    data->next = ((void *)0);
    data->value = value;
    return data;
}

variable_types: value double

variable_types: struct plot_data { struct plot_data *next; double value; } *


decompiled_code:
int __fastcall plot_data_parse_append(_QWORD *a1, const char *a2)
{
char v4; // bp
int result; // eax
int *v6; // rbp
double v7; // xmm0_8
char *v8; // rbp
double *v9; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
while ( 1 )
{
v4 = *a2;
result = isspace(*a2);
if ( !result )
break;
++a2;
}
if ( !v4 )
break;
v6 = __errno_location();
*v6 = 0;
v7 = strtod(a2, &endptr);
if ( *v6 )
return -1;
v8 = endptr;
if ( endptr == a2 )
return -1;
v9 = plot_data_create(v7);
*a1 = v9;
a2 = v8;
a1 = v9;
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1, const char *a2)
{
char v4; // bp
int result; // eax
int *v6; // rbp
double v7; // xmm0_8
char *v8; // rbp
double *v9; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
while ( 1 )
{
v4 = *a2;
result = isspace(*a2);
if ( !result )
break;
++a2;
}
if ( !v4 )
break;
v6 = __errno_location();
*v6 = 0;
v7 = strtod(a2, &endptr);
if ( *v6 )
return -1;
v8 = endptr;
if ( endptr == a2 )
return -1;
v9 = func9(v7);
*a1 = v9;
a2 = v8;
a1 = v9;
}
return result;
}

original_code:
int
plot_data_parse_append (struct plot_data *data_tail, char *string)
{
    char *string_tail;
    double value;
    while (1) {
        while (isspace (*string))
            string++;
        if (*string == '\0')
            break;
        (*__errno_location ()) = 0;
        value = strtod (string, &string_tail);
        if ((*__errno_location ()) || string == string_tail)
            return -1;
        string = string_tail;
        data_tail->next = plot_data_create (value);
        data_tail = data_tail->next;
    }
    return 0;
}

canonical_original_code:
int plot_data_parse_append(struct plot_data *data_tail, char *string)
{
    char *string_tail;
    double value;
    while (1) {
        while (isspace (*string))
            string++;
        if (*string == '\0')
            break;
        (*__errno_location ()) = 0;
        value = strtod (string, &string_tail);
        if ((*__errno_location ()) || string == string_tail)
            return -1;
        string = string_tail;
        data_tail->next = plot_data_create (value);
        data_tail = data_tail->next;
    }
    return 0;
}

variable_types:
string
char *

user_defined_types: struct plot_data { struct plot_data *next; double value; }


decompiled_code:
void *plot_data_parse_stdin()
{
void *v0; // rbx
void *result; // rax
void *ptr; // [rsp+0h] [rbp-18h] BYREF

v0 = read_all_stdin();
ptr = 0LL;
if ( plot_data_parse_append(&ptr, (const char *)v0) < 0 )
{
plot_data_destroy(ptr);
result = 0LL;
}
else
{
free(v0);
result = ptr;
}
return result;
}

canonical_decompiled_code:
void *func12()
{
void *v0; // rbx
void *result; // rax
void *ptr; // [rsp+0h] [rbp-18h] BYREF

v0 = func8();
ptr = 0LL;
if ( func11(&ptr, (const char *)v0) < 0 )
{
func10(ptr);
result = 0LL;
}
else
{
free(v0);
result = ptr;
}
return result;
}

original_code:
struct plot_data *
plot_data_parse_stdin (void)
{
    char *buffer;
    struct plot_data fake_head;
    buffer = read_all_stdin ();
    fake_head.next = ((void *)0);
    if (plot_data_parse_append (&fake_head, buffer) < 0) {
        plot_data_destroy (fake_head.next);
        return ((void *)0);
    }
    free (buffer);
    buffer = ((void *)0);
    return fake_head.next;
}

canonical_original_code:
struct plot_data *plot_data_parse_stdin()
{
    char *buffer;
    struct plot_data fake_head;
    buffer = read_all_stdin ();
    fake_head.next = ((void *)0);
    if (plot_data_parse_append (&fake_head, buffer) < 0) {
        plot_data_destroy (fake_head.next);
        return ((void *)0);
    }
    free (buffer);
    buffer = ((void *)0);
    return fake_head.next;
}

variable_types:
buffer
char *

return_type: struct plot_data { struct plot_data *next; double value; } *


decompiled_code:
int __fastcall plot_data_draw(double *a1)
{
double *v1; // r12
double *v2; // rbx
double v3; // rbp
__int64 v4; // rax
__int64 v5; // r13
unsigned __int64 v6; // rbx
char v7; // r13
int result; // eax

if ( !a1 )
return 0;
v1 = a1;
v2 = a1;
v3 = 0.0;
do
{
v3 = fmax(fabs(v2[1]), v3);
v2 = *(double **)v2;
}
while ( v2 );
while ( 1 )
{
v4 = lrint(v1[1] / v3 * 60.0);
v5 = v4;
if ( v4 < 0 )
break;
v6 = abs64(v4);
flockfile(stdout);
if ( v5 )
{
v7 = 43;
goto LABEL_9;
}
LABEL_5:
putchar_unlocked(10);
funlockfile(stdout);
v1 = *(double **)v1;
if ( !v1 )
return 0;
}
v6 = abs64(v4);
flockfile(stdout);
v7 = 45;
LABEL_9:
while ( 1 )
{
result = putchar_unlocked(v7);
if ( result == -1 )
return result;
if ( !--v6 )
goto LABEL_5;
}
}

canonical_decompiled_code:
int __fastcall func13(double *a1)
{
double *v1; // r12
double *v2; // rbx
double v3; // rbp
__int64 v4; // rax
__int64 v5; // r13
unsigned __int64 v6; // rbx
char v7; // r13
int result; // eax

if ( !a1 )
return 0;
v1 = a1;
v2 = a1;
v3 = 0.0;
do
{
v3 = fmax(fabs(v2[1]), v3);
v2 = *(double **)v2;
}
while ( v2 );
while ( 1 )
{
v4 = lrint(v1[1] / v3 * 60.0);
v5 = v4;
if ( v4 < 0 )
break;
v6 = abs64(v4);
flockfile(stdout);
if ( v5 )
{
v7 = 43;
goto LABEL_9;
}
LABEL_5:
putchar_unlocked(10);
funlockfile(stdout);
v1 = *(double **)v1;
if ( !v1 )
return 0;
}
v6 = abs64(v4);
flockfile(stdout);
v7 = 45;
LABEL_9:
while ( 1 )
{
result = putchar_unlocked(v7);
if ( result == -1 )
return result;
if ( !--v6 )
goto LABEL_5;
}
}

original_code:
int
plot_data_draw (struct plot_data *data)
{
    struct plot_data *tmp;
    double max_value = 0.0;
    long int i;
    char c;
    for (tmp = data; tmp; tmp = tmp->next) {
        max_value = fmax (fabs (tmp->value), max_value);
    }
    for (tmp = data; tmp; tmp = tmp->next) {
        i = lrint (tmp->value / max_value * 60);
        c = i >= 0 ? '+' : '-';
        i = labs (i);
        flockfile (stdout);
        for (; i; i--) {
            if (putchar_unlocked (c) == (-1))
                return -1;
        }
        putchar_unlocked ('\n');
        funlockfile (stdout);
    }
    return 0;
}

canonical_original_code:
int plot_data_draw(struct plot_data *data)
{
    struct plot_data *tmp;
    double max_value = 0.0;
    long i;
    char c;
    for (tmp = data; tmp; tmp = tmp->next) {
        max_value = fmax (fabs (tmp->value), max_value);
    }
    for (tmp = data; tmp; tmp = tmp->next) {
        i = lrint (tmp->value / max_value * 60);
        c = i >= 0 ? '+' : '-';
        i = labs (i);
        flockfile (stdout);
        for (; i; i--) {
            if (putchar_unlocked (c) == (-1))
                return -1;
        }
        putchar_unlocked ('\n');
        funlockfile (stdout);
    }
    return 0;
}

variable_types: i long

variable_types: c char


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
exit(2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
exit(2);
}
return result;
}

original_code:
void *
xmalloc (size_t size)
{
    void *ret;
    ret = malloc (size);
    if (ret)
        return ret;
    fprintf (stderr, "cannot allocate memory\n");
    exit (2);
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
    void *ret;
    ret = malloc (size);
    if (ret)
        return ret;
    fprintf (stderr, "cannot allocate memory\n");
    exit (2);
}

variable_types:
size
unsigned long

variable_types:
ret
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double *v3; // rax
double *v4; // rbx
int result; // eax

v3 = (double *)plot_data_parse_stdin();
if ( v3 )
{
v4 = v3;
if ( plot_data_draw(v3) < 0 )
fwrite("failed to print plot.\n", 1uLL, 0x16uLL, stderr);
plot_data_destroy(v4);
result = 0;
}
else
{
fwrite("failed to read data.\n", 1uLL, 0x15uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double *v3; // rax
double *v4; // rbx
int result; // eax

v3 = (double *)func12();
if ( v3 )
{
v4 = v3;
if ( func13(v3) < 0 )
fwrite("failed to print plot.\n", 1uLL, 0x16uLL, stderr);
func10(v4);
result = 0;
}
else
{
fwrite("failed to read data.\n", 1uLL, 0x15uLL, stderr);
result = 1;
}
return result;
}

original_code:
int
main (int argc, char **argv)
{
    struct plot_data *data;
    data = plot_data_parse_stdin ();
    if (!data) {
        fprintf (stderr, "failed to read data.\n");
        return 1;
    }
    if (plot_data_draw (data) < 0)
        fprintf (stderr, "failed to print plot.\n");
    plot_data_destroy (data);
    data = ((void *)0);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct plot_data *data;
    data = plot_data_parse_stdin ();
    if (!data) {
        fprintf (stderr, "failed to read data.\n");
        return 1;
    }
    if (plot_data_draw (data) < 0)
        fprintf (stderr, "failed to print plot.\n");
    plot_data_destroy (data);
    data = ((void *)0);
    return 0;
}


decompiled_code:
int __fastcall libeasy_print_integer(unsigned int a1)
{
const char *v1; // rax

v1 = colliding_convert(a1);
return printf("libeasy: In English, %d is %s\n", a1, v1);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1)
{
const char *v1; // rax

v1 = func1(a1);
return printf("libeasy: In English, %d is %s\n", a1, v1);
}

original_code:
int
libeasy_print_integer (int x)
{
    return printf ("libeasy: "
                   "In English, %d is %s\n", x, colliding_convert (x));
}

canonical_original_code:
int libeasy_print_integer(int x)
{
    return printf ("libeasy: "
                   "In English, %d is %s\n", x, colliding_convert (x));
}

variable_types: x int


decompiled_code:
__int64 __fastcall squares_up_to(int a1)
{
unsigned int v1; // edx
unsigned int v2; // eax

if ( a1 <= 0 )
return 0;
v1 = 0;
do
{
v2 = v1 + 2;
++v1;
}
while ( (int)(v2 * v2) <= a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // edx
unsigned int v2; // eax

if ( a1 <= 0 )
return 0;
v1 = 0;
do
{
v2 = v1 + 2;
++v1;
}
while ( (int)(v2 * v2) <= a1 );
return v1;
}

original_code:
int
squares_up_to (int x)
{
    int i, count;
    for (i = 1, count = 0; i * i <= x; i++, count++) {}
    return count;
}

canonical_original_code:
int squares_up_to(int x)
{
    int i; int count;
    for (i = 1, count = 0; i * i <= x; i++, count++) {}
    return count;
}

variable_types: i int

variable_types: count int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

v3 = squares_up_to(1052);
printf("There are %d square numbers less than or equal to %d.\n", v3, 1052LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

v3 = func7(1052);
printf("There are %d square numbers less than or equal to %d.\n", v3, 1052LL);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
    int n, result;
    n = 1052;
    result = squares_up_to (n);
    printf ("There are %d square numbers less than or equal to %d.\n",
            result, n);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int n; int result;
    n = 1052;
    result = squares_up_to (n);
    printf ("There are %d square numbers less than or equal to %d.\n",
            result, n);
    return 0;
}

variable_types:
argv
char **

variable_types: n int

variable_types: result int


decompiled_code:
__int64 __fastcall multiply_operator(unsigned int a1, unsigned int a2)
{
fwrite("> multiply_operator got: ", 1uLL, 0x19uLL, _bss_start);
printf("%d, %d\n", a1, a2);
return a2 * a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
fwrite("> multiply_operator got: ", 1uLL, 0x19uLL, _bss_start);
printf("%d, %d\n", a1, a2);
return a2 * a1;
}

original_code:
int
multiply_operator (int x, int y)
{
    fputs ("> multiply_operator got: ", stdout);
    printf ("%d, %d\n", x, y);
    return x * y;
}

canonical_original_code:
int multiply_operator(int x, int y)
{
    fputs ("> multiply_operator got: ", stdout);
    printf ("%d, %d\n", x, y);
    return x * y;
}

variable_types: y int


decompiled_code:
__int64 __fastcall difference_operator(unsigned int a1, unsigned int a2)
{
fwrite("> difference_operator got: ", 1uLL, 0x1BuLL, _bss_start);
printf("%d, %d\n", a1, a2);
return a1 - a2;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
fwrite("> difference_operator got: ", 1uLL, 0x1BuLL, _bss_start);
printf("%d, %d\n", a1, a2);
return a1 - a2;
}

original_code:
int
difference_operator (int x, int y)
{
    fputs ("> difference_operator got: ", stdout);
    printf ("%d, %d\n", x, y);
    return x - y;
}

canonical_original_code:
int difference_operator(int x, int y)
{
    fputs ("> difference_operator got: ", stdout);
    printf ("%d, %d\n", x, y);
    return x - y;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 (__fastcall *v5)(unsigned int, unsigned int); // rax
unsigned int v6; // eax
__int64 (__fastcall *v7)(unsigned int, unsigned int); // rax
unsigned int v8; // eax
__int64 (__fastcall *v9)(unsigned int, unsigned int); // rax
unsigned int v10; // eax

fwrite("=== Direct assignment to function pointer ===\n", 1uLL, 0x2EuLL, _bss_start);
v3 = multiply_operator(4u, 3u);
printf("%d\n", v3);
v4 = difference_operator(4u, 3u);
printf("%d\n", v4);
fputc(10, _bss_start);
fwrite("=== Lookup by name ===\n", 1uLL, 0x17uLL, _bss_start);
v5 = get_operator_by_name("times");
v6 = v5(5u, 8u);
printf("%d\n", v6);
v7 = get_operator_by_name("minus");
v8 = v7(5u, 8u);
printf("%d\n", v8);
fputc(10, _bss_start);
fwrite("=== Skip assignment to function pointer === \n", 1uLL, 0x2DuLL, _bss_start);
v9 = get_operator_by_name("times");
v10 = v9(4294967294u, 3u);
printf("%d\n", v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 (__fastcall *v5)(unsigned int, unsigned int); // rax
unsigned int v6; // eax
__int64 (__fastcall *v7)(unsigned int, unsigned int); // rax
unsigned int v8; // eax
__int64 (__fastcall *v9)(unsigned int, unsigned int); // rax
unsigned int v10; // eax

fwrite("=== Direct assignment to function pointer ===\n", 1uLL, 0x2EuLL, _bss_start);
v3 = func7(4u, 3u);
printf("%d\n", v3);
v4 = func8(4u, 3u);
printf("%d\n", v4);
fputc(10, _bss_start);
fwrite("=== Lookup by name ===\n", 1uLL, 0x17uLL, _bss_start);
v5 = get_operator_by_name("times");
v6 = v5(5u, 8u);
printf("%d\n", v6);
v7 = get_operator_by_name("minus");
v8 = v7(5u, 8u);
printf("%d\n", v8);
fputc(10, _bss_start);
fwrite("=== Skip assignment to function pointer === \n", 1uLL, 0x2DuLL, _bss_start);
v9 = get_operator_by_name("times");
v10 = v9(4294967294u, 3u);
printf("%d\n", v10);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
    int (*binary_operator) (int, int);
    fputs ("=== Direct assignment to function pointer ===\n", stdout);
    binary_operator = multiply_operator;
    printf ("%d\n", binary_operator (4, 3));
    binary_operator = difference_operator;
    printf ("%d\n", binary_operator (4, 3));
    fputs ("\n", stdout);
    fputs ("=== Lookup by name ===\n", stdout);
    binary_operator = get_operator_by_name ("times");
    printf ("%d\n", binary_operator (5, 8));
    binary_operator = get_operator_by_name ("minus");
    printf ("%d\n", binary_operator (5, 8));
    fputs ("\n", stdout);
    fputs ("=== Skip assignment to function pointer === \n", stdout);
    printf ("%d\n", get_operator_by_name ("times") (-2, 3));
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int (*binary_operator)(int, int);
    fputs ("=== Direct assignment to function pointer ===\n", stdout);
    binary_operator = multiply_operator;
    printf ("%d\n", binary_operator (4, 3));
    binary_operator = difference_operator;
    printf ("%d\n", binary_operator (4, 3));
    fputs ("\n", stdout);
    fputs ("=== Lookup by name ===\n", stdout);
    binary_operator = get_operator_by_name ("times");
    printf ("%d\n", binary_operator (5, 8));
    binary_operator = get_operator_by_name ("minus");
    printf ("%d\n", binary_operator (5, 8));
    fputs ("\n", stdout);
    fputs ("=== Skip assignment to function pointer === \n", stdout);
    printf ("%d\n", get_operator_by_name ("times") (-2, 3));
    return 0;
}

variable_types: argc int


decompiled_code:
int __fastcall print_help(const char *a1)
{
printf("Usage: %s <number>...\n\n", a1);
puts(
"Given a list of integers (a_1, a_2, ..., a_n),\n"
"computes (a_2 - a_1, a_3 - a_2, ..., a_1 - a_n),\n"
"then repeats again on the output list.\n");
return printf("Example: %s 0 0 1 0 0\n0 1 -1 0 0\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
printf("Usage: %s <number>...\n\n", a1);
puts(
"Given a list of integers (a_1, a_2, ..., a_n),\n"
"computes (a_2 - a_1, a_3 - a_2, ..., a_1 - a_n),\n"
"then repeats again on the output list.\n");
return printf("Example: %s 0 0 1 0 0\n0 1 -1 0 0\n", a1);
}

original_code:
void
print_help (const char *name)
{
    printf ("Usage: %s <number>...\n\n", name);
    printf ("Given a list of integers (a_1, a_2, ..., a_n),\n"
            "computes (a_2 - a_1, a_3 - a_2, ..., a_1 - a_n),\n"
            "then repeats again on the output list.\n\n");
    printf ("Example: %s 0 0 1 0 0\n"
            "0 1 -1 0 0\n", name);
}

canonical_original_code:
void print_help(char *name)
{
    printf ("Usage: %s <number>...\n\n", name);
    printf ("Given a list of integers (a_1, a_2, ..., a_n),\n"
            "computes (a_2 - a_1, a_3 - a_2, ..., a_1 - a_n),\n"
            "then repeats again on the output list.\n\n");
    printf ("Example: %s 0 0 1 0 0\n"
            "0 1 -1 0 0\n", name);
}

variable_types:
name
char *


original_code:
void
print_buffer (long int *buffer, size_t size)
{
    size_t i;
    for (i = 0; i < size - 1; i++)
        printf ("%ld ", buffer[i]);
    printf ("%ld\n", buffer[i]);
}

canonical_original_code:
void print_buffer(long *buffer, unsigned long size)
{
    unsigned long i;
    for (i = 0; i < size - 1; i++)
        printf ("%ld ", buffer[i]);
    printf ("%ld\n", buffer[i]);
}

variable_types:
buffer
long *

variable_types:
i
unsigned long


decompiled_code:
int __fastcall differences_loop(_QWORD *a1, _QWORD *a2, unsigned __int64 a3)
{
put_differences((__int64)a2, a1, a3);
print_buffer((__int64)a2, a3);
put_differences((__int64)a1, a2, a3);
print_buffer((__int64)a1, a3);
put_differences((__int64)a2, a1, a3);
print_buffer((__int64)a2, a3);
put_differences((__int64)a1, a2, a3);
print_buffer((__int64)a1, a3);
put_differences((__int64)a2, a1, a3);
return print_buffer((__int64)a2, a3);
}

original_code:
void
differences_loop (long int *primary, long int *secondary, size_t size)
{
    size_t i;
    for (i = 0; i < 5 / 2; i++) {
        put_differences (secondary, primary, size);
        print_buffer (secondary, size);
        put_differences (primary, secondary, size);
        print_buffer (primary, size);
    }
    if (5 % 2 == 1) {
        put_differences (secondary, primary, size);
        print_buffer (secondary, size);
    }
}

canonical_original_code:
void differences_loop(long *primary, long *secondary, unsigned long size)
{
    unsigned long i;
    for (i = 0; i < 5 / 2; i++) {
        put_differences (secondary, primary, size);
        print_buffer (secondary, size);
        put_differences (primary, secondary, size);
        print_buffer (primary, size);
    }
    if (5 % 2 == 1) {
        put_differences (secondary, primary, size);
        print_buffer (secondary, size);
    }
}

variable_types:
primary
long *

variable_types:
secondary
long *


decompiled_code:
__int64 __fastcall parse_strings(__int64 a1, __int64 a2, __int64 a3)
{
int *v4; // rax
int *v5; // rbp
__int64 v6; // rbx
unsigned int v7; // edx
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = __errno_location();
*v4 = 0;
if ( !a3 )
return 0;
v5 = v4;
v6 = 0LL;
while ( 1 )
{
*(_QWORD *)(a1 + 8 * v6) = strtol(*(const char **)(a2 + 8 * v6), &endptr, 10);
v7 = *v5;
if ( *v5 )
return (unsigned int)-1;
if ( !endptr )
return (unsigned int)-1;
if ( *endptr )
break;
if ( a3 == ++v6 )
return v7;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
int *v4; // rax
int *v5; // rbp
__int64 v6; // rbx
unsigned int v7; // edx
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = __errno_location();
*v4 = 0;
if ( !a3 )
return 0;
v5 = v4;
v6 = 0LL;
while ( 1 )
{
*(_QWORD *)(a1 + 8 * v6) = strtol(*(const char **)(a2 + 8 * v6), &endptr, 10);
v7 = *v5;
if ( *v5 )
return (unsigned int)-1;
if ( !endptr )
return (unsigned int)-1;
if ( *endptr )
break;
if ( a3 == ++v6 )
return v7;
}
return (unsigned int)-1;
}

original_code:
int
parse_strings (long int *out, char **strings, size_t size)
{
    char *tail;
    size_t i;
    (*__errno_location ()) = 0;
    for (i = 0; i < size; i++) {
        out[i] = strtol (strings[i], &tail, 10);
        if ((*__errno_location ()) || !tail || *tail != '\0')
            return -1;
    }
    return 0;
}

canonical_original_code:
int parse_strings(long *out, char **strings, unsigned long size)
{
    char *tail;
    unsigned long i;
    (*__errno_location ()) = 0;
    for (i = 0; i < size; i++) {
        out[i] = strtol (strings[i], &tail, 10);
        if ((*__errno_location ()) || !tail || *tail != '\0')
            return -1;
    }
    return 0;
}

variable_types:
out
long *

variable_types:
strings
char **

variable_types:
tail
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
void *v4; // rsp
void *v5; // rsp
int v6; // er13
__int64 v8; // [rsp+0h] [rbp-30h] BYREF

if ( argc <= 1 )
goto LABEL_5;
v3 = argc - 1;
v4 = alloca(8 * v3 + 8);
v5 = alloca(8 * v3 + 8);
v6 = parse_strings((__int64)&v8, (__int64)(argv + 1), v3);
if ( v6 )
{
puts("failed to parse numbers");
LABEL_5:
print_help(*argv);
return 1;
}
differences_loop(&v8, &v8, v3);
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
void *v4; // rsp
void *v5; // rsp
int v6; // er13
__int64 v8; // [rsp+0h] [rbp-30h] BYREF

if ( argc <= 1 )
goto LABEL_5;
v3 = argc - 1;
v4 = alloca(8 * v3 + 8);
v5 = alloca(8 * v3 + 8);
v6 = func11((__int64)&v8, (__int64)(argv + 1), v3);
if ( v6 )
{
puts("failed to parse numbers");
LABEL_5:
func7(*argv);
return 1;
}
func10(&v8, &v8, v3);
return v6;
}

original_code:
int
main (int argc, char **argv)
{
    long int *buffer1;
    long int *buffer2;
    size_t size;
    int ret;
    if (argc <= 1)
        goto usagefail;
    size = argc - 1;
    buffer1 = __builtin_alloca (sizeof (*buffer1) * size);
    buffer2 = __builtin_alloca (sizeof (*buffer2) * size);
    ret = parse_strings (buffer1, argv + 1, size);
    if (ret) {
        printf ("failed to parse numbers\n");
        goto usagefail;
    }
    differences_loop (buffer1, buffer2, size);
    return 0;
usagefail:
    print_help (argv[0]);
    return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
    long *buffer1;
    long *buffer2;
    unsigned long size;
    int ret;
    if (argc <= 1)
        goto usagefail;
    size = argc - 1;
    buffer1 = __builtin_alloca (sizeof (*buffer1) * size);
    buffer2 = __builtin_alloca (sizeof (*buffer2) * size);
    ret = parse_strings (buffer1, argv + 1, size);
    if (ret) {
        printf ("failed to parse numbers\n");
        goto usagefail;
    }
    differences_loop (buffer1, buffer2, size);
    return 0;
usagefail:
    print_help (argv[0]);
    return 1;
}

variable_types:
size
unsigned long

variable_types: ret int


decompiled_code:
__int64 __fastcall scramble_char(char a1)
{
return a1 & 0x7F;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return a1 & 0x7F;
}

original_code:
static char
scramble_char (const char c)
{
    return (c + 0) & 127;
}

canonical_original_code:
static char scramble_char(char c)
{
    return (c + 0) & 127;
}

variable_types: c char

return_type: char


decompiled_code:
int __fastcall libstupid_print_integer(unsigned int a1)
{
const char *v1; // rax

v1 = (const char *)colliding_convert();
return printf("libstupid: In Roman numerals, %d is %s\n", a1, v1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
const char *v1; // rax

v1 = (const char *)func2();
return printf("libstupid: In Roman numerals, %d is %s\n", a1, v1);
}

original_code:
int
libstupid_print_integer (int x)
{
    return printf ("libstupid: "
                   "In Roman numerals, %d is %s\n", x, colliding_convert (x));
}

canonical_original_code:
int libstupid_print_integer(int x)
{
    return printf ("libstupid: "
                   "In Roman numerals, %d is %s\n", x, colliding_convert (x));
}

variable_types: x int


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fprintf(stderr, "dying: %s\n", a1);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(stderr, "dying: %s\n", a1);
exit(2);
}

original_code:
void
die (const char *message)
{
    fprintf (stderr, "dying: %s\n", message);
    exit (2);
}

canonical_original_code:
void die(char *message)
{
    fprintf (stderr, "dying: %s\n", message);
    exit (2);
}

variable_types:
message
char *


decompiled_code:
void __fastcall dump_output_reverse(__int64 a1, __int64 a2)
{
char *i; // rbx

flockfile(stdout);
for ( i = (char *)(a2 - 1); (char *)(a1 - 1) != i; --i )
{
if ( putchar_unlocked(*i) == -1 )
die("could not write to standard output");
}
funlockfile(stdout);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, __int64 a2)
{
char *i; // rbx

flockfile(stdout);
for ( i = (char *)(a2 - 1); (char *)(a1 - 1) != i; --i )
{
if ( putchar_unlocked(*i) == -1 )
func7("could not write to standard output");
}
funlockfile(stdout);
}

original_code:
void
dump_output_reverse (char *str, char *str_end)
{
    int ret;
    char tmp;
    str--;
    flockfile (stdout);
    for (str_end--; str_end != str; str_end--) {
        tmp = *str_end;
        ret = putchar_unlocked (tmp);
        if (ret == (-1))
            die ("could not write to standard output");
    }
    funlockfile (stdout);
}

canonical_original_code:
void dump_output_reverse(char *str, char *str_end)
{
    int ret;
    char tmp;
    str--;
    flockfile (stdout);
    for (str_end--; str_end != str; str_end--) {
        tmp = *str_end;
        ret = putchar_unlocked (tmp);
        if (ret == (-1))
            die ("could not write to standard output");
    }
    funlockfile (stdout);
}

variable_types:
str
char *

variable_types: tmp char


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
die("cannot allocate memory");
return result;
}

canonical_decompiled_code:
void *__fastcall func8(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func7("cannot allocate memory");
return result;
}

original_code:
void *
xmalloc (size_t size)
{
    void *ret;
    ret = malloc (size);
    if (!ret)
        die ("cannot allocate memory");
    return ret;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
    void *ret;
    ret = malloc (size);
    if (!ret)
        die ("cannot allocate memory");
    return ret;
}

variable_types:
ret
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-78h] BYREF
void *block; // [rsp+8h] [rbp-70h] BYREF
struct obstack obstack; // [rsp+10h] [rbp-68h] BYREF

_obstack_begin(&obstack, 0, 0, (void *(*)(__int64))xmalloc, free);
dump_input(&obstack, (char **)&block, &v4);
if ( LODWORD(obstack.object_base) != LODWORD(obstack.next_free) )
__assert_fail("obstack_object_size (&buffer) == 0", "simple-obstack.c", 0x4Bu, "main");
dump_output_reverse((__int64)block, v4);
if ( obstack.chunk >= block || obstack.chunk_limit <= block )
obstack_free(&obstack, block);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-78h] BYREF
void *block; // [rsp+8h] [rbp-70h] BYREF
struct obstack obstack; // [rsp+10h] [rbp-68h] BYREF

_obstack_begin(&obstack, 0, 0, (void *(*)(__int64))xmalloc, free);
func9(&obstack, (char **)&block, &v4);
if ( LODWORD(obstack.object_base) != LODWORD(obstack.next_free) )
__assert_fail("obstack_object_size (&buffer) == 0", "simple-obstack.c", 0x4Bu, "main");
func10((__int64)block, v4);
if ( obstack.chunk >= block || obstack.chunk_limit <= block )
obstack_free(&obstack, block);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
    struct obstack buffer;
    char *str;
    char *str_end;
    _obstack_begin ((&buffer), 0, 0, (void *(*)(long))xmalloc, (void (*)(void *))free);
    dump_input (&buffer, &str, &str_end);
    ((void) sizeof ((__extension__ ({ struct obstack const *__o = (&buffer); (unsigned) (__o->next_free - __o->object_base); }) == 0) ? 1 : 0), __extension__ ({ if (__extension__ ({ struct obstack const *__o = (&buffer); (unsigned) (__o->next_free - __o->object_base); }) == 0) ; else __assert_fail ("obstack_object_size (&buffer) == 0", "simple-obstack.c", 75, __extension__ __PRETTY_FUNCTION__); }));
    dump_output_reverse (str, str_end);
    __extension__ ({ struct obstack *__o = (&buffer); void *__obj = (str); if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit) __o->next_free = __o->object_base = (char *) __obj; else (obstack_free) (__o, __obj); });
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct obstack buffer;
    char *str;
    char *str_end;
    _obstack_begin ((&buffer), 0, 0, (void *(*)(long))xmalloc, (void (*)(void *))free);
    dump_input (&buffer, &str, &str_end);
    ((void) sizeof ((__extension__ ({ struct obstack *__o = (&buffer); (unsigned int) (__o->next_free - __o->object_base); }) == 0) ? 1 : 0), __extension__ ({ if (__extension__ ({ struct obstack *__o = (&buffer); (unsigned int) (__o->next_free - __o->object_base); }) == 0) ; else __assert_fail ("obstack_object_size (&buffer) == 0", "simple-obstack.c", 75, __extension__ __PRETTY_FUNCTION__); }));
    dump_output_reverse (str, str_end);
    __extension__ ({ struct obstack *__o = (&buffer); void *__obj = (str); if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit) __o->next_free = __o->object_base = (char *) __obj; else (obstack_free) (__o, __obj); });
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } *


usage

decompiled_code:
size_t usage()
{
return fwrite(
"Note: Sounds and lights vary by model\n"
" - Light states: off, on, blink\n"
" -r <state> | red light\n"
" -y <state> | yellow light\n"
" -b <state> | blue light\n"
" -g <state> | green light\n"
" -w <state> | white light\n"
"\n"
" - Sound states: off, use 1-5 to play sound\n"
" -s <state> | speaker\n"
"\n",
1uLL,
0x122uLL,
stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite(
"Note: Sounds and lights vary by model\n"
" - Light states: off, on, blink\n"
" -r <state> | red light\n"
" -y <state> | yellow light\n"
" -b <state> | blue light\n"
" -g <state> | green light\n"
" -w <state> | white light\n"
"\n"
" - Sound states: off, use 1-5 to play sound\n"
" -s <state> | speaker\n"
"\n",
1uLL,
0x122uLL,
stderr);
}

original_code:
void usage()
{
 fprintf(stderr, "Note: Sounds and lights vary by model\n - Light states: off, on, blink\n   -r <state>  |  red light\n   -y <state>  |  yellow light\n   -b <state>  |  blue light\n   -g <state>  |  green light\n   -w <state>  |  white light\n\n - Sound states: off, use 1-5 to play sound\n   -s <state>  |  speaker\n\n");
}


decompiled_code:
char __fastcall parse_option(int *a1, const char *a2, int a3)
{
int v3; // eax
bool v4; // zf

LOBYTE(v3) = (_BYTE)a2;
if ( a3 )
{
if ( !strcmp(a2, "off") )
{
*a1 = 0;
}
else if ( !strcmp(a2, "on") )
{
*a1 = 1;
}
else
{
v4 = strcmp(a2, "blink") == 0;
LOBYTE(v3) = !v4;
if ( !v4 )
{
fwrite("Invalid state selection\n", 1uLL, 0x18uLL, stderr);
usage();
exit(1);
}
*a1 = 2;
}
}
else if ( !strcmp(a2, "off") )
{
*a1 = 0;
}
else
{
v3 = atoi(a2);
if ( (unsigned int)(v3 - 1) > 4 )
{
fwrite("Sound selection invalid or out of range\n", 1uLL, 0x28uLL, stderr);
usage();
exit(1);
}
*a1 = v3;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func8(int *a1, const char *a2, int a3)
{
int v3; // eax
bool v4; // zf

LOBYTE(v3) = (_BYTE)a2;
if ( a3 )
{
if ( !strcmp(a2, "off") )
{
*a1 = 0;
}
else if ( !strcmp(a2, "on") )
{
*a1 = 1;
}
else
{
v4 = strcmp(a2, "blink") == 0;
LOBYTE(v3) = !v4;
if ( !v4 )
{
fwrite("Invalid state selection\n", 1uLL, 0x18uLL, stderr);
func7();
exit(1);
}
*a1 = 2;
}
}
else if ( !strcmp(a2, "off") )
{
*a1 = 0;
}
else
{
v3 = atoi(a2);
if ( (unsigned int)(v3 - 1) > 4 )
{
fwrite("Sound selection invalid or out of range\n", 1uLL, 0x28uLL, stderr);
func7();
exit(1);
}
*a1 = v3;
}
return v3;
}

original_code:
void parse_option(int *target, char *option, int lightopt)
{
 int soundopt;
 if(lightopt)
 {
  if(strcmp(option, "off") == 0)
  {
   *target = light_off;
  }
  else if(strcmp(option, "on") == 0)
  {
   *target = light_on;
  }
  else if(strcmp(option, "blink") == 0)
  {
   *target = light_blink;
  }
  else
  {
   fprintf(stderr, "Invalid state selection\n");
   usage();
   exit(1);
  }
 }
 else
 {
  if(strcmp(option, "off") == 0)
  {
   *target = sound_off;
  }
  else
  {
   soundopt = atoi(option);
   if(soundopt >= 1 && soundopt <= 5)
   {
    *target = soundopt;
   }
   else
   {
    fprintf(stderr, "Sound selection invalid or out of range\n");
    usage();
    exit(1);
   }
  }
 }
}

variable_types:
target
int *

variable_types:
option
char *

variable_types: lightopt int

variable_types: soundopt int