getAdjacentPiece

original_code:
PIECE_e getAdjacentPiece(char* adjacentPiece, DIRECTIONS_e* adjacencyDirection)
{
 char* colorToMove;
 char* numberToMove;
 char* typeToMove;
 PIECE_e piece;
 if ('-' == adjacentPiece[0])
 {
  colorToMove = &adjacentPiece[1];
  typeToMove = &adjacentPiece[2];
  numberToMove = &adjacentPiece[3];
  *adjacencyDirection = WEST;
 }
 else if ('\\' == adjacentPiece[0])
 {
  colorToMove = &adjacentPiece[1];
  typeToMove = &adjacentPiece[2];
  numberToMove = &adjacentPiece[3];
  *adjacencyDirection = NORTHWEST;
 }
 else if ('/' == adjacentPiece[0])
 {
  colorToMove = &adjacentPiece[1];
  typeToMove = &adjacentPiece[2];
  numberToMove = &adjacentPiece[3];
  *adjacencyDirection = SOUTHWEST;
 }
 else
 {
  colorToMove = &adjacentPiece[0];
  typeToMove = &adjacentPiece[1];
  numberToMove = &adjacentPiece[2];
  if(*typeToMove == 'Q')
  {
   if ('/' == adjacentPiece[2])
    *adjacencyDirection = NORTHEAST;
   else if ('-' == adjacentPiece[2])
    *adjacencyDirection = EAST;
   else if ('\\' == adjacentPiece[2])
    *adjacencyDirection = SOUTHEAST;
   else
    *adjacencyDirection = MAX_DIR;
  }
  else
  {
   if ('/' == adjacentPiece[3])
    *adjacencyDirection = NORTHEAST;
   else if ('-' == adjacentPiece[3])
    *adjacencyDirection = EAST;
   else if ('\\' == adjacentPiece[3])
    *adjacencyDirection = SOUTHEAST;
   else
    *adjacencyDirection = MAX_DIR;
  }
 }
 piece = translateTypeAndNumberToIndex(*colorToMove, *typeToMove, *numberToMove);
 return piece;
}

canonical_original_code:
enum PIECE_e getAdjacentPiece(char *adjacentPiece, enum DIRECTIONS_e *adjacencyDirection)
{
 char *colorToMove;
 char *numberToMove;
 char *typeToMove;
 enum PIECE_e piece;
 if ('-' == adjacentPiece[0])
 {
  colorToMove = &adjacentPiece[1];
  typeToMove = &adjacentPiece[2];
  numberToMove = &adjacentPiece[3];
  *adjacencyDirection = WEST;
 }
 else if ('\\' == adjacentPiece[0])
 {
  colorToMove = &adjacentPiece[1];
  typeToMove = &adjacentPiece[2];
  numberToMove = &adjacentPiece[3];
  *adjacencyDirection = NORTHWEST;
 }
 else if ('/' == adjacentPiece[0])
 {
  colorToMove = &adjacentPiece[1];
  typeToMove = &adjacentPiece[2];
  numberToMove = &adjacentPiece[3];
  *adjacencyDirection = SOUTHWEST;
 }
 else
 {
  colorToMove = &adjacentPiece[0];
  typeToMove = &adjacentPiece[1];
  numberToMove = &adjacentPiece[2];
  if(*typeToMove == 'Q')
  {
   if ('/' == adjacentPiece[2])
    *adjacencyDirection = NORTHEAST;
   else if ('-' == adjacentPiece[2])
    *adjacencyDirection = EAST;
   else if ('\\' == adjacentPiece[2])
    *adjacencyDirection = SOUTHEAST;
   else
    *adjacencyDirection = MAX_DIR;
  }
  else
  {
   if ('/' == adjacentPiece[3])
    *adjacencyDirection = NORTHEAST;
   else if ('-' == adjacentPiece[3])
    *adjacencyDirection = EAST;
   else if ('\\' == adjacentPiece[3])
    *adjacencyDirection = SOUTHEAST;
   else
    *adjacencyDirection = MAX_DIR;
  }
 }
 piece = translateTypeAndNumberToIndex(*colorToMove, *typeToMove, *numberToMove);
 return piece;
}

variable_types:
adjacentPiece
char *

variable_types: enum DIRECTIONS_e { NORTHEAST=0, EAST=1, SOUTHEAST=2, SOUTHWEST=3, WEST=4, NORTHWEST=5, MAX_DIR=6 } *

return_type: enum PIECE_e { WHITE_QUEEN=0, WHITE_BEETLE_ONE=1, WHITE_BEETLE_TWO=2, WHITE_GRASSHOPPER_ONE=3, WHITE_GRASSHOPPER_TWO=4, WHITE_GRASSHOPPER_THREE=5, WHITE_ANT_ONE=6, WHITE_ANT_TWO=7, WHITE_ANT_THREE=8, WHITE_SPIDER_ONE=9, WHITE_SPIDER_TWO=10, BLACK_QUEEN=11, BLACK_BEETLE_ONE=12, BLACK_BEETLE_TWO=13, BLACK_GRASSHOPPER_ONE=14, BLACK_GRASSHOPPER_TWO=15, BLACK_GRASSHOPPER_THREE=16, BLACK_ANT_ONE=17, BLACK_ANT_TWO=18, BLACK_ANT_THREE=19, BLACK_SPIDER_ONE=20, BLACK_SPIDER_TWO=21, MAX_PIECES=22, EMPTY_SPACE=23 }


parseMoveStringAndSetupBoardState

