fenRead

decompiled_code:
bool __fastcall fenRead(__int64 a1, char *a2)
{
const char **v2; // rbx
unsigned int v3; // er12
char *v4; // rax
char *v5; // rbx
char v6; // al
unsigned int v7; // er14
unsigned int v8; // ebp
bool result; // al
unsigned int v10; // eax
int v11; // er15
unsigned int v12; // eax
int v13; // er15
_BYTE *v14; // rbx
char v15; // al
unsigned int v16; // ebp
unsigned int v17; // ebx
char *v18; // [rsp+0h] [rbp-68h] BYREF
_BYTE *v19; // [rsp+8h] [rbp-60h]
__int64 v20; // [rsp+10h] [rbp-58h]
_BYTE *v21; // [rsp+18h] [rbp-50h]
char *nptr; // [rsp+20h] [rbp-48h]
char *v23; // [rsp+28h] [rbp-40h]

v18 = a2;
v2 = (const char **)&v18;
v3 = 1;
while ( 1 )
{
v4 = strchr(*v2, 32);
if ( !v4 )
break;
v2[1] = v4 + 1;
++v3;
++v2;
if ( v3 == 6 )
goto LABEL_4;
}
if ( v3 <= 3 )
return 0;
LABEL_4:
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 248) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 256) >> 3));
*(_DWORD *)(a1 + 256) = 0;
*(_DWORD *)(a1 + 260) = CastRightsNone;
*(_DWORD *)(a1 + 264) = 127;
*(_DWORD *)(a1 + 268) = 0;
*(_DWORD *)(a1 + 272) = 1;
v5 = v18;
v6 = *v18;
if ( *v18 == 32 )
return 0;
v7 = 7;
v8 = 0;
while ( 2 )
{
++v5;
switch ( v6 )
{
case '/':
if ( v8 == 8 )
{
--v7;
v8 = 0;
goto LABEL_9;
}
return 0;
case '1':
++v8;
goto LABEL_9;
case '2':
v8 += 2;
goto LABEL_9;
case '3':
v8 += 3;
goto LABEL_9;
case '4':
v8 += 4;
goto LABEL_9;
case '5':
v8 += 5;
goto LABEL_9;
case '6':
v8 += 6;
goto LABEL_9;
case '7':
v8 += 7;
goto LABEL_9;
case '8':
v8 += 8;
goto LABEL_9;
case 'B':
v10 = sqMake(v8, v7);
v11 = ((unsigned __int8)sqIsLight(v10) == 0) + 3;
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = v11;
goto LABEL_9;
case 'K':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 7;
goto LABEL_9;
case 'N':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 2;
goto LABEL_9;
case 'P':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 1;
goto LABEL_9;
case 'Q':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 6;
goto LABEL_9;
case 'R':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 5;
goto LABEL_9;
case 'b':
v12 = sqMake(v8, v7);
v13 = ((unsigned __int8)sqIsLight(v12) == 0) + 11;
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = v13;
goto LABEL_9;
case 'k':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 15;
goto LABEL_9;
case 'n':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 10;
goto LABEL_9;
case 'p':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 9;
goto LABEL_9;
case 'q':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 14;
goto LABEL_9;
case 'r':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 13;
LABEL_9:
v6 = *v5;
if ( *v5 != 32 )
continue;
result = v8 != 8 || v7 != 0;
if ( result )
{
result = 0;
}
else
{
if ( *v19 == 98 )
{
*(_DWORD *)(a1 + 256) = 1;
}
else
{
if ( *v19 != 119 )
return result;
*(_DWORD *)(a1 + 256) = 0;
}
*(_DWORD *)(a1 + 260) = posCastRightsFromStr(v20, a1);
v14 = v21;
v15 = *v21;
if ( *v21 )
{
if ( v21[1] )
{
if ( v15 != 45 )
{
v16 = fileFromChar((unsigned int)v15);
v17 = rankFromChar((unsigned int)(char)v14[1]);
if ( (unsigned __int8)fileIsValid(v16) )
{
if ( (unsigned __int8)rankIsValid(v17) )
*(_DWORD *)(a1 + 264) = sqMake(v16, v17);
}
}
}
}
if ( v3 > 4 )
*(_DWORD *)(a1 + 268) = atoi(nptr);
result = 1;
if ( v3 > 5 )
{
*(_DWORD *)(a1 + 272) = atoi(v23);
result = 1;
}
}
break;
default:
return 0;
}
return result;
}
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, char *a2)
{
const char **v2; // rbx
unsigned int v3; // er12
char *v4; // rax
char *v5; // rbx
char v6; // al
unsigned int v7; // er14
unsigned int v8; // ebp
bool result; // al
unsigned int v10; // eax
int v11; // er15
unsigned int v12; // eax
int v13; // er15
_BYTE *v14; // rbx
char v15; // al
unsigned int v16; // ebp
unsigned int v17; // ebx
char *v18; // [rsp+0h] [rbp-68h] BYREF
_BYTE *v19; // [rsp+8h] [rbp-60h]
__int64 v20; // [rsp+10h] [rbp-58h]
_BYTE *v21; // [rsp+18h] [rbp-50h]
char *nptr; // [rsp+20h] [rbp-48h]
char *v23; // [rsp+28h] [rbp-40h]

v18 = a2;
v2 = (const char **)&v18;
v3 = 1;
while ( 1 )
{
v4 = strchr(*v2, 32);
if ( !v4 )
break;
v2[1] = v4 + 1;
++v3;
++v2;
if ( v3 == 6 )
goto LABEL_4;
}
if ( v3 <= 3 )
return 0;
LABEL_4:
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 248) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 256) >> 3));
*(_DWORD *)(a1 + 256) = 0;
*(_DWORD *)(a1 + 260) = CastRightsNone;
*(_DWORD *)(a1 + 264) = 127;
*(_DWORD *)(a1 + 268) = 0;
*(_DWORD *)(a1 + 272) = 1;
v5 = v18;
v6 = *v18;
if ( *v18 == 32 )
return 0;
v7 = 7;
v8 = 0;
while ( 2 )
{
++v5;
switch ( v6 )
{
case '/':
if ( v8 == 8 )
{
--v7;
v8 = 0;
goto LABEL_9;
}
return 0;
case '1':
++v8;
goto LABEL_9;
case '2':
v8 += 2;
goto LABEL_9;
case '3':
v8 += 3;
goto LABEL_9;
case '4':
v8 += 4;
goto LABEL_9;
case '5':
v8 += 5;
goto LABEL_9;
case '6':
v8 += 6;
goto LABEL_9;
case '7':
v8 += 7;
goto LABEL_9;
case '8':
v8 += 8;
goto LABEL_9;
case 'B':
v10 = sqMake(v8, v7);
v11 = ((unsigned __int8)sqIsLight(v10) == 0) + 3;
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = v11;
goto LABEL_9;
case 'K':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 7;
goto LABEL_9;
case 'N':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 2;
goto LABEL_9;
case 'P':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 1;
goto LABEL_9;
case 'Q':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 6;
goto LABEL_9;
case 'R':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 5;
goto LABEL_9;
case 'b':
v12 = sqMake(v8, v7);
v13 = ((unsigned __int8)sqIsLight(v12) == 0) + 11;
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = v13;
goto LABEL_9;
case 'k':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 15;
goto LABEL_9;
case 'n':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 10;
goto LABEL_9;
case 'p':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 9;
goto LABEL_9;
case 'q':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 14;
goto LABEL_9;
case 'r':
*(_DWORD *)(a1 + 4LL * (unsigned int)sqMake(v8++, v7)) = 13;
LABEL_9:
v6 = *v5;
if ( *v5 != 32 )
continue;
result = v8 != 8 || v7 != 0;
if ( result )
{
result = 0;
}
else
{
if ( *v19 == 98 )
{
*(_DWORD *)(a1 + 256) = 1;
}
else
{
if ( *v19 != 119 )
return result;
*(_DWORD *)(a1 + 256) = 0;
}
*(_DWORD *)(a1 + 260) = posCastRightsFromStr(v20, a1);
v14 = v21;
v15 = *v21;
if ( *v21 )
{
if ( v21[1] )
{
if ( v15 != 45 )
{
v16 = fileFromChar((unsigned int)v15);
v17 = rankFromChar((unsigned int)(char)v14[1]);
if ( (unsigned __int8)fileIsValid(v16) )
{
if ( (unsigned __int8)rankIsValid(v17) )
*(_DWORD *)(a1 + 264) = sqMake(v16, v17);
}
}
}
}
if ( v3 > 4 )
*(_DWORD *)(a1 + 268) = atoi(nptr);
result = 1;
if ( v3 > 5 )
{
*(_DWORD *)(a1 + 272) = atoi(v23);
result = 1;
}
}
break;
default:
return 0;
}
return result;
}
}

original_code:
_Bool fenRead(Fen *data, const char *string) {
 const char *fields[6];
 fields[0]=string;
 unsigned int fieldCount;
 for(fieldCount=1;fieldCount<6;fieldCount++) {
  char *next=strstr(fields[fieldCount-1], " ");
  if (next==((void *)0))
   break;
  fields[fieldCount]=next+1;
 }
 if (fieldCount<=3)
  return 0;
 memset(data->array, PieceNone, SqNB*sizeof(Piece));
 data->stm=ColourWhite;
 data->castRights=CastRightsNone;
 data->epSq=SqInvalid;
 data->halfMoveNumber=0;
 data->fullMoveNumber=1;
 const char *c=fields[0];
 unsigned int x=0, y=7;
 while(*c!=' ')
  switch(*c++) {
   case '1': x+=1; break;
   case '2': x+=2; break;
   case '3': x+=3; break;
   case '4': x+=4; break;
   case '5': x+=5; break;
   case '6': x+=6; break;
   case '7': x+=7; break;
   case '8': x+=8; break;
   case '/':
    if (x!=8)
     return 0;
    x=0;
    --y;
   break;
   case 'P': data->array[sqMake(x++,y)]=PieceWPawn; break;
   case 'N': data->array[sqMake(x++,y)]=PieceWKnight; break;
   case 'B': data->array[sqMake(x,y)]=(sqIsLight(sqMake(x,y)) ? PieceWBishopL : PieceWBishopD); ++x; break;
   case 'R': data->array[sqMake(x++,y)]=PieceWRook; break;
   case 'Q': data->array[sqMake(x++,y)]=PieceWQueen; break;
   case 'K': data->array[sqMake(x++,y)]=PieceWKing; break;
   case 'p': data->array[sqMake(x++,y)]=PieceBPawn; break;
   case 'n': data->array[sqMake(x++,y)]=PieceBKnight; break;
   case 'b': data->array[sqMake(x,y)]=(sqIsLight(sqMake(x,y)) ? PieceBBishopL : PieceBBishopD); ++x; break;
   case 'r': data->array[sqMake(x++,y)]=PieceBRook; break;
   case 'q': data->array[sqMake(x++,y)]=PieceBQueen; break;
   case 'k': data->array[sqMake(x++,y)]=PieceBKing; break;
   default: return 0; break;
  }
 if (y!=0 || x!=8)
  return 0;
 switch(fields[1][0]) {
  case 'w': data->stm=ColourWhite; break;
  case 'b': data->stm=ColourBlack; break;
  default: return 0; break;
 }
 c=fields[2];
 data->castRights=posCastRightsFromStr(c, data->array);
 if (fields[3][0]!='\0' && fields[3][1]!='\0' && fields[3][0]!='-') {
  File file=fileFromChar(fields[3][0]);
  Rank rank=rankFromChar(fields[3][1]);
  if (fileIsValid(file) && rankIsValid(rank))
   data->epSq=sqMake(file, rank);
 }
 if (fieldCount>=5)
  data->halfMoveNumber=atoi(fields[4]);
 if (fieldCount>=6)
  data->fullMoveNumber=atoi(fields[5]);
 return 1;
}

canonical_original_code:
_Bool fenRead(struct Fen *data, char *string) {
 char *fields[6];
 fields[0]=string;
 unsigned int fieldCount;
 for(fieldCount=1;fieldCount<6;fieldCount++) {
  char *next = strstr(fields[fieldCount-1], " ");
  if (next==((void *)0))
   break;
  fields[fieldCount]=next+1;
 }
 if (fieldCount<=3)
  return 0;
 memset(data->array, PieceNone, SqNB*sizeof(Piece));
 data->stm=ColourWhite;
 data->castRights=CastRightsNone;
 data->epSq=SqInvalid;
 data->halfMoveNumber=0;
 data->fullMoveNumber=1;
 char *c = fields[0];
 unsigned int x = 0; unsigned int y = 7;
 while(*c!=' ')
  switch(*c++) {
   case '1': x+=1; break;
   case '2': x+=2; break;
   case '3': x+=3; break;
   case '4': x+=4; break;
   case '5': x+=5; break;
   case '6': x+=6; break;
   case '7': x+=7; break;
   case '8': x+=8; break;
   case '/':
    if (x!=8)
     return 0;
    x=0;
    --y;
   break;
   case 'P': data->array[sqMake(x++,y)]=PieceWPawn; break;
   case 'N': data->array[sqMake(x++,y)]=PieceWKnight; break;
   case 'B': data->array[sqMake(x,y)]=(sqIsLight(sqMake(x,y)) ? PieceWBishopL : PieceWBishopD); ++x; break;
   case 'R': data->array[sqMake(x++,y)]=PieceWRook; break;
   case 'Q': data->array[sqMake(x++,y)]=PieceWQueen; break;
   case 'K': data->array[sqMake(x++,y)]=PieceWKing; break;
   case 'p': data->array[sqMake(x++,y)]=PieceBPawn; break;
   case 'n': data->array[sqMake(x++,y)]=PieceBKnight; break;
   case 'b': data->array[sqMake(x,y)]=(sqIsLight(sqMake(x,y)) ? PieceBBishopL : PieceBBishopD); ++x; break;
   case 'r': data->array[sqMake(x++,y)]=PieceBRook; break;
   case 'q': data->array[sqMake(x++,y)]=PieceBQueen; break;
   case 'k': data->array[sqMake(x++,y)]=PieceBKing; break;
   default: return 0; break;
  }
 if (y!=0 || x!=8)
  return 0;
 switch(fields[1][0]) {
  case 'w': data->stm=ColourWhite; break;
  case 'b': data->stm=ColourBlack; break;
  default: return 0; break;
 }
 c=fields[2];
 data->castRights=posCastRightsFromStr(c, data->array);
 if (fields[3][0]!='\0' && fields[3][1]!='\0' && fields[3][0]!='-') {
  enum File file = fileFromChar(fields[3][0]);
  enum Rank rank = rankFromChar(fields[3][1]);
  if (fileIsValid(file) && rankIsValid(rank))
   data->epSq=sqMake(file, rank);
 }
 if (fieldCount>=5)
  data->halfMoveNumber=atoi(fields[4]);
 if (fieldCount>=6)
  data->fullMoveNumber=atoi(fields[5]);
 return 1;
}

