touch

original_code:
int touch (Landscape *lndscp, int pointX, int pointY)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      if (
           ((pointX - lndscp->xPnts[j]) * (lndscp->yRoof[j - 1] - lndscp->yRoof[j])
             - (pointY - lndscp->yRoof[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           < 0)
           &&
           ((pointX - lndscp->xPnts[j]) * (lndscp->yBottom[j - 1] - lndscp->yBottom[j])
             - (pointY - lndscp->yBottom[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           > 0)
         )
        return 0;
      else
        return 1;
    }
  }
}

canonical_original_code:
int touch(struct Landscape *lndscp, int pointX, int pointY)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      if (
           ((pointX - lndscp->xPnts[j]) * (lndscp->yRoof[j - 1] - lndscp->yRoof[j])
             - (pointY - lndscp->yRoof[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           < 0)
           &&
           ((pointX - lndscp->xPnts[j]) * (lndscp->yBottom[j - 1] - lndscp->yBottom[j])
             - (pointY - lndscp->yBottom[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           > 0)
         )
        return 0;
      else
        return 1;
    }
  }
}

variable_types: pointX int

variable_types: pointY int


getYRoof

repo: rnestler/heligame

original_code:
int getYRoof(Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yRoof[j-1]
          + ((lndscp->yRoof[j] - lndscp->yRoof[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}

canonical_original_code:
int getYRoof(struct Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yRoof[j-1]
          + ((lndscp->yRoof[j] - lndscp->yRoof[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}

variable_types: struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } *

variable_types: j int

return_type: int


getYBottom

original_code:
int getYBottom(Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yBottom[j-1]
          + ((lndscp->yBottom[j] - lndscp->yBottom[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}

canonical_original_code:
int getYBottom(struct Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yBottom[j-1]
          + ((lndscp->yBottom[j] - lndscp->yBottom[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}

user_defined_types: struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; }


decompiled_code:
__int64 __fastcall heli_update(float *a1, int a2, float a3)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm0_4

v3 = (float)((float)a2 * a3) + a1[2];
a1[2] = v3;
a1[1] = v3 + a1[1];
result = DIORead(97LL);
if ( (_DWORD)result )
{
*a1 = *a1 - 1.0;
}
else
{
result = DIORead(100LL);
if ( (_DWORD)result )
*a1 = *a1 + 1.0;
}
v5 = a1[1];
if ( v5 <= 80.0 )
{
if ( v5 < 0.0 )
a1[1] = 0.0;
}
else
{
a1[1] = 80.0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1, int a2, float a3)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm0_4

v3 = (float)((float)a2 * a3) + a1[2];
a1[2] = v3;
a1[1] = v3 + a1[1];
result = DIORead(97LL);
if ( (_DWORD)result )
{
*a1 = *a1 - 1.0;
}
else
{
result = DIORead(100LL);
if ( (_DWORD)result )
*a1 = *a1 + 1.0;
}
v5 = a1[1];
if ( v5 <= 80.0 )
{
if ( v5 < 0.0 )
a1[1] = 0.0;
}
else
{
a1[1] = 80.0;
}
return result;
}

original_code:
void heli_update(Heli* heli, float acc, int dtime)
{
 heli->speed += acc*dtime;
 heli->y += heli->speed;
 if(DIORead(SDLK_a)) {
  heli->x -= 1;
 }
 else if(DIORead(SDLK_d)) {
  heli->x += 1;
 }
 if(heli->y > 80) heli->y = 80;
 if(heli->y < 0) heli->y = 0;
}

canonical_original_code:
void heli_update(struct Heli *heli, float acc, int dtime)
{
 heli->speed += acc*dtime;
 heli->y += heli->speed;
 if(DIORead(SDLK_a)) {
  heli->x -= 1;
 }
 else if(DIORead(SDLK_d)) {
  heli->x += 1;
 }
 if(heli->y > 80) heli->y = 80;
 if(heli->y < 0) heli->y = 0;
}

variable_types:
heli
struct Heli { float x; float speed; } *

variable_types: acc float

variable_types: dtime int

return_type: void


decompiled_code:
__int64 __fastcall heli_draw(float *a1)
{
return DisplayDrawCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(float *a1)
{
return DisplayDrawCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

original_code:
void heli_draw(Heli* heli)
{
 DisplayDrawCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}

canonical_original_code:
void heli_draw(struct Heli *heli)
{
 DisplayDrawCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}


decompiled_code:
__int64 __fastcall heli_clear(float *a1)
{
return DisplayClearCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(float *a1)
{
return DisplayClearCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

original_code:
void heli_clear(Heli* heli)
{
 DisplayClearCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}

canonical_original_code:
void heli_clear(struct Heli *heli)
{
 DisplayClearCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}


decompiled_code:
float __fastcall heli_get_y(__int64 a1)
{
return *(float *)(a1 + 4);
}

canonical_decompiled_code:
float __fastcall func4(__int64 a1)
{
return *(float *)(a1 + 4);
}

original_code:
float heli_get_y(Heli* heli)
{
 return heli->y;
}

canonical_original_code:
float heli_get_y(struct Heli *heli)
{
 return heli->y;
}

return_type: float


decompiled_code:
__int64 __fastcall heli_check_collision(float *a1, float a2, float a3, float a4, float a5)
{
__int64 result; // rax
float v6; // [rsp+0h] [rbp-1Ch]

v6 = (float)((float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3)))
* (float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3))))
/ (float)((float)((float)(a4 - a2) * (float)(a4 - a2)) + (float)((float)(a5 - a3) * (float)(a5 - a3)));
printf("%f\n", (float)(v6 - 5.0));
result = 0LL;
if ( v6 <= 25.0 )
{
if ( (float)(*a1 - 5.0) > fmaxf(a2, a4) )
{
puts("xbig");
result = 0LL;
}
else if ( (float)(a1[1] - 5.0) > fmaxf(a3, a5) )
{
puts("xsmall");
result = 0LL;
}
else if ( fminf(a2, a4) > (float)(*a1 + 5.0) )
{
puts("ybig");
result = 0LL;
}
else
{
result = 1LL;
if ( fminf(a3, a5) > (float)(a1[1] + 5.0) )
{
puts("ysmall");
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(float *a1, float a2, float a3, float a4, float a5)
{
__int64 result; // rax
float v6; // [rsp+0h] [rbp-1Ch]

v6 = (float)((float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3)))
* (float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3))))
/ (float)((float)((float)(a4 - a2) * (float)(a4 - a2)) + (float)((float)(a5 - a3) * (float)(a5 - a3)));
printf("%f\n", (float)(v6 - 5.0));
result = 0LL;
if ( v6 <= 25.0 )
{
if ( (float)(*a1 - 5.0) > fmaxf(a2, a4) )
{
puts("xbig");
result = 0LL;
}
else if ( (float)(a1[1] - 5.0) > fmaxf(a3, a5) )
{
puts("xsmall");
result = 0LL;
}
else if ( fminf(a2, a4) > (float)(*a1 + 5.0) )
{
puts("ybig");
result = 0LL;
}
else
{
result = 1LL;
if ( fminf(a3, a5) > (float)(a1[1] + 5.0) )
{
puts("ysmall");
result = 0LL;
}
}
}
return result;
}

original_code:
int heli_check_collision(Heli *heli, float x1, float y1, float x2, float y2)
{
 float dirx = x2-x1;
 float diry = y2-y1;
 float diffx = heli->x - x1;
 float diffy = heli->y - y1;
 float a = dirx*diffy - diry*diffx;
 float r = dirx*dirx + diry*diry;
 a = a*a;
 printf("%f\n", a/r-heliRadius);
 if(a/r<=heliRadius*heliRadius) {
  if(heli->x-heliRadius > (x1>x2? x1 : x2)){ printf("xbig\n"); return 0;}
  if(heli->y-heliRadius > (y1>y2? y1 : y2)){ printf("xsmall\n"); return 0;}
  if(heli->x+heliRadius < (x1<x2? x1 : x2)){ printf("ybig\n"); return 0;}
  if(heli->y+heliRadius < (y1<y2? y1 : y2)){ printf("ysmall\n"); return 0;}
  return 1;
 }
 return 0;
}

canonical_original_code:
int heli_check_collision(struct Heli *heli, float x1, float y1, float x2, float y2)
{
 float dirx = x2-x1;
 float diry = y2-y1;
 float diffx = heli->x - x1;
 float diffy = heli->y - y1;
 float a = dirx*diffy - diry*diffx;
 float r = dirx*dirx + diry*diry;
 a = a*a;
 printf("%f\n", a/r-heliRadius);
 if(a/r<=heliRadius*heliRadius) {
  if(heli->x-heliRadius > (x1>x2? x1 : x2)){ printf("xbig\n"); return 0;}
  if(heli->y-heliRadius > (y1>y2? y1 : y2)){ printf("xsmall\n"); return 0;}
  if(heli->x+heliRadius < (x1<x2? x1 : x2)){ printf("ybig\n"); return 0;}
  if(heli->y+heliRadius < (y1<y2? y1 : y2)){ printf("ysmall\n"); return 0;}
  return 1;
 }
 return 0;
}

variable_types: dirx float

variable_types: diry float

variable_types: diffx float

variable_types: diffy float

variable_types: a float

variable_types: r float


original_code:
int v_semi(float *V, float lamda)
{
 float get_f_variable(char *);
 float k,accum,to_kcal;
 int i,numatm, a_number(void);
 ATOM *ap, *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 accum = 0.;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  accum -= to_kcal*k*ap->mass*(ap->vx*ap->vx);
  accum -= to_kcal*k*ap->mass*(ap->vy*ap->vy);
  accum -= to_kcal*k*ap->mass*(ap->vz*ap->vz);
 }
 *V += accum;
 return 0;
}

canonical_original_code:
int v_semi(float *V, float lamda)
{
 float get_f_variable(char *);
 float k; float accum; float to_kcal;
 int i; int numatm; int a_number();
 struct ATOM *ap; struct ATOM *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 accum = 0.;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  accum -= to_kcal*k*ap->mass*(ap->vx*ap->vx);
  accum -= to_kcal*k*ap->mass*(ap->vy*ap->vy);
  accum -= to_kcal*k*ap->mass*(ap->vz*ap->vz);
 }
 *V += accum;
 return 0;
}

variable_types:
V
float *

variable_types: lamda float

variable_types: k float

variable_types: accum float

variable_types: i int

variable_types: numatm int

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *(int)


original_code:
int f_semi( float lambda)
{
 float get_f_variable(char *);
 float k,to_kcal;
 int i,numatm, a_number(void);
 ATOM *ap, *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 to_kcal += to_kcal;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  ap->fx += to_kcal*k*ap->fx;
  ap->fy += to_kcal*k*ap->fy;
  ap->fz += to_kcal*k*ap->fz;
 }
 return 0;
}

canonical_original_code:
int f_semi(float lambda)
{
 float get_f_variable(char *);
 float k; float to_kcal;
 int i; int numatm; int a_number();
 struct ATOM *ap; struct ATOM *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 to_kcal += to_kcal;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  ap->fx += to_kcal*k*ap->fx;
  ap->fy += to_kcal*k*ap->fy;
  ap->fz += to_kcal*k*ap->fz;
 }
 return 0;
}

variable_types: lambda float

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *


main

canonical_name: main

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

set_f_variable("mxdq", argv, envp, 0.05);
set_f_variable("mxcut", argv, v3, 6.0);
set_i_variable("nostep", 1LL);
read_eval_do(stdin, stdout);
return 0;
}

original_code:
int main()
{
    void read_eval_do();
    set_f_variable( "mxdq", .05);
    set_f_variable( "mxcut", 6.);
    set_i_variable( "nostep", 1);
    read_eval_do( stdin,stdout);
}


randf

original_code:
float randf()
{
    static float buff[55];
    static int ip = 0,jp = 0,kp;
    int i,seed,get_i_variable();
    static double xva;
    if( ip == 0 && jp == 0)
    {
        seed = get_i_variable("seed");
        for( ip=0; ip < 55; ip++)
        { seed = (seed*2349+14867)%32767;
            buff[ip] = (float)seed/32767.;
            if( buff[ip] > 1.) buff[ip] = buff[ip]-1.;
            if( buff[ip] < 0.) buff[ip] = buff[ip]+1.;
        }
        ip = 23; jp=54; kp = 0;
    }
    i = kp;
    xva = buff[jp]+buff[ip];
    if( xva > 1.) xva = xva -1.;
    buff[kp] = xva;
    kp = (kp+1)%55;
    ip = (ip+1)%55;
    jp = (jp+1)%55;
    return buff[i];
}

canonical_original_code:
float randf()
{
    static float buff[55];
    static int ip = 0; static int jp = 0; static int kp;
    int i; int seed; int get_i_variable();
    static double xva;
    if( ip == 0 && jp == 0)
    {
        seed = get_i_variable("seed");
        for( ip=0; ip < 55; ip++)
        { seed = (seed*2349+14867)%32767;
            buff[ip] = (float)seed/32767.;
            if( buff[ip] > 1.) buff[ip] = buff[ip]-1.;
            if( buff[ip] < 0.) buff[ip] = buff[ip]+1.;
        }
        ip = 23; jp=54; kp = 0;
    }
    i = kp;
    xva = buff[jp]+buff[ip];
    if( xva > 1.) xva = xva -1.;
    buff[kp] = xva;
    kp = (kp+1)%55;
    ip = (ip+1)%55;
    jp = (jp+1)%55;
    return buff[i];
}

variable_types:
buff
float [55]

variable_types: ip int

variable_types: jp int

variable_types: kp int

variable_types: seed int

variable_types: xva double


randg

original_code:
float randg()
{
    float randf();
    float x1,x2,norm;
    norm = 2.;
    while( norm > 1.)
    {
        x1 = 2.*randf()-1; x2 = 2.*randf()-1;
        norm = x1*x1 + x2*x2;
    }
    if( norm < 1.e-9) norm = 1.e-9;
    return x1*sqrt( -2.*log(norm)/norm );
}

canonical_original_code:
float randg()
{
    float randf();
    float x1; float x2; float norm;
    norm = 2.;
    while( norm > 1.)
    {
        x1 = 2.*randf()-1; x2 = 2.*randf()-1;
        norm = x1*x1 + x2*x2;
    }
    if( norm < 1.e-9) norm = 1.e-9;
    return x1*sqrt( -2.*log(norm)/norm );
}

variable_types:
randf
float ()

variable_types: norm float


decompiled_code:
__int64 grasp_valid_coordinate()
{
__int64 result; // rax
int v1; // ebp
__int64 v2; // r13
int v3; // ebx
unsigned int v4; // er12
float *v5; // rax

result = a_number();
if ( (int)result > 0 )
{
v1 = result;
v2 = *(_QWORD *)(a_next(0xFFFFFFFFLL) + 80);
if ( v1 != 1 )
{
v3 = 1;
while ( 2 )
{
v4 = 0;
do
{
v5 = (float *)a_next(v4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)v2 - *v5) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 4) - v5[1]) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 8) - v5[2]) & LC0) < 0.1 )
{
return 0LL;
}
++v4;
}
while ( v4 != v3 );
++v3;
v2 = *(_QWORD *)(v2 + 80);
if ( v1 != v3 )
continue;
break;
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // ebp
__int64 v2; // r13
int v3; // ebx
unsigned int v4; // er12
float *v5; // rax

result = a_number();
if ( (int)result > 0 )
{
v1 = result;
v2 = *(_QWORD *)(a_next(0xFFFFFFFFLL) + 80);
if ( v1 != 1 )
{
v3 = 1;
while ( 2 )
{
v4 = 0;
do
{
v5 = (float *)a_next(v4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)v2 - *v5) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 4) - v5[1]) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 8) - v5[2]) & LC0) < 0.1 )
{
return 0LL;
}
++v4;
}
while ( v4 != v3 );
++v3;
v2 = *(_QWORD *)(v2 + 80);
if ( v1 != v3 )
continue;
break;
}
}
result = 1LL;
}
return result;
}