decompiled_code:
char *__fastcall parseMoveStringAndSetupBoardState(char *a1)
{
char *v1; // rax
unsigned int v2; // eax
char *result; // rax
char *v4; // rdi
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF
char v8[5]; // [rsp+12h] [rbp-16h] BYREF
char v9[5]; // [rsp+17h] [rbp-11h] BYREF
char v10; // [rsp+1Ch] [rbp-Ch] BYREF

moveNumber = 1;
strtok(a1, "=,");
v1 = strtok(0LL, "\",");
if ( v1 == "," || !v1 )
{
printf("wS1");
exit(0);
}
if ( (unsigned int)_isoc99_sscanf(v1, "%d. %5s", &v10, v9) == -1 )
{
printf("wS1");
exit(0);
}
v2 = getPieceToMove(v9);
playFirstPiece(v2);
++moveNumber;
result = strtok(0LL, ",");
v4 = result;
if ( result != ", " && result )
{
do
{
result = (char *)_isoc99_sscanf(v4, "%d. %s %s", &v10, v9, v8);
if ( (_DWORD)result == -1 )
break;
v5 = getPieceToMove(v9);
v6 = getAdjacentPiece(v8, &v7);
movePiece(v5, v6, v7);
++moveNumber;
result = strtok(0LL, ",");
v4 = result;
if ( result == ", " )
break;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1)
{
char *v1; // rax
unsigned int v2; // eax
char *result; // rax
char *v4; // rdi
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF
char v8[5]; // [rsp+12h] [rbp-16h] BYREF
char v9[5]; // [rsp+17h] [rbp-11h] BYREF
char v10; // [rsp+1Ch] [rbp-Ch] BYREF

moveNumber = 1;
strtok(a1, "=,");
v1 = strtok(0LL, "\",");
if ( v1 == "," || !v1 )
{
printf("wS1");
exit(0);
}
if ( (unsigned int)_isoc99_sscanf(v1, "%d. %5s", &v10, v9) == -1 )
{
printf("wS1");
exit(0);
}
v2 = func0(v9);
playFirstPiece(v2);
++moveNumber;
result = strtok(0LL, ",");
v4 = result;
if ( result != ", " && result )
{
do
{
result = (char *)_isoc99_sscanf(v4, "%d. %s %s", &v10, v9, v8);
if ( (_DWORD)result == -1 )
break;
v5 = func0(v9);
v6 = func1(v8, &v7);
movePiece(v5, v6, v7);
++moveNumber;
result = strtok(0LL, ",");
v4 = result;
if ( result == ", " )
break;
}
while ( result );
}
return result;
}

original_code:
void parseMoveStringAndSetupBoardState(char* moveString)
{
 char* nextMove;
 int moveNum;
 char pieceToMove[5];
 PIECE_e piece;
 char adjacentPiece[5];
 PIECE_e pieceAdjacent;
 DIRECTIONS_e adjacencyDirection;
 moveNumber = 1;
 nextMove = strtok(moveString, "=,");
 nextMove = strtok(((void *)0), "\",");
 if (nextMove == ((void *)0) || nextMove == ",")
 {
  printf("wS1");
  exit(0);
 }
 if ((-1) == sscanf(nextMove, "%d. %5s", &moveNum, pieceToMove))
 {
  printf("wS1");
  exit(0);
 }
 piece = getPieceToMove(pieceToMove);
 playFirstPiece(piece);
 moveNumber++;
 nextMove = strtok(((void *)0), ",");
 while (nextMove != ((void *)0) && nextMove != ", ")
 {
  if ((-1) == sscanf(nextMove, "%d. %s %s", &moveNum, pieceToMove, adjacentPiece))
  {
   break;
  }
  piece = getPieceToMove(pieceToMove);
  pieceAdjacent = getAdjacentPiece(adjacentPiece, &adjacencyDirection);
  movePiece(piece, pieceAdjacent, adjacencyDirection);
  moveNumber++;
  nextMove = strtok(((void *)0), ",");
 }
}

canonical_original_code:
void parseMoveStringAndSetupBoardState(char *moveString)
{
 char *nextMove;
 int moveNum;
 char pieceToMove[5];
 enum PIECE_e piece;
 char adjacentPiece[5];
 enum PIECE_e pieceAdjacent;
 enum DIRECTIONS_e adjacencyDirection;
 moveNumber = 1;
 nextMove = strtok(moveString, "=,");
 nextMove = strtok(((void *)0), "\",");
 if (nextMove == ((void *)0) || nextMove == ",")
 {
  printf("wS1");
  exit(0);
 }
 if ((-1) == sscanf(nextMove, "%d. %5s", &moveNum, pieceToMove))
 {
  printf("wS1");
  exit(0);
 }
 piece = getPieceToMove(pieceToMove);
 playFirstPiece(piece);
 moveNumber++;
 nextMove = strtok(((void *)0), ",");
 while (nextMove != ((void *)0) && nextMove != ", ")
 {
  if ((-1) == sscanf(nextMove, "%d. %s %s", &moveNum, pieceToMove, adjacentPiece))
  {
   break;
  }
  piece = getPieceToMove(pieceToMove);
  pieceAdjacent = getAdjacentPiece(adjacentPiece, &adjacencyDirection);
  movePiece(piece, pieceAdjacent, adjacencyDirection);
  moveNumber++;
  nextMove = strtok(((void *)0), ",");
 }
}

variable_types:
moveString
char *

variable_types:
nextMove
char *

variable_types: moveNum int

variable_types:
pieceToMove
char [5]

variable_types: enum PIECE_e { WHITE_QUEEN=0, WHITE_BEETLE_ONE=1, WHITE_BEETLE_TWO=2, WHITE_GRASSHOPPER_ONE=3, WHITE_GRASSHOPPER_TWO=4, WHITE_GRASSHOPPER_THREE=5, WHITE_ANT_ONE=6, WHITE_ANT_TWO=7, WHITE_ANT_THREE=8, WHITE_SPIDER_ONE=9, WHITE_SPIDER_TWO=10, BLACK_QUEEN=11, BLACK_BEETLE_ONE=12, BLACK_BEETLE_TWO=13, BLACK_GRASSHOPPER_ONE=14, BLACK_GRASSHOPPER_TWO=15, BLACK_GRASSHOPPER_THREE=16, BLACK_ANT_ONE=17, BLACK_ANT_TWO=18, BLACK_ANT_THREE=19, BLACK_SPIDER_ONE=20, BLACK_SPIDER_TWO=21, MAX_PIECES=22, EMPTY_SPACE=23 }

variable_types:
adjacentPiece
char [5]

variable_types: enum DIRECTIONS_e { NORTHEAST=0, EAST=1, SOUTHEAST=2, SOUTHWEST=3, WEST=4, NORTHWEST=5, MAX_DIR=6 }

return_type: void


printBoard

decompiled_code:
__int64 __fastcall printBoard(int a1, int a2)
{
__int64 result; // rax
char *v3; // r14
int v4; // er13
int v5; // ebx
char *v6; // rbp
int v7; // ebx
int v8; // [rsp+4h] [rbp-44h]

result = (unsigned int)(126 - a2);
v8 = result;
if ( a2 + 126 >= (int)result )
{
v3 = &board[256 * (126LL - a1) + 126 + a2];
v4 = 2 * a2;
do
{
v7 = v4;
if ( v4 > 0 )
{
do
{
fwrite(&off_5810917, 1uLL, 3uLL, stderr);
--v7;
}
while ( v7 );
}
--v4;
if ( 126 - a1 <= a1 + 126 )
{
v6 = v3;
v5 = 126 - a1;
do
{
if ( *v6 == 23 )
{
fwrite(" - ", 1uLL, 5uLL, stderr);
}
else
{
getPieceName(*v6, &pieceNamePtr);
fprintf(stderr, " %s ", (const char *)pieceNamePtr);
}
++v5;
v6 += 256;
}
while ( v5 <= a1 + 126 );
}
fputc(10, stderr);
--v3;
result = (unsigned int)(v4 + a2 + 126 - 2 * a2);
}
while ( v8 <= (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
__int64 result; // rax
char *v3; // r14
int v4; // er13
int v5; // ebx
char *v6; // rbp
int v7; // ebx
int v8; // [rsp+4h] [rbp-44h]

result = (unsigned int)(126 - a2);
v8 = result;
if ( a2 + 126 >= (int)result )
{
v3 = &board[256 * (126LL - a1) + 126 + a2];
v4 = 2 * a2;
do
{
v7 = v4;
if ( v4 > 0 )
{
do
{
fwrite(&off_5810917, 1uLL, 3uLL, stderr);
--v7;
}
while ( v7 );
}
--v4;
if ( 126 - a1 <= a1 + 126 )
{
v6 = v3;
v5 = 126 - a1;
do
{
if ( *v6 == 23 )
{
fwrite(" - ", 1uLL, 5uLL, stderr);
}
else
{
func3(*v6, &pieceNamePtr);
fprintf(stderr, " %s ", (const char *)pieceNamePtr);
}
++v5;
v6 += 256;
}
while ( v5 <= a1 + 126 );
}
fputc(10, stderr);
--v3;
result = (unsigned int)(v4 + a2 + 126 - 2 * a2);
}
while ( v8 <= (int)result );
}
return result;
}

original_code:
void printBoard(int xSize, int ySize)
{
 int x, y, z;
 char** pptr = &pieceNamePtr;
 int spaceCount = ySize * 2;
 for (y = (ySize + 126); y >= (-1*ySize + 126); y--)
 {
  for (z = spaceCount; z > 0; z--)
   fprintf(stderr, "   ");
  spaceCount--;
  for (x = (-1*xSize + 126); x <= (xSize + 126); x++)
  {
   if (board[x][y] == EMPTY_SPACE)
   {
    fprintf(stderr, "  -  ");
   }
   else
   {
    getPieceName(board[x][y], pptr);
    fprintf(stderr, " %s ", pieceNamePtr);
   }
  }
  fprintf(stderr, "\n");
 }
}

canonical_original_code:
void printBoard(int xSize, int ySize)
{
 int x; int y; int z;
 char **pptr = &pieceNamePtr;
 int spaceCount = ySize * 2;
 for (y = (ySize + 126); y >= (-1*ySize + 126); y--)
 {
  for (z = spaceCount; z > 0; z--)
   fprintf(stderr, "   ");
  spaceCount--;
  for (x = (-1*xSize + 126); x <= (xSize + 126); x++)
  {
   if (board[x][y] == EMPTY_SPACE)
   {
    fprintf(stderr, "  -  ");
   }
   else
   {
    getPieceName(board[x][y], pptr);
    fprintf(stderr, " %s ", pieceNamePtr);
   }
  }
  fprintf(stderr, "\n");
 }
}

variable_types: xSize int

variable_types: ySize int

variable_types: x int

variable_types: y int

variable_types: z int

variable_types:
pptr
char **

variable_types: spaceCount int


getAdjacentPieceAndQualifier

decompiled_code:
__int64 __fastcall getAdjacentPieceAndQualifier(int a1, unsigned __int8 a2, unsigned __int8 a3, _QWORD *a4, _QWORD *a5)
{
int v7; // eax
int v8; // er8
unsigned __int8 v9; // cl
unsigned __int8 v10; // si
unsigned __int8 v11; // cl
unsigned __int8 v12; // cl
int v13; // eax
unsigned __int8 v14; // dl
unsigned __int8 v15; // dl
__int64 result; // rax

v7 = a2;
v8 = a3 + 1;
v9 = board[256 * (unsigned __int64)a2 + v8];
if ( v9 > 0x15u || v9 == a1 )
{
v10 = board[256 * (__int64)(a2 + 1) + a3];
if ( v10 > 0x15u || v10 == a1 )
{
v11 = board[256 * (__int64)(v7 + 1) - 1 + a3];
if ( v11 > 0x15u || v11 == a1 )
{
v12 = board[256 * (__int64)v7 - 1 + a3];
if ( v12 > 0x15u || v12 == a1 )
{
v13 = v7 - 1;
v14 = board[256 * (__int64)v13 + a3];
if ( v14 > 0x15u || v14 == a1 )
{
v15 = board[256 * (__int64)v13 + v8];
result = 0LL;
if ( v15 <= 0x15u && v15 != a1 )
{
getPieceName(v15, a4);
*a5 = &unk_581092A;
result = 0LL;
}
}
else
{
getPieceName(v14, a4);
*a5 = (char *)&off_5810926 + 2;
result = 0LL;
}
}
else
{
getPieceName(v12, a4);
*a5 = &off_5810926;
result = 0LL;
}
}
else
{
getPieceName(v11, a4);
*a5 = &unk_581092A;
result = 1LL;
}
}
else
{
getPieceName(v10, a4);
*a5 = (char *)&off_5810926 + 2;
result = 1LL;
}
}
else
{
getPieceName(v9, a4);
*a5 = &off_5810926;
result = 1LL;
}
return result;
}

original_code:
_Bool getAdjacentPieceAndQualifier(PIECE_e piece, uint8_t x, uint8_t y, char** pieceName, char** qualifier)
{
 if (board[(x)][(y+1)] < MAX_PIECES && board[(x)][(y+1)] != piece)
 {
  getPieceName(board[(x)][(y+1)], pieceName);
  *qualifier = "/";
  return 1;
 }
 else if (board[(x+1)][(y)] < MAX_PIECES && board[(x+1)][(y)] != piece)
 {
  getPieceName(board[(x+1)][(y)], pieceName);
  *qualifier = "-";
  return 1;
 }
 else if (board[(x+1)][(y-1)] < MAX_PIECES && board[(x+1)][(y-1)] != piece)
 {
  getPieceName(board[(x+1)][(y-1)], pieceName);
  *qualifier = "\\";
  return 1;
 }
 else if (board[(x)][(y-1)] < MAX_PIECES && board[(x)][(y-1)] != piece)
 {
  getPieceName(board[(x)][(y-1)], pieceName);
  *qualifier = "/";
  return 0;
 }
 else if (board[(x-1)][(y)] < MAX_PIECES && board[(x-1)][(y)] != piece)
 {
  getPieceName(board[(x-1)][(y)], pieceName);
  *qualifier = "-";
  return 0;
 }
 else if (board[(x-1)][(y+1)] < MAX_PIECES && board[(x-1)][(y+1)] != piece)
 {
  getPieceName(board[(x-1)][(y+1)], pieceName);
  *qualifier = "\\";
  return 0;
 }
 return 0;
}

canonical_original_code:
_Bool getAdjacentPieceAndQualifier(enum PIECE_e piece, unsigned char x, unsigned char y, char **pieceName, char **qualifier)
{
 if (board[(x)][(y+1)] < MAX_PIECES && board[(x)][(y+1)] != piece)
 {
  getPieceName(board[(x)][(y+1)], pieceName);
  *qualifier = "/";
  return 1;
 }
 else if (board[(x+1)][(y)] < MAX_PIECES && board[(x+1)][(y)] != piece)
 {
  getPieceName(board[(x+1)][(y)], pieceName);
  *qualifier = "-";
  return 1;
 }
 else if (board[(x+1)][(y-1)] < MAX_PIECES && board[(x+1)][(y-1)] != piece)
 {
  getPieceName(board[(x+1)][(y-1)], pieceName);
  *qualifier = "\\";
  return 1;
 }
 else if (board[(x)][(y-1)] < MAX_PIECES && board[(x)][(y-1)] != piece)
 {
  getPieceName(board[(x)][(y-1)], pieceName);
  *qualifier = "/";
  return 0;
 }
 else if (board[(x-1)][(y)] < MAX_PIECES && board[(x-1)][(y)] != piece)
 {
  getPieceName(board[(x-1)][(y)], pieceName);
  *qualifier = "-";
  return 0;
 }
 else if (board[(x-1)][(y+1)] < MAX_PIECES && board[(x-1)][(y+1)] != piece)
 {
  getPieceName(board[(x-1)][(y+1)], pieceName);
  *qualifier = "\\";
  return 0;
 }
 return 0;
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types:
pieceName
char **

variable_types:
qualifier
char **

user_defined_types: enum PIECE_e { WHITE_QUEEN=0, WHITE_BEETLE_ONE=1, WHITE_BEETLE_TWO=2, WHITE_GRASSHOPPER_ONE=3, WHITE_GRASSHOPPER_TWO=4, WHITE_GRASSHOPPER_THREE=5, WHITE_ANT_ONE=6, WHITE_ANT_TWO=7, WHITE_ANT_THREE=8, WHITE_SPIDER_ONE=9, WHITE_SPIDER_TWO=10, BLACK_QUEEN=11, BLACK_BEETLE_ONE=12, BLACK_BEETLE_TWO=13, BLACK_GRASSHOPPER_ONE=14, BLACK_GRASSHOPPER_TWO=15, BLACK_GRASSHOPPER_THREE=16, BLACK_ANT_ONE=17, BLACK_ANT_TWO=18, BLACK_ANT_THREE=19, BLACK_SPIDER_ONE=20, BLACK_SPIDER_TWO=21, MAX_PIECES=22, EMPTY_SPACE=23 }


printOutBestMove

decompiled_code:
int printOutBestMove()
{
__int16 v0; // bx
unsigned int v1; // ebp
int result; // eax

v0 = currMove;
v1 = BYTE2(currMove);
getPieceName(BYTE2(currMove), &pieceNamePtr);
pickUpPiece(v1);
if ( (unsigned __int8)getAdjacentPieceAndQualifier(v1, v0, HIBYTE(v0), &pieceAdjNamePtr, &pieceQualifierPtr) )
result = printf(
"%s %s%s",
(const char *)pieceNamePtr,
(const char *)pieceQualifierPtr,
(const char *)pieceAdjNamePtr);
else
result = printf(
"%s %s%s",
(const char *)pieceNamePtr,
(const char *)pieceAdjNamePtr,
(const char *)pieceQualifierPtr);
return result;
}

canonical_decompiled_code:
int func6()
{
__int16 v0; // bx
unsigned int v1; // ebp
int result; // eax

v0 = currMove;
v1 = BYTE2(currMove);
func3(BYTE2(currMove), &pieceNamePtr);
pickUpPiece(v1);
if ( (unsigned __int8)func5(v1, v0, HIBYTE(v0), &pieceAdjNamePtr, &pieceQualifierPtr) )
result = printf(
"%s %s%s",
(const char *)pieceNamePtr,
(const char *)pieceQualifierPtr,
(const char *)pieceAdjNamePtr);
else
result = printf(
"%s %s%s",
(const char *)pieceNamePtr,
(const char *)pieceAdjNamePtr,
(const char *)pieceQualifierPtr);
return result;
}

original_code:
void printOutBestMove(void)
{
 PIECE_e piece;
 uint8_t x, y;
 char** pptr;
 char** pptr2;
 char** pptr3;
 pptr = &pieceNamePtr;
 pptr2 = &pieceQualifierPtr;
 pptr3 = &pieceAdjNamePtr;
 piece = ((currMove.move & (0x00FF0000)) >> (16));
 x = ((currMove.move & (0x000000FF)) >> (0));
 y = ((currMove.move & (0x0000FF00)) >> (8));
 getPieceName(piece, pptr);
 pickUpPiece(piece);
 if(getAdjacentPieceAndQualifier(piece, x, y, pptr3, pptr2))
 {
  printf("%s %s%s", pieceNamePtr, pieceQualifierPtr, pieceAdjNamePtr);
 }
 else
 {
  printf( "%s %s%s", pieceNamePtr, pieceAdjNamePtr, pieceQualifierPtr);
 }
}

canonical_original_code:
void printOutBestMove()
{
 enum PIECE_e piece;
 unsigned char x; unsigned char y;
 char **pptr;
 char **pptr2;
 char **pptr3;
 pptr = &pieceNamePtr;
 pptr2 = &pieceQualifierPtr;
 pptr3 = &pieceAdjNamePtr;
 piece = ((currMove.move & (0x00FF0000)) >> (16));
 x = ((currMove.move & (0x000000FF)) >> (0));
 y = ((currMove.move & (0x0000FF00)) >> (8));
 getPieceName(piece, pptr);
 pickUpPiece(piece);
 if(getAdjacentPieceAndQualifier(piece, x, y, pptr3, pptr2))
 {
  printf("%s %s%s", pieceNamePtr, pieceQualifierPtr, pieceAdjNamePtr);
 }
 else
 {
  printf( "%s %s%s", pieceNamePtr, pieceAdjNamePtr, pieceQualifierPtr);
 }
}


initState

decompiled_code:
int initState()
{
void *v0; // rbx
void *v1; // rax

initPieces();
initBoard();
initSearch();
initPinnedMap();
v0 = malloc(5uLL);
pieceNamePtr = (__int64)v0;
pieceQualifierPtr = (__int64)malloc(3uLL);
v1 = malloc(5uLL);
pieceAdjNamePtr = (__int64)v1;
if ( !v0 )
LODWORD(v1) = puts("ERROR: Could not allocate char ptr");
return (int)v1;
}

canonical_decompiled_code:
int func7()
{
void *v0; // rbx
void *v1; // rax

initPieces();
initBoard();
initSearch();
initPinnedMap();
v0 = malloc(5uLL);
pieceNamePtr = (__int64)v0;
pieceQualifierPtr = (__int64)malloc(3uLL);
v1 = malloc(5uLL);
pieceAdjNamePtr = (__int64)v1;
if ( !v0 )
LODWORD(v1) = puts("ERROR: Could not allocate char ptr");
return (int)v1;
}

original_code:
void initState(void)
{
 initPieces();
 initBoard();
 initSearch();
 initPinnedMap();
 pieceNamePtr = (char*)malloc(sizeof(char)*5);
 pieceQualifierPtr = (char*)malloc(sizeof(char)*3);
 pieceAdjNamePtr = (char*)malloc(sizeof(char)*5);
 if (pieceNamePtr == ((void *)0))
 {
  printf("ERROR: Could not allocate char ptr\n");
 }
}

canonical_original_code:
void initState()
{
 initPieces();
 initBoard();
 initSearch();
 initPinnedMap();
 pieceNamePtr = (char *)malloc(sizeof(char)*5);
 pieceQualifierPtr = (char *)malloc(sizeof(char)*3);
 pieceAdjNamePtr = (char *)malloc(sizeof(char)*5);
 if (pieceNamePtr == ((void *)0))
 {
  printf("ERROR: Could not allocate char ptr\n");
 }
}


explorePieces

decompiled_code:
__int64 __fastcall explorePieces(unsigned int a1)
{
unsigned __int8 v1; // r13
unsigned __int8 v2; // r12
unsigned __int8 v3; // al
unsigned int v4; // ebx
int v5; // er14
int v6; // ebp

pieceArray[a1] = 0;
v1 = getXpos();
v2 = getYpos(a1);
v3 = getZpos(a1);
v4 = 1;
if ( v3 > 1u )
{
if ( (v3 & 1) != 0 )
{
v4 = 1;
}
else
{
do
{
v3 >>= 1;
++v4;
}
while ( (v3 & 1) == 0 );
}
}
v5 = v2 + 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)v1 + v5] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (unsigned __int64)v1 + v5]] )
{
v4 += explorePieces();
}
if ( (unsigned __int8)board[256 * (__int64)(v1 + 1) + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)(v1 + 1) + v2]] )
{
v4 += explorePieces();
}
if ( (unsigned __int8)board[256 * (__int64)(v1 + 1) - 1 + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)(v1 + 1) - 1 + v2]] )
{
v4 += explorePieces();
}
if ( (unsigned __int8)board[256 * (unsigned __int64)v1 - 1 + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (unsigned __int64)v1 - 1 + v2]] )
{
v4 += explorePieces();
}
v6 = v1 - 1;
if ( (unsigned __int8)board[256 * (__int64)v6 + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)v6 + v2]] )
{
v4 += explorePieces();
}
if ( (unsigned __int8)board[256 * (__int64)v6 + v5] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)v6 + v5]] )
{
v4 += explorePieces();
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
unsigned __int8 v1; // r13
unsigned __int8 v2; // r12
unsigned __int8 v3; // al
unsigned int v4; // ebx
int v5; // er14
int v6; // ebp

pieceArray[a1] = 0;
v1 = getXpos();
v2 = getYpos(a1);
v3 = getZpos(a1);
v4 = 1;
if ( v3 > 1u )
{
if ( (v3 & 1) != 0 )
{
v4 = 1;
}
else
{
do
{
v3 >>= 1;
++v4;
}
while ( (v3 & 1) == 0 );
}
}
v5 = v2 + 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)v1 + v5] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (unsigned __int64)v1 + v5]] )
{
v4 += func0();
}
if ( (unsigned __int8)board[256 * (__int64)(v1 + 1) + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)(v1 + 1) + v2]] )
{
v4 += func0();
}
if ( (unsigned __int8)board[256 * (__int64)(v1 + 1) - 1 + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)(v1 + 1) - 1 + v2]] )
{
v4 += func0();
}
if ( (unsigned __int8)board[256 * (unsigned __int64)v1 - 1 + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (unsigned __int64)v1 - 1 + v2]] )
{
v4 += func0();
}
v6 = v1 - 1;
if ( (unsigned __int8)board[256 * (__int64)v6 + v2] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)v6 + v2]] )
{
v4 += func0();
}
if ( (unsigned __int8)board[256 * (__int64)v6 + v5] <= 0x15u
&& pieceArray[(unsigned __int8)board[256 * (__int64)v6 + v5]] )
{
v4 += func0();
}
return v4;
}

