repo: BullPaf/Pacman

decompiled_code:
int __fastcall extract_val(__int64 a1, int a2)
{
int v4; // er15
int v5; // edx
int v6; // ebx
__int64 v7; // rax
int v8; // eax
char v9; // cl
int v10; // er12
char v11; // si
__int64 v12; // rax
char *v13; // rdi
int v14; // ecx
int v15; // edx
int v16; // edx
int v17; // er12
char v18; // si
__int64 v19; // rax
char *v20; // rdi
int v21; // ecx
int v22; // edx
char v23; // al
__int64 v25; // [rsp+8h] [rbp-50h]
char nptr[59]; // [rsp+1Dh] [rbp-3Bh] BYREF

strcpy(nptr, "00");
v4 = 0;
v5 = 0;
v6 = 0;
v25 = 31LL * a2;
do
{
LODWORD(v7) = *(unsigned __int8 *)(a1 + v5);
if ( (_BYTE)v7 == 32 )
{
++v5;
}
else
{
switch ( (_BYTE)v7 )
{
case '0':
v7 = v25 + v6;
LODWORD(LEVEL[v7]) = 0;
++v5;
break;
case '1':
LODWORD(LEVEL[v25 + v6]) = 1;
v10 = v5 + 2;
v11 = *(_BYTE *)(a1 + v5 + 2);
if ( v11 != 32 )
{
v12 = v5 + 3;
v13 = &nptr[-v5];
v14 = -2 - v5;
do
{
v13[v12 - 3] = v11;
v15 = v14 + v12;
v10 = v12++;
v11 = *(_BYTE *)(a1 + v12 - 1);
}
while ( v11 != 32 );
if ( v15 == 1 )
{
nptr[1] = nptr[0];
nptr[0] = 48;
}
}
v16 = atoi(nptr);
v7 = v25 + v6;
HIDWORD(LEVEL[v7]) = v16;
v5 = v10 + 1;
break;
case '2':
LODWORD(LEVEL[v25 + v6]) = 2;
v17 = v5 + 2;
v18 = *(_BYTE *)(a1 + v5 + 2);
if ( v18 != 32 )
{
v19 = v5 + 3;
v20 = &nptr[-v5];
v21 = -2 - v5;
do
{
v20[v19 - 3] = v18;
v22 = v21 + v19;
v17 = v19++;
v18 = *(_BYTE *)(a1 + v19 - 1);
}
while ( v18 != 32 );
if ( v22 == 1 )
{
nptr[1] = nptr[0];
nptr[0] = 48;
}
}
HIDWORD(LEVEL[v25 + v6]) = atoi(nptr);
LODWORD(v7) = atoi(nptr);
if ( (_DWORD)v7 == 9 )
++POINTS;
v5 = v17 + 1;
break;
case '3':
LODWORD(LEVEL[v25 + v6]) = 3;
PAC_START_X = v6;
PAC_START_Y = a2;
v23 = *(_BYTE *)(a1 + v5 + 2);
switch ( v23 )
{
case '0':
PAC_START_DIRECTION = 0;
break;
case '1':
PAC_START_DIRECTION = 1;
break;
case '2':
PAC_START_DIRECTION = 2;
break;
case '3':
PAC_START_DIRECTION = 3;
break;
}
v7 = v25 + v6;
HIDWORD(LEVEL[v7]) = PAC_START_DIRECTION;
v5 += 3;
break;
case '4':
v8 = NB_GHOST;
if ( NB_GHOST > 15 )
{
fwrite("Fatal Error: Too much ghosts!\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
++NB_GHOST;
LODWORD(LEVEL[v25 + v6]) = 4;
v9 = *(_BYTE *)(a1 + v5 + 2);
switch ( v9 )
{
case '0':
v4 = 0;
break;
case '1':
v4 = 1;
break;
case '2':
v4 = 2;
break;
case '3':
v4 = 3;
break;
}
GHOST_START_X[v8] = v6;
GHOST_START_Y[v8] = a2;
GHOST_COULEUR[v8] = v4;
v7 = v25 + v6;
HIDWORD(LEVEL[v7]) = v4;
v5 += 3;
break;
}
++v6;
}
}
while ( v6 <= 30 );
if ( v6 != 31 )
{
fprintf(
stderr,
"Error, file level not correctly formated: Expected %d values, only %d values were read\n",
31LL,
(unsigned int)v6);
exit(1);
}
return v7;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
int v4; // er15
int v5; // edx
int v6; // ebx
__int64 v7; // rax
int v8; // eax
char v9; // cl
int v10; // er12
char v11; // si
__int64 v12; // rax
char *v13; // rdi
int v14; // ecx
int v15; // edx
int v16; // edx
int v17; // er12
char v18; // si
__int64 v19; // rax
char *v20; // rdi
int v21; // ecx
int v22; // edx
char v23; // al
__int64 v25; // [rsp+8h] [rbp-50h]
char nptr[59]; // [rsp+1Dh] [rbp-3Bh] BYREF

strcpy(nptr, "00");
v4 = 0;
v5 = 0;
v6 = 0;
v25 = 31LL * a2;
do
{
LODWORD(v7) = *(unsigned __int8 *)(a1 + v5);
if ( (_BYTE)v7 == 32 )
{
++v5;
}
else
{
switch ( (_BYTE)v7 )
{
case '0':
v7 = v25 + v6;
LODWORD(LEVEL[v7]) = 0;
++v5;
break;
case '1':
LODWORD(LEVEL[v25 + v6]) = 1;
v10 = v5 + 2;
v11 = *(_BYTE *)(a1 + v5 + 2);
if ( v11 != 32 )
{
v12 = v5 + 3;
v13 = &nptr[-v5];
v14 = -2 - v5;
do
{
v13[v12 - 3] = v11;
v15 = v14 + v12;
v10 = v12++;
v11 = *(_BYTE *)(a1 + v12 - 1);
}
while ( v11 != 32 );
if ( v15 == 1 )
{
nptr[1] = nptr[0];
nptr[0] = 48;
}
}
v16 = atoi(nptr);
v7 = v25 + v6;
HIDWORD(LEVEL[v7]) = v16;
v5 = v10 + 1;
break;
case '2':
LODWORD(LEVEL[v25 + v6]) = 2;
v17 = v5 + 2;
v18 = *(_BYTE *)(a1 + v5 + 2);
if ( v18 != 32 )
{
v19 = v5 + 3;
v20 = &nptr[-v5];
v21 = -2 - v5;
do
{
v20[v19 - 3] = v18;
v22 = v21 + v19;
v17 = v19++;
v18 = *(_BYTE *)(a1 + v19 - 1);
}
while ( v18 != 32 );
if ( v22 == 1 )
{
nptr[1] = nptr[0];
nptr[0] = 48;
}
}
HIDWORD(LEVEL[v25 + v6]) = atoi(nptr);
LODWORD(v7) = atoi(nptr);
if ( (_DWORD)v7 == 9 )
++POINTS;
v5 = v17 + 1;
break;
case '3':
LODWORD(LEVEL[v25 + v6]) = 3;
PAC_START_X = v6;
PAC_START_Y = a2;
v23 = *(_BYTE *)(a1 + v5 + 2);
switch ( v23 )
{
case '0':
PAC_START_DIRECTION = 0;
break;
case '1':
PAC_START_DIRECTION = 1;
break;
case '2':
PAC_START_DIRECTION = 2;
break;
case '3':
PAC_START_DIRECTION = 3;
break;
}
v7 = v25 + v6;
HIDWORD(LEVEL[v7]) = PAC_START_DIRECTION;
v5 += 3;
break;
case '4':
v8 = NB_GHOST;
if ( NB_GHOST > 15 )
{
fwrite("Fatal Error: Too much ghosts!\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
++NB_GHOST;
LODWORD(LEVEL[v25 + v6]) = 4;
v9 = *(_BYTE *)(a1 + v5 + 2);
switch ( v9 )
{
case '0':
v4 = 0;
break;
case '1':
v4 = 1;
break;
case '2':
v4 = 2;
break;
case '3':
v4 = 3;
break;
}
GHOST_START_X[v8] = v6;
GHOST_START_Y[v8] = a2;
GHOST_COULEUR[v8] = v4;
v7 = v25 + v6;
HIDWORD(LEVEL[v7]) = v4;
v5 += 3;
break;
}
++v6;
}
}
while ( v6 <= 30 );
if ( v6 != 31 )
{
fprintf(
stderr,
"Error, file level not correctly formated: Expected %d values, only %d values were read\n",
31LL,
(unsigned int)v6);
exit(1);
}
return v7;
}

original_code:
void extract_val(char *s, int line)
{
 char nb[3], type;
 nb[0]='0'; nb[1]='0'; nb[2]='\0';
 int nb_val=0,i=0,j=0,ghost=0;
 while(nb_val < 31)
 {
  if(s[i] != ' ')
  {
   type = s[i];
   if(type == '0')
   {
    LEVEL[line][nb_val].type = RIEN;
    i++;
   }
   else if(type=='1')
   {
    LEVEL[line][nb_val].type = MUR;
    i+=2;
    while(s[i] != ' ')
    {
     nb[j]=s[i];
     j++; i++;
    }
    if(j==1)
    {
     nb[1]=nb[0];
     nb[0]='0';
    }
    LEVEL[line][nb_val].elt_type=atoi(nb);
    i++; j=0;
   }
   else if(type=='2')
   {
    LEVEL[line][nb_val].type = BONUS;
    i+=2;
    while(s[i] != ' ')
    {
     nb[j]=s[i];
     j++; i++;
    }
    if(j==1)
    {
     nb[1]=nb[0];
     nb[0]='0';
    }
    LEVEL[line][nb_val].elt_type=atoi(nb);
    if(atoi(nb) == 9) POINTS++;
    i++; j=0;
   }
   else if(type=='3')
   {
    i+=2;
    LEVEL[line][nb_val].type = PACMAN;
    PAC_START_X=nb_val;
    PAC_START_Y=line;
    if(s[i]=='0') PAC_START_DIRECTION = HAUT;
    else if(s[i]=='1') PAC_START_DIRECTION = DROITE;
    else if(s[i]=='2') PAC_START_DIRECTION = BAS;
    else if(s[i]=='3') PAC_START_DIRECTION = GAUCHE;
    LEVEL[line][nb_val].elt_type=PAC_START_DIRECTION;
    i++;
   }
   else if(type=='4')
   {
    i+=2;
    if(NB_GHOST < 16) NB_GHOST++;
    else
    {
     fprintf(stderr, "Fatal Error: Too much ghosts!\n");
     exit(1);
    }
    LEVEL[line][nb_val].type = GHOST;
    if(s[i]=='0') ghost=ROUGE;
    else if(s[i]=='1') ghost=VIOLET;
    else if(s[i]=='2') ghost=BLEU;
    else if(s[i]=='3') ghost=JAUNE;
    GHOST_START_X[NB_GHOST-1]=nb_val;
    GHOST_START_Y[NB_GHOST-1]=line;
    GHOST_COULEUR[NB_GHOST-1]=ghost;
    LEVEL[line][nb_val].elt_type=ghost;
    i++;
   }
   nb_val ++;
  }
  else i++;
 }
 if (nb_val != 31)
 {
  fprintf(stderr, "Error, file level not correctly formated: Expected %d values, only %d values were read\n", 31, nb_val);
  exit(1);
 }
}

canonical_original_code:
void extract_val(char *s, int line)
{
 char nb[3]; char type;
 nb[0]='0'; nb[1]='0'; nb[2]='\0';
 int nb_val = 0; int i = 0; int j = 0; int ghost = 0;
 while(nb_val < 31)
 {
  if(s[i] != ' ')
  {
   type = s[i];
   if(type == '0')
   {
    LEVEL[line][nb_val].type = RIEN;
    i++;
   }
   else if(type=='1')
   {
    LEVEL[line][nb_val].type = MUR;
    i+=2;
    while(s[i] != ' ')
    {
     nb[j]=s[i];
     j++; i++;
    }
    if(j==1)
    {
     nb[1]=nb[0];
     nb[0]='0';
    }
    LEVEL[line][nb_val].elt_type=atoi(nb);
    i++; j=0;
   }
   else if(type=='2')
   {
    LEVEL[line][nb_val].type = BONUS;
    i+=2;
    while(s[i] != ' ')
    {
     nb[j]=s[i];
     j++; i++;
    }
    if(j==1)
    {
     nb[1]=nb[0];
     nb[0]='0';
    }
    LEVEL[line][nb_val].elt_type=atoi(nb);
    if(atoi(nb) == 9) POINTS++;
    i++; j=0;
   }
   else if(type=='3')
   {
    i+=2;
    LEVEL[line][nb_val].type = PACMAN;
    PAC_START_X=nb_val;
    PAC_START_Y=line;
    if(s[i]=='0') PAC_START_DIRECTION = HAUT;
    else if(s[i]=='1') PAC_START_DIRECTION = DROITE;
    else if(s[i]=='2') PAC_START_DIRECTION = BAS;
    else if(s[i]=='3') PAC_START_DIRECTION = GAUCHE;
    LEVEL[line][nb_val].elt_type=PAC_START_DIRECTION;
    i++;
   }
   else if(type=='4')
   {
    i+=2;
    if(NB_GHOST < 16) NB_GHOST++;
    else
    {
     fprintf(stderr, "Fatal Error: Too much ghosts!\n");
     exit(1);
    }
    LEVEL[line][nb_val].type = GHOST;
    if(s[i]=='0') ghost=ROUGE;
    else if(s[i]=='1') ghost=VIOLET;
    else if(s[i]=='2') ghost=BLEU;
    else if(s[i]=='3') ghost=JAUNE;
    GHOST_START_X[NB_GHOST-1]=nb_val;
    GHOST_START_Y[NB_GHOST-1]=line;
    GHOST_COULEUR[NB_GHOST-1]=ghost;
    LEVEL[line][nb_val].elt_type=ghost;
    i++;
   }
   nb_val ++;
  }
  else i++;
 }
 if (nb_val != 31)
 {
  fprintf(stderr, "Error, file level not correctly formated: Expected %d values, only %d values were read\n", 31, nb_val);
  exit(1);
 }
}

variable_types:
s
char *

variable_types:
nb
char [3]

variable_types: type char

variable_types: j int

variable_types: ghost int


decompiled_code:
__int64 init_level()
{
unsigned __int64 v0; // rdx
_DWORD *v1; // rax
__int64 result; // rax

v0 = (unsigned int)((_DWORD)LEVEL + 248);
do
{
v1 = (_DWORD *)(v0 - 248);
do
{
*v1 = 0;
v1 += 2;
}
while ( v1 != (_DWORD *)v0 );
v0 += 248LL;
}
while ( v0 != (_DWORD)LEVEL + 7936 );
for ( result = 0LL; result != 16; ++result )
{
GHOST_START_X[result] = -1;
GHOST_START_Y[result] = -1;
}
POINTS = 0;
NB_GHOST = 0;
return result * 4;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned __int64 v0; // rdx
_DWORD *v1; // rax
__int64 result; // rax

v0 = (unsigned int)((_DWORD)LEVEL + 248);
do
{
v1 = (_DWORD *)(v0 - 248);
do
{
*v1 = 0;
v1 += 2;
}
while ( v1 != (_DWORD *)v0 );
v0 += 248LL;
}
while ( v0 != (_DWORD)LEVEL + 7936 );
for ( result = 0LL; result != 16; ++result )
{
GHOST_START_X[result] = -1;
GHOST_START_Y[result] = -1;
}
POINTS = 0;
NB_GHOST = 0;
return result * 4;
}

original_code:
void init_level()
{
 int i,j;
 for(i=0; i<31; i++)
 {
  for(j=0; j<31; j++)
   LEVEL[i][j].type = RIEN;
 }
 for(i=0; i<16; i++) GHOST_START_Y[i]=GHOST_START_X[i]=-1;
 POINTS=0;
 NB_GHOST=0;
}

canonical_original_code:
void init_level()
{
 int i; int j;
 for(i=0; i<31; i++)
 {
  for(j=0; j<31; j++)
   LEVEL[i][j].type = RIEN;
 }
 for(i=0; i<16; i++) GHOST_START_Y[i]=GHOST_START_X[i]=-1;
 POINTS=0;
 NB_GHOST=0;
}

variable_types: i int

return_type: void


decompiled_code:
__int64 init_blocks()
{
__int64 i; // rbx
__int64 j; // rbx
__int64 k; // rbx
__int64 l; // rbx
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

for ( i = 0LL; i != 20; ++i )
{
sprintf(v5, "image/level/%d.png", (unsigned int)i);
BLOCK_MUR[i] = IMG_Load(v5);
}
for ( j = 0LL; j != 10; ++j )
{
sprintf(v5, "image/bonus/%d.png", (unsigned int)j);
BLOCK_BONUS[j] = IMG_Load(v5);
}
for ( k = 0LL; k != 4; ++k )
{
sprintf(v5, "image/pacman/%d.png", (unsigned int)(2 * k));
BLOCK_PACMAN[k] = IMG_Load(v5);
}
for ( l = 0LL; l != 4; ++l )
{
sprintf(v5, "image/ghosts/%d.png", (unsigned int)(8 * l));
BLOCK_GHOST[l] = IMG_Load(v5);
}
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rbx
__int64 j; // rbx
__int64 k; // rbx
__int64 l; // rbx
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

for ( i = 0LL; i != 20; ++i )
{
sprintf(v5, "image/level/%d.png", (unsigned int)i);
BLOCK_MUR[i] = IMG_Load(v5);
}
for ( j = 0LL; j != 10; ++j )
{
sprintf(v5, "image/bonus/%d.png", (unsigned int)j);
BLOCK_BONUS[j] = IMG_Load(v5);
}
for ( k = 0LL; k != 4; ++k )
{
sprintf(v5, "image/pacman/%d.png", (unsigned int)(2 * k));
BLOCK_PACMAN[k] = IMG_Load(v5);
}
for ( l = 0LL; l != 4; ++l )
{
sprintf(v5, "image/ghosts/%d.png", (unsigned int)(8 * l));
BLOCK_GHOST[l] = IMG_Load(v5);
}
return 1LL;
}

original_code:
int init_blocks()
{
 int i;
 char img[32];
 for (i=0; i<20; i++)
 {
  sprintf(img, "image/level/%d.png", i);
  BLOCK_MUR[i] = IMG_Load(img);
 }
 for (i=0; i<10; i++)
 {
  sprintf(img, "image/bonus/%d.png", i);
  BLOCK_BONUS[i] = IMG_Load(img);
 }
 for (i=0; i<4; i++)
 {
  sprintf(img, "image/pacman/%d.png", i*2);
  BLOCK_PACMAN[i] = IMG_Load(img);
 }
 for (i=0; i<4; i++)
 {
  sprintf(img, "image/ghosts/%d.png", i*8);
  BLOCK_GHOST[i] = IMG_Load(img);
 }
 return 1;
}

variable_types:
img
char [32]

return_type: int


original_code:
void draw_level()
{
 int i,j;
 POINT p1, p2;
 SDL_Rect position;
 for(i=0; i<31; i++)
 {
  position.y=i*20;
  for(j=0; j<31; j++)
  {
   position.x=j*20;
   affiche_une_case(LEVEL[i][j], &position, screen);
  }
 }
 p1.x=p2.x=20*31; p1.y=20*31 -1; p2.y=0;
 draw_line(p1, p2, 0xffff, screen);
}

canonical_original_code:
void draw_level()
{
 int i; int j;
 struct point p1; struct point p2;
 struct SDL_Rect position;
 for(i=0; i<31; i++)
 {
  position.y=i*20;
  for(j=0; j<31; j++)
  {
   position.x=j*20;
   affiche_une_case(LEVEL[i][j], &position, screen);
  }
 }
 p1.x=p2.x=20*31; p1.y=20*31 -1; p2.y=0;
 draw_line(p1, p2, 0xffff, screen);
}

variable_types: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
_BOOL8 __fastcall dans_case(int a1)
{
return ((unsigned __int16)(SHIWORD(a1) % 20) | (unsigned __int16)((__int16)a1 % 20)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1)
{
return ((unsigned __int16)(SHIWORD(a1) % 20) | (unsigned __int16)((__int16)a1 % 20)) == 0;
}

original_code:
int dans_case(SDL_Rect pos)
{
 if( (pos.x % 20==0) && (pos.y % 20==0) ) return 1;
 else return 0;
}

canonical_original_code:
int dans_case(struct SDL_Rect pos)
{
 if( (pos.x % 20==0) && (pos.y % 20==0) ) return 1;
 else return 0;
}

user_defined_types: struct SDL_Rect { short x; unsigned short w; }


original_code:
SDL_Rect get_case(SDL_Rect position, int direction)
{
 SDL_Rect pos;
 switch(direction)
 {
  case DROITE:
   pos.x = (position.x+20 -1)/20;
   pos.y = position.y/20;
   break;
  case BAS:
   pos.x = position.x/20;
   pos.y = (position.y+20 -1)/20;
   break;
  default:
   pos.x = position.x/20;
   pos.y = position.y/20;
   break;
 }
 return pos;
}

canonical_original_code:
struct SDL_Rect get_case(struct SDL_Rect position, int direction)
{
 struct SDL_Rect pos;
 switch(direction)
 {
  case DROITE:
   pos.x = (position.x+20 -1)/20;
   pos.y = position.y/20;
   break;
  case BAS:
   pos.x = position.x/20;
   pos.y = (position.y+20 -1)/20;
   break;
  default:
   pos.x = position.x/20;
   pos.y = position.y/20;
   break;
 }
 return pos;
}

variable_types:
position
struct SDL_Rect

variable_types: direction int

return_type: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
__int64 __fastcall remove_right_bloc(unsigned int a1)
{
__int64 result; // rax

result = 11LL;
if ( a1 )
{
switch ( a1 )
{
case 3u:
result = 10LL;
break;
case 5u:
result = 12LL;
break;
case 6u:
result = 2LL;
break;
default:
result = 1LL;
if ( a1 != 7 )
{
if ( a1 == 8 )
{
result = 4LL;
}
else
{
result = 17LL;
if ( a1 != 14 )
result = a1;
}
}
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 result; // rax

result = 11LL;
if ( a1 )
{
switch ( a1 )
{
case 3u:
result = 10LL;
break;
case 5u:
result = 12LL;
break;
case 6u:
result = 2LL;
break;
default:
result = 1LL;
if ( a1 != 7 )
{
if ( a1 == 8 )
{
result = 4LL;
}
else
{
result = 17LL;
if ( a1 != 14 )
result = a1;
}
}
break;
}
}
return result;
}

original_code:
int remove_right_bloc(int elt)
{
 if(elt==0) return 11;
 else if(elt==3) return 10;
 else if(elt==5) return 12;
 else if(elt==6) return 2;
 else if(elt==7) return 1;
 else if(elt==8) return 4;
 else if(elt==14) return 17;
 else return elt;
}

variable_types: elt int


decompiled_code:
__int64 __fastcall remove_left_bloc(unsigned int a1)
{
__int64 result; // rax

result = 13LL;
if ( a1 )
{
switch ( a1 )
{
case 2u:
result = 12LL;
break;
case 4u:
result = 10LL;
break;
case 6u:
result = 5LL;
break;
case 8u:
result = 3LL;
break;
default:
result = 1LL;
if ( a1 != 9 )
{
result = 19LL;
if ( a1 != 14 )
result = a1;
}
break;
}
}
return result;
}

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

result = 13LL;
if ( a1 )
{
switch ( a1 )
{
case 2u:
result = 12LL;
break;
case 4u:
result = 10LL;
break;
case 6u:
result = 5LL;
break;
case 8u:
result = 3LL;
break;
default:
result = 1LL;
if ( a1 != 9 )
{
result = 19LL;
if ( a1 != 14 )
result = a1;
}
break;
}
}
return result;
}

original_code:
int remove_left_bloc(int elt)
{
 if(elt==0) return 13;
 else if(elt==2) return 12;
 else if(elt==4) return 10;
 else if(elt==6) return 5;
 else if(elt==8) return 3;
 else if(elt==9) return 1;
 else if(elt==14) return 19;
 else return elt;
}


decompiled_code:
__int64 __fastcall remove_up_bloc(unsigned int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 1u:
return 10LL;
case 2u:
return 11LL;
case 5u:
return 13LL;
}
result = 0LL;
if ( a1 != 6 )
{
if ( a1 == 7 )
{
result = 3LL;
}
else if ( a1 == 9 )
{
result = 4LL;
}
else
{
result = 16LL;
if ( a1 != 15 )
result = a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 1u:
return 10LL;
case 2u:
return 11LL;
case 5u:
return 13LL;
}
result = 0LL;
if ( a1 != 6 )
{
if ( a1 == 7 )
{
result = 3LL;
}
else if ( a1 == 9 )
{
result = 4LL;
}
else
{
result = 16LL;
if ( a1 != 15 )
result = a1;
}
}
return result;
}

original_code:
int remove_up_bloc(int elt)
{
 if(elt==1) return 10;
 else if(elt==2) return 11;
 else if(elt==5) return 13;
 else if(elt==6) return 0;
 else if(elt==7) return 3;
 else if(elt==9) return 4;
 else if(elt==15) return 16;
 else return elt;
}


decompiled_code:
__int64 __fastcall remove_down_bloc(unsigned int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 1u:
return 12LL;
case 3u:
return 13LL;
case 4u:
return 11LL;
case 7u:
return 5LL;
}
result = 0LL;
if ( a1 != 8 )
{
if ( a1 == 9 )
{
result = 2LL;
}
else
{
result = 18LL;
if ( a1 != 15 )
result = a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 1u:
return 12LL;
case 3u:
return 13LL;
case 4u:
return 11LL;
case 7u:
return 5LL;
}
result = 0LL;
if ( a1 != 8 )
{
if ( a1 == 9 )
{
result = 2LL;
}
else
{
result = 18LL;
if ( a1 != 15 )
result = a1;
}
}
return result;
}

original_code:
int remove_down_bloc(int elt)
{
 if(elt==1) return 12;
 else if(elt==3) return 13;
 else if(elt==4) return 11;
 else if(elt==7) return 5;
 else if(elt==8) return 0;
 else if(elt==9) return 2;
 else if(elt==15) return 18;
 else return elt;
}


decompiled_code:
__int64 __fastcall remove_bloc(int a1, int a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r12
int v5; // ebp
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rbp
__int64 v9; // r12
__int64 v10; // rbp
__int64 v11; // rdx
__int64 v12; // rbp
__int64 v13; // rbp

v2 = a2 + 31LL * a1;
LODWORD(LEVEL[v2]) = 0;
result = (unsigned int)(HIDWORD(LEVEL[v2]) - 14);
switch ( (int)result )
{
case 0:
if ( !a2 )
goto LABEL_29;
result = a2 - 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
{
v4 = a2 - 1 + 31LL * a1;
result = remove_right_bloc(HIDWORD(LEVEL[v4]));
HIDWORD(LEVEL[v4]) = result;
}
if ( a2 <= 30 )
{
LABEL_29:
v5 = a2 + 1;
result = a2 + 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
goto LABEL_26;
}
break;
case 1:
if ( !a1 )
goto LABEL_30;
v6 = 31LL * (a1 - 1);
result = v6 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
{
v9 = v6 + a2;
result = remove_down_bloc(HIDWORD(LEVEL[v9]));
HIDWORD(LEVEL[v9]) = result;
}
if ( a1 <= 30 )
{
LABEL_30:
v7 = 31LL * (a1 + 1);
result = v7 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
goto LABEL_14;
}
break;
case 2:
if ( a1 <= 30 )
{
v7 = 31LL * (a1 + 1);
result = v7 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
{
LABEL_14:
v8 = v7 + a2;
result = remove_up_bloc(HIDWORD(LEVEL[result]));
HIDWORD(LEVEL[v8]) = result;
}
}
break;
case 3:
if ( a2 )
{
result = a2 - 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
{
v10 = 31LL * a1 + a2 - 1;
result = remove_right_bloc(HIDWORD(LEVEL[v10]));
HIDWORD(LEVEL[v10]) = result;
}
}
break;
case 4:
if ( a1 )
{
v11 = 31LL * (a1 - 1);
result = v11 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
{
v12 = v11 + a2;
result = remove_down_bloc(HIDWORD(LEVEL[result]));
HIDWORD(LEVEL[v12]) = result;
}
}
break;
case 5:
if ( a2 <= 30 )
{
v5 = a2 + 1;
result = a2 + 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
{
LABEL_26:
v13 = 31LL * a1 + v5;
result = remove_left_bloc(HIDWORD(LEVEL[v13]));
HIDWORD(LEVEL[v13]) = result;
}
}
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // r12
int v5; // ebp
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rbp
__int64 v9; // r12
__int64 v10; // rbp
__int64 v11; // rdx
__int64 v12; // rbp
__int64 v13; // rbp

v2 = a2 + 31LL * a1;
LODWORD(LEVEL[v2]) = 0;
result = (unsigned int)(HIDWORD(LEVEL[v2]) - 14);
switch ( (int)result )
{
case 0:
if ( !a2 )
goto LABEL_29;
result = a2 - 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
{
v4 = a2 - 1 + 31LL * a1;
result = func7(HIDWORD(LEVEL[v4]));
HIDWORD(LEVEL[v4]) = result;
}
if ( a2 <= 30 )
{
LABEL_29:
v5 = a2 + 1;
result = a2 + 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
goto LABEL_26;
}
break;
case 1:
if ( !a1 )
goto LABEL_30;
v6 = 31LL * (a1 - 1);
result = v6 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
{
v9 = v6 + a2;
result = func10(HIDWORD(LEVEL[v9]));
HIDWORD(LEVEL[v9]) = result;
}
if ( a1 <= 30 )
{
LABEL_30:
v7 = 31LL * (a1 + 1);
result = v7 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
goto LABEL_14;
}
break;
case 2:
if ( a1 <= 30 )
{
v7 = 31LL * (a1 + 1);
result = v7 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
{
LABEL_14:
v8 = v7 + a2;
result = func9(HIDWORD(LEVEL[result]));
HIDWORD(LEVEL[v8]) = result;
}
}
break;
case 3:
if ( a2 )
{
result = a2 - 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
{
v10 = 31LL * a1 + a2 - 1;
result = func7(HIDWORD(LEVEL[v10]));
HIDWORD(LEVEL[v10]) = result;
}
}
break;
case 4:
if ( a1 )
{
v11 = 31LL * (a1 - 1);
result = v11 + a2;
if ( LODWORD(LEVEL[result]) == 1 )
{
v12 = v11 + a2;
result = func10(HIDWORD(LEVEL[result]));
HIDWORD(LEVEL[v12]) = result;
}
}
break;
case 5:
if ( a2 <= 30 )
{
v5 = a2 + 1;
result = a2 + 1 + 31LL * a1;
if ( LODWORD(LEVEL[result]) == 1 )
{
LABEL_26:
v13 = 31LL * a1 + v5;
result = func8(HIDWORD(LEVEL[v13]));
HIDWORD(LEVEL[v13]) = result;
}
}
break;
default:
return result;
}
return result;
}

original_code:
void remove_bloc(int y, int x)
{
 LEVEL[y][x].type=RIEN;
 switch(LEVEL[y][x].elt_type)
 {
  case 14:
   if(x && LEVEL[y][x-1].type==MUR) LEVEL[y][x-1].elt_type = remove_right_bloc(LEVEL[y][x-1].elt_type);
   if(x<31 && LEVEL[y][x+1].type==MUR)
    LEVEL[y][x+1].elt_type = remove_left_bloc(LEVEL[y][x+1].elt_type);
   break;
  case 15:
   if(y && LEVEL[y-1][x].type==MUR) LEVEL[y-1][x].elt_type = remove_down_bloc(LEVEL[y-1][x].elt_type);
   if(y<31 && LEVEL[y+1][x].type==MUR)
    LEVEL[y+1][x].elt_type = remove_up_bloc(LEVEL[y+1][x].elt_type);
   break;
  case 16:
   if(y<31 && LEVEL[y+1][x].type==MUR)
    LEVEL[y+1][x].elt_type = remove_up_bloc(LEVEL[y+1][x].elt_type);
   break;
  case 17:
   if(x && LEVEL[y][x-1].type==MUR) LEVEL[y][x-1].elt_type = remove_right_bloc(LEVEL[y][x-1].elt_type);
   break;
  case 18:
   if(y && LEVEL[y-1][x].type==MUR) LEVEL[y-1][x].elt_type = remove_down_bloc(LEVEL[y-1][x].elt_type);
   break;
  case 19:
   if(x<31 && LEVEL[y][x+1].type==MUR)
    LEVEL[y][x+1].elt_type = remove_left_bloc(LEVEL[y][x+1].elt_type);
   break;
 }
}

variable_types: y int

variable_types: x int


decompiled_code:
void delete_blocks()
{
void **v0; // rbx
void **v1; // rbx
void **v2; // rbx
void **v3; // rbx

v0 = (void **)BLOCK_MUR;
do
free(*v0++);
while ( v0 != (void **)(unsigned int)((_DWORD)BLOCK_MUR + 160) );
v1 = (void **)BLOCK_BONUS;
do
free(*v1++);
while ( v1 != (void **)(unsigned int)((_DWORD)BLOCK_BONUS + 80) );
v2 = (void **)BLOCK_PACMAN;
do
free(*v2++);
while ( (void **)(unsigned int)((_DWORD)BLOCK_PACMAN + 32) != v2 );
v3 = (void **)BLOCK_GHOST;
do
free(*v3++);
while ( (void **)(unsigned int)((_DWORD)BLOCK_GHOST + 32) != v3 );
}

canonical_decompiled_code:
void func17()
{
void **v0; // rbx
void **v1; // rbx
void **v2; // rbx
void **v3; // rbx

v0 = (void **)BLOCK_MUR;
do
free(*v0++);
while ( v0 != (void **)(unsigned int)((_DWORD)BLOCK_MUR + 160) );
v1 = (void **)BLOCK_BONUS;
do
free(*v1++);
while ( v1 != (void **)(unsigned int)((_DWORD)BLOCK_BONUS + 80) );
v2 = (void **)BLOCK_PACMAN;
do
free(*v2++);
while ( (void **)(unsigned int)((_DWORD)BLOCK_PACMAN + 32) != v2 );
v3 = (void **)BLOCK_GHOST;
do
free(*v3++);
while ( (void **)(unsigned int)((_DWORD)BLOCK_GHOST + 32) != v3 );
}

original_code:
void delete_blocks()
{
 int i;
 for (i=0; i<20; i++)
  free(BLOCK_MUR[i]);
 for (i=0; i<10; i++)
  free(BLOCK_BONUS[i]);
 for (i=0; i<4; i++)
  free(BLOCK_PACMAN[i]);
 for (i=0; i<4; i++)
  free(BLOCK_GHOST[i]);
}


decompiled_code:
__int64 __fastcall print_key(char *dest, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v5; // ebp

result = strlen(dest);
v5 = result;
if ( *(_BYTE *)(a2 + 8) && (int)result > 0 )
{
*(_BYTE *)(a2 + 8) = 0;
dest[(int)result - 1] = 0;
}
else if ( *(_BYTE *)(a2 + 32) )
{
*(_BYTE *)(a2 + 32) = 0;
}
else if ( *(_BYTE *)(a2 + 340) )
{
result = strlen((const char *)(a2 + 340));
if ( result + v5 < (unsigned __int64)a3 )
result = (__int64)strcat(dest, (const char *)(a2 + 340));
}
*(_BYTE *)(a2 + 340) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *dest, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v5; // ebp

result = strlen(dest);
v5 = result;
if ( *(_BYTE *)(a2 + 8) && (int)result > 0 )
{
*(_BYTE *)(a2 + 8) = 0;
dest[(int)result - 1] = 0;
}
else if ( *(_BYTE *)(a2 + 32) )
{
*(_BYTE *)(a2 + 32) = 0;
}
else if ( *(_BYTE *)(a2 + 340) )
{
result = strlen((const char *)(a2 + 340));
if ( result + v5 < (unsigned __int64)a3 )
result = (__int64)strcat(dest, (const char *)(a2 + 340));
}
*(_BYTE *)(a2 + 340) = 0;
return result;
}

original_code:
void print_key(char* chaine, Input *in, unsigned max_size)
{
 int size = strlen(chaine);
 if(in->key[SDLK_BACKSPACE] && size > 0)
 {
  in->key[SDLK_BACKSPACE]=0;
  chaine[size-1]='\0';
 }
 else if(in->key[SDLK_SPACE]) in->key[SDLK_SPACE]=0;
 else if( strlen(in->touche) && (size+strlen(in->touche) < max_size) ) strcat(chaine, in->touche);
 in->touche[0]='\0';
}

canonical_original_code:
void print_key(char *chaine, struct Input *in, unsigned int max_size)
{
 int size = strlen(chaine);
 if(in->key[SDLK_BACKSPACE] && size > 0)
 {
  in->key[SDLK_BACKSPACE]=0;
  chaine[size-1]='\0';
 }
 else if(in->key[SDLK_SPACE]) in->key[SDLK_SPACE]=0;
 else if( strlen(in->touche) && (size+strlen(in->touche) < max_size) ) strcat(chaine, in->touche);
 in->touche[0]='\0';
}

variable_types:
chaine
char *

variable_types: struct Input { char key[-1]; int mousex; char mousebuttons[8]; char touche[2]; char quit; } *

variable_types: size int


decompiled_code:
__int64 __fastcall plot_object(int a1, int a2, int a3)
{
__int64 result; // rax
int i; // esi
__int64 v7; // rdx
__int64 v8; // rax

result = LODWORD(editor[a3]);
if ( (_DWORD)result == 3 )
{
v7 = 0LL;
for ( i = 0; i != 31; ++i )
{
v8 = 0LL;
while ( LODWORD(LEVEL[v8 + v7]) != 3 )
{
if ( ++v8 == 31 )
goto LABEL_8;
}
LODWORD(LEVEL[31 * i + (int)v8]) = 0;
LABEL_8:
v7 += 31LL;
}
goto LABEL_5;
}
if ( (_DWORD)result != 4 )
{
if ( LODWORD(LEVEL[31 * (a2 / 20) + a1 / 20]) == 4 )
--NB_GHOST;
LABEL_5:
result = editor[a3];
LEVEL[31 * (a2 / 20) + a1 / 20] = result;
return result;
}
if ( NB_GHOST <= 15 )
{
if ( LODWORD(LEVEL[31 * (a2 / 20) + a1 / 20]) != 4 )
++NB_GHOST;
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
__int64 result; // rax
int i; // esi
__int64 v7; // rdx
__int64 v8; // rax

result = LODWORD(editor[a3]);
if ( (_DWORD)result == 3 )
{
v7 = 0LL;
for ( i = 0; i != 31; ++i )
{
v8 = 0LL;
while ( LODWORD(LEVEL[v8 + v7]) != 3 )
{
if ( ++v8 == 31 )
goto LABEL_8;
}
LODWORD(LEVEL[31 * i + (int)v8]) = 0;
LABEL_8:
v7 += 31LL;
}
goto LABEL_5;
}
if ( (_DWORD)result != 4 )
{
if ( LODWORD(LEVEL[31 * (a2 / 20) + a1 / 20]) == 4 )
--NB_GHOST;
LABEL_5:
result = editor[a3];
LEVEL[31 * (a2 / 20) + a1 / 20] = result;
return result;
}
if ( NB_GHOST <= 15 )
{
if ( LODWORD(LEVEL[31 * (a2 / 20) + a1 / 20]) != 4 )
++NB_GHOST;
goto LABEL_5;
}
return result;
}

original_code:
void plot_object(int x, int y, int type)
{
 if(editor[type].type==PACMAN)
 {
  int i,j;
  for(i=0; i<31; i++)
  {
   for(j=0; j<31; j++)
   {
    if(LEVEL[i][j].type==PACMAN)
    {
     LEVEL[i][j].type=RIEN;
     break;
    }
   }
  }
 }
 else if(editor[type].type==GHOST)
 {
  if(NB_GHOST >= 16) return;
  else if(LEVEL[y/20][x/20].type != GHOST) NB_GHOST++;
 }
 else if(LEVEL[y/20][x/20].type == GHOST) NB_GHOST--;
 LEVEL[y/20][x/20] = editor[type];
}

canonical_original_code:
void plot_object(int x, int y, int type)
{
 if(editor[type].type==PACMAN)
 {
  int i; int j;
  for(i=0; i<31; i++)
  {
   for(j=0; j<31; j++)
   {
    if(LEVEL[i][j].type==PACMAN)
    {
     LEVEL[i][j].type=RIEN;
     break;
    }
   }
  }
 }
 else if(editor[type].type==GHOST)
 {
  if(NB_GHOST >= 16) return;
  else if(LEVEL[y/20][x/20].type != GHOST) NB_GHOST++;
 }
 else if(LEVEL[y/20][x/20].type == GHOST) NB_GHOST--;
 LEVEL[y/20][x/20] = editor[type];
}

variable_types: type int


decompiled_code:
__int64 init_editor()
{
__int64 i; // rax
__int64 j; // rax
__int64 result; // rax

for ( i = 0LL; i != 20; ++i )
{
LODWORD(editor[i]) = 1;
HIDWORD(editor[i]) = i;
}
for ( j = 0LL; j != 10; ++j )
{
LODWORD(editor[j + 20]) = 2;
HIDWORD(editor[j + 20]) = j;
}
LODWORD(editor[30]) = 3;
HIDWORD(editor[30]) = 0;
LODWORD(editor[31]) = 3;
HIDWORD(editor[31]) = 1;
LODWORD(editor[32]) = 3;
HIDWORD(editor[32]) = 2;
LODWORD(editor[33]) = 3;
HIDWORD(editor[33]) = 3;
for ( result = 0LL; result != 4; ++result )
{
LODWORD(editor[result + 34]) = 4;
HIDWORD(editor[result + 34]) = result;
}
return result;
}

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

for ( i = 0LL; i != 20; ++i )
{
LODWORD(editor[i]) = 1;
HIDWORD(editor[i]) = i;
}
for ( j = 0LL; j != 10; ++j )
{
LODWORD(editor[j + 20]) = 2;
HIDWORD(editor[j + 20]) = j;
}
LODWORD(editor[30]) = 3;
HIDWORD(editor[30]) = 0;
LODWORD(editor[31]) = 3;
HIDWORD(editor[31]) = 1;
LODWORD(editor[32]) = 3;
HIDWORD(editor[32]) = 2;
LODWORD(editor[33]) = 3;
HIDWORD(editor[33]) = 3;
for ( result = 0LL; result != 4; ++result )
{
LODWORD(editor[result + 34]) = 4;
HIDWORD(editor[result + 34]) = result;
}
return result;
}

original_code:
void init_editor()
{
 int i, j;
 for(i=0; i<20; i++)
 {
  editor[i].type=MUR;
  editor[i].elt_type=i;
 }
 for(j=0; j<10; j++)
 {
  editor[i].type=BONUS;
  editor[i].elt_type=j;
  i++;
 }
 for(j=0; j<4; j++)
 {
  editor[i].type=PACMAN;
  editor[i].elt_type=j;
  i++;
 }
 for(j=0; j<4; j++)
 {
  editor[i].type=GHOST;
  editor[i].elt_type=j;
  i++;
 }
}

canonical_original_code:
void init_editor()
{
 int i; int j;
 for(i=0; i<20; i++)
 {
  editor[i].type=MUR;
  editor[i].elt_type=i;
 }
 for(j=0; j<10; j++)
 {
  editor[i].type=BONUS;
  editor[i].elt_type=j;
  i++;
 }
 for(j=0; j<4; j++)
 {
  editor[i].type=PACMAN;
  editor[i].elt_type=j;
  i++;
 }
 for(j=0; j<4; j++)
 {
  editor[i].type=GHOST;
  editor[i].elt_type=j;
  i++;
 }
}


decompiled_code:
size_t __fastcall print_info(_DWORD *a1, int a2, __int64 a3, int a4)
{
size_t result; // rax
int v6; // er13
int v7; // er13
char v8[168]; // [rsp+0h] [rbp-A8h] BYREF

sprintf(v8, "%s ", &LEVEL_FILE[128 * (__int64)a4]);
result = (unsigned int)*a1;
switch ( (_DWORD)result )
{
case 2:
v7 = SDL_GetTicks();
result = (size_t)&v8[strlen(v8)];
strcpy((char *)result, "loaded !");
if ( v7 - a2 <= 4999 )
return aff_pol(v8, 22LL, a3, 0xFFFFLL);
*a1 = 0;
break;
case 3:
result = (unsigned int)SDL_GetTicks() - a2;
if ( (int)result <= 4999 )
result = aff_pol("Level destroyed !", 22LL, a3, 0xFFFFLL);
else
*a1 = 0;
break;
case 1:
v6 = SDL_GetTicks();
result = strlen(v8);
*(_QWORD *)&v8[result] = 0x21206465766173LL;
if ( v6 - a2 > 4999 )
{
*a1 = 0;
return result;
}
return aff_pol(v8, 22LL, a3, 0xFFFFLL);
default:
return result;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(_DWORD *a1, int a2, __int64 a3, int a4)
{
size_t result; // rax
int v6; // er13
int v7; // er13
char v8[168]; // [rsp+0h] [rbp-A8h] BYREF

sprintf(v8, "%s ", &LEVEL_FILE[128 * (__int64)a4]);
result = (unsigned int)*a1;
switch ( (_DWORD)result )
{
case 2:
v7 = SDL_GetTicks();
result = (size_t)&v8[strlen(v8)];
strcpy((char *)result, "loaded !");
if ( v7 - a2 <= 4999 )
return aff_pol(v8, 22LL, a3, 0xFFFFLL);
*a1 = 0;
break;
case 3:
result = (unsigned int)SDL_GetTicks() - a2;
if ( (int)result <= 4999 )
result = aff_pol("Level destroyed !", 22LL, a3, 0xFFFFLL);
else
*a1 = 0;
break;
case 1:
v6 = SDL_GetTicks();
result = strlen(v8);
*(_QWORD *)&v8[result] = 0x21206465766173LL;
if ( v6 - a2 > 4999 )
{
*a1 = 0;
return result;
}
return aff_pol(v8, 22LL, a3, 0xFFFFLL);
default:
return result;
}
return result;
}

original_code:
void print_info(int *message, int tempsPrecedent, POINT p, int level)
{
 int tempsActuel;
 char tmp[128];
 sprintf(tmp, "%s ", LEVEL_FILE[level]);
 switch(*message)
 {
  case AUCUN:
   break;
  case SAVE:
   tempsActuel = SDL_GetTicks();
   strcat(tmp, "saved !");
   if (tempsActuel - tempsPrecedent < 5000) aff_pol(tmp, 22, p, 0xffff);
   else *message=AUCUN;
   break;
  case LOAD:
   tempsActuel = SDL_GetTicks();
   strcat(tmp, "loaded !");
   if (tempsActuel - tempsPrecedent < 5000) aff_pol(tmp, 22, p, 0xffff);
   else *message=AUCUN;
   break;
  case DELETE:
   tempsActuel = SDL_GetTicks();
   if (tempsActuel - tempsPrecedent < 5000) aff_pol("Level destroyed !", 22, p, 0xffff);
   else *message=AUCUN;
   break;
  default : break;
 }
}

canonical_original_code:
void print_info(int *message, int tempsPrecedent, struct point p, int level)
{
 int tempsActuel;
 char tmp[128];
 sprintf(tmp, "%s ", LEVEL_FILE[level]);
 switch(*message)
 {
  case AUCUN:
   break;
  case SAVE:
   tempsActuel = SDL_GetTicks();
   strcat(tmp, "saved !");
   if (tempsActuel - tempsPrecedent < 5000) aff_pol(tmp, 22, p, 0xffff);
   else *message=AUCUN;
   break;
  case LOAD:
   tempsActuel = SDL_GetTicks();
   strcat(tmp, "loaded !");
   if (tempsActuel - tempsPrecedent < 5000) aff_pol(tmp, 22, p, 0xffff);
   else *message=AUCUN;
   break;
  case DELETE:
   tempsActuel = SDL_GetTicks();
   if (tempsActuel - tempsPrecedent < 5000) aff_pol("Level destroyed !", 22, p, 0xffff);
   else *message=AUCUN;
   break;
  default : break;
 }
}

variable_types:
message
int *

variable_types: tempsPrecedent int

variable_types:
p
struct point { int x; }

variable_types: level int

variable_types: tempsActuel int

variable_types:
tmp
char [128]


decompiled_code:
__int64 load_gui()
{
__int64 v0; // rbp
__int64 v1; // rbx
unsigned __int64 v2; // rbp
unsigned int i; // ebx
int j; // ebx
__int64 result; // rax
__int16 v6[24]; // [rsp+8h] [rbp-30h] BYREF

LODWORD(v0) = 620;
draw_line(0x26B0000026CLL, 620LL, 0xFFFFLL, screen);
v1 = 619LL;
do
{
v0 = (v1 << 32) | (unsigned int)v0;
draw_line(v0, (v1 << 32) | 0x2DF, 0xFFFFLL, screen);
v1 = (unsigned int)(v1 - 23);
}
while ( (_DWORD)v1 != 412 );
v2 = (unsigned int)v0 | 0x26B00000000LL;
for ( i = 620; i != 758; i += 23 )
{
v2 = i | v2 & 0xFFFFFFFF00000000LL;
draw_line(v2, i | 0x1B300000000LL, 0xFFFFLL, screen);
}
for ( j = 0; j != 38; ++j )
{
v6[0] = 23 * (j % 5) + 622;
v6[1] = 23 * (j / 5) + 2;
result = affiche_une_case(editor[j], v6, screen);
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
__int64 v1; // rbx
unsigned __int64 v2; // rbp
unsigned int i; // ebx
int j; // ebx
__int64 result; // rax
__int16 v6[24]; // [rsp+8h] [rbp-30h] BYREF

LODWORD(v0) = 620;
draw_line(0x26B0000026CLL, 620LL, 0xFFFFLL, screen);
v1 = 619LL;
do
{
v0 = (v1 << 32) | (unsigned int)v0;
draw_line(v0, (v1 << 32) | 0x2DF, 0xFFFFLL, screen);
v1 = (unsigned int)(v1 - 23);
}
while ( (_DWORD)v1 != 412 );
v2 = (unsigned int)v0 | 0x26B00000000LL;
for ( i = 620; i != 758; i += 23 )
{
v2 = i | v2 & 0xFFFFFFFF00000000LL;
draw_line(v2, i | 0x1B300000000LL, 0xFFFFLL, screen);
}
for ( j = 0; j != 38; ++j )
{
v6[0] = 23 * (j % 5) + 622;
v6[1] = 23 * (j / 5) + 2;
result = affiche_une_case(editor[j], v6, screen);
}
return result;
}

variable_types: i int


decompiled_code:
__int64 __fastcall highlight_block(int a1)
{
return draw_rectangle(
((unsigned __int64)(unsigned int)(23 * (a1 / -5) + 618) << 32) | (unsigned int)(23 * (a1 % 5) + 621),
((unsigned __int64)(unsigned int)(23 * (a1 / -5) + 597) << 32) | (unsigned int)(23 * (a1 % 5) + 642),
61440LL,
screen);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return draw_rectangle(
((unsigned __int64)(unsigned int)(23 * (a1 / -5) + 618) << 32) | (unsigned int)(23 * (a1 % 5) + 621),
((unsigned __int64)(unsigned int)(23 * (a1 / -5) + 597) << 32) | (unsigned int)(23 * (a1 % 5) + 642),
61440LL,
screen);
}

canonical_original_code:
void highlight_block(int type)
{
 struct point p1; struct point p2;
 p1.x=20*31 +1+(type%5)*(20 +3);
 p2.x=p1.x+20 +1;
 p1.y=20*31 -2-(type/5)*(20 +3);
 p2.y=p1.y-(20 +1);
 draw_rectangle(p1, p2, 0xf000, screen);
}


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

result = (unsigned int)(5 * (a2 / 23) + (a1 - 620) / 23);
if ( (int)result >= 38 )
result = a3;
return result;
}

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

result = (unsigned int)(5 * (a2 / 23) + (a1 - 620) / 23);
if ( (int)result >= 38 )
result = a3;
return result;
}

original_code:
int get_block_type(int x, int y, int type)
{
 int col = (x-20*31)/(20 +3);
 int line = y/(20 +3);
 int new_type = line*5 + col;
 if(new_type<10 +20 +4 +4) return new_type;
 else return type;
}

variable_types: col int

variable_types: line int


editer

decompiled_code:
__int64 editer()
{
unsigned int v0; // er13
int v1; // er14
int v2; // ebx
int v3; // eax
unsigned int v4; // ebp
int v5; // eax
__int16 v6; // bp
int v7; // edx
__int16 v8; // r12
int v9; // eax
int v10; // eax
unsigned int v11; // eax
char v13[64]; // [rsp+0h] [rbp-1E8h] BYREF
int v14[89]; // [rsp+40h] [rbp-1A8h] BYREF
int v15; // [rsp+1A4h] [rbp-44h] BYREF
__int16 v16; // [rsp+1A8h] [rbp-40h] BYREF
__int16 v17; // [rsp+1AAh] [rbp-3Eh]

init_graphics(820LL, 620LL, "Editeur Pacman");
SDL_ShowCursor(1LL);
SDL_WarpMouse(310LL, 310LL);
v17 = 0;
v16 = 0;
v15 = 0;
init_blocks();
init_editor();
init_level();
memset(v14, 0, 0x158uLL);
v0 = -1;
v1 = 0;
v2 = 0;
while ( 1 )
{
UpdateEvents(v14);
v6 = v14[81];
v7 = v14[81] / 20;
v16 = 20 * (v14[81] / 20);
v8 = v14[82];
v9 = v14[82] / 20;
v17 = 20 * (v14[82] / 20);
if ( BYTE2(v14[85]) )
exit(0);
if ( BYTE1(v14[83]) )
{
if ( v14[82] <= 818 && v14[81] > 619 )
{
v2 = get_block_type(v14[81], v14[82], v2);
v16 = v6 - 10;
v17 = v8 - 10;
}
else if ( v14[81] <= 0x26Bu )
{
plot_object(v14[81], v14[82], v2);
}
}
else if ( HIBYTE(v14[83]) )
{
if ( v14[81] <= 0x26Bu )
{
if ( LODWORD(LEVEL[31 * v9 + v7]) == 4 )
--NB_GHOST;
LODWORD(LEVEL[31 * v9 + v7]) = 0;
}
}
else if ( LOBYTE(v14[84]) )
{
v2 = (v2 - 1) % 38;
if ( v2 < 0 )
v2 = 37;
}
else if ( BYTE1(v14[84]) )
{
v2 = (v2 + 1) % 38;
}
if ( HIBYTE(v14[6]) )
{
HIBYTE(v14[6]) = 0;
v10 = edit_menu();
switch ( v10 )
{
case 1:
v3 = save_menu(v0);
if ( v3 )
{
if ( v3 == 1 )
{
new_file_menu(v13);
v4 = NB_LEVEL;
strcpy(&LEVEL_FILE[128 * (__int64)NB_LEVEL], v13);
save_level(v4);
v0 = NB_LEVEL++;
v15 = 1;
v1 = SDL_GetTicks();
}
}
else
{
save_level(v0);
v15 = 1;
v1 = SDL_GetTicks();
}
break;
case 2:
v5 = select_file_menu();
v0 = v5;
if ( NB_LEVEL > v5 )
{
load_level((unsigned int)v5);
v15 = 2;
v1 = SDL_GetTicks();
}
break;
case 3:
init_level();
v15 = 3;
v1 = SDL_GetTicks();
break;
case 5:
return 0LL;
}
}
v11 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, 0LL, v11);
load_gui();
highlight_block(v2);
draw_level();
if ( v2 <= 19 )
{
SDL_UpperBlit(BLOCK_MUR[v2], 0LL, screen, &v16);
}
else if ( v2 <= 29 )
{
SDL_UpperBlit(BLOCK_BONUS[v2 % 20], 0LL, screen, &v16);
}
else if ( v2 > 33 )
{
SDL_UpperBlit(BLOCK_GHOST[v2 % 34], 0LL, screen, &v16);
}
else
{
SDL_UpperBlit(BLOCK_PACMAN[v2 % 30], 0LL, screen, &v16);
}
print_info(&v15, v1, 0x20800000276LL, v0);
SDL_Flip(screen);
}
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er13
int v1; // er14
int v2; // ebx
int v3; // eax
unsigned int v4; // ebp
int v5; // eax
__int16 v6; // bp
int v7; // edx
__int16 v8; // r12
int v9; // eax
int v10; // eax
unsigned int v11; // eax
char v13[64]; // [rsp+0h] [rbp-1E8h] BYREF
int v14[89]; // [rsp+40h] [rbp-1A8h] BYREF
int v15; // [rsp+1A4h] [rbp-44h] BYREF
__int16 v16; // [rsp+1A8h] [rbp-40h] BYREF
__int16 v17; // [rsp+1AAh] [rbp-3Eh]

init_graphics(820LL, 620LL, "Editeur Pacman");
SDL_ShowCursor(1LL);
SDL_WarpMouse(310LL, 310LL);
v17 = 0;
v16 = 0;
v15 = 0;
init_blocks();
func1();
init_level();
memset(v14, 0, 0x158uLL);
v0 = -1;
v1 = 0;
v2 = 0;
while ( 1 )
{
UpdateEvents(v14);
v6 = v14[81];
v7 = v14[81] / 20;
v16 = 20 * (v14[81] / 20);
v8 = v14[82];
v9 = v14[82] / 20;
v17 = 20 * (v14[82] / 20);
if ( BYTE2(v14[85]) )
exit(0);
if ( BYTE1(v14[83]) )
{
if ( v14[82] <= 818 && v14[81] > 619 )
{
v2 = func5(v14[81], v14[82], v2);
v16 = v6 - 10;
v17 = v8 - 10;
}
else if ( v14[81] <= 0x26Bu )
{
func0(v14[81], v14[82], v2);
}
}
else if ( HIBYTE(v14[83]) )
{
if ( v14[81] <= 0x26Bu )
{
if ( LODWORD(LEVEL[31 * v9 + v7]) == 4 )
--NB_GHOST;
LODWORD(LEVEL[31 * v9 + v7]) = 0;
}
}
else if ( LOBYTE(v14[84]) )
{
v2 = (v2 - 1) % 38;
if ( v2 < 0 )
v2 = 37;
}
else if ( BYTE1(v14[84]) )
{
v2 = (v2 + 1) % 38;
}
if ( HIBYTE(v14[6]) )
{
HIBYTE(v14[6]) = 0;
v10 = edit_menu();
switch ( v10 )
{
case 1:
v3 = save_menu(v0);
if ( v3 )
{
if ( v3 == 1 )
{
new_file_menu(v13);
v4 = NB_LEVEL;
strcpy(&LEVEL_FILE[128 * (__int64)NB_LEVEL], v13);
save_level(v4);
v0 = NB_LEVEL++;
v15 = 1;
v1 = SDL_GetTicks();
}
}
else
{
save_level(v0);
v15 = 1;
v1 = SDL_GetTicks();
}
break;
case 2:
v5 = select_file_menu();
v0 = v5;
if ( NB_LEVEL > v5 )
{
load_level((unsigned int)v5);
v15 = 2;
v1 = SDL_GetTicks();
}
break;
case 3:
init_level();
v15 = 3;
v1 = SDL_GetTicks();
break;
case 5:
return 0LL;
}
}
v11 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, 0LL, v11);
func3();
func4(v2);
draw_level();
if ( v2 <= 19 )
{
SDL_UpperBlit(BLOCK_MUR[v2], 0LL, screen, &v16);
}
else if ( v2 <= 29 )
{
SDL_UpperBlit(BLOCK_BONUS[v2 % 20], 0LL, screen, &v16);
}
else if ( v2 > 33 )
{
SDL_UpperBlit(BLOCK_GHOST[v2 % 34], 0LL, screen, &v16);
}
else
{
SDL_UpperBlit(BLOCK_PACMAN[v2 % 30], 0LL, screen, &v16);
}
func2(&v15, v1, 0x20800000276LL, v0);
SDL_Flip(screen);
}
}

original_code:
int editer()
{
 init_graphics(20*31 +200, 20*31, "Editeur Pacman");
 SDL_ShowCursor(1);
 SDL_WarpMouse(20*31 / 2, 20*31 / 2);
 POINT info;
 info.x=20*31 +10;
 info.y=20*31 -100;
 SDL_Rect position;
 position.x=position.y=0;
 int type=0, ok=1, message=AUCUN, tempsPrecedent=0, level=-1, selection=0;
 init_blocks();
 init_editor();
 init_level();
 Input in;
 memset(&in,0,sizeof(in));
 while(ok)
 {
  UpdateEvents(&in);
  position.x = (in.mousex/20)*20;
  position.y = (in.mousey/20)*20;
  if(in.quit) exit(0);
  if (in.mousebuttons[1])
  {
   if( (in.mousex >= 20*31) && (in.mousey < 20*31 +200 -1) )
   {
    type = get_block_type(in.mousex, in.mousey, type);
    position.x = in.mousex-20/2;
    position.y = in.mousey-20/2;
   }
   else if ( (in.mousex < 20*31) && (in.mousex >= 0) )
    plot_object(in.mousex, in.mousey, type);
  }
  else if (in.mousebuttons[3])
  {
   if( (in.mousex < 20*31) && (in.mousex >= 0) ) {
    if(LEVEL[in.mousey/20][in.mousex/20].type == GHOST) NB_GHOST--;
    LEVEL[in.mousey/20][in.mousex/20].type = RIEN;
   }
  }
  else if (in.mousebuttons[4])
  {
   type = (type-1)%(10 +20 +4 +4);
   if (type < 0) type = 10 +20 +4 +4 -1;
  }
  else if (in.mousebuttons[5]) type = (type+1)%(10 +20 +4 +4);
  if(in.key[SDLK_ESCAPE])
  {
   in.key[SDLK_ESCAPE]=0;
   selection=edit_menu();
   if(selection==1)
   {
    int tmp = save_menu(level);
    if(tmp==0)
    {
     save_level(level);
     message=SAVE;
     tempsPrecedent = SDL_GetTicks();
    }
    if(tmp==1)
    {
     char new_file[64];
     new_file_menu(new_file);
     strcpy(LEVEL_FILE[NB_LEVEL], new_file);
     save_level(NB_LEVEL);
     NB_LEVEL++;
     level=NB_LEVEL-1;
     message=SAVE;
     tempsPrecedent = SDL_GetTicks();
    }
   }
   else if(selection == 2)
   {
    level = select_file_menu();
    if(level<NB_LEVEL)
    {
     load_level(level);
     message=LOAD;
     tempsPrecedent = SDL_GetTicks();
    }
   }
   else if (selection == 3)
   {
    init_level();
    message=DELETE;
    tempsPrecedent = SDL_GetTicks();
   }
   else if (selection == 5) return 0;
  }
  SDL_FillRect(screen, ((void *)0), SDL_MapRGB(screen->format, 0, 0, 0));
  load_gui();
  highlight_block(type);
  draw_level();
  if(type<20) SDL_UpperBlit(BLOCK_MUR[type], ((void *)0), screen, &position);
  else if(type<10 +20)
   SDL_UpperBlit(BLOCK_BONUS[type%20], ((void *)0), screen, &position);
  else if(type<10 +20 +4)
   SDL_UpperBlit(BLOCK_PACMAN[type%(20 +10)], ((void *)0), screen, &position);
  else SDL_UpperBlit(BLOCK_GHOST[type%(20 +10 +4)], ((void *)0), screen, &position);
  print_info(&message, tempsPrecedent, info, level);
  SDL_Flip(screen);
 }
 return 0;
}

canonical_original_code:
int editer()
{
 init_graphics(20*31 +200, 20*31, "Editeur Pacman");
 SDL_ShowCursor(1);
 SDL_WarpMouse(20*31 / 2, 20*31 / 2);
 struct point info;
 info.x=20*31 +10;
 info.y=20*31 -100;
 struct SDL_Rect position;
 position.x=position.y=0;
 int type = 0; int ok = 1; int message = AUCUN; int tempsPrecedent = 0; int level = -1; int selection = 0;
 init_blocks();
 init_editor();
 init_level();
 struct Input in;
 memset(&in,0,sizeof(in));
 while(ok)
 {
  UpdateEvents(&in);
  position.x = (in.mousex/20)*20;
  position.y = (in.mousey/20)*20;
  if(in.quit) exit(0);
  if (in.mousebuttons[1])
  {
   if( (in.mousex >= 20*31) && (in.mousey < 20*31 +200 -1) )
   {
    type = get_block_type(in.mousex, in.mousey, type);
    position.x = in.mousex-20/2;
    position.y = in.mousey-20/2;
   }
   else if ( (in.mousex < 20*31) && (in.mousex >= 0) )
    plot_object(in.mousex, in.mousey, type);
  }
  else if (in.mousebuttons[3])
  {
   if( (in.mousex < 20*31) && (in.mousex >= 0) ) {
    if(LEVEL[in.mousey/20][in.mousex/20].type == GHOST) NB_GHOST--;
    LEVEL[in.mousey/20][in.mousex/20].type = RIEN;
   }
  }
  else if (in.mousebuttons[4])
  {
   type = (type-1)%(10 +20 +4 +4);
   if (type < 0) type = 10 +20 +4 +4 -1;
  }
  else if (in.mousebuttons[5]) type = (type+1)%(10 +20 +4 +4);
  if(in.key[SDLK_ESCAPE])
  {
   in.key[SDLK_ESCAPE]=0;
   selection=edit_menu();
   if(selection==1)
   {
    int tmp = save_menu(level);
    if(tmp==0)
    {
     save_level(level);
     message=SAVE;
     tempsPrecedent = SDL_GetTicks();
    }
    if(tmp==1)
    {
     char new_file[64];
     new_file_menu(new_file);
     strcpy(LEVEL_FILE[NB_LEVEL], new_file);
     save_level(NB_LEVEL);
     NB_LEVEL++;
     level=NB_LEVEL-1;
     message=SAVE;
     tempsPrecedent = SDL_GetTicks();
    }
   }
   else if(selection == 2)
   {
    level = select_file_menu();
    if(level<NB_LEVEL)
    {
     load_level(level);
     message=LOAD;
     tempsPrecedent = SDL_GetTicks();
    }
   }
   else if (selection == 3)
   {
    init_level();
    message=DELETE;
    tempsPrecedent = SDL_GetTicks();
   }
   else if (selection == 5) return 0;
  }
  SDL_FillRect(screen, ((void *)0), SDL_MapRGB(screen->format, 0, 0, 0));
  load_gui();
  highlight_block(type);
  draw_level();
  if(type<20) SDL_UpperBlit(BLOCK_MUR[type], ((void *)0), screen, &position);
  else if(type<10 +20)
   SDL_UpperBlit(BLOCK_BONUS[type%20], ((void *)0), screen, &position);
  else if(type<10 +20 +4)
   SDL_UpperBlit(BLOCK_PACMAN[type%(20 +10)], ((void *)0), screen, &position);
  else SDL_UpperBlit(BLOCK_GHOST[type%(20 +10 +4)], ((void *)0), screen, &position);
  print_info(&message, tempsPrecedent, info, level);
  SDL_Flip(screen);
 }
 return 0;
}

variable_types:
info
struct point { int x; }

variable_types: struct SDL_Rect { short x; unsigned short w; }

variable_types: ok int

variable_types: message int

variable_types: selection int

variable_types: struct Input { char key[-1]; int mousex; char mousebuttons[8]; char touche[2]; char quit; }

variable_types: tmp int


decompiled_code:
__int64 __fastcall init_graphics(unsigned int a1, unsigned int a2, __int64 a3)
{
const char *v5; // rax

SDL_Init(32LL);
SDL_EnableUNICODE(1LL);
screen = SDL_SetVideoMode(a1, a2, 16LL, 1073741840LL);
if ( !screen )
{
v5 = (const char *)SDL_GetError();
fprintf(stderr, "Impossible de passer en %dx%d en 16 bpp: %s\n", a1, a2, v5);
exit(1);
}
SDL_ShowCursor(0LL);
return SDL_WM_SetCaption(a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3)
{
const char *v5; // rax

SDL_Init(32LL);
SDL_EnableUNICODE(1LL);
screen = SDL_SetVideoMode(a1, a2, 16LL, 1073741840LL);
if ( !screen )
{
v5 = (const char *)SDL_GetError();
fprintf(stderr, "Impossible de passer en %dx%d en 16 bpp: %s\n", a1, a2, v5);
exit(1);
}
SDL_ShowCursor(0LL);
return SDL_WM_SetCaption(a3, 0LL);
}

original_code:
void init_graphics(int W, int H, char* s)
{
 SDL_Init(0x00000020);
 SDL_EnableUNICODE(1);
 screen = SDL_SetVideoMode(W, H, 16, 0x00000000|0x40000000|0x00000010);
 if ( screen == ((void *)0) )
 {
  fprintf(stderr, "Impossible de passer en %dx%d en 16 bpp: %s\n", W, H, SDL_GetError());
  exit(1);
 }
 SDL_ShowCursor(0);
 SDL_WM_SetCaption(s, ((void *)0));
}

canonical_original_code:
void init_graphics(int W, int H, char *s)
{
 SDL_Init(0x00000020);
 SDL_EnableUNICODE(1);
 screen = SDL_SetVideoMode(W, H, 16, 0x00000000|0x40000000|0x00000010);
 if ( screen == ((void *)0) )
 {
  fprintf(stderr, "Impossible de passer en %dx%d en 16 bpp: %s\n", W, H, SDL_GetError());
  exit(1);
 }
 SDL_ShowCursor(0);
 SDL_WM_SetCaption(s, ((void *)0));
}

variable_types: W int

variable_types: H int

variable_types:
s
char *


decompiled_code:
__int64 __fastcall can_move(int a1, unsigned int a2, int a3, _DWORD *a4)
{
int v5; // eax
int v6; // ebp
unsigned int v7; // er14
__int16 v8; // bx
unsigned int v9; // er15
__int64 result; // rax
__int16 v11; // bp
__int16 v12; // bp
__int16 v13; // bx
__int64 v14; // rdi
__int16 v15; // bx

HIWORD(v5) = HIWORD(a1);
LOWORD(v5) = (__int16)a1 >> 15;
v6 = ((26215 * (__int16)a1) >> 19) - v5;
v7 = (__int16)a1 / 20;
v8 = SHIWORD(a1) / 20;
v9 = SHIWORD(a1) / 20;
if ( a2 == 2 )
{
if ( !(unsigned int)dans_case() )
return (a3 & 0xFFFFFFFD) == 0;
result = 1LL;
if ( v9 != 30 )
{
v15 = v8 + 1;
v14 = (unsigned int)v15;
result = 1LL;
if ( LEVEL[62 * v15 + 2 * v7] == 1 )
{
result = 0LL;
if ( LEVEL[62 * v15 + 1 + 2 * v7] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
goto LABEL_35;
}
}
}
}
else if ( (int)a2 > 2 )
{
result = 0LL;
if ( a2 == 3 )
{
if ( (unsigned int)dans_case() )
{
result = 1LL;
if ( (__int16)a1 / 20 )
{
v12 = v6 - 1;
result = 1LL;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 2 * v12] == 1 )
{
result = 0LL;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 1 + 2 * v12] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
{
remove_bloc(v9, (unsigned int)v12);
--*a4;
result = 1LL;
}
}
}
}
}
else
{
result = (a3 & 0xFFFFFFFD) == 1;
}
}
}
else
{
if ( a2 )
{
if ( a2 != 1 )
return 0LL;
if ( !(unsigned int)dans_case() )
return (a3 & 0xFFFFFFFD) == 1;
result = a2;
if ( v7 != 30 )
{
v11 = v6 + 1;
result = a2;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 2 * v11] == 1 )
{
result = 0LL;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 1 + 2 * v11] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
{
remove_bloc(v9, (unsigned int)v11);
--*a4;
result = a2;
}
}
}
}
return result;
}
if ( !(unsigned int)dans_case() )
return (a3 & 0xFFFFFFFD) == 0;
result = 1LL;
if ( SHIWORD(a1) / 20 )
{
v13 = v8 - 1;
v14 = (unsigned int)v13;
result = 1LL;
if ( LEVEL[62 * v13 + 2 * v7] == 1 )
{
result = a2;
if ( LEVEL[62 * v13 + 1 + 2 * v7] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
{
LABEL_35:
remove_bloc(v14, v7);
--*a4;
return 1LL;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned int a2, int a3, _DWORD *a4)
{
int v5; // eax
int v6; // ebp
unsigned int v7; // er14
__int16 v8; // bx
unsigned int v9; // er15
__int64 result; // rax
__int16 v11; // bp
__int16 v12; // bp
__int16 v13; // bx
__int64 v14; // rdi
__int16 v15; // bx

HIWORD(v5) = HIWORD(a1);
LOWORD(v5) = (__int16)a1 >> 15;
v6 = ((26215 * (__int16)a1) >> 19) - v5;
v7 = (__int16)a1 / 20;
v8 = SHIWORD(a1) / 20;
v9 = SHIWORD(a1) / 20;
if ( a2 == 2 )
{
if ( !(unsigned int)dans_case() )
return (a3 & 0xFFFFFFFD) == 0;
result = 1LL;
if ( v9 != 30 )
{
v15 = v8 + 1;
v14 = (unsigned int)v15;
result = 1LL;
if ( LEVEL[62 * v15 + 2 * v7] == 1 )
{
result = 0LL;
if ( LEVEL[62 * v15 + 1 + 2 * v7] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
goto LABEL_35;
}
}
}
}
else if ( (int)a2 > 2 )
{
result = 0LL;
if ( a2 == 3 )
{
if ( (unsigned int)dans_case() )
{
result = 1LL;
if ( (__int16)a1 / 20 )
{
v12 = v6 - 1;
result = 1LL;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 2 * v12] == 1 )
{
result = 0LL;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 1 + 2 * v12] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
{
remove_bloc(v9, (unsigned int)v12);
--*a4;
result = 1LL;
}
}
}
}
}
else
{
result = (a3 & 0xFFFFFFFD) == 1;
}
}
}
else
{
if ( a2 )
{
if ( a2 != 1 )
return 0LL;
if ( !(unsigned int)dans_case() )
return (a3 & 0xFFFFFFFD) == 1;
result = a2;
if ( v7 != 30 )
{
v11 = v6 + 1;
result = a2;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 2 * v11] == 1 )
{
result = 0LL;
if ( LEVEL[62 * (SHIWORD(a1) / 20) + 1 + 2 * v11] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
{
remove_bloc(v9, (unsigned int)v11);
--*a4;
result = a2;
}
}
}
}
return result;
}
if ( !(unsigned int)dans_case() )
return (a3 & 0xFFFFFFFD) == 0;
result = 1LL;
if ( SHIWORD(a1) / 20 )
{
v13 = v8 - 1;
v14 = (unsigned int)v13;
result = 1LL;
if ( LEVEL[62 * v13 + 2 * v7] == 1 )
{
result = a2;
if ( LEVEL[62 * v13 + 1 + 2 * v7] > 13 )
{
result = (unsigned int)*a4;
if ( (_DWORD)result )
{
LABEL_35:
remove_bloc(v14, v7);
--*a4;
return 1LL;
}
}
}
}
}
return result;
}

