mainMenuUpdate

decompiled_code:
__int64 __fastcall mainMenuUpdate(int a1)
{
char v1; // bl
__int64 result; // rax
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = 0;
mainMenuTotalTimeElapsed += a1;
if ( (unsigned int)isKeyPressed() )
{
v1 = getChar();
flushInput();
}
result = (unsigned int)skIntro;
if ( !skIntro && (unsigned __int64)mainMenuTotalTimeElapsed <= 0x270F )
{
if ( (v1 & 0xDF) == 81 )
{
skIntro = 1;
return result;
}
return 0LL;
}
if ( mainMenuEnterScrAnim && (unsigned __int64)mainMenuTotalTimeElapsed <= 0x18F )
return 0LL;
if ( v1 <= 50 )
{
if ( v1 <= 48 )
{
LABEL_11:
if ( (unsigned __int64)(mainMenuTotalTimeElapsed - mainMenuTimeLastMovement) > 0x3E7 )
{
if ( (unsigned int)won(mainMenuGrid, 0LL) || (unsigned int)fullGrid(mainMenuGrid) )
{
deleteGrid(mainMenuGrid);
mainMenuGrid = createGrid();
}
else
{
nextMoveAI(mainMenuGrid, (unsigned int)mainMenuPlayTurn, v3);
setCell(mainMenuGrid, v3[0], (unsigned int)mainMenuPlayTurn);
mainMenuLastCellSigned = v3[0];
mainMenuCurrentCellDrawTime = rand() % 300 + 100;
mainMenuPlayTurn = mainMenuPlayTurn != 1;
}
mainMenuTimeLastMovement = mainMenuTotalTimeElapsed;
}
return 0LL;
}
result = (unsigned int)(char)(v1 - 48);
}
else
{
switch ( v1 )
{
case 'N':
case 'n':
exitQuest = 0;
goto LABEL_11;
case 'Q':
case 'q':
if ( !exitQuest )
exitQuest = 1;
goto LABEL_11;
case 'Y':
case 'y':
if ( !exitQuest )
goto LABEL_11;
result = 0xFFFFFFFFLL;
break;
default:
goto LABEL_11;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
char v1; // bl
__int64 result; // rax
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = 0;
mainMenuTotalTimeElapsed += a1;
if ( (unsigned int)isKeyPressed() )
{
v1 = getChar();
flushInput();
}
result = (unsigned int)skIntro;
if ( !skIntro && (unsigned __int64)mainMenuTotalTimeElapsed <= 0x270F )
{
if ( (v1 & 0xDF) == 81 )
{
skIntro = 1;
return result;
}
return 0LL;
}
if ( mainMenuEnterScrAnim && (unsigned __int64)mainMenuTotalTimeElapsed <= 0x18F )
return 0LL;
if ( v1 <= 50 )
{
if ( v1 <= 48 )
{
LABEL_11:
if ( (unsigned __int64)(mainMenuTotalTimeElapsed - mainMenuTimeLastMovement) > 0x3E7 )
{
if ( (unsigned int)won(mainMenuGrid, 0LL) || (unsigned int)fullGrid(mainMenuGrid) )
{
deleteGrid(mainMenuGrid);
mainMenuGrid = createGrid();
}
else
{
nextMoveAI(mainMenuGrid, (unsigned int)mainMenuPlayTurn, v3);
setCell(mainMenuGrid, v3[0], (unsigned int)mainMenuPlayTurn);
mainMenuLastCellSigned = v3[0];
mainMenuCurrentCellDrawTime = rand() % 300 + 100;
mainMenuPlayTurn = mainMenuPlayTurn != 1;
}
mainMenuTimeLastMovement = mainMenuTotalTimeElapsed;
}
return 0LL;
}
result = (unsigned int)(char)(v1 - 48);
}
else
{
switch ( v1 )
{
case 'N':
case 'n':
exitQuest = 0;
goto LABEL_11;
case 'Q':
case 'q':
if ( !exitQuest )
exitQuest = 1;
goto LABEL_11;
case 'Y':
case 'y':
if ( !exitQuest )
goto LABEL_11;
result = 0xFFFFFFFFLL;
break;
default:
goto LABEL_11;
}
}
return result;
}

original_code:
int mainMenuUpdate(int deltaT)
{
 char key = '\0';
 int introductionAnim, enteringAnim;
 mainMenuTotalTimeElapsed += deltaT;
 if(isKeyPressed())
 {
  key = getChar();
  flushInput();
 }
 introductionAnim = !skIntro && mainMenuTotalTimeElapsed < 10000;
 enteringAnim = mainMenuEnterScrAnim && mainMenuTotalTimeElapsed < 400;
 if(introductionAnim && (key == 'q' || key == 'Q'))
  skIntro = 1;
 if(!introductionAnim && !enteringAnim)
 {
  switch(key)
  {
  case '1':
  case '2':
   return (int)(key - '0');
  case 'q':
  case 'Q':
   if(!exitQuest)
    exitQuest = 1;
   break;
  case 'y':
  case 'Y':
   if(exitQuest)
    return -1;
   break;
  case 'n':
  case 'N':
   exitQuest = 0;
   break;
  }
 }
 if(!introductionAnim && !enteringAnim &&
  mainMenuTotalTimeElapsed - mainMenuTimeLastMovement >= 1000)
 {
  if(!won(mainMenuGrid, ((void *)0)) && !fullGrid(mainMenuGrid))
  {
   enum Cell move;
   nextMoveAI(mainMenuGrid, mainMenuPlayTurn, &move);
   setCell(mainMenuGrid, move, (CellState)mainMenuPlayTurn);
   mainMenuLastCellSigned = move;
   mainMenuCurrentCellDrawTime = (rand() % (400 - 100)) + 100;
   if(mainMenuPlayTurn == cross)
    mainMenuPlayTurn = circle;
   else
    mainMenuPlayTurn = cross;
  }
  else
  {
   deleteGrid(mainMenuGrid);
   mainMenuGrid = createGrid();
  }
  mainMenuTimeLastMovement = mainMenuTotalTimeElapsed;
 }
 return 0;
}

canonical_original_code:
int mainMenuUpdate(int deltaT)
{
 char key = '\0';
 int introductionAnim; int enteringAnim;
 mainMenuTotalTimeElapsed += deltaT;
 if(isKeyPressed())
 {
  key = getChar();
  flushInput();
 }
 introductionAnim = !skIntro && mainMenuTotalTimeElapsed < 10000;
 enteringAnim = mainMenuEnterScrAnim && mainMenuTotalTimeElapsed < 400;
 if(introductionAnim && (key == 'q' || key == 'Q'))
  skIntro = 1;
 if(!introductionAnim && !enteringAnim)
 {
  switch(key)
  {
  case '1':
  case '2':
   return (int)(key - '0');
  case 'q':
  case 'Q':
   if(!exitQuest)
    exitQuest = 1;
   break;
  case 'y':
  case 'Y':
   if(exitQuest)
    return -1;
   break;
  case 'n':
  case 'N':
   exitQuest = 0;
   break;
  }
 }
 if(!introductionAnim && !enteringAnim &&
  mainMenuTotalTimeElapsed - mainMenuTimeLastMovement >= 1000)
 {
  if(!won(mainMenuGrid, ((void *)0)) && !fullGrid(mainMenuGrid))
  {
   enum Cell move;
   nextMoveAI(mainMenuGrid, mainMenuPlayTurn, &move);
   setCell(mainMenuGrid, move, (enum Players)mainMenuPlayTurn);
   mainMenuLastCellSigned = move;
   mainMenuCurrentCellDrawTime = (rand() % (400 - 100)) + 100;
   if(mainMenuPlayTurn == cross)
    mainMenuPlayTurn = circle;
   else
    mainMenuPlayTurn = cross;
  }
  else
  {
   deleteGrid(mainMenuGrid);
   mainMenuGrid = createGrid();
  }
  mainMenuTimeLastMovement = mainMenuTotalTimeElapsed;
 }
 return 0;
}

variable_types: key char

variable_types: introductionAnim int

variable_types: enteringAnim int

variable_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 }


mainMenuDraw

decompiled_code:
__int64 __fastcall mainMenuDraw(__int64 a1)
{
__int64 i; // rax
int v3; // ecx
__int64 v4; // rsi
int j; // edi
int v6; // eax
int v7; // edx
int v8; // esi
__int64 result; // rax
unsigned __int64 v10; // rdi
__int64 v11; // rsi
char v12; // al
__int64 v13; // rax
__int64 v14; // rax

for ( i = 0LL; consoleHigh * consoleBase > (int)i; ++i )
*(_BYTE *)(a1 + i) = 32;
printGrid(
mainMenuGrid,
(unsigned int)mainMenuLastCellSigned,
(unsigned int)(mainMenuTotalTimeElapsed - mainMenuTimeLastMovement),
(unsigned int)mainMenuCurrentCellDrawTime,
mainMenuGridImage);
v3 = consoleBase;
v4 = 0LL;
for ( j = consoleBase * consoleHigh; v3 * consoleHigh > (int)v4; j = v3 * consoleHigh )
{
v7 = (int)v4 % v3;
v6 = (int)v4 / v3;
if ( (int)v4 % v3 <= 74 && v6 <= 23 )
{
if ( v6 > 1 && v7 <= 21 )
{
*(_BYTE *)(a1 + v4) = *(_BYTE *)(*((_QWORD *)mainMenuGridImage + v6 - 2) + v7);
v3 = consoleBase;
}
else if ( (unsigned int)(v6 - 18) > 4 || exitQuest )
{
*(_BYTE *)(a1 + v4) = mainMenuBaseImage[76 * v6 + v7];
v3 = consoleBase;
}
else
{
*(_BYTE *)(a1 + v4) = 32;
v3 = consoleBase;
}
}
++v4;
}
v8 = skIntro;
if ( !skIntro && (unsigned __int64)mainMenuTotalTimeElapsed <= 0x270F )
{
if ( (unsigned __int64)(mainMenuTotalTimeElapsed - 2000) > 0xBB7 )
{
if ( (unsigned __int64)(mainMenuTotalTimeElapsed - 5000) <= 0x7CF )
{
v8 = 36;
}
else if ( (unsigned __int64)mainMenuTotalTimeElapsed > 0x1B57 )
{
v8 = (mainMenuTotalTimeElapsed - 7000) * (24 * v3 - 36) / 0xBB8uLL + 36;
}
}
else
{
v8 = (36 * mainMenuTotalTimeElapsed - 72000) / 0xBB8uLL;
}
if ( mainMenuTotalTimeElapsed % 0x3E8uLL <= 0x1F3 && v8 < j )
{
v13 = v8++;
*(_BYTE *)(a1 + v13) = 95;
v3 = consoleBase;
}
if ( v8 < v3 * consoleHigh )
{
v14 = v8;
do
{
*(_BYTE *)(a1 + v14) = 32;
v3 = consoleBase;
++v14;
}
while ( consoleBase * consoleHigh > (int)v14 );
}
}
result = (unsigned int)mainMenuEnterScrAnim;
if ( mainMenuEnterScrAnim )
{
result = mainMenuTotalTimeElapsed;
if ( (unsigned __int64)mainMenuTotalTimeElapsed <= 0x18F )
{
result = (unsigned int)(v3 * consoleHigh);
v10 = v3 * (400 - mainMenuTotalTimeElapsed) / 0x190uLL;
if ( (int)result > 0 )
{
v11 = 0LL;
do
{
if ( (int)v10 + (int)v11 % v3 < v3 )
v12 = *(_BYTE *)(a1 + (int)v11 + (int)v10);
else
v12 = *((_BYTE *)mainMenuPreviousScreen + (int)v10 + (int)v11 - v3);
*(_BYTE *)(a1 + v11) = v12;
v3 = consoleBase;
++v11;
result = (unsigned int)(consoleBase * consoleHigh);
}
while ( (int)result > (int)v11 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 i; // rax
int v3; // ecx
__int64 v4; // rsi
int j; // edi
int v6; // eax
int v7; // edx
int v8; // esi
__int64 result; // rax
unsigned __int64 v10; // rdi
__int64 v11; // rsi
char v12; // al
__int64 v13; // rax
__int64 v14; // rax

for ( i = 0LL; consoleHigh * consoleBase > (int)i; ++i )
*(_BYTE *)(a1 + i) = 32;
printGrid(
mainMenuGrid,
(unsigned int)mainMenuLastCellSigned,
(unsigned int)(mainMenuTotalTimeElapsed - mainMenuTimeLastMovement),
(unsigned int)mainMenuCurrentCellDrawTime,
mainMenuGridImage);
v3 = consoleBase;
v4 = 0LL;
for ( j = consoleBase * consoleHigh; v3 * consoleHigh > (int)v4; j = v3 * consoleHigh )
{
v7 = (int)v4 % v3;
v6 = (int)v4 / v3;
if ( (int)v4 % v3 <= 74 && v6 <= 23 )
{
if ( v6 > 1 && v7 <= 21 )
{
*(_BYTE *)(a1 + v4) = *(_BYTE *)(*((_QWORD *)mainMenuGridImage + v6 - 2) + v7);
v3 = consoleBase;
}
else if ( (unsigned int)(v6 - 18) > 4 || exitQuest )
{
*(_BYTE *)(a1 + v4) = mainMenuBaseImage[76 * v6 + v7];
v3 = consoleBase;
}
else
{
*(_BYTE *)(a1 + v4) = 32;
v3 = consoleBase;
}
}
++v4;
}
v8 = skIntro;
if ( !skIntro && (unsigned __int64)mainMenuTotalTimeElapsed <= 0x270F )
{
if ( (unsigned __int64)(mainMenuTotalTimeElapsed - 2000) > 0xBB7 )
{
if ( (unsigned __int64)(mainMenuTotalTimeElapsed - 5000) <= 0x7CF )
{
v8 = 36;
}
else if ( (unsigned __int64)mainMenuTotalTimeElapsed > 0x1B57 )
{
v8 = (mainMenuTotalTimeElapsed - 7000) * (24 * v3 - 36) / 0xBB8uLL + 36;
}
}
else
{
v8 = (36 * mainMenuTotalTimeElapsed - 72000) / 0xBB8uLL;
}
if ( mainMenuTotalTimeElapsed % 0x3E8uLL <= 0x1F3 && v8 < j )
{
v13 = v8++;
*(_BYTE *)(a1 + v13) = 95;
v3 = consoleBase;
}
if ( v8 < v3 * consoleHigh )
{
v14 = v8;
do
{
*(_BYTE *)(a1 + v14) = 32;
v3 = consoleBase;
++v14;
}
while ( consoleBase * consoleHigh > (int)v14 );
}
}
result = (unsigned int)mainMenuEnterScrAnim;
if ( mainMenuEnterScrAnim )
{
result = mainMenuTotalTimeElapsed;
if ( (unsigned __int64)mainMenuTotalTimeElapsed <= 0x18F )
{
result = (unsigned int)(v3 * consoleHigh);
v10 = v3 * (400 - mainMenuTotalTimeElapsed) / 0x190uLL;
if ( (int)result > 0 )
{
v11 = 0LL;
do
{
if ( (int)v10 + (int)v11 % v3 < v3 )
v12 = *(_BYTE *)(a1 + (int)v11 + (int)v10);
else
v12 = *((_BYTE *)mainMenuPreviousScreen + (int)v10 + (int)v11 - v3);
*(_BYTE *)(a1 + v11) = v12;
v3 = consoleBase;
++v11;
result = (unsigned int)(consoleBase * consoleHigh);
}
while ( (int)result > (int)v11 );
}
}
}
return result;
}

original_code:
void mainMenuDraw(char *videoBuffer)
{
 int i;
 for(i = 0; i < consoleBase*consoleHigh; i++)
  videoBuffer[i] = ' ';
 printGrid(mainMenuGrid, mainMenuLastCellSigned, mainMenuTotalTimeElapsed - mainMenuTimeLastMovement,
  mainMenuCurrentCellDrawTime, mainMenuGridImage);
 for(i = 0; i < consoleBase*consoleHigh; i++)
 {
  int row = i / consoleBase,
   column = i % consoleBase;
  if(column < 75 && row < 24)
  {
   if(row >= 2 && column < 22 && row < 24)
    videoBuffer[i] = mainMenuGridImage[row-2][column];
   else if(row >= 18 && row < 23 && !exitQuest)
    videoBuffer[i] = ' ';
   else
    videoBuffer[i] = mainMenuBaseImage[row][column];
  }
 }
 if(!skIntro && mainMenuTotalTimeElapsed < 10000)
 {
  int printedChar = 0;
  if(mainMenuTotalTimeElapsed >= 2000 && mainMenuTotalTimeElapsed < 5000)
   printedChar = (mainMenuTotalTimeElapsed - 2000) * 36 / 3000;
  else if(mainMenuTotalTimeElapsed >= 5000 && mainMenuTotalTimeElapsed < 7000)
   printedChar = 36;
  else if(mainMenuTotalTimeElapsed >= 7000)
   printedChar = (mainMenuTotalTimeElapsed - 7000) * (consoleBase*24 - 36) / 3000 + 36;
  if(mainMenuTotalTimeElapsed % 1000 < 500 && printedChar < consoleBase*consoleHigh)
   videoBuffer[printedChar++] = '_';
  for(; printedChar < consoleBase*consoleHigh; printedChar++)
   videoBuffer[printedChar] = ' ';
 }
 if(mainMenuEnterScrAnim && mainMenuTotalTimeElapsed < 400)
 {
  int shift = consoleBase * (400 - mainMenuTotalTimeElapsed) / 400;
  for(i = 0; i < consoleBase*consoleHigh; i++)
  {
   int column = i % consoleBase;
   if(column + shift < consoleBase)
    videoBuffer[i] = videoBuffer[i + shift];
   else
    videoBuffer[i] = mainMenuPreviousScreen[i - consoleBase + shift];
  }
 }
}

canonical_original_code:
void mainMenuDraw(char *videoBuffer)
{
 int i;
 for(i = 0; i < consoleBase*consoleHigh; i++)
  videoBuffer[i] = ' ';
 printGrid(mainMenuGrid, mainMenuLastCellSigned, mainMenuTotalTimeElapsed - mainMenuTimeLastMovement,
  mainMenuCurrentCellDrawTime, mainMenuGridImage);
 for(i = 0; i < consoleBase*consoleHigh; i++)
 {
  int row = i / consoleBase; int column = i % consoleBase;
  if(column < 75 && row < 24)
  {
   if(row >= 2 && column < 22 && row < 24)
    videoBuffer[i] = mainMenuGridImage[row-2][column];
   else if(row >= 18 && row < 23 && !exitQuest)
    videoBuffer[i] = ' ';
   else
    videoBuffer[i] = mainMenuBaseImage[row][column];
  }
 }
 if(!skIntro && mainMenuTotalTimeElapsed < 10000)
 {
  int printedChar = 0;
  if(mainMenuTotalTimeElapsed >= 2000 && mainMenuTotalTimeElapsed < 5000)
   printedChar = (mainMenuTotalTimeElapsed - 2000) * 36 / 3000;
  else if(mainMenuTotalTimeElapsed >= 5000 && mainMenuTotalTimeElapsed < 7000)
   printedChar = 36;
  else if(mainMenuTotalTimeElapsed >= 7000)
   printedChar = (mainMenuTotalTimeElapsed - 7000) * (consoleBase*24 - 36) / 3000 + 36;
  if(mainMenuTotalTimeElapsed % 1000 < 500 && printedChar < consoleBase*consoleHigh)
   videoBuffer[printedChar++] = '_';
  for(; printedChar < consoleBase*consoleHigh; printedChar++)
   videoBuffer[printedChar] = ' ';
 }
 if(mainMenuEnterScrAnim && mainMenuTotalTimeElapsed < 400)
 {
  int shift = consoleBase * (400 - mainMenuTotalTimeElapsed) / 400;
  for(i = 0; i < consoleBase*consoleHigh; i++)
  {
   int column = i % consoleBase;
   if(column + shift < consoleBase)
    videoBuffer[i] = videoBuffer[i + shift];
   else
    videoBuffer[i] = mainMenuPreviousScreen[i - consoleBase + shift];
  }
 }
}

variable_types:
videoBuffer
char *

variable_types: i int

variable_types: row int

variable_types: column int

variable_types: printedChar int

variable_types: shift int

return_type: void


createGameHistory

decompiled_code:
char *createGameHistory()
{
char *v0; // r12
char *v1; // rbx

v0 = (char *)malloc(0xC0uLL);
v1 = v0;
do
{
v1 += 8;
*((_QWORD *)v1 - 1) = createGameResult();
}
while ( v1 != v0 + 192 );
return v0;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // r12
char *v1; // rbx

v0 = (char *)malloc(0xC0uLL);
v1 = v0;
do
{
v1 += 8;
*((_QWORD *)v1 - 1) = createGameResult();
}
while ( v1 != v0 + 192 );
return v0;
}

original_code:
struct GameHistory createGameHistory()
{
 int i;
 struct GameHistory history;
 history.arrayPointer = 0;
 history.totalGameCounter = 0;
 history.history = (struct GameResult *)malloc(sizeof(struct GameResult) * 24);
 for(i = 0; i < 24; i++)
  history.history[i] = createGameResult();
 return history;
}

variable_types: struct GameHistory { struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; } *history; int arrayPointer; unsigned int totalGameCounter; }

user_defined_types: struct GameHistory { struct GameResult *history; int arrayPointer; unsigned int totalGameCounter; }

user_defined_types: struct GameResult { enum Players winner; enum CellLine winningLine; }


deleteGameHistory

decompiled_code:
void __fastcall deleteGameHistory(void *ptr)
{
void *v1; // r12
char *v2; // rbp
__int64 *v3; // rbx
__int64 v4; // rdi

v1 = ptr;
v2 = (char *)ptr + 192;
v3 = (__int64 *)ptr;
do
{
v4 = *v3++;
deleteGameResult(v4);
}
while ( v3 != (__int64 *)v2 );
free(v1);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v1; // r12
char *v2; // rbp
__int64 *v3; // rbx
__int64 v4; // rdi

v1 = ptr;
v2 = (char *)ptr + 192;
v3 = (__int64 *)ptr;
do
{
v4 = *v3++;
deleteGameResult(v4);
}
while ( v3 != (__int64 *)v2 );
free(v1);
}

original_code:
void deleteGameHistory(struct GameHistory history)
{
 int i;
 for(i = 0; i < 24; i++)
  deleteGameResult(history.history[i]);
 free(history.history);
}

user_defined_types: enum Players { noPlayer=-1, circle=0, cross=1 }


getGameHistoryTotalCounter

decompiled_code:
unsigned __int64 __fastcall getGameHistoryTotalCounter(__int64 a1, unsigned __int64 a2)
{
return HIDWORD(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
return HIDWORD(a2);
}

original_code:
int getGameHistoryTotalCounter(struct GameHistory history)
{
 return history.totalGameCounter;
}

return_type: int


getGameResult

decompiled_code:
__int64 __fastcall getGameResult(__int64 a1, unsigned __int64 a2)
{
int v2; // eax
int v3; // edx
_QWORD *v4; // rcx
unsigned int v5; // er8
_QWORD *v6; // rbp
int v8; // ebx

v2 = getGameHistoryTotalCounter(a1, a2);
if ( v2 <= v3 )
return v5;
v6 = v4;
if ( v2 - 24 > v3 )
return v5;
v8 = v3 + a2 - v2 + (v3 + (int)a2 - v2 < 0 ? 0x18 : 0);
deleteGameResult(*v4);
*v6 = copyGameResult(*(_QWORD *)(a1 + 8LL * v8));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2)
{
int v2; // eax
int v3; // edx
_QWORD *v4; // rcx
unsigned int v5; // er8
_QWORD *v6; // rbp
int v8; // ebx

v2 = func3(a1, a2);
if ( v2 <= v3 )
return v5;
v6 = v4;
if ( v2 - 24 > v3 )
return v5;
v8 = v3 + a2 - v2 + (v3 + (int)a2 - v2 < 0 ? 0x18 : 0);
deleteGameResult(*v4);
*v6 = copyGameResult(*(_QWORD *)(a1 + 8LL * v8));
return 1LL;
}

original_code:
int getGameResult(struct GameHistory history, int id, struct GameResult *result)
{
 if(id >= getGameHistoryTotalCounter(history) ||
  id < getGameHistoryTotalCounter(history) - 24)
  return 0;
 else
 {
  int idPointer = history.arrayPointer + id - getGameHistoryTotalCounter(history);
  if(idPointer < 0)
   idPointer += 24;
  deleteGameResult(*result);
  *result = copyGameResult(history.history[idPointer]);
  return 1;
 }
}

variable_types: id int

variable_types:
result
struct GameResult *

variable_types: idPointer int


addGameResult

decompiled_code:
__int64 __fastcall addGameResult(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax

deleteGameResult(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8)));
*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8)) = copyGameResult(a2);
v2 = *(_DWORD *)(a1 + 8);
++*(_DWORD *)(a1 + 12);
v3 = v2 + 1;
result = (unsigned int)(24 * ((v2 + 1) / 24));
*(_DWORD *)(a1 + 8) = v3 - result;
return result;
}

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

deleteGameResult(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8)));
*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8)) = copyGameResult(a2);
v2 = *(_DWORD *)(a1 + 8);
++*(_DWORD *)(a1 + 12);
v3 = v2 + 1;
result = (unsigned int)(24 * ((v2 + 1) / 24));
*(_DWORD *)(a1 + 8) = v3 - result;
return result;
}