original_code:
static uint32_t explorePieces(PIECE_e piece)
{
 uint32_t piecesExplored = 0;
 uint8_t xpos, ypos, zpos;
 PIECE_e neighbour;
 pieceArray[piece] = 0;
 piecesExplored++;
 xpos = getXpos(piece);
 ypos = getYpos(piece);
 zpos = getZpos(piece);
 if (zpos > (1))
 {
  while (!(zpos & 1))
  {
   zpos = zpos >> 1;
   piecesExplored++;
  }
 }
 neighbour = board[xpos][ypos+1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos+1][ypos];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos+1][ypos-1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos][ypos-1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos-1][ypos];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos-1][ypos+1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 return piecesExplored;
}

canonical_original_code:
static unsigned int explorePieces(enum PIECE_e piece)
{
 unsigned int piecesExplored = 0;
 unsigned char xpos; unsigned char ypos; unsigned char zpos;
 enum PIECE_e neighbour;
 pieceArray[piece] = 0;
 piecesExplored++;
 xpos = getXpos(piece);
 ypos = getYpos(piece);
 zpos = getZpos(piece);
 if (zpos > (1))
 {
  while (!(zpos & 1))
  {
   zpos = zpos >> 1;
   piecesExplored++;
  }
 }
 neighbour = board[xpos][ypos+1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos+1][ypos];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos+1][ypos-1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos][ypos-1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos-1][ypos];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 neighbour = board[xpos-1][ypos+1];
 if (neighbour < MAX_PIECES && pieceArray[neighbour])
  piecesExplored += explorePieces(neighbour);
 return piecesExplored;
}

variable_types:
piecesExplored
unsigned int

variable_types:
xpos
unsigned char

variable_types:
ypos
unsigned char

variable_types:
zpos
unsigned char

return_type: unsigned int


getOccupiedPositionsAroundCoords

decompiled_code:
char __fastcall getOccupiedPositionsAroundCoords(unsigned __int8 a1, unsigned __int8 a2)
{
int v2; // er8
char result; // al
int v4; // ecx
int v5; // edx

v2 = a2 + 1;
result = board[256 * (unsigned __int64)a1 + v2] != 23;
v4 = a1 + 1;
if ( board[256 * (__int64)v4 + a2] != 23 )
result |= 2u;
if ( board[256 * (__int64)v4 - 1 + a2] != 23 )
result |= 4u;
if ( board[256 * (unsigned __int64)a1 - 1 + a2] != 23 )
result |= 8u;
v5 = a1 - 1;
if ( board[256 * (__int64)v5 + a2] != 23 )
result |= 0x10u;
if ( board[256 * (__int64)v5 + v2] != 23 )
result |= 0x20u;
return result;
}

canonical_decompiled_code:
char __fastcall func1(unsigned __int8 a1, unsigned __int8 a2)
{
int v2; // er8
char result; // al
int v4; // ecx
int v5; // edx

v2 = a2 + 1;
result = board[256 * (unsigned __int64)a1 + v2] != 23;
v4 = a1 + 1;
if ( board[256 * (__int64)v4 + a2] != 23 )
result |= 2u;
if ( board[256 * (__int64)v4 - 1 + a2] != 23 )
result |= 4u;
if ( board[256 * (unsigned __int64)a1 - 1 + a2] != 23 )
result |= 8u;
v5 = a1 - 1;
if ( board[256 * (__int64)v5 + a2] != 23 )
result |= 0x10u;
if ( board[256 * (__int64)v5 + v2] != 23 )
result |= 0x20u;
return result;
}

original_code:
uint8_t getOccupiedPositionsAroundCoords(uint8_t xpos, uint8_t ypos)
{
 uint8_t retVal = 0;
 if (board[xpos][ypos+1] != EMPTY_SPACE)
  retVal |= (1 << NE_SHIFT);
 if (board[xpos+1][ypos] != EMPTY_SPACE)
  retVal |= (1 << E_SHIFT);
 if (board[xpos+1][ypos-1] != EMPTY_SPACE)
  retVal |= (1 << SE_SHIFT);
 if (board[xpos][ypos-1] != EMPTY_SPACE)
  retVal |= (1 << SW_SHIFT);
 if (board[xpos-1][ypos] != EMPTY_SPACE)
  retVal |= (1 << W_SHIFT);
 if (board[xpos-1][ypos+1] != EMPTY_SPACE)
  retVal |= (1 << NW_SHIFT);
 return retVal;
}

canonical_original_code:
unsigned char getOccupiedPositionsAroundCoords(unsigned char xpos, unsigned char ypos)
{
 unsigned char retVal = 0;
 if (board[xpos][ypos+1] != EMPTY_SPACE)
  retVal |= (1 << NE_SHIFT);
 if (board[xpos+1][ypos] != EMPTY_SPACE)
  retVal |= (1 << E_SHIFT);
 if (board[xpos+1][ypos-1] != EMPTY_SPACE)
  retVal |= (1 << SE_SHIFT);
 if (board[xpos][ypos-1] != EMPTY_SPACE)
  retVal |= (1 << SW_SHIFT);
 if (board[xpos-1][ypos] != EMPTY_SPACE)
  retVal |= (1 << W_SHIFT);
 if (board[xpos-1][ypos+1] != EMPTY_SPACE)
  retVal |= (1 << NW_SHIFT);
 return retVal;
}

variable_types:
retVal
unsigned char

return_type: unsigned char


getNumberOfOccupiedSquaresAroundCoords