original_code:
int can_move(SDL_Rect pos, int new_direction, int cur_direction, int *key)
{
 int case_x = pos.x / 20, case_y = pos.y / 20;
 switch (new_direction)
 {
  case DROITE:
   if (!dans_case(pos)) {
    if( (cur_direction==GAUCHE) || (cur_direction==DROITE) ) return 1;
   }
   else if(case_x == 31 -1) return 1;
   else if(LEVEL[case_y][case_x+1].type != MUR) return 1;
   else if(LEVEL[case_y][case_x+1].elt_type >= 14 && *key)
   {
    remove_bloc(case_y, case_x+1);
    (*key)--;
    return 1;
   }
   break;
  case GAUCHE:
   if(!dans_case(pos)) {
    if( (cur_direction==GAUCHE) || (cur_direction==DROITE) ) return 1;
   }
   else if(case_x == 0) return 1;
   else if(LEVEL[case_y][case_x-1].type != MUR) return 1;
   else if(LEVEL[case_y][case_x-1].elt_type >= 14 && *key)
   {
    remove_bloc(case_y, case_x-1);
    (*key)--;
    return 1;
   }
   break;
  case HAUT:
   if(!dans_case(pos)) {
    if( (cur_direction==HAUT) || (cur_direction==BAS) ) return 1;
   }
   else if(case_y == 0) return 1;
   else if(LEVEL[case_y-1][case_x].type != MUR) return 1;
   else if(LEVEL[case_y-1][case_x].elt_type >= 14 && *key)
   {
    remove_bloc(case_y-1, case_x);
    (*key)--;
    return 1;
   }
   break;
  case BAS:
   if(!dans_case(pos)) {
    if( (cur_direction==HAUT) || (cur_direction==BAS) ) return 1;
   }
   else if(case_y == 31 -1) return 1;
   else if(LEVEL[case_y+1][case_x].type != MUR) return 1;
   else if(LEVEL[case_y+1][case_x].elt_type >= 14 && *key)
   {
    remove_bloc(case_y+1, case_x);
    (*key)--;
    return 1;
   }
   break;
  default: break;
 }
 return 0;
}