original_code:
int grasp_valid_coordinate()
{
    int na,a_number();
    ATOM *ap1,*ap2,*a_next();
    int i,j;
    float x,y,z;
    na = a_number();
    if( na < 1) return ;
    ap1 = a_next(-1);
    ap1 = ap1->next;
    for( i=1; i< na; i++)
    {
        for( j=0; j< i; j++)
        {
            ap2 = a_next(j);
            x = fabs(ap1->x -ap2->x);
            if( x < 1.e-1)
            {
                y = fabs(ap1->y -ap2->y);
                if( y < 1.e-1)
                {
                    z = fabs(ap1->z -ap2->z);
                    if( z< 1.e-1)
                    {
                        return 1==0;
                    }}}
        }
        ap1 = ap1->next;
    }
    return 1==1;
}

canonical_original_code:
int grasp_valid_coordinate()
{
    int na; int a_number();
    struct ATOM *ap1; struct ATOM *ap2; struct ATOM *a_next();
    int i; int j;
    float x; float y; float z;
    na = a_number();
    if( na < 1) return ;
    ap1 = a_next(-1);
    ap1 = ap1->next;
    for( i=1; i< na; i++)
    {
        for( j=0; j< i; j++)
        {
            ap2 = a_next(j);
            x = fabs(ap1->x -ap2->x);
            if( x < 1.e-1)
            {
                y = fabs(ap1->y -ap2->y);
                if( y < 1.e-1)
                {
                    z = fabs(ap1->z -ap2->z);
                    if( z< 1.e-1)
                    {
                        return 1==0;
                    }}}
        }
        ap1 = ap1->next;
    }
    return 1==1;
}

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *()

variable_types: j int

variable_types: x float

variable_types: y float

variable_types: z float


ghost

decompiled_code:
__int64 __fastcall ghost(int a1, int a2, int a3)
{
int v3; // er14
_QWORD *v5; // rax
__int64 v6; // r12
unsigned int v7; // ebp
unsigned int i; // ebx
__int64 v9; // rsi

v3 = a2;
v5 = malloc(0x18uLL);
if ( !v5 )
{
aaerror("memory allocation error in ghost\n");
exit(0);
}
v6 = firstGHOST;
firstGHOST = (__int64)v5;
v5[2] = v6;
if ( a2 > a3 )
{
v3 = a3;
a3 = a2;
}
*(_DWORD *)v5 = v3;
*((_DWORD *)v5 + 1) = a3;
for ( *((_DWORD *)v5 + 2) = a1; v6; v6 = *(_QWORD *)(v6 + 16) )
{
if ( *(_DWORD *)(v6 + 8) != a1 && v3 <= a3 )
{
v7 = v3;
do
{
for ( i = *(_DWORD *)v6; *(_DWORD *)(v6 + 4) >= (signed int)i; ++i )
{
v9 = i;
tailor_exclude(v7, v9);
}
++v7;
}
while ( a3 >= (int)v7 );
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
int v3; // er14
_QWORD *v5; // rax
__int64 v6; // r12
unsigned int v7; // ebp
unsigned int i; // ebx
__int64 v9; // rsi

v3 = a2;
v5 = malloc(0x18uLL);
if ( !v5 )
{
aaerror("memory allocation error in ghost\n");
exit(0);
}
v6 = firstGHOST;
firstGHOST = (__int64)v5;
v5[2] = v6;
if ( a2 > a3 )
{
v3 = a3;
a3 = a2;
}
*(_DWORD *)v5 = v3;
*((_DWORD *)v5 + 1) = a3;
for ( *((_DWORD *)v5 + 2) = a1; v6; v6 = *(_QWORD *)(v6 + 16) )
{
if ( *(_DWORD *)(v6 + 8) != a1 && v3 <= a3 )
{
v7 = v3;
do
{
for ( i = *(_DWORD *)v6; *(_DWORD *)(v6 + 4) >= (signed int)i; ++i )
{
v9 = i;
tailor_exclude(v7, v9);
}
++v7;
}
while ( a3 >= (int)v7 );
}
}
return 0LL;
}

original_code:
int ghost( int serial, int low, int high)
{
 int tailor_exclude(int,int);
 GHOST *gp;
 gp = (GHOST *)malloc( sizeof(GHOST));
 if( gp == ((void *)0)) {aaerror("memory allocation error in ghost\n"); exit(0);}
 gp->next_ghost = firstGHOST;
 firstGHOST = gp;
 if( low > high) { int i = low; low = high; high = i;}
 gp->low = low;
 gp->high = high;
 gp->serial = serial;
 while( gp->next_ghost != ((void *)0))
 {
  int i,j;
  gp = gp->next_ghost;
  if( gp->serial == serial) continue;
  for( i= low; i<= high; i++)
   for( j= gp->low; j <= gp->high; j++)
    tailor_exclude(i,j);
 }
 return 0;
}

canonical_original_code:
int ghost(int serial, int low, int high)
{
 int tailor_exclude(int, int);
 struct GHOST *gp;
 gp = (struct GHOST *)malloc( sizeof(GHOST));
 if( gp == ((void *)0)) {aaerror("memory allocation error in ghost\n"); exit(0);}
 gp->next_ghost = firstGHOST;
 firstGHOST = gp;
 if( low > high) { int i = low; low = high; high = i;}
 gp->low = low;
 gp->high = high;
 gp->serial = serial;
 while( gp->next_ghost != ((void *)0))
 {
  int i; int j;
  gp = gp->next_ghost;
  if( gp->serial == serial) continue;
  for( i= low; i<= high; i++)
   for( j= gp->low; j <= gp->high; j++)
    tailor_exclude(i,j);
 }
 return 0;
}

variable_types: serial int

variable_types: low int

variable_types: high int

variable_types: struct GHOST { int low; int serial; void *next_ghost; } *

variable_types: i int


decompiled_code:
__int64 gene_valid_coordinate()
{
__int64 result; // rax
int v1; // ebp
__int64 v2; // r13
int i; // ebx
unsigned int v4; // er12
float v5; // xmm2_4
float v6; // xmm3_4
float v7; // xmm1_4
float v8; // xmm2_4
float v9; // xmm3_4

result = a_number();
if ( (int)result > 0 )
{
v1 = result;
result = a_next(0xFFFFFFFFLL);
v2 = *(_QWORD *)(result + 80);
if ( v1 != 1 )
{
for ( i = 1; i != v1; ++i )
{
v4 = 0;
do
{
result = a_next(v4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)v2 - *(float *)result) & LC0) < 0.00001 )
{
v5 = *(float *)(result + 4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 4) - v5) & LC0) < 0.00001 )
{
v6 = *(float *)(result + 8);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 8) - v6) & LC0) < 0.00001 )
{
v7 = *(float *)result + 0.0001;
*(float *)result = v7;
v8 = v5 + 0.0001;
v9 = v6 + 0.0001;
*(float *)(result + 4) = v8;
*(float *)(result + 8) = v9;
}
}
}
++v4;
}
while ( v4 != i );
v2 = *(_QWORD *)(v2 + 80);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // ebp
__int64 v2; // r13
int i; // ebx
unsigned int v4; // er12
float v5; // xmm2_4
float v6; // xmm3_4
float v7; // xmm1_4
float v8; // xmm2_4
float v9; // xmm3_4

result = a_number();
if ( (int)result > 0 )
{
v1 = result;
result = a_next(0xFFFFFFFFLL);
v2 = *(_QWORD *)(result + 80);
if ( v1 != 1 )
{
for ( i = 1; i != v1; ++i )
{
v4 = 0;
do
{
result = a_next(v4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)v2 - *(float *)result) & LC0) < 0.00001 )
{
v5 = *(float *)(result + 4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 4) - v5) & LC0) < 0.00001 )
{
v6 = *(float *)(result + 8);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 8) - v6) & LC0) < 0.00001 )
{
v7 = *(float *)result + 0.0001;
*(float *)result = v7;
v8 = v5 + 0.0001;
v9 = v6 + 0.0001;
*(float *)(result + 4) = v8;
*(float *)(result + 8) = v9;
}
}
}
++v4;
}
while ( v4 != i );
v2 = *(_QWORD *)(v2 + 80);
}
}
}
return result;
}

original_code:
void gene_valid_coordinate()
{
    int na,a_number();
    ATOM *ap1,*ap2,*a_next();
    int i,j;
    float x,y,z;
    na = a_number();
    if( na < 1) return ;
    ap1 = a_next(-1);
    ap1 = ap1->next;
    for( i=1; i< na; i++)
    {
        for( j=0; j< i; j++)
        {
            ap2 = a_next(j);
            x = fabs(ap1->x -ap2->x);
            if( x < 1.e-5)
            {
                y = fabs(ap1->y -ap2->y);
                if( y < 1.e-5)
                {
                    z = fabs(ap1->z -ap2->z);
                    if( z< 1.e-5)
                    {
                        ap2->x += 1.e-4;
                        ap2->y += 1.e-4;
                        ap2->z += 1.e-4;
                    }}}
        }
        ap1 = ap1->next;
    }
}

canonical_original_code:
void gene_valid_coordinate()
{
    int na; int a_number();
    struct ATOM *ap1; struct ATOM *ap2; struct ATOM *a_next();
    int i; int j;
    float x; float y; float z;
    na = a_number();
    if( na < 1) return ;
    ap1 = a_next(-1);
    ap1 = ap1->next;
    for( i=1; i< na; i++)
    {
        for( j=0; j< i; j++)
        {
            ap2 = a_next(j);
            x = fabs(ap1->x -ap2->x);
            if( x < 1.e-5)
            {
                y = fabs(ap1->y -ap2->y);
                if( y < 1.e-5)
                {
                    z = fabs(ap1->z -ap2->z);
                    if( z< 1.e-5)
                    {
                        ap2->x += 1.e-4;
                        ap2->y += 1.e-4;
                        ap2->z += 1.e-4;
                    }}}
        }
        ap1 = ap1->next;
    }
}

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *


original_code:
int DILL_next( int i, ATOM **n1, ATOM **n2 )
{
static DILL *np = ((void *)0) ;
 *n1 = ((void *)0) ; *n2 = ((void *)0);
 if( DILL_first == ((void *)0) ) return (1==0);
 if( np == ((void *)0) || i <= 0 ) { np = DILL_first;}
  else{ np = np->next; }
  *n1 = np->atom1; *n2 = np->atom2;
  if( np->next != np)return (1==1);
  return ( 1== 0);
}

canonical_original_code:
int DILL_next(int i, struct ATOM **n1, struct ATOM **n2)
{
static struct DILL *np = ((void *)0);
 *n1 = ((void *)0) ; *n2 = ((void *)0);
 if( DILL_first == ((void *)0) ) return (1==0);
 if( np == ((void *)0) || i <= 0 ) { np = DILL_first;}
  else{ np = np->next; }
  *n1 = np->atom1; *n2 = np->atom2;
  if( np->next != np)return (1==1);
  return ( 1== 0);
}

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } **

variable_types: struct DILL { struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *atom1; float k; void *next; } *

user_defined_types: struct DILL { struct ATOM *atom1; float k; void *next; }


memset

repo: robbesol/xprintf

decompiled_code:
void memset()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void *memset(void *p, int val, size_t len) { }

canonical_original_code: void *memset(void *p, int val, unsigned long len) { }

variable_types:
p
void *

variable_types: val int

variable_types:
len
unsigned long

return_type: void *


fmod

decompiled_code:
void __fastcall fmod(double x, double y)
{
;
}

canonical_decompiled_code:
void __fastcall func1(double x, double y)
{
;
}

original_code: double fmod(double d1, double d2) { }

canonical_original_code: double fmod(double d1, double d2) { }

return_type: double


floor

decompiled_code:
// attributes: thunk
void __fastcall floor(double x)
{
ceil_localalias();
}

canonical_decompiled_code:
void __fastcall func3(double x)
{
func2();
}

original_code: double floor(double d) { }

canonical_original_code: double floor(double d) { }

variable_types: d double


fabs

decompiled_code:
// attributes: thunk
void __fastcall fabs(double x)
{
ceil_localalias();
}

canonical_decompiled_code:
void __fastcall func4(double x)
{
func2();
}

original_code: double fabs(double x) { }

canonical_original_code: double fabs(double x) { }

variable_types: x double


decompiled_code:
void __fastcall log10(double x)
{
;
}

canonical_decompiled_code:
void __fastcall func5(double x)
{
;
}

original_code: double log10(double d) { }

canonical_original_code: double log10(double d) { }


modf

decompiled_code:
void __fastcall modf(double x, double *ipart)
{
;
}

canonical_decompiled_code:
void __fastcall func6(double x, double *ipart)
{
;
}

original_code: double modf(double d, double *dp) { }

canonical_original_code: double modf(double d, double *dp) { }

variable_types:
dp
double *


doPointerOutput

decompiled_code:
int doPointerOutput()
{
zap = (char *)zap + 4;
fprintf(stderr, "%p", zap);
fprintf(stderr, " -- %s\n", "%p");
fprintf(stderr, "%#p", zap);
fprintf(stderr, " -- %s\n", "%#p");
fprintf(stderr, "%8p", zap);
fprintf(stderr, " -- %s\n", "%8p");
fprintf(stderr, "%#8p", zap);
fprintf(stderr, " -- %s\n", "%#8p");
fprintf(stderr, "%08p", zap);
fprintf(stderr, " -- %s\n", "%08p");
fprintf(stderr, "%#08p", zap);
fprintf(stderr, " -- %s\n", "%#08p");
fprintf(stderr, "%.8p", zap);
fprintf(stderr, " -- %s\n", "%.8p");
fprintf(stderr, "%#.8p", zap);
fprintf(stderr, " -- %s\n", "%#.8p");
fprintf(stderr, "%0.8p", zap);
fprintf(stderr, " -- %s\n", "%0.8p");
fprintf(stderr, "%#0.8p", zap);
fprintf(stderr, " -- %s\n", "%#0.8p");
fprintf(stderr, "%08.8p", zap);
fprintf(stderr, " -- %s\n", "%08.8p");
fprintf(stderr, "%#08.8p", zap);
return fprintf(stderr, " -- %s\n", "%#08.8p");
}

canonical_decompiled_code:
int func7()
{
zap = (char *)zap + 4;
fprintf(stderr, "%p", zap);
fprintf(stderr, " -- %s\n", "%p");
fprintf(stderr, "%#p", zap);
fprintf(stderr, " -- %s\n", "%#p");
fprintf(stderr, "%8p", zap);
fprintf(stderr, " -- %s\n", "%8p");
fprintf(stderr, "%#8p", zap);
fprintf(stderr, " -- %s\n", "%#8p");
fprintf(stderr, "%08p", zap);
fprintf(stderr, " -- %s\n", "%08p");
fprintf(stderr, "%#08p", zap);
fprintf(stderr, " -- %s\n", "%#08p");
fprintf(stderr, "%.8p", zap);
fprintf(stderr, " -- %s\n", "%.8p");
fprintf(stderr, "%#.8p", zap);
fprintf(stderr, " -- %s\n", "%#.8p");
fprintf(stderr, "%0.8p", zap);
fprintf(stderr, " -- %s\n", "%0.8p");
fprintf(stderr, "%#0.8p", zap);
fprintf(stderr, " -- %s\n", "%#0.8p");
fprintf(stderr, "%08.8p", zap);
fprintf(stderr, " -- %s\n", "%08.8p");
fprintf(stderr, "%#08.8p", zap);
return fprintf(stderr, " -- %s\n", "%#08.8p");
}

original_code:
static void doPointerOutput(void) {
 zap++;
 do {fprintf(stderr, "%p", zap); fprintf(stderr, " -- %s\n", "%p");} while (0);
 do {fprintf(stderr, "%#p", zap); fprintf(stderr, " -- %s\n", "%#p");} while (0);
 do {fprintf(stderr, "%8p", zap); fprintf(stderr, " -- %s\n", "%8p");} while (0);
 do {fprintf(stderr, "%#8p", zap); fprintf(stderr, " -- %s\n", "%#8p");} while (0);
 do {fprintf(stderr, "%08p", zap); fprintf(stderr, " -- %s\n", "%08p");} while (0);
 do {fprintf(stderr, "%#08p", zap); fprintf(stderr, " -- %s\n", "%#08p");} while (0);
 do {fprintf(stderr, "%.8p", zap); fprintf(stderr, " -- %s\n", "%.8p");} while (0);
 do {fprintf(stderr, "%#.8p", zap); fprintf(stderr, " -- %s\n", "%#.8p");} while (0);
 do {fprintf(stderr, "%0.8p", zap); fprintf(stderr, " -- %s\n", "%0.8p");} while (0);
 do {fprintf(stderr, "%#0.8p", zap); fprintf(stderr, " -- %s\n", "%#0.8p");} while (0);
 do {fprintf(stderr, "%08.8p", zap); fprintf(stderr, " -- %s\n", "%08.8p");} while (0);
 do {fprintf(stderr, "%#08.8p", zap); fprintf(stderr, " -- %s\n", "%#08.8p");} while (0);
}

