decompiled_code:
_BOOL8 __fastcall are_two_reports_active(__int64 a1, __int64 a2)
{
int v2; // er8
_BOOL8 result; // rax

v2 = equald(*(double *)(a1 + 8), *(double *)(a2 + 16), 0.0000001);
result = 0LL;
if ( !v2 )
result = (unsigned int)equald(*(double *)(a1 + 16), *(double *)(a2 + 16), 0.0000001) == 0;
return result;
}

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

v2 = equald(*(double *)(a1 + 8), *(double *)(a2 + 16), 0.0000001);
result = 0LL;
if ( !v2 )
result = (unsigned int)equald(*(double *)(a1 + 16), *(double *)(a2 + 16), 0.0000001) == 0;
return result;
}

original_code:
int are_two_reports_active(struct Report *aRep, struct Report *bRep)
{
 if(!equald(aRep->gPoint.x, bRep->gPoint.y, 1e-7)
 && !equald(aRep->gPoint.y, bRep->gPoint.y, 1e-7))
  return 1;
 return 0;
}

variable_types: struct Report { long timestamp; struct Point { double x; double y; } gPoint; short speed; short angle; char state; char msgType; double routeLeng; double gasVol; char errorInfo; char shown; struct Duallist { struct Item { void *datap; struct Item *prev; struct Item *next; } *head; unsigned long nItems; } candRoads; struct Item *onRoad; int onRoadId; struct Path { struct Duallist roads; double length; int turns; } *onPath; struct Trace { char vName[32]; char type; struct Duallist reports; struct Item *at; long startAt; long endAt; struct Box { double xmin; double ymin; double xmax; double ymax; } box; char onRoute[32]; double maxSpeed; double countdown; char isHeadingValid; union Int_RGBO { unsigned int integer; struct RGBO { unsigned char red; unsigned char green; unsigned char blue; unsigned char opacity; } rgbo; } color; double var1; double var2; double var3; struct Duallist transVecHistory; } *fromTrace; } *

variable_types:
bRep
struct Report *

user_defined_types: struct Report { long timestamp; struct Point gPoint; short speed; short angle; char state; char msgType; double routeLeng; double gasVol; char errorInfo; char shown; struct Duallist candRoads; struct Item *onRoad; int onRoadId; struct Path *onPath; struct Trace *fromTrace; }

user_defined_types: struct Trace { char vName[32]; char type; struct Duallist reports; struct Item *at; long startAt; long endAt; struct Box box; char onRoute[32]; double maxSpeed; double countdown; char isHeadingValid; union Int_RGBO color; double var1; double var2; double var3; struct Duallist transVecHistory; }

user_defined_types: union Int_RGBO { unsigned int integer; struct RGBO rgbo; }


zigset

repo: AltraVita/vanetcsim

variable_types:
jsrseed
unsigned long

variable_types: dn double

variable_types: tn double

variable_types: vn double

variable_types: q double

variable_types: de double

variable_types: te double

variable_types: ve double

variable_types: i int

return_type: void


simplePowPPM

repo: AmmarkoV/RGBDAcquisition