canonical_original_code:
int can_move(struct SDL_Rect pos, int new_direction, int cur_direction, int *key)
{
 int case_x = pos.x / 20; int case_y = pos.y / 20;
 switch (new_direction)
 {
  case DROITE:
   if (!dans_case(pos)) {
    if( (cur_direction==GAUCHE) || (cur_direction==DROITE) ) return 1;
   }
   else if(case_x == 31 -1) return 1;
   else if(LEVEL[case_y][case_x+1].type != MUR) return 1;
   else if(LEVEL[case_y][case_x+1].elt_type >= 14 && *key)
   {
    remove_bloc(case_y, case_x+1);
    (*key)--;
    return 1;
   }
   break;
  case GAUCHE:
   if(!dans_case(pos)) {
    if( (cur_direction==GAUCHE) || (cur_direction==DROITE) ) return 1;
   }
   else if(case_x == 0) return 1;
   else if(LEVEL[case_y][case_x-1].type != MUR) return 1;
   else if(LEVEL[case_y][case_x-1].elt_type >= 14 && *key)
   {
    remove_bloc(case_y, case_x-1);
    (*key)--;
    return 1;
   }
   break;
  case HAUT:
   if(!dans_case(pos)) {
    if( (cur_direction==HAUT) || (cur_direction==BAS) ) return 1;
   }
   else if(case_y == 0) return 1;
   else if(LEVEL[case_y-1][case_x].type != MUR) return 1;
   else if(LEVEL[case_y-1][case_x].elt_type >= 14 && *key)
   {
    remove_bloc(case_y-1, case_x);
    (*key)--;
    return 1;
   }
   break;
  case BAS:
   if(!dans_case(pos)) {
    if( (cur_direction==HAUT) || (cur_direction==BAS) ) return 1;
   }
   else if(case_y == 31 -1) return 1;
   else if(LEVEL[case_y+1][case_x].type != MUR) return 1;
   else if(LEVEL[case_y+1][case_x].elt_type >= 14 && *key)
   {
    remove_bloc(case_y+1, case_x);
    (*key)--;
    return 1;
   }
   break;
  default: break;
 }
 return 0;
}