canonical_original_code:
static void doPointerOutput() {
 zap++;
 do {fprintf(stderr, "%p", zap); fprintf(stderr, " -- %s\n", "%p");} while (0);
 do {fprintf(stderr, "%#p", zap); fprintf(stderr, " -- %s\n", "%#p");} while (0);
 do {fprintf(stderr, "%8p", zap); fprintf(stderr, " -- %s\n", "%8p");} while (0);
 do {fprintf(stderr, "%#8p", zap); fprintf(stderr, " -- %s\n", "%#8p");} while (0);
 do {fprintf(stderr, "%08p", zap); fprintf(stderr, " -- %s\n", "%08p");} while (0);
 do {fprintf(stderr, "%#08p", zap); fprintf(stderr, " -- %s\n", "%#08p");} while (0);
 do {fprintf(stderr, "%.8p", zap); fprintf(stderr, " -- %s\n", "%.8p");} while (0);
 do {fprintf(stderr, "%#.8p", zap); fprintf(stderr, " -- %s\n", "%#.8p");} while (0);
 do {fprintf(stderr, "%0.8p", zap); fprintf(stderr, " -- %s\n", "%0.8p");} while (0);
 do {fprintf(stderr, "%#0.8p", zap); fprintf(stderr, " -- %s\n", "%#0.8p");} while (0);
 do {fprintf(stderr, "%08.8p", zap); fprintf(stderr, " -- %s\n", "%08.8p");} while (0);
 do {fprintf(stderr, "%#08.8p", zap); fprintf(stderr, " -- %s\n", "%#08.8p");} while (0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
doPointerOutput(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
return 0;
}

original_code:
int main(void) {
 doPointerOutput();
 return 0;
}

canonical_original_code:
int main() {
 doPointerOutput();
 return 0;
}


decompiled_code:
__int64 xprintf__debug2host(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return xprintf__debug2hostV(a1, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return xprintf__debug2hostV(a1, va);
}

original_code:
void xprintf__debug2host(const char *format, ...) {
 va_list ap;
 __builtin_va_start(ap,format);
 xprintf__debug2hostV(format, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void xprintf__debug2host(char *format, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 xprintf__debug2hostV(format, ap);
 __builtin_va_end(ap);
}

variable_types:
format
char *


decompiled_code:
__int64 __fastcall xprintf__debugFormatV(const char *a1, char *a2, char a3, __int64 a4, __int64 a5)
{
const char *v9; // rdi
char v10; // al
__int64 v11; // rsi
__int64 v12; // rsi

xprintf__debug2host((__int64)"***** xvprintf(\"%s\"", a1);
v9 = " == ?)\n";
if ( a2 )
{
xprintf__debug2host((__int64)" -> ");
if ( a2[16] )
xprintf__debug2host((__int64)"%c ", (unsigned int)a2[16]);
xprintf__debug2host((__int64)"\"%%");
v10 = *a2;
if ( (*a2 & 8) != 0 )
{
xprintf__debug2host((__int64)"#");
v10 = *a2;
}
if ( (v10 & 4) != 0 )
{
xprintf__debug2host((__int64)" ");
v10 = *a2;
}
if ( (v10 & 2) != 0 )
{
xprintf__debug2host((__int64)a0);
v10 = *a2;
}
if ( (v10 & 1) != 0 )
{
xprintf__debug2host((__int64)&a0[1]);
v10 = *a2;
}
if ( (v10 & 0x10) != 0 )
xprintf__debug2host((__int64)&a0[2]);
v11 = *((unsigned int *)a2 + 1);
if ( (_DWORD)v11 )
xprintf__debug2host((__int64)"%d", v11);
v12 = *((unsigned int *)a2 + 2);
if ( (int)v12 >= 0 )
xprintf__debug2host((__int64)".%d", v12);
xprintf__debug2host((__int64)"%c\"", (unsigned int)a3);
xprintf__debug2host((__int64)" base %d): ", *((unsigned int *)a2 + 3));
xprintf__debug2hostV(a4, a5);
v9 = "\n";
}
return xprintf__debug2host((__int64)v9);
}

original_code:
void xprintf__debugFormatV(const char * const format,
  const struct xprintf__conversionPparams *params, char consSpec,
  const char *msgFmt, va_list ap) {
 xprintf__debug2host("***** xvprintf(\"%s\"", format);
 if (params == 0) {
  xprintf__debug2host(" == ?)\n");
  return;
 }
 xprintf__debug2host(" -> ");
 if (params->sign != '\0') {
  xprintf__debug2host("%c ", params->sign);
 }
 xprintf__debug2host("\"%%");
 if (params->flags.alternative) {
  xprintf__debug2host("#");
 }
 if (params->flags.signspace) {
  xprintf__debug2host(" ");
 }
 if (params->flags.signplus) {
  xprintf__debug2host("+");
 }
 if (params->flags.leftjustified) {
  xprintf__debug2host("-");
 }
 if (params->flags.leadingzeroes) {
  xprintf__debug2host("0");
 }
 if (params->minWidth != 0) {
  xprintf__debug2host("%d", params->minWidth);
 }
 if (params->precision >= 0) {
  xprintf__debug2host(".%d", params->precision);
 }
 xprintf__debug2host("%c\"", consSpec);
 xprintf__debug2host(" base %d): ", params->digitBase);
 xprintf__debug2hostV(msgFmt, ap);
 xprintf__debug2host("\n");
}

canonical_original_code:
void xprintf__debugFormatV(char *format, struct xprintf__conversionPparams *params, char consSpec, char *msgFmt, __builtin_va_list ap) {
 xprintf__debug2host("***** xvprintf(\"%s\"", format);
 if (params == 0) {
  xprintf__debug2host(" == ?)\n");
  return;
 }
 xprintf__debug2host(" -> ");
 if (params->sign != '\0') {
  xprintf__debug2host("%c ", params->sign);
 }
 xprintf__debug2host("\"%%");
 if (params->flags.alternative) {
  xprintf__debug2host("#");
 }
 if (params->flags.signspace) {
  xprintf__debug2host(" ");
 }
 if (params->flags.signplus) {
  xprintf__debug2host("+");
 }
 if (params->flags.leftjustified) {
  xprintf__debug2host("-");
 }
 if (params->flags.leadingzeroes) {
  xprintf__debug2host("0");
 }
 if (params->minWidth != 0) {
  xprintf__debug2host("%d", params->minWidth);
 }
 if (params->precision >= 0) {
  xprintf__debug2host(".%d", params->precision);
 }
 xprintf__debug2host("%c\"", consSpec);
 xprintf__debug2host(" base %d): ", params->digitBase);
 xprintf__debug2hostV(msgFmt, ap);
 xprintf__debug2host("\n");
}

variable_types: struct xprintf__conversionPparams { struct xprintf__conversionFlags { unsigned int leftjustified; unsigned int signplus; unsigned int signspace; unsigned int alternative; unsigned int leadingzeroes; unsigned int upper; } flags; int minWidth; int precision; unsigned int digitBase; char sign; enum xprintf__conversionSpec { convUnsupportedUnknown=0, convSignedIntegral=1, convUnsignedIntegral=2, convDoubleExponent=3, convDoubleFixed=4, convDoubleGeneral=5, convChar=6, convString=7, convPercent=8, convDoubleUnsupported=9, convPointer=10, convStoreCount=11, _conv_count=12 } convSpec; enum conversionSize { sizeDefault=0, sizeChar=1, sizeShort=2, sizeLong=3, sizeLongLong=4, sizeIntmax_t=5, sizeSize_t=6, sizePtrdiff_t=7, sizeLongDouble=8, _size_count=9 } argLength; } *

variable_types: consSpec char

variable_types:
msgFmt
char *

user_defined_types: struct xprintf__conversionPparams { struct xprintf__conversionFlags flags; int minWidth; int precision; unsigned int digitBase; char sign; enum xprintf__conversionSpec convSpec; enum conversionSize argLength; }


decompiled_code:
int log_ID(const char *a1, const char **a2, const char *a3, ...)
{
const char *v4; // rcx
const char *v5; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( a1 )
fprintf(stderr, "%s", a1);
if ( a2 )
{
v4 = a2[1];
v5 = *a2;
if ( v4 )
fprintf(stderr, "%s/%s", v5, v4);
else
fprintf(stderr, "%s", v5);
}
else
{
fprintf(stderr, "[NULLname/NULLtest]");
}
va_start(arg, a3);
return vfprintf(stderr, a3, arg);
}

canonical_decompiled_code:
int func0(const char *a1, const char **a2, const char *a3, ...)
{
const char *v4; // rcx
const char *v5; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( a1 )
fprintf(stderr, "%s", a1);
if ( a2 )
{
v4 = a2[1];
v5 = *a2;
if ( v4 )
fprintf(stderr, "%s/%s", v5, v4);
else
fprintf(stderr, "%s", v5);
}
else
{
fprintf(stderr, "[NULLname/NULLtest]");
}
va_start(arg, a3);
return vfprintf(stderr, a3, arg);
}

original_code:
static void log_ID(const char *pre, const struct test_printf_info *tpip,
  const char *postFmt, ...) {
 if (pre != 0) {
  fprintf(stderr, "%s", pre);
 }
 if (tpip == 0)
  fprintf(stderr, "[NULLname/NULLtest]");
 else if (tpip->test_name == 0)
  fprintf(stderr, "%s", tpip->test_subjectName);
 else
  fprintf(stderr, "%s/%s", tpip->test_subjectName, tpip->test_name);
 if (postFmt != 0) {
  va_list ap;
  __builtin_va_start(ap,postFmt);
  vfprintf(stderr, postFmt, ap);
  __builtin_va_end(ap);
 }
}

canonical_original_code:
static void log_ID(char *pre, struct test_printf_info *tpip, char *postFmt, ...) {
 if (pre != 0) {
  fprintf(stderr, "%s", pre);
 }
 if (tpip == 0)
  fprintf(stderr, "[NULLname/NULLtest]");
 else if (tpip->test_name == 0)
  fprintf(stderr, "%s", tpip->test_subjectName);
 else
  fprintf(stderr, "%s/%s", tpip->test_subjectName, tpip->test_name);
 if (postFmt != 0) {
  __builtin_va_list ap;
  __builtin_va_start(ap,postFmt);
  vfprintf(stderr, postFmt, ap);
  __builtin_va_end(ap);
 }
}

variable_types:
pre
char *

variable_types: struct test_printf_info { char *test_subjectName; char *test_name; int (*test_printf_p)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap); int tests_total; int tests_failed; int tests_grandtotal; int tests_grandfailed; char *curtest_poshead; } *

variable_types:
postFmt
char *


handleProgError

decompiled_code:
void __noreturn handleProgError(const char **a1, const char *a2, ...)
{
const char *v2; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

fflush(stdout);
fprintf(stderr, "\n##### PROGRAM error");
if ( a1 )
{
fprintf(stderr, " with %s", *a1);
v2 = a1[1];
if ( v2 )
fprintf(stderr, "/%s", v2);
}
va_start(arg, a2);
vfprintf(stderr, a2, arg);
fprintf(stderr, "\n");
fflush(stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(const char **a1, const char *a2, ...)
{
const char *v2; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

fflush(stdout);
fprintf(stderr, "\n##### PROGRAM error");
if ( a1 )
{
fprintf(stderr, " with %s", *a1);
v2 = a1[1];
if ( v2 )
fprintf(stderr, "/%s", v2);
}
va_start(arg, a2);
vfprintf(stderr, a2, arg);
fprintf(stderr, "\n");
fflush(stderr);
exit(1);
}

original_code:
int handleProgError(const struct test_printf_info * tpi, const char *msg, ...) {
 fflush(stdout);
 fprintf(stderr, "\n##### PROGRAM error");
 if (tpi != 0) {
  fprintf(stderr, " with %s", tpi->test_subjectName);
  if (tpi->test_name != 0)
   fprintf(stderr, "/%s", tpi->test_name);
 }
 va_list ap;
 __builtin_va_start(ap,msg);
 vfprintf(stderr, msg, ap);
 __builtin_va_end(ap);
 fprintf(stderr, "\n");
 fflush(stderr);
 exit(1);
 return -1;
}

canonical_original_code:
int handleProgError(struct test_printf_info *tpi, char *msg, ...) {
 fflush(stdout);
 fprintf(stderr, "\n##### PROGRAM error");
 if (tpi != 0) {
  fprintf(stderr, " with %s", tpi->test_subjectName);
  if (tpi->test_name != 0)
   fprintf(stderr, "/%s", tpi->test_name);
 }
 __builtin_va_list ap;
 __builtin_va_start(ap,msg);
 vfprintf(stderr, msg, ap);
 __builtin_va_end(ap);
 fprintf(stderr, "\n");
 fflush(stderr);
 exit(1);
 return -1;
}

variable_types:
msg
char *

user_defined_types: struct test_printf_info { char *test_subjectName; char *test_name; int (*test_printf_p)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap); int tests_total; int tests_failed; int tests_grandtotal; int tests_grandfailed; char *curtest_poshead; }


initTPI

decompiled_code:
__int64 __fastcall initTPI(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "initTPI", "tpi");
if ( !a2 )
handleProgError((const char **)a1, " %s() called with %s NULL\n", "initTPI", "name");
if ( !a3 )
handleProgError((const char **)a1, " %s() called with %s NULL\n", "initTPI", "fn");
result = 0xFFFFFFFFLL;
*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = a3;
*(_QWORD *)(a1 + 24) = 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "initTPI", "tpi");
if ( !a2 )
func1((const char **)a1, " %s() called with %s NULL\n", "initTPI", "name");
if ( !a3 )
func1((const char **)a1, " %s() called with %s NULL\n", "initTPI", "fn");
result = 0xFFFFFFFFLL;
*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = a3;
*(_QWORD *)(a1 + 24) = 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
static void initTPI(struct test_printf_info *tpi, const char name[],
  test_printf_p fn) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 while (name == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "name");
 while (fn == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "fn");
 tpi->test_subjectName = name;
 tpi->test_name = 0;
 tpi->test_printf_p = fn;
 tpi->tests_total = -1;
 tpi->tests_failed = 0;
 tpi->tests_grandtotal = 0;
 tpi->tests_grandfailed = 0;
}

canonical_original_code:
static void initTPI(struct test_printf_info *tpi, char name[], int (*fn)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap)) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 while (name == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "name");
 while (fn == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "fn");
 tpi->test_subjectName = name;
 tpi->test_name = 0;
 tpi->test_printf_p = fn;
 tpi->tests_total = -1;
 tpi->tests_failed = 0;
 tpi->tests_grandtotal = 0;
 tpi->tests_grandfailed = 0;
}

variable_types:
name
char []

variable_types: int (*)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap)


writeErrorHeader

decompiled_code:
int __fastcall writeErrorHeader(__int64 a1, const char *a2)
{
const char *v2; // r12
int result; // eax

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "writeErrorHeader", "tpi");
v2 = *(const char **)(a1 + 40);
++*(_DWORD *)(a1 + 24);
++*(_DWORD *)(a1 + 32);
++*(_DWORD *)(a1 + 28);
++*(_DWORD *)(a1 + 36);
if ( !v2 )
v2 = "[unknown file.pos]: ";
fprintf(stderr, "==========\n");
result = log_ID(v2, (const char **)a1, " failed");
if ( a2 )
result = fprintf(stderr, " for \"%s\"", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2)
{
const char *v2; // r12
int result; // eax

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "writeErrorHeader", "tpi");
v2 = *(const char **)(a1 + 40);
++*(_DWORD *)(a1 + 24);
++*(_DWORD *)(a1 + 32);
++*(_DWORD *)(a1 + 28);
++*(_DWORD *)(a1 + 36);
if ( !v2 )
v2 = "[unknown file.pos]: ";
fprintf(stderr, "==========\n");
result = func0(v2, (const char **)a1, " failed");
if ( a2 )
result = fprintf(stderr, " for \"%s\"", a2);
return result;
}

original_code:
static void writeErrorHeader(struct test_printf_info * tpi, const char *format) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 tpi->tests_total++;
 tpi->tests_grandtotal++;
 tpi->tests_failed++;
 tpi->tests_grandfailed++;
 const char *posid = tpi->curtest_poshead;
 if (posid == 0) {
  posid = "[unknown file.pos]: ";
 }
 fprintf(stderr, "==========\n");
 log_ID(posid, tpi, " failed");
 if (format != 0) {
  fprintf(stderr, " for \"%s\"", format);
 }
}

canonical_original_code:
static void writeErrorHeader(struct test_printf_info *tpi, char *format) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 tpi->tests_total++;
 tpi->tests_grandtotal++;
 tpi->tests_failed++;
 tpi->tests_grandfailed++;
 char *posid = tpi->curtest_poshead;
 if (posid == 0) {
  posid = "[unknown file.pos]: ";
 }
 fprintf(stderr, "==========\n");
 log_ID(posid, tpi, " failed");
 if (format != 0) {
  fprintf(stderr, " for \"%s\"", format);
 }
}

variable_types:
posid
char *


startAllTests

decompiled_code:
__int64 __fastcall startAllTests(const char ***a1, __int64 a2, __int64 a3)
{
const char **v4; // rax
const char **v5; // rbp
__int64 result; // rax
__int64 v7; // rdx

if ( !a1 )
handleProgError(0LL, " %s() called with tpip NULL\n", "startAllTests");
v4 = (const char **)malloc(0x30uLL);
v5 = v4;
if ( !v4 )
{
fflush(stdout);
fprintf(stderr, "##### error: malloc(sizeof (struct test_printf_info)) failed\n");
fflush(stderr);
exit(1);
}
result = initTPI((__int64)v4, a2, a3);
v7 = *((unsigned int *)v5 + 9);
if ( (int)v7 < 0 )
handleProgError(v5, ": initTPI weird grand: %d/%d\n", v7, *((unsigned int *)v5 + 8));
*a1 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char ***a1, __int64 a2, __int64 a3)
{
const char **v4; // rax
const char **v5; // rbp
__int64 result; // rax
__int64 v7; // rdx

if ( !a1 )
func1(0LL, " %s() called with tpip NULL\n", "startAllTests");
v4 = (const char **)malloc(0x30uLL);
v5 = v4;
if ( !v4 )
{
fflush(stdout);
fprintf(stderr, "##### error: malloc(sizeof (struct test_printf_info)) failed\n");
fflush(stderr);
exit(1);
}
result = func2((__int64)v4, a2, a3);
v7 = *((unsigned int *)v5 + 9);
if ( (int)v7 < 0 )
func1(v5, ": initTPI weird grand: %d/%d\n", v7, *((unsigned int *)v5 + 8));
*a1 = v5;
return result;
}