decompiled_code:
__int64 __fastcall simplePowPPM(unsigned int a1, int a2)
{
unsigned int v2; // er8
int v3; // esi
int i; // eax

v2 = 1;
if ( a2 )
{
v2 = a1;
v3 = a2 - 1;
if ( v3 )
{
for ( i = 0; i != v3; ++i )
v2 *= a1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
unsigned int v2; // er8
int v3; // esi
int i; // eax

v2 = 1;
if ( a2 )
{
v2 = a1;
v3 = a2 - 1;
if ( v3 )
{
for ( i = 0; i != v3; ++i )
v2 *= a1;
}
}
return v2;
}

original_code:
unsigned int simplePowPPM(unsigned int base,unsigned int exp)
{
    if (exp==0) return 1;
    unsigned int retres=base;
    unsigned int i=0;
    for (i=0; i<exp-1; i++)
    {
        retres*=base;
    }
    return retres;
}

canonical_original_code:
unsigned int simplePowPPM(unsigned int base, unsigned int exp)
{
    if (exp==0) return 1;
    unsigned int retres = base;
    unsigned int i = 0;
    for (i=0; i<exp-1; i++)
    {
        retres*=base;
    }
    return retres;
}

variable_types:
base
unsigned int

variable_types:
exp
unsigned int

variable_types:
retres
unsigned int

variable_types:
i
unsigned int

return_type: unsigned int


swapDepthEndianness

decompiled_code:
__int64 __fastcall swapDepthEndianness(__int64 a1)
{
char *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
char *i; // rdx
char v5; // cl
char v6; // si
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = *(char **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(unsigned int *)(a1 + 20);
v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v2 == 16 )
{
for ( i = &v1[(unsigned int)(2 * *(_DWORD *)(a1 + 12) * *(_DWORD *)(a1 + 8) * v3)]; i > v1; *(v1 - 1) = v5 )
{
v5 = *v1;
v6 = v1[1];
v1 += 2;
*(v1 - 2) = v6;
}
result = 1LL;
}
else
{
fprintf(stderr, "Only 16bit PNM files need swapping ( we have a %u bit x %u channels file )..\n", v2, v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
char *i; // rdx
char v5; // cl
char v6; // si
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = *(char **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(unsigned int *)(a1 + 20);
v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v2 == 16 )
{
for ( i = &v1[(unsigned int)(2 * *(_DWORD *)(a1 + 12) * *(_DWORD *)(a1 + 8) * v3)]; i > v1; *(v1 - 1) = v5 )
{
v5 = *v1;
v6 = v1[1];
v1 += 2;
*(v1 - 2) = v6;
}
result = 1LL;
}
else
{
fprintf(stderr, "Only 16bit PNM files need swapping ( we have a %u bit x %u channels file )..\n", v2, v3);
result = 0LL;
}
return result;
}

original_code:
int swapDepthEndianness(struct Image * img)
{
  if (img==0) { return 0; }
  if (img->pixels==0) { return 0; }
  if (img->bitsperpixel!=16) { fprintf(stderr,"Only 16bit PNM files need swapping ( we have a %u bit x %u channels file )..\n",img->bitsperpixel , img->channels); return 0; }
  unsigned char * traverser=(unsigned char * ) img->pixels;
  unsigned char * traverserSwap1;
  unsigned char * traverserSwap2;
  unsigned int bytesperpixel = (img->bitsperpixel/8);
  unsigned char * endOfMem = traverser + img->width * img->height * img->channels * bytesperpixel;
  while ( ( traverser < endOfMem) )
  {
    traverserSwap1 = traverser;
    traverserSwap2 = traverser+1;
    unsigned char tmp = *traverserSwap1;
    *traverserSwap1 = *traverserSwap2;
    *traverserSwap2 = tmp;
    traverser += bytesperpixel;
  }
 return 1;
}

canonical_original_code:
int swapDepthEndianness(struct Image *img)
{
  if (img==0) { return 0; }
  if (img->pixels==0) { return 0; }
  if (img->bitsperpixel!=16) { fprintf(stderr,"Only 16bit PNM files need swapping ( we have a %u bit x %u channels file )..\n",img->bitsperpixel , img->channels); return 0; }
  unsigned char *traverser = (unsigned char * ) img->pixels;
  unsigned char *traverserSwap1;
  unsigned char *traverserSwap2;
  unsigned int bytesperpixel = (img->bitsperpixel/8);
  unsigned char *endOfMem = traverser + img->width * img->height * img->channels * bytesperpixel;
  while ( ( traverser < endOfMem) )
  {
    traverserSwap1 = traverser;
    traverserSwap2 = traverser+1;
    unsigned char tmp = *traverserSwap1;
    *traverserSwap1 = *traverserSwap2;
    *traverserSwap2 = tmp;
    traverser += bytesperpixel;
  }
 return 1;
}

variable_types: struct Image { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int channels; unsigned int bitsperpixel; unsigned int image_size; unsigned long timestamp; } *

variable_types:
traverser
unsigned char *

variable_types:
bytesperpixel
unsigned int

variable_types:
endOfMem
unsigned char *

variable_types:
tmp
unsigned char

return_type: int


ReadPPM

decompiled_code:
_BOOL8 __fastcall ReadPPM(const char *a1, __int64 a2)
{
void *v2; // rax

v2 = ReadPNM(
*(void **)a2,
a1,
(unsigned int *)(a2 + 8),
(unsigned int *)(a2 + 12),
(_QWORD *)(a2 + 32),
(unsigned int *)(a2 + 20),
(unsigned int *)(a2 + 16));
*(_DWORD *)(a2 + 20) *= 8;
*(_QWORD *)a2 = v2;
return v2 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1, __int64 a2)
{
void *v2; // rax

v2 = func2(
*(void **)a2,
a1,
(unsigned int *)(a2 + 8),
(unsigned int *)(a2 + 12),
(_QWORD *)(a2 + 32),
(unsigned int *)(a2 + 20),
(unsigned int *)(a2 + 16));
*(_DWORD *)(a2 + 20) *= 8;
*(_QWORD *)a2 = v2;
return v2 != 0LL;
}

original_code:
int ReadPPM(const char * filename,struct Image * pic,char read_only_header)
{
  pic->pixels = ReadPNM(pic->pixels , filename, &pic->width, &pic->height, &pic->timestamp ,&pic->bitsperpixel , &pic->channels );
  pic->bitsperpixel = pic->bitsperpixel * 8;
  return (pic->pixels!=0);
}

canonical_original_code:
int ReadPPM(char *filename, struct Image *pic, char read_only_header)
{
  pic->pixels = ReadPNM(pic->pixels , filename, &pic->width, &pic->height, &pic->timestamp ,&pic->bitsperpixel , &pic->channels );
  pic->bitsperpixel = pic->bitsperpixel * 8;
  return (pic->pixels!=0);
}

variable_types:
filename
char *

user_defined_types: struct Image { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int channels; unsigned int bitsperpixel; unsigned int image_size; unsigned long timestamp; }


ReadSwappedPPM

decompiled_code:
_BOOL8 __fastcall ReadSwappedPPM(const char *a1, _QWORD *a2)
{
ReadPPM(a1, (__int64)a2);
swapDepthEndianness((__int64)a2);
return *a2 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, _QWORD *a2)
{
func3(a1, (__int64)a2);
func1((__int64)a2);
return *a2 != 0LL;
}

original_code:
int ReadSwappedPPM(const char * filename,struct Image * pic,char read_only_header)
{
  ReadPPM(filename,pic,read_only_header);
  swapDepthEndianness(pic);
  return (pic->pixels!=0);
}

canonical_original_code:
int ReadSwappedPPM(char *filename, struct Image *pic, char read_only_header)
{
  ReadPPM(filename,pic,read_only_header);
  swapDepthEndianness(pic);
  return (pic->pixels!=0);
}


WriteSwappedPPM

decompiled_code:
__int64 __fastcall WriteSwappedPPM(const char *a1, __int64 a2)
{
swapDepthEndianness(a2);
return WritePPM(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
func1(a2);
return func5(a1, a2);
}

original_code:
int WriteSwappedPPM(const char * filename,struct Image * pic)
{
   swapDepthEndianness(pic);
   return WritePPM(filename,pic);
}

canonical_original_code:
int WriteSwappedPPM(char *filename, struct Image *pic)
{
   swapDepthEndianness(pic);
   return WritePPM(filename,pic);
}


WriteJPEGFile

decompiled_code:
__int64 __fastcall WriteJPEGFile(_QWORD *a1, char *a2)
{
return WriteJPEGInternal(a2, a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, char *a2)
{
return func5(a2, a1, 0LL, 0LL);
}

original_code:
int WriteJPEGFile(struct Image * pic,char *filename)
{
    int quality = 75;
    return WriteJPEGInternal(filename,pic,0,0,quality);
}

canonical_original_code:
int WriteJPEGFile(struct Image *pic, char *filename)
{
    int quality = 75;
    return WriteJPEGInternal(filename,pic,0,0,quality);
}

variable_types: quality int


WriteJPEGMemory

decompiled_code:
__int64 __fastcall WriteJPEGMemory(_QWORD *a1, __int64 a2, __int64 *a3)
{
return WriteJPEGInternal(0LL, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2, __int64 *a3)
{
return func5(0LL, a1, a2, a3);
}

original_code:
int WriteJPEGMemory(struct Image * pic,char *mem,unsigned long * mem_size,int quality)
{
    return WriteJPEGInternal(0,pic,mem,mem_size,quality);
}

canonical_original_code:
int WriteJPEGMemory(struct Image *pic, char *mem, unsigned long *mem_size, int quality)
{
    return WriteJPEGInternal(0,pic,mem,mem_size,quality);
}

variable_types:
mem
char *


jpegtest

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

if ( (int)ReadJPEG("test.jpg", 0LL, 0) <= 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)WriteJPEGFile(0LL, "test_out.jpg") >> 31);
return result;
}

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

if ( (int)func4("test.jpg", 0LL, 0) <= 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)func6(0LL, "test_out.jpg") >> 31);
return result;
}

original_code:
int jpegtest()
{
 char *infilename = (char*) "test.jpg", *outfilename = (char*) "test_out.jpg";
 if( ReadJPEG( infilename , 0 , 0 ) > 0 )
 {
  if( WriteJPEGFile( 0 , outfilename ) < 0 ) return -1;
 }
 else return -1;
 return 0;
}

canonical_original_code:
int jpegtest()
{
 char *infilename = (char*) "test.jpg"; char *outfilename = (char*) "test_out.jpg";
 if( ReadJPEG( infilename , 0 , 0 ) > 0 )
 {
  if( WriteJPEGFile( 0 , outfilename ) < 0 ) return -1;
 }
 else return -1;
 return 0;
}

variable_types:
infilename
char *

variable_types:
outfilename
char *


decompiled_code:
__int64 read_2_bytes()
{
int v0; // eax
int v1; // ebx
int v2; // eax
__int64 result; // rax

v0 = getc(myfile);
if ( v0 == -1 || (v1 = v0, v2 = getc(myfile), v2 == -1) )
result = 0LL;
else
result = (unsigned int)((v1 << 8) + v2);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // ebx
int v2; // eax
__int64 result; // rax

v0 = getc(myfile);
if ( v0 == -1 || (v1 = v0, v2 = getc(myfile), v2 == -1) )
result = 0LL;
else
result = (unsigned int)((v1 << 8) + v2);
return result;
}

original_code:
static unsigned int
read_2_bytes (void)
{
  int c1, c2;
  c1 = getc(myfile);
  if (c1 == (-1)) { read_byte_error_while_reading=1; return 0; }
  c2 = getc(myfile);
  if (c2 == (-1)) { read_byte_error_while_reading=1; return 0; }
  return (((unsigned int) c1) << 8) + ((unsigned int) c2);
}

canonical_original_code:
static unsigned int read_2_bytes()
{
  int c1; int c2;
  c1 = getc(myfile);
  if (c1 == (-1)) { read_byte_error_while_reading=1; return 0; }
  c2 = getc(myfile);
  if (c2 == (-1)) { read_byte_error_while_reading=1; return 0; }
  return (((unsigned int) c1) << 8) + ((unsigned int) c2);
}


decompiled_code:
int read_1_byte()
{
int result; // eax

result = getc(myfile);
if ( result == -1 )
result = 0;
return result;
}

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

result = getc(myfile);
if ( result == -1 )
result = 0;
return result;
}

original_code:
static int
read_1_byte (void)
{
  int c;
  c = getc(myfile);
  if (c == (-1)) { read_byte_error_while_reading=1; return 0; }
  return c;
}

canonical_original_code:
static int read_1_byte()
{
  int c;
  c = getc(myfile);
  if (c == (-1)) { read_byte_error_while_reading=1; return 0; }
  return c;
}

variable_types: c int


GetJPGOrientationOfFile

decompiled_code:
__int64 __fastcall GetJPGOrientationOfFile(const char *a1)
{
char *v1; // r13
__int16 *v2; // rbx
int v3; // er12
unsigned int v5; // ebp
__int64 v6; // r13
__int64 v7; // rbx
unsigned int v8; // eax
int v9; // esi
unsigned int i; // eax
int v11; // ecx
int v12; // edx

v1 = exif_data;
v2 = (__int16 *)exif_data;
myfile = 0LL;
myfile = fopen(a1, "rb");
if ( myfile )
{
do
{
v2 = (__int16 *)((char *)v2 + 1);
*((_BYTE *)v2 - 1) = read_1_byte();
}
while ( &word_384 != v2 );
if ( byte_381 == -40 && ((unsigned __int8)byte_382 & exif_data[0]) == 0xFF && byte_383 == -31 )
{
v5 = read_2_bytes();
if ( v5 > 7 )
{
do
*v1++ = read_1_byte();
while ( v1 != &byte_386 );
if ( exif_data[0] == 69 && byte_381 == 120 && byte_382 == 105 && byte_383 == 102 && !word_384 )
{
v6 = v5 - 8;
v7 = 0LL;
if ( v5 != 8 )
{
do
*(_BYTE *)(++v7 + 895) = read_1_byte();
while ( v7 != v6 );
if ( (unsigned int)v6 > 0xB )
{
if ( exif_data[0] == 73 )
{
if ( byte_381 == 73 && !byte_383 && byte_382 == 42 && !byte_387 && !byte_386 )
{
v8 = (unsigned __int8)word_384 + (HIBYTE(word_384) << 8);
if ( v8 <= v5 - 10 )
{
v9 = 0;
v3 = ((unsigned __int8)exif_data[v8 + 1] << 8) + (unsigned __int8)exif_data[v8];
goto LABEL_26;
}
}
}
else if ( exif_data[0] == 77 && byte_381 == 77 && !byte_382 && byte_383 == 42 && !word_384 )
{
v8 = (unsigned __int8)byte_387 + ((unsigned __int8)byte_386 << 8);
if ( v8 <= v5 - 10 )
{
v9 = 1;
v3 = ((unsigned __int8)exif_data[v8] << 8) + (unsigned __int8)exif_data[v8 + 1];
LABEL_26:
if ( !v3 )
{
LABEL_48:
fclose(myfile);
return (unsigned int)v3;
}
for ( i = v8 + 2; v5 - 20 >= i; i += 12 )
{
v11 = (unsigned __int8)exif_data[i];
v12 = (unsigned __int8)exif_data[i + 1];
if ( v9 )
v11 <<= 8;
else
v12 <<= 8;
if ( v11 + v12 == 274 )
{
if ( v9 )
{
if ( exif_data[i + 8] )
goto LABEL_40;
v3 = (unsigned __int8)exif_data[i + 9];
}
else
{
if ( exif_data[i + 9] )
goto LABEL_40;
v3 = (unsigned __int8)exif_data[i + 8];
}
if ( v3 <= 8 )
goto LABEL_48;
goto LABEL_40;
}
if ( !--v3 )
goto LABEL_48;
}
goto LABEL_40;
}
}
LABEL_40:
fclose(myfile);
return 0;
}
}
}
}
}
v3 = 0;
fclose(myfile);
}
else
{
v3 = 0;
fprintf(stderr, " Can't open %s\n", a1);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
char *v1; // r13
__int16 *v2; // rbx
int v3; // er12
unsigned int v5; // ebp
__int64 v6; // r13
__int64 v7; // rbx
unsigned int v8; // eax
int v9; // esi
unsigned int i; // eax
int v11; // ecx
int v12; // edx

v1 = exif_data;
v2 = (__int16 *)exif_data;
myfile = 0LL;
myfile = fopen(a1, "rb");
if ( myfile )
{
do
{
v2 = (__int16 *)((char *)v2 + 1);
*((_BYTE *)v2 - 1) = func1();
}
while ( &word_384 != v2 );
if ( byte_381 == -40 && ((unsigned __int8)byte_382 & exif_data[0]) == 0xFF && byte_383 == -31 )
{
v5 = func0();
if ( v5 > 7 )
{
do
*v1++ = func1();
while ( v1 != &byte_386 );
if ( exif_data[0] == 69 && byte_381 == 120 && byte_382 == 105 && byte_383 == 102 && !word_384 )
{
v6 = v5 - 8;
v7 = 0LL;
if ( v5 != 8 )
{
do
*(_BYTE *)(++v7 + 895) = func1();
while ( v7 != v6 );
if ( (unsigned int)v6 > 0xB )
{
if ( exif_data[0] == 73 )
{
if ( byte_381 == 73 && !byte_383 && byte_382 == 42 && !byte_387 && !byte_386 )
{
v8 = (unsigned __int8)word_384 + (HIBYTE(word_384) << 8);
if ( v8 <= v5 - 10 )
{
v9 = 0;
v3 = ((unsigned __int8)exif_data[v8 + 1] << 8) + (unsigned __int8)exif_data[v8];
goto LABEL_26;
}
}
}
else if ( exif_data[0] == 77 && byte_381 == 77 && !byte_382 && byte_383 == 42 && !word_384 )
{
v8 = (unsigned __int8)byte_387 + ((unsigned __int8)byte_386 << 8);
if ( v8 <= v5 - 10 )
{
v9 = 1;
v3 = ((unsigned __int8)exif_data[v8] << 8) + (unsigned __int8)exif_data[v8 + 1];
LABEL_26:
if ( !v3 )
{
LABEL_48:
fclose(myfile);
return (unsigned int)v3;
}
for ( i = v8 + 2; v5 - 20 >= i; i += 12 )
{
v11 = (unsigned __int8)exif_data[i];
v12 = (unsigned __int8)exif_data[i + 1];
if ( v9 )
v11 <<= 8;
else
v12 <<= 8;
if ( v11 + v12 == 274 )
{
if ( v9 )
{
if ( exif_data[i + 8] )
goto LABEL_40;
v3 = (unsigned __int8)exif_data[i + 9];
}
else
{
if ( exif_data[i + 9] )
goto LABEL_40;
v3 = (unsigned __int8)exif_data[i + 8];
}
if ( v3 <= 8 )
goto LABEL_48;
goto LABEL_40;
}
if ( !--v3 )
goto LABEL_48;
}
goto LABEL_40;
}
}
LABEL_40:
fclose(myfile);
return 0;
}
}
}
}
}
v3 = 0;
fclose(myfile);
}
else
{
v3 = 0;
fprintf(stderr, " Can't open %s\n", a1);
}
return (unsigned int)v3;
}

original_code:
unsigned int GetJPGOrientationOfFile(char * filename)
{
  read_byte_error_while_reading=0;
  myfile=0;
  int set_flag=0;
  unsigned int length=0, i=0;
  int is_motorola=0;
  unsigned int offset=0, number_of_tags=0, tagnum=0;
  set_flag = 0;
  myfile = fopen(filename, "rb");
    if ( myfile == 0)
    {
      fprintf(stderr, " Can't open %s\n", filename);
      return 0;
    }
  for (i = 0; i < 4; i++) { exif_data[i] = (unsigned char) read_1_byte(); }
  if (exif_data[0] != 0xFF ||
      exif_data[1] != 0xD8 ||
      exif_data[2] != 0xFF ||
      exif_data[3] != 0xE1) { fclose(myfile); return 0; }
  length = read_2_bytes();
  if (length < 8) { fclose(myfile); return 0; }
  length -= 8;
  for (i = 0; i < 6; i++) { exif_data[i] = (unsigned char) read_1_byte(); }
  if (exif_data[0] != 0x45 ||
      exif_data[1] != 0x78 ||
      exif_data[2] != 0x69 ||
      exif_data[3] != 0x66 ||
      exif_data[4] != 0 ||
      exif_data[5] != 0) { fclose(myfile); return 0; }
  for (i = 0; i < length; i++) { exif_data[i] = (unsigned char) read_1_byte(); }
  if (length < 12) { fclose(myfile); return 0; }
  if (exif_data[0] == 0x49 && exif_data[1] == 0x49) { is_motorola = 0; } else
  if (exif_data[0] == 0x4D && exif_data[1] == 0x4D) { is_motorola = 1; } else
                                                    { fclose(myfile); return 0; }
  if (is_motorola)
  {
    if (exif_data[2] != 0) { fclose(myfile); return 0; }
    if (exif_data[3] != 0x2A) { fclose(myfile); return 0; }
  } else
  {
    if (exif_data[3] != 0) { fclose(myfile); return 0; }
    if (exif_data[2] != 0x2A) { fclose(myfile); return 0; }
  }
  if (is_motorola)
  {
    if (exif_data[4] != 0) { fclose(myfile); return 0; }
    if (exif_data[5] != 0) { fclose(myfile); return 0; }
    offset = exif_data[6];
    offset <<= 8;
    offset += exif_data[7];
  } else
  {
    if (exif_data[7] != 0) { fclose(myfile); return 0; }
    if (exif_data[6] != 0) { fclose(myfile); return 0; }
    offset = exif_data[5];
    offset <<= 8;
    offset += exif_data[4];
  }
  if (offset > length - 2) { fclose(myfile); return 0; }
  if (is_motorola)
  {
    number_of_tags = exif_data[offset];
    number_of_tags <<= 8;
    number_of_tags += exif_data[offset+1];
  } else
  {
    number_of_tags = exif_data[offset+1];
    number_of_tags <<= 8;
    number_of_tags += exif_data[offset];
  }
  if (number_of_tags == 0) { fclose(myfile); return 0; }
  offset += 2;
  for (;;)
  {
    if (offset > length - 12) { fclose(myfile); return 0; }
    if (is_motorola)
    {
      tagnum = exif_data[offset];
      tagnum <<= 8;
      tagnum += exif_data[offset+1];
    } else
    {
      tagnum = exif_data[offset+1];
      tagnum <<= 8;
      tagnum += exif_data[offset];
    }
    if (tagnum == 0x0112) break;
    if (--number_of_tags == 0) { fclose(myfile); return 0; }
    offset += 12;
  }
    if (is_motorola)
    {
      if (exif_data[offset+8] != 0) { fclose(myfile); return 0; }
      set_flag = exif_data[offset+9];
    } else
    {
      if (exif_data[offset+9] != 0) { fclose(myfile); return 0; }
      set_flag = exif_data[offset+8];
    }
    if (set_flag > 8) { fclose(myfile); return 0; }
    fclose(myfile);
  return (unsigned int) set_flag;
}

canonical_original_code:
unsigned int GetJPGOrientationOfFile(char *filename)
{
  read_byte_error_while_reading=0;
  myfile=0;
  int set_flag = 0;
  unsigned int length = 0; unsigned int i = 0;
  int is_motorola = 0;
  unsigned int offset = 0; unsigned int number_of_tags = 0; unsigned int tagnum = 0;
  set_flag = 0;
  myfile = fopen(filename, "rb");
    if ( myfile == 0)
    {
      fprintf(stderr, " Can't open %s\n", filename);
      return 0;
    }
  for (i = 0; i < 4; i++) { exif_data[i] = (unsigned char) read_1_byte(); }
  if (exif_data[0] != 0xFF ||
      exif_data[1] != 0xD8 ||
      exif_data[2] != 0xFF ||
      exif_data[3] != 0xE1) { fclose(myfile); return 0; }
  length = read_2_bytes();
  if (length < 8) { fclose(myfile); return 0; }
  length -= 8;
  for (i = 0; i < 6; i++) { exif_data[i] = (unsigned char) read_1_byte(); }
  if (exif_data[0] != 0x45 ||
      exif_data[1] != 0x78 ||
      exif_data[2] != 0x69 ||
      exif_data[3] != 0x66 ||
      exif_data[4] != 0 ||
      exif_data[5] != 0) { fclose(myfile); return 0; }
  for (i = 0; i < length; i++) { exif_data[i] = (unsigned char) read_1_byte(); }
  if (length < 12) { fclose(myfile); return 0; }
  if (exif_data[0] == 0x49 && exif_data[1] == 0x49) { is_motorola = 0; } else
  if (exif_data[0] == 0x4D && exif_data[1] == 0x4D) { is_motorola = 1; } else
                                                    { fclose(myfile); return 0; }
  if (is_motorola)
  {
    if (exif_data[2] != 0) { fclose(myfile); return 0; }
    if (exif_data[3] != 0x2A) { fclose(myfile); return 0; }
  } else
  {
    if (exif_data[3] != 0) { fclose(myfile); return 0; }
    if (exif_data[2] != 0x2A) { fclose(myfile); return 0; }
  }
  if (is_motorola)
  {
    if (exif_data[4] != 0) { fclose(myfile); return 0; }
    if (exif_data[5] != 0) { fclose(myfile); return 0; }
    offset = exif_data[6];
    offset <<= 8;
    offset += exif_data[7];
  } else
  {
    if (exif_data[7] != 0) { fclose(myfile); return 0; }
    if (exif_data[6] != 0) { fclose(myfile); return 0; }
    offset = exif_data[5];
    offset <<= 8;
    offset += exif_data[4];
  }
  if (offset > length - 2) { fclose(myfile); return 0; }
  if (is_motorola)
  {
    number_of_tags = exif_data[offset];
    number_of_tags <<= 8;
    number_of_tags += exif_data[offset+1];
  } else
  {
    number_of_tags = exif_data[offset+1];
    number_of_tags <<= 8;
    number_of_tags += exif_data[offset];
  }
  if (number_of_tags == 0) { fclose(myfile); return 0; }
  offset += 2;
  for (;;)
  {
    if (offset > length - 12) { fclose(myfile); return 0; }
    if (is_motorola)
    {
      tagnum = exif_data[offset];
      tagnum <<= 8;
      tagnum += exif_data[offset+1];
    } else
    {
      tagnum = exif_data[offset+1];
      tagnum <<= 8;
      tagnum += exif_data[offset];
    }
    if (tagnum == 0x0112) break;
    if (--number_of_tags == 0) { fclose(myfile); return 0; }
    offset += 12;
  }
    if (is_motorola)
    {
      if (exif_data[offset+8] != 0) { fclose(myfile); return 0; }
      set_flag = exif_data[offset+9];
    } else
    {
      if (exif_data[offset+9] != 0) { fclose(myfile); return 0; }
      set_flag = exif_data[offset+8];
    }
    if (set_flag > 8) { fclose(myfile); return 0; }
    fclose(myfile);
  return (unsigned int) set_flag;
}

variable_types:
length
unsigned int

variable_types:
offset
unsigned int

variable_types:
tagnum
unsigned int


workerThread

decompiled_code:
void *__fastcall workerThread(void *a1)
{
__int64 v1; // r12
double v2; // xmm3_8
int v3; // ebx
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm1_8

fprintf(stdout, "Thread-%u: Started..!\n", *((unsigned int *)a1 + 4));
v1 = *(_QWORD *)a1 + 16LL * *((unsigned int *)a1 + 4);
threadpoolWorkerInitialWait_isra_0((__int64)a1);
LABEL_2:
v2 = *(double *)&LC3;
if ( (unsigned int)threadpoolWorkerLoopCondition_isra_0(*((_QWORD *)a1 + 1)) )
{
v3 = 0;
while ( 1 )
{
v4 = (double)v3 + v2;
if ( v4 < 0.0 )
{
v5 = (double)v3 + sqrt(v4);
v2 = *(double *)&LC3;
if ( v5 < 0.0 )
{
LABEL_11:
v6 = sqrt(v5);
v2 = *(double *)&LC3;
goto LABEL_7;
}
}
else
{
v5 = (double)v3 + sqrt(v4);
if ( v5 < 0.0 )
goto LABEL_11;
}
v6 = sqrt(v5);
LABEL_7:
if ( ++v3 == 40000000 )
{
*(double *)(v1 + 8) = v6 + (double)*((int *)a1 + 4);
threadpoolWorkerLoopEnd_isra_0((__int64)a1);
goto LABEL_2;
}
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
__int64 v1; // r12
double v2; // xmm3_8
int v3; // ebx
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm1_8

fprintf(stdout, "Thread-%u: Started..!\n", *((unsigned int *)a1 + 4));
v1 = *(_QWORD *)a1 + 16LL * *((unsigned int *)a1 + 4);
func7((__int64)a1);
LABEL_2:
v2 = *(double *)&LC3;
if ( (unsigned int)func6(*((_QWORD *)a1 + 1)) )
{
v3 = 0;
while ( 1 )
{
v4 = (double)v3 + v2;
if ( v4 < 0.0 )
{
v5 = (double)v3 + sqrt(v4);
v2 = *(double *)&LC3;
if ( v5 < 0.0 )
{
LABEL_11:
v6 = sqrt(v5);
v2 = *(double *)&LC3;
goto LABEL_7;
}
}
else
{
v5 = (double)v3 + sqrt(v4);
if ( v5 < 0.0 )
goto LABEL_11;
}
v6 = sqrt(v5);
LABEL_7:
if ( ++v3 == 40000000 )
{
*(double *)(v1 + 8) = v6 + (double)*((int *)a1 + 4);
func5((__int64)a1);
goto LABEL_2;
}
}
}
return 0LL;
}

original_code:
void *workerThread(void * arg)
{
    struct threadContext * ptr = (struct threadContext *) arg;
    fprintf(stdout,"Thread-%u: Started..!\n",ptr->threadID);
    struct workerThreadContext * contextArray = (struct workerThreadContext *) ptr->argumentToPass;
    struct workerThreadContext * ctx = &contextArray[ptr->threadID];
    threadpoolWorkerInitialWait(ptr);
    unsigned int i;
    double work=ctx->computationInput;
    double workStepTwo;
    while (threadpoolWorkerLoopCondition(ptr))
    {
        for ( i = 0; i < 40000000; i++ )
        {
            work = (double) i + 42.23;
            work = sqrt(work);
            workStepTwo = sqrt(work + (double) i);
        }
        ctx->computationOutput = workStepTwo + ptr->threadID;
        threadpoolWorkerLoopEnd(ptr);
    }
    return 0;
}

canonical_original_code:
void *workerThread(void *arg)
{
    struct threadContext *ptr = (struct threadContext *) arg;
    fprintf(stdout,"Thread-%u: Started..!\n",ptr->threadID);
    struct workerThreadContext *contextArray = (struct workerThreadContext *) ptr->argumentToPass;
    struct workerThreadContext *ctx = &contextArray[ptr->threadID];
    threadpoolWorkerInitialWait(ptr);
    unsigned int i;
    double work = ctx->computationInput;
    double workStepTwo;
    while (threadpoolWorkerLoopCondition(ptr))
    {
        for ( i = 0; i < 40000000; i++ )
        {
            work = (double) i + 42.23;
            work = sqrt(work);
            workStepTwo = sqrt(work + (double) i);
        }
        ctx->computationOutput = workStepTwo + ptr->threadID;
        threadpoolWorkerLoopEnd(ptr);
    }
    return 0;
}

variable_types:
arg
void *

variable_types: struct threadContext { void *argumentToPass; struct workerPool { char initialized; char work; char mainThreadWaiting; int completedWorkNumber; union pthread_attr_t { char __size[56]; long __align; } initializationAttribute; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } startWorkMutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } startWorkCondition; union pthread_mutex_t completeWorkMutex; union pthread_cond_t completeWorkCondition; unsigned int numberOfThreads; struct threadContext *workerPoolContext; unsigned long *workerPoolIDs; } *pool; unsigned int threadID; char threadInitialized; } *

variable_types: struct workerThreadContext { double computationInput; double computationOutput; } *

variable_types: work double

variable_types: workStepTwo double

return_type: void *

user_defined_types: struct threadContext { void *argumentToPass; struct workerPool *pool; unsigned int threadID; char threadInitialized; }

user_defined_types: struct workerPool { char initialized; char work; char mainThreadWaiting; int completedWorkNumber; union pthread_attr_t initializationAttribute; union pthread_mutex_t startWorkMutex; union pthread_cond_t startWorkCondition; union pthread_mutex_t completeWorkMutex; union pthread_cond_t completeWorkCondition; unsigned int numberOfThreads; struct threadContext *workerPoolContext; unsigned long *workerPoolIDs; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
char *v5; // rbx
char *v6; // r13
unsigned int v7; // ebx
__int64 v8; // rdx
double v9; // xmm0_8
_BYTE v10[272]; // [rsp+0h] [rbp-318h] BYREF
char v11[480]; // [rsp+110h] [rbp-208h] BYREF
char v12; // [rsp+2F0h] [rbp-28h] BYREF

memset(v10, 0, 0x108uLL);
memset(v11, 0, sizeof(v11));
if ( threadpoolCreate_constprop_0((__int64)v10, (__int64)v11) )
{
v4 = 0;
fwrite("Worker thread pool created.. \n", 1uLL, 0x1EuLL, stdout);
do
{
++v4;
v5 = v11;
fprintf(stdout, "Iteration %u/%u \n", v4, 4LL);
threadpoolMainThreadPrepareWorkForWorkers_isra_0((__int64)v10);
fwrite("Main thread preparing tasks..!\n", 1uLL, 0x1FuLL, stdout);
do
{
v5 += 16;
*((double *)v5 - 2) = (float)((float)rand() / 2147483.0);
}
while ( v5 != &v12 );
v6 = &v11[8];
v7 = 0;
threadpoolMainThreadWaitForWorkersToFinish_isra_0((__int64)v10);
fwrite("Main thread collecting results..!\n", 1uLL, 0x22uLL, stdout);
do
{
v8 = v7;
v9 = *(double *)v6;
++v7;
v6 += 16;
fprintf(stdout, "Thread %u / Output : %f\n", v8, v9);
}
while ( v7 != 30 );
}
while ( v4 != 4 );
}
fwrite("Done with everything..!\n", 1uLL, 0x18uLL, stdout);
threadpoolDestroy_isra_0((__int64)v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
char *v5; // rbx
char *v6; // r13
unsigned int v7; // ebx
__int64 v8; // rdx
double v9; // xmm0_8
_BYTE v10[272]; // [rsp+0h] [rbp-318h] BYREF
char v11[480]; // [rsp+110h] [rbp-208h] BYREF
char v12; // [rsp+2F0h] [rbp-28h] BYREF

memset(v10, 0, 0x108uLL);
memset(v11, 0, sizeof(v11));
if ( func1((__int64)v10, (__int64)v11) )
{
v4 = 0;
fwrite("Worker thread pool created.. \n", 1uLL, 0x1EuLL, stdout);
do
{
++v4;
v5 = v11;
fprintf(stdout, "Iteration %u/%u \n", v4, 4LL);
func4((__int64)v10);
fwrite("Main thread preparing tasks..!\n", 1uLL, 0x1FuLL, stdout);
do
{
v5 += 16;
*((double *)v5 - 2) = (float)((float)rand() / 2147483.0);
}
while ( v5 != &v12 );
v6 = &v11[8];
v7 = 0;
func3((__int64)v10);
fwrite("Main thread collecting results..!\n", 1uLL, 0x22uLL, stdout);
do
{
v8 = v7;
v9 = *(double *)v6;
++v7;
v6 += 16;
fprintf(stdout, "Thread %u / Output : %f\n", v8, v9);
}
while ( v7 != 30 );
}
while ( v4 != 4 );
}
fwrite("Done with everything..!\n", 1uLL, 0x18uLL, stdout);
func2((__int64)v10);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    struct workerPool pool= {0};
    struct workerThreadContext context[30]= {0};
    if ( threadpoolCreate(&pool,30,workerThread,(void *) context) )
    {
        fprintf(stdout,"Worker thread pool created.. \n");
        unsigned int iterationID;
        for (iterationID=0; iterationID<4; iterationID++)
        {
            fprintf(stdout,"Iteration %u/%u \n",iterationID+1,4);
            threadpoolMainThreadPrepareWorkForWorkers(&pool);
            fprintf(stdout,"Main thread preparing tasks..!\n");
            unsigned int contextID;
            for (contextID=0; contextID<30; contextID++)
            {
                context[contextID].computationInput = (float)rand()/(float)(2147483647/1000);
            }
            threadpoolMainThreadWaitForWorkersToFinish(&pool);
            fprintf(stdout,"Main thread collecting results..!\n");
            for (contextID=0; contextID<30; contextID++)
            {
                fprintf(stdout,"Thread %u / Output : %f\n",contextID,context[contextID].computationOutput);
            }
        }
    }
    fprintf(stdout,"Done with everything..!\n");
    threadpoolDestroy(&pool);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct workerPool pool = {0};
    struct workerThreadContext context[30] = {0};
    if ( threadpoolCreate(&pool,30,workerThread,(void *) context) )
    {
        fprintf(stdout,"Worker thread pool created.. \n");
        unsigned int iterationID;
        for (iterationID=0; iterationID<4; iterationID++)
        {
            fprintf(stdout,"Iteration %u/%u \n",iterationID+1,4);
            threadpoolMainThreadPrepareWorkForWorkers(&pool);
            fprintf(stdout,"Main thread preparing tasks..!\n");
            unsigned int contextID;
            for (contextID=0; contextID<30; contextID++)
            {
                context[contextID].computationInput = (float)rand()/(float)(2147483647/1000);
            }
            threadpoolMainThreadWaitForWorkersToFinish(&pool);
            fprintf(stdout,"Main thread collecting results..!\n");
            for (contextID=0; contextID<30; contextID++)
            {
                fprintf(stdout,"Thread %u / Output : %f\n",contextID,context[contextID].computationOutput);
            }
        }
    }
    fprintf(stdout,"Done with everything..!\n");
    threadpoolDestroy(&pool);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct workerPool { char initialized; char work; char mainThreadWaiting; int completedWorkNumber; union pthread_attr_t { char __size[56]; long __align; } initializationAttribute; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } startWorkMutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } startWorkCondition; union pthread_mutex_t completeWorkMutex; union pthread_cond_t completeWorkCondition; unsigned int numberOfThreads; struct threadContext { void *argumentToPass; struct workerPool *pool; unsigned int threadID; char threadInitialized; } *workerPoolContext; unsigned long *workerPoolIDs; }

variable_types: struct workerThreadContext { double computationInput; double computationOutput; } [30]

variable_types:
iterationID
unsigned int

variable_types:
contextID
unsigned int


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

va_start(arg, a1);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
}

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

va_start(arg, a1);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
}

original_code:
void abort_(const char * s, ...)
{
        va_list args;
        __builtin_va_start(args,s);
        vfprintf(stderr, s, args);
        fprintf(stderr, "\n");
        __builtin_va_end(args);
}

canonical_original_code:
void abort_(char *s, ...)
{
        __builtin_va_list args;
        __builtin_va_start(args,s);
        vfprintf(stderr, s, args);
        fprintf(stderr, "\n");
        __builtin_va_end(args);
}

variable_types:
s
char *


countdownDelay

repo: AmmarkoV/VisualBotNGine

decompiled_code:
int __fastcall countdownDelay(int a1)
{
unsigned int v1; // ebx
int result; // eax

if ( a1 > 0 )
{
v1 = a1;
do
{
fprintf(stderr, "%u\n", v1);
result = usleep(0xF4240u);
--v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
unsigned int v1; // ebx
int result; // eax

if ( a1 > 0 )
{
v1 = a1;
do
{
fprintf(stderr, "%u\n", v1);
result = usleep(0xF4240u);
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void countdownDelay(int seconds)
{
    if (seconds==0) { return; }
    int secCounter=seconds;
    for (secCounter=seconds; secCounter>0; secCounter--)
    {
      fprintf(stderr,"%u\n",secCounter);
      usleep(1000*1000);
    }
}

canonical_original_code:
void countdownDelay(int seconds)
{
    if (seconds==0) { return; }
    int secCounter = seconds;
    for (secCounter=seconds; secCounter>0; secCounter--)
    {
      fprintf(stderr,"%u\n",secCounter);
      usleep(1000*1000);
    }
}

variable_types: seconds int

variable_types: secCounter int


mouseToNeutral

decompiled_code:
int __fastcall mouseToNeutral(int a1, int a2)
{
_BYTE savedregs[520]; // [rsp+0h] [rbp+0h] BYREF

sprintf(
savedregs,
"xdotool mousemove --sync %u %u click 1",
(unsigned int)(a1 + mouseNeutralX),
(unsigned int)(a2 + mouseNeutralY));
system(savedregs);
return usleep(clickdelay);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
_BYTE savedregs[520]; // [rsp+0h] [rbp+0h] BYREF

sprintf(
savedregs,
"xdotool mousemove --sync %u %u click 1",
(unsigned int)(a1 + mouseNeutralX),
(unsigned int)(a2 + mouseNeutralY));
system(savedregs);
return usleep(clickdelay);
}

original_code:
void mouseToNeutral(unsigned int clientX,unsigned int clientY)
{
  char commandStr[512];
  sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",clientX+mouseNeutralX,clientY+mouseNeutralY);
  int retres=system(commandStr);
  usleep(clickdelay);
}

canonical_original_code:
void mouseToNeutral(unsigned int clientX, unsigned int clientY)
{
  char commandStr[512];
  sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",clientX+mouseNeutralX,clientY+mouseNeutralY);
  int retres = system(commandStr);
  usleep(clickdelay);
}

variable_types:
clientX
unsigned int

variable_types:
clientY
unsigned int

variable_types:
commandStr
char [512]

variable_types: retres int


executePlan

decompiled_code:
__int64 __fastcall executePlan(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // ebp
unsigned int *i; // rbx
char v4; // al
__int64 v5; // rdx
char v6[552]; // [rsp-228h] [rbp-228h] BYREF

result = allowMouseControl;
if ( allowMouseControl )
{
v2 = 0;
for ( i = a1 + 1; *a1 > v2; i += 5 )
{
while ( 1 )
{
v5 = *i;
if ( *(_QWORD *)i != *((_QWORD *)i + 1) )
break;
++v2;
i += 5;
fwrite("Movement is null\n", 1uLL, 0x11uLL, stderr);
if ( *a1 <= v2 )
goto LABEL_11;
}
v4 = *((_BYTE *)i + 16);
switch ( v4 )
{
case 1:
sprintf(v6, "xdotool mousemove --sync %u %u click 1", v5, i[1]);
system(v6);
fwrite("Moving : Single Click OK .. ", 1uLL, 0x1CuLL, stderr);
usleep(clickdelay);
break;
case 2:
sprintf(v6, "xdotool mousemove --sync %u %u click 1", v5, i[1]);
system(v6);
fwrite("Moving : From OK .. ", 1uLL, 0x14uLL, stderr);
usleep(clickdelay);
sprintf(v6, "xdotool mousemove --sync %u %u click 1", i[2], i[3]);
system(v6);
fwrite("To OK \n", 1uLL, 7uLL, stderr);
break;
case 0:
mouseToNeutral(resX, resY);
usleep(5 * clickdelay);
break;
}
++v2;
}
LABEL_11:
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // ebp
unsigned int *i; // rbx
char v4; // al
__int64 v5; // rdx
char v6[552]; // [rsp-228h] [rbp-228h] BYREF

result = allowMouseControl;
if ( allowMouseControl )
{
v2 = 0;
for ( i = a1 + 1; *a1 > v2; i += 5 )
{
while ( 1 )
{
v5 = *i;
if ( *(_QWORD *)i != *((_QWORD *)i + 1) )
break;
++v2;
i += 5;
fwrite("Movement is null\n", 1uLL, 0x11uLL, stderr);
if ( *a1 <= v2 )
goto LABEL_11;
}
v4 = *((_BYTE *)i + 16);
switch ( v4 )
{
case 1:
sprintf(v6, "xdotool mousemove --sync %u %u click 1", v5, i[1]);
system(v6);
fwrite("Moving : Single Click OK .. ", 1uLL, 0x1CuLL, stderr);
usleep(clickdelay);
break;
case 2:
sprintf(v6, "xdotool mousemove --sync %u %u click 1", v5, i[1]);
system(v6);
fwrite("Moving : From OK .. ", 1uLL, 0x14uLL, stderr);
usleep(clickdelay);
sprintf(v6, "xdotool mousemove --sync %u %u click 1", i[2], i[3]);
system(v6);
fwrite("To OK \n", 1uLL, 7uLL, stderr);
break;
case 0:
func1(resX, resY);
usleep(5 * clickdelay);
break;
}
++v2;
}
LABEL_11:
result = 1LL;
}
return result;
}

original_code:
int executePlan(struct mouseMovements * plan)
{
  if (!allowMouseControl) { return 0; }
  char commandStr[512];
  int i=0 , retres=0;
  for (i=0; i<plan->totalMovements; i++)
  {
   if ( (plan->movement[i].fromX==plan->movement[i].toX) &&
        (plan->movement[i].fromY==plan->movement[i].toY) )
            { fprintf(stderr,"Movement is null\n"); }
    else
    {
      switch (plan->movement[i].mode)
      {
        case MOVE_CLICK_AND_MOVE_CLICK :
          sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",plan->movement[i].fromX,plan->movement[i].fromY);
          retres=system(commandStr);
          fprintf(stderr,"Moving : From OK .. ");
          usleep(clickdelay);
          sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",plan->movement[i].toX,plan->movement[i].toY);
          retres=system(commandStr);
          fprintf(stderr,"To OK \n");
        break;
        case SINGLE_MOVE_CLICK :
          sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",plan->movement[i].fromX,plan->movement[i].fromY);
          retres=system(commandStr);
          fprintf(stderr,"Moving : Single Click OK .. ");
          usleep(clickdelay);
        break;
        case MOVE_TO_NEUTRAL :
          mouseToNeutral(resX,resY);
          usleep(clickdelay*5);
        break;
      }
    }
  }
  return 1;
}

canonical_original_code:
int executePlan(struct mouseMovements *plan)
{
  if (!allowMouseControl) { return 0; }
  char commandStr[512];
  int i = 0; int retres = 0;
  for (i=0; i<plan->totalMovements; i++)
  {
   if ( (plan->movement[i].fromX==plan->movement[i].toX) &&
        (plan->movement[i].fromY==plan->movement[i].toY) )
            { fprintf(stderr,"Movement is null\n"); }
    else
    {
      switch (plan->movement[i].mode)
      {
        case MOVE_CLICK_AND_MOVE_CLICK :
          sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",plan->movement[i].fromX,plan->movement[i].fromY);
          retres=system(commandStr);
          fprintf(stderr,"Moving : From OK .. ");
          usleep(clickdelay);
          sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",plan->movement[i].toX,plan->movement[i].toY);
          retres=system(commandStr);
          fprintf(stderr,"To OK \n");
        break;
        case SINGLE_MOVE_CLICK :
          sprintf(commandStr,"xdotool mousemove --sync %u %u click 1",plan->movement[i].fromX,plan->movement[i].fromY);
          retres=system(commandStr);
          fprintf(stderr,"Moving : Single Click OK .. ");
          usleep(clickdelay);
        break;
        case MOVE_TO_NEUTRAL :
          mouseToNeutral(resX,resY);
          usleep(clickdelay*5);
        break;
      }
    }
  }
  return 1;
}

variable_types: struct mouseMovements { unsigned int totalMovements; struct mouseMovementItem { unsigned int fromX; unsigned int fromY; unsigned int toX; unsigned int toY; char mode; } movement[100]; } *

variable_types: i int

user_defined_types: struct mouseMovements { unsigned int totalMovements; struct mouseMovementItem movement[100]; }


reloadScreen

decompiled_code:
__int64 reloadScreen()
{
_QWORD *v0; // r12

destroyImage();
if ( !allowSnapshot )
return readImage("ramfs/screenshot.pnm", 3LL, 0LL);
v0 = (_QWORD *)createImage(1920LL, 1080LL, 3LL, 8LL);
getScreen(*v0, v0 + 1, (char *)v0 + 12);
return (__int64)v0;
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // r12

destroyImage();
if ( !allowSnapshot )
return readImage("ramfs/screenshot.pnm", 3LL, 0LL);
v0 = (_QWORD *)createImage(1920LL, 1080LL, 3LL, 8LL);
getScreen(*v0, v0 + 1, (char *)v0 + 12);
return (__int64)v0;
}

original_code:
struct Image * reloadScreen(struct Image * lastImg)
{
  destroyImage(lastImg);
  if (!allowSnapshot) { return readImage("ramfs/screenshot.pnm",PNM_CODEC,0); }
    struct Image * newImg = createImage(1920,1080,3,8);
    getScreen(newImg->pixels , &newImg->width, &newImg->height);
    return newImg;
}

canonical_original_code:
struct Image *reloadScreen(struct Image *lastImg)
{
  destroyImage(lastImg);
  if (!allowSnapshot) { return readImage("ramfs/screenshot.pnm",PNM_CODEC,0); }
    struct Image *newImg = createImage(1920,1080,3,8);
    getScreen(newImg->pixels , &newImg->width, &newImg->height);
    return newImg;
}

variable_types:
lastImg
struct Image *

variable_types: struct Image { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int channels; unsigned int bitsperpixel; unsigned int image_size; } *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
const char **v5; // r13
const char *v6; // r15
__int64 v7; // rbp
unsigned int v8; // ebx
__int64 v9; // rdx
const char *v10; // rdi
const char *v11; // rdi
const char *v12; // rdi
int v13; // eax
const char *v14; // rdi
unsigned int v15; // er15
unsigned int v16[518]; // [rsp+10h] [rbp-818h] BYREF

if ( argc > 0 )
{
v4 = argv;
v5 = &argv[(unsigned int)(argc - 1) + 1];
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = *v4;
if ( strcasecmp(*v4, "-clickdelay") )
break;
v10 = v4[1];
++v4;
clickdelay = 1000 * atoi(v10);
fprintf(stderr, "clickdelay set to %u milliseconds \n", clickdelay);
if ( v4 == v5 )
goto LABEL_12;
}
if ( strcasecmp(v6, "-delay") )
break;
v11 = v4[1];
++v4;
delay = 1000 * atoi(v11);
fprintf(stderr, "delay set to %u milliseconds \n", delay);
if ( v4 == v5 )
goto LABEL_12;
}
if ( strcasecmp(v6, "-clientXY") )
break;
v12 = v4[1];
++v4;
v13 = atoi(v12);
v14 = v4[1];
v15 = v13;
resX = v13;
resY = atoi(v14);
fprintf(stderr, "client set to %u %u \n", v15, resY);
if ( v4 == v5 )
goto LABEL_12;
}
if ( strcasecmp(v6, "-doNotMove") )
break;
++v4;
allowMouseControl = 0;
fwrite("Deactivated mouse control\n", 1uLL, 0x1AuLL, stderr);
if ( v4 == v5 )
goto LABEL_12;
}
if ( !strcasecmp(v6, "-doNotGrab") )
{
allowSnapshot = 0;
fwrite("Deactivated screen grabbing \n", 1uLL, 0x1DuLL, stderr);
}
else if ( !strcasecmp(v6, "-clickDelay") )
{
clickdelay = 1000 * atoi(v4[1]);
fprintf(stderr, "Set click delay to %u\n", clickdelay);
}
else if ( !strcasecmp(v6, "-Delay") )
{
delay = 1000 * atoi(v4[1]);
fprintf(stderr, "Set delay to %u\n", delay);
}
++v4;
}
while ( v4 != v5 );
}
LABEL_12:
initXwdLib((unsigned int)argc, argv);
fwrite("Please ready your window\n", 1uLL, 0x19uLL, stderr);
countdownDelay(0);
fwrite("Starting Up\n", 1uLL, 0xCuLL, stderr);
v7 = reloadScreen(0LL);
if ( (unsigned int)initializeEngine("bejeweled blitz") )
{
v8 = 0;
resX = oX + 175;
resY = oY + 109;
while ( 1 )
{
v9 = v8++;
fprintf(stderr, "Round %u \n", v9);
if ( (unsigned int)thinkWhatToPlay(
*(_QWORD *)v7,
*(unsigned int *)(v7 + 8),
*(unsigned int *)(v7 + 12),
resX,
resY,
v16) )
{
executePlan(v16);
}
else
{
fwrite("Can't think of a move to play\n", 1uLL, 0x1EuLL, stderr);
++totalNotMoves;
if ( __ROR4__(-858993459 * totalNotMoves + 429496728, 2) <= 0xCCCCCCCu )
mouseToNeutral(resX, resY);
usleep(dontknowdelay);
}
usleep(delay);
v7 = reloadScreen(v7);
}
}
fwrite("Error initializing engine :(\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
const char **v5; // r13
const char *v6; // r15
__int64 v7; // rbp
unsigned int v8; // ebx
__int64 v9; // rdx
const char *v10; // rdi
const char *v11; // rdi
const char *v12; // rdi
int v13; // eax
const char *v14; // rdi
unsigned int v15; // er15
unsigned int v16[518]; // [rsp+10h] [rbp-818h] BYREF

if ( argc > 0 )
{
v4 = argv;
v5 = &argv[(unsigned int)(argc - 1) + 1];
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = *v4;
if ( strcasecmp(*v4, "-clickdelay") )
break;
v10 = v4[1];
++v4;
clickdelay = 1000 * atoi(v10);
fprintf(stderr, "clickdelay set to %u milliseconds \n", clickdelay);
if ( v4 == v5 )
goto LABEL_12;
}
if ( strcasecmp(v6, "-delay") )
break;
v11 = v4[1];
++v4;
delay = 1000 * atoi(v11);
fprintf(stderr, "delay set to %u milliseconds \n", delay);
if ( v4 == v5 )
goto LABEL_12;
}
if ( strcasecmp(v6, "-clientXY") )
break;
v12 = v4[1];
++v4;
v13 = atoi(v12);
v14 = v4[1];
v15 = v13;
resX = v13;
resY = atoi(v14);
fprintf(stderr, "client set to %u %u \n", v15, resY);
if ( v4 == v5 )
goto LABEL_12;
}
if ( strcasecmp(v6, "-doNotMove") )
break;
++v4;
allowMouseControl = 0;
fwrite("Deactivated mouse control\n", 1uLL, 0x1AuLL, stderr);
if ( v4 == v5 )
goto LABEL_12;
}
if ( !strcasecmp(v6, "-doNotGrab") )
{
allowSnapshot = 0;
fwrite("Deactivated screen grabbing \n", 1uLL, 0x1DuLL, stderr);
}
else if ( !strcasecmp(v6, "-clickDelay") )
{
clickdelay = 1000 * atoi(v4[1]);
fprintf(stderr, "Set click delay to %u\n", clickdelay);
}
else if ( !strcasecmp(v6, "-Delay") )
{
delay = 1000 * atoi(v4[1]);
fprintf(stderr, "Set delay to %u\n", delay);
}
++v4;
}
while ( v4 != v5 );
}
LABEL_12:
initXwdLib((unsigned int)argc, argv);
fwrite("Please ready your window\n", 1uLL, 0x19uLL, stderr);
func0(0);
fwrite("Starting Up\n", 1uLL, 0xCuLL, stderr);
v7 = func3(0LL);
if ( (unsigned int)initializeEngine("bejeweled blitz") )
{
v8 = 0;
resX = oX + 175;
resY = oY + 109;
while ( 1 )
{
v9 = v8++;
fprintf(stderr, "Round %u \n", v9);
if ( (unsigned int)thinkWhatToPlay(
*(_QWORD *)v7,
*(unsigned int *)(v7 + 8),
*(unsigned int *)(v7 + 12),
resX,
resY,
v16) )
{
func2(v16);
}
else
{
fwrite("Can't think of a move to play\n", 1uLL, 0x1EuLL, stderr);
++totalNotMoves;
if ( __ROR4__(-858993459 * totalNotMoves + 429496728, 2) <= 0xCCCCCCCu )
func1(resX, resY);
usleep(dontknowdelay);
}
usleep(delay);
v7 = func3(v7);
}
}
fwrite("Error initializing engine :(\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
  int i=0;
  for (i=0; i<argc; i++)
  {
    if (strcasecmp(argv[i],"-clickdelay")==0) { clickdelay=1000*atoi(argv[i+1]); fprintf(stderr,"clickdelay set to %u milliseconds \n",clickdelay); } else
    if (strcasecmp(argv[i],"-delay")==0) { delay=1000*atoi(argv[i+1]); fprintf(stderr,"delay set to %u milliseconds \n",delay); } else
    if (strcasecmp(argv[i],"-clientXY")==0) { resX=atoi(argv[i+1]); resY=atoi(argv[i+2]); fprintf(stderr,"client set to %u %u \n",resX,resY); } else
    if (strcasecmp(argv[i],"-doNotMove")==0) { allowMouseControl=0; fprintf(stderr,"Deactivated mouse control\n"); } else
    if (strcasecmp(argv[i],"-doNotGrab")==0) { allowSnapshot=0; fprintf(stderr,"Deactivated screen grabbing \n"); } else
    if (strcasecmp(argv[i],"-clickDelay")==0) { clickdelay=atoi(argv[i+1])*1000; fprintf(stderr,"Set click delay to %u\n",clickdelay); } else
    if (strcasecmp(argv[i],"-Delay")==0) { delay=atoi(argv[i+1])*1000; fprintf(stderr,"Set delay to %u\n",delay); }
  }
    initXwdLib(argc,argv);
    fprintf(stderr,"Please ready your window\n");
    countdownDelay(0);
    fprintf(stderr,"Starting Up\n");
    struct Image * haystack = reloadScreen(0);
    unsigned int iterations=0;
    unsigned int fromX , fromY , toX , toY;
    struct mouseMovements ourPlan;
    if (! initializeEngine("bejeweled blitz") )
    {
       fprintf(stderr,"Error initializing engine :(\n");
       exit(1);
    }
    resX = oX+175 , resY = oY+109;
    while (1)
    {
      fprintf(stderr,"Round %u \n",iterations);
      ++iterations;
       unsigned int possibleMoves= thinkWhatToPlay(
                                                        haystack->pixels, haystack->width , haystack->height ,
                                                        resX , resY , &ourPlan
                                                   );
       if ( possibleMoves==0 )
          {
            fprintf(stderr,"Can't think of a move to play\n");
            ++totalNotMoves;
            if (totalNotMoves%20==0) { mouseToNeutral(resX,resY); }
            usleep(dontknowdelay);
          }
            else
          {
            executePlan(&ourPlan);
          }
      usleep(delay);
      haystack = reloadScreen(haystack);
    }
    destroyImage(haystack);
    stopEngine();
    closeXwdLib();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int i = 0;
  for (i=0; i<argc; i++)
  {
    if (strcasecmp(argv[i],"-clickdelay")==0) { clickdelay=1000*atoi(argv[i+1]); fprintf(stderr,"clickdelay set to %u milliseconds \n",clickdelay); } else
    if (strcasecmp(argv[i],"-delay")==0) { delay=1000*atoi(argv[i+1]); fprintf(stderr,"delay set to %u milliseconds \n",delay); } else
    if (strcasecmp(argv[i],"-clientXY")==0) { resX=atoi(argv[i+1]); resY=atoi(argv[i+2]); fprintf(stderr,"client set to %u %u \n",resX,resY); } else
    if (strcasecmp(argv[i],"-doNotMove")==0) { allowMouseControl=0; fprintf(stderr,"Deactivated mouse control\n"); } else
    if (strcasecmp(argv[i],"-doNotGrab")==0) { allowSnapshot=0; fprintf(stderr,"Deactivated screen grabbing \n"); } else
    if (strcasecmp(argv[i],"-clickDelay")==0) { clickdelay=atoi(argv[i+1])*1000; fprintf(stderr,"Set click delay to %u\n",clickdelay); } else
    if (strcasecmp(argv[i],"-Delay")==0) { delay=atoi(argv[i+1])*1000; fprintf(stderr,"Set delay to %u\n",delay); }
  }
    initXwdLib(argc,argv);
    fprintf(stderr,"Please ready your window\n");
    countdownDelay(0);
    fprintf(stderr,"Starting Up\n");
    struct Image *haystack = reloadScreen(0);
    unsigned int iterations = 0;
    unsigned int fromX; unsigned int fromY; unsigned int toX; unsigned int toY;
    struct mouseMovements ourPlan;
    if (! initializeEngine("bejeweled blitz") )
    {
       fprintf(stderr,"Error initializing engine :(\n");
       exit(1);
    }
    resX = oX+175 , resY = oY+109;
    while (1)
    {
      fprintf(stderr,"Round %u \n",iterations);
      ++iterations;
       unsigned int possibleMoves = thinkWhatToPlay(
                                                        haystack->pixels, haystack->width , haystack->height ,
                                                        resX , resY , &ourPlan
                                                   );
       if ( possibleMoves==0 )
          {
            fprintf(stderr,"Can't think of a move to play\n");
            ++totalNotMoves;
            if (totalNotMoves%20==0) { mouseToNeutral(resX,resY); }
            usleep(dontknowdelay);
          }
            else
          {
            executePlan(&ourPlan);
          }
      usleep(delay);
      haystack = reloadScreen(haystack);
    }
    destroyImage(haystack);
    stopEngine();
    closeXwdLib();
    return 0;
}