variable_types:
key
int *


decompiled_code:
__int64 __fastcall in_intersection(int a1, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebx
__int64 result; // rax

HIWORD(v2) = HIWORD(a1);
LOWORD(v2) = (__int16)a1 >> 15;
v3 = ((26215 * (__int16)a1) >> 19) - v2;
v4 = a1 >> 16;
LOWORD(v4) = SHIWORD(a1) >> 15;
v5 = ((26215 * (a1 >> 16)) >> 19) - v4;
if ( (unsigned int)(SHIWORD(a1) / 20) > 0x1E || (unsigned __int16)v3 > 0x1Eu )
return 0LL;
if ( (a2 & 0xFFFFFFFD) == 1 )
{
result = dans_case();
if ( (_DWORD)result )
{
result = a2 & 0xFFFFFFFD;
if ( LEVEL[62 * (__int16)(v5 - 1) + 2 * (__int16)v3] == 1 )
result = LEVEL[62 * (__int16)(v5 + 1) + 2 * (__int16)v3] != 1;
}
}
else
{
result = dans_case();
if ( (_DWORD)result )
{
result = 1LL;
if ( LEVEL[62 * (__int16)v5 + 2 * (__int16)(v3 + 1)] == 1 )
result = LEVEL[62 * (__int16)v5 + 2 * (__int16)(v3 - 1)] != 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebx
__int64 result; // rax

HIWORD(v2) = HIWORD(a1);
LOWORD(v2) = (__int16)a1 >> 15;
v3 = ((26215 * (__int16)a1) >> 19) - v2;
v4 = a1 >> 16;
LOWORD(v4) = SHIWORD(a1) >> 15;
v5 = ((26215 * (a1 >> 16)) >> 19) - v4;
if ( (unsigned int)(SHIWORD(a1) / 20) > 0x1E || (unsigned __int16)v3 > 0x1Eu )
return 0LL;
if ( (a2 & 0xFFFFFFFD) == 1 )
{
result = dans_case();
if ( (_DWORD)result )
{
result = a2 & 0xFFFFFFFD;
if ( LEVEL[62 * (__int16)(v5 - 1) + 2 * (__int16)v3] == 1 )
result = LEVEL[62 * (__int16)(v5 + 1) + 2 * (__int16)v3] != 1;
}
}
else
{
result = dans_case();
if ( (_DWORD)result )
{
result = 1LL;
if ( LEVEL[62 * (__int16)v5 + 2 * (__int16)(v3 + 1)] == 1 )
result = LEVEL[62 * (__int16)v5 + 2 * (__int16)(v3 - 1)] != 1;
}
}
return result;
}

original_code:
int in_intersection(SDL_Rect pos, int direction)
{
 int case_x = pos.x / 20, case_y = pos.y / 20;
 if(case_y >= 31 || case_y < 0 || case_x >= 31 || case_x < 0) return 0;
 if(direction == DROITE || direction == GAUCHE)
 {
  if(dans_case(pos) && (LEVEL[case_y-1][case_x].type != MUR || LEVEL[case_y+1][case_x].type != MUR)) return 1;
 }
 else
 {
  if(dans_case(pos) && (LEVEL[case_y][case_x+1].type != MUR || LEVEL[case_y][case_x-1].type != MUR)) return 1;
 }
 return 0;
}

canonical_original_code:
int in_intersection(struct SDL_Rect pos, int direction)
{
 int case_x = pos.x / 20; int case_y = pos.y / 20;
 if(case_y >= 31 || case_y < 0 || case_x >= 31 || case_x < 0) return 0;
 if(direction == DROITE || direction == GAUCHE)
 {
  if(dans_case(pos) && (LEVEL[case_y-1][case_x].type != MUR || LEVEL[case_y+1][case_x].type != MUR)) return 1;
 }
 else
 {
  if(dans_case(pos) && (LEVEL[case_y][case_x+1].type != MUR || LEVEL[case_y][case_x-1].type != MUR)) return 1;
 }
 return 0;
}

variable_types: direction int


original_code:
void adjust_position(SDL_Rect *pos, int cur_direction)
{
 SDL_Rect Case = get_case(*pos, cur_direction);
 if(LEVEL[Case.y][Case.x].type == MUR)
 {
  switch(cur_direction)
  {
   case DROITE:
    pos->x = (Case.x-1)*20;
    break;
   case GAUCHE:
    pos->x = (Case.x+1)*20;
    break;
   case HAUT:
    pos->y = (Case.y+1)*20;
    break;
   case BAS:
    pos->y = (Case.y-1)*20;
    break;
  }
 }
}

canonical_original_code:
void adjust_position(struct SDL_Rect *pos, int cur_direction)
{
 struct SDL_Rect Case = get_case(*pos, cur_direction);
 if(LEVEL[Case.y][Case.x].type == MUR)
 {
  switch(cur_direction)
  {
   case DROITE:
    pos->x = (Case.x-1)*20;
    break;
   case GAUCHE:
    pos->x = (Case.x+1)*20;
    break;
   case HAUT:
    pos->y = (Case.y+1)*20;
    break;
   case BAS:
    pos->y = (Case.y-1)*20;
    break;
  }
 }
}

variable_types: struct SDL_Rect { short x; unsigned short w; } *


move

original_code:
void move(SDL_Rect *pos, int direction, int speed)
{
 switch (direction)
 {
  case DROITE:
   pos->x += speed;
   if(pos->x+20 > 20*31) pos->x = -20 +speed;
   break;
  case GAUCHE:
   pos->x -= speed;
   if(pos->x+20 <= 0) pos->x = 20*31 -speed;
   break;
  case HAUT:
   pos->y -= speed;
   if(pos->y+20 <= 0) pos->y = 20*31 -speed;
   break;
  case BAS:
   pos->y += speed;
   if(pos->y+20 > 20*31) pos->y = -20 +speed;
   break;
  default: break;
 }
}

canonical_original_code:
void move(struct SDL_Rect *pos, int direction, int speed)
{
 switch (direction)
 {
  case DROITE:
   pos->x += speed;
   if(pos->x+20 > 20*31) pos->x = -20 +speed;
   break;
  case GAUCHE:
   pos->x -= speed;
   if(pos->x+20 <= 0) pos->x = 20*31 -speed;
   break;
  case HAUT:
   pos->y -= speed;
   if(pos->y+20 <= 0) pos->y = 20*31 -speed;
   break;
  case BAS:
   pos->y += speed;
   if(pos->y+20 > 20*31) pos->y = -20 +speed;
   break;
  default: break;
 }
}

variable_types: speed int


original_code:
void human_controller(Input in, config cfg, int controller, SDL_Rect *position, int *cur_direction, int *nb_keys, int *speed, int *num_image, SDL_Rect target)
{
 int new_direction;
 if(in.key[cfg.players[controller].down]) new_direction=BAS;
 else if(in.key[cfg.players[controller].up]) new_direction=HAUT;
 else if (in.key[cfg.players[controller].left]) new_direction=GAUCHE;
 else if (in.key[cfg.players[controller].right]) new_direction=DROITE;
 else new_direction=*cur_direction;
 adjust_position(position, *cur_direction);
 if(can_move(*position, new_direction, *cur_direction, nb_keys))
 {
  move(position, new_direction, *speed);
  *cur_direction = new_direction;
 }
 else if(can_move(*position, *cur_direction, *cur_direction, nb_keys)) move(position, *cur_direction, *speed);
}

canonical_original_code:
void human_controller(struct Input in, struct config cfg, int controller, struct SDL_Rect *position, int *cur_direction, int *nb_keys, int *speed, int *num_image, struct SDL_Rect target)
{
 int new_direction;
 if(in.key[cfg.players[controller].down]) new_direction=BAS;
 else if(in.key[cfg.players[controller].up]) new_direction=HAUT;
 else if (in.key[cfg.players[controller].left]) new_direction=GAUCHE;
 else if (in.key[cfg.players[controller].right]) new_direction=DROITE;
 else new_direction=*cur_direction;
 adjust_position(position, *cur_direction);
 if(can_move(*position, new_direction, *cur_direction, nb_keys))
 {
  move(position, new_direction, *speed);
  *cur_direction = new_direction;
 }
 else if(can_move(*position, *cur_direction, *cur_direction, nb_keys)) move(position, *cur_direction, *speed);
}

variable_types: struct config { int nb_players; struct player { int up; int character; } players[2]; }

variable_types: controller int

variable_types:
speed
int *

variable_types:
target
struct SDL_Rect

user_defined_types: struct Input { char key[-1]; int mousex; char mousebuttons[8]; char touche[2]; char quit; }

user_defined_types: struct config { int nb_players; struct player players[2]; }


decompiled_code:
__int64 __fastcall find_direction(__int64 a1, int a2, __int64 a3, _DWORD *a4)
{
int v6; // eax
__int16 v7; // bx
int v8; // er15
int v9; // eax
int v10; // er14
int v11; // eax
unsigned int v12; // ebx
int v13; // eax
int v14; // eax
int v15; // eax

if ( (_WORD)a3 == 0xFFFF || WORD1(a3) == 0xFFFF )
goto LABEL_20;
v6 = get_case(a1);
v7 = v6;
v8 = v6 >> 16;
v9 = get_case(a3);
v10 = v9 >> 16;
if ( (__int16)v9 >= v7 )
{
if ( (__int16)v9 > v7 )
{
v14 = can_move(a1, 1u, a2, a4);
if ( a2 != 3 )
{
v12 = 1;
if ( v14 )
return v12;
}
}
LABEL_6:
if ( (__int16)v8 > (__int16)v10 )
{
v15 = can_move(a1, 0, a2, a4);
if ( a2 != 2 )
{
v12 = 0;
if ( v15 )
return v12;
}
}
else if ( (__int16)v8 < (__int16)v10 )
{
v11 = can_move(a1, 2u, a2, a4);
if ( a2 )
{
v12 = 2;
if ( v11 )
return v12;
}
}
do
LABEL_20:
v12 = rand() % 4;
while ( !(unsigned int)can_move(a1, v12, a2, a4) );
return v12;
}
v13 = can_move(a1, 3u, a2, a4);
if ( a2 == 1 )
goto LABEL_6;
v12 = 3;
if ( !v13 )
goto LABEL_6;
return v12;
}

original_code:
int find_direction(SDL_Rect pos, int cur_direction, SDL_Rect target, int *nb_keys)
{
 if(target.x != -1 && target.y != -1)
 {
  SDL_Rect ftm_case, target_case;
  ftm_case = get_case(pos, cur_direction);
  target_case = get_case(target, HAUT);
  if(ftm_case.x > target_case.x)
  {
   if(can_move(pos, GAUCHE, cur_direction, nb_keys) && cur_direction != DROITE) return GAUCHE;
  }
  else if(ftm_case.x < target_case.x)
  {
   if(can_move(pos, DROITE, cur_direction, nb_keys) && cur_direction != GAUCHE) return DROITE;
  }
  if(ftm_case.y > target_case.y)
  {
   if(can_move(pos, HAUT, cur_direction, nb_keys) && cur_direction != BAS) return HAUT;
  }
  else if(ftm_case.y < target_case.y)
  {
   if(can_move(pos, BAS, cur_direction, nb_keys) && cur_direction != HAUT) return BAS;
  }
 }
 int rand_dir = rand()%4;
 while( !can_move(pos, rand_dir, cur_direction, nb_keys) ) rand_dir = rand()%4;
 return rand_dir;
}

canonical_original_code:
int find_direction(struct SDL_Rect pos, int cur_direction, struct SDL_Rect target, int *nb_keys)
{
 if(target.x != -1 && target.y != -1)
 {
  struct SDL_Rect ftm_case; struct SDL_Rect target_case;
  ftm_case = get_case(pos, cur_direction);
  target_case = get_case(target, HAUT);
  if(ftm_case.x > target_case.x)
  {
   if(can_move(pos, GAUCHE, cur_direction, nb_keys) && cur_direction != DROITE) return GAUCHE;
  }
  else if(ftm_case.x < target_case.x)
  {
   if(can_move(pos, DROITE, cur_direction, nb_keys) && cur_direction != GAUCHE) return DROITE;
  }
  if(ftm_case.y > target_case.y)
  {
   if(can_move(pos, HAUT, cur_direction, nb_keys) && cur_direction != BAS) return HAUT;
  }
  else if(ftm_case.y < target_case.y)
  {
   if(can_move(pos, BAS, cur_direction, nb_keys) && cur_direction != HAUT) return BAS;
  }
 }
 int rand_dir = rand()%4;
 while( !can_move(pos, rand_dir, cur_direction, nb_keys) ) rand_dir = rand()%4;
 return rand_dir;
}

variable_types: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
void __fastcall ia_controller(__int64 a1, __int64 *a2, int *a3, _DWORD *a4, _DWORD *a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, __int64 a56)
{
int v59; // er12

adjust_position((__int64)a2, *a3);
if ( (unsigned int)in_intersection(*a2, *a3) || !(unsigned int)can_move(*a2, *a3, *a3, a4) )
{
v59 = find_direction(*a2, *a3, a56, a4);
move((__int16 *)a2, v59, *a5);
*a3 = v59;
}
else
{
move((__int16 *)a2, *a3, *a5);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 *a2, int *a3, _DWORD *a4, _DWORD *a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, __int64 a56)
{
int v59; // er12

func2((__int64)a2, *a3);
if ( (unsigned int)func1(*a2, *a3) || !(unsigned int)func0(*a2, *a3, *a3, a4) )
{
v59 = func5(*a2, *a3, a56, a4);
func3((__int16 *)a2, v59, *a5);
*a3 = v59;
}
else
{
func3((__int16 *)a2, *a3, *a5);
}
}

original_code:
void ia_controller(Input in, config cfg, int controller, SDL_Rect *position, int *cur_direction, int *nb_keys, int *speed, int *num_image, SDL_Rect target)
{
 int new_direction;
 adjust_position(position, *cur_direction);
 if(in_intersection(*position, *cur_direction))
 {
  new_direction = find_direction(*position, *cur_direction, target, nb_keys);
  move(position, new_direction, *speed);
  *cur_direction = new_direction;
 }
 else if(can_move(*position, *cur_direction, *cur_direction, nb_keys))
  move(position, *cur_direction, *speed);
 else
 {
  new_direction = find_direction(*position, *cur_direction, target, nb_keys);
  move(position, new_direction, *speed);
  *cur_direction = new_direction;
 }
}

canonical_original_code:
void ia_controller(struct Input in, struct config cfg, int controller, struct SDL_Rect *position, int *cur_direction, int *nb_keys, int *speed, int *num_image, struct SDL_Rect target)
{
 int new_direction;
 adjust_position(position, *cur_direction);
 if(in_intersection(*position, *cur_direction))
 {
  new_direction = find_direction(*position, *cur_direction, target, nb_keys);
  move(position, new_direction, *speed);
  *cur_direction = new_direction;
 }
 else if(can_move(*position, *cur_direction, *cur_direction, nb_keys))
  move(position, *cur_direction, *speed);
 else
 {
  new_direction = find_direction(*position, *cur_direction, target, nb_keys);
  move(position, new_direction, *speed);
  *cur_direction = new_direction;
 }
}

user_defined_types: struct player { int up; int character; }


original_code:
int draw_result(char *file, int score)
{
 POINT p1,p2;
 int i=0, j=9, newscore=-1;
 One p[10];
 char chaine[128];
 char title[32];
 if(!read_results(file, p)) return 0;
 for(i=0; i<10; i++)
 {
  if(score > p[i].score)
  {
   newscore=i;
   break;
  }
 }
 if(newscore >= 0)
 {
  while(j != newscore)
  {
   p[j].score=p[j-1].score;
   strcpy(p[j].name, p[j-1].name);
   j--;
  }
  p[newscore].score=score;
  for(i=0; i<8; i++) p[newscore].name[i]='\0';
  strcpy(title, "NEW SCORE!");
 }
 else strcpy(title, "SCORE");
 Input in;
 memset(&in,0,sizeof(in));
 while(!in.quit)
 {
  UpdateEvents(&in);
  if(in.key[SDLK_RETURN])
  {
   if(!write_score(file, p)) return 0;
   else return 1;
  }
  else if(in.key[SDLK_ESCAPE]) return 0;
  SDL_FillRect(screen, ((void *)0), SDL_MapRGB(screen->format, 0, 0, 0));
  p1.x=200; p1.y=50;
  p2.x=400; p2.y=p1.y;
  aff_pol(title, 50, p1, 0xffc0);
  if(newscore >= 0) print_key(p[newscore].name, &in, 8);
  for(i=0; i<10; i++)
  {
   p1.y+=50; p2.y=p1.y;
   if(i==newscore) aff_pol(p[newscore].name, 30, p1, 0xffc0);
   else aff_pol(p[i].name, 30, p1, 0xffc0);
   sprintf(chaine, "%d", p[i].score);
   aff_pol(chaine, 30, p2, 0xffc0);
  }
  SDL_Flip(screen);
 }
 fprintf(stderr, "Score not saved, reason: Unknown!\n");
 return 0;
}

canonical_original_code:
int draw_result(char *file, int score)
{
 struct point p1; struct point p2;
 int i = 0; int j = 9; int newscore = -1;
 struct One p[10];
 char chaine[128];
 char title[32];
 if(!read_results(file, p)) return 0;
 for(i=0; i<10; i++)
 {
  if(score > p[i].score)
  {
   newscore=i;
   break;
  }
 }
 if(newscore >= 0)
 {
  while(j != newscore)
  {
   p[j].score=p[j-1].score;
   strcpy(p[j].name, p[j-1].name);
   j--;
  }
  p[newscore].score=score;
  for(i=0; i<8; i++) p[newscore].name[i]='\0';
  strcpy(title, "NEW SCORE!");
 }
 else strcpy(title, "SCORE");
 struct Input in;
 memset(&in,0,sizeof(in));
 while(!in.quit)
 {
  UpdateEvents(&in);
  if(in.key[SDLK_RETURN])
  {
   if(!write_score(file, p)) return 0;
   else return 1;
  }
  else if(in.key[SDLK_ESCAPE]) return 0;
  SDL_FillRect(screen, ((void *)0), SDL_MapRGB(screen->format, 0, 0, 0));
  p1.x=200; p1.y=50;
  p2.x=400; p2.y=p1.y;
  aff_pol(title, 50, p1, 0xffc0);
  if(newscore >= 0) print_key(p[newscore].name, &in, 8);
  for(i=0; i<10; i++)
  {
   p1.y+=50; p2.y=p1.y;
   if(i==newscore) aff_pol(p[newscore].name, 30, p1, 0xffc0);
   else aff_pol(p[i].name, 30, p1, 0xffc0);
   sprintf(chaine, "%d", p[i].score);
   aff_pol(chaine, 30, p2, 0xffc0);
  }
  SDL_Flip(screen);
 }
 fprintf(stderr, "Score not saved, reason: Unknown!\n");
 return 0;
}

variable_types:
file
char *

variable_types: score int

variable_types: i int

variable_types: j int

variable_types: newscore int

variable_types: struct One { char name[8]; int score; } [10]

variable_types:
chaine
char [128]

variable_types:
title
char [32]


repo: Burke-Lauenroth-Lab/SOILWAT

decompiled_code:
int sw_error(int status, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
if ( status )
exit(status);
return result;
}

canonical_decompiled_code:
int func0(int status, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
if ( status )
exit(status);
return result;
}

original_code:
void sw_error(int code, const char *format, ...)
{
  va_list ap;
  __builtin_va_start(ap,format);
  vfprintf(stderr, format, ap);
  __builtin_va_end(ap);
  if (code == 0) {
  } else {
      exit(code);
  }
}

canonical_original_code:
void sw_error(int code, char *format, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,format);
  vfprintf(stderr, format, ap);
  __builtin_va_end(ap);
  if (code == 0) {
  } else {
      exit(code);
  }
}

variable_types: code int

variable_types:
format
char *


DirName

decompiled_code:
char *__fastcall DirName(char *src)
{
char *v1; // rax
size_t v2; // rbx

s_1[0] = 0;
v1 = strrchr(src, 47);
if ( v1 || (v1 = strrchr(src, 92)) != 0LL )
{
v2 = (int)v1 - (int)src + 1;
strncpy(s_1, src, v2);
s_1[v2] = 0;
}
return s_1;
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
char *v1; // rax
size_t v2; // rbx

s_1[0] = 0;
v1 = strrchr(src, 47);
if ( v1 || (v1 = strrchr(src, 92)) != 0LL )
{
v2 = (int)v1 - (int)src + 1;
strncpy(s_1, src, v2);
s_1[v2] = 0;
}
return s_1;
}

original_code:
char *DirName(const char *p) {
 static char s[4096];
 char *c;
 int l;
 char sep1 = '/', sep2 = '\\';
 *s = '\0';
 if (!(c = (char*) strrchr(p, (int) sep1)))
  c = (char*) strrchr(p, (int) sep2);
 if (c) {
  l = c - p + 1;
  strncpy(s, p, l);
  s[l] = '\0';
 }
 return s;
}

canonical_original_code:
char *DirName(char *p) {
 static char s[4096];
 char *c;
 int l;
 char sep1 = '/'; char sep2 = '\\';
 *s = '\0';
 if (!(c = (char *) strrchr(p, (int) sep1)))
  c = (char *) strrchr(p, (int) sep2);
 if (c) {
  l = c - p + 1;
  strncpy(s, p, l);
  s[l] = '\0';
 }
 return s;
}

variable_types:
p
char *

variable_types:
c
char *

variable_types: l int

return_type: char *


BaseName

decompiled_code:
char *__fastcall BaseName(char *s)
{
char *v1; // rax
char *result; // rax

v1 = strrchr(s, 47);
if ( v1 || (v1 = strrchr(s, 92)) != 0LL )
result = v1 + 1;
else
result = s;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *s)
{
char *v1; // rax
char *result; // rax

v1 = strrchr(s, 47);
if ( v1 || (v1 = strrchr(s, 92)) != 0LL )
result = v1 + 1;
else
result = s;
return result;
}

original_code:
const char *BaseName(const char *p) {
 char *c;
 char sep1 = '/', sep2 = '\\';
 if (!(c = (char*) strrchr(p, (int) sep1)))
  c = (char*) strrchr(p, (int) sep2);
 return ((c != ((void *)0) )? c+1 : p);
}

canonical_original_code:
char *BaseName(char *p) {
 char *c;
 char sep1 = '/'; char sep2 = '\\';
 if (!(c = (char *) strrchr(p, (int) sep1)))
  c = (char *) strrchr(p, (int) sep2);
 return ((c != ((void *)0) )? c+1 : p);
}


FileExists

decompiled_code:
_BOOL8 __fastcall FileExists(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
Bool FileExists(const char *name) {
 struct stat statbuf;
 Bool result = swFALSE;
 if (0 == stat(name, &statbuf))
  result = ((((statbuf.st_mode)) & 0170000) == (0100000)) ? swTRUE : swFALSE;
 return (result);
}

canonical_original_code:
enum Bool FileExists(char *name) {
 struct stat statbuf;
 enum Bool result = swFALSE;
 if (0 == stat(name, &statbuf))
  result = ((((statbuf.st_mode)) & 0170000) == (0100000)) ? swTRUE : swFALSE;
 return (result);
}

variable_types:
name
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types:
result
enum Bool { swFALSE=expr, swTRUE=expr }

return_type: enum Bool { swFALSE=expr, swTRUE=expr }


DirExists

decompiled_code:
_BOOL8 __fastcall DirExists(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
Bool DirExists(const char *dname) {
 struct stat statbuf;
 Bool result = swFALSE;
 if (0 == stat(dname, &statbuf))
  result = ((((statbuf.st_mode)) & 0170000) == (0040000)) ? swTRUE : swFALSE;
 return (result);
}

canonical_original_code:
enum Bool DirExists(char *dname) {
 struct stat statbuf;
 enum Bool result = swFALSE;
 if (0 == stat(dname, &statbuf))
  result = ((((statbuf.st_mode)) & 0170000) == (0040000)) ? swTRUE : swFALSE;
 return (result);
}

variable_types:
dname
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


ChDir

decompiled_code:
_BOOL8 __fastcall ChDir(const char *a1)
{
return chdir(a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(const char *a1)
{
return chdir(a1) == 0;
}

original_code:
Bool ChDir(const char *dname) {
 return (chdir(dname) == 0) ? swTRUE : swFALSE;
}

canonical_original_code:
enum Bool ChDir(char *dname) {
 return (chdir(dname) == 0) ? swTRUE : swFALSE;
}


MkDir

decompiled_code:
_BOOL8 __fastcall MkDir(__int64 a1)
{
_BOOL4 v1; // ebx
char *v2; // rbp
__int64 v3; // rbx
int v4; // er12
char *v5; // rax
int v6; // edx
const char **v7; // r12
__int64 *v8; // r13
__int64 v10[261]; // [rsp+0h] [rbp-828h] BYREF

memset(v10, 0, 0x800uLL);
v1 = 0;
if ( a1 )
{
v2 = (char *)sw_strdup(a1);
if ( !v2 )
sw_error(-1, "Out of memory making string in MkDir()");
v10[0] = (__int64)strtok(v2, "\\/");
v3 = 1LL;
do
{
v4 = v3;
v5 = strtok(0LL, "\\/");
v10[v3] = (__int64)v5;
v6 = v3++;
}
while ( v5 );
errstr = 0;
if ( v4 <= 0 )
{
v1 = 1;
}
else
{
v7 = (const char **)v10;
v8 = &v10[(unsigned int)(v6 - 1) + 1];
while ( 1 )
{
strcat(&errstr, *v7);
v1 = DirExists(&errstr);
if ( !v1 && mkdir(&errstr, 0x1FFu) && *_errno_location() == 13 )
break;
*(_WORD *)(&errstr + strlen(&errstr)) = 47;
if ( ++v7 == (const char **)v8 )
{
v1 = 1;
break;
}
}
}
free(v2);
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
_BOOL4 v1; // ebx
char *v2; // rbp
__int64 v3; // rbx
int v4; // er12
char *v5; // rax
int v6; // edx
const char **v7; // r12
__int64 *v8; // r13
__int64 v10[261]; // [rsp+0h] [rbp-828h] BYREF

memset(v10, 0, 0x800uLL);
v1 = 0;
if ( a1 )
{
v2 = (char *)sw_strdup(a1);
if ( !v2 )
func0(-1, "Out of memory making string in MkDir()");
v10[0] = (__int64)strtok(v2, "\\/");
v3 = 1LL;
do
{
v4 = v3;
v5 = strtok(0LL, "\\/");
v10[v3] = (__int64)v5;
v6 = v3++;
}
while ( v5 );
errstr = 0;
if ( v4 <= 0 )
{
v1 = 1;
}
else
{
v7 = (const char **)v10;
v8 = &v10[(unsigned int)(v6 - 1) + 1];
while ( 1 )
{
strcat(&errstr, *v7);
v1 = func8(&errstr);
if ( !v1 && mkdir(&errstr, 0x1FFu) && *_errno_location() == 13 )
break;
*(_WORD *)(&errstr + strlen(&errstr)) = 47;
if ( ++v7 == (const char **)v8 )
{
v1 = 1;
break;
}
}
}
free(v2);
}
return v1;
}

original_code:
Bool MkDir(const char *dname) {
 int r, i, n;
 Bool result = swTRUE;
 char *a[256] = { 0 },
  *c;
 const char *delim = "\\/";
 if ((((void *)0) == (dname)))
  return swFALSE;
 if (((void *)0) == (c = sw_strdup(dname))) {
  sw_error(-1, "Out of memory making string in MkDir()");
 }
 n = 0;
 a[n++] = strtok(c, delim);
 while (((void *)0) != (a[n++] = strtok(((void *)0), delim)))
  ;
 n--;
 errstr[0] = '\0';
 for (i = 0; i < n; i++) {
  strcat(errstr, a[i]);
  if (!DirExists(errstr)) {
   if (0 != (r = mkdir(errstr, 0777))) {
    if ((*__errno_location ()) == 13) {
     result = swFALSE;
     break;
    }
   }
  }
  strcat(errstr, "/");
 }
 free(c);
 return result;
}

canonical_original_code:
enum Bool MkDir(char *dname) {
 int r; int i; int n;
 enum Bool result = swTRUE;
 char *a[256] = { 0 }; char *c;
 char *delim = "\\/";
 if ((((void *)0) == (dname)))
  return swFALSE;
 if (((void *)0) == (c = sw_strdup(dname))) {
  sw_error(-1, "Out of memory making string in MkDir()");
 }
 n = 0;
 a[n++] = strtok(c, delim);
 while (((void *)0) != (a[n++] = strtok(((void *)0), delim)))
  ;
 n--;
 errstr[0] = '\0';
 for (i = 0; i < n; i++) {
  strcat(errstr, a[i]);
  if (!DirExists(errstr)) {
   if (0 != (r = mkdir(errstr, 0777))) {
    if ((*__errno_location ()) == 13) {
     result = swFALSE;
     break;
    }
   }
  }
  strcat(errstr, "/");
 }
 free(c);
 return result;
}

variable_types: r int

variable_types: n int

variable_types:
delim
char *


RemoveFiles

decompiled_code:
__int64 __fastcall RemoveFiles(char *src)
{
__int64 result; // rax
__int64 v2; // rbp
char *v3; // rsi
int v4; // eax
__int64 v5; // rbx
char *v6; // r12
unsigned int v7; // er12
__int64 v8; // rbx
int v9; // [rsp+0h] [rbp-41Ch] BYREF
char dest[1048]; // [rsp+4h] [rbp-418h] BYREF

result = 1LL;
if ( src )
{
v2 = getfiles(src, &v9);
if ( v2 )
{
v3 = DirName(src);
strcpy(dest, v3);
v4 = strlen(dest);
if ( v9 <= 0 )
{
v7 = 1;
LABEL_12:
Mem_Free(v2);
return v7;
}
v5 = 0LL;
v6 = &dest[v4];
while ( 1 )
{
strcpy(v6, *(const char **)(v2 + 8 * v5));
if ( remove(dest) )
break;
if ( v9 <= (int)++v5 )
{
v7 = 1;
goto LABEL_9;
}
}
v7 = 0;
}
else
{
v7 = 1;
}
LABEL_9:
if ( v9 > 0 )
{
v8 = 0LL;
do
Mem_Free(*(_QWORD *)(v2 + 8 * v8++));
while ( v9 > (int)v8 );
}
goto LABEL_12;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *src)
{
__int64 result; // rax
__int64 v2; // rbp
char *v3; // rsi
int v4; // eax
__int64 v5; // rbx
char *v6; // r12
unsigned int v7; // er12
__int64 v8; // rbx
int v9; // [rsp+0h] [rbp-41Ch] BYREF
char dest[1048]; // [rsp+4h] [rbp-418h] BYREF

result = 1LL;
if ( src )
{
v2 = func5(src, &v9);
if ( v2 )
{
v3 = func3(src);
strcpy(dest, v3);
v4 = strlen(dest);
if ( v9 <= 0 )
{
v7 = 1;
LABEL_12:
Mem_Free(v2);
return v7;
}
v5 = 0LL;
v6 = &dest[v4];
while ( 1 )
{
strcpy(v6, *(const char **)(v2 + 8 * v5));
if ( remove(dest) )
break;
if ( v9 <= (int)++v5 )
{
v7 = 1;
goto LABEL_9;
}
}
v7 = 0;
}
else
{
v7 = 1;
}
LABEL_9:
if ( v9 > 0 )
{
v8 = 0LL;
do
Mem_Free(*(_QWORD *)(v2 + 8 * v8++));
while ( v9 > (int)v8 );
}
goto LABEL_12;
}
return result;
}

original_code:
Bool RemoveFiles(const char *fspec) {
 char **flist, fname[1024];
 int i, nfiles, dlen, result = swTRUE;
 if (fspec == ((void *)0) )
  return swTRUE;
 if ((flist = getfiles(fspec, &nfiles))) {
  strcpy(fname, DirName(fspec));
  dlen = strlen(fname);
  for (i = 0; i < nfiles; i++) {
   strcpy(fname + dlen, flist[i]);
   if (0 != remove(fname)) {
    result = swFALSE;
    break;
   }
  }
 }
 for (i = 0; i < nfiles; i++)
  Mem_Free(flist[i]);
 Mem_Free(flist);
 return (Bool) result;
}

canonical_original_code:
enum Bool RemoveFiles(char *fspec) {
 char **flist; char fname[1024];
 int i; int nfiles; int dlen; int result = swTRUE;
 if (fspec == ((void *)0) )
  return swTRUE;
 if ((flist = getfiles(fspec, &nfiles))) {
  strcpy(fname, DirName(fspec));
  dlen = strlen(fname);
  for (i = 0; i < nfiles; i++) {
   strcpy(fname + dlen, flist[i]);
   if (0 != remove(fname)) {
    result = swFALSE;
    break;
   }
  }
 }
 for (i = 0; i < nfiles; i++)
  Mem_Free(flist[i]);
 Mem_Free(flist);
 return (enum Bool) result;
}

variable_types:
fspec
char *

variable_types:
flist
char **

variable_types:
fname
char [1024]

variable_types: i int

variable_types: nfiles int

variable_types: dlen int

variable_types: result int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
logged = 0;
atexit((void (*)(void))&sw_check_log);
logfp = stdout;
sw_init_args((unsigned int)argc, argv);
if ( !QuietMode )
sw_print_version();
SW_CTL_setup_model(&firstfile);
SW_CTL_read_inputs_from_disk();
SW_WTH_finalize_all_weather();
SW_CTL_init_run();
SW_OUT_set_ncol();
SW_OUT_set_colnames();
SW_OUT_create_files();
SW_CTL_main();
SW_OUT_close_files();
SW_CTL_clear_model(1LL);
return 0;
}

original_code:
int main(int argc, char **argv) {
 logged = swFALSE;
 atexit(sw_check_log);
 logfp = stdout;
 sw_init_args(argc, argv);
 if (!QuietMode) {
  sw_print_version();
 }
 SW_CTL_setup_model(_firstfile);
 SW_CTL_read_inputs_from_disk();
 SW_WTH_finalize_all_weather();
 SW_CTL_init_run();
 SW_OUT_set_ncol();
 SW_OUT_set_colnames();
 SW_OUT_create_files();
 SW_CTL_main();
 SW_OUT_close_files();
 SW_CTL_clear_model(swTRUE);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void *__fastcall Mem_Malloc(size_t a1, const char *a2)
{
void *v2; // rbx

v2 = malloc(a1);
if ( !v2 )
LogError(logfp, 12LL, "Out of memory in %s()", a2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, const char *a2)
{
void *v2; // rbx

v2 = malloc(a1);
if ( !v2 )
LogError(logfp, 12LL, "Out of memory in %s()", a2);
return v2;
}

original_code:
void *Mem_Malloc(size_t size, const char *funcname) {
 void *p;
 p = malloc(size);
 if (p == ((void *)0) )
  LogError(logfp, 0x0c, "Out of memory in %s()", funcname);
 return p;
}

canonical_original_code:
void *Mem_Malloc(unsigned long size, char *funcname) {
 void *p;
 p = malloc(size);
 if (p == ((void *)0) )
  LogError(logfp, 0x0c, "Out of memory in %s()", funcname);
 return p;
}

variable_types:
size
unsigned long

variable_types:
funcname
char *

variable_types:
p
void *

return_type: void *


decompiled_code:
char *__fastcall Str_Dup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)Mem_Malloc(v1 + 1, "Str_Dup()");
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1, "Str_Dup()");
return strcpy(v2, src);
}

original_code:
char *Str_Dup(const char *s) {
 char *p;
 p = (char *) Mem_Malloc(strlen(s) + 1, "Str_Dup()");
 strcpy(p, s);
 return p;
}

canonical_original_code:
char *Str_Dup(char *s) {
 char *p;
 p = (char *) Mem_Malloc(strlen(s) + 1, "Str_Dup()");
 strcpy(p, s);
 return p;
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
void *__fastcall Mem_ReAlloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 || !a2 )
_assert_fail("p != NULL && sizeNew > 0", "src/mymemory.c", 0xBFu, "Mem_ReAlloc");
result = realloc(a1, a2);
if ( !result )
{
LogError(logfp, 12LL, "realloc failed in Mem_ReAlloc()");
result = a1;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 || !a2 )
_assert_fail("p != NULL && sizeNew > 0", "src/mymemory.c", 0xBFu, "Mem_ReAlloc");
result = realloc(a1, a2);
if ( !result )
{
LogError(logfp, 12LL, "realloc failed in Mem_ReAlloc()");
result = a1;
}
return result;
}

original_code:
void *Mem_ReAlloc(void *block, size_t sizeNew) {
 byte *p = (byte *) block,
 *pNew;
 ((p != ((void *)0) && sizeNew > 0) ? (void) (0) : __assert_fail ("p != NULL && sizeNew > 0", "src/mymemory.c", 191, __extension__ __PRETTY_FUNCTION__));
 pNew = (byte *) realloc(p, sizeNew);
 if (pNew != ((void *)0) ) {
  p = pNew;
 } else
  LogError(logfp, 0x0c, "realloc failed in Mem_ReAlloc()");
 return p;
}

canonical_original_code:
void *Mem_ReAlloc(void *block, unsigned long sizeNew) {
 unsigned char *p = (byte *) block; unsigned char *pNew;
 ((p != ((void *)0) && sizeNew > 0) ? (void) (0) : __assert_fail ("p != NULL && sizeNew > 0", "src/mymemory.c", 191, __extension__ __PRETTY_FUNCTION__));
 pNew = (unsigned char *) realloc(p, sizeNew);
 if (pNew != ((void *)0) ) {
  p = pNew;
 } else
  LogError(logfp, 0x0c, "realloc failed in Mem_ReAlloc()");
 return p;
}

variable_types:
block
void *

variable_types:
sizeNew
unsigned long

variable_types:
p
unsigned char *

variable_types:
pNew
unsigned char *


decompiled_code:
void __fastcall Mem_Free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void Mem_Free(void *block) {
 free(block);
}


decompiled_code:
void *__fastcall Mem_Set(void *a1, unsigned __int8 a2, size_t a3)
{
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func4(void *a1, unsigned __int8 a2, size_t a3)
{
return memset(a1, a2, a3);
}

original_code:
void Mem_Set(void *block, byte c, size_t n) {
 memset(block, (int) c, n);
}

canonical_original_code:
void Mem_Set(void *block, unsigned char c, unsigned long n) {
 memset(block, (int) c, n);
}

variable_types:
c
unsigned char

variable_types:
n
unsigned long


decompiled_code:
void *__fastcall Mem_Calloc(__int64 a1, __int64 a2, const char *a3)
{
void *v3; // rbx

v3 = Mem_Malloc(a1 * a2, a3);
Mem_Set(v3, 0, a1 * a2);
return v3;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, __int64 a2, const char *a3)
{
void *v3; // rbx

v3 = func0(a1 * a2, a3);
func4(v3, 0, a1 * a2);
return v3;
}

original_code:
void *Mem_Calloc(size_t nobjs, size_t size, const char *funcname) {
 void *p;
 p = Mem_Malloc(size * nobjs, funcname);
 Mem_Set(p, 0, size * nobjs);
 return p;
}

canonical_original_code:
void *Mem_Calloc(unsigned long nobjs, unsigned long size, char *funcname) {
 void *p;
 p = Mem_Malloc(size * nobjs, funcname);
 Mem_Set(p, 0, size * nobjs);
 return p;
}

variable_types:
nobjs
unsigned long


decompiled_code:
void *__fastcall Mem_Copy(void *a1, const void *a2, size_t a3)
{
return memcpy(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, const void *a2, size_t a3)
{
return memcpy(a1, a2, a3);
}

original_code:
void Mem_Copy(void *dest, const void *src, size_t n) {
 memcpy(dest, src, n);
}

canonical_original_code:
void Mem_Copy(void *dest, void *src, unsigned long n) {
 memcpy(dest, src, n);
}

variable_types:
dest
void *

variable_types:
src
void *


decompiled_code:
const char *__fastcall Str_TrimRight(const char *a1)
{
const char *v1; // rbx

v1 = &a1[strlen(a1)];
do
--v1;
while ( a1 <= v1 && ((*_ctype_b_loc())[*v1] & 0x2000) != 0 );
*((_BYTE *)v1 + 1) = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
const char *v1; // rbx

v1 = &a1[strlen(a1)];
do
--v1;
while ( a1 <= v1 && ((*_ctype_b_loc())[*v1] & 0x2000) != 0 );
*((_BYTE *)v1 + 1) = 0;
return a1;
}

original_code:
char *Str_TrimRight(char *s) {
 char *p = s + strlen(s);
 while ((--p) >= s && ((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short int) _ISspace))
  ;
 *(++p) = '\0';
 return s;
}

canonical_original_code:
char *Str_TrimRight(char *s) {
 char *p = s + strlen(s);
 while ((--p) >= s && ((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short) _ISspace))
  ;
 *(++p) = '\0';
 return s;
}


decompiled_code:
__int64 __fastcall Str_CompareI(char *a1, char *a2)
{
size_t v2; // rax
_BYTE *v3; // rbp
size_t v4; // rax
_BYTE *v5; // rbx
const char *v6; // r13
const char *v7; // rax
unsigned int v8; // er12

v2 = strlen(a1);
v3 = malloc(v2 + 1);
v4 = strlen(a2);
v5 = malloc(v4 + 1);
v6 = Str_ToUpper(a2, v5);
v7 = Str_ToUpper(a1, v3);
v8 = strcmp(v7, v6);
free(v3);
free(v5);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char *a2)
{
size_t v2; // rax
_BYTE *v3; // rbp
size_t v4; // rax
_BYTE *v5; // rbx
const char *v6; // r13
const char *v7; // rax
unsigned int v8; // er12

v2 = strlen(a1);
v3 = malloc(v2 + 1);
v4 = strlen(a2);
v5 = malloc(v4 + 1);
v6 = Str_ToUpper(a2, v5);
v7 = Str_ToUpper(a1, v3);
v8 = strcmp(v7, v6);
free(v3);
free(v5);
return v8;
}

original_code:
int Str_CompareI(char *t, char *s) {
 char *t1 = (char *) malloc(strlen(t) + 1);
 char *s1 = (char *) malloc(strlen(s) + 1);
 int r = strcmp(Str_ToUpper(t, t1), Str_ToUpper(s, s1));
 free(t1);
 free(s1);
 return r;
}

variable_types:
t
char *

variable_types: r int


UnComment

decompiled_code:
const char *__fastcall UnComment(char *haystack)
{
char *v1; // rax
char *v3; // rax

v1 = strchr(haystack, 35);
if ( v1 )
{
*v1 = 0;
}
else
{
v3 = strstr(haystack, "/*");
if ( v3 )
uncomment_cstyle((__int64)v3);
}
return Str_TrimRight(haystack);
}

canonical_decompiled_code:
const char *__fastcall func3(char *haystack)
{
char *v1; // rax
char *v3; // rax

v1 = strchr(haystack, 35);
if ( v1 )
{
*v1 = 0;
}
else
{
v3 = strstr(haystack, "/*");
if ( v3 )
func0((__int64)v3);
}
return func1(haystack);
}

original_code:
void UnComment(char *s) {
 char *p;
 if ((p = strchr(s, '#')))
  *p = '\0';
 else if ((p = strstr(s, "/*")))
  uncomment_cstyle(p);
 Str_TrimRight(s);
}


interpolation

decompiled_code:
double __fastcall interpolation(double a1, double a2, double a3, double a4, double a5)
{
return (a4 - a3) / (a2 - a1) * (a5 - a1) + a3;
}

canonical_decompiled_code:
double __fastcall func4(double a1, double a2, double a3, double a4, double a5)
{
return (a4 - a3) / (a2 - a1) * (a5 - a1) + a3;
}

original_code:
double interpolation(double x1, double x2, double y1, double y2, double deltaX) {
 return y1 + (((y2 - y1) / (x2 - x1)) * (deltaX - x1));
}

variable_types: deltaX double

return_type: double


variable_types:
equal
unsigned int *

variable_types:
size
unsigned int

variable_types: depth double

variable_types:
bounds
double []

variable_types:
i
unsigned int


lobfM

original_code:
double lobfM(double xs[], double ys[], unsigned int n) {
 double sumX, sumY, sumXY, sumX2, temp;
 unsigned int i;
 sumX = sumY = sumXY = sumX2 = 0.0;
 for (i = 0; i < n; i++) {
  sumX += xs[i];
  sumY += ys[i];
  sumXY += (xs[i] * ys[i]);
  sumX2 += ((xs[i]) * (xs[i]));
 }
 temp = n + 0.0;
 return ((sumX * sumY - temp * sumXY) / (((sumX) * (sumX)) - n * sumX2));
}

canonical_original_code:
double lobfM(double xs[], double ys[], unsigned int n) {
 double sumX; double sumY; double sumXY; double sumX2; double temp;
 unsigned int i;
 sumX = sumY = sumXY = sumX2 = 0.0;
 for (i = 0; i < n; i++) {
  sumX += xs[i];
  sumY += ys[i];
  sumXY += (xs[i] * ys[i]);
  sumX2 += ((xs[i]) * (xs[i]));
 }
 temp = n + 0.0;
 return ((sumX * sumY - temp * sumXY) / (((sumX) * (sumX)) - n * sumX2));
}

variable_types:
xs
double []

variable_types:
ys
double []

variable_types:
n
unsigned int

variable_types: sumX double

variable_types: sumY double

variable_types: sumXY double

variable_types: temp double


lobf

decompiled_code:
void __fastcall lobf(double *a1, double *a2, __int64 a3, __int64 a4, int a5)
{
*a1 = lobfM(a3, a4, a5);
*a2 = lobfB(a3, a4, a5);
}

canonical_decompiled_code:
void __fastcall func8(double *a1, double *a2, __int64 a3, __int64 a4, int a5)
{
*a1 = func6(a3, a4, a5);
*a2 = func7(a3, a4, a5);
}

original_code:
void lobf(double *m, double *b, double xs[], double ys[], unsigned int n) {
 *m = lobfM(xs, ys, n);
 *b = lobfB(xs, ys, n);
}

variable_types:
m
double *

variable_types:
b
double *


decompiled_code:
void *__fastcall sw_strdup(void *src)
{
size_t v1; // rbp
void *result; // rax

v1 = strlen((const char *)src) + 1;
result = malloc(v1);
if ( result )
result = memcpy(result, src, v1);
return result;
}

canonical_decompiled_code:
void *__fastcall func9(void *src)
{
size_t v1; // rbp
void *result; // rax

v1 = strlen((const char *)src) + 1;
result = malloc(v1);
if ( result )
result = memcpy(result, src, v1);
return result;
}

original_code:
char * sw_strdup(const char * s)
{
  size_t len = 1 + strlen(s);
  char *p = (char*) malloc(len);
  return p ? (char*) memcpy(p, s, len) : ((void *)0);
}

canonical_original_code:
char *sw_strdup(char *s)
{
  unsigned long len = 1 + strlen(s);
  char *p = (char*) malloc(len);
  return p ? (char *) memcpy(p, s, len) : ((void *)0);
}

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
p
char *


decompiled_code:
double __fastcall get_running_mean(int a1, double a2, double a3)
{
return (a3 - a2) / (double)a1 + a2;
}

canonical_decompiled_code:
double __fastcall func10(int a1, double a2, double a3)
{
return (a3 - a2) / (double)a1 + a2;
}

original_code:
double get_running_mean(unsigned int n, double mean_prev, double val_to_add)
{
 return mean_prev + (val_to_add - mean_prev) / n;
}


decompiled_code:
double __fastcall get_running_sqr(double a1, double a2, double a3)
{
return (a3 - a1) * (a3 - a2);
}

canonical_decompiled_code:
double __fastcall func11(double a1, double a2, double a3)
{
return (a3 - a1) * (a3 - a2);
}

original_code:
double get_running_sqr(double mean_prev, double mean_current, double val_to_add)
{
 return (val_to_add - mean_prev) * (val_to_add - mean_current);
}


decompiled_code:
double __fastcall final_running_sd(unsigned int a1, double a2)
{
double result; // xmm0_8
double v3; // xmm0_8

if ( a1 <= 1 )
return 0.0;
v3 = a2 / (double)(int)(a1 - 1);
if ( v3 < 0.0 )
result = sqrt(v3);
else
result = sqrt(v3);
return result;
}

canonical_decompiled_code:
double __fastcall func12(unsigned int a1, double a2)
{
double result; // xmm0_8
double v3; // xmm0_8

if ( a1 <= 1 )
return 0.0;
v3 = a2 / (double)(int)(a1 - 1);
if ( v3 < 0.0 )
result = sqrt(v3);
else
result = sqrt(v3);
return result;
}

original_code:
double final_running_sd(unsigned int n, double ssqr)
{
 return (n > 1) ? ((sizeof(ssqr / (n - 1))==sizeof(float)) ? sqrtf(ssqr / (n - 1)) : sqrt(ssqr / (n - 1))) : 0.;
}

variable_types: ssqr double