decompiled_code:
__int64 __fastcall getNumberOfOccupiedSquaresAroundCoords(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al
int v3; // ecx
unsigned int v4; // edx

v2 = getOccupiedPositionsAroundCoords(a1, a2);
v3 = 0;
v4 = 0;
do
v4 += ((int)v2 >> v3++) & 1;
while ( v3 != 6 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al
int v3; // ecx
unsigned int v4; // edx

v2 = func1(a1, a2);
v3 = 0;
v4 = 0;
do
v4 += ((int)v2 >> v3++) & 1;
while ( v3 != 6 );
return v4;
}

original_code:
uint8_t getNumberOfOccupiedSquaresAroundCoords(uint8_t xpos, uint8_t ypos)
{
 uint8_t sum = 0;
 uint8_t retVal = getOccupiedPositionsAroundCoords(xpos, ypos);
 for (int i = 0; i < 6; i++)
 {
  if ((retVal >> i) & 1)
   sum +=1;
 }
 return sum;
}

canonical_original_code:
unsigned char getNumberOfOccupiedSquaresAroundCoords(unsigned char xpos, unsigned char ypos)
{
 unsigned char sum = 0;
 unsigned char retVal = getOccupiedPositionsAroundCoords(xpos, ypos);
 for (int i = 0; i < 6; i++)
 {
  if ((retVal >> i) & 1)
   sum +=1;
 }
 return sum;
}

variable_types:
sum
unsigned char

variable_types: i int


initBoard

decompiled_code:
_BYTE *initBoard()
{
unsigned __int64 v0; // rdx
_BYTE *result; // rax

v0 = (unsigned int)((_DWORD)board + 256);
do
{
result = (_BYTE *)(v0 - 256);
do
*result++ = 23;
while ( result != (_BYTE *)v0 );
v0 += 256LL;
}
while ( v0 != (_DWORD)board + 65792 );
return result;
}

canonical_decompiled_code:
_BYTE *func3()
{
unsigned __int64 v0; // rdx
_BYTE *result; // rax

v0 = (unsigned int)((_DWORD)board + 256);
do
{
result = (_BYTE *)(v0 - 256);
do
*result++ = 23;
while ( result != (_BYTE *)v0 );
v0 += 256LL;
}
while ( v0 != (_DWORD)board + 65792 );
return result;
}

original_code:
void initBoard(void)
{
 int i, j;
 for (i = 0; i < 256; i++)
 {
  for (j = 0; j < 256; j++)
  {
   board[i][j] = EMPTY_SPACE;
  }
 }
}

canonical_original_code:
void initBoard()
{
 int i; int j;
 for (i = 0; i < 256; i++)
 {
  for (j = 0; j < 256; j++)
  {
   board[i][j] = EMPTY_SPACE;
  }
 }
}

variable_types: j int


isHiveBroken

decompiled_code:
bool __fastcall isHiveBroken(unsigned int a1)
{
__int64 v1; // rbx
int v2; // ebp
unsigned __int8 v3; // bl
unsigned __int8 v4; // al
int v5; // er8
unsigned __int8 v6; // cl
unsigned __int8 v7; // si
int v8; // edx
unsigned __int8 v9; // al
unsigned __int8 v10; // dl
int v11; // eax

v1 = 0LL;
v2 = 0;
do
{
pieceArray[v1] = 0;
if ( (unsigned __int8)hasPieceBeenPlayed((unsigned int)v1) )
{
++v2;
pieceArray[v1] = 1;
}
++v1;
}
while ( v1 != 22 );
v3 = getXpos(a1);
v4 = getYpos(a1);
v5 = v4 + 1;
v6 = board[256 * (unsigned __int64)v3 + v5];
if ( v6 <= 0x15u && pieceArray[v6] )
goto LABEL_18;
v7 = board[256 * (__int64)(v3 + 1) + v4];
if ( v7 <= 0x15u && pieceArray[v7] )
{
v11 = explorePieces(v7);
return v2 != v11;
}
if ( (v6 = board[256 * (__int64)(v3 + 1) - 1 + v4], v6 <= 0x15u) && pieceArray[v6]
|| (v6 = board[256 * (unsigned __int64)v3 - 1 + v4], v6 <= 0x15u) && pieceArray[v6] )
{
LABEL_18:
v11 = explorePieces(v6);
}
else
{
v8 = v3 - 1;
v9 = board[256 * (__int64)v8 + v4];
if ( v9 <= 0x15u && pieceArray[v9] )
{
v11 = explorePieces(v9);
}
else
{
v10 = board[256 * (__int64)v8 + v5];
v11 = 0;
if ( v10 <= 0x15u )
{
v11 = pieceArray[v10];
if ( v11 )
v11 = explorePieces(v10);
}
}
}
return v2 != v11;
}

canonical_decompiled_code:
bool __fastcall func4(unsigned int a1)
{
__int64 v1; // rbx
int v2; // ebp
unsigned __int8 v3; // bl
unsigned __int8 v4; // al
int v5; // er8
unsigned __int8 v6; // cl
unsigned __int8 v7; // si
int v8; // edx
unsigned __int8 v9; // al
unsigned __int8 v10; // dl
int v11; // eax

v1 = 0LL;
v2 = 0;
do
{
pieceArray[v1] = 0;
if ( (unsigned __int8)hasPieceBeenPlayed((unsigned int)v1) )
{
++v2;
pieceArray[v1] = 1;
}
++v1;
}
while ( v1 != 22 );
v3 = getXpos(a1);
v4 = getYpos(a1);
v5 = v4 + 1;
v6 = board[256 * (unsigned __int64)v3 + v5];
if ( v6 <= 0x15u && pieceArray[v6] )
goto LABEL_18;
v7 = board[256 * (__int64)(v3 + 1) + v4];
if ( v7 <= 0x15u && pieceArray[v7] )
{
v11 = func0(v7);
return v2 != v11;
}
if ( (v6 = board[256 * (__int64)(v3 + 1) - 1 + v4], v6 <= 0x15u) && pieceArray[v6]
|| (v6 = board[256 * (unsigned __int64)v3 - 1 + v4], v6 <= 0x15u) && pieceArray[v6] )
{
LABEL_18:
v11 = func0(v6);
}
else
{
v8 = v3 - 1;
v9 = board[256 * (__int64)v8 + v4];
if ( v9 <= 0x15u && pieceArray[v9] )
{
v11 = func0(v9);
}
else
{
v10 = board[256 * (__int64)v8 + v5];
v11 = 0;
if ( v10 <= 0x15u )
{
v11 = pieceArray[v10];
if ( v11 )
v11 = func0(v10);
}
}
}
return v2 != v11;
}

original_code:
_Bool isHiveBroken(PIECE_e pieceToCheck)
{
 PIECE_e piece, startingPiece;
 uint8_t xpos, ypos;
 uint32_t numberOfPiecesPlayed = 0;
 uint32_t piecesExplored = 0;
 for (piece = 0; piece < MAX_PIECES; piece++)
 {
  pieceArray[piece] = 0;
  if (hasPieceBeenPlayed(piece))
  {
   numberOfPiecesPlayed++;
   pieceArray[piece] = 1;
   startingPiece = piece;
  }
 }
 xpos = getXpos(pieceToCheck);
 ypos = getYpos(pieceToCheck);
 if (board[xpos][ypos+1] < MAX_PIECES && pieceArray[board[xpos][ypos+1]])
  piecesExplored += explorePieces(board[xpos][ypos+1]);
 else if (board[xpos+1][ypos] < MAX_PIECES && pieceArray[board[xpos+1][ypos]])
  piecesExplored += explorePieces(board[xpos+1][ypos]);
 else if (board[xpos+1][ypos-1] < MAX_PIECES && pieceArray[board[xpos+1][ypos-1]])
  piecesExplored += explorePieces(board[xpos+1][ypos-1]);
 else if (board[xpos][ypos-1] < MAX_PIECES && pieceArray[board[xpos][ypos-1]])
  piecesExplored += explorePieces(board[xpos][ypos-1]);
 else if (board[xpos-1][ypos] < MAX_PIECES && pieceArray[board[xpos-1][ypos]])
  piecesExplored += explorePieces(board[xpos-1][ypos]);
 else if (board[xpos-1][ypos+1] < MAX_PIECES && pieceArray[board[xpos-1][ypos+1]])
  piecesExplored += explorePieces(board[xpos-1][ypos+1]);
 if (numberOfPiecesPlayed != piecesExplored)
  return 1;
 return 0;
}

canonical_original_code:
_Bool isHiveBroken(enum PIECE_e pieceToCheck)
{
 enum PIECE_e piece; enum PIECE_e startingPiece;
 unsigned char xpos; unsigned char ypos;
 unsigned int numberOfPiecesPlayed = 0;
 unsigned int piecesExplored = 0;
 for (piece = 0; piece < MAX_PIECES; piece++)
 {
  pieceArray[piece] = 0;
  if (hasPieceBeenPlayed(piece))
  {
   numberOfPiecesPlayed++;
   pieceArray[piece] = 1;
   startingPiece = piece;
  }
 }
 xpos = getXpos(pieceToCheck);
 ypos = getYpos(pieceToCheck);
 if (board[xpos][ypos+1] < MAX_PIECES && pieceArray[board[xpos][ypos+1]])
  piecesExplored += explorePieces(board[xpos][ypos+1]);
 else if (board[xpos+1][ypos] < MAX_PIECES && pieceArray[board[xpos+1][ypos]])
  piecesExplored += explorePieces(board[xpos+1][ypos]);
 else if (board[xpos+1][ypos-1] < MAX_PIECES && pieceArray[board[xpos+1][ypos-1]])
  piecesExplored += explorePieces(board[xpos+1][ypos-1]);
 else if (board[xpos][ypos-1] < MAX_PIECES && pieceArray[board[xpos][ypos-1]])
  piecesExplored += explorePieces(board[xpos][ypos-1]);
 else if (board[xpos-1][ypos] < MAX_PIECES && pieceArray[board[xpos-1][ypos]])
  piecesExplored += explorePieces(board[xpos-1][ypos]);
 else if (board[xpos-1][ypos+1] < MAX_PIECES && pieceArray[board[xpos-1][ypos+1]])
  piecesExplored += explorePieces(board[xpos-1][ypos+1]);
 if (numberOfPiecesPlayed != piecesExplored)
  return 1;
 return 0;
}

variable_types: enum PIECE_e { WHITE_QUEEN=0, WHITE_BEETLE_ONE=1, WHITE_BEETLE_TWO=2, WHITE_GRASSHOPPER_ONE=3, WHITE_GRASSHOPPER_TWO=4, WHITE_GRASSHOPPER_THREE=5, WHITE_ANT_ONE=6, WHITE_ANT_TWO=7, WHITE_ANT_THREE=8, WHITE_SPIDER_ONE=9, WHITE_SPIDER_TWO=10, BLACK_QUEEN=11, BLACK_BEETLE_ONE=12, BLACK_BEETLE_TWO=13, BLACK_GRASSHOPPER_ONE=14, BLACK_GRASSHOPPER_TWO=15, BLACK_GRASSHOPPER_THREE=16, BLACK_ANT_ONE=17, BLACK_ANT_TWO=18, BLACK_ANT_THREE=19, BLACK_SPIDER_ONE=20, BLACK_SPIDER_TWO=21, MAX_PIECES=22, EMPTY_SPACE=23 }

variable_types:
numberOfPiecesPlayed
unsigned int


isGate

decompiled_code:
bool __fastcall isGate(unsigned __int8 a1, unsigned __int8 a2)
{
return (unsigned __int8)getNumberOfOccupiedSquaresAroundCoords(a1, a2) == 5;
}

canonical_decompiled_code:
bool __fastcall func5(unsigned __int8 a1, unsigned __int8 a2)
{
return (unsigned __int8)func2(a1, a2) == 5;
}

original_code:
inline _Bool isGate(uint8_t xpos, uint8_t ypos)
{
 return (5 == getNumberOfOccupiedSquaresAroundCoords(xpos, ypos));
}

canonical_original_code:
inline _Bool isGate(unsigned char xpos, unsigned char ypos)
{
 return (5 == getNumberOfOccupiedSquaresAroundCoords(xpos, ypos));
}


isGateOrUnnattached

decompiled_code:
__int64 __fastcall isGateOrUnnattached(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned int v2; // eax
int v3; // edx

v2 = getNumberOfOccupiedSquaresAroundCoords(a1, a2);
LOBYTE(v3) = (_BYTE)v2 == 5;
LOBYTE(v2) = (_BYTE)v2 == 0;
return v3 | v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned int v2; // eax
int v3; // edx

v2 = func2(a1, a2);
LOBYTE(v3) = (_BYTE)v2 == 5;
LOBYTE(v2) = (_BYTE)v2 == 0;
return v3 | v2;
}

original_code:
inline _Bool isGateOrUnnattached(uint8_t xpos, uint8_t ypos)
{
 uint8_t temp = getNumberOfOccupiedSquaresAroundCoords(xpos, ypos);
 if (temp == 5 || temp == 0)
  return 1;
 return 0;
}

canonical_original_code:
inline _Bool isGateOrUnnattached(unsigned char xpos, unsigned char ypos)
{
 unsigned char temp = getNumberOfOccupiedSquaresAroundCoords(xpos, ypos);
 if (temp == 5 || temp == 0)
  return 1;
 return 0;
}

variable_types:
temp
unsigned char


isSquareOccupied

decompiled_code:
bool __fastcall isSquareOccupied(unsigned __int8 a1, unsigned __int8 a2)
{
return board[256 * (unsigned __int64)a1 + a2] != 23;
}

canonical_decompiled_code:
bool __fastcall func7(unsigned __int8 a1, unsigned __int8 a2)
{
return board[256 * (unsigned __int64)a1 + a2] != 23;
}

original_code:
inline _Bool isSquareOccupied(uint8_t xpos, uint8_t ypos)
{
 if (board[xpos][ypos] != EMPTY_SPACE)
  return 1;
 return 0;
}

canonical_original_code:
inline _Bool isSquareOccupied(unsigned char xpos, unsigned char ypos)
{
 if (board[xpos][ypos] != EMPTY_SPACE)
  return 1;
 return 0;
}


isSlidable

decompiled_code:
__int64 __fastcall isSlidable(unsigned __int8 a1, unsigned __int8 a2, int a3)
{
unsigned int v3; // ecx

if ( a3 )
{
switch ( a3 )
{
case 1:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] > 0x15u;
break;
case 2:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] > 0x15u;
break;
case 3:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] > 0x15u;
break;
case 4:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] > 0x15u;
break;
default:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] > 0x15u;
break;
}
}
else
{
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] > 0x15u;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, unsigned __int8 a2, int a3)
{
unsigned int v3; // ecx

if ( a3 )
{
switch ( a3 )
{
case 1:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] > 0x15u;
break;
case 2:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] > 0x15u;
break;
case 3:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] > 0x15u;
break;
case 4:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] > 0x15u;
break;
default:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] > 0x15u;
break;
}
}
else
{
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] <= 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] > 0x15u;
}
return v3;
}