original_code:
void startAllTests(struct test_printf_info **tpip, const char name[],
  test_printf_p fn) {
 if (tpip == 0) {
  handleProgError(0, " %s() called with tpip NULL\n", __func__);
 }
 struct test_printf_info *tpi = malloc(sizeof *tpi);
 if (tpi == 0) {
  fflush(stdout);
  fprintf(stderr,
    "##### error: malloc(sizeof (struct test_printf_info)) failed\n");
  fflush(stderr);
  exit(1);
 }
 initTPI(tpi, name, fn);
 if (tpi->tests_grandfailed < 0) {
  handleProgError(tpi, ": initTPI weird grand: %d/%d\n",
    tpi->tests_grandfailed, tpi->tests_grandtotal);
 }
 *tpip = tpi;
}

canonical_original_code:
void startAllTests(struct test_printf_info **tpip, char name[], int (*fn)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap)) {
 if (tpip == 0) {
  handleProgError(0, " %s() called with tpip NULL\n", __func__);
 }
 struct test_printf_info *tpi = malloc(sizeof *tpi);
 if (tpi == 0) {
  fflush(stdout);
  fprintf(stderr,
    "##### error: malloc(sizeof (struct test_printf_info)) failed\n");
  fflush(stderr);
  exit(1);
 }
 initTPI(tpi, name, fn);
 if (tpi->tests_grandfailed < 0) {
  handleProgError(tpi, ": initTPI weird grand: %d/%d\n",
    tpi->tests_grandfailed, tpi->tests_grandtotal);
 }
 *tpip = tpi;
}

variable_types: struct test_printf_info { char *test_subjectName; char *test_name; int (*test_printf_p)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap); int tests_total; int tests_failed; int tests_grandtotal; int tests_grandfailed; char *curtest_poshead; } **


endAllTests

decompiled_code:
__int64 __fastcall endAllTests(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rcx

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "endAllTests", "tpi");
v1 = *(unsigned int *)(a1 + 32);
if ( (_DWORD)v1 )
{
v2 = *(unsigned int *)(a1 + 36);
if ( (int)v2 > 0 )
{
log_ID("----- ", (const char **)a1, " had errors: %d/%d\n", v2, v1);
}
else if ( (_DWORD)v2 )
{
log_ID("----- ", (const char **)a1, " weird: %d/%d\n", v2, v1);
}
else
{
log_ID("----- ", (const char **)a1, ": no errors\n");
}
}
else
{
log_ID("----- ", (const char **)a1, ": no tests done\n");
}
if ( *(int *)(a1 + 24) >= 0 )
handleProgError((const char **)a1, ": last tests not endTests()ed");
return *(unsigned int *)(a1 + 36);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rcx

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "endAllTests", "tpi");
v1 = *(unsigned int *)(a1 + 32);
if ( (_DWORD)v1 )
{
v2 = *(unsigned int *)(a1 + 36);
if ( (int)v2 > 0 )
{
func0("----- ", (const char **)a1, " had errors: %d/%d\n", v2, v1);
}
else if ( (_DWORD)v2 )
{
func0("----- ", (const char **)a1, " weird: %d/%d\n", v2, v1);
}
else
{
func0("----- ", (const char **)a1, ": no errors\n");
}
}
else
{
func0("----- ", (const char **)a1, ": no tests done\n");
}
if ( *(int *)(a1 + 24) >= 0 )
func1((const char **)a1, ": last tests not endTests()ed");
return *(unsigned int *)(a1 + 36);
}

original_code:
int endAllTests(struct test_printf_info *tpi) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 if (tpi->tests_grandtotal == 0) {
  log_ID("----- ", tpi, ": no tests done\n");
 } else if (tpi->tests_grandfailed > 0) {
  log_ID("----- ", tpi, " had errors: %d/%d\n", tpi->tests_grandfailed,
    tpi->tests_grandtotal);
 } else if (tpi->tests_grandfailed < 0) {
  log_ID("----- ", tpi, " weird: %d/%d\n", tpi->tests_grandfailed,
    tpi->tests_grandtotal);
 } else {
  log_ID("----- ", tpi, ": no errors\n");
 }
 if (tpi->tests_total >= 0) {
  handleProgError(tpi, ": last tests not endTests()ed");
 }
 return tpi->tests_grandfailed;
}


startTests

decompiled_code:
int __fastcall startTests(__int64 a1, const char *a2)
{
__int64 v2; // rcx
size_t v3; // rbx
int result; // eax
char s[30]; // [rsp+Ah] [rbp-1Eh] BYREF

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "startTests", "tpi");
if ( !a2 )
handleProgError((const char **)a1, " %s() called with %s NULL\n", "startTests", "test_name");
v2 = *(unsigned int *)(a1 + 36);
if ( (int)v2 < 0 )
handleProgError((const char **)a1, ": startTests(\"%s\") weird grand: %d/%d\n", a2, v2, *(unsigned int *)(a1 + 32));
if ( *(int *)(a1 + 24) >= 0 )
handleProgError((const char **)a1, ": last tests not endTests()ed");
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 24) = 0LL;
strcpy(s, "test_");
v3 = (int)strlen(s);
result = strncmp(a2, s, v3);
if ( !result )
*(_QWORD *)(a1 + 8) = &a2[v3];
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, const char *a2)
{
__int64 v2; // rcx
size_t v3; // rbx
int result; // eax
char s[30]; // [rsp+Ah] [rbp-1Eh] BYREF

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "startTests", "tpi");
if ( !a2 )
func1((const char **)a1, " %s() called with %s NULL\n", "startTests", "test_name");
v2 = *(unsigned int *)(a1 + 36);
if ( (int)v2 < 0 )
func1((const char **)a1, ": startTests(\"%s\") weird grand: %d/%d\n", a2, v2, *(unsigned int *)(a1 + 32));
if ( *(int *)(a1 + 24) >= 0 )
func1((const char **)a1, ": last tests not endTests()ed");
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 24) = 0LL;
strcpy(s, "test_");
v3 = (int)strlen(s);
result = strncmp(a2, s, v3);
if ( !result )
*(_QWORD *)(a1 + 8) = &a2[v3];
return result;
}

original_code:
void startTests(struct test_printf_info * tpi, const char test_name[]) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 while (test_name == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "test_name");;
 if (tpi->tests_grandfailed < 0) {
  handleProgError(tpi, ": startTests(\"%s\") weird grand: %d/%d\n",
    test_name, tpi->tests_grandfailed, tpi->tests_grandtotal);
 }
 if (tpi->tests_total >= 0) {
  handleProgError(tpi, ": last tests not endTests()ed");
 }
 tpi->tests_total = 0;
 tpi->tests_failed = 0;
 tpi->test_name = test_name;
 const char name_prefix[] = "test_";
 const int name_prefix_len = strlen(name_prefix);
 if (0 == strncmp(test_name, name_prefix, name_prefix_len)) {
  tpi->test_name = test_name + name_prefix_len;
 }
}

canonical_original_code:
void startTests(struct test_printf_info *tpi, char test_name[]) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 while (test_name == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "test_name");;
 if (tpi->tests_grandfailed < 0) {
  handleProgError(tpi, ": startTests(\"%s\") weird grand: %d/%d\n",
    test_name, tpi->tests_grandfailed, tpi->tests_grandtotal);
 }
 if (tpi->tests_total >= 0) {
  handleProgError(tpi, ": last tests not endTests()ed");
 }
 tpi->tests_total = 0;
 tpi->tests_failed = 0;
 tpi->test_name = test_name;
 char name_prefix[] = "test_";
 int name_prefix_len = strlen(name_prefix);
 if (0 == strncmp(test_name, name_prefix, name_prefix_len)) {
  tpi->test_name = test_name + name_prefix_len;
 }
}


endTests

decompiled_code:
__int64 __fastcall endTests(__int64 a1)
{
__int64 v1; // rcx

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "endTests", "tpi");
v1 = *(unsigned int *)(a1 + 36);
if ( (int)v1 < 0 )
handleProgError(
(const char **)a1,
": endTests(\"%s\") weird grand: %d/%d\n",
*(const char **)(a1 + 8),
v1,
*(unsigned int *)(a1 + 32));
if ( *(int *)(a1 + 28) > 0 )
fprintf(stderr, "==========\n");
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 24) = 0xFFFFFFFFLL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rcx

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "endTests", "tpi");
v1 = *(unsigned int *)(a1 + 36);
if ( (int)v1 < 0 )
func1(
(const char **)a1,
": endTests(\"%s\") weird grand: %d/%d\n",
*(const char **)(a1 + 8),
v1,
*(unsigned int *)(a1 + 32));
if ( *(int *)(a1 + 28) > 0 )
fprintf(stderr, "==========\n");
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 24) = 0xFFFFFFFFLL;
return 0LL;
}

original_code:
int endTests(struct test_printf_info * tpi) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 if (tpi->tests_grandfailed < 0) {
  handleProgError(tpi, ": endTests(\"%s\") weird grand: %d/%d\n",
    tpi->test_name, tpi->tests_grandfailed, tpi->tests_grandtotal);
 }
 if (tpi->tests_failed > 0) {
  fprintf(stderr, "==========\n");
 }
 tpi->test_name = 0;
 tpi->tests_total = -1;
 tpi->tests_failed = 0;
 return tpi->tests_failed;
}

canonical_original_code:
int endTests(struct test_printf_info *tpi) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 if (tpi->tests_grandfailed < 0) {
  handleProgError(tpi, ": endTests(\"%s\") weird grand: %d/%d\n",
    tpi->test_name, tpi->tests_grandfailed, tpi->tests_grandtotal);
 }
 if (tpi->tests_failed > 0) {
  fprintf(stderr, "==========\n");
 }
 tpi->test_name = 0;
 tpi->tests_total = -1;
 tpi->tests_failed = 0;
 return tpi->tests_failed;
}


logSuccess

decompiled_code:
void __fastcall logSuccess(__int64 a1)
{
if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "logSuccess", "tpi");
++*(_DWORD *)(a1 + 24);
++*(_DWORD *)(a1 + 32);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "logSuccess", "tpi");
++*(_DWORD *)(a1 + 24);
++*(_DWORD *)(a1 + 32);
}

original_code:
void logSuccess(struct test_printf_info * tpi, const char *expected,
  int expectedLen, const char *format) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 (void) expected;
 (void) expectedLen;
 (void) format;
 tpi->tests_total++;
 tpi->tests_grandtotal++;
}

canonical_original_code:
void logSuccess(struct test_printf_info *tpi, char *expected, int expectedLen, char *format) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 (void) expected;
 (void) expectedLen;
 (void) format;
 tpi->tests_total++;
 tpi->tests_grandtotal++;
}

variable_types:
expected
char *

variable_types: expectedLen int


logErrorRemark

decompiled_code:
int logErrorRemark(__int64 a1, const char *a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
writeErrorHeader(a1, a2);
fprintf(stderr, " ");
vfprintf(stderr, a3, arg);
return fprintf(stderr, "\n");
}

canonical_decompiled_code:
int func9(__int64 a1, const char *a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
func3(a1, a2);
fprintf(stderr, " ");
vfprintf(stderr, a3, arg);
return fprintf(stderr, "\n");
}

original_code:
void logErrorRemark(struct test_printf_info * tpi, const char *format,
  const char *msgFmt, ...) {
 writeErrorHeader(tpi, format);
 fprintf(stderr, " ");
 va_list va;
 __builtin_va_start(va,msgFmt);
 vfprintf(stderr, msgFmt, va);
 __builtin_va_end(va);
 fprintf(stderr, "\n");
}

canonical_original_code:
void logErrorRemark(struct test_printf_info *tpi, char *format, char *msgFmt, ...) {
 writeErrorHeader(tpi, format);
 fprintf(stderr, " ");
 __builtin_va_list va;
 __builtin_va_start(va,msgFmt);
 vfprintf(stderr, msgFmt, va);
 __builtin_va_end(va);
 fprintf(stderr, "\n");
}


logErrorResult

decompiled_code:
int __fastcall logErrorResult(__int64 a1, const char *a2, unsigned int a3, const char *a4, const char *a5, int a6)
{
const char *v9; // r12

writeErrorHeader(a1, a4);
v9 = *(const char **)(a1 + 40);
if ( !v9 )
v9 = (const char *)&unk_D74;
fprintf(stderr, "\n%s expected: %3d ", v9, a3);
if ( a2 )
fprintf(stderr, "\"%.*s\"", a3, a2);
else
fprintf(stderr, "null");
fprintf(stderr, "\n%s got: %3d ", v9, (unsigned int)a6);
if ( !a5 )
{
fprintf(stderr, "null");
if ( a6 >= 0 )
return fprintf(stderr, "\n");
LABEL_10:
fprintf(stderr, " -- returned ERRORCODE %d", (unsigned int)a6);
return fprintf(stderr, "\n");
}
fprintf(stderr, "\"%.*s\"", a6, a5);
if ( a6 < 0 )
goto LABEL_10;
return fprintf(stderr, "\n");
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, const char *a2, unsigned int a3, const char *a4, const char *a5, int a6)
{
const char *v9; // r12

func3(a1, a4);
v9 = *(const char **)(a1 + 40);
if ( !v9 )
v9 = (const char *)&unk_D74;
fprintf(stderr, "\n%s expected: %3d ", v9, a3);
if ( a2 )
fprintf(stderr, "\"%.*s\"", a3, a2);
else
fprintf(stderr, "null");
fprintf(stderr, "\n%s got: %3d ", v9, (unsigned int)a6);
if ( !a5 )
{
fprintf(stderr, "null");
if ( a6 >= 0 )
return fprintf(stderr, "\n");
LABEL_10:
fprintf(stderr, " -- returned ERRORCODE %d", (unsigned int)a6);
return fprintf(stderr, "\n");
}
fprintf(stderr, "\"%.*s\"", a6, a5);
if ( a6 < 0 )
goto LABEL_10;
return fprintf(stderr, "\n");
}