original_code:
void addGameResult(struct GameHistory *history, struct GameResult result)
{
 deleteGameResult(history->history[history->arrayPointer]);
 history->history[history->arrayPointer] = copyGameResult(result);
 history->arrayPointer = (history->arrayPointer + 1) % 24;
 history->totalGameCounter++;
}

variable_types: struct GameHistory { struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; } *history; int arrayPointer; unsigned int totalGameCounter; } *

variable_types:
result
struct GameResult


printGameHistory

decompiled_code:
void __fastcall printGameHistory(__int64 a1, unsigned __int64 a2, _QWORD *a3, int a4, int a5)
{
int v6; // er12
int v7; // ebx
int v8; // eax
int v9; // ebp
__int64 v10; // rbx
int v11; // eax
char v12; // r11
int v13; // ecx
int v14; // eax
int v15; // er11
unsigned int v16; // eax
_BYTE *v17; // rax
unsigned int v18; // er9
char *v19; // rcx
char v20; // al
int v21; // [rsp+14h] [rbp-64h]
int v22; // [rsp+18h] [rbp-60h]
int v23; // [rsp+18h] [rbp-60h]
unsigned int v24; // [rsp+1Ch] [rbp-5Ch]
int v25; // [rsp+1Ch] [rbp-5Ch]
unsigned int ptr; // [rsp+28h] [rbp-50h]
_BYTE *ptra; // [rsp+28h] [rbp-50h]
int v30; // [rsp+30h] [rbp-48h] BYREF
unsigned int v31; // [rsp+34h] [rbp-44h] BYREF
__int64 v32; // [rsp+38h] [rbp-40h]

v6 = a4;
v7 = a5;
v8 = getGameHistoryTotalCounter(a1, a2);
v21 = countIntegerDigits((unsigned int)(v8 - 1));
if ( v7 > 0 )
{
v9 = 0;
while ( 1 )
{
v10 = 0LL;
if ( a4 > 0 )
break;
LABEL_13:
++v9;
++a3;
if ( a5 == v9 )
return;
}
while ( 1 )
{
while ( (int)v10 > 47 || v9 > 7 )
{
*(_BYTE *)(*a3 + v10++) = 0;
if ( v6 == v10 )
goto LABEL_13;
}
v11 = getGameHistoryTotalCounter(a1, a2);
v14 = v11 - 1 - (v9 + 8 * (v13 >> 4));
if ( v14 < 0 )
goto LABEL_15;
v15 = v12 & 0xF;
if ( v21 <= v15 )
{
if ( v21 == v15 )
{
*(_BYTE *)(*a3 + v10) = 58;
}
else
{
v25 = v15;
v32 = createGameResult();
getGameResult(a1, a2);
getGameResultState(v32, &v30, &v31);
deleteGameResult(v32);
if ( v21 + 2 == v25 )
{
if ( v30 )
{
if ( v30 == 1 )
{
*(_BYTE *)(*a3 + v10) = 88;
}
else if ( v30 == -1 )
{
*(_BYTE *)(*a3 + v10) = 45;
}
}
else
{
*(_BYTE *)(*a3 + v10) = 79;
}
}
else
{
v19 = (char *)(v10 + *a3);
if ( v21 + 3 >= v25 || v21 + 9 < v25 || v30 == -1 )
{
*v19 = 32;
}
else
{
if ( v21 + 7 < v25 )
v20 = *((_BYTE *)*(&CellLineNames + v31) + v25 - (v21 + 8));
else
v20 = byte_4C1[v25 - (v21 + 4)];
*v19 = v20;
}
}
}
goto LABEL_9;
}
v22 = v15;
v24 = v14;
v16 = countIntegerDigits((unsigned int)v14);
v23 = v16 - v21 + v22;
if ( v23 < 0 )
{
LABEL_15:
*(_BYTE *)(*a3 + v10) = 32;
}
else
{
ptr = v16;
v17 = malloc((int)v16);
v18 = ptr;
ptra = v17;
integerToString(v24, v17, v18);
*(_BYTE *)(*a3 + v10) = ptra[v23];
free(ptra);
}
LABEL_9:
if ( v6 == ++v10 )
goto LABEL_13;
}
}
}