variable_types: argc int

variable_types:
iterations
unsigned int

variable_types:
fromX
unsigned int

variable_types:
fromY
unsigned int

variable_types:
toX
unsigned int

variable_types:
toY
unsigned int

variable_types: struct mouseMovements { unsigned int totalMovements; struct mouseMovementItem { unsigned int fromX; unsigned int fromY; unsigned int toX; unsigned int toY; char mode; } movement[100]; }

variable_types:
possibleMoves
unsigned int

user_defined_types: struct Image { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int channels; unsigned int bitsperpixel; unsigned int image_size; }


compareTableTile

decompiled_code:
__int64 __fastcall compareTableTile(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, _DWORD *a9)
{
__int64 result; // rax
char v14[4]; // [rsp+10h] [rbp-40h] BYREF
char v15[60]; // [rsp+14h] [rbp-3Ch] BYREF

if ( (int)colorVariance(a2, a3, a4, a5, a6, a7, a8) > 10149 )
{
result = compareToPatternSet(a1, a2, a3, a4, a5, a6, a7, a8, &unk_11170, a9, v14, v15);
if ( (_DWORD)result )
result = *a9 != 0;
}
else
{
*a9 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, _DWORD *a9)
{
__int64 result; // rax
char v14[4]; // [rsp+10h] [rbp-40h] BYREF
char v15[60]; // [rsp+14h] [rbp-3Ch] BYREF

if ( (int)colorVariance(a2, a3, a4, a5, a6, a7, a8) > 10149 )
{
result = compareToPatternSet(a1, a2, a3, a4, a5, a6, a7, a8, &unk_11170, a9, v14, v15);
if ( (_DWORD)result )
result = *a9 != 0;
}
else
{
*a9 = 0;
result = 1LL;
}
return result;
}

original_code:
int compareTableTile(struct PatternSet * pattSet ,
                     unsigned char * screen , unsigned int screenWidth ,unsigned int screenHeight ,
                     unsigned int sX,unsigned int sY , unsigned int width ,unsigned int height ,
                     unsigned int * pick)
{
  unsigned int patternNum , tileNum;
   if ( colorVariance( screen, screenWidth ,screenHeight , sX, sY, width , height) < 10150 )
   {
       *pick=NO_PIECE;
       return 1;
   }
   if (
        compareToPatternSet( pattSet ,
                             screen , screenWidth , screenHeight ,
                             sX,sY , width ,height ,
                             70000 ,
                             pick ,
                             &patternNum ,
                             &tileNum)
      )
   {
       if ( *pick!= UNKNOWN_PIECE )
       {
           return 1;
       }
   }
 return 0;
}

canonical_original_code:
int compareTableTile(struct PatternSet *pattSet, unsigned char *screen, unsigned int screenWidth, unsigned int screenHeight, unsigned int sX, unsigned int sY, unsigned int width, unsigned int height, unsigned int *pick)
{
  unsigned int patternNum; unsigned int tileNum;
   if ( colorVariance( screen, screenWidth ,screenHeight , sX, sY, width , height) < 10150 )
   {
       *pick=NO_PIECE;
       return 1;
   }
   if (
        compareToPatternSet( pattSet ,
                             screen , screenWidth , screenHeight ,
                             sX,sY , width ,height ,
                             70000 ,
                             pick ,
                             &patternNum ,
                             &tileNum)
      )
   {
       if ( *pick!= UNKNOWN_PIECE )
       {
           return 1;
       }
   }
 return 0;
}

variable_types: struct PatternSet { unsigned int totalPatterns; struct PatternItem { unsigned int totalTiles; unsigned int value; unsigned char use; unsigned int acceptScore; struct Image { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int channels; unsigned int bitsperpixel; unsigned int image_size; } *tile[256]; unsigned int nonTransparentPixels[256]; unsigned int totalPixels[256]; char name[512]; } pattern[256]; } *

variable_types:
screen
unsigned char *

variable_types:
screenWidth
unsigned int

variable_types:
screenHeight
unsigned int

variable_types:
sX
unsigned int

variable_types:
sY
unsigned int

variable_types:
width
unsigned int

variable_types:
height
unsigned int

variable_types:
pick
unsigned int *

variable_types:
patternNum
unsigned int

variable_types:
tileNum
unsigned int

user_defined_types: struct PatternSet { unsigned int totalPatterns; struct PatternItem pattern[256]; }

user_defined_types: struct PatternItem { unsigned int totalTiles; unsigned int value; unsigned char use; unsigned int acceptScore; struct Image *tile[256]; unsigned int nonTransparentPixels[256]; unsigned int totalPixels[256]; char name[512]; }


seeTable

decompiled_code:
__int64 __fastcall seeTable(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, int a5, int a6)
{
unsigned int v8; // er15
_DWORD *v9; // rbx
__int64 v10; // rdx
__int64 i; // [rsp+8h] [rbp-260h]
char s[568]; // [rsp+30h] [rbp-238h] BYREF

sprintf(s, "see%u", ++seeFunctionCalls);
dumpPatternSet(&set, s);
for ( i = 0LL; i != 8; ++i )
{
v8 = 0;
v9 = (_DWORD *)(4 * i + a1);
do
{
while ( 1 )
{
*v9 = 0;
fprintf(
stderr,
"%u,%u table has %u,%u coords\n",
v8,
(unsigned int)i,
v8 * settings[2] + a5,
(unsigned int)(i * settings[3] + a6));
if ( (unsigned int)compareTableTile(
(__int64)&set,
a2,
a3,
a4,
v8 * settings[2] + a5,
(int)i * settings[3] + a6,
settings[2],
settings[3],
v9) )
break;
++v8;
v9 += 8;
if ( v8 == 8 )
goto LABEL_6;
}
v10 = v8++;
v9 += 8;
fprintf(stderr, "Table[%u][%u] got assigned via tiles\n", v10, (unsigned int)i);
}
while ( v8 != 8 );
LABEL_6:
;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, int a5, int a6)
{
unsigned int v8; // er15
_DWORD *v9; // rbx
__int64 v10; // rdx
__int64 i; // [rsp+8h] [rbp-260h]
char s[568]; // [rsp+30h] [rbp-238h] BYREF

sprintf(s, "see%u", ++seeFunctionCalls);
dumpPatternSet(&set, s);
for ( i = 0LL; i != 8; ++i )
{
v8 = 0;
v9 = (_DWORD *)(4 * i + a1);
do
{
while ( 1 )
{
*v9 = 0;
fprintf(
stderr,
"%u,%u table has %u,%u coords\n",
v8,
(unsigned int)i,
v8 * settings[2] + a5,
(unsigned int)(i * settings[3] + a6));
if ( (unsigned int)func0(
(__int64)&set,
a2,
a3,
a4,
v8 * settings[2] + a5,
(int)i * settings[3] + a6,
settings[2],
settings[3],
v9) )
break;
++v8;
v9 += 8;
if ( v8 == 8 )
goto LABEL_6;
}
v10 = v8++;
v9 += 8;
fprintf(stderr, "Table[%u][%u] got assigned via tiles\n", v10, (unsigned int)i);
}
while ( v8 != 8 );
LABEL_6:
;
}
return 1LL;
}

original_code:
int seeTable(unsigned int table[8][8] ,
             unsigned char * screen , unsigned int screenWidth ,unsigned int screenHeight ,
             unsigned int clientStartX , unsigned int clientStartY)
{
    ++seeFunctionCalls;
    char dumpMsg[512];
    sprintf(dumpMsg,"see%u",seeFunctionCalls);
    dumpPatternSet(&set,dumpMsg);
    unsigned int halfBlockX = (unsigned int) settings.blockX/2;
    unsigned int halfBlockY = (unsigned int) settings.blockY/2;
    unsigned char R,G,B;
    unsigned int x,y;
    for (y=0; y<8; y++)
    {
     for (x=0; x<8; x++)
     {
      table[x][y]=UNKNOWN_PIECE;
      fprintf(stderr,"%u,%u table has %u,%u coords\n",x,y,clientStartX + x*settings.blockX, clientStartY + y*settings.blockY);
      if
        (
          compareTableTile(&set,
                           screen,screenWidth,screenHeight,
                           clientStartX + x*settings.blockX,
                           clientStartY + y*settings.blockY,
                           settings.blockX ,
                           settings.blockY ,
                           &table[x][y] )
        )
        {
          fprintf(stderr,"Table[%u][%u] got assigned via tiles\n",x,y);
        }
     }
    }
  return 1;
}

canonical_original_code:
int seeTable(unsigned int table[8][8], unsigned char *screen, unsigned int screenWidth, unsigned int screenHeight, unsigned int clientStartX, unsigned int clientStartY)
{
    ++seeFunctionCalls;
    char dumpMsg[512];
    sprintf(dumpMsg,"see%u",seeFunctionCalls);
    dumpPatternSet(&set,dumpMsg);
    unsigned int halfBlockX = (unsigned int) settings.blockX/2;
    unsigned int halfBlockY = (unsigned int) settings.blockY/2;
    unsigned char R; unsigned char G; unsigned char B;
    unsigned int x; unsigned int y;
    for (y=0; y<8; y++)
    {
     for (x=0; x<8; x++)
     {
      table[x][y]=UNKNOWN_PIECE;
      fprintf(stderr,"%u,%u table has %u,%u coords\n",x,y,clientStartX + x*settings.blockX, clientStartY + y*settings.blockY);
      if
        (
          compareTableTile(&set,
                           screen,screenWidth,screenHeight,
                           clientStartX + x*settings.blockX,
                           clientStartY + y*settings.blockY,
                           settings.blockX ,
                           settings.blockY ,
                           &table[x][y] )
        )
        {
          fprintf(stderr,"Table[%u][%u] got assigned via tiles\n",x,y);
        }
     }
    }
  return 1;
}

variable_types:
table
unsigned int [8][8]

variable_types:
clientStartX
unsigned int

variable_types:
clientStartY
unsigned int

variable_types:
dumpMsg
char [512]

variable_types:
halfBlockX
unsigned int

variable_types:
halfBlockY
unsigned int

variable_types:
R
unsigned char

variable_types:
G
unsigned char

variable_types:
B
unsigned char

variable_types:
x
unsigned int

variable_types:
y
unsigned int


seeButtons

decompiled_code:
__int64 __fastcall seeButtons(__int64 a1, unsigned int a2, unsigned int a3, _DWORD *a4, _DWORD *a5)
{
_DWORD *v5; // rbx
__int64 v6; // rbp
unsigned int v7; // er15
unsigned int v8; // er14
__int64 v9; // rdx
__int64 result; // rax
unsigned int v14[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v14[0] = 10000000;
if ( numberOfButtons )
{
v5 = buttons;
v6 = 0LL;
while ( 1 )
{
fprintf(stderr, "Comparing Button %u \n", (unsigned int)v6);
v7 = settings[0] + v5[2];
v8 = settings[1] + v5[3];
fprintf(
stderr,
"%u,%u size %ux%u \n",
v7,
v8,
*(unsigned int *)(*(_QWORD *)v5 + 8LL),
*(unsigned int *)(*(_QWORD *)v5 + 12LL));
compareRGBPatchesNeighborhoodIgnoreColor(
3LL,
3LL,
a1,
v7,
v8,
a2,
a3,
**(_QWORD **)v5,
0LL,
0LL,
*(unsigned int *)(*(_QWORD *)v5 + 8LL),
*(unsigned int *)(*(_QWORD *)v5 + 12LL),
123LL,
123LL,
0LL,
*(unsigned int *)(*(_QWORD *)v5 + 8LL),
*(unsigned int *)(*(_QWORD *)v5 + 12LL),
v14,
&unk_15F90);
fprintf(stderr, "Compared Button %u , score %u \n", (unsigned int)v6, v14[0]);
if ( v14[0] <= (unsigned int)&unk_15F8F )
break;
v6 = (unsigned int)(v6 + 1);
v5 += 4;
if ( numberOfButtons <= (unsigned int)v6 )
goto LABEL_6;
}
fprintf(stderr, "Button %u Matches\n", (unsigned int)v6);
v9 = buttons[2 * v6];
*a4 = (*(_DWORD *)(v9 + 8) >> 1) + v7;
*a5 = (*(_DWORD *)(v9 + 12) >> 1) + v8;
result = 1LL;
}
else
{
LABEL_6:
fwrite("No Button Matches\n", 1uLL, 0x12uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3, _DWORD *a4, _DWORD *a5)
{
_DWORD *v5; // rbx
__int64 v6; // rbp
unsigned int v7; // er15
unsigned int v8; // er14
__int64 v9; // rdx
__int64 result; // rax
unsigned int v14[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v14[0] = 10000000;
if ( numberOfButtons )
{
v5 = buttons;
v6 = 0LL;
while ( 1 )
{
fprintf(stderr, "Comparing Button %u \n", (unsigned int)v6);
v7 = settings[0] + v5[2];
v8 = settings[1] + v5[3];
fprintf(
stderr,
"%u,%u size %ux%u \n",
v7,
v8,
*(unsigned int *)(*(_QWORD *)v5 + 8LL),
*(unsigned int *)(*(_QWORD *)v5 + 12LL));
compareRGBPatchesNeighborhoodIgnoreColor(
3LL,
3LL,
a1,
v7,
v8,
a2,
a3,
**(_QWORD **)v5,
0LL,
0LL,
*(unsigned int *)(*(_QWORD *)v5 + 8LL),
*(unsigned int *)(*(_QWORD *)v5 + 12LL),
123LL,
123LL,
0LL,
*(unsigned int *)(*(_QWORD *)v5 + 8LL),
*(unsigned int *)(*(_QWORD *)v5 + 12LL),
v14,
&unk_15F90);
fprintf(stderr, "Compared Button %u , score %u \n", (unsigned int)v6, v14[0]);
if ( v14[0] <= (unsigned int)&unk_15F8F )
break;
v6 = (unsigned int)(v6 + 1);
v5 += 4;
if ( numberOfButtons <= (unsigned int)v6 )
goto LABEL_6;
}
fprintf(stderr, "Button %u Matches\n", (unsigned int)v6);
v9 = buttons[2 * v6];
*a4 = (*(_DWORD *)(v9 + 8) >> 1) + v7;
*a5 = (*(_DWORD *)(v9 + 12) >> 1) + v8;
result = 1LL;
}
else
{
LABEL_6:
fwrite("No Button Matches\n", 1uLL, 0x12uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int seeButtons( unsigned char * screen , unsigned int screenWidth ,unsigned int screenHeight , unsigned int * clickX , unsigned int * clickY )
{
  unsigned int currentScore=10000000;
  unsigned int buttonNum = 0;
   for ( buttonNum=0; buttonNum < numberOfButtons; buttonNum++ )
   {
       fprintf(stderr,"Comparing Button %u \n",buttonNum);
       unsigned int sX = settings.clientX + buttons[buttonNum].checkX;
       unsigned int sY = settings.clientY + buttons[buttonNum].checkY;
       fprintf(stderr,"%u,%u size %ux%u \n", sX , sY , buttons[buttonNum].buttonsImg->width , buttons[buttonNum].buttonsImg->height);
       compareRGBPatchesNeighborhoodIgnoreColor(
                                     3,3,
                                     screen , sX , sY , screenWidth, screenHeight ,
                                     buttons[buttonNum].buttonsImg->pixels ,
                                      0, 0 ,
                                     buttons[buttonNum].buttonsImg->width ,
                                     buttons[buttonNum].buttonsImg->height,
                                     123,123,0,
                                     buttons[buttonNum].buttonsImg->width,
                                     buttons[buttonNum].buttonsImg->height ,
                                     &currentScore ,
                                     90000
                                    );
       fprintf(stderr,"Compared Button %u , score %u \n",buttonNum,currentScore);
      if (currentScore<90000)
      {
        fprintf(stderr,"Button %u Matches\n",buttonNum);
        *clickX = (unsigned int) sX + buttons[buttonNum].buttonsImg->width/2;
        *clickY = (unsigned int) sY + buttons[buttonNum].buttonsImg->height/2;
        return 1;
      }
   }
  fprintf(stderr,"No Button Matches\n");
  return 0;
}

canonical_original_code:
int seeButtons(unsigned char *screen, unsigned int screenWidth, unsigned int screenHeight, unsigned int *clickX, unsigned int *clickY)
{
  unsigned int currentScore = 10000000;
  unsigned int buttonNum = 0;
   for ( buttonNum=0; buttonNum < numberOfButtons; buttonNum++ )
   {
       fprintf(stderr,"Comparing Button %u \n",buttonNum);
       unsigned int sX = settings.clientX + buttons[buttonNum].checkX;
       unsigned int sY = settings.clientY + buttons[buttonNum].checkY;
       fprintf(stderr,"%u,%u size %ux%u \n", sX , sY , buttons[buttonNum].buttonsImg->width , buttons[buttonNum].buttonsImg->height);
       compareRGBPatchesNeighborhoodIgnoreColor(
                                     3,3,
                                     screen , sX , sY , screenWidth, screenHeight ,
                                     buttons[buttonNum].buttonsImg->pixels ,
                                      0, 0 ,
                                     buttons[buttonNum].buttonsImg->width ,
                                     buttons[buttonNum].buttonsImg->height,
                                     123,123,0,
                                     buttons[buttonNum].buttonsImg->width,
                                     buttons[buttonNum].buttonsImg->height ,
                                     &currentScore ,
                                     90000
                                    );
       fprintf(stderr,"Compared Button %u , score %u \n",buttonNum,currentScore);
      if (currentScore<90000)
      {
        fprintf(stderr,"Button %u Matches\n",buttonNum);
        *clickX = (unsigned int) sX + buttons[buttonNum].buttonsImg->width/2;
        *clickY = (unsigned int) sY + buttons[buttonNum].buttonsImg->height/2;
        return 1;
      }
   }
  fprintf(stderr,"No Button Matches\n");
  return 0;
}

variable_types:
screen
unsigned char *

variable_types:
screenWidth
unsigned int

variable_types:
screenHeight
unsigned int

variable_types:
clickX
unsigned int *

variable_types:
clickY
unsigned int *

variable_types:
currentScore
unsigned int

variable_types:
buttonNum
unsigned int

variable_types:
sX
unsigned int

variable_types:
sY
unsigned int


seeScore

decompiled_code:
__int64 __fastcall seeScore(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char *a8)
{
__int64 result; // rax

if ( (unsigned int)doOCR(a1, a2, a3, a4) )
{
printf("OCR String is %s \n", a8);
result = 1LL;
}
else
{
puts("Could not read an OCR String ");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char *a8)
{
__int64 result; // rax

if ( (unsigned int)doOCR(a1, a2, a3, a4) )
{
printf("OCR String is %s \n", a8);
result = 1LL;
}
else
{
puts("Could not read an OCR String ");
result = 0LL;
}
return result;
}

original_code:
int seeScore( unsigned char * screen , unsigned int screenWidth ,unsigned int screenHeight ,
              unsigned int x,unsigned int y , unsigned int width , unsigned int height ,
              char * strOutput , unsigned int strOutputMaxLength
            )
{
   if (
        doOCR(
              screen, screenWidth,screenHeight,
              x , y , width , height ,
              &scoreOCR ,
              strOutput ,
              strOutputMaxLength
             )
       )
        { printf("OCR String is %s \n",strOutput); return 1; } else
        { printf("Could not read an OCR String \n"); }
   return 0;
}

canonical_original_code:
int seeScore(unsigned char *screen, unsigned int screenWidth, unsigned int screenHeight, unsigned int x, unsigned int y, unsigned int width, unsigned int height, char *strOutput, unsigned int strOutputMaxLength)
{
   if (
        doOCR(
              screen, screenWidth,screenHeight,
              x , y , width , height ,
              &scoreOCR ,
              strOutput ,
              strOutputMaxLength
             )
       )
        { printf("OCR String is %s \n",strOutput); return 1; } else
        { printf("Could not read an OCR String \n"); }
   return 0;
}

variable_types:
width
unsigned int

variable_types:
height
unsigned int

variable_types:
strOutput
char *

variable_types:
strOutputMaxLength
unsigned int


initVision

decompiled_code:
__int64 initVision()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rdx
bool v3; // zf
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rdx
__int64 v8; // r12
__int64 v9; // rdx
__int64 v10; // r12
__int64 v11; // rdx
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // r12
__int64 v15; // rdx
unsigned int v16; // edx

set[0] = 0;
addToPatternSet(set, "Engines/Gweled/Pieces/hypercube", 8LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/yellow", 4LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/orange", 3LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/red", 6LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/blue", 5LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/green", 1LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/pink", 7LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/white", 2LL, 500LL);
dumpPatternSet(set, "Initialization");
scoreOCR[0] = 0;
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score0_", 48LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score1_", 49LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score2_", 50LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score3_", 51LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score4_", 52LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score5_", 53LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score6_", 54LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score7_", 55LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score8_", 56LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score9_", 57LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/scoreComma_", 44LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/scoreSpace_", 32LL, 500LL);
numberOfButtons = 0;
v0 = readImage("Engines/Gweled/Menus/xButton.pnm", 3LL, 0LL);
v1 = numberOfButtons;
buttons[0] = v0;
v2 = 2LL * numberOfButtons;
v3 = buttons[v2] == 0LL;
buttons[v2 + 1] = 0x3B000001EALL;
if ( !v3 )
{
v1 = (unsigned int)(v1 + 1);
numberOfButtons = v1;
}
buttons[2 * v1] = readImage("Engines/Gweled/Menus/playButton.pnm", 3LL, 0LL);
v4 = numberOfButtons;
v5 = 2LL * numberOfButtons;
v3 = buttons[v5] == 0LL;
buttons[v5 + 1] = 0xC9FFFFFFAALL;
if ( !v3 )
{
v4 = (unsigned int)(v4 + 1);
numberOfButtons = v4;
}
buttons[2 * v4] = readImage("Engines/Gweled/Menus/playNowButton.pnm", 3LL, 0LL);
v6 = numberOfButtons;
v7 = 2LL * numberOfButtons;
v3 = buttons[v7] == 0LL;
buttons[v7 + 1] = 0x1220000002ALL;
if ( !v3 )
{
v6 = (unsigned int)(v6 + 1);
numberOfButtons = v6;
}
buttons[2 * v6] = readImage("Engines/Gweled/Menus/noThanks.pnm", 3LL, 0LL);
v8 = numberOfButtons;
v9 = 2LL * numberOfButtons;
v3 = buttons[v9] == 0LL;
buttons[v9 + 1] = 0x13BFFFFFFE3LL;
if ( !v3 )
{
v8 = (unsigned int)(v8 + 1);
numberOfButtons = v8;
}
buttons[2 * v8] = readImage("Engines/Gweled/Menus/playAgain.pnm", 3LL, 0LL);
v10 = numberOfButtons;
v11 = 2LL * numberOfButtons;
v3 = buttons[v11] == 0LL;
buttons[v11 + 1] = 0x198FFFFFFE6LL;
if ( !v3 )
{
v10 = (unsigned int)(v10 + 1);
numberOfButtons = v10;
}
buttons[2 * v10] = readImage("Engines/Gweled/Menus/continueButton.pnm", 3LL, 0LL);
v12 = numberOfButtons;
v13 = 2LL * numberOfButtons;
v3 = buttons[v13] == 0LL;
buttons[v13 + 1] = 0x12C000000F3LL;
if ( !v3 )
{
v12 = (unsigned int)(v12 + 1);
numberOfButtons = v12;
}
buttons[2 * v12] = readImage("Engines/Gweled/Menus/cancelButton.pnm", 3LL, 0LL);
v14 = numberOfButtons;
v15 = 2LL * numberOfButtons;
v3 = buttons[v15] == 0LL;
buttons[v15 + 1] = 0x1AC0000007CLL;
if ( !v3 )
{
v14 = (unsigned int)(v14 + 1);
numberOfButtons = v14;
}
buttons[2 * v14] = readImage("Engines/Gweled/Menus/leaveParty.pnm", 3LL, 0LL);
v16 = numberOfButtons;
v3 = buttons[2 * numberOfButtons] == 0LL;
buttons[2 * numberOfButtons + 1] = 0x123FFFFFF7ALL;
if ( !v3 )
numberOfButtons = v16 + 1;
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rdx
bool v3; // zf
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rdx
__int64 v8; // r12
__int64 v9; // rdx
__int64 v10; // r12
__int64 v11; // rdx
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // r12
__int64 v15; // rdx
unsigned int v16; // edx

set[0] = 0;
addToPatternSet(set, "Engines/Gweled/Pieces/hypercube", 8LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/yellow", 4LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/orange", 3LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/red", 6LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/blue", 5LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/green", 1LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/pink", 7LL, 500LL);
addToPatternSet(set, "Engines/Gweled/Pieces/white", 2LL, 500LL);
dumpPatternSet(set, "Initialization");
scoreOCR[0] = 0;
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score0_", 48LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score1_", 49LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score2_", 50LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score3_", 51LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score4_", 52LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score5_", 53LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score6_", 54LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score7_", 55LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score8_", 56LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/score9_", 57LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/scoreComma_", 44LL, 500LL);
addToPatternSet(scoreOCR, "Engines/Gweled/OCR/scoreSpace_", 32LL, 500LL);
numberOfButtons = 0;
v0 = readImage("Engines/Gweled/Menus/xButton.pnm", 3LL, 0LL);
v1 = numberOfButtons;
buttons[0] = v0;
v2 = 2LL * numberOfButtons;
v3 = buttons[v2] == 0LL;
buttons[v2 + 1] = 0x3B000001EALL;
if ( !v3 )
{
v1 = (unsigned int)(v1 + 1);
numberOfButtons = v1;
}
buttons[2 * v1] = readImage("Engines/Gweled/Menus/playButton.pnm", 3LL, 0LL);
v4 = numberOfButtons;
v5 = 2LL * numberOfButtons;
v3 = buttons[v5] == 0LL;
buttons[v5 + 1] = 0xC9FFFFFFAALL;
if ( !v3 )
{
v4 = (unsigned int)(v4 + 1);
numberOfButtons = v4;
}
buttons[2 * v4] = readImage("Engines/Gweled/Menus/playNowButton.pnm", 3LL, 0LL);
v6 = numberOfButtons;
v7 = 2LL * numberOfButtons;
v3 = buttons[v7] == 0LL;
buttons[v7 + 1] = 0x1220000002ALL;
if ( !v3 )
{
v6 = (unsigned int)(v6 + 1);
numberOfButtons = v6;
}
buttons[2 * v6] = readImage("Engines/Gweled/Menus/noThanks.pnm", 3LL, 0LL);
v8 = numberOfButtons;
v9 = 2LL * numberOfButtons;
v3 = buttons[v9] == 0LL;
buttons[v9 + 1] = 0x13BFFFFFFE3LL;
if ( !v3 )
{
v8 = (unsigned int)(v8 + 1);
numberOfButtons = v8;
}
buttons[2 * v8] = readImage("Engines/Gweled/Menus/playAgain.pnm", 3LL, 0LL);
v10 = numberOfButtons;
v11 = 2LL * numberOfButtons;
v3 = buttons[v11] == 0LL;
buttons[v11 + 1] = 0x198FFFFFFE6LL;
if ( !v3 )
{
v10 = (unsigned int)(v10 + 1);
numberOfButtons = v10;
}
buttons[2 * v10] = readImage("Engines/Gweled/Menus/continueButton.pnm", 3LL, 0LL);
v12 = numberOfButtons;
v13 = 2LL * numberOfButtons;
v3 = buttons[v13] == 0LL;
buttons[v13 + 1] = 0x12C000000F3LL;
if ( !v3 )
{
v12 = (unsigned int)(v12 + 1);
numberOfButtons = v12;
}
buttons[2 * v12] = readImage("Engines/Gweled/Menus/cancelButton.pnm", 3LL, 0LL);
v14 = numberOfButtons;
v15 = 2LL * numberOfButtons;
v3 = buttons[v15] == 0LL;
buttons[v15 + 1] = 0x1AC0000007CLL;
if ( !v3 )
{
v14 = (unsigned int)(v14 + 1);
numberOfButtons = v14;
}
buttons[2 * v14] = readImage("Engines/Gweled/Menus/leaveParty.pnm", 3LL, 0LL);
v16 = numberOfButtons;
v3 = buttons[2 * numberOfButtons] == 0LL;
buttons[2 * numberOfButtons + 1] = 0x123FFFFFF7ALL;
if ( !v3 )
numberOfButtons = v16 + 1;
return 1LL;
}

original_code:
int initVision()
{
  set.totalPatterns=0;
  addToPatternSet(&set,"Engines/Gweled/Pieces/hypercube",HYPERCUBE_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/yellow",YELLOW_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/orange",ORANGE_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/red",RED_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/blue",BLUE_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/green",GREEN_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/pink",PINK_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/white",WHITE_PIECE,500);
  dumpPatternSet(&set,"Initialization");
    scoreOCR.totalPatterns=0;
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score0_",0+'0',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score1_",0+'1',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score2_",0+'2',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score3_",0+'3',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score4_",0+'4',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score5_",0+'5',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score6_",0+'6',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score7_",0+'7',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score8_",0+'8',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score9_",0+'9',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/scoreComma_",0+',',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/scoreSpace_",0+' ',500);
  numberOfButtons=0;
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/xButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 827 - 337;
  buttons[numberOfButtons].checkY = (signed int) 441 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/playButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 251 - 337;
  buttons[numberOfButtons].checkY = (signed int) 583 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/playNowButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 379 - 337 ;
  buttons[numberOfButtons].checkY = (signed int) 672 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/noThanks.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 308 - 337 ;
  buttons[numberOfButtons].checkY = (signed int) 697 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/playAgain.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 311 - 337;
  buttons[numberOfButtons].checkY = (signed int) 790 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/continueButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 580 - 337;
  buttons[numberOfButtons].checkY = (signed int) 682 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/cancelButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 743 - 619;
  buttons[numberOfButtons].checkY = (signed int) 782 - 354;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/leaveParty.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (signed int) 485 - 619;
  buttons[numberOfButtons].checkY = (signed int) 645 - 354;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  return 1;
}

canonical_original_code:
int initVision()
{
  set.totalPatterns=0;
  addToPatternSet(&set,"Engines/Gweled/Pieces/hypercube",HYPERCUBE_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/yellow",YELLOW_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/orange",ORANGE_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/red",RED_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/blue",BLUE_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/green",GREEN_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/pink",PINK_PIECE,500);
  addToPatternSet(&set,"Engines/Gweled/Pieces/white",WHITE_PIECE,500);
  dumpPatternSet(&set,"Initialization");
    scoreOCR.totalPatterns=0;
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score0_",0+'0',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score1_",0+'1',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score2_",0+'2',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score3_",0+'3',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score4_",0+'4',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score5_",0+'5',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score6_",0+'6',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score7_",0+'7',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score8_",0+'8',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/score9_",0+'9',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/scoreComma_",0+',',500);
    addToPatternSet(&scoreOCR,"Engines/Gweled/OCR/scoreSpace_",0+' ',500);
  numberOfButtons=0;
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/xButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 827 - 337;
  buttons[numberOfButtons].checkY = (int) 441 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/playButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 251 - 337;
  buttons[numberOfButtons].checkY = (int) 583 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/playNowButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 379 - 337 ;
  buttons[numberOfButtons].checkY = (int) 672 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/noThanks.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 308 - 337 ;
  buttons[numberOfButtons].checkY = (int) 697 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/playAgain.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 311 - 337;
  buttons[numberOfButtons].checkY = (int) 790 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/continueButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 580 - 337;
  buttons[numberOfButtons].checkY = (int) 682 - 382;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/cancelButton.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 743 - 619;
  buttons[numberOfButtons].checkY = (int) 782 - 354;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  buttons[numberOfButtons].buttonsImg=readImage("Engines/Gweled/Menus/leaveParty.pnm",PNM_CODEC,0);
  buttons[numberOfButtons].checkX = (int) 485 - 619;
  buttons[numberOfButtons].checkY = (int) 645 - 354;
  if (buttons[numberOfButtons].buttonsImg!=0) { ++numberOfButtons; }
  return 1;
}


stopVision

decompiled_code:
__int64 stopVision()
{
emptyPatternSet(set);
emptyPatternSet(scoreOCR);
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
emptyPatternSet(set);
emptyPatternSet(scoreOCR);
return 1LL;
}

original_code:
int stopVision()
{
  emptyPatternSet(&set);
  emptyPatternSet(&scoreOCR);
  return 1;
}


WriteJPEGFile

decompiled_code:
__int64 __fastcall WriteJPEGFile(__int64 *a1, char *a2)
{
return WriteJPEGInternal(a2, a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, char *a2)
{
return func5(a2, a1, 0LL, 0LL);
}

original_code:
int WriteJPEGFile(struct Image * pic,char *filename)
{
    return WriteJPEGInternal(filename,pic,0,0);
}

canonical_original_code:
int WriteJPEGFile(struct Image *pic, char *filename)
{
    return WriteJPEGInternal(filename,pic,0,0);
}

variable_types: struct Image { unsigned char *pixels; unsigned int width; unsigned int height; unsigned int channels; unsigned int bitsperpixel; unsigned int image_size; } *

variable_types:
filename
char *


WriteJPEGMemory

decompiled_code:
__int64 __fastcall WriteJPEGMemory(__int64 *a1, const void *a2, __int64 *a3)
{
return WriteJPEGInternal(0LL, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, const void *a2, __int64 *a3)
{
return func5(0LL, a1, a2, a3);
}

original_code:
int WriteJPEGMemory(struct Image * pic,char *mem,unsigned long * mem_size)
{
    return WriteJPEGInternal(0,pic,mem,mem_size);
}

canonical_original_code:
int WriteJPEGMemory(struct Image *pic, char *mem, unsigned long *mem_size)
{
    return WriteJPEGInternal(0,pic,mem,mem_size);
}

variable_types:
mem
char *


jpegtest

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

if ( (int)ReadJPEG("test.jpg", 0LL, 0) <= 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)WriteJPEGFile(0LL, "test_out.jpg") >> 31);
return result;
}

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

if ( (int)func4("test.jpg", 0LL, 0) <= 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)func6(0LL, "test_out.jpg") >> 31);
return result;
}

original_code:
int jpegtest()
{
 char *infilename = (char*) "test.jpg", *outfilename = (char*) "test_out.jpg";
 if( ReadJPEG( infilename , 0 , 0 ) > 0 )
 {
  if( WriteJPEGFile( 0 , outfilename ) < 0 ) return -1;
 }
 else return -1;
 return 0;
}

canonical_original_code:
int jpegtest()
{
 char *infilename = (char*) "test.jpg"; char *outfilename = (char*) "test_out.jpg";
 if( ReadJPEG( infilename , 0 , 0 ) > 0 )
 {
  if( WriteJPEGFile( 0 , outfilename ) < 0 ) return -1;
 }
 else return -1;
 return 0;
}

variable_types:
infilename
char *

variable_types:
outfilename
char *


simplePow

decompiled_code:
__int64 __fastcall simplePow(unsigned int a1, int a2)
{
unsigned int v2; // er8
int v3; // esi
int i; // eax

v2 = 1;
if ( a2 )
{
v2 = a1;
v3 = a2 - 1;
if ( v3 )
{
for ( i = 0; i != v3; ++i )
v2 *= a1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
unsigned int v2; // er8
int v3; // esi
int i; // eax

v2 = 1;
if ( a2 )
{
v2 = a1;
v3 = a2 - 1;
if ( v3 )
{
for ( i = 0; i != v3; ++i )
v2 *= a1;
}
}
return v2;
}

original_code:
unsigned int simplePow(unsigned int base,unsigned int exp)
{
    if (exp==0) return 1;
    unsigned int retres=base;
    unsigned int i=0;
    for (i=0; i<exp-1; i++)
    {
        retres*=base;
    }
    return retres;
}

canonical_original_code:
unsigned int simplePow(unsigned int base, unsigned int exp)
{
    if (exp==0) return 1;
    unsigned int retres = base;
    unsigned int i = 0;
    for (i=0; i<exp-1; i++)
    {
        retres*=base;
    }
    return retres;
}

variable_types:
base
unsigned int

variable_types:
exp
unsigned int

variable_types:
retres
unsigned int

variable_types:
i
unsigned int


writeImageFile

decompiled_code:
__int64 __fastcall writeImageFile(void *ptr, unsigned int a2, __int64 a3)
{
if ( a2 > 3 )
{
if ( a2 == 4 && !(unsigned int)WritePNG(a3, ptr) )
free(ptr);
return 0LL;
}
if ( a2 <= 1 )
{
if ( a2 == 1 )
return WriteJPEGFile(ptr, a3);
return 0LL;
}
WritePPM(a3, ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr, unsigned int a2, __int64 a3)
{
if ( a2 > 3 )
{
if ( a2 == 4 && !(unsigned int)WritePNG(a3, ptr) )
free(ptr);
return 0LL;
}
if ( a2 <= 1 )
{
if ( a2 == 1 )
return WriteJPEGFile(ptr, a3);
return 0LL;
}
WritePPM(a3, ptr);
return 0LL;
}

original_code:
int writeImageFile(struct Image * pic,unsigned int type,char *filename)
{
   switch (type)
   {
      case JPG_CODEC :
       return WriteJPEGFile(pic,filename);
      case PPM_CODEC :
      case PNM_CODEC :
       WritePPM(filename,pic);
      break;
      case PNG_CODEC :
       if (!WritePNG(filename,pic)) { free(pic); pic=0; }
      break;
      default :
        break;
   };
   return 0;
}

canonical_original_code:
int writeImageFile(struct Image *pic, unsigned int type, char *filename)
{
   switch (type)
   {
      case JPG_CODEC :
       return WriteJPEGFile(pic,filename);
      case PPM_CODEC :
      case PNM_CODEC :
       WritePPM(filename,pic);
      break;
      case PNG_CODEC :
       if (!WritePNG(filename,pic)) { free(pic); pic=0; }
      break;
      default :
        break;
   };
   return 0;
}

variable_types:
type
unsigned int


writeImageMemory

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

if ( a2 == 1 )
result = WriteJPEGMemory(a1, a3, a4);
else
result = 0LL;
return result;
}

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

if ( a2 == 1 )
result = WriteJPEGMemory(a1, a3, a4);
else
result = 0LL;
return result;
}

original_code:
int writeImageMemory(struct Image * pic,unsigned int type,char *mem,unsigned long * mem_size)
{
   switch (type)
   {
      case JPG_CODEC :
       return WriteJPEGMemory(pic,mem,mem_size);
      default :
        break;
   };
   return 0;
}

canonical_original_code:
int writeImageMemory(struct Image *pic, unsigned int type, char *mem, unsigned long *mem_size)
{
   switch (type)
   {
      case JPG_CODEC :
       return WriteJPEGMemory(pic,mem,mem_size);
      default :
        break;
   };
   return 0;
}


destroyImage

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

if ( !ptr )
return 0LL;
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
return 1LL;
}

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

if ( !ptr )
return 0LL;
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
return 1LL;
}

original_code:
int destroyImage(struct Image * img)
{
    if (img==0) {return 0; }
    if (img->pixels!=0) { free(img->pixels); img->pixels=0; }
    if (img!=0) { free(img); img=0; }
    return 1;
}

canonical_original_code:
int destroyImage(struct Image *img)
{
    if (img==0) {return 0; }
    if (img->pixels!=0) { free(img->pixels); img->pixels=0; }
    if (img!=0) { free(img); img=0; }
    return 1;
}