initVision

decompiled_code:
__int64 initVision()
{
unsigned int v0; // ecx
char *v1; // rax
unsigned int v2; // ebx
unsigned int v3; // ecx
char *v4; // rax
unsigned int v5; // ebx
unsigned int v6; // ecx
char *v7; // rax
unsigned int v8; // ebx
unsigned int v9; // ecx
char *v10; // rax
unsigned int v11; // ebx
unsigned int v12; // ecx
char *v13; // rax
unsigned int v14; // ebx
unsigned int v15; // ecx
char *v16; // rax
unsigned int v17; // ebx
unsigned int v18; // ecx
char *v19; // rax
unsigned int v20; // ebx
unsigned int v21; // ecx
char *v22; // rax

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;
buttons[0] = readImage("Engines/Gweled/Menus/xButton.pnm", 3LL, 0LL);
v0 = numberOfButtons;
v1 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v1 + 2) = 490;
*((_DWORD *)v1 + 3) = 59;
if ( *(_QWORD *)v1 )
numberOfButtons = v0 + 1;
v2 = numberOfButtons;
buttons[2 * v2] = readImage("Engines/Gweled/Menus/playButton.pnm", 3LL, 0LL);
v3 = numberOfButtons;
v4 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v4 + 2) = -86;
*((_DWORD *)v4 + 3) = 201;
if ( *(_QWORD *)v4 )
numberOfButtons = v3 + 1;
v5 = numberOfButtons;
buttons[2 * v5] = readImage("Engines/Gweled/Menus/playNowButton.pnm", 3LL, 0LL);
v6 = numberOfButtons;
v7 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v7 + 2) = 42;
*((_DWORD *)v7 + 3) = 290;
if ( *(_QWORD *)v7 )
numberOfButtons = v6 + 1;
v8 = numberOfButtons;
buttons[2 * v8] = readImage("Engines/Gweled/Menus/noThanks.pnm", 3LL, 0LL);
v9 = numberOfButtons;
v10 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v10 + 2) = -29;
*((_DWORD *)v10 + 3) = 315;
if ( *(_QWORD *)v10 )
numberOfButtons = v9 + 1;
v11 = numberOfButtons;
buttons[2 * v11] = readImage("Engines/Gweled/Menus/playAgain.pnm", 3LL, 0LL);
v12 = numberOfButtons;
v13 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v13 + 2) = -26;
*((_DWORD *)v13 + 3) = 408;
if ( *(_QWORD *)v13 )
numberOfButtons = v12 + 1;
v14 = numberOfButtons;
buttons[2 * v14] = readImage("Engines/Gweled/Menus/continueButton.pnm", 3LL, 0LL);
v15 = numberOfButtons;
v16 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v16 + 2) = 243;
*((_DWORD *)v16 + 3) = 300;
if ( *(_QWORD *)v16 )
numberOfButtons = v15 + 1;
v17 = numberOfButtons;
buttons[2 * v17] = readImage("Engines/Gweled/Menus/cancelButton.pnm", 3LL, 0LL);
v18 = numberOfButtons;
v19 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v19 + 2) = 124;
*((_DWORD *)v19 + 3) = 428;
if ( *(_QWORD *)v19 )
numberOfButtons = v18 + 1;
v20 = numberOfButtons;
buttons[2 * v20] = readImage("Engines/Gweled/Menus/leaveParty.pnm", 3LL, 0LL);
v21 = numberOfButtons;
v22 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v22 + 2) = -134;
*((_DWORD *)v22 + 3) = 291;
if ( *(_QWORD *)v22 )
numberOfButtons = v21 + 1;
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ecx
char *v1; // rax
unsigned int v2; // ebx
unsigned int v3; // ecx
char *v4; // rax
unsigned int v5; // ebx
unsigned int v6; // ecx
char *v7; // rax
unsigned int v8; // ebx
unsigned int v9; // ecx
char *v10; // rax
unsigned int v11; // ebx
unsigned int v12; // ecx
char *v13; // rax
unsigned int v14; // ebx
unsigned int v15; // ecx
char *v16; // rax
unsigned int v17; // ebx
unsigned int v18; // ecx
char *v19; // rax
unsigned int v20; // ebx
unsigned int v21; // ecx
char *v22; // rax

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;
buttons[0] = readImage("Engines/Gweled/Menus/xButton.pnm", 3LL, 0LL);
v0 = numberOfButtons;
v1 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v1 + 2) = 490;
*((_DWORD *)v1 + 3) = 59;
if ( *(_QWORD *)v1 )
numberOfButtons = v0 + 1;
v2 = numberOfButtons;
buttons[2 * v2] = readImage("Engines/Gweled/Menus/playButton.pnm", 3LL, 0LL);
v3 = numberOfButtons;
v4 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v4 + 2) = -86;
*((_DWORD *)v4 + 3) = 201;
if ( *(_QWORD *)v4 )
numberOfButtons = v3 + 1;
v5 = numberOfButtons;
buttons[2 * v5] = readImage("Engines/Gweled/Menus/playNowButton.pnm", 3LL, 0LL);
v6 = numberOfButtons;
v7 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v7 + 2) = 42;
*((_DWORD *)v7 + 3) = 290;
if ( *(_QWORD *)v7 )
numberOfButtons = v6 + 1;
v8 = numberOfButtons;
buttons[2 * v8] = readImage("Engines/Gweled/Menus/noThanks.pnm", 3LL, 0LL);
v9 = numberOfButtons;
v10 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v10 + 2) = -29;
*((_DWORD *)v10 + 3) = 315;
if ( *(_QWORD *)v10 )
numberOfButtons = v9 + 1;
v11 = numberOfButtons;
buttons[2 * v11] = readImage("Engines/Gweled/Menus/playAgain.pnm", 3LL, 0LL);
v12 = numberOfButtons;
v13 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v13 + 2) = -26;
*((_DWORD *)v13 + 3) = 408;
if ( *(_QWORD *)v13 )
numberOfButtons = v12 + 1;
v14 = numberOfButtons;
buttons[2 * v14] = readImage("Engines/Gweled/Menus/continueButton.pnm", 3LL, 0LL);
v15 = numberOfButtons;
v16 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v16 + 2) = 243;
*((_DWORD *)v16 + 3) = 300;
if ( *(_QWORD *)v16 )
numberOfButtons = v15 + 1;
v17 = numberOfButtons;
buttons[2 * v17] = readImage("Engines/Gweled/Menus/cancelButton.pnm", 3LL, 0LL);
v18 = numberOfButtons;
v19 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v19 + 2) = 124;
*((_DWORD *)v19 + 3) = 428;
if ( *(_QWORD *)v19 )
numberOfButtons = v18 + 1;
v20 = numberOfButtons;
buttons[2 * v20] = readImage("Engines/Gweled/Menus/leaveParty.pnm", 3LL, 0LL);
v21 = numberOfButtons;
v22 = (char *)&buttons[2 * numberOfButtons];
*((_DWORD *)v22 + 2) = -134;
*((_DWORD *)v22 + 3) = 291;
if ( *(_QWORD *)v22 )
numberOfButtons = v21 + 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

repo: AmmarkoV/VisualBotNGine

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;
}

return_type: int


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 *

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


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; // edx
int v3; // esi
int i; // eax

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

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