original_code:
void logErrorResult(struct test_printf_info * tpi, const char *expected,
  int expectedLen, const char *format, const char *result, int resultLen) {
 writeErrorHeader(tpi, format);
 char *head = tpi->curtest_poshead;
 if (head == 0) {
  head = "";
 }
 fprintf(stderr, "\n%s expected: %3d ", head, expectedLen);
 if (expected == 0) {
  fprintf(stderr, "null");
 } else {
  fprintf(stderr, "\"%.*s\"", expectedLen, expected);
 }
 fprintf(stderr, "\n%s      got: %3d ", head, resultLen);
 if (result == 0) {
  fprintf(stderr, "null");
 } else {
  fprintf(stderr, "\"%.*s\"", resultLen, result);
 }
 if (resultLen < 0) {
  fprintf(stderr, " -- returned ERRORCODE %d", resultLen);
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void logErrorResult(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, char *result, int resultLen) {
 writeErrorHeader(tpi, format);
 char *head = tpi->curtest_poshead;
 if (head == 0) {
  head = "";
 }
 fprintf(stderr, "\n%s expected: %3d ", head, expectedLen);
 if (expected == 0) {
  fprintf(stderr, "null");
 } else {
  fprintf(stderr, "\"%.*s\"", expectedLen, expected);
 }
 fprintf(stderr, "\n%s      got: %3d ", head, resultLen);
 if (result == 0) {
  fprintf(stderr, "null");
 } else {
  fprintf(stderr, "\"%.*s\"", resultLen, result);
 }
 if (resultLen < 0) {
  fprintf(stderr, " -- returned ERRORCODE %d", resultLen);
 }
 fprintf(stderr, "\n");
}

variable_types:
result
char *

variable_types: resultLen int

variable_types:
head
char *


compareResult

decompiled_code:
__int64 __fastcall compareResult(__int64 a1, const void *a2, signed int a3, const char *a4, const void *a5, int a6)
{
int v8; // eax
const void *v9; // [rsp+0h] [rbp-38h]
const char *v10; // [rsp+10h] [rbp-28h]
int v11; // [rsp+1Ch] [rbp-1Ch]

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "compareResult", "tpi");
if ( a3 >= 0 && a2 )
{
if ( a5 )
{
if ( a3 == a6 )
{
v11 = a6;
v10 = a4;
v9 = a5;
v8 = memcmp(a5, a2, a3);
a5 = v9;
a4 = v10;
a6 = v11;
if ( !v8 )
goto LABEL_8;
}
}
LABEL_6:
logErrorResult(a1, (const char *)a2, a3, a4, (const char *)a5, a6);
return 0LL;
}
if ( a6 >= 0 )
goto LABEL_6;
LABEL_8:
logSuccess(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const void *a2, signed int a3, const char *a4, const void *a5, int a6)
{
int v8; // eax
const void *v9; // [rsp+0h] [rbp-38h]
const char *v10; // [rsp+10h] [rbp-28h]
int v11; // [rsp+1Ch] [rbp-1Ch]

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "compareResult", "tpi");
if ( a3 >= 0 && a2 )
{
if ( a5 )
{
if ( a3 == a6 )
{
v11 = a6;
v10 = a4;
v9 = a5;
v8 = memcmp(a5, a2, a3);
a5 = v9;
a4 = v10;
a6 = v11;
if ( !v8 )
goto LABEL_8;
}
}
LABEL_6:
func10(a1, (const char *)a2, a3, a4, (const char *)a5, a6);
return 0LL;
}
if ( a6 >= 0 )
goto LABEL_6;
LABEL_8:
func8(a1);
return 1LL;
}

original_code:
int compareResult(struct test_printf_info * tpi, const char *expected,
  int expectedLen, const char *format, const char *result, int resultLen) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 int testPassed;
 if (expectedLen < 0 || expected == 0) {
  testPassed = resultLen < 0;
 } else if (result == 0) {
  testPassed = 0;
 } else {
  testPassed = resultLen == expectedLen
    && 0 == memcmp(result, expected, expectedLen);
 }
 if (testPassed) {
  logSuccess(tpi, expected, expectedLen, format);
 } else {
  logErrorResult(tpi, expected, expectedLen, format, result, resultLen);
 }
 return testPassed;
}

canonical_original_code:
int compareResult(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, char *result, int resultLen) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 int testPassed;
 if (expectedLen < 0 || expected == 0) {
  testPassed = resultLen < 0;
 } else if (result == 0) {
  testPassed = 0;
 } else {
  testPassed = resultLen == expectedLen
    && 0 == memcmp(result, expected, expectedLen);
 }
 if (testPassed) {
  logSuccess(tpi, expected, expectedLen, format);
 } else {
  logErrorResult(tpi, expected, expectedLen, format, result, resultLen);
 }
 return testPassed;
}

variable_types:
format
char *

variable_types: testPassed int


vtest

decompiled_code:
__int64 __fastcall vtest(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
size_t v6; // rax
const char *v8; // rcx

if ( !a1 )
handleProgError(0LL, " %s() called with %s NULL\n", "vtest", "tpi");
if ( !a2 )
{
v8 = "xanswer";
LABEL_7:
handleProgError((const char **)a1, " %s() called with %s NULL\n", "vtest", v8);
}
if ( !*(_QWORD *)(a1 + 16) )
{
v8 = "tpi->test_printf_p";
goto LABEL_7;
}
fflush(stdout);
v6 = strlen(a2);
return (*(__int64 (__fastcall **)(__int64, const char *, size_t, __int64, __int64))(a1 + 16))(a1, a2, v6, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
size_t v6; // rax
const char *v8; // rcx

if ( !a1 )
func1(0LL, " %s() called with %s NULL\n", "vtest", "tpi");
if ( !a2 )
{
v8 = "xanswer";
LABEL_7:
func1((const char **)a1, " %s() called with %s NULL\n", "vtest", v8);
}
if ( !*(_QWORD *)(a1 + 16) )
{
v8 = "tpi->test_printf_p";
goto LABEL_7;
}
fflush(stdout);
v6 = strlen(a2);
return (*(__int64 (__fastcall **)(__int64, const char *, size_t, __int64, __int64))(a1 + 16))(a1, a2, v6, a3, a4);
}

original_code:
int vtest(struct test_printf_info * tpi, char *xanswer,
  const char * restrict format, va_list ap) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 while (xanswer == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "xanswer");
 while (tpi->test_printf_p == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi->test_printf_p");
 fflush(stdout);
 return tpi->test_printf_p(tpi, xanswer, strlen(xanswer), format, ap);
}

canonical_original_code:
int vtest(struct test_printf_info *tpi, char *xanswer, char *format, __builtin_va_list ap) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 while (xanswer == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "xanswer");
 while (tpi->test_printf_p == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi->test_printf_p");
 fflush(stdout);
 return tpi->test_printf_p(tpi, xanswer, strlen(xanswer), format, ap);
}

variable_types:
xanswer
char *


decompiled_code:
void __fastcall test_setpos(const char *a1, unsigned int a2, __int64 a3)
{
void *v4; // rdi

if ( !a3 )
handleProgError(0LL, " %s() called with %s NULL\n", "test_setpos", "tpi");
v4 = *(void **)(a3 + 40);
if ( v4 )
free(v4);
*(_QWORD *)(a3 + 40) = 0LL;
if ( a1 )
{
if ( asprintf((char **)(a3 + 40), "%s:%d: ", a1, a2) < 0 )
*(_QWORD *)(a3 + 40) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func13(const char *a1, unsigned int a2, __int64 a3)
{
void *v4; // rdi

if ( !a3 )
func1(0LL, " %s() called with %s NULL\n", "test_setpos", "tpi");
v4 = *(void **)(a3 + 40);
if ( v4 )
free(v4);
*(_QWORD *)(a3 + 40) = 0LL;
if ( a1 )
{
if ( asprintf((char **)(a3 + 40), "%s:%d: ", a1, a2) < 0 )
*(_QWORD *)(a3 + 40) = 0LL;
}
}

original_code:
void test_setpos(const char curFile[], int curLine,
  struct test_printf_info * tpi) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 if (tpi->curtest_poshead != 0) {
  free(tpi->curtest_poshead);
 }
 tpi->curtest_poshead = 0;
 if (curFile == 0) {
  return;
 }
 if (asprintf(&tpi->curtest_poshead, "%s:%d: ", curFile, curLine) < 0) {
  tpi->curtest_poshead = 0;
 }
}

canonical_original_code:
void test_setpos(char curFile[], int curLine, struct test_printf_info *tpi) {
 while (tpi == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "tpi");
 if (tpi->curtest_poshead != 0) {
  free(tpi->curtest_poshead);
 }
 tpi->curtest_poshead = 0;
 if (curFile == 0) {
  return;
 }
 if (asprintf(&tpi->curtest_poshead, "%s:%d: ", curFile, curLine) < 0) {
  tpi->curtest_poshead = 0;
 }
}

variable_types:
curFile
char []

variable_types: curLine int


test

decompiled_code:
__int64 test(const char *a1, unsigned int a2, __int64 a3, const char *a4, __int64 a5, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a5);
test_setpos(a1, a2, a3);
return vtest(a3, a4, a5, (__int64)va);
}

canonical_decompiled_code:
__int64 func14(const char *a1, unsigned int a2, __int64 a3, const char *a4, __int64 a5, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a5);
func13(a1, a2, a3);
return func12(a3, a4, a5, (__int64)va);
}

original_code:
int test(const char curFile[], int curLine, struct test_printf_info * tpi,
  char *xanswer, const char * restrict format, ...) {
 test_setpos(curFile, curLine, tpi);
 va_list ap;
 __builtin_va_start(ap,format);
 int result = vtest(tpi, xanswer, format, ap);
 __builtin_va_end(ap);
 return result;
}

canonical_original_code:
int test(char curFile[], int curLine, struct test_printf_info *tpi, char *xanswer, char *format, ...) {
 test_setpos(curFile, curLine, tpi);
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 int result = vtest(tpi, xanswer, format, ap);
 __builtin_va_end(ap);
 return result;
}

variable_types: struct test_printf_info { char *test_subjectName; char *test_name; int (*test_printf_p)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap); int tests_total; int tests_failed; int tests_grandtotal; int tests_grandfailed; char *curtest_poshead; } *

variable_types: result int


vtestHost

