decompiled_code:
__int64 __fastcall gpio_get_value(unsigned int a1, _DWORD *a2)
{
int v2; // eax
unsigned int v3; // ebx
char buf; // [rsp+Fh] [rbp-59h] BYREF
char s[88]; // [rsp+10h] [rbp-58h] BYREF

snprintf(s, 0x40uLL, "/sys/class/gpio/gpio%d/value", a1);
v2 = open(s, 0);
v3 = v2;
if ( v2 < 0 )
{
perror("gpio/get-value");
}
else
{
read(v2, &buf, 1uLL);
*a2 = buf != 48;
close(v3);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, _DWORD *a2)
{
int v2; // eax
unsigned int v3; // ebx
char buf; // [rsp+Fh] [rbp-59h] BYREF
char s[88]; // [rsp+10h] [rbp-58h] BYREF

snprintf(s, 0x40uLL, "/sys/class/gpio/gpio%d/value", a1);
v2 = open(s, 0);
v3 = v2;
if ( v2 < 0 )
{
perror("gpio/get-value");
}
else
{
read(v2, &buf, 1uLL);
*a2 = buf != 48;
close(v3);
v3 = 0;
}
return v3;
}

original_code:
int gpio_get_value(unsigned int gpio, unsigned int *value)
{
 int fd, len;
 char buf[64];
 char ch;
 len = snprintf(buf, sizeof(buf), "/sys/class/gpio" "/gpio%d/value", gpio);
 fd = open(buf, 00);
 if (fd < 0) {
  perror("gpio/get-value");
  return fd;
 }
 read(fd, &ch, 1);
 if (ch != '0') {
  *value = 1;
 } else {
  *value = 0;
 }
 close(fd);
 return 0;
}

canonical_original_code:
int gpio_get_value(unsigned int gpio, unsigned int *value)
{
 int fd; int len;
 char buf[64];
 char ch;
 len = snprintf(buf, sizeof(buf), "/sys/class/gpio" "/gpio%d/value", gpio);
 fd = open(buf, 00);
 if (fd < 0) {
  perror("gpio/get-value");
  return fd;
 }
 read(fd, &ch, 1);
 if (ch != '0') {
  *value = 1;
 } else {
  *value = 0;
 }
 close(fd);
 return 0;
}

variable_types:
value
unsigned int *

variable_types: ch char


repo: geolocationrhit/Senior-Design

decompiled_code:
__int64 __fastcall gpio_fd_open(unsigned int a1)
{
int v1; // ebx
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

snprintf(v3, 0x40uLL, "/sys/class/gpio/gpio%d/value", a1);
v1 = open(v3, 2048);
if ( v1 < 0 )
perror("gpio/fd_open");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v1; // ebx
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

snprintf(v3, 0x40uLL, "/sys/class/gpio/gpio%d/value", a1);
v1 = open(v3, 2048);
if ( v1 < 0 )
perror("gpio/fd_open");
return (unsigned int)v1;
}

original_code:
int gpio_fd_open(unsigned int gpio)
{
 int fd, len;
 char buf[64];
 len = snprintf(buf, sizeof(buf), "/sys/class/gpio" "/gpio%d/value", gpio);
 fd = open(buf, 00 | 04000 );
 if (fd < 0) {
  perror("gpio/fd_open");
 }
 return fd;
}

canonical_original_code:
int gpio_fd_open(unsigned int gpio)
{
 int fd; int len;
 char buf[64];
 len = snprintf(buf, sizeof(buf), "/sys/class/gpio" "/gpio%d/value", gpio);
 fd = open(buf, 00 | 04000 );
 if (fd < 0) {
  perror("gpio/fd_open");
 }
 return fd;
}

variable_types:
gpio
unsigned int

variable_types: fd int

variable_types: len int

variable_types:
buf
char [64]

return_type: int


decompiled_code:
int __fastcall gpio_fd_close(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
return close(a1);
}

original_code:
int gpio_fd_close(int fd)
{
 return close(fd);
}


decompiled_code:
void signal_handler()
{
puts("Program Exited by User");
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
gpio_set_value(73LL, 0LL);
keepGoing = 0;
}

canonical_decompiled_code:
void func0()
{
puts("Program Exited by User");
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
gpio_set_value(73LL, 0LL);
keepGoing = 0;
}

original_code:
void signal_handler(int sig)
{
        printf( "Program Exited by User\n" );
 gpio_set_value(75, 0);
 gpio_set_value(71, 0);
 gpio_set_value(77, 0);
 gpio_set_value(73, 0);
 keepGoing = 0;
}

variable_types: sig int

return_type: void


gpioInit

decompiled_code:
__int64 gpioInit()
{
gpio_export(75LL);
gpio_set_dir(75LL, 1LL);
gpio_export(71LL);
gpio_set_dir(71LL, 1LL);
gpio_export(77LL);
gpio_set_dir(77LL, 1LL);
gpio_export(73LL);
return gpio_set_dir(73LL, 1LL);
}

canonical_decompiled_code:
__int64 func1()
{
gpio_export(75LL);
gpio_set_dir(75LL, 1LL);
gpio_export(71LL);
gpio_set_dir(71LL, 1LL);
gpio_export(77LL);
gpio_set_dir(77LL, 1LL);
gpio_export(73LL);
return gpio_set_dir(73LL, 1LL);
}

original_code:
int gpioInit(){
 gpio_export(75);
 gpio_set_dir(75, 1);
 gpio_export(71);
 gpio_set_dir(71, 1);
 gpio_export(77);
 gpio_set_dir(77, 1);
 gpio_export(73);
 gpio_set_dir(73, 1);
}


testTurn

decompiled_code:
__int64 testTurn()
{
gpio_set_value(75LL, 1LL);
gpio_set_value(77LL, 1LL);
sleep(1u);
gpio_set_value(75LL, 0LL);
gpio_set_value(77LL, 0LL);
sleep(1u);
gpio_set_value(71LL, 1LL);
gpio_set_value(77LL, 1LL);
sleep(1u);
gpio_set_value(71LL, 0LL);
return gpio_set_value(77LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
gpio_set_value(75LL, 1LL);
gpio_set_value(77LL, 1LL);
sleep(1u);
gpio_set_value(75LL, 0LL);
gpio_set_value(77LL, 0LL);
sleep(1u);
gpio_set_value(71LL, 1LL);
gpio_set_value(77LL, 1LL);
sleep(1u);
gpio_set_value(71LL, 0LL);
return gpio_set_value(77LL, 0LL);
}

original_code:
int testTurn(){
 gpio_set_value(75, 1);
 gpio_set_value(77,1);
 sleep(1);
 gpio_set_value(75, 0);
 gpio_set_value(77,0);
 sleep(1);
 gpio_set_value(71, 1);
 gpio_set_value(77,1);
 sleep(1);
 gpio_set_value(71, 0);
 gpio_set_value(77,0);
}


decompiled_code:
float __fastcall wrap180(float result)
{
if ( result > 180.0 )
return result - 360.0;
if ( result < -180.0 )
result = result + 360.0;
return result;
}

canonical_decompiled_code:
float __fastcall func3(float result)
{
if ( result > 180.0 )
return result - 360.0;
if ( result < -180.0 )
result = result + 360.0;
return result;
}

original_code:
float wrap180(float angle){
 if (angle > 180.0) angle -= 360.0;
 else if (angle < -180.0) angle += 360.0;
 return angle;
}

variable_types: angle float

return_type: float


getCompassHeading

decompiled_code:
__int64 getCompassHeading()
{
return getHeading((unsigned int)fd);
}

canonical_decompiled_code:
__int64 func4()
{
return getHeading((unsigned int)fd);
}

original_code:
float getCompassHeading(void){
 return getHeading(fd);
}

canonical_original_code:
float getCompassHeading(){
 return getHeading(fd);
}


turn

decompiled_code:
__int64 __fastcall turn(float a1)
{
double v2; // xmm0_8
float v3; // [rsp+4h] [rbp-14h]
float v4; // [rsp+8h] [rbp-10h]
float v5; // [rsp+Ch] [rbp-Ch]

v5 = a1;
getHeading((unsigned int)fd);
v4 = a1;
v3 = wrap180(a1 - a1);
printf("deltaHeading: %f, currentHeading: %f, tolerance: %d\n", v3, v4, 5LL);
for ( ; keepGoing; v3 = wrap180(v5 - *(float *)&v2) )
{
if ( (int)abs32((int)v3) <= 5 )
break;
v2 = v3;
if ( v3 <= 0.0 )
{
printf("**turning left**deltaHeading negative: %f, currentHeading: %f\n", v3, v4);
gpio_set_value(71LL, 1LL);
gpio_set_value(75LL, 0LL);
gpio_set_value(77LL, 1LL);
gpio_set_value(73LL, 0LL);
}
else
{
printf("**turning right**deltaHeading positive: %f, currentHeading: %f\n", v3, v4);
gpio_set_value(75LL, 1LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(73LL, 1LL);
gpio_set_value(77LL, 0LL);
}
getHeading((unsigned int)fd);
v4 = *(float *)&v2;
}
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
return gpio_set_value(73LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(float a1)
{
double v2; // xmm0_8
float v3; // [rsp+4h] [rbp-14h]
float v4; // [rsp+8h] [rbp-10h]
float v5; // [rsp+Ch] [rbp-Ch]

v5 = a1;
getHeading((unsigned int)fd);
v4 = a1;
v3 = func3(a1 - a1);
printf("deltaHeading: %f, currentHeading: %f, tolerance: %d\n", v3, v4, 5LL);
for ( ; keepGoing; v3 = func3(v5 - *(float *)&v2) )
{
if ( (int)abs32((int)v3) <= 5 )
break;
v2 = v3;
if ( v3 <= 0.0 )
{
printf("**turning left**deltaHeading negative: %f, currentHeading: %f\n", v3, v4);
gpio_set_value(71LL, 1LL);
gpio_set_value(75LL, 0LL);
gpio_set_value(77LL, 1LL);
gpio_set_value(73LL, 0LL);
}
else
{
printf("**turning right**deltaHeading positive: %f, currentHeading: %f\n", v3, v4);
gpio_set_value(75LL, 1LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(73LL, 1LL);
gpio_set_value(77LL, 0LL);
}
getHeading((unsigned int)fd);
v4 = *(float *)&v2;
}
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
return gpio_set_value(73LL, 0LL);
}

original_code:
int turn(float heading){
 float currentHeading = getHeading(fd);
 float deltaHeading = wrap180(heading - currentHeading);
 const int tolerance = 5;
 printf("deltaHeading: %f, currentHeading: %f, tolerance: %d\n", deltaHeading, currentHeading, tolerance);
 while(keepGoing && abs(deltaHeading) > tolerance){
  if(deltaHeading > 0){
   printf("**turning right**deltaHeading positive: %f, currentHeading: %f\n", deltaHeading, currentHeading);
   gpio_set_value(75, 1);
   gpio_set_value(71, 0);
   gpio_set_value(73, 1);
   gpio_set_value(77, 0);
  } else {
   printf("**turning left**deltaHeading negative: %f, currentHeading: %f\n", deltaHeading, currentHeading);
   gpio_set_value(71, 1);
   gpio_set_value(75, 0);
   gpio_set_value(77, 1);
   gpio_set_value(73, 0);
  }
  currentHeading = getHeading(fd);
  deltaHeading = wrap180(heading - currentHeading);
 }
 gpio_set_value(75, 0);
 gpio_set_value(71, 0);
 gpio_set_value(77, 0);
 gpio_set_value(73, 0);
}

canonical_original_code:
int turn(float heading){
 float currentHeading = getHeading(fd);
 float deltaHeading = wrap180(heading - currentHeading);
 int tolerance = 5;
 printf("deltaHeading: %f, currentHeading: %f, tolerance: %d\n", deltaHeading, currentHeading, tolerance);
 while(keepGoing && abs(deltaHeading) > tolerance){
  if(deltaHeading > 0){
   printf("**turning right**deltaHeading positive: %f, currentHeading: %f\n", deltaHeading, currentHeading);
   gpio_set_value(75, 1);
   gpio_set_value(71, 0);
   gpio_set_value(73, 1);
   gpio_set_value(77, 0);
  } else {
   printf("**turning left**deltaHeading negative: %f, currentHeading: %f\n", deltaHeading, currentHeading);
   gpio_set_value(71, 1);
   gpio_set_value(75, 0);
   gpio_set_value(77, 1);
   gpio_set_value(73, 0);
  }
  currentHeading = getHeading(fd);
  deltaHeading = wrap180(heading - currentHeading);
 }
 gpio_set_value(75, 0);
 gpio_set_value(71, 0);
 gpio_set_value(77, 0);
 gpio_set_value(73, 0);
}

variable_types: heading float

variable_types: currentHeading float

variable_types: deltaHeading float

variable_types: tolerance int


bbCheck

decompiled_code:
_BOOL8 __fastcall bbCheck(double a1, double a2, double a3, double a4, double a5)
{
return a5 * 0.00001147942942838844 > (a2 + a4) / a1 + a3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(double a1, double a2, double a3, double a4, double a5)
{
return a5 * 0.00001147942942838844 > (a2 + a4) / a1 + a3;
}

original_code:
short bbCheck(double m, double b, waypoint newWPCoord, double tolerance){
 return newWPCoord.x + (newWPCoord.y + b)/((double) m) < tolerance * 0.000011479429428388439;
}

canonical_original_code:
short bbCheck(double m, double b, struct waypoint newWPCoord, double tolerance){
 return newWPCoord.x + (newWPCoord.y + b)/((double) m) < tolerance * 0.000011479429428388439;
}

variable_types: m double

variable_types: b double

variable_types:
newWPCoord
struct waypoint { double x; double y; }

variable_types: tolerance double

return_type: short


findSlope

decompiled_code:
__m128 __fastcall findSlope(double a1, double a2, double a3, __m128 a4)
{
*(double *)a4.m128_u64 = (*(double *)a4.m128_u64 - a2) / (a3 - a1);
return a4;
}

canonical_decompiled_code:
__m128 __fastcall func7(double a1, double a2, double a3, __m128 a4)
{
*(double *)a4.m128_u64 = (*(double *)a4.m128_u64 - a2) / (a3 - a1);
return a4;
}

original_code:
double findSlope(waypoint currentPos, waypoint newPos){
 return (newPos.y - currentPos.y)/(newPos.x - currentPos.x);
}

canonical_original_code:
double findSlope(struct waypoint currentPos, struct waypoint newPos){
 return (newPos.y - currentPos.y)/(newPos.x - currentPos.x);
}

variable_types:
currentPos
struct waypoint { double x; double y; }

variable_types:
newPos
struct waypoint

return_type: double


findLine

decompiled_code:
double *__fastcall findLine(double *a1, double a2, double a3, double a4, __m128 a5)
{
double v6; // xmm0_8

v6 = *(double *)findSlope(a2, a3, a4, a5).m128_u64;
*a1 = v6;
a1[1] = a3 - v6 * a2;
return a1;
}

canonical_decompiled_code:
double *__fastcall func8(double *a1, double a2, double a3, double a4, __m128 a5)
{
double v6; // xmm0_8

v6 = *(double *)func7(a2, a3, a4, a5).m128_u64;
*a1 = v6;
a1[1] = a3 - v6 * a2;
return a1;
}

original_code:
double * findLine(waypoint currentPos, waypoint newPos, double * mb){
 mb[0] = findSlope(currentPos, newPos);
 mb[1] = currentPos.y - mb[0]*currentPos.x;
 return mb;
}

canonical_original_code:
double *findLine(struct waypoint currentPos, struct waypoint newPos, double *mb){
 mb[0] = findSlope(currentPos, newPos);
 mb[1] = currentPos.y - mb[0]*currentPos.x;
 return mb;
}

variable_types:
mb
double *

return_type: double *


move

decompiled_code:
void move()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
int move(waypoint gpsCoord){
 int originalLineM, originalLineB;
}

canonical_original_code:
int move(struct waypoint gpsCoord){
 int originalLineM; int originalLineB;
}

variable_types:
gpsCoord
struct waypoint { double x; double y; }

variable_types: originalLineM int

variable_types: originalLineB int


moveForward

decompiled_code:
__int64 __fastcall moveForward(__useconds_t useconds)
{
gpio_set_value(75LL, 1LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 1LL);
gpio_set_value(73LL, 0LL);
usleep(useconds);
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
return gpio_set_value(73LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__useconds_t useconds)
{
gpio_set_value(75LL, 1LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 1LL);
gpio_set_value(73LL, 0LL);
usleep(useconds);
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
return gpio_set_value(73LL, 0LL);
}

original_code:
void moveForward(int useconds){
 gpio_set_value(75, 1);
        gpio_set_value(71, 0);
        gpio_set_value(77, 1);
        gpio_set_value(73, 0);
 usleep(useconds);
 gpio_set_value(75, 0);
        gpio_set_value(71, 0);
        gpio_set_value(77, 0);
        gpio_set_value(73, 0);
}

variable_types: useconds int


getGPSlocation

decompiled_code:
__int64 __fastcall getGPSlocation(__int64 a1)
{
getGPS(a1, (unsigned int)gpsRet);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
getGPS(a1, (unsigned int)gpsRet);
return a1;
}

original_code:
dataGPS getGPSlocation(void){
 return getGPS(gpsRet);
}

canonical_original_code:
struct dataGPS getGPSlocation(){
 return getGPS(gpsRet);
}

return_type: struct dataGPS { double x; double y; double time; int valid; }


waypointManager

decompiled_code:
void waypointManager()
{
double *v0; // rbp
int v1; // ebx
double v2; // r12
double v3; // r13
double *v4; // rbx
int v5; // er12
double v6; // xmm0_8
double v7; // xmm3_8
double v8; // xmm2_8
float v9; // [rsp+Ch] [rbp-5Ch]
double v10; // [rsp+10h] [rbp-58h] BYREF
double v11; // [rsp+18h] [rbp-50h]
double v12; // [rsp+20h] [rbp-48h] BYREF
double v13; // [rsp+28h] [rbp-40h]
int v14; // [rsp+38h] [rbp-30h]

puts("Beginning\r");
addWaypointxy(-87.32231400000001, 39.483694);
v0 = (double *)getCurrentWaypoint();
printf("\r\nTrying to initialize GPS");
getGPS(&v12, (unsigned int)gpsRet);
v1 = v14;
if ( v14 )
{
v2 = v12;
v3 = v13;
}
else
{
do
{
sleep(5u);
puts("\r\nWaiting for valid GPS data....\r");
getGPS(&v12, (unsigned int)gpsRet);
++v1;
}
while ( !v14 && v1 <= 9 );
v2 = v12;
v3 = v13;
}
v4 = (double *)malloc(0x10uLL);
*v4 = v2;
v4[1] = v3;
v9 = angleBetweenPoints(*v0, v0[1], v2, v3);
turn(v9);
findLine(&v10, *v4, v4[1], *v0, (__m128)*((unsigned __int64 *)v0 + 1));
printf("\r\nCurrent position: x %lf, y %lf\r\n", v2, v3);
printf("Waypoint to move to: x %lf, y %lf\r\n", *v0, v0[1]);
printf("Turn heading: %f\r\n", v9);
printf("Line: m %lf, b %lf\r\n", v10, v11);
if ( keepGoing )
{
do
{
if ( keepGoing )
{
while ( distanceBetweenPoints(*v4, v4[1], *v0, v0[1]) > 0.00003443828828516532 )
{
v6 = distanceBetweenPoints(*v4, v4[1], *v0, v0[1]);
printf("Going straight\r\ndistance to target: %lf\r\ntolerance: %lf\r\n", v6, *(double *)&LC18);
gpio_set_value(75LL, 1LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 1LL);
gpio_set_value(73LL, 0LL);
getGPS(&v12, (unsigned int)gpsRet);
v7 = v13;
v8 = v12;
*v4 = v12;
v4[1] = v7;
if ( !bbCheck(v10, v11, v8, v7, 3.0) )
{
returnToPreviousWaypoint();
puts("We're outside of the bounds. Returning to the previous waypoint\r");
break;
}
sleep(2u);
if ( !keepGoing )
break;
}
}
puts("We've hit the waypoint! Stopping the motors...\r");
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
gpio_set_value(73LL, 0LL);
v5 = advanceToNextWaypoint();
v0 = (double *)getCurrentWaypoint();
printf("KeepGoing: %d...should be 0 if we've hit the end of the waypoints", (unsigned int)keepGoing);
}
while ( keepGoing && v5 != -1 );
}
free(v4);
free(v0);
}

canonical_decompiled_code:
void func12()
{
double *v0; // rbp
int v1; // ebx
double v2; // r12
double v3; // r13
double *v4; // rbx
int v5; // er12
double v6; // xmm0_8
double v7; // xmm3_8
double v8; // xmm2_8
float v9; // [rsp+Ch] [rbp-5Ch]
double v10; // [rsp+10h] [rbp-58h] BYREF
double v11; // [rsp+18h] [rbp-50h]
double v12; // [rsp+20h] [rbp-48h] BYREF
double v13; // [rsp+28h] [rbp-40h]
int v14; // [rsp+38h] [rbp-30h]

puts("Beginning\r");
addWaypointxy(-87.32231400000001, 39.483694);
v0 = (double *)getCurrentWaypoint();
printf("\r\nTrying to initialize GPS");
getGPS(&v12, (unsigned int)gpsRet);
v1 = v14;
if ( v14 )
{
v2 = v12;
v3 = v13;
}
else
{
do
{
sleep(5u);
puts("\r\nWaiting for valid GPS data....\r");
getGPS(&v12, (unsigned int)gpsRet);
++v1;
}
while ( !v14 && v1 <= 9 );
v2 = v12;
v3 = v13;
}
v4 = (double *)malloc(0x10uLL);
*v4 = v2;
v4[1] = v3;
v9 = angleBetweenPoints(*v0, v0[1], v2, v3);
func5(v9);
func8(&v10, *v4, v4[1], *v0, (__m128)*((unsigned __int64 *)v0 + 1));
printf("\r\nCurrent position: x %lf, y %lf\r\n", v2, v3);
printf("Waypoint to move to: x %lf, y %lf\r\n", *v0, v0[1]);
printf("Turn heading: %f\r\n", v9);
printf("Line: m %lf, b %lf\r\n", v10, v11);
if ( keepGoing )
{
do
{
if ( keepGoing )
{
while ( distanceBetweenPoints(*v4, v4[1], *v0, v0[1]) > 0.00003443828828516532 )
{
v6 = distanceBetweenPoints(*v4, v4[1], *v0, v0[1]);
printf("Going straight\r\ndistance to target: %lf\r\ntolerance: %lf\r\n", v6, *(double *)&LC18);
gpio_set_value(75LL, 1LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 1LL);
gpio_set_value(73LL, 0LL);
getGPS(&v12, (unsigned int)gpsRet);
v7 = v13;
v8 = v12;
*v4 = v12;
v4[1] = v7;
if ( !func6(v10, v11, v8, v7, 3.0) )
{
returnToPreviousWaypoint();
puts("We're outside of the bounds. Returning to the previous waypoint\r");
break;
}
sleep(2u);
if ( !keepGoing )
break;
}
}
puts("We've hit the waypoint! Stopping the motors...\r");
gpio_set_value(75LL, 0LL);
gpio_set_value(71LL, 0LL);
gpio_set_value(77LL, 0LL);
gpio_set_value(73LL, 0LL);
v5 = advanceToNextWaypoint();
v0 = (double *)getCurrentWaypoint();
printf("KeepGoing: %d...should be 0 if we've hit the end of the waypoints", (unsigned int)keepGoing);
}
while ( keepGoing && v5 != -1 );
}
free(v4);
free(v0);
}

original_code:
void waypointManager(void){
 waypoint * newWP = (waypoint *) malloc(sizeof(waypoint));
 dataGPS curPosGPS;
 float turnHeading;
 double tolerance = 3;
 printf("Beginning\r\n");
 addWaypointxy(-87.322314, 39.483694);
 newWP = getCurrentWaypoint();
 printf("\r\nTrying to initialize GPS");
 curPosGPS = getGPS(gpsRet);
 if(!curPosGPS.valid){
  for(int i = 0; i < 10 && !curPosGPS.valid; i++){
   sleep(5);
   printf("\r\nWaiting for valid GPS data....\r\n");
   curPosGPS = getGPS(gpsRet);
  }
 }
 waypoint * curPosWP = (waypoint *) malloc(sizeof(waypoint));
 curPosWP->x = curPosGPS.x;
 curPosWP->y = curPosGPS.y;
 turnHeading = angleBetweenPoints(*newWP, *curPosWP);
 turn(turnHeading);
 double line_mb[2];
 findLine(*curPosWP, * newWP, line_mb);
 printf("\r\nCurrent position: x %lf, y %lf\r\n", curPosWP->x, curPosWP->y);
 printf("Waypoint to move to: x %lf, y %lf\r\n", newWP->x, newWP->y);
 printf("Turn heading: %f\r\n", turnHeading);
 printf("Line: m %lf, b %lf\r\n", line_mb[0], line_mb[1]);
 int waypointsLeft = 1;
 while(keepGoing && waypointsLeft){
  while(keepGoing && distanceBetweenPoints(*curPosWP, *newWP) > tolerance*0.000011479429428388439){
   printf("Going straight\r\ndistance to target: %lf\r\ntolerance: %lf\r\n", distanceBetweenPoints(*curPosWP, *newWP), tolerance*0.000011479429428388439);
   gpio_set_value(75, 1);
   gpio_set_value(71, 0);
   gpio_set_value(77, 1);
   gpio_set_value(73, 0);
   curPosGPS = getGPS(gpsRet);
   curPosWP->x = curPosGPS.x;
   curPosWP->y = curPosGPS.y;
   if(!bbCheck(line_mb[0], line_mb[1], * curPosWP, tolerance)){
    returnToPreviousWaypoint();
    printf("We're outside of the bounds. Returning to the previous waypoint\r\n");
    break;
   }
   sleep(2);
  }
  printf("We've hit the waypoint! Stopping the motors...\r\n");
  gpio_set_value(75, 0);
  gpio_set_value(71, 0);
  gpio_set_value(77, 0);
  gpio_set_value(73, 0);
  waypointsLeft = (advanceToNextWaypoint() != -1);
  newWP = getCurrentWaypoint();
  printf("KeepGoing: %d...should be 0 if we've hit the end of the waypoints", keepGoing);
 }
 free(curPosWP);
 free(newWP);
}

canonical_original_code:
void waypointManager(){
 struct waypoint *newWP = (waypoint *) malloc(sizeof(waypoint));
 struct dataGPS curPosGPS;
 float turnHeading;
 double tolerance = 3;
 printf("Beginning\r\n");
 addWaypointxy(-87.322314, 39.483694);
 newWP = getCurrentWaypoint();
 printf("\r\nTrying to initialize GPS");
 curPosGPS = getGPS(gpsRet);
 if(!curPosGPS.valid){
  for(int i = 0; i < 10 && !curPosGPS.valid; i++){
   sleep(5);
   printf("\r\nWaiting for valid GPS data....\r\n");
   curPosGPS = getGPS(gpsRet);
  }
 }
 struct waypoint *curPosWP = (waypoint *) malloc(sizeof(waypoint));
 curPosWP->x = curPosGPS.x;
 curPosWP->y = curPosGPS.y;
 turnHeading = angleBetweenPoints(*newWP, *curPosWP);
 turn(turnHeading);
 double line_mb[2];
 findLine(*curPosWP, * newWP, line_mb);
 printf("\r\nCurrent position: x %lf, y %lf\r\n", curPosWP->x, curPosWP->y);
 printf("Waypoint to move to: x %lf, y %lf\r\n", newWP->x, newWP->y);
 printf("Turn heading: %f\r\n", turnHeading);
 printf("Line: m %lf, b %lf\r\n", line_mb[0], line_mb[1]);
 int waypointsLeft = 1;
 while(keepGoing && waypointsLeft){
  while(keepGoing && distanceBetweenPoints(*curPosWP, *newWP) > tolerance*0.000011479429428388439){
   printf("Going straight\r\ndistance to target: %lf\r\ntolerance: %lf\r\n", distanceBetweenPoints(*curPosWP, *newWP), tolerance*0.000011479429428388439);
   gpio_set_value(75, 1);
   gpio_set_value(71, 0);
   gpio_set_value(77, 1);
   gpio_set_value(73, 0);
   curPosGPS = getGPS(gpsRet);
   curPosWP->x = curPosGPS.x;
   curPosWP->y = curPosGPS.y;
   if(!bbCheck(line_mb[0], line_mb[1], * curPosWP, tolerance)){
    returnToPreviousWaypoint();
    printf("We're outside of the bounds. Returning to the previous waypoint\r\n");
    break;
   }
   sleep(2);
  }
  printf("We've hit the waypoint! Stopping the motors...\r\n");
  gpio_set_value(75, 0);
  gpio_set_value(71, 0);
  gpio_set_value(77, 0);
  gpio_set_value(73, 0);
  waypointsLeft = (advanceToNextWaypoint() != -1);
  newWP = getCurrentWaypoint();
  printf("KeepGoing: %d...should be 0 if we've hit the end of the waypoints", keepGoing);
 }
 free(curPosWP);
 free(newWP);
}

variable_types: struct waypoint { double x; double y; } *

variable_types: struct dataGPS { double x; double y; double time; int valid; }

variable_types: turnHeading float

variable_types: i int

variable_types: waypointsLeft int


initSensors

decompiled_code:
__int64 initSensors()
{
__int64 result; // rax

fd = init_I2C();
init_compass((unsigned int)fd);
gpioInit();
result = init_GPS();
gpsRet = result;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax

fd = init_I2C();
init_compass((unsigned int)fd);
func1();
result = init_GPS();
gpsRet = result;
return result;
}

original_code:
void initSensors(void){
       fd = init_I2C();
       init_compass(fd);
       gpioInit();
 gpsRet = init_GPS();
}

canonical_original_code:
void initSensors(){
       fd = init_I2C();
       init_compass(fd);
       gpioInit();
 gpsRet = init_GPS();
}


main

canonical_name: main

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

signal(2, (__sighandler_t)signal_handler);
fd = init_I2C();
init_compass((unsigned int)fd);
gpioInit();
waypointManager();
return result;
}

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

signal(2, (__sighandler_t)signal_handler);
fd = init_I2C();
init_compass((unsigned int)fd);
func1();
func12();
return result;
}

original_code:
void main(int * argv){
 signal(2, signal_handler);
 fd = init_I2C();
 init_compass(fd);
 gpioInit();
 waypointManager();
}

canonical_original_code:
void main(int *argv){
 signal(2, signal_handler);
 fd = init_I2C();
 init_compass(fd);
 gpioInit();
 waypointManager();
}

variable_types:
argv
int *


decompiled_code:
__int64 init_I2C()
{
unsigned int v0; // ebx

v0 = open("/dev/i2c-3", 2);
if ( ioctl(v0, 0x703uLL, 34LL) < 0 )
{
fprintf(stderr, "Failed to set slave address: %m\n");
v0 = 2;
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // ebx

v0 = open("/dev/i2c-3", 2);
if ( ioctl(v0, 0x703uLL, 34LL) < 0 )
{
fprintf(stderr, "Failed to set slave address: %m\n");
v0 = 2;
}
return v0;
}

original_code:
int init_I2C(void){
        int fd;
        fd = open( "/dev/i2c-3", 02);
        if( ioctl(fd, 0x0703, 0x22) < 0)
        {
                fprintf(stderr, "Failed to set slave address: %m\n");
                return 2;
        }
        return fd;
}

canonical_original_code:
int init_I2C(){
        int fd;
        fd = open( "/dev/i2c-3", 02);
        if( ioctl(fd, 0x0703, 0x22) < 0)
        {
                fprintf(stderr, "Failed to set slave address: %m\n");
                return 2;
        }
        return fd;
}

variable_types: fd int


decompiled_code:
int __fastcall init_compass(int a1)
{
ssize_t v1; // rax
__int64 buf; // [rsp+6h] [rbp-12h] BYREF
__int16 v4; // [rsp+Eh] [rbp-Ah]

buf = 6452295LL;
v4 = 0;
v1 = write(a1, &buf, 3uLL);
if ( v1 != 3 )
LODWORD(v1) = fprintf(stderr, "Failed to set to continous mode: %m\n");
return v1;
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
ssize_t v1; // rax
__int64 buf; // [rsp+6h] [rbp-12h] BYREF
__int16 v4; // [rsp+Eh] [rbp-Ah]

buf = 6452295LL;
v4 = 0;
v1 = write(a1, &buf, 3uLL);
if ( v1 != 3 )
LODWORD(v1) = fprintf(stderr, "Failed to set to continous mode: %m\n");
return v1;
}

original_code:
void init_compass(int fd){
        char buf[10] = {0};
        buf[0] = 'G';
        buf[1] = 0x74;
        buf[2] = 0b01100010;
        if(write(fd,buf,3)!=3)
       fprintf(stderr, "Failed to set to continous mode: %m\n");
}

variable_types:
buf
char [10]


decompiled_code:
int __fastcall calibrate_compass(int fd)
{
__int64 buf; // [rsp+6h] [rbp-12h] BYREF
__int16 v3; // [rsp+Eh] [rbp-Ah]

buf = 67LL;
v3 = 0;
if ( write(fd, &buf, 1uLL) != 1 )
fprintf(stderr, "Failed to start calibration: %m\n");
printf("Calibration started\n\r");
sleep(0xAu);
LOBYTE(buf) = 69;
if ( write(fd, &buf, 1uLL) != 1 )
fprintf(stderr, "Failed to exit calibration: %m\n");
return printf("Calibration complete\n\r");
}

canonical_decompiled_code:
int __fastcall func8(int fd)
{
__int64 buf; // [rsp+6h] [rbp-12h] BYREF
__int16 v3; // [rsp+Eh] [rbp-Ah]

buf = 67LL;
v3 = 0;
if ( write(fd, &buf, 1uLL) != 1 )
fprintf(stderr, "Failed to start calibration: %m\n");
printf("Calibration started\n\r");
sleep(0xAu);
LOBYTE(buf) = 69;
if ( write(fd, &buf, 1uLL) != 1 )
fprintf(stderr, "Failed to exit calibration: %m\n");
return printf("Calibration complete\n\r");
}

original_code:
void calibrate_compass(int fd){
 char buf[10] = {0};
 buf[0] = 'C';
 if(write(fd,buf,1)!=1)
   fprintf(stderr, "Failed to start calibration: %m\n");
 printf("Calibration started\n\r");
 sleep(10);
 buf[0] = 'E';
 if(write(fd,buf,1)!=1)
   fprintf(stderr, "Failed to exit calibration: %m\n");
 printf("Calibration complete\n\r");
}


getHeading

decompiled_code:
float __fastcall getHeading(int a1)
{
__int64 buf; // [rsp+6h] [rbp-12h] BYREF
__int16 v3; // [rsp+Eh] [rbp-Ah]

buf = 0LL;
v3 = 0;
if ( read(a1, &buf, 2uLL) != 2 )
fprintf(stderr, "Failed to read compass: %m\n");
return (double)(SBYTE1(buf) + ((char)buf << 8)) / 10.0;
}

canonical_decompiled_code:
float __fastcall func9(int a1)
{
__int64 buf; // [rsp+6h] [rbp-12h] BYREF
__int16 v3; // [rsp+Eh] [rbp-Ah]

buf = 0LL;
v3 = 0;
if ( read(a1, &buf, 2uLL) != 2 )
fprintf(stderr, "Failed to read compass: %m\n");
return (double)(SBYTE1(buf) + ((char)buf << 8)) / 10.0;
}

original_code:
float getHeading(int fd){
        char data[10] = {0};
        if(read(fd,data,2)!=2)
                fprintf(stderr,"Failed to read compass: %m\n");
        float result = ((data[0] << 8) + data[1])/10.0;
        return result;
}

variable_types:
data
char [10]

variable_types: result float


addWaypoint

decompiled_code:
__int64 __fastcall addWaypoint(double a1, double a2)
{
int v2; // edx
double *v3; // rax

v2 = numberOfWaypoints[0];
if ( numberOfWaypoints[0] > 99 )
return 0xFFFFFFFFLL;
v3 = (double *)((char *)&waypointList + 16 * numberOfWaypoints[0]);
*v3 = a1;
v3[1] = a2;
numberOfWaypoints[0] = v2 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(double a1, double a2)
{
int v2; // edx
double *v3; // rax

v2 = numberOfWaypoints[0];
if ( numberOfWaypoints[0] > 99 )
return 0xFFFFFFFFLL;
v3 = (double *)((char *)&waypointList + 16 * numberOfWaypoints[0]);
*v3 = a1;
v3[1] = a2;
numberOfWaypoints[0] = v2 + 1;
return 0LL;
}

original_code:
int addWaypoint(waypoint newWaypoint){
 if(numberOfWaypoints < 100){
  waypointList[numberOfWaypoints] = newWaypoint;
  numberOfWaypoints++;
  return 0;
 }
 else
  return -1;
}

canonical_original_code:
int addWaypoint(struct waypoint newWaypoint){
 if(numberOfWaypoints < 100){
  waypointList[numberOfWaypoints] = newWaypoint;
  numberOfWaypoints++;
  return 0;
 }
 else
  return -1;
}

variable_types:
newWaypoint
struct waypoint { double x; double y; }


addWaypointxy

decompiled_code:
__int64 addWaypointxy()
{
return addWaypoint();
}

canonical_decompiled_code:
__int64 func7()
{
return func6();
}

original_code:
int addWaypointxy(double x, double y){
 waypoint newwp;
 newwp.x = x;
 newwp.y = y;
 return addWaypoint(newwp);
}

canonical_original_code:
int addWaypointxy(double x, double y){
 struct waypoint newwp;
 newwp.x = x;
 newwp.y = y;
 return addWaypoint(newwp);
}

variable_types: x double

variable_types: y double

variable_types:
newwp
struct waypoint { double x; double y; }


getCurrentWaypoint

decompiled_code:
char *getCurrentWaypoint()
{
char *result; // rax

if ( numberOfWaypoints[0] <= 0 )
result = 0LL;
else
result = (char *)&waypointList + 16 * currentWaypoint;
return result;
}

canonical_decompiled_code:
char *func8()
{
char *result; // rax

if ( numberOfWaypoints[0] <= 0 )
result = 0LL;
else
result = (char *)&waypointList + 16 * currentWaypoint;
return result;
}

original_code:
waypoint * getCurrentWaypoint(void){
 if(numberOfWaypoints <= 0)
  return ((void *)0);
 return &waypointList[currentWaypoint];
}

canonical_original_code:
struct waypoint *getCurrentWaypoint(){
 if(numberOfWaypoints <= 0)
  return ((void *)0);
 return &waypointList[currentWaypoint];
}

return_type: struct waypoint { double x; double y; } *


getNumberOfWaypoints

decompiled_code:
__int64 getNumberOfWaypoints()
{
return (unsigned int)numberOfWaypoints[0];
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)numberOfWaypoints[0];
}

original_code:
int getNumberOfWaypoints(void){
 return numberOfWaypoints;
}

canonical_original_code:
int getNumberOfWaypoints(){
 return numberOfWaypoints;
}


advanceToNextWaypoint

decompiled_code:
__int64 advanceToNextWaypoint()
{
if ( currentWaypoint >= numberOfWaypoints[0] )
return 0xFFFFFFFFLL;
return (unsigned int)++currentWaypoint;
}

canonical_decompiled_code:
__int64 func10()
{
if ( currentWaypoint >= numberOfWaypoints[0] )
return 0xFFFFFFFFLL;
return (unsigned int)++currentWaypoint;
}

original_code:
int advanceToNextWaypoint(void){
 if(currentWaypoint >= numberOfWaypoints)
  return -1;
 else
  return ++currentWaypoint;
}

canonical_original_code:
int advanceToNextWaypoint(){
 if(currentWaypoint >= numberOfWaypoints)
  return -1;
 else
  return ++currentWaypoint;
}


returnToPreviousWaypoint

decompiled_code:
__int64 returnToPreviousWaypoint()
{
if ( !currentWaypoint )
return 0xFFFFFFFFLL;
return (unsigned int)--currentWaypoint;
}

canonical_decompiled_code:
__int64 func11()
{
if ( !currentWaypoint )
return 0xFFFFFFFFLL;
return (unsigned int)--currentWaypoint;
}

original_code:
int returnToPreviousWaypoint(void){
 if(currentWaypoint == 0)
  return -1;
 else
  return --currentWaypoint;
}

canonical_original_code:
int returnToPreviousWaypoint(){
 if(currentWaypoint == 0)
  return -1;
 else
  return --currentWaypoint;
}


distanceBetweenPoints

decompiled_code:
double __fastcall distanceBetweenPoints(double a1, double a2, double a3, double a4)
{
double v4; // xmm3_8
double result; // xmm0_8

v4 = (a4 - a2) * (a4 - a2) + (a3 - a1) * (a3 - a1);
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

canonical_decompiled_code:
double __fastcall func12(double a1, double a2, double a3, double a4)
{
double v4; // xmm3_8
double result; // xmm0_8

v4 = (a4 - a2) * (a4 - a2) + (a3 - a1) * (a3 - a1);
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

original_code:
double distanceBetweenPoints(waypoint A, waypoint B){
 double d = sqrt(pow(B.x - A.x,2)+pow(B.y - A.y,2));
 return d;
}

canonical_original_code:
double distanceBetweenPoints(struct waypoint A, struct waypoint B){
 double d = sqrt(pow(B.x - A.x,2)+pow(B.y - A.y,2));
 return d;
}

variable_types:
A
struct waypoint { double x; double y; }

variable_types:
B
struct waypoint

variable_types: d double


angleBetweenPoints

decompiled_code:
float __fastcall angleBetweenPoints(double a1, double a2, double a3, double a4)
{
float v4; // xmm1_4
float v5; // xmm2_4
float result; // xmm0_4

v4 = a4 - a2;
v5 = a3 - a1;
result = atan2(v5, v4) * 180.0 / 3.14159265359;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

canonical_decompiled_code:
float __fastcall func13(double a1, double a2, double a3, double a4)
{
float v4; // xmm1_4
float v5; // xmm2_4
float result; // xmm0_4

v4 = a4 - a2;
v5 = a3 - a1;
result = atan2(v5, v4) * 180.0 / 3.14159265359;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

original_code:
float angleBetweenPoints(waypoint A, waypoint B){
 float deltax = B.x - A.x;
 float deltay = B.y - A.y;
 float angle = atan2(deltax,deltay) * 180 / 3.14159265359;
 if (angle < 0)
  angle = angle + 360;
        return angle;
}

canonical_original_code:
float angleBetweenPoints(struct waypoint A, struct waypoint B){
 float deltax = B.x - A.x;
 float deltay = B.y - A.y;
 float angle = atan2(deltax,deltay) * 180 / 3.14159265359;
 if (angle < 0)
  angle = angle + 360;
        return angle;
}

variable_types: deltax float

variable_types: deltay float

variable_types: angle float


sendToGPS

decompiled_code:
__int64 __fastcall sendToGPS(int fd)
{
__int64 *v1; // rax
char v2; // cl
char v3; // si
__int64 i; // rbx
__int64 v6[12]; // [rsp+0h] [rbp-88h] BYREF
int v7; // [rsp+60h] [rbp-28h]
__int64 buf[4]; // [rsp+68h] [rbp-20h] BYREF

buf[0] = 990274229LL;
v1 = buf;
v2 = 0;
v3 = 0;
do
{
v3 += *((_BYTE *)v1 + 2);
v2 += v3;
v1 = (__int64 *)((char *)v1 + 1);
}
while ( v1 != (__int64 *)((char *)buf + 4) );
BYTE6(buf[0]) = v3;
HIBYTE(buf[0]) = v2;
if ( write(fd, buf, 8uLL) != 8 )
fprintf(stderr, "Failed to set to continous mode: %m\n");
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
v6[7] = 0LL;
v6[8] = 0LL;
v6[9] = 0LL;
v6[10] = 0LL;
v6[11] = 0LL;
v7 = 0;
if ( read(fd, v6, 0x3EuLL) != 62 )
fprintf(stderr, "Failed to read compass: %m\n");
for ( i = 0LL; i != 62; ++i )
printf("%d: %x\n\r", (unsigned int)i, (unsigned int)*((char *)v6 + i));
return 0LL;
}

original_code:
int sendToGPS(int serial_file){
  char buf[52] = {0};
        buf[0] = 'G';
        buf[1] = 0x74;
        buf[2] = 0b01100010;
 char buf_read[8] = {0};
 buf_read[0] = 0xB5;
 buf_read[1] = 0x62;
 buf_read[2] = 0x06;
 buf_read[3] = 0x3B;
 buf_read[4] = 0x00;
 buf_read[5] = 0x00;
 char ck_a = 0;
 char ck_b = 0;
 int i = 0;
 for(i=2; i < 6; i++){
  ck_a = ck_a + buf_read[i];
  ck_b = ck_b + ck_a;
 }
 buf_read[6] = ck_a;
 buf_read[7] = ck_b;
        if(write(serial_file,buf_read,8)!=8)
       fprintf(stderr, "Failed to set to continous mode: %m\n");
 char data[100] = {0};
 if(read(serial_file,data,62)!=62)
                fprintf(stderr,"Failed to read compass: %m\n");
 i = 0;
 for(i = 0; i < 62; i++)
  printf("%d: %x\n\r",i, data[i]);
 return 0;
}

variable_types:
buf
char [52]

variable_types: i int

variable_types:
data
char [100]


decompiled_code:
void __fastcall __noreturn handle_egl_error(const char *a1)
{
unsigned int v1; // eax

v1 = eglGetError();
fprintf(stderr, " %s: egl error \"%s\" (0x%x)\n", a1, error_strings_0[v1 - 12288], v1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
unsigned int v1; // eax

v1 = eglGetError();
fprintf(stderr, " %s: egl error \"%s\" (0x%x)\n", a1, error_strings_0[v1 - 12288], v1);
exit(1);
}

original_code:
static void handle_egl_error(const char *name)
{
    static char * const error_strings[] = {
        "EGL_SUCCESS",
        "EGL_NOT_INITIALIZED",
        "EGL_BAD_ACCESS",
        "EGL_BAD_ALLOC",
        "EGL_BAD_ATTRIBUTE",
        "EGL_BAD_CONFIG",
        "EGL_BAD_CONTEXT",
        "EGL_BAD_CURRENT_SURFACE",
        "EGL_BAD_DISPLAY",
        "EGL_BAD_MATCH",
        "EGL_BAD_NATIVE_PIXMAP",
        "EGL_BAD_NATIVE_WINDOW",
        "EGL_BAD_PARAMETER",
        "EGL_BAD_SURFACE"
    };
    EGLint error_code=eglGetError();
    fprintf(stderr," %s: egl error \"%s\" (0x%x)\n", name,
            error_strings[error_code-0x3000], error_code);
    exit(1);
}

canonical_original_code:
static void handle_egl_error(char *name)
{
    static char *error_strings[] = {
        "EGL_SUCCESS",
        "EGL_NOT_INITIALIZED",
        "EGL_BAD_ACCESS",
        "EGL_BAD_ALLOC",
        "EGL_BAD_ATTRIBUTE",
        "EGL_BAD_CONFIG",
        "EGL_BAD_CONTEXT",
        "EGL_BAD_CURRENT_SURFACE",
        "EGL_BAD_DISPLAY",
        "EGL_BAD_MATCH",
        "EGL_BAD_NATIVE_PIXMAP",
        "EGL_BAD_NATIVE_WINDOW",
        "EGL_BAD_PARAMETER",
        "EGL_BAD_SURFACE"
    };
    int error_code = eglGetError();
    fprintf(stderr," %s: egl error \"%s\" (0x%x)\n", name,
            error_strings[error_code-0x3000], error_code);
    exit(1);
}

variable_types:
name
char *


eglOpen

decompiled_code:
__int64 eglOpen()
{
__int64 v0; // rax
const char *v1; // rax
const char *v2; // rax
__int64 v3; // rcx
__int64 result; // rax
int v5[6]; // [rsp+0h] [rbp-38h] BYREF
int v6[3]; // [rsp+18h] [rbp-20h] BYREF
int v7; // [rsp+24h] [rbp-14h] BYREF
char v8[4]; // [rsp+28h] [rbp-10h] BYREF
char v9[12]; // [rsp+2Ch] [rbp-Ch] BYREF

v6[0] = 12440;
v6[1] = 2;
v6[2] = 12344;
v5[0] = 12339;
v5[1] = 4;
v5[2] = 12352;
v5[3] = 4;
v5[4] = 12344;
v0 = eglGetDisplay(nativeDisplay);
eglDisplay = v0;
if ( v0 )
{
if ( (unsigned int)eglInitialize(v0, v9, v8) )
{
v1 = (const char *)eglQueryString(eglDisplay, 12372LL);
printf("EGL_VERSION = %s\n", v1);
v2 = (const char *)eglQueryString(eglDisplay, 12373LL);
printf("EGL_EXTENSIONS: %s\n", v2);
eglBindAPI(12448LL);
if ( !(unsigned int)eglChooseConfig(eglDisplay, v5, &eglConfig, 1LL, &v7) || v7 != 1 )
handle_egl_error("eglChooseConfig");
eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, 0LL);
if ( !eglWindowSurface )
handle_egl_error("eglCreateWindowSurface");
v3 = eglCreateContext(eglDisplay, eglConfig, 0LL, v6);
eglContext = v3;
if ( !v3 )
handle_egl_error("eglCreateContext");
if ( !(unsigned int)eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, v3) )
handle_egl_error("eglMakeCurrent");
result = 0LL;
}
else
{
puts("eglInitialize failed");
result = 0xFFFFFFFFLL;
}
}
else
{
puts("eglGetDisplay error");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
const char *v1; // rax
const char *v2; // rax
__int64 v3; // rcx
__int64 result; // rax
int v5[6]; // [rsp+0h] [rbp-38h] BYREF
int v6[3]; // [rsp+18h] [rbp-20h] BYREF
int v7; // [rsp+24h] [rbp-14h] BYREF
char v8[4]; // [rsp+28h] [rbp-10h] BYREF
char v9[12]; // [rsp+2Ch] [rbp-Ch] BYREF

v6[0] = 12440;
v6[1] = 2;
v6[2] = 12344;
v5[0] = 12339;
v5[1] = 4;
v5[2] = 12352;
v5[3] = 4;
v5[4] = 12344;
v0 = eglGetDisplay(nativeDisplay);
eglDisplay = v0;
if ( v0 )
{
if ( (unsigned int)eglInitialize(v0, v9, v8) )
{
v1 = (const char *)eglQueryString(eglDisplay, 12372LL);
printf("EGL_VERSION = %s\n", v1);
v2 = (const char *)eglQueryString(eglDisplay, 12373LL);
printf("EGL_EXTENSIONS: %s\n", v2);
eglBindAPI(12448LL);
if ( !(unsigned int)eglChooseConfig(eglDisplay, v5, &eglConfig, 1LL, &v7) || v7 != 1 )
func0("eglChooseConfig");
eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, 0LL);
if ( !eglWindowSurface )
func0("eglCreateWindowSurface");
v3 = eglCreateContext(eglDisplay, eglConfig, 0LL, v6);
eglContext = v3;
if ( !v3 )
func0("eglCreateContext");
if ( !(unsigned int)eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, v3) )
func0("eglMakeCurrent");
result = 0LL;
}
else
{
puts("eglInitialize failed");
result = 0xFFFFFFFFLL;
}
}
else
{
puts("eglGetDisplay error");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int eglOpen(void)
{
    EGLint majorVersion;
    EGLint minorVersion;
    EGLint numConfigs;
    EGLBoolean ret;
    const char *ver, *extensions;
    int k = 0, i = 0, fnd = 0;
    EGLint gl_context_attribs[] = {
        0x3098, 2,
        0x3038
    };
    EGLint pi32ConfigAttribs[] = {
        0x3033, 0x0004,
        0x3040, 0x0004,
        0x3038
    };
    eglDisplay = eglGetDisplay(nativeDisplay);
    if (!eglDisplay) {
        printf("eglGetDisplay error\n");
        return -1;
    }
    if (!eglInitialize(eglDisplay, &majorVersion, &minorVersion)) {
        printf("eglInitialize failed\n");
        return -1;
    }
    ver = eglQueryString(eglDisplay, 0x3054);
    printf("EGL_VERSION = %s\n", ver);
    extensions = eglQueryString(eglDisplay, 0x3055);
    printf("EGL_EXTENSIONS: %s\n", extensions);
    eglBindAPI(0x30A0);
    if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &numConfigs) || numConfigs != 1) {
  handle_egl_error("eglChooseConfig");
        return -1;
    }
    eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, ((void *)0));
    if (eglWindowSurface == ((EGLSurface) (0))) {
        handle_egl_error("eglCreateWindowSurface");
        return -1;
    }
    eglContext = eglCreateContext(eglDisplay, eglConfig, ((void *)0), gl_context_attribs);
    if (eglContext == ((EGLContext) (0))) {
        handle_egl_error("eglCreateContext");
        return -1;
    }
    ret = eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, eglContext);
    if (ret == 0) {
        handle_egl_error("eglMakeCurrent");
        return -1;
    }
    return 0;
}

canonical_original_code:
static int eglOpen()
{
    int majorVersion;
    int minorVersion;
    int numConfigs;
    unsigned int ret;
    char *ver; char *extensions;
    int k = 0; int i = 0; int fnd = 0;
    int gl_context_attribs[] = {
        0x3098, 2,
        0x3038
    };
    int pi32ConfigAttribs[] = {
        0x3033, 0x0004,
        0x3040, 0x0004,
        0x3038
    };
    eglDisplay = eglGetDisplay(nativeDisplay);
    if (!eglDisplay) {
        printf("eglGetDisplay error\n");
        return -1;
    }
    if (!eglInitialize(eglDisplay, &majorVersion, &minorVersion)) {
        printf("eglInitialize failed\n");
        return -1;
    }
    ver = eglQueryString(eglDisplay, 0x3054);
    printf("EGL_VERSION = %s\n", ver);
    extensions = eglQueryString(eglDisplay, 0x3055);
    printf("EGL_EXTENSIONS: %s\n", extensions);
    eglBindAPI(0x30A0);
    if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &numConfigs) || numConfigs != 1) {
  handle_egl_error("eglChooseConfig");
        return -1;
    }
    eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, ((void *)0));
    if (eglWindowSurface == ((EGLSurface) (0))) {
        handle_egl_error("eglCreateWindowSurface");
        return -1;
    }
    eglContext = eglCreateContext(eglDisplay, eglConfig, ((void *)0), gl_context_attribs);
    if (eglContext == ((EGLContext) (0))) {
        handle_egl_error("eglCreateContext");
        return -1;
    }
    ret = eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, eglContext);
    if (ret == 0) {
        handle_egl_error("eglMakeCurrent");
        return -1;
    }
    return 0;
}

variable_types: majorVersion int

variable_types: minorVersion int

variable_types: numConfigs int

variable_types:
ret
unsigned int

variable_types:
ver
char *

variable_types:
extensions
char *

variable_types: k int

variable_types: fnd int


eglClose

decompiled_code:
__int64 eglClose()
{
eglMakeCurrent(eglDisplay, 0LL, 0LL, 0LL);
eglDestroyContext(eglDisplay, eglContext);
eglDestroySurface(eglDisplay, eglWindowSurface);
return eglTerminate(eglDisplay);
}

canonical_decompiled_code:
__int64 func2()
{
eglMakeCurrent(eglDisplay, 0LL, 0LL, 0LL);
eglDestroyContext(eglDisplay, eglContext);
eglDestroySurface(eglDisplay, eglWindowSurface);
return eglTerminate(eglDisplay);
}

original_code:
static void eglClose(void)
{
    eglMakeCurrent(eglDisplay, ((void *)0), ((void *)0), ((void *)0));
    eglDestroyContext(eglDisplay, eglContext);
    eglDestroySurface(eglDisplay, eglWindowSurface);
    eglTerminate(eglDisplay);
}

canonical_original_code:
static void eglClose()
{
    eglMakeCurrent(eglDisplay, ((void *)0), ((void *)0), ((void *)0));
    eglDestroyContext(eglDisplay, eglContext);
    eglDestroySurface(eglDisplay, eglWindowSurface);
    eglTerminate(eglDisplay);
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // ebx
int result; // eax

v3 = 100;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
v3 = atoi(*(const char **)&argc);
}
if ( (int)platform_open(*(_QWORD *)&argc, argv, envp) < 0 )
{
puts("can't init platform");
result = -1;
}
else
{
nativeDisplay = plat_get_display();
nativeWindow = plat_get_window();
plat_get_geometry(&width, &height);
if ( (int)eglOpen() < 0 )
{
puts("error in eglOpen");
result = -1;
}
else
{
gles2_init();
v4 = v3 - 1;
if ( v3 >= 0 )
{
do
{
gles2_update_state(v4);
gles2_draw((unsigned int)width, (unsigned int)height);
eglSwapBuffers(eglDisplay, eglWindowSurface);
--v4;
}
while ( v4 != -2 );
}
eglClose();
platform_close();
result = 0;
}
}
return result;
}

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

v3 = 100;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
v3 = atoi(*(const char **)&argc);
}
if ( (int)platform_open(*(_QWORD *)&argc, argv, envp) < 0 )
{
puts("can't init platform");
result = -1;
}
else
{
nativeDisplay = plat_get_display();
nativeWindow = plat_get_window();
plat_get_geometry(&width, &height);
if ( (int)func1() < 0 )
{
puts("error in eglOpen");
result = -1;
}
else
{
gles2_init();
v4 = v3 - 1;
if ( v3 >= 0 )
{
do
{
gles2_update_state(v4);
gles2_draw((unsigned int)width, (unsigned int)height);
eglSwapBuffers(eglDisplay, eglWindowSurface);
--v4;
}
while ( v4 != -2 );
}
func2();
platform_close();
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int iterations = 100;
    int ret = 0;
    if(argc > 1)
        iterations = atoi(argv[1]);
 ret = platform_open();
 if (0 > ret) {
  printf("can't init platform\n");
  return -1;
 }
 nativeDisplay = plat_get_display();
    if (0 > nativeDisplay) {
        printf("can't get platform display\n");
        return -1;
    }
 nativeWindow = plat_get_window();
    if (0 > nativeWindow) {
        printf("can't get platform window\n");
        return -1;
    }
 plat_get_geometry(&width, &height);
 ret = eglOpen();
 if (0 > ret) {
        printf("error in eglOpen\n");
        return -1;
    }
 gles2_init();
    while(iterations-- >= 0) {
  gles2_update_state(iterations);
  gles2_draw(width, height);
  eglSwapBuffers(eglDisplay, eglWindowSurface);
    }
    eglClose();
 platform_close();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: iterations int

variable_types: ret int


xwinClose

decompiled_code:
void xwinClose()
{
if ( xWindow )
XDestroyWindow(xDisplay, xWindow);
if ( xColormap )
XFreeColormap(xDisplay, xColormap);
if ( xDisplay )
XCloseDisplay(xDisplay);
if ( xVisual )
free(xVisual);
}

canonical_decompiled_code:
void func0()
{
if ( xWindow )
XDestroyWindow(xDisplay, xWindow);
if ( xColormap )
XFreeColormap(xDisplay, xColormap);
if ( xDisplay )
XCloseDisplay(xDisplay);
if ( xVisual )
free(xVisual);
}

original_code:
static void xwinClose(void)
{
    if (xWindow)
    {
        XDestroyWindow(xDisplay, xWindow);
    }
    if (xColormap)
    {
        XFreeColormap(xDisplay, xColormap);
    }
    if (xDisplay)
    {
        XCloseDisplay(xDisplay);
    }
    if (xVisual)
    {
        free(xVisual);
    }
}

canonical_original_code:
static void xwinClose()
{
    if (xWindow)
    {
        XDestroyWindow(xDisplay, xWindow);
    }
    if (xColormap)
    {
        XFreeColormap(xDisplay, xColormap);
    }
    if (xDisplay)
    {
        XCloseDisplay(xDisplay);
    }
    if (xVisual)
    {
        free(xVisual);
    }
}


xwinOpen

decompiled_code:
__int64 xwinOpen()
{
Display *v0; // rax
int v1; // ebx
Display *v2; // rbp
Screen *v3; // rax
int v4; // er12
Window v5; // r13
int v6; // ebx
int v7; // eax
int v8; // er9
Window v9; // rsi
__int64 result; // rax
XSetWindowAttributes v11; // [rsp+0h] [rbp-98h] BYREF

xWindow = 0LL;
*(_QWORD *)&xScreen = 0LL;
xDisplay = 0LL;
xVisual = 0LL;
v0 = XOpenDisplay(0LL);
xDisplay = v0;
if ( v0 )
{
v1 = XDefaultScreen(v0);
*(_QWORD *)&xScreen = v1;
v2 = xDisplay;
v3 = &xDisplay->screens[(__int64)v1];
v4 = v3->root_depth;
v5 = v3->root;
xVisual = calloc(1uLL, 0x40uLL);
XMatchVisualInfo(v2, v1, v4, 4, (XVisualInfo *)xVisual);
if ( xVisual )
{
xColormap = XCreateColormap(xDisplay, v5, *(Visual **)xVisual, 0);
v11.colormap = xColormap;
v11.event_mask = 163855LL;
v6 = 640;
if ( XDisplayWidth(xDisplay, xScreen) <= 640 )
v6 = XDisplayWidth(xDisplay, xScreen);
v7 = XDisplayHeight(xDisplay, xScreen);
v8 = 480;
if ( v7 <= 480 )
v8 = XDisplayHeight(xDisplay, xScreen);
v9 = XCreateWindow(
xDisplay,
xDisplay->screens[*(_QWORD *)&xScreen].root,
0,
0,
v6,
v8,
0,
*((_DWORD *)xVisual + 5),
1u,
*(Visual **)xVisual,
0x280AuLL,
&v11);
xWindow = v9;
if ( v9 )
{
XMapWindow(xDisplay, v9);
XFlush(xDisplay);
result = 0LL;
}
else
{
puts("Error: Couldn't cread XWindow");
xwinClose();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Error: Unable to acquire visual");
xwinClose();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Error: Unable to open X display");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
Display *v0; // rax
int v1; // ebx
Display *v2; // rbp
Screen *v3; // rax
int v4; // er12
Window v5; // r13
int v6; // ebx
int v7; // eax
int v8; // er9
Window v9; // rsi
__int64 result; // rax
XSetWindowAttributes v11; // [rsp+0h] [rbp-98h] BYREF

xWindow = 0LL;
*(_QWORD *)&xScreen = 0LL;
xDisplay = 0LL;
xVisual = 0LL;
v0 = XOpenDisplay(0LL);
xDisplay = v0;
if ( v0 )
{
v1 = XDefaultScreen(v0);
*(_QWORD *)&xScreen = v1;
v2 = xDisplay;
v3 = &xDisplay->screens[(__int64)v1];
v4 = v3->root_depth;
v5 = v3->root;
xVisual = calloc(1uLL, 0x40uLL);
XMatchVisualInfo(v2, v1, v4, 4, (XVisualInfo *)xVisual);
if ( xVisual )
{
xColormap = XCreateColormap(xDisplay, v5, *(Visual **)xVisual, 0);
v11.colormap = xColormap;
v11.event_mask = 163855LL;
v6 = 640;
if ( XDisplayWidth(xDisplay, xScreen) <= 640 )
v6 = XDisplayWidth(xDisplay, xScreen);
v7 = XDisplayHeight(xDisplay, xScreen);
v8 = 480;
if ( v7 <= 480 )
v8 = XDisplayHeight(xDisplay, xScreen);
v9 = XCreateWindow(
xDisplay,
xDisplay->screens[*(_QWORD *)&xScreen].root,
0,
0,
v6,
v8,
0,
*((_DWORD *)xVisual + 5),
1u,
*(Visual **)xVisual,
0x280AuLL,
&v11);
xWindow = v9;
if ( v9 )
{
XMapWindow(xDisplay, v9);
XFlush(xDisplay);
result = 0LL;
}
else
{
puts("Error: Couldn't cread XWindow");
func0();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Error: Unable to acquire visual");
func0();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Error: Unable to open X display");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int xwinOpen(void)
{
    XSetWindowAttributes window_attributes;
    Window root_window;
    unsigned int window_mask;
    int height_corrected;
    int width_corrected;
    int color_depth;
    xWindow = 0;
    xScreen = 0;
    xDisplay = ((void *)0);
    xVisual = ((void *)0);
    xDisplay = XOpenDisplay(0);
    if (!xDisplay)
    {
        printf("Error: Unable to open X display\n");
        return -1;
    }
    xScreen = XDefaultScreen(xDisplay);
    color_depth = ((&((_XPrivDisplay)(xDisplay))->screens[xScreen])->root_depth);
    root_window = ((&((_XPrivDisplay)(xDisplay))->screens[xScreen])->root);
    xVisual = (XVisualInfo*) calloc(1, sizeof(XVisualInfo));
    XMatchVisualInfo(xDisplay, xScreen, color_depth, 4, xVisual);
    if (!xVisual)
    {
        printf("Error: Unable to acquire visual\n");
        xwinClose();
        return -1;
    }
    xColormap = XCreateColormap(xDisplay, root_window, xVisual->visual, 0);
    window_attributes.colormap = xColormap;
    window_attributes.event_mask = (1L<<17) | (1L<<15) | (1L<<2) | (1L<<3) | (1L<<0) | (1L<<1);
    window_mask = (1L<<1) | (1L<<3) | (1L<<11) | (1L<<13);
    width_corrected = 640 < XDisplayWidth(xDisplay, xScreen) ? 640 : XDisplayWidth(xDisplay, xScreen);
    height_corrected = 480 < XDisplayHeight(xDisplay, xScreen) ? 480 : XDisplayHeight(xDisplay, xScreen);
    xWindow = XCreateWindow(xDisplay, ((&((_XPrivDisplay)(xDisplay))->screens[xScreen])->root), 0, 0,
            width_corrected, height_corrected, 0, xVisual->depth, 1,
            xVisual->visual, window_mask, &window_attributes);
    if (0 == xWindow)
    {
        printf("Error: Couldn't cread XWindow\n");
        xwinClose();
        return -1;
    }
    XMapWindow(xDisplay, xWindow);
    XFlush(xDisplay);
    return 0;
}

canonical_original_code:
static int xwinOpen()
{
    struct XSetWindowAttributes window_attributes;
    unsigned long root_window;
    unsigned int window_mask;
    int height_corrected;
    int width_corrected;
    int color_depth;
    xWindow = 0;
    xScreen = 0;
    xDisplay = ((void *)0);
    xVisual = ((void *)0);
    xDisplay = XOpenDisplay(0);
    if (!xDisplay)
    {
        printf("Error: Unable to open X display\n");
        return -1;
    }
    xScreen = XDefaultScreen(xDisplay);
    color_depth = ((&((_XPrivDisplay)(xDisplay))->screens[xScreen])->root_depth);
    root_window = ((&((_XPrivDisplay)(xDisplay))->screens[xScreen])->root);
    xVisual = (struct XVisualInfo *) calloc(1, sizeof(XVisualInfo));
    XMatchVisualInfo(xDisplay, xScreen, color_depth, 4, xVisual);
    if (!xVisual)
    {
        printf("Error: Unable to acquire visual\n");
        xwinClose();
        return -1;
    }
    xColormap = XCreateColormap(xDisplay, root_window, xVisual->visual, 0);
    window_attributes.colormap = xColormap;
    window_attributes.event_mask = (1L<<17) | (1L<<15) | (1L<<2) | (1L<<3) | (1L<<0) | (1L<<1);
    window_mask = (1L<<1) | (1L<<3) | (1L<<11) | (1L<<13);
    width_corrected = 640 < XDisplayWidth(xDisplay, xScreen) ? 640 : XDisplayWidth(xDisplay, xScreen);
    height_corrected = 480 < XDisplayHeight(xDisplay, xScreen) ? 480 : XDisplayHeight(xDisplay, xScreen);
    xWindow = XCreateWindow(xDisplay, ((&((_XPrivDisplay)(xDisplay))->screens[xScreen])->root), 0, 0,
            width_corrected, height_corrected, 0, xVisual->depth, 1,
            xVisual->visual, window_mask, &window_attributes);
    if (0 == xWindow)
    {
        printf("Error: Couldn't cread XWindow\n");
        xwinClose();
        return -1;
    }
    XMapWindow(xDisplay, xWindow);
    XFlush(xDisplay);
    return 0;
}

variable_types: struct XSetWindowAttributes { unsigned long background_pixmap; unsigned long background_pixel; unsigned long border_pixmap; unsigned long border_pixel; int bit_gravity; int win_gravity; int backing_store; unsigned long backing_planes; unsigned long backing_pixel; int save_under; long event_mask; long do_not_propagate_mask; int override_redirect; unsigned long colormap; unsigned long cursor; }

user_defined_types: struct XVisualInfo { struct Visual *visual; unsigned long visualid; int screen; int depth; int class; unsigned long red_mask; unsigned long green_mask; unsigned long blue_mask; int colormap_size; int bits_per_rgb; }

user_defined_types: struct Visual { struct _XExtData *ext_data; unsigned long visualid; int class; unsigned long red_mask; int bits_per_rgb; int map_entries; }

user_defined_types: struct _XExtData { int number; struct _XExtData *next; int (*free_private)(struct _XExtData *extension); char *private_data; }


decompiled_code:
__int64 platform_open()
{
return xwinOpen();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

original_code:
int platform_open(void)
{
 return xwinOpen();
}

canonical_original_code:
int platform_open()
{
 return xwinOpen();
}


decompiled_code:
void platform_close()
{
xwinClose();
}

canonical_decompiled_code:
void func3()
{
func0();
}

original_code:
void platform_close(void)
{
 xwinClose();
}

canonical_original_code:
void platform_close()
{
 xwinClose();
}


decompiled_code:
Window plat_get_window()
{
return xWindow;
}

canonical_decompiled_code:
Window func5()
{
return xWindow;
}

original_code:
EGLNativeWindowType plat_get_window(void)
{
 return (EGLNativeWindowType) xWindow;
}

canonical_original_code:
unsigned long plat_get_window()
{
 return (unsigned long) xWindow;
}

return_type: unsigned long


repo: georgik/fimuni-c-cpp-examples

decompiled_code:
const char *test_convert()
{
_DWORD *v0; // rbx
const char *result; // rax
int v2; // edx
char v3[10]; // [rsp+6h] [rbp-12h] BYREF

v0 = malloc(0x18uLL);
strcpy(&v3[6], "Jan");
strcpy(v3, "Novak");
*(_QWORD *)v0 = &v3[6];
*((_QWORD *)v0 + 1) = v3;
v0[4] = 45;
convert(v0);
result = "age should be increased to 46";
if ( v0[4] == 46 )
{
if ( !strcmp(*(const char **)v0, "JAN") )
{
v2 = strcmp(*((const char **)v0 + 1), "NOVAK");
result = "surname should be uppercase";
if ( !v2 )
{
free(v0);
result = 0LL;
}
}
else
{
result = "surname should be uppercase" + 3;
}
}
return result;
}

canonical_decompiled_code:
const char *func8()
{
_DWORD *v0; // rbx
const char *result; // rax
int v2; // edx
char v3[10]; // [rsp+6h] [rbp-12h] BYREF

v0 = malloc(0x18uLL);
strcpy(&v3[6], "Jan");
strcpy(v3, "Novak");
*(_QWORD *)v0 = &v3[6];
*((_QWORD *)v0 + 1) = v3;
v0[4] = 45;
func10(v0);
result = "age should be increased to 46";
if ( v0[4] == 46 )
{
if ( !strcmp(*(const char **)v0, "JAN") )
{
v2 = strcmp(*((const char **)v0 + 1), "NOVAK");
result = "surname should be uppercase";
if ( !v2 )
{
free(v0);
result = 0LL;
}
}
else
{
result = "surname should be uppercase" + 3;
}
}
return result;
}

original_code:
static char * test_convert() {
    Person* person = malloc(sizeof(Person));
    char name[] = "Jan";
    char surname[] = "Novak";
    person->name = name;
    person->surname = surname;
    person->age = 45;
    convert(person);
    do { if (!((46==person->age))) return "age should be increased to 46"; } while (0);
    do { if (!(!strcmp(person->name,"JAN"))) return "name should be uppercase"; } while (0);
    do { if (!(!strcmp(person->surname,"NOVAK"))) return "surname should be uppercase"; } while (0);
    free(person);
    return 0;
}

canonical_original_code:
static char *test_convert() {
    struct Person *person = malloc(sizeof(Person));
    char name[] = "Jan";
    char surname[] = "Novak";
    person->name = name;
    person->surname = surname;
    person->age = 45;
    convert(person);
    do { if (!((46==person->age))) return "age should be increased to 46"; } while (0);
    do { if (!(!strcmp(person->name,"JAN"))) return "name should be uppercase"; } while (0);
    do { if (!(!strcmp(person->surname,"NOVAK"))) return "surname should be uppercase"; } while (0);
    free(person);
    return 0;
}

variable_types: struct Person { char *name; char *surname; int age; } *

variable_types:
name
char []

variable_types:
surname
char []

return_type: char *


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

result = test_convert();
v1 = tests_run;
if ( result )
{
++tests_run;
}
else
{
result = (const char *)test_name();
tests_run = v1 + 2;
}
return result;
}

canonical_decompiled_code:
const char *func9()
{
const char *result; // rax
int v1; // ebx

result = func8();
v1 = tests_run;
if ( result )
{
++tests_run;
}
else
{
result = (const char *)func7();
tests_run = v1 + 2;
}
return result;
}

original_code:
static char * all_tests() {
    do { char *message = test_convert(); tests_run++; if (message) return message; } while (0);
    do { char *message = test_name(); tests_run++; if (message) return message; } while (0);
    return 0;
}

canonical_original_code:
static char *all_tests() {
    do { char *message = test_convert(); tests_run++; if (message) return message; } while (0);
    do { char *message = test_name(); tests_run++; if (message) return message; } while (0);
    return 0;
}

variable_types:
message
char *


convert

decompiled_code:
size_t __fastcall convert(__int64 a1)
{
unsigned int i; // ebp
const char *v2; // rbx
unsigned int j; // ebp
const char *v4; // rbx
size_t result; // rax

for ( i = 0; ; ++i )
{
v2 = *(const char **)a1;
if ( i >= strlen(*(const char **)a1) )
break;
v2[i] = (*__ctype_toupper_loc())[v2[i]];
}
for ( j = 0; ; ++j )
{
v4 = *(const char **)(a1 + 8);
result = strlen(v4);
if ( j >= result )
break;
v4[j] = (*__ctype_toupper_loc())[v4[j]];
}
++*(_DWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(__int64 a1)
{
unsigned int i; // ebp
const char *v2; // rbx
unsigned int j; // ebp
const char *v4; // rbx
size_t result; // rax

for ( i = 0; ; ++i )
{
v2 = *(const char **)a1;
if ( i >= strlen(*(const char **)a1) )
break;
v2[i] = (*__ctype_toupper_loc())[v2[i]];
}
for ( j = 0; ; ++j )
{
v4 = *(const char **)(a1 + 8);
result = strlen(v4);
if ( j >= result )
break;
v4[j] = (*__ctype_toupper_loc())[v4[j]];
}
++*(_DWORD *)(a1 + 16);
return result;
}

original_code:
void convert(Person * person) {
   unsigned int i;
   for (i=0; i<strlen(person->name); i ++) {
       person->name[i] = toupper(person->name[i]);
   }
   for (i=0; i<strlen(person->surname); i ++) {
       person->surname[i] = toupper(person->surname[i]);
   }
   person->age ++;
}

canonical_original_code:
void convert(struct Person *person) {
   unsigned int i;
   for (i=0; i<strlen(person->name); i ++) {
       person->name[i] = toupper(person->name[i]);
   }
   for (i=0; i<strlen(person->surname); i ++) {
       person->surname[i] = toupper(person->surname[i]);
   }
   person->age ++;
}

variable_types:
i
unsigned int

user_defined_types: struct Person { char *name; char *surname; int age; }


decompiled_code:
__int64 test_name()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
static char * test_name() {
    Person* person = malloc(sizeof(Person));
    person->name = "";
    person->surname = "Topinka";
    do { if (!(!strcmp(person->name, ""))) return "name should be empty"; } while (0);
    do { if (!(!strcmp(person->surname, "Topinka"))) return "surname should be Topinka"; } while (0);
    free(person);
    return 0;
}

canonical_original_code:
static char *test_name() {
    struct Person *person = malloc(sizeof(Person));
    person->name = "";
    person->surname = "Topinka";
    do { if (!(!strcmp(person->name, ""))) return "name should be empty"; } while (0);
    do { if (!(!strcmp(person->surname, "Topinka"))) return "surname should be Topinka"; } while (0);
    free(person);
    return 0;
}


main

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

v3 = all_tests();
if ( v3 )
{
puts("THERE ARE TEST FAILURES:");
puts(v3);
}
else
{
puts("ALL TESTS PASSED");
}
printf("Tests run: %d\n", (unsigned int)tests_run);
return v3 != 0LL;
}

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

v3 = func9();
if ( v3 )
{
puts("THERE ARE TEST FAILURES:");
puts(v3);
}
else
{
puts("ALL TESTS PASSED");
}
printf("Tests run: %d\n", (unsigned int)tests_run);
return v3 != 0LL;
}

original_code:
int main(int argc, char **argv) {
    char *result = all_tests();
    if (result != 0) {
        printf("THERE ARE TEST FAILURES:\n");
        printf("%s\n", result);
    }
    else {
        printf("ALL TESTS PASSED\n");
    }
    printf("Tests run: %d\n", tests_run);
    return result != 0;
}

variable_types:
argv
char **

variable_types:
result
char *


decompiled_code:
void __fastcall increment_age(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
}

original_code:
void increment_age(Person *person) {
    person->age++;
}

canonical_original_code:
void increment_age(struct Person *person) {
    person->age++;
}


setup

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

result = malloc(0x18uLL);
employee = result;
*result = "Arnost";
result[1] = "Topinka";
*((_DWORD *)result + 4) = 42;
return result;
}

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

result = malloc(0x18uLL);
employee = result;
*result = "Arnost";
result[1] = "Topinka";
*((_DWORD *)result + 4) = 42;
return result;
}

original_code:
void setup() {
    employee = malloc(sizeof(Person));
    employee->name = "Arnost";
    employee->surname = "Topinka";
    employee->age = 42;
}


teardown

decompiled_code:
void teardown()
{
free(employee);
}

canonical_decompiled_code:
void func3()
{
free(employee);
}

original_code:
void teardown() {
    free(employee);
}

canonical_original_code:
void teardown() {
    free(employee);
}


decompiled_code:
void test_age()
{
tcase_fn_start("test_age", "main.c", 49LL);
setup();
increment_age((__int64)employee);
if ( *((_DWORD *)employee + 4) == 43 )
{
mark_point("main.c", 52LL);
teardown();
}
else
{
ck_assert_failed("main.c", 52LL, "Assertion 'employee->age == 43' failed", "Incorrect age.", 0LL);
make_suite();
}
}

canonical_decompiled_code:
void func5()
{
tcase_fn_start("test_age", "main.c", 49LL);
func2();
func0((__int64)employee);
if ( *((_DWORD *)employee + 4) == 43 )
{
mark_point("main.c", 52LL);
func3();
}
else
{
ck_assert_failed("main.c", 52LL, "Assertion 'employee->age == 43' failed", "Incorrect age.", 0LL);
func6();
}
}

original_code:
static void test_age (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_age", "main.c", 49); {
    setup();
    increment_age(employee);
    (employee->age == 43) ? _mark_point("main.c", 52) : _ck_assert_failed("main.c", 52, "Assertion '""employee->age == 43""' failed" , "Incorrect age.", ((void *)0));
    teardown();
}
}

canonical_original_code:
static void test_age(int _i){ tcase_fn_start ("""test_age", "main.c", 49); {
    setup();
    increment_age(employee);
    (employee->age == 43) ? _mark_point("main.c", 52) : _ck_assert_failed("main.c", 52, "Assertion '""employee->age == 43""' failed" , "Incorrect age.", ((void *)0));
    teardown();
}
}


decompiled_code:
void test_name()
{
tcase_fn_start("test_name", "main.c", 57LL);
setup();
rename_person(employee, (__int64)"Franta");
if ( !strcmp(*(const char **)employee, "Franta") )
{
mark_point("main.c", 60LL);
teardown();
}
else
{
ck_assert_failed(
"main.c",
60LL,
"Assertion '!strcmp( employee->name, \"Franta\")' failed",
"Employee should be renamed.",
0LL);
test_age();
}
}

canonical_decompiled_code:
void func4()
{
tcase_fn_start("test_name", "main.c", 57LL);
func2();
func1(employee, (__int64)"Franta");
if ( !strcmp(*(const char **)employee, "Franta") )
{
mark_point("main.c", 60LL);
func3();
}
else
{
ck_assert_failed(
"main.c",
60LL,
"Assertion '!strcmp( employee->name, \"Franta\")' failed",
"Employee should be renamed.",
0LL);
func5();
}
}

original_code:
static void test_name (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_name", "main.c", 57); {
    setup();
    rename_person(employee, "Franta");
    (!strcmp( employee->name, "Franta")) ? _mark_point("main.c", 60) : _ck_assert_failed("main.c", 60, "Assertion '""!strcmp( employee->name, \"Franta\")""' failed" , "Employee should be renamed.", ((void *)0));
    teardown();
}
}

canonical_original_code:
static void test_name(int _i){ tcase_fn_start ("""test_name", "main.c", 57); {
    setup();
    rename_person(employee, "Franta");
    (!strcmp( employee->name, "Franta")) ? _mark_point("main.c", 60) : _ck_assert_failed("main.c", 60, "Assertion '""!strcmp( employee->name, \"Franta\")""' failed" , "Employee should be renamed.", ((void *)0));
    teardown();
}
}


repo: germ/dasm-dvm

decompiled_code:
char __fastcall get_inst(unsigned __int8 a1)
{
return a1 >> 5;
}

canonical_decompiled_code:
char __fastcall func7(unsigned __int8 a1)
{
return a1 >> 5;
}

original_code:
unsigned char get_inst(unsigned char c) {
  return c >> 5;
}

variable_types:
c
unsigned char

return_type: unsigned char


decompiled_code:
_BOOL8 __fastcall get_reg(char a1)
{
return (a1 & 0x10) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(char a1)
{
return (a1 & 0x10) != 0;
}

original_code:
unsigned char get_reg (unsigned char c) {
  return c = (c >> 4) & 0x01;
}

canonical_original_code:
unsigned char get_reg(unsigned char c) {
  return c = (c >> 4) & 0x01;
}


decompiled_code:
__int64 __fastcall get_loc(char a1)
{
return a1 & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
return a1 & 0xF;
}

original_code:
unsigned char get_loc (unsigned char c) {
  return c & 0x0F;
}

canonical_original_code:
unsigned char get_loc(unsigned char c) {
  return c & 0x0F;
}


decompiled_code:
__int64 __fastcall get_bit(int a1, char a2)
{
return a1 & (unsigned int)(1 << a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char a2)
{
return a1 & (unsigned int)(1 << a2);
}

original_code:
unsigned char get_bit (unsigned char c, unsigned char b) {
  return c & (1 << b);
}

canonical_original_code:
unsigned char get_bit(unsigned char c, unsigned char b) {
  return c & (1 << b);
}

variable_types:
b
unsigned char


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
printf("ERROR: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(const char *a1)
{
printf("ERROR: %s\n", a1);
exit(1);
}

original_code:
void error(char* msg) {
  printf("ERROR: %s\n", msg);
  exit(1);
}

canonical_original_code:
void error(char *msg) {
  printf("ERROR: %s\n", msg);
  exit(1);
}

variable_types:
msg
char *


decompiled_code:
int __fastcall print_state(unsigned __int8 *a1, unsigned __int8 *a2, unsigned __int8 **a3, _QWORD *a4)
{
__int64 i; // rbx

printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", **a3, (*a3)[1]);
printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n", *a2, *a1);
printf("Memory\n\t");
for ( i = 0LL; ; ++i )
{
if ( (_DWORD)i == 8 )
{
printf("\n\t");
printf("%.2X ", *(unsigned __int8 *)(*a4 + i));
continue;
}
printf("%.2X ", *(unsigned __int8 *)(*a4 + i));
if ( (int)i + 1 > 15 )
break;
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int8 *a1, unsigned __int8 *a2, unsigned __int8 **a3, _QWORD *a4)
{
__int64 i; // rbx

printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", **a3, (*a3)[1]);
printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n", *a2, *a1);
printf("Memory\n\t");
for ( i = 0LL; ; ++i )
{
if ( (_DWORD)i == 8 )
{
printf("\n\t");
printf("%.2X ", *(unsigned __int8 *)(*a4 + i));
continue;
}
printf("%.2X ", *(unsigned __int8 *)(*a4 + i));
if ( (int)i + 1 > 15 )
break;
}
return putchar(10);
}

original_code:
void print_state(unsigned char* ip, unsigned char* ir, unsigned char** reg, unsigned char** mem) {
  int i;
  printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", (*reg)[0], (*reg)[1]);
  printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n",*ir, *ip);
  printf("Memory\n\t");
  for (i = 0; i < 16; i++) {
    if (i == 8) printf("\n\t");
    printf("%.2X ", (*mem)[i]);
  }
  printf("\n");
  return;
}

canonical_original_code:
void print_state(unsigned char *ip, unsigned char *ir, unsigned char **reg, unsigned char **mem) {
  int i;
  printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", (*reg)[0], (*reg)[1]);
  printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n",*ir, *ip);
  printf("Memory\n\t");
  for (i = 0; i < 16; i++) {
    if (i == 8) printf("\n\t");
    printf("%.2X ", (*mem)[i]);
  }
  printf("\n");
  return;
}

variable_types:
ip
unsigned char *

variable_types:
ir
unsigned char *

variable_types:
reg
unsigned char **

variable_types:
mem
unsigned char **

variable_types: i int


canonical_original_code:
unsigned char get_inst(unsigned char c) {
  return c >> 5;
}


decompiled_code:
void __fastcall __noreturn asm_error(unsigned int a1)
{
printf("Could not parse at line %d, Exiting\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(unsigned int a1)
{
printf("Could not parse at line %d, Exiting\n", a1);
exit(1);
}

original_code:
void asm_error(int line) {
  printf("Could not parse at line %d, Exiting\n", line);
  exit(1);
}

variable_types: line int


repo: gertjanvanzwieten/halfspace

decompiled_code:
__int64 __fastcall get_displacements(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, double a5)
{
__int64 v5; // rbx
__int64 v7; // r15
__int64 v8; // rdx
__int64 result; // rax
__int64 v10; // [rsp+0h] [rbp-58h] BYREF

if ( a4 )
{
v5 = a1;
v7 = a1 + 24LL * a4;
do
{
v8 = a3;
a3 += 24LL;
get_displacement(&v10, a2, v8, a5);
v5 += 24LL;
result = Vector_copy();
}
while ( v5 != v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, double a5)
{
__int64 v5; // rbx
__int64 v7; // r15
__int64 v8; // rdx
__int64 result; // rax
__int64 v10; // [rsp+0h] [rbp-58h] BYREF

if ( a4 )
{
v5 = a1;
v7 = a1 + 24LL * a4;
do
{
v8 = a3;
a3 += 24LL;
get_displacement(&v10, a2, v8, a5);
v5 += 24LL;
result = Vector_copy();
}
while ( v5 != v7 );
}
return result;
}

original_code:
void get_displacements( Vector *out, SourceParams *params, Vector *where, double poisson, int count ) {
  while ( count-- ) Vector_copy( out++, get_displacement(params,where++,poisson) );
}

canonical_original_code:
void get_displacements(struct Vector *out, struct SourceParams *params, struct Vector *where, double poisson, int count) {
  while ( count-- ) Vector_copy( out++, get_displacement(params,where++,poisson) );
}

variable_types:
out
struct Vector { double x; } *

variable_types: struct SourceParams { double strike; double dip; double length; double width; double xbottom; double strikeslip; } *

variable_types:
where
struct Vector *

variable_types: poisson double

variable_types: count int


decompiled_code:
__int64 __fastcall get_gradients(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, double a5)
{
__int64 v5; // rbx
__int64 v7; // r15
__int64 v8; // rdx
__int64 result; // rax
__int64 v10; // [rsp+0h] [rbp-88h] BYREF

if ( a4 )
{
v5 = a1;
v7 = a1 + 72LL * a4;
do
{
v8 = a3;
a3 += 24LL;
get_gradient(&v10, a2, v8, a5);
v5 += 72LL;
result = Matrix_copy();
}
while ( v5 != v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, double a5)
{
__int64 v5; // rbx
__int64 v7; // r15
__int64 v8; // rdx
__int64 result; // rax
__int64 v10; // [rsp+0h] [rbp-88h] BYREF

if ( a4 )
{
v5 = a1;
v7 = a1 + 72LL * a4;
do
{
v8 = a3;
a3 += 24LL;
get_gradient(&v10, a2, v8, a5);
v5 += 72LL;
result = Matrix_copy();
}
while ( v5 != v7 );
}
return result;
}

original_code:
void get_gradients( Matrix *out, SourceParams *params, Vector *where, double poisson, int count ) {
  while ( count-- ) Matrix_copy( out++, get_gradient(params,where++,poisson) );
}

canonical_original_code:
void get_gradients(struct Matrix *out, struct SourceParams *params, struct Vector *where, double poisson, int count) {
  while ( count-- ) Matrix_copy( out++, get_gradient(params,where++,poisson) );
}

variable_types: struct Matrix { struct Vector { double x; } x; } *

user_defined_types: struct SourceParams { double strike; double dip; double length; double width; double xbottom; double strikeslip; }


isEditingEditor

repo: getreu/grpn

decompiled_code:
_BOOL8 isEditingEditor()
{
return Eend != &Ebuf;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return Eend != &Ebuf;
}

original_code:
int isEditingEditor() {
    return (Ebuf != Eend);
}


cursorPosEditor

decompiled_code:
signed __int64 cursorPosEditor()
{
return Epos - &Ebuf;
}

canonical_decompiled_code:
signed __int64 func1()
{
return Epos - &Ebuf;
}

original_code:
int cursorPosEditor() {
    return (int)(Epos-Ebuf);
}


setCursorPosEditor

decompiled_code:
char *__fastcall setCursorPosEditor(int a1)
{
char *result; // rax
signed __int64 v2; // rcx
char *v3; // rdi

if ( a1 < 0 )
{
Epos = Ebuf;
}
else
{
result = Eend;
v2 = a1;
v3 = &Ebuf[a1];
if ( v2 > Eend - Ebuf )
v3 = Eend;
Epos = v3;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax
signed __int64 v2; // rcx
char *v3; // rdi

if ( a1 < 0 )
{
Epos = Ebuf;
}
else
{
result = Eend;
v2 = a1;
v3 = &Ebuf[a1];
if ( v2 > Eend - Ebuf )
v3 = Eend;
Epos = v3;
}
return result;
}

original_code:
void setCursorPosEditor(int pos) {
    if (pos < 0) {
 Epos = Ebuf;
    } else if (pos > Eend-Ebuf) {
 Epos = Eend;
    } else {
 Epos = Ebuf + pos;
    }
}

variable_types: pos int


getPrevEditor

decompiled_code:
__int64 getPrevEditor()
{
__int64 result; // rax

result = 0LL;
if ( Epos >= &Ebuf[1] )
result = (unsigned __int8)*(Epos - 1);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

result = 0LL;
if ( Epos >= &Ebuf[1] )
result = (unsigned __int8)*(Epos - 1);
return result;
}

original_code:
char getPrevEditor() {
    if (Epos < Ebuf+1)
 return '\0';
    return *(Epos-1);
}

return_type: char


getLineEditor

decompiled_code:
char *getLineEditor()
{
*Eend = 0;
return Ebuf;
}

canonical_decompiled_code:
char *func4()
{
*Eend = 0;
return Ebuf;
}

original_code:
char * getLineEditor() {
    *Eend = '\0';
    return Ebuf;
}

canonical_original_code:
char *getLineEditor() {
    *Eend = '\0';
    return Ebuf;
}


finishEditor

decompiled_code:
char *finishEditor()
{
char *result; // rax

result = Eend;
if ( Eend > Ebuf )
{
*Eend = 0;
result = (char *)readLine(Ebuf);
}
Eend = Ebuf;
Epos = Ebuf;
return result;
}

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

result = Eend;
if ( Eend > Ebuf )
{
*Eend = 0;
result = (char *)readLine(Ebuf);
}
Eend = Ebuf;
Epos = Ebuf;
return result;
}

original_code:
void finishEditor() {
    if (Eend > Ebuf) {
 *Eend = '\0';
 readLine(Ebuf);
    }
    Epos = Eend = Ebuf;
}


insertEditor

decompiled_code:
char *__fastcall insertEditor(char a1)
{
char *v1; // rax
char *i; // rdx
char *result; // rax
char *v4; // rdx

v1 = Eend;
for ( i = Epos; Epos <= v1; i = Epos )
{
v1[1] = *v1;
--v1;
}
*i = a1;
result = Epos + 1;
v4 = Eend + 1;
if ( Eend + 1 >= &Ebuf[1022] )
v4 = (char *)(unsigned int)((_DWORD)Ebuf + 1022);
Eend = v4;
if ( (unsigned __int64)result >= (unsigned int)((_DWORD)Ebuf + 1022) )
result = (char *)(unsigned int)((_DWORD)Ebuf + 1021);
Epos = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(char a1)
{
char *v1; // rax
char *i; // rdx
char *result; // rax
char *v4; // rdx

v1 = Eend;
for ( i = Epos; Epos <= v1; i = Epos )
{
v1[1] = *v1;
--v1;
}
*i = a1;
result = Epos + 1;
v4 = Eend + 1;
if ( Eend + 1 >= &Ebuf[1022] )
v4 = (char *)(unsigned int)((_DWORD)Ebuf + 1022);
Eend = v4;
if ( (unsigned __int64)result >= (unsigned int)((_DWORD)Ebuf + 1022) )
result = (char *)(unsigned int)((_DWORD)Ebuf + 1021);
Epos = result;
return result;
}

original_code:
void insertEditor(char c) {
    char *p;
    for (p = Eend; p >= Epos; p--)
 *(p+1) = *p;
    *Epos = c;
    Epos++;
    Eend++;
    if (Eend >= Ebuf + 1024 - 2)
 Eend = Ebuf + 1024 - 2;
    if (Epos >= Ebuf + 1024 - 2)
 Epos = Ebuf + 1024 - 3;
}

variable_types: c char

variable_types:
p
char *


deleteEditor

decompiled_code:
char *deleteEditor()
{
char *result; // rax
char *v1; // rdx

result = Epos;
if ( Epos != Ebuf )
{
v1 = Eend;
if ( Epos < Eend )
{
do
{
*(result - 1) = *result;
++result;
v1 = Eend;
}
while ( Eend > result );
}
--Epos;
Eend = v1 - 1;
}
return result;
}

canonical_decompiled_code:
char *func7()
{
char *result; // rax
char *v1; // rdx

result = Epos;
if ( Epos != Ebuf )
{
v1 = Eend;
if ( Epos < Eend )
{
do
{
*(result - 1) = *result;
++result;
v1 = Eend;
}
while ( Eend > result );
}
--Epos;
Eend = v1 - 1;
}
return result;
}

original_code:
void deleteEditor(){
    char *p;
    if (Epos == Ebuf)
 return;
    for (p = Epos; p < Eend; p++)
 *(p-1) = *p;
    Epos--;
    Eend--;
}


homeEditor

decompiled_code:
void homeEditor()
{
Epos = Ebuf;
}

canonical_decompiled_code:
void func8()
{
Epos = Ebuf;
}

original_code:
void homeEditor(){
    Epos = Ebuf;
}

canonical_original_code:
void homeEditor(){
    Epos = Ebuf;
}


endEditor

decompiled_code:
char *endEditor()
{
char *result; // rax

result = Eend;
Epos = Eend;
return result;
}

canonical_decompiled_code:
char *func9()
{
char *result; // rax

result = Eend;
Epos = Eend;
return result;
}

original_code:
void endEditor() {
    Epos = Eend;
}

canonical_original_code:
void endEditor() {
    Epos = Eend;
}


rightEditor

decompiled_code:
char *rightEditor()
{
char *result; // rax

result = Epos + 1;
if ( Epos + 1 > Eend )
result = Eend;
Epos = result;
return result;
}

canonical_decompiled_code:
char *func10()
{
char *result; // rax

result = Epos + 1;
if ( Epos + 1 > Eend )
result = Eend;
Epos = result;
return result;
}

original_code:
void rightEditor() {
    Epos++;
    if (Epos > Eend)
 Epos = Eend;
}


leftEditor

decompiled_code:
char *leftEditor()
{
char *result; // rax

result = Epos - 1;
if ( Epos - 1 < Ebuf )
result = Ebuf;
Epos = result;
return result;
}

canonical_decompiled_code:
char *func11()
{
char *result; // rax

result = Epos - 1;
if ( Epos - 1 < Ebuf )
result = Ebuf;
Epos = result;
return result;
}

original_code:
void leftEditor() {
    Epos--;
    if (Epos < Ebuf)
 Epos = Ebuf;
}


cancelEditor

decompiled_code:
void cancelEditor()
{
Epos = Ebuf;
Eend = Ebuf;
Ebuf[0] = 0;
}

canonical_decompiled_code:
void func12()
{
Epos = Ebuf;
Eend = Ebuf;
Ebuf[0] = 0;
}

original_code:
void cancelEditor() {
    Eend = Epos = Ebuf;
    *Ebuf = '\0';
}


initUndoSystem

decompiled_code:
unsigned __int64 initUndoSystem()
{
__int64 *v0; // rbx
unsigned __int64 result; // rax

if ( initialized_0 )
{
v0 = (__int64 *)undoStacks;
do
{
clearNamedStack(v0);
v0 += 2;
}
while ( v0 != (__int64 *)(unsigned int)((_DWORD)undoStacks + 160) );
}
initialized_0 = 1;
for ( result = 0LL; result != 10; ++result )
{
nSavedItems[result] = 0;
nUndoItems[result] = 0;
*(_QWORD *)&undoStacks[result * 4 + 2] = 0LL;
undoStacks[result * 4] = 0;
}
ringIndx = 0;
undoLevel = 0;
return result * 4;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
__int64 *v0; // rbx
unsigned __int64 result; // rax

if ( initialized_0 )
{
v0 = (__int64 *)undoStacks;
do
{
clearNamedStack(v0);
v0 += 2;
}
while ( v0 != (__int64 *)(unsigned int)((_DWORD)undoStacks + 160) );
}
initialized_0 = 1;
for ( result = 0LL; result != 10; ++result )
{
nSavedItems[result] = 0;
nUndoItems[result] = 0;
*(_QWORD *)&undoStacks[result * 4 + 2] = 0LL;
undoStacks[result * 4] = 0;
}
ringIndx = 0;
undoLevel = 0;
return result * 4;
}

original_code:
void initUndoSystem()
{
    int i;
    static int initialized = 0;
    if (initialized != 0) {
 for (i = 0; i < 10; i++) {
     clearNamedStack(&(undoStacks[i]));
 }
    }
    initialized = 1;
    for (i = 0; i < 10; i++) {
 nSavedItems[i] = 0;
 nUndoItems[i] = 0;
 undoStacks[i].head = ((void *)0);
 undoStacks[i].length = 0;
    }
    ringIndx = 0;
    undoLevel = 0;
}

variable_types: initialized int


UndoStack

decompiled_code:
__int64 UndoStack()
{
int v0; // eax
int v1; // edx
int v2; // ebx
__int64 v3; // rax
unsigned int v4; // ebx
__int64 v5; // rax
__int64 result; // rax

if ( !undoLevel )
return setStringError("Undo Error: Nothing to Undo.");
v0 = ringIndx - 1;
if ( ringIndx - 1 < 0 )
v0 = 9;
ringIndx = v0;
v1 = undoLevel - 1;
if ( undoLevel - 1 <= 0 )
v1 = 0;
undoLevel = v1;
if ( nUndoItems[v0] > 0 )
{
v2 = 0;
do
{
v3 = Pop();
freeNumber(v3);
++v2;
v0 = ringIndx;
}
while ( nUndoItems[ringIndx] > v2 );
}
v4 = nSavedItems[v0];
v5 = getStack();
copyStack(&undoStacks[4 * ringIndx], v5, v4);
clearNamedStack(&undoStacks[4 * ringIndx]);
result = ringIndx;
nSavedItems[ringIndx] = 0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // edx
int v2; // ebx
__int64 v3; // rax
unsigned int v4; // ebx
__int64 v5; // rax
__int64 result; // rax

if ( !undoLevel )
return setStringError("Undo Error: Nothing to Undo.");
v0 = ringIndx - 1;
if ( ringIndx - 1 < 0 )
v0 = 9;
ringIndx = v0;
v1 = undoLevel - 1;
if ( undoLevel - 1 <= 0 )
v1 = 0;
undoLevel = v1;
if ( nUndoItems[v0] > 0 )
{
v2 = 0;
do
{
v3 = Pop();
freeNumber(v3);
++v2;
v0 = ringIndx;
}
while ( nUndoItems[ringIndx] > v2 );
}
v4 = nSavedItems[v0];
v5 = getStack();
copyStack(&undoStacks[4 * ringIndx], v5, v4);
clearNamedStack(&undoStacks[4 * ringIndx]);
result = ringIndx;
nSavedItems[ringIndx] = 0;
return result;
}

original_code:
void UndoStack() {
    int i;
    if (undoLevel == 0) {
 setStringError("Undo Error: Nothing to Undo.");
 return;
    }
    ringIndx--;
    if (ringIndx < 0)
 ringIndx = 10 - 1;
    undoLevel--;
    if (undoLevel <= 0)
 undoLevel = 0;
    for (i = 0; i < nUndoItems[ringIndx]; i++) {
 freeNumber(Pop());
    }
    copyStack(&(undoStacks[ringIndx]), getStack(), nSavedItems[ringIndx]);
    clearNamedStack(&(undoStacks[ringIndx]));
    nSavedItems[ringIndx] = 0;
}


CancelStackState

decompiled_code:
__int64 CancelStackState()
{
__int64 v0; // rdi

v0 = ringIndx;
nSavedItems[ringIndx] = 0;
return clearNamedStack(&undoStacks[4 * v0]);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdi

v0 = ringIndx;
nSavedItems[ringIndx] = 0;
return clearNamedStack(&undoStacks[4 * v0]);
}

original_code:
void CancelStackState()
{
    nSavedItems[ringIndx] = 0;
    clearNamedStack(&(undoStacks[ringIndx]));
}


SaveStackState

decompiled_code:
__int64 __fastcall SaveStackState(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( undoLevel > 9 )
clearNamedStack(&undoStacks[4 * ringIndx]);
v1 = ringIndx;
nSavedItems[ringIndx] = a1;
v2 = getStack();
return copyStack(v2, &undoStacks[4 * v1], a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( undoLevel > 9 )
clearNamedStack(&undoStacks[4 * ringIndx]);
v1 = ringIndx;
nSavedItems[ringIndx] = a1;
v2 = getStack();
return copyStack(v2, &undoStacks[4 * v1], a1);
}

original_code:
void SaveStackState(int args)
{
    if (undoLevel >= 10) {
 clearNamedStack(&(undoStacks[ringIndx]));
    }
    nSavedItems[ringIndx] = args;
    copyStack(getStack(), &(undoStacks[ringIndx]), args);
}

variable_types: args int


AddStackState

decompiled_code:
__int64 __fastcall AddStackState(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rax

v1 = ringIndx;
nSavedItems[ringIndx] += a1;
v2 = getStack();
return copyStack(v2, &undoStacks[4 * v1], a1);
}

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

v1 = ringIndx;
nSavedItems[ringIndx] += a1;
v2 = getStack();
return copyStack(v2, &undoStacks[4 * v1], a1);
}

original_code:
void AddStackState(int args)
{
    nSavedItems[ringIndx] += args;
    copyStack(getStack(), &(undoStacks[ringIndx]), args);
}


UndoStackState

decompiled_code:
__int64 __fastcall UndoStackState(int a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax

v1 = ringIndx;
nUndoItems[ringIndx] = a1;
v2 = undoLevel + 1;
if ( undoLevel + 1 > 9 )
v2 = 10;
undoLevel = v2;
result = (unsigned int)(v1 + 1);
if ( (int)result > 9 )
result = 0LL;
ringIndx = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax

v1 = ringIndx;
nUndoItems[ringIndx] = a1;
v2 = undoLevel + 1;
if ( undoLevel + 1 > 9 )
v2 = 10;
undoLevel = v2;
result = (unsigned int)(v1 + 1);
if ( (int)result > 9 )
result = 0LL;
ringIndx = result;
return result;
}

original_code:
void UndoStackState(int args)
{
    nUndoItems[ringIndx] = args;
    undoLevel++;
    if (undoLevel >= 10)
 undoLevel = 10;
    ringIndx++;
    if (ringIndx >= 10)
 ringIndx = 0;
}


getStack

decompiled_code:
int *getStack()
{
return &stack;
}

canonical_decompiled_code:
int *func0()
{
return &stack;
}

original_code:
struct Stack *getStack() {
    return &stack;
}

return_type: struct Stack { int length; struct StackElem { struct StackElem *t; struct StackElem *b; struct _Number { int refCnt; int type; void *data; } *data; } *head; } *

user_defined_types: struct Stack { int length; struct StackElem *head; }

user_defined_types: struct StackElem { struct StackElem *t; struct StackElem *b; struct _Number *data; }


stackLen

decompiled_code:
__int64 stackLen()
{
return (unsigned int)stack;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)stack;
}

original_code:
int stackLen() {
    return stack.length;
}

canonical_original_code:
int stackLen() {
    return stack.length;
}


newStackChunk

decompiled_code:
_DWORD *newStackChunk()
{
_DWORD *v0; // rax
_DWORD *v1; // rsi
_DWORD *v2; // rax
_QWORD *v3; // rdx

v0 = calloc(0x290uLL, 1uLL);
if ( !v0 )
{
perror("Malloc");
exit(0);
}
v1 = v0;
*v0 = 19;
v2 = v0 + 44;
v3 = v1 + 2;
do
{
*v3 = v2;
*((_QWORD *)v2 + 2) = 0LL;
v2 += 6;
++v3;
}
while ( v2 != v1 + 164 );
return v1;
}

original_code:
struct StackChunk * newStackChunk()
{
    int i;
    struct StackChunk *c;
    c = calloc(sizeof(*c), 1);
    if (c == ((void *)0)) {
 perror("Malloc");
 exit(0);
    }
    c->freeIndx = 20 - 1;
    for (i = 0; i < 20; i++) {
 c->freeList[i] = &((c->ary)[i]);
 c->ary[i].data = ((void *)0);
    }
    return c;
}

canonical_original_code:
struct StackChunk *newStackChunk()
{
    int i;
    struct StackChunk *c;
    c = calloc(sizeof(*c), 1);
    if (c == ((void *)0)) {
 perror("Malloc");
 exit(0);
    }
    c->freeIndx = 20 - 1;
    for (i = 0; i < 20; i++) {
 c->freeList[i] = &((c->ary)[i]);
 c->ary[i].data = ((void *)0);
    }
    return c;
}

variable_types: struct StackChunk { int freeIndx; struct StackElem { struct StackElem *t; struct StackElem *b; struct _Number { int refCnt; int type; void *data; } *data; } *freeList[20]; struct StackChunk *next; struct StackElem ary[20]; } *

user_defined_types: struct StackChunk { int freeIndx; struct StackElem *freeList[20]; struct StackChunk *next; struct StackElem ary[20]; }


newStackEle

decompiled_code:
__int64 newStackEle()
{
__int64 v0; // rbx
int i; // eax
__int64 v2; // rbp
int v3; // eax

v0 = stackChunkHead;
for ( i = *(_DWORD *)stackChunkHead; *(_DWORD *)v0 == -1; i = *(_DWORD *)v0 )
v0 = *(_QWORD *)(v0 + 168);
v2 = *(_QWORD *)(v0 + 8LL * i + 8);
v3 = i - 1;
if ( v3 < 0 )
{
*(_DWORD *)v0 = -1;
if ( !*(_QWORD *)(v0 + 168) )
*(_QWORD *)(v0 + 168) = newStackChunk();
}
else
{
*(_DWORD *)v0 = v3;
}
return v2;
}

original_code:
struct StackElem * newStackEle() {
    struct StackElem *s;
    struct StackChunk *c;
    for (c = stackChunkHead; c->freeIndx == -1; c = c->next);
    s = c->freeList[c->freeIndx];
    c->freeIndx--;
    if (c->freeIndx < 0) {
 c->freeIndx = -1;
 if(c->next == ((void *)0))
     c->next = newStackChunk();
    }
    return s;
}

canonical_original_code:
struct StackElem *newStackEle() {
    struct StackElem *s;
    struct StackChunk *c;
    for (c = stackChunkHead; c->freeIndx == -1; c = c->next);
    s = c->freeList[c->freeIndx];
    c->freeIndx--;
    if (c->freeIndx < 0) {
 c->freeIndx = -1;
 if(c->next == ((void *)0))
     c->next = newStackChunk();
    }
    return s;
}

variable_types: struct StackElem { struct StackElem *t; struct StackElem *b; struct _Number { int refCnt; int type; void *data; } *data; } *


stackAddToFreeList

decompiled_code:
__int64 __fastcall stackAddToFreeList(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // ecx

for ( result = stackChunkHead; result; result = *(_QWORD *)(result + 168) )
{
if ( a1 >= result + 176 && a1 <= result + 656 )
{
v2 = (*(_DWORD *)result)++;
*(_QWORD *)(result + 8LL * (v2 + 1) + 8) = a1;
}
}
return result;
}

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

for ( result = stackChunkHead; result; result = *(_QWORD *)(result + 168) )
{
if ( a1 >= result + 176 && a1 <= result + 656 )
{
v2 = (*(_DWORD *)result)++;
*(_QWORD *)(result + 8LL * (v2 + 1) + 8) = a1;
}
}
return result;
}

original_code:
void stackAddToFreeList(struct StackElem *s)
{
    struct StackChunk *c;
    for (c = stackChunkHead; c != ((void *)0); c = c->next)
 if (s >= c->ary && s <= &((c->ary)[20]))
     c->freeList[++(c->freeIndx)] = s;
}

user_defined_types: struct _Number { int refCnt; int type; void *data; }


copyStack

decompiled_code:
__int64 __fastcall copyStack(__int64 a1, __int64 a2, int a3)
{
_QWORD *v4; // r12
int v5; // er13
_QWORD *v6; // rbx
__int64 result; // rax

v4 = *(_QWORD **)(a1 + 8);
if ( a3 > 0 && v4 )
{
v5 = 0;
do
{
v6 = (_QWORD *)newStackEle();
v6[2] = v4[2];
*v6 = *(_QWORD *)(a2 + 8);
v6[1] = 0LL;
incRefcntNumber();
if ( *v6 )
*(_QWORD *)(*v6 + 8LL) = v6;
*(_QWORD *)(a2 + 8) = v6;
++*(_DWORD *)a2;
++v5;
v4 = (_QWORD *)*v4;
}
while ( a3 > v5 && v4 );
}
else
{
v5 = 0;
}
result = 1LL;
if ( a3 != v5 )
{
fwrite("copyStack: Error copying stack.\n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
_QWORD *v4; // r12
int v5; // er13
_QWORD *v6; // rbx
__int64 result; // rax

v4 = *(_QWORD **)(a1 + 8);
if ( a3 > 0 && v4 )
{
v5 = 0;
do
{
v6 = (_QWORD *)func3();
v6[2] = v4[2];
*v6 = *(_QWORD *)(a2 + 8);
v6[1] = 0LL;
incRefcntNumber();
if ( *v6 )
*(_QWORD *)(*v6 + 8LL) = v6;
*(_QWORD *)(a2 + 8) = v6;
++*(_DWORD *)a2;
++v5;
v4 = (_QWORD *)*v4;
}
while ( a3 > v5 && v4 );
}
else
{
v5 = 0;
}
result = 1LL;
if ( a3 != v5 )
{
fwrite("copyStack: Error copying stack.\n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int copyStack(struct Stack *srcStack, struct Stack *dstStack, int nelts)
{
    int i;
    struct StackElem *dst, *src;
    for (i = 0, src = srcStack->head; i < nelts && src; i++, src = src->t) {
 dst = newStackEle();
 dst->data = src->data;
 dst->t = dstStack->head;
 dst->b = ((void *)0);
 incRefcntNumber(dst->data);
 if (dst->t)
     dst->t->b = dst;
 dstStack->head = dst;
 dstStack->length++;
    }
    if (i != nelts) {
 fprintf(stderr, "copyStack: Error copying stack.\n");
 return 0;
    }
    return 1;
}

canonical_original_code:
int copyStack(struct Stack *srcStack, struct Stack *dstStack, int nelts)
{
    int i;
    struct StackElem *dst; struct StackElem *src;
    for (i = 0, src = srcStack->head; i < nelts && src; i++, src = src->t) {
 dst = newStackEle();
 dst->data = src->data;
 dst->t = dstStack->head;
 dst->b = ((void *)0);
 incRefcntNumber(dst->data);
 if (dst->t)
     dst->t->b = dst;
 dstStack->head = dst;
 dstStack->length++;
    }
    if (i != nelts) {
 fprintf(stderr, "copyStack: Error copying stack.\n");
 return 0;
    }
    return 1;
}

variable_types: struct Stack { int length; struct StackElem { struct StackElem *t; struct StackElem *b; struct _Number { int refCnt; int type; void *data; } *data; } *head; } *

variable_types:
dstStack
struct Stack *

variable_types: nelts int


decompiled_code:
__int64 setup_stack()
{
*((_QWORD *)&stack + 1) = 0LL;
stack = 0;
stackChunkHead = (__int64)newStackChunk();
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
*((_QWORD *)&stack + 1) = 0LL;
stack = 0;
stackChunkHead = (__int64)func2();
return 1LL;
}

original_code:
int setup_stack()
{
    stack.head = ((void *)0);
    stack.length = 0;
    stackChunkHead = newStackChunk();
    return 1;
}


clearNamedStack

decompiled_code:
__int64 __fastcall clearNamedStack(__int64 a1)
{
_QWORD *i; // rbx
__int64 result; // rax

for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)*i )
{
decRefcntNumber(i[2]);
freeNumber(i[2]);
result = stackAddToFreeList((unsigned __int64)i);
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)a1 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_QWORD *i; // rbx
__int64 result; // rax

for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)*i )
{
decRefcntNumber(i[2]);
freeNumber(i[2]);
result = func4((unsigned __int64)i);
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)a1 = 0;
return result;
}

original_code:
void clearNamedStack(struct Stack *stk)
{
    struct StackElem *s;
    for (s = stk->head; s; s = s->t) {
 decRefcntNumber(s->data);
 freeNumber(s->data);
 stackAddToFreeList(s);
    }
    stk->head = ((void *)0);
    stk->length = 0;
}


clearStack

decompiled_code:
__int64 clearStack()
{
return clearNamedStack((__int64)&stack);
}

canonical_decompiled_code:
__int64 func8()
{
return func7((__int64)&stack);
}

original_code:
void clearStack() {
    clearNamedStack(&stack);
}


printStack

decompiled_code:
void printStack()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
char *v2; // rbp

v0 = (_QWORD *)*((_QWORD *)&stack + 1);
if ( v0 )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
}
while ( v0 );
do
{
v2 = (char *)printNumber(v1[2]);
puts(v2);
free(v2);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
}

canonical_decompiled_code:
void func9()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
char *v2; // rbp

v0 = (_QWORD *)*((_QWORD *)&stack + 1);
if ( v0 )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
}
while ( v0 );
do
{
v2 = (char *)printNumber(v1[2]);
puts(v2);
free(v2);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
}

original_code:
void printStack()
{
    char *c;
    struct StackElem *s = ((void *)0);
    struct StackElem *p = ((void *)0);
    for (s = stack.head; s; s = s->t)
 p = s;
    for (s = p; p; p = p->b) {
 c = printNumber(p->data);
 printf("%s\n", c);
 free(c);
    }
}

variable_types:
c
char *