v2 = 1;
if ( a2 )
{
v3 = a2 - 1;
if ( v3 )
{
v2 = a1;
for ( i = 0; i != v3; ++i )
v2 *= a1;
}
else
{
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

return_type: unsigned int


writeImageFile

decompiled_code:
__int64 __fastcall writeImageFile(void *ptr, unsigned int a2, __int64 a3)
{
unsigned int v3; // ebx

if ( a2 > 3 )
{
v3 = 0;
if ( a2 == 4 )
{
v3 = WritePNG(a3, ptr);
if ( v3 )
v3 = 0;
else
free(ptr);
}
}
else if ( a2 > 1 )
{
WritePPM(a3, ptr);
v3 = 0;
}
else
{
v3 = 0;
if ( a2 == 1 )
v3 = WriteJPEGFile(ptr, a3);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr, unsigned int a2, __int64 a3)
{
unsigned int v3; // ebx

if ( a2 > 3 )
{
v3 = 0;
if ( a2 == 4 )
{
v3 = WritePNG(a3, ptr);
if ( v3 )
v3 = 0;
else
free(ptr);
}
}
else if ( a2 > 1 )
{
WritePPM(a3, ptr);
v3 = 0;
}
else
{
v3 = 0;
if ( a2 == 1 )
v3 = WriteJPEGFile(ptr, a3);
}
return v3;
}

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

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

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

result = 0LL;
if ( a2 == 1 )
result = WriteJPEGMemory(a1, a3, a4);
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;
}


addToPatternSet

decompiled_code:
__int64 __fastcall addToPatternSet(_DWORD *a1, const char *a2, int a3, int a4)
{
__int64 v6; // r12
unsigned int v7; // er14
unsigned int v8; // ebx
__int64 v9; // r15
__int64 v10; // rax
__int64 v11; // rdx
int v12; // er12
int v13; // ecx
__int64 v14; // rax
__int64 v15; // rax
unsigned int v17; // [rsp+1Ch] [rbp-24Ch]
_DWORD *v18; // [rsp+28h] [rbp-240h]
char s[568]; // [rsp+30h] [rbp-238h] BYREF

v17 = (*a1)++;
v6 = 1156LL * v17;
strncpy((char *)&a1[v6 + 1030], a2, 0x7EuLL);
v18 = &a1[v6];
v18[3] = a3;
v18[5] = a4;
*((_BYTE *)v18 + 16) = 1;
v7 = 0;
v8 = 1;
v9 = 578LL * v17;
while ( 1 )
{
snprintf(s, 0x200uLL, "%s%u.pnm", a2, v8);
if ( !(unsigned int)patFileExists(s) )
break;
v15 = readImage(s, 3LL, 0LL);
*(_QWORD *)&a1[2 * v7 + 6 + 2 * v9] = v15;
if ( v15 )
{
fprintf(stderr, "\x1B[32mLoaded %s , we now have %u patterns for set %u\n\x1B[0m", s, v7, v17);
v10 = *(_QWORD *)&a1[2 * v7 + 6 + 2 * v9];
v11 = *(unsigned int *)(v10 + 12);
v12 = v11 * *(_DWORD *)(v10 + 8);
v13 = countOccurancesOfRGBPixel(*(_QWORD *)v10, *(unsigned int *)(v10 + 8), v11, 123LL, 123LL, 0LL);
v14 = 1156LL * v17 + v7;
a1[v14 + 518] = v12 - v13;
a1[v14 + 774] = v12;
++v7;
}
if ( ++v8 == 255 )
return 1LL;
}
if ( v8 == 1 )
fprintf(stderr, "\x1B[31mFailed to load any files for #%u -> %s \n\x1B[0m", 1LL, s);
v18[2] = v7;
return 1LL;
}

original_code:
int addToPatternSet(struct PatternSet * set , char * name , unsigned int value , unsigned int score)
{
  unsigned int curSetNum = set->totalPatterns;
  ++set->totalPatterns;
  strncpy(set->pattern[curSetNum].name,name,126);
  set->pattern[curSetNum].value=value;
  set->pattern[curSetNum].acceptScore=score;
  set->pattern[curSetNum].use=1;
  char fName[512];
  unsigned int i=1;
  unsigned int totalTiles = 0;
  while (i<255)
  {
      snprintf(fName,512,"%s%u.pnm",name,i);
      if (patFileExists(fName))
      {
        set->pattern[curSetNum].tile[totalTiles] = readImage( fName , PNM_CODEC , 0 );
        if (set->pattern[curSetNum].tile[totalTiles]!=0)
        {
          fprintf(stderr,"\033[32m" "Loaded %s , we now have %u patterns for set %u\n" "\033[0m",fName, totalTiles , curSetNum);
          unsigned int totalPixels = set->pattern[curSetNum].tile[totalTiles]->width * set->pattern[curSetNum].tile[totalTiles]->height;
          unsigned int transPixels = countOccurancesOfRGBPixel(set->pattern[curSetNum].tile[totalTiles]->pixels,
                                                                                set->pattern[curSetNum].tile[totalTiles]->width,
                                                                                set->pattern[curSetNum].tile[totalTiles]->height,
                                                                                123,123,0);
          set->pattern[curSetNum].nonTransparentPixels[totalTiles] = totalPixels - transPixels;
          set->pattern[curSetNum].totalPixels[totalTiles]= totalPixels ;
          ++totalTiles;
        }
      } else
      {
        if (i==1) { fprintf(stderr,"\033[31m" "Failed to load any files for #%u -> %s \n" "\033[0m",i,fName); }
        set->pattern[curSetNum].totalTiles=totalTiles ;
        break;
      }
      ++i;
  }
  return 1;
}

canonical_original_code:
int addToPatternSet(struct PatternSet *set, char *name, unsigned int value, unsigned int score)
{
  unsigned int curSetNum = set->totalPatterns;
  ++set->totalPatterns;
  strncpy(set->pattern[curSetNum].name,name,126);
  set->pattern[curSetNum].value=value;
  set->pattern[curSetNum].acceptScore=score;
  set->pattern[curSetNum].use=1;
  char fName[512];
  unsigned int i = 1;
  unsigned int totalTiles = 0;
  while (i<255)
  {
      snprintf(fName,512,"%s%u.pnm",name,i);
      if (patFileExists(fName))
      {
        set->pattern[curSetNum].tile[totalTiles] = readImage( fName , PNM_CODEC , 0 );
        if (set->pattern[curSetNum].tile[totalTiles]!=0)
        {
          fprintf(stderr,"\033[32m" "Loaded %s , we now have %u patterns for set %u\n" "\033[0m",fName, totalTiles , curSetNum);
          unsigned int totalPixels = set->pattern[curSetNum].tile[totalTiles]->width * set->pattern[curSetNum].tile[totalTiles]->height;
          unsigned int transPixels = countOccurancesOfRGBPixel(set->pattern[curSetNum].tile[totalTiles]->pixels,
                                                                                set->pattern[curSetNum].tile[totalTiles]->width,
                                                                                set->pattern[curSetNum].tile[totalTiles]->height,
                                                                                123,123,0);
          set->pattern[curSetNum].nonTransparentPixels[totalTiles] = totalPixels - transPixels;
          set->pattern[curSetNum].totalPixels[totalTiles]= totalPixels ;
          ++totalTiles;
        }
      } else
      {
        if (i==1) { fprintf(stderr,"\033[31m" "Failed to load any files for #%u -> %s \n" "\033[0m",i,fName); }
        set->pattern[curSetNum].totalTiles=totalTiles ;
        break;
      }
      ++i;
  }
  return 1;
}

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:
name
char *

variable_types:
value
unsigned int

variable_types:
score
unsigned int

variable_types:
curSetNum
unsigned int

variable_types:
fName
char [512]

variable_types:
totalTiles
unsigned int

variable_types:
totalPixels
unsigned int

variable_types:
transPixels
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]; }


dumpPatternSet