decompiled_code:
__int64 __fastcall vtestHost(const char **a1, const char *a2, const __m128i *a3)
{
int v4; // eax
unsigned int v5; // er13
unsigned int v6; // eax
char *v7; // r15
unsigned int v8; // er12
unsigned int v9; // eax
char *s; // [rsp+0h] [rbp-48h] BYREF
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v13; // [rsp+18h] [rbp-30h]

if ( !a2 )
handleProgError(a1, " %s() called with %s NULL\n", "vtestHost", "format");
arg = _mm_loadu_si128(a3);
v13 = a3[1].m128i_i64[0];
v4 = vasprintf(&s, a2, &arg);
v5 = v4;
if ( s && v4 >= 0 )
{
v6 = vtest((__int64)a1, s, (__int64)a2, (__int64)a3);
v7 = s;
v8 = v6;
v9 = strlen(s);
if ( v9 != v5 )
{
logErrorRemark((__int64)a1, a2, "HOST problem: vasprintf() = [%d] but result is [%d] \"%s\"\n", v5, v9, v7);
v7 = s;
}
free(v7);
}
else
{
v8 = 0;
logErrorRemark((__int64)a1, a2, "HOST problem: vasprintf() failed: %d\n", (unsigned int)v4);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char **a1, const char *a2, const __m128i *a3)
{
int v4; // eax
unsigned int v5; // er13
unsigned int v6; // eax
char *v7; // r15
unsigned int v8; // er12
unsigned int v9; // eax
char *s; // [rsp+0h] [rbp-48h] BYREF
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v13; // [rsp+18h] [rbp-30h]

if ( !a2 )
func1(a1, " %s() called with %s NULL\n", "vtestHost", "format");
arg = _mm_loadu_si128(a3);
v13 = a3[1].m128i_i64[0];
v4 = vasprintf(&s, a2, &arg);
v5 = v4;
if ( s && v4 >= 0 )
{
v6 = func12((__int64)a1, s, (__int64)a2, (__int64)a3);
v7 = s;
v8 = v6;
v9 = strlen(s);
if ( v9 != v5 )
{
func9((__int64)a1, a2, "HOST problem: vasprintf() = [%d] but result is [%d] \"%s\"\n", v5, v9, v7);
v7 = s;
}
free(v7);
}
else
{
v8 = 0;
func9((__int64)a1, a2, "HOST problem: vasprintf() failed: %d\n", (unsigned int)v4);
}
return v8;
}

original_code:
int vtestHost(struct test_printf_info * tpi, const char * restrict format,
  va_list ap) {
 while (format == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "format");
 char *xanswer;
 va_list xap;
 __builtin_va_copy(xap,ap);
 int xansLen = vasprintf(&xanswer, format, xap);
 __builtin_va_end(xap);
 if (xanswer == 0 || xansLen < 0) {
  logErrorRemark(tpi, format, "HOST problem:  vasprintf() failed: %d\n",
    xansLen);
  return 0;
 }
 int result = vtest(tpi, xanswer, format, ap);
 if ((int) strlen(xanswer) != xansLen) {
  logErrorRemark(tpi, format,
    "HOST problem: vasprintf() = [%d] but result is [%d] \"%s\"\n",
    xansLen, (int) strlen(xanswer), xanswer);
 }
 free(xanswer);
 return result;
}

canonical_original_code:
int vtestHost(struct test_printf_info *tpi, char *format, __builtin_va_list ap) {
 while (format == 0) handleProgError(tpi, " %s() called with %s NULL\n", __func__, "format");
 char *xanswer;
 __builtin_va_list xap;
 __builtin_va_copy(xap,ap);
 int xansLen = vasprintf(&xanswer, format, xap);
 __builtin_va_end(xap);
 if (xanswer == 0 || xansLen < 0) {
  logErrorRemark(tpi, format, "HOST problem:  vasprintf() failed: %d\n",
    xansLen);
  return 0;
 }
 int result = vtest(tpi, xanswer, format, ap);
 if ((int) strlen(xanswer) != xansLen) {
  logErrorRemark(tpi, format,
    "HOST problem: vasprintf() = [%d] but result is [%d] \"%s\"\n",
    xansLen, (int) strlen(xanswer), xanswer);
 }
 free(xanswer);
 return result;
}

variable_types: xansLen int


testHost

decompiled_code:
__int64 testHost(const char *a1, unsigned int a2, const char **a3, const char *a4, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a4);
test_setpos(a1, a2, (__int64)a3);
return vtestHost(a3, a4, (const __m128i *)va);
}

canonical_decompiled_code:
__int64 func16(const char *a1, unsigned int a2, const char **a3, const char *a4, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a4);
func13(a1, a2, (__int64)a3);
return func15(a3, a4, (const __m128i *)va);
}

original_code:
int testHost(char curFile[], int curLine, struct test_printf_info * tpi,
  const char * restrict format, ...) {
 test_setpos(curFile, curLine, tpi);
 va_list ap;
 __builtin_va_start(ap,format);
 int result = vtestHost(tpi, format, ap);
 __builtin_va_end(ap);
 return result;
}

canonical_original_code:
int testHost(char curFile[], int curLine, struct test_printf_info *tpi, char *format, ...) {
 test_setpos(curFile, curLine, tpi);
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 int result = vtestHost(tpi, format, ap);
 __builtin_va_end(ap);
 return result;
}


setTestingHost

decompiled_code:
void __fastcall setTestingHost(int a1)
{
testingHost = a1;
}

canonical_decompiled_code:
void __fastcall func17(int a1)
{
testingHost = a1;
}

original_code:
void setTestingHost(int value) {
 testingHost = value;
}

variable_types: value int


isTestingHost

decompiled_code:
__int64 isTestingHost()
{
return (unsigned int)testingHost;
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned int)testingHost;
}

original_code:
int isTestingHost(void) {
 return testingHost;
}

canonical_original_code:
int isTestingHost() {
 return testingHost;
}


decompiled_code:
__int64 __fastcall test__write_to_buf(__int64 a1, const void *a2, unsigned int a3)
{
__int64 v3; // rbp
char *v5; // rax
_BYTE *v6; // rdx
unsigned int v7; // eax

v3 = *(_QWORD *)(a1 + 16);
if ( !*(_QWORD *)v3 )
return 0xFFFFFFFFLL;
v5 = (char *)realloc(*(void **)v3, (int)(a3 + *(_DWORD *)(v3 + 8) + 1));
*(_QWORD *)v3 = v5;
if ( !v5 )
return 0xFFFFFFFFLL;
memcpy(&v5[*(int *)(v3 + 8)], a2, a3);
v6 = *(_BYTE **)v3;
v7 = a3 + *(_DWORD *)(v3 + 8);
*(_DWORD *)(v3 + 8) = v7;
v6[v7] = 0;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const void *a2, unsigned int a3)
{
__int64 v3; // rbp
char *v5; // rax
_BYTE *v6; // rdx
unsigned int v7; // eax

v3 = *(_QWORD *)(a1 + 16);
if ( !*(_QWORD *)v3 )
return 0xFFFFFFFFLL;
v5 = (char *)realloc(*(void **)v3, (int)(a3 + *(_DWORD *)(v3 + 8) + 1));
*(_QWORD *)v3 = v5;
if ( !v5 )
return 0xFFFFFFFFLL;
memcpy(&v5[*(int *)(v3 + 8)], a2, a3);
v6 = *(_BYTE **)v3;
v7 = a3 + *(_DWORD *)(v3 + 8);
*(_DWORD *)(v3 + 8) = v7;
v6[v7] = 0;
return a3;
}

original_code:
static int test__write_to_buf(struct xprintf_protectedChannel *xchpr,
  const char *pData, unsigned int length) {
 struct testChannel *xchp = xchpr->channel;
 if (xchp->buf == 0)
  return -1;
 int newBufLen = xchp->len + length + 1;
 xchp->buf = realloc(xchp->buf, newBufLen);
 if (xchp->buf == 0)
  return -1;
 memcpy(xchp->buf + xchp->len, pData, length);
 xchp->len += length;
 xchp->buf[xchp->len] = '\0';
 return length;
}

canonical_original_code:
static int test__write_to_buf(struct xprintf_protectedChannel *xchpr, char *pData, unsigned int length) {
 struct testChannel *xchp = xchpr->channel;
 if (xchp->buf == 0)
  return -1;
 int newBufLen = xchp->len + length + 1;
 xchp->buf = realloc(xchp->buf, newBufLen);
 if (xchp->buf == 0)
  return -1;
 memcpy(xchp->buf + xchp->len, pData, length);
 xchp->len += length;
 xchp->buf[xchp->len] = '\0';
 return length;
}

variable_types: struct xprintf_protectedChannel { int protectionCredentials; int (*writeProtected)(struct xprintf_protectedChannel *xprch, char *pData, unsigned int length); void *channel; } *

variable_types:
pData
char *

variable_types:
length
unsigned int

variable_types: struct testChannel { char *buf; int len; } *

variable_types: newBufLen int


decompiled_code:
__int64 __fastcall vtest_xprintf_core(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5)
{
unsigned int v8; // eax
unsigned int v9; // er12
void *ptr; // [rsp+0h] [rbp-58h] BYREF
int v12; // [rsp+8h] [rbp-50h]
__int64 v13[9]; // [rsp+10h] [rbp-48h] BYREF

ptr = malloc(1uLL);
v12 = 0;
v13[0] = 0LL;
v13[1] = (__int64)test__write_to_buf;
v13[2] = (__int64)&ptr;
v8 = xvprintf_protected(v13, a4, a5);
v9 = compareResult(a1, a2, a3, a4, ptr, v8);
if ( ptr )
free(ptr);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5)
{
unsigned int v8; // eax
unsigned int v9; // er12
void *ptr; // [rsp+0h] [rbp-58h] BYREF
int v12; // [rsp+8h] [rbp-50h]
__int64 v13[9]; // [rsp+10h] [rbp-48h] BYREF

ptr = malloc(1uLL);
v12 = 0;
v13[0] = 0LL;
v13[1] = (__int64)test__write_to_buf;
v13[2] = (__int64)&ptr;
v8 = xvprintf_protected(v13, a4, a5);
v9 = compareResult(a1, a2, a3, a4, ptr, v8);
if ( ptr )
free(ptr);
return v9;
}

original_code:
int vtest_xprintf_core(struct test_printf_info *tpi,
  const char *expected, int expectedLen, const char *format, va_list ap) {
 struct testChannel xch = { .buf = malloc(1), .len = 0 };
 struct xprintf_protectedChannel xchpr = { .channel = &xch,
   .writeProtected = test__write_to_buf };
 int count = xvprintf_protected(&xchpr, format, ap);
 int result = compareResult(tpi, expected, expectedLen, format,
   xch.buf, count);
 if (xch.buf != 0)
  free(xch.buf);
 return result;
}

canonical_original_code:
int vtest_xprintf_core(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap) {
 struct testChannel xch = { .buf = malloc(1), .len = 0 };
 struct xprintf_protectedChannel xchpr = { .channel = &xch,
   .writeProtected = test__write_to_buf };
 int count = xvprintf_protected(&xchpr, format, ap);
 int result = compareResult(tpi, expected, expectedLen, format,
   xch.buf, count);
 if (xch.buf != 0)
  free(xch.buf);
 return result;
}

variable_types:
expected
char *

variable_types: expectedLen int

variable_types: struct testChannel { char *buf; int len; }

variable_types: struct xprintf_protectedChannel { int protectionCredentials; int (*writeProtected)(struct xprintf_protectedChannel *xprch, char *pData, unsigned int length); void *channel; }

variable_types: count int


original_code:
static inline int xprintf__handleSpecial(
  struct xprintf_protectedChannel *xchpr,
  const struct xprintf__conversionPparams *params, double doubleArg) {
 const char *specStr = 0;
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, doubleArg)) {
 case 0:
  specStr = "nan";
  if (params->flags.upper) {
   specStr = "NAN";
  }
  break;
 case 1:
  specStr = "inf";
  if (params->flags.upper) {
   specStr = "INF";
  }
  break;
 case 2:
  break;
 case 3:
  break;
 case 4:
  break;
 default:
  DEBUG_FORMAT(params, "unknown fpclassify(%f): %d", doubleArg,
    __builtin_fpclassify (0, 1, 4, 3, 2, doubleArg));
  return (-1);
 }
 if (specStr == 0) {
  return 0;
 }
 struct xprintf__conversionPparams stringParams = *params;
 stringParams.flags.alternative = 0;
 stringParams.precision = -1;
 return xvprintf__printString(xchpr, &stringParams, specStr);
}

canonical_original_code:
static inline int xprintf__handleSpecial(struct xprintf_protectedChannel *xchpr, struct xprintf__conversionPparams *params, double doubleArg) {
 char *specStr = 0;
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, doubleArg)) {
 case 0:
  specStr = "nan";
  if (params->flags.upper) {
   specStr = "NAN";
  }
  break;
 case 1:
  specStr = "inf";
  if (params->flags.upper) {
   specStr = "INF";
  }
  break;
 case 2:
  break;
 case 3:
  break;
 case 4:
  break;
 default:
  DEBUG_FORMAT(params, "unknown fpclassify(%f): %d", doubleArg,
    __builtin_fpclassify (0, 1, 4, 3, 2, doubleArg));
  return (-1);
 }
 if (specStr == 0) {
  return 0;
 }
 struct xprintf__conversionPparams stringParams = *params;
 stringParams.flags.alternative = 0;
 stringParams.precision = -1;
 return xvprintf__printString(xchpr, &stringParams, specStr);
}

variable_types: struct xprintf__conversionPparams { struct xprintf__conversionFlags { unsigned int leftjustified; unsigned int signplus; unsigned int signspace; unsigned int alternative; unsigned int leadingzeroes; unsigned int upper; } flags; int minWidth; int precision; unsigned int digitBase; char sign; enum xprintf__conversionSpec { convUnsupportedUnknown=0, convSignedIntegral=1, convUnsignedIntegral=2, convDoubleExponent=3, convDoubleFixed=4, convDoubleGeneral=5, convChar=6, convString=7, convPercent=8, convDoubleUnsupported=9, convPointer=10, convStoreCount=11, _conv_count=12 } convSpec; enum conversionSize { sizeDefault=0, sizeChar=1, sizeShort=2, sizeLong=3, sizeLongLong=4, sizeIntmax_t=5, sizeSize_t=6, sizePtrdiff_t=7, sizeLongDouble=8, _size_count=9 } argLength; } *

variable_types: doubleArg double

variable_types:
specStr
char *

user_defined_types: struct xprintf_protectedChannel { int protectionCredentials; int (*writeProtected)(struct xprintf_protectedChannel *xprch, char *pData, unsigned int length); void *channel; }


