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 *


repo: geolocationrhit/Senior-Design

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

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

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

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

return_type: 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]

return_type: void


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

v3 = 0;
buf = 67LL;
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-22h] BYREF
__int16 v3; // [rsp+Eh] [rbp-1Ah]

v3 = 0;
buf = 67LL;
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]

v3 = 0;
buf = 0LL;
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]

v3 = 0;
buf = 0LL;
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

return_type: float


addWaypoint

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

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

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

if ( numberOfWaypoints[0] > 99 )
return 0xFFFFFFFFLL;
v2 = (double *)((char *)&waypointList + 16 * numberOfWaypoints[0]++);
*v2 = a1;
v2[1] = a2;
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:
// attributes: thunk
__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:
void __fastcall distanceBetweenPoints(double a1, double a2, double a3, double a4)
{
double v4; // xmm3_8

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

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

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

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

return_type: 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 i; // rbx
__int64 v2; // rdx
__int64 v3; // rsi
__int64 buf; // [rsp+8h] [rbp-90h] BYREF
__int128 v6[6]; // [rsp+10h] [rbp-88h] BYREF
int v7; // [rsp+70h] [rbp-28h]

buf = 0xC94100003B0662B5LL;
if ( write(fd, &buf, 8uLL) != 8 )
fprintf(stderr, "Failed to set to continous mode: %m\n");
v7 = 0;
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
if ( read(fd, v6, 0x3EuLL) != 62 )
fprintf(stderr, "Failed to read compass: %m\n");
for ( i = 0LL; i != 62; ++i )
{
v2 = (unsigned int)*((char *)v6 + i);
v3 = (unsigned int)i;
printf("%d: %x\n\r", v3, v2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
__int64 i; // rbx
__int64 v2; // rdx
__int64 v3; // rsi
__int64 buf; // [rsp+8h] [rbp-90h] BYREF
__int128 v6[6]; // [rsp+10h] [rbp-88h] BYREF
int v7; // [rsp+70h] [rbp-28h]

buf = 0xC94100003B0662B5LL;
if ( write(fd, &buf, 8uLL) != 8 )
fprintf(stderr, "Failed to set to continous mode: %m\n");
v7 = 0;
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
if ( read(fd, v6, 0x3EuLL) != 62 )
fprintf(stderr, "Failed to read compass: %m\n");
for ( i = 0LL; i != 62; ++i )
{
v2 = (unsigned int)*((char *)v6 + i);
v3 = (unsigned int)i;
printf("%d: %x\n\r", v3, v2);
}
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 result; // rax
char v4[4]; // [rsp+8h] [rbp-40h] BYREF
char v5[4]; // [rsp+Ch] [rbp-3Ch] BYREF
int v6; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+14h] [rbp-34h] BYREF
int v8; // [rsp+1Ch] [rbp-2Ch]
__int64 v9[2]; // [rsp+20h] [rbp-28h] BYREF
int v10; // [rsp+30h] [rbp-18h]

v7 = 0x200003098LL;
v9[0] = 0x400003033LL;
v8 = 12344;
v9[1] = 0x400003040LL;
v10 = 12344;
v0 = eglGetDisplay(nativeDisplay);
eglDisplay = v0;
if ( v0 )
{
if ( (unsigned int)eglInitialize(v0, v4, v5) )
{
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, v9, &eglConfig, 1LL, &v6) || v6 != 1 )
handle_egl_error("eglChooseConfig");
eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, 0LL);
if ( !eglWindowSurface )
handle_egl_error("eglCreateWindowSurface");
eglContext = eglCreateContext(eglDisplay, eglConfig, 0LL, &v7);
if ( !eglContext )
handle_egl_error("eglCreateContext");
if ( !(unsigned int)eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, eglContext) )
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 result; // rax
char v4[4]; // [rsp+8h] [rbp-40h] BYREF
char v5[4]; // [rsp+Ch] [rbp-3Ch] BYREF
int v6; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+14h] [rbp-34h] BYREF
int v8; // [rsp+1Ch] [rbp-2Ch]
__int64 v9[2]; // [rsp+20h] [rbp-28h] BYREF
int v10; // [rsp+30h] [rbp-18h]

v7 = 0x200003098LL;
v9[0] = 0x400003033LL;
v8 = 12344;
v9[1] = 0x400003040LL;
v10 = 12344;
v0 = eglGetDisplay(nativeDisplay);
eglDisplay = v0;
if ( v0 )
{
if ( (unsigned int)eglInitialize(v0, v4, v5) )
{
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, v9, &eglConfig, 1LL, &v6) || v6 != 1 )
func0("eglChooseConfig");
eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, 0LL);
if ( !eglWindowSurface )
func0("eglCreateWindowSurface");
eglContext = eglCreateContext(eglDisplay, eglConfig, 0LL, &v7);
if ( !eglContext )
func0("eglCreateContext");
if ( !(unsigned int)eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, eglContext) )
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

canonical_name: 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
__int64 v5; // rdi
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
{
v5 = v4--;
gles2_update_state(v5);
gles2_draw((unsigned int)width, (unsigned int)height);
eglSwapBuffers(eglDisplay, eglWindowSurface);
}
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
__int64 v5; // rdi
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
{
v5 = v4--;
gles2_update_state(v5);
gles2_draw((unsigned int)width, (unsigned int)height);
eglSwapBuffers(eglDisplay, eglWindowSurface);
}
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; // eax
Display *v2; // r12
int v3; // ebp
Screen *v4; // rax
int v5; // er13
Window v6; // r14
int v7; // ebp
Colormap v8; // rax
int v9; // eax
int v10; // er9
__int64 result; // rax
XSetWindowAttributes v12; // [rsp+0h] [rbp-98h] BYREF

