original_code:
void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
                 const int N, const void *alpha, const void *X, const int incX,
                 const void *Y, const int incY, void *A, const int lda)
{
   char UL;
   int n, i, j, tincx, tincy, incx=incX, incy=incY;
   double *x=(double *)X, *xx=(double *)X, *y=(double *)Y,
         *yy=(double *)Y, *tx, *ty, *stx, *sty;
   extern int CBLAS_CallFromC;
   extern int RowMajorStrg;
   RowMajorStrg = 0;
   CBLAS_CallFromC = 1;
   if (order == CblasColMajor)
   {
      if (Uplo == CblasLower) UL = 'L';
      else if (Uplo == CblasUpper) UL = 'U';
      else
      {
         cblas_xerbla(2, "cblas_zher2", "Illegal Uplo setting, %d\n",Uplo );
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      zher2_(&UL, &N, alpha, X, &incx,
                                            Y, &incy, A, &lda);
   } else if (order == CblasRowMajor)
   {
      RowMajorStrg = 1;
      if (Uplo == CblasUpper) UL = 'L';
      else if (Uplo == CblasLower) UL = 'U';
      else
      {
         cblas_xerbla(2, "cblas_zher2", "Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (N > 0)
      {
         n = N << 1;
         x = malloc(n*sizeof(double));
         y = malloc(n*sizeof(double));
         tx = x;
         ty = y;
         if( incX > 0 ) {
            i = incX << 1 ;
            tincx = 2;
            stx= x+n;
         } else {
            i = incX *(-2);
            tincx = -2;
            stx = x-2;
            x +=(n-2);
         }
         if( incY > 0 ) {
            j = incY << 1;
            tincy = 2;
            sty= y+n;
         } else {
            j = incY *(-2);
            tincy = -2;
            sty = y-2;
            y +=(n-2);
         }
         do
         {
            *x = *xx;
            x[1] = -xx[1];
            x += tincx ;
            xx += i;
         }
         while (x != stx);
         do
         {
            *y = *yy;
            y[1] = -yy[1];
            y += tincy ;
            yy += j;
         }
         while (y != sty);
         x=tx;
         y=ty;
            incx = 1;
            incy = 1;
      } else
      {
         x = (double *) X;
         y = (double *) Y;
      }
      zher2_(&UL, &N, alpha, y, &incy, x,
                                      &incx, A, &lda);
   }
   else
   {
      cblas_xerbla(1, "cblas_zher2", "Illegal Order setting, %d\n", order);
      CBLAS_CallFromC = 0;
      RowMajorStrg = 0;
      return;
   }
   if(X!=x)
      free(x);
   if(Y!=y)
      free(y);
   CBLAS_CallFromC = 0;
   RowMajorStrg = 0;
   return;
}

canonical_original_code:
void cblas_zher2(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, int N, void *alpha, void *X, int incX, void *Y, int incY, void *A, int lda)
{
   char UL;
   int n; int i; int j; int tincx; int tincy; int incx = incX; int incy = incY;
   double *x = (double *)X; double *xx = (double *)X; double *y = (double *)Y; double *yy = (double *)Y; double *tx; double *ty; double *stx; double *sty;
   extern int CBLAS_CallFromC;
   extern int RowMajorStrg;
   RowMajorStrg = 0;
   CBLAS_CallFromC = 1;
   if (order == CblasColMajor)
   {
      if (Uplo == CblasLower) UL = 'L';
      else if (Uplo == CblasUpper) UL = 'U';
      else
      {
         cblas_xerbla(2, "cblas_zher2", "Illegal Uplo setting, %d\n",Uplo );
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      zher2_(&UL, &N, alpha, X, &incx,
                                            Y, &incy, A, &lda);
   } else if (order == CblasRowMajor)
   {
      RowMajorStrg = 1;
      if (Uplo == CblasUpper) UL = 'L';
      else if (Uplo == CblasLower) UL = 'U';
      else
      {
         cblas_xerbla(2, "cblas_zher2", "Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (N > 0)
      {
         n = N << 1;
         x = malloc(n*sizeof(double));
         y = malloc(n*sizeof(double));
         tx = x;
         ty = y;
         if( incX > 0 ) {
            i = incX << 1 ;
            tincx = 2;
            stx= x+n;
         } else {
            i = incX *(-2);
            tincx = -2;
            stx = x-2;
            x +=(n-2);
         }
         if( incY > 0 ) {
            j = incY << 1;
            tincy = 2;
            sty= y+n;
         } else {
            j = incY *(-2);
            tincy = -2;
            sty = y-2;
            y +=(n-2);
         }
         do
         {
            *x = *xx;
            x[1] = -xx[1];
            x += tincx ;
            xx += i;
         }
         while (x != stx);
         do
         {
            *y = *yy;
            y[1] = -yy[1];
            y += tincy ;
            yy += j;
         }
         while (y != sty);
         x=tx;
         y=ty;
            incx = 1;
            incy = 1;
      } else
      {
         x = (double *) X;
         y = (double *) Y;
      }
      zher2_(&UL, &N, alpha, y, &incy, x,
                                      &incx, A, &lda);
   }
   else
   {
      cblas_xerbla(1, "cblas_zher2", "Illegal Order setting, %d\n", order);
      CBLAS_CallFromC = 0;
      RowMajorStrg = 0;
      return;
   }
   if(X!=x)
      free(x);
   if(Y!=y)
      free(y);
   CBLAS_CallFromC = 0;
   RowMajorStrg = 0;
   return;
}

variable_types: enum CBLAS_ORDER { CblasRowMajor=101, CblasColMajor=102 }

variable_types:
alpha
void *

variable_types:
X
void *

variable_types:
Y
void *

variable_types: incY int

variable_types:
A
void *

variable_types: lda int

variable_types: UL char

variable_types: n int

variable_types: i int

variable_types: j int

variable_types: tincx int

variable_types: tincy int

variable_types: incx int

variable_types: incy int

variable_types:
x
double *

variable_types:
xx
double *

variable_types:
y
double *

variable_types:
yy
double *

variable_types:
tx
double *

variable_types:
ty
double *

variable_types:
stx
double *

variable_types:
sty
double *


repo: ivanjimenez/ipaap

decompiled_code:
__int64 __fastcall cblas_daxpy(int a1, __int64 a2, int a3, __int64 a4, int a5, double a6)
{
int v7; // [rsp+Ch] [rbp-1Ch] BYREF
double v8; // [rsp+10h] [rbp-18h] BYREF
int v9; // [rsp+18h] [rbp-10h] BYREF
int v10[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v10[0] = a1;
v8 = a6;
v9 = a3;
v7 = a5;
return daxpy_(v10, &v8, a2, &v9, a4, &v7);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3, __int64 a4, int a5, double a6)
{
int v7; // [rsp+Ch] [rbp-1Ch] BYREF
double v8; // [rsp+10h] [rbp-18h] BYREF
int v9; // [rsp+18h] [rbp-10h] BYREF
int v10[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v10[0] = a1;
v8 = a6;
v9 = a3;
v7 = a5;
return daxpy_(v10, &v8, a2, &v9, a4, &v7);
}

original_code:
void cblas_daxpy( const int N, const double alpha, const double *X,
                       const int incX, double *Y, const int incY)
{
   daxpy_( &N, &alpha, X, &incX, Y, &incY);
}

canonical_original_code:
void cblas_daxpy(int N, double alpha, double *X, int incX, double *Y, int incY)
{
   daxpy_( &N, &alpha, X, &incX, Y, &incY);
}

variable_types: N int

variable_types: alpha double

variable_types:
X
double *

variable_types: incX int

variable_types:
Y
double *

variable_types: incY int

return_type: void


decompiled_code:
__int64 __fastcall cblas_dtpsv(unsigned int a1, unsigned int a2, unsigned int a3, __int64 a4, int a5, __int64 a6, __int64 a7, char a8)
{
__int64 result; // rax
int v9[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v10; // [rsp+1Dh] [rbp-Bh] BYREF
char v11; // [rsp+1Eh] [rbp-Ah] BYREF
char v12[9]; // [rsp+1Fh] [rbp-9h] BYREF

v9[0] = a5;
RowMajorStrg = 0;
CBLAS_CallFromC = 1;
if ( a1 != 102 )
{
if ( a1 != 101 )
{
result = cblas_xerbla(1LL, "cblas_dtpsv", "Illegal Order setting, %d\n", a1);
goto LABEL_39;
}
RowMajorStrg = 1;
if ( a2 == 121 )
{
v11 = 76;
LABEL_6:
switch ( a3 )
{
case 'o':
v12[0] = 84;
break;
case 'p':
v12[0] = 78;
break;
case 'q':
v12[0] = 78;
break;
default:
LABEL_25:
result = cblas_xerbla(3LL, "cblas_dtpsv", "Illegal TransA setting, %d\n", a3);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( (_DWORD)a4 == 132 )
{
v10 = 85;
goto LABEL_23;
}
if ( (_DWORD)a4 == 131 )
{
v10 = 78;
goto LABEL_23;
}
LABEL_27:
result = cblas_xerbla(4LL, "cblas_dtpsv", "Illegal Diag setting, %d\n", a4);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( a2 == 122 )
{
v11 = 85;
goto LABEL_6;
}
LABEL_18:
result = cblas_xerbla(2LL, "cblas_dtpsv", "Illegal Uplo setting, %d\n", a2);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( a2 == 121 )
{
v11 = 85;
}
else
{
if ( a2 != 122 )
goto LABEL_18;
v11 = 76;
}
switch ( a3 )
{
case 'o':
v12[0] = 78;
break;
case 'p':
v12[0] = 84;
break;
case 'q':
v12[0] = 67;
break;
default:
goto LABEL_25;
}
if ( (_DWORD)a4 == 132 )
{
v10 = 85;
}
else
{
if ( (_DWORD)a4 != 131 )
goto LABEL_27;
v10 = 78;
}
LABEL_23:
result = dtpsv_(&v11, v12, &v10, v9, a6, a7, &a8);
LABEL_39:
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, unsigned int a3, __int64 a4, int a5, __int64 a6, __int64 a7, char a8)
{
__int64 result; // rax
int v9[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v10; // [rsp+1Dh] [rbp-Bh] BYREF
char v11; // [rsp+1Eh] [rbp-Ah] BYREF
char v12[9]; // [rsp+1Fh] [rbp-9h] BYREF

v9[0] = a5;
RowMajorStrg = 0;
CBLAS_CallFromC = 1;
if ( a1 != 102 )
{
if ( a1 != 101 )
{
result = cblas_xerbla(1LL, "cblas_dtpsv", "Illegal Order setting, %d\n", a1);
goto LABEL_39;
}
RowMajorStrg = 1;
if ( a2 == 121 )
{
v11 = 76;
LABEL_6:
switch ( a3 )
{
case 'o':
v12[0] = 84;
break;
case 'p':
v12[0] = 78;
break;
case 'q':
v12[0] = 78;
break;
default:
LABEL_25:
result = cblas_xerbla(3LL, "cblas_dtpsv", "Illegal TransA setting, %d\n", a3);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( (_DWORD)a4 == 132 )
{
v10 = 85;
goto LABEL_23;
}
if ( (_DWORD)a4 == 131 )
{
v10 = 78;
goto LABEL_23;
}
LABEL_27:
result = cblas_xerbla(4LL, "cblas_dtpsv", "Illegal Diag setting, %d\n", a4);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( a2 == 122 )
{
v11 = 85;
goto LABEL_6;
}
LABEL_18:
result = cblas_xerbla(2LL, "cblas_dtpsv", "Illegal Uplo setting, %d\n", a2);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( a2 == 121 )
{
v11 = 85;
}
else
{
if ( a2 != 122 )
goto LABEL_18;
v11 = 76;
}
switch ( a3 )
{
case 'o':
v12[0] = 78;
break;
case 'p':
v12[0] = 84;
break;
case 'q':
v12[0] = 67;
break;
default:
goto LABEL_25;
}
if ( (_DWORD)a4 == 132 )
{
v10 = 85;
}
else
{
if ( (_DWORD)a4 != 131 )
goto LABEL_27;
v10 = 78;
}
LABEL_23:
result = dtpsv_(&v11, v12, &v10, v9, a6, a7, &a8);
LABEL_39:
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}

original_code:
void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
                 const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
                 const int N, const double *Ap, double *X, const int incX)
{
   char TA;
   char UL;
   char DI;
   extern int CBLAS_CallFromC;
   extern int RowMajorStrg;
   RowMajorStrg = 0;
   CBLAS_CallFromC = 1;
   if (order == CblasColMajor)
   {
      if (Uplo == CblasUpper) UL = 'U';
      else if (Uplo == CblasLower) UL = 'L';
      else
      {
         cblas_xerbla(2, "cblas_dtpsv","Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (TransA == CblasNoTrans) TA = 'N';
      else if (TransA == CblasTrans) TA = 'T';
      else if (TransA == CblasConjTrans) TA = 'C';
      else
      {
         cblas_xerbla(3, "cblas_dtpsv","Illegal TransA setting, %d\n", TransA);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (Diag == CblasUnit) DI = 'U';
      else if (Diag == CblasNonUnit) DI = 'N';
      else
      {
         cblas_xerbla(4, "cblas_dtpsv","Illegal Diag setting, %d\n", Diag);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      dtpsv_( &UL, &TA, &DI, &N, Ap, X, &incX);
   }
   else if (order == CblasRowMajor)
   {
      RowMajorStrg = 1;
      if (Uplo == CblasUpper) UL = 'L';
      else if (Uplo == CblasLower) UL = 'U';
      else
      {
         cblas_xerbla(2, "cblas_dtpsv","Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (TransA == CblasNoTrans) TA = 'T';
      else if (TransA == CblasTrans) TA = 'N';
      else if (TransA == CblasConjTrans) TA = 'N';
      else
      {
         cblas_xerbla(3, "cblas_dtpsv","Illegal TransA setting, %d\n", TransA);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (Diag == CblasUnit) DI = 'U';
      else if (Diag == CblasNonUnit) DI = 'N';
      else
      {
         cblas_xerbla(4, "cblas_dtpsv","Illegal Diag setting, %d\n", Diag);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      dtpsv_( &UL, &TA, &DI, &N, Ap, X,&incX);
   }
   else cblas_xerbla(1, "cblas_dtpsv", "Illegal Order setting, %d\n", order);
   CBLAS_CallFromC = 0;
   RowMajorStrg = 0;
   return;
}

canonical_original_code:
void cblas_dtpsv(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE TransA, enum CBLAS_DIAG Diag, int N, double *Ap, double *X, int incX)
{
   char TA;
   char UL;
   char DI;
   extern int CBLAS_CallFromC;
   extern int RowMajorStrg;
   RowMajorStrg = 0;
   CBLAS_CallFromC = 1;
   if (order == CblasColMajor)
   {
      if (Uplo == CblasUpper) UL = 'U';
      else if (Uplo == CblasLower) UL = 'L';
      else
      {
         cblas_xerbla(2, "cblas_dtpsv","Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (TransA == CblasNoTrans) TA = 'N';
      else if (TransA == CblasTrans) TA = 'T';
      else if (TransA == CblasConjTrans) TA = 'C';
      else
      {
         cblas_xerbla(3, "cblas_dtpsv","Illegal TransA setting, %d\n", TransA);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (Diag == CblasUnit) DI = 'U';
      else if (Diag == CblasNonUnit) DI = 'N';
      else
      {
         cblas_xerbla(4, "cblas_dtpsv","Illegal Diag setting, %d\n", Diag);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      dtpsv_( &UL, &TA, &DI, &N, Ap, X, &incX);
   }
   else if (order == CblasRowMajor)
   {
      RowMajorStrg = 1;
      if (Uplo == CblasUpper) UL = 'L';
      else if (Uplo == CblasLower) UL = 'U';
      else
      {
         cblas_xerbla(2, "cblas_dtpsv","Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (TransA == CblasNoTrans) TA = 'T';
      else if (TransA == CblasTrans) TA = 'N';
      else if (TransA == CblasConjTrans) TA = 'N';
      else
      {
         cblas_xerbla(3, "cblas_dtpsv","Illegal TransA setting, %d\n", TransA);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if (Diag == CblasUnit) DI = 'U';
      else if (Diag == CblasNonUnit) DI = 'N';
      else
      {
         cblas_xerbla(4, "cblas_dtpsv","Illegal Diag setting, %d\n", Diag);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      dtpsv_( &UL, &TA, &DI, &N, Ap, X,&incX);
   }
   else cblas_xerbla(1, "cblas_dtpsv", "Illegal Order setting, %d\n", order);
   CBLAS_CallFromC = 0;
   RowMajorStrg = 0;
   return;
}

variable_types: enum CBLAS_ORDER { CblasRowMajor=101, CblasColMajor=102 }

variable_types: enum CBLAS_UPLO { CblasUpper=121, CblasLower=122 }

variable_types: enum CBLAS_TRANSPOSE { CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113 }

variable_types: enum CBLAS_DIAG { CblasNonUnit=131, CblasUnit=132 }

variable_types:
Ap
double *

variable_types: TA char

variable_types: UL char

variable_types: DI char

variable_types: RowMajorStrg int


parseargs

repo: ivartj/platformer

decompiled_code:
int __fastcall parseargs(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt_long(argc, argv, "h", &longopts_0, 0LL);
if ( result == -1 )
break;
if ( result == 104 )
{
usage(stdout);
exit(0);
}
if ( result <= 104 && (result == 58 || result == 63) )
{
usage(stderr);
exit(1);
}
}
if ( optind != argc )
{
usage(stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt_long(argc, argv, "h", &longopts_0, 0LL);
if ( result == -1 )
break;
if ( result == 104 )
{
func0(stdout);
exit(0);
}
if ( result <= 104 && (result == 58 || result == 63) )
{
func0(stderr);
exit(1);
}
}
if ( optind != argc )
{
func0(stderr);
exit(1);
}
return result;
}

original_code:
void parseargs(int argc, char *argv[])
{
 int c;
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h' },
  { 0, 0, 0, 0 },
 };
 while((c = getopt_long(argc, argv, "h", longopts, ((void *)0))) != -1)
 switch(c) {
 case 'h':
  usage(stdout);
  exit(0);
 case '?':
 case ':':
  usage(stderr);
  exit(1);
 }
 switch(argc - optind) {
 case 0:
  break;
 default:
  usage(stderr);
  exit(1);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


init

decompiled_code:
void init()
{
int v0; // eax
const char *v1; // rdx
int v2; // eax
const char *v3; // rdx

if ( (unsigned int)video_init(640LL, 480LL) )
{
v0 = geterrmsg();
error((int)"Failed to initialize video: %s", v0, v1);
}
if ( (unsigned int)load_init() )
{
v2 = geterrmsg();
error((int)"Failed to initialize image loading: %s", v2, v3);
}
}

canonical_decompiled_code:
void func2()
{
int v0; // eax
const char *v1; // rdx
int v2; // eax
const char *v3; // rdx

if ( (unsigned int)video_init(640LL, 480LL) )
{
v0 = geterrmsg();
error((int)"Failed to initialize video: %s", v0, v1);
}
if ( (unsigned int)load_init() )
{
v2 = geterrmsg();
error((int)"Failed to initialize image loading: %s", v2, v3);
}
}

original_code:
void init(void)
{
 int err;
 err = video_init(640, 480);
 if(err)
  error("Failed to initialize video: %s", geterrmsg());
 err = load_init();
 if(err)
  error("Failed to initialize image loading: %s", geterrmsg());
}

canonical_original_code:
void init()
{
 int err;
 err = video_init(640, 480);
 if(err)
  error("Failed to initialize video: %s", geterrmsg());
 err = load_init();
 if(err)
  error("Failed to initialize image loading: %s", geterrmsg());
}

variable_types: err int


fail

decompiled_code:
void __noreturn fail()
{
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
exit(1);
}

original_code:
void fail(void)
{
 exit(1);
}

canonical_original_code:
void fail()
{
 exit(1);
}


quit

decompiled_code:
void __noreturn quit()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func4()
{
exit(0);
}

original_code:
void quit(void)
{
 exit(0);
}

canonical_original_code:
void quit()
{
 exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
parseargs(argc, (char **)argv);
init();
quit();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func1(argc, (char **)argv);
func2();
func4();
}

original_code:
int main(int argc, char *argv[])
{
 parseargs(argc, argv);
 init();
 quit();
 return 0;
}

return_type: int


original_code:
uint64_t hash_create(unsigned char *data, size_t len)
{
 uint64_t hash;
 int hashlen;
 unsigned char *bytes;
 int i;
 hash = 0;
 hashlen = sizeof(hash);
 bytes = (unsigned char *)&hash;
 for(i = 0; i < len; i++)
  bytes[i % hashlen] ^= data[i];
 return hash;
}

canonical_original_code:
unsigned long hash_create(unsigned char *data, unsigned long len)
{
 unsigned long hash;
 int hashlen;
 unsigned char *bytes;
 int i;
 hash = 0;
 hashlen = sizeof(hash);
 bytes = (unsigned char *)&hash;
 for(i = 0; i < len; i++)
  bytes[i % hashlen] ^= data[i];
 return hash;
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned long

variable_types:
hash
unsigned long

variable_types: hashlen int

variable_types:
bytes
unsigned char *

variable_types: i int

return_type: unsigned long


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

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

original_code:
void gfx_destroy(gfx *g)
{
 free(g);
}

canonical_original_code:
void gfx_destroy(struct _gfx *g)
{
 free(g);
}

variable_types: struct _gfx { struct _image { int w; unsigned int *pix; void *private; } *img; int x; unsigned int c; } *

user_defined_types: struct _gfx { struct _image *img; int x; unsigned int c; }


decompiled_code:
void __fastcall gfx_translate(__int64 a1, int a2, int a3)
{
*(_DWORD *)(a1 + 8) += a2;
*(_DWORD *)(a1 + 12) += a3;
}

original_code:
void gfx_translate(gfx *g, int x, int y)
{
 g->x += x;
 g->y += y;
}

canonical_original_code:
void gfx_translate(struct _gfx *g, int x, int y)
{
 g->x += x;
 g->y += y;
}

variable_types: x int

variable_types: y int

user_defined_types: struct _image { int w; unsigned int *pix; void *private; }


decompiled_code:
void __fastcall gfx_color(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

original_code:
void gfx_color(gfx *g, color c)
{
 g->c = c;
}

canonical_original_code:
void gfx_color(struct _gfx *g, unsigned int c)
{
 g->c = c;
}

variable_types:
c
unsigned int


original_code:
void gfx_dot(gfx *g, int x, int y)
{
 int tx, ty;
 tx = x + g->x;
 ty = y + g->y;
 if(tx < 0 || tx >= g->img->w)
  return;
 if(ty < 0 || ty >= g->img->h)
  return;
 g->img->pix[tx + ty * g->img->w] = g->c;
}

canonical_original_code:
void gfx_dot(struct _gfx *g, int x, int y)
{
 int tx; int ty;
 tx = x + g->x;
 ty = y + g->y;
 if(tx < 0 || tx >= g->img->w)
  return;
 if(ty < 0 || ty >= g->img->h)
  return;
 g->img->pix[tx + ty * g->img->w] = g->c;
}

variable_types: tx int

variable_types: ty int


original_code:
void gfx_fill(gfx *g, rect *r)
{
 rect rr;
 memcpy(&rr, r, sizeof(rr));
 rr.x += g->x;
 rr.y += g->y;
 image_fill(g->img, &rr, g->c);
}

canonical_original_code:
void gfx_fill(struct _gfx *g, struct rect *r)
{
 struct rect rr;
 memcpy(&rr, r, sizeof(rr));
 rr.x += g->x;
 rr.y += g->y;
 image_fill(g->img, &rr, g->c);
}

variable_types:
r
struct rect { int x; } *

variable_types:
rr
struct rect { int x; }


decompiled_code:
__int64 __fastcall gfx_get(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // esi
int *v5; // r8
int v6; // ecx
int v7; // edx

result = 0LL;
v4 = *(_DWORD *)(a1 + 8) + a2;
if ( v4 >= 0 )
{
v5 = *(int **)a1;
v6 = **(_DWORD **)a1;
v7 = *(_DWORD *)(a1 + 12) + a3;
if ( v7 < 0 || v6 <= v4 )
{
result = 0LL;
}
else if ( v5[1] > v7 )
{
result = *(unsigned int *)(*((_QWORD *)v5 + 1) + 4LL * (v6 * v7 + v4));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // esi
int *v5; // r8
int v6; // ecx
int v7; // edx

result = 0LL;
v4 = *(_DWORD *)(a1 + 8) + a2;
if ( v4 >= 0 )
{
v5 = *(int **)a1;
v6 = **(_DWORD **)a1;
v7 = *(_DWORD *)(a1 + 12) + a3;
if ( v7 < 0 || v6 <= v4 )
{
result = 0LL;
}
else if ( v5[1] > v7 )
{
result = *(unsigned int *)(*((_QWORD *)v5 + 1) + 4LL * (v6 * v7 + v4));
}
}
return result;
}

original_code:
color gfx_get(gfx *g, int x, int y)
{
 x += g->x;
 y += g->y;
 if(x < 0 || x >= g->img->w)
  return 0;
 if(y < 0 || y >= g->img->h)
  return 0;
 return g->img->pix[x + g->img->w * y];
}

canonical_original_code:
unsigned int gfx_get(struct _gfx *g, int x, int y)
{
 x += g->x;
 y += g->y;
 if(x < 0 || x >= g->img->w)
  return 0;
 if(y < 0 || y >= g->img->h)
  return 0;
 return g->img->pix[x + g->img->w * y];
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall gfx_blit(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
return blitrxy(
a2,
a3,
*(_QWORD *)a1,
(unsigned int)(*(_DWORD *)(a1 + 8) + a4),
(unsigned int)(*(_DWORD *)(a1 + 12) + a5));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
return blitrxy(
a2,
a3,
*(_QWORD *)a1,
(unsigned int)(*(_DWORD *)(a1 + 8) + a4),
(unsigned int)(*(_DWORD *)(a1 + 12) + a5));
}

original_code:
void gfx_blit(gfx *g, image *img, rect *r, int x, int y)
{
 blitrxy(img, r, g->img, g->x + x, g->y + y);
}

canonical_original_code:
void gfx_blit(struct _gfx *g, struct _image *img, struct rect *r, int x, int y)
{
 blitrxy(img, r, g->img, g->x + x, g->y + y);
}

variable_types:
img
struct _image *


decompiled_code:
__int64 __fastcall dnode_iter_next(__int64 *a1, void *a2)
{
__int64 v2; // rax

v2 = *a1;
if ( !*a1 )
return 0LL;
*a1 = *(_QWORD *)(v2 + 16);
memcpy(a2, *(const void **)v2, *(_QWORD *)(v2 + 8));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, void *a2)
{
__int64 v2; // rax

v2 = *a1;
if ( !*a1 )
return 0LL;
*a1 = *(_QWORD *)(v2 + 16);
memcpy(a2, *(const void **)v2, *(_QWORD *)(v2 + 8));
return 1LL;
}

original_code:
int dnode_iter_next(iter *i, void *retval)
{
 dnode *dn;
 dn = (dnode *)(i->data.v);
 if(dn == ((void *)0))
  return 0;
 i->data.v = dn->next;
 memcpy(retval, dn->data, dn->datalen);
 return 1;
}

canonical_original_code:
int dnode_iter_next(struct _iter *i, void *retval)
{
 struct _dnode *dn;
 dn = (struct _dnode *)(i->data.v);
 if(dn == ((void *)0))
  return 0;
 i->data.v = dn->next;
 memcpy(retval, dn->data, dn->datalen);
 return 1;
}

variable_types: struct _iter { union _data { void *v; int i; double d; } data; int (*next)(struct _iter *i, void *retval); } *

variable_types:
retval
void *

variable_types: struct _dnode { void *data; unsigned long datalen; struct _dnode *next; struct _dnode *prev; struct _dlist { struct _dnode *first; struct _dnode *last; } *list; } *

user_defined_types: struct _iter { union _data data; int (*next)(struct _iter *i, void *retval); }

user_defined_types: struct _dnode { void *data; unsigned long datalen; struct _dnode *next; struct _dnode *prev; struct _dlist *list; }


decompiled_code:
void *dlist_create()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
dlist *dlist_create(void)
{
 dlist *dl;
 dl = calloc(1, sizeof(dlist));
 return dl;
}

canonical_original_code:
struct _dlist *dlist_create()
{
 struct _dlist *dl;
 dl = calloc(1, sizeof(dlist));
 return dl;
}

variable_types: struct _dlist { struct _dnode { void *data; unsigned long datalen; struct _dnode *next; struct _dnode *prev; struct _dlist *list; } *first; struct _dnode *last; } *

user_defined_types: struct _dlist { struct _dnode *first; struct _dnode *last; }


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

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

original_code:
dnode *dnode_next(dnode *dn)
{
 return dn->next;
}

canonical_original_code:
struct _dnode *dnode_next(struct _dnode *dn)
{
 return dn->next;
}

variable_types:
dn
struct _dnode *

return_type: struct _dnode { void *data; unsigned long datalen; struct _dnode *next; struct _dnode *prev; struct _dlist { struct _dnode *first; struct _dnode *last; } *list; } *


decompiled_code:
__int64 __fastcall dnode_prev(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
dnode *dnode_prev(dnode *dn)
{
 return dn->prev;
}

canonical_original_code:
struct _dnode *dnode_prev(struct _dnode *dn)
{
 return dn->prev;
}


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

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

original_code:
dnode *dlist_last(dlist *dl)
{
 return dl->last;
}

canonical_original_code:
struct _dnode *dlist_last(struct _dlist *dl)
{
 return dl->last;
}

variable_types:
dl
struct _dlist *


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

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

original_code:
dnode *dlist_first(dlist *dl)
{
 return dl->first;
}

canonical_original_code:
struct _dnode *dlist_first(struct _dlist *dl)
{
 return dl->first;
}


original_code:
void dnode_rem(dnode *dn)
{
 if(dn->prev != ((void *)0))
  dn->prev->next = dn->next;
 else
  dn->list->first = dn->next;
 if(dn->next != ((void *)0))
  dn->next->prev = dn->prev;
 else
  dn->list->last = dn->prev;
 free(dn->data);
 free(dn);
}

canonical_original_code:
void dnode_rem(struct _dnode *dn)
{
 if(dn->prev != ((void *)0))
  dn->prev->next = dn->next;
 else
  dn->list->first = dn->next;
 if(dn->next != ((void *)0))
  dn->next->prev = dn->prev;
 else
  dn->list->last = dn->prev;
 free(dn->data);
 free(dn);
}


decompiled_code:
_BOOL8 __fastcall dlist_iter(_QWORD *a1, _QWORD *a2)
{
*a2 = *a1;
a2[1] = dnode_iter_next;
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(_QWORD *a1, _QWORD *a2)
{
*a2 = *a1;
a2[1] = dnode_iter_next;
return *a1 != 0LL;
}

original_code:
int dlist_iter(dlist *dl, iter *i)
{
 i->data.v = dl->first;
 i->next = dnode_iter_next;
 return dl->first != ((void *)0);
}

canonical_original_code:
int dlist_iter(struct _dlist *dl, struct _iter *i)
{
 i->data.v = dl->first;
 i->next = dnode_iter_next;
 return dl->first != ((void *)0);
}

user_defined_types: union _data { void *v; int i; double d; }


decompiled_code:
__int64 thread_sleep()
{
return SDL_Delay();
}

canonical_decompiled_code:
__int64 func0()
{
return SDL_Delay();
}

original_code:
void thread_sleep(int ms)
{
 SDL_Delay(ms);
}

variable_types: ms int


vwarning

decompiled_code:
size_t __fastcall vwarning(char *format, __gnuc_va_list arg)
{
vfprintf(stderr, format, arg);
return fwrite(&unk_4A0, 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(char *format, __gnuc_va_list arg)
{
vfprintf(stderr, format, arg);
return fwrite(&unk_4A0, 1uLL, 2uLL, stderr);
}

original_code:
void vwarning(const char *fmt, va_list ap)
{
 vfprintf(stderr, fmt, ap);
 fprintf(stderr, ".\n");
}

canonical_original_code:
void vwarning(char *fmt, __builtin_va_list ap)
{
 vfprintf(stderr, fmt, ap);
 fprintf(stderr, ".\n");
}

variable_types:
fmt
char *


geterrmsg

decompiled_code:
void *geterrmsg()
{
return &errmsg;
}

canonical_decompiled_code:
void *func1()
{
return &errmsg;
}

original_code:
char *geterrmsg(void)
{
 return errmsg;
}

canonical_original_code:
char *geterrmsg()
{
 return errmsg;
}

return_type: char *


seterrmsg

original_code:
int seterrmsg(const char *fmt, ...)
{
 va_list ap;
 int len;
 char bakmsg[sizeof(errmsg)] = { 0 };
 __builtin_va_start(ap,fmt);
 len = vsnprintf(bakmsg, sizeof(errmsg), fmt, ap);
 memcpy(errmsg, bakmsg, len + 1);
 __builtin_va_end(ap);
 return -1;
}

canonical_original_code:
int seterrmsg(char *fmt, ...)
{
 __builtin_va_list ap;
 int len;
 char bakmsg[-1] = { 0 };
 __builtin_va_start(ap,fmt);
 len = vsnprintf(bakmsg, sizeof(errmsg), fmt, ap);
 memcpy(errmsg, bakmsg, len + 1);
 __builtin_va_end(ap);
 return -1;
}

variable_types: len int

variable_types:
bakmsg
char [-1]


error

decompiled_code:
void __noreturn error(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vwarning(a1, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
func0(a1, arg);
exit(1);
}

original_code:
void error(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vwarning(fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void error(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vwarning(fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


warning

decompiled_code:
size_t warning(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return vwarning(a1, arg);
}

canonical_decompiled_code:
size_t func4(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return func0(a1, arg);
}

original_code:
void warning(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vwarning(fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void warning(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vwarning(fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
__int64 seterrmsg_freeimage()
{
return seterrmsg(&unk_1AA);
}

canonical_decompiled_code:
__int64 func0()
{
return seterrmsg(&unk_1AA);
}

original_code:
static void seterrmsg_freeimage(FREE_IMAGE_FORMAT fif, const char *message)
{
 seterrmsg("%s", message);
}

canonical_original_code:
static void seterrmsg_freeimage(int fif, char *message)
{
 seterrmsg("%s", message);
}

variable_types: fif int

variable_types:
message
char *


decompiled_code:
__int64 load_init()
{
FreeImage_Initialise(0LL);
atexit((void (*)(void))&FreeImage_DeInitialise);
FreeImage_SetOutputMessage(seterrmsg_freeimage);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
FreeImage_Initialise(0LL);
atexit((void (*)(void))&FreeImage_DeInitialise);
FreeImage_SetOutputMessage(seterrmsg_freeimage);
return 0LL;
}

original_code:
int load_init(void)
{
 FreeImage_Initialise(0);
 atexit(FreeImage_DeInitialise);
 FreeImage_SetOutputMessage(seterrmsg_freeimage);
 return 0;
}

canonical_original_code:
int load_init()
{
 FreeImage_Initialise(0);
 atexit(FreeImage_DeInitialise);
 FreeImage_SetOutputMessage(seterrmsg_freeimage);
 return 0;
}


decompiled_code:
__int64 __fastcall load_image(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r13
unsigned int v3; // ebx
__int64 v4; // r15
__int64 v5; // rbp
size_t v6; // r14
char *v7; // r12
__int64 v8; // rbp
int v9; // ebx
const char *v11; // rax
const char *v12; // rax
__int64 v13; // [rsp+0h] [rbp-48h]
__int64 v14; // [rsp+8h] [rbp-40h]

v1 = FreeImage_Load(13LL, a1, 0LL);
v2 = v1;
if ( v1 )
{
v3 = FreeImage_GetWidth(v1);
v4 = (unsigned int)FreeImage_GetHeight(v2);
v14 = FreeImage_Allocate(v3, v4, 32LL, 16711680LL, 65280LL, 255LL);
if ( (unsigned int)FreeImage_Paste(v14, v2, 0LL, 0LL, 255LL) )
{
FreeImage_Unload(v2);
v5 = FreeImage_GetBits(v14);
v2 = image_create(v3, (unsigned int)v4);
if ( (int)v4 > 0 )
{
v6 = 4LL * (int)v3;
v13 = 4LL * -v3;
v7 = (char *)(v5 + 4LL * (int)((v4 - 1) * v3));
v8 = 0LL;
v9 = 0;
do
{
memcpy((void *)(*(_QWORD *)(v2 + 8) + v8), v7, v6);
++v9;
v8 += v6;
v7 += v13;
}
while ( (_DWORD)v4 != v9 );
}
FreeImage_Unload(v14);
}
else
{
v12 = (const char *)geterrmsg();
seterrmsg("FreeImage_Paste: %s", v12);
FreeImage_Unload(v2);
FreeImage_Unload(v14);
v2 = 0LL;
}
}
else
{
v11 = (const char *)geterrmsg();
seterrmsg("FreeImage_Load: %s", v11);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r13
unsigned int v3; // ebx
__int64 v4; // r15
__int64 v5; // rbp
size_t v6; // r14
char *v7; // r12
__int64 v8; // rbp
int v9; // ebx
const char *v11; // rax
const char *v12; // rax
__int64 v13; // [rsp+0h] [rbp-48h]
__int64 v14; // [rsp+8h] [rbp-40h]

v1 = FreeImage_Load(13LL, a1, 0LL);
v2 = v1;
if ( v1 )
{
v3 = FreeImage_GetWidth(v1);
v4 = (unsigned int)FreeImage_GetHeight(v2);
v14 = FreeImage_Allocate(v3, v4, 32LL, 16711680LL, 65280LL, 255LL);
if ( (unsigned int)FreeImage_Paste(v14, v2, 0LL, 0LL, 255LL) )
{
FreeImage_Unload(v2);
v5 = FreeImage_GetBits(v14);
v2 = image_create(v3, (unsigned int)v4);
if ( (int)v4 > 0 )
{
v6 = 4LL * (int)v3;
v13 = 4LL * -v3;
v7 = (char *)(v5 + 4LL * (int)((v4 - 1) * v3));
v8 = 0LL;
v9 = 0;
do
{
memcpy((void *)(*(_QWORD *)(v2 + 8) + v8), v7, v6);
++v9;
v8 += v6;
v7 += v13;
}
while ( (_DWORD)v4 != v9 );
}
FreeImage_Unload(v14);
}
else
{
v12 = (const char *)geterrmsg();
seterrmsg("FreeImage_Paste: %s", v12);
FreeImage_Unload(v2);
FreeImage_Unload(v14);
v2 = 0LL;
}
}
else
{
v11 = (const char *)geterrmsg();
seterrmsg("FreeImage_Load: %s", v11);
}
return v2;
}

original_code:
image *load_image(const char *path)
{
 FIBITMAP *src;
 FIBITMAP *dest;
 int width, height;
 int ok;
 int x, y;
 image *val = ((void *)0);
 color *bitmap;
 src = FreeImage_Load(FIF_PNG, path, 0);
 if(src == ((void *)0)) {
  seterrmsg("FreeImage_Load: %s", geterrmsg());
  return ((void *)0);
 }
 width = FreeImage_GetWidth(src);
 height = FreeImage_GetHeight(src);
 dest = FreeImage_Allocate(width, height, 32,
  0x00FF0000,
  0x0000FF00,
  0x000000FF);
 ok = FreeImage_Paste(dest, src, 0, 0, 255);
 if(!ok) {
  seterrmsg("FreeImage_Paste: %s", geterrmsg());
  FreeImage_Unload(src);
  FreeImage_Unload(dest);
  return ((void *)0);
 }
 FreeImage_Unload(src);
 bitmap = (color *)FreeImage_GetBits(dest);
 val = image_create(width, height);
 for(y = 0; y < height; y++)
  memcpy(&(val->pix[y * width]), &(bitmap[(height - 1 - y) * width]), width * sizeof(color));
 FreeImage_Unload(dest);
 return val;
}

canonical_original_code:
struct _image *load_image(char *path)
{
 struct FIBITMAP *src;
 struct FIBITMAP *dest;
 int width; int height;
 int ok;
 int x; int y;
 struct _image *val = ((void *)0);
 unsigned int *bitmap;
 src = FreeImage_Load(FIF_PNG, path, 0);
 if(src == ((void *)0)) {
  seterrmsg("FreeImage_Load: %s", geterrmsg());
  return ((void *)0);
 }
 width = FreeImage_GetWidth(src);
 height = FreeImage_GetHeight(src);
 dest = FreeImage_Allocate(width, height, 32,
  0x00FF0000,
  0x0000FF00,
  0x000000FF);
 ok = FreeImage_Paste(dest, src, 0, 0, 255);
 if(!ok) {
  seterrmsg("FreeImage_Paste: %s", geterrmsg());
  FreeImage_Unload(src);
  FreeImage_Unload(dest);
  return ((void *)0);
 }
 FreeImage_Unload(src);
 bitmap = (unsigned int *)FreeImage_GetBits(dest);
 val = image_create(width, height);
 for(y = 0; y < height; y++)
  memcpy(&(val->pix[y * width]), &(bitmap[(height - 1 - y) * width]), width * sizeof(color));
 FreeImage_Unload(dest);
 return val;
}

variable_types:
path
char *

variable_types:
src
struct FIBITMAP { void *data; } *

variable_types:
dest
struct FIBITMAP { void *data; } *

variable_types: width int

variable_types: height int

variable_types: ok int

variable_types: x int

variable_types: y int

variable_types: struct _image { int w; unsigned int *pix; void *private; } *

variable_types:
bitmap
unsigned int *


decompiled_code:
void *array_create()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
array *array_create(void)
{
 return (array *)calloc(1, sizeof(array));
}

canonical_original_code:
struct _array *array_create()
{
 return (struct _array *)calloc(1, sizeof(array));
}

return_type: struct _array { int len; void **els; } *


original_code:
int array_add(array *a, void *el)
{
 if(a->len == a->cap) {
  if(a->cap == 0)
   a->cap = 256;
  else
   a->cap <<= 1;
  a->els = realloc(a->els, a->cap * sizeof(void *));
 }
 a->els[a->len++] = el;
 return a->len - 1;
}

canonical_original_code:
int array_add(struct _array *a, void *el)
{
 if(a->len == a->cap) {
  if(a->cap == 0)
   a->cap = 256;
  else
   a->cap <<= 1;
  a->els = realloc(a->els, a->cap * sizeof(void *));
 }
 a->els[a->len++] = el;
 return a->len - 1;
}

variable_types: struct _array { int len; void **els; } *

variable_types:
el
void *


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

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
void *array_get(array *a, int idx)
{
 if(idx >= a->len)
  return ((void *)0);
 return a->els[idx];
}

canonical_original_code:
void *array_get(struct _array *a, int idx)
{
 if(idx >= a->len)
  return ((void *)0);
 return a->els[idx];
}

variable_types: idx int

return_type: void *


rgba

decompiled_code:
__int64 __fastcall rgba(double a1, double a2, double a3, double a4)
{
return (unsigned __int8)(int)(a3 * 255.0) | ((((((unsigned __int8)(int)(a4 * 255.0) << 8) | (unsigned __int8)(int)(a1 * 255.0)) << 8) | (unsigned int)(unsigned __int8)(int)(a2 * 255.0)) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4)
{
return (unsigned __int8)(int)(a3 * 255.0) | ((((((unsigned __int8)(int)(a4 * 255.0) << 8) | (unsigned __int8)(int)(a1 * 255.0)) << 8) | (unsigned int)(unsigned __int8)(int)(a2 * 255.0)) << 8);
}

canonical_original_code:
unsigned int rgba(double r, double g, double b, double a)
{
 unsigned int c;
 c = 0;
 c |= (unsigned char)(a * 255.0); c <<= 8;
 c |= (unsigned char)(r * 255.0); c <<= 8;
 c |= (unsigned char)(g * 255.0); c <<= 8;
 c |= (unsigned char)(b * 255.0);
 return c;
}

variable_types: r double

variable_types: g double

variable_types: b double

variable_types: a double

variable_types:
c
unsigned int


rgb

decompiled_code:
__int64 __fastcall rgb(double a1, double a2, double a3)
{
return (unsigned __int8)(int)(a3 * 255.0) | (((unsigned __int8)(int)(a2 * 255.0) | ((unsigned __int8)(int)(a1 * 255.0) << 8)) << 8) | 0xFF000000;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1, double a2, double a3)
{
return (unsigned __int8)(int)(a3 * 255.0) | (((unsigned __int8)(int)(a2 * 255.0) | ((unsigned __int8)(int)(a1 * 255.0) << 8)) << 8) | 0xFF000000;
}

canonical_original_code:
unsigned int rgb(double r, double g, double b)
{
 unsigned int c;
 double a;
 a = 1.0;
 c = 0;
 c |= (unsigned char)(a * 255.0); c <<= 8;
 c |= (unsigned char)(r * 255.0); c <<= 8;
 c |= (unsigned char)(g * 255.0); c <<= 8;
 c |= (unsigned char)(b * 255.0);
 return c;
}


getrgb

decompiled_code:
__int64 __fastcall getrgb(int a1, double *a2, double *a3, double *a4)
{
__int64 result; // rax

*a2 = (double)BYTE2(a1) / 255.0;
*a3 = (double)BYTE1(a1) / 255.0;
result = (unsigned __int8)a1;
*a4 = (double)(unsigned __int8)a1 / 255.0;
return result;
}

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

*a2 = (double)BYTE2(a1) / 255.0;
*a3 = (double)BYTE1(a1) / 255.0;
result = (unsigned __int8)a1;
*a4 = (double)(unsigned __int8)a1 / 255.0;
return result;
}

variable_types:
r
double *

variable_types:
g
double *

variable_types:
b
double *


decompiled_code:
_BOOL8 __fastcall prime_check(int a1)
{
int v1; // eax
int v2; // esi
int v3; // ebp
int v4; // ecx

v1 = prime_get(0LL);
v2 = v1 * v1;
if ( a1 >= v1 * v1 && a1 % v1 )
{
v3 = 0;
do
{
v4 = prime_get((unsigned int)++v3);
v2 = v4 * v4;
}
while ( v4 * v4 <= a1 && a1 % v4 );
}
return a1 < v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
int v1; // eax
int v2; // esi
int v3; // ebp
int v4; // ecx

v1 = func3(0LL);
v2 = v1 * v1;
if ( a1 >= v1 * v1 && a1 % v1 )
{
v3 = 0;
do
{
v4 = func3((unsigned int)++v3);
v2 = v4 * v4;
}
while ( v4 * v4 <= a1 && a1 % v4 );
}
return a1 < v2;
}

original_code:
int prime_check(int num)
{
 int i;
 int prime;
 for(prime = prime_get(i = 0);
     (prime * prime <= num) && (num % prime != 0);
     prime = prime_get(++i));
 if(prime * prime > num)
  return 1;
 else
  return 0;
}

variable_types: num int

variable_types: i int

variable_types: prime int


decompiled_code:
__int64 __fastcall prime_get(int a1)
{
while ( len <= a1 )
inc();
return *((unsigned int *)primes + a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
while ( len <= a1 )
func2();
return *((unsigned int *)primes + a1);
}

original_code:
int prime_get(int idx)
{
 while(len <= idx)
  inc();
 return primes[idx];
}


decompiled_code:
__int64 __fastcall prime_above(int a1)
{
unsigned int i; // ebx

for ( i = a1 + 1; !prime_check(i); ++i )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int i; // ebx

for ( i = a1 + 1; !func1(i); ++i )
;
return i;
}

original_code:
int prime_above(int num)
{
 for(++num; !prime_check(num); num++);
 return num;
}


lockcanvas

decompiled_code:
__int64 lockcanvas()
{
__int64 result; // rax
_DWORD *v1; // rdx

if ( *(_DWORD *)(canvas + 40) || (*(_DWORD *)canvas & 0x4005) != 0 )
SDL_LockSurface();
if ( !video )
video = (__int64)calloc(1uLL, 0x18uLL);
result = canvas;
v1 = (_DWORD *)video;
*(_QWORD *)(video + 8) = *(_QWORD *)(canvas + 32);
*v1 = *(_DWORD *)(result + 16);
*(_DWORD *)(video + 4) = *(_DWORD *)(result + 20);
*(_QWORD *)(video + 16) = result;
return result;
}

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

if ( *(_DWORD *)(canvas + 40) || (*(_DWORD *)canvas & 0x4005) != 0 )
SDL_LockSurface();
if ( !video )
video = (__int64)calloc(1uLL, 0x18uLL);
result = canvas;
v1 = (_DWORD *)video;
*(_QWORD *)(video + 8) = *(_QWORD *)(canvas + 32);
*v1 = *(_DWORD *)(result + 16);
*(_DWORD *)(video + 4) = *(_DWORD *)(result + 20);
*(_QWORD *)(video + 16) = result;
return result;
}

original_code:
void lockcanvas(void)
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_LockSurface(canvas);
 if(video == ((void *)0))
  video = calloc(1, sizeof(image));
 video->pix = canvas->pixels;
 video->w = canvas->w;
 video->h = canvas->h;
 video->private = canvas;
}

canonical_original_code:
void lockcanvas()
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_LockSurface(canvas);
 if(video == ((void *)0))
  video = calloc(1, sizeof(image));
 video->pix = canvas->pixels;
 video->w = canvas->w;
 video->h = canvas->h;
 video->private = canvas;
}


unlockcanvas

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

if ( *(_DWORD *)(canvas + 40) || (*(_DWORD *)canvas & 0x4005) != 0 )
result = SDL_UnlockSurface();
return result;
}

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

if ( *(_DWORD *)(canvas + 40) || (*(_DWORD *)canvas & 0x4005) != 0 )
result = SDL_UnlockSurface();
return result;
}

original_code:
void unlockcanvas(void)
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_UnlockSurface(canvas);
}

canonical_original_code:
void unlockcanvas()
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_UnlockSurface(canvas);
}


decompiled_code:
__int64 sdl_init()
{
unsigned int v0; // ebx
const char *v2; // rax

v0 = 0;
if ( !sdl_initialized )
{
v0 = SDL_Init(32LL);
if ( v0 )
{
v2 = (const char *)SDL_GetError();
v0 = seterrmsg("SDL failed to initialize: %s", v2);
}
else
{
atexit((void (*)(void))&SDL_Quit);
sdl_initialized = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
const char *v2; // rax

v0 = 0;
if ( !sdl_initialized )
{
v0 = SDL_Init(32LL);
if ( v0 )
{
v2 = (const char *)SDL_GetError();
v0 = seterrmsg("SDL failed to initialize: %s", v2);
}
else
{
atexit((void (*)(void))&SDL_Quit);
sdl_initialized = 1;
}
}
return v0;
}

original_code:
int sdl_init(void)
{
 int err;
 if(sdl_initialized)
  return 0;
 err = SDL_Init(0x00000020);
 if(err)
  return seterrmsg("SDL failed to initialize: %s", SDL_GetError());
 atexit(SDL_Quit);
 sdl_initialized = 1;
 return 0;
}

canonical_original_code:
int sdl_init()
{
 int err;
 if(sdl_initialized)
  return 0;
 err = SDL_Init(0x00000020);
 if(err)
  return seterrmsg("SDL failed to initialize: %s", SDL_GetError());
 atexit(SDL_Quit);
 sdl_initialized = 1;
 return 0;
}

variable_types: err int


decompiled_code:
__int64 __fastcall video_init(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
const char *v4; // rax
const char *v5; // rax

v2 = sdl_init();
if ( !v2 )
{
canvas = SDL_CreateRGBSurface(1LL, a1, a2, 32LL, 16711680LL, 65280LL, 255LL, -16777216LL);
if ( canvas )
{
window = SDL_SetVideoMode(a1, a2, 32LL, 1LL);
if ( window )
{
lockcanvas();
}
else
{
v5 = (const char *)SDL_GetError();
v2 = seterrmsg("Failed to open SDL window: %s", v5);
}
}
else
{
v4 = (const char *)SDL_GetError();
v2 = seterrmsg("Failed to create SDL canvas: %s", v4);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
const char *v4; // rax
const char *v5; // rax

v2 = func3();
if ( !v2 )
{
canvas = SDL_CreateRGBSurface(1LL, a1, a2, 32LL, 16711680LL, 65280LL, 255LL, -16777216LL);
if ( canvas )
{
window = SDL_SetVideoMode(a1, a2, 32LL, 1LL);
if ( window )
{
func0();
}
else
{
v5 = (const char *)SDL_GetError();
v2 = seterrmsg("Failed to open SDL window: %s", v5);
}
}
else
{
v4 = (const char *)SDL_GetError();
v2 = seterrmsg("Failed to create SDL canvas: %s", v4);
}
}
return v2;
}

original_code:
int video_init(int w, int h)
{
 int err;
 err = sdl_init();
 if(err)
  return err;
 canvas = SDL_CreateRGBSurface(0x00000001, w, h, 32,
  0x00FF0000,
  0x0000FF00,
  0x000000FF,
  0xFF000000);
 if(canvas == ((void *)0))
  return seterrmsg("Failed to create SDL canvas: %s", SDL_GetError());
 window = SDL_SetVideoMode(w, h, 32, 0x00000001);
 if(window == ((void *)0))
  return seterrmsg("Failed to open SDL window: %s", SDL_GetError());
 lockcanvas();
 return 0;
}

variable_types: w int

variable_types: h int


decompiled_code:
__int64 video_update()
{
unlockcanvas();
SDL_UpperBlit(canvas, 0LL, window, 0LL);
SDL_Flip(window);
return lockcanvas();
}

canonical_decompiled_code:
__int64 func5()
{
func1();
SDL_UpperBlit(canvas, 0LL, window, 0LL);
SDL_Flip(window);
return func0();
}

original_code:
void video_update(void)
{
 unlockcanvas();
 SDL_UpperBlit(canvas, ((void *)0), window, ((void *)0));
 SDL_Flip(window);
 lockcanvas();
}

canonical_original_code:
void video_update()
{
 unlockcanvas();
 SDL_UpperBlit(canvas, ((void *)0), window, ((void *)0));
 SDL_Flip(window);
 lockcanvas();
}


blitxymask

decompiled_code:
__int64 blitxymask()
{
return seterrmsg("Unimplemented method blitxymask");
}

canonical_decompiled_code:
__int64 func11()
{
return seterrmsg("Unimplemented method blitxymask");
}

original_code:
int blitxymask(image *src, image *dest, int x, int y, image *mask)
{
 return seterrmsg("Unimplemented method blitxymask");
}

canonical_original_code:
int blitxymask(struct _image *src, struct _image *dest, int x, int y, struct _image *mask)
{
 return seterrmsg("Unimplemented method blitxymask");
}

variable_types: struct _image { int w; unsigned int *pix; void *private; } *

variable_types:
dest
struct _image *

variable_types: x int

variable_types: y int

variable_types:
mask
struct _image *


decompiled_code:
__int64 __fastcall ps2rect(unsigned int a1, unsigned int a2, signed int a3, unsigned int a4)
{
__int64 v4; // rax

v4 = a2;
if ( (int)a1 >= a3 )
a1 = a3;
if ( (int)a2 >= (int)a4 )
v4 = a4;
return (v4 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, signed int a3, unsigned int a4)
{
__int64 v4; // rax

v4 = a2;
if ( (int)a1 >= a3 )
a1 = a3;
if ( (int)a2 >= (int)a4 )
v4 = a4;
return (v4 << 32) | a1;
}

original_code:
rect ps2rect(int x, int y, int x2, int y2)
{
 rect r;
 if(x < x2) {
  r.x = x;
  r.w = x2 - x;
 } else {
  r.x = x2;
  r.w = x - x2;
 }
 if(y < y2) {
  r.y = y;
  r.h = y2 - y;
 } else {
  r.y = y2;
  r.h = y - y2;
 }
 return r;
}

canonical_original_code:
struct rect ps2rect(int x, int y, int x2, int y2)
{
 struct rect r;
 if(x < x2) {
  r.x = x;
  r.w = x2 - x;
 } else {
  r.x = x2;
  r.w = x - x2;
 }
 if(y < y2) {
  r.y = y;
  r.h = y2 - y;
 } else {
  r.y = y2;
  r.h = y - y2;
 }
 return r;
}

variable_types:
r
struct rect { int x; }

return_type: struct rect { int x; }


original_code:
int rect_isoverlap(rect *a, rect *b)
{
 if(b->x >= a->x + a->w)
  return 0;
 if(a->x >= b->x + b->w)
  return 0;
 if(b->y >= a->y + a->h)
  return 0;
 if(a->y >= b->y + b->h)
  return 0;
 return 1;
}

canonical_original_code:
int rect_isoverlap(struct rect *a, struct rect *b)
{
 if(b->x >= a->x + a->w)
  return 0;
 if(a->x >= b->x + b->w)
  return 0;
 if(b->y >= a->y + a->h)
  return 0;
 if(a->y >= b->y + b->h)
  return 0;
 return 1;
}

variable_types:
a
struct rect { int x; } *

variable_types:
b
struct rect *


original_code:
int rect_iswithin(rect *a, rect *b)
{
 if(a->x > b->x)
  return 0;
 if(a->x + a->w < b->x + b->w)
  return 0;
 if(a->y > b->y)
  return 0;
 if(a->y + a->h < b->y + b->h)
  return 0;
 return 1;
}

canonical_original_code:
int rect_iswithin(struct rect *a, struct rect *b)
{
 if(a->x > b->x)
  return 0;
 if(a->x + a->w < b->x + b->w)
  return 0;
 if(a->y > b->y)
  return 0;
 if(a->y + a->h < b->y + b->h)
  return 0;
 return 1;
}


iterate

original_code:
int iterate(iter *i, void *retval)
{
 return i->next(i, retval);
}

canonical_original_code:
int iterate(struct _iter *i, void *retval)
{
 return i->next(i, retval);
}

variable_types: struct _iter { union _data { void *v; int i; double d; } data; int (*next)(struct _iter *i, void *retval); } *

variable_types:
retval
void *


repo: iveteran/HelloWorld

decompiled_code:
int __fastcall looking_enter(const void *a1)
{
return printf("looking_enter %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1)
{
return printf("looking_enter %p\n", a1);
}

original_code:
void looking_enter(void *node, void *object, struct node_operations *ops)
{
    printf("looking_enter %p\n", node);
}

variable_types:
node
void *

variable_types:
object
void *

variable_types: struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *


decompiled_code:
int __fastcall looking_exit(const void *a1)
{
return printf("looking_exit %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1)
{
return printf("looking_exit %p\n", a1);
}

original_code:
void looking_exit(void *node, void *object, struct node_operations *ops)
{
    printf("looking_exit %p\n", node);
}

user_defined_types: struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); }


decompiled_code:
int __fastcall standing_enter(const void *a1)
{
return printf("standing_enter %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1)
{
return printf("standing_enter %p\n", a1);
}

original_code:
void standing_enter(void *node, void *object, struct node_operations *ops)
{
    printf("standing_enter %p\n", node);
}


decompiled_code:
int __fastcall standing_exit(const void *a1)
{
return printf("standing_exit %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const void *a1)
{
return printf("standing_exit %p\n", a1);
}

original_code:
void standing_exit(void *node, void *object, struct node_operations *ops)
{
    printf("standing_exit %p\n", node);
}


decompiled_code:
__int64 __fastcall looking_tick(const void *a1, __int64 a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rbp
__int64 v5; // rax

printf("looking_tick %p\n", a1);
v4 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v5 = node_control(a1);
return v4(v5);
}

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

printf("looking_tick %p\n", a1);
v4 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v5 = node_control(a1);
return v4(v5);
}

original_code:
void looking_tick(void *node, void *object, struct node_operations *ops)
{
    printf("looking_tick %p\n", node);
    ops->success(node_control(node));
}


decompiled_code:
int __fastcall running_enter(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_enter %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_enter %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

original_code:
void running_enter(void *node, void *object, struct node_operations *ops)
{
    int dir = *(int *) node_blackboard(node);
    printf("running_enter %p %s\n", node, DIR_NAME[dir]);
}

variable_types: dir int


decompiled_code:
int __fastcall running_exit(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_exit %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

canonical_decompiled_code:
int __fastcall func6(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_exit %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

original_code:
void running_exit(void *node, void *object, struct node_operations *ops)
{
    int dir = *(int *) node_blackboard(node);
    printf("running_exit %p %s\n", node, DIR_NAME[dir]);
}


decompiled_code:
__int64 __fastcall running_tick(const void *a1, __int64 a2, __int64 a3)
{
int *v4; // rax
__int64 (__fastcall *v5)(__int64); // rbp
__int64 v6; // rax

v4 = (int *)node_blackboard();
printf("running_tick %p %s\n", a1, (const char *)DIR_NAME[*v4]);
v5 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v6 = node_control(a1);
return v5(v6);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, __int64 a2, __int64 a3)
{
int *v4; // rax
__int64 (__fastcall *v5)(__int64); // rbp
__int64 v6; // rax

v4 = (int *)node_blackboard();
printf("running_tick %p %s\n", a1, (const char *)DIR_NAME[*v4]);
v5 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v6 = node_control(a1);
return v5(v6);
}

original_code:
void running_tick(void *node, void *object, struct node_operations *ops)
{
    int dir = *(int *) node_blackboard(node);
    printf("running_tick %p %s\n", node, DIR_NAME[dir]);
    ops->success(node_control(node));
}


decompiled_code:
__int64 __fastcall standing_tick(const void *a1, __int64 a2, __int64 (__fastcall **a3)(__int64))
{
int *v4; // rbx
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64); // rbx
__int64 v7; // rax
__int64 result; // rax
__int64 (__fastcall *v9)(__int64); // rbx
__int64 v10; // rax

v4 = (int *)node_blackboard();
v5 = (unsigned int)(*v4 + 1);
*v4 = v5;
printf("standing_tick %p, stanging_count %d\n", a1, v5);
if ( *v4 > 4 )
{
v9 = a3[1];
v10 = node_control(a1);
result = v9(v10);
}
else
{
if ( (unsigned int)(*v4 - 3) <= 1 )
v6 = a3[2];
else
v6 = *a3;
v7 = node_control(a1);
result = v6(v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, __int64 a2, __int64 (__fastcall **a3)(__int64))
{
int *v4; // rbx
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64); // rbx
__int64 v7; // rax
__int64 result; // rax
__int64 (__fastcall *v9)(__int64); // rbx
__int64 v10; // rax

v4 = (int *)node_blackboard();
v5 = (unsigned int)(*v4 + 1);
*v4 = v5;
printf("standing_tick %p, stanging_count %d\n", a1, v5);
if ( *v4 > 4 )
{
v9 = a3[1];
v10 = node_control(a1);
result = v9(v10);
}
else
{
if ( (unsigned int)(*v4 - 3) <= 1 )
v6 = a3[2];
else
v6 = *a3;
v7 = node_control(a1);
result = v6(v7);
}
return result;
}

original_code:
void standing_tick(void *node, void *object, struct node_operations *ops)
{
    int *standing_count = node_blackboard(node);
    *standing_count = *standing_count+1;
    printf("standing_tick %p, stanging_count %d\n", node, *standing_count);
    if (*standing_count > 4)
        ops->success(node_control(node));
    else if (*standing_count >= 3 && *standing_count <= 4)
        ops->fail(node_control(node));
    else
        ops->running(node_control(node));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int (__fastcall *v3)(const void *); // rbx
void *v4; // rax
__int64 v5; // r13
__int64 *v6; // rbp
int (__fastcall **v7)(const void *); // rbx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rbp
unsigned int i; // ebx
int v13[4]; // [rsp+0h] [rbp-98h] BYREF
__int64 v14[4]; // [rsp+10h] [rbp-88h] BYREF
int (__fastcall *v15)(const void *); // [rsp+30h] [rbp-68h] BYREF
void *v16; // [rsp+38h] [rbp-60h]
int (__fastcall *v17)(const void *); // [rsp+40h] [rbp-58h]
int v18; // [rsp+5Ch] [rbp-3Ch] BYREF
__int64 v19[7]; // [rsp+60h] [rbp-38h] BYREF

behaviourtree_init(argc, argv, envp);
v15 = standing_enter;
v16 = standing_tick;
v17 = standing_exit;
LODWORD(v14[0]) = 0;
v3 = (int (__fastcall *)(const void *))node_create(&v15, v14);
v15 = looking_enter;
v16 = looking_tick;
v17 = looking_exit;
v4 = (void *)node_create(&v15, 0LL);
v15 = v3;
v16 = v4;
v5 = branch_create(1LL, 2LL, &v15);
v14[0] = (__int64)running_enter;
v14[1] = (__int64)running_tick;
v14[2] = (__int64)running_exit;
v13[0] = 2;
v13[1] = 4;
v13[2] = 6;
v13[3] = 8;
v6 = (__int64 *)v13;
v7 = &v15;
do
{
*v7 = (int (__fastcall *)(const void *))node_create(v14, v6);
v6 = (__int64 *)((char *)v6 + 4);
++v7;
}
while ( v6 != v14 );
v8 = branch_create(2LL, 4LL, &v15);
v19[0] = v5;
v19[1] = v8;
v9 = branch_create(0LL, 2LL, v19);
v10 = behaviourtree_create(v9);
v18 = 1;
for ( i = 0; i != 10; ++i )
{
printf(">>> behaviourtree_tick %d\n", i);
behaviourtree_tick(v10, &v18);
}
putchar(10);
behaviourtree_tick(v10, &v18);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    behaviourtree_init();
    void *priority_checking_node = 0;
    void *random_running_node = 0;
    {
        void *standing_node = 0;
        void *looking_node = 0;
        {
            struct node_callbacks standing_cbs = {
                .enter = standing_enter,
                .tick = standing_tick,
                .exit = standing_exit
            };
            int standing_count = 0;
            standing_node = node_create(&standing_cbs, &standing_count);
        }
        {
            struct node_callbacks looking_cbs = {
                .enter = looking_enter,
                .tick = looking_tick,
                .exit = looking_exit
            };
            looking_node = node_create(&looking_cbs, 0);
        }
        void *node_list[2] = { standing_node, looking_node };
        priority_checking_node = branch_create(BRANCH_TYPE_PRIORITY, 2, node_list);
    }
    {
        struct node_callbacks running_cbs = {
            .enter = running_enter,
            .tick = running_tick,
            .exit = running_exit
        };
        int running_dir[4] = { DIR_S, DIR_W, DIR_E, DIR_N };
        void *running_node[4];
        int i = 0;
        for (; i < 4; ++i)
        {
            running_node[i] = node_create(&running_cbs, &running_dir[i]);
        }
        random_running_node = branch_create(BRANCH_TYPE_RANDOM, 4, running_node);
    }
    void *node_list[2] = { priority_checking_node, random_running_node };
    void *branch = branch_create(BRANCH_TYPE_SEQUENCE, 2, node_list);
    void *tree = behaviourtree_create(branch);
    int ctx = 1;
    int tick = 0;
    for (tick = 0; tick < 10; ++tick)
    {
        printf(">>> behaviourtree_tick %d\n", tick);
        behaviourtree_tick(tree, (void *)&ctx);
    }
    printf("\n");
    behaviourtree_tick(tree, (void *)&ctx);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); }

variable_types: i int

variable_types:
branch
void *

variable_types:
tree
void *

variable_types: ctx int

variable_types: tick int

user_defined_types: struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); }


decompiled_code:
__int64 __fastcall node_running(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (**(__int64 (***)(void))(*(_QWORD *)v1 + 8LL))();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (**(__int64 (***)(void))(*(_QWORD *)v1 + 8LL))();
return result;
}

original_code:
void node_running(void *node)
{
    struct node* this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->running(this->control); } while(0);
    }
}

canonical_original_code:
void node_running(void *node)
{
    struct node *this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->running(this->control); } while(0);
    }
}

variable_types: struct node { struct node_vtable { struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); } *cbs; struct node_operations *ops; void (*release)(void *node); } *vtable; struct node *control; void *object; void *blackboard; } *

user_defined_types: struct node { struct node_vtable *vtable; struct node *control; void *object; void *blackboard; }

user_defined_types: struct node_vtable { struct node_callbacks *cbs; struct node_operations *ops; void (*release)(void *node); }


decompiled_code:
__int64 __fastcall node_success(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 8LL))();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 8LL))();
return result;
}

original_code:
void node_success(void *node)
{
    struct node* this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->success(this->control); } while(0);
    }
}

canonical_original_code:
void node_success(void *node)
{
    struct node *this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->success(this->control); } while(0);
    }
}


decompiled_code:
__int64 __fastcall node_fail(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 16LL))();
return result;
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 16LL))();
return result;
}

original_code:
void node_fail(void *node)
{
    struct node* this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->fail(this->control); } while(0);
    }
}

canonical_original_code:
void node_fail(void *node)
{
    struct node *this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->fail(this->control); } while(0);
    }
}


original_code:
void branch_enter(void *node, void *object, struct node_operations *ops)
{
    struct branch *this = node;
    if (!this->is_running)
    {
        this->node.object = object;
        this->running_idx = 0;
    }
}

variable_types: struct branch { struct node { struct node_vtable { struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); } *cbs; struct node_operations *ops; void (*release)(void *node); } *vtable; struct node *control; void *object; void *blackboard; } node; char is_running; int running_idx; int child_num; struct node *child_list[]; } *

user_defined_types: struct branch { struct node node; char is_running; int running_idx; int child_num; struct node *child_list[]; }


decompiled_code:
void branch_exit()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void branch_exit(void *node, void *object, struct node_operations *ops)
{
}


original_code:
void branch_running(void *node)
{
    struct branch *this = node;
    this->is_running = 1;
    do { this->node.control->vtable->ops->running(this->node.control); } while(0);
}


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

result = node_running(a1);
*(_BYTE *)(a1 + 40) = 0;
return result;
}

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

result = func0(a1);
*(_BYTE *)(a1 + 40) = 0;
return result;
}

original_code:
void behaviourtree_running(void *bt)
{
    struct behaviourtree *this = (struct behaviourtree *)bt;
    node_running((struct node *)this);
    this->started = 0;
}

variable_types:
bt
void *

variable_types: struct behaviourtree { struct node { struct node_vtable { struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); } *cbs; struct node_operations *ops; void (*release)(void *node); } *vtable; struct node *control; void *object; void *blackboard; } node; struct branch { struct node node; char is_running; int running_idx; int child_num; struct node *child_list[]; } *root; char started; } *

user_defined_types: struct behaviourtree { struct node node; struct branch *root; char started; }


original_code:
void behaviourtree_success(void *bt)
{
    struct behaviourtree *this = (struct behaviourtree *)bt;
    do { (&this->root->node)->vtable->cbs->exit((&this->root->node), this->node.object, (&this->root->node)->control->vtable->ops); } while(0);
    this->started = 0;
    node_success((struct node *)this);
}


original_code:
void behaviourtree_fail(void *bt)
{
    struct behaviourtree *this = (struct behaviourtree *)bt;
    do { (&this->root->node)->vtable->cbs->exit((&this->root->node), this->node.object, (&this->root->node)->control->vtable->ops); } while(0);
    this->started = 0;
    node_fail((struct node *)this);
}


decompiled_code:
int __fastcall random_enter(__int64 a1, __int64 a2)
{
unsigned int v2; // edx

branch_enter(a1, a2);
v2 = (int)random() % *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 36) = v2;
return printf(">>> random_enter running_idx %d\n", v2);
}

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

func3(a1, a2);
v2 = (int)random() % *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 36) = v2;
return printf(">>> random_enter running_idx %d\n", v2);
}

original_code:
void random_enter(void *node, void *object, struct node_operations *ops)
{
    struct branch *this = node;
    branch_enter(this, object, ops);
    int rand = random();
    this->running_idx = rand % this->child_num;
    printf(">>> random_enter running_idx %d\n", this->running_idx);
}

variable_types: rand int


decompiled_code:
__int64 __fastcall node_release(__int64 a1)
{
return (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)a1 + 16LL))(a1);
}

original_code:
void node_release(struct node *this)
{
    this->vtable->release(this);
}


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

if ( *((int *)ptr + 10) > 0 )
{
v1 = 0LL;
do
node_release(*((_QWORD *)ptr + v1++ + 6));
while ( *((_DWORD *)ptr + 10) > (int)v1 );
}
free(ptr);
}

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

if ( *((int *)ptr + 10) > 0 )
{
v1 = 0LL;
do
func10(*((_QWORD *)ptr + v1++ + 6));
while ( *((_DWORD *)ptr + 10) > (int)v1 );
}
free(ptr);
}

original_code:
void branch_release(void *node)
{
    struct branch *this = node;
    int i = 0;
    for (; i < this->child_num; ++i)
    {
        struct node *running_node = this->child_list[i];
        node_release(running_node);
    }
    free(this);
}

variable_types:
node
void *


decompiled_code:
void __fastcall behaviourtree_release(void *ptr)
{
node_release(*((_QWORD *)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
func10(*((_QWORD *)ptr + 4));
free(ptr);
}

original_code:
void behaviourtree_release(void *bt)
{
    struct behaviourtree *this = bt;
    node_release((struct node *)this->root);
    free(this);
}


original_code:
void node_callrun(struct node *this, void *object)
{
    this->vtable->cbs->tick(this, object, this->vtable->ops);
}

variable_types:
object
void *


original_code:
void branch_run(struct branch *this, void *object)
{
    struct node *running_node = this->child_list[this->running_idx];
    if (!this->is_running)
    {
        do { running_node->vtable->cbs->enter(running_node, object, running_node->control->vtable->ops); } while(0);
    }
    do { running_node->vtable->cbs->tick(running_node, object, running_node->control->vtable->ops); } while(0);
}


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

result = *(unsigned int *)(a1 + 40);
if ( *(_DWORD *)(a1 + 36) < (int)result )
result = branch_run(a1, a2);
return result;
}

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

result = *(unsigned int *)(a1 + 40);
if ( *(_DWORD *)(a1 + 36) < (int)result )
result = func14(a1, a2);
return result;
}

original_code:
void branch_tick(void *node, void *object, struct node_operations *ops)
{
    struct branch *this = node;
    if (this->running_idx < this->child_num)
    {
        branch_run(this, object);
    }
}

variable_types: struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *


original_code:
void branch_success(void *node)
{
    struct branch *this = node;
    this->is_running = 0;
    struct node *running_node = this->child_list[this->running_idx];
    do { running_node->vtable->cbs->exit(running_node, this->node.object, running_node->control->vtable->ops); } while(0);
}


decompiled_code:
__int64 __fastcall sequence_success(__int64 a1)
{
int v1; // eax
__int64 result; // rax

branch_success(a1);
v1 = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = v1;
if ( v1 < *(_DWORD *)(a1 + 40) )
result = branch_run(a1, *(_QWORD *)(a1 + 16));
else
result = (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 8LL))();
return result;
}

original_code:
void sequence_success(void *node)
{
    struct branch *this = node;
    branch_success(this);
    this->running_idx++;
    if (this->running_idx < this->child_num)
    {
        branch_run(this, this->node.object);
    }
    else
    {
        do { this->node.control->vtable->ops->success(this->node.control); } while(0);
    }
}


decompiled_code:
__int64 __fastcall random_success(__int64 a1)
{
branch_success(a1);
return (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 8LL))();
}

original_code:
void random_success(void *node)
{
    struct branch *this = node;
    branch_success(this);
    do { this->node.control->vtable->ops->success(this->node.control); } while(0);
}


decompiled_code:
__int64 __fastcall priority_success(__int64 a1)
{
branch_success(a1);
return (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 8LL))();
}

original_code:
void priority_success(void *node)
{
    struct branch *this = node;
    branch_success(this);
    do { this->node.control->vtable->ops->success(this->node.control); } while(0);
}


original_code:
void branch_fail(void *node)
{
    struct branch *this = node;
    this->is_running = 0;
    struct node *running_node = this->child_list[this->running_idx];
    do { running_node->vtable->cbs->exit(running_node, this->node.object, running_node->control->vtable->ops); } while(0);
}


decompiled_code:
__int64 __fastcall sequence_fail(__int64 a1)
{
branch_fail(a1);
return (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 16LL))();
}

original_code:
void sequence_fail(void *node)
{
    struct branch *this = node;
    branch_fail(this);
    do { this->node.control->vtable->ops->fail(this->node.control); } while(0);
}


original_code:
void random_fail(void *node)
{
    struct branch *this = node;
    branch_fail(this);
    do { this->node.control->vtable->ops->fail(this->node.control); } while(0);
}


decompiled_code:
__int64 __fastcall priority_fail(__int64 a1)
{
int v1; // eax
__int64 result; // rax

branch_fail(a1);
v1 = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = v1;
if ( v1 < *(_DWORD *)(a1 + 40) )
result = branch_run(a1, *(_QWORD *)(a1 + 16));
else
result = (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 16LL))();
return result;
}

original_code:
void priority_fail(void *node)
{
    struct branch *this = node;
    branch_fail(this);
    this->running_idx++;
    if (this->running_idx < this->child_num)
    {
        branch_run(this, this->node.object);
    }
    else
    {
        do { this->node.control->vtable->ops->fail(this->node.control); } while(0);
    }
}


original_code:
void behaviourtree_tick(void *bt, void *object)
{
    if (bt == 0) return;
    struct behaviourtree *this = (struct behaviourtree *)bt;
    if (this->started)
    {
        node_running(&this->node);
    }
    else
    {
        this->started = 1;
        this->node.object = object;
        do { (&this->root->node)->vtable->cbs->enter((&this->root->node), object, (&this->root->node)->control->vtable->ops); } while(0);
        node_callrun(&this->root->node, object);
    }
}


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

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

original_code:
void *node_control(void *node)
{
    struct node *this = node;
    return this->control;
}


decompiled_code:
__int64 __fastcall node_blackboard(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
void *node_blackboard(void *node)
{
    struct node *this = node;
    return this->blackboard;
}


decompiled_code:
int __fastcall example_enter(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_enter %p %d\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_enter %p %d\n", a1, v2);
}

original_code:
void example_enter(void *node, void *object, struct node_operations *ops)
{
    int *ctx = (int *)object;
    *ctx = *ctx + 1;
    printf("example_enter %p %d\n", node, *ctx);
}

variable_types:
ctx
int *


decompiled_code:
int __fastcall example_exit(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_exit %p %d\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_exit %p %d\n", a1, v2);
}

original_code:
void example_exit(void *node, void *object, struct node_operations *ops)
{
    int *ctx = (int *)object;
    *ctx = *ctx + 1;
    printf("example_exit %p %d\n", node, *ctx);
}


decompiled_code:
__int64 __fastcall example_tick(const void *a1, int *a2, __int64 (__fastcall **a3)(__int64))
{
__int64 v4; // rdx
__int64 (__fastcall *v5)(__int64); // rbp
__int64 v6; // rax
__int64 result; // rax
__int64 (__fastcall *v8)(__int64); // rbp
__int64 v9; // rax

v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
printf("example_tick %p %d\n", a1, v4);
if ( (const void *)node_list == a1 )
{
v8 = a3[2];
v9 = node_control(a1);
result = v8(v9);
}
else
{
if ( *a2 > 9 )
v5 = a3[1];
else
v5 = *a3;
v6 = node_control(a1);
result = v5(v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1, int *a2, __int64 (__fastcall **a3)(__int64))
{
__int64 v4; // rdx
__int64 (__fastcall *v5)(__int64); // rbp
__int64 v6; // rax
__int64 result; // rax
__int64 (__fastcall *v8)(__int64); // rbp
__int64 v9; // rax

v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
printf("example_tick %p %d\n", a1, v4);
if ( (const void *)node_list == a1 )
{
v8 = a3[2];
v9 = node_control(a1);
result = v8(v9);
}
else
{
if ( *a2 > 9 )
v5 = a3[1];
else
v5 = *a3;
v6 = node_control(a1);
result = v5(v6);
}
return result;
}

original_code:
void example_tick(void *node, void *object, struct node_operations *ops)
{
    int *ctx = (int *)object;
    *ctx = *ctx + 1;
    printf("example_tick %p %d\n", node, *ctx);
    if (node == node_list[0])
    {
        ops->fail(node_control(node));
        return;
    }
    if (*ctx < 10) ops->running(node_control(node));
    else ops->success(node_control(node));
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // r12
const void *v4; // rax
__int64 v5; // rax
__int64 v6; // rbp
unsigned int j; // ebx
int v9; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v10[7]; // [rsp+10h] [rbp-38h] BYREF

behaviourtree_init(argc, argv, envp);
v10[0] = (__int64)example_enter;
v10[1] = (__int64)example_tick;
v10[2] = (__int64)example_exit;
for ( i = 0LL; i != 3; ++i )
{
node_list = node_create(v10, 0LL);
printf(">>> node_create %d %p\n", 0LL, (const void *)node_list);
v4 = (const void *)node_create(v10, 0LL);
*(&node_list + 1) = (__int64)v4;
printf(">>> node_create %d %p\n", 1LL, v4);
putchar(10);
v5 = branch_create((unsigned int)i, 2LL, &node_list);
v6 = behaviourtree_create(v5);
printf(">>> branch_type %s\n", BRANCH_NAME_0[i]);
v9 = 1;
for ( j = 0; j != 10; ++j )
{
printf(">>> behaviourtree_tick %d\n", j);
behaviourtree_tick(v6, &v9);
}
putchar(10);
behaviourtree_release(v6);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    behaviourtree_init();
    struct node_callbacks example_cbs = {
        .enter = example_enter,
        .tick = example_tick,
        .exit = example_exit
    };
    int begin_type = BRANCH_TYPE_BEGIN;
    int end_type = BRANCH_TYPE_COUNT;
    int running_type = begin_type;
    for (; running_type < end_type; ++running_type)
    {
        int i = 0;
        for (i = 0; i < 2; ++i)
        {
            node_list[i] = node_create(&example_cbs, 0);
            printf(">>> node_create %d %p\n", i, node_list[i]);
        }
        printf("\n");
        void *branch = branch_create(running_type, 2, node_list);
        void *tree = behaviourtree_create(branch);
        static const char *BRANCH_NAME[3] = { "SEQUENCE", "PRIORITY", "RANDOM" };
        printf(">>> branch_type %s\n", BRANCH_NAME[running_type]);
        int ctx = 1;
        int tick = 0;
        for (tick = 0; tick < 10; ++tick)
        {
            printf(">>> behaviourtree_tick %d\n", tick);
            behaviourtree_tick(tree, (void *)&ctx);
        }
        printf("\n");
        behaviourtree_release(tree);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    behaviourtree_init();
    struct node_callbacks example_cbs = {
        .enter = example_enter,
        .tick = example_tick,
        .exit = example_exit
    };
    int begin_type = BRANCH_TYPE_BEGIN;
    int end_type = BRANCH_TYPE_COUNT;
    int running_type = begin_type;
    for (; running_type < end_type; ++running_type)
    {
        int i = 0;
        for (i = 0; i < 2; ++i)
        {
            node_list[i] = node_create(&example_cbs, 0);
            printf(">>> node_create %d %p\n", i, node_list[i]);
        }
        printf("\n");
        void *branch = branch_create(running_type, 2, node_list);
        void *tree = behaviourtree_create(branch);
        static char *BRANCH_NAME[3] = { "SEQUENCE", "PRIORITY", "RANDOM" };
        printf(">>> branch_type %s\n", BRANCH_NAME[running_type]);
        int ctx = 1;
        int tick = 0;
        for (tick = 0; tick < 10; ++tick)
        {
            printf(">>> behaviourtree_tick %d\n", tick);
            behaviourtree_tick(tree, (void *)&ctx);
        }
        printf("\n");
        behaviourtree_release(tree);
    }
    return 0;
}

variable_types: argc int


fib

decompiled_code:
__int64 __fastcall fib(unsigned int a1)
{
__int64 result; // rax
int v2; // ebp

result = 1LL;
if ( a1 > 1 )
{
v2 = fib(a1 - 1);
result = v2 + (unsigned int)fib(a1 - 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 result; // rax
int v2; // ebp

result = 1LL;
if ( a1 > 1 )
{
v2 = func6(a1 - 1);
result = v2 + (unsigned int)func6(a1 - 2);
}
return result;
}

original_code:
unsigned int fib(unsigned int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    return fib(n-1) + fib(n-2);
}

variable_types:
n
unsigned int


main

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

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


repo: ivoarch/antiwm

decompiled_code:
void alrm_handler()
{
__int64 v0; // rbp
int v1; // ebx

puts("alarm recieved");
if ( num_screens > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
hide_bar(screens + v0);
++v1;
v0 += 200LL;
}
while ( num_screens > v1 );
}
XFlush(dpy);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbp
int v1; // ebx

puts("alarm recieved");
if ( num_screens > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
hide_bar(screens + v0);
++v1;
v0 += 200LL;
}
while ( num_screens > v1 );
}
XFlush(dpy);
}

original_code:
void
alrm_handler ()
{
  int i;
  printf ("alarm recieved\n");
  for (i=0; i<num_screens; i++)
    {
      hide_bar (&screens[i]);
    }
  XFlush (dpy);
}

canonical_original_code:
void alrm_handler()
{
  int i;
  printf ("alarm recieved\n");
  for (i=0; i<num_screens; i++)
    {
      hide_bar (&screens[i]);
    }
  XFlush (dpy);
}


decompiled_code:
int clean_up()
{
XSync(dpy, 0);
XSetInputFocus(dpy, 1uLL, 1, 0LL);
return XCloseDisplay(dpy);
}

canonical_decompiled_code:
int func3()
{
XSync(dpy, 0);
XSetInputFocus(dpy, 1uLL, 1, 0LL);
return XCloseDisplay(dpy);
}

original_code:
void
clean_up ()
{
  XSync(dpy, 0);
  XSetInputFocus (dpy, 1L, (int)1L, 0L);
  XCloseDisplay (dpy);
}

canonical_original_code:
void clean_up()
{
  XSync(dpy, 0);
  XSetInputFocus (dpy, 1L, (int)1L, 0L);
  XCloseDisplay (dpy);
}


sighandler

decompiled_code:
void __noreturn sighandler()
{
fwrite("antiwm: sighander failure\n", 1uLL, 0x1AuLL, stderr);
clean_up();
exit(1);
}

canonical_decompiled_code:
void __noreturn func4()
{
fwrite("antiwm: sighander failure\n", 1uLL, 0x1AuLL, stderr);
func3();
exit(1);
}

original_code:
void
sighandler ()
{
  fprintf (stderr, "antiwm: sighander failure\n");
  clean_up ();
  exit (1);
}

canonical_original_code:
void sighandler()
{
  fprintf (stderr, "antiwm: sighander failure\n");
  clean_up ();
  exit (1);
}


decompiled_code:
void hup_handler()
{
fwrite("antiwm: restarting\n", 1uLL, 0x13uLL, stderr);
clean_up();
execvp(*myargv, myargv);
}

canonical_decompiled_code:
void func5()
{
fwrite("antiwm: restarting\n", 1uLL, 0x13uLL, stderr);
func3();
execvp(*myargv, myargv);
}

original_code:
void
hup_handler ()
{
  fprintf (stderr, "antiwm: restarting\n");
  clean_up ();
  execvp(myargv[0], myargv);
}

canonical_original_code:
void hup_handler()
{
  fprintf (stderr, "antiwm: restarting\n");
  clean_up ();
  execvp(myargv[0], myargv);
}


decompiled_code:
void init_window_list()
{
a_window_tail = 0LL;
a_window_head = 0LL;
a_current_window = 0LL;
}

canonical_decompiled_code:
void func3()
{
a_window_tail = 0LL;
a_window_head = 0LL;
a_current_window = 0LL;
}

original_code:
void
init_window_list ()
{
  a_window_head = a_window_tail = ((void *)0);
  a_current_window = ((void *)0);
}

canonical_original_code:
void init_window_list()
{
  a_window_head = a_window_tail = ((void *)0);
  a_current_window = ((void *)0);
}


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

result = a_current_window;
if ( a_current_window )
{
a_current_window = *(_QWORD *)(a_current_window + 32);
if ( !a_current_window )
a_current_window = a_window_head;
if ( !*(_DWORD *)(a_current_window + 24) )
next_window();
result = set_active_window((_QWORD *)a_current_window);
}
return result;
}

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

result = a_current_window;
if ( a_current_window )
{
a_current_window = *(_QWORD *)(a_current_window + 32);
if ( !a_current_window )
a_current_window = a_window_head;
if ( !*(_DWORD *)(a_current_window + 24) )
func7();
result = func6((_QWORD *)a_current_window);
}
return result;
}

original_code:
void
next_window ()
{
  if (a_current_window != ((void *)0))
    {
      a_current_window = a_current_window->next;
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_head;
 }
      if (a_current_window->state == 0) next_window ();
      set_active_window (a_current_window);
    }
}

canonical_original_code:
void next_window()
{
  if (a_current_window != ((void *)0))
    {
      a_current_window = a_current_window->next;
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_head;
 }
      if (a_current_window->state == 0) next_window ();
      set_active_window (a_current_window);
    }
}


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

result = a_current_window;
if ( a_current_window )
{
set_current_window(*(_QWORD *)(a_current_window + 40));
if ( !a_current_window )
a_current_window = a_window_tail;
if ( !*(_DWORD *)(a_current_window + 24) )
prev_window();
result = set_active_window((_QWORD *)a_current_window);
}
return result;
}

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

result = a_current_window;
if ( a_current_window )
{
func2(*(_QWORD *)(a_current_window + 40));
if ( !a_current_window )
a_current_window = a_window_tail;
if ( !*(_DWORD *)(a_current_window + 24) )
func9();
result = func6((_QWORD *)a_current_window);
}
return result;
}

original_code:
void
prev_window ()
{
  if (a_current_window != ((void *)0))
    {
      set_current_window (a_current_window->prev);
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_tail;
 }
      if (a_current_window->state == 0) prev_window ();
      set_active_window (a_current_window);
    }
}

canonical_original_code:
void prev_window()
{
  if (a_current_window != ((void *)0))
    {
      set_current_window (a_current_window->prev);
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_tail;
 }
      if (a_current_window->state == 0) prev_window ();
      set_active_window (a_current_window);
    }
}


decompiled_code:
__int64 last_window()
{
a_current_window = find_last_accessed_window();
return set_active_window((_QWORD *)a_current_window);
}

canonical_decompiled_code:
__int64 func10()
{
a_current_window = func5();
return func6((_QWORD *)a_current_window);
}

original_code:
void
last_window ()
{
  a_current_window = find_last_accessed_window ();
  set_active_window (a_current_window);
}

canonical_original_code:
void last_window()
{
  a_current_window = find_last_accessed_window ();
  set_active_window (a_current_window);
}


spawn

decompiled_code:
int __fastcall spawn(char *arg)
{
if ( !fork() )
{
if ( fork() )
exit(0);
putenv(dpy->display_name);
execlp(arg, arg, 0LL);
fprintf(stderr, "antiwm: exec %s ", arg);
perror(" failed");
exit(1);
}
wait(0LL);
return printf("spawned %s\n", arg);
}

canonical_decompiled_code:
int __fastcall func1(char *arg)
{
if ( !fork() )
{
if ( fork() )
exit(0);
putenv(dpy->display_name);
execlp(arg, arg, 0LL);
fprintf(stderr, "antiwm: exec %s ", arg);
perror(" failed");
exit(1);
}
wait(0LL);
return printf("spawned %s\n", arg);
}

original_code:
void
spawn(char *prog)
{
  if (fork() == 0) {
    if (fork() == 0) {
      putenv((((_XPrivDisplay)(dpy))->display_name));
      execlp(prog, prog, (char *)((void *)0));
      fprintf(stderr, "antiwm: exec %s ", prog);
      perror(" failed");
      exit(1);
    }
    exit(0);
  }
  wait((int *) 0);
  printf ("spawned %s\n", prog);
}

variable_types:
prog
char *


decompiled_code:
int __fastcall grab_prefix_key(Window a1)
{
KeyCode v1; // al

v1 = XKeysymToKeycode(dpy, 0x74uLL);
return XGrabKey(dpy, v1, 4u, a1, 1, 1, 1);
}

canonical_decompiled_code:
int __fastcall func0(Window a1)
{
KeyCode v1; // al

v1 = XKeysymToKeycode(dpy, 0x74uLL);
return XGrabKey(dpy, v1, 4u, a1, 1, 1, 1);
}

original_code:
static void
grab_prefix_key (Window w)
{
  XGrabKey(dpy, XKeysymToKeycode (dpy, 't' ), (1<<2), w, 1,
    1, 1);
}

canonical_original_code:
static void grab_prefix_key(unsigned long w)
{
  XGrabKey(dpy, XKeysymToKeycode (dpy, 't' ), (1<<2), w, 1,
    1, 1);
}

variable_types:
w
unsigned long


repo: ivokub/huffkub

decompiled_code:
int __fastcall parse_args(int argc, char **argv)
{
int result; // eax

opts = 0;
while ( 1 )
{
result = getopt(argc, argv, "cxiof:d:hv");
if ( result == -1 )
return result;
switch ( result )
{
case 'c':
if ( (opts & 2) != 0 )
{
error(2, 0, "-c and -x are exclusive");
LABEL_7:
if ( (opts & 1) != 0 )
{
error(2, 0, "-c and -x are exclusive");
LABEL_10:
if ( (opts & 0x10) != 0 )
{
error(2, 0, "-f and -i are exclusive");
LABEL_13:
if ( (opts & 0x20) != 0 )
{
error(2, 0, "-d and -o are exclusive");
LABEL_16:
if ( (opts & 4) != 0 )
{
error(2, 0, "-f and -i are exclusive");
LABEL_19:
if ( (opts & 8) != 0 )
{
error(2, 0, "-d and -o are exclusive");
LABEL_22:
opts |= 0x40u;
}
else
{
opts |= 0x20u;
strncpy(outputfile, optarg, 0x80uLL);
}
}
else
{
opts |= 0x10u;
strncpy(inputfile, optarg, 0x80uLL);
}
}
else
{
opts |= 8u;
}
}
else
{
opts |= 4u;
}
}
else
{
opts |= 2u;
}
}
else
{
opts |= 1u;
}
break;
case 'd':
goto LABEL_19;
case 'f':
goto LABEL_16;
case 'i':
goto LABEL_10;
case 'o':
goto LABEL_13;
case 'v':
goto LABEL_22;
case 'x':
goto LABEL_7;
default:
puts(
"Simple file packer using Huffman algorithm.\n"
"\n"
"Usage:\thuffkub [-c] [-x] [-i] [-o] [-f inputfile] [-d outputfile]\n"
"\n"
"Argument usage:\n"
"\t -c\t\tPack (exclusive with -x)\n"
"\t -x\t\tUnpack (exclusive with -c)\n"
"\t -i\t\tRead input from stdin (exclusive with -f)\n"
"\t -o\t\tWrite output to stdout (exclusive with -d)\n"
"\t -f FILE\tRead input from FILE (exclusive with -i)\n"
"\t -d FILE\tWrite output to FILE (exclusive with -o)\n"
"\t -v\t\tVerbose output (only when -o is not set)\n"
"\t -h\t\tPrint this help message");
exit(0);
}
}
}

canonical_decompiled_code:
int __fastcall func0(int argc, char **argv)
{
int result; // eax

opts = 0;
while ( 1 )
{
result = getopt(argc, argv, "cxiof:d:hv");
if ( result == -1 )
return result;
switch ( result )
{
case 'c':
if ( (opts & 2) != 0 )
{
error(2, 0, "-c and -x are exclusive");
LABEL_7:
if ( (opts & 1) != 0 )
{
error(2, 0, "-c and -x are exclusive");
LABEL_10:
if ( (opts & 0x10) != 0 )
{
error(2, 0, "-f and -i are exclusive");
LABEL_13:
if ( (opts & 0x20) != 0 )
{
error(2, 0, "-d and -o are exclusive");
LABEL_16:
if ( (opts & 4) != 0 )
{
error(2, 0, "-f and -i are exclusive");
LABEL_19:
if ( (opts & 8) != 0 )
{
error(2, 0, "-d and -o are exclusive");
LABEL_22:
opts |= 0x40u;
}
else
{
opts |= 0x20u;
strncpy(outputfile, optarg, 0x80uLL);
}
}
else
{
opts |= 0x10u;
strncpy(inputfile, optarg, 0x80uLL);
}
}
else
{
opts |= 8u;
}
}
else
{
opts |= 4u;
}
}
else
{
opts |= 2u;
}
}
else
{
opts |= 1u;
}
break;
case 'd':
goto LABEL_19;
case 'f':
goto LABEL_16;
case 'i':
goto LABEL_10;
case 'o':
goto LABEL_13;
case 'v':
goto LABEL_22;
case 'x':
goto LABEL_7;
default:
puts(
"Simple file packer using Huffman algorithm.\n"
"\n"
"Usage:\thuffkub [-c] [-x] [-i] [-o] [-f inputfile] [-d outputfile]\n"
"\n"
"Argument usage:\n"
"\t -c\t\tPack (exclusive with -x)\n"
"\t -x\t\tUnpack (exclusive with -c)\n"
"\t -i\t\tRead input from stdin (exclusive with -f)\n"
"\t -o\t\tWrite output to stdout (exclusive with -d)\n"
"\t -f FILE\tRead input from FILE (exclusive with -i)\n"
"\t -d FILE\tWrite output to FILE (exclusive with -o)\n"
"\t -v\t\tVerbose output (only when -o is not set)\n"
"\t -h\t\tPrint this help message");
exit(0);
}
}
}

original_code:
void parse_args(int argc, char **argv) {
 opts = 0;
 int opt;
 while ((opt = getopt(argc, argv, "cxiof:d:hv")) != -1) {
  switch (opt) {
  case 'c':
   if (opts & 0x2)
    error(2, 0, "-c and -x are exclusive");
   opts |= 0x1;
   break;
  case 'x':
   if (opts & 0x1)
    error(2, 0, "-c and -x are exclusive");
   opts |= 0x2;
   break;
  case 'i':
   if (opts & 0x10)
    error(2, 0, "-f and -i are exclusive");
   opts |= 0x4;
   break;
  case 'o':
   if (opts & 0x20)
    error(2, 0, "-d and -o are exclusive");
   opts |= 0x8;
   break;
  case 'f':
   if (opts & 0x4)
    error(2, 0, "-f and -i are exclusive");
   opts |= 0x10;
   strncpy(inputfile, optarg, 128);
   break;
  case 'd':
   if (opts & 0x8)
    error(2, 0, "-d and -o are exclusive");
   opts |= 0x20;
   strncpy(outputfile, optarg, 128);
   break;
  case 'v':
   opts |= 0x40;
   break;
  case 'h':
  default:
   printf("Simple file packer using Huffman algorithm.\n\n"
    "Usage:\thuffkub [-c] [-x] [-i] [-o] [-f inputfile] [-d outputfile]\n\n"
    "Argument usage:\n\t -c\t\tPack (exclusive with -x)\n"
    "\t -x\t\tUnpack (exclusive with -c)\n"
    "\t -i\t\tRead input from stdin (exclusive with -f)\n"
    "\t -o\t\tWrite output to stdout (exclusive with -d)\n"
    "\t -f FILE\tRead input from FILE (exclusive with -i)\n"
    "\t -d FILE\tWrite output to FILE (exclusive with -o)\n"
    "\t -v\t\tVerbose output (only when -o is not set)\n"
    "\t -h\t\tPrint this help message\n");
   exit(0);
  }
 }
}

variable_types:
argv
char **

variable_types: opt int


decompiled_code:
size_t verbose_print()
{
_QWORD *v0; // rbx
__int64 v1; // rax

fwrite("/*\nCHAR\tFREQ\tCODE\n", 1uLL, 0x12uLL, stderr);
v0 = &chararray;
do
{
if ( *v0 )
{
fprintf(stderr, "%c\t%d\t", *(unsigned __int8 *)(*v0 + 20LL), *(unsigned int *)(*v0 + 16LL));
v1 = calc_code(*v0);
print_code(v1);
}
++v0;
}
while ( v0 != (_QWORD *)(unsigned int)((_DWORD)&chararray + 2048) );
return fwrite("\n*/", 1uLL, 3uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
_QWORD *v0; // rbx
__int64 v1; // rax

fwrite("/*\nCHAR\tFREQ\tCODE\n", 1uLL, 0x12uLL, stderr);
v0 = &chararray;
do
{
if ( *v0 )
{
fprintf(stderr, "%c\t%d\t", *(unsigned __int8 *)(*v0 + 20LL), *(unsigned int *)(*v0 + 16LL));
v1 = calc_code(*v0);
print_code(v1);
}
++v0;
}
while ( v0 != (_QWORD *)(unsigned int)((_DWORD)&chararray + 2048) );
return fwrite("\n*/", 1uLL, 3uLL, stderr);
}

original_code:
void verbose_print() {
 int i = 0;
 fprintf(stderr, "/*\nCHAR\tFREQ\tCODE\n");
 for (i = 0; i < 256; i++) {
  if (chararray[i] != ((void *)0)) {
   fprintf(stderr, "%c\t%d\t", chararray[i]->ch, chararray[i]->freq);
   print_code(calc_code(chararray[i]));
  }
 }
 fprintf(stderr, "\n*/");
}

variable_types: i int