variable_types: struct Fen { enum Piece { PieceNone=expr, PieceWPawn=expr, PieceWKnight=expr, PieceWBishopL=expr, PieceWBishopD=expr, PieceWRook=expr, PieceWQueen=expr, PieceWKing=expr, PieceBPawn=expr, PieceBKnight=expr, PieceBBishopL=expr, PieceBBishopD=expr, PieceBRook=expr, PieceBQueen=expr, PieceBKing=expr, PieceNB=expr } array[-1]; enum Colour { ColourWhite=0, ColourBlack=1, ColourNB=2 } stm; struct CastRights { unsigned char rookSq[-1][-1]; } castRights; enum Sq { SqA1=0, SqB1=1, SqC1=2, SqD1=3, SqE1=4, SqF1=5, SqG1=6, SqH1=7, SqA2=8, SqB2=9, SqC2=10, SqD2=11, SqE2=12, SqF2=13, SqG2=14, SqH2=15, SqA3=16, SqB3=17, SqC3=18, SqD3=19, SqE3=20, SqF3=21, SqG3=22, SqH3=23, SqA4=24, SqB4=25, SqC4=26, SqD4=27, SqE4=28, SqF4=29, SqG4=30, SqH4=31, SqA5=32, SqB5=33, SqC5=34, SqD5=35, SqE5=36, SqF5=37, SqG5=38, SqH5=39, SqA6=40, SqB6=41, SqC6=42, SqD6=43, SqE6=44, SqF6=45, SqG6=46, SqH6=47, SqA7=48, SqB7=49, SqC7=50, SqD7=51, SqE7=52, SqF7=53, SqG7=54, SqH7=55, SqA8=56, SqB8=57, SqC8=58, SqD8=59, SqE8=60, SqF8=61, SqG8=62, SqH8=63, SqNB=64, SqInvalid=127 } epSq; unsigned int halfMoveNumber; } *

variable_types:
string
char *

variable_types:
fields
char *[6]

variable_types:
fieldCount
unsigned int

variable_types:
next
char *

variable_types:
c
char *

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: enum Rank { Rank1=0, Rank2=1, Rank3=2, Rank4=3, Rank5=4, Rank6=5, Rank7=6, Rank8=7, RankNB=8 }

user_defined_types: struct Fen { enum Piece array[-1]; enum Colour stm; struct CastRights castRights; enum Sq epSq; unsigned int halfMoveNumber; }


fenWrite

decompiled_code:
char *__fastcall fenWrite(_DWORD *a1, char *a2)
{
unsigned int i; // er14
int v3; // er12
char v4; // al
unsigned int j; // ebp
int v6; // ebx
_BYTE *v7; // rbx
char *v8; // rax
unsigned int v9; // eax
char v10; // bl
unsigned int v11; // eax
char v12; // al
char v14[120]; // [rsp+0h] [rbp-78h] BYREF

*a2 = 0;
for ( i = 7; i != -1; --i )
{
v3 = 0;
for ( j = 0; j != 8; ++j )
{
v6 = sqMake(j, i);
if ( a1[v6] )
{
if ( v3 > 0 )
{
sprintf(v14, "%i", (unsigned int)v3);
strcat(a2, v14);
v3 = 0;
}
v4 = pieceToChar((unsigned int)a1[v6]);
sprintf(v14, "%c", (unsigned int)v4);
strcat(a2, v14);
}
else
{
++v3;
}
}
if ( v3 > 0 )
{
sprintf(v14, "%i", (unsigned int)v3);
strcat(a2, v14);
}
if ( !i )
break;
*(_WORD *)&a2[strlen(a2)] = 47;
}
v7 = &unk_8A0;
if ( a1[64] )
v7 = &unk_8A3;
v8 = &a2[strlen(a2)];
*(_WORD *)v8 = *(_WORD *)v7;
v8[2] = v7[2];
*(_WORD *)&a2[strlen(a2)] = 32;
posCastRightsToStr((unsigned int)a1[65], v14);
strcat(a2, v14);
if ( a1[66] == 127 )
{
strcat(a2, " -");
}
else
{
v9 = sqRank();
v10 = rankToChar(v9);
v11 = sqFile((unsigned int)a1[66]);
v12 = fileToChar(v11);
sprintf(v14, " %c%c", (unsigned int)v12, (unsigned int)v10);
strcat(a2, v14);
}
sprintf(v14, " %i %i", (unsigned int)a1[67], (unsigned int)a1[68]);
return strcat(a2, v14);
}

canonical_decompiled_code:
char *__fastcall func1(_DWORD *a1, char *a2)
{
unsigned int i; // er14
int v3; // er12
char v4; // al
unsigned int j; // ebp
int v6; // ebx
_BYTE *v7; // rbx
char *v8; // rax
unsigned int v9; // eax
char v10; // bl
unsigned int v11; // eax
char v12; // al
char v14[120]; // [rsp+0h] [rbp-78h] BYREF

*a2 = 0;
for ( i = 7; i != -1; --i )
{
v3 = 0;
for ( j = 0; j != 8; ++j )
{
v6 = sqMake(j, i);
if ( a1[v6] )
{
if ( v3 > 0 )
{
sprintf(v14, "%i", (unsigned int)v3);
strcat(a2, v14);
v3 = 0;
}
v4 = pieceToChar((unsigned int)a1[v6]);
sprintf(v14, "%c", (unsigned int)v4);
strcat(a2, v14);
}
else
{
++v3;
}
}
if ( v3 > 0 )
{
sprintf(v14, "%i", (unsigned int)v3);
strcat(a2, v14);
}
if ( !i )
break;
*(_WORD *)&a2[strlen(a2)] = 47;
}
v7 = &unk_8A0;
if ( a1[64] )
v7 = &unk_8A3;
v8 = &a2[strlen(a2)];
*(_WORD *)v8 = *(_WORD *)v7;
v8[2] = v7[2];
*(_WORD *)&a2[strlen(a2)] = 32;
posCastRightsToStr((unsigned int)a1[65], v14);
strcat(a2, v14);
if ( a1[66] == 127 )
{
strcat(a2, " -");
}
else
{
v9 = sqRank();
v10 = rankToChar(v9);
v11 = sqFile((unsigned int)a1[66]);
v12 = fileToChar(v11);
sprintf(v14, " %c%c", (unsigned int)v12, (unsigned int)v10);
strcat(a2, v14);
}
sprintf(v14, " %i %i", (unsigned int)a1[67], (unsigned int)a1[68]);
return strcat(a2, v14);
}

original_code:
void fenWrite(Fen *data, char string[static 128]) {
 ((void) (0));
 char tempStr[64];
 string[0]='\0';
 int x, y;
 for(y=7; y>=0; --y) {
  int gap=0;
  for(x=0; x<8; ++x) {
   Sq sq=sqMake(x, y);
   if (data->array[sq]==PieceNone) {
    ++gap;
    continue;
   }
   if (gap>0) {
    sprintf(tempStr, "%i", gap);
    strcat(string, tempStr);
    gap=0;
   }
   sprintf(tempStr, "%c", pieceToChar(data->array[sq]));
   strcat(string, tempStr);
  }
  if (gap>0) {
   sprintf(tempStr, "%i", gap);
   strcat(string, tempStr);
  }
  if (y!=0)
   strcat(string, "/");
 }
 strcat(string, (data->stm==ColourWhite ? " w" : " b"));
 strcat(string, " ");
 posCastRightsToStr(data->castRights, tempStr);
 strcat(string, tempStr);
 if (data->epSq!=SqInvalid) {
  sprintf(tempStr, " %c%c", fileToChar(sqFile(data->epSq)), rankToChar(sqRank(data->epSq)));
  strcat(string, tempStr);
 } else
  strcat(string, " -");
 sprintf(tempStr, " %i %i", data->halfMoveNumber, data->fullMoveNumber);
 strcat(string, tempStr);
}

canonical_original_code:
void fenWrite(struct Fen *data, char string[128]) {
 ((void) (0));
 char tempStr[64];
 string[0]='\0';
 int x; int y;
 for(y=7; y>=0; --y) {
  int gap = 0;
  for(x=0; x<8; ++x) {
   enum Sq sq = sqMake(x, y);
   if (data->array[sq]==PieceNone) {
    ++gap;
    continue;
   }
   if (gap>0) {
    sprintf(tempStr, "%i", gap);
    strcat(string, tempStr);
    gap=0;
   }
   sprintf(tempStr, "%c", pieceToChar(data->array[sq]));
   strcat(string, tempStr);
  }
  if (gap>0) {
   sprintf(tempStr, "%i", gap);
   strcat(string, tempStr);
  }
  if (y!=0)
   strcat(string, "/");
 }
 strcat(string, (data->stm==ColourWhite ? " w" : " b"));
 strcat(string, " ");
 posCastRightsToStr(data->castRights, tempStr);
 strcat(string, tempStr);
 if (data->epSq!=SqInvalid) {
  sprintf(tempStr, " %c%c", fileToChar(sqFile(data->epSq)), rankToChar(sqRank(data->epSq)));
  strcat(string, tempStr);
 } else
  strcat(string, " -");
 sprintf(tempStr, " %i %i", data->halfMoveNumber, data->fullMoveNumber);
 strcat(string, tempStr);
}

variable_types:
string
char [128]

variable_types:
tempStr
char [64]

variable_types: x int

variable_types: y int

variable_types: gap int

return_type: void

user_defined_types: enum Colour { ColourWhite=0, ColourBlack=1, ColourNB=2 }

user_defined_types: struct CastRights { unsigned char rookSq[-1][-1]; }

user_defined_types: enum Piece { PieceNone=expr, PieceWPawn=expr, PieceWKnight=expr, PieceWBishopL=expr, PieceWBishopD=expr, PieceWRook=expr, PieceWQueen=expr, PieceWKing=expr, PieceBPawn=expr, PieceBKnight=expr, PieceBBishopL=expr, PieceBBishopD=expr, PieceBRook=expr, PieceBQueen=expr, PieceBKing=expr, PieceNB=expr }


threadExit

decompiled_code:
void __noreturn threadExit()
{
pthread_exit(0LL);
}

canonical_decompiled_code:
void __noreturn func0()
{
pthread_exit(0LL);
}

original_code:
void threadExit(void *dummy) {
 pthread_exit(((void *)0));
}

variable_types:
dummy
void *


lockFree