original_code:
void printGameHistory(struct GameHistory history, char** imageGameHistory, int bAlloc, int hAlloc)
{
 int i, j;
 int maxLengthID = countIntegerDigits(getGameHistoryTotalCounter(history) - 1);
 for(i = 0; i < hAlloc; i++)
  for(j = 0; j < bAlloc; j++)
   if(i < 8 && j < 48)
   {
    int columnOfRecord = j/16;
    int currentRecordID = (getGameHistoryTotalCounter(history) - 1) - (columnOfRecord*8 + i);
    if(currentRecordID >= 0)
    {
     int stringPositionOnRecord = j%16;
     if(stringPositionOnRecord < maxLengthID)
     {
      int countIDDigits = countIntegerDigits(currentRecordID);
      int IDDigitPosition = countIDDigits - maxLengthID + stringPositionOnRecord;
      if(IDDigitPosition >= 0)
      {
       char *IDString = (char*)malloc(sizeof(char)*countIDDigits);
       integerToString(currentRecordID, IDString, countIDDigits);
       imageGameHistory[i][j] = IDString[IDDigitPosition];
       free(IDString);
      }
      else
       imageGameHistory[i][j] = ' ';
     }
     else if(stringPositionOnRecord == maxLengthID)
      imageGameHistory[i][j] = ':';
     else
     {
      enum Players winner;
      enum CellLine winningLine;
      struct GameResult IDResult = createGameResult();
      getGameResult(history, currentRecordID, &IDResult);
      getGameResultState(IDResult, &winner, &winningLine);
      deleteGameResult(IDResult);
      if(stringPositionOnRecord == maxLengthID + 2)
       switch(winner)
       {
       case noPlayer: imageGameHistory[i][j] = '-'; break;
       case circle: imageGameHistory[i][j] = 'O'; break;
       case cross: imageGameHistory[i][j] = 'X';
       }
      else if(stringPositionOnRecord >= maxLengthID + 4 &&
       stringPositionOnRecord < maxLengthID + 10 &&
       winner != noPlayer)
      {
       if(stringPositionOnRecord < maxLengthID + 8)
       {
        char *baseStr = "on: ";
        imageGameHistory[i][j] = baseStr[stringPositionOnRecord - (maxLengthID + 4)];
       }
       else
        imageGameHistory[i][j] = CellLineNames[winningLine][stringPositionOnRecord - (maxLengthID + 8)];
      }
      else
       imageGameHistory[i][j] = ' ';
     }
    }
    else
     imageGameHistory[i][j] = ' ';
   }
   else
    imageGameHistory[i][j] = '\0';
}

canonical_original_code:
void printGameHistory(struct GameHistory history, char **imageGameHistory, int bAlloc, int hAlloc)
{
 int i; int j;
 int maxLengthID = countIntegerDigits(getGameHistoryTotalCounter(history) - 1);
 for(i = 0; i < hAlloc; i++)
  for(j = 0; j < bAlloc; j++)
   if(i < 8 && j < 48)
   {
    int columnOfRecord = j/16;
    int currentRecordID = (getGameHistoryTotalCounter(history) - 1) - (columnOfRecord*8 + i);
    if(currentRecordID >= 0)
    {
     int stringPositionOnRecord = j%16;
     if(stringPositionOnRecord < maxLengthID)
     {
      int countIDDigits = countIntegerDigits(currentRecordID);
      int IDDigitPosition = countIDDigits - maxLengthID + stringPositionOnRecord;
      if(IDDigitPosition >= 0)
      {
       char *IDString = (char*)malloc(sizeof(char)*countIDDigits);
       integerToString(currentRecordID, IDString, countIDDigits);
       imageGameHistory[i][j] = IDString[IDDigitPosition];
       free(IDString);
      }
      else
       imageGameHistory[i][j] = ' ';
     }
     else if(stringPositionOnRecord == maxLengthID)
      imageGameHistory[i][j] = ':';
     else
     {
      enum Players winner;
      enum CellLine winningLine;
      struct GameResult IDResult = createGameResult();
      getGameResult(history, currentRecordID, &IDResult);
      getGameResultState(IDResult, &winner, &winningLine);
      deleteGameResult(IDResult);
      if(stringPositionOnRecord == maxLengthID + 2)
       switch(winner)
       {
       case noPlayer: imageGameHistory[i][j] = '-'; break;
       case circle: imageGameHistory[i][j] = 'O'; break;
       case cross: imageGameHistory[i][j] = 'X';
       }
      else if(stringPositionOnRecord >= maxLengthID + 4 &&
       stringPositionOnRecord < maxLengthID + 10 &&
       winner != noPlayer)
      {
       if(stringPositionOnRecord < maxLengthID + 8)
       {
        char *baseStr = "on: ";
        imageGameHistory[i][j] = baseStr[stringPositionOnRecord - (maxLengthID + 4)];
       }
       else
        imageGameHistory[i][j] = CellLineNames[winningLine][stringPositionOnRecord - (maxLengthID + 8)];
      }
      else
       imageGameHistory[i][j] = ' ';
     }
    }
    else
     imageGameHistory[i][j] = ' ';
   }
   else
    imageGameHistory[i][j] = '\0';
}

variable_types:
imageGameHistory
char **

variable_types: bAlloc int

variable_types: hAlloc int

variable_types: j int

variable_types: maxLengthID int

variable_types: columnOfRecord int

variable_types: currentRecordID int

variable_types: stringPositionOnRecord int

variable_types: countIDDigits int

variable_types: IDDigitPosition int

variable_types:
IDString
char *

variable_types: struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; }

variable_types:
baseStr
char *


playTrisInitialize

decompiled_code:
void *__fastcall playTrisInitialize(int a1, int a2, __int64 a3, int a4, int a5, int a6)
{
char v8; // al
char *v9; // rbx
char *v10; // r13
__int64 v11; // rdx
char *v12; // rbx
char *v13; // rbp
void *result; // rax
int v16; // er15
_BYTE *v17; // rdx
__int64 v18; // rax
int v19; // [rsp+Ch] [rbp-3Ch]

playTrisGameMode = a4;
playTrisEnterScrAnim = a3 != 0;
if ( a3 )
{
v16 = consoleBase;
v19 = consoleHigh;
playTrisPreviousScreen = malloc(consoleHigh * (__int64)consoleBase);
v17 = playTrisPreviousScreen;
if ( v19 * v16 > 0 )
{
v18 = 0LL;
while ( 1 )
{
v17[v18] = *(_BYTE *)(a3 + v18);
if ( consoleHigh * consoleBase <= (int)++v18 )
break;
v17 = playTrisPreviousScreen;
}
}
}
playTrisTotalTimeElapsed = 0LL;
playTrisTimeLastMovement = 0LL;
v8 = rand();
playTrisCircleIntelligence = a5;
playTrisCrossIntelligence = a6;
playTrisTurn = v8 & 1;
playTrisCircleWinCounter = 0;
playTrisCrossWinCounter = 0;
playTrisGrid = createGrid();
playTrisGridImage = malloc(0xB0uLL);
v9 = (char *)playTrisGridImage;
v10 = (char *)playTrisGridImage + 176;
do
{
v9 += 8;
*((_QWORD *)v9 - 1) = malloc(0x16uLL);
}
while ( v10 != v9 );
consoleHigh = a2;
consoleBase = a1;
playTrisGameHistory = createGameHistory();
*(&playTrisGameHistory + 1) = v11;
playTrisGameHistoryImage = malloc(0x40uLL);
v12 = (char *)playTrisGameHistoryImage;
v13 = (char *)playTrisGameHistoryImage + 64;
do
{
v12 += 8;
result = malloc(0x30uLL);
*((_QWORD *)v12 - 1) = result;
}
while ( v12 != v13 );
showInstruction = 0;
instructionPosition = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1, int a2, __int64 a3, int a4, int a5, int a6)
{
char v8; // al
char *v9; // rbx
char *v10; // r13
__int64 v11; // rdx
char *v12; // rbx
char *v13; // rbp
void *result; // rax
int v16; // er15
_BYTE *v17; // rdx
__int64 v18; // rax
int v19; // [rsp+Ch] [rbp-3Ch]

playTrisGameMode = a4;
playTrisEnterScrAnim = a3 != 0;
if ( a3 )
{
v16 = consoleBase;
v19 = consoleHigh;
playTrisPreviousScreen = malloc(consoleHigh * (__int64)consoleBase);
v17 = playTrisPreviousScreen;
if ( v19 * v16 > 0 )
{
v18 = 0LL;
while ( 1 )
{
v17[v18] = *(_BYTE *)(a3 + v18);
if ( consoleHigh * consoleBase <= (int)++v18 )
break;
v17 = playTrisPreviousScreen;
}
}
}
playTrisTotalTimeElapsed = 0LL;
playTrisTimeLastMovement = 0LL;
v8 = rand();
playTrisCircleIntelligence = a5;
playTrisCrossIntelligence = a6;
playTrisTurn = v8 & 1;
playTrisCircleWinCounter = 0;
playTrisCrossWinCounter = 0;
playTrisGrid = createGrid();
playTrisGridImage = malloc(0xB0uLL);
v9 = (char *)playTrisGridImage;
v10 = (char *)playTrisGridImage + 176;
do
{
v9 += 8;
*((_QWORD *)v9 - 1) = malloc(0x16uLL);
}
while ( v10 != v9 );
consoleHigh = a2;
consoleBase = a1;
playTrisGameHistory = createGameHistory();
*(&playTrisGameHistory + 1) = v11;
playTrisGameHistoryImage = malloc(0x40uLL);
v12 = (char *)playTrisGameHistoryImage;
v13 = (char *)playTrisGameHistoryImage + 64;
do
{
v12 += 8;
result = malloc(0x30uLL);
*((_QWORD *)v12 - 1) = result;
}
while ( v12 != v13 );
showInstruction = 0;
instructionPosition = 0;
return result;
}

original_code:
void playTrisInitialize(int consoleB, int consoleH, char *prevScreen, enum GameMode gameMode,
 enum PlayerTypes circleIntelligence, enum PlayerTypes crossIntelligence)
{
 int i;
 playTrisGameMode = gameMode;
 playTrisEnterScrAnim = prevScreen != 0;
 if(playTrisEnterScrAnim)
 {
  playTrisPreviousScreen = (char*)malloc(sizeof(char)*consoleBase*consoleHigh);
  for(i = 0; i < consoleBase*consoleHigh; i++)
   playTrisPreviousScreen[i] = prevScreen[i];
 }
 playTrisTotalTimeElapsed = 0;
 playTrisTimeLastMovement = 0;
 playTrisTurn = (rand() % 2 == 0 ? circle : cross);
 playTrisCircleIntelligence = circleIntelligence;
 playTrisCrossIntelligence = crossIntelligence;
 playTrisCircleWinCounter = 0;
 playTrisCrossWinCounter = 0;
 playTrisGrid = createGrid();
 playTrisGridImage = (char**)malloc(sizeof(char*)*22);
 for(i = 0; i < 22; i++)
  playTrisGridImage[i] = (char*)malloc(sizeof(char)*22);
 consoleBase = consoleB;
 consoleHigh = consoleH;
 playTrisGameHistory = createGameHistory();
 playTrisGameHistoryImage = (char**)malloc(sizeof(char*)*8);
 for(i = 0; i < 8; i++)
  playTrisGameHistoryImage[i] = (char*)malloc(sizeof(char)*48);
 showInstruction = 0;
 instructionPosition = 0;
}

canonical_original_code:
void playTrisInitialize(int consoleB, int consoleH, char *prevScreen, enum GameMode gameMode, enum PlayerTypes circleIntelligence, enum PlayerTypes crossIntelligence)
{
 int i;
 playTrisGameMode = gameMode;
 playTrisEnterScrAnim = prevScreen != 0;
 if(playTrisEnterScrAnim)
 {
  playTrisPreviousScreen = (char *)malloc(sizeof(char)*consoleBase*consoleHigh);
  for(i = 0; i < consoleBase*consoleHigh; i++)
   playTrisPreviousScreen[i] = prevScreen[i];
 }
 playTrisTotalTimeElapsed = 0;
 playTrisTimeLastMovement = 0;
 playTrisTurn = (rand() % 2 == 0 ? circle : cross);
 playTrisCircleIntelligence = circleIntelligence;
 playTrisCrossIntelligence = crossIntelligence;
 playTrisCircleWinCounter = 0;
 playTrisCrossWinCounter = 0;
 playTrisGrid = createGrid();
 playTrisGridImage = (char **)malloc(sizeof(char *)*22);
 for(i = 0; i < 22; i++)
  playTrisGridImage[i] = (char *)malloc(sizeof(char)*22);
 consoleBase = consoleB;
 consoleHigh = consoleH;
 playTrisGameHistory = createGameHistory();
 playTrisGameHistoryImage = (char **)malloc(sizeof(char *)*8);
 for(i = 0; i < 8; i++)
  playTrisGameHistoryImage[i] = (char *)malloc(sizeof(char)*48);
 showInstruction = 0;
 instructionPosition = 0;
}

variable_types: consoleB int

variable_types: consoleH int

variable_types:
prevScreen
char *

variable_types:
gameMode
enum GameMode { local=0, network=1 }

variable_types:
circleIntelligence
enum PlayerTypes { human=0, AI=1 }

variable_types:
crossIntelligence
enum PlayerTypes { human=0, AI=1 }

variable_types: i int

user_defined_types:
enum GameMode { local=0, network=1 }
enum PlayerTypes { human=0, AI=1 }


playTrisDestroy

decompiled_code:
void playTrisDestroy()
{
__int64 v0; // rbx
void *v1; // rdi
__int64 v2; // rbx
void *v3; // rdi

v0 = 0LL;
deleteGrid(playTrisGrid);
deleteGameHistory(playTrisGameHistory, *(&playTrisGameHistory + 1));
do
{
v1 = *(void **)((char *)playTrisGridImage + v0);
v0 += 8LL;
free(v1);
}
while ( v0 != 176 );
v2 = 0LL;
free(playTrisGridImage);
do
{
v3 = *(void **)((char *)playTrisGameHistoryImage + v2);
v2 += 8LL;
free(v3);
}
while ( v2 != 64 );
free(playTrisGameHistoryImage);
if ( playTrisEnterScrAnim )
free(playTrisPreviousScreen);
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx
void *v1; // rdi
__int64 v2; // rbx
void *v3; // rdi

v0 = 0LL;
deleteGrid(playTrisGrid);
deleteGameHistory(playTrisGameHistory, *(&playTrisGameHistory + 1));
do
{
v1 = *(void **)((char *)playTrisGridImage + v0);
v0 += 8LL;
free(v1);
}
while ( v0 != 176 );
v2 = 0LL;
free(playTrisGridImage);
do
{
v3 = *(void **)((char *)playTrisGameHistoryImage + v2);
v2 += 8LL;
free(v3);
}
while ( v2 != 64 );
free(playTrisGameHistoryImage);
if ( playTrisEnterScrAnim )
free(playTrisPreviousScreen);
}

original_code:
void playTrisDestroy()
{
 int i;
 deleteGrid(playTrisGrid);
 deleteGameHistory(playTrisGameHistory);
 for(i = 0; i < 22; i++)
  free(playTrisGridImage[i]);
 free(playTrisGridImage);
 for(i = 0; i < 8; i++)
  free(playTrisGameHistoryImage[i]);
 free(playTrisGameHistoryImage);
 if(playTrisEnterScrAnim)
  free(playTrisPreviousScreen);
}


playTrisDraw