decompiled_code:
__int64 dumpPatternSet()
{
fwrite("dumping Pattern sets deactivated\n", 1uLL, 0x21uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
fwrite("dumping Pattern sets deactivated\n", 1uLL, 0x21uLL, stderr);
return 0LL;
}

original_code:
int dumpPatternSet(struct PatternSet * pattSet ,char * stage)
{
  fprintf(stderr,"dumping Pattern sets deactivated\n");
  return 0;
 unsigned int tileNum=0;
 unsigned int patternNum=0;
 char fName[512];
 for ( patternNum=0; patternNum < pattSet->totalPatterns; patternNum++ )
 {
   fprintf(stderr,"Dumping %s %s :  ",stage,pattSet->pattern[patternNum].name);
   if (pattSet->pattern[patternNum].totalTiles==0)
   {
    fprintf(stderr,"EMPTY");
   } else
   {
     for ( tileNum=0; tileNum < pattSet->pattern[patternNum].totalTiles; tileNum++ )
      {
        snprintf(fName,512,"Dump/%sPattern%uTile%u.pnm",stage,patternNum,tileNum);
        fprintf(stderr,"%s ",fName);
        writeImageFile(pattSet->pattern[patternNum].tile[tileNum],PNM_CODEC,fName);
      }
   }
   fprintf(stderr,"\n");
  }
}

canonical_original_code:
int dumpPatternSet(struct PatternSet *pattSet, char *stage)
{
  fprintf(stderr,"dumping Pattern sets deactivated\n");
  return 0;
 unsigned int tileNum = 0;
 unsigned int patternNum = 0;
 char fName[512];
 for ( patternNum=0; patternNum < pattSet->totalPatterns; patternNum++ )
 {
   fprintf(stderr,"Dumping %s %s :  ",stage,pattSet->pattern[patternNum].name);
   if (pattSet->pattern[patternNum].totalTiles==0)
   {
    fprintf(stderr,"EMPTY");
   } else
   {
     for ( tileNum=0; tileNum < pattSet->pattern[patternNum].totalTiles; tileNum++ )
      {
        snprintf(fName,512,"Dump/%sPattern%uTile%u.pnm",stage,patternNum,tileNum);
        fprintf(stderr,"%s ",fName);
        writeImageFile(pattSet->pattern[patternNum].tile[tileNum],PNM_CODEC,fName);
      }
   }
   fprintf(stderr,"\n");
  }
}

variable_types:
stage
char *

variable_types:
tileNum
unsigned int

variable_types:
patternNum
unsigned int


emptyPatternSet

decompiled_code:
__int64 __fastcall emptyPatternSet(unsigned int *a1)
{
unsigned int i; // er13
unsigned int j; // ebp
_QWORD *v4; // rbx
unsigned int *v5; // r12

for ( i = 0; *a1 > i; ++i )
{
v5 = &a1[1156 * i];
v4 = v5 + 6;
for ( j = 0; v5[2] > j; ++v4 )
{
destroyImage(*v4);
*v4 = 0LL;
++j;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
unsigned int i; // er13
unsigned int j; // ebp
_QWORD *v4; // rbx
unsigned int *v5; // r12

for ( i = 0; *a1 > i; ++i )
{
v5 = &a1[1156 * i];
v4 = v5 + 6;
for ( j = 0; v5[2] > j; ++v4 )
{
destroyImage(*v4);
*v4 = 0LL;
++j;
}
}
return 1LL;
}

original_code:
int emptyPatternSet(struct PatternSet * pattSet)
{
  unsigned int tileNum=0;
  unsigned int patternNum=0;
  for ( patternNum=0; patternNum < pattSet->totalPatterns; patternNum++ )
  {
   for ( tileNum=0; tileNum < pattSet->pattern[patternNum].totalTiles; tileNum++ )
   {
        destroyImage( pattSet->pattern[patternNum].tile[tileNum] );
        pattSet->pattern[patternNum].tile[tileNum]=0;
   }
  }
    return 1;
}

canonical_original_code:
int emptyPatternSet(struct PatternSet *pattSet)
{
  unsigned int tileNum = 0;
  unsigned int patternNum = 0;
  for ( patternNum=0; patternNum < pattSet->totalPatterns; patternNum++ )
  {
   for ( tileNum=0; tileNum < pattSet->pattern[patternNum].totalTiles; tileNum++ )
   {
        destroyImage( pattSet->pattern[patternNum].tile[tileNum] );
        pattSet->pattern[patternNum].tile[tileNum]=0;
   }
  }
    return 1;
}


getPatternSetItemWidth

decompiled_code:
__int64 __fastcall getPatternSetItemWidth(unsigned int *a1, unsigned int a2, int a3)
{
__int64 v3; // rcx

v3 = *a1;
if ( (unsigned int)v3 > a2 )
return *(unsigned int *)(*(_QWORD *)&a1[1156 * a2 + 6 + 2 * a3] + 8LL);
fprintf(stderr, "getPatternSetItemWidth asking for out of bounds pattern ( number %u / %u )\n", a2, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, unsigned int a2, int a3)
{
__int64 v3; // rcx

v3 = *a1;
if ( (unsigned int)v3 > a2 )
return *(unsigned int *)(*(_QWORD *)&a1[1156 * a2 + 6 + 2 * a3] + 8LL);
fprintf(stderr, "getPatternSetItemWidth asking for out of bounds pattern ( number %u / %u )\n", a2, v3);
return 0LL;
}

original_code:
unsigned int getPatternSetItemWidth(struct PatternSet * pattSet , unsigned int patternNum , unsigned int tileNum)
{
    if (patternNum<pattSet->totalPatterns)
    {
      return pattSet->pattern[patternNum].tile[tileNum]->width;
    }
 fprintf(stderr,"getPatternSetItemWidth asking for out of bounds pattern ( number %u / %u )\n",patternNum,pattSet->totalPatterns);
 return 0;
}

canonical_original_code:
unsigned int getPatternSetItemWidth(struct PatternSet *pattSet, unsigned int patternNum, unsigned int tileNum)
{
    if (patternNum<pattSet->totalPatterns)
    {
      return pattSet->pattern[patternNum].tile[tileNum]->width;
    }
 fprintf(stderr,"getPatternSetItemWidth asking for out of bounds pattern ( number %u / %u )\n",patternNum,pattSet->totalPatterns);
 return 0;
}


compareToPatternSet

decompiled_code:
__int64 __fastcall compareToPatternSet(_DWORD *a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, unsigned int a9, unsigned int *a10, unsigned int *a11, unsigned int *a12)
{
unsigned int v12; // er12
__int64 v13; // rbx
unsigned int v14; // eax
_DWORD *v15; // rbp
__int64 result; // rax
__int64 v17; // rax
unsigned int v18; // [rsp+10h] [rbp-488h]
__int64 v23; // [rsp+38h] [rbp-460h]
unsigned int v24; // [rsp+44h] [rbp-454h]
unsigned int v25; // [rsp+48h] [rbp-450h]
unsigned int v26; // [rsp+4Ch] [rbp-44Ch]
char v27[8]; // [rsp+50h] [rbp-448h] BYREF
__int64 v28; // [rsp+58h] [rbp-440h]
char v29[496]; // [rsp+60h] [rbp-438h] BYREF
char s[8]; // [rsp+250h] [rbp-248h] BYREF
__int64 v31; // [rsp+258h] [rbp-240h]
char v32[496]; // [rsp+260h] [rbp-238h] BYREF
unsigned int v33[15]; // [rsp+45Ch] [rbp-3Ch] BYREF

v33[0] = a9 + 1;
if ( *a1 )
{
v18 = a9 + 1;
v12 = 0;
v26 = 0;
v25 = 0;
v24 = 0;
while ( 1 )
{
v23 = 1156LL * v12;
v15 = &a1[v23];
if ( a1[v23 + 2] )
{
v13 = 0LL;
do
{
v33[0] = a9 + 1;
if ( (unsigned int)compareRGBPatchesIgnoreColor(
a2,
a5,
a6,
a3,
a4,
**(_QWORD **)&v15[2 * v13 + 6],
0LL,
0LL,
*(unsigned int *)(*(_QWORD *)&v15[2 * v13 + 6] + 8LL),
*(unsigned int *)(*(_QWORD *)&v15[2 * v13 + 6] + 12LL),
123LL,
123LL,
0LL,
a7,
a8,
v33,
10 * a9) )
{
v14 = (int)(float)((float)(v15[v13 + 774] / v15[v13 + 518]) * (float)(int)v33[0]);
v33[0] = v14;
if ( v14 < v18 )
{
v24 = v15[3];
v26 = v13;
v25 = v12;
v18 = v14;
}
}
++v13;
}
while ( v15[2] > (unsigned int)v13 );
}
if ( v15[5] > v18 )
break;
if ( *a1 <= ++v12 )
goto LABEL_14;
}
fprintf(stderr, "INSTA-Selected %s with a score of %u \n", (const char *)&a1[v23 + 1030], v18);
*a10 = v24;
*a11 = v25;
*a12 = v26;
result = 1LL;
}
else
{
v26 = 0;
v25 = 0;
v24 = 0;
v18 = a9 + 1;
LABEL_14:
fprintf(stderr, "Thinking about best score\n");
result = 0LL;
if ( a9 > v18 )
{
*(_QWORD *)v27 = 0LL;
v28 = 0LL;
memset(v29, 0, sizeof(v29));
*(_QWORD *)s = 0LL;
v31 = 0LL;
memset(v32, 0, sizeof(v32));
snprintf(s, 0x200uLL, "Dump/tile%u_%u_like_%u_%u_score_%u", 0LL, 0LL, v25, v26, v18);
snprintf(v27, 0x200uLL, "Most like %u with score %u", v24, v18);
bitBltRGBToFile(s, v27, a2, a5, a6, a3, a4, a7, a8);
snprintf(s, 0x200uLL, "Dump/tile%u_%u_like_%u_%u_score_%uB", 0LL, 0LL, v25, v26, v18);
v17 = *(_QWORD *)&a1[1156 * v25 + 6 + 2 * v26];
bitBltRGBToFile(
s,
v27,
*(_QWORD *)v17,
0LL,
0LL,
*(unsigned int *)(v17 + 8),
*(unsigned int *)(v17 + 12),
*(unsigned int *)(v17 + 8),
*(_DWORD *)(v17 + 12));
fprintf(stderr, "Not so sure , but selected %u with a score of %u \n", v24, v18);
*a10 = v24;
*a11 = v25;
*a12 = v26;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, unsigned int a9, unsigned int *a10, unsigned int *a11, unsigned int *a12)
{
unsigned int v12; // er12
__int64 v13; // rbx
unsigned int v14; // eax
_DWORD *v15; // rbp
__int64 result; // rax
__int64 v17; // rax
unsigned int v18; // [rsp+10h] [rbp-488h]
__int64 v23; // [rsp+38h] [rbp-460h]
unsigned int v24; // [rsp+44h] [rbp-454h]
unsigned int v25; // [rsp+48h] [rbp-450h]
unsigned int v26; // [rsp+4Ch] [rbp-44Ch]
char v27[8]; // [rsp+50h] [rbp-448h] BYREF
__int64 v28; // [rsp+58h] [rbp-440h]
char v29[496]; // [rsp+60h] [rbp-438h] BYREF
char s[8]; // [rsp+250h] [rbp-248h] BYREF
__int64 v31; // [rsp+258h] [rbp-240h]
char v32[496]; // [rsp+260h] [rbp-238h] BYREF
unsigned int v33[15]; // [rsp+45Ch] [rbp-3Ch] BYREF

v33[0] = a9 + 1;
if ( *a1 )
{
v18 = a9 + 1;
v12 = 0;
v26 = 0;
v25 = 0;
v24 = 0;
while ( 1 )
{
v23 = 1156LL * v12;
v15 = &a1[v23];
if ( a1[v23 + 2] )
{
v13 = 0LL;
do
{
v33[0] = a9 + 1;
if ( (unsigned int)compareRGBPatchesIgnoreColor(
a2,
a5,
a6,
a3,
a4,
**(_QWORD **)&v15[2 * v13 + 6],
0LL,
0LL,
*(unsigned int *)(*(_QWORD *)&v15[2 * v13 + 6] + 8LL),
*(unsigned int *)(*(_QWORD *)&v15[2 * v13 + 6] + 12LL),
123LL,
123LL,
0LL,
a7,
a8,
v33,
10 * a9) )
{
v14 = (int)(float)((float)(v15[v13 + 774] / v15[v13 + 518]) * (float)(int)v33[0]);
v33[0] = v14;
if ( v14 < v18 )
{
v24 = v15[3];
v26 = v13;
v25 = v12;
v18 = v14;
}
}
++v13;
}
while ( v15[2] > (unsigned int)v13 );
}
if ( v15[5] > v18 )
break;
if ( *a1 <= ++v12 )
goto LABEL_14;
}
fprintf(stderr, "INSTA-Selected %s with a score of %u \n", (const char *)&a1[v23 + 1030], v18);
*a10 = v24;
*a11 = v25;
*a12 = v26;
result = 1LL;
}
else
{
v26 = 0;
v25 = 0;
v24 = 0;
v18 = a9 + 1;
LABEL_14:
fprintf(stderr, "Thinking about best score\n");
result = 0LL;
if ( a9 > v18 )
{
*(_QWORD *)v27 = 0LL;
v28 = 0LL;
memset(v29, 0, sizeof(v29));
*(_QWORD *)s = 0LL;
v31 = 0LL;
memset(v32, 0, sizeof(v32));
snprintf(s, 0x200uLL, "Dump/tile%u_%u_like_%u_%u_score_%u", 0LL, 0LL, v25, v26, v18);
snprintf(v27, 0x200uLL, "Most like %u with score %u", v24, v18);
bitBltRGBToFile(s, v27, a2, a5, a6, a3, a4, a7, a8);
snprintf(s, 0x200uLL, "Dump/tile%u_%u_like_%u_%u_score_%uB", 0LL, 0LL, v25, v26, v18);
v17 = *(_QWORD *)&a1[1156 * v25 + 6 + 2 * v26];
bitBltRGBToFile(
s,
v27,
*(_QWORD *)v17,
0LL,
0LL,
*(unsigned int *)(v17 + 8),
*(unsigned int *)(v17 + 12),
*(unsigned int *)(v17 + 8),
*(_DWORD *)(v17 + 12));
fprintf(stderr, "Not so sure , but selected %u with a score of %u \n", v24, v18);
*a10 = v24;
*a11 = v25;
*a12 = v26;
result = 1LL;
}
}
return result;
}

original_code:
int compareToPatternSet(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 maximumAcceptedScore,
                        unsigned int * pick ,
                        unsigned int * resultPatternNum ,
                        unsigned int * resultTileNum
                        )
{
  unsigned int currentScore=maximumAcceptedScore+1;
  unsigned int bestScore=maximumAcceptedScore+1;
  unsigned int bestPick=0;
  unsigned int bestPattern=0;
  unsigned int bestTile=0;
  unsigned int bestCandidates=0;
  unsigned int tileNum=0;
  unsigned int patternNum=0;
  for ( patternNum=0; patternNum < pattSet->totalPatterns; patternNum++ )
  {
   if (pattSet->pattern[patternNum].totalTiles>0)
   {
    for ( tileNum=0; tileNum < pattSet->pattern[patternNum].totalTiles; tileNum++ )
    {
       currentScore=maximumAcceptedScore+1;
       if (
            compareRGBPatchesIgnoreColor(
                                         screen , sX , sY , screenWidth, screenHeight ,
                                         pattSet->pattern[patternNum].tile[tileNum]->pixels ,
                                         0, 0 ,
                                         pattSet->pattern[patternNum].tile[tileNum]->width ,
                                         pattSet->pattern[patternNum].tile[tileNum]->height,
                                         123,123,0,
                                         width, height ,
                                         &currentScore ,
                                         10*maximumAcceptedScore
                                        )
           )
      {
          float differentTransCompensationFactor = pattSet->pattern[patternNum].totalPixels[tileNum] / pattSet->pattern[patternNum].nonTransparentPixels[tileNum];
          currentScore = currentScore * differentTransCompensationFactor;
       if (currentScore<bestScore)
       {
         bestScore = currentScore;
         bestPick = pattSet->pattern[patternNum].value;
         bestPattern=patternNum;
         bestTile=tileNum;
         ++bestCandidates;
       }
      }
     }
    }
   if (bestScore < pattSet->pattern[patternNum].acceptScore )
    {
      fprintf(stderr,"INSTA-Selected %s with a score of %u \n",pattSet->pattern[patternNum].name,bestScore);
      *pick=bestPick;
      *resultPatternNum=bestPattern;
      *resultTileNum=bestTile;
      return 1;
    }
 }
  fprintf(stderr,"Thinking about best score\n",pattSet->totalPatterns);
   if (bestScore < maximumAcceptedScore )
    {
         unsigned int x=0,y=0;
         char comment[512]={0};
         char nameUsed[512]={0};
         snprintf(nameUsed,512,"Dump/tile%u_%u_like_%u_%u_score_%u",x,y,bestPattern,bestTile,bestScore);
         snprintf(comment,512,"Most like  %u   with score %u", bestPick,bestScore);
         bitBltRGBToFile( nameUsed ,
                           comment,
                           screen , sX , sY , screenWidth, screenHeight, width, height );
         snprintf(nameUsed,512,"Dump/tile%u_%u_like_%u_%u_score_%uB",x,y,bestPattern,bestTile,bestScore);
         bitBltRGBToFile( nameUsed , comment,
                           pattSet->pattern[bestPattern].tile[bestTile]->pixels ,
                           0 , 0
                           , pattSet->pattern[bestPattern].tile[bestTile]->width , pattSet->pattern[bestPattern].tile[bestTile]->height
                           , pattSet->pattern[bestPattern].tile[bestTile]->width , pattSet->pattern[bestPattern].tile[bestTile]->height );
      fprintf(stderr,"Not so sure , but selected %u with a score of %u \n",bestPick,bestScore);
      *pick=bestPick;
      *resultPatternNum=bestPattern;
      *resultTileNum=bestTile;
      return 1;
    }
 return 0;
}

canonical_original_code:
int compareToPatternSet(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 maximumAcceptedScore, unsigned int *pick, unsigned int *resultPatternNum, unsigned int *resultTileNum)
{
  unsigned int currentScore = maximumAcceptedScore+1;
  unsigned int bestScore = maximumAcceptedScore+1;
  unsigned int bestPick = 0;
  unsigned int bestPattern = 0;
  unsigned int bestTile = 0;
  unsigned int bestCandidates = 0;
  unsigned int tileNum = 0;
  unsigned int patternNum = 0;
  for ( patternNum=0; patternNum < pattSet->totalPatterns; patternNum++ )
  {
   if (pattSet->pattern[patternNum].totalTiles>0)
   {
    for ( tileNum=0; tileNum < pattSet->pattern[patternNum].totalTiles; tileNum++ )
    {
       currentScore=maximumAcceptedScore+1;
       if (
            compareRGBPatchesIgnoreColor(
                                         screen , sX , sY , screenWidth, screenHeight ,
                                         pattSet->pattern[patternNum].tile[tileNum]->pixels ,
                                         0, 0 ,
                                         pattSet->pattern[patternNum].tile[tileNum]->width ,
                                         pattSet->pattern[patternNum].tile[tileNum]->height,
                                         123,123,0,
                                         width, height ,
                                         &currentScore ,
                                         10*maximumAcceptedScore
                                        )
           )
      {
          float differentTransCompensationFactor = pattSet->pattern[patternNum].totalPixels[tileNum] / pattSet->pattern[patternNum].nonTransparentPixels[tileNum];
          currentScore = currentScore * differentTransCompensationFactor;
       if (currentScore<bestScore)
       {
         bestScore = currentScore;
         bestPick = pattSet->pattern[patternNum].value;
         bestPattern=patternNum;
         bestTile=tileNum;
         ++bestCandidates;
       }
      }
     }
    }
   if (bestScore < pattSet->pattern[patternNum].acceptScore )
    {
      fprintf(stderr,"INSTA-Selected %s with a score of %u \n",pattSet->pattern[patternNum].name,bestScore);
      *pick=bestPick;
      *resultPatternNum=bestPattern;
      *resultTileNum=bestTile;
      return 1;
    }
 }
  fprintf(stderr,"Thinking about best score\n",pattSet->totalPatterns);
   if (bestScore < maximumAcceptedScore )
    {
         unsigned int x = 0; unsigned int y = 0;
         char comment[512] = {0};
         char nameUsed[512] = {0};
         snprintf(nameUsed,512,"Dump/tile%u_%u_like_%u_%u_score_%u",x,y,bestPattern,bestTile,bestScore);
         snprintf(comment,512,"Most like  %u   with score %u", bestPick,bestScore);
         bitBltRGBToFile( nameUsed ,
                           comment,
                           screen , sX , sY , screenWidth, screenHeight, width, height );
         snprintf(nameUsed,512,"Dump/tile%u_%u_like_%u_%u_score_%uB",x,y,bestPattern,bestTile,bestScore);
         bitBltRGBToFile( nameUsed , comment,
                           pattSet->pattern[bestPattern].tile[bestTile]->pixels ,
                           0 , 0
                           , pattSet->pattern[bestPattern].tile[bestTile]->width , pattSet->pattern[bestPattern].tile[bestTile]->height
                           , pattSet->pattern[bestPattern].tile[bestTile]->width , pattSet->pattern[bestPattern].tile[bestTile]->height );
      fprintf(stderr,"Not so sure , but selected %u with a score of %u \n",bestPick,bestScore);
      *pick=bestPick;
      *resultPatternNum=bestPattern;
      *resultTileNum=bestTile;
      return 1;
    }
 return 0;
}

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:
maximumAcceptedScore
unsigned int

variable_types:
pick
unsigned int *

variable_types:
resultPatternNum
unsigned int *

variable_types:
resultTileNum
unsigned int *

variable_types:
currentScore
unsigned int

variable_types:
bestScore
unsigned int

variable_types:
bestPick
unsigned int

variable_types:
bestPattern
unsigned int

variable_types:
bestTile
unsigned int

variable_types:
bestCandidates
unsigned int

variable_types: differentTransCompensationFactor float

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
comment
char [512]

variable_types:
nameUsed
char [512]


original_code:
char *Get_Display_Name(
    int *pargc,
    char **argv)
{
    int argc = *pargc;
    char **pargv = argv+1;
    char *displayname = ((void *)0);
    int i;
    for (i = 1; i < argc; i++) {
 char *arg = argv[i];
 if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
     if (++i >= argc) usage ();
     displayname = argv[i];
     *pargc -= 2;
     continue;
 }
 if (!strcmp(arg,"-")) {
  while (i<argc)
   *pargv++ = argv[i++];
  break;
 }
 *pargv++ = arg;
    }
    *pargv = ((void *)0);
    return (displayname);
}

canonical_original_code:
char *Get_Display_Name(int *pargc, char **argv)
{
    int argc = *pargc;
    char **pargv = argv+1;
    char *displayname = ((void *)0);
    int i;
    for (i = 1; i < argc; i++) {
 char *arg = argv[i];
 if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
     if (++i >= argc) usage ();
     displayname = argv[i];
     *pargc -= 2;
     continue;
 }
 if (!strcmp(arg,"-")) {
  while (i<argc)
   *pargv++ = argv[i++];
  break;
 }
 *pargv++ = arg;
    }
    *pargv = ((void *)0);
    return (displayname);
}

variable_types:
pargc
int *

variable_types:
argv
char **

variable_types: argc int

variable_types:
pargv
char **

variable_types:
displayname
char *

variable_types: i int

variable_types:
arg
char *

return_type: char *


decompiled_code:
int __fastcall Setup_Display_And_Screen(int *a1, __int64 a2)
{
char *v2; // rax
int result; // eax

v2 = (char *)Get_Display_Name(a1, a2);
dpy = Open_Display(v2);
result = XDefaultScreen(dpy);
screen = result;
return result;
}

canonical_decompiled_code:
int __fastcall func1(int *a1, __int64 a2)
{
char *v2; // rax
int result; // eax

v2 = (char *)func0(a1, a2);
dpy = Open_Display(v2);
result = XDefaultScreen(dpy);
screen = result;
return result;
}

original_code:
void Setup_Display_And_Screen(
    int *argc,
    char **argv)
{
        char *displayname = ((void *)0);
        displayname = Get_Display_Name(argc, argv);
 dpy = Open_Display (displayname);
 screen = XDefaultScreen(dpy);
}

canonical_original_code:
void Setup_Display_And_Screen(int *argc, char **argv)
{
        char *displayname = ((void *)0);
        displayname = Get_Display_Name(argc, argv);
 dpy = Open_Display (displayname);
 screen = XDefaultScreen(dpy);
}

variable_types:
argc
int *

return_type: void


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

dpy = Open_Display(0LL);
result = XDefaultScreen(dpy);
screen = result;
return result;
}

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

dpy = Open_Display(0LL);
result = XDefaultScreen(dpy);
screen = result;
return result;
}

original_code:
void Setup_Null_Display_And_Screen( )
{
    char *displayname = ((void *)0);
 dpy = Open_Display (displayname);
 screen = XDefaultScreen(dpy);
}

canonical_original_code:
void Setup_Null_Display_And_Screen()
{
    char *displayname = ((void *)0);
 dpy = Open_Display (displayname);
 screen = XDefaultScreen(dpy);
}


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

if ( dpy )
{
result = XCloseDisplay(dpy);
dpy = 0LL;
}
return result;
}

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

if ( dpy )
{
result = XCloseDisplay(dpy);
dpy = 0LL;
}
return result;
}