original_code:
inline _Bool isSlidable(uint8_t x, uint8_t y, DIRECTIONS_e dir)
{
 if (NORTHEAST == dir)
 {
  if ((board[(x+1)][(y)] < MAX_PIECES) && (board[(x-1)][(y+1)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (EAST == dir)
 {
  if ((board[(x)][(y+1)] < MAX_PIECES) && (board[(x+1)][(y-1)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (SOUTHEAST == dir)
 {
  if ((board[(x)][(y-1)] < MAX_PIECES) && (board[(x+1)][(y)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (SOUTHWEST == dir)
 {
  if ((board[(x+1)][(y-1)] < MAX_PIECES) && (board[(x-1)][(y)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (WEST == dir)
 {
  if ((board[(x-1)][(y+1)] < MAX_PIECES) && (board[(x)][(y-1)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else
 {
  if ((board[(x)][(y+1)] < MAX_PIECES) && (board[(x-1)][(y)] < MAX_PIECES))
   return 0;
  return 1;
 }
}

canonical_original_code:
inline _Bool isSlidable(unsigned char x, unsigned char y, enum DIRECTIONS_e dir)
{
 if (NORTHEAST == dir)
 {
  if ((board[(x+1)][(y)] < MAX_PIECES) && (board[(x-1)][(y+1)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (EAST == dir)
 {
  if ((board[(x)][(y+1)] < MAX_PIECES) && (board[(x+1)][(y-1)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (SOUTHEAST == dir)
 {
  if ((board[(x)][(y-1)] < MAX_PIECES) && (board[(x+1)][(y)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (SOUTHWEST == dir)
 {
  if ((board[(x+1)][(y-1)] < MAX_PIECES) && (board[(x-1)][(y)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else if (WEST == dir)
 {
  if ((board[(x-1)][(y+1)] < MAX_PIECES) && (board[(x)][(y-1)] < MAX_PIECES))
   return 0;
  return 1;
 }
 else
 {
  if ((board[(x)][(y+1)] < MAX_PIECES) && (board[(x-1)][(y)] < MAX_PIECES))
   return 0;
  return 1;
 }
}

variable_types: enum DIRECTIONS_e { NORTHEAST=0, EAST=1, SOUTHEAST=2, SOUTHWEST=3, WEST=4, NORTHWEST=5, MAX_DIR=6 }


isTouchingCommonPiece

decompiled_code:
__int64 __fastcall isTouchingCommonPiece(unsigned __int8 a1, unsigned __int8 a2, int a3)
{
unsigned int v3; // ecx

if ( a3 )
{
switch ( a3 )
{
case 1:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] <= 0x15u;
break;
case 2:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] <= 0x15u;
break;
case 3:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] <= 0x15u;
break;
case 4:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] <= 0x15u;
break;
default:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] <= 0x15u;
break;
}
}
else
{
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] <= 0x15u;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1, unsigned __int8 a2, int a3)
{
unsigned int v3; // ecx

if ( a3 )
{
switch ( a3 )
{
case 1:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] <= 0x15u;
break;
case 2:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] <= 0x15u;
break;
case 3:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) - 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] <= 0x15u;
break;
case 4:
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (unsigned __int64)a1 - 1 + a2] <= 0x15u;
break;
default:
v3 = 1;
if ( (unsigned __int8)board[256 * (unsigned __int64)a1 + 1 + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + a2] <= 0x15u;
break;
}
}
else
{
v3 = 1;
if ( (unsigned __int8)board[256 * (__int64)(a1 + 1) + a2] > 0x15u )
LOBYTE(v3) = (unsigned __int8)board[256 * (__int64)(a1 - 1) + 1 + a2] <= 0x15u;
}
return v3;
}

original_code:
inline _Bool isTouchingCommonPiece(uint8_t x, uint8_t y, DIRECTIONS_e dir)
{
 if (NORTHEAST == dir)
 {
  if (board[(x+1)][(y)] < MAX_PIECES)
   return 1;
  else if (board[(x-1)][(y+1)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (EAST == dir)
 {
  if (board[(x)][(y+1)] < MAX_PIECES)
   return 1;
  else if (board[(x+1)][(y-1)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (SOUTHEAST == dir)
 {
  if (board[(x)][(y-1)] < MAX_PIECES)
   return 1;
  else if (board[(x+1)][(y)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (SOUTHWEST == dir)
 {
  if (board[(x+1)][(y-1)] < MAX_PIECES)
   return 1;
  else if (board[(x-1)][(y)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (WEST == dir)
 {
  if (board[(x-1)][(y+1)] < MAX_PIECES)
   return 1;
  else if (board[(x)][(y-1)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else
 {
  if (board[(x)][(y+1)] < MAX_PIECES)
   return 1;
  else if (board[(x-1)][(y)] < MAX_PIECES)
   return 1;
  return 0;
 }
}

canonical_original_code:
inline _Bool isTouchingCommonPiece(unsigned char x, unsigned char y, enum DIRECTIONS_e dir)
{
 if (NORTHEAST == dir)
 {
  if (board[(x+1)][(y)] < MAX_PIECES)
   return 1;
  else if (board[(x-1)][(y+1)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (EAST == dir)
 {
  if (board[(x)][(y+1)] < MAX_PIECES)
   return 1;
  else if (board[(x+1)][(y-1)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (SOUTHEAST == dir)
 {
  if (board[(x)][(y-1)] < MAX_PIECES)
   return 1;
  else if (board[(x+1)][(y)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (SOUTHWEST == dir)
 {
  if (board[(x+1)][(y-1)] < MAX_PIECES)
   return 1;
  else if (board[(x-1)][(y)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else if (WEST == dir)
 {
  if (board[(x-1)][(y+1)] < MAX_PIECES)
   return 1;
  else if (board[(x)][(y-1)] < MAX_PIECES)
   return 1;
  return 0;
 }
 else
 {
  if (board[(x)][(y+1)] < MAX_PIECES)
   return 1;
  else if (board[(x-1)][(y)] < MAX_PIECES)
   return 1;
  return 0;
 }
}

user_defined_types: enum DIRECTIONS_e { NORTHEAST=0, EAST=1, SOUTHEAST=2, SOUTHWEST=3, WEST=4, NORTHWEST=5, MAX_DIR=6 }


isTouchingOnlySameColor

decompiled_code:
bool __fastcall isTouchingOnlySameColor(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
int v4; // ebx
int v5; // er13
unsigned __int8 v6; // di
unsigned __int8 v7; // di
unsigned __int8 v8; // di
unsigned __int8 v9; // di
int v10; // ebp
unsigned __int8 v11; // di
unsigned __int8 v12; // di
bool result; // al
char v14; // dl
char v15; // dl
char v16; // dl
char v17; // dl
char v18; // dl

v4 = a3;
v5 = a3 + 1;
v6 = board[256 * (unsigned __int64)a2 + v5];
if ( v6 > 0x15u || (v14 = isWhite(v6), result = 0, v14 == a1) )
{
v7 = board[256 * (__int64)(a2 + 1) + v4];
if ( v7 > 0x15u || (v15 = isWhite(v7), result = 0, v15 == a1) )
{
v8 = board[256 * (__int64)(a2 + 1) - 1 + v4];
if ( v8 > 0x15u || (v16 = isWhite(v8), result = 0, v16 == a1) )
{
v9 = board[256 * (unsigned __int64)a2 - 1 + v4];
if ( v9 > 0x15u || (v17 = isWhite(v9), result = 0, v17 == a1) )
{
v10 = a2 - 1;
v11 = board[256 * (__int64)v10 + v4];
if ( v11 > 0x15u || (v18 = isWhite(v11), result = 0, v18 == a1) )
{
v12 = board[256 * (__int64)v10 + v5];
result = 1;
if ( v12 <= 0x15u )
result = (unsigned __int8)isWhite(v12) == a1;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func10(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
int v4; // ebx
int v5; // er13
unsigned __int8 v6; // di
unsigned __int8 v7; // di
unsigned __int8 v8; // di
unsigned __int8 v9; // di
int v10; // ebp
unsigned __int8 v11; // di
unsigned __int8 v12; // di
bool result; // al
char v14; // dl
char v15; // dl
char v16; // dl
char v17; // dl
char v18; // dl

v4 = a3;
v5 = a3 + 1;
v6 = board[256 * (unsigned __int64)a2 + v5];
if ( v6 > 0x15u || (v14 = isWhite(v6), result = 0, v14 == a1) )
{
v7 = board[256 * (__int64)(a2 + 1) + v4];
if ( v7 > 0x15u || (v15 = isWhite(v7), result = 0, v15 == a1) )
{
v8 = board[256 * (__int64)(a2 + 1) - 1 + v4];
if ( v8 > 0x15u || (v16 = isWhite(v8), result = 0, v16 == a1) )
{
v9 = board[256 * (unsigned __int64)a2 - 1 + v4];
if ( v9 > 0x15u || (v17 = isWhite(v9), result = 0, v17 == a1) )
{
v10 = a2 - 1;
v11 = board[256 * (__int64)v10 + v4];
if ( v11 > 0x15u || (v18 = isWhite(v11), result = 0, v18 == a1) )
{
v12 = board[256 * (__int64)v10 + v5];
result = 1;
if ( v12 <= 0x15u )
result = (unsigned __int8)isWhite(v12) == a1;
}
}
}
}
}
return result;
}

original_code:
_Bool isTouchingOnlySameColor(_Bool white, uint8_t x, uint8_t y)
{
 if (board[(x)][(y+1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x)][(y+1)]))
   return 0;
 }
 if (board[(x+1)][(y)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x+1)][(y)]))
   return 0;
 }
 if (board[(x+1)][(y-1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x+1)][(y-1)]))
   return 0;
 }
 if (board[(x)][(y-1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x)][(y-1)]))
   return 0;
 }
 if (board[(x-1)][(y)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x-1)][(y)]))
   return 0;
 }
 if (board[(x-1)][(y+1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x-1)][(y+1)]))
   return 0;
 }
 return 1;
}

canonical_original_code:
_Bool isTouchingOnlySameColor(_Bool white, unsigned char x, unsigned char y)
{
 if (board[(x)][(y+1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x)][(y+1)]))
   return 0;
 }
 if (board[(x+1)][(y)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x+1)][(y)]))
   return 0;
 }
 if (board[(x+1)][(y-1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x+1)][(y-1)]))
   return 0;
 }
 if (board[(x)][(y-1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x)][(y-1)]))
   return 0;
 }
 if (board[(x-1)][(y)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x-1)][(y)]))
   return 0;
 }
 if (board[(x-1)][(y+1)] < MAX_PIECES)
 {
  if (white != isWhite(board[(x-1)][(y+1)]))
   return 0;
 }
 return 1;
}


getTime

decompiled_code:
__int64 getTime()
{
return (unsigned int)(int)((double)(int)clock() * 1000.0 / 1000000.0);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)(int)((double)(int)clock() * 1000.0 / 1000000.0);
}

original_code:
int getTime()
{
    double timeTaken;
    clock_t mark;
    mark = clock();
 timeTaken = (double) mark;
 timeTaken = (1000 * timeTaken) / ((__clock_t) 1000000);
    return (int) timeTaken;
}

canonical_original_code:
int getTime()
{
    double timeTaken;
    long mark;
    mark = clock();
 timeTaken = (double) mark;
 timeTaken = (1000 * timeTaken) / ((long) 1000000);
    return (int) timeTaken;
}

variable_types: timeTaken double

variable_types: mark long

return_type: int


startTimer

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

result = getTime();
searchTime = result;
return result;
}

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

result = func0();
searchTime = result;
return result;
}

original_code:
void startTimer(void)
{
    searchTime = getTime();
}

canonical_original_code:
void startTimer()
{
    searchTime = getTime();
}


getSearchTime

decompiled_code:
__int64 getSearchTime()
{
return (unsigned int)getTime() - searchTime;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)func0() - searchTime;
}

original_code:
int getSearchTime(void)
{
 return (getTime() - searchTime);
}

canonical_original_code:
int getSearchTime()
{
 return (getTime() - searchTime);
}


canonical_original_code:
unsigned long rand64()
{
    return rand() ^ ((unsigned long)rand() << 15) ^ ((unsigned long)rand() << 30) ^
 ((unsigned long)rand() << 45) ^ ((unsigned long)rand() << 60);
}

return_type: unsigned long


probeHash

decompiled_code:
__int64 __fastcall probeHash(int a1, unsigned int a2, unsigned int a3)
{
unsigned __int64 v4; // rdx
__int64 result; // rax
int v6; // ecx

v4 = currentZobristKey % 0x2C0000uLL;
result = 0LL;
if ( currentZobristKey == hash_table[3 * (currentZobristKey % 0x2C0000uLL)]
&& SLODWORD(hash_table[3 * (currentZobristKey % 0x2C0000uLL) + 1]) >= a1 )
{
v6 = HIDWORD(hash_table[3 * (currentZobristKey % 0x2C0000uLL) + 1]);
if ( v6 == 1 )
{
result = LODWORD(hash_table[3 * (currentZobristKey % 0x2C0000uLL) + 2]);
}
else if ( v6 == 2 )
{
result = 0LL;
if ( SLODWORD(hash_table[3 * v4 + 2]) <= (signed int)a2 )
result = a2;
}
else
{
result = 0LL;
if ( v6 == 3 )
{
result = 0LL;
if ( SLODWORD(hash_table[3 * v4 + 2]) >= (signed int)a3 )
result = a3;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned int a2, unsigned int a3)
{
unsigned __int64 v4; // rdx
__int64 result; // rax
int v6; // ecx

v4 = currentZobristKey % 0x2C0000uLL;
result = 0LL;
if ( currentZobristKey == hash_table[3 * (currentZobristKey % 0x2C0000uLL)]
&& SLODWORD(hash_table[3 * (currentZobristKey % 0x2C0000uLL) + 1]) >= a1 )
{
v6 = HIDWORD(hash_table[3 * (currentZobristKey % 0x2C0000uLL) + 1]);
if ( v6 == 1 )
{
result = LODWORD(hash_table[3 * (currentZobristKey % 0x2C0000uLL) + 2]);
}
else if ( v6 == 2 )
{
result = 0LL;
if ( SLODWORD(hash_table[3 * v4 + 2]) <= (signed int)a2 )
result = a2;
}
else
{
result = 0LL;
if ( v6 == 3 )
{
result = 0LL;
if ( SLODWORD(hash_table[3 * v4 + 2]) >= (signed int)a3 )
result = a3;
}
}
}
return result;
}

original_code:
int probeHash(int depth, int alpha, int beta)
{
    HASH_t *hash = &hash_table[currentZobristKey % (2883584)];
    if (hash->key == currentZobristKey)
 {
        if (hash->depth >= depth)
  {
            if (hash->flags == 1)
                return hash->val;
            if ((hash->flags == 2) &&
                (hash->val <= alpha))
                return alpha;
            if ((hash->flags == 3) &&
                (hash->val >= beta))
                return beta;
        }
    }
    return 0;
}

canonical_original_code:
int probeHash(int depth, int alpha, int beta)
{
    struct HASH_t *hash = &hash_table[currentZobristKey % (2883584)];
    if (hash->key == currentZobristKey)
 {
        if (hash->depth >= depth)
  {
            if (hash->flags == 1)
                return hash->val;
            if ((hash->flags == 2) &&
                (hash->val <= alpha))
                return alpha;
            if ((hash->flags == 3) &&
                (hash->val >= beta))
                return beta;
        }
    }
    return 0;
}

variable_types: depth int

variable_types: alpha int

variable_types: beta int

variable_types: struct HASH_t { unsigned long key; int depth; int flags; int val; union MOVE_t { struct { unsigned int xpos; unsigned int ypos; enum PIECE_e { WHITE_QUEEN=0, WHITE_BEETLE_ONE=1, WHITE_BEETLE_TWO=2, WHITE_GRASSHOPPER_ONE=3, WHITE_GRASSHOPPER_TWO=4, WHITE_GRASSHOPPER_THREE=5, WHITE_ANT_ONE=6, WHITE_ANT_TWO=7, WHITE_ANT_THREE=8, WHITE_SPIDER_ONE=9, WHITE_SPIDER_TWO=10, BLACK_QUEEN=11, BLACK_BEETLE_ONE=12, BLACK_BEETLE_TWO=13, BLACK_GRASSHOPPER_ONE=14, BLACK_GRASSHOPPER_TWO=15, BLACK_GRASSHOPPER_THREE=16, BLACK_ANT_ONE=17, BLACK_ANT_TWO=18, BLACK_ANT_THREE=19, BLACK_SPIDER_ONE=20, BLACK_SPIDER_TWO=21, MAX_PIECES=22, EMPTY_SPACE=23 } piece; unsigned int reserved; } MOVE_BITS_t; unsigned int move; } best; } *

user_defined_types: struct HASH_t { unsigned long key; int depth; int flags; int val; union MOVE_t best; }

user_defined_types: union MOVE_t { struct { unsigned int xpos; unsigned int ypos; enum PIECE_e piece; unsigned int reserved; } MOVE_BITS_t; unsigned int move; }


recordHash

decompiled_code:
unsigned __int64 __fastcall recordHash(int a1, int a2, int a3)
{
unsigned __int64 v4; // rdx
unsigned __int64 result; // rax
unsigned __int64 v6; // rcx

v4 = currentZobristKey % 0x2C0000uLL;
result = 2 * (currentZobristKey % 0x2C0000uLL);
v6 = 3 * (currentZobristKey % 0x2C0000uLL);
hash_table[v6] = currentZobristKey;
LODWORD(hash_table[v6 + 2]) = a2;
HIDWORD(hash_table[v6 + 1]) = a3;
LODWORD(hash_table[result + 1 + v4]) = a1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(int a1, int a2, int a3)
{
unsigned __int64 v4; // rdx
unsigned __int64 result; // rax
unsigned __int64 v6; // rcx

v4 = currentZobristKey % 0x2C0000uLL;
result = 2 * (currentZobristKey % 0x2C0000uLL);
v6 = 3 * (currentZobristKey % 0x2C0000uLL);
hash_table[v6] = currentZobristKey;
LODWORD(hash_table[v6 + 2]) = a2;
HIDWORD(hash_table[v6 + 1]) = a3;
LODWORD(hash_table[result + 1 + v4]) = a1;
return result;
}

original_code:
void recordHash(int depth, int val, int flags)
{
    HASH_t *hash = &hash_table[currentZobristKey % (2883584)];
    hash->key = currentZobristKey;
    hash->val = val;
 hash->flags = flags;
    hash->depth = depth;
}

canonical_original_code:
void recordHash(int depth, int val, int flags)
{
    struct HASH_t *hash = &hash_table[currentZobristKey % (2883584)];
    hash->key = currentZobristKey;
    hash->val = val;
 hash->flags = flags;
    hash->depth = depth;
}

variable_types: val int

variable_types: flags int


getZobristKey

decompiled_code:
__int64 getZobristKey()
{
return currentZobristKey;
}

canonical_decompiled_code:
__int64 func3()
{
return currentZobristKey;
}

original_code:
uint64_t getZobristKey()
{
 return currentZobristKey;
}

canonical_original_code:
unsigned long getZobristKey()
{
 return currentZobristKey;
}


addPieceToZobristKey

decompiled_code:
__int64 __fastcall addPieceToZobristKey(unsigned int a1)
{
unsigned __int8 v1; // r12
unsigned __int8 v2; // bp
__int64 result; // rax

v1 = isWhite();
v2 = getXpos(a1);
result = (unsigned __int8)getYpos(a1) + ((v2 + ((a1 + 22LL * v1) << 8)) << 8);
currentZobristKey ^= zobrist[result] ^ blackToPlayKey;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned __int8 v1; // r12
unsigned __int8 v2; // bp
__int64 result; // rax

v1 = isWhite();
v2 = getXpos(a1);
result = (unsigned __int8)getYpos(a1) + ((v2 + ((a1 + 22LL * v1) << 8)) << 8);
currentZobristKey ^= zobrist[result] ^ blackToPlayKey;
return result;
}

original_code:
void addPieceToZobristKey(PIECE_e piece)
{
 uint8_t colour, x, y;
 colour = isWhite(piece);
 x = getXpos(piece);
 y = getYpos(piece);
 currentZobristKey ^= zobrist[colour][piece][x][y];
 currentZobristKey ^= blackToPlayKey;
}

canonical_original_code:
void addPieceToZobristKey(enum PIECE_e piece)
{
 unsigned char colour; unsigned char x; unsigned char y;
 colour = isWhite(piece);
 x = getXpos(piece);
 y = getYpos(piece);
 currentZobristKey ^= zobrist[colour][piece][x][y];
 currentZobristKey ^= blackToPlayKey;
}

variable_types:
colour
unsigned char

variable_types:
x
unsigned char

variable_types:
y
unsigned char


zobristInit

decompiled_code:
__int64 zobristInit()
{
__int64 v0; // r15
__int64 v1; // r13
__int64 v2; // r14
_QWORD *v3; // r12
_QWORD *v4; // rbp
_QWORD *v5; // rbx
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-40h]

v0 = (unsigned int)((_DWORD)zobrist + 2048);
v1 = 0LL;
do
{
v2 = v1 << 8;
v1 += 22LL;
v7 = v2 + 5632;
v3 = (_QWORD *)v0;
do
{
v4 = v3;
v3 += 0x10000;
do
{
v5 = v4 - 256;
do
*v5++ = rand64();
while ( v5 != v4 );
v4 += 256;
}
while ( v4 != v3 );
v2 += 256LL;
}
while ( v2 != v7 );
v0 += 11534336LL;
}
while ( v1 != 44 );
result = rand64();
blackToPlayKey = result;
currentZobristKey = 0LL;
cacheHits = 0;
cacheMisses = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // r15
__int64 v1; // r13
__int64 v2; // r14
_QWORD *v3; // r12
_QWORD *v4; // rbp
_QWORD *v5; // rbx
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-40h]

v0 = (unsigned int)((_DWORD)zobrist + 2048);
v1 = 0LL;
do
{
v2 = v1 << 8;
v1 += 22LL;
v7 = v2 + 5632;
v3 = (_QWORD *)v0;
do
{
v4 = v3;
v3 += 0x10000;
do
{
v5 = v4 - 256;
do
*v5++ = func0();
while ( v5 != v4 );
v4 += 256;
}
while ( v4 != v3 );
v2 += 256LL;
}
while ( v2 != v7 );
v0 += 11534336LL;
}
while ( v1 != 44 );
result = func0();
blackToPlayKey = result;
currentZobristKey = 0LL;
cacheHits = 0;
cacheMisses = 0;
return result;
}

original_code:
void zobristInit(void)
{
 uint32_t colour, piece, x, y;
 for (colour = 0; colour < MAX_COLOURS; colour++)
 {
  for (piece = 0; piece < MAX_PIECES; piece++)
  {
   for (x = 0; x < (256); x++)
   {
    for (y = 0; y < (256); y++)
    {
     zobrist[colour][piece][x][y] = rand64();
    }
   }
  }
 }
 blackToPlayKey = rand64();
 currentZobristKey = 0;
 cacheHits = 0;
 cacheMisses = 0;
}

canonical_original_code:
void zobristInit()
{
 unsigned int colour; unsigned int piece; unsigned int x; unsigned int y;
 for (colour = 0; colour < MAX_COLOURS; colour++)
 {
  for (piece = 0; piece < MAX_PIECES; piece++)
  {
   for (x = 0; x < (256); x++)
   {
    for (y = 0; y < (256); y++)
    {
     zobrist[colour][piece][x][y] = rand64();
    }
   }
  }
 }
 blackToPlayKey = rand64();
 currentZobristKey = 0;
 cacheHits = 0;
 cacheMisses = 0;
}

variable_types:
colour
unsigned int

variable_types:
piece
unsigned int

variable_types:
x
unsigned int

variable_types:
y
unsigned int


evaluateBoard

decompiled_code:
__int64 __fastcall evaluateBoard(__int64 a1)
{
unsigned int v1; // ebx
int v2; // er15
int v3; // er12
int v4; // er14
unsigned int v5; // ebp
int v6; // eax
unsigned int v7; // er14
unsigned __int8 v9; // bl
unsigned __int8 v10; // al
char v11; // al
unsigned __int8 v12; // bl
unsigned __int8 v13; // al
char v14; // al

v1 = 1;
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = v1 - 1;
if ( !(unsigned __int8)hasPieceBeenPlayed(v1 - 1) )
break;
v6 = *(_DWORD *)(a1 + 4LL * v5);
if ( !v6 )
v4 += pinnedMap[v5];
if ( v5 > 0xA )
{
v2 += v6;
break;
}
v3 += v6;
LABEL_4:
++v1;
}
if ( v1 <= 0x15 )
goto LABEL_4;
v7 = 5 * (v3 - v2) + v4;
if ( (unsigned __int8)hasPieceBeenPlayed(0LL) )
{
v9 = getXpos(0LL);
v10 = getYpos(0LL);
v11 = getNumberOfOccupiedSquaresAroundCoords(v9, v10);
switch ( v11 )
{
case 5:
v7 -= 4000;
break;
case 4:
v7 -= 2000;
break;
case 3:
v7 -= 400;
break;
}
}
if ( (unsigned __int8)hasPieceBeenPlayed(11LL) )
{
v12 = getXpos(11LL);
v13 = getYpos(11LL);
v14 = getNumberOfOccupiedSquaresAroundCoords(v12, v13);
switch ( v14 )
{
case 5:
v7 += 4000;
break;
case 4:
v7 += 2000;
break;
case 3:
v7 += 400;
break;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
int v2; // er15
int v3; // er12
int v4; // er14
unsigned int v5; // ebp
int v6; // eax
unsigned int v7; // er14
unsigned __int8 v9; // bl
unsigned __int8 v10; // al
char v11; // al
unsigned __int8 v12; // bl
unsigned __int8 v13; // al
char v14; // al

v1 = 1;
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = v1 - 1;
if ( !(unsigned __int8)hasPieceBeenPlayed(v1 - 1) )
break;
v6 = *(_DWORD *)(a1 + 4LL * v5);
if ( !v6 )
v4 += pinnedMap[v5];
if ( v5 > 0xA )
{
v2 += v6;
break;
}
v3 += v6;
LABEL_4:
++v1;
}
if ( v1 <= 0x15 )
goto LABEL_4;
v7 = 5 * (v3 - v2) + v4;
if ( (unsigned __int8)hasPieceBeenPlayed(0LL) )
{
v9 = getXpos(0LL);
v10 = getYpos(0LL);
v11 = getNumberOfOccupiedSquaresAroundCoords(v9, v10);
switch ( v11 )
{
case 5:
v7 -= 4000;
break;
case 4:
v7 -= 2000;
break;
case 3:
v7 -= 400;
break;
}
}
if ( (unsigned __int8)hasPieceBeenPlayed(11LL) )
{
v12 = getXpos(11LL);
v13 = getYpos(11LL);
v14 = getNumberOfOccupiedSquaresAroundCoords(v12, v13);
switch ( v14 )
{
case 5:
v7 += 4000;
break;
case 4:
v7 += 2000;
break;
case 3:
v7 += 400;
break;
}
}
return v7;
}

original_code:
int evaluateBoard(EVALUATE_INFO_t *eval)
{
 int score = 0;
 uint8_t x, y, occupied;
 PIECE_e i;
 int whiteMovesForPlayedPieces = 0;
 int blackMovesForPlayedPieces = 0;
 for (i = WHITE_QUEEN; i < MAX_PIECES; i++)
 {
  if (hasPieceBeenPlayed(i))
  {
   if (eval->validMoves[i] == 0)
   {
    score += pinnedMap[i];
   }
   if (i < BLACK_QUEEN)
   {
    whiteMovesForPlayedPieces += eval->validMoves[i];
   }
   else
   {
    blackMovesForPlayedPieces += eval->validMoves[i];
   }
  }
 }
 score += (whiteMovesForPlayedPieces - blackMovesForPlayedPieces) * 5;
 if (hasPieceBeenPlayed(WHITE_QUEEN))
 {
  x = getXpos(WHITE_QUEEN);
  y = getYpos(WHITE_QUEEN);
  occupied = getNumberOfOccupiedSquaresAroundCoords(x, y);
  if (occupied == 5)
  {
   score -= (4000);
  }
  else if (occupied == 4)
  {
   score -= (2000);
  }
  else if (occupied == 3)
  {
   score -= (400);
  }
  else if (occupied == 2)
  {
   score -= (0);
  }
 }
 if (hasPieceBeenPlayed(BLACK_QUEEN))
 {
  x = getXpos(BLACK_QUEEN);
  y = getYpos(BLACK_QUEEN);
  occupied = getNumberOfOccupiedSquaresAroundCoords(x, y);
  if (occupied == 5)
  {
   score += (4000);
  }
  else if (occupied == 4)
  {
   score += (2000);
  }
  else if (occupied == 3)
  {
   score += (400);
  }
  else if (occupied == 2)
  {
   score += (0);
  }
 }
 return score;
}

canonical_original_code:
int evaluateBoard(struct EVALUATE_INFO_t *eval)
{
 int score = 0;
 unsigned char x; unsigned char y; unsigned char occupied;
 enum PIECE_e i;
 int whiteMovesForPlayedPieces = 0;
 int blackMovesForPlayedPieces = 0;
 for (i = WHITE_QUEEN; i < MAX_PIECES; i++)
 {
  if (hasPieceBeenPlayed(i))
  {
   if (eval->validMoves[i] == 0)
   {
    score += pinnedMap[i];
   }
   if (i < BLACK_QUEEN)
   {
    whiteMovesForPlayedPieces += eval->validMoves[i];
   }
   else
   {
    blackMovesForPlayedPieces += eval->validMoves[i];
   }
  }
 }
 score += (whiteMovesForPlayedPieces - blackMovesForPlayedPieces) * 5;
 if (hasPieceBeenPlayed(WHITE_QUEEN))
 {
  x = getXpos(WHITE_QUEEN);
  y = getYpos(WHITE_QUEEN);
  occupied = getNumberOfOccupiedSquaresAroundCoords(x, y);
  if (occupied == 5)
  {
   score -= (4000);
  }
  else if (occupied == 4)
  {
   score -= (2000);
  }
  else if (occupied == 3)
  {
   score -= (400);
  }
  else if (occupied == 2)
  {
   score -= (0);
  }
 }
 if (hasPieceBeenPlayed(BLACK_QUEEN))
 {
  x = getXpos(BLACK_QUEEN);
  y = getYpos(BLACK_QUEEN);
  occupied = getNumberOfOccupiedSquaresAroundCoords(x, y);
  if (occupied == 5)
  {
   score += (4000);
  }
  else if (occupied == 4)
  {
   score += (2000);
  }
  else if (occupied == 3)
  {
   score += (400);
  }
  else if (occupied == 2)
  {
   score += (0);
  }
 }
 return score;
}

variable_types: struct EVALUATE_INFO_t { unsigned int validMoves[-1]; unsigned int whiteMoves; unsigned int blackMoves; } *

variable_types: score int

variable_types:
occupied
unsigned char

variable_types: enum PIECE_e { WHITE_QUEEN=0, WHITE_BEETLE_ONE=1, WHITE_BEETLE_TWO=2, WHITE_GRASSHOPPER_ONE=3, WHITE_GRASSHOPPER_TWO=4, WHITE_GRASSHOPPER_THREE=5, WHITE_ANT_ONE=6, WHITE_ANT_TWO=7, WHITE_ANT_THREE=8, WHITE_SPIDER_ONE=9, WHITE_SPIDER_TWO=10, BLACK_QUEEN=11, BLACK_BEETLE_ONE=12, BLACK_BEETLE_TWO=13, BLACK_GRASSHOPPER_ONE=14, BLACK_GRASSHOPPER_TWO=15, BLACK_GRASSHOPPER_THREE=16, BLACK_ANT_ONE=17, BLACK_ANT_TWO=18, BLACK_ANT_THREE=19, BLACK_SPIDER_ONE=20, BLACK_SPIDER_TWO=21, MAX_PIECES=22, EMPTY_SPACE=23 }

variable_types: whiteMovesForPlayedPieces int

variable_types: blackMovesForPlayedPieces int


initPinnedMap

decompiled_code:
void initPinnedMap()
{
pinnedMap[0] = -400;
pinnedMap[1] = -80;
pinnedMap[2] = -80;
pinnedMap[3] = -40;
pinnedMap[4] = -40;
pinnedMap[5] = -40;
pinnedMap[6] = -50;
pinnedMap[7] = -50;
pinnedMap[9] = -30;
pinnedMap[10] = -30;
pinnedMap[11] = 400;
pinnedMap[12] = 80;
pinnedMap[13] = 80;
pinnedMap[14] = 40;
pinnedMap[15] = 40;
pinnedMap[16] = 40;
pinnedMap[17] = 50;
pinnedMap[18] = 50;
pinnedMap[20] = 30;
pinnedMap[21] = 30;
}

canonical_decompiled_code:
void func1()
{
pinnedMap[0] = -400;
pinnedMap[1] = -80;
pinnedMap[2] = -80;
pinnedMap[3] = -40;
pinnedMap[4] = -40;
pinnedMap[5] = -40;
pinnedMap[6] = -50;
pinnedMap[7] = -50;
pinnedMap[9] = -30;
pinnedMap[10] = -30;
pinnedMap[11] = 400;
pinnedMap[12] = 80;
pinnedMap[13] = 80;
pinnedMap[14] = 40;
pinnedMap[15] = 40;
pinnedMap[16] = 40;
pinnedMap[17] = 50;
pinnedMap[18] = 50;
pinnedMap[20] = 30;
pinnedMap[21] = 30;
}

original_code:
void initPinnedMap(void)
{
 pinnedMap[WHITE_QUEEN] = -(400);
 pinnedMap[WHITE_BEETLE_ONE] = -(80);
 pinnedMap[WHITE_BEETLE_TWO] = -(80);
 pinnedMap[WHITE_GRASSHOPPER_ONE] = -(40);
 pinnedMap[WHITE_GRASSHOPPER_TWO] = -(40);
 pinnedMap[WHITE_GRASSHOPPER_THREE] = -(40);
 pinnedMap[WHITE_ANT_ONE] = -(50);
 pinnedMap[WHITE_ANT_TWO] = -(50);
 pinnedMap[WHITE_ANT_TWO] = -(50);
 pinnedMap[WHITE_SPIDER_ONE] = -(30);
 pinnedMap[WHITE_SPIDER_TWO] = -(30);
 pinnedMap[BLACK_QUEEN] = (400);
 pinnedMap[BLACK_BEETLE_ONE] = (80);
 pinnedMap[BLACK_BEETLE_TWO] = (80);
 pinnedMap[BLACK_GRASSHOPPER_ONE] = (40);
 pinnedMap[BLACK_GRASSHOPPER_TWO] = (40);
 pinnedMap[BLACK_GRASSHOPPER_THREE] = (40);
 pinnedMap[BLACK_ANT_ONE] = (50);
 pinnedMap[BLACK_ANT_TWO] = (50);
 pinnedMap[BLACK_ANT_TWO] = (50);
 pinnedMap[BLACK_SPIDER_ONE] = (30);
 pinnedMap[BLACK_SPIDER_TWO] = (30);
}

canonical_original_code:
void initPinnedMap()
{
 pinnedMap[WHITE_QUEEN] = -(400);
 pinnedMap[WHITE_BEETLE_ONE] = -(80);
 pinnedMap[WHITE_BEETLE_TWO] = -(80);
 pinnedMap[WHITE_GRASSHOPPER_ONE] = -(40);
 pinnedMap[WHITE_GRASSHOPPER_TWO] = -(40);
 pinnedMap[WHITE_GRASSHOPPER_THREE] = -(40);
 pinnedMap[WHITE_ANT_ONE] = -(50);
 pinnedMap[WHITE_ANT_TWO] = -(50);
 pinnedMap[WHITE_ANT_TWO] = -(50);
 pinnedMap[WHITE_SPIDER_ONE] = -(30);
 pinnedMap[WHITE_SPIDER_TWO] = -(30);
 pinnedMap[BLACK_QUEEN] = (400);
 pinnedMap[BLACK_BEETLE_ONE] = (80);
 pinnedMap[BLACK_BEETLE_TWO] = (80);
 pinnedMap[BLACK_GRASSHOPPER_ONE] = (40);
 pinnedMap[BLACK_GRASSHOPPER_TWO] = (40);
 pinnedMap[BLACK_GRASSHOPPER_THREE] = (40);
 pinnedMap[BLACK_ANT_ONE] = (50);
 pinnedMap[BLACK_ANT_TWO] = (50);
 pinnedMap[BLACK_ANT_TWO] = (50);
 pinnedMap[BLACK_SPIDER_ONE] = (30);
 pinnedMap[BLACK_SPIDER_TWO] = (30);
}


parseTimeString

decompiled_code:
__int64 __fastcall parseTimeString(char *a1)
{
char *v1; // rbx
char *v2; // r12
char *v3; // rbp
__int64 v4; // rbx
__int64 result; // rax

strtok(a1, "=,");
v1 = strtok(0LL, ",");
v2 = strtok(0LL, ",");
v3 = strtok(0LL, ",");
v4 = atol(v1) / 2;
totalGameTimePerPlayer = v4;
whiteRemainingTime = v4 - atol(v2);
result = atol(v3);
blackRemainingTime = v4 - result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char *v1; // rbx
char *v2; // r12
char *v3; // rbp
__int64 v4; // rbx
__int64 result; // rax

strtok(a1, "=,");
v1 = strtok(0LL, ",");
v2 = strtok(0LL, ",");
v3 = strtok(0LL, ",");
v4 = atol(v1) / 2;
totalGameTimePerPlayer = v4;
whiteRemainingTime = v4 - atol(v2);
result = atol(v3);
blackRemainingTime = v4 - result;
return result;
}

original_code:
void parseTimeString(char* timeString)
{
 char* totalTime;
 char* whiteUsedTime;
 char* blackUsedTime;
 totalTime = strtok(timeString, "=,");
 totalTime = strtok(((void *)0), ",");
 whiteUsedTime = strtok(((void *)0), ",");
 blackUsedTime = strtok(((void *)0), ",");
 totalGameTimePerPlayer = (uint32_t) (atol(totalTime) / 2);
 whiteRemainingTime = totalGameTimePerPlayer - (uint32_t)atol(whiteUsedTime);
 blackRemainingTime = totalGameTimePerPlayer - (uint32_t)atol(blackUsedTime);
}

canonical_original_code:
void parseTimeString(char *timeString)
{
 char *totalTime;
 char *whiteUsedTime;
 char *blackUsedTime;
 totalTime = strtok(timeString, "=,");
 totalTime = strtok(((void *)0), ",");
 whiteUsedTime = strtok(((void *)0), ",");
 blackUsedTime = strtok(((void *)0), ",");
 totalGameTimePerPlayer = (unsigned int) (atol(totalTime) / 2);
 whiteRemainingTime = totalGameTimePerPlayer - (unsigned int)atol(whiteUsedTime);
 blackRemainingTime = totalGameTimePerPlayer - (unsigned int)atol(blackUsedTime);
}

variable_types:
timeString
char *

variable_types:
totalTime
char *

variable_types:
whiteUsedTime
char *

variable_types:
blackUsedTime
char *


isWin

decompiled_code:
__int64 isWin()
{
unsigned __int8 v0; // bl
unsigned __int8 v1; // al
bool v2; // r12
unsigned int v3; // ebp
unsigned __int8 v4; // bl
unsigned __int8 v5; // al

v0 = getXpos(0LL);
v1 = getYpos(0LL);
v2 = (unsigned __int8)getNumberOfOccupiedSquaresAroundCoords(v0, v1) == 6;
v3 = 0;
if ( v2 )
v3 = -10000;
v4 = getXpos(11LL);
v5 = getYpos(11LL);
if ( (unsigned __int8)getNumberOfOccupiedSquaresAroundCoords(v4, v5) == 6 )
v3 = !v2 ? 10000 : 1;
return v3;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int8 v0; // bl
unsigned __int8 v1; // al
bool v2; // r12
unsigned int v3; // ebp
unsigned __int8 v4; // bl
unsigned __int8 v5; // al

v0 = getXpos(0LL);
v1 = getYpos(0LL);
v2 = (unsigned __int8)getNumberOfOccupiedSquaresAroundCoords(v0, v1) == 6;
v3 = 0;
if ( v2 )
v3 = -10000;
v4 = getXpos(11LL);
v5 = getYpos(11LL);
if ( (unsigned __int8)getNumberOfOccupiedSquaresAroundCoords(v4, v5) == 6 )
v3 = !v2 ? 10000 : 1;
return v3;
}

original_code:
int isWin(void)
{
 int winScore = 0;
 uint8_t xpos, ypos;
 _Bool blackwin = 0;
 xpos = getXpos(WHITE_QUEEN);
 ypos = getYpos(WHITE_QUEEN);
 if (6 == getNumberOfOccupiedSquaresAroundCoords(xpos, ypos))
 {
  winScore = (-10000);
  blackwin = 1;
 }
 xpos = getXpos(BLACK_QUEEN);
 ypos = getYpos(BLACK_QUEEN);
 if (6 == getNumberOfOccupiedSquaresAroundCoords(xpos, ypos))
 {
  winScore = (10000);
  if (blackwin)
   winScore = (1);
 }
 return winScore;
}

canonical_original_code:
int isWin()
{
 int winScore = 0;
 unsigned char xpos; unsigned char ypos;
 _Bool blackwin = 0;
 xpos = getXpos(WHITE_QUEEN);
 ypos = getYpos(WHITE_QUEEN);
 if (6 == getNumberOfOccupiedSquaresAroundCoords(xpos, ypos))
 {
  winScore = (-10000);
  blackwin = 1;
 }
 xpos = getXpos(BLACK_QUEEN);
 ypos = getYpos(BLACK_QUEEN);
 if (6 == getNumberOfOccupiedSquaresAroundCoords(xpos, ypos))
 {
  winScore = (10000);
  if (blackwin)
   winScore = (1);
 }
 return winScore;
}

variable_types: winScore int

variable_types:
xpos
unsigned char

variable_types:
ypos
unsigned char


repo: yeison/banker-s

decompiled_code:
__int64 __fastcall pop_back(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx
__int64 v3; // rax

v1 = *a1;
if ( !*a1 )
return 0;
v2 = *v1;
if ( v1 == a1[1] )
{
a1[1] = 0LL;
*a1 = 0LL;
}
else
{
v3 = *((_QWORD *)v1 + 1);
*a1 = (unsigned int *)v3;
*(_QWORD *)(v3 + 16) = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx
__int64 v3; // rax

v1 = *a1;
if ( !*a1 )
return 0;
v2 = *v1;
if ( v1 == a1[1] )
{
a1[1] = 0LL;
*a1 = 0LL;
}
else
{
v3 = *((_QWORD *)v1 + 1);
*a1 = (unsigned int *)v3;
*(_QWORD *)(v3 + 16) = 0LL;
}
return v2;
}

original_code:
int pop_back( queue *queue ){
    if(queue->head == ((void *)0)){
        return ((void *)0);
    }
    int value = queue->head->value;
    queue_int *head = queue->head;
    if (queue->head == queue->tail) {
        queue->head = queue->tail = ((void *)0);
    } else {
        queue->head = head->next;
        queue->head->previous = ((void *)0);
    }
    return value;
}

canonical_original_code:
int pop_back(struct queue *queue){
    if(queue->head == ((void *)0)){
        return ((void *)0);
    }
    int value = queue->head->value;
    struct queue_int *head = queue->head;
    if (queue->head == queue->tail) {
        queue->head = queue->tail = ((void *)0);
    } else {
        queue->head = head->next;
        queue->head->previous = ((void *)0);
    }
    return value;
}

variable_types: struct queue { struct queue_int { int value; struct queue_int *next; struct queue_int *previous; } *head; struct queue_int *tail; } *

variable_types: value int

user_defined_types: struct queue { struct queue_int *head; struct queue_int *tail; }


decompiled_code:
__int64 __fastcall pop_front(int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx
__int64 v3; // rax

v1 = (unsigned int *)a1[1];
if ( !v1 )
return 0;
v2 = *v1;
if ( v1 == (unsigned int *)*a1 )
{
a1[1] = 0LL;
*a1 = 0LL;
}
else
{
v3 = *((_QWORD *)v1 + 2);
a1[1] = (int *)v3;
*(_QWORD *)(v3 + 8) = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx
__int64 v3; // rax

v1 = (unsigned int *)a1[1];
if ( !v1 )
return 0;
v2 = *v1;
if ( v1 == (unsigned int *)*a1 )
{
a1[1] = 0LL;
*a1 = 0LL;
}
else
{
v3 = *((_QWORD *)v1 + 2);
a1[1] = (int *)v3;
*(_QWORD *)(v3 + 8) = 0LL;
}
return v2;
}

original_code:
int pop_front( queue *queue ){
    if(queue->tail == ((void *)0)){
        return ((void *)0);
    }
    int value = queue->tail->value;
    queue_int *tail = queue->tail;
    if (queue->head == queue->tail) {
        queue->head = queue->tail = ((void *)0);
    } else {
        queue->tail = tail->previous;
        queue->tail->next = ((void *)0);
    }
    return value;
}

canonical_original_code:
int pop_front(struct queue *queue){
    if(queue->tail == ((void *)0)){
        return ((void *)0);
    }
    int value = queue->tail->value;
    struct queue_int *tail = queue->tail;
    if (queue->head == queue->tail) {
        queue->head = queue->tail = ((void *)0);
    } else {
        queue->tail = tail->previous;
        queue->tail->next = ((void *)0);
    }
    return value;
}

variable_types: struct queue_int { int value; struct queue_int *next; struct queue_int *previous; } *


decompiled_code:
bool __fastcall is_empty(_QWORD *a1)
{
bool result; // al

result = 0;
if ( !*a1 )
result = a1[1] == 0LL;
return result;
}

canonical_decompiled_code:
bool __fastcall func2(_QWORD *a1)
{
bool result; // al

result = 0;
if ( !*a1 )
result = a1[1] == 0LL;
return result;
}

original_code:
_Bool is_empty( queue *queue ){
    if (queue->head == ((void *)0) && queue->tail == ((void *)0)) {
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool is_empty(struct queue *queue){
    if (queue->head == ((void *)0) && queue->tail == ((void *)0)) {
        return 1;
    }
    return 0;
}

user_defined_types: struct queue_int { int value; struct queue_int *next; struct queue_int *previous; }


printQueues

decompiled_code:
void __fastcall printQueues(__int64 a1, int a2)
{
__int64 v2; // r13
__int64 i; // rbx
unsigned int v4; // er12
unsigned int v5; // ebp
const char *v6; // rax

if ( a2 > 0 )
{
v2 = 1LL;
do
{
printf("\nTask %d:\n", (unsigned int)v2);
for ( i = *(_QWORD *)(a1 + 8 * v2 - 8); i; i = *(_QWORD *)(i + 24) )
{
v4 = *(_DWORD *)(i + 16);
v5 = *(_DWORD *)(i + 12) + 1;
v6 = (const char *)getActivityType(*(unsigned int *)(i + 8));
printf("\t%2d %2d %10s %2d %2d\n", (unsigned int)(*(_DWORD *)i + 1), *(unsigned int *)(i + 4), v6, v5, v4);
}
++v2;
}
while ( v2 != a2 + 1 );
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // r13
__int64 i; // rbx
unsigned int v4; // er12
unsigned int v5; // ebp
const char *v6; // rax

if ( a2 > 0 )
{
v2 = 1LL;
do
{
printf("\nTask %d:\n", (unsigned int)v2);
for ( i = *(_QWORD *)(a1 + 8 * v2 - 8); i; i = *(_QWORD *)(i + 24) )
{
v4 = *(_DWORD *)(i + 16);
v5 = *(_DWORD *)(i + 12) + 1;
v6 = (const char *)getActivityType(*(unsigned int *)(i + 8));
printf("\t%2d %2d %10s %2d %2d\n", (unsigned int)(*(_DWORD *)i + 1), *(unsigned int *)(i + 4), v6, v5, v4);
}
++v2;
}
while ( v2 != a2 + 1 );
}
}

original_code:
void printQueues(activity** taskTable, int numberOfTasks){
    for (int i=0; i < numberOfTasks; i++) {
        printf("\nTask %d:\n", i+1);
        activity *tempActivity = taskTable[i];
        while (tempActivity != ((void *)0)) {
            printf("\t%2d %2d %10s %2d %2d\n",
                   tempActivity->taskNumber+1,
                   tempActivity->delay,
                   getActivityType(tempActivity->type),
                   tempActivity->resourceType+1,
                   tempActivity->resourceAmount);
            tempActivity = tempActivity->next;
        }
    }
}

canonical_original_code:
void printQueues(struct activity **taskTable, int numberOfTasks){
    for (int i = 0; i < numberOfTasks; i++) {
        printf("\nTask %d:\n", i+1);
        struct activity *tempActivity = taskTable[i];
        while (tempActivity != ((void *)0)) {
            printf("\t%2d %2d %10s %2d %2d\n",
                   tempActivity->taskNumber+1,
                   tempActivity->delay,
                   getActivityType(tempActivity->type),
                   tempActivity->resourceType+1,
                   tempActivity->resourceAmount);
            tempActivity = tempActivity->next;
        }
    }
}

variable_types: struct activity { int taskNumber; int delay; int type; int resourceType; int resourceAmount; int currentState; struct activity *next; } **

variable_types: numberOfTasks int

variable_types: i int


getActivityTypeValue

decompiled_code:
__int64 __fastcall getActivityTypeValue(const char *a1)
{
if ( !strcmp(a1, "initiate") )
return 2LL;
if ( !strcmp(a1, "request") )
return 3LL;
if ( !strcmp(a1, "release") )
return 4LL;
if ( strcmp(a1, "terminate") )
{
perror("Activity type requested is unknown. Please use proper formatting.");
exit(2);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
if ( !strcmp(a1, "initiate") )
return 2LL;
if ( !strcmp(a1, "request") )
return 3LL;
if ( !strcmp(a1, "release") )
return 4LL;
if ( strcmp(a1, "terminate") )
{
perror("Activity type requested is unknown. Please use proper formatting.");
exit(2);
}
return 1LL;
}

original_code:
int getActivityTypeValue(char *type){
 if(!strcmp(type, "initiate"))
  return 2;
 else if(!strcmp(type, "request"))
  return 3;
 else if(!strcmp(type, "release"))
  return 4;
 else if(!strcmp(type, "terminate"))
  return 1;
 else {
  perror("Activity type requested is unknown.  Please use proper formatting.");
  exit(2);
 }
}

variable_types:
type
char *


makeActivityQueues

decompiled_code:
__int64 __fastcall makeActivityQueues(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
_DWORD *v4; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
result = _isoc99_scanf("%d", v5);
if ( (_DWORD)result == -1 )
break;
v3 = *(_QWORD *)(a2 + 8LL * v5[0] - 8);
v4 = makeActivityNode(v5[0] - 1);
if ( v3 )
*(_QWORD *)(v3 + 24) = v4;
else
*(_QWORD *)(a1 + 8LL * v5[0] - 8) = v4;
*(_QWORD *)(a2 + 8LL * v5[0] - 8) = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
_DWORD *v4; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
result = _isoc99_scanf("%d", v5);
if ( (_DWORD)result == -1 )
break;
v3 = *(_QWORD *)(a2 + 8LL * v5[0] - 8);
v4 = makeActivityNode(v5[0] - 1);
if ( v3 )
*(_QWORD *)(v3 + 24) = v4;
else
*(_QWORD *)(a1 + 8LL * v5[0] - 8) = v4;
*(_QWORD *)(a2 + 8LL * v5[0] - 8) = v4;
}
return result;
}

original_code:
void makeActivityQueues(activity *taskTable[], activity *taskTableTails[]){
 int currentTask;
 activity *currentActivityPtr;
 while(scanf("%d", &currentTask) != (-1)){
        if (taskTableTails[currentTask-1]){
            currentActivityPtr = taskTableTails[currentTask-1];
            currentActivityPtr->next = makeActivityNode(currentTask-1);
            currentActivityPtr = currentActivityPtr->next;
        }
        else {
            currentActivityPtr = makeActivityNode(currentTask-1);
            taskTable[currentTask-1] = currentActivityPtr;
        }
        taskTableTails[currentTask-1] = currentActivityPtr;
    }
}

canonical_original_code:
void makeActivityQueues(struct activity *taskTable[], struct activity *taskTableTails[]){
 int currentTask;
 struct activity *currentActivityPtr;
 while(scanf("%d", &currentTask) != (-1)){
        if (taskTableTails[currentTask-1]){
            currentActivityPtr = taskTableTails[currentTask-1];
            currentActivityPtr->next = makeActivityNode(currentTask-1);
            currentActivityPtr = currentActivityPtr->next;
        }
        else {
            currentActivityPtr = makeActivityNode(currentTask-1);
            taskTable[currentTask-1] = currentActivityPtr;
        }
        taskTableTails[currentTask-1] = currentActivityPtr;
    }
}

variable_types: struct activity { int taskNumber; int delay; int type; int resourceType; int resourceAmount; int currentState; struct activity *next; } *[]

variable_types:
taskTableTails
struct activity *[]

variable_types: currentTask int


getActivityType

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

if ( a1 == 3 )
return "request";
if ( a1 > 3 )
{
result = (const char *)&unk_1F9;
if ( a1 == 4 )
result = "release";
}
else
{
result = "terminate";
if ( a1 != 1 )
{
result = (const char *)&unk_1F9;
if ( a1 == 2 )
result = "initiate";
}
}
return result;
}

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

if ( a1 == 3 )
return "request";
if ( a1 > 3 )
{
result = (const char *)&unk_1F9;
if ( a1 == 4 )
result = "release";
}
else
{
result = "terminate";
if ( a1 != 1 )
{
result = (const char *)&unk_1F9;
if ( a1 == 2 )
result = "initiate";
}
}
return result;
}

original_code:
char* getActivityType(int activityTypeValue){
    switch (activityTypeValue) {
        case 2:
            return "initiate";
        case 3:
            return "request";
        case 4:
            return "release";
        case 1:
            return "terminate";
        default:
            return "";
    }
}

canonical_original_code:
char *getActivityType(int activityTypeValue){
    switch (activityTypeValue) {
        case 2:
            return "initiate";
        case 3:
            return "request";
        case 4:
            return "release";
        case 1:
            return "terminate";
        default:
            return "";
    }
}

variable_types: activityTypeValue int

return_type: char *


repo: yrutschle/sslh

decompiled_code:
int __fastcall stop_listeners(int sig)
{
__int64 v1; // rbp
__int64 v2; // rbx
int result; // eax

if ( listener_pid_number > 0 )
{
v1 = 4LL * (unsigned int)listener_pid_number;
v2 = 0LL;
do
{
result = kill(*(_DWORD *)(listener_pid + v2), sig);
v2 += 4LL;
}
while ( v2 != v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int sig)
{
__int64 v1; // rbp
__int64 v2; // rbx
int result; // eax

if ( listener_pid_number > 0 )
{
v1 = 4LL * (unsigned int)listener_pid_number;
v2 = 0LL;
do
{
result = kill(*(_DWORD *)(listener_pid + v2), sig);
v2 += 4LL;
}
while ( v2 != v1 );
}
return result;
}

original_code:
void stop_listeners(int sig)
{
    int i;
    for (i = 0; i < listener_pid_number; i++) {
        kill(listener_pid[i], sig);
    }
}

variable_types: sig int


shovel

original_code:
int shovel(struct connection *cnx)
{
   fd_set fds;
   int res, i;
   int max_fd = (((cnx->q[0].fd) > (cnx->q[1].fd)) ? (cnx->q[0].fd) : (cnx->q[1].fd)) + 1;
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
   while (1) {
      ((void) (((&fds)->fds_bits)[((cnx->q[0].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[0].fd) % (8 * (int) sizeof (__fd_mask)))))));
      ((void) (((&fds)->fds_bits)[((cnx->q[1].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[1].fd) % (8 * (int) sizeof (__fd_mask)))))));
      res = select(
                   max_fd,
                   &fds,
                   ((void *)0),
                   ((void *)0),
                   ((void *)0)
                  );
      if (res == -1) { print_message(msg_system_error, "%s:%d:", "sslh-fork.c", 56); perror("select"); exit(1); };
      for (i = 0; i < 2; i++) {
          if (((((&fds)->fds_bits)[((cnx->q[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cnx->q[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
              res = fd2fd(&cnx->q[1-i], &cnx->q[i]);
              if (res == 0) {
                  print_message(msg_fd, "%s %s", i ? "client" : "server", "socket closed\n");
                  return res;
              }
          }
      }
   }
}

canonical_original_code:
int shovel(struct connection *cnx)
{
   struct fd_set fds;
   int res; int i;
   int max_fd = (((cnx->q[0].fd) > (cnx->q[1].fd)) ? (cnx->q[0].fd) : (cnx->q[1].fd)) + 1;
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
   while (1) {
      ((void) (((&fds)->fds_bits)[((cnx->q[0].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[0].fd) % (8 * (int) sizeof (__fd_mask)))))));
      ((void) (((&fds)->fds_bits)[((cnx->q[1].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cnx->q[1].fd) % (8 * (int) sizeof (__fd_mask)))))));
      res = select(
                   max_fd,
                   &fds,
                   ((void *)0),
                   ((void *)0),
                   ((void *)0)
                  );
      if (res == -1) { print_message(msg_system_error, "%s:%d:", "sslh-fork.c", 56); perror("select"); exit(1); };
      for (i = 0; i < 2; i++) {
          if (((((&fds)->fds_bits)[((cnx->q[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cnx->q[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
              res = fd2fd(&cnx->q[1-i], &cnx->q[i]);
              if (res == 0) {
                  print_message(msg_fd, "%s %s", i ? "client" : "server", "socket closed\n");
                  return res;
              }
          }
      }
   }
}

variable_types: struct connection { int type; struct sslhcfg_protocols_item { char *name; char *host; char *port; int service_is_present; char *service; int is_udp; int udp_timeout; int fork; int tfo_ok; int transparent; int resolve_on_forward; int log_level; int keepalive; unsigned long sni_hostnames_len; char **sni_hostnames; unsigned long alpn_protocols_len; char **alpn_protocols; unsigned long regex_patterns_len; char **regex_patterns; int minlength_is_present; int minlength; int (*probe)(char *, long, struct sslhcfg_protocols_item *); struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *saddr; void *data; struct dl_list { struct connection *head; struct connection *tail; } timeouts; } *proto; enum connection_state { ST_PROBING=1, ST_SHOVELING=2 } state; long probe_timeout; struct queue { int fd; void *begin_deferred_data; void *deferred_data; int deferred_data_size; } q[2]; struct sockaddr client_addr; unsigned int addrlen; int local_endpoint; long last_active; struct connection *timeout_prev; int target_sock; } *

variable_types:
fds
struct fd_set { long fds_bits[-1]; }

variable_types: res int

user_defined_types: struct connection { int type; struct sslhcfg_protocols_item *proto; enum connection_state state; long probe_timeout; struct queue q[2]; struct sockaddr client_addr; unsigned int addrlen; int local_endpoint; long last_active; struct connection *timeout_prev; int target_sock; }

user_defined_types: struct sslhcfg_protocols_item { char *name; char *host; char *port; int service_is_present; char *service; int is_udp; int udp_timeout; int fork; int tfo_ok; int transparent; int resolve_on_forward; int log_level; int keepalive; unsigned long sni_hostnames_len; char **sni_hostnames; unsigned long alpn_protocols_len; char **alpn_protocols; unsigned long regex_patterns_len; char **regex_patterns; int minlength_is_present; int minlength; int (*probe)(char *, long, struct sslhcfg_protocols_item *); struct addrinfo *saddr; void *data; struct dl_list timeouts; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
void set_listen_procname()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void set_listen_procname(struct listen_endpoint *listen_socket)
{
}

variable_types: struct listen_endpoint { int socketfd; int type; } *


decompiled_code:
__int64 __fastcall tcp_listener(int *a1, int a2, int a3)
{
int *v3; // rbp
int *v4; // rbx
char *v5; // rax
unsigned int v7; // eax
int v8; // ebx
__pid_t v9; // eax
int *v10; // r14
char *v11; // rax
int *v12; // rbp

v3 = &a1[2 * a3];
while ( 1 )
{
v7 = accept(*v3, 0LL, 0LL);
v8 = v7;
if ( v7 == -1 )
break;
print_message(msg_fd, *((_QWORD *)&msg_fd + 1), "accepted fd %d\n", v7);
v9 = fork();
if ( v9 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
print_message(
msg_system_error,
*((_QWORD *)&msg_system_error + 1),
"fork failed: err %d: %s\n",
(unsigned int)*v10,
v11);
}
else if ( !v9 )
{
if ( a2 > 0 )
{
v12 = a1;
do
{
close(*v12);
v12 += 2;
}
while ( v12 != &a1[2 * (a2 - 1) + 2] );
}
start_shoveler(v8);
}
close(v8);
}
v4 = _errno_location();
v5 = strerror(*v4);
return print_message(
msg_system_error,
*((_QWORD *)&msg_system_error + 1),
"%s:%d:%s:%d:%s\n",
"sslh-fork.c",
180LL,
"accept",
(unsigned int)*v4,
v5);
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, int a2, int a3)
{
int *v3; // rbp
int *v4; // rbx
char *v5; // rax
unsigned int v7; // eax
int v8; // ebx
__pid_t v9; // eax
int *v10; // r14
char *v11; // rax
int *v12; // rbp

v3 = &a1[2 * a3];
while ( 1 )
{
v7 = accept(*v3, 0LL, 0LL);
v8 = v7;
if ( v7 == -1 )
break;
print_message(msg_fd, *((_QWORD *)&msg_fd + 1), "accepted fd %d\n", v7);
v9 = fork();
if ( v9 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
print_message(
msg_system_error,
*((_QWORD *)&msg_system_error + 1),
"fork failed: err %d: %s\n",
(unsigned int)*v10,
v11);
}
else if ( !v9 )
{
if ( a2 > 0 )
{
v12 = a1;
do
{
close(*v12);
v12 += 2;
}
while ( v12 != &a1[2 * (a2 - 1) + 2] );
}
func2(v8);
}
close(v8);
}
v4 = _errno_location();
v5 = strerror(*v4);
return print_message(
msg_system_error,
*((_QWORD *)&msg_system_error + 1),
"%s:%d:%s:%d:%s\n",
"sslh-fork.c",
180LL,
"accept",
(unsigned int)*v4,
v5);
}

original_code:
void tcp_listener(struct listen_endpoint* endpoint, int num_endpoints, int active_endpoint)
{
    int i, in_socket;
    while (1) {
        in_socket = accept(endpoint[active_endpoint].socketfd, 0, 0);
        if (in_socket == -1) { print_message(msg_system_error, "%s:%d:%s:%d:%s\n", "sslh-fork.c", 180, "accept", (*__errno_location ()), strerror((*__errno_location ()))); return ; };
        print_message(msg_fd, "accepted fd %d\n", in_socket);
        switch(fork()) {
        case -1: print_message(msg_system_error, "fork failed: err %d: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
                 break;
        case 0:
                 for (i = 0; i < num_endpoints; i++)
                     close(endpoint[i].socketfd);
                 start_shoveler(in_socket);
                 exit(0);
        default:
                 break;
        }
        close(in_socket);
    }
}

canonical_original_code:
void tcp_listener(struct listen_endpoint *endpoint, int num_endpoints, int active_endpoint)
{
    int i; int in_socket;
    while (1) {
        in_socket = accept(endpoint[active_endpoint].socketfd, 0, 0);
        if (in_socket == -1) { print_message(msg_system_error, "%s:%d:%s:%d:%s\n", "sslh-fork.c", 180, "accept", (*__errno_location ()), strerror((*__errno_location ()))); return ; };
        print_message(msg_fd, "accepted fd %d\n", in_socket);
        switch(fork()) {
        case -1: print_message(msg_system_error, "fork failed: err %d: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
                 break;
        case 0:
                 for (i = 0; i < num_endpoints; i++)
                     close(endpoint[i].socketfd);
                 start_shoveler(in_socket);
                 exit(0);
        default:
                 break;
        }
        close(in_socket);
    }
}

user_defined_types: struct listen_endpoint { int socketfd; int type; }