decompiled_code:
unsigned __int64 __fastcall playTrisDraw(char *a1)
{
char *v1; // rbp
int v2; // ebx
int v3; // ecx
int v4; // esi
__int64 v5; // rax
char *v6; // r13
int v7; // er12
int v8; // eax
int v9; // edx
int v10; // ecx
unsigned __int64 result; // rax
int v12; // er8
int v13; // esi
__int64 v14; // rdi
int v15; // esi
__int64 v16; // rax
char v17; // al
char v18; // al
char v19; // al
__int64 v20; // rdx
unsigned int v21; // er15
int v22; // [rsp+4h] [rbp-44h]
_BYTE *ptr; // [rsp+8h] [rbp-40h]

v1 = a1;
v2 = 18 * instructionPosition / 100;
printGrid(
playTrisGrid,
(unsigned int)playTrisLastCellSigned,
(unsigned int)(playTrisTotalTimeElapsed - playTrisTimeLastMovement),
(unsigned int)playTrisCurrentCellDrawTime,
playTrisGridImage);
printGameHistory(playTrisGameHistory, *(&playTrisGameHistory + 1), playTrisGameHistoryImage, 48LL, 8LL);
v3 = consoleBase;
v4 = consoleBase * consoleHigh;
if ( consoleBase * consoleHigh > 0 )
{
v5 = 0LL;
do
{
a1[v5] = 32;
v3 = consoleBase;
++v5;
v4 = consoleBase * consoleHigh;
}
while ( consoleBase * consoleHigh > (int)v5 );
if ( v4 > 0 )
{
v6 = a1;
v7 = 0;
do
{
v9 = v7 % v3;
v8 = v7 / v3;
if ( v7 % v3 > 78 || v8 > 23 )
goto LABEL_31;
if ( (unsigned int)(v9 - 1) <= 4 && v8 == 1 )
{
if ( playTrisCrossIntelligence )
v17 = AIString[v9 - 1];
else
v17 = humanString[v9 - 1];
*v6 = v17;
goto LABEL_22;
}
if ( (unsigned int)(v9 - 16) <= 4 && v8 == 1 )
{
if ( playTrisCircleIntelligence )
v18 = AIString[v9 - 16];
else
v18 = humanString[v9 - 16];
*v6 = v18;
goto LABEL_22;
}
if ( (unsigned int)(v8 - 2) <= 0x15 && v9 <= 21 )
{
*v6 = *(_BYTE *)(*((_QWORD *)playTrisGridImage + v8 - 2) + v9);
goto LABEL_22;
}
v10 = v9 - 57;
if ( (unsigned int)(v9 - 57) <= 5 && v8 <= 4 )
{
v20 = 7LL * v8;
if ( playTrisTurn )
v19 = imageCrossCell[v10 + v20];
else
v19 = imageCircleCell[v10 + v20];
goto LABEL_42;
}
if ( 24 - v2 <= v8 && v9 > 24 )
{
v19 = instructionImage[55 * v2 - 1345 + 55 * v8 + v9];
LABEL_42:
*v6 = v19;
goto LABEL_22;
}
if ( (unsigned int)(v8 - 7) <= 1 )
{
if ( (unsigned int)(v9 - 41) <= 3 )
{
v21 = playTrisCrossWinCounter;
if ( v8 != 7 )
v21 = playTrisCircleWinCounter;
v22 = countIntegerDigits(v21) - v9 + 40;
if ( v22 >= 0 )
{
ptr = malloc(4uLL);
integerToString(v21, ptr, 4LL);
*v6 = ptr[(int)(countIntegerDigits(v21) - 1 - v22)];
free(ptr);
goto LABEL_22;
}
LABEL_31:
*v6 = 32;
goto LABEL_22;
}
}
else if ( (unsigned int)(v8 - 12) <= 7 && (unsigned int)(v9 - 26) <= 0x2F )
{
*v6 = *(_BYTE *)(*((_QWORD *)playTrisGameHistoryImage + v8 - 12) + v9 - 26LL);
goto LABEL_22;
}
*v6 = playTrisBaseImage[80 * v8 + v9];
LABEL_22:
v3 = consoleBase;
++v7;
++v6;
v4 = consoleBase * consoleHigh;
}
while ( consoleBase * consoleHigh > v7 );
}
}
result = playTrisTotalTimeElapsed;
if ( (unsigned __int64)playTrisTotalTimeElapsed <= 0x18F )
{
result = 0xA3D70A3D70A3D71LL * ((unsigned __int64)(v3 * (400 - playTrisTotalTimeElapsed)) >> 4);
v12 = v3 * (400 - playTrisTotalTimeElapsed) / 0x190uLL;
v13 = v4 - 1;
if ( v13 >= 0 )
{
v14 = v13;
v15 = v13 - v3 * (400 - playTrisTotalTimeElapsed) / 0x190uLL;
while ( 1 )
{
if ( (int)v14 % v3 < v12 )
{
--v15;
result = *((unsigned __int8 *)playTrisPreviousScreen + (int)v14 + v3 - v12);
v1[v14--] = result;
if ( (int)v14 < 0 )
return result;
}
else
{
v16 = v15--;
result = (unsigned __int8)v1[v16];
v1[v14--] = result;
if ( (int)v14 < 0 )
return result;
}
v3 = consoleBase;
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char *a1)
{
char *v1; // rbp
int v2; // ebx
int v3; // ecx
int v4; // esi
__int64 v5; // rax
char *v6; // r13
int v7; // er12
int v8; // eax
int v9; // edx
int v10; // ecx
unsigned __int64 result; // rax
int v12; // er8
int v13; // esi
__int64 v14; // rdi
int v15; // esi
__int64 v16; // rax
char v17; // al
char v18; // al
char v19; // al
__int64 v20; // rdx
unsigned int v21; // er15
int v22; // [rsp+4h] [rbp-44h]
_BYTE *ptr; // [rsp+8h] [rbp-40h]

v1 = a1;
v2 = 18 * instructionPosition / 100;
printGrid(
playTrisGrid,
(unsigned int)playTrisLastCellSigned,
(unsigned int)(playTrisTotalTimeElapsed - playTrisTimeLastMovement),
(unsigned int)playTrisCurrentCellDrawTime,
playTrisGridImage);
printGameHistory(playTrisGameHistory, *(&playTrisGameHistory + 1), playTrisGameHistoryImage, 48LL, 8LL);
v3 = consoleBase;
v4 = consoleBase * consoleHigh;
if ( consoleBase * consoleHigh > 0 )
{
v5 = 0LL;
do
{
a1[v5] = 32;
v3 = consoleBase;
++v5;
v4 = consoleBase * consoleHigh;
}
while ( consoleBase * consoleHigh > (int)v5 );
if ( v4 > 0 )
{
v6 = a1;
v7 = 0;
do
{
v9 = v7 % v3;
v8 = v7 / v3;
if ( v7 % v3 > 78 || v8 > 23 )
goto LABEL_31;
if ( (unsigned int)(v9 - 1) <= 4 && v8 == 1 )
{
if ( playTrisCrossIntelligence )
v17 = AIString[v9 - 1];
else
v17 = humanString[v9 - 1];
*v6 = v17;
goto LABEL_22;
}
if ( (unsigned int)(v9 - 16) <= 4 && v8 == 1 )
{
if ( playTrisCircleIntelligence )
v18 = AIString[v9 - 16];
else
v18 = humanString[v9 - 16];
*v6 = v18;
goto LABEL_22;
}
if ( (unsigned int)(v8 - 2) <= 0x15 && v9 <= 21 )
{
*v6 = *(_BYTE *)(*((_QWORD *)playTrisGridImage + v8 - 2) + v9);
goto LABEL_22;
}
v10 = v9 - 57;
if ( (unsigned int)(v9 - 57) <= 5 && v8 <= 4 )
{
v20 = 7LL * v8;
if ( playTrisTurn )
v19 = imageCrossCell[v10 + v20];
else
v19 = imageCircleCell[v10 + v20];
goto LABEL_42;
}
if ( 24 - v2 <= v8 && v9 > 24 )
{
v19 = instructionImage[55 * v2 - 1345 + 55 * v8 + v9];
LABEL_42:
*v6 = v19;
goto LABEL_22;
}
if ( (unsigned int)(v8 - 7) <= 1 )
{
if ( (unsigned int)(v9 - 41) <= 3 )
{
v21 = playTrisCrossWinCounter;
if ( v8 != 7 )
v21 = playTrisCircleWinCounter;
v22 = countIntegerDigits(v21) - v9 + 40;
if ( v22 >= 0 )
{
ptr = malloc(4uLL);
integerToString(v21, ptr, 4LL);
*v6 = ptr[(int)(countIntegerDigits(v21) - 1 - v22)];
free(ptr);
goto LABEL_22;
}
LABEL_31:
*v6 = 32;
goto LABEL_22;
}
}
else if ( (unsigned int)(v8 - 12) <= 7 && (unsigned int)(v9 - 26) <= 0x2F )
{
*v6 = *(_BYTE *)(*((_QWORD *)playTrisGameHistoryImage + v8 - 12) + v9 - 26LL);
goto LABEL_22;
}
*v6 = playTrisBaseImage[80 * v8 + v9];
LABEL_22:
v3 = consoleBase;
++v7;
++v6;
v4 = consoleBase * consoleHigh;
}
while ( consoleBase * consoleHigh > v7 );
}
}
result = playTrisTotalTimeElapsed;
if ( (unsigned __int64)playTrisTotalTimeElapsed <= 0x18F )
{
result = 0xA3D70A3D70A3D71LL * ((unsigned __int64)(v3 * (400 - playTrisTotalTimeElapsed)) >> 4);
v12 = v3 * (400 - playTrisTotalTimeElapsed) / 0x190uLL;
v13 = v4 - 1;
if ( v13 >= 0 )
{
v14 = v13;
v15 = v13 - v3 * (400 - playTrisTotalTimeElapsed) / 0x190uLL;
while ( 1 )
{
if ( (int)v14 % v3 < v12 )
{
--v15;
result = *((unsigned __int8 *)playTrisPreviousScreen + (int)v14 + v3 - v12);
v1[v14--] = result;
if ( (int)v14 < 0 )
return result;
}
else
{
v16 = v15--;
result = (unsigned __int8)v1[v16];
v1[v14--] = result;
if ( (int)v14 < 0 )
return result;
}
v3 = consoleBase;
}
}
}
return result;
}

original_code:
void playTrisDraw(char *videoBuffer)
{
 int i, j;
 int instructionHigh = instructionPosition * 18 / 100;
 printGrid(playTrisGrid, playTrisLastCellSigned, playTrisTotalTimeElapsed - playTrisTimeLastMovement, playTrisCurrentCellDrawTime,
  playTrisGridImage);
 printGameHistory(playTrisGameHistory, playTrisGameHistoryImage, 48, 8);
 for(i = 0; i < consoleBase*consoleHigh; i++)
  videoBuffer[i] = ' ';
 for(i = 0; i < consoleBase*consoleHigh; i++)
 {
  int row = i / consoleBase,
   column = i % consoleBase;
  if(column < 79 && row < 24)
  {
   if(row == 1 && column >= 1 && column < 6)
   {
    if(playTrisCrossIntelligence == human)
     videoBuffer[i] = humanString[column - 1];
    else
     videoBuffer[i] = AIString[column - 1];
   }
   else if(row == 1 && column >= 16 && column < 21)
   {
    if(playTrisCircleIntelligence == human)
     videoBuffer[i] = humanString[column - 16];
    else
     videoBuffer[i] = AIString[column - 16];
   }
   else if(row >= 2 && row < 24 && column < 22)
    videoBuffer[i] = playTrisGridImage[row-2][column];
   else if(row < 5 && column >= 57 && column < 63)
    videoBuffer[i] = (playTrisTurn == circle ? imageCircleCell[row][column-57] : imageCrossCell[row][column-57]);
   else if(row >= 24 - instructionHigh && row < 24 && column >= 25 && column < 79)
   {
    videoBuffer[i] = instructionImage[row + instructionHigh - 24][column - 25];
   }
   else if(row >= 7 && row < 9 && column >= 41 && column < 45)
   {
    int score = (row == 7 ? playTrisCrossWinCounter : playTrisCircleWinCounter);
    int digitToFind = countIntegerDigits(score) - column + 40;
    if(digitToFind >= 0)
    {
     char *scoreStr = (char *)malloc(sizeof(char)*4);
     integerToString(score, scoreStr, 4);
     videoBuffer[i] = scoreStr[countIntegerDigits(score) - 1 - digitToFind];
     free(scoreStr);
    }
    else
     videoBuffer[i] = ' ';
   }
   else if(row >= 12 && row < 20 && column >= 26 && column < 74)
    videoBuffer[i] = playTrisGameHistoryImage[row-12][column-26];
   else if(row < 24 && column < 80)
    videoBuffer[i] = playTrisBaseImage[row][column];
  }
  else
   videoBuffer[i] = ' ';
 }
 if(playTrisTotalTimeElapsed < 400)
 {
  int shift = consoleBase * (400 - playTrisTotalTimeElapsed) / 400;
  for(i = consoleBase*consoleHigh - 1; i >= 0; i--)
   if(i%consoleBase < shift)
    videoBuffer[i] = playTrisPreviousScreen[i + consoleBase - shift];
   else
    videoBuffer[i] = videoBuffer[i - shift];
 }
}

canonical_original_code:
void playTrisDraw(char *videoBuffer)
{
 int i; int j;
 int instructionHigh = instructionPosition * 18 / 100;
 printGrid(playTrisGrid, playTrisLastCellSigned, playTrisTotalTimeElapsed - playTrisTimeLastMovement, playTrisCurrentCellDrawTime,
  playTrisGridImage);
 printGameHistory(playTrisGameHistory, playTrisGameHistoryImage, 48, 8);
 for(i = 0; i < consoleBase*consoleHigh; i++)
  videoBuffer[i] = ' ';
 for(i = 0; i < consoleBase*consoleHigh; i++)
 {
  int row = i / consoleBase; int column = i % consoleBase;
  if(column < 79 && row < 24)
  {
   if(row == 1 && column >= 1 && column < 6)
   {
    if(playTrisCrossIntelligence == human)
     videoBuffer[i] = humanString[column - 1];
    else
     videoBuffer[i] = AIString[column - 1];
   }
   else if(row == 1 && column >= 16 && column < 21)
   {
    if(playTrisCircleIntelligence == human)
     videoBuffer[i] = humanString[column - 16];
    else
     videoBuffer[i] = AIString[column - 16];
   }
   else if(row >= 2 && row < 24 && column < 22)
    videoBuffer[i] = playTrisGridImage[row-2][column];
   else if(row < 5 && column >= 57 && column < 63)
    videoBuffer[i] = (playTrisTurn == circle ? imageCircleCell[row][column-57] : imageCrossCell[row][column-57]);
   else if(row >= 24 - instructionHigh && row < 24 && column >= 25 && column < 79)
   {
    videoBuffer[i] = instructionImage[row + instructionHigh - 24][column - 25];
   }
   else if(row >= 7 && row < 9 && column >= 41 && column < 45)
   {
    int score = (row == 7 ? playTrisCrossWinCounter : playTrisCircleWinCounter);
    int digitToFind = countIntegerDigits(score) - column + 40;
    if(digitToFind >= 0)
    {
     char *scoreStr = (char *)malloc(sizeof(char)*4);
     integerToString(score, scoreStr, 4);
     videoBuffer[i] = scoreStr[countIntegerDigits(score) - 1 - digitToFind];
     free(scoreStr);
    }
    else
     videoBuffer[i] = ' ';
   }
   else if(row >= 12 && row < 20 && column >= 26 && column < 74)
    videoBuffer[i] = playTrisGameHistoryImage[row-12][column-26];
   else if(row < 24 && column < 80)
    videoBuffer[i] = playTrisBaseImage[row][column];
  }
  else
   videoBuffer[i] = ' ';
 }
 if(playTrisTotalTimeElapsed < 400)
 {
  int shift = consoleBase * (400 - playTrisTotalTimeElapsed) / 400;
  for(i = consoleBase*consoleHigh - 1; i >= 0; i--)
   if(i%consoleBase < shift)
    videoBuffer[i] = playTrisPreviousScreen[i + consoleBase - shift];
   else
    videoBuffer[i] = videoBuffer[i - shift];
 }
}

variable_types:
videoBuffer
char *

variable_types: j int

variable_types: instructionHigh int

variable_types: row int

variable_types: column int

variable_types: score int

variable_types: digitToFind int

variable_types:
scoreStr
char *

variable_types: shift int


humanTryToSetCell

decompiled_code:
__int64 __fastcall humanTryToSetCell(unsigned int a1)
{
int v1; // er8
__int64 result; // rax

v1 = getCell(playTrisGrid, a1);
result = 0LL;
if ( v1 == -1 )
{
setCell(playTrisGrid, a1, (unsigned int)playTrisTurn);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // er8
__int64 result; // rax

v1 = getCell(playTrisGrid, a1);
result = 0LL;
if ( v1 == -1 )
{
setCell(playTrisGrid, a1, (unsigned int)playTrisTurn);
result = 1LL;
}
return result;
}

original_code:
int humanTryToSetCell(enum Cell cell)
{
 if(getCell(playTrisGrid, cell) == noPlayer)
 {
  setCell(playTrisGrid, cell, playTrisTurn);
  return 1;
 }
 return 0;
}

variable_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 }


swapPlayers

decompiled_code:
__int64 swapPlayers()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
__int64 v4; // rsi

v0 = playTrisCircleWinCounter;
playTrisCircleWinCounter = playTrisCrossWinCounter;
playTrisCrossWinCounter = v0;
v1 = playTrisCircleIntelligence;
playTrisCircleIntelligence = playTrisCrossIntelligence;
playTrisCrossIntelligence = v1;
swapPlayersGameHistory(&playTrisGameHistory);
v2 = 0;
playTrisTurn = playTrisTurn == 0;
do
{
while ( 1 )
{
result = getCell(playTrisGrid, v2);
if ( (_DWORD)result == -1 )
goto LABEL_3;
if ( (_DWORD)result )
break;
result = setCell(playTrisGrid, v2, 1LL);
LABEL_3:
if ( ++v2 == 9 )
return result;
}
v4 = v2++;
result = setCell(playTrisGrid, v4, 0LL);
}
while ( v2 != 9 );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
__int64 v4; // rsi

v0 = playTrisCircleWinCounter;
playTrisCircleWinCounter = playTrisCrossWinCounter;
playTrisCrossWinCounter = v0;
v1 = playTrisCircleIntelligence;
playTrisCircleIntelligence = playTrisCrossIntelligence;
playTrisCrossIntelligence = v1;
swapPlayersGameHistory(&playTrisGameHistory);
v2 = 0;
playTrisTurn = playTrisTurn == 0;
do
{
while ( 1 )
{
result = getCell(playTrisGrid, v2);
if ( (_DWORD)result == -1 )
goto LABEL_3;
if ( (_DWORD)result )
break;
result = setCell(playTrisGrid, v2, 1LL);
LABEL_3:
if ( ++v2 == 9 )
return result;
}
v4 = v2++;
result = setCell(playTrisGrid, v4, 0LL);
}
while ( v2 != 9 );
return result;
}

original_code:
void swapPlayers()
{
 int i, scoreTemp;
 enum PlayerTypes intelligenceTemp;
 scoreTemp = playTrisCircleWinCounter;
 playTrisCircleWinCounter = playTrisCrossWinCounter;
 playTrisCrossWinCounter = scoreTemp;
 intelligenceTemp = playTrisCircleIntelligence;
 playTrisCircleIntelligence = playTrisCrossIntelligence;
 playTrisCrossIntelligence = intelligenceTemp;
 swapPlayersGameHistory(&playTrisGameHistory);
 if(playTrisTurn == circle)
  playTrisTurn = cross;
 else
  playTrisTurn = circle;
 for(i = 0; i < 9; i++)
 {
  CellState cellSt = getCell(playTrisGrid, (enum Cell)i);
  if(cellSt != noPlayer)
   if(cellSt == circle)
    setCell(playTrisGrid, (enum Cell)i, cross);
   else
    setCell(playTrisGrid, (enum Cell)i, circle);
 }
}

canonical_original_code:
void swapPlayers()
{
 int i; int scoreTemp;
 enum PlayerTypes intelligenceTemp;
 scoreTemp = playTrisCircleWinCounter;
 playTrisCircleWinCounter = playTrisCrossWinCounter;
 playTrisCrossWinCounter = scoreTemp;
 intelligenceTemp = playTrisCircleIntelligence;
 playTrisCircleIntelligence = playTrisCrossIntelligence;
 playTrisCrossIntelligence = intelligenceTemp;
 swapPlayersGameHistory(&playTrisGameHistory);
 if(playTrisTurn == circle)
  playTrisTurn = cross;
 else
  playTrisTurn = circle;
 for(i = 0; i < 9; i++)
 {
  enum Players cellSt = getCell(playTrisGrid, (enum Cell)i);
  if(cellSt != noPlayer)
   if(cellSt == circle)
    setCell(playTrisGrid, (enum Cell)i, cross);
   else
    setCell(playTrisGrid, (enum Cell)i, circle);
 }
}

variable_types: scoreTemp int

variable_types:
intelligenceTemp
enum PlayerTypes { human=0, AI=1 }

variable_types: enum Players { noPlayer=-1, circle=0, cross=1 }

user_defined_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 }


playTrisUpdate

decompiled_code:
__int64 __fastcall playTrisUpdate(int a1)
{
unsigned int v1; // ebp
__int64 result; // rax
int v3; // ebx
char v4; // r12
int v5; // [rsp+0h] [rbp-28h] BYREF
unsigned int v6; // [rsp+4h] [rbp-24h] BYREF
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

playTrisTotalTimeElapsed += a1;
if ( !(unsigned int)isKeyPressed() )
{
v1 = 0;
if ( playTrisEnterScrAnim && (unsigned __int64)playTrisTotalTimeElapsed <= 0x18F )
goto LABEL_8;
v7[0] = createGameResult();
LABEL_5:
if ( (unsigned int)won(playTrisGrid, v7) || (unsigned int)fullGrid(playTrisGrid) )
{
if ( (unsigned __int64)(playTrisTotalTimeElapsed - playTrisTimeLastMovement) > 0x3E7 )
{
addGameResult(&playTrisGameHistory, v7[0]);
getGameResultState(v7[0], &v5, &v6);
if ( v5 )
{
if ( v5 == 1 )
++playTrisCrossWinCounter;
}
else
{
++playTrisCircleWinCounter;
}
playTrisTimeLastMovement = playTrisTotalTimeElapsed;
deleteGrid(playTrisGrid);
playTrisGrid = createGrid();
}
goto LABEL_7;
}
if ( playTrisTurn )
{
if ( playTrisTurn == 1 && !playTrisCrossIntelligence )
{
LABEL_25:
if ( !(unsigned int)playerSelectedCell(v1, &v6) || !(unsigned int)humanTryToSetCell(v6) )
goto LABEL_7;
goto LABEL_27;
}
}
else if ( !playTrisCircleIntelligence )
{
goto LABEL_25;
}
if ( (unsigned __int64)(playTrisTotalTimeElapsed - playTrisTimeLastMovement) <= 0x3E7 )
goto LABEL_7;
nextMoveAI(playTrisGrid, (unsigned int)playTrisTurn, &v6);
setCell(playTrisGrid, v6, (unsigned int)playTrisTurn);
LABEL_27:
playTrisLastCellSigned = v6;
playTrisTurn = playTrisTurn == 0;
playTrisTimeLastMovement = playTrisTotalTimeElapsed;
playTrisCurrentCellDrawTime = rand() % 300 + 100;
LABEL_7:
deleteGameResult(v7[0]);
goto LABEL_8;
}
v4 = getChar();
flushInput();
if ( !playTrisEnterScrAnim || (unsigned __int64)playTrisTotalTimeElapsed > 0x18F )
{
v1 = v4;
v7[0] = createGameResult();
switch ( v4 )
{
case 'I':
case 'i':
showInstruction = showInstruction == 0;
goto LABEL_5;
case 'M':
case 'm':
result = 0xFFFFFFFFLL;
break;
case 'P':
case 'p':
swapPlayers();
goto LABEL_5;
default:
goto LABEL_5;
}
return result;
}
LABEL_8:
result = (unsigned int)showInstruction;
if ( showInstruction )
{
v3 = instructionPosition + a1 / 2;
if ( v3 > 100 )
{
instructionPosition = 100;
return 0LL;
}
LABEL_13:
instructionPosition = v3;
return 0LL;
}
v3 = instructionPosition - a1 / 2;
if ( v3 >= 0 )
goto LABEL_13;
instructionPosition = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
unsigned int v1; // ebp
__int64 result; // rax
int v3; // ebx
char v4; // r12
int v5; // [rsp+0h] [rbp-28h] BYREF
unsigned int v6; // [rsp+4h] [rbp-24h] BYREF
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

playTrisTotalTimeElapsed += a1;
if ( !(unsigned int)isKeyPressed() )
{
v1 = 0;
if ( playTrisEnterScrAnim && (unsigned __int64)playTrisTotalTimeElapsed <= 0x18F )
goto LABEL_8;
v7[0] = createGameResult();
LABEL_5:
if ( (unsigned int)won(playTrisGrid, v7) || (unsigned int)fullGrid(playTrisGrid) )
{
if ( (unsigned __int64)(playTrisTotalTimeElapsed - playTrisTimeLastMovement) > 0x3E7 )
{
addGameResult(&playTrisGameHistory, v7[0]);
getGameResultState(v7[0], &v5, &v6);
if ( v5 )
{
if ( v5 == 1 )
++playTrisCrossWinCounter;
}
else
{
++playTrisCircleWinCounter;
}
playTrisTimeLastMovement = playTrisTotalTimeElapsed;
deleteGrid(playTrisGrid);
playTrisGrid = createGrid();
}
goto LABEL_7;
}
if ( playTrisTurn )
{
if ( playTrisTurn == 1 && !playTrisCrossIntelligence )
{
LABEL_25:
if ( !(unsigned int)playerSelectedCell(v1, &v6) || !(unsigned int)func3(v6) )
goto LABEL_7;
goto LABEL_27;
}
}
else if ( !playTrisCircleIntelligence )
{
goto LABEL_25;
}
if ( (unsigned __int64)(playTrisTotalTimeElapsed - playTrisTimeLastMovement) <= 0x3E7 )
goto LABEL_7;
nextMoveAI(playTrisGrid, (unsigned int)playTrisTurn, &v6);
setCell(playTrisGrid, v6, (unsigned int)playTrisTurn);
LABEL_27:
playTrisLastCellSigned = v6;
playTrisTurn = playTrisTurn == 0;
playTrisTimeLastMovement = playTrisTotalTimeElapsed;
playTrisCurrentCellDrawTime = rand() % 300 + 100;
LABEL_7:
deleteGameResult(v7[0]);
goto LABEL_8;
}
v4 = getChar();
flushInput();
if ( !playTrisEnterScrAnim || (unsigned __int64)playTrisTotalTimeElapsed > 0x18F )
{
v1 = v4;
v7[0] = createGameResult();
switch ( v4 )
{
case 'I':
case 'i':
showInstruction = showInstruction == 0;
goto LABEL_5;
case 'M':
case 'm':
result = 0xFFFFFFFFLL;
break;
case 'P':
case 'p':
func4();
goto LABEL_5;
default:
goto LABEL_5;
}
return result;
}
LABEL_8:
result = (unsigned int)showInstruction;
if ( showInstruction )
{
v3 = instructionPosition + a1 / 2;
if ( v3 > 100 )
{
instructionPosition = 100;
return 0LL;
}
LABEL_13:
instructionPosition = v3;
return 0LL;
}
v3 = instructionPosition - a1 / 2;
if ( v3 >= 0 )
goto LABEL_13;
instructionPosition = 0;
return result;
}

original_code:
int playTrisUpdate(int deltaT)
{
 char key = '\0';
 int enteringAnim;
 playTrisTotalTimeElapsed += deltaT;
 if(isKeyPressed())
 {
  key = getChar();
  flushInput();
 }
 enteringAnim = playTrisEnterScrAnim && playTrisTotalTimeElapsed < 400;
 if(!enteringAnim)
 {
  struct GameResult gameResult = createGameResult();
  switch(key)
  {
  case 'i':
  case 'I':
   showInstruction = !showInstruction;
   break;
  case 'p':
  case 'P':
   swapPlayers();
   break;
  case 'm':
  case 'M':
   return -1;
  }
  if(won(playTrisGrid, &gameResult) || fullGrid(playTrisGrid))
  {
   if(playTrisTotalTimeElapsed - playTrisTimeLastMovement >= 1000)
   {
    enum Players winner;
    enum CellLine winningLine;
    addGameResult(&playTrisGameHistory, gameResult);
    getGameResultState(gameResult, &winner, &winningLine);
    if(winner == circle)
     playTrisCircleWinCounter++;
    if(winner == cross)
     playTrisCrossWinCounter++;
    playTrisTimeLastMovement = playTrisTotalTimeElapsed;
    deleteGrid(playTrisGrid);
    playTrisGrid = createGrid();
   }
  }
  else
  {
   int correctlyMoved = 0;
   enum Cell selectedCell;
   if((playTrisTurn == circle && playTrisCircleIntelligence == human) ||
    (playTrisTurn == cross && playTrisCrossIntelligence == human))
   {
    if(playerSelectedCell(key, &selectedCell))
     correctlyMoved = humanTryToSetCell(selectedCell);
   }
   else if(playTrisTotalTimeElapsed - playTrisTimeLastMovement >= 1000)
   {
    nextMoveAI(playTrisGrid, playTrisTurn, &selectedCell);
    setCell(playTrisGrid, selectedCell, playTrisTurn);
    correctlyMoved = 1;
   }
   if(correctlyMoved)
   {
    playTrisLastCellSigned = selectedCell;
    playTrisTurn = (playTrisTurn == circle ? cross : circle);
    playTrisTimeLastMovement = playTrisTotalTimeElapsed;
    playTrisCurrentCellDrawTime = (rand() % (400 - 100)) + 100;
   }
  }
  deleteGameResult(gameResult);
 }
 if(showInstruction)
 {
  instructionPosition += deltaT * 100 / 200;
  if(instructionPosition > 100)
   instructionPosition = 100;
 }
 else
 {
  instructionPosition -= deltaT * 100 / 200;
  if(instructionPosition < 0)
   instructionPosition = 0;
 }
 return 0;
}

variable_types: deltaT int

variable_types: key char

variable_types: enteringAnim int

variable_types: struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; }