xWindow = 0LL;
*(_QWORD *)&xScreen = 0LL;
xDisplay = 0LL;
xVisual = 0LL;
v0 = XOpenDisplay(0LL);
xDisplay = v0;
if ( v0 )
{
v1 = XDefaultScreen(v0);
v2 = xDisplay;
v3 = v1;
*(_QWORD *)&xScreen = v1;
v4 = &xDisplay->screens[(__int64)v1];
v5 = v4->root_depth;
v6 = v4->root;
xVisual = calloc(1uLL, 0x40uLL);
XMatchVisualInfo(v2, v3, v5, 4, (XVisualInfo *)xVisual);
if ( xVisual )
{
v7 = 640;
v8 = XCreateColormap(xDisplay, v6, *(Visual **)xVisual, 0);
v12.event_mask = 163855LL;
xColormap = v8;
v12.colormap = v8;
if ( XDisplayWidth(xDisplay, xScreen) <= 640 )
v7 = XDisplayWidth(xDisplay, xScreen);
v9 = XDisplayHeight(xDisplay, xScreen);
v10 = 480;
if ( v9 <= 480 )
v10 = XDisplayHeight(xDisplay, xScreen);
xWindow = XCreateWindow(
xDisplay,
xDisplay->screens[*(_QWORD *)&xScreen].root,
0,
0,
v7,
v10,
0,
*((_DWORD *)xVisual + 5),
1u,
*(Visual **)xVisual,
0x280AuLL,
&v12);
if ( xWindow )
{
XMapWindow(xDisplay, xWindow);
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; // eax
Display *v2; // r12
int v3; // ebp
Screen *v4; // rax
int v5; // er13
Window v6; // r14
int v7; // ebp
Colormap v8; // rax
int v9; // eax
int v10; // er9
__int64 result; // rax
XSetWindowAttributes v12; // [rsp+0h] [rbp-98h] BYREF

xWindow = 0LL;
*(_QWORD *)&xScreen = 0LL;
xDisplay = 0LL;
xVisual = 0LL;
v0 = XOpenDisplay(0LL);
xDisplay = v0;
if ( v0 )
{
v1 = XDefaultScreen(v0);
v2 = xDisplay;
v3 = v1;
*(_QWORD *)&xScreen = v1;
v4 = &xDisplay->screens[(__int64)v1];
v5 = v4->root_depth;
v6 = v4->root;
xVisual = calloc(1uLL, 0x40uLL);
XMatchVisualInfo(v2, v3, v5, 4, (XVisualInfo *)xVisual);
if ( xVisual )
{
v7 = 640;
v8 = XCreateColormap(xDisplay, v6, *(Visual **)xVisual, 0);
v12.event_mask = 163855LL;
xColormap = v8;
v12.colormap = v8;
if ( XDisplayWidth(xDisplay, xScreen) <= 640 )
v7 = XDisplayWidth(xDisplay, xScreen);
v9 = XDisplayHeight(xDisplay, xScreen);
v10 = 480;
if ( v9 <= 480 )
v10 = XDisplayHeight(xDisplay, xScreen);
xWindow = XCreateWindow(
xDisplay,
xDisplay->screens[*(_QWORD *)&xScreen].root,
0,
0,
v7,
v10,
0,
*((_DWORD *)xVisual + 5),
1u,
*(Visual **)xVisual,
0x280AuLL,
&v12);
if ( xWindow )
{
XMapWindow(xDisplay, xWindow);
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:
// attributes: thunk
__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:
// attributes: thunk
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; // rbp
const char *result; // rax
int v2; // er8
int v3; // [rsp+6h] [rbp-12h] BYREF
char v4[8]; // [rsp+Ah] [rbp-Eh] BYREF

v3 = 7233866;
v0 = malloc(0x18uLL);
strcpy(v4, "Novak");
*(_QWORD *)v0 = &v3;
*((_QWORD *)v0 + 1) = v4;
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; // rbp
const char *result; // rax
int v2; // er8
int v3; // [rsp+6h] [rbp-12h] BYREF
char v4[8]; // [rsp+Ah] [rbp-Eh] BYREF

v3 = 7233866;
v0 = malloc(0x18uLL);
strcpy(v4, "Novak");
*(_QWORD *)v0 = &v3;
*((_QWORD *)v0 + 1) = v4;
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 *__fastcall all_tests(__int64 a1, __int64 a2)
{
const char *result; // rax
int v3; // edx

result = test_convert();
if ( result )
{
++tests_run;
}
else
{
result = (const char *)test_name(a1, a2, (unsigned int)(tests_run + 2));
tests_run = v3;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(__int64 a1, __int64 a2)
{
const char *result; // rax
int v3; // edx

result = func8();
if ( result )
{
++tests_run;
}
else
{
result = (const char *)func7(a1, a2, (unsigned int)(tests_run + 2));
tests_run = v3;
}
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
char *v2; // rbx
const char *v3; // rbx
unsigned int j; // ebp
char *v5; // rbx
const char *v6; // rbx
size_t result; // rax

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

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

for ( i = 0; ; ++i )
{
v3 = *(const char **)a1;
if ( i >= strlen(*(const char **)a1) )
break;
v2 = (char *)&v3[i];
*v2 = (*__ctype_toupper_loc())[*v2];
}
for ( j = 0; ; ++j )
{
v6 = *(const char **)(a1 + 8);
result = strlen(v6);
if ( j >= result )
break;
v5 = (char *)&v6[j];
*v5 = (*__ctype_toupper_loc())[*v5];
}
++*(_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; }


main

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

v3 = (const char *)all_tests(argc, argv, envp);
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 = (const char *)func9(argc, argv, envp);
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:
__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;
}


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()
{
unsigned __int64 v0; // rcx

tcase_fn_start("test_name", "main.c", 57LL);
setup();
rename_person(employee, (__int64)"Franta");
if ( !memcmp(*(const void **)employee, "Franta", v0) )
{
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()
{
unsigned __int64 v0; // rcx

tcase_fn_start("test_name", "main.c", 57LL);
func2();
func1(employee, (__int64)"Franta");
if ( !memcmp(*(const void **)employee, "Franta", v0) )
{
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, __int64 a4)
{
__int64 v5; // rbx

printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", **a3, (*a3)[1]);
v5 = 0LL;
printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n", *a2, *a1);
printf("Memory\n\t");
while ( v5 == 8 )
{
printf("\n\t");
printf("%.2X ", *(unsigned __int8 *)(*(_QWORD *)a4 + 8LL));
LABEL_3:
++v5;
}
printf("%.2X ", *(unsigned __int8 *)(*(_QWORD *)a4 + v5));
if ( v5 != 15 )
goto LABEL_3;
return putchar(10);
}

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

printf("Registers\n\tr0:%.2X\n\tr1:%.2X\n", **a3, (*a3)[1]);
v5 = 0LL;
printf("Instruction\n\tCurrent:%X\n\tPointer:%X\n", *a2, *a1);
printf("Memory\n\t");
while ( v5 == 8 )
{
printf("\n\t");
printf("%.2X ", *(unsigned __int8 *)(*(_QWORD *)a4 + 8LL));
LABEL_3:
++v5;
}
printf("%.2X ", *(unsigned __int8 *)(*(_QWORD *)a4 + v5));
if ( v5 != 15 )
goto LABEL_3;
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; // r14
__int64 v7; // rbx
__int64 result; // rax
__int64 v9; // [rsp+0h] [rbp-58h] BYREF

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

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

if ( a4 )
{
v5 = a1 + 24LL * a4;
v7 = a1;
do
{
get_displacement(&v9, a2, a3, a5);
v7 += 24LL;
a3 += 24LL;
result = Vector_copy();
}
while ( v7 != v5 );
}
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; // r14
__int64 v7; // rbx
__int64 result; // rax
__int64 v9; // [rsp+0h] [rbp-88h] BYREF

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

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

if ( a4 )
{
v5 = a1 + 72LL * a4;
v7 = a1;
do
{
get_gradient(&v9, a2, a3, a5);
v7 += 72LL;
a3 += 24LL;
result = Matrix_copy();
}
while ( v7 != v5 );
}
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:
void __fastcall setCursorPosEditor(int a1)
{
char *v1; // rax

if ( a1 < 0 )
{
Epos = Ebuf;
}
else
{
v1 = &Ebuf[a1];
if ( a1 > Eend - Ebuf )
v1 = Eend;
Epos = v1;
}
}

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

if ( a1 < 0 )
{
Epos = Ebuf;
}
else
{
v1 = &Ebuf[a1];
if ( a1 > Eend - Ebuf )
v1 = Eend;
Epos = v1;
}
}

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 v3; // dl
char *v4; // rdx
char *result; // rax

v1 = Eend;
for ( i = Epos; Epos <= v1; i = Epos )
{
v3 = *v1--;
v1[2] = v3;
}
*i = a1;
v4 = Eend + 1;
result = Epos + 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 v3; // dl
char *v4; // rdx
char *result; // rax

v1 = Eend;
for ( i = Epos; Epos <= v1; i = Epos )
{
v3 = *v1--;
v1[2] = v3;
}
*i = a1;
v4 = Eend + 1;
result = Epos + 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
char v2; // dl

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

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

result = Epos;
if ( Epos != Ebuf )
{
v1 = Eend;
if ( Epos < Eend )
{
do
{
v2 = *result++;
*(result - 2) = v2;
v1 = Eend;
}
while ( Eend > result );
result = Epos;
}
Epos = --result;
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:
char *initUndoSystem()
{
char *v0; // rbx
char *v1; // rdi
char *result; // rax

if ( initialized_0 )
{
v0 = (char *)&undoStacks;
do
{
v1 = v0;
v0 += 16;
clearNamedStack(v1);
}
while ( v0 != (char *)&undoStacks + 160 );
}
initialized_0 = 1;
result = (char *)&undoStacks;
*((_QWORD *)&nSavedItems + 4) = 0LL;
*((_QWORD *)&nUndoItems + 4) = 0LL;
nSavedItems = 0LL;
*(&nSavedItems + 1) = 0LL;
nUndoItems = 0LL;
*(&nUndoItems + 1) = 0LL;
do
{
*((_QWORD *)result + 1) = 0LL;
result += 16;
*((_DWORD *)result - 4) = 0;
}
while ( result != (char *)&undoStacks + 160 );
ringIndx = 0;
undoLevel = 0;
return result;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rbx
char *v1; // rdi
char *result; // rax

if ( initialized_0 )
{
v0 = (char *)&undoStacks;
do
{
v1 = v0;
v0 += 16;
clearNamedStack(v1);
}
while ( v0 != (char *)&undoStacks + 160 );
}
initialized_0 = 1;
result = (char *)&undoStacks;
*((_QWORD *)&nSavedItems + 4) = 0LL;
*((_QWORD *)&nUndoItems + 4) = 0LL;
nSavedItems = 0LL;
*(&nSavedItems + 1) = 0LL;
nUndoItems = 0LL;
*(&nUndoItems + 1) = 0LL;
do
{
*((_QWORD *)result + 1) = 0LL;
result += 16;
*((_DWORD *)result - 4) = 0;
}
while ( result != (char *)&undoStacks + 160 );
ringIndx = 0;
undoLevel = 0;
return result;
}

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()
{
__int64 v0; // rax
int v1; // edx
int v2; // ebx
__int64 v3; // rax
unsigned int v4; // er12
__int64 v5; // rax
__int64 result; // rax

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

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

if ( !undoLevel )
return setStringError("Undo Error: Nothing to Undo.");
LODWORD(v0) = ringIndx - 1;
if ( ringIndx - 1 < 0 )
{
ringIndx = 9;
LODWORD(v0) = 9;
}
else
{
--ringIndx;
}
v1 = undoLevel - 1;
v0 = (int)v0;
if ( undoLevel - 1 <= 0 )
v1 = 0;
undoLevel = v1;
if ( *((int *)&nUndoItems + (int)v0) > 0 )
{
v2 = 0;
do
{
++v2;
v3 = Pop();
freeNumber(v3);
v0 = ringIndx;
}
while ( *((_DWORD *)&nUndoItems + ringIndx) > v2 );
}
v4 = *((_DWORD *)&nSavedItems + v0);
v5 = getStack();
copyStack((char *)&undoStacks + 16 * ringIndx, v5, v4);
clearNamedStack((char *)&undoStacks + 16 * ringIndx);
result = ringIndx;
*((_DWORD *)&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;
*((_DWORD *)&nSavedItems + ringIndx) = 0;
return clearNamedStack((char *)&undoStacks + 16 * v0);
}

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

v0 = ringIndx;
*((_DWORD *)&nSavedItems + ringIndx) = 0;
return clearNamedStack((char *)&undoStacks + 16 * 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((char *)&undoStacks + 16 * ringIndx);
v1 = ringIndx;
*((_DWORD *)&nSavedItems + ringIndx) = a1;
v2 = getStack();
return copyStack(v2, (char *)&undoStacks + 16 * v1, a1);
}

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

if ( undoLevel > 9 )
clearNamedStack((char *)&undoStacks + 16 * ringIndx);
v1 = ringIndx;
*((_DWORD *)&nSavedItems + ringIndx) = a1;
v2 = getStack();
return copyStack(v2, (char *)&undoStacks + 16 * 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;
*((_DWORD *)&nSavedItems + ringIndx) += a1;
v2 = getStack();
return copyStack(v2, (char *)&undoStacks + 16 * v1, a1);
}

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

v1 = ringIndx;
*((_DWORD *)&nSavedItems + ringIndx) += a1;
v2 = getStack();
return copyStack(v2, (char *)&undoStacks + 16 * 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; // esi
int v2; // eax
int v3; // edx
__int64 result; // rax

v1 = undoLevel;
v2 = ringIndx;
*((_DWORD *)&nUndoItems + ringIndx) = a1;
v3 = v1 + 1;
if ( v1 + 1 > 9 )
v3 = 10;
result = (unsigned int)(v2 + 1);
undoLevel = v3;
if ( (int)result > 9 )
result = 0LL;
ringIndx = result;
return result;
}

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

v1 = undoLevel;
v2 = ringIndx;
*((_DWORD *)&nUndoItems + ringIndx) = a1;
v3 = v1 + 1;
if ( v1 + 1 > 9 )
v3 = 10;
result = (unsigned int)(v2 + 1);
undoLevel = v3;
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

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; // r12
int v3; // eax
bool v5; // zf

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 )
{
v5 = *(_QWORD *)(v0 + 168) == 0LL;
*(_DWORD *)v0 = -1;
if ( v5 )
*(_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 v7; // rax
__int64 result; // rax

v4 = *(_QWORD **)(a1 + 8);
if ( v4 && a3 > 0 )
{
v5 = 0;
do
{
v6 = (_QWORD *)newStackEle();
v6[2] = v4[2];
v7 = *(_QWORD *)(a2 + 8);
v6[1] = 0LL;
*v6 = v7;
incRefcntNumber();
if ( *v6 )
*(_QWORD *)(*v6 + 8LL) = v6;
++v5;
++*(_DWORD *)a2;
v4 = (_QWORD *)*v4;
*(_QWORD *)(a2 + 8) = v6;
}
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 v7; // rax
__int64 result; // rax

v4 = *(_QWORD **)(a1 + 8);
if ( v4 && a3 > 0 )
{
v5 = 0;
do
{
v6 = (_QWORD *)func3();
v6[2] = v4[2];
v7 = *(_QWORD *)(a2 + 8);
v6[1] = 0LL;
*v6 = v7;
incRefcntNumber();
if ( *v6 )
*(_QWORD *)(*v6 + 8LL) = v6;
++v5;
++*(_DWORD *)a2;
v4 = (_QWORD *)*v4;
*(_QWORD *)(a2 + 8) = v6;
}
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 *


getStackEle

decompiled_code:
__int64 __fastcall getStackEle(int a1)
{
_QWORD *v1; // rdx
int i; // eax

if ( a1 < 0 || stack <= a1 )
return 0LL;
v1 = (_QWORD *)*((_QWORD *)&stack + 1);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v1 = (_QWORD *)*v1;
}
return v1[2];
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
_QWORD *v1; // rdx
int i; // eax

if ( a1 < 0 || stack <= a1 )
return 0LL;
v1 = (_QWORD *)*((_QWORD *)&stack + 1);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v1 = (_QWORD *)*v1;
}
return v1[2];
}

original_code:
Number * getStackEle(int which)
{
    int i;
    struct StackElem *s = ((void *)0);
    if (which < 0 || which >= stack.length)
 return ((void *)0);
    s = stack.head;
    for (i = 0; i < which; i++)
 s = s->t;
    return s->data;
}

canonical_original_code:
struct _Number *getStackEle(int which)
{
    int i;
    struct StackElem *s = ((void *)0);
    if (which < 0 || which >= stack.length)
 return ((void *)0);
    s = stack.head;
    for (i = 0; i < which; i++)
 s = s->t;
    return s->data;
}

variable_types: which int

variable_types: i int

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


Push

decompiled_code:
__int64 __fastcall Push(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
__int64 result; // rax

v1 = newStackEle();
*(_QWORD *)(v1 + 16) = a1;
v2 = (_QWORD *)v1;
v3 = *((_QWORD *)&stack + 1);
v2[1] = 0LL;
*v2 = v3;
incRefcntNumber(a1);
if ( *v2 )
*(_QWORD *)(*v2 + 8LL) = v2;
*((_QWORD *)&stack + 1) = v2;
result = 1LL;
++stack;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
__int64 v3; // rax
__int64 result; // rax

v1 = func3();
*(_QWORD *)(v1 + 16) = a1;
v2 = (_QWORD *)v1;
v3 = *((_QWORD *)&stack + 1);
v2[1] = 0LL;
*v2 = v3;
incRefcntNumber(a1);
if ( *v2 )
*(_QWORD *)(*v2 + 8LL) = v2;
*((_QWORD *)&stack + 1) = v2;
result = 1LL;
++stack;
return result;
}

original_code:
int Push(Number *data)
{
    struct StackElem *s;
    s = newStackEle();
    s->data = data;
    s->t = stack.head;
    s->b = ((void *)0);
    incRefcntNumber(data);
    if(s->t)
 s->t->b = s;
    stack.head = s;
    stack.length++;
    return 1;
}

canonical_original_code:
int Push(struct _Number *data)
{
    struct StackElem *s;
    s = newStackEle();
    s->data = data;
    s->t = stack.head;
    s->b = ((void *)0);
    incRefcntNumber(data);
    if(s->t)
 s->t->b = s;
    stack.head = s;
    stack.length++;
    return 1;
}

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


Pop

decompiled_code:
__int64 Pop()
{
__int64 *v0; // rbp
__int64 v1; // rax
__int64 v2; // r12

v0 = (__int64 *)*((_QWORD *)&stack + 1);
if ( !v0 )
return 0LL;
v1 = *v0;
if ( *v0 )
{
*(_QWORD *)(v1 + 8) = 0LL;
*((_QWORD *)&stack + 1) = v1;
}
else
{
*((_QWORD *)&stack + 1) = 0LL;
}
v2 = v0[2];
decRefcntNumber(v2);
stackAddToFreeList((unsigned __int64)v0);
--stack;
return v2;
}

original_code:
Number * Pop()
{
    Number *ptr;
    struct StackElem *s;
    s = stack.head;
    if(s == ((void *)0))
 return ((void *)0);
    if(s->t) {
 s->t->b = ((void *)0);
 stack.head = s->t;
    } else
 stack.head = ((void *)0);
    ptr = s->data;
    decRefcntNumber(ptr);
    stackAddToFreeList(s);
    stack.length--;
    return ptr;
}

canonical_original_code:
struct _Number *Pop()
{
    struct _Number *ptr;
    struct StackElem *s;
    s = stack.head;
    if(s == ((void *)0))
 return ((void *)0);
    if(s->t) {
 s->t->b = ((void *)0);
 stack.head = s->t;
    } else
 stack.head = ((void *)0);
    ptr = s->data;
    decRefcntNumber(ptr);
    stackAddToFreeList(s);
    stack.length--;
    return ptr;
}


resetError

decompiled_code:
void resetError()
{
ErrorString = 0;
}

canonical_decompiled_code:
void func0()
{
ErrorString = 0;
}

original_code:
void resetError() {
    *ErrorString = '\0';
}


isError

decompiled_code:
_BOOL8 isError()
{
return ErrorString != 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return ErrorString != 0;
}

original_code:
int isError() {
    return *ErrorString != '\0';
}


getStringError

decompiled_code:
char *getStringError()
{
return &ErrorString;
}

canonical_decompiled_code:
char *func2()
{
return &ErrorString;
}

original_code:
char *getStringError() {
    return ErrorString;
}


setStringError

decompiled_code:
char *__fastcall setStringError(char *src)
{
char *result; // rax

result = strncpy(ErrorString, src, 0x400uLL);
ErrorString[1023] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
char *result; // rax

result = strncpy(ErrorString, src, 0x400uLL);
ErrorString[1023] = 0;
return result;
}

original_code:
void setStringError(char *error) {
    strncpy(ErrorString, error, 1024);
    ErrorString[1024 -1] = '\0';
}

variable_types:
error
char *


checkArgs

decompiled_code:
__int64 __fastcall checkArgs(const char *a1, int a2)
{
int v2; // er8
__int64 result; // rax

v2 = stackLen();
result = 0LL;
if ( v2 < a2 )
{
sprintf(ErrorString, "%s Error: Too few Arguments.", a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2)
{
int v2; // er8
__int64 result; // rax

v2 = stackLen();
result = 0LL;
if ( v2 < a2 )
{
sprintf(ErrorString, "%s Error: Too few Arguments.", a1);
result = 1LL;
}
return result;
}

original_code:
int checkArgs(char *name, int args) {
    if (stackLen() < args) {
 sprintf(ErrorString, "%s Error: Too few Arguments.", name);
 return 1;
    }
    return 0;
}

variable_types:
name
char *


invalidTyprError

decompiled_code:
int __fastcall invalidTyprError(const char *a1)
{
return sprintf(ErrorString, "%s Error: Invalid Type.", a1);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
return sprintf(ErrorString, "%s Error: Invalid Type.", a1);
}

original_code:
void invalidTyprError(char *name) {
    sprintf(ErrorString, "%s Error: Invalid Type.", name);
}


getRadixMode

decompiled_code:
__int64 getRadixMode()
{
return (unsigned int)radixMode;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)radixMode;
}

original_code:
int getRadixMode(){
    return radixMode;
}

canonical_original_code:
int getRadixMode(){
    return radixMode;
}


setRadixMode

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

if ( a1 == 32 )
{
radixMode = 32;
}
else if ( a1 == 16 )
{
radixMode = 16;
}
else
{
result = puts("setRadixMode invalid mode");
}
return result;
}

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

if ( a1 == 32 )
{
radixMode = 32;
}
else if ( a1 == 16 )
{
radixMode = 16;
}
else
{
result = puts("setRadixMode invalid mode");
}
return result;
}

original_code:
void setRadixMode(int mode)
{
    if (mode == 0x20)
 radixMode = 0x20;
    else if (mode == 0x10)
 radixMode = 0x10;
    else
 printf("setRadixMode invalid mode\n");
}

variable_types: mode int


setPolarMode

decompiled_code:
void __fastcall setPolarMode(int a1)
{
polarMode = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
polarMode = a1;
}

original_code:
void setPolarMode(int val) {
    polarMode = val;
}

variable_types: val int


getPolarMode

decompiled_code:
__int64 getPolarMode()
{
return (unsigned int)polarMode;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)polarMode;
}

original_code:
int getPolarMode() {
    return polarMode;
}


setBaseMode

decompiled_code:
void __fastcall setBaseMode(int a1)
{
baseMode = a1;
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
baseMode = a1;
}

original_code:
void setBaseMode(int val) {
    baseMode = val;
}


getBaseMode

decompiled_code:
__int64 getBaseMode()
{
return (unsigned int)baseMode;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)baseMode;
}

original_code:
int getBaseMode() {
    return baseMode;
}

canonical_original_code:
int getBaseMode() {
    return baseMode;
}


getModeDisplayString

decompiled_code:
char *getModeDisplayString()
{
int v0; // eax
int v1; // eax
int v2; // eax
bool v3; // cc
size_t v4; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
size_t v10; // rax

v0 = getRadixMode();
if ( v0 == 16 )
{
strcpy(buf_0, " Degrees ");
v1 = getPolarMode();
if ( v1 != 64 )
goto LABEL_5;
LABEL_16:
v7 = strlen(buf_0);
*(_QWORD *)&buf_0[v7] = 0x75676E6174636552LL;
*(int *)((char *)&dword_3E8 + v7) = 544366956;
*(__int16 *)((char *)&word_3EC + v7) = 8224;
byte_3EE[v7] = 0;
v2 = getBaseMode();
v3 = v2 <= 4;
if ( v2 != 4 )
goto LABEL_8;
LABEL_17:
*(_QWORD *)&buf_0[strlen(buf_0)] = 0x6C616D69636544LL;
return buf_0;
}
if ( v0 == 32 )
strcpy(buf_0, " Radians ");
else
fwrite("invalid Radix mode\n", 1uLL, 0x13uLL, stderr);
v1 = getPolarMode();
if ( v1 == 64 )
goto LABEL_16;
LABEL_5:
if ( v1 == 128 )
{
v8 = strlen(buf_0);
*(_QWORD *)&buf_0[v8] = 0x20202072616C6F50LL;
*((_BYTE *)&dword_3E8 + v8) = 0;
}
else
{
fwrite("invalid Polar mode\n", 1uLL, 0x13uLL, stderr);
}
v2 = getBaseMode();
v3 = v2 <= 4;
if ( v2 == 4 )
goto LABEL_17;
LABEL_8:
if ( v3 )
{
if ( v2 == 1 )
{
v9 = strlen(buf_0);
*(_DWORD *)&buf_0[v9] = 1634625858;
*(_WORD *)&buf_0[v9 + 4] = 31090;
buf_0[v9 + 6] = 0;
return buf_0;
}
if ( v2 == 2 )
{
v6 = strlen(buf_0);
*(_DWORD *)&buf_0[v6] = 1635017551;
*(_WORD *)&buf_0[v6 + 4] = 108;
return buf_0;
}
}
else
{
if ( v2 == 8 )
{
v10 = strlen(buf_0);
*(_QWORD *)&buf_0[v10] = 0x6963656461786548LL;
*(int *)((char *)&dword_3E8 + v10) = 7102829;
return buf_0;
}
if ( v2 == 1024 )
{
v4 = strlen(buf_0);
*(_QWORD *)&buf_0[v4] = 0x2D6C616D69636544LL;
*(int *)((char *)&dword_3E8 + v4) = 6778437;
return buf_0;
}
}
fwrite("invalid Base mode\n", 1uLL, 0x12uLL, stderr);
return buf_0;
}

original_code:
char *getModeDisplayString()
{
    int rad_mode, pol_mode, base_mode;
    static char buf[256];
    rad_mode = getRadixMode();
    switch (rad_mode) {
    case 0x10:
 strcpy(buf, " Degrees   ");
 break;
    case 0x20:
 strcpy(buf, " Radians   ");
 break;
    default:
 fprintf(stderr, "invalid Radix mode\n");
 break;
    }
    pol_mode = getPolarMode();
    switch (pol_mode) {
    case 0x40:
 strcat(buf, "Rectangular   ");
 break;
    case 0x80:
 strcat(buf, "Polar   ");
 break;
    default:
 fprintf(stderr, "invalid Polar mode\n");
 break;
    }
    base_mode = getBaseMode();
    switch (base_mode) {
    case 0x1:
 strcat(buf, "Binary");
 break;
    case 0x2:
 strcat(buf, "Octal");
 break;
    case 0x4:
 strcat(buf, "Decimal");
 break;
    case 0x400:
 strcat(buf, "Decimal-Eng");
 break;
    case 0x8:
 strcat(buf, "Hexadecimal");
 break;
    default:
 fprintf(stderr, "invalid Base mode\n");
 break;
    }
    return buf;
}

canonical_original_code:
char *getModeDisplayString()
{
    int rad_mode; int pol_mode; int base_mode;
    static char buf[256];
    rad_mode = getRadixMode();
    switch (rad_mode) {
    case 0x10:
 strcpy(buf, " Degrees   ");
 break;
    case 0x20:
 strcpy(buf, " Radians   ");
 break;
    default:
 fprintf(stderr, "invalid Radix mode\n");
 break;
    }
    pol_mode = getPolarMode();
    switch (pol_mode) {
    case 0x40:
 strcat(buf, "Rectangular   ");
 break;
    case 0x80:
 strcat(buf, "Polar   ");
 break;
    default:
 fprintf(stderr, "invalid Polar mode\n");
 break;
    }
    base_mode = getBaseMode();
    switch (base_mode) {
    case 0x1:
 strcat(buf, "Binary");
 break;
    case 0x2:
 strcat(buf, "Octal");
 break;
    case 0x4:
 strcat(buf, "Decimal");
 break;
    case 0x400:
 strcat(buf, "Decimal-Eng");
 break;
    case 0x8:
 strcat(buf, "Hexadecimal");
 break;
    default:
 fprintf(stderr, "invalid Base mode\n");
 break;
    }
    return buf;
}

variable_types:
buf
char [256]


quitCB

decompiled_code:
// attributes: thunk
__int64 quitCB()
{
return gtk_main_quit();
}

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

original_code:
void quitCB(gpointer data) {
    gtk_main_quit();
}

canonical_original_code:
void quitCB(void *data) {
    gtk_main_quit();
}

variable_types:
data
void *


clearCB

decompiled_code:
__int64 clearCB()
{
clearLCD();
return redrawLCD();
}

canonical_decompiled_code:
__int64 func3()
{
clearLCD();
return redrawLCD();
}

original_code:
void clearCB(gpointer data) {
    clearLCD();
    redrawLCD();
}

canonical_original_code:
void clearCB(void *data) {
    clearLCD();
    redrawLCD();
}


aboutCB

decompiled_code:
__int64 aboutCB()
{
return about_popup();
}

canonical_decompiled_code:
__int64 func4()
{
return about_popup();
}

original_code:
void aboutCB(gpointer data) {
    about_popup();
}

canonical_original_code:
void aboutCB(void *data) {
    about_popup();
}


licenseCB

decompiled_code:
__int64 licenseCB()
{
return license_popup();
}

canonical_decompiled_code:
__int64 func5()
{
return license_popup();
}

original_code:
void licenseCB(gpointer data) {
    license_popup();
}

canonical_original_code:
void licenseCB(void *data) {
    license_popup();
}


helpCB

decompiled_code:
__int64 helpCB()
{
return help_popup();
}

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

original_code:
void helpCB(gpointer data) {
    help_popup();
}

canonical_original_code:
void helpCB(void *data) {
    help_popup();
}


baseCB

decompiled_code:
__int64 baseCB()
{
setBaseMode();
redrawLCD();
return refreshModeDisplay();
}

canonical_decompiled_code:
__int64 func7()
{
setBaseMode();
redrawLCD();
return refreshModeDisplay();
}

original_code:
void baseCB(gpointer clientData) {
    setBaseMode(((gint) (glong) (clientData)));
    redrawLCD();
    refreshModeDisplay();
}

canonical_original_code:
void baseCB(void *clientData) {
    setBaseMode(((gint) (glong) (clientData)));
    redrawLCD();
    refreshModeDisplay();
}

variable_types:
clientData
void *


radixCB

decompiled_code:
__int64 radixCB()
{
setRadixMode();
redrawLCD();
return refreshModeDisplay();
}

canonical_decompiled_code:
__int64 func10()
{
setRadixMode();
redrawLCD();
return refreshModeDisplay();
}

original_code:
void radixCB(gpointer clientData) {
    setRadixMode(((gint) (glong) (clientData)));
    redrawLCD();
    refreshModeDisplay();
}

canonical_original_code:
void radixCB(void *clientData) {
    setRadixMode(((gint) (glong) (clientData)));
    redrawLCD();
    refreshModeDisplay();
}


cmodeCB

decompiled_code:
__int64 __fastcall cmodeCB(int a1)
{
if ( a1 == 64 )
{
setPolarMode(64LL);
}
else
{
if ( a1 != 128 )
{
fwrite("Error: cmodeCB: i shouldn't get here\n", 1uLL, 0x25uLL, stderr);
exit(0);
}
setPolarMode(128LL);
}
redrawLCD();
return refreshModeDisplay();
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
if ( a1 == 64 )
{
setPolarMode(64LL);
}
else
{
if ( a1 != 128 )
{
fwrite("Error: cmodeCB: i shouldn't get here\n", 1uLL, 0x25uLL, stderr);
exit(0);
}
setPolarMode(128LL);
}
redrawLCD();
return refreshModeDisplay();
}

original_code:
void cmodeCB(gpointer clientData) {
    switch(((gint) (glong) (clientData))) {
    case 0x40:
 setPolarMode(0x40);
 break;
    case 0x80:
 setPolarMode(0x80);
 break;
    default:
 fprintf(stderr, "Error: cmodeCB: i shouldn't get here\n");
 exit(0);
    }
    redrawLCD();
    refreshModeDisplay();
}

canonical_original_code:
void cmodeCB(void *clientData) {
    switch(((gint) (glong) (clientData))) {
    case 0x40:
 setPolarMode(0x40);
 break;
    case 0x80:
 setPolarMode(0x80);
 break;
    default:
 fprintf(stderr, "Error: cmodeCB: i shouldn't get here\n");
 exit(0);
    }
    redrawLCD();
    refreshModeDisplay();
}


dmodeCB

decompiled_code:
__int64 dmodeCB()
{
setLCDDispMode();
return redrawLCD();
}

canonical_decompiled_code:
__int64 func16()
{
setLCDDispMode();
return redrawLCD();
}

original_code:
void dmodeCB(gpointer clientData) {
    setLCDDispMode(((gint) (glong) (clientData)));
    redrawLCD();
}

canonical_original_code:
void dmodeCB(void *clientData) {
    setLCDDispMode(((gint) (glong) (clientData)));
    redrawLCD();
}


decompiled_code:
__int64 setup_constant()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // r12
__int64 v14; // rbp
__int64 v15; // rax

v0 = newReal();
realE = setRealDouble(v0, 2.718281828459045);
v1 = newReal();
realPi = setRealDouble(v1, 3.141592653589793);
v2 = newReal();
realPi2 = setRealDouble(v2, 1.570796326794897);
v3 = newReal();
realZero = setRealDouble(v3, 0.0);
v4 = newReal();
realHalf = setRealDouble(v4, 0.5);
v5 = newReal();
realTen = setRealDouble(v5, 10.0);
v6 = newReal();
realOne = setRealDouble(v6, 1.0);
v7 = newReal();
realTwo = setRealDouble(v7, 2.0);
v8 = newReal();
realMOne = setRealDouble(v8, -1.0);
v9 = newReal();
v10 = setRealDouble(v9, 180.0);
real180Pi = divReal(v10, realPi);
freeReal(v10);
v11 = newReal();
v12 = setRealDouble(v11, 1.0);
v13 = realZero;
v14 = v12;
v15 = newCmplx();
cmplxI = setCmplxReal(v15, v13, v14);
return freeReal(v14);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // r12
__int64 v14; // rbp
__int64 v15; // rax

v0 = newReal();
realE = setRealDouble(v0, 2.718281828459045);
v1 = newReal();
realPi = setRealDouble(v1, 3.141592653589793);
v2 = newReal();
realPi2 = setRealDouble(v2, 1.570796326794897);
v3 = newReal();
realZero = setRealDouble(v3, 0.0);
v4 = newReal();
realHalf = setRealDouble(v4, 0.5);
v5 = newReal();
realTen = setRealDouble(v5, 10.0);
v6 = newReal();
realOne = setRealDouble(v6, 1.0);
v7 = newReal();
realTwo = setRealDouble(v7, 2.0);
v8 = newReal();
realMOne = setRealDouble(v8, -1.0);
v9 = newReal();
v10 = setRealDouble(v9, 180.0);
real180Pi = divReal(v10, realPi);
freeReal(v10);
v11 = newReal();
v12 = setRealDouble(v11, 1.0);
v13 = realZero;
v14 = v12;
v15 = newCmplx();
cmplxI = setCmplxReal(v15, v13, v14);
return freeReal(v14);
}

original_code:
void setup_constant(){
    Real *tmp;
    realE = setRealDouble(newReal(), 2.7182818284590452354);
    realPi = setRealDouble(newReal(), 3.14159265358979323846);
    realPi2 = setRealDouble(newReal(), 1.57079632679489661923);
    realZero = setRealDouble(newReal(), 0.0);
    realHalf = setRealDouble(newReal(), 0.5);
    realTen = setRealDouble(newReal(), 10.0);
    realOne = setRealDouble(newReal(), 1.0);
    realTwo = setRealDouble(newReal(), 2.0);
    realMOne = setRealDouble(newReal(), -1.0);
    tmp = setRealDouble(newReal(), 180.0);
    real180Pi = divReal(tmp, realPi);
    freeReal(tmp);
    tmp = setRealDouble(newReal(), 1.0);
    cmplxI = setCmplxReal(newCmplx(), realZero, tmp);
    freeReal(tmp);
}

canonical_original_code:
void setup_constant(){
    struct _Real *tmp;
    realE = setRealDouble(newReal(), 2.7182818284590452354);
    realPi = setRealDouble(newReal(), 3.14159265358979323846);
    realPi2 = setRealDouble(newReal(), 1.57079632679489661923);
    realZero = setRealDouble(newReal(), 0.0);
    realHalf = setRealDouble(newReal(), 0.5);
    realTen = setRealDouble(newReal(), 10.0);
    realOne = setRealDouble(newReal(), 1.0);
    realTwo = setRealDouble(newReal(), 2.0);
    realMOne = setRealDouble(newReal(), -1.0);
    tmp = setRealDouble(newReal(), 180.0);
    real180Pi = divReal(tmp, realPi);
    freeReal(tmp);
    tmp = setRealDouble(newReal(), 1.0);
    cmplxI = setCmplxReal(newCmplx(), realZero, tmp);
    freeReal(tmp);
}

variable_types:
tmp
struct _Real { char ok; double num; } *


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
if ( a1 )
fprintf(stderr, "Error: %s\n", a1);
fwrite("Usage: grpn [-fn font] [-btn-fn font] [-disp-fn font] [-bm basemode]\n", 1uLL, 0x45uLL, stderr);
fwrite(" [-rows n] [-cols n] [-b]\n", 1uLL, 0x25uLL, stderr);
fwrite(" -b: Don't draw the buttons.\n", 1uLL, 0x26uLL, stderr);
fwrite(" -rows: Display (a minimum of) \"n\" rows.\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -cols: Display (a minimum of) \"n\" columns.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -btn-fn: Use \"font\" for the buttons and menu-bar.\n", 1uLL, 0x37uLL, stderr);
fwrite(" -disp-fn: Use \"font\" for the main display.\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -fn: Specifies both -btn-fn and -disp-fn.\n", 1uLL, 0x33uLL, stderr);
return fwrite(" -bm: basemode: dec, eng, bin, oct or hex.\n", 1uLL, 0x34uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
if ( a1 )
fprintf(stderr, "Error: %s\n", a1);
fwrite("Usage: grpn [-fn font] [-btn-fn font] [-disp-fn font] [-bm basemode]\n", 1uLL, 0x45uLL, stderr);
fwrite(" [-rows n] [-cols n] [-b]\n", 1uLL, 0x25uLL, stderr);
fwrite(" -b: Don't draw the buttons.\n", 1uLL, 0x26uLL, stderr);
fwrite(" -rows: Display (a minimum of) \"n\" rows.\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -cols: Display (a minimum of) \"n\" columns.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -btn-fn: Use \"font\" for the buttons and menu-bar.\n", 1uLL, 0x37uLL, stderr);
fwrite(" -disp-fn: Use \"font\" for the main display.\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -fn: Specifies both -btn-fn and -disp-fn.\n", 1uLL, 0x33uLL, stderr);
return fwrite(" -bm: basemode: dec, eng, bin, oct or hex.\n", 1uLL, 0x34uLL, stderr);
}

original_code:
void usage(char *str){
    if (str)
 fprintf(stderr, "Error: %s\n", str);
    fprintf(stderr, "Usage: grpn [-fn font] [-btn-fn font] [-disp-fn font] [-bm basemode]\n");
    fprintf(stderr, "            [-rows n] [-cols n] [-b]\n");
    fprintf(stderr, "   -b:        Don't draw the buttons.\n");
    fprintf(stderr, "   -rows:     Display (a minimum of) \"n\" rows.\n");
    fprintf(stderr, "   -cols:     Display (a minimum of) \"n\" columns.\n");
    fprintf(stderr, "   -btn-fn:   Use \"font\" for the buttons and menu-bar.\n");
    fprintf(stderr, "   -disp-fn:  Use \"font\" for the main display.\n");
    fprintf(stderr, "   -fn:       Specifies both -btn-fn and -disp-fn.\n");
    fprintf(stderr, "   -bm:        basemode: dec, eng, bin, oct or hex.\n");
}

variable_types:
str
char *


main

repo: gfv/byteoscilloscope

original_code:
int main(int argc, char** argv) {
    int i = 0;
    char wave[129];
    for(int j = 0; j < 128; j++) {
        wave[j] = ' ';
    }
    wave[128] = 0;
    while (!feof(stdin)) {
        wave[64] = '|';
        wave[32] = '[';
        wave[96] = ']';
        unsigned char c;
        i++;
        scanf("%c", &c);
        printf("\n");
        int rv = (c/2);
        int initial = c;
        wave[rv] = '%';
        printf("[%s] ", wave);
        wave[rv] = ' ';
        if (rv > 96 || rv < 32) {
            printf("\033[01;31m%d\033[00m RED", rv);
        } else {
            printf("%d", initial);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int i = 0;
    char wave[129];
    for(int j = 0; j < 128; j++) {
        wave[j] = ' ';
    }
    wave[128] = 0;
    while (!feof(stdin)) {
        wave[64] = '|';
        wave[32] = '[';
        wave[96] = ']';
        unsigned char c;
        i++;
        scanf("%c", &c);
        printf("\n");
        int rv = (c/2);
        int initial = c;
        wave[rv] = '%';
        printf("[%s] ", wave);
        wave[rv] = ' ';
        if (rv > 96 || rv < 32) {
            printf("\033[01;31m%d\033[00m RED", rv);
        } else {
            printf("%d", initial);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
wave
char [129]

variable_types: j int

variable_types:
c
unsigned char

variable_types: rv int

variable_types: initial int