original_code:
void Close_Display(void)
{
    if (dpy == ((void *)0)) return;
    XCloseDisplay(dpy);
    dpy = ((void *)0);
}

canonical_original_code:
void Close_Display()
{
    if (dpy == ((void *)0)) return;
    XCloseDisplay(dpy);
    dpy = ((void *)0);
}


getRootWindow

decompiled_code:
Window getRootWindow()
{
return dpy->screens[(__int64)screen].root;
}

canonical_decompiled_code:
Window func4()
{
return dpy->screens[(__int64)screen].root;
}

original_code:
Window getRootWindow()
{
  Window w=0;
  w=((&((_XPrivDisplay)(dpy))->screens[screen])->root);
  return (w);
}

canonical_original_code:
unsigned long getRootWindow()
{
  unsigned long w = 0;
  w=((&((_XPrivDisplay)(dpy))->screens[screen])->root);
  return (w);
}

variable_types:
w
unsigned long

return_type: unsigned long


outl

decompiled_code:
int outl(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fflush(stdout);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int func6(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fflush(stdout);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

original_code:
void
outl(char *msg, ...)
{
 va_list args;
 fflush(stdout);
 __builtin_va_start(args,msg);
 vfprintf(stderr, msg, args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
 fflush(stderr);
}

canonical_original_code:
void outl(char *msg, ...)
{
 __builtin_va_list args;
 fflush(stdout);
 __builtin_va_start(args,msg);
 vfprintf(stderr, msg, args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
 fflush(stderr);
}

variable_types:
msg
char *


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

va_start(arg, a1);
fflush(stdout);
fflush(stderr);
fprintf(stderr, "%s: error: ", program_name);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
Close_Display();
exit(1);
}

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

va_start(arg, a1);
fflush(stdout);
fflush(stderr);
fprintf(stderr, "%s: error: ", program_name);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
func3();
exit(1);
}

original_code:
void Fatal_Error(char *msg, ...)
{
 va_list args;
 fflush(stdout);
 fflush(stderr);
 fprintf(stderr, "%s: error: ", program_name);
 __builtin_va_start(args,msg);
 vfprintf(stderr, msg, args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
        Close_Display();
 exit(1);
}

canonical_original_code:
void Fatal_Error(char *msg, ...)
{
 __builtin_va_list args;
 fflush(stdout);
 fflush(stderr);
 fprintf(stderr, "%s: error: ", program_name);
 __builtin_va_start(args,msg);
 vfprintf(stderr, msg, args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
        Close_Display();
 exit(1);
}


original_code:
Window Select_Window_Args(
    int *rargc,
    char **argv)
{
 int nargc=1;
 int argc;
 char **nargv;
 Window w=0;
 nargv = argv+1; argc = (*rargc);
 while (++argv, --argc>0) {
  if (!strcmp(argv[0], "-")) {
   nargv++[0]=argv[0], nargc++;
   while (++argv, --argc>0)
     nargv++[0]=argv[0], nargc++;
   break;
  }
  if (!strcmp(argv[0], "-root")) {
   w=((&((_XPrivDisplay)(dpy))->screens[screen])->root);
   continue;
  }
  if (!strcmp(argv[0], "-name")) {
   if (++argv, --argc==0) usage();
   w = Window_With_Name(dpy, ((&((_XPrivDisplay)(dpy))->screens[screen])->root),
          argv[0]);
   if (!w)
     Fatal_Error("No window with name %s exists!",argv[0]);
   continue;
  }
  if (!strcmp(argv[0], "-id")) {
   if (++argv, --argc==0) usage();
   w=0;
   sscanf(argv[0], "0x%lx", &w);
   if (!w)
     sscanf(argv[0], "%lu", &w);
   if (!w)
     Fatal_Error("Invalid window id format: %s.", argv[0]);
   continue;
  }
  nargv++[0]=argv[0], nargc++;
 }
 (*rargc) = nargc;
 return(w);
}

canonical_original_code:
unsigned long Select_Window_Args(int *rargc, char **argv)
{
 int nargc = 1;
 int argc;
 char **nargv;
 unsigned long w = 0;
 nargv = argv+1; argc = (*rargc);
 while (++argv, --argc>0) {
  if (!strcmp(argv[0], "-")) {
   nargv++[0]=argv[0], nargc++;
   while (++argv, --argc>0)
     nargv++[0]=argv[0], nargc++;
   break;
  }
  if (!strcmp(argv[0], "-root")) {
   w=((&((_XPrivDisplay)(dpy))->screens[screen])->root);
   continue;
  }
  if (!strcmp(argv[0], "-name")) {
   if (++argv, --argc==0) usage();
   w = Window_With_Name(dpy, ((&((_XPrivDisplay)(dpy))->screens[screen])->root),
          argv[0]);
   if (!w)
     Fatal_Error("No window with name %s exists!",argv[0]);
   continue;
  }
  if (!strcmp(argv[0], "-id")) {
   if (++argv, --argc==0) usage();
   w=0;
   sscanf(argv[0], "0x%lx", &w);
   if (!w)
     sscanf(argv[0], "%lu", &w);
   if (!w)
     Fatal_Error("Invalid window id format: %s.", argv[0]);
   continue;
  }
  nargv++[0]=argv[0], nargc++;
 }
 (*rargc) = nargc;
 return(w);
}

variable_types:
rargc
int *

variable_types: nargc int

variable_types:
nargv
char **


decompiled_code:
__int64 read_2_bytes()
{
int v0; // ebx
__int64 result; // rax
int v2; // eax
unsigned int v3; // ebx
bool v4; // zf

v0 = getc(myfile);
result = 0LL;
if ( v0 != -1 )
{
v2 = getc(myfile);
v3 = v2 + (v0 << 8);
v4 = v2 == -1;
result = 0LL;
if ( !v4 )
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
__int64 result; // rax
int v2; // eax
unsigned int v3; // ebx
bool v4; // zf

v0 = getc(myfile);
result = 0LL;
if ( v0 != -1 )
{
v2 = getc(myfile);
v3 = v2 + (v0 << 8);
v4 = v2 == -1;
result = 0LL;
if ( !v4 )
result = v3;
}
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
char *v2; // rbx
int v3; // ebx
unsigned int v5; // er12
char *v6; // rbx
unsigned int v7; // eax
int v8; // esi
unsigned int v9; // eax
unsigned int v10; // er12
int v11; // edi
int v12; // edx

myfile = 0LL;
myfile = fopen(a1, "rb");
v1 = exif_data;
v2 = exif_data;
if ( !myfile )
{
fprintf(stderr, " Can't open %s\n", a1);
return 0;
}
do
*v2++ = read_1_byte();
while ( v2 != &exif_data[4] );
if ( byte_501[0] == -40 && ((unsigned __int8)byte_502 & exif_data[0]) == 0xFF && byte_503 == -31 )
{
v5 = read_2_bytes();
v6 = exif_data;
if ( v5 > 7 )
{
do
*v6++ = read_1_byte();
while ( v6 != &byte_506 );
if ( exif_data[0] == 69 && byte_501[0] == 120 && byte_502 == 105 && byte_503 == 102 && !word_504 && v5 != 8 )
{
do
*v1++ = read_1_byte();
while ( v1 != &byte_501[v5 - 9] );
if ( v5 - 8 > 0xB )
{
if ( exif_data[0] == 73 )
{
if ( byte_501[0] == 73 && !byte_503 && byte_502 == 42 && !byte_507 && !byte_506 )
{
v7 = (unsigned __int8)word_504 + (HIBYTE(word_504) << 8);
if ( v5 - 10 >= v7 )
{
v3 = ((unsigned __int8)exif_data[v7 + 1] << 8) + (unsigned __int8)exif_data[v7];
v8 = 0;
LABEL_38:
v9 = v7 + 2;
v10 = v5 - 20;
if ( !v3 )
{
LABEL_39:
fclose(myfile);
return (unsigned int)v3;
}
while ( v10 >= v9 )
{
if ( v8 )
{
v11 = (unsigned __int8)exif_data[v9] << 8;
v12 = (unsigned __int8)exif_data[v9 + 1];
}
else
{
v11 = (unsigned __int8)exif_data[v9 + 1] << 8;
v12 = (unsigned __int8)exif_data[v9];
}
if ( v11 + v12 == 274 )
{
if ( v8 )
{
if ( exif_data[v9 + 8] )
goto LABEL_6;
v3 = (unsigned __int8)exif_data[v9 + 9];
}
else
{
if ( exif_data[v9 + 9] )
goto LABEL_6;
v3 = (unsigned __int8)exif_data[v9 + 8];
}
fclose(myfile);
if ( v3 > 8 )
v3 = 0;
return (unsigned int)v3;
}
if ( !--v3 )
goto LABEL_39;
v9 += 12;
}
goto LABEL_6;
}
}
}
else if ( exif_data[0] == 77 && byte_501[0] == 77 && !byte_502 && byte_503 == 42 && !word_504 )
{
v7 = (unsigned __int8)byte_507 + ((unsigned __int8)byte_506 << 8);
if ( v5 - 10 >= v7 )
{
v3 = ((unsigned __int8)exif_data[v7] << 8) + (unsigned __int8)exif_data[v7 + 1];
v8 = 1;
goto LABEL_38;
}
}
}
}
}
}
LABEL_6:
fclose(myfile);
return 0;
}

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

myfile = 0LL;
myfile = fopen(a1, "rb");
v1 = exif_data;
v2 = exif_data;
if ( !myfile )
{
fprintf(stderr, " Can't open %s\n", a1);
return 0;
}
do
*v2++ = func1();
while ( v2 != &exif_data[4] );
if ( byte_501[0] == -40 && ((unsigned __int8)byte_502 & exif_data[0]) == 0xFF && byte_503 == -31 )
{
v5 = func0();
v6 = exif_data;
if ( v5 > 7 )
{
do
*v6++ = func1();
while ( v6 != &byte_506 );
if ( exif_data[0] == 69 && byte_501[0] == 120 && byte_502 == 105 && byte_503 == 102 && !word_504 && v5 != 8 )
{
do
*v1++ = func1();
while ( v1 != &byte_501[v5 - 9] );
if ( v5 - 8 > 0xB )
{
if ( exif_data[0] == 73 )
{
if ( byte_501[0] == 73 && !byte_503 && byte_502 == 42 && !byte_507 && !byte_506 )
{
v7 = (unsigned __int8)word_504 + (HIBYTE(word_504) << 8);
if ( v5 - 10 >= v7 )
{
v3 = ((unsigned __int8)exif_data[v7 + 1] << 8) + (unsigned __int8)exif_data[v7];
v8 = 0;
LABEL_38:
v9 = v7 + 2;
v10 = v5 - 20;
if ( !v3 )
{
LABEL_39:
fclose(myfile);
return (unsigned int)v3;
}
while ( v10 >= v9 )
{
if ( v8 )
{
v11 = (unsigned __int8)exif_data[v9] << 8;
v12 = (unsigned __int8)exif_data[v9 + 1];
}
else
{
v11 = (unsigned __int8)exif_data[v9 + 1] << 8;
v12 = (unsigned __int8)exif_data[v9];
}
if ( v11 + v12 == 274 )
{
if ( v8 )
{
if ( exif_data[v9 + 8] )
goto LABEL_6;
v3 = (unsigned __int8)exif_data[v9 + 9];
}
else
{
if ( exif_data[v9 + 9] )
goto LABEL_6;
v3 = (unsigned __int8)exif_data[v9 + 8];
}
fclose(myfile);
if ( v3 > 8 )
v3 = 0;
return (unsigned int)v3;
}
if ( !--v3 )
goto LABEL_39;
v9 += 12;
}
goto LABEL_6;
}
}
}
else if ( exif_data[0] == 77 && byte_501[0] == 77 && !byte_502 && byte_503 == 42 && !word_504 )
{
v7 = (unsigned __int8)byte_507 + ((unsigned __int8)byte_506 << 8);
if ( v5 - 10 >= v7 )
{
v3 = ((unsigned __int8)exif_data[v7] << 8) + (unsigned __int8)exif_data[v7 + 1];
v8 = 1;
goto LABEL_38;
}
}
}
}
}
}
LABEL_6:
fclose(myfile);
return 0;
}

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;
  i = 1;
  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;
  i = 1;
  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:
filename
char *

variable_types:
length
unsigned int

variable_types:
i
unsigned int

variable_types:
offset
unsigned int

variable_types:
tagnum
unsigned int


RGBfindImageInImage

decompiled_code:
__int64 __fastcall RGBfindImageInImage(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5, unsigned int a6, unsigned int *a7, unsigned int *a8, unsigned int a9, unsigned int a10)
{
__int64 v10; // r12
__int64 v11; // rbp
unsigned int v12; // er13
__int64 result; // rax
unsigned int v14; // ebx
unsigned int v15; // [rsp+4h] [rbp-74h]
unsigned int v18; // [rsp+20h] [rbp-58h]
unsigned int v19; // [rsp+24h] [rbp-54h]
unsigned int v20; // [rsp+28h] [rbp-50h]
unsigned int v21; // [rsp+2Ch] [rbp-4Ch]
unsigned int v22[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v22[0] = 10000000;
v21 = a3 - a6 - 1;
if ( v21 <= 1 )
{
v20 = 0;
v19 = 0;
v18 = 10000000;
LABEL_4:
if ( a9 >= v18 )
{
fwrite("RGBfindImageInImage found an acceptable needle in the haystack\n", 1uLL, 0x3FuLL, stderr);
*a7 = v19;
*a8 = v20;
result = v18 + 1;
}
else
{
fwrite("RGBfindImageInImage unable to find needle in haystack", 1uLL, 0x35uLL, stderr);
result = 0LL;
}
}
else
{
v10 = a5;
v11 = a6;
v12 = 1;
v20 = 0;
v19 = 0;
v18 = 10000000;
v15 = a2 - a5 - 1;
while ( 1 )
{
v14 = 1;
if ( v15 > 1 )
break;
LABEL_12:
if ( ++v12 == v21 )
goto LABEL_4;
}
while ( 1 )
{
if ( (unsigned int)compareRGBPatches(a1, v14, v12, a2, a3, a4, 0LL, 0LL, v10, v11, v10, v11, v22, a10) )
{
if ( v22[0] < v18 )
{
v20 = v12;
v19 = v14;
v18 = v22[0];
}
if ( v22[0] <= a9 )
break;
}
if ( ++v14 == v15 )
goto LABEL_12;
}
result = v18 + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5, unsigned int a6, unsigned int *a7, unsigned int *a8, unsigned int a9, unsigned int a10)
{
__int64 v10; // r12
__int64 v11; // rbp
unsigned int v12; // er13
__int64 result; // rax
unsigned int v14; // ebx
unsigned int v15; // [rsp+4h] [rbp-74h]
unsigned int v18; // [rsp+20h] [rbp-58h]
unsigned int v19; // [rsp+24h] [rbp-54h]
unsigned int v20; // [rsp+28h] [rbp-50h]
unsigned int v21; // [rsp+2Ch] [rbp-4Ch]
unsigned int v22[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v22[0] = 10000000;
v21 = a3 - a6 - 1;
if ( v21 <= 1 )
{
v20 = 0;
v19 = 0;
v18 = 10000000;
LABEL_4:
if ( a9 >= v18 )
{
fwrite("RGBfindImageInImage found an acceptable needle in the haystack\n", 1uLL, 0x3FuLL, stderr);
*a7 = v19;
*a8 = v20;
result = v18 + 1;
}
else
{
fwrite("RGBfindImageInImage unable to find needle in haystack", 1uLL, 0x35uLL, stderr);
result = 0LL;
}
}
else
{
v10 = a5;
v11 = a6;
v12 = 1;
v20 = 0;
v19 = 0;
v18 = 10000000;
v15 = a2 - a5 - 1;
while ( 1 )
{
v14 = 1;
if ( v15 > 1 )
break;
LABEL_12:
if ( ++v12 == v21 )
goto LABEL_4;
}
while ( 1 )
{
if ( (unsigned int)compareRGBPatches(a1, v14, v12, a2, a3, a4, 0LL, 0LL, v10, v11, v10, v11, v22, a10) )
{
if ( v22[0] < v18 )
{
v20 = v12;
v19 = v14;
v18 = v22[0];
}
if ( v22[0] <= a9 )
break;
}
if ( ++v14 == v15 )
goto LABEL_12;
}
result = v18 + 1;
}
return result;
}

original_code:
int RGBfindImageInImage(
                        unsigned char * haystack , unsigned int haystackWidth , unsigned int haystackHeight ,
                        unsigned char * needle , unsigned int needleWidth , unsigned int needleHeight ,
                        unsigned int * resX ,
                        unsigned int * resY ,
                        unsigned int acceptableScore,
                        unsigned int maxScore
                       )
{
  unsigned int bestScore=10000000 , bestX=0 , bestY=0;
  unsigned int score=bestScore , x , y;
  for (y=1; y<haystackHeight-needleHeight-1; y++)
  {
    for (x=1; x<haystackWidth-needleWidth-1; x++)
    {
       if (
             compareRGBPatches( haystack , x , y , haystackWidth , haystackHeight,
                                needle , 0 , 0 , needleWidth , needleHeight ,
                                needleWidth , needleHeight
                                , &score , maxScore )
           )
           {
              if ( score < bestScore) { bestScore = score; bestX=x; bestY = y; }
              if (score <= acceptableScore ) { return bestScore+1; }
           }
    }
  }
  if (bestScore<=acceptableScore)
   {
    fprintf(stderr,"RGBfindImageInImage found an acceptable needle in the haystack\n");
    *resX = bestX;
    *resY = bestY;
    return bestScore+1;
   } else
   {
     fprintf(stderr,"RGBfindImageInImage unable to find needle in haystack");
   }
  return 0;
}

canonical_original_code:
int RGBfindImageInImage(unsigned char *haystack, unsigned int haystackWidth, unsigned int haystackHeight, unsigned char *needle, unsigned int needleWidth, unsigned int needleHeight, unsigned int *resX, unsigned int *resY, unsigned int acceptableScore, unsigned int maxScore)
{
  unsigned int bestScore = 10000000; unsigned int bestX = 0; unsigned int bestY = 0;
  unsigned int score = bestScore; unsigned int x; unsigned int y;
  for (y=1; y<haystackHeight-needleHeight-1; y++)
  {
    for (x=1; x<haystackWidth-needleWidth-1; x++)
    {
       if (
             compareRGBPatches( haystack , x , y , haystackWidth , haystackHeight,
                                needle , 0 , 0 , needleWidth , needleHeight ,
                                needleWidth , needleHeight
                                , &score , maxScore )
           )
           {
              if ( score < bestScore) { bestScore = score; bestX=x; bestY = y; }
              if (score <= acceptableScore ) { return bestScore+1; }
           }
    }
  }
  if (bestScore<=acceptableScore)
   {
    fprintf(stderr,"RGBfindImageInImage found an acceptable needle in the haystack\n");
    *resX = bestX;
    *resY = bestY;
    return bestScore+1;
   } else
   {
     fprintf(stderr,"RGBfindImageInImage unable to find needle in haystack");
   }
  return 0;
}

variable_types:
haystack
unsigned char *

variable_types:
haystackWidth
unsigned int

variable_types:
haystackHeight
unsigned int

variable_types:
needle
unsigned char *

variable_types:
needleWidth
unsigned int

variable_types:
needleHeight
unsigned int

variable_types:
resX
unsigned int *

variable_types:
resY
unsigned int *

variable_types:
acceptableScore
unsigned int

variable_types:
maxScore
unsigned int

variable_types:
bestScore
unsigned int

variable_types:
bestX
unsigned int

variable_types:
bestY
unsigned int

variable_types:
score
unsigned int

variable_types:
x
unsigned int

variable_types:
y
unsigned int


ReadPPM

decompiled_code:
_BOOL8 __fastcall ReadPPM(char *filename, __int64 a2)
{
void *v2; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v2 = ReadPNM(*(void **)a2, filename, (unsigned int *)(a2 + 8), (unsigned int *)(a2 + 12), &v4);
*(_QWORD *)a2 = v2;
return v2 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *filename, __int64 a2)
{
void *v2; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v2 = func0(*(void **)a2, filename, (unsigned int *)(a2 + 8), (unsigned int *)(a2 + 12), &v4);
*(_QWORD *)a2 = v2;
return v2 != 0LL;
}

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

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

variable_types:
filename
char *

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:
timestamp
unsigned long


getPieceName

decompiled_code:
const char *__fastcall getPieceName(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "GREEN_PIECE";
break;
case 2:
result = "WHITE_PIECE";
break;
case 3:
result = "ORANGE_PIECE";
break;
case 4:
result = "YELLOW_PIECE";
break;
case 5:
result = "BLUE_PIECE";
break;
case 6:
result = "RED_PIECE";
break;
case 7:
result = "PINK_PIECE";
break;
case 8:
result = "HYPERCUBE_PIECE";
break;
default:
result = "UNKNOWN";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "GREEN_PIECE";
break;
case 2:
result = "WHITE_PIECE";
break;
case 3:
result = "ORANGE_PIECE";
break;
case 4:
result = "YELLOW_PIECE";
break;
case 5:
result = "BLUE_PIECE";
break;
case 6:
result = "RED_PIECE";
break;
case 7:
result = "PINK_PIECE";
break;
case 8:
result = "HYPERCUBE_PIECE";
break;
default:
result = "UNKNOWN";
break;
}
return result;
}

original_code:
char * getPieceName(int pieceVal)
{
  switch (pieceVal)
  {
    case GREEN_PIECE : return "GREEN_PIECE"; break;
    case WHITE_PIECE : return "WHITE_PIECE"; break;
    case ORANGE_PIECE : return "ORANGE_PIECE"; break;
    case YELLOW_PIECE : return "YELLOW_PIECE"; break;
    case BLUE_PIECE : return "BLUE_PIECE"; break;
    case RED_PIECE : return "RED_PIECE"; break;
    case PINK_PIECE : return "PINK_PIECE"; break;
    case HYPERCUBE_PIECE : return "HYPERCUBE_PIECE"; break;
    default :
     return "UNKNOWN";
    break;
  }
  return "Nothing ";
}

canonical_original_code:
char *getPieceName(int pieceVal)
{
  switch (pieceVal)
  {
    case GREEN_PIECE : return "GREEN_PIECE"; break;
    case WHITE_PIECE : return "WHITE_PIECE"; break;
    case ORANGE_PIECE : return "ORANGE_PIECE"; break;
    case YELLOW_PIECE : return "YELLOW_PIECE"; break;
    case BLUE_PIECE : return "BLUE_PIECE"; break;
    case RED_PIECE : return "RED_PIECE"; break;
    case PINK_PIECE : return "PINK_PIECE"; break;
    case HYPERCUBE_PIECE : return "HYPERCUBE_PIECE"; break;
    default :
     return "UNKNOWN";
    break;
  }
  return "Nothing ";
}

variable_types: pieceVal int


writePieceChar

decompiled_code:
__int64 __fastcall writePieceChar(int a1)
{
switch ( a1 )
{
case 1:
printf("\x1B[32m G\x1B[0m");
break;
case 2:
printf("\x1B[37m W\x1B[0m");
break;
case 3:
printf("\x1B[33m O\x1B[0m");
break;
case 4:
printf("\x1B[33m Y\x1B[0m");
break;
case 5:
printf("\x1B[36m B\x1B[0m");
break;
case 6:
printf("\x1B[31m R\x1B[0m");
break;
case 7:
printf("\x1B[35m P\x1B[0m");
break;
case 8:
printf("\x1B[35m #\x1B[0m");
break;
default:
printf(" ?");
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
switch ( a1 )
{
case 1:
printf("\x1B[32m G\x1B[0m");
break;
case 2:
printf("\x1B[37m W\x1B[0m");
break;
case 3:
printf("\x1B[33m O\x1B[0m");
break;
case 4:
printf("\x1B[33m Y\x1B[0m");
break;
case 5:
printf("\x1B[36m B\x1B[0m");
break;
case 6:
printf("\x1B[31m R\x1B[0m");
break;
case 7:
printf("\x1B[35m P\x1B[0m");
break;
case 8:
printf("\x1B[35m #\x1B[0m");
break;
default:
printf(" ?");
break;
}
return 0LL;
}

original_code:
int writePieceChar(int pieceVal)
{
  switch (pieceVal)
  {
    case GREEN_PIECE : printf("\033[32m" " G" "\033[0m"); break;
    case WHITE_PIECE : printf("\033[37m" " W" "\033[0m"); break;
    case ORANGE_PIECE : printf("\033[33m" " O" "\033[0m"); break;
    case YELLOW_PIECE : printf("\033[33m" " Y" "\033[0m"); break;
    case BLUE_PIECE : printf("\033[36m" " B" "\033[0m"); break;
    case RED_PIECE : printf("\033[31m" " R" "\033[0m"); break;
    case PINK_PIECE : printf("\033[35m" " P" "\033[0m"); break;
    case HYPERCUBE_PIECE : printf("\033[35m" " #" "\033[0m"); break;
    default :
     printf(" ?" );
    break;
  }
  return 0;
}


printTable

variable_types:
table
unsigned int [8][8]


formulatePlan

decompiled_code:
__int64 __fastcall formulatePlan(__int64 a1, unsigned int *a2, _DWORD *a3)
{
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // edx
__int64 result; // rax
unsigned int *v8; // r12
unsigned int *v9; // rbx
unsigned int v10; // ebp
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // r8
unsigned int v15; // er10
_DWORD *v16; // rsi
unsigned int v17; // er8
int v18; // [rsp+4h] [rbp-44h]
unsigned int v19; // [rsp+8h] [rbp-40h]
unsigned int v20; // [rsp+Ch] [rbp-3Ch]

v4 = settings[2];
v5 = settings[3];
*a3 = 0;
v6 = a2[1285];
result = 0LL;
if ( v6 )
{
v8 = a2;
if ( v6 > 3 )
a2[1285] = 3;
fprintf(stderr, "Old LastMove was %u,%u / ", lastMoveX, lastMoveY);
if ( a2[1285] )
{
v19 = v4 >> 1;
v20 = v5 >> 1;
v9 = a2;
v18 = 0;
v10 = 0;
do
{
v11 = *v9;
if ( (unsigned int)v11 > 7
|| (v12 = v9[1], (unsigned int)v12 > 7)
|| (v13 = v9[2], (unsigned int)v13 > 7)
|| (v14 = v9[3], (unsigned int)v14 > 7) )
{
fwrite("Incorrect solution item\n", 1uLL, 0x18uLL, stderr);
}
else
{
printf("Move %u,%u to %u,%u\n", v11, v12, v13, v14);
v15 = settings[0] + v19;
v16 = &a3[5 * v18];
v16[1] = settings[0] + v19 + settings[2] * *v9;
v17 = settings[1] + v20;
v16[2] = v17 + settings[3] * v9[1];
v16[3] = v15 + settings[3] * v9[2];
v16[4] = v17 + settings[3] * v9[3];
*((_BYTE *)v16 + 20) = 2;
lastMoveX = v9[2];
lastMoveY = v9[3];
++v18;
++*a3;
}
++v10;
v9 += 5;
}
while ( v8[1285] > v10 );
}
fprintf(stderr, "New LastMove is %u,%u \n", lastMoveX, lastMoveY);
result = (unsigned int)*a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2, _DWORD *a3)
{
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // edx
__int64 result; // rax
unsigned int *v8; // r12
unsigned int *v9; // rbx
unsigned int v10; // ebp
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // r8
unsigned int v15; // er10
_DWORD *v16; // rsi
unsigned int v17; // er8
int v18; // [rsp+4h] [rbp-44h]
unsigned int v19; // [rsp+8h] [rbp-40h]
unsigned int v20; // [rsp+Ch] [rbp-3Ch]

v4 = settings[2];
v5 = settings[3];
*a3 = 0;
v6 = a2[1285];
result = 0LL;
if ( v6 )
{
v8 = a2;
if ( v6 > 3 )
a2[1285] = 3;
fprintf(stderr, "Old LastMove was %u,%u / ", lastMoveX, lastMoveY);
if ( a2[1285] )
{
v19 = v4 >> 1;
v20 = v5 >> 1;
v9 = a2;
v18 = 0;
v10 = 0;
do
{
v11 = *v9;
if ( (unsigned int)v11 > 7
|| (v12 = v9[1], (unsigned int)v12 > 7)
|| (v13 = v9[2], (unsigned int)v13 > 7)
|| (v14 = v9[3], (unsigned int)v14 > 7) )
{
fwrite("Incorrect solution item\n", 1uLL, 0x18uLL, stderr);
}
else
{
printf("Move %u,%u to %u,%u\n", v11, v12, v13, v14);
v15 = settings[0] + v19;
v16 = &a3[5 * v18];
v16[1] = settings[0] + v19 + settings[2] * *v9;
v17 = settings[1] + v20;
v16[2] = v17 + settings[3] * v9[1];
v16[3] = v15 + settings[3] * v9[2];
v16[4] = v17 + settings[3] * v9[3];
*((_BYTE *)v16 + 20) = 2;
lastMoveX = v9[2];
lastMoveY = v9[3];
++v18;
++*a3;
}
++v10;
v9 += 5;
}
while ( v8[1285] > v10 );
}
fprintf(stderr, "New LastMove is %u,%u \n", lastMoveX, lastMoveY);
result = (unsigned int)*a3;
}
return result;
}

original_code:
int formulatePlan(unsigned int table[8][8] , struct solutionList * list , struct mouseMovements * ourPlan)
{
  unsigned int halfBlockX = (unsigned int) settings.blockX/2;
  unsigned int halfBlockY = (unsigned int) settings.blockY/2;
  ourPlan->totalMovements=0;
  if (list->currentSolutions==0) { return 0; }
  if (list->currentSolutions>3) { list->currentSolutions=3; }
 fprintf(stderr,"Old LastMove was %u,%u  / ",lastMoveX,lastMoveY);
  unsigned int i=0;
  unsigned int mC = 0;
  for (i=0; i<list->currentSolutions; i++)
  {
        if (
            (list->solution[i].fromX<8) &&
            (list->solution[i].fromY<8) &&
            (list->solution[i].toX<8) &&
            (list->solution[i].toY<8)
            )
        {
           printf("Move %u,%u to %u,%u\n",list->solution[i].fromX,list->solution[i].fromY,list->solution[i].toX,list->solution[i].toY);
           ourPlan->movement[mC].fromX = settings.clientX + halfBlockX + ( list->solution[i].fromX * settings.blockX);
           ourPlan->movement[mC].fromY = settings.clientY + halfBlockY + ( list->solution[i].fromY * settings.blockY);
           ourPlan->movement[mC].toX = settings.clientX + halfBlockX + ( list->solution[i].toX * settings.blockY);
           ourPlan->movement[mC].toY = settings.clientY + halfBlockY + ( list->solution[i].toY * settings.blockY);
           ourPlan->movement[mC].mode = MOVE_CLICK_AND_MOVE_CLICK;
           lastMoveX=list->solution[i].toX;
           lastMoveY=list->solution[i].toY;
           ++mC;
           ++ourPlan->totalMovements;
        } else
        { fprintf(stderr,"Incorrect solution item\n"); }
  }
  fprintf(stderr,"New LastMove is %u,%u \n",lastMoveX,lastMoveY );
  return ourPlan->totalMovements;
}

canonical_original_code:
int formulatePlan(unsigned int table[8][8], struct solutionList *list, struct mouseMovements *ourPlan)
{
  unsigned int halfBlockX = (unsigned int) settings.blockX/2;
  unsigned int halfBlockY = (unsigned int) settings.blockY/2;
  ourPlan->totalMovements=0;
  if (list->currentSolutions==0) { return 0; }
  if (list->currentSolutions>3) { list->currentSolutions=3; }
 fprintf(stderr,"Old LastMove was %u,%u  / ",lastMoveX,lastMoveY);
  unsigned int i = 0;
  unsigned int mC = 0;
  for (i=0; i<list->currentSolutions; i++)
  {
        if (
            (list->solution[i].fromX<8) &&
            (list->solution[i].fromY<8) &&
            (list->solution[i].toX<8) &&
            (list->solution[i].toY<8)
            )
        {
           printf("Move %u,%u to %u,%u\n",list->solution[i].fromX,list->solution[i].fromY,list->solution[i].toX,list->solution[i].toY);
           ourPlan->movement[mC].fromX = settings.clientX + halfBlockX + ( list->solution[i].fromX * settings.blockX);
           ourPlan->movement[mC].fromY = settings.clientY + halfBlockY + ( list->solution[i].fromY * settings.blockY);
           ourPlan->movement[mC].toX = settings.clientX + halfBlockX + ( list->solution[i].toX * settings.blockY);
           ourPlan->movement[mC].toY = settings.clientY + halfBlockY + ( list->solution[i].toY * settings.blockY);
           ourPlan->movement[mC].mode = MOVE_CLICK_AND_MOVE_CLICK;
           lastMoveX=list->solution[i].toX;
           lastMoveY=list->solution[i].toY;
           ++mC;
           ++ourPlan->totalMovements;
        } else
        { fprintf(stderr,"Incorrect solution item\n"); }
  }
  fprintf(stderr,"New LastMove is %u,%u \n",lastMoveX,lastMoveY );
  return ourPlan->totalMovements;
}

variable_types: struct solutionList { struct solutionItem { unsigned int fromX; unsigned int fromY; unsigned int toX; unsigned int toY; unsigned int score; } solution[-1]; unsigned int currentSolutions; } *

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:
halfBlockX
unsigned int

variable_types:
halfBlockY
unsigned int

variable_types:
i
unsigned int

variable_types:
mC
unsigned int

user_defined_types: struct solutionList { struct solutionItem solution[-1]; unsigned int currentSolutions; }

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


thinkWhatToPlay

decompiled_code:
__int64 __fastcall thinkWhatToPlay(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int *a6)
{
__int64 result; // rax
int v9; // eax
unsigned int v10; // esi
__int64 v11; // r8
unsigned int *v12; // rcx
unsigned int v13; // edi
unsigned int v14; // [rsp+8h] [rbp-1550h] BYREF
unsigned int v15; // [rsp+Ch] [rbp-154Ch] BYREF
unsigned int v16[1288]; // [rsp+10h] [rbp-1548h] BYREF
char v17[296]; // [rsp+1430h] [rbp-128h] BYREF

settings[0] = a4;
settings[1] = a5;
memset(v17, 0, 0x100uLL);
seeTable(v17, a1, a2, a3, a4, a5);
printTable((__int64)v17);
if ( (unsigned int)isSceneTooAmbiguous(v17) )
{
*a6 = 0;
printf("Scene is too ambiguous :( ( %u / %u ) \n", ++continuousUncertainty, 40LL);
result = 0LL;
if ( continuousUncertainty > 0x28 )
{
v9 = *a6;
LOBYTE(a6[5 * *a6 + 5]) = 0;
*a6 = v9 + 1;
v14 = 0;
v15 = 0;
result = seeButtons(a1, a2, a3, &v14, &v15);
if ( (_DWORD)result )
{
v10 = v14;
v11 = *a6;
v12 = &a6[5 * v11];
v12[1] = v14;
v13 = v15;
v12[2] = v15;
v12[3] = v10 + 1;
v12[4] = v13 + 1;
*((_BYTE *)v12 + 20) = 1;
LOBYTE(a6[5 * (unsigned int)(v11 + 1) + 5]) = 0;
*a6 = v11 + 2;
fprintf(stderr, "Grinding play , Found Button @ %u , %u \n", v10, v13);
result = 1LL;
}
}
}
else
{
memset(v16, 0, 0x1418uLL);
getValidMoves(v17, v16);
result = formulatePlan((__int64)v17, v16, a6);
continuousUncertainty = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int *a6)
{
__int64 result; // rax
int v9; // eax
unsigned int v10; // esi
__int64 v11; // r8
unsigned int *v12; // rcx
unsigned int v13; // edi
unsigned int v14; // [rsp+8h] [rbp-1550h] BYREF
unsigned int v15; // [rsp+Ch] [rbp-154Ch] BYREF
unsigned int v16[1288]; // [rsp+10h] [rbp-1548h] BYREF
char v17[296]; // [rsp+1430h] [rbp-128h] BYREF

settings[0] = a4;
settings[1] = a5;
memset(v17, 0, 0x100uLL);
seeTable(v17, a1, a2, a3, a4, a5);
func2((__int64)v17);
if ( (unsigned int)isSceneTooAmbiguous(v17) )
{
*a6 = 0;
printf("Scene is too ambiguous :( ( %u / %u ) \n", ++continuousUncertainty, 40LL);
result = 0LL;
if ( continuousUncertainty > 0x28 )
{
v9 = *a6;
LOBYTE(a6[5 * *a6 + 5]) = 0;
*a6 = v9 + 1;
v14 = 0;
v15 = 0;
result = seeButtons(a1, a2, a3, &v14, &v15);
if ( (_DWORD)result )
{
v10 = v14;
v11 = *a6;
v12 = &a6[5 * v11];
v12[1] = v14;
v13 = v15;
v12[2] = v15;
v12[3] = v10 + 1;
v12[4] = v13 + 1;
*((_BYTE *)v12 + 20) = 1;
LOBYTE(a6[5 * (unsigned int)(v11 + 1) + 5]) = 0;
*a6 = v11 + 2;
fprintf(stderr, "Grinding play , Found Button @ %u , %u \n", v10, v13);
result = 1LL;
}
}
}
else
{
memset(v16, 0, 0x1418uLL);
getValidMoves(v17, v16);
result = func3((__int64)v17, v16, a6);
continuousUncertainty = 0;
}
return result;
}

original_code:
int thinkWhatToPlay(unsigned char * screen , unsigned int screenWidth ,unsigned int screenHeight ,
                    unsigned int clientStartX , unsigned int clientStartY ,
                    struct mouseMovements * ourPlan )
{
    unsigned int resX = clientStartX , resY = clientStartY;
    settings.clientX = clientStartX;
    settings.clientY = clientStartY;
    unsigned int table[8][8]={0};
    seeTable(table , screen , screenWidth , screenHeight , clientStartX , clientStartY);
    printTable(table);
    if ( isSceneTooAmbiguous(table) )
       {
         ourPlan->totalMovements=0;
         ++continuousUncertainty;
         printf("Scene is too ambiguous :( ( %u / %u ) \n", continuousUncertainty , 40);
         if ( (1) && (continuousUncertainty>40) )
         {
           ourPlan->movement[ourPlan->totalMovements].mode = MOVE_TO_NEUTRAL;
           ++ourPlan->totalMovements;
           unsigned int clickX=0 , clickY=0;
           if ( seeButtons( screen , screenWidth , screenHeight , &clickX , &clickY) )
              {
                 ourPlan->movement[ourPlan->totalMovements].fromX = clickX;
                 ourPlan->movement[ourPlan->totalMovements].fromY = clickY;
                 ourPlan->movement[ourPlan->totalMovements].toX = clickX+1;
                 ourPlan->movement[ourPlan->totalMovements].toY = clickY+1;
                 ourPlan->movement[ourPlan->totalMovements].mode = SINGLE_MOVE_CLICK;
                 ++ourPlan->totalMovements;
                 ourPlan->movement[ourPlan->totalMovements].mode = MOVE_TO_NEUTRAL;
                 ++ourPlan->totalMovements;
                 fprintf(stderr,"Grinding play , Found Button @ %u , %u \n",clickX,clickY);
                 return 1;
              }
         }
         return 0;
       }
    struct solutionList list={0};
    list.currentSolutions=0;
    getValidMoves(table , &list );
    unsigned int totalSolutions = formulatePlan(table , &list ,ourPlan);
    continuousUncertainty=0;
    return totalSolutions;
}

canonical_original_code:
int thinkWhatToPlay(unsigned char *screen, unsigned int screenWidth, unsigned int screenHeight, unsigned int clientStartX, unsigned int clientStartY, struct mouseMovements *ourPlan)
{
    unsigned int resX = clientStartX; unsigned int resY = clientStartY;
    settings.clientX = clientStartX;
    settings.clientY = clientStartY;
    unsigned int table[8][8] = {0};
    seeTable(table , screen , screenWidth , screenHeight , clientStartX , clientStartY);
    printTable(table);
    if ( isSceneTooAmbiguous(table) )
       {
         ourPlan->totalMovements=0;
         ++continuousUncertainty;
         printf("Scene is too ambiguous :( ( %u / %u ) \n", continuousUncertainty , 40);
         if ( (1) && (continuousUncertainty>40) )
         {
           ourPlan->movement[ourPlan->totalMovements].mode = MOVE_TO_NEUTRAL;
           ++ourPlan->totalMovements;
           unsigned int clickX = 0; unsigned int clickY = 0;
           if ( seeButtons( screen , screenWidth , screenHeight , &clickX , &clickY) )
              {
                 ourPlan->movement[ourPlan->totalMovements].fromX = clickX;
                 ourPlan->movement[ourPlan->totalMovements].fromY = clickY;
                 ourPlan->movement[ourPlan->totalMovements].toX = clickX+1;
                 ourPlan->movement[ourPlan->totalMovements].toY = clickY+1;
                 ourPlan->movement[ourPlan->totalMovements].mode = SINGLE_MOVE_CLICK;
                 ++ourPlan->totalMovements;
                 ourPlan->movement[ourPlan->totalMovements].mode = MOVE_TO_NEUTRAL;
                 ++ourPlan->totalMovements;
                 fprintf(stderr,"Grinding play , Found Button @ %u , %u \n",clickX,clickY);
                 return 1;
              }
         }
         return 0;
       }
    struct solutionList list = {0};
    list.currentSolutions=0;
    getValidMoves(table , &list );
    unsigned int totalSolutions = formulatePlan(table , &list ,ourPlan);
    continuousUncertainty=0;
    return totalSolutions;
}

variable_types:
screen
unsigned char *

variable_types:
screenWidth
unsigned int

variable_types:
screenHeight
unsigned int

variable_types:
clientStartX
unsigned int

variable_types:
clientStartY
unsigned int

variable_types:
resX
unsigned int

variable_types:
resY
unsigned int

variable_types:
clickX
unsigned int

variable_types:
clickY
unsigned int

variable_types: struct solutionList { struct solutionItem { unsigned int fromX; unsigned int fromY; unsigned int toX; unsigned int toY; unsigned int score; } solution[-1]; unsigned int currentSolutions; }

variable_types:
totalSolutions
unsigned int

user_defined_types: struct mouseMovementItem { unsigned int fromX; unsigned int fromY; unsigned int toX; unsigned int toY; char mode; }


initializeEngine

decompiled_code:
__int64 __fastcall initializeEngine(char *s1)
{
if ( !strcasecmp(s1, "bejeweled blitz") )
{
settings[0] = 333;
settings[1] = 399;
settings[2] = 40;
settings[3] = 40;
settings[4] = 0;
settings[5] = 3;
settings[6] = 29;
}
else if ( !strcasecmp(s1, "gweled") )
{
settings[0] = 337;
settings[1] = 382;
settings[2] = 48;
settings[3] = 48;
settings[4] = 0;
settings[5] = 3;
settings[6] = 29;
}
return initVision();
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1)
{
if ( !strcasecmp(s1, "bejeweled blitz") )
{
settings[0] = 333;
settings[1] = 399;
settings[2] = 40;
settings[3] = 40;
settings[4] = 0;
settings[5] = 3;
settings[6] = 29;
}
else if ( !strcasecmp(s1, "gweled") )
{
settings[0] = 337;
settings[1] = 382;
settings[2] = 48;
settings[3] = 48;
settings[4] = 0;
settings[5] = 3;
settings[6] = 29;
}
return initVision();
}

original_code:
int initializeEngine(char * settingsStr)
{
    if ( strcasecmp(settingsStr,"bejeweled blitz")==0 )
    {
      settings.clientX = 333;
      settings.clientY = 399;
      settings.blockX = 40;
      settings.blockY = 40;
      settings.offsetX = 0;
      settings.offsetY = 3;
      settings.threshold = 29;
    } else
    if ( strcasecmp(settingsStr,"gweled")==0 )
    {
      settings.clientX = 337;
      settings.clientY = 382;
      settings.blockX = 48;
      settings.blockY = 48;
      settings.offsetX = 0;
      settings.offsetY = 3;
      settings.threshold = 29;
    }
    return initVision();
}

canonical_original_code:
int initializeEngine(char *settingsStr)
{
    if ( strcasecmp(settingsStr,"bejeweled blitz")==0 )
    {
      settings.clientX = 333;
      settings.clientY = 399;
      settings.blockX = 40;
      settings.blockY = 40;
      settings.offsetX = 0;
      settings.offsetY = 3;
      settings.threshold = 29;
    } else
    if ( strcasecmp(settingsStr,"gweled")==0 )
    {
      settings.clientX = 337;
      settings.clientY = 382;
      settings.blockX = 48;
      settings.blockY = 48;
      settings.offsetX = 0;
      settings.offsetY = 3;
      settings.threshold = 29;
    }
    return initVision();
}

variable_types:
settingsStr
char *


stopEngine

decompiled_code:
__int64 stopEngine()
{
return stopVision();
}

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

original_code:
int stopEngine()
{
    stopVision();
}

canonical_original_code:
int stopEngine()
{
    stopVision();
}


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 *