decompiled_code:
void __fastcall lockFree(void *ptr)
{
if ( ptr )
{
sem_destroy((sem_t *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
sem_destroy((sem_t *)ptr);
free(ptr);
}
}

original_code:
void lockFree(Lock *lock) {
 if (lock==((void *)0))
  return;
 sem_destroy(&lock->lock);
 free(lock);
}

canonical_original_code:
void lockFree(struct Lock *lock) {
 if (lock==((void *)0))
  return;
 sem_destroy(&lock->lock);
 free(lock);
}

variable_types: struct Lock { union sem_t { char __size[32]; long __align; } lock; } *


threadNew

decompiled_code:
pthread_t *threadNew()
{
pthread_t *v0; // rbx
sem_t *v1; // rbp
sem_t *v2; // r12

v0 = (pthread_t *)malloc(0x28uLL);
v1 = lockNew(1u);
v2 = lockNew(0);
if ( v1 == 0LL || v0 == 0LL || !v2 )
{
lockFree(v1);
lockFree(v2);
free(v0);
v0 = 0LL;
}
else
{
*v0 = (pthread_t)v1;
v0[1] = (pthread_t)v2;
v0[3] = 0LL;
v0[4] = 0LL;
if ( pthread_create(v0 + 2, 0LL, threadMain, v0) )
{
lockFree((void *)*v0);
lockFree((void *)v0[1]);
free(v0);
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
pthread_t *func2()
{
pthread_t *v0; // rbx
sem_t *v1; // rbp
sem_t *v2; // r12

v0 = (pthread_t *)malloc(0x28uLL);
v1 = lockNew(1u);
v2 = lockNew(0);
if ( v1 == 0LL || v0 == 0LL || !v2 )
{
func1(v1);
func1(v2);
free(v0);
v0 = 0LL;
}
else
{
*v0 = (pthread_t)v1;
v0[1] = (pthread_t)v2;
v0[3] = 0LL;
v0[4] = 0LL;
if ( pthread_create(v0 + 2, 0LL, threadMain, v0) )
{
func1((void *)*v0);
func1((void *)v0[1]);
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
Thread *threadNew(void)
{
 Thread *thread=malloc(sizeof(Thread));
 Lock *lock=lockNew(1);
 Lock *runFlag=lockNew(0);
 if (thread==((void *)0) || lock==((void *)0) || runFlag==((void *)0)) {
  lockFree(lock);
  lockFree(runFlag);
  free(thread);
  return ((void *)0);
 }
 thread->lock=lock;
 thread->runFlag=runFlag;
 thread->function=((void *)0);
 thread->userData=((void *)0);
 if (pthread_create(&thread->id, ((void *)0), &threadMain, (void *)thread)!=0) {
  lockFree(thread->lock);
  lockFree(thread->runFlag);
  free(thread);
  return ((void *)0);
 }
 return thread;
}

canonical_original_code:
struct Thread *threadNew()
{
 struct Thread *thread = malloc(sizeof(Thread));
 struct Lock *lock = lockNew(1);
 struct Lock *runFlag = lockNew(0);
 if (thread==((void *)0) || lock==((void *)0) || runFlag==((void *)0)) {
  lockFree(lock);
  lockFree(runFlag);
  free(thread);
  return ((void *)0);
 }
 thread->lock=lock;
 thread->runFlag=runFlag;
 thread->function=((void *)0);
 thread->userData=((void *)0);
 if (pthread_create(&thread->id, ((void *)0), &threadMain, (void *)thread)!=0) {
  lockFree(thread->lock);
  lockFree(thread->runFlag);
  free(thread);
  return ((void *)0);
 }
 return thread;
}

variable_types: struct Thread { struct Lock { union sem_t { char __size[32]; long __align; } lock; } *lock; unsigned long id; void (*function)(void *userData); void *userData; } *

user_defined_types: struct Thread { struct Lock *lock; unsigned long id; void (*function)(void *userData); void *userData; }


lockWait

decompiled_code:
int __fastcall lockWait(sem_t *a1)
{
return sem_wait(a1);
}

canonical_decompiled_code:
int __fastcall func3(sem_t *a1)
{
return sem_wait(a1);
}

original_code:
void lockWait(Lock *lock) {
 sem_wait(&lock->lock);
}

canonical_original_code:
void lockWait(struct Lock *lock) {
 sem_wait(&lock->lock);
}

user_defined_types: union sem_t { char __size[32]; long __align; }


lockPost

decompiled_code:
int __fastcall lockPost(sem_t *a1)
{
return sem_post(a1);
}

canonical_decompiled_code:
int __fastcall func4(sem_t *a1)
{
return sem_post(a1);
}

original_code:
void lockPost(Lock *lock) {
 sem_post(&lock->lock);
}

canonical_original_code:
void lockPost(struct Lock *lock) {
 sem_post(&lock->lock);
}


threadRun

decompiled_code:
int __fastcall threadRun(__int64 a1, __int64 a2, __int64 a3)
{
lockWait(*(sem_t **)a1);
*(_QWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 32) = a3;
return lockPost(*(sem_t **)(a1 + 8));
}

original_code:
void threadRun(Thread *thread, void (*function)(void *userData), void *userData) {
 lockWait(thread->lock);
 thread->function=function;
 thread->userData=userData;
 lockPost(thread->runFlag);
}

canonical_original_code:
void threadRun(struct Thread *thread, void (*function)(void *userData), void *userData) {
 lockWait(thread->lock);
 thread->function=function;
 thread->userData=userData;
 lockPost(thread->runFlag);
}

variable_types:
function
void (*)(void *userData)

variable_types:
userData
void *


threadFree

decompiled_code:
void __fastcall threadFree(void *ptr)
{
if ( ptr )
{
threadRun((__int64)ptr, (__int64)threadExit, 0LL);
pthread_join(*((_QWORD *)ptr + 2), 0LL);
lockFree(*(void **)ptr);
lockFree(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
func5((__int64)ptr, (__int64)threadExit, 0LL);
pthread_join(*((_QWORD *)ptr + 2), 0LL);
func1(*(void **)ptr);
func1(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void threadFree(Thread *thread) {
 if (thread==((void *)0))
  return;
 threadRun(thread, &threadExit, ((void *)0));
 pthread_join(thread->id, ((void *)0));
 lockFree(thread->lock);
 lockFree(thread->runFlag);
 free(thread);
}

canonical_original_code:
void threadFree(struct Thread *thread) {
 if (thread==((void *)0))
  return;
 threadRun(thread, &threadExit, ((void *)0));
 pthread_join(thread->id, ((void *)0));
 lockFree(thread->lock);
 lockFree(thread->runFlag);
 free(thread);
}


threadWaitReady

decompiled_code:
int __fastcall threadWaitReady(sem_t **a1)
{
lockWait(*a1);
return lockPost(*a1);
}

canonical_decompiled_code:
int __fastcall func7(sem_t **a1)
{
func3(*a1);
return func4(*a1);
}

original_code:
void threadWaitReady(Thread *thread) {
 lockWait(thread->lock);
 lockPost(thread->lock);
}

canonical_original_code:
void threadWaitReady(struct Thread *thread) {
 lockWait(thread->lock);
 lockPost(thread->lock);
}


threadMain

decompiled_code:
void __fastcall __noreturn threadMain(void *a1)
{
while ( 1 )
{
lockWait(*((sem_t **)a1 + 1));
(*((void (__fastcall **)(_QWORD))a1 + 3))(*((_QWORD *)a1 + 4));
lockPost(*(sem_t **)a1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
while ( 1 )
{
func3(*((sem_t **)a1 + 1));
(*((void (__fastcall **)(_QWORD))a1 + 3))(*((_QWORD *)a1 + 4));
func4(*(sem_t **)a1);
}
}

original_code:
void *threadMain(void *threadData) {
 Thread *thread=(Thread *)threadData;
 while(1) {
  lockWait(thread->runFlag);
  thread->function(thread->userData);
  lockPost(thread->lock);
 }
 return ((void *)0);
}

canonical_original_code:
void *threadMain(void *threadData) {
 struct Thread *thread = (Thread *)threadData;
 while(1) {
  lockWait(thread->runFlag);
  thread->function(thread->userData);
  lockPost(thread->lock);
 }
 return ((void *)0);
}

variable_types:
threadData
void *

return_type: void *


lockTryWait

decompiled_code:
bool __fastcall lockTryWait(sem_t *a1)
{
return sem_trywait(a1) == 0;
}

canonical_decompiled_code:
bool __fastcall func9(sem_t *a1)
{
return sem_trywait(a1) == 0;
}

original_code:
_Bool lockTryWait(Lock *lock) {
 return (sem_trywait(&lock->lock)==0);
}

canonical_original_code:
_Bool lockTryWait(struct Lock *lock) {
 return (sem_trywait(&lock->lock)==0);
}


moveMake

decompiled_code:
__int64 __fastcall moveMake(int a1, int a2, int a3)
{
return (a1 << 6) | a2 | (unsigned int)(a3 << 12);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
return (a1 << 6) | a2 | (unsigned int)(a3 << 12);
}

original_code:
Move moveMake(Sq fromSq, Sq toSq, Piece toPiece) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return (((Move)fromSq)<<6)|(((Move)toSq)<<0)|(((Move)toPiece)<<12);
}

canonical_original_code:
unsigned int moveMake(enum Sq fromSq, enum Sq toSq, enum Piece toPiece) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return (((unsigned int)fromSq)<<6)|(((unsigned int)toSq)<<0)|(((unsigned int)toPiece)<<12);
}

variable_types: enum Piece { PieceNone=expr, PieceWPawn=expr, PieceWKnight=expr, PieceWBishopL=expr, PieceWBishopD=expr, PieceWRook=expr, PieceWQueen=expr, PieceWKing=expr, PieceBPawn=expr, PieceBKnight=expr, PieceBBishopL=expr, PieceBBishopD=expr, PieceBRook=expr, PieceBQueen=expr, PieceBKing=expr, PieceNB=expr }

return_type: unsigned int


moveGetFromSq

decompiled_code:
__int64 __fastcall moveGetFromSq(unsigned int a1)
{
return (a1 >> 6) & 0x3F;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return (a1 >> 6) & 0x3F;
}

original_code:
Sq moveGetFromSq(Move move) {
 return (move>>6)&63;
}

canonical_original_code:
enum Sq moveGetFromSq(unsigned int move) {
 return (move>>6)&63;
}

variable_types:
move
unsigned int


moveGetToSqRaw

decompiled_code:
__int64 __fastcall moveGetToSqRaw(char a1)
{
return a1 & 0x3F;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return a1 & 0x3F;
}

original_code:
Sq moveGetToSqRaw(Move move) {
 return (move>>0)&63;
}

canonical_original_code:
enum Sq moveGetToSqRaw(unsigned int move) {
 return (move>>0)&63;
}


moveIsValid

decompiled_code:
bool __fastcall moveIsValid(unsigned int a1)
{
int v1; // ebp

v1 = moveGetFromSq(a1);
return v1 != (unsigned int)moveGetToSqRaw(a1);
}

canonical_decompiled_code:
bool __fastcall func3(unsigned int a1)
{
int v1; // ebp

v1 = func1(a1);
return v1 != (unsigned int)func2(a1);
}

original_code:
_Bool moveIsValid(Move move) {
 return (moveGetFromSq(move)!=moveGetToSqRaw(move));
}

canonical_original_code:
_Bool moveIsValid(unsigned int move) {
 return (moveGetFromSq(move)!=moveGetToSqRaw(move));
}


moveGetToPiece

decompiled_code:
__int64 __fastcall moveGetToPiece(unsigned int a1)
{
return a1 >> 12;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return a1 >> 12;
}

original_code:
Piece moveGetToPiece(Move move) {
 ((void) (0));
 return move>>12;
}

canonical_original_code:
enum Piece moveGetToPiece(unsigned int move) {
 ((void) (0));
 return move>>12;
}

return_type: enum Piece { PieceNone=expr, PieceWPawn=expr, PieceWKnight=expr, PieceWBishopL=expr, PieceWBishopD=expr, PieceWRook=expr, PieceWQueen=expr, PieceWKing=expr, PieceBPawn=expr, PieceBKnight=expr, PieceBBishopL=expr, PieceBBishopD=expr, PieceBRook=expr, PieceBQueen=expr, PieceBKing=expr, PieceNB=expr }


moveGetToPieceType

decompiled_code:
__int64 __fastcall moveGetToPieceType(unsigned int a1)
{
unsigned int v1; // eax

v1 = moveGetToPiece(a1);
return pieceGetType(v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
unsigned int v1; // eax

v1 = func4(a1);
return pieceGetType(v1);
}

original_code:
PieceType moveGetToPieceType(Move move) {
 ((void) (0));
 return pieceGetType(moveGetToPiece(move));
}

canonical_original_code:
enum PieceType moveGetToPieceType(unsigned int move) {
 ((void) (0));
 return pieceGetType(moveGetToPiece(move));
}

return_type: enum PieceType { PieceTypeNone=0, PieceTypePawn=1, PieceTypeKnight=2, PieceTypeBishopL=3, PieceTypeBishopD=4, PieceTypeRook=5, PieceTypeQueen=6, PieceTypeKing=7, PieceTypeNB=8 }


moveGetColour

decompiled_code:
__int64 __fastcall moveGetColour(unsigned int a1)
{
unsigned int v1; // eax

v1 = moveGetToPiece(a1);
return pieceGetColour(v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // eax

v1 = func4(a1);
return pieceGetColour(v1);
}

original_code:
Colour moveGetColour(Move move) {
 ((void) (0));
 return pieceGetColour(moveGetToPiece(move));
}

canonical_original_code:
enum Colour moveGetColour(unsigned int move) {
 ((void) (0));
 return pieceGetColour(moveGetToPiece(move));
}

return_type: enum Colour { ColourWhite=0, ColourBlack=1, ColourNB=2 }


moveIsDP

decompiled_code:
_BOOL8 __fastcall moveIsDP(unsigned int a1)
{
unsigned int v1; // eax
int v2; // ebp
unsigned int v3; // eax
int v4; // er12
int v5; // edx
bool v6; // al

v1 = moveGetToSqRaw(a1);
v2 = sqRank(v1);
v3 = moveGetFromSq(a1);
v4 = sqRank(v3);
v5 = moveGetToPieceType(a1);
v6 = 0;
if ( v5 == 1 )
v6 = abs32(v2 - v4) == 2;
return v6;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned int a1)
{
unsigned int v1; // eax
int v2; // ebp
unsigned int v3; // eax
int v4; // er12
int v5; // edx
bool v6; // al

v1 = func2(a1);
v2 = sqRank(v1);
v3 = func1(a1);
v4 = sqRank(v3);
v5 = func5(a1);
v6 = 0;
if ( v5 == 1 )
v6 = abs32(v2 - v4) == 2;
return v6;
}

original_code:
_Bool moveIsDP(Move move) {
 ((void) (0));
 int toRank=sqRank(moveGetToSqRaw(move));
 int fromRank=sqRank(moveGetFromSq(move));
 return (moveGetToPieceType(move)==PieceTypePawn && abs(toRank-fromRank)==2);
}

canonical_original_code:
_Bool moveIsDP(unsigned int move) {
 ((void) (0));
 int toRank = sqRank(moveGetToSqRaw(move));
 int fromRank = sqRank(moveGetFromSq(move));
 return (moveGetToPieceType(move)==PieceTypePawn && abs(toRank-fromRank)==2);
}

variable_types: toRank int

variable_types: fromRank int


ttInit

decompiled_code:
__int64 ttInit()
{
__int64 v0; // rax
__int64 result; // rax

v0 = htableNew(32LL, 16LL);
tt = v0;
if ( v0 )
{
uciOptionNewSpin("Hash", &htableResizeInterface, v0, 1LL, 0x20000LL, 16LL);
result = uciOptionNewButton("Clear Hash", &htableClearInterface, tt);
}
else
{
mainFatalError("Error: Could not allocate transposition table.\n");
result = ttQuit();
}
return result;
}

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

v0 = htableNew(32LL, 16LL);
tt = v0;
if ( v0 )
{
uciOptionNewSpin("Hash", &htableResizeInterface, v0, 1LL, 0x20000LL, 16LL);
result = uciOptionNewButton("Clear Hash", &htableClearInterface, tt);
}
else
{
mainFatalError("Error: Could not allocate transposition table.\n");
result = func1();
}
return result;
}

original_code:
void ttInit(void) {
 tt=htableNew(sizeof(TTCluster), ttDefaultSizeMb);
 if (tt==((void *)0))
  mainFatalError("Error: Could not allocate transposition table.\n");
 uciOptionNewSpin("Hash", &htableResizeInterface, tt, 1, ttMaxSizeMb, ttDefaultSizeMb);
 uciOptionNewButton("Clear Hash", &htableClearInterface, tt);
}

canonical_original_code:
void ttInit() {
 tt=htableNew(sizeof(TTCluster), ttDefaultSizeMb);
 if (tt==((void *)0))
  mainFatalError("Error: Could not allocate transposition table.\n");
 uciOptionNewSpin("Hash", &htableResizeInterface, tt, 1, ttMaxSizeMb, ttDefaultSizeMb);
 uciOptionNewButton("Clear Hash", &htableClearInterface, tt);
}


ttQuit

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

result = htableFree(tt);
tt = 0LL;
return result;
}

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

result = htableFree(tt);
tt = 0LL;
return result;
}

original_code:
void ttQuit(void) {
 htableFree(tt);
 tt=((void *)0);
}

canonical_original_code:
void ttQuit() {
 htableFree(tt);
 tt=((void *)0);
}


ttClear

decompiled_code:
__int64 ttClear()
{
return htableClear(tt);
}

canonical_decompiled_code:
__int64 func2()
{
return htableClear(tt);
}

original_code:
void ttClear(void) {
 htableClear(tt);
}

canonical_original_code:
void ttClear() {
 htableClear(tt);
}


ttEntryUnused

decompiled_code:
bool __fastcall ttEntryUnused(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 2) == MoveInvalid;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 2) == MoveInvalid;
}

original_code:
_Bool ttEntryUnused(const TTEntry *entry) {
 return (entry->move==MoveInvalid);
}

canonical_original_code:
_Bool ttEntryUnused(struct TTEntry *entry) {
 return (entry->move==MoveInvalid);
}

variable_types: struct TTEntry { unsigned short keyUpper; unsigned short move; short score; unsigned char depth; unsigned char bound; unsigned char date; } *


ttFull

decompiled_code:
__int64 ttFull()
{
__int64 v0; // r13
unsigned int v1; // er14
unsigned int v2; // er15
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // er12

v0 = htableGrab(tt, 0LL);
v1 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
do
{
v5 += !ttEntryUnused(v0 + 8LL * v3++);
++v4;
}
while ( v3 <= 3 && v4 <= 0x3E7 );
htableRelease(tt, v2);
v1 += 4294967;
if ( v4 > 0x3E7 )
break;
v2 = v1;
v0 = htableGrab(tt, v1);
v3 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // r13
unsigned int v1; // er14
unsigned int v2; // er15
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // er12

v0 = htableGrab(tt, 0LL);
v1 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
do
{
v5 += !func4(v0 + 8LL * v3++);
++v4;
}
while ( v3 <= 3 && v4 <= 0x3E7 );
htableRelease(tt, v2);
v1 += 4294967;
if ( v4 > 0x3E7 )
break;
v2 = v1;
v0 = htableGrab(tt, v1);
v3 = 0;
}
return v5;
}

original_code:
unsigned int ttFull(void) {
 unsigned total=0;
 unsigned checked=0;
 size_t index, indexDelta=((1llu)<<(32))/1000;
 for(index=0;checked<1000;index+=indexDelta) {
  TTCluster *cluster=htableGrab(tt, index);
  unsigned entry;
  for(entry=0; entry<(4u) && checked<1000; ++entry,++checked)
   total+=(!ttEntryUnused(&cluster->entries[entry]));
  htableRelease(tt, index);
 }
 return total;
}

canonical_original_code:
unsigned int ttFull() {
 unsigned int total = 0;
 unsigned int checked = 0;
 unsigned long index; unsigned long indexDelta = ((1llu)<<(32))/1000;
 for(index=0;checked<1000;index+=indexDelta) {
  struct TTCluster *cluster = htableGrab(tt, index);
  unsigned int entry;
  for(entry=0; entry<(4u) && checked<1000; ++entry,++checked)
   total+=(!ttEntryUnused(&cluster->entries[entry]));
  htableRelease(tt, index);
 }
 return total;
}

variable_types:
total
unsigned int

variable_types:
checked
unsigned int

variable_types:
index
unsigned long

variable_types:
indexDelta
unsigned long

variable_types: struct TTCluster { struct TTEntry { unsigned short keyUpper; unsigned short move; short score; unsigned char depth; unsigned char bound; unsigned char date; } entries[-1]; } *

variable_types:
entry
unsigned int

user_defined_types: struct TTCluster { struct TTEntry entries[-1]; }


ttEntryFitness

decompiled_code:
__int64 __fastcall ttEntryFitness(int a1, int a2, unsigned __int8 a3)
{
return 1 - (unsigned int)a3 + 2 * ((a1 << 7) - a2) + 254;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2, unsigned __int8 a3)
{
return 1 - (unsigned int)a3 + 2 * ((a1 << 7) - a2) + 254;
}

original_code:
unsigned int ttEntryFitness(unsigned int age, Depth depth, _Bool exact) {
 ((void) (0));
 ((void) (0));
 return 2*DepthMax*age+2*(DepthMax-1-depth)+(1-exact);
}

canonical_original_code:
unsigned int ttEntryFitness(unsigned int age, enum Depth depth, _Bool exact) {
 ((void) (0));
 ((void) (0));
 return 2*DepthMax*age+2*(DepthMax-1-depth)+(1-exact);
}

variable_types:
age
unsigned int

variable_types: enum Depth { DepthMax=128, DepthInvalid=255 }


bbSq

decompiled_code:
__int64 __fastcall bbSq(char a1)
{
return 1LL << a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return 1LL << a1;
}

original_code:
BB bbSq(Sq sq) {
 typedef struct { int static_assertion_failed : !!(SqNB<=64); } static_assertion_failed_0;
 ((void) (0));
 return ((BB)1)<<sq;
}

canonical_original_code:
unsigned long bbSq(enum Sq sq) {
 typedef struct { int static_assertion_failed : !!(SqNB<=64); } static_assertion_failed_0;
 ((void) (0));
 return ((unsigned long)1)<<sq;
}

return_type: unsigned long


bbInit

decompiled_code:
__int64 bbInit()
{
unsigned int v0; // eax
int v1; // er12
unsigned int v2; // er13
__int64 v3; // r15
__int64 v4; // r14
unsigned int v5; // ebx
char v6; // al
unsigned int k; // ebx
char v8; // al
unsigned int v9; // ebp
__int64 result; // rax
unsigned int v11; // eax
__int64 v12; // r15
unsigned int i; // er14
signed int v14; // er12
unsigned __int64 v15; // [rsp+0h] [rbp-78h]
unsigned int j; // [rsp+0h] [rbp-78h]
char *v17; // [rsp+8h] [rbp-70h]
unsigned int v18; // [rsp+10h] [rbp-68h]
int v19; // [rsp+1Ch] [rbp-5Ch]
int v20[8]; // [rsp+20h] [rbp-58h] BYREF
char v21; // [rsp+40h] [rbp-38h] BYREF

memset(BBBetween, 0, sizeof(BBBetween));
memset(BBBeyond, 0, sizeof(BBBeyond));
v20[0] = -17;
v20[1] = -16;
v20[2] = -15;
v20[3] = -1;
v20[4] = 1;
v20[5] = 15;
v20[6] = 16;
v20[7] = 17;
v19 = 64;
v18 = 0;
do
{
v17 = (char *)v20;
do
{
v0 = sqMake((unsigned __int8)v18 >> 4, v18 & 7);
v1 = *(_DWORD *)v17;
v2 = *(_DWORD *)v17 + v18;
if ( (((unsigned __int8)*(_DWORD *)v17 + (_BYTE)v18) & 0x88) == 0 )
{
v3 = 0LL;
v15 = (unsigned __int64)v0 << 6;
while ( 1 )
{
v4 = (unsigned int)sqMake((unsigned __int8)v2 >> 4, v2 & 7);
BBBetween[v15 + v4] = v3;
v2 += v1;
if ( (v2 & 0x88) != 0 )
break;
v5 = v2;
do
{
v6 = sqMake((unsigned __int8)v5 >> 4, v5 & 7);
BBBeyond[v15 + v4] |= bbSq(v6);
v5 += v1;
}
while ( (v5 & 0x88) == 0 );
v3 |= bbSq(v4);
}
}
v17 += 4;
}
while ( v17 != &v21 );
v18 = (v18 + 9) & 0xFFFFFFF7;
--v19;
}
while ( v19 );
v14 = 7;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; result = j )
{
v11 = sqMake(j, i);
BBPawnSq[v11] = 0LL;
v9 = 0;
v12 = v11;
do
{
for ( k = 0; k != 8; ++k )
{
if ( (int)abs32(j - k) <= v14 && (int)i <= (int)v9 )
{
v8 = sqMake(k, v9);
BBPawnSq[v12] |= bbSq(v8);
}
}
++v9;
}
while ( v9 != 8 );
++j;
}
--v14;
}
return result;
}

original_code:
void bbInit(void) {
 memset(BBBetween, 0, sizeof(BB)*SqNB*SqNB);
 memset(BBBeyond, 0, sizeof(BB)*SqNB*SqNB);
 unsigned int sqA, sqB, sqC;
 const int dirs[8]={-17,-16,-15,-1,+1,+15,+16,+17};
 int dirI, dir;
 for(sqA=0;sqA<128;sqA=((sqA+9)&~8))
  for(dirI=0;dirI<8;++dirI) {
   Sq sqA64=(sqMake(((sqA)&0xF0)>>4 , ((sqA)&0x07)));
   dir=dirs[dirI];
   BB set=BBNone;
   for(sqB=sqA+dir;;sqB+=dir) {
    if (sqB & 0x88)
     break;
    Sq sqB64=(sqMake(((sqB)&0xF0)>>4 , ((sqB)&0x07)));
    BBBetween[sqA64][sqB64]=set;
    for(sqC=sqB+dir;!(sqC & 0x88);sqC+=dir)
     BBBeyond[sqA64][sqB64]|=bbSq((sqMake(((sqC)&0xF0)>>4 , ((sqC)&0x07))));
    set|=bbSq(sqB64);
   }
  }
 int f1, f2, r1, r2;
 for(r1=Rank1;r1<=Rank8;++r1)
  for(f1=FileA;f1<=FileH;++f1) {
   sqA=sqMake(f1,r1);
   BBPawnSq[sqA]=BBNone;
   for(r2=Rank1;r2<=Rank8;++r2)
   for(f2=FileA;f2<=FileH;++f2)
    if (abs(f1-f2)<=7-r1 && r2>=r1)
     BBPawnSq[sqA]|=bbSq(sqMake(f2,r2));
  }
}

canonical_original_code:
void bbInit() {
 memset(BBBetween, 0, sizeof(BB)*SqNB*SqNB);
 memset(BBBeyond, 0, sizeof(BB)*SqNB*SqNB);
 unsigned int sqA; unsigned int sqB; unsigned int sqC;
 int dirs[8] = {-17,-16,-15,-1,+1,+15,+16,+17};
 int dirI; int dir;
 for(sqA=0;sqA<128;sqA=((sqA+9)&~8))
  for(dirI=0;dirI<8;++dirI) {
   enum Sq sqA64 = (sqMake(((sqA)&0xF0)>>4 , ((sqA)&0x07)));
   dir=dirs[dirI];
   unsigned long set = BBNone;
   for(sqB=sqA+dir;;sqB+=dir) {
    if (sqB & 0x88)
     break;
    enum Sq sqB64 = (sqMake(((sqB)&0xF0)>>4 , ((sqB)&0x07)));
    BBBetween[sqA64][sqB64]=set;
    for(sqC=sqB+dir;!(sqC & 0x88);sqC+=dir)
     BBBeyond[sqA64][sqB64]|=bbSq((sqMake(((sqC)&0xF0)>>4 , ((sqC)&0x07))));
    set|=bbSq(sqB64);
   }
  }
 int f1; int f2; int r1; int r2;
 for(r1=Rank1;r1<=Rank8;++r1)
  for(f1=FileA;f1<=FileH;++f1) {
   sqA=sqMake(f1,r1);
   BBPawnSq[sqA]=BBNone;
   for(r2=Rank1;r2<=Rank8;++r2)
   for(f2=FileA;f2<=FileH;++f2)
    if (abs(f1-f2)<=7-r1 && r2>=r1)
     BBPawnSq[sqA]|=bbSq(sqMake(f2,r2));
  }
}

variable_types:
sqA
unsigned int

variable_types:
sqB
unsigned int

variable_types:
sqC
unsigned int

variable_types:
dirs
int [8]

variable_types: dirI int

variable_types: dir int

variable_types:
set
unsigned long


bbDraw

decompiled_code:
__int64 __fastcall bbDraw(__int64 a1)
{
unsigned int i; // ebp
unsigned int j; // ebx
char v3; // al
_BOOL8 v4; // rsi
__int64 result; // rax

for ( i = 7; i != -1; --i )
{
for ( j = 0; j != 8; ++j )
{
v3 = sqMake(j, i);
v4 = (a1 & bbSq(v3)) != 0;
uciWrite(&unk_10700, v4);
}
result = uciWrite(&unk_10704, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int i; // ebp
unsigned int j; // ebx
char v3; // al
_BOOL8 v4; // rsi
__int64 result; // rax

for ( i = 7; i != -1; --i )
{
for ( j = 0; j != 8; ++j )
{
v3 = sqMake(j, i);
v4 = (a1 & func0(v3)) != 0;
uciWrite(&unk_10700, v4);
}
result = uciWrite(&unk_10704, v4);
}
return result;
}

original_code:
void bbDraw(BB bb) {
 int x, y;
 for(y=7;y>=0;--y) {
  for(x=0;x<8;++x)
   uciWrite(" %i", (bbSq(sqMake(x,y)) & bb)!=BBNone);
  uciWrite("\n");
 }
}

canonical_original_code:
void bbDraw(unsigned long bb) {
 int x; int y;
 for(y=7;y>=0;--y) {
  for(x=0;x<8;++x)
   uciWrite(" %i", (bbSq(sqMake(x,y)) & bb)!=BBNone);
  uciWrite("\n");
 }
}

variable_types:
bb
unsigned long

variable_types: x int

variable_types: y int


bbFile

decompiled_code:
__int64 __fastcall bbFile(char a1)
{
return 0x101010101010101LL << a1;
}

original_code:
BB bbFile(File file) {
 ((void) (0));
 return (BBFileA<<file);
}

canonical_original_code:
unsigned long bbFile(enum File file) {
 ((void) (0));
 return (BBFileA<<file);
}

variable_types: enum File { FileA=0, FileB=1, FileC=2, FileD=3, FileE=4, FileF=5, FileG=6, FileH=7, FileNB=8 }


bbRank

decompiled_code:
__int64 __fastcall bbRank(char a1)
{
return 255LL << (8 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return 255LL << (8 * a1);
}

original_code:
BB bbRank(Rank rank) {
 ((void) (0));
 return (BBRank1<<(8*rank));
}

canonical_original_code:
unsigned long bbRank(enum Rank rank) {
 ((void) (0));
 return (BBRank1<<(8*rank));
}

variable_types: enum Rank { Rank1=0, Rank2=1, Rank3=2, Rank4=3, Rank5=4, Rank6=5, Rank7=6, Rank8=7, RankNB=8 }


bbPopCount

decompiled_code:
__int64 bbPopCount()
{
return _popcountdi2();
}

canonical_decompiled_code:
__int64 func5()
{
return _popcountdi2();
}

original_code:
unsigned int bbPopCount(BB bb) {
  return __builtin_popcountll(bb);
}

canonical_original_code:
unsigned int bbPopCount(unsigned long bb) {
  return __builtin_popcountll(bb);
}


bbScanForward

decompiled_code:
__int64 __fastcall bbScanForward(__int64 _RDI)
{
__int64 result; // rax

__asm { tzcnt rax, rdi }
return result;
}

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

__asm { tzcnt rax, rdi }
return result;
}

original_code:
Sq bbScanForward(BB bb) {
 ((void) (0));
  return __builtin_ctzll(bb);
}

canonical_original_code:
enum Sq bbScanForward(unsigned long bb) {
 ((void) (0));
  return __builtin_ctzll(bb);
}


bbScanReset

decompiled_code:
__int64 __fastcall bbScanReset(__int64 *a1)
{
__int64 v1; // rbp
__int64 result; // rax

v1 = *a1;
result = bbScanForward(*a1);
*a1 = v1 & (v1 - 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1)
{
__int64 v1; // rbp
__int64 result; // rax

v1 = *a1;
result = func6(*a1);
*a1 = v1 & (v1 - 1);
return result;
}

original_code:
Sq bbScanReset(BB *bb) {
 ((void) (0));
 ((void) (0));
 Sq sq=bbScanForward(*bb);
 *bb&=(*bb-1);
 return sq;
}

canonical_original_code:
enum Sq bbScanReset(unsigned long *bb) {
 ((void) (0));
 ((void) (0));
 enum Sq sq = bbScanForward(*bb);
 *bb&=(*bb-1);
 return sq;
}

variable_types:
bb
unsigned long *


bbNorth

decompiled_code:
__int64 __fastcall bbNorth(__int64 a1, char a2)
{
return a1 << (8 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char a2)
{
return a1 << (8 * a2);
}

original_code:
BB bbNorth(BB bb, unsigned int n) {
 return (bb<<(8*n));
}

canonical_original_code:
unsigned long bbNorth(unsigned long bb, unsigned int n) {
 return (bb<<(8*n));
}

variable_types:
n
unsigned int


bbSouth

decompiled_code:
unsigned __int64 __fastcall bbSouth(unsigned __int64 a1, char a2)
{
return a1 >> (8 * a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned __int64 a1, char a2)
{
return a1 >> (8 * a2);
}

original_code:
BB bbSouth(BB bb, unsigned int n) {
 return (bb>>(8*n));
}

canonical_original_code:
unsigned long bbSouth(unsigned long bb, unsigned int n) {
 return (bb>>(8*n));
}


bbNorthOne

decompiled_code:
__int64 __fastcall bbNorthOne(__int64 a1)
{
return bbNorth(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func8(a1, 1);
}

original_code:
BB bbNorthOne(BB bb) {
 return bbNorth(bb, 1);
}

canonical_original_code:
unsigned long bbNorthOne(unsigned long bb) {
 return bbNorth(bb, 1);
}


bbSouthOne

decompiled_code:
unsigned __int64 __fastcall bbSouthOne(unsigned __int64 a1)
{
return bbSouth(a1, 1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned __int64 a1)
{
return func9(a1, 1);
}

original_code:
BB bbSouthOne(BB bb) {
 return bbSouth(bb, 1);
}

canonical_original_code:
unsigned long bbSouthOne(unsigned long bb) {
 return bbSouth(bb, 1);
}


bbWestOne

decompiled_code:
unsigned __int64 __fastcall bbWestOne(__int64 a1)
{
return (a1 & (unsigned __int64)~bbFile(0)) >> 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(__int64 a1)
{
return (a1 & (unsigned __int64)~func3(0)) >> 1;
}

original_code:
BB bbWestOne(BB bb) {
 return ((bb & ~bbFile(FileA))>>1);
}

canonical_original_code:
unsigned long bbWestOne(unsigned long bb) {
 return ((bb & ~bbFile(FileA))>>1);
}


bbEastOne

decompiled_code:
__int64 __fastcall bbEastOne(__int64 a1)
{
return 2 * (a1 & ~bbFile(7));
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return 2 * (a1 & ~func3(7));
}

original_code:
BB bbEastOne(BB bb) {
 return ((bb & ~bbFile(FileH))<<1);
}

canonical_original_code:
unsigned long bbEastOne(unsigned long bb) {
 return ((bb & ~bbFile(FileH))<<1);
}


bbForwardOne

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

if ( a2 )
result = bbSouthOne(a1);
else
result = bbNorthOne(a1);
return result;
}

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

if ( a2 )
result = func11(a1);
else
result = func10(a1);
return result;
}

original_code:
BB bbForwardOne(BB bb, Colour colour) {
 ((void) (0));
 return (colour==ColourWhite ? bbNorthOne(bb) : bbSouthOne(bb));
}

canonical_original_code:
unsigned long bbForwardOne(unsigned long bb, enum Colour colour) {
 ((void) (0));
 return (colour==ColourWhite ? bbNorthOne(bb) : bbSouthOne(bb));
}

variable_types: enum Colour { ColourWhite=0, ColourBlack=1, ColourNB=2 }


bbBackwardOne

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

if ( a2 )
result = bbNorthOne(a1);
else
result = bbSouthOne(a1);
return result;
}

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

if ( a2 )
result = func10(a1);
else
result = func11(a1);
return result;
}

original_code:
BB bbBackwardOne(BB bb, Colour colour) {
 ((void) (0));
 return (colour==ColourWhite ? bbSouthOne(bb) : bbNorthOne(bb));
}

canonical_original_code:
unsigned long bbBackwardOne(unsigned long bb, enum Colour colour) {
 ((void) (0));
 return (colour==ColourWhite ? bbSouthOne(bb) : bbNorthOne(bb));
}


bbNorthFill

decompiled_code:
__int64 __fastcall bbNorthFill(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

v1 = bbNorth(a1, 1) | a1;
v2 = bbNorth(v1, 2) | v1;
return v2 | bbNorth(v2, 4);
}

original_code:
BB bbNorthFill(BB bb) {
 bb|=bbNorth(bb, 1);
 bb|=bbNorth(bb, 2);
 bb|=bbNorth(bb, 4);
 return bb;
}

canonical_original_code:
unsigned long bbNorthFill(unsigned long bb) {
 bb|=bbNorth(bb, 1);
 bb|=bbNorth(bb, 2);
 bb|=bbNorth(bb, 4);
 return bb;
}


bbSouthFill

decompiled_code:
unsigned __int64 __fastcall bbSouthFill(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // rbx

v1 = bbSouth(a1, 1) | a1;
v2 = bbSouth(v1, 2) | v1;
return v2 | bbSouth(v2, 4);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // rbx

v1 = func9(a1, 1) | a1;
v2 = func9(v1, 2) | v1;
return v2 | func9(v2, 4);
}

original_code:
BB bbSouthFill(BB bb) {
 bb|=bbSouth(bb, 1);
 bb|=bbSouth(bb, 2);
 bb|=bbSouth(bb, 4);
 return bb;
}

canonical_original_code:
unsigned long bbSouthFill(unsigned long bb) {
 bb|=bbSouth(bb, 1);
 bb|=bbSouth(bb, 2);
 bb|=bbSouth(bb, 4);
 return bb;
}


bbFileFill

decompiled_code:
unsigned __int64 __fastcall bbFileFill(unsigned __int64 a1)
{
__int64 v1; // rbx

v1 = bbNorthFill(a1);
return v1 | bbSouthFill(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func18(unsigned __int64 a1)
{
__int64 v1; // rbx

v1 = func16(a1);
return v1 | func17(a1);
}

original_code:
BB bbFileFill(BB bb) {
 return bbNorthFill(bb) | bbSouthFill(bb);
}

canonical_original_code:
unsigned long bbFileFill(unsigned long bb) {
 return bbNorthFill(bb) | bbSouthFill(bb);
}


bbWingify

decompiled_code:
__int64 __fastcall bbWingify(__int64 a1)
{
unsigned __int64 v1; // rbx

v1 = bbWestOne(a1);
return v1 | bbEastOne(a1);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
unsigned __int64 v1; // rbx

v1 = func12(a1);
return v1 | func13(a1);
}

original_code:
BB bbWingify(BB bb) {
 return bbWestOne(bb) | bbEastOne(bb);
}

canonical_original_code:
unsigned long bbWingify(unsigned long bb) {
 return bbWestOne(bb) | bbEastOne(bb);
}


bbBetween

decompiled_code:
__int64 __fastcall bbBetween(__int64 a1, __int64 a2)
{
return BBBetween[64 * a1 + a2];
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2)
{
return BBBetween[64 * a1 + a2];
}

original_code:
BB bbBetween(BB sq1, BB sq2) {
 ((void) (0));
 ((void) (0));
 return BBBetween[sq1][sq2];
}

canonical_original_code:
unsigned long bbBetween(unsigned long sq1, unsigned long sq2) {
 ((void) (0));
 ((void) (0));
 return BBBetween[sq1][sq2];
}


bbBeyond

decompiled_code:
__int64 __fastcall bbBeyond(__int64 a1, __int64 a2)
{
return BBBeyond[64 * a1 + a2];
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2)
{
return BBBeyond[64 * a1 + a2];
}

original_code:
BB bbBeyond(BB sq1, BB sq2) {
 ((void) (0));
 ((void) (0));
 return BBBeyond[sq1][sq2];
}

canonical_original_code:
unsigned long bbBeyond(unsigned long sq1, unsigned long sq2) {
 ((void) (0));
 ((void) (0));
 return BBBeyond[sq1][sq2];
}


bbPawnSq

decompiled_code:
__int64 __fastcall bbPawnSq(int a1)
{
return BBPawnSq[a1];
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1)
{
return BBPawnSq[a1];
}

original_code:
BB bbPawnSq(Sq sq) {
 ((void) (0));
 return BBPawnSq[sq];
}

canonical_original_code:
unsigned long bbPawnSq(enum Sq sq) {
 ((void) (0));
 return BBPawnSq[sq];
}


bbMirror

canonical_original_code:
unsigned long bbMirror(unsigned long bb) {
 unsigned long k1 = 0x5555555555555555llu;
 unsigned long k2 = 0x3333333333333333llu;
 unsigned long k4 = 0x0f0f0f0f0f0f0f0fllu;
 bb=((bb>>1) & k1) + 2*(bb & k1);
 bb=((bb>>2) & k2) + 4*(bb & k2);
 bb=((bb>>4) & k4) + 16*(bb & k4);
 return bb;
}


bbFlip

decompiled_code:
__int64 __fastcall bbFlip(unsigned __int64 a1)
{
unsigned __int64 v1; // rax

v1 = (a1 << 8) & 0xFF00FF00FF00FF00LL | (a1 >> 8) & 0xFF00FF00FF00FFLL;
return __ROL8__((v1 >> 16) & 0xFFFF0000FFFFLL | (v1 << 16) & 0xFFFF0000FFFF0000LL, 32);
}

canonical_original_code:
unsigned long bbFlip(unsigned long bb) {
 unsigned long k1 = 0x00FF00FF00FF00FFllu;
 unsigned long k2 = 0x0000FFFF0000FFFFllu;
 bb=((bb>> 8) & k1) | ((bb & k1)<< 8);
 bb=((bb>>16) & k2) | ((bb & k2)<<16);
 bb=( bb>>32) | ( bb <<32);
 return bb;
}


decompiled_code:
__int64 __fastcall initmagicmoves_occ(__int64 a1, int a2, __int64 a3)
{
unsigned __int64 v4; // rax
__int64 v5; // rdi

if ( a2 <= 0 )
return 0LL;
v4 = 0LL;
v5 = 0LL;
do
{
if ( _bittest64(&a3, v4) )
v5 |= 1LL << *(_DWORD *)(a1 + 4 * v4);
++v4;
}
while ( v4 != a2 );
return v5;
}

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

if ( a2 <= 0 )
return 0LL;
v4 = 0LL;
v5 = 0LL;
do
{
if ( _bittest64(&a3, v4) )
v5 |= 1LL << *(_DWORD *)(a1 + 4 * v4);
++v4;
}
while ( v4 != a2 );
return v5;
}

original_code:
U64 initmagicmoves_occ(const int* squares, const int numSquares, const U64 linocc)
{
 int i;
 U64 ret=0;
 for(i=0;i<numSquares;i++)
  if(linocc&(((U64)(1))<<i)) ret|=(((U64)(1))<<squares[i]);
 return ret;
}

canonical_original_code:
unsigned long long initmagicmoves_occ(int *squares, int numSquares, unsigned long long linocc)
{
 int i;
 unsigned long long ret = 0;
 for(i=0;i<numSquares;i++)
  if(linocc&(((U64)(1))<<i)) ret|=(((U64)(1))<<squares[i]);
 return ret;
}

variable_types:
squares
int *

variable_types: numSquares int

variable_types:
linocc
unsigned long long

variable_types: i int

variable_types:
ret
unsigned long long

return_type: unsigned long long


decompiled_code:
__int64 __fastcall initmagicmoves_Rmoves(int a1, __int64 a2)
{
char v2; // al
char v3; // cl
__int64 v4; // rdi
unsigned __int64 v5; // rdx
__int64 v6; // rcx
__int64 result; // rax
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rcx

v2 = a1;
v3 = a1 + 7;
if ( a1 >= 0 )
v3 = a1;
v4 = 255LL << (v3 & 0xF8);
v5 = 1LL << v2;
v6 = 1LL << v2;
result = 0LL;
while ( 1 )
{
v6 <<= 8;
result |= v6;
if ( !v6 )
break;
if ( (a2 & v6) != 0 )
{
v8 = v5;
goto LABEL_8;
}
}
v8 = v5;
LABEL_8:
while ( 1 )
{
v8 >>= 8;
result |= v8;
if ( !v8 )
break;
if ( (v8 & a2) != 0 )
{
v9 = v5;
goto LABEL_12;
}
}
v9 = v5;
do
{
LABEL_12:
v9 *= 2LL;
if ( (v9 & v4) == 0 )
break;
result |= v9;
}
while ( (v9 & a2) == 0 );
do
{
v5 >>= 1;
if ( (v5 & v4) == 0 )
break;
result |= v5;
}
while ( (v5 & a2) == 0 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
char v2; // al
char v3; // cl
__int64 v4; // rdi
unsigned __int64 v5; // rdx
__int64 v6; // rcx
__int64 result; // rax
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rcx

v2 = a1;
v3 = a1 + 7;
if ( a1 >= 0 )
v3 = a1;
v4 = 255LL << (v3 & 0xF8);
v5 = 1LL << v2;
v6 = 1LL << v2;
result = 0LL;
while ( 1 )
{
v6 <<= 8;
result |= v6;
if ( !v6 )
break;
if ( (a2 & v6) != 0 )
{
v8 = v5;
goto LABEL_8;
}
}
v8 = v5;
LABEL_8:
while ( 1 )
{
v8 >>= 8;
result |= v8;
if ( !v8 )
break;
if ( (v8 & a2) != 0 )
{
v9 = v5;
goto LABEL_12;
}
}
v9 = v5;
do
{
LABEL_12:
v9 *= 2LL;
if ( (v9 & v4) == 0 )
break;
result |= v9;
}
while ( (v9 & a2) == 0 );
do
{
v5 >>= 1;
if ( (v5 & v4) == 0 )
break;
result |= v5;
}
while ( (v5 & a2) == 0 );
return result;
}

original_code:
U64 initmagicmoves_Rmoves(const int square, const U64 occ)
{
 U64 ret=0;
 U64 bit;
 U64 rowbits=(((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 return ret;
}

canonical_original_code:
unsigned long long initmagicmoves_Rmoves(int square, unsigned long long occ)
{
 unsigned long long ret = 0;
 unsigned long long bit;
 unsigned long long rowbits = (((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 return ret;
}

variable_types: square int

variable_types:
occ
unsigned long long

variable_types:
bit
unsigned long long

variable_types:
rowbits
unsigned long long


original_code:
U64 initmagicmoves_Bmoves(const int square, const U64 occ)
{
 U64 ret=0;
 U64 bit;
 U64 bit2;
 U64 rowbits=(((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8-1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8+1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8-1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8+1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 return ret;
}

canonical_original_code:
unsigned long long initmagicmoves_Bmoves(int square, unsigned long long occ)
{
 unsigned long long ret = 0;
 unsigned long long bit;
 unsigned long long bit2;
 unsigned long long rowbits = (((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8-1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8+1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8-1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8+1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 return ret;
}


initmagicmoves

original_code:
void initmagicmoves(void)
{
 int i;
 int initmagicmoves_bitpos64_database[64]={
 63, 0, 58, 1, 59, 47, 53, 2,
 60, 39, 48, 27, 54, 33, 42, 3,
 61, 51, 37, 40, 49, 18, 28, 20,
 55, 30, 34, 11, 43, 14, 22, 4,
 62, 57, 46, 52, 38, 26, 32, 41,
 50, 36, 17, 19, 29, 10, 13, 21,
 56, 45, 25, 31, 35, 16, 9, 12,
 44, 24, 15, 8, 23, 7, 6, 5};
 U64* magicmoves_b_indices2[64]=
 {
  magicmovesbdb+4992, magicmovesbdb+2624, magicmovesbdb+256, magicmovesbdb+896,
  magicmovesbdb+1280, magicmovesbdb+1664, magicmovesbdb+4800, magicmovesbdb+5120,
  magicmovesbdb+2560, magicmovesbdb+2656, magicmovesbdb+288, magicmovesbdb+928,
  magicmovesbdb+1312, magicmovesbdb+1696, magicmovesbdb+4832, magicmovesbdb+4928,
  magicmovesbdb+0, magicmovesbdb+128, magicmovesbdb+320, magicmovesbdb+960,
  magicmovesbdb+1344, magicmovesbdb+1728, magicmovesbdb+2304, magicmovesbdb+2432,
  magicmovesbdb+32, magicmovesbdb+160, magicmovesbdb+448, magicmovesbdb+2752,
  magicmovesbdb+3776, magicmovesbdb+1856, magicmovesbdb+2336, magicmovesbdb+2464,
  magicmovesbdb+64, magicmovesbdb+192, magicmovesbdb+576, magicmovesbdb+3264,
  magicmovesbdb+4288, magicmovesbdb+1984, magicmovesbdb+2368, magicmovesbdb+2496,
  magicmovesbdb+96, magicmovesbdb+224, magicmovesbdb+704, magicmovesbdb+1088,
  magicmovesbdb+1472, magicmovesbdb+2112, magicmovesbdb+2400, magicmovesbdb+2528,
  magicmovesbdb+2592, magicmovesbdb+2688, magicmovesbdb+832, magicmovesbdb+1216,
  magicmovesbdb+1600, magicmovesbdb+2240, magicmovesbdb+4864, magicmovesbdb+4960,
  magicmovesbdb+5056, magicmovesbdb+2720, magicmovesbdb+864, magicmovesbdb+1248,
  magicmovesbdb+1632, magicmovesbdb+2272, magicmovesbdb+4896, magicmovesbdb+5184
 };
 U64* magicmoves_r_indices2[64]=
 {
  magicmovesrdb+86016, magicmovesrdb+73728, magicmovesrdb+36864, magicmovesrdb+43008,
  magicmovesrdb+47104, magicmovesrdb+51200, magicmovesrdb+77824, magicmovesrdb+94208,
  magicmovesrdb+69632, magicmovesrdb+32768, magicmovesrdb+38912, magicmovesrdb+10240,
  magicmovesrdb+14336, magicmovesrdb+53248, magicmovesrdb+57344, magicmovesrdb+81920,
  magicmovesrdb+24576, magicmovesrdb+33792, magicmovesrdb+6144, magicmovesrdb+11264,
  magicmovesrdb+15360, magicmovesrdb+18432, magicmovesrdb+58368, magicmovesrdb+61440,
  magicmovesrdb+26624, magicmovesrdb+4096, magicmovesrdb+7168, magicmovesrdb+0,
  magicmovesrdb+2048, magicmovesrdb+19456, magicmovesrdb+22528, magicmovesrdb+63488,
  magicmovesrdb+28672, magicmovesrdb+5120, magicmovesrdb+8192, magicmovesrdb+1024,
  magicmovesrdb+3072, magicmovesrdb+20480, magicmovesrdb+23552, magicmovesrdb+65536,
  magicmovesrdb+30720, magicmovesrdb+34816, magicmovesrdb+9216, magicmovesrdb+12288,
  magicmovesrdb+16384, magicmovesrdb+21504, magicmovesrdb+59392, magicmovesrdb+67584,
  magicmovesrdb+71680, magicmovesrdb+35840, magicmovesrdb+39936, magicmovesrdb+13312,
  magicmovesrdb+17408, magicmovesrdb+54272, magicmovesrdb+60416, magicmovesrdb+83968,
  magicmovesrdb+90112, magicmovesrdb+75776, magicmovesrdb+40960, magicmovesrdb+45056,
  magicmovesrdb+49152, magicmovesrdb+55296, magicmovesrdb+79872, magicmovesrdb+98304
 };
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares=0;
  U64 temp=magicmoves_b_mask[i];
  while(temp)
  {
   U64 bit=temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2ULL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   U64 tempocc=initmagicmoves_occ(squares,numsquares,temp);
    *(magicmoves_b_indices2[i]+(((tempocc)*magicmoves_b_magics[i])>>magicmoves_b_shift[i]))=initmagicmoves_Bmoves(i,tempocc);
  }
 }
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares=0;
  U64 temp=magicmoves_r_mask[i];
  while(temp)
  {
   U64 bit=temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2ULL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   U64 tempocc=initmagicmoves_occ(squares,numsquares,temp);
    *(magicmoves_r_indices2[i]+(((tempocc)*magicmoves_r_magics[i])>>magicmoves_r_shift[i]))=initmagicmoves_Rmoves(i,tempocc);
  }
 }
}

canonical_original_code:
void initmagicmoves()
{
 int i;
 int initmagicmoves_bitpos64_database[64] = {
 63, 0, 58, 1, 59, 47, 53, 2,
 60, 39, 48, 27, 54, 33, 42, 3,
 61, 51, 37, 40, 49, 18, 28, 20,
 55, 30, 34, 11, 43, 14, 22, 4,
 62, 57, 46, 52, 38, 26, 32, 41,
 50, 36, 17, 19, 29, 10, 13, 21,
 56, 45, 25, 31, 35, 16, 9, 12,
 44, 24, 15, 8, 23, 7, 6, 5};
 unsigned long long *magicmoves_b_indices2[64] = {
  magicmovesbdb+4992, magicmovesbdb+2624, magicmovesbdb+256, magicmovesbdb+896,
  magicmovesbdb+1280, magicmovesbdb+1664, magicmovesbdb+4800, magicmovesbdb+5120,
  magicmovesbdb+2560, magicmovesbdb+2656, magicmovesbdb+288, magicmovesbdb+928,
  magicmovesbdb+1312, magicmovesbdb+1696, magicmovesbdb+4832, magicmovesbdb+4928,
  magicmovesbdb+0, magicmovesbdb+128, magicmovesbdb+320, magicmovesbdb+960,
  magicmovesbdb+1344, magicmovesbdb+1728, magicmovesbdb+2304, magicmovesbdb+2432,
  magicmovesbdb+32, magicmovesbdb+160, magicmovesbdb+448, magicmovesbdb+2752,
  magicmovesbdb+3776, magicmovesbdb+1856, magicmovesbdb+2336, magicmovesbdb+2464,
  magicmovesbdb+64, magicmovesbdb+192, magicmovesbdb+576, magicmovesbdb+3264,
  magicmovesbdb+4288, magicmovesbdb+1984, magicmovesbdb+2368, magicmovesbdb+2496,
  magicmovesbdb+96, magicmovesbdb+224, magicmovesbdb+704, magicmovesbdb+1088,
  magicmovesbdb+1472, magicmovesbdb+2112, magicmovesbdb+2400, magicmovesbdb+2528,
  magicmovesbdb+2592, magicmovesbdb+2688, magicmovesbdb+832, magicmovesbdb+1216,
  magicmovesbdb+1600, magicmovesbdb+2240, magicmovesbdb+4864, magicmovesbdb+4960,
  magicmovesbdb+5056, magicmovesbdb+2720, magicmovesbdb+864, magicmovesbdb+1248,
  magicmovesbdb+1632, magicmovesbdb+2272, magicmovesbdb+4896, magicmovesbdb+5184
 };
 unsigned long long *magicmoves_r_indices2[64] = {
  magicmovesrdb+86016, magicmovesrdb+73728, magicmovesrdb+36864, magicmovesrdb+43008,
  magicmovesrdb+47104, magicmovesrdb+51200, magicmovesrdb+77824, magicmovesrdb+94208,
  magicmovesrdb+69632, magicmovesrdb+32768, magicmovesrdb+38912, magicmovesrdb+10240,
  magicmovesrdb+14336, magicmovesrdb+53248, magicmovesrdb+57344, magicmovesrdb+81920,
  magicmovesrdb+24576, magicmovesrdb+33792, magicmovesrdb+6144, magicmovesrdb+11264,
  magicmovesrdb+15360, magicmovesrdb+18432, magicmovesrdb+58368, magicmovesrdb+61440,
  magicmovesrdb+26624, magicmovesrdb+4096, magicmovesrdb+7168, magicmovesrdb+0,
  magicmovesrdb+2048, magicmovesrdb+19456, magicmovesrdb+22528, magicmovesrdb+63488,
  magicmovesrdb+28672, magicmovesrdb+5120, magicmovesrdb+8192, magicmovesrdb+1024,
  magicmovesrdb+3072, magicmovesrdb+20480, magicmovesrdb+23552, magicmovesrdb+65536,
  magicmovesrdb+30720, magicmovesrdb+34816, magicmovesrdb+9216, magicmovesrdb+12288,
  magicmovesrdb+16384, magicmovesrdb+21504, magicmovesrdb+59392, magicmovesrdb+67584,
  magicmovesrdb+71680, magicmovesrdb+35840, magicmovesrdb+39936, magicmovesrdb+13312,
  magicmovesrdb+17408, magicmovesrdb+54272, magicmovesrdb+60416, magicmovesrdb+83968,
  magicmovesrdb+90112, magicmovesrdb+75776, magicmovesrdb+40960, magicmovesrdb+45056,
  magicmovesrdb+49152, magicmovesrdb+55296, magicmovesrdb+79872, magicmovesrdb+98304
 };
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares = 0;
  unsigned long long temp = magicmoves_b_mask[i];
  while(temp)
  {
   unsigned long long bit = temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2ULL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   unsigned long long tempocc = initmagicmoves_occ(squares,numsquares,temp);
    *(magicmoves_b_indices2[i]+(((tempocc)*magicmoves_b_magics[i])>>magicmoves_b_shift[i]))=initmagicmoves_Bmoves(i,tempocc);
  }
 }
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares = 0;
  unsigned long long temp = magicmoves_r_mask[i];
  while(temp)
  {
   unsigned long long bit = temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2ULL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   unsigned long long tempocc = initmagicmoves_occ(squares,numsquares,temp);
    *(magicmoves_r_indices2[i]+(((tempocc)*magicmoves_r_magics[i])>>magicmoves_r_shift[i]))=initmagicmoves_Rmoves(i,tempocc);
  }
 }
}

variable_types:
squares
int [64]

variable_types: numsquares int

variable_types:
temp
unsigned long long

variable_types:
tempocc
unsigned long long


attacksInit

decompiled_code:
__int64 attacksInit()
{
__int64 v0; // r14
__int64 v1; // r15
unsigned int i; // er12
int v3; // ebx
int v4; // ebx
int v5; // ebp
int v6; // ebp

v0 = 0LL;
v1 = BBNone;
do
{
attacksArrayKnight[v0] = v1;
attacksArrayKing[v0] = v1;
for ( i = 0; i != 64; ++i )
{
v3 = sqFile((unsigned int)v0);
v4 = abs32(v3 - sqFile(i));
v5 = sqRank((unsigned int)v0);
v6 = abs32(v5 - sqRank(i));
if ( v4 == 1 && v6 == 2 || v4 == 2 && v6 == 1 )
attacksArrayKnight[v0] |= bbSq(i);
if ( v4 <= 1 && v6 <= 1 && v6 | v4 )
attacksArrayKing[v0] |= bbSq(i);
}
++v0;
}
while ( v0 != 64 );
return initmagicmoves();
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r14
__int64 v1; // r15
unsigned int i; // er12
int v3; // ebx
int v4; // ebx
int v5; // ebp
int v6; // ebp

v0 = 0LL;
v1 = BBNone;
do
{
attacksArrayKnight[v0] = v1;
attacksArrayKing[v0] = v1;
for ( i = 0; i != 64; ++i )
{
v3 = sqFile((unsigned int)v0);
v4 = abs32(v3 - sqFile(i));
v5 = sqRank((unsigned int)v0);
v6 = abs32(v5 - sqRank(i));
if ( v4 == 1 && v6 == 2 || v4 == 2 && v6 == 1 )
attacksArrayKnight[v0] |= bbSq(i);
if ( v4 <= 1 && v6 <= 1 && v6 | v4 )
attacksArrayKing[v0] |= bbSq(i);
}
++v0;
}
while ( v0 != 64 );
return initmagicmoves();
}

original_code:
void attacksInit(void) {
 Sq from, to;
 for(from=0;from<SqNB;++from) {
  attacksArrayKnight[from]=BBNone;
  attacksArrayKing[from]=BBNone;
  for(to=0;to<SqNB;++to) {
   int dX=abs(((int)sqFile(from))-((int)sqFile(to)));
   int dY=abs(((int)sqRank(from))-((int)sqRank(to)));
   if ((dX==1 && dY==2) || (dX==2 && dY==1))
    attacksArrayKnight[from]|=bbSq(to);
   if (dX<=1 && dY<=1 && (dX!=0 || dY!=0))
    attacksArrayKing[from]|=bbSq(to);
  }
 }
 initmagicmoves();
}

canonical_original_code:
void attacksInit() {
 enum Sq from; enum Sq to;
 for(from=0;from<SqNB;++from) {
  attacksArrayKnight[from]=BBNone;
  attacksArrayKing[from]=BBNone;
  for(to=0;to<SqNB;++to) {
   int dX = abs(((int)sqFile(from))-((int)sqFile(to)));
   int dY = abs(((int)sqRank(from))-((int)sqRank(to)));
   if ((dX==1 && dY==2) || (dX==2 && dY==1))
    attacksArrayKnight[from]|=bbSq(to);
   if (dX<=1 && dY<=1 && (dX!=0 || dY!=0))
    attacksArrayKing[from]|=bbSq(to);
  }
 }
 initmagicmoves();
}

variable_types: dX int

variable_types: dY int


attacksPawn

decompiled_code:
__int64 __fastcall attacksPawn(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rax

v2 = bbSq(a1);
v3 = bbWingify(v2);
return bbForwardOne(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rax

v2 = bbSq(a1);
v3 = bbWingify(v2);
return bbForwardOne(v3, a2);
}

original_code:
BB attacksPawn(Sq sq, Colour colour) {
 ((void) (0));
 return bbForwardOne(bbWingify(bbSq(sq)), colour);
}

canonical_original_code:
unsigned long attacksPawn(enum Sq sq, enum Colour colour) {
 ((void) (0));
 return bbForwardOne(bbWingify(bbSq(sq)), colour);
}


attacksKnight

decompiled_code:
__int64 __fastcall attacksKnight(int a1)
{
return attacksArrayKnight[a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return attacksArrayKnight[a1];
}

original_code:
BB attacksKnight(Sq sq) {
 ((void) (0));
 return attacksArrayKnight[sq];
}

canonical_original_code:
unsigned long attacksKnight(enum Sq sq) {
 ((void) (0));
 return attacksArrayKnight[sq];
}


attacksBishop

decompiled_code:
__int64 __fastcall attacksBishop(unsigned int a1, unsigned __int64 a2)
{
return *(_QWORD *)(*((_QWORD *)&magicmoves_b_indices + a1)
+ 8
* ((*((_QWORD *)&magicmoves_b_magics + a1) * (*((_QWORD *)&magicmoves_b_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_b_shift + a1)));
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned __int64 a2)
{
return *(_QWORD *)(*((_QWORD *)&magicmoves_b_indices + a1)
+ 8
* ((*((_QWORD *)&magicmoves_b_magics + a1) * (*((_QWORD *)&magicmoves_b_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_b_shift + a1)));
}

original_code:
BB attacksBishop(Sq sq, BB occ) {
 ((void) (0));
 return Bmagic(sq, occ);
}

canonical_original_code:
unsigned long attacksBishop(enum Sq sq, unsigned long occ) {
 ((void) (0));
 return Bmagic(sq, occ);
}

variable_types:
occ
unsigned long


attacksRook

decompiled_code:
__int64 __fastcall attacksRook(unsigned int a1, unsigned __int64 a2)
{
return *(_QWORD *)(*((_QWORD *)&magicmoves_r_indices + a1)
+ 8
* ((*((_QWORD *)&magicmoves_r_magics + a1) * (*((_QWORD *)&magicmoves_r_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_r_shift + a1)));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned __int64 a2)
{
return *(_QWORD *)(*((_QWORD *)&magicmoves_r_indices + a1)
+ 8
* ((*((_QWORD *)&magicmoves_r_magics + a1) * (*((_QWORD *)&magicmoves_r_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_r_shift + a1)));
}

original_code:
BB attacksRook(Sq sq, BB occ) {
 ((void) (0));
 return Rmagic(sq, occ);
}

canonical_original_code:
unsigned long attacksRook(enum Sq sq, unsigned long occ) {
 ((void) (0));
 return Rmagic(sq, occ);
}


attacksQueen

decompiled_code:
__int64 __fastcall attacksQueen(unsigned int a1, unsigned __int64 a2)
{
return *(_QWORD *)(*((_QWORD *)&magicmoves_b_indices + a1)
+ 8
* ((*((_QWORD *)&magicmoves_b_magics + a1) * (*((_QWORD *)&magicmoves_b_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_b_shift + a1))) | *(_QWORD *)(*((_QWORD *)&magicmoves_r_indices + a1) + 8 * ((*((_QWORD *)&magicmoves_r_magics + a1) * (*((_QWORD *)&magicmoves_r_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_r_shift + a1)));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned __int64 a2)
{
return *(_QWORD *)(*((_QWORD *)&magicmoves_b_indices + a1)
+ 8
* ((*((_QWORD *)&magicmoves_b_magics + a1) * (*((_QWORD *)&magicmoves_b_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_b_shift + a1))) | *(_QWORD *)(*((_QWORD *)&magicmoves_r_indices + a1) + 8 * ((*((_QWORD *)&magicmoves_r_magics + a1) * (*((_QWORD *)&magicmoves_r_mask + a1) & a2)) >> *((_DWORD *)&magicmoves_r_shift + a1)));
}

original_code:
BB attacksQueen(Sq sq, BB occ) {
 ((void) (0));
 return (Bmagic(sq, occ)|Rmagic(sq, occ));
}

canonical_original_code:
unsigned long attacksQueen(enum Sq sq, unsigned long occ) {
 ((void) (0));
 return (Bmagic(sq, occ)|Rmagic(sq, occ));
}


attacksKing

decompiled_code:
__int64 __fastcall attacksKing(int a1)
{
return attacksArrayKing[a1];
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return attacksArrayKing[a1];
}

original_code:
BB attacksKing(Sq sq) {
 ((void) (0));
 return attacksArrayKing[sq];
}

canonical_original_code:
unsigned long attacksKing(enum Sq sq) {
 ((void) (0));
 return attacksArrayKing[sq];
}


attacksPiece

decompiled_code:
__int64 __fastcall attacksPiece(unsigned int a1, unsigned int a2, unsigned __int64 a3)
{
unsigned int v4; // eax
__int64 result; // rax

switch ( (unsigned int)pieceGetType() )
{
case 1u:
v4 = pieceGetColour(a1);
result = attacksPawn(a2, v4);
break;
case 2u:
result = attacksKnight(a2);
break;
case 3u:
case 4u:
result = attacksBishop(a2, a3);
break;
case 5u:
result = attacksRook(a2, a3);
break;
case 6u:
result = attacksQueen(a2, a3);
break;
case 7u:
result = attacksKing(a2);
break;
default:
result = BBNone;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, unsigned __int64 a3)
{
unsigned int v4; // eax
__int64 result; // rax

switch ( (unsigned int)pieceGetType() )
{
case 1u:
v4 = pieceGetColour(a1);
result = func1(a2, v4);
break;
case 2u:
result = func2(a2);
break;
case 3u:
case 4u:
result = func3(a2, a3);
break;
case 5u:
result = func4(a2, a3);
break;
case 6u:
result = func5(a2, a3);
break;
case 7u:
result = func6(a2);
break;
default:
result = BBNone;
break;
}
return result;
}

original_code:
BB attacksPiece(Piece piece, Sq sq, BB occ) {
 ((void) (0));
 ((void) (0));
 switch(pieceGetType(piece)) {
  case PieceTypePawn: return attacksPawn(sq, pieceGetColour(piece)); break;
  case PieceTypeKnight: return attacksKnight(sq); break;
  case PieceTypeBishopL: return attacksBishop(sq, occ); break;
  case PieceTypeBishopD: return attacksBishop(sq, occ); break;
  case PieceTypeRook: return attacksRook(sq, occ); break;
  case PieceTypeQueen: return attacksQueen(sq, occ); break;
  case PieceTypeKing: return attacksKing(sq); break;
  default: ((void) (0)); return BBNone; break;
 }
}

canonical_original_code:
unsigned long attacksPiece(enum Piece piece, enum Sq sq, unsigned long occ) {
 ((void) (0));
 ((void) (0));
 switch(pieceGetType(piece)) {
  case PieceTypePawn: return attacksPawn(sq, pieceGetColour(piece)); break;
  case PieceTypeKnight: return attacksKnight(sq); break;
  case PieceTypeBishopL: return attacksBishop(sq, occ); break;
  case PieceTypeBishopD: return attacksBishop(sq, occ); break;
  case PieceTypeRook: return attacksRook(sq, occ); break;
  case PieceTypeQueen: return attacksQueen(sq, occ); break;
  case PieceTypeKing: return attacksKing(sq); break;
  default: ((void) (0)); return BBNone; break;
 }
}

variable_types: enum Piece { PieceNone=expr, PieceWPawn=expr, PieceWKnight=expr, PieceWBishopL=expr, PieceWBishopD=expr, PieceWRook=expr, PieceWQueen=expr, PieceWKing=expr, PieceBPawn=expr, PieceBKnight=expr, PieceBBishopL=expr, PieceBBishopD=expr, PieceBRook=expr, PieceBQueen=expr, PieceBKing=expr, PieceNB=expr }


attacksPieceType

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

switch ( a1 )
{
case 2:
result = attacksKnight(a2);
break;
case 3:
case 4:
result = attacksBishop(a2, a3);
break;
case 5:
result = attacksRook(a2, a3);
break;
case 6:
result = attacksQueen(a2, a3);
break;
case 7:
result = attacksKing(a2);
break;
default:
result = BBNone;
break;
}
return result;
}

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

switch ( a1 )
{
case 2:
result = func2(a2);
break;
case 3:
case 4:
result = func3(a2, a3);
break;
case 5:
result = func4(a2, a3);
break;
case 6:
result = func5(a2, a3);
break;
case 7:
result = func6(a2);
break;
default:
result = BBNone;
break;
}
return result;
}

original_code:
BB attacksPieceType(PieceType type, Sq sq, BB occ) {
 ((void) (0));
 ((void) (0));
 switch(type) {
  case PieceTypeKnight: return attacksKnight(sq); break;
  case PieceTypeBishopL: return attacksBishop(sq, occ); break;
  case PieceTypeBishopD: return attacksBishop(sq, occ); break;
  case PieceTypeRook: return attacksRook(sq, occ); break;
  case PieceTypeQueen: return attacksQueen(sq, occ); break;
  case PieceTypeKing: return attacksKing(sq); break;
  default: ((void) (0)); return BBNone; break;
 }
}

canonical_original_code:
unsigned long attacksPieceType(enum PieceType type, enum Sq sq, unsigned long occ) {
 ((void) (0));
 ((void) (0));
 switch(type) {
  case PieceTypeKnight: return attacksKnight(sq); break;
  case PieceTypeBishopL: return attacksBishop(sq, occ); break;
  case PieceTypeBishopD: return attacksBishop(sq, occ); break;
  case PieceTypeRook: return attacksRook(sq, occ); break;
  case PieceTypeQueen: return attacksQueen(sq, occ); break;
  case PieceTypeKing: return attacksKing(sq); break;
  default: ((void) (0)); return BBNone; break;
 }
}

variable_types: enum PieceType { PieceTypeNone=0, PieceTypePawn=1, PieceTypeKnight=2, PieceTypeBishopL=3, PieceTypeBishopD=4, PieceTypeRook=5, PieceTypeQueen=6, PieceTypeKing=7, PieceTypeNB=8 }


htableFree

decompiled_code:
void __fastcall htableFree(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void htableFree(HTable *table) {
 free(table->entries);
 free(table);
}

canonical_original_code:
void htableFree(struct HTable *table) {
 free(table->entries);
 free(table);
}

variable_types: struct HTable { unsigned long entrySize; unsigned long entryCount; void *entries; } *


htableClear

decompiled_code:
void *__fastcall htableClear(__int64 a1)
{
return memset(*(void **)(a1 + 16), 0, *(_QWORD *)a1 * *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
return memset(*(void **)(a1 + 16), 0, *(_QWORD *)a1 * *(_QWORD *)(a1 + 8));
}

original_code:
void htableClear(HTable *table) {
 memset(table->entries, 0, table->entryCount*table->entrySize);
}

canonical_original_code:
void htableClear(struct HTable *table) {
 memset(table->entries, 0, table->entryCount*table->entrySize);
}

user_defined_types: struct HTable { unsigned long entrySize; unsigned long entryCount; void *entries; }


htableResize

decompiled_code:
__int64 __fastcall htableResize(__int64 a1, unsigned int a2)
{
unsigned __int64 v2; // rsi
__int64 v3; // rdx
unsigned __int64 v4; // rbp
void *v5; // rax

v2 = (unsigned __int64)a2 << 20;
v3 = 0x100000000LL;
if ( v2 / *(_QWORD *)a1 <= 0x100000000LL )
v3 = v2 / *(_QWORD *)a1;
v4 = v3;
if ( v2 < *(_QWORD *)a1 )
return 0LL;
while ( 1 )
{
v5 = realloc(*(void **)(a1 + 16), *(_QWORD *)a1 * v4);
if ( v5 )
{
*(_QWORD *)(a1 + 16) = v5;
*(_QWORD *)(a1 + 8) = v4;
htableClear(a1);
return 1LL;
}
if ( v4 <= 1 )
break;
v4 >>= 1;
}
return 0LL;
}

original_code:
_Bool htableResize(HTable *table, unsigned int sizeMb) {
 ((void) (0));
 ((void) (0));
 uint64_t entryCount=(((uint64_t)sizeMb)*1024llu*1024llu)/table->entrySize;
 if (entryCount>((1llu)<<(32)))
  entryCount=((1llu)<<(32));
 while(entryCount>0) {
  void *ptr=realloc(table->entries, entryCount*table->entrySize);
  if (ptr!=((void *)0)) {
   table->entries=ptr;
   table->entryCount=entryCount;
   htableClear(table);
   return 1;
  }
  entryCount/=2;
 }
 return 0;
}

canonical_original_code:
_Bool htableResize(struct HTable *table, unsigned int sizeMb) {
 ((void) (0));
 ((void) (0));
 unsigned long entryCount = (((uint64_t)sizeMb)*1024llu*1024llu)/table->entrySize;
 if (entryCount>((1llu)<<(32)))
  entryCount=((1llu)<<(32));
 while(entryCount>0) {
  void *ptr = realloc(table->entries, entryCount*table->entrySize);
  if (ptr!=((void *)0)) {
   table->entries=ptr;
   table->entryCount=entryCount;
   htableClear(table);
   return 1;
  }
  entryCount/=2;
 }
 return 0;
}

variable_types:
sizeMb
unsigned int

variable_types:
entryCount
unsigned long

variable_types:
ptr
void *


htableResizeInterface

decompiled_code:
__int64 __fastcall htableResizeInterface(__int64 a1, unsigned int a2)
{
return htableResize(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return func2(a1, a2);
}

original_code:
void htableResizeInterface(void *table, long long int sizeMb) {
 htableResize(table, sizeMb);
}

canonical_original_code:
void htableResizeInterface(void *table, long long sizeMb) {
 htableResize(table, sizeMb);
}

variable_types:
table
void *

variable_types:
sizeMb
long long


htableClearInterface

decompiled_code:
void *__fastcall htableClearInterface(__int64 a1)
{
return htableClear(a1);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1)
{
return func1(a1);
}

original_code:
void htableClearInterface(void *table) {
 htableClear(table);
}


htableRelease

decompiled_code:
void htableRelease()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void htableRelease(HTable *table, HTableKey key) {
}

canonical_original_code:
void htableRelease(struct HTable *table, unsigned int key) {
}

variable_types:
key
unsigned int


htableGetEntryCount

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

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

original_code:
size_t htableGetEntryCount(const HTable *table) {
 return table->entryCount;
}

canonical_original_code:
unsigned long htableGetEntryCount(struct HTable *table) {
 return table->entryCount;
}


htableIndexToEntry

decompiled_code:
__int64 __fastcall htableIndexToEntry(_QWORD *a1, __int64 a2)
{
return a1[2] + *a1 * a2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
return a1[2] + *a1 * a2;
}

original_code:
void *htableIndexToEntry(HTable *table, uint64_t index) {
 ((void) (0));
 return ((void *)(((char *)table->entries)+(index*table->entrySize)));
}

canonical_original_code:
void *htableIndexToEntry(struct HTable *table, unsigned long index) {
 ((void) (0));
 return ((void *)(((char *)table->entries)+(index*table->entrySize)));
}

variable_types:
index
unsigned long


htableKeyToEntry

decompiled_code:
__int64 __fastcall htableKeyToEntry(_QWORD *a1, unsigned int a2)
{
return htableIndexToEntry(a1, (a1[1] * (unsigned __int64)a2) >> 32);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, unsigned int a2)
{
return func8(a1, (a1[1] * (unsigned __int64)a2) >> 32);
}

original_code:
void *htableKeyToEntry(HTable *table, HTableKey key) {
 uint64_t index=(((uint64_t)key)*table->entryCount)>>32;
 ((void) (0));
 return htableIndexToEntry(table, index);
}

canonical_original_code:
void *htableKeyToEntry(struct HTable *table, unsigned int key) {
 unsigned long index = (((uint64_t)key)*table->entryCount)>>32;
 ((void) (0));
 return htableIndexToEntry(table, index);
}


htableGrab

decompiled_code:
// attributes: thunk
__int64 __fastcall htableGrab(_QWORD *a1, unsigned int a2)
{
return htableKeyToEntry(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, unsigned int a2)
{
return func9(a1, a2);
}

original_code:
void *htableGrab(HTable *table, HTableKey key) {
 return htableKeyToEntry(table, key);
}

canonical_original_code:
void *htableGrab(struct HTable *table, unsigned int key) {
 return htableKeyToEntry(table, key);
}


killersCutoff

decompiled_code:
__int64 __fastcall killersCutoff(unsigned int a1, int a2)
{
__int64 v2; // rdx
__int64 i; // rax
int v4; // ecx
__int64 result; // rax

v2 = 4LL * a1;
for ( i = 0LL; i != 3; ++i )
{
v4 = i;
if ( killers[i + v2] == a2 )
break;
if ( MoveInvalid == a2 )
break;
v4 = i + 1;
}
result = v4;
if ( v4 > 0 )
{
do
{
killers[result + v2] = killers[result - 1 + v2];
--result;
}
while ( (int)result > 0 );
}
killers[4 * a1] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
__int64 v2; // rdx
__int64 i; // rax
int v4; // ecx
__int64 result; // rax

v2 = 4LL * a1;
for ( i = 0LL; i != 3; ++i )
{
v4 = i;
if ( killers[i + v2] == a2 )
break;
if ( MoveInvalid == a2 )
break;
v4 = i + 1;
}
result = v4;
if ( v4 > 0 )
{
do
{
killers[result + v2] = killers[result - 1 + v2];
--result;
}
while ( (int)result > 0 );
}
killers[4 * a1] = a2;
return result;
}

original_code:
void killersCutoff(Depth ply, Move move) {
 int i;
 for(i=0;i<4 -1;++i) {
  if (move==killers[ply][i] || move==MoveInvalid)
   break;
 }
 for(;i>0;--i)
  killers[ply][i]=killers[ply][i-1];
 killers[ply][0]=move;
}

canonical_original_code:
void killersCutoff(enum Depth ply, unsigned int move) {
 int i;
 for(i=0;i<4 -1;++i) {
  if (move==killers[ply][i] || move==MoveInvalid)
   break;
 }
 for(;i>0;--i)
  killers[ply][i]=killers[ply][i-1];
 killers[ply][0]=move;
}

variable_types: enum Depth { DepthMax=128, DepthInvalid=255 }

variable_types:
move
unsigned int

variable_types: i int


killersClear

decompiled_code:
int *killersClear()
{
int v0; // edx
int *result; // rax

v0 = MoveInvalid;
result = killers;
do
{
*result = v0;
result[1] = v0;
result[2] = v0;
result[3] = v0;
result += 4;
}
while ( (int *)(unsigned int)((_DWORD)killers + 2048) != result );
return result;
}

canonical_decompiled_code:
int *func1()
{
int v0; // edx
int *result; // rax

v0 = MoveInvalid;
result = killers;
do
{
*result = v0;
result[1] = v0;
result[2] = v0;
result[3] = v0;
result += 4;
}
while ( (int *)(unsigned int)((_DWORD)killers + 2048) != result );
return result;
}

original_code:
void killersClear(void) {
 int i, j;
 for(i=0;i<DepthMax;++i)
  for(j=0;j<4;++j)
   killers[i][j]=MoveInvalid;
}

canonical_original_code:
void killersClear() {
 int i; int j;
 for(i=0;i<DepthMax;++i)
  for(j=0;j<4;++j)
   killers[i][j]=MoveInvalid;
}

variable_types: j int


scoredMoveMake

decompiled_code:
__int64 __fastcall scoredMoveMake(__int64 a1, unsigned int a2)
{
return (a1 << 16) | a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
return (a1 << 16) | a2;
}

original_code:
ScoredMove scoredMoveMake(MoveScore score, Move move) {
 return (((ScoredMove)score)<<16) | ((ScoredMove)move);
}

canonical_original_code:
unsigned long scoredMoveMake(unsigned long score, unsigned int move) {
 return (((unsigned long)score)<<16) | ((unsigned long)move);
}

variable_types:
score
unsigned long


scoredMoveGetScore

decompiled_code:
unsigned __int64 __fastcall scoredMoveGetScore(unsigned __int64 a1)
{
return a1 >> 16;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1)
{
return a1 >> 16;
}

original_code:
MoveScore scoredMoveGetScore(ScoredMove scoredMove) {
 return scoredMove>>16;
}

canonical_original_code:
unsigned long scoredMoveGetScore(unsigned long scoredMove) {
 return scoredMove>>16;
}

variable_types:
scoredMove
unsigned long


scoredMoveGetMove

decompiled_code:
__int64 __fastcall scoredMoveGetMove(unsigned __int16 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
return a1;
}

original_code:
Move scoredMoveGetMove(ScoredMove scoredMove) {
 return scoredMove & ((1llu<<16)-1);
}

canonical_original_code:
unsigned int scoredMoveGetMove(unsigned long scoredMove) {
 return scoredMove & ((1llu<<16)-1);
}


scoredMoveCompGT

decompiled_code:
bool __fastcall scoredMoveCompGT(unsigned __int64 a1, unsigned __int64 a2)
{
return a1 > a2;
}

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

original_code:
_Bool scoredMoveCompGT(ScoredMove moveA, ScoredMove moveB) {
 ((void) (0));
 return moveA>moveB;
}

canonical_original_code:
_Bool scoredMoveCompGT(unsigned long moveA, unsigned long moveB) {
 ((void) (0));
 return moveA>moveB;
}

variable_types:
moveA
unsigned long

variable_types:
moveB
unsigned long


timeGet

decompiled_code:
unsigned __int64 timeGet()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 0x3E8uLL;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 0x3E8uLL;
}

original_code:
TimeMs timeGet(void) {
 struct timeval tp;
 gettimeofday(&tp, ((void *)0));
 return tp.tv_sec*1000llu+tp.tv_usec/1000llu;
}

canonical_original_code:
unsigned long long timeGet() {
 struct timeval tp;
 gettimeofday(&tp, ((void *)0));
 return tp.tv_sec*1000llu+tp.tv_usec/1000llu;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
uciInit(argc, argv, envp);
bbInit();
attacksInit();
bitbaseInit();
posInit();
evalInit();
ttInit();
searchInit();
uciLoop();
searchQuit();
ttQuit();
evalQuit();
bitbaseQuit();
return 0;
}

original_code:
int main(int argc, char **argv) {
 uciInit();
 bbInit();
 attacksInit();
 bitbaseInit();
 posInit();
 evalInit();
 ttInit();
 searchInit();
 uciLoop();
 searchQuit();
 ttQuit();
 evalQuit();
 bitbaseQuit();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


mainFatalError

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

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

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

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void mainFatalError(const char *format, ...) {
 va_list ap;
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void mainFatalError(char *format, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
 exit(1);
}

variable_types:
format
char *


benchmark

decompiled_code:
__int64 benchmark()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx

searchClear();
evalClear();
v0 = benchmarkFen((__int64)"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 9u);
v1 = benchmarkFen((__int64)"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 8u) + v0;
v2 = benchmarkFen((__int64)"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1", 0xBu) + v1;
v3 = benchmarkFen((__int64)"r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1", 9u) + v2;
v4 = benchmarkFen((__int64)"rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6", 8u) + v3;
v5 = benchmarkFen((__int64)"r1bq1rk1/pppnnppp/4p3/3pP3/1b1P4/2NB3N/PPP2PPP/R1BQK2R w KQ - 3 7", 8u) + v4;
v6 = benchmarkFen((__int64)"rnb3nr/ppq2kpp/4pp2/1B1pP3/P5Q1/B1p2N2/2P2PPP/R4RK1 w - - 0 1", 7u) + v5;
return v6 + benchmarkFen((__int64)"3B4/1r2p3/r2p1p2/bkp1P1p1/1p1P1PPp/p1P1K2P/PPB5/8 w - - 0 1", 0xAu);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx

searchClear();
evalClear();
v0 = func0((__int64)"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 9u);
v1 = func0((__int64)"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 8u) + v0;
v2 = func0((__int64)"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1", 0xBu) + v1;
v3 = func0((__int64)"r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1", 9u) + v2;
v4 = func0((__int64)"rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6", 8u) + v3;
v5 = func0((__int64)"r1bq1rk1/pppnnppp/4p3/3pP3/1b1P4/2NB3N/PPP2PPP/R1BQK2R w KQ - 3 7", 8u) + v4;
v6 = func0((__int64)"rnb3nr/ppq2kpp/4pp2/1B1pP3/P5Q1/B1p2N2/2P2PPP/R4RK1 w - - 0 1", 7u) + v5;
return v6 + func0((__int64)"3B4/1r2p3/r2p1p2/bkp1P1p1/1p1P1PPp/p1P1K2P/PPB5/8 w - - 0 1", 0xAu);
}

original_code:
unsigned long long int benchmark(void) {
 searchClear();
 evalClear();
 unsigned long long int nodes=0;
 nodes+=benchmarkFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 9);
 nodes+=benchmarkFen("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 8);
 nodes+=benchmarkFen("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1", 11);
 nodes+=benchmarkFen("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1", 9);
 nodes+=benchmarkFen("rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6", 8);
 nodes+=benchmarkFen("r1bq1rk1/pppnnppp/4p3/3pP3/1b1P4/2NB3N/PPP2PPP/R1BQK2R w KQ - 3 7", 8);
 nodes+=benchmarkFen("rnb3nr/ppq2kpp/4pp2/1B1pP3/P5Q1/B1p2N2/2P2PPP/R4RK1 w - - 0 1", 7);
 nodes+=benchmarkFen("3B4/1r2p3/r2p1p2/bkp1P1p1/1p1P1PPp/p1P1K2P/PPB5/8 w - - 0 1", 10);
 return nodes;
}

canonical_original_code:
unsigned long long benchmark() {
 searchClear();
 evalClear();
 unsigned long long nodes = 0;
 nodes+=benchmarkFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 9);
 nodes+=benchmarkFen("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", 8);
 nodes+=benchmarkFen("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1", 11);
 nodes+=benchmarkFen("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1", 9);
 nodes+=benchmarkFen("rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6", 8);
 nodes+=benchmarkFen("r1bq1rk1/pppnnppp/4p3/3pP3/1b1P4/2NB3N/PPP2PPP/R1BQK2R w KQ - 3 7", 8);
 nodes+=benchmarkFen("rnb3nr/ppq2kpp/4pp2/1B1pP3/P5Q1/B1p2N2/2P2PPP/R4RK1 w - - 0 1", 7);
 nodes+=benchmarkFen("3B4/1r2p3/r2p1p2/bkp1P1p1/1p1P1PPp/p1P1K2P/PPB5/8 w - - 0 1", 10);
 return nodes;
}

variable_types:
nodes
unsigned long long


pop

repo: Darksecond/Landmine

decompiled_code:
__int64 pop()
{
__int16 v0; // ax

v0 = reg[1] + 1;
reg[1] = v0;
return (unsigned __int16)reg[v0];
}

canonical_decompiled_code:
__int64 func0()
{
__int16 v0; // ax

v0 = reg[1] + 1;
reg[1] = v0;
return (unsigned __int16)reg[v0];
}

original_code:
int16_t pop()
{
 return reg[++reg[1]];
}

canonical_original_code:
short pop()
{
 return reg[++reg[1]];
}

return_type: short


push

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

LOWORD(result) = reg[1];
reg[1] = result - 1;
result = (__int16)result;
reg[(__int16)result] = a1;
return result;
}

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

LOWORD(result) = reg[1];
reg[1] = result - 1;
result = (__int16)result;
reg[(__int16)result] = a1;
return result;
}

original_code:
void push(int16_t value)
{
 reg[reg[1]--] = value;
}

canonical_original_code:
void push(short value)
{
 reg[reg[1]--] = value;
}

variable_types: value short


chkzero

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

if ( a1 )
result = (unsigned __int16)reg[2] & 0xFFFE;
else
result = (unsigned __int16)reg[2] | 1u;
reg[2] = result;
return result;
}

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

if ( a1 )
result = (unsigned __int16)reg[2] & 0xFFFE;
else
result = (unsigned __int16)reg[2] | 1u;
reg[2] = result;
return result;
}

original_code:
void chkzero(int16_t value)
{
 if (value == 0)
 {
  reg[2] = reg[2]|1;
 }
 else
 {
  reg[2] = reg[2] & (~1);
 }
}

canonical_original_code:
void chkzero(short value)
{
 if (value == 0)
 {
  reg[2] = reg[2]|1;
 }
 else
 {
  reg[2] = reg[2] & (~1);
 }
}


chkcarry

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

if ( a1 )
result = (unsigned __int16)reg[2] | 2u;
else
result = (unsigned __int16)reg[2] & 0xFFFD;
reg[2] = result;
return result;
}

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

if ( a1 )
result = (unsigned __int16)reg[2] | 2u;
else
result = (unsigned __int16)reg[2] & 0xFFFD;
reg[2] = result;
return result;
}

original_code:
void chkcarry(int16_t value)
{
 if (value != 0)
 {
  reg[2] = reg[2]|2;
 }
 else
 {
  reg[2] = reg[2] & (~2);
 }
}

canonical_original_code:
void chkcarry(short value)
{
 if (value != 0)
 {
  reg[2] = reg[2]|2;
 }
 else
 {
  reg[2] = reg[2] & (~2);
 }
}


decompiled_code:
__int64 vm_running()
{
return ((unsigned __int8)((unsigned __int16)reg[2] >> 3) ^ 1) & 1;
}

canonical_decompiled_code:
__int64 func4()
{
return ((unsigned __int8)((unsigned __int16)reg[2] >> 3) ^ 1) & 1;
}

original_code:
uint8_t vm_running()
{
 if((reg[2] & 8))
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

canonical_original_code:
unsigned char vm_running()
{
 if((reg[2] & 8))
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall vm_interrupt(unsigned __int8 a1)
{
__int64 result; // rax

if ( (reg[2] & 4) != 0 )
{
if ( intr[a1] )
{
result = (unsigned int)(1 << a1);
*((_DWORD *)reg_u32 + 127) |= result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
__int64 result; // rax

if ( (reg[2] & 4) != 0 )
{
if ( intr[a1] )
{
result = (unsigned int)(1 << a1);
*((_DWORD *)reg_u32 + 127) |= result;
}
}
return result;
}

original_code:
void vm_interrupt(uint8_t interrupt)
{
 if (reg[2] & 4)
 {
  if(intr[interrupt])
  {
   reg_u32[127] = reg_u32[127] | (1 << interrupt);
  }
 }
}

canonical_original_code:
void vm_interrupt(unsigned char interrupt)
{
 if (reg[2] & 4)
 {
  if(intr[interrupt])
  {
   reg_u32[127] = reg_u32[127] | (1 << interrupt);
  }
 }
}

variable_types:
interrupt
unsigned char