decompiled_code:
__int64 __fastcall getExponent10(double a1)
{
double v2; // xmm0_8
double v3; // xmm0_8

if ( COERCE_DOUBLE(*(_QWORD *)&a1 & LC4) > 1.797693134862316e308
|| COERCE_DOUBLE(*(_QWORD *)&a1 & LC4) < 2.225073858507201e-308 && a1 == 0.0 )
{
return 0LL;
}
v2 = fabs(a1);
v3 = log10(v2);
return (unsigned int)(int)floor(v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1)
{
double v2; // xmm0_8
double v3; // xmm0_8

if ( COERCE_DOUBLE(*(_QWORD *)&a1 & LC4) > 1.797693134862316e308
|| COERCE_DOUBLE(*(_QWORD *)&a1 & LC4) < 2.225073858507201e-308 && a1 == 0.0 )
{
return 0LL;
}
v2 = fabs(a1);
v3 = log10(v2);
return (unsigned int)(int)floor(v3);
}

original_code:
static inline int getExponent10(double doubleArg) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, doubleArg)) {
 case 2:
  return 0;
 case 0:
 case 1:
  return 0;
 }
 return floor(log10(fabs(doubleArg)));
}


original_code:
static int xprintf__doubleSwitch(struct xprintf_protectedChannel *xchpr,
  const struct xprintf__conversionPparams *params, double doubleArg) {
 if (xchpr == 0) {
  return (-1);
 }
 if (params == 0) {
  return (-1);
 }
 if (xchpr->writeProtected == 0) {
  return (-1);
 }
 int outCount = xprintf__handleSpecial(xchpr, params, doubleArg);
 if (outCount != 0) {
  return outCount;
 }
 switch (params->convSpec) {
 case convDoubleExponent:
  return xprintf__e(xchpr, params, doubleArg);
 case convDoubleFixed:
  return xprintf__f(xchpr, params, doubleArg);
 case convDoubleGeneral:
  break;
 case convDoubleUnsupported:
  DEBUG_FORMAT(params, "bad convSpec %d", params->convSpec);
  return (-1);
 default:
  DEBUG_FORMAT(params, "bad convSpec %d", params->convSpec);
  return (-1);
 }
 int P = params->precision;
 if (P < 0) {
  P = 6;
 } else if (P == 0) {
  P = 1;
 }
 const int X = getExponent10(doubleArg);
 if (P > X && X >= -4) {
  struct xprintf__conversionPparams p = *params;
  p.precision = P - (X + 1);
  return xprintf__f(xchpr, &p, doubleArg);
 } else {
  struct xprintf__conversionPparams p = *params;
  p.precision = P - 1;
  return xprintf__e(xchpr, &p, doubleArg);
 }
}

canonical_original_code:
static int xprintf__doubleSwitch(struct xprintf_protectedChannel *xchpr, struct xprintf__conversionPparams *params, double doubleArg) {
 if (xchpr == 0) {
  return (-1);
 }
 if (params == 0) {
  return (-1);
 }
 if (xchpr->writeProtected == 0) {
  return (-1);
 }
 int outCount = xprintf__handleSpecial(xchpr, params, doubleArg);
 if (outCount != 0) {
  return outCount;
 }
 switch (params->convSpec) {
 case convDoubleExponent:
  return xprintf__e(xchpr, params, doubleArg);
 case convDoubleFixed:
  return xprintf__f(xchpr, params, doubleArg);
 case convDoubleGeneral:
  break;
 case convDoubleUnsupported:
  DEBUG_FORMAT(params, "bad convSpec %d", params->convSpec);
  return (-1);
 default:
  DEBUG_FORMAT(params, "bad convSpec %d", params->convSpec);
  return (-1);
 }
 int P = params->precision;
 if (P < 0) {
  P = 6;
 } else if (P == 0) {
  P = 1;
 }
 int X = getExponent10(doubleArg);
 if (P > X && X >= -4) {
  struct xprintf__conversionPparams p = *params;
  p.precision = P - (X + 1);
  return xprintf__f(xchpr, &p, doubleArg);
 } else {
  struct xprintf__conversionPparams p = *params;
  p.precision = P - 1;
  return xprintf__e(xchpr, &p, doubleArg);
 }
}

variable_types: outCount int

variable_types: P int

variable_types: X int

variable_types: struct xprintf__conversionPparams { struct xprintf__conversionFlags { unsigned int leftjustified; unsigned int signplus; unsigned int signspace; unsigned int alternative; unsigned int leadingzeroes; unsigned int upper; } flags; int minWidth; int precision; unsigned int digitBase; char sign; enum xprintf__conversionSpec { convUnsupportedUnknown=0, convSignedIntegral=1, convUnsignedIntegral=2, convDoubleExponent=3, convDoubleFixed=4, convDoubleGeneral=5, convChar=6, convString=7, convPercent=8, convDoubleUnsupported=9, convPointer=10, convStoreCount=11, _conv_count=12 } convSpec; enum conversionSize { sizeDefault=0, sizeChar=1, sizeShort=2, sizeLong=3, sizeLongLong=4, sizeIntmax_t=5, sizeSize_t=6, sizePtrdiff_t=7, sizeLongDouble=8, _size_count=9 } argLength; }


xvsnprintf

decompiled_code:
__int64 __fastcall xvsnprintf(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h] BYREF
__int64 (__fastcall *v7)(__int64, char *, unsigned int); // [rsp+18h] [rbp-20h]
__int64 *v8; // [rsp+20h] [rbp-18h]

if ( !a3 )
return 0xFFFFFFFFLL;
v6 = 0;
v7 = xvsnprintf__writeProtected;
v8 = 0LL;
if ( a2 )
{
if ( !a1 )
return 0xFFFFFFFFLL;
v5[0] = a1;
v5[1] = a1 + a2 - 1;
v8 = v5;
}
return xvprintf_protected(&v6, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h] BYREF
__int64 (__fastcall *v7)(__int64, char *, unsigned int); // [rsp+18h] [rbp-20h]
__int64 *v8; // [rsp+20h] [rbp-18h]

if ( !a3 )
return 0xFFFFFFFFLL;
v6 = 0;
v7 = xvsnprintf__writeProtected;
v8 = 0LL;
if ( a2 )
{
if ( !a1 )
return 0xFFFFFFFFLL;
v5[0] = a1;
v5[1] = a1 + a2 - 1;
v8 = v5;
}
return xvprintf_protected(&v6, a3, a4);
}

original_code:
int xvsnprintf(char * restrict str, size_t size, const char * restrict format,
  va_list ap) {
 if (format == 0) {
  return (-1);
 }
 struct xprintf_protectedChannel xchpr = {
   .writeProtected = xvsnprintf__writeProtected,
   .protectionCredentials = 0,
   .channel = 0,
   };
 if (size == 0) {
  xchpr.channel = 0;
  return xvprintf_protected(&xchpr, format, ap);
 } else if (str == 0) {
  return (-1);
 } else {
  struct xsnprintf_channel data = {
    .nextCharPos = str,
    .maxNullPos = str + size - 1
    };
  xchpr.channel = &data;
  return xvprintf_protected(&xchpr, format, ap);
 }
}

canonical_original_code:
int xvsnprintf(char *str, unsigned long size, char *format, __builtin_va_list ap) {
 if (format == 0) {
  return (-1);
 }
 struct xprintf_protectedChannel xchpr = {
   .writeProtected = xvsnprintf__writeProtected,
   .protectionCredentials = 0,
   .channel = 0,
   };
 if (size == 0) {
  xchpr.channel = 0;
  return xvprintf_protected(&xchpr, format, ap);
 } else if (str == 0) {
  return (-1);
 } else {
  struct xsnprintf_channel data = {
    .nextCharPos = str,
    .maxNullPos = str + size - 1
    };
  xchpr.channel = &data;
  return xvprintf_protected(&xchpr, format, ap);
 }
}

variable_types:
str
char *

variable_types:
size
unsigned long

variable_types:
format
char *

variable_types: struct xsnprintf_channel { char *nextCharPos; char *maxNullPos; }


xsnprintf

decompiled_code:
__int64 xsnprintf(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return xvsnprintf(a1, a2, a3, (__int64)va);
}

canonical_decompiled_code:
__int64 func2(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return func1(a1, a2, a3, (__int64)va);
}

original_code:
int xsnprintf(char * restrict str, size_t size, const char * restrict format,
  ...) {
 va_list ap;
 __builtin_va_start(ap,format);
 int outCount = xvsnprintf(str, size, format, ap);
 __builtin_va_end(ap);
 return outCount;
}

canonical_original_code:
int xsnprintf(char *str, unsigned long size, char *format, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 int outCount = xvsnprintf(str, size, format, ap);
 __builtin_va_end(ap);
 return outCount;
}


decompiled_code:
int __fastcall xprintf__debug2hostV(char *format, __gnuc_va_list arg)
{
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int __fastcall func0(char *format, __gnuc_va_list arg)
{
return vfprintf(stderr, format, arg);
}

original_code:
void xprintf__debug2hostV(const char * format, va_list ap) {
  vfprintf(stderr, format, ap);
}

canonical_original_code:
void xprintf__debug2hostV(char *format, __builtin_va_list ap) {
  vfprintf(stderr, format, ap);
}


decompiled_code:
__int64 __fastcall test_iso_strings(__int64 a1)
{
startTests(a1, "test_iso_strings");
test("tests-iso.c", 230LL, a1, "a");
test("tests-iso.c", 233LL, a1, "ab");
test("tests-iso.c", 234LL, a1, &unk_16C4);
test("tests-iso.c", 235LL, a1, " abc");
test("tests-iso.c", 236LL, a1, "abc ");
test("tests-iso.c", 237LL, a1, " ab");
test("tests-iso.c", 238LL, a1, " abc");
test("tests-iso.c", 239LL, a1, "abc ");
test("tests-iso.c", 240LL, a1, " ab");
test("tests-iso.c", 243LL, a1, "%");
return endTests(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
startTests(a1, "test_iso_strings");
test("tests-iso.c", 230LL, a1, "a");
test("tests-iso.c", 233LL, a1, "ab");
test("tests-iso.c", 234LL, a1, &unk_16C4);
test("tests-iso.c", 235LL, a1, " abc");
test("tests-iso.c", 236LL, a1, "abc ");
test("tests-iso.c", 237LL, a1, " ab");
test("tests-iso.c", 238LL, a1, " abc");
test("tests-iso.c", 239LL, a1, "abc ");
test("tests-iso.c", 240LL, a1, " ab");
test("tests-iso.c", 243LL, a1, "%");
return endTests(a1);
}

original_code:
void test_iso_strings(struct test_printf_info *tpi) {
 startTests(tpi, __func__);
 test("tests-iso.c", 230, tpi, "a", "%c", 'a');
 test("tests-iso.c", 233, tpi, "ab", "%.2s", "abc");
 test("tests-iso.c", 234, tpi, "abc", "%.6s", "abc");
 test("tests-iso.c", 235, tpi, "  abc", "%5s", "abc");
 test("tests-iso.c", 236, tpi, "abc  ", "%-5s", "abc");
 test("tests-iso.c", 237, tpi, "   ab", "%5.2s", "abc");
 test("tests-iso.c", 238, tpi, "  abc", "%*s", 5, "abc");
 test("tests-iso.c", 239, tpi, "abc  ", "%*s", -5, "abc");
 test("tests-iso.c", 240, tpi, "   ab", "%*.*s", 5, 2, "abc");
 test("tests-iso.c", 243, tpi, "%", "%%");
 endTests(tpi);
}

variable_types: struct test_printf_info { char *test_subjectName; char *test_name; int (*test_printf_p)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap); int tests_total; int tests_failed; int tests_grandtotal; int tests_grandfailed; char *curtest_poshead; } *


decompiled_code:
__int64 __fastcall test_all_iso(__int64 a1)
{
test_iso_ints(a1);
test_iso_strings(a1);
test_iso_doubles(a1);
return test_BrunoHaible(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
func0(a1);
func1(a1);
test_iso_doubles(a1);
return test_BrunoHaible(a1);
}

original_code:
void test_all_iso(struct test_printf_info *tpi) {
 test_iso_ints(tpi);
 test_iso_strings(tpi);
 test_iso_doubles(tpi);
 test_BrunoHaible(tpi);
}


snprintf

decompiled_code:
__int64 snprintf(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return xvsnprintf(a1, a2, a3, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return xvsnprintf(a1, a2, a3, va);
}

original_code:
int snprintf(char *restrict str, size_t size, const char *restrict format, ...) {
 va_list ap;
 __builtin_va_start(ap,format);
 int outCount = xvsnprintf(str, size, format, ap);
 __builtin_va_end(ap);
 return outCount;
}

canonical_original_code:
int snprintf(char *str, unsigned long size, char *format, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 int outCount = xvsnprintf(str, size, format, ap);
 __builtin_va_end(ap);
 return outCount;
}


vsnprintf

decompiled_code:
// attributes: thunk
__int64 __fastcall vsnprintf(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return xvsnprintf(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return xvsnprintf(a1, a2, a3, a4);
}

original_code:
int vsnprintf(char *restrict str, size_t size, const char *restrict format,
  va_list ap) {
 return xvsnprintf(str, size, format, ap);
}

canonical_original_code:
int vsnprintf(char *str, unsigned long size, char *format, __builtin_va_list ap) {
 return xvsnprintf(str, size, format, ap);
}