variable_types: correctlyMoved int


checkWinPossibility

decompiled_code:
__int64 __fastcall checkWinPossibility(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int i; // ebx
__int64 v5; // r12
int v6; // er15

for ( i = 0; i != 9; ++i )
{
if ( (unsigned int)getCell(a1, i) == -1 )
{
v5 = copyGrid(a1);
setCell(v5, i, a2);
v6 = won(v5, 0LL);
deleteGrid(v5);
if ( v6 )
{
*a3 = i;
return 1LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int i; // ebx
__int64 v5; // r12
int v6; // er15

for ( i = 0; i != 9; ++i )
{
if ( (unsigned int)getCell(a1, i) == -1 )
{
v5 = copyGrid(a1);
setCell(v5, i, a2);
v6 = won(v5, 0LL);
deleteGrid(v5);
if ( v6 )
{
*a3 = i;
return 1LL;
}
}
}
return 0LL;
}

original_code:
int checkWinPossibility(Grid grid, enum Players sign, enum Cell *move)
{
 int i;
 for(i = 0; i < 9; i++)
  if(getCell(grid, (enum Cell)i) == noPlayer)
  {
   int win;
   Grid newGrid = copyGrid(grid);
   setCell(newGrid, (enum Cell)i, sign);
   win = won(newGrid, ((void *)0));
   deleteGrid(newGrid);
   if(win)
   {
    *move = (enum Cell)i;
    return 1;
   }
  }
 return 0;
}

canonical_original_code:
int checkWinPossibility(enum Players **grid, enum Players sign, enum Cell *move)
{
 int i;
 for(i = 0; i < 9; i++)
  if(getCell(grid, (enum Cell)i) == noPlayer)
  {
   int win;
   enum Players **newGrid = copyGrid(grid);
   setCell(newGrid, (enum Cell)i, sign);
   win = won(newGrid, ((void *)0));
   deleteGrid(newGrid);
   if(win)
   {
    *move = (enum Cell)i;
    return 1;
   }
  }
 return 0;
}

variable_types: enum Players { noPlayer=-1, circle=0, cross=1 } **

variable_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 } *

variable_types: i int

variable_types: win int


nextMoveAI

decompiled_code:
__int64 __fastcall nextMoveAI(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int v5; // er12
__int64 v6[15]; // [rsp+0h] [rbp-78h]

if ( (unsigned int)won(a1, 0LL) || (unsigned int)fullGrid(a1) )
return 0LL;
if ( !(unsigned int)checkWinPossibility(a1, a2, a3) && !(unsigned int)checkWinPossibility(a1, a2 == 0, a3) )
{
do
{
v6[0] = 0LL;
v6[5] = 0x600000005LL;
v6[6] = 0x700000006LL;
v6[1] = 0x200000001LL;
v6[2] = 0x300000002LL;
v6[3] = 0x400000004LL;
v6[4] = 0x400000004LL;
v6[7] = 0x800000008LL;
v5 = *((_DWORD *)v6 + rand() % 16);
}
while ( (unsigned int)getCell(a1, v5) != -1 );
*a3 = v5;
}
return 1LL;
}

original_code:
int nextMoveAI(Grid grid, enum Players AISign, enum Cell *move)
{
 if(won(grid, ((void *)0)) || fullGrid(grid))
  return 0;
 if(checkWinPossibility(grid, AISign, move) ||
  checkWinPossibility(grid, (AISign == circle ? cross : circle), move))
  return 1;
 while(1)
 {
  enum Cell redirect[] = {cellA1, cellA1,
        cellA2,
        cellA3, cellA3,
        cellB1,
        cellB2, cellB2, cellB2, cellB2,
        cellB3,
        cellC1, cellC1,
        cellC2,
        cellC3, cellC3};
  int index = rand()%16;
  if(getCell(grid, redirect[index]) == noPlayer)
  {
   *move = redirect[index];
   return 1;
  }
 }
}

canonical_original_code:
int nextMoveAI(enum Players **grid, enum Players AISign, enum Cell *move)
{
 if(won(grid, ((void *)0)) || fullGrid(grid))
  return 0;
 if(checkWinPossibility(grid, AISign, move) ||
  checkWinPossibility(grid, (AISign == circle ? cross : circle), move))
  return 1;
 while(1)
 {
  enum Cell redirect[] = {cellA1, cellA1,
        cellA2,
        cellA3, cellA3,
        cellB1,
        cellB2, cellB2, cellB2, cellB2,
        cellB3,
        cellC1, cellC1,
        cellC2,
        cellC3, cellC3};
  int index = rand()%16;
  if(getCell(grid, redirect[index]) == noPlayer)
  {
   *move = redirect[index];
   return 1;
  }
 }
}

variable_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 } []

variable_types: index int


isKeyPressed

decompiled_code:
__int64 isKeyPressed()
{
int v0; // edi
__int64 result; // rax

v0 = wgetch(stdscr);
result = 0LL;
if ( v0 != -1 )
{
ungetch(v0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edi
__int64 result; // rax

v0 = wgetch(stdscr);
result = 0LL;
if ( v0 != -1 )
{
ungetch(v0);
result = 1LL;
}
return result;
}

original_code:
int isKeyPressed()
{
 int ch = wgetch(stdscr);
    if (ch != (-1)) {
        ungetch(ch);
        return 1;
    } else {
        return 0;
    }
}

variable_types: ch int


getChar

decompiled_code:
int getChar()
{
return wgetch(stdscr);
}

canonical_decompiled_code:
int func1()
{
return wgetch(stdscr);
}

original_code:
char getChar()
{
 return wgetch(stdscr);
}

return_type: char


flushInput

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

while ( 1 )
{
result = isKeyPressed();
if ( !(_DWORD)result )
break;
getChar();
}
return result;
}

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

while ( 1 )
{
result = func0();
if ( !(_DWORD)result )
break;
func1();
}
return result;
}

original_code:
void flushInput()
{
 while(isKeyPressed())
  getChar();
}


playerSelectedCell

decompiled_code:
__int64 __fastcall playerSelectedCell(char a1, _DWORD *a2)
{
__int64 result; // rax

switch ( a1 )
{
case '1':
case 'Z':
case 'z':
*a2 = 6;
result = 1LL;
break;
case '2':
case 'X':
case 'x':
*a2 = 7;
result = 1LL;
break;
case '3':
case 'C':
case 'c':
*a2 = 8;
result = 1LL;
break;
case '4':
case 'A':
case 'a':
*a2 = 3;
result = 1LL;
break;
case '5':
case 'S':
case 's':
*a2 = 4;
result = 1LL;
break;
case '6':
case 'D':
case 'd':
*a2 = 5;
result = 1LL;
break;
case '7':
case 'Q':
case 'q':
*a2 = 0;
result = 1LL;
break;
case '8':
case 'W':
case 'w':
*a2 = 1;
result = 1LL;
break;
case '9':
case 'E':
case 'e':
*a2 = 2;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, _DWORD *a2)
{
__int64 result; // rax

switch ( a1 )
{
case '1':
case 'Z':
case 'z':
*a2 = 6;
result = 1LL;
break;
case '2':
case 'X':
case 'x':
*a2 = 7;
result = 1LL;
break;
case '3':
case 'C':
case 'c':
*a2 = 8;
result = 1LL;
break;
case '4':
case 'A':
case 'a':
*a2 = 3;
result = 1LL;
break;
case '5':
case 'S':
case 's':
*a2 = 4;
result = 1LL;
break;
case '6':
case 'D':
case 'd':
*a2 = 5;
result = 1LL;
break;
case '7':
case 'Q':
case 'q':
*a2 = 0;
result = 1LL;
break;
case '8':
case 'W':
case 'w':
*a2 = 1;
result = 1LL;
break;
case '9':
case 'E':
case 'e':
*a2 = 2;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int playerSelectedCell(char pressedKey, enum Cell *cell)
{
 switch(pressedKey)
 {
 case 'q': case 'Q': case '7':
  *cell = cellA1;
  return 1;
 case 'w': case 'W': case '8':
  *cell = cellA2;
  return 1;
 case 'e': case 'E': case '9':
  *cell = cellA3;
  return 1;
 case 'a': case 'A': case '4':
  *cell = cellB1;
  return 1;
 case 's': case 'S': case '5':
  *cell = cellB2;
  return 1;
 case 'd': case 'D': case '6':
  *cell = cellB3;
  return 1;
 case 'z': case 'Z': case '1':
  *cell = cellC1;
  return 1;
 case 'x': case 'X': case '2':
  *cell = cellC2;
  return 1;
 case 'c': case 'C': case '3':
  *cell = cellC3;
  return 1;
 }
 return 0;
}

variable_types: pressedKey char


decompiled_code:
void *__fastcall delete_book_file(char *s2, char *a2, void *ptr)
{
int v4; // eax
__int64 v5; // r12
char *v6; // rbp
void *result; // rax

v4 = strcmp(s2, (const char *)ptr);
v5 = *(_QWORD *)((char *)ptr + 90);
if ( !v4 && !strcmp(a2, (const char *)ptr + 30) )
{
puts("\nSuccess! There's the book that you delete");
free(ptr);
result = (void *)v5;
}
else
{
v6 = (char *)ptr;
if ( v5 )
{
while ( strcmp((const char *)v5, s2) || strcmp((const char *)(v5 + 30), a2) )
{
v6 = (char *)v5;
if ( !*(_QWORD *)(v5 + 90) )
goto LABEL_9;
v5 = *(_QWORD *)(v5 + 90);
}
*(_QWORD *)(v6 + 90) = *(_QWORD *)(v5 + 90);
puts("\nSuccess! There's the book that you delete");
free(*(void **)((char *)ptr + 90));
result = ptr;
}
else
{
LABEL_9:
puts("\nSorry, There's no the book that you delete");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(char *s2, char *a2, void *ptr)
{
int v4; // eax
__int64 v5; // r12
char *v6; // rbp
void *result; // rax

v4 = strcmp(s2, (const char *)ptr);
v5 = *(_QWORD *)((char *)ptr + 90);
if ( !v4 && !strcmp(a2, (const char *)ptr + 30) )
{
puts("\nSuccess! There's the book that you delete");
free(ptr);
result = (void *)v5;
}
else
{
v6 = (char *)ptr;
if ( v5 )
{
while ( strcmp((const char *)v5, s2) || strcmp((const char *)(v5 + 30), a2) )
{
v6 = (char *)v5;
if ( !*(_QWORD *)(v5 + 90) )
goto LABEL_9;
v5 = *(_QWORD *)(v5 + 90);
}
*(_QWORD *)(v6 + 90) = *(_QWORD *)(v5 + 90);
puts("\nSuccess! There's the book that you delete");
free(*(void **)((char *)ptr + 90));
result = ptr;
}
else
{
LABEL_9:
puts("\nSorry, There's no the book that you delete");
result = 0LL;
}
}
return result;
}

original_code:
BOOK_NODE* delete_book_file(char* a, char* b, BOOK_NODE *list){
 BOOK_NODE *Temp;
 if(strcmp(a, list -> book) == 0 && strcmp(b, list -> author) == 0){
  Temp = list;
  list = list -> next;
  printf("\nSuccess! There's the book that you delete\n");
  free (Temp);
  return list;
 }else{
  BOOK_NODE* Current = list;
  Temp = list;
  while (Current -> next != ((void *)0) && (strcmp(Current -> next -> book, a) != 0|| strcmp(Current -> next -> author, b) != 0)){
   Current = Current-> next;
  }
  if(Current -> next != ((void *)0)){
   Current -> next = Current -> next -> next;
   printf("\nSuccess! There's the book that you delete\n");
   free (Temp -> next);
   return list;
  }
 }
 printf("\nSorry, There's no the book that you delete\n");
 return 0;
}

canonical_original_code:
struct booktype_node *delete_book_file(char *a, char *b, struct booktype_node *list){
 struct booktype_node *Temp;
 if(strcmp(a, list -> book) == 0 && strcmp(b, list -> author) == 0){
  Temp = list;
  list = list -> next;
  printf("\nSuccess! There's the book that you delete\n");
  free (Temp);
  return list;
 }else{
  struct booktype_node *Current = list;
  Temp = list;
  while (Current -> next != ((void *)0) && (strcmp(Current -> next -> book, a) != 0|| strcmp(Current -> next -> author, b) != 0)){
   Current = Current-> next;
  }
  if(Current -> next != ((void *)0)){
   Current -> next = Current -> next -> next;
   printf("\nSuccess! There's the book that you delete\n");
   free (Temp -> next);
   return list;
  }
 }
 printf("\nSorry, There's no the book that you delete\n");
 return 0;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
list
struct booktype_node *

variable_types: struct booktype_node { char book[30]; char author[15]; char publisher[15]; char price[15]; char year[15]; struct booktype_node *next; } *


Find

decompiled_code:
char *__fastcall Find(char *s1, char *a2, char *s2)
{
int v4; // ebp

putchar(10);
while ( 1 )
{
v4 = strcmp(s1, s2);
if ( !v4 && !strcmp(a2, s2 + 30) )
break;
if ( !*(_QWORD *)(s2 + 90) )
{
if ( v4 || strcmp(a2, s2 + 30) )
{
puts("\nSorry, There's no the book that you find");
return 0LL;
}
break;
}
puts("plese wait...");
s2 = *(char **)(s2 + 90);
}
puts("\nSuccess! There's the book that you find");
return s2;
}

canonical_decompiled_code:
char *__fastcall func1(char *s1, char *a2, char *s2)
{
int v4; // ebp

putchar(10);
while ( 1 )
{
v4 = strcmp(s1, s2);
if ( !v4 && !strcmp(a2, s2 + 30) )
break;
if ( !*(_QWORD *)(s2 + 90) )
{
if ( v4 || strcmp(a2, s2 + 30) )
{
puts("\nSorry, There's no the book that you find");
return 0LL;
}
break;
}
puts("plese wait...");
s2 = *(char **)(s2 + 90);
}
puts("\nSuccess! There's the book that you find");
return s2;
}

original_code:
BOOK_NODE* Find(char* t, char* t2, BOOK_NODE *list){
 printf("\n");
 while((strcmp(t, list -> book) != 0 || strcmp(t2, list -> author) != 0) && list -> next != 0){
  printf("plese wait...\n");
  list = list -> next;
 }
 if(strcmp(t, list -> book) == 0 && strcmp(t2, list -> author) == 0){
  printf("\nSuccess! There's the book that you find\n");
  return (list);
 } else {
  printf("\nSorry, There's no the book that you find\n");
  return 0;
 }
}

canonical_original_code:
struct booktype_node *Find(char *t, char *t2, struct booktype_node *list){
 printf("\n");
 while((strcmp(t, list -> book) != 0 || strcmp(t2, list -> author) != 0) && list -> next != 0){
  printf("plese wait...\n");
  list = list -> next;
 }
 if(strcmp(t, list -> book) == 0 && strcmp(t2, list -> author) == 0){
  printf("\nSuccess! There's the book that you find\n");
  return (list);
 } else {
  printf("\nSorry, There's no the book that you find\n");
  return 0;
 }
}

variable_types:
t
char *

return_type: struct booktype_node { char book[30]; char author[15]; char publisher[15]; char price[15]; char year[15]; struct booktype_node *next; } *


insert

original_code:
BOOK_NODE *insert(BOOK_NODE *book_st, BOOK_NODE *list)
{
    BOOK_NODE *current = ((void *)0);
    BOOK_NODE *follow = ((void *)0);
    BOOK_NODE *newnode = ((void *)0);
    current = list;
    follow = list;
    newnode = (BOOK_NODE *)malloc(sizeof(BOOK_NODE));
    if(newnode == ((void *)0))
    {
        printf("Failed to allocate memory.\n");
        return list;
    }
    *newnode = *book_st;
    while((current != ((void *)0)) && strcmp(current -> book, book_st -> book) < 0)
    {
        follow = current;
        current = current -> next;
    }
    newnode -> next = current;
    if(current == list)
    {
        list = newnode;
    }
    else
    {
        follow -> next = newnode;
    }
    return list;
}

canonical_original_code:
struct booktype_node *insert(struct booktype_node *book_st, struct booktype_node *list)
{
    struct booktype_node *current = ((void *)0);
    struct booktype_node *follow = ((void *)0);
    struct booktype_node *newnode = ((void *)0);
    current = list;
    follow = list;
    newnode = (struct booktype_node *)malloc(sizeof(BOOK_NODE));
    if(newnode == ((void *)0))
    {
        printf("Failed to allocate memory.\n");
        return list;
    }
    *newnode = *book_st;
    while((current != ((void *)0)) && strcmp(current -> book, book_st -> book) < 0)
    {
        follow = current;
        current = current -> next;
    }
    newnode -> next = current;
    if(current == list)
    {
        list = newnode;
    }
    else
    {
        follow -> next = newnode;
    }
    return list;
}

user_defined_types: struct booktype_node { char book[30]; char author[15]; char publisher[15]; char price[15]; char year[15]; struct booktype_node *next; }


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 90);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 90);
return result;
}

original_code:
unsigned int counting_links(BOOK_NODE *books)
{
    int ui_counter = 0;
    while(1)
    {
        if(books == ((void *)0))
        {
            break;
        }
        else
        {
            ui_counter = ui_counter + 1;
            books = books -> next;
        }
    }
    return ui_counter;
}

canonical_original_code:
unsigned int counting_links(struct booktype_node *books)
{
    int ui_counter = 0;
    while(1)
    {
        if(books == ((void *)0))
        {
            break;
        }
        else
        {
            ui_counter = ui_counter + 1;
            books = books -> next;
        }
    }
    return ui_counter;
}

return_type: unsigned int


decompiled_code:
void __fastcall print_links(__int64 a1)
{
unsigned int v1; // ebx
int v2; // edx
const char *v3; // r15
const char *v4; // r14
const char *v5; // r13
const char *v6; // r12
const char *v7; // rbp
const char *v8; // rax
unsigned int v9; // eax
int v10; // [rsp+Ch] [rbp-4Ch]
__int64 v11; // [rsp+10h] [rbp-48h]

if ( a1 )
{
v1 = 1;
puts("================= Book List =================");
v2 = 0;
v11 = a1;
v3 = (const char *)a1;
v4 = (const char *)(a1 + 30);
v5 = (const char *)(a1 + 45);
v6 = (const char *)(a1 + 60);
v7 = (const char *)(a1 + 75);
while ( 1 )
{
while ( 1 )
{
v10 = v2;
putchar(10);
printf("#%d\n", v1);
printf("Book : %s\n", v3);
printf("Author : %15s | ", v4);
printf("Publisher : %15s\n", v5);
printf("Price : %15s | ", v6);
printf("Year : %15s\n", v7);
if ( v10 == 4 )
break;
v8 = *(const char **)(v11 + 90);
if ( !v8 )
break;
v11 = *(_QWORD *)(v11 + 90);
++v1;
v2 = v10 + 1;
v3 = v8;
v4 = v8 + 30;
v5 = v8 + 45;
v6 = v8 + 60;
v7 = v8 + 75;
}
v9 = counting_links(a1);
printf("(p)revious, (Enter Key) for next page, (q)uit :: %d / %d > ", v1, v9);
if ( (unsigned __int8)getchar() == 113 )
break;
v2 = 0;
}
_fpurge(stdin);
}
else
{
puts("\nThere is no book to show in book list.");
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
unsigned int v1; // ebx
int v2; // edx
const char *v3; // r15
const char *v4; // r14
const char *v5; // r13
const char *v6; // r12
const char *v7; // rbp
const char *v8; // rax
unsigned int v9; // eax
int v10; // [rsp+Ch] [rbp-4Ch]
__int64 v11; // [rsp+10h] [rbp-48h]

if ( a1 )
{
v1 = 1;
puts("================= Book List =================");
v2 = 0;
v11 = a1;
v3 = (const char *)a1;
v4 = (const char *)(a1 + 30);
v5 = (const char *)(a1 + 45);
v6 = (const char *)(a1 + 60);
v7 = (const char *)(a1 + 75);
while ( 1 )
{
while ( 1 )
{
v10 = v2;
putchar(10);
printf("#%d\n", v1);
printf("Book : %s\n", v3);
printf("Author : %15s | ", v4);
printf("Publisher : %15s\n", v5);
printf("Price : %15s | ", v6);
printf("Year : %15s\n", v7);
if ( v10 == 4 )
break;
v8 = *(const char **)(v11 + 90);
if ( !v8 )
break;
v11 = *(_QWORD *)(v11 + 90);
++v1;
v2 = v10 + 1;
v3 = v8;
v4 = v8 + 30;
v5 = v8 + 45;
v6 = v8 + 60;
v7 = v8 + 75;
}
v9 = func3(a1);
printf("(p)revious, (Enter Key) for next page, (q)uit :: %d / %d > ", v1, v9);
if ( (unsigned __int8)getchar() == 113 )
break;
v2 = 0;
}
_fpurge(stdin);
}
else
{
puts("\nThere is no book to show in book list.");
}
}

original_code:
void *print_links(BOOK_NODE *linked_list)
{
    BOOK_NODE *temp;
    int i_cnt = 0;
    int i_book_number = 1;
    char c_cmd = 0;
    temp = linked_list;
    if(temp == ((void *)0))
    {
        printf("\nThere is no book to show in book list.\n");
        return;
    }
    printf("================= Book List =================\n");
    while('q' != c_cmd)
    {
        while(1)
        {
            putchar('\n');
            printf("#%d\n", i_book_number);
            printf("Book      : %s\n", temp -> book);
            printf("Author    : %15s | ", temp -> author);
            printf("Publisher : %15s\n", temp -> publisher);
            printf("Price     : %15s | ", temp -> price);
            printf("Year      : %15s\n", temp -> year);
            if((i_cnt == 4) || (temp -> next == ((void *)0)))
            {
                i_cnt = 0;
                break;
            }
            temp = temp -> next;
            ++i_book_number;
            ++i_cnt;
        }
        printf("(p)revious, (Enter Key) for next page, (q)uit :: %d / %d > ", i_book_number, counting_links(linked_list));
        c_cmd = getchar();
    }
    __fpurge(stdin);
    return;
}

canonical_original_code:
void *print_links(struct booktype_node *linked_list)
{
    struct booktype_node *temp;
    int i_cnt = 0;
    int i_book_number = 1;
    char c_cmd = 0;
    temp = linked_list;
    if(temp == ((void *)0))
    {
        printf("\nThere is no book to show in book list.\n");
        return;
    }
    printf("================= Book List =================\n");
    while('q' != c_cmd)
    {
        while(1)
        {
            putchar('\n');
            printf("#%d\n", i_book_number);
            printf("Book      : %s\n", temp -> book);
            printf("Author    : %15s | ", temp -> author);
            printf("Publisher : %15s\n", temp -> publisher);
            printf("Price     : %15s | ", temp -> price);
            printf("Year      : %15s\n", temp -> year);
            if((i_cnt == 4) || (temp -> next == ((void *)0)))
            {
                i_cnt = 0;
                break;
            }
            temp = temp -> next;
            ++i_book_number;
            ++i_cnt;
        }
        printf("(p)revious, (Enter Key) for next page, (q)uit :: %d / %d > ", i_book_number, counting_links(linked_list));
        c_cmd = getchar();
    }
    __fpurge(stdin);
    return;
}

return_type: void *


decompiled_code:
int __fastcall INIT_writing_header(int a1)
{
int v1; // eax
int v2; // ebp
int v4; // [rsp+0h] [rbp-38h] BYREF
__m128i v5; // [rsp+4h] [rbp-34h]
__int64 v6[4]; // [rsp+14h] [rbp-24h] BYREF

qmemcpy(v6, "**************", 14);
v4 = a1;
v5 = _mm_load_si128((const __m128i *)&LC2);
v1 = open("book.dbf", 578, 384LL);
if ( v1 < 0 )
{
puts("Failed to open the file for writing.");
exit(-1);
}
v2 = v1;
write(v1, &v4, 0x22uLL);
return close(v2);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int v1; // eax
int v2; // ebp
int v4; // [rsp+0h] [rbp-38h] BYREF
__m128i v5; // [rsp+4h] [rbp-34h]
__int64 v6[4]; // [rsp+14h] [rbp-24h] BYREF

qmemcpy(v6, "**************", 14);
v4 = a1;
v5 = _mm_load_si128((const __m128i *)&LC2);
v1 = open("book.dbf", 578, 384LL);
if ( v1 < 0 )
{
puts("Failed to open the file for writing.");
exit(-1);
}
v2 = v1;
write(v1, &v4, 0x22uLL);
return close(v2);
}

original_code:
void INIT_writing_header(unsigned int amount_of_books)
{
    DBF_HEADER header = {0, "******************************"};
    header.amount_of_book = amount_of_books;
    int outfd;
    outfd = open("book.dbf", 0100 | 01000 | 02, 0400 | 0200);
    if(outfd < 0)
    {
        printf("Failed to open the file for writing.\n");
        exit(-1);
    }
    write(outfd, &header, sizeof(header));
    close(outfd);
}

canonical_original_code:
void INIT_writing_header(unsigned int amount_of_books)
{
    struct dbf_header header = {0, "******************************"};
    header.amount_of_book = amount_of_books;
    int outfd;
    outfd = open("book.dbf", 0100 | 01000 | 02, 0400 | 0200);
    if(outfd < 0)
    {
        printf("Failed to open the file for writing.\n");
        exit(-1);
    }
    write(outfd, &header, sizeof(header));
    close(outfd);
}

variable_types: struct dbf_header { unsigned int amount_of_book; char magic_number[30]; }

variable_types: outfd int


decompiled_code:
int __fastcall writing_data_file(void *buf)
{
int v2; // eax
int v3; // eax
int v4; // ebp
char v6; // [rsp+Fh] [rbp-49h] BYREF
char bufa[72]; // [rsp+10h] [rbp-48h] BYREF

v6 = 124;
v2 = counting_links();
INIT_writing_header(v2);
v3 = open("book.dbf", 2);
if ( v3 < 0 )
{
perror("Sorry, failed to open the file.");
exit(-1);
}
v4 = v3;
read(v3, bufa, 0x22uLL);
do
{
write(v4, buf, 0x62uLL);
lseek(v4, 0xFFFFFFFFLL, 1);
write(v4, &v6, 1uLL);
buf = *(void **)((char *)buf + 90);
}
while ( buf );
return close(v4);
}

canonical_decompiled_code:
int __fastcall func1(void *buf)
{
int v2; // eax
int v3; // eax
int v4; // ebp
char v6; // [rsp+Fh] [rbp-49h] BYREF
char bufa[72]; // [rsp+10h] [rbp-48h] BYREF

v6 = 124;
v2 = counting_links();
func0(v2);
v3 = open("book.dbf", 2);
if ( v3 < 0 )
{
perror("Sorry, failed to open the file.");
exit(-1);
}
v4 = v3;
read(v3, bufa, 0x22uLL);
do
{
write(v4, buf, 0x62uLL);
lseek(v4, 0xFFFFFFFFLL, 1);
write(v4, &v6, 1uLL);
buf = *(void **)((char *)buf + 90);
}
while ( buf );
return close(v4);
}

original_code:
void writing_data_file(BOOK_NODE *books)
{
    DBF_HEADER header;
    char turple = '|';
    int infd;
    char buffer[35];
    header.amount_of_book = counting_links(books);
    INIT_writing_header(header.amount_of_book);
    infd = open("book.dbf", 02);
    if(infd < 0)
    {
        perror("Sorry, failed to open the file.");
        exit(-1);
    }
    read(infd, buffer, 34);
    while(1)
    {
        write(infd, books, (sizeof(BOOK_NODE)));
        lseek(infd, -1, 1);
        write(infd, &turple, 1);
        if(books -> next == ((void *)0))
        {
            break;
        }
        else
        {
            books = books -> next;
        }
    }
    close(infd);
}

canonical_original_code:
void writing_data_file(struct booktype_node *books)
{
    struct dbf_header header;
    char turple = '|';
    int infd;
    char buffer[35];
    header.amount_of_book = counting_links(books);
    INIT_writing_header(header.amount_of_book);
    infd = open("book.dbf", 02);
    if(infd < 0)
    {
        perror("Sorry, failed to open the file.");
        exit(-1);
    }
    read(infd, buffer, 34);
    while(1)
    {
        write(infd, books, (sizeof(BOOK_NODE)));
        lseek(infd, -1, 1);
        write(infd, &turple, 1);
        if(books -> next == ((void *)0))
        {
            break;
        }
        else
        {
            books = books -> next;
        }
    }
    close(infd);
}

variable_types: turple char

variable_types: infd int

variable_types:
buffer
char [35]

user_defined_types: struct dbf_header { unsigned int amount_of_book; char magic_number[30]; }


decompiled_code:
__int64 __fastcall checking_header(int *a1)
{
int v1; // eax
unsigned int v2; // ebx
bool v3; // zf
__int64 result; // rax
__m128i v5; // [rsp+0h] [rbp-88h] BYREF
char v6[16]; // [rsp+10h] [rbp-78h] BYREF
unsigned int buf; // [rsp+20h] [rbp-68h] BYREF
char src[44]; // [rsp+24h] [rbp-64h] BYREF
char dest[56]; // [rsp+50h] [rbp-38h] BYREF

strcpy(v6, "**************");
v5 = _mm_load_si128((const __m128i *)&LC2);
v1 = open("book.dbf", 2);
*a1 = v1;
read(v1, &buf, 0x22uLL);
v2 = buf;
strcpy(dest, src);
dest[30] = 0;
v3 = strcmp(dest, v5.m128i_i8) == 0;
result = 0xFFFFFFFFLL;
if ( v3 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1)
{
int v1; // eax
unsigned int v2; // ebx
bool v3; // zf
__int64 result; // rax
__m128i v5; // [rsp+0h] [rbp-88h] BYREF
char v6[16]; // [rsp+10h] [rbp-78h] BYREF
unsigned int buf; // [rsp+20h] [rbp-68h] BYREF
char src[44]; // [rsp+24h] [rbp-64h] BYREF
char dest[56]; // [rsp+50h] [rbp-38h] BYREF

strcpy(v6, "**************");
v5 = _mm_load_si128((const __m128i *)&LC2);
v1 = open("book.dbf", 2);
*a1 = v1;
read(v1, &buf, 0x22uLL);
v2 = buf;
strcpy(dest, src);
dest[30] = 0;
v3 = strcmp(dest, v5.m128i_i8) == 0;
result = 0xFFFFFFFFLL;
if ( v3 )
result = v2;
return result;
}

original_code:
int checking_header(int *infd)
{
    DBF_HEADER header_temp;
    unsigned int amountBooks = 0;
    char magic_key_from_file[35];
    char buffer[31] = {"******************************"};
    *infd = open("book.dbf", 02);
    if(infd < 0)
    {
        perror("Failed to open the file :: ");
       return;
    }
    read(*infd, &header_temp, sizeof(DBF_HEADER));
    amountBooks = header_temp.amount_of_book;
    strcpy(magic_key_from_file, header_temp.magic_number);
    magic_key_from_file[30] = '\0';
    if(0 == strcmp(magic_key_from_file, buffer))
    {
        return amountBooks;
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int checking_header(int *infd)
{
    struct dbf_header header_temp;
    unsigned int amountBooks = 0;
    char magic_key_from_file[35];
    char buffer[31] = {"******************************"};
    *infd = open("book.dbf", 02);
    if(infd < 0)
    {
        perror("Failed to open the file :: ");
       return;
    }
    read(*infd, &header_temp, sizeof(DBF_HEADER));
    amountBooks = header_temp.amount_of_book;
    strcpy(magic_key_from_file, header_temp.magic_number);
    magic_key_from_file[30] = '\0';
    if(0 == strcmp(magic_key_from_file, buffer))
    {
        return amountBooks;
    }
    else
    {
        return -1;
    }
}

variable_types:
infd
int *

variable_types:
amountBooks
unsigned int

variable_types:
buffer
char [31]


decompiled_code:
__int64 __fastcall loading_data_file(__int64 a1)
{
__int64 v1; // rbp
int v2; // er12
int i; // ebx
__int64 result; // rax
int fd; // [rsp+Ch] [rbp-8Ch] BYREF
char buf[136]; // [rsp+10h] [rbp-88h] BYREF

v1 = a1;
fd = open("book.dbf", 2);
if ( fd == -1 )
{
puts("There is no data file, \"book.dbf\" or failed to open the file.");
close(-1);
result = a1;
}
else
{
v2 = checking_header(&fd);
if ( v2 < 0 )
{
puts("The data file might be broken. Please check the file. ");
result = a1;
}
else
{
lseek(fd, 34LL, 0);
if ( v2 )
{
for ( i = 1; i <= v2; ++i )
{
read(fd, buf, 0x62uLL);
v1 = insert(buf, v1);
}
}
result = v1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
int v2; // er12
int i; // ebx
__int64 result; // rax
int fd; // [rsp+Ch] [rbp-8Ch] BYREF
char buf[136]; // [rsp+10h] [rbp-88h] BYREF

v1 = a1;
fd = open("book.dbf", 2);
if ( fd == -1 )
{
puts("There is no data file, \"book.dbf\" or failed to open the file.");
close(-1);
result = a1;
}
else
{
v2 = func2(&fd);
if ( v2 < 0 )
{
puts("The data file might be broken. Please check the file. ");
result = a1;
}
else
{
lseek(fd, 34LL, 0);
if ( v2 )
{
for ( i = 1; i <= v2; ++i )
{
read(fd, buf, 0x62uLL);
v1 = insert(buf, v1);
}
}
result = v1;
}
}
return result;
}

original_code:
BOOK_NODE *loading_data_file(BOOK_NODE *data)
{
    BOOK_NODE temp;
    BOOK_NODE *temp_return = data;
    int amount_books;
    int infd;
    int i_counter;
    infd = open("book.dbf", 02);
    if(infd == -1)
    {
        printf("There is no data file, \"book.dbf\" or failed to open the file.\n");
        close(infd);
        return temp_return;
    }
    amount_books = checking_header(&infd);
    if(amount_books < 0)
    {
        printf("The data file might be broken. Please check the file. \n");
        return temp_return;
    }
    else
    {
        lseek(infd, 1 * sizeof(DBF_HEADER), 0);
        for(i_counter = 1; amount_books >= i_counter; ++i_counter)
        {
            read(infd, &temp, sizeof(BOOK_NODE));
            temp_return = insert(&temp, temp_return);
        }
    }
    return temp_return;
}

canonical_original_code:
struct booktype_node *loading_data_file(struct booktype_node *data)
{
    struct booktype_node temp;
    struct booktype_node *temp_return = data;
    int amount_books;
    int infd;
    int i_counter;
    infd = open("book.dbf", 02);
    if(infd == -1)
    {
        printf("There is no data file, \"book.dbf\" or failed to open the file.\n");
        close(infd);
        return temp_return;
    }
    amount_books = checking_header(&infd);
    if(amount_books < 0)
    {
        printf("The data file might be broken. Please check the file. \n");
        return temp_return;
    }
    else
    {
        lseek(infd, 1 * sizeof(DBF_HEADER), 0);
        for(i_counter = 1; amount_books >= i_counter; ++i_counter)
        {
            read(infd, &temp, sizeof(BOOK_NODE));
            temp_return = insert(&temp, temp_return);
        }
    }
    return temp_return;
}

variable_types:
data
struct booktype_node *

variable_types: struct booktype_node { char book[30]; char author[15]; char publisher[15]; char price[15]; char year[15]; struct booktype_node *next; }


main

canonical_name: main

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

original_code:
int main()
{
    menu_print();
    return 0;
}

canonical_original_code:
int main()
{
    menu_print();
    return 0;
}


decompiled_code:
__int64 print_list_books()
{
return print_links(main_list);
}

canonical_decompiled_code:
__int64 func0()
{
return print_links(main_list);
}

original_code:
void print_list_books()
{
    print_links(main_list);
    return;
}


decompiled_code:
size_t __fastcall inputing_data_except_null(char *s, int a2)
{
size_t result; // rax

fgets(s, a2, stdin);
_fpurge(stdin);
result = strlen(s);
s[result - 1] = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(char *s, int a2)
{
size_t result; // rax

fgets(s, a2, stdin);
_fpurge(stdin);
result = strlen(s);
s[result - 1] = 0;
return result;
}

original_code:
void inputing_data_except_null(char *data, int length)
{
    fgets(data, length, stdin);
    __fpurge(stdin);
    *(data + strlen(data) - 1) = 0;
}

variable_types:
data
char *

variable_types: length int


decompiled_code:
__int64 insert_book()
{
char v1[96]; // [rsp+0h] [rbp-78h] BYREF
__int16 v2; // [rsp+60h] [rbp-18h]

memset(v1, 0, sizeof(v1));
v2 = 0;
printf("Enter the book's title : ");
inputing_data_except_null(v1, 30);
printf("Enter the author's name : ");
inputing_data_except_null(&v1[30], 15);
printf("Enter the publisher's name : ");
inputing_data_except_null(&v1[45], 15);
printf("Enter the price of the book : ");
inputing_data_except_null(&v1[60], 15);
printf("Enter the year of publishing : ");
inputing_data_except_null(&v1[75], 15);
main_list = insert(v1, main_list);
return writing_data_file(main_list);
}

canonical_decompiled_code:
__int64 func2()
{
char v1[96]; // [rsp+0h] [rbp-78h] BYREF
__int16 v2; // [rsp+60h] [rbp-18h]

memset(v1, 0, sizeof(v1));
v2 = 0;
printf("Enter the book's title : ");
func1(v1, 30);
printf("Enter the author's name : ");
func1(&v1[30], 15);
printf("Enter the publisher's name : ");
func1(&v1[45], 15);
printf("Enter the price of the book : ");
func1(&v1[60], 15);
printf("Enter the year of publishing : ");
func1(&v1[75], 15);
main_list = insert(v1, main_list);
return writing_data_file(main_list);
}

original_code:
void insert_book()
{
    BOOK_NODE books = {0, 0, 0, 0, 0, 0};
    printf("Enter the book's title : ");
    inputing_data_except_null(books.book, sizeof(books.book));
    printf("Enter the author's name : ");
    inputing_data_except_null(books.author, sizeof(books.author));
    printf("Enter the publisher's name : ");
    inputing_data_except_null(books.publisher, sizeof(books.publisher));
    printf("Enter the price of the book : ");
    inputing_data_except_null(books.price, sizeof(books.price));
    printf("Enter the year of publishing : ");
    inputing_data_except_null(books.year, sizeof(books.year));
    main_list = insert(&books, main_list);
    writing_data_file(main_list);
}

canonical_original_code:
void insert_book()
{
    struct booktype_node books = {0, 0, 0, 0, 0, 0};
    printf("Enter the book's title : ");
    inputing_data_except_null(books.book, sizeof(books.book));
    printf("Enter the author's name : ");
    inputing_data_except_null(books.author, sizeof(books.author));
    printf("Enter the publisher's name : ");
    inputing_data_except_null(books.publisher, sizeof(books.publisher));
    printf("Enter the price of the book : ");
    inputing_data_except_null(books.price, sizeof(books.price));
    printf("Enter the year of publishing : ");
    inputing_data_except_null(books.year, sizeof(books.year));
    main_list = insert(&books, main_list);
    writing_data_file(main_list);
}


decompiled_code:
__int64 __fastcall pointing_location_of_null(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( *a1 == 10 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] != 10 );
return v2;
}

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

if ( *a1 == 10 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] != 10 );
return v2;
}

original_code:
int pointing_location_of_null(char *data)
{
    int icnt = 0;
    while(1)
    {
        if(*(data + icnt) == '\n')
        {
            break;
        }
        icnt++;
    }
    return icnt;
}

variable_types: icnt int


decompiled_code:
int delete_book()
{
__int64 v0; // rax
char v2[32]; // [rsp-20h] [rbp-48h] BYREF
char s[40]; // [rsp+0h] [rbp-28h] BYREF

deleted_book = 0LL;
if ( *(_QWORD *)(main_list + 90) )
{
puts("What Kind of Book do you want to delete?");
printf("Book Name: ");
inputing_data_except_null(v2, 30);
printf("\nBook Author: ");
inputing_data_except_null(s, 30);
v0 = delete_book_file(v2, s, main_list);
deleted_book = v0;
if ( v0 )
{
main_list = v0;
LODWORD(v0) = writing_data_file(v0);
}
}
else
{
LODWORD(v0) = puts("List is one! Do you want delete list? Delete 'book.bdf'!");
}
return v0;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rax
char v2[32]; // [rsp-20h] [rbp-48h] BYREF
char s[40]; // [rsp+0h] [rbp-28h] BYREF

deleted_book = 0LL;
if ( *(_QWORD *)(main_list + 90) )
{
puts("What Kind of Book do you want to delete?");
printf("Book Name: ");
func1(v2, 30);
printf("\nBook Author: ");
func1(s, 30);
v0 = delete_book_file(v2, s, main_list);
deleted_book = v0;
if ( v0 )
{
main_list = v0;
LODWORD(v0) = writing_data_file(v0);
}
}
else
{
LODWORD(v0) = puts("List is one! Do you want delete list? Delete 'book.bdf'!");
}
return v0;
}

original_code:
void delete_book(){
 deleted_book = ((void *)0);
 if (main_list -> next == 0){
  printf("List is one! Do you want delete list? Delete 'book.bdf'!\n");
  return;
 }
 printf("What Kind of Book do you want to delete?\n");
 char name[30];
 char author[30];
 printf("Book Name: ");
 inputing_data_except_null(name, sizeof(name));
 printf("\nBook Author: ");
 inputing_data_except_null(author, sizeof(author));
 deleted_book = delete_book_file(name, author, main_list);
 if (deleted_book != 0){
  main_list = deleted_book;
  writing_data_file(main_list);
 }
}

variable_types:
name
char [30]

variable_types:
author
char [30]


decompiled_code:
int Find_book()
{
const char *v0; // rax
char v2[32]; // [rsp+0h] [rbp-48h] BYREF
char s[40]; // [rsp+20h] [rbp-28h] BYREF

Found_book = 0LL;
puts("What is name of the book?");
printf("Book Name: ");
inputing_data_except_null(v2, 30);
printf("\nBook Author: ");
inputing_data_except_null(s, 30);
v0 = (const char *)Find(v2, s, main_list);
Found_book = (__int64)v0;
if ( v0 )
{
printf("Book : %s\n", v0);
printf("Author : %15s | ", (const char *)(Found_book + 30));
printf("Publisher : %15s\n", (const char *)(Found_book + 45));
printf("Price : %15s | ", (const char *)(Found_book + 60));
LODWORD(v0) = printf("Year : %15s\n", (const char *)(Found_book + 75));
}
return (int)v0;
}

canonical_decompiled_code:
int func5()
{
const char *v0; // rax
char v2[32]; // [rsp+0h] [rbp-48h] BYREF
char s[40]; // [rsp+20h] [rbp-28h] BYREF

Found_book = 0LL;
puts("What is name of the book?");
printf("Book Name: ");
func1(v2, 30);
printf("\nBook Author: ");
func1(s, 30);
v0 = (const char *)Find(v2, s, main_list);
Found_book = (__int64)v0;
if ( v0 )
{
printf("Book : %s\n", v0);
printf("Author : %15s | ", (const char *)(Found_book + 30));
printf("Publisher : %15s\n", (const char *)(Found_book + 45));
printf("Price : %15s | ", (const char *)(Found_book + 60));
LODWORD(v0) = printf("Year : %15s\n", (const char *)(Found_book + 75));
}
return (int)v0;
}

original_code:
void Find_book()
{
 Found_book = ((void *)0);
 printf("What is name of the book?\n");
 char name[30];
 char author[30];
 printf("Book Name: ");
 inputing_data_except_null(name, sizeof(name));
 printf("\nBook Author: ");
 inputing_data_except_null(author, sizeof(author));
 Found_book = Find(name, author, main_list);
 if (Found_book != 0){
  printf("Book      : %s\n", Found_book -> book);
  printf("Author    : %15s | ", Found_book -> author);
  printf("Publisher : %15s\n", Found_book -> publisher);
  printf("Price     : %15s | ", Found_book -> price);
  printf("Year      : %15s\n", Found_book -> year);
 }
}


decompiled_code:
void menu_print()
{
int v0; // ebx

main_list = loading_data_file(main_list);
while ( 1 )
{
putchar(10);
puts("1. Insert");
puts("2. List");
puts("3. Save as a data file");
puts("4. (new)Delete List");
puts("5. (new)Search the Book");
puts("6. Quit\n");
printf("Enter the number : ");
v0 = getchar();
_fpurge(stdin);
switch ( v0 )
{
case '1':
insert_book();
break;
case '2':
print_list_books();
break;
case '3':
writing_data_file(main_list);
break;
case '4':
delete_book();
break;
case '5':
Find_book();
break;
case '6':
puts("Thanks for using. See you again.");
exit(-1);
default:
puts("You enter the wrong number.");
break;
}
}
}

canonical_decompiled_code:
void func6()
{
int v0; // ebx

main_list = loading_data_file(main_list);
while ( 1 )
{
putchar(10);
puts("1. Insert");
puts("2. List");
puts("3. Save as a data file");
puts("4. (new)Delete List");
puts("5. (new)Search the Book");
puts("6. Quit\n");
printf("Enter the number : ");
v0 = getchar();
_fpurge(stdin);
switch ( v0 )
{
case '1':
func2();
break;
case '2':
func0();
break;
case '3':
writing_data_file(main_list);
break;
case '4':
func4();
break;
case '5':
func5();
break;
case '6':
puts("Thanks for using. See you again.");
exit(-1);
default:
puts("You enter the wrong number.");
break;
}
}
}

original_code:
int menu_print()
{
    int choisen_menu_number;
    main_list = loading_data_file(main_list);
    while(1)
    {
        putchar('\n');
        printf("1.  Insert\n");
        printf("2.  List\n");
        printf("3.  Save as a data file\n");
 printf("4.  (new)Delete List\n");
 printf("5.  (new)Search the Book\n");
        printf("6.  Quit\n\n");
        printf("Enter the number : ");
        choisen_menu_number = getchar();
        __fpurge(stdin);
        switch(choisen_menu_number)
        {
        case '1':
            insert_book();
            break;
        case '2':
            print_list_books();
            break;
        case '3':
            writing_data_file(main_list);
            break;
        case '4':
  delete_book();
     break;
 case '5':
  Find_book();
             break;
 case '6':
            printf("Thanks for using. See you again.\n");
            exit(-1);
        default:
            printf("You enter the wrong number.\n");
        }
    }
    return choisen_menu_number;
}