DotProduct

decompiled_code:
float __fastcall DotProduct(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

canonical_decompiled_code:
float __fastcall func5(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

original_code:
float DotProduct(Vector3D Vector1, Vector3D Vector2){
 return Vector1.x*Vector2.x + Vector1.y*Vector2.y + Vector1.z*Vector2.z;
}

canonical_original_code:
float DotProduct(struct Vector3D Vector1, struct Vector3D Vector2){
 return Vector1.x*Vector2.x + Vector1.y*Vector2.y + Vector1.z*Vector2.z;
}

return_type: float


Norm

repo: ACCITD/ITD

decompiled_code:
float __fastcall Norm(double a1, float a2)
{
float v2; // xmm0_4
float result; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
result = sqrtf(v2);
else
result = fsqrt(v2);
return result;
}

canonical_decompiled_code:
float __fastcall func6(double a1, float a2)
{
float v2; // xmm0_4
float result; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
result = sqrtf(v2);
else
result = fsqrt(v2);
return result;
}

original_code:
float Norm(Vector3D V){
 return sqrt(V.x*V.x + V.y*V.y + V.z*V.z);
}

canonical_original_code:
float Norm(struct Vector3D V){
 return sqrt(V.x*V.x + V.y*V.y + V.z*V.z);
}

variable_types: struct Vector3D { float x; float y; float z; }


Normalize

decompiled_code:
__m128i __fastcall Normalize(double a1, float a2)
{
float v2; // xmm0_4
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

v2 = Norm(a1, a2);
*(float *)v5.m128i_i32 = *(float *)&a1 / v2;
*(float *)&v5.m128i_i32[1] = *((float *)&a1 + 1) / v2;
return _mm_loadl_epi64(&v5);
}

original_code:
Vector3D Normalize(Vector3D V){
 Vector3D newVector;
 float norm = Norm(V);
 newVector.x = V.x / norm;
 newVector.y = V.y / norm;
 newVector.z = V.z / norm;
 return newVector;
}

canonical_original_code:
struct Vector3D Normalize(struct Vector3D V){
 struct Vector3D newVector;
 float norm = Norm(V);
 newVector.x = V.x / norm;
 newVector.y = V.y / norm;
 newVector.z = V.z / norm;
 return newVector;
}

variable_types:
V
struct Vector3D

variable_types: norm float

return_type: struct Vector3D { float x; float y; float z; }


dumpVector

decompiled_code:
int __fastcall dumpVector(double a1, float a2)
{
puts("\nDump vector :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

canonical_decompiled_code:
int __fastcall func8(double a1, float a2)
{
puts("\nDump vector :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

original_code:
void dumpVector(Vector3D vect){
 printf("\nDump vector :\n");
 printf("\tx : %f\n", vect.x);
 printf("\ty : %f\n", vect.y);
 printf("\tz : %f\n", vect.z);
}

canonical_original_code:
void dumpVector(struct Vector3D vect){
 printf("\nDump vector :\n");
 printf("\tx : %f\n", vect.x);
 printf("\ty : %f\n", vect.y);
 printf("\tz : %f\n", vect.z);
}

return_type: void

user_defined_types: struct Vector3D { float x; float y; float z; }


createEmptyTowerStat

decompiled_code:
_DWORD *createEmptyTowerStat()
{
_DWORD *result; // rax

result = malloc(0x40uLL);
if ( result )
{
*result = 100;
result[1] = 100;
result[2] = 180;
result[3] = 190;
result[4] = 60;
result[5] = 40;
result[6] = 120;
result[7] = 150;
result[8] = 40;
result[9] = 50;
result[10] = 150;
result[11] = 80;
result[12] = 40;
result[13] = 100;
result[14] = 280;
result[15] = 250;
}
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x40uLL);
if ( result )
{
*result = 100;
result[1] = 100;
result[2] = 180;
result[3] = 190;
result[4] = 60;
result[5] = 40;
result[6] = 120;
result[7] = 150;
result[8] = 40;
result[9] = 50;
result[10] = 150;
result[11] = 80;
result[12] = 40;
result[13] = 100;
result[14] = 280;
result[15] = 250;
}
return result;
}

original_code:
TowerStat* createEmptyTowerStat(){
 TowerStat* towerstat = (TowerStat*) malloc(sizeof(TowerStat));
 if(towerstat == ((void *)0)) return ((void *)0);
 towerstat->powerR=100;
 towerstat->rateR=100;
 towerstat->rangeR=180;
 towerstat->costR=190;
 towerstat->powerL=60;
 towerstat->rateL=40;
 towerstat->rangeL=120;
 towerstat->costL=150;
 towerstat->powerM=40;
 towerstat->rateM=50;
 towerstat->rangeM=150;
 towerstat->costM=80;
 towerstat->powerH=40;
 towerstat->rateH=100;
 towerstat->rangeH=280;
 towerstat->costH=250;
 return towerstat;
}

canonical_original_code:
struct TowerStat *createEmptyTowerStat(){
 struct TowerStat *towerstat = (TowerStat*) malloc(sizeof(TowerStat));
 if(towerstat == ((void *)0)) return ((void *)0);
 towerstat->powerR=100;
 towerstat->rateR=100;
 towerstat->rangeR=180;
 towerstat->costR=190;
 towerstat->powerL=60;
 towerstat->rateL=40;
 towerstat->rangeL=120;
 towerstat->costL=150;
 towerstat->powerM=40;
 towerstat->rateM=50;
 towerstat->rangeM=150;
 towerstat->costM=80;
 towerstat->powerH=40;
 towerstat->rateH=100;
 towerstat->rangeH=280;
 towerstat->costH=250;
 return towerstat;
}

variable_types: struct TowerStat { int powerR; int rateR; int rangeR; int costR; int powerL; int rateL; int rangeL; int costL; int powerM; int rateM; int rangeM; int costM; int powerH; int rateH; int rangeH; int costH; } *


drawMonster

original_code:
void drawMonster(const Monster* monster){
 if(monster == ((void *)0)) return;
 GLuint monsterTexture = 0;
 Vector3D direction = Normalize(monster->direction);
 float factorX = DotProduct(direction, ITD_X_AXIS);
 float factorY = DotProduct(direction, ITD_Y_AXIS);
 float epsilon = 0.4;
 switch(monster->type){
  case BLUE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_GAUCHE;
   }
   else if (fabs(factorX) >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DROITE;
   }
   else if ( fabs(factorX + 0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
  break;
  case ORANGE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
  break;
  case GREEN_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
  break;
  default : return;
  break;
 }
 glPushMatrix();
 glColor3ub(255,255,255);
 glTranslatef(monster->position.x, monster->position.y, monster->position.z);
 glPushMatrix();
 glScalef(MONSTER_WIDTH_PX,MONSTER_WIDTH_PX,1.0);
 drawTexturedQuad(monsterTexture);
 glPopMatrix();
 float fullBarSize = (MONSTER_WIDTH_PX / 1.2);
 float barSize = monster->life / ((float)monster->maxLife) * fullBarSize;
 float decalY = - (MONSTER_WIDTH_PX / 1.2 - barSize) / 2.0;
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , 0., 0.);
 glScalef(4.0, fullBarSize, 1.);
 glColor3ub(255,0,0);
 drawQuad();
 glPopMatrix();
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , decalY, 0.);
 glColor3ub(0,255,0);
 glScalef(4.0, barSize, 1.);
 drawQuad();
 glPopMatrix();
 glPopMatrix();
}

canonical_original_code:
void drawMonster(struct Monster *monster){
 if(monster == ((void *)0)) return;
 unsigned int monsterTexture = 0;
 struct Vector3D direction = Normalize(monster->direction);
 float factorX = DotProduct(direction, ITD_X_AXIS);
 float factorY = DotProduct(direction, ITD_Y_AXIS);
 float epsilon = 0.4;
 switch(monster->type){
  case BLUE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_GAUCHE;
   }
   else if (fabs(factorX) >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DROITE;
   }
   else if ( fabs(factorX + 0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.BLUE_OCTOPUS_ID;
  break;
  case ORANGE_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.ORANGE_OCTOPUS_ID;
  break;
  case GREEN_OCTOPUS :
   if (factorY <= -1. + epsilon && fabs(factorX) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
   }
   else if (factorY > 1. - epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DOS;
   }
   else if (factorX < -1. + epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_GAUCHE;
   }
   else if (factorX >= 1.- epsilon && fabs(factorY) < epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DROITE;
   }
   else if (fabs(factorX+0.5)<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_GAUCHE;
   }
   else if (-factorX-0.5<epsilon){
    monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID_DEMI_DROITE;
   }
   else monsterTexture = GAME_TEXTURES_ID.GREEN_OCTOPUS_ID;
  break;
  default : return;
  break;
 }
 glPushMatrix();
 glColor3ub(255,255,255);
 glTranslatef(monster->position.x, monster->position.y, monster->position.z);
 glPushMatrix();
 glScalef(MONSTER_WIDTH_PX,MONSTER_WIDTH_PX,1.0);
 drawTexturedQuad(monsterTexture);
 glPopMatrix();
 float fullBarSize = (MONSTER_WIDTH_PX / 1.2);
 float barSize = monster->life / ((float)monster->maxLife) * fullBarSize;
 float decalY = - (MONSTER_WIDTH_PX / 1.2 - barSize) / 2.0;
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , 0., 0.);
 glScalef(4.0, fullBarSize, 1.);
 glColor3ub(255,0,0);
 drawQuad();
 glPopMatrix();
 glPushMatrix();
 glTranslatef(MONSTER_WIDTH_PX / 2.0 + 10 , decalY, 0.);
 glColor3ub(0,255,0);
 glScalef(4.0, barSize, 1.);
 drawQuad();
 glPopMatrix();
 glPopMatrix();
}

variable_types: struct Monster { enum MonsterType { BLUE_OCTOPUS=0, ORANGE_OCTOPUS=1, GREEN_OCTOPUS=2 } type; int life; int maxLife; int rocketResistance; int laserResistance; int gunResistance; int hybridResistance; int money; int speed; struct Point3D { float x; float y; float z; } position; struct Point3D realPosition; struct Point3D destination; struct Vector3D { float x; float y; float z; } direction; int nbTurnsSinceLastMove; } *

variable_types:
monsterTexture
unsigned int

variable_types: factorX float

variable_types: factorY float

variable_types: epsilon float

variable_types: fullBarSize float

variable_types: barSize float

variable_types: decalY float

user_defined_types: struct Monster { enum MonsterType type; int life; int maxLife; int rocketResistance; int laserResistance; int gunResistance; int hybridResistance; int money; int speed; struct Point3D position; struct Point3D realPosition; struct Point3D destination; struct Vector3D direction; int nbTurnsSinceLastMove; }


createMissile

decompiled_code:
char *__fastcall createMissile(int a1, double a2, float a3, double a4, float a5)
{
char *v5; // rax
char *v6; // rbx

v5 = (char *)malloc(0x20uLL);
v6 = v5;
if ( v5 )
{
*(double *)v5 = a2;
*((float *)v5 + 2) = a3;
*(double *)(v5 + 12) = a4;
*((float *)v5 + 5) = a5;
*((_DWORD *)v5 + 6) = a1;
}
else
{
fwrite(&unk_CF0, 1uLL, 0x2CuLL, stderr);
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func3(int a1, double a2, float a3, double a4, float a5)
{
char *v5; // rax
char *v6; // rbx

v5 = (char *)malloc(0x20uLL);
v6 = v5;
if ( v5 )
{
*(double *)v5 = a2;
*((float *)v5 + 2) = a3;
*(double *)(v5 + 12) = a4;
*((float *)v5 + 5) = a5;
*((_DWORD *)v5 + 6) = a1;
}
else
{
fwrite(&unk_CF0, 1uLL, 0x2CuLL, stderr);
}
return v6;
}

original_code:
Missile* createMissile(Point3D startPoint, Point3D endPoint, Uint32 startTime){
 Missile* missile = (Missile*) malloc(sizeof(Missile));
 if(missile == ((void *)0)) {
  fprintf(stderr, "Erreur fatale : plus de mémoire disponible\n");
  return ((void *)0);
 }
 missile->startPoint = startPoint;
 missile->endPoint = endPoint;
 missile->startTime = startTime;
 return missile;
}

canonical_original_code:
struct Missile *createMissile(struct Point3D startPoint, struct Point3D endPoint, unsigned int startTime){
 struct Missile *missile = (Missile*) malloc(sizeof(Missile));
 if(missile == ((void *)0)) {
  fprintf(stderr, "Erreur fatale : plus de mémoire disponible\n");
  return ((void *)0);
 }
 missile->startPoint = startPoint;
 missile->endPoint = endPoint;
 missile->startTime = startTime;
 return missile;
}

variable_types:
startPoint
struct Point3D

variable_types:
endPoint
struct Point3D

variable_types:
startTime
unsigned int

variable_types: struct Missile { struct Point3D { float x; float y; float z; } startPoint; struct Point3D endPoint; unsigned int startTime; struct Color3u { unsigned char red; unsigned char green; unsigned char blue; } color; } *

user_defined_types: struct Missile { struct Point3D startPoint; struct Point3D endPoint; unsigned int startTime; struct Color3u color; }


PointXYZ

decompiled_code:
__m128i __fastcall PointXYZ(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
Point3D PointXYZ(float x, float y, float z){
 Point3D p;
 p.x = x;
 p.y = y;
 p.z = z;
 return p;
}

canonical_original_code:
struct Point3D PointXYZ(float x, float y, float z){
 struct Point3D p;
 p.x = x;
 p.y = y;
 p.z = z;
 return p;
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: struct Point3D { float x; float y; float z; }


dumpPoint

decompiled_code:
int __fastcall dumpPoint(double a1, float a2)
{
puts("\nDump point :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

canonical_decompiled_code:
int __fastcall func2(double a1, float a2)
{
puts("\nDump point :");
printf("\tx : %f\n", *(float *)&a1);
printf("\ty : %f\n", *((float *)&a1 + 1));
return printf("\tz : %f\n", a2);
}

original_code:
void dumpPoint(Point3D point){
 printf("\nDump point :\n");
 printf("\tx : %f\n", point.x);
 printf("\ty : %f\n", point.y);
 printf("\tz : %f\n", point.z);
}

canonical_original_code:
void dumpPoint(struct Point3D point){
 printf("\nDump point :\n");
 printf("\tx : %f\n", point.x);
 printf("\ty : %f\n", point.y);
 printf("\tz : %f\n", point.z);
}

user_defined_types: struct Point3D { float x; float y; float z; }


decompiled_code:
int __fastcall print_results(unsigned __int8 *a1)
{
__int64 i; // rbx
int result; // eax

puts("Final state:");
printf("r0: %X\tr1: %X\n", *a1, a1[1]);
puts("Memory:");
printf("%X ", a1[2]);
for ( i = 2LL; i != 17; ++i )
{
result = printf("%X ", a1[i + 1]);
if ( (i & 3) == 0 )
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int8 *a1)
{
__int64 i; // rbx
int result; // eax

puts("Final state:");
printf("r0: %X\tr1: %X\n", *a1, a1[1]);
puts("Memory:");
printf("%X ", a1[2]);
for ( i = 2LL; i != 17; ++i )
{
result = printf("%X ", a1[i + 1]);
if ( (i & 3) == 0 )
result = putchar(10);
}
return result;
}

original_code:
void print_results(processor * p) {
    printf("Final state:\n");
    printf("r0: %X\tr1: %X\n", p->r0, p->r1);
    printf("Memory:\n");
    int i;
    for (i = 0; i < 16; ++i) {
        printf("%X ", p->mem[i]);
        if ((i + 1) % 4 == 0) {
            printf("\n");
        }
    }
}

canonical_original_code:
void print_results(struct processor *p) {
    printf("Final state:\n");
    printf("r0: %X\tr1: %X\n", p->r0, p->r1);
    printf("Memory:\n");
    int i;
    for (i = 0; i < 16; ++i) {
        printf("%X ", p->mem[i]);
        if ((i + 1) % 4 == 0) {
            printf("\n");
        }
    }
}

variable_types: struct processor { unsigned char r0; unsigned char r1; unsigned char mem[16]; } *

variable_types: i int


instruction

decompiled_code:
__int16 __fastcall instruction(unsigned __int8 *a1, __int16 a2)
{
char v2; // al
unsigned __int8 v3; // bp
char v4; // r12
unsigned __int8 v5; // dl
unsigned __int8 v6; // al
__int16 result; // ax

v2 = a2;
v3 = a2;
v4 = HIBYTE(a2);
v5 = a1[(unsigned __int8)a2 + 2];
LOBYTE(a2) = 0;
if ( v5 > 7u )
{
v3 = v2 + 1;
LOBYTE(a2) = a1[(unsigned __int8)(v2 + 1) + 2];
}
switch ( v5 )
{
case 0u:
v4 = 1;
goto LABEL_23;
case 1u:
*a1 = (*a1 + a1[1]) & 0xF;
goto LABEL_23;
case 2u:
*a1 = (*a1 - a1[1]) % 16;
goto LABEL_23;
case 3u:
*a1 = (*a1 + 1) & 0xF;
goto LABEL_23;
case 4u:
a1[1] = (a1[1] + 1) & 0xF;
goto LABEL_23;
case 5u:
*a1 = (*a1 - 1) & 0xF;
goto LABEL_23;
case 6u:
a1[1] = (a1[1] - 1) & 0xF;
goto LABEL_23;
case 7u:
putchar(7);
v6 = *a1;
*a1 = a1[1];
a1[1] = v6;
goto LABEL_23;
case 8u:
printf("%d\n", (unsigned __int8)a2);
goto LABEL_23;
case 9u:
*a1 = a1[(unsigned __int8)a2 + 2];
goto LABEL_23;
case 0xAu:
a1[1] = a1[(unsigned __int8)a2 + 2];
goto LABEL_23;
case 0xBu:
a1[(unsigned __int8)a2 + 2] = *a1;
goto LABEL_23;
case 0xCu:
a1[(unsigned __int8)a2 + 2] = a1[1];
goto LABEL_23;
case 0xDu:
return a2;
case 0xEu:
if ( *a1 )
goto LABEL_23;
result = a2;
break;
case 0xFu:
if ( !*a1 )
goto LABEL_23;
result = a2;
break;
default:
printf("Unknown instruction: %d\nHalting...", a1[v3 + 2]);
v4 = 1;
LABEL_23:
LOBYTE(result) = v3 + 1;
HIBYTE(result) = v4;
break;
}
return result;
}

canonical_decompiled_code:
__int16 __fastcall func8(unsigned __int8 *a1, __int16 a2)
{
char v2; // al
unsigned __int8 v3; // bp
char v4; // r12
unsigned __int8 v5; // dl
unsigned __int8 v6; // al
__int16 result; // ax

v2 = a2;
v3 = a2;
v4 = HIBYTE(a2);
v5 = a1[(unsigned __int8)a2 + 2];
LOBYTE(a2) = 0;
if ( v5 > 7u )
{
v3 = v2 + 1;
LOBYTE(a2) = a1[(unsigned __int8)(v2 + 1) + 2];
}
switch ( v5 )
{
case 0u:
v4 = 1;
goto LABEL_23;
case 1u:
*a1 = (*a1 + a1[1]) & 0xF;
goto LABEL_23;
case 2u:
*a1 = (*a1 - a1[1]) % 16;
goto LABEL_23;
case 3u:
*a1 = (*a1 + 1) & 0xF;
goto LABEL_23;
case 4u:
a1[1] = (a1[1] + 1) & 0xF;
goto LABEL_23;
case 5u:
*a1 = (*a1 - 1) & 0xF;
goto LABEL_23;
case 6u:
a1[1] = (a1[1] - 1) & 0xF;
goto LABEL_23;
case 7u:
putchar(7);
v6 = *a1;
*a1 = a1[1];
a1[1] = v6;
goto LABEL_23;
case 8u:
printf("%d\n", (unsigned __int8)a2);
goto LABEL_23;
case 9u:
*a1 = a1[(unsigned __int8)a2 + 2];
goto LABEL_23;
case 0xAu:
a1[1] = a1[(unsigned __int8)a2 + 2];
goto LABEL_23;
case 0xBu:
a1[(unsigned __int8)a2 + 2] = *a1;
goto LABEL_23;
case 0xCu:
a1[(unsigned __int8)a2 + 2] = a1[1];
goto LABEL_23;
case 0xDu:
return a2;
case 0xEu:
if ( *a1 )
goto LABEL_23;
result = a2;
break;
case 0xFu:
if ( !*a1 )
goto LABEL_23;
result = a2;
break;
default:
printf("Unknown instruction: %d\nHalting...", a1[v3 + 2]);
v4 = 1;
LABEL_23:
LOBYTE(result) = v3 + 1;
HIBYTE(result) = v4;
break;
}
return result;
}

original_code:
program_state_t instruction(processor * p, program_state_t state) {
    byte cur = state.cur;
    byte data = 0;
    if (p->mem[cur] >= 0x8) {
        data = p->mem[++(state.cur)];
    }
    switch(p->mem[cur]) {
        case 0x0:
            state.halt = 1;
            break;
        case 0x1:
            p->r0 = (p->r0 + p->r1) % 16;
            break;
        case 0x2:
            p->r0 = (p->r0 - p->r1) % 16;
            break;
        case 0x3:
            p->r0++;
            p->r0 %= 16;
            break;
        case 0x4:
            p->r1++;
            p->r1 %= 16;
            break;
        case 0x5:
            p->r0--;
            p->r0 %= 16;
            break;
        case 0x6:
            p->r1--;
            p->r1 %= 16;
            break;
        case 0x7:
            printf("\a");
            data = p->r0;
            p->r0 = p->r1;
            p->r1 = data;
            break;
        case 0x8:
            printf("%d\n", data);
            break;
        case 0x9:
            p->r0 = p->mem[data];
            break;
        case 0xA:
            p->r1 = p->mem[data];
            break;
        case 0xB:
            p->mem[data] = p->r0;
            break;
        case 0xC:
            p->mem[data] = p->r1;
            break;
        case 0xD:
            state.cur = data;
            return state;
        case 0xE:
            if (p->r0 == 0) {
                state.cur = data;
                return state;
            }
            break;
        case 0xF:
            if (p->r0 != 0) {
                state.cur = data;
                return state;
            }
            break;
        default:
            printf("Unknown instruction: %d\nHalting...", p->mem[state.cur]);
            state.halt = 1;
    }
    state.cur++;
    return state;
}

canonical_original_code:
struct program_state_t instruction(struct processor *p, struct program_state_t state) {
    unsigned char cur = state.cur;
    unsigned char data = 0;
    if (p->mem[cur] >= 0x8) {
        data = p->mem[++(state.cur)];
    }
    switch(p->mem[cur]) {
        case 0x0:
            state.halt = 1;
            break;
        case 0x1:
            p->r0 = (p->r0 + p->r1) % 16;
            break;
        case 0x2:
            p->r0 = (p->r0 - p->r1) % 16;
            break;
        case 0x3:
            p->r0++;
            p->r0 %= 16;
            break;
        case 0x4:
            p->r1++;
            p->r1 %= 16;
            break;
        case 0x5:
            p->r0--;
            p->r0 %= 16;
            break;
        case 0x6:
            p->r1--;
            p->r1 %= 16;
            break;
        case 0x7:
            printf("\a");
            data = p->r0;
            p->r0 = p->r1;
            p->r1 = data;
            break;
        case 0x8:
            printf("%d\n", data);
            break;
        case 0x9:
            p->r0 = p->mem[data];
            break;
        case 0xA:
            p->r1 = p->mem[data];
            break;
        case 0xB:
            p->mem[data] = p->r0;
            break;
        case 0xC:
            p->mem[data] = p->r1;
            break;
        case 0xD:
            state.cur = data;
            return state;
        case 0xE:
            if (p->r0 == 0) {
                state.cur = data;
                return state;
            }
            break;
        case 0xF:
            if (p->r0 != 0) {
                state.cur = data;
                return state;
            }
            break;
        default:
            printf("Unknown instruction: %d\nHalting...", p->mem[state.cur]);
            state.halt = 1;
    }
    state.cur++;
    return state;
}

variable_types:
state
struct program_state_t

variable_types:
cur
unsigned char

variable_types:
data
unsigned char

return_type: struct program_state_t { unsigned char cur; unsigned char halt; }

user_defined_types: struct processor { unsigned char r0; unsigned char r1; unsigned char mem[16]; }


decompiled_code:
_QWORD *LinkedStack_new()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
int *v3; // rbp
char *v4; // r8

v0 = malloc(8uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
}
else
{
v3 = __errno_location();
v4 = "None";
if ( *v3 )
v4 = strerror(*v3);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Out of memory.\n", "src/Stack.c", 11LL, v4);
*v3 = 0;
}
return v1;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
int *v3; // rbp
char *v4; // r8

v0 = malloc(8uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
}
else
{
v3 = __errno_location();
v4 = "None";
if ( *v3 )
v4 = strerror(*v3);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Out of memory.\n", "src/Stack.c", 11LL, v4);
*v3 = 0;
}
return v1;
}

original_code:
LinkedStack * LinkedStack_new()
{
    LinkedStack * stack = malloc(sizeof(LinkedStack));
    { if(!(stack)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Out of memory." "\n", "src/Stack.c", 11, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; } };
    stack->head = ((void *)0);
    return stack;
error:
    return ((void *)0);
}

canonical_original_code:
struct LinkedStack *LinkedStack_new()
{
    struct LinkedStack *stack = malloc(sizeof(LinkedStack));
    { if(!(stack)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Out of memory." "\n", "src/Stack.c", 11, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; } };
    stack->head = ((void *)0);
    return stack;
error:
    return ((void *)0);
}

variable_types: struct LinkedStack { struct _StackNode { void *val; struct _StackNode *next; } *head; } *

user_defined_types: struct LinkedStack { struct _StackNode *head; }


decompiled_code:
__int64 __fastcall LinkedStack_push(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax
int *v4; // rbx
char *v5; // r8
int *v6; // rbx
char *v7; // r8

if ( a1 )
{
v2 = malloc(0x10uLL);
if ( v2 )
{
*v2 = a2;
v2[1] = *a1;
*a1 = v2;
result = 0LL;
}
else
{
v6 = __errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Out of memory.\n", "src/Stack.c", 26LL, v7);
*v6 = 0;
result = 0xFFFFFFFFLL;
}
}
else
{
v4 = __errno_location();
v5 = "None";
if ( *v4 )
v5 = strerror(*v4);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Push given NULL stack.\n", "src/Stack.c", 22LL, v5);
*v4 = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax
int *v4; // rbx
char *v5; // r8
int *v6; // rbx
char *v7; // r8

if ( a1 )
{
v2 = malloc(0x10uLL);
if ( v2 )
{
*v2 = a2;
v2[1] = *a1;
*a1 = v2;
result = 0LL;
}
else
{
v6 = __errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Out of memory.\n", "src/Stack.c", 26LL, v7);
*v6 = 0;
result = 0xFFFFFFFFLL;
}
}
else
{
v4 = __errno_location();
v5 = "None";
if ( *v4 )
v5 = strerror(*v4);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Push given NULL stack.\n", "src/Stack.c", 22LL, v5);
*v4 = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int LinkedStack_push(LinkedStack * stack, void * value)
{
    if(!(stack != ((void *)0))) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Push given NULL stack." "\n", "src/Stack.c", 22, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
    _StackNode * node = malloc(sizeof(_StackNode));
    { if(!(node)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Out of memory." "\n", "src/Stack.c", 26, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; } };
    node->val = value;
    node->next = stack->head;
    stack->head = node;
    return 0;
error:
    return -1;
}

canonical_original_code:
int LinkedStack_push(struct LinkedStack *stack, void *value)
{
    if(!(stack != ((void *)0))) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Push given NULL stack." "\n", "src/Stack.c", 22, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
    struct _StackNode *node = malloc(sizeof(_StackNode));
    { if(!(node)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Out of memory." "\n", "src/Stack.c", 26, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; } };
    node->val = value;
    node->next = stack->head;
    stack->head = node;
    return 0;
error:
    return -1;
}

variable_types:
value
void *

variable_types: struct _StackNode { void *val; struct _StackNode *next; } *

return_type: int


decompiled_code:
_BOOL8 __fastcall LinkedStack_empty(_QWORD *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 )
result = *a1 == 0LL;
return result;
}

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

result = 1LL;
if ( a1 )
result = *a1 == 0LL;
return result;
}

original_code:
int LinkedStack_empty(LinkedStack * stack)
{
    return stack == ((void *)0) || stack->head == ((void *)0);
}

canonical_original_code:
int LinkedStack_empty(struct LinkedStack *stack)
{
    return stack == ((void *)0) || stack->head == ((void *)0);
}

user_defined_types: struct _StackNode { void *val; struct _StackNode *next; }


decompiled_code:
void __fastcall LinkedStack_destroy(void *ptr)
{
void **v1; // rbx

if ( ptr )
{
while ( !LinkedStack_empty(ptr) )
{
v1 = *(void ***)ptr;
*(_QWORD *)ptr = *(_QWORD *)(*(_QWORD *)ptr + 8LL);
free(*v1);
free(v1);
}
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
void **v1; // rbx

if ( ptr )
{
while ( !func9(ptr) )
{
v1 = *(void ***)ptr;
*(_QWORD *)ptr = *(_QWORD *)(*(_QWORD *)ptr + 8LL);
free(*v1);
free(v1);
}
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

original_code:
void LinkedStack_destroy(LinkedStack * stack)
{
    if(!(stack != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    while (!LinkedStack_empty(stack)) {
        _StackNode * n = stack->head;
        stack->head = n->next;
        free(n->val);
        free(n);
    }
    free(stack);
error:
    return;
}

canonical_original_code:
void LinkedStack_destroy(struct LinkedStack *stack)
{
    if(!(stack != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    while (!LinkedStack_empty(stack)) {
        struct _StackNode *n = stack->head;
        stack->head = n->next;
        free(n->val);
        free(n);
    }
    free(stack);
error:
    return;
}


decompiled_code:
_QWORD *TokenList_new()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
int *v3; // rbp
char *v4; // r8

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
*((_DWORD *)v0 + 4) = 0;
}
else
{
v3 = __errno_location();
v4 = "None";
if ( *v3 )
v4 = strerror(*v3);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Out of memory.\n", "src/TokenList.c", 38LL, v4);
*v3 = 0;
}
return v1;
}

canonical_decompiled_code:
_QWORD *func11()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
int *v3; // rbp
char *v4; // r8

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
*((_DWORD *)v0 + 4) = 0;
}
else
{
v3 = __errno_location();
v4 = "None";
if ( *v3 )
v4 = strerror(*v3);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Out of memory.\n", "src/TokenList.c", 38LL, v4);
*v3 = 0;
}
return v1;
}

original_code:
TokenList * TokenList_new()
{
    TokenList * list = malloc(sizeof(TokenList));
    { if(!(list)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Out of memory." "\n", "src/TokenList.c", 38, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; } }
    list->head = ((void *)0);
    list->tail = ((void *)0);
    list->length = 0;
    return list;
error:
    return ((void *)0);
}

canonical_original_code:
struct TokenList *TokenList_new()
{
    struct TokenList *list = malloc(sizeof(TokenList));
    { if(!(list)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Out of memory." "\n", "src/TokenList.c", 38, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; } }
    list->head = ((void *)0);
    list->tail = ((void *)0);
    list->length = 0;
    return list;
error:
    return ((void *)0);
}

variable_types: struct TokenList { struct _TokenListNode { struct _TokenListNode *next; struct _TokenListNode *prev; struct Token { int type; union { char *str; double num; }; } *token; } *head; struct _TokenListNode *tail; int length; } *

user_defined_types: struct TokenList { struct _TokenListNode *head; struct _TokenListNode *tail; int length; }

user_defined_types: struct _TokenListNode { struct _TokenListNode *next; struct _TokenListNode *prev; struct Token *token; }


decompiled_code:
void __fastcall Token_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
if ( *(_DWORD *)ptr != 1 )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
}
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
if ( *(_DWORD *)ptr != 1 )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
}
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

original_code:
void Token_destroy(Token * token)
{
    if(!(token != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    if (token->type != 1 && token->str != ((void *)0)) {
        free(token->str);
    }
    free(token);
error:
    return;
}

canonical_original_code:
void Token_destroy(struct Token *token)
{
    if(!(token != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    if (token->type != 1 && token->str != ((void *)0)) {
        free(token->str);
    }
    free(token);
error:
    return;
}

variable_types: struct Token { int type; union { char *str; double num; }; } *


decompiled_code:
void __fastcall TokenListNode_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
Token_destroy(v2);
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
func13(v2);
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

original_code:
void TokenListNode_destroy(_TokenListNode * node)
{
    if(!(node != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    if (node->token != ((void *)0)) {
        Token_destroy(node->token);
    }
    free(node);
error:
    return;
}

canonical_original_code:
void TokenListNode_destroy(struct _TokenListNode *node)
{
    if(!(node != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    if (node->token != ((void *)0)) {
        Token_destroy(node->token);
    }
    free(node);
error:
    return;
}

variable_types: struct _TokenListNode { struct _TokenListNode *next; struct _TokenListNode *prev; struct Token { int type; union { char *str; double num; }; } *token; } *


decompiled_code:
void __fastcall TokenList_destroy(void *ptr)
{
_QWORD *v2; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( v2 )
{
do
{
*(_QWORD *)ptr = *v2;
TokenListNode_destroy(v2);
v2 = *(_QWORD **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
_QWORD *v2; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( v2 )
{
do
{
*(_QWORD *)ptr = *v2;
func14(v2);
v2 = *(_QWORD **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}
else
{
*__errno_location() = 0;
}
}

original_code:
void TokenList_destroy(TokenList * list)
{
    if(!(list != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    if (!(list->head == ((void *)0)) || !(list->tail == ((void *)0))) {
        _TokenListNode * node;
        while (list->head != ((void *)0)) {
            node = list->head;
            list->head = node->next;
            TokenListNode_destroy(node);
        }
    }
    free(list);
error:
    return;
}

canonical_original_code:
void TokenList_destroy(struct TokenList *list)
{
    if(!(list != ((void *)0))) { ; (*__errno_location ())=0; goto error; };
    if (!(list->head == ((void *)0)) || !(list->tail == ((void *)0))) {
        struct _TokenListNode *node;
        while (list->head != ((void *)0)) {
            node = list->head;
            list->head = node->next;
            TokenListNode_destroy(node);
        }
    }
    free(list);
error:
    return;
}

user_defined_types: struct Token { int type; union { char *str; double num; }; }


decompiled_code:
const char *test_stack_push_pop()
{
_QWORD *v0; // rbx
int v1; // edi
char *v2; // r8
const char *result; // rax
int v4; // edi
char *v5; // r8
int v6; // edi
char *v7; // r8
int v8; // edi
char *v9; // r8
int v10; // edi
char *v11; // r8

v0 = LinkedStack_new();
if ( (unsigned int)LinkedStack_push(v0, (__int64)"first") )
{
v1 = *__errno_location();
v2 = "None";
if ( v1 )
v2 = strerror(v1);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to push first item\n", "tests/stack_tests.c", 12LL, v2);
result = "Failed to push first item";
}
else if ( (unsigned int)LinkedStack_push(v0, (__int64)"second") )
{
v4 = *__errno_location();
v5 = "None";
if ( v4 )
v5 = strerror(v4);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to push second item\n", "tests/stack_tests.c", 13LL, v5);
result = "Failed to push second item";
}
else if ( LinkedStack_pop((_QWORD **)v0) == (_QWORD **)"second" )
{
if ( LinkedStack_pop((_QWORD **)v0) == (_QWORD **)"first" )
{
result = (const char *)LinkedStack_pop((_QWORD **)v0);
if ( result )
{
v10 = *__errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
fprintf(
stderr,
"[ERROR] (%s:%d errno: %s) Failed to pop NULL from empty stack.\n",
"tests/stack_tests.c",
17LL,
v11);
result = "Failed to pop NULL from empty stack.";
}
}
else
{
v8 = *__errno_location();
v9 = "None";
if ( v8 )
v9 = strerror(v8);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to pop first item.\n", "tests/stack_tests.c", 16LL, v9);
result = "Failed to pop first item.";
}
}
else
{
v6 = *__errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to pop second item.\n", "tests/stack_tests.c", 15LL, v7);
result = "Failed to pop second item.";
}
return result;
}

canonical_decompiled_code:
const char *func16()
{
_QWORD *v0; // rbx
int v1; // edi
char *v2; // r8
const char *result; // rax
int v4; // edi
char *v5; // r8
int v6; // edi
char *v7; // r8
int v8; // edi
char *v9; // r8
int v10; // edi
char *v11; // r8

v0 = func7();
if ( (unsigned int)func8(v0, (__int64)"first") )
{
v1 = *__errno_location();
v2 = "None";
if ( v1 )
v2 = strerror(v1);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to push first item\n", "tests/stack_tests.c", 12LL, v2);
result = "Failed to push first item";
}
else if ( (unsigned int)func8(v0, (__int64)"second") )
{
v4 = *__errno_location();
v5 = "None";
if ( v4 )
v5 = strerror(v4);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to push second item\n", "tests/stack_tests.c", 13LL, v5);
result = "Failed to push second item";
}
else if ( LinkedStack_pop((_QWORD **)v0) == (_QWORD **)"second" )
{
if ( LinkedStack_pop((_QWORD **)v0) == (_QWORD **)"first" )
{
result = (const char *)LinkedStack_pop((_QWORD **)v0);
if ( result )
{
v10 = *__errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
fprintf(
stderr,
"[ERROR] (%s:%d errno: %s) Failed to pop NULL from empty stack.\n",
"tests/stack_tests.c",
17LL,
v11);
result = "Failed to pop NULL from empty stack.";
}
}
else
{
v8 = *__errno_location();
v9 = "None";
if ( v8 )
v9 = strerror(v8);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to pop first item.\n", "tests/stack_tests.c", 16LL, v9);
result = "Failed to pop first item.";
}
}
else
{
v6 = *__errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
fprintf(stderr, "[ERROR] (%s:%d errno: %s) Failed to pop second item.\n", "tests/stack_tests.c", 15LL, v7);
result = "Failed to pop second item.";
}
return result;
}

original_code:
char * test_stack_push_pop()
{
    LinkedStack * stack = LinkedStack_new();
    char * first = "first";
    char * second = "second";
    if(!(LinkedStack_push(stack, first) == 0)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to push first item" "\n", "tests/stack_tests.c", 12, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to push first item"; };
    if(!(LinkedStack_push(stack, second) == 0)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to push second item" "\n", "tests/stack_tests.c", 13, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to push second item"; };
    if(!(LinkedStack_pop(stack) == second)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to pop second item." "\n", "tests/stack_tests.c", 15, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to pop second item."; };
    if(!(LinkedStack_pop(stack) == first)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to pop first item." "\n", "tests/stack_tests.c", 16, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to pop first item."; };
    if(!(LinkedStack_pop(stack) == ((void *)0))) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to pop NULL from empty stack." "\n", "tests/stack_tests.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to pop NULL from empty stack."; };
    return ((void *)0);
}

canonical_original_code:
char *test_stack_push_pop()
{
    struct LinkedStack *stack = LinkedStack_new();
    char *first = "first";
    char *second = "second";
    if(!(LinkedStack_push(stack, first) == 0)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to push first item" "\n", "tests/stack_tests.c", 12, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to push first item"; };
    if(!(LinkedStack_push(stack, second) == 0)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to push second item" "\n", "tests/stack_tests.c", 13, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to push second item"; };
    if(!(LinkedStack_pop(stack) == second)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to pop second item." "\n", "tests/stack_tests.c", 15, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to pop second item."; };
    if(!(LinkedStack_pop(stack) == first)) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to pop first item." "\n", "tests/stack_tests.c", 16, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to pop first item."; };
    if(!(LinkedStack_pop(stack) == ((void *)0))) { fprintf(stderr, "[ERROR] (%s:%d errno: %s) " "Failed to pop NULL from empty stack." "\n", "tests/stack_tests.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); return "Failed to pop NULL from empty stack."; };
    return ((void *)0);
}

variable_types:
first
char *

variable_types:
second
char *

return_type: char *


decompiled_code:
const char *all_tests()
{
const char *result; // rax

fprintf(stderr, "[DEBUG] (%s:%d) \n-----%s\n", "tests/stack_tests.c", 24LL, " test_stack_push_pop");
result = test_stack_push_pop();
++tests_run;
return result;
}

canonical_decompiled_code:
const char *func17()
{
const char *result; // rax

fprintf(stderr, "[DEBUG] (%s:%d) \n-----%s\n", "tests/stack_tests.c", 24LL, " test_stack_push_pop");
result = func16();
++tests_run;
return result;
}

original_code:
char * all_tests() {
    char * message = ((void *)0);
    fprintf(stderr, "[DEBUG] (%s:%d) " "\n-----%s" "\n", "tests/stack_tests.c", 24, " " "test_stack_push_pop"); message = test_stack_push_pop(); tests_run++; if (message) return message;;
    return ((void *)0);
}

canonical_original_code:
char *all_tests() {
    char *message = ((void *)0);
    fprintf(stderr, "[DEBUG] (%s:%d) " "\n-----%s" "\n", "tests/stack_tests.c", 24, " " "test_stack_push_pop"); message = test_stack_push_pop(); tests_run++; if (message) return message;;
    return ((void *)0);
}

variable_types:
message
char *


main

canonical_name: main

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

fprintf(stderr, "[DEBUG] (%s:%d) ----- RUNNING: %s\n", "tests/stack_tests.c", 29LL, *argv);
printf("----\nRUNNING: %s\n", *argv);
v3 = all_tests();
v4 = v3;
if ( v3 )
printf("FAILED: %s\n", v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
exit(v4 != 0LL);
}

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

fprintf(stderr, "[DEBUG] (%s:%d) ----- RUNNING: %s\n", "tests/stack_tests.c", 29LL, *argv);
printf("----\nRUNNING: %s\n", *argv);
v3 = func17();
v4 = v3;
if ( v3 )
printf("FAILED: %s\n", v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
exit(v4 != 0LL);
}

original_code: int main(int argc, char *argv[]) { argc = 1; fprintf(stderr, "[DEBUG] (%s:%d) " "----- RUNNING: %s" "\n", "tests/stack_tests.c", 29, argv[0]); printf("----\nRUNNING: %s\n", argv[0]); char * result = all_tests(); if (result != 0) { printf("FAILED: %s\n", result); } else { printf("ALL TESTS PASSED\n"); } printf("Tests run: %d\n", tests_run); exit(result != 0);}

canonical_original_code: int main(int argc, char *argv[]) { argc = 1; fprintf(stderr, "[DEBUG] (%s:%d) " "----- RUNNING: %s" "\n", "tests/stack_tests.c", 29, argv[0]); printf("----\nRUNNING: %s\n", argv[0]); char *result = all_tests(); if (result != 0) { printf("FAILED: %s\n", result); } else { printf("ALL TESTS PASSED\n"); } printf("Tests run: %d\n", tests_run); exit(result != 0);}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
result
char *


createIntegerNode

repo: AKdroid/DataStructures

decompiled_code:
void *createIntegerNode()
{
return malloc(0x18uLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x18uLL);
}

original_code:
IntegerList* createIntegerNode(){
    return (IntegerList *)malloc(sizeof(IntegerList));
}

canonical_original_code:
struct IntegerList *createIntegerNode(){
    return (struct IntegerList *)malloc(sizeof(IntegerList));
}

return_type: struct IntegerList { int num; struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } node; } *

user_defined_types: struct IntegerList { int num; struct linklist_head node; }


getIntegerList

decompiled_code:
__int64 __fastcall getIntegerList(__int64 a1)
{
__int64 result; // rax

result = a1 - 8;
if ( !a1 )
result = 0LL;
return result;
}

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

result = a1 - 8;
if ( !a1 )
result = 0LL;
return result;
}

original_code:
IntegerList * getIntegerList(linklist *node_){
    if(node_==((void *)0))
        return ((void *)0);
    int offset=__builtin_offsetof (IntegerList, node);
    char *temp=(char *)node_;
    return (IntegerList *)(temp-offset);
}

canonical_original_code:
struct IntegerList *getIntegerList(struct linklist_head *node_){
    if(node_==((void *)0))
        return ((void *)0);
    int offset = __builtin_offsetof (IntegerList, node);
    char *temp = (char *)node_;
    return (struct IntegerList *)(temp-offset);
}

variable_types: offset int

variable_types:
temp
char *

user_defined_types: struct linklist_head { struct linklist_head *next; struct linklist_head *prev; }


decompiled_code:
void __fastcall remove_Integer(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
void *v4; // rax

v2 = get(a2, a1);
if ( v2 )
{
v3 = v2;
if ( !(unsigned int)detachnode(a2, a1) )
{
v4 = (void *)getIntegerList(v3);
free(v4);
}
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
void *v4; // rax

v2 = get(a2, a1);
if ( v2 )
{
v3 = v2;
if ( !(unsigned int)detachnode(a2, a1) )
{
v4 = (void *)func2(v3);
free(v4);
}
}
}

original_code:
void remove_Integer(int position,linklist **first){
    linklist*temp=get(first,position);
    IntegerList* tempI;
    if(temp!=((void *)0)){
        tempI=getIntegerList(temp);
        int result=detachnode(first,position);
        if(result==0)
        free(tempI);
    }
}

canonical_original_code:
void remove_Integer(int position, struct linklist_head **first){
    struct linklist_head *temp = get(first,position);
    struct IntegerList *tempI;
    if(temp!=((void *)0)){
        tempI=getIntegerList(temp);
        int result = detachnode(first,position);
        if(result==0)
        free(tempI);
    }
}

variable_types: position int

variable_types: struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } **

variable_types: struct IntegerList { int num; struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } node; } *

variable_types: result int


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

result = get(a1, a2);
if ( result )
result = getIntegerList(result);
return result;
}

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

result = get(a1, a2);
if ( result )
result = func2(result);
return result;
}

original_code:
IntegerList* get_Integer(linklist ** first,int position){
    linklist* temp=get(first,position);
    if(temp!=((void *)0))
        return getIntegerList(temp);
    else
        return ((void *)0);
}

canonical_original_code:
struct IntegerList *get_Integer(struct linklist_head **first, int position){
    struct linklist_head *temp = get(first,position);
    if(temp!=((void *)0))
        return getIntegerList(temp);
    else
        return ((void *)0);
}

variable_types:
first
struct linklist_head **

variable_types: struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } *


getnextentry

decompiled_code:
__int64 __fastcall getnextentry(__int64 a1)
{
return getIntegerList(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return func2(*(_QWORD *)(a1 + 8));
}

original_code:
IntegerList* getnextentry(IntegerList* curr){
    return getIntegerList(curr->node.next);
}

canonical_original_code:
struct IntegerList *getnextentry(struct IntegerList *curr){
    return getIntegerList(curr->node.next);
}

variable_types:
curr
struct IntegerList *


getpreventry

decompiled_code:
__int64 __fastcall getpreventry(__int64 a1)
{
return getIntegerList(*(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return func2(*(_QWORD *)(a1 + 16));
}

original_code:
IntegerList* getpreventry(IntegerList* curr){
    return getIntegerList(curr->node.prev);
}

canonical_original_code:
struct IntegerList *getpreventry(struct IntegerList *curr){
    return getIntegerList(curr->node.prev);
}


decompiled_code:
void sort_list()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void sort_list(IntegerList * list_first){
}

canonical_original_code:
void sort_list(struct IntegerList *list_first){
}


decompiled_code:
__int64 __fastcall search_list(int a1, __int64 *a2)
{
__int64 v3; // rax
_DWORD *v4; // rdi
unsigned int v5; // ebx

v3 = getIntegerList(*a2);
if ( !v3 )
return (unsigned int)-1;
v4 = (_DWORD *)v3;
v5 = -1;
while ( 1 )
{
++v5;
if ( *v4 == a1 )
break;
v4 = (_DWORD *)getnextentry((__int64)v4);
if ( !v4 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 *a2)
{
__int64 v3; // rax
_DWORD *v4; // rdi
unsigned int v5; // ebx

v3 = func2(*a2);
if ( !v3 )
return (unsigned int)-1;
v4 = (_DWORD *)v3;
v5 = -1;
while ( 1 )
{
++v5;
if ( *v4 == a1 )
break;
v4 = (_DWORD *)func6((__int64)v4);
if ( !v4 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int search_list(int number,linklist ** first){
    int pos=-1,cnt=-1;
    IntegerList * entry =getIntegerList(*first);
    while(entry!= ((void *)0)){
        pos++;
        if(entry->num==number){
            cnt=pos;
            break;
        }
        entry=getnextentry(entry);
    }
    return cnt;
}

canonical_original_code:
int search_list(int number, struct linklist_head **first){
    int pos = -1; int cnt = -1;
    struct IntegerList *entry = getIntegerList(*first);
    while(entry!= ((void *)0)){
        pos++;
        if(entry->num==number){
            cnt=pos;
            break;
        }
        entry=getnextentry(entry);
    }
    return cnt;
}

variable_types: number int

variable_types: pos int

variable_types: cnt int


display

decompiled_code:
int __fastcall display(unsigned int *a1)
{
return printf("%d \n ", *a1);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
return printf("%d \n ", *a1);
}

original_code:
void display(IntegerList *list_entry){
    printf("%d \n ",list_entry->num);
}

canonical_original_code:
void display(struct IntegerList *list_entry){
    printf("%d \n ",list_entry->num);
}


displayall

decompiled_code:
__int64 __fastcall displayall(__int64 *a1)
{
unsigned int *v1; // rbx
int i; // ebp
__int64 result; // rax

v1 = (unsigned int *)getIntegerList(*a1);
for ( i = 0; ; ++i )
{
result = count(a1);
if ( (int)result <= i )
break;
printf("%d\n", *v1);
v1 = (unsigned int *)getnextentry((__int64)v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
unsigned int *v1; // rbx
int i; // ebp
__int64 result; // rax

v1 = (unsigned int *)func2(*a1);
for ( i = 0; ; ++i )
{
result = count(a1);
if ( (int)result <= i )
break;
printf("%d\n", *v1);
v1 = (unsigned int *)func6((__int64)v1);
}
return result;
}

original_code:
void displayall(linklist** first){
    int i;
    IntegerList*nw=getIntegerList(*first);
    for(i=0;i<count(first);i++){
        printf("%d\n",nw->num);
        nw=getnextentry(nw);
    }
}

canonical_original_code:
void displayall(struct linklist_head **first){
    int i;
    struct IntegerList *nw = getIntegerList(*first);
    for(i=0;i<count(first);i++){
        printf("%d\n",nw->num);
        nw=getnextentry(nw);
    }
}

variable_types: i int


createNode

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

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
BST * createNode(){
    BST * node= (BST *)malloc(sizeof(BST));
    node->data=0;
    node->left=((void *)0);
    node->right=((void *)0);
    return node;
}

canonical_original_code:
struct BST *createNode(){
    struct BST *node = (BST *)malloc(sizeof(BST));
    node->data=0;
    node->left=((void *)0);
    node->right=((void *)0);
    return node;
}

variable_types: struct BST { int data; struct BST *left; struct BST *right; } *


deleteNode

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

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

original_code:
void deleteNode(BST * node){
    free(node);
}

canonical_original_code:
void deleteNode(struct BST *node){
    free(node);
}

user_defined_types: struct BST { int data; struct BST *left; struct BST *right; }


search

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

*a3 = 0LL;
if ( !a2 )
return 0LL;
if ( *(_DWORD *)a2 > (int)a1 )
{
result = search(a1, *(_QWORD *)(a2 + 8), a3);
if ( *(_QWORD *)(a2 + 8) == result )
*a3 = a2;
}
else
{
result = a2;
if ( *(_DWORD *)a2 < (int)a1 )
{
result = search(a1, *(_QWORD *)(a2 + 16), a3);
if ( *(_QWORD *)(a2 + 16) == result )
*a3 = a2;
}
}
return result;
}

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

*a3 = 0LL;
if ( !a2 )
return 0LL;
if ( *(_DWORD *)a2 > (int)a1 )
{
result = func2(a1, *(_QWORD *)(a2 + 8), a3);
if ( *(_QWORD *)(a2 + 8) == result )
*a3 = a2;
}
else
{
result = a2;
if ( *(_DWORD *)a2 < (int)a1 )
{
result = func2(a1, *(_QWORD *)(a2 + 16), a3);
if ( *(_QWORD *)(a2 + 16) == result )
*a3 = a2;
}
}
return result;
}

original_code:
BST *search(int data_,BST *root,BST **parent){
    BST* node=((void *)0);
    *parent=((void *)0);
    if(root!=((void *)0)){
        if(data_<root->data){
           node= search(data_,root->left,parent);
           if(root->left==node){
               *parent=root;
           }
        }
        else if(data_>root->data){
            node=search(data_,root->right,parent);
            if(root->right==node){
               *parent=root;
           }
        }
        else{
            return root;
        }
    }
    return node;
}

canonical_original_code:
struct BST *search(int data_, struct BST *root, struct BST **parent){
    struct BST *node = ((void *)0);
    *parent=((void *)0);
    if(root!=((void *)0)){
        if(data_<root->data){
           node= search(data_,root->left,parent);
           if(root->left==node){
               *parent=root;
           }
        }
        else if(data_>root->data){
            node=search(data_,root->right,parent);
            if(root->right==node){
               *parent=root;
           }
        }
        else{
            return root;
        }
    }
    return node;
}

variable_types:
root
struct BST *

variable_types:
parent
struct BST **

return_type: struct BST { int data; struct BST *left; struct BST *right; } *


removeData

original_code:
int removeData(int data_,BST **root){
    BST* parent=((void *)0),*succ=((void *)0);
    BST *node=search(data_,*root,&parent);
    if(node==((void *)0))
        return 0;
    else
    {
        if(node->left!=((void *)0)&&node->right!=((void *)0)){
            parent=node;
            succ=node->right;
            while(succ->left!=((void *)0)){
                parent=succ;
                succ=succ->left;
            }
            printf("In double children\n");
            node->data=succ->data;
            node=succ;
        }
        if(node->left==((void *)0)&&node->right==((void *)0)){
            if(parent->left==node )
                parent->left=((void *)0);
            else
                parent->right=((void *)0);
        }
        else if(node->left==((void *)0)){
            if(parent->left==node )
                parent->left=node->right;
            else
                parent->right=node->right;
        }
        else if(node->right==((void *)0)){
            if(parent->left==node )
                parent->left=node->left;
            else
                parent->right=node->left;
        }
        deleteNode(node);
        return 1;
    }
}

canonical_original_code:
int removeData(int data_, struct BST **root){
    struct BST *parent = ((void *)0); struct BST *succ = ((void *)0);
    struct BST *node = search(data_,*root,&parent);
    if(node==((void *)0))
        return 0;
    else
    {
        if(node->left!=((void *)0)&&node->right!=((void *)0)){
            parent=node;
            succ=node->right;
            while(succ->left!=((void *)0)){
                parent=succ;
                succ=succ->left;
            }
            printf("In double children\n");
            node->data=succ->data;
            node=succ;
        }
        if(node->left==((void *)0)&&node->right==((void *)0)){
            if(parent->left==node )
                parent->left=((void *)0);
            else
                parent->right=((void *)0);
        }
        else if(node->left==((void *)0)){
            if(parent->left==node )
                parent->left=node->right;
            else
                parent->right=node->right;
        }
        else if(node->right==((void *)0)){
            if(parent->left==node )
                parent->left=node->left;
            else
                parent->right=node->left;
        }
        deleteNode(node);
        return 1;
    }
}

variable_types: struct BST { int data; struct BST *left; struct BST *right; } **


decompiled_code:
__int64 __fastcall display_inorder(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
display_inorder(*((_QWORD *)a1 + 1));
printf("%d\n", *a1);
result = display_inorder(*((_QWORD *)a1 + 2));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
func4(*((_QWORD *)a1 + 1));
printf("%d\n", *a1);
result = func4(*((_QWORD *)a1 + 2));
}
return result;
}

original_code:
void display_inorder(BST *root){
    if(root==((void *)0))
        return;
     display_inorder(root->left);
     printf("%d\n",root->data);
     display_inorder(root->right);
}

canonical_original_code:
void display_inorder(struct BST *root){
    if(root==((void *)0))
        return;
     display_inorder(root->left);
     printf("%d\n",root->data);
     display_inorder(root->right);
}


resetcount

decompiled_code:
void resetcount()
{
bst_cnt = 0;
}

canonical_decompiled_code:
void func5()
{
bst_cnt = 0;
}

original_code:
void resetcount(){
    bst_cnt=0;
}

canonical_original_code:
void resetcount(){
    bst_cnt=0;
}


decompiled_code:
__int64 __fastcall display_order_statistic(unsigned int *a1, unsigned int a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

if ( a1 )
{
display_order_statistic(*((_QWORD *)a1 + 1));
if ( bst_cnt == a2 )
{
v5 = *a1;
*a3 = v5;
printf("\nmedian=%d , %d", a2, v5);
}
++bst_cnt;
result = display_order_statistic(*((_QWORD *)a1 + 2));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, unsigned int a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

if ( a1 )
{
func6(*((_QWORD *)a1 + 1));
if ( bst_cnt == a2 )
{
v5 = *a1;
*a3 = v5;
printf("\nmedian=%d , %d", a2, v5);
}
++bst_cnt;
result = func6(*((_QWORD *)a1 + 2));
}
return result;
}

original_code:
void display_order_statistic(BST *root,int order,int *value){
    if(root==((void *)0))
        return;
     display_order_statistic(root->left,order,value);
     if(bst_cnt==order){
         *value=root->data;
         printf("\nmedian=%d , %d",bst_cnt,root->data);
     }
     bst_cnt++;
     display_order_statistic(root->right,order,value);
}

canonical_original_code:
void display_order_statistic(struct BST *root, int order, int *value){
    if(root==((void *)0))
        return;
     display_order_statistic(root->left,order,value);
     if(bst_cnt==order){
         *value=root->data;
         printf("\nmedian=%d , %d",bst_cnt,root->data);
     }
     bst_cnt++;
     display_order_statistic(root->right,order,value);
}

variable_types: order int

variable_types:
value
int *


decompiled_code:
__int64 __fastcall display_preorder(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
printf("%d\n", *a1);
display_preorder(*((_QWORD *)a1 + 1));
result = display_preorder(*((_QWORD *)a1 + 2));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
printf("%d\n", *a1);
func7(*((_QWORD *)a1 + 1));
result = func7(*((_QWORD *)a1 + 2));
}
return result;
}

original_code:
void display_preorder(BST *root){
    if(root==((void *)0))
        return;
     printf("%d\n",root->data);
     display_preorder(root->left);
     display_preorder(root->right);
}

canonical_original_code:
void display_preorder(struct BST *root){
    if(root==((void *)0))
        return;
     printf("%d\n",root->data);
     display_preorder(root->left);
     display_preorder(root->right);
}


decompiled_code:
int __fastcall display_postorder(unsigned int *a1)
{
int result; // eax

if ( a1 )
{
display_postorder(*((_QWORD *)a1 + 1));
display_postorder(*((_QWORD *)a1 + 2));
result = printf("%d\n", *a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
int result; // eax

if ( a1 )
{
func8(*((_QWORD *)a1 + 1));
func8(*((_QWORD *)a1 + 2));
result = printf("%d\n", *a1);
}
return result;
}

original_code:
void display_postorder(BST *root){
    if(root==((void *)0))
        return;
    display_postorder(root->left);
    display_postorder(root->right);
    printf("%d\n",root->data);
}

canonical_original_code:
void display_postorder(struct BST *root){
    if(root==((void *)0))
        return;
    display_postorder(root->left);
    display_postorder(root->right);
    printf("%d\n",root->data);
}


decompiled_code:
__int64 __fastcall display_reverseinorder(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
display_reverseinorder(*((_QWORD *)a1 + 2));
printf("%d\n", *a1);
result = display_reverseinorder(*((_QWORD *)a1 + 1));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
{
func9(*((_QWORD *)a1 + 2));
printf("%d\n", *a1);
result = func9(*((_QWORD *)a1 + 1));
}
return result;
}

original_code:
void display_reverseinorder(BST *root){
    if(root==((void *)0))
        return;
    display_reverseinorder(root->right);
    printf("%d\n",root->data);
    display_reverseinorder(root->left);
}

canonical_original_code:
void display_reverseinorder(struct BST *root){
    if(root==((void *)0))
        return;
    display_reverseinorder(root->right);
    printf("%d\n",root->data);
    display_reverseinorder(root->left);
}


createnode

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
linklist * createnode(){
    linklist*nw= (linklist *)malloc(sizeof(linklist));
    nw->next=((void *)0);
    nw->prev=((void *)0);
    return nw;
}

canonical_original_code:
struct linklist_head *createnode(){
    struct linklist_head *nw = (linklist *)malloc(sizeof(linklist));
    nw->next=((void *)0);
    nw->prev=((void *)0);
    return nw;
}

return_type: struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } *


deletenode

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

original_code:
void deletenode(linklist *node){
    free(node);
}

canonical_original_code:
void deletenode(struct linklist_head *node){
    free(node);
}


gotonext

decompiled_code:
__int64 __fastcall gotonext(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
linklist * gotonext( linklist * current){
    return current->next;
}

canonical_original_code:
struct linklist_head *gotonext(struct linklist_head *current){
    return current->next;
}

variable_types:
current
struct linklist_head *


gotoprevious

decompiled_code:
__int64 __fastcall gotoprevious(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
linklist * gotoprevious(linklist * current){
    return current->prev;
}

canonical_original_code:
struct linklist_head *gotoprevious(struct linklist_head *current){
    return current->prev;
}


count

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

original_code:
int count(linklist **first){
    int count=0;
    linklist *now=*first;
    while(now != ((void *)0)){
        count++;
        now=now->next;
    }
    return count;
}

canonical_original_code:
int count(struct linklist_head **first){
    int count = 0;
    struct linklist_head *now = *first;
    while(now != ((void *)0)){
        count++;
        now=now->next;
    }
    return count;
}

variable_types: struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } **

variable_types: count int


insert

decompiled_code:
__int64 __fastcall insert(_QWORD **a1, int a2, _QWORD *a3)
{
__int64 result; // rax
_QWORD *v5; // rdx
int v6; // esi
int v7; // eax

if ( (int)count(a1) < a2 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v5 = *a1;
if ( a2 > 1 )
{
v6 = a2 - 1;
v7 = 0;
do
{
v5 = (_QWORD *)*v5;
++v7;
}
while ( v7 != v6 );
}
*a3 = *v5;
a3[1] = v5;
if ( *v5 )
*(_QWORD *)(*v5 + 8LL) = a3;
*v5 = a3;
result = 0LL;
}
else
{
a3[1] = 0LL;
*a3 = *a1;
*a1 = a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD **a1, int a2, _QWORD *a3)
{
__int64 result; // rax
_QWORD *v5; // rdx
int v6; // esi
int v7; // eax

if ( (int)func4(a1) < a2 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v5 = *a1;
if ( a2 > 1 )
{
v6 = a2 - 1;
v7 = 0;
do
{
v5 = (_QWORD *)*v5;
++v7;
}
while ( v7 != v6 );
}
*a3 = *v5;
a3[1] = v5;
if ( *v5 )
*(_QWORD *)(*v5 + 8LL) = a3;
*v5 = a3;
result = 0LL;
}
else
{
a3[1] = 0LL;
*a3 = *a1;
*a1 = a3;
result = 0LL;
}
return result;
}

original_code:
int insert( linklist **first,int position,linklist* node){
    int i;
    linklist *nw;
    if(position>count(first)){
        return -1;
    }
    else if(position == 0){
        node->prev=((void *)0);
        node->next=*first;
        *first=node;
    }
    else{
        nw=*first;
        for(i=0;i<position-1;i++){
            nw=nw->next;
        }
        node->next=nw->next;
        node->prev=nw;
        if(nw->next!=((void *)0))
        nw->next->prev=node;
        nw->next=node;
    }
    return 0;
}

canonical_original_code:
int insert(struct linklist_head **first, int position, struct linklist_head *node){
    int i;
    struct linklist_head *nw;
    if(position>count(first)){
        return -1;
    }
    else if(position == 0){
        node->prev=((void *)0);
        node->next=*first;
        *first=node;
    }
    else{
        nw=*first;
        for(i=0;i<position-1;i++){
            nw=nw->next;
        }
        node->next=nw->next;
        node->prev=nw;
        if(nw->next!=((void *)0))
        nw->next->prev=node;
        nw->next=node;
    }
    return 0;
}

variable_types: position int

variable_types:
node
struct linklist_head *


detachnode

decompiled_code:
__int64 __fastcall detachnode(_QWORD **a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // rcx
int v4; // edx
_QWORD *v5; // rax

if ( (int)count(a1) <= a2 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v3 = *a1;
if ( a2 > 1 )
{
v4 = 0;
do
{
v3 = (_QWORD *)*v3;
++v4;
}
while ( v4 != a2 - 1 );
}
v5 = (_QWORD *)*v3;
*v3 = *(_QWORD *)*v3;
*(_QWORD *)(*v5 + 8LL) = v3;
result = 0LL;
}
else
{
*(_QWORD *)(**a1 + 8LL) = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD **a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // rcx
int v4; // edx
_QWORD *v5; // rax

if ( (int)func4(a1) <= a2 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v3 = *a1;
if ( a2 > 1 )
{
v4 = 0;
do
{
v3 = (_QWORD *)*v3;
++v4;
}
while ( v4 != a2 - 1 );
}
v5 = (_QWORD *)*v3;
*v3 = *(_QWORD *)*v3;
*(_QWORD *)(*v5 + 8LL) = v3;
result = 0LL;
}
else
{
*(_QWORD *)(**a1 + 8LL) = 0LL;
result = 0LL;
}
return result;
}

original_code:
int detachnode (linklist **first,int position){
    int i;
    linklist *now,*temp;
    if(position>=count(first))
        return -1;
    else if(position==0){
        now=*first;
        now->next->prev=((void *)0);
        first=&now->next;
    }
    else{
        now=*first;
        for(i=0;i<position-1;i++){
            now=now->next;
        }
        temp=now->next;
        now->next=temp->next;
        temp->next->prev=now;
    }
    return 0;
}

canonical_original_code:
int detachnode(struct linklist_head **first, int position){
    int i;
    struct linklist_head *now; struct linklist_head *temp;
    if(position>=count(first))
        return -1;
    else if(position==0){
        now=*first;
        now->next->prev=((void *)0);
        first=&now->next;
    }
    else{
        now=*first;
        for(i=0;i<position-1;i++){
            now=now->next;
        }
        temp=now->next;
        now->next=temp->next;
        temp->next->prev=now;
    }
    return 0;
}

variable_types: struct linklist_head { struct linklist_head *next; struct linklist_head *prev; } *


main

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

if ( argc <= 1 )
{
fprintf(stderr, "usage: %s dir\n", *argv);
result = 1;
}
else
{
checkdir(argv[1], 0LL);
result = 0;
}
return result;
}

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

if ( argc <= 1 )
{
fprintf(stderr, "usage: %s dir\n", *argv);
result = 1;
}
else
{
func7(argv[1], 0LL);
result = 0;
}
return result;
}

original_code:
int main(int argc, char** argv) {
 if (argc <= 1) {
  fprintf(stderr, "usage: %s dir\n", argv[0]);
  return 1;
 }
 checkdir(argv[1], ((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc <= 1) {
  fprintf(stderr, "usage: %s dir\n", argv[0]);
  return 1;
 }
 checkdir(argv[1], ((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall OpenI2C(unsigned int a1, int a2, int *a3)
{
unsigned int v4; // ebx
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v6, 0x10uLL, "/dev/i2c-%d", a1);
fd = open(v6, a2 | 2);
if ( fd != -1 )
return 0;
v4 = -1;
*a3 = *__errno_location();
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2, int *a3)
{
unsigned int v4; // ebx
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v6, 0x10uLL, "/dev/i2c-%d", a1);
fd = open(v6, a2 | 2);
if ( fd != -1 )
return 0;
v4 = -1;
*a3 = *__errno_location();
return v4;
}

original_code:
int OpenI2C(int bus, int extra_open_flags, int *err)
{
 char fName[16];
 snprintf(fName,16,"/dev/i2c-%d",bus);
 if (-1 == (fd = open(fName,02|extra_open_flags)))
 {
  *err = (*__errno_location ());
  return -1;
 }
 return 0;
}

variable_types: bus int

variable_types:
err
int *

variable_types:
fName
char [16]


decompiled_code:
__int64 __fastcall CloseI2C(int *a1)
{
unsigned int v1; // ebx

if ( close(fd) != -1 )
return 0;
v1 = -1;
*a1 = *__errno_location();
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
unsigned int v1; // ebx

if ( close(fd) != -1 )
return 0;
v1 = -1;
*a1 = *__errno_location();
return v1;
}

original_code:
int CloseI2C(int *err)
{
 if (-1 == close(fd))
 {
  *err = (*__errno_location ());
  return -1;
 }
 return 0;
}


WriteBytes

decompiled_code:
__int64 __fastcall WriteBytes(__int16 a1, unsigned __int8 *a2, int *a3)
{
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 *v6; // [rsp+8h] [rbp-20h]
__int16 *v7; // [rsp+10h] [rbp-18h] BYREF
int v8; // [rsp+18h] [rbp-10h]

v5[0] = a1;
v5[1] = 0;
v5[2] = *a2;
v6 = a2 + 1;
v7 = v5;
v8 = 1;
if ( ioctl(fd, 0x707uLL, &v7) >= 0 )
return 0LL;
*a3 = *__errno_location();
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int16 a1, unsigned __int8 *a2, int *a3)
{
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 *v6; // [rsp+8h] [rbp-20h]
__int16 *v7; // [rsp+10h] [rbp-18h] BYREF
int v8; // [rsp+18h] [rbp-10h]

v5[0] = a1;
v5[1] = 0;
v5[2] = *a2;
v6 = a2 + 1;
v7 = v5;
v8 = 1;
if ( ioctl(fd, 0x707uLL, &v7) >= 0 )
return 0LL;
*a3 = *__errno_location();
return 0xFFFFFFFFLL;
}

original_code:
int WriteBytes(int address, unsigned char bytes[], int *err)
{
    struct i2c_rdwr_ioctl_data ioctl_arg;
    struct i2c_msg messages[1];
    messages[0].addr = address;
    messages[0].flags = 0;
 messages[0].len = sizeof(unsigned char) * bytes[0];
    messages[0].buf = bytes + 1;
    ioctl_arg.msgs = messages;
    ioctl_arg.nmsgs = 1;
 if(ioctl(fd, 0x0707, &ioctl_arg) < 0)
 {
  *err = (*__errno_location ());
  return -1;
 }
 return 0;
}

variable_types: address int

variable_types:
bytes
unsigned char []

variable_types: struct i2c_rdwr_ioctl_data { struct i2c_msg { unsigned short addr; unsigned short flags; unsigned short len; unsigned char *buf; } *msgs; unsigned int nmsgs; }

variable_types: struct i2c_msg { unsigned short addr; unsigned short flags; unsigned short len; unsigned char *buf; } [1]

user_defined_types: struct i2c_rdwr_ioctl_data { struct i2c_msg *msgs; unsigned int nmsgs; }


ReadBytes

decompiled_code:
__int64 __fastcall ReadBytes(__int16 a1, unsigned __int8 *a2, int *a3)
{
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 *v6; // [rsp+8h] [rbp-20h]
__int16 *v7; // [rsp+10h] [rbp-18h] BYREF
int v8; // [rsp+18h] [rbp-10h]

v5[0] = a1;
v5[1] = 1;
v5[2] = *a2;
v6 = a2;
v7 = v5;
v8 = 1;
if ( ioctl(fd, 0x707uLL, &v7) >= 0 )
return 0LL;
*a3 = *__errno_location();
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1, unsigned __int8 *a2, int *a3)
{
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 *v6; // [rsp+8h] [rbp-20h]
__int16 *v7; // [rsp+10h] [rbp-18h] BYREF
int v8; // [rsp+18h] [rbp-10h]

v5[0] = a1;
v5[1] = 1;
v5[2] = *a2;
v6 = a2;
v7 = v5;
v8 = 1;
if ( ioctl(fd, 0x707uLL, &v7) >= 0 )
return 0LL;
*a3 = *__errno_location();
return 0xFFFFFFFFLL;
}

original_code:
int ReadBytes(int address, unsigned char bytes[256], int *err)
{
    struct i2c_rdwr_ioctl_data ioctl_arg;
    struct i2c_msg messages[1];
    messages[0].addr = address;
    messages[0].flags = 0x0001;
    messages[0].len = sizeof(unsigned char) * bytes[0];
    messages[0].buf = bytes;
    ioctl_arg.msgs = messages;
    ioctl_arg.nmsgs = 1;
    if(ioctl(fd, 0x0707, &ioctl_arg) < 0)
 {
  *err = (*__errno_location ());
  return -1;
    }
 return 0;
}

variable_types:
bytes
unsigned char [256]

user_defined_types: struct i2c_msg { unsigned short addr; unsigned short flags; unsigned short len; unsigned char *buf; }


repo: AVGP/CubeSatRemote

decompiled_code:
__int64 __fastcall qb_validateFrame(char **a1, _WORD **a2, unsigned __int16 a3)
{
char v3; // r8
__int64 result; // rax
_WORD **v5; // rax
__int64 v6; // rsi
char *v7; // rax

v3 = **a1;
result = 1LL;
if ( (v3 & 3) == 0 )
{
if ( a3 )
{
v5 = a2;
v6 = (__int64)&a2[a3];
while ( **v5 != *(_WORD *)*a1 >> 6 )
{
if ( ++v5 == (_WORD **)v6 )
return 2LL;
}
if ( (v3 & 8) != 0 )
{
v7 = a1[1];
LOBYTE(v7) = *v7 != 0;
result = (unsigned int)(16 * (_DWORD)v7);
}
else
{
result = 0LL;
}
}
else
{
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, _WORD **a2, unsigned __int16 a3)
{
char v3; // r8
__int64 result; // rax
_WORD **v5; // rax
__int64 v6; // rsi
char *v7; // rax

v3 = **a1;
result = 1LL;
if ( (v3 & 3) == 0 )
{
if ( a3 )
{
v5 = a2;
v6 = (__int64)&a2[a3];
while ( **v5 != *(_WORD *)*a1 >> 6 )
{
if ( ++v5 == (_WORD **)v6 )
return 2LL;
}
if ( (v3 & 8) != 0 )
{
v7 = a1[1];
LOBYTE(v7) = *v7 != 0;
result = (unsigned int)(16 * (_DWORD)v7);
}
else
{
result = 0LL;
}
}
else
{
result = 2LL;
}
}
return result;
}

original_code:
char qb_validateFrame(qb_tc_frame *frame, unsigned short **spacecraft_ids, unsigned short num_spacecraft_ids) {
        if(frame->header->version != 0) return 1;
        int i=0;
        unsigned char valid_scid = 0;
        for(i=0;i<num_spacecraft_ids;i++) {
            if(*spacecraft_ids[i] == frame->header->spacecraft_id) {
                valid_scid = 1;
                break;
            }
        }
        if(valid_scid != 1) return 2;
        if(frame->header->ctrl_command_flag == 1) {
            unsigned char len = 1;;
            unsigned char mask = 0;
            char *tmp = malloc(len);
            memcpy(tmp, frame->data, len);
            mask = 0;
            if(((int)*tmp ^ mask) != 0)
                return 16;
            memcpy(tmp, frame->data, len);
            mask = 0x4100;;
            if(((int)*tmp ^ mask) != 0)
                return 16;
            free(tmp);
        }
        return 0;
    }

canonical_original_code:
char qb_validateFrame(struct qb_tc_frame *frame, unsigned short **spacecraft_ids, unsigned short num_spacecraft_ids) {
        if(frame->header->version != 0) return 1;
        int i = 0;
        unsigned char valid_scid = 0;
        for(i=0;i<num_spacecraft_ids;i++) {
            if(*spacecraft_ids[i] == frame->header->spacecraft_id) {
                valid_scid = 1;
                break;
            }
        }
        if(valid_scid != 1) return 2;
        if(frame->header->ctrl_command_flag == 1) {
            unsigned char len = 1;;
            unsigned char mask = 0;
            char *tmp = malloc(len);
            memcpy(tmp, frame->data, len);
            mask = 0;
            if(((int)*tmp ^ mask) != 0)
                return 16;
            memcpy(tmp, frame->data, len);
            mask = 0x4100;;
            if(((int)*tmp ^ mask) != 0)
                return 16;
            free(tmp);
        }
        return 0;
    }

variable_types: struct qb_tc_frame { struct qb_tc_frame_header { unsigned char version; unsigned char bypass_flag; unsigned char ctrl_command_flag; unsigned char spare; unsigned short spacecraft_id; unsigned char vc_id; unsigned short length; unsigned char seq; } *header; struct qb_tc_segment { struct qb_tc_segment_header { unsigned char seq_flags; unsigned char map_id; } *head; void *data; } *data; unsigned short checksum; } *

variable_types: i int

variable_types:
len
unsigned char

variable_types:
mask
unsigned char

variable_types:
tmp
char *

return_type: char

user_defined_types: struct qb_tc_frame { struct qb_tc_frame_header *header; struct qb_tc_segment *data; unsigned short checksum; }

user_defined_types: struct qb_tc_segment { struct qb_tc_segment_header *head; void *data; }


repo: AaronWilhelm/YoDawgIHearYouLikeToSing

decompiled_code:
float __fastcall max_peak(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // er12
float v5; // [rsp+8h] [rbp-30h]
float v6; // [rsp+Ch] [rbp-2Ch]

fflush(_bss_start);
if ( a2 <= 1 )
{
v3 = 1;
}
else
{
v2 = 1LL;
v3 = 1;
v5 = 0.0;
do
{
v6 = (float)(*(float *)(a1 + 8 * v2) * *(float *)(a1 + 8 * v2))
+ (float)(*(float *)(a1 + 8 * v2 + 4) * *(float *)(a1 + 8 * v2 + 4));
fflush(_bss_start);
if ( v6 > v5 )
v3 = v2;
v5 = fmaxf(v6, v5);
++v2;
}
while ( a2 / 2 >= (int)v2 );
}
fflush(_bss_start);
printf(
"the index is %d the frequency is %f ",
(unsigned int)v3,
(float)((float)(44100.0 / (float)a2) * (float)v3));
return (float)((float)((float)(a2 - 2) / (float)((float)a2 * (float)a2)) * 44100.0) * (float)v3;
}

canonical_decompiled_code:
float __fastcall func13(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // er12
float v5; // [rsp+8h] [rbp-30h]
float v6; // [rsp+Ch] [rbp-2Ch]

fflush(_bss_start);
if ( a2 <= 1 )
{
v3 = 1;
}
else
{
v2 = 1LL;
v3 = 1;
v5 = 0.0;
do
{
v6 = (float)(*(float *)(a1 + 8 * v2) * *(float *)(a1 + 8 * v2))
+ (float)(*(float *)(a1 + 8 * v2 + 4) * *(float *)(a1 + 8 * v2 + 4));
fflush(_bss_start);
if ( v6 > v5 )
v3 = v2;
v5 = fmaxf(v6, v5);
++v2;
}
while ( a2 / 2 >= (int)v2 );
}
fflush(_bss_start);
printf(
"the index is %d the frequency is %f ",
(unsigned int)v3,
(float)((float)(44100.0 / (float)a2) * (float)v3));
return (float)((float)((float)(a2 - 2) / (float)((float)a2 * (float)a2)) * 44100.0) * (float)v3;
}

original_code:
float max_peak(struct complex_t* fft_data, int length)
{
 float peak = 0;
 int index = 1;
 int i;
 float sample;
    fflush(stdout);
 for(i = 1; i < length/2 +1; i++)
 {
        sample = (fft_data[i].real * fft_data[i].real) + (fft_data[i].imag * fft_data[i].imag);
        fflush(stdout);
  if(sample > peak)
  {
   index = i;
   peak = sample;
  }
 }
    fflush(stdout);
    printf("the index is %d    the frequency is %f    ",index,(float)index*(44100/((float)length)));
    return (float)index * (44100 * (((float)(length - 2))/((float)length*(float)length)));
}

canonical_original_code:
float max_peak(struct complex_t *fft_data, int length)
{
 float peak = 0;
 int index = 1;
 int i;
 float sample;
    fflush(stdout);
 for(i = 1; i < length/2 +1; i++)
 {
        sample = (fft_data[i].real * fft_data[i].real) + (fft_data[i].imag * fft_data[i].imag);
        fflush(stdout);
  if(sample > peak)
  {
   index = i;
   peak = sample;
  }
 }
    fflush(stdout);
    printf("the index is %d    the frequency is %f    ",index,(float)index*(44100/((float)length)));
    return (float)index * (44100 * (((float)(length - 2))/((float)length*(float)length)));
}

variable_types: struct complex_t { float real; float imag; } *

variable_types: length int

variable_types: peak float

variable_types: index int

variable_types: sample float


decompiled_code:
float __fastcall find_ratio(float a1)
{
int v1; // edx
int v2; // eax
int v3; // ecx
float v4; // xmm0_4
float v5; // xmm6_4
__m128 v6; // xmm2
__m128 v7; // xmm0
__m128 v8; // xmm0
float v11; // [rsp+8h] [rbp-10h]
float v12; // [rsp+Ch] [rbp-Ch]

fflush(_bss_start);
v1 = 16;
v2 = 32;
do
{
v4 = notes[v2];
if ( v4 >= a1 && a1 >= notes[v2 - 1] )
break;
v3 = v2 - v1;
v2 += v1;
if ( a1 <= v4 )
v2 = v3;
v1 /= 2;
}
while ( v2 != 1 );
v5 = notes[v2];
v6 = (__m128)LODWORD(notes[v2 - 1]);
v7.m128_f32[0] = v5 - (float)((float)(v5 - v6.m128_f32[0]) * 0.5);
v8 = _mm_cmplt_ss(v7, (__m128)LODWORD(a1));
LODWORD(v12) = _mm_andnot_ps(v8, v6).m128_u32[0] | LODWORD(v5) & v8.m128_i32[0];
printf("new frequency %f original frequency %f ", v12, a1);
v11 = v12 / a1;
printf("ratio %f \n", v11);
fflush(_bss_start);
return v11;
}

canonical_decompiled_code:
float __fastcall func14(float a1)
{
int v1; // edx
int v2; // eax
int v3; // ecx
float v4; // xmm0_4
float v5; // xmm6_4
__m128 v6; // xmm2
__m128 v7; // xmm0
__m128 v8; // xmm0
float v11; // [rsp+8h] [rbp-10h]
float v12; // [rsp+Ch] [rbp-Ch]

fflush(_bss_start);
v1 = 16;
v2 = 32;
do
{
v4 = notes[v2];
if ( v4 >= a1 && a1 >= notes[v2 - 1] )
break;
v3 = v2 - v1;
v2 += v1;
if ( a1 <= v4 )
v2 = v3;
v1 /= 2;
}
while ( v2 != 1 );
v5 = notes[v2];
v6 = (__m128)LODWORD(notes[v2 - 1]);
v7.m128_f32[0] = v5 - (float)((float)(v5 - v6.m128_f32[0]) * 0.5);
v8 = _mm_cmplt_ss(v7, (__m128)LODWORD(a1));
LODWORD(v12) = _mm_andnot_ps(v8, v6).m128_u32[0] | LODWORD(v5) & v8.m128_i32[0];
printf("new frequency %f original frequency %f ", v12, a1);
v11 = v12 / a1;
printf("ratio %f \n", v11);
fflush(_bss_start);
return v11;
}

original_code:
float find_ratio(float current_freq)
{
    int index = 33 - 1;
    int index_counter = (33 - 1) / 2;
    freq_ratio ratio;
    int done = 0;
    fflush(stdout);
    ratio.denominator = current_freq;
    while (!done)
    {
        if( current_freq <= notes[index] && current_freq >= notes[index - 1])
        {
            done = 1;
            break;
        }
        if ( current_freq > notes[index])
        {
            index += index_counter;
        } else
        {
            index -= index_counter;
        }
        index_counter /= 2;
        if( index == 1)
        {
            done = 1;
            break;
        }
    }
    if( current_freq > notes[index] - ((notes[index] - notes[index -1])/2))
        ratio.numerator = notes[index];
    else
        ratio.numerator = notes[index - 1];
    printf("new frequency %f   original frequency %f  ", ratio.numerator, ratio.denominator);
    printf("ratio %f \n",(float)ratio.numerator / (float)ratio.denominator);
    fflush(stdout);
    return (float)ratio.numerator / (float)ratio.denominator;
}

canonical_original_code:
float find_ratio(float current_freq)
{
    int index = 33 - 1;
    int index_counter = (33 - 1) / 2;
    struct freq_ratio ratio;
    int done = 0;
    fflush(stdout);
    ratio.denominator = current_freq;
    while (!done)
    {
        if( current_freq <= notes[index] && current_freq >= notes[index - 1])
        {
            done = 1;
            break;
        }
        if ( current_freq > notes[index])
        {
            index += index_counter;
        } else
        {
            index -= index_counter;
        }
        index_counter /= 2;
        if( index == 1)
        {
            done = 1;
            break;
        }
    }
    if( current_freq > notes[index] - ((notes[index] - notes[index -1])/2))
        ratio.numerator = notes[index];
    else
        ratio.numerator = notes[index - 1];
    printf("new frequency %f   original frequency %f  ", ratio.numerator, ratio.denominator);
    printf("ratio %f \n",(float)ratio.numerator / (float)ratio.denominator);
    fflush(stdout);
    return (float)ratio.numerator / (float)ratio.denominator;
}

variable_types: struct freq_ratio { float numerator; float denominator; }

variable_types: done int


upsample

decompiled_code:
__int64 __fastcall upsample(float *a1, _DWORD *a2, int a3)
{
float v3; // xmm1_4
__int64 i; // rax

if ( (unsigned __int64)(2LL * a3 - (a3 - 1)) > 2 )
return 0xFFFFFFFFLL;
v3 = (float)(*a1 - a1[1]) / (float)a3;
*a2 = *(_DWORD *)a1;
if ( a3 > 1 )
{
for ( i = 1LL; i != a3; ++i )
*(float *)&a2[i] = (float)((float)(int)i * v3) + *a1;
}
a2[a3] = *((_DWORD *)a1 + 1);
return (unsigned int)(a3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(float *a1, _DWORD *a2, int a3)
{
float v3; // xmm1_4
__int64 i; // rax

if ( (unsigned __int64)(2LL * a3 - (a3 - 1)) > 2 )
return 0xFFFFFFFFLL;
v3 = (float)(*a1 - a1[1]) / (float)a3;
*a2 = *(_DWORD *)a1;
if ( a3 > 1 )
{
for ( i = 1LL; i != a3; ++i )
*(float *)&a2[i] = (float)((float)(int)i * v3) + *a1;
}
a2[a3] = *((_DWORD *)a1 + 1);
return (unsigned int)(a3 + 1);
}

original_code:
int upsample(float* o_data, float* n_data, int factor)
{
    float slope;
    int i,j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < factor * (sizeof(o_data)/sizeof(o_data[0]))-(factor-1))
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - 1;i++)
    {
        slope = (o_data[i] - o_data[i+1]) / factor;
        n_data[i*factor] = o_data[i];
        for(j = 1; j < factor; j++)
        {
            n_data[(i*factor)+j] = o_data[i] + (j*slope);
        }
    }
    n_data[i*factor] = o_data[i];
    return ((sizeof(o_data)/sizeof(o_data[0]))*factor)-(factor-1);
}

canonical_original_code:
int upsample(float *o_data, float *n_data, int factor)
{
    float slope;
    int i; int j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < factor * (sizeof(o_data)/sizeof(o_data[0]))-(factor-1))
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - 1;i++)
    {
        slope = (o_data[i] - o_data[i+1]) / factor;
        n_data[i*factor] = o_data[i];
        for(j = 1; j < factor; j++)
        {
            n_data[(i*factor)+j] = o_data[i] + (j*slope);
        }
    }
    n_data[i*factor] = o_data[i];
    return ((sizeof(o_data)/sizeof(o_data[0]))*factor)-(factor-1);
}

variable_types: factor int

variable_types: slope float

variable_types: j int


downsample

original_code:
int downsample(float* o_data, float* n_data, int factor)
{
    float average;
    int i,j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < (sizeof(o_data)/sizeof(o_data[0])) / factor)
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - factor; i+=factor)
    {
        average = 0;
        for(j = 0; j < factor; j++)
        {
            average += o_data[i+j];
        }
        average /= factor;
        n_data[i / factor] = average;
    }
    n_data[i*factor] = o_data[i];
    return ((sizeof(o_data)/sizeof(o_data[0])) / factor);
}

canonical_original_code:
int downsample(float *o_data, float *n_data, int factor)
{
    float average;
    int i; int j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < (sizeof(o_data)/sizeof(o_data[0])) / factor)
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - factor; i+=factor)
    {
        average = 0;
        for(j = 0; j < factor; j++)
        {
            average += o_data[i+j];
        }
        average /= factor;
        n_data[i / factor] = average;
    }
    n_data[i*factor] = o_data[i];
    return ((sizeof(o_data)/sizeof(o_data[0])) / factor);
}

variable_types: average float


decompiled_code:
__int64 __fastcall upsample_c(_DWORD *a1, _DWORD *a2)
{
*a2 = *a1;
a2[1] = a1[1];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(_DWORD *a1, _DWORD *a2)
{
*a2 = *a1;
a2[1] = a1[1];
return 1LL;
}

original_code:
int upsample_c(struct complex_t* o_data, struct complex_t* n_data, int factor)
{
    float i_slope, q_slope;
    int i,j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < factor * (sizeof(o_data)/sizeof(o_data[0]))-(factor-1))
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - 1;i++)
    {
        i_slope = (o_data[i].real - o_data[i+1].real) / factor;
        q_slope = (o_data[i].imag - o_data[i+1].imag) / factor;
        n_data[i*factor].imag = o_data[i].imag;
        n_data[i*factor].real = o_data[i].real;
        for(j = 1; j < factor; j++)
        {
            n_data[(i*factor)+j].real = o_data[i].real + (j*i_slope);
            n_data[(i*factor)+j].imag = o_data[i].imag + (j*q_slope);
        }
    }
    n_data[i*factor].real = o_data[i].real;
    n_data[i*factor].imag = o_data[i].imag;
    return ((sizeof(o_data)/sizeof(o_data[0]))*factor)-(factor-1);
}

canonical_original_code:
int upsample_c(struct complex_t *o_data, struct complex_t *n_data, int factor)
{
    float i_slope; float q_slope;
    int i; int j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < factor * (sizeof(o_data)/sizeof(o_data[0]))-(factor-1))
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - 1;i++)
    {
        i_slope = (o_data[i].real - o_data[i+1].real) / factor;
        q_slope = (o_data[i].imag - o_data[i+1].imag) / factor;
        n_data[i*factor].imag = o_data[i].imag;
        n_data[i*factor].real = o_data[i].real;
        for(j = 1; j < factor; j++)
        {
            n_data[(i*factor)+j].real = o_data[i].real + (j*i_slope);
            n_data[(i*factor)+j].imag = o_data[i].imag + (j*q_slope);
        }
    }
    n_data[i*factor].real = o_data[i].real;
    n_data[i*factor].imag = o_data[i].imag;
    return ((sizeof(o_data)/sizeof(o_data[0]))*factor)-(factor-1);
}

user_defined_types: struct complex_t { float real; float imag; }


original_code:
int downsample_c(struct complex_t* o_data, struct complex_t* n_data, int factor)
{
    float i_average, q_average;
    int i,j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < (sizeof(o_data)/sizeof(o_data[0])) / factor)
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - factor; i+=factor)
    {
        i_average = 0;
        q_average = 0;
        for(j = 0; j < factor; j++)
        {
            i_average += o_data[i+j].real;
            q_average += o_data[i+j].imag;
        }
        i_average /= factor;
        q_average /= factor;
        n_data[i / factor].real = i_average;
        n_data[i / factor].imag = q_average;
    }
    n_data[i*factor].real = o_data[i].real;
    n_data[i*factor].imag = o_data[i].imag;
    return ((sizeof(o_data)/sizeof(o_data[0])) / factor);
}

canonical_original_code:
int downsample_c(struct complex_t *o_data, struct complex_t *n_data, int factor)
{
    float i_average; float q_average;
    int i; int j;
    if ((sizeof(n_data)/sizeof(n_data[0])) < (sizeof(o_data)/sizeof(o_data[0])) / factor)
    {
        return -1;
    }
    for(i = 0; i < (sizeof(o_data)/sizeof(o_data[0])) - factor; i+=factor)
    {
        i_average = 0;
        q_average = 0;
        for(j = 0; j < factor; j++)
        {
            i_average += o_data[i+j].real;
            q_average += o_data[i+j].imag;
        }
        i_average /= factor;
        q_average /= factor;
        n_data[i / factor].real = i_average;
        n_data[i / factor].imag = q_average;
    }
    n_data[i*factor].real = o_data[i].real;
    n_data[i*factor].imag = o_data[i].imag;
    return ((sizeof(o_data)/sizeof(o_data[0])) / factor);
}