decompiled_code:
char __fastcall parse_cmdline(unsigned __int64 a1, const char **a2, _DWORD *a3, _DWORD *a4, int *a5, _DWORD *a6, int *a7)
{
__int64 i; // rbx
bool v12; // cf
bool v13; // zf
const char *v14; // rdx
const char *v15; // rdi
__int64 v16; // rcx
const char *v17; // rsi
char v18; // al
bool v19; // cf
bool v20; // zf
int v21; // eax
const char *v22; // rdi
const char *v23; // rdi
const char *v24; // rdi

if ( a1 <= 1 )
printhelpNquit(*a2);
for ( i = 1LL; i != a1; v13 = i == a1 )
{
if ( opt_help(a2[i]) )
printhelpNquit(*a2);
v12 = ++i < a1;
}
v14 = a2[1];
v15 = "preset";
v16 = 7LL;
v17 = v14;
do
{
if ( !v16 )
break;
v12 = *v17 < (unsigned int)*v15;
v13 = *v17++ == *v15++;
--v16;
}
while ( v13 );
v18 = (!v12 && !v13) - v12;
v19 = 0;
v20 = v18 == 0;
if ( v18 )
{
v22 = "auto";
v16 = 5LL;
v17 = a2[1];
do
{
if ( !v16 )
break;
v19 = *v17 < (unsigned int)*v22;
v20 = *v17++ == *v22++;
--v16;
}
while ( v20 );
if ( (!v19 && !v20) != v19 )
printhelpNquit(*a2);
*a6 = 1;
}
else
{
*a6 = 0;
}
if ( (unsigned int)isname(a2[2], v17, v14, v16) )
{
*a4 = 1;
}
else
{
v23 = a2[2];
if ( !v23 )
printhelpNquit(*a2);
*a5 = atoi(v23);
}
if ( !a2[3] )
printhelpNquit(*a2);
v13 = strcmp(a2[3], "nop") == 0;
LOBYTE(v21) = !v13;
if ( v13 )
{
*a3 = 0;
}
else if ( !strcmp(a2[3], "num") )
{
*a3 = 1;
v24 = a2[4];
if ( !v24 )
printhelpNquit(*a2);
v21 = atoi(v24);
*a7 = v21;
}
else
{
v13 = strcmp(a2[3], "fix") == 0;
LOBYTE(v21) = !v13;
if ( !v13 )
printhelpNquit(*a2);
*a3 = 2;
}
return v21;
}

original_code:
void parse_cmdline(int *argc, char *argv[], int *mode, int *forkmode, pid_t *pidtarg, int *offsetmode, int *valeax)
{
    int cont;
    if (argc<=1) printhelpNquit(argv[0]);
    for (cont=1; cont<argc; cont++)
        {
        if (opt_help(argv[cont]))
            {
            printhelpNquit(argv[0]);
            }
        }
    if (strcmp(argv[1],"preset")==0)*offsetmode=0;
    else if (strcmp(argv[1],"auto")==0)*offsetmode=1;
    else printhelpNquit(argv[0]);
    if (isname(argv[2]))(*forkmode)=1;
    else if (argv[2]==((void *)0)) printhelpNquit(argv[0]);
    else *pidtarg=atoi(argv[2]);
    if (argv[3]==((void *)0)) printhelpNquit(argv[0]);
    else if (strcmp(argv[3],"nop")==0) *mode=0;
    else if (strcmp(argv[3],"num")==0) *mode=1;
    else if (strcmp(argv[3],"fix")==0) *mode=2;
    else printhelpNquit(argv[0]);
    if ((*mode)==1)
        {
        if (argv[4]==((void *)0)) printhelpNquit(argv[0]);
        else *valeax=atoi(argv[4]);
        }
}

canonical_original_code:
void parse_cmdline(int *argc, char *argv[], int *mode, int *forkmode, int *pidtarg, int *offsetmode, int *valeax)
{
    int cont;
    if (argc<=1) printhelpNquit(argv[0]);
    for (cont=1; cont<argc; cont++)
        {
        if (opt_help(argv[cont]))
            {
            printhelpNquit(argv[0]);
            }
        }
    if (strcmp(argv[1],"preset")==0)*offsetmode=0;
    else if (strcmp(argv[1],"auto")==0)*offsetmode=1;
    else printhelpNquit(argv[0]);
    if (isname(argv[2]))(*forkmode)=1;
    else if (argv[2]==((void *)0)) printhelpNquit(argv[0]);
    else *pidtarg=atoi(argv[2]);
    if (argv[3]==((void *)0)) printhelpNquit(argv[0]);
    else if (strcmp(argv[3],"nop")==0) *mode=0;
    else if (strcmp(argv[3],"num")==0) *mode=1;
    else if (strcmp(argv[3],"fix")==0) *mode=2;
    else printhelpNquit(argv[0]);
    if ((*mode)==1)
        {
        if (argv[4]==((void *)0)) printhelpNquit(argv[0]);
        else *valeax=atoi(argv[4]);
        }
}

variable_types:
argc
int *

variable_types:
argv
char *[]

variable_types:
mode
int *

variable_types:
forkmode
int *

variable_types:
pidtarg
int *

variable_types:
offsetmode
int *

variable_types:
valeax
int *

variable_types: cont int


endNcurses

decompiled_code:
void endNcurses(void)
{
endwin();
}

canonical_decompiled_code:
void func0(void)
{
endwin();
}

original_code:
void endNcurses()
{
    endwin();
}

canonical_original_code:
void endNcurses()
{
    endwin();
}

return_type: void


decompiled_code:
__int64 __fastcall crea_snacache(_QWORD *a1, int a2, int a3)
{
void *v4; // rax
__int64 v5; // rbx
__int64 v6; // r12
void **v7; // r13
int v9; // ebx
int v10; // er13

v4 = malloc(8LL * a2);
*a1 = v4;
if ( !v4 )
return 0LL;
if ( a2 <= 0 )
return 1LL;
v5 = 0LL;
while ( 1 )
{
v6 = 8 * v5;
v7 = (void **)(*a1 + 8 * v5);
*v7 = malloc(a3);
if ( !*(_QWORD *)(*a1 + 8 * v5) )
break;
if ( ++v5 == a2 )
return 1LL;
}
if ( (int)v5 < 0 )
return 0LL;
v9 = v5 + 1;
v10 = 0;
do
{
free(*(void **)(*a1 + v6));
++v10;
}
while ( v9 != v10 );
return 0LL;
}

original_code:
int crea_snacache(char ***board, int maxx, int maxy)
{
    int cont,r;
    (*board)=(char **)malloc(sizeof(char*)*maxx);
    if ((*board)==((void *)0)) return 0;
    for (cont=0; cont<maxx; cont++)
        {
        (*board)[cont]=(char*)malloc(sizeof(char)*maxy);
        if ((*board)[cont]==((void *)0))
            {
            for (r=0; r<=cont; r++) free((*board)[cont]);
            return 0;
            }
        }
    return 1;
}

canonical_original_code:
int crea_snacache(char ***board, int maxx, int maxy)
{
    int cont; int r;
    (*board)=(char **)malloc(sizeof(char *)*maxx);
    if ((*board)==((void *)0)) return 0;
    for (cont=0; cont<maxx; cont++)
        {
        (*board)[cont]=(char *)malloc(sizeof(char)*maxy);
        if ((*board)[cont]==((void *)0))
            {
            for (r=0; r<=cont; r++) free((*board)[cont]);
            return 0;
            }
        }
    return 1;
}

variable_types:
board
char ***

variable_types: maxx int

variable_types: maxy int

variable_types: r int

return_type: int


decompiled_code:
int __fastcall dump_snacache(_QWORD *a1, int a2, int a3)
{
__int64 v3; // r13
__int64 i; // rbp
_QWORD *v5; // rbx
int result; // eax

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = a1;
if ( a2 > 0 )
{
do
printw("%d", (unsigned int)*(char *)(*v5++ + i));
while ( v5 != &a1[(unsigned int)(a2 - 1) + 1] );
}
result = printw("\n");
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1, int a2, int a3)
{
__int64 v3; // r13
__int64 i; // rbp
_QWORD *v5; // rbx
int result; // eax

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = a1;
if ( a2 > 0 )
{
do
printw("%d", (unsigned int)*(char *)(*v5++ + i));
while ( v5 != &a1[(unsigned int)(a2 - 1) + 1] );
}
result = printw("\n");
}
}
return result;
}

original_code:
void dump_snacache(char **board, int maxx, int maxy)
{
    int x,y;
    for (y=0; y<maxy; y++)
        {
        for (x=0; x<maxx; x++)
            {
            printw("%d",board[x][y]);
            }
        printw("\n");
        }
}

canonical_original_code:
void dump_snacache(char **board, int maxx, int maxy)
{
    int x; int y;
    for (y=0; y<maxy; y++)
        {
        for (x=0; x<maxx; x++)
            {
            printw("%d",board[x][y]);
            }
        printw("\n");
        }
}

variable_types:
board
char **

variable_types: x int

variable_types: y int


decompiled_code:
void __fastcall kill_snacache(void **a1)
{
free(*a1);
*a1 = 0LL;
}

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

original_code:
void kill_snacache(char ***board)
{
    free(*board);
    (*board)=((void *)0);
}


creaserpente

decompiled_code:
__int64 __fastcall creaserpente(__int64 a1, int a2, int a3, int a4, int a5)
{
void *v8; // rax
int v9; // edx
__int64 result; // rax

*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 8) = 1;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 24) = 0;
*(_DWORD *)(a1 + 28) = 0;
v8 = malloc(8 * a5 * (__int64)a4);
*(_QWORD *)a1 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
v9 = crea_snacache((_QWORD *)(a1 + 40), a4, a5);
result = 0xFFFFFFFFLL;
if ( v9 )
{
**(_DWORD **)a1 = a2;
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = a3;
regen_snacache(a1, a4, a5);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3, int a4, int a5)
{
void *v8; // rax
int v9; // edx
__int64 result; // rax

*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 8) = 1;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 24) = 0;
*(_DWORD *)(a1 + 28) = 0;
v8 = malloc(8 * a5 * (__int64)a4);
*(_QWORD *)a1 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
v9 = func1((_QWORD *)(a1 + 40), a4, a5);
result = 0xFFFFFFFFLL;
if ( v9 )
{
**(_DWORD **)a1 = a2;
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = a3;
regen_snacache(a1, a4, a5);
result = 1LL;
}
return result;
}

original_code:
int creaserpente(snake *chi,int startx,int starty,int maxx,int maxy)
{
    chi->direz=0;
    chi->scheduledir=0;
    chi->numsezioni=1;
    chi->portalcross=0;
    chi->ate=0;
    chi->keepexp=0;
    chi->sezioni=(punto*)malloc(sizeof(punto)*maxx*maxy);
    if (chi->sezioni==((void *)0)) return -1;
    if (!crea_snacache(&(chi->cache),maxx,maxy))return -1;
    chi->sezioni[0].x=startx;
    chi->sezioni[0].y=starty;
    regen_snacache(chi,maxx,maxy);
    return 1;
}

canonical_original_code:
int creaserpente(struct snake *chi, int startx, int starty, int maxx, int maxy)
{
    chi->direz=0;
    chi->scheduledir=0;
    chi->numsezioni=1;
    chi->portalcross=0;
    chi->ate=0;
    chi->keepexp=0;
    chi->sezioni=(struct punto *)malloc(sizeof(punto)*maxx*maxy);
    if (chi->sezioni==((void *)0)) return -1;
    if (!crea_snacache(&(chi->cache),maxx,maxy))return -1;
    chi->sezioni[0].x=startx;
    chi->sezioni[0].y=starty;
    regen_snacache(chi,maxx,maxy);
    return 1;
}

variable_types: struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } *

variable_types: startx int

variable_types: starty int

user_defined_types: struct snake { struct punto *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; }


creacampo

decompiled_code:
__int64 __fastcall creacampo(__int64 a1)
{
int v1; // ebp
int v2; // er12
void *v3; // rax
__int64 result; // rax

*(_DWORD *)(a1 + 80) = 0;
*(_DWORD *)(a1 + 64) = 0;
*(_QWORD *)(a1 + 96) = 0LL;
v1 = *(_DWORD *)(a1 + 84);
v2 = *(_DWORD *)(a1 + 88);
v3 = malloc(8 * v2 * (__int64)v1);
*(_QWORD *)(a1 + 72) = v3;
if ( v3 )
result = 3 * (unsigned int)((int)creaserpente(a1, v1 / 2, v2 / 2, v1, v2) > 0) - 2;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int creacampo(campo *dove)
{
    dove->numpowerups=0;
    dove->numportals=0;
    dove->toblast=((void *)0);
    dove->powerup=(punto*)malloc(sizeof(punto)*dove->larg*dove->alt);
    if (dove->powerup==((void *)0)) return -1;
    if (creaserpente(&(dove->serpente),dove->larg/2,dove->alt/2,dove->larg,dove->alt)<=0) return -2;
    return 1;
}

canonical_original_code:
int creacampo(struct campo *dove)
{
    dove->numpowerups=0;
    dove->numportals=0;
    dove->toblast=((void *)0);
    dove->powerup=(struct punto *)malloc(sizeof(punto)*dove->larg*dove->alt);
    if (dove->powerup==((void *)0)) return -1;
    if (creaserpente(&(dove->serpente),dove->larg/2,dove->alt/2,dove->larg,dove->alt)<=0) return -2;
    return 1;
}

variable_types: struct campo { struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } serpente; struct punto portale[2]; int numportals; int nextportime; struct punto *powerup; int numpowerups; int larg; int alt; struct punto *toblast; int blastlung; } *

user_defined_types: struct campo { struct snake serpente; struct punto portale[2]; int numportals; int nextportime; struct punto *powerup; int numpowerups; int larg; int alt; struct punto *toblast; int blastlung; }


decompiled_code:
void __fastcall end_gioco(void **a1)
{
kill_snacache(a1 + 5);
free(*a1);
free(a1[9]);
}

canonical_decompiled_code:
void __fastcall func7(void **a1)
{
func3(a1 + 5);
free(*a1);
free(a1[9]);
}

original_code:
void end_gioco(vars *varia)
{
    kill_snacache(&(varia->gioco.serpente.cache));
    free(varia->gioco.serpente.sezioni);
    free(varia->gioco.powerup);
}

canonical_original_code:
void end_gioco(struct vars *varia)
{
    kill_snacache(&(varia->gioco.serpente.cache));
    free(varia->gioco.serpente.sezioni);
    free(varia->gioco.powerup);
}

variable_types: struct vars { struct campo { struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } serpente; struct punto portale[2]; int numportals; int nextportime; struct punto *powerup; int numpowerups; int larg; int alt; struct punto *toblast; int blastlung; } gioco; struct leaderboard { struct punteggio { int score; char nome[10]; char flags[6]; } *entry; int numentry; int curr; } board; int score; int speed; int quit; int paused; int gameover; int gamemode; int colori; int safe_graph; int game_insane; char playername[10]; } *

user_defined_types: struct vars { struct campo gioco; struct leaderboard board; int score; int speed; int quit; int paused; int gameover; int gamemode; int colori; int safe_graph; int game_insane; char playername[10]; }

user_defined_types: struct leaderboard { struct punteggio *entry; int numentry; int curr; }


decompiled_code:
char __fastcall init_colori(__int64 a1)
{
char result; // al

result = has_colors();
if ( result )
{
*(_DWORD *)(a1 + 152) = 1;
start_color();
init_pair(5, 1, 0);
init_pair(6, 4, 0);
init_pair(1, 3, 0);
init_pair(2, 2, 0);
result = init_pair(3, 5, 0);
}
else
{
*(_DWORD *)(a1 + 152) = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func8(__int64 a1)
{
char result; // al

result = has_colors();
if ( result )
{
*(_DWORD *)(a1 + 152) = 1;
start_color();
init_pair(5, 1, 0);
init_pair(6, 4, 0);
init_pair(1, 3, 0);
init_pair(2, 2, 0);
result = init_pair(3, 5, 0);
}
else
{
*(_DWORD *)(a1 + 152) = 0;
}
return result;
}

original_code:
void init_colori(vars *varia)
{
    if (has_colors() == 0)
        {
        varia->colori=0;
        }
    else
        {
        varia->colori=1;
        start_color();
        init_pair(((0)+5), 1, 0);
        init_pair(((1)+5), 4, 0);
        init_pair(1, 3, 0);
        init_pair(2, 2, 0);
        init_pair(3, 5, 0);
        }
}

canonical_original_code:
void init_colori(struct vars *varia)
{
    if (has_colors() == 0)
        {
        varia->colori=0;
        }
    else
        {
        varia->colori=1;
        start_color();
        init_pair(((0)+5), 1, 0);
        init_pair(((1)+5), 4, 0);
        init_pair(1, 3, 0);
        init_pair(2, 2, 0);
        init_pair(3, 5, 0);
        }
}

user_defined_types: struct punteggio { int score; char nome[10]; char flags[6]; }


startNcurses

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

initscr();
wclear(stdscr);
wtimeout(stdscr, 0);
noecho();
keypad(stdscr, 1);
v2 = -1;
if ( stdscr )
v2 = stdscr->_maxy + 1;
*a2 = v2;
if ( stdscr )
{
v3 = stdscr->_maxx + 1;
*a1 = v3;
if ( (v3 & 1) == 0 )
goto LABEL_8;
}
else
{
v3 = -1;
}
*a1 = v3 - 1;
LABEL_8:
if ( (*a2 & 1) != 0 )
--*a2;
*a1 -= 2;
*a2 -= 2;
result = (unsigned int)(*a1 / 2);
*a1 = result;
return result;
}

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

initscr();
wclear(stdscr);
wtimeout(stdscr, 0);
noecho();
keypad(stdscr, 1);
v2 = -1;
if ( stdscr )
v2 = stdscr->_maxy + 1;
*a2 = v2;
if ( stdscr )
{
v3 = stdscr->_maxx + 1;
*a1 = v3;
if ( (v3 & 1) == 0 )
goto LABEL_8;
}
else
{
v3 = -1;
}
*a1 = v3 - 1;
LABEL_8:
if ( (*a2 & 1) != 0 )
--*a2;
*a1 -= 2;
*a2 -= 2;
result = (unsigned int)(*a1 / 2);
*a1 = result;
return result;
}

original_code:
void startNcurses(int *larg, int *alt)
{
    initscr();
 wclear(stdscr);
    wtimeout(stdscr,(0));
    noecho();
    keypad (stdscr, 1);
    (*alt = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), *larg = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    if ((*larg)%2!=0)(*larg)--;
    if ((*alt)%2!=0)(*alt)--;
    (*larg)=(*larg)-2;
    (*alt)=(*alt)-2;
    (*larg)=(*larg)/2;
}

canonical_original_code:
void startNcurses(int *larg, int *alt)
{
    initscr();
 wclear(stdscr);
    wtimeout(stdscr,(0));
    noecho();
    keypad (stdscr, 1);
    (*alt = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), *larg = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    if ((*larg)%2!=0)(*larg)--;
    if ((*alt)%2!=0)(*alt)--;
    (*larg)=(*larg)-2;
    (*alt)=(*alt)-2;
    (*larg)=(*larg)/2;
}

variable_types:
larg
int *

variable_types:
alt
int *


riprova

original_code:
void riprova(vars *varia)
{
    varia->paused=0;
    varia->quit=0;
    varia->score=0;
    varia->gameover=0;
    varia->gioco.numportals=0;
    varia->gioco.nextportime=0;
    varia->gioco.numpowerups=0;
    varia->gioco.toblast=((void *)0);
    varia->gioco.serpente.numsezioni=1;
    varia->gioco.serpente.sezioni[0].x=varia->gioco.larg/2;
    varia->gioco.serpente.sezioni[0].y=varia->gioco.alt/2;
    regen_snacache(&(varia->gioco.serpente),varia->gioco.larg,varia->gioco.alt);
    varia->gioco.serpente.ate=0;
    varia->gioco.serpente.portalcross=0;
    varia->gioco.serpente.keepexp=0;
    wclear(stdscr);
    wrefresh(stdscr);
}

canonical_original_code:
void riprova(struct vars *varia)
{
    varia->paused=0;
    varia->quit=0;
    varia->score=0;
    varia->gameover=0;
    varia->gioco.numportals=0;
    varia->gioco.nextportime=0;
    varia->gioco.numpowerups=0;
    varia->gioco.toblast=((void *)0);
    varia->gioco.serpente.numsezioni=1;
    varia->gioco.serpente.sezioni[0].x=varia->gioco.larg/2;
    varia->gioco.serpente.sezioni[0].y=varia->gioco.alt/2;
    regen_snacache(&(varia->gioco.serpente),varia->gioco.larg,varia->gioco.alt);
    varia->gioco.serpente.ate=0;
    varia->gioco.serpente.portalcross=0;
    varia->gioco.serpente.keepexp=0;
    wclear(stdscr);
    wrefresh(stdscr);
}


gameover

decompiled_code:
__int64 __fastcall gameover(__int64 a1, int a2)
{
__int64 v2; // rbp

*(_DWORD *)(a1 + 140) = 1;
*(_DWORD *)(a1 + 144) = a2;
v2 = a1 + 112;
if ( (unsigned int)open_savefile(a1 + 112, "scoreboard.txt") == -3 )
{
++*(_DWORD *)(a1 + 160);
if ( (unsigned int)copyfile("scoreboard.txt.backup", "scoreboard.txt") )
{
if ( (unsigned int)open_savefile(v2, "scoreboard.txt") == -3 )
{
*(_DWORD *)(a1 + 160) += 2;
remove("scoreboard.txt");
remove("scoreboard.txt.backup");
}
}
else
{
*(_DWORD *)(a1 + 160) += 2;
remove("scoreboard.txt");
open_savefile(v2, "scoreboard.txt");
}
}
update_savefile(a1 + 164, *(unsigned int *)(a1 + 128), "scoreboard.txt", a1);
copyfile("scoreboard.txt", "scoreboard.txt.backup");
free(*(void **)(a1 + 112));
return open_savefile(v2, "scoreboard.txt");
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 v2; // rbp

*(_DWORD *)(a1 + 140) = 1;
*(_DWORD *)(a1 + 144) = a2;
v2 = a1 + 112;
if ( (unsigned int)open_savefile(a1 + 112, "scoreboard.txt") == -3 )
{
++*(_DWORD *)(a1 + 160);
if ( (unsigned int)func11("scoreboard.txt.backup", "scoreboard.txt") )
{
if ( (unsigned int)open_savefile(v2, "scoreboard.txt") == -3 )
{
*(_DWORD *)(a1 + 160) += 2;
remove("scoreboard.txt");
remove("scoreboard.txt.backup");
}
}
else
{
*(_DWORD *)(a1 + 160) += 2;
remove("scoreboard.txt");
open_savefile(v2, "scoreboard.txt");
}
}
update_savefile(a1 + 164, *(unsigned int *)(a1 + 128), "scoreboard.txt", a1);
func11("scoreboard.txt", "scoreboard.txt.backup");
free(*(void **)(a1 + 112));
return open_savefile(v2, "scoreboard.txt");
}

original_code:
void gameover(vars *varia, int causa)
{
    int ret,ret2;
    varia->paused=1;
    varia->gameover=causa;
    ret=open_savefile(&(varia->board),"scoreboard.txt");
    if (ret==-3)
        {
        varia->game_insane+=0b1;
        ret2=copyfile("scoreboard.txt.backup","scoreboard.txt");
        if (ret2!=0)
            {
            ret=open_savefile(&(varia->board),"scoreboard.txt");
            if (ret==-3)
                {
                varia->game_insane+=0b10;
                remove("scoreboard.txt");
                remove("scoreboard.txt.backup");
                }
            }
        else
            {
            varia->game_insane+=0b10;
            remove("scoreboard.txt");
            open_savefile(&(varia->board),"scoreboard.txt");
            }
        update_savefile(varia->playername,varia->score,"scoreboard.txt",varia);
        copyfile("scoreboard.txt","scoreboard.txt.backup");
        }
    else
        {
        update_savefile(varia->playername,varia->score,"scoreboard.txt",varia);
        copyfile("scoreboard.txt","scoreboard.txt.backup");
        }
    free(varia->board.entry);
    open_savefile(&(varia->board),"scoreboard.txt");
}

canonical_original_code:
void gameover(struct vars *varia, int causa)
{
    int ret; int ret2;
    varia->paused=1;
    varia->gameover=causa;
    ret=open_savefile(&(varia->board),"scoreboard.txt");
    if (ret==-3)
        {
        varia->game_insane+=0b1;
        ret2=copyfile("scoreboard.txt.backup","scoreboard.txt");
        if (ret2!=0)
            {
            ret=open_savefile(&(varia->board),"scoreboard.txt");
            if (ret==-3)
                {
                varia->game_insane+=0b10;
                remove("scoreboard.txt");
                remove("scoreboard.txt.backup");
                }
            }
        else
            {
            varia->game_insane+=0b10;
            remove("scoreboard.txt");
            open_savefile(&(varia->board),"scoreboard.txt");
            }
        update_savefile(varia->playername,varia->score,"scoreboard.txt",varia);
        copyfile("scoreboard.txt","scoreboard.txt.backup");
        }
    else
        {
        update_savefile(varia->playername,varia->score,"scoreboard.txt",varia);
        copyfile("scoreboard.txt","scoreboard.txt.backup");
        }
    free(varia->board.entry);
    open_savefile(&(varia->board),"scoreboard.txt");
}

variable_types: causa int

variable_types: ret int


checkwin

decompiled_code:
__int64 __fastcall checkwin(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)(a1[22] * a1[21]);
if ( a1[2] == (_DWORD)result )
result = gameover((__int64)a1, 2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)(a1[22] * a1[21]);
if ( a1[2] == (_DWORD)result )
result = func13((__int64)a1, 2);
return result;
}

original_code:
void checkwin(vars *varia)
{
    if (varia->gioco.serpente.numsezioni==(varia->gioco.larg*varia->gioco.alt))
        {
        gameover(varia,2);
        }
}

canonical_original_code:
void checkwin(struct vars *varia)
{
    if (varia->gioco.serpente.numsezioni==(varia->gioco.larg*varia->gioco.alt))
        {
        gameover(varia,2);
        }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char *v4; // rax

setlocale(6, "it_IT.UTF-8");
v3 = time(0LL);
srand(v3);
startNcurses((int *)(unsigned int)((_DWORD)globali + 84), (int *)(unsigned int)((_DWORD)globali + 88));
v4 = getenv("USER");
snprintf((char *)(unsigned int)((_DWORD)globali + 164), 0xAuLL, "%s", v4);
init_colori((__int64)globali);
*(_DWORD *)&globali[132] = 2;
*(_DWORD *)&globali[36] = 0;
*(_DWORD *)&globali[156] = 0;
if ( (unsigned int)parse_cmdline((unsigned int)argc, argv, globali) )
{
start_gioco(globali);
}
else
{
start_gioco(globali);
*(_DWORD *)&globali[144] = 1;
*(_DWORD *)&globali[140] = 1;
title_loop(globali);
*(_DWORD *)&globali[140] = 0;
*(_DWORD *)&globali[144] = 0;
}
atexit(endNcurses);
wclear(stdscr);
wrefresh(stdscr);
game_loop(globali);
end_gioco((void **)globali);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char *v4; // rax

setlocale(6, "it_IT.UTF-8");
v3 = time(0LL);
srand(v3);
func9((int *)(unsigned int)((_DWORD)globali + 84), (int *)(unsigned int)((_DWORD)globali + 88));
v4 = getenv("USER");
snprintf((char *)(unsigned int)((_DWORD)globali + 164), 0xAuLL, "%s", v4);
func8((__int64)globali);
*(_DWORD *)&globali[132] = 2;
*(_DWORD *)&globali[36] = 0;
*(_DWORD *)&globali[156] = 0;
if ( (unsigned int)parse_cmdline((unsigned int)argc, argv, globali) )
{
func6(globali);
}
else
{
func6(globali);
*(_DWORD *)&globali[144] = 1;
*(_DWORD *)&globali[140] = 1;
title_loop(globali);
*(_DWORD *)&globali[140] = 0;
*(_DWORD *)&globali[144] = 0;
}
atexit(endNcurses);
wclear(stdscr);
wrefresh(stdscr);
game_loop(globali);
func7((void **)globali);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    setlocale(6,"it_IT.UTF-8");
    srand(time(((void *)0)));
    startNcurses(&(globali.gioco.larg),&(globali.gioco.alt));
    snprintf(globali.playername,10,"%s",getenv("USER"));
    init_colori(&globali);
    globali.speed=2;
    globali.gioco.serpente.ai=0b0;
    globali.safe_graph=0;
    if (!parse_cmdline(argc,argv,&globali))
        {
        start_gioco(&globali);
        globali.gameover=1;
        globali.paused=1;
        title_loop(&globali);
        globali.paused=0;
        globali.gameover=0;
        }
    else start_gioco(&globali);
    atexit(endNcurses);
    wclear(stdscr);
    wrefresh(stdscr);
    game_loop(&globali);
    end_gioco(&globali);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


presopup

decompiled_code:
__int64 __fastcall presopup(__int64 a1, int a2, int a3)
{
int v3; // ecx
__int64 v5; // rdx
__int64 i; // rax

v3 = *(_DWORD *)(a1 + 80);
if ( v3 <= 0 )
return 0LL;
v5 = *(_QWORD *)(a1 + 72);
for ( i = 0LL; i != v3; ++i )
{
if ( *(_DWORD *)(v5 + 8 * i) == a2 && *(_DWORD *)(v5 + 8 * i + 4) == a3 )
{
removepup(a1, (unsigned int)i);
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
int v3; // ecx
__int64 v5; // rdx
__int64 i; // rax

v3 = *(_DWORD *)(a1 + 80);
if ( v3 <= 0 )
return 0LL;
v5 = *(_QWORD *)(a1 + 72);
for ( i = 0LL; i != v3; ++i )
{
if ( *(_DWORD *)(v5 + 8 * i) == a2 && *(_DWORD *)(v5 + 8 * i + 4) == a3 )
{
removepup(a1, (unsigned int)i);
return 1LL;
}
}
return 0LL;
}

original_code:
int presopup(vars *varia, int x, int y)
{
    int cont,num=varia->gioco.numpowerups;
    for (cont=0; cont<num; cont++)
        {
        if (varia->gioco.powerup[cont].x==x && varia->gioco.powerup[cont].y==y)
            {
            removepup(&(varia->gioco),cont);
            return 1;
            }
        }
    return 0;
}

canonical_original_code:
int presopup(struct vars *varia, int x, int y)
{
    int cont; int num = varia->gioco.numpowerups;
    for (cont=0; cont<num; cont++)
        {
        if (varia->gioco.powerup[cont].x==x && varia->gioco.powerup[cont].y==y)
            {
            removepup(&(varia->gioco),cont);
            return 1;
            }
        }
    return 0;
}

variable_types: cont int

variable_types: num int


presoportal

decompiled_code:
__int64 __fastcall presoportal(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax

if ( a1[12] != a2 || (result = 1LL, a1[13] != a3) )
{
result = 0LL;
if ( a1[14] == a2 )
result = 2 * (unsigned int)(a1[15] == a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax

if ( a1[12] != a2 || (result = 1LL, a1[13] != a3) )
{
result = 0LL;
if ( a1[14] == a2 )
result = 2 * (unsigned int)(a1[15] == a3);
}
return result;
}

original_code:
inline int presoportal(vars *varia, int x, int y)
{
    if (x==varia->gioco.portale[0].x && y==varia->gioco.portale[0].y) return 1;
    if (x==varia->gioco.portale[1].x && y==varia->gioco.portale[1].y) return 2;
    return 0;
}

canonical_original_code:
inline int presoportal(struct vars *varia, int x, int y)
{
    if (x==varia->gioco.portale[0].x && y==varia->gioco.portale[0].y) return 1;
    if (x==varia->gioco.portale[1].x && y==varia->gioco.portale[1].y) return 2;
    return 0;
}


presomuro

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

result = 1LL;
if ( a2 >= 0 )
{
if ( *(_DWORD *)(a1 + 84) <= a2 || a3 < 0 )
result = 1LL;
else
result = *(_DWORD *)(a1 + 88) <= a3;
}
return result;
}

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

result = 1LL;
if ( a2 >= 0 )
{
if ( *(_DWORD *)(a1 + 84) <= a2 || a3 < 0 )
result = 1LL;
else
result = *(_DWORD *)(a1 + 88) <= a3;
}
return result;
}

original_code:
inline int presomuro(vars *varia, int x, int y)
{
    if (x<0 || x>=varia->gioco.larg || y<0 || y>=varia->gioco.alt) return 1;
    return 0;
}

canonical_original_code:
inline int presomuro(struct vars *varia, int x, int y)
{
    if (x<0 || x>=varia->gioco.larg || y<0 || y>=varia->gioco.alt) return 1;
    return 0;
}


morsocoda

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

if ( a2 < 0 || a3 < 0 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 84) > a2 && *(_DWORD *)(a1 + 88) > a3 )
result = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * a2) + a3) == 1;
return result;
}

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

if ( a2 < 0 || a3 < 0 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 84) > a2 && *(_DWORD *)(a1 + 88) > a3 )
result = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * a2) + a3) == 1;
return result;
}

original_code:
inline int morsocoda(vars *varia, int x, int y)
{
    snake *serp=&(varia->gioco.serpente);
    if (x<0 || y<0 || x>=varia->gioco.larg || y>=varia->gioco.alt) return 0;
    if (serp->cache[x][y]==1) return 1;
    return 0;
}

canonical_original_code:
inline int morsocoda(struct vars *varia, int x, int y)
{
    struct snake *serp = &(varia->gioco.serpente);
    if (x<0 || y<0 || x>=varia->gioco.larg || y>=varia->gioco.alt) return 0;
    if (serp->cache[x][y]==1) return 1;
    return 0;
}


original_code:
void fisica_serp(vars *varia)
{
    int newposx,newposy,lastposx,lastposy,cont,port;
    snake *serp=&(varia->gioco.serpente);
    serp->direz=serp->scheduledir;
    newposx=serp->sezioni[0].x;
    newposy=serp->sezioni[0].y;
    if (serp->ai&0b1)
        {
        if (rotelle(varia,&newposx,&newposy,serp->direz)==0)calc_direz(serp->direz,&newposx,&newposy);
        }
    else
        {
        calc_direz(serp->direz,&newposx,&newposy);
        }
    if (morsocoda(varia,newposx,newposy)) gameover(varia,-1);
    else if (presomuro(varia,newposx,newposy)) gameover(varia,-2);
    else
        {
        if (varia->gamemode&0b10000)
            {
            port=presoportal(varia,newposx,newposy);
            if (port!=0)
                {
                if (port==2)port=0;
                else port=1;
                newposx=varia->gioco.portale[port].x;
                newposy=varia->gioco.portale[port].y;
                serp->portalcross=1;
                }
            if (serp->portalcross>0)
                {
                serp->portalcross++;
                if (serp->portalcross==serp->numsezioni)serp->portalcross=0;
                }
            }
        if (morsocoda(varia,newposx,newposy)) gameover(varia,-1);
        else if (presomuro(varia,newposx,newposy)) gameover(varia,-2);
        else
            {
            serp->cache[newposx][newposy]=1;
            if (presopup(varia,newposx,newposy))mangiacibo(varia);
            for (cont=0; cont<serp->numsezioni; cont++)
                {
                lastposx=serp->sezioni[cont].x;
                serp->sezioni[cont].x=newposx;
                lastposy=serp->sezioni[cont].y;
                serp->sezioni[cont].y=newposy;
                newposx=lastposx;
                newposy=lastposy;
                }
            if (serp->ate>0)
                {
                varia->score+=10;
                serp->sezioni[serp->numsezioni].x=lastposx;
                serp->sezioni[serp->numsezioni].y=lastposy;
                serp->numsezioni++;
                serp->ate--;
                }
            else
                {
                wmove(stdscr,(lastposy+1),((lastposx*2)+1));
                serp->cache[lastposx][lastposy]=0;
                printw("  ");
                }
            }
        }
    serp->scheduledir=serp->direz;
}

canonical_original_code:
void fisica_serp(struct vars *varia)
{
    int newposx; int newposy; int lastposx; int lastposy; int cont; int port;
    struct snake *serp = &(varia->gioco.serpente);
    serp->direz=serp->scheduledir;
    newposx=serp->sezioni[0].x;
    newposy=serp->sezioni[0].y;
    if (serp->ai&0b1)
        {
        if (rotelle(varia,&newposx,&newposy,serp->direz)==0)calc_direz(serp->direz,&newposx,&newposy);
        }
    else
        {
        calc_direz(serp->direz,&newposx,&newposy);
        }
    if (morsocoda(varia,newposx,newposy)) gameover(varia,-1);
    else if (presomuro(varia,newposx,newposy)) gameover(varia,-2);
    else
        {
        if (varia->gamemode&0b10000)
            {
            port=presoportal(varia,newposx,newposy);
            if (port!=0)
                {
                if (port==2)port=0;
                else port=1;
                newposx=varia->gioco.portale[port].x;
                newposy=varia->gioco.portale[port].y;
                serp->portalcross=1;
                }
            if (serp->portalcross>0)
                {
                serp->portalcross++;
                if (serp->portalcross==serp->numsezioni)serp->portalcross=0;
                }
            }
        if (morsocoda(varia,newposx,newposy)) gameover(varia,-1);
        else if (presomuro(varia,newposx,newposy)) gameover(varia,-2);
        else
            {
            serp->cache[newposx][newposy]=1;
            if (presopup(varia,newposx,newposy))mangiacibo(varia);
            for (cont=0; cont<serp->numsezioni; cont++)
                {
                lastposx=serp->sezioni[cont].x;
                serp->sezioni[cont].x=newposx;
                lastposy=serp->sezioni[cont].y;
                serp->sezioni[cont].y=newposy;
                newposx=lastposx;
                newposy=lastposy;
                }
            if (serp->ate>0)
                {
                varia->score+=10;
                serp->sezioni[serp->numsezioni].x=lastposx;
                serp->sezioni[serp->numsezioni].y=lastposy;
                serp->numsezioni++;
                serp->ate--;
                }
            else
                {
                wmove(stdscr,(lastposy+1),((lastposx*2)+1));
                serp->cache[lastposx][lastposy]=0;
                printw("  ");
                }
            }
        }
    serp->scheduledir=serp->direz;
}

variable_types: newposx int

variable_types: newposy int

variable_types: lastposx int

variable_types: lastposy int

variable_types: port int


decompiled_code:
_BOOL8 __fastcall opt_normalmode(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-s") )
v1 = strcmp(a1, "--start") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-s") )
v1 = strcmp(a1, "--start") == 0;
return v1;
}

original_code:
int opt_normalmode(char *opt)
{
    if (strcmp(opt,"-s")==0) return 1;
    if (strcmp(opt,"--start")==0) return 1;
    return 0;
}

variable_types:
opt
char *


decompiled_code:
_BOOL8 __fastcall opt_doublemode(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-d") )
v1 = strcmp(a1, "--double") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-d") )
v1 = strcmp(a1, "--double") == 0;
return v1;
}

original_code:
int opt_doublemode(char *opt)
{
    if (strcmp(opt,"-d")==0) return 1;
    if (strcmp(opt,"--double")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_russianmode(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-r") )
v1 = strcmp(a1, "--russian") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-r") )
v1 = strcmp(a1, "--russian") == 0;
return v1;
}

original_code:
int opt_russianmode(char *opt)
{
    if (strcmp(opt,"-r")==0) return 1;
    if (strcmp(opt,"--russian")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_expmode(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-e") )
v1 = strcmp(a1, "--exponential") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-e") )
v1 = strcmp(a1, "--exponential") == 0;
return v1;
}

original_code:
int opt_expmode(char *opt)
{
    if (strcmp(opt,"-e")==0) return 1;
    if (strcmp(opt,"--exponential")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_speed(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-v") )
v1 = strcmp(a1, "--velocity") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-v") )
v1 = strcmp(a1, "--velocity") == 0;
return v1;
}

original_code:
int opt_speed(char *opt)
{
    if (strcmp(opt,"-v")==0) return 1;
    if (strcmp(opt,"--velocity")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_version(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-V") )
v1 = strcmp(a1, "--version") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-V") )
v1 = strcmp(a1, "--version") == 0;
return v1;
}

original_code:
int opt_version(char *opt)
{
    if (strcmp(opt,"-V")==0) return 1;
    if (strcmp(opt,"--version")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_portals(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-a") )
v1 = strcmp(a1, "--aperture") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-a") )
v1 = strcmp(a1, "--aperture") == 0;
return v1;
}

original_code:
int opt_portals(char *opt)
{
    if (strcmp(opt,"-a")==0) return 1;
    if (strcmp(opt,"--aperture")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_paused(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-p") )
v1 = strcmp(a1, "--paused") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-p") )
v1 = strcmp(a1, "--paused") == 0;
return v1;
}

original_code:
int opt_paused(char *opt)
{
    if (strcmp(opt,"-p")==0) return 1;
    if (strcmp(opt,"--paused")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_leaderboard(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-l") )
v1 = strcmp(a1, "--leaderboard") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-l") )
v1 = strcmp(a1, "--leaderboard") == 0;
return v1;
}

original_code:
int opt_leaderboard(char *opt)
{
    if (strcmp(opt,"-l")==0) return 1;
    if (strcmp(opt,"--leaderboard")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_help(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-h") )
{
v1 = 1;
if ( strcmp(a1, "--help") )
v1 = strcmp(a1, "-?") == 0;
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-h") )
{
v1 = 1;
if ( strcmp(a1, "--help") )
v1 = strcmp(a1, "-?") == 0;
}
return v1;
}

original_code:
int opt_help(char *opt)
{
    if (strcmp(opt,"-h")==0) return 1;
    if (strcmp(opt,"--help")==0) return 1;
    if (strcmp(opt,"-?")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_playername(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-n") )
v1 = strcmp(a1, "--name") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-n") )
v1 = strcmp(a1, "--name") == 0;
return v1;
}

original_code:
int opt_playername(char *opt)
{
    if (strcmp(opt,"-n")==0) return 1;
    if (strcmp(opt,"--name")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_resize(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-m") )
v1 = strcmp(a1, "--map") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-m") )
v1 = strcmp(a1, "--map") == 0;
return v1;
}

original_code:
int opt_resize(char *opt)
{
    if (strcmp(opt,"-m")==0) return 1;
    if (strcmp(opt,"--map")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_safegraph(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-S") )
v1 = strcmp(a1, "--simple-graphic") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-S") )
v1 = strcmp(a1, "--simple-graphic") == 0;
return v1;
}

original_code:
int opt_safegraph(char *opt)
{
    if (strcmp(opt,"-S")==0) return 1;
    if (strcmp(opt,"--simple-graphic")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_ai(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-c") )
v1 = strcmp(a1, "--computer") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-c") )
v1 = strcmp(a1, "--computer") == 0;
return v1;
}

original_code:
int opt_ai(char *opt)
{
    if (strcmp(opt,"-c")==0) return 1;
    if (strcmp(opt,"--computer")==0) return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall opt_singola(const char *a1)
{
return opt_speed(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(const char *a1)
{
return func4(a1);
}

original_code:
int opt_singola(char *opt)
{
    if (opt_speed(opt)) return 1;
    return 0;
}


printHelpExit

decompiled_code:
void __fastcall __noreturn printHelpExit(__int64 a1, const char *a2)
{
char *v2; // rax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v2 = getenv("LANG");
snprintf(s, 3uLL, "%s", v2);
end_gioco(a1);
endNcurses();
printf("%s -- Language: %s\n", "v 1.2 copyleft agentOfChaos informaniac99<AT>gmail<DOT>com", s);
if ( !strcmp(s, "it") )
{
puts("sn4ke! Gioco per console simile a snake.");
puts("Comandi:\twasd / tasti freccia per muovere il serpente");
puts("\t\ttastiera per operare nei menu; freccie su/giu per scorrere i punteggi");
printf("\tUtilizzo: %s [opzioni]\n", a2);
puts("Opzioni riga di comando:");
puts(aSStartInziaSub);
puts(aDDoubleInziaSu);
puts(aRRussianInziaS);
puts(aEExponentialIn);
puts(aVNumVelocityNu_0);
puts("\t-p --paused\t\t\tInizia il gioco in pausa (solo con -s -d -e -r)");
puts("\t-a --aperture\t\t\tAttiva i portali");
puts(aSSimpleGraphic_0);
puts("\t-m [h] [w] --map [h] [w]\tImposta manualmente la dimensione dello schermo (WxH)");
puts(aNNomeNameNomeI);
puts(aCModeComputerM_0);
puts(
"\t-l [num] --leaderboard [num]\tScrive i primi [num] punteggi migliori, poi termina. Il file dei punteggi non viene alterato");
puts("\t-h --help -?\t\t\tScrivi questo menu di aiuto e termina");
puts("Sottosistema AI (Artificial Intelligence)");
printf("\tlazy mode: il programma prende automaticamante il controllo in caso di urto imminente; ");
puts(aLIaSiLimitaADe);
puts("\nIndicatori partita (ultima colonna della tavola punteggi)");
puts("\tStringa d'esempio:\tdpl2");
puts(aSDREIndicaLaMo);
puts("\tp\t\t\tIndica che i portali sono attivi");
puts(aLIndicaCheLaAi);
puts(a01234IndicaLaV);
puts(aKIndicaCheLaPa);
}
else
{
puts("sn4ke! Snake-like game for the console.");
puts("Controls:\twasd / arrow keys move snake around");
puts("\t\tkeyboard operates menus; arrow keys up/down to scroll the scoreboard");
printf("\tUsage: %s [options]\n", a2);
puts("Command line options:");
puts("\t-s --start\t\t\tStart the game immediately (normal mode)");
puts("\t-d --double\t\t\tStart the game immediately (double growth mode)");
puts("\t-r --russian\t\t\tStart the game immediately (russian roulette mode)");
puts("\t-e --exponential\t\tStart the game immediately (exponential growth mode)");
puts("\t-v [num] --velocity [num]\tSet snake's speed (0-4)");
puts("\t-p --paused\t\t\tStart the game paused (only with -s -d -e -r)");
puts("\t-a --aperture\t\t\tEnable portals");
puts("\t-S --simple-graphic\t\tUses a more simple and portable set of graphic symbols");
puts("\t-m [h] [w] --map [h] [w]\tManually override screen size (WxH)");
puts("\t-n [name] --name [name]\t\tSet player's name as [name]. Default is env(USER)");
puts("\t-c [mode] --computer [mode]\tEnable AI subsystem. Mode can be \"no\" or \"lazy\". Default is \"no\"");
puts(
"\t-l [num] --leaderboard [num]\tPrints the first [num] top scores, then quits. The leaderboard file won't be modified");
puts("\t-h --help -?\t\t\tPrint this help menu and quit");
puts("AI subsystem (Artificial Intelligence)");
printf("\tlazy mode: the program will automatically assume control in case of imminent crash; ");
puts("AI action is limited to redirecting the snake in the most convenien direction.");
puts("\nGame indicators (last column in the leaderboard)");
puts("\tExample string:\tdpl2");
puts("\ts / d / r / e\t\tIndicates game mode");
puts("\tp\t\t\tIndicates portals are enabled ");
puts("\tl\t\t\tIndicates lazy mode AI is enabled");
puts("\t0 / 1 / 2 / 3 / 4\t\tIndicates game speed");
puts("\tk\t\t\tMarks a won game (snake filling the whole screen)");
}
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func15(__int64 a1, const char *a2)
{
char *v2; // rax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v2 = getenv("LANG");
snprintf(s, 3uLL, "%s", v2);
end_gioco(a1);
endNcurses();
printf("%s -- Language: %s\n", "v 1.2 copyleft agentOfChaos informaniac99<AT>gmail<DOT>com", s);
if ( !strcmp(s, "it") )
{
puts("sn4ke! Gioco per console simile a snake.");
puts("Comandi:\twasd / tasti freccia per muovere il serpente");
puts("\t\ttastiera per operare nei menu; freccie su/giu per scorrere i punteggi");
printf("\tUtilizzo: %s [opzioni]\n", a2);
puts("Opzioni riga di comando:");
puts(aSStartInziaSub);
puts(aDDoubleInziaSu);
puts(aRRussianInziaS);
puts(aEExponentialIn);
puts(aVNumVelocityNu_0);
puts("\t-p --paused\t\t\tInizia il gioco in pausa (solo con -s -d -e -r)");
puts("\t-a --aperture\t\t\tAttiva i portali");
puts(aSSimpleGraphic_0);
puts("\t-m [h] [w] --map [h] [w]\tImposta manualmente la dimensione dello schermo (WxH)");
puts(aNNomeNameNomeI);
puts(aCModeComputerM_0);
puts(
"\t-l [num] --leaderboard [num]\tScrive i primi [num] punteggi migliori, poi termina. Il file dei punteggi non viene alterato");
puts("\t-h --help -?\t\t\tScrivi questo menu di aiuto e termina");
puts("Sottosistema AI (Artificial Intelligence)");
printf("\tlazy mode: il programma prende automaticamante il controllo in caso di urto imminente; ");
puts(aLIaSiLimitaADe);
puts("\nIndicatori partita (ultima colonna della tavola punteggi)");
puts("\tStringa d'esempio:\tdpl2");
puts(aSDREIndicaLaMo);
puts("\tp\t\t\tIndica che i portali sono attivi");
puts(aLIndicaCheLaAi);
puts(a01234IndicaLaV);
puts(aKIndicaCheLaPa);
}
else
{
puts("sn4ke! Snake-like game for the console.");
puts("Controls:\twasd / arrow keys move snake around");
puts("\t\tkeyboard operates menus; arrow keys up/down to scroll the scoreboard");
printf("\tUsage: %s [options]\n", a2);
puts("Command line options:");
puts("\t-s --start\t\t\tStart the game immediately (normal mode)");
puts("\t-d --double\t\t\tStart the game immediately (double growth mode)");
puts("\t-r --russian\t\t\tStart the game immediately (russian roulette mode)");
puts("\t-e --exponential\t\tStart the game immediately (exponential growth mode)");
puts("\t-v [num] --velocity [num]\tSet snake's speed (0-4)");
puts("\t-p --paused\t\t\tStart the game paused (only with -s -d -e -r)");
puts("\t-a --aperture\t\t\tEnable portals");
puts("\t-S --simple-graphic\t\tUses a more simple and portable set of graphic symbols");
puts("\t-m [h] [w] --map [h] [w]\tManually override screen size (WxH)");
puts("\t-n [name] --name [name]\t\tSet player's name as [name]. Default is env(USER)");
puts("\t-c [mode] --computer [mode]\tEnable AI subsystem. Mode can be \"no\" or \"lazy\". Default is \"no\"");
puts(
"\t-l [num] --leaderboard [num]\tPrints the first [num] top scores, then quits. The leaderboard file won't be modified");
puts("\t-h --help -?\t\t\tPrint this help menu and quit");
puts("AI subsystem (Artificial Intelligence)");
printf("\tlazy mode: the program will automatically assume control in case of imminent crash; ");
puts("AI action is limited to redirecting the snake in the most convenien direction.");
puts("\nGame indicators (last column in the leaderboard)");
puts("\tExample string:\tdpl2");
puts("\ts / d / r / e\t\tIndicates game mode");
puts("\tp\t\t\tIndicates portals are enabled ");
puts("\tl\t\t\tIndicates lazy mode AI is enabled");
puts("\t0 / 1 / 2 / 3 / 4\t\tIndicates game speed");
puts("\tk\t\t\tMarks a won game (snake filling the whole screen)");
}
exit(0);
}

original_code:
void printHelpExit(vars *varia,char *nome)
{
    char lang[3];
    snprintf(lang,3,"%s",getenv("LANG"));
    end_gioco(varia);
    endNcurses();
    printf("%s -- Language: %s\n","v 1.2  copyleft  agentOfChaos  informaniac99<AT>gmail<DOT>com",lang);
    if (strcmp(lang,"it")==0)
        {
        printf("sn4ke! Gioco per console simile a snake.\n");
        printf("Comandi:\twasd / tasti freccia per muovere il serpente\n");
        printf("\t\ttastiera per operare nei menu; freccie su/giu per scorrere i punteggi\n");
        printf("\tUtilizzo: %s [opzioni]\n",nome);
        printf("Opzioni riga di comando:\n");
        printf("\t-s --start\t\t\tInzia subito il gioco (modalità normale)\n");
        printf("\t-d --double\t\t\tInzia subito il gioco (modalità crescita doppia)\n");
        printf("\t-r --russian\t\t\tInzia subito il gioco (modalità roulette russa)\n");
        printf("\t-e --exponential\t\tInzia subito il gioco (modalità crescita esponenziale)\n");
        printf("\t-v [num] --velocity [num]\tImposta la velocità di gioco (0-4)\n");
        printf("\t-p --paused\t\t\tInizia il gioco in pausa (solo con -s -d -e -r)\n");
        printf("\t-a --aperture\t\t\tAttiva i portali\n");
        printf("\t-S --simple-graphic\t\tUsa un set di simboli grafici più semplice e portabile\n");
        printf("\t-m [h] [w] --map [h] [w]\tImposta manualmente la dimensione dello schermo (WxH)\n");
        printf("\t-n [nome] --name [nome]\t\tImposta il nome del giocatore a [nome]. Default è env(USER)\n");
        printf("\t-c [mode] --computer [mode]\tAttiva il sottosistema AI. Mode può essere \"no\" oppure \"lazy\". Default è \"no\"\n");
        printf("\t-l [num] --leaderboard [num]\tScrive i primi [num] punteggi migliori, poi termina. Il file dei punteggi non viene alterato\n");
        printf("\t-h --help -?\t\t\tScrivi questo menu di aiuto e termina\n");
        printf("Sottosistema AI (Artificial Intelligence)\n");
        printf("\tlazy mode: il programma prende automaticamante il controllo in caso di urto imminente; ");
        printf("L' ia si limita a deviare il serpente nella direzione più conveniente.\n");
        printf("\nIndicatori partita (ultima colonna della tavola punteggi)\n");
        printf("\tStringa d'esempio:\tdpl2\n");
        printf("\ts / d / r / e\t\tIndica la modalità di gioco\n");
        printf("\tp\t\t\tIndica che i portali sono attivi\n");
        printf("\tl\t\t\tIndica che la AI è attiva in lazy mode\n");
        printf("\t0 / 1 / 2 / 3 / 4\t\tIndica la velocità di gioco\n");
        printf("\tk\t\t\tIndica che la partita è stata vinta (il serpente ha riempito il campo)\n");
        }
    else
        {
        printf("sn4ke! Snake-like game for the console.\n");
        printf("Controls:\twasd / arrow keys move snake around\n");
        printf("\t\tkeyboard operates menus; arrow keys up/down to scroll the scoreboard\n");
        printf("\tUsage: %s [options]\n",nome);
        printf("Command line options:\n");
        printf("\t-s --start\t\t\tStart the game immediately (normal mode)\n");
        printf("\t-d --double\t\t\tStart the game immediately (double growth mode)\n");
        printf("\t-r --russian\t\t\tStart the game immediately (russian roulette mode)\n");
        printf("\t-e --exponential\t\tStart the game immediately (exponential growth mode)\n");
        printf("\t-v [num] --velocity [num]\tSet snake's speed (0-4)\n");
        printf("\t-p --paused\t\t\tStart the game paused (only with -s -d -e -r)\n");
        printf("\t-a --aperture\t\t\tEnable portals\n");
        printf("\t-S --simple-graphic\t\tUses a more simple and portable set of graphic symbols\n");
        printf("\t-m [h] [w] --map [h] [w]\tManually override screen size (WxH)\n");
        printf("\t-n [name] --name [name]\t\tSet player's name as [name]. Default is env(USER)\n");
        printf("\t-c [mode] --computer [mode]\tEnable AI subsystem. Mode can be \"no\" or \"lazy\". Default is \"no\"\n");
        printf("\t-l [num] --leaderboard [num]\tPrints the first [num] top scores, then quits. The leaderboard file won't be modified\n");
        printf("\t-h --help -?\t\t\tPrint this help menu and quit\n");
        printf("AI subsystem (Artificial Intelligence)\n");
        printf("\tlazy mode: the program will automatically assume control in case of imminent crash; ");
        printf("AI action is limited to redirecting the snake in the most convenien direction.\n");
        printf("\nGame indicators (last column in the leaderboard)\n");
        printf("\tExample string:\tdpl2\n");
        printf("\ts / d / r / e\t\tIndicates game mode\n");
        printf("\tp\t\t\tIndicates portals are enabled \n");
        printf("\tl\t\t\tIndicates lazy mode AI is enabled\n");
        printf("\t0 / 1 / 2 / 3 / 4\t\tIndicates game speed\n");
        printf("\tk\t\t\tMarks a won game (snake filling the whole screen)\n");
        }
    exit(0);
}

canonical_original_code:
void printHelpExit(struct vars *varia, char *nome)
{
    char lang[3];
    snprintf(lang,3,"%s",getenv("LANG"));
    end_gioco(varia);
    endNcurses();
    printf("%s -- Language: %s\n","v 1.2  copyleft  agentOfChaos  informaniac99<AT>gmail<DOT>com",lang);
    if (strcmp(lang,"it")==0)
        {
        printf("sn4ke! Gioco per console simile a snake.\n");
        printf("Comandi:\twasd / tasti freccia per muovere il serpente\n");
        printf("\t\ttastiera per operare nei menu; freccie su/giu per scorrere i punteggi\n");
        printf("\tUtilizzo: %s [opzioni]\n",nome);
        printf("Opzioni riga di comando:\n");
        printf("\t-s --start\t\t\tInzia subito il gioco (modalità normale)\n");
        printf("\t-d --double\t\t\tInzia subito il gioco (modalità crescita doppia)\n");
        printf("\t-r --russian\t\t\tInzia subito il gioco (modalità roulette russa)\n");
        printf("\t-e --exponential\t\tInzia subito il gioco (modalità crescita esponenziale)\n");
        printf("\t-v [num] --velocity [num]\tImposta la velocità di gioco (0-4)\n");
        printf("\t-p --paused\t\t\tInizia il gioco in pausa (solo con -s -d -e -r)\n");
        printf("\t-a --aperture\t\t\tAttiva i portali\n");
        printf("\t-S --simple-graphic\t\tUsa un set di simboli grafici più semplice e portabile\n");
        printf("\t-m [h] [w] --map [h] [w]\tImposta manualmente la dimensione dello schermo (WxH)\n");
        printf("\t-n [nome] --name [nome]\t\tImposta il nome del giocatore a [nome]. Default è env(USER)\n");
        printf("\t-c [mode] --computer [mode]\tAttiva il sottosistema AI. Mode può essere \"no\" oppure \"lazy\". Default è \"no\"\n");
        printf("\t-l [num] --leaderboard [num]\tScrive i primi [num] punteggi migliori, poi termina. Il file dei punteggi non viene alterato\n");
        printf("\t-h --help -?\t\t\tScrivi questo menu di aiuto e termina\n");
        printf("Sottosistema AI (Artificial Intelligence)\n");
        printf("\tlazy mode: il programma prende automaticamante il controllo in caso di urto imminente; ");
        printf("L' ia si limita a deviare il serpente nella direzione più conveniente.\n");
        printf("\nIndicatori partita (ultima colonna della tavola punteggi)\n");
        printf("\tStringa d'esempio:\tdpl2\n");
        printf("\ts / d / r / e\t\tIndica la modalità di gioco\n");
        printf("\tp\t\t\tIndica che i portali sono attivi\n");
        printf("\tl\t\t\tIndica che la AI è attiva in lazy mode\n");
        printf("\t0 / 1 / 2 / 3 / 4\t\tIndica la velocità di gioco\n");
        printf("\tk\t\t\tIndica che la partita è stata vinta (il serpente ha riempito il campo)\n");
        }
    else
        {
        printf("sn4ke! Snake-like game for the console.\n");
        printf("Controls:\twasd / arrow keys move snake around\n");
        printf("\t\tkeyboard operates menus; arrow keys up/down to scroll the scoreboard\n");
        printf("\tUsage: %s [options]\n",nome);
        printf("Command line options:\n");
        printf("\t-s --start\t\t\tStart the game immediately (normal mode)\n");
        printf("\t-d --double\t\t\tStart the game immediately (double growth mode)\n");
        printf("\t-r --russian\t\t\tStart the game immediately (russian roulette mode)\n");
        printf("\t-e --exponential\t\tStart the game immediately (exponential growth mode)\n");
        printf("\t-v [num] --velocity [num]\tSet snake's speed (0-4)\n");
        printf("\t-p --paused\t\t\tStart the game paused (only with -s -d -e -r)\n");
        printf("\t-a --aperture\t\t\tEnable portals\n");
        printf("\t-S --simple-graphic\t\tUses a more simple and portable set of graphic symbols\n");
        printf("\t-m [h] [w] --map [h] [w]\tManually override screen size (WxH)\n");
        printf("\t-n [name] --name [name]\t\tSet player's name as [name]. Default is env(USER)\n");
        printf("\t-c [mode] --computer [mode]\tEnable AI subsystem. Mode can be \"no\" or \"lazy\". Default is \"no\"\n");
        printf("\t-l [num] --leaderboard [num]\tPrints the first [num] top scores, then quits. The leaderboard file won't be modified\n");
        printf("\t-h --help -?\t\t\tPrint this help menu and quit\n");
        printf("AI subsystem (Artificial Intelligence)\n");
        printf("\tlazy mode: the program will automatically assume control in case of imminent crash; ");
        printf("AI action is limited to redirecting the snake in the most convenien direction.\n");
        printf("\nGame indicators (last column in the leaderboard)\n");
        printf("\tExample string:\tdpl2\n");
        printf("\ts / d / r / e\t\tIndicates game mode\n");
        printf("\tp\t\t\tIndicates portals are enabled \n");
        printf("\tl\t\t\tIndicates lazy mode AI is enabled\n");
        printf("\t0 / 1 / 2 / 3 / 4\t\tIndicates game speed\n");
        printf("\tk\t\t\tMarks a won game (snake filling the whole screen)\n");
        }
    exit(0);
}

variable_types:
nome
char *

variable_types:
lang
char [3]


printVersExit

decompiled_code:
void __fastcall __noreturn printVersExit(__int64 a1)
{
end_gioco(a1);
endNcurses();
puts("v 1.2 copyleft agentOfChaos informaniac99<AT>gmail<DOT>com");
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func16(__int64 a1)
{
end_gioco(a1);
endNcurses();
puts("v 1.2 copyleft agentOfChaos informaniac99<AT>gmail<DOT>com");
exit(0);
}

original_code:
void printVersExit(vars *varia)
{
    end_gioco(varia);
    endNcurses();
    printf("%s\n","v 1.2  copyleft  agentOfChaos  informaniac99<AT>gmail<DOT>com");
    exit(0);
}

canonical_original_code:
void printVersExit(struct vars *varia)
{
    end_gioco(varia);
    endNcurses();
    printf("%s\n","v 1.2  copyleft  agentOfChaos  informaniac99<AT>gmail<DOT>com");
    exit(0);
}

variable_types: struct vars { struct campo { struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } serpente; struct punto portale[2]; int numportals; int nextportime; struct punto *powerup; int numpowerups; int larg; int alt; struct punto *toblast; int blastlung; } gioco; struct leaderboard { struct punteggio { int score; char nome[10]; char flags[6]; } *entry; int numentry; int curr; } board; int score; int speed; int quit; int paused; int gameover; int gamemode; int colori; int safe_graph; int game_insane; char playername[10]; } *


decompiled_code:
__int64 __fastcall parse_cmdline(int a1, const char **a2, _DWORD *a3)
{
int v4; // ebp
__int64 v5; // rbx
const char **v6; // r12
const char *v7; // r13
const char *v8; // r13
const char *v9; // rdi
const char *v10; // r13
const char *v11; // r13
const char *v12; // rdi
unsigned int v13; // eax
const char *v14; // r12
const char *v15; // rdi
const char **v16; // r13
int v17; // eax
int v18; // edx
int v19; // eax
int v20; // edx
const char *v21; // rax
unsigned int v23; // [rsp+4h] [rbp-54h]
int v25; // [rsp+Ch] [rbp-4Ch]
int v26; // [rsp+10h] [rbp-48h]
int v27; // [rsp+14h] [rbp-44h]
char *s; // [rsp+18h] [rbp-40h]

if ( a1 > 1 )
{
v27 = 0;
v26 = 0;
v25 = 0;
v23 = 0;
v4 = 1;
s = (char *)(a3 + 41);
while ( 1 )
{
v5 = v4;
v6 = &a2[v5];
v7 = a2[v5];
if ( opt_help(v7) )
printHelpExit((__int64)a3, *a2);
if ( opt_safegraph(v7) )
a3[39] = 1;
if ( !v23 )
{
v8 = *v6;
if ( opt_normalmode(*v6) )
{
++a3[37];
v23 = 1;
goto LABEL_5;
}
if ( opt_doublemode(v8) )
{
a3[37] += 2;
v23 = 1;
goto LABEL_5;
}
if ( opt_russianmode(v8) )
{
a3[37] += 8;
v23 = 1;
goto LABEL_5;
}
if ( opt_expmode(v8) )
{
a3[37] += 4;
v23 = 1;
goto LABEL_5;
}
}
if ( !v25 && opt_speed(*v6) && (v9 = a2[v5 + 1]) != 0LL )
{
a3[33] = atoi(v9) % 5;
++v4;
v25 = 1;
}
else if ( !v26 && opt_portals(*v6) )
{
a3[37] += 16;
v26 = 1;
}
else if ( !v27 && opt_playername(*v6) && (v10 = a2[v5 + 1], strlen(v10) <= 9) )
{
snprintf(s, 0xAuLL, "%s", v10);
++v4;
v27 = 1;
}
else
{
v11 = *v6;
if ( opt_paused(*v6) )
{
a3[35] = 1;
}
else
{
if ( opt_leaderboard(v11) )
{
v12 = a2[v5 + 1];
if ( v12 )
{
v13 = atoi(v12);
printNexit(a3, v13);
}
else
{
printNexit(a3, 50LL);
}
}
v14 = *v6;
if ( !opt_resize(v14) )
{
if ( opt_ai(v14) )
{
v21 = a2[v5 + 1];
if ( v21 )
goto LABEL_40;
}
LABEL_49:
if ( opt_version(v14) )
printVersExit((__int64)a3);
goto LABEL_5;
}
v15 = a2[v5 + 1];
if ( !v15 )
goto LABEL_49;
v16 = &a2[v5 + 2];
if ( !*v16 )
{
if ( opt_ai(v14) )
{
v21 = a2[v5 + 1];
LABEL_40:
if ( !strcmp(v21, "no") )
{
a3[9] = 0;
}
else if ( !strcmp(v21, "lazy") )
{
a3[9] = 1;
}
++v4;
goto LABEL_5;
}
goto LABEL_49;
}
v17 = atoi(v15);
v18 = v17 >> 31;
a3[22] = v18 ^ v17;
a3[22] -= v18;
v19 = atoi(*v16);
v20 = v19 >> 31;
a3[21] = v20 ^ v19;
a3[21] -= v20;
v4 += 2;
}
}
LABEL_5:
if ( a1 <= ++v4 )
return v23;
}
}
return 0;
}

original_code:
int parse_cmdline(int argc, char *argv[],vars *varia)
{
    int skiptitle=0;
    int cont;
    int gameset=0;
    int speedset=0;
    int portalset=0;
    int nomeset=0;
    for (cont=1; cont<argc; cont++)
        {
        if (opt_help(argv[cont]))
            {
            printHelpExit(varia,argv[0]);
            }
        if (opt_safegraph(argv[cont]))
            {
            varia->safe_graph=1;
            }
        if (!gameset)
            {
            if (opt_normalmode(argv[cont]))
                {
                varia->gamemode+=0b01;
                gameset=1;
                continue;
                }
            else if (opt_doublemode(argv[cont]))
                {
                varia->gamemode+=0b10;
                gameset=1;
                continue;
                }
            else if (opt_russianmode(argv[cont]))
                {
                varia->gamemode+=0b1000;
                gameset=1;
                continue;
                }
            else if (opt_expmode(argv[cont]))
                {
                varia->gamemode+=0b100;
                gameset=1;
                continue;
                }
            }
        if (!speedset)
            {
            if (opt_speed(argv[cont]) && argv[cont+1]!=((void *)0))
                {
                varia->speed=atoi(argv[cont+1])%5;
                cont++;
                speedset=1;
                continue;
                }
            }
        if (!portalset)
            {
            if (opt_portals(argv[cont]))
                {
                varia->gamemode+=0b10000;
                portalset=1;
                continue;
                }
            }
        if (!nomeset)
            {
            if (opt_playername(argv[cont]) && (strlen(argv[cont+1])<10))
                {
                snprintf(varia->playername,10,"%s",argv[cont+1]);
                cont++;
                nomeset=1;
                continue;
                }
            }
        if (opt_paused(argv[cont]))
            {
            varia->paused=1;
            continue;
            }
        if (opt_leaderboard(argv[cont]))
            {
            if (argv[cont+1]==((void *)0)) printNexit(varia,50);
            else printNexit(varia,atoi(argv[cont+1]));
            }
        if (opt_resize(argv[cont]) && argv[cont+1]!=((void *)0) && argv[cont+2]!=((void *)0))
            {
            varia->gioco.alt=abs(atoi(argv[cont+1]));
            varia->gioco.larg=abs(atoi(argv[cont+2]));
            cont+=2;
            continue;
            }
        if (opt_ai(argv[cont]) && argv[cont+1]!=((void *)0))
            {
            if (strcmp(argv[cont+1],"no")==0) varia->gioco.serpente.ai=0b0;
            else if (strcmp(argv[cont+1],"lazy")==0) varia->gioco.serpente.ai=0b1;
            cont++;
            continue;
            }
        if (opt_version(argv[cont]))
            {
            printVersExit(varia);
            }
        }
    return gameset;
}

canonical_original_code:
int parse_cmdline(int argc, char *argv[], struct vars *varia)
{
    int skiptitle = 0;
    int cont;
    int gameset = 0;
    int speedset = 0;
    int portalset = 0;
    int nomeset = 0;
    for (cont=1; cont<argc; cont++)
        {
        if (opt_help(argv[cont]))
            {
            printHelpExit(varia,argv[0]);
            }
        if (opt_safegraph(argv[cont]))
            {
            varia->safe_graph=1;
            }
        if (!gameset)
            {
            if (opt_normalmode(argv[cont]))
                {
                varia->gamemode+=0b01;
                gameset=1;
                continue;
                }
            else if (opt_doublemode(argv[cont]))
                {
                varia->gamemode+=0b10;
                gameset=1;
                continue;
                }
            else if (opt_russianmode(argv[cont]))
                {
                varia->gamemode+=0b1000;
                gameset=1;
                continue;
                }
            else if (opt_expmode(argv[cont]))
                {
                varia->gamemode+=0b100;
                gameset=1;
                continue;
                }
            }
        if (!speedset)
            {
            if (opt_speed(argv[cont]) && argv[cont+1]!=((void *)0))
                {
                varia->speed=atoi(argv[cont+1])%5;
                cont++;
                speedset=1;
                continue;
                }
            }
        if (!portalset)
            {
            if (opt_portals(argv[cont]))
                {
                varia->gamemode+=0b10000;
                portalset=1;
                continue;
                }
            }
        if (!nomeset)
            {
            if (opt_playername(argv[cont]) && (strlen(argv[cont+1])<10))
                {
                snprintf(varia->playername,10,"%s",argv[cont+1]);
                cont++;
                nomeset=1;
                continue;
                }
            }
        if (opt_paused(argv[cont]))
            {
            varia->paused=1;
            continue;
            }
        if (opt_leaderboard(argv[cont]))
            {
            if (argv[cont+1]==((void *)0)) printNexit(varia,50);
            else printNexit(varia,atoi(argv[cont+1]));
            }
        if (opt_resize(argv[cont]) && argv[cont+1]!=((void *)0) && argv[cont+2]!=((void *)0))
            {
            varia->gioco.alt=abs(atoi(argv[cont+1]));
            varia->gioco.larg=abs(atoi(argv[cont+2]));
            cont+=2;
            continue;
            }
        if (opt_ai(argv[cont]) && argv[cont+1]!=((void *)0))
            {
            if (strcmp(argv[cont+1],"no")==0) varia->gioco.serpente.ai=0b0;
            else if (strcmp(argv[cont+1],"lazy")==0) varia->gioco.serpente.ai=0b1;
            cont++;
            continue;
            }
        if (opt_version(argv[cont]))
            {
            printVersExit(varia);
            }
        }
    return gameset;
}

variable_types: skiptitle int

variable_types: gameset int

variable_types: speedset int

variable_types: portalset int

variable_types: nomeset int


turnleft

decompiled_code:
__int64 __fastcall turnleft(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result == 2 )
{
*a1 = 1;
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
*a1 = 2;
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
*a1 = 0;
}
else
{
*a1 = 3;
}
return result;
}

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

result = (unsigned int)*a1;
if ( (_DWORD)result == 2 )
{
*a1 = 1;
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
*a1 = 2;
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
*a1 = 0;
}
else
{
*a1 = 3;
}
return result;
}

original_code:
void turnleft(int *direz)
{
    switch (*direz)
        {
        case 0: (*direz)=3; break;
        case 1: (*direz)=0; break;
        case 2: (*direz)=1; break;
        case 3: (*direz)=2; break;
        }
}

variable_types:
direz
int *


turnright

decompiled_code:
__int64 __fastcall turnright(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result == 2 )
{
*a1 = 3;
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
*a1 = 0;
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
*a1 = 2;
}
else
{
*a1 = 1;
}
return result;
}

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

result = (unsigned int)*a1;
if ( (_DWORD)result == 2 )
{
*a1 = 3;
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
*a1 = 0;
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
*a1 = 2;
}
else
{
*a1 = 1;
}
return result;
}

original_code:
void turnright(int *direz)
{
    switch (*direz)
        {
        case 0: (*direz)=1; break;
        case 1: (*direz)=2; break;
        case 2: (*direz)=3; break;
        case 3: (*direz)=0; break;
        }
}


clearmatrix

decompiled_code:
void __fastcall clearmatrix(_BYTE *a1, int a2)
{
_BYTE *v2; // rax

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = 0;
while ( v2 != &a1[a2 - 1 + 1] );
}
}

original_code:
void clearmatrix(char *matrix, int size)
{
    int cont;
    for (cont=0; cont<size; cont++)matrix[cont]=0;
}

variable_types:
matrix
char *

variable_types: size int

variable_types: cont int


decompiled_code:
int __fastcall colora_dbg(int a1, int a2, char a3)
{
move(a2 + 1, 2 * a1 + 1);
printw("%c%c", (unsigned int)a3, (unsigned int)a3);
refresh();
return usleep(0x2710u);
}

canonical_decompiled_code:
int __fastcall func4(int a1, int a2, char a3)
{
move(a2 + 1, 2 * a1 + 1);
printw("%c%c", (unsigned int)a3, (unsigned int)a3);
refresh();
return usleep(0x2710u);
}

original_code:
void colora_dbg(int x,int y,char car)
{
    move(y+1,(x*2)+1);
    printw("%c%c",car,car);
    refresh();
    usleep(1000*10);
}

canonical_original_code:
void colora_dbg(int x, int y, char car)
{
    move(y+1,(x*2)+1);
    printw("%c%c",car,car);
    refresh();
    usleep(1000*10);
}

variable_types: x int

variable_types: y int

variable_types: car char


original_code:
void ailog_matrix(char *campo, int alt, int larg)
{
    int x,y;
    for (y=0; y<alt; y++)
        {
        for (x=0; x<larg; x++)
            {
            if (campo[(((y)*(larg))+(x))])ailog("X");
            else ailog("_");
            }
        ailog("\n");
        }
    ailog("\n");
}

canonical_original_code:
void ailog_matrix(char *campo, int alt, int larg)
{
    int x; int y;
    for (y=0; y<alt; y++)
        {
        for (x=0; x<larg; x++)
            {
            if (campo[(((y)*(larg))+(x))])ailog("X");
            else ailog("_");
            }
        ailog("\n");
        }
    ailog("\n");
}

variable_types:
campo
char *

variable_types: alt int

variable_types: larg int


contalibere

decompiled_code:
__int64 __fastcall contalibere(int a1, int a2, __int64 a3, unsigned int a4, unsigned int a5, __int64 a6)
{
unsigned int v10; // ebx

*(_BYTE *)(a3 + (int)(a1 + a4 * a2)) = 1;
v10 = 1;
while ( (unsigned int)addcella(a6, a3, a4, a5) )
++v10;
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2, __int64 a3, unsigned int a4, unsigned int a5, __int64 a6)
{
unsigned int v10; // ebx

*(_BYTE *)(a3 + (int)(a1 + a4 * a2)) = 1;
v10 = 1;
while ( (unsigned int)addcella(a6, a3, a4, a5) )
++v10;
return v10;
}

original_code:
int contalibere(int sx, int sy, char *campo, int larg, int alt,vars *varia)
{
    int numlibere=0;
    int fatta=1;
    int ret;
    campo[(((sy)*(larg))+(sx))]=1;
    numlibere++;
    while (fatta)
        {
        ret=addcella(varia,campo,larg,alt);
        if (ret) numlibere++;
        else fatta=0;
        }
    return numlibere;
}

canonical_original_code:
int contalibere(int sx, int sy, char *campo, int larg, int alt, struct vars *varia)
{
    int numlibere = 0;
    int fatta = 1;
    int ret;
    campo[(((sy)*(larg))+(sx))]=1;
    numlibere++;
    while (fatta)
        {
        ret=addcella(varia,campo,larg,alt);
        if (ret) numlibere++;
        else fatta=0;
        }
    return numlibere;
}

variable_types: sx int

variable_types: sy int

variable_types: numlibere int

variable_types: fatta int

variable_types: ret int


findway

original_code:
int findway(int ex, int ey, int dir1, int dir2, vars *varia)
{
    int sin=0,des=0;
    char *matrix;
    int sx=ex,sy=ey,dx=ex,dy=ey;
    calc_direz(dir1,&sx,&sy);
    calc_direz(dir2,&dx,&dy);
    matrix=(char*)malloc(sizeof(char)*varia->gioco.larg*varia->gioco.alt);
    if (matrix==((void *)0))return -1;
    clearmatrix(matrix,varia->gioco.larg*varia->gioco.alt);
    sin=contalibere(sx,sy,matrix,varia->gioco.larg,varia->gioco.alt,varia);
    clearmatrix(matrix,varia->gioco.larg*varia->gioco.alt);
    des=contalibere(dx,dy,matrix,varia->gioco.larg,varia->gioco.alt,varia);
    free(matrix);
    return (des>sin);
}

canonical_original_code:
int findway(int ex, int ey, int dir1, int dir2, struct vars *varia)
{
    int sin = 0; int des = 0;
    char *matrix;
    int sx = ex; int sy = ey; int dx = ex; int dy = ey;
    calc_direz(dir1,&sx,&sy);
    calc_direz(dir2,&dx,&dy);
    matrix=(char *)malloc(sizeof(char)*varia->gioco.larg*varia->gioco.alt);
    if (matrix==((void *)0))return -1;
    clearmatrix(matrix,varia->gioco.larg*varia->gioco.alt);
    sin=contalibere(sx,sy,matrix,varia->gioco.larg,varia->gioco.alt,varia);
    clearmatrix(matrix,varia->gioco.larg*varia->gioco.alt);
    des=contalibere(dx,dy,matrix,varia->gioco.larg,varia->gioco.alt,varia);
    free(matrix);
    return (des>sin);
}

variable_types: ex int

variable_types: ey int

variable_types: struct vars { struct campo { struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } serpente; struct punto portale[2]; int numportals; int nextportime; struct punto *powerup; int numpowerups; int larg; int alt; struct punto *toblast; int blastlung; } gioco; struct leaderboard { struct punteggio { int score; char nome[10]; char flags[6]; } *entry; int numentry; int curr; } board; int score; int speed; int quit; int paused; int gameover; int gamemode; int colori; int safe_graph; int game_insane; char playername[10]; } *

variable_types: sin int

variable_types: des int

variable_types: dx int

variable_types: dy int


rotelle

decompiled_code:
__int64 __fastcall rotelle(__int64 a1, int *a2, int *a3, unsigned int a4)
{
__int64 result; // rax
int v7; // edx
int v8; // edx
unsigned int v9; // [rsp+8h] [rbp-40h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v11; // [rsp+10h] [rbp-38h] BYREF
unsigned int v12; // [rsp+14h] [rbp-34h] BYREF
unsigned int v13; // [rsp+18h] [rbp-30h] BYREF
unsigned int v14[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v14[0] = *a2;
v13 = *a3;
calc_direz(a4, v14, &v13);
if ( (unsigned int)morsocoda(a1, v14[0], v13) || (result = presomuro(a1, v14[0], v13), (_DWORD)result) )
{
v10 = *a2;
v9 = *a3;
v12 = a4;
turnright(&v12);
calc_direz(v12, &v10, &v9);
if ( (unsigned int)morsocoda(a1, v10, v9) || (unsigned int)presomuro(a1, v10, v9) )
{
v10 = *a2;
v9 = *a3;
v12 = a4;
turnleft(&v12);
calc_direz(v12, &v10, &v9);
v7 = morsocoda(a1, v10, v9);
result = 1LL;
if ( !v7 )
{
v8 = presomuro(a1, v10, v9);
result = 1LL;
if ( !v8 )
{
calc_direz(v12, a2, a3);
*(_DWORD *)(a1 + 12) = v12;
result = 1LL;
}
}
}
else
{
v10 = *a2;
v9 = *a3;
v12 = a4;
turnleft(&v12);
calc_direz(v12, &v10, &v9);
if ( (unsigned int)morsocoda(a1, v10, v9) || (unsigned int)presomuro(a1, v10, v9) )
{
v11 = a4;
turnright(&v11);
calc_direz(v11, a2, a3);
*(_DWORD *)(a1 + 12) = v11;
result = 1LL;
}
else
{
v11 = a4;
turnright(&v11);
if ( (unsigned int)findway(*a2, *a3, v12, v11, a1) )
{
calc_direz(v11, a2, a3);
*(_DWORD *)(a1 + 12) = v11;
}
else
{
calc_direz(v12, a2, a3);
*(_DWORD *)(a1 + 12) = v12;
}
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int *a2, int *a3, unsigned int a4)
{
__int64 result; // rax
int v7; // edx
int v8; // edx
unsigned int v9; // [rsp+8h] [rbp-40h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v11; // [rsp+10h] [rbp-38h] BYREF
unsigned int v12; // [rsp+14h] [rbp-34h] BYREF
unsigned int v13; // [rsp+18h] [rbp-30h] BYREF
unsigned int v14[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v14[0] = *a2;
v13 = *a3;
calc_direz(a4, v14, &v13);
if ( (unsigned int)morsocoda(a1, v14[0], v13) || (result = presomuro(a1, v14[0], v13), (_DWORD)result) )
{
v10 = *a2;
v9 = *a3;
v12 = a4;
func2(&v12);
calc_direz(v12, &v10, &v9);
if ( (unsigned int)morsocoda(a1, v10, v9) || (unsigned int)presomuro(a1, v10, v9) )
{
v10 = *a2;
v9 = *a3;
v12 = a4;
func1(&v12);
calc_direz(v12, &v10, &v9);
v7 = morsocoda(a1, v10, v9);
result = 1LL;
if ( !v7 )
{
v8 = presomuro(a1, v10, v9);
result = 1LL;
if ( !v8 )
{
calc_direz(v12, a2, a3);
*(_DWORD *)(a1 + 12) = v12;
result = 1LL;
}
}
}
else
{
v10 = *a2;
v9 = *a3;
v12 = a4;
func1(&v12);
calc_direz(v12, &v10, &v9);
if ( (unsigned int)morsocoda(a1, v10, v9) || (unsigned int)presomuro(a1, v10, v9) )
{
v11 = a4;
func2(&v11);
calc_direz(v11, a2, a3);
*(_DWORD *)(a1 + 12) = v11;
result = 1LL;
}
else
{
v11 = a4;
func2(&v11);
if ( (unsigned int)func7(*a2, *a3, v12, v11, a1) )
{
calc_direz(v11, a2, a3);
*(_DWORD *)(a1 + 12) = v11;
}
else
{
calc_direz(v12, a2, a3);
*(_DWORD *)(a1 + 12) = v12;
}
result = 1LL;
}
}
}
return result;
}

original_code:
int rotelle(vars *varia, int *px, int *py, int direz)
{
    int newposx=(*px);
    int newposy=(*py);
    snake *serp=&(varia->gioco.serpente);
    int turndir,turndir2,turnposx,turnposy,way;
    calc_direz(direz,&newposx,&newposy);
    if (morsocoda(varia,newposx,newposy) || presomuro(varia,newposx,newposy))
        {
        turnposx=*px;
        turnposy=*py;
        turndir=direz;
        turnright(&turndir);
        calc_direz(turndir,&turnposx,&turnposy);
        if (morsocoda(varia,turnposx,turnposy) || presomuro(varia,turnposx,turnposy))
            {
            turnposx=*px;
            turnposy=*py;
            turndir=direz;
            turnleft(&turndir);
            calc_direz(turndir,&turnposx,&turnposy);
            if (morsocoda(varia,turnposx,turnposy) || presomuro(varia,turnposx,turnposy))
                {
                }
            else
                {
                calc_direz(turndir,px,py);
                serp->direz=turndir;
                }
            }
        else
            {
            turnposx=*px;
            turnposy=*py;
            turndir=direz;
            turnleft(&turndir);
            calc_direz(turndir,&turnposx,&turnposy);
            if (morsocoda(varia,turnposx,turnposy) || presomuro(varia,turnposx,turnposy))
                {
                turndir2=direz;
                turnright(&turndir2);
                calc_direz(turndir2,px,py);
                serp->direz=turndir2;
                }
            else
                {
                turndir2=direz;
                turnright(&turndir2);
                way=findway(*px,*py,turndir,turndir2,varia);
                if (way)
                    {
                    calc_direz(turndir2,px,py);
                    serp->direz=turndir2;
                    }
                else
                    {
                    calc_direz(turndir,px,py);
                    serp->direz=turndir;
                    }
                }
            }
        return 1;
        }
    return 0;
}

canonical_original_code:
int rotelle(struct vars *varia, int *px, int *py, int direz)
{
    int newposx = (*px);
    int newposy = (*py);
    struct snake *serp = &(varia->gioco.serpente);
    int turndir; int turndir2; int turnposx; int turnposy; int way;
    calc_direz(direz,&newposx,&newposy);
    if (morsocoda(varia,newposx,newposy) || presomuro(varia,newposx,newposy))
        {
        turnposx=*px;
        turnposy=*py;
        turndir=direz;
        turnright(&turndir);
        calc_direz(turndir,&turnposx,&turnposy);
        if (morsocoda(varia,turnposx,turnposy) || presomuro(varia,turnposx,turnposy))
            {
            turnposx=*px;
            turnposy=*py;
            turndir=direz;
            turnleft(&turndir);
            calc_direz(turndir,&turnposx,&turnposy);
            if (morsocoda(varia,turnposx,turnposy) || presomuro(varia,turnposx,turnposy))
                {
                }
            else
                {
                calc_direz(turndir,px,py);
                serp->direz=turndir;
                }
            }
        else
            {
            turnposx=*px;
            turnposy=*py;
            turndir=direz;
            turnleft(&turndir);
            calc_direz(turndir,&turnposx,&turnposy);
            if (morsocoda(varia,turnposx,turnposy) || presomuro(varia,turnposx,turnposy))
                {
                turndir2=direz;
                turnright(&turndir2);
                calc_direz(turndir2,px,py);
                serp->direz=turndir2;
                }
            else
                {
                turndir2=direz;
                turnright(&turndir2);
                way=findway(*px,*py,turndir,turndir2,varia);
                if (way)
                    {
                    calc_direz(turndir2,px,py);
                    serp->direz=turndir2;
                    }
                else
                    {
                    calc_direz(turndir,px,py);
                    serp->direz=turndir;
                    }
                }
            }
        return 1;
        }
    return 0;
}

variable_types:
px
int *

variable_types:
py
int *

variable_types: direz int

variable_types: newposx int

variable_types: newposy int

variable_types: struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } *

variable_types: turndir int

variable_types: turnposx int

variable_types: turnposy int

variable_types: way int


decompiled_code:
int __fastcall game_step(__int64 a1, _DWORD *a2, int *a3, _DWORD *a4, __int64 a5)
{
int result; // eax

result = comandi();
if ( !*(_DWORD *)(a1 + 136) )
{
if ( *a2 >= speed_setting[*(int *)(a1 + 132)] )
{
fisica_serp(a1);
checkwin(a1);
*a2 = 0;
}
if ( *a3 > 249 )
{
*(_DWORD *)(a1 + 20) = *(_DWORD *)(a1 + 20) == 0;
*a3 = 0;
}
if ( *a4 >= 1000 * *(_DWORD *)(a1 + 68) )
{
if ( (*(_BYTE *)(a1 + 148) & 0x10) != 0 )
{
timerPortal(a1);
drop_portal(a1);
}
*a4 = 0;
}
droppup(a1);
grafica(a1, 1LL);
blastanim(a1, a5);
wrefresh(stdscr);
*a2 += 10;
*a3 += 10;
*a4 += 10;
result = usleep(0x2710u);
}
return result;
}

original_code:
void game_step(vars *varia, int *itimer, int *atimer, int *ptimer, int *blaster)
{
    int speed;
    comandi(varia);
    if (!varia->quit)
        {
        speed=speed_setting[varia->speed];
        if ((*itimer) >= speed)
            {
            fisica_serp(varia);
            checkwin(varia);
            (*itimer)=0;
            }
        if ((*atimer) >=250)
            {
            if (varia->gioco.serpente.ciclo_anim==0)varia->gioco.serpente.ciclo_anim=1;
            else varia->gioco.serpente.ciclo_anim=0;
            (*atimer)=0;
            }
        if ((*ptimer) >= (varia->gioco.nextportime*1000))
            {
            if ((varia->gamemode&0b10000)!=0)
                {
                timerPortal(varia);
                drop_portal(varia);
                }
            (*ptimer)=0;
            }
        droppup(varia);
        grafica(varia,1);
        blastanim(varia,blaster);
        wrefresh(stdscr);
        (*itimer)+=10;
        (*atimer)+=10;
        (*ptimer)+=10;
        usleep(1000*10);
        }
}

canonical_original_code:
void game_step(struct vars *varia, int *itimer, int *atimer, int *ptimer, int *blaster)
{
    int speed;
    comandi(varia);
    if (!varia->quit)
        {
        speed=speed_setting[varia->speed];
        if ((*itimer) >= speed)
            {
            fisica_serp(varia);
            checkwin(varia);
            (*itimer)=0;
            }
        if ((*atimer) >=250)
            {
            if (varia->gioco.serpente.ciclo_anim==0)varia->gioco.serpente.ciclo_anim=1;
            else varia->gioco.serpente.ciclo_anim=0;
            (*atimer)=0;
            }
        if ((*ptimer) >= (varia->gioco.nextportime*1000))
            {
            if ((varia->gamemode&0b10000)!=0)
                {
                timerPortal(varia);
                drop_portal(varia);
                }
            (*ptimer)=0;
            }
        droppup(varia);
        grafica(varia,1);
        blastanim(varia,blaster);
        wrefresh(stdscr);
        (*itimer)+=10;
        (*atimer)+=10;
        (*ptimer)+=10;
        usleep(1000*10);
        }
}

variable_types:
itimer
int *

variable_types:
atimer
int *

variable_types:
ptimer
int *

variable_types:
blaster
int *

variable_types: speed int


decompiled_code:
int __fastcall game_pause_step(__int64 a1, int *a2, int a3)
{
int v4; // eax

if ( a3 && *a2 <= 399 )
grafica(a1, 0LL);
else
grafica(a1, 1LL);
overlay_scritta(a1);
if ( *(_DWORD *)(a1 + 144) )
{
wmove(stdscr, 1, 1);
v4 = *(_DWORD *)(a1 + 144);
switch ( v4 )
{
case -1:
printw("Ti sei morso la coda! ");
break;
case -2:
printw("Ti sei schiantato! ");
break;
case 2:
printw("Hai vinto la partita! ");
break;
default:
printw("Fine della partita! ");
break;
}
printw("| q per chiudere | r per ricominciare");
if ( (*(_BYTE *)(a1 + 160) & 1) != 0 )
{
wmove(stdscr, 2, 1);
printw("File salvataggi corrotto! Recupero backup..");
}
if ( (*(_BYTE *)(a1 + 160) & 2) != 0 )
printw(" assente / corrotto. D'oh!");
scrivi_punteggi((unsigned int)(*(_DWORD *)(a1 + 88) / 2 + 1), (unsigned int)(*(_DWORD *)(a1 + 84) - 13), 8LL, a1);
}
if ( *a2 > 799 )
*a2 = 0;
wrefresh(stdscr);
comandi_pausa(a1);
*a2 += 10;
return usleep(0x2710u);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int *a2, int a3)
{
int v4; // eax

if ( a3 && *a2 <= 399 )
grafica(a1, 0LL);
else
grafica(a1, 1LL);
overlay_scritta(a1);
if ( *(_DWORD *)(a1 + 144) )
{
wmove(stdscr, 1, 1);
v4 = *(_DWORD *)(a1 + 144);
switch ( v4 )
{
case -1:
printw("Ti sei morso la coda! ");
break;
case -2:
printw("Ti sei schiantato! ");
break;
case 2:
printw("Hai vinto la partita! ");
break;
default:
printw("Fine della partita! ");
break;
}
printw("| q per chiudere | r per ricominciare");
if ( (*(_BYTE *)(a1 + 160) & 1) != 0 )
{
wmove(stdscr, 2, 1);
printw("File salvataggi corrotto! Recupero backup..");
}
if ( (*(_BYTE *)(a1 + 160) & 2) != 0 )
printw(" assente / corrotto. D'oh!");
scrivi_punteggi((unsigned int)(*(_DWORD *)(a1 + 88) / 2 + 1), (unsigned int)(*(_DWORD *)(a1 + 84) - 13), 8LL, a1);
}
if ( *a2 > 799 )
*a2 = 0;
wrefresh(stdscr);
comandi_pausa(a1);
*a2 += 10;
return usleep(0x2710u);
}

original_code:
void game_pause_step(vars *varia, int *btimer,int blink)
{
    int tblink=800;
    if (blink)
        {
        if ((*btimer)<tblink/2) grafica(varia,0);
        else if ((*btimer)>=tblink/2) grafica(varia,1);
        }
    else grafica(varia,1);
    overlay_scritta(varia);
    if (varia->gameover!=0)
        {
        wmove(stdscr,(1),(1));
        if (varia->gameover==-1)printw("Ti sei morso la coda! ");
        else if (varia->gameover==-2)printw("Ti sei schiantato! ");
        else if (varia->gameover==2)printw("Hai vinto la partita! ");
        else printw("Fine della partita! ");
        printw("| q per chiudere | r per ricominciare");
        if (varia->game_insane&0b1)
            {
            wmove(stdscr,(2),(1));
            printw("File salvataggi corrotto! Recupero backup..");
            }
        if (varia->game_insane&0b10)
            {
            printw(" assente / corrotto. D'oh!");
            }
        scrivi_punteggi((varia->gioco.alt/2)+4-3,(((varia->gioco.larg*2)+2)/2)-14,8,varia);
        }
    if ((*btimer)>=tblink)(*btimer)=0;
    wrefresh(stdscr);
    comandi_pausa(varia);
    (*btimer)+=10;
    usleep(1000*10);
}

canonical_original_code:
void game_pause_step(struct vars *varia, int *btimer, int blink)
{
    int tblink = 800;
    if (blink)
        {
        if ((*btimer)<tblink/2) grafica(varia,0);
        else if ((*btimer)>=tblink/2) grafica(varia,1);
        }
    else grafica(varia,1);
    overlay_scritta(varia);
    if (varia->gameover!=0)
        {
        wmove(stdscr,(1),(1));
        if (varia->gameover==-1)printw("Ti sei morso la coda! ");
        else if (varia->gameover==-2)printw("Ti sei schiantato! ");
        else if (varia->gameover==2)printw("Hai vinto la partita! ");
        else printw("Fine della partita! ");
        printw("| q per chiudere | r per ricominciare");
        if (varia->game_insane&0b1)
            {
            wmove(stdscr,(2),(1));
            printw("File salvataggi corrotto! Recupero backup..");
            }
        if (varia->game_insane&0b10)
            {
            printw(" assente / corrotto. D'oh!");
            }
        scrivi_punteggi((varia->gioco.alt/2)+4-3,(((varia->gioco.larg*2)+2)/2)-14,8,varia);
        }
    if ((*btimer)>=tblink)(*btimer)=0;
    wrefresh(stdscr);
    comandi_pausa(varia);
    (*btimer)+=10;
    usleep(1000*10);
}

variable_types: struct vars { struct campo { struct snake { struct punto { int x; int y; } *sezioni; int numsezioni; int direz; int scheduledir; int ciclo_anim; int ate; int keepexp; int portalcross; int ai; char **cache; } serpente; struct punto portale[2]; int numportals; int nextportime; struct punto *powerup; int numpowerups; int larg; int alt; struct punto *toblast; int blastlung; } gioco; struct leaderboard { struct punteggio { int score; char nome[10]; char flags[6]; } *entry; int numentry; int curr; } board; int score; int speed; int quit; int paused; int gameover; int gamemode; int colori; int safe_graph; int game_insane; char playername[10]; } *

variable_types:
btimer
int *

variable_types: blink int

variable_types: tblink int


decompiled_code:
__int64 __fastcall game_pause_loop(__int64 a1, int a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 0;
do
{
if ( !*(_DWORD *)(a1 + 140) )
break;
game_pause_step(a1, v3, a2);
}
while ( !*(_DWORD *)(a1 + 136) );
if ( *(_DWORD *)(a1 + 144) )
free(*(void **)(a1 + 112));
return delete_scritta(a1);
}

original_code:
void game_pause_loop(vars *varia, int blink)
{
    int btimer=0;
    while (varia->paused)
        {
        game_pause_step(varia,&btimer,blink);
        if (varia->quit) break;
        }
    if (varia->gameover!=0)
        {
        free(varia->board.entry);
        }
    delete_scritta(varia);
}

canonical_original_code:
void game_pause_loop(struct vars *varia, int blink)
{
    int btimer = 0;
    while (varia->paused)
        {
        game_pause_step(varia,&btimer,blink);
        if (varia->quit) break;
        }
    if (varia->gameover!=0)
        {
        free(varia->board.entry);
        }
    delete_scritta(varia);
}

variable_types: btimer int


decompiled_code:
int __fastcall game_loop(_DWORD *a1)
{
int result; // eax
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v4 = 0;
v3 = 0;
v2 = 0;
while ( !a1[34] )
{
result = game_step((__int64)a1, v5, &v4, &v3, (__int64)&v2);
if ( a1[35] )
result = game_pause_loop((__int64)a1, a1[36] >> 31);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(_DWORD *a1)
{
int result; // eax
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v4 = 0;
v3 = 0;
v2 = 0;
while ( !a1[34] )
{
result = func0((__int64)a1, v5, &v4, &v3, (__int64)&v2);
if ( a1[35] )
result = func2((__int64)a1, a1[36] >> 31);
}
return result;
}

original_code:
void game_loop(vars *varia)
{
    int itimer=0;
    int atimer=0;
    int ptimer=0;
    int blaster=0;
    while (!varia->quit)
        {
        game_step(varia,&itimer,&atimer,&ptimer,&blaster);
        if (varia->paused)game_pause_loop(varia,(varia->gameover<0 ? 1 : 0));
        }
}

canonical_original_code:
void game_loop(struct vars *varia)
{
    int itimer = 0;
    int atimer = 0;
    int ptimer = 0;
    int blaster = 0;
    while (!varia->quit)
        {
        game_step(varia,&itimer,&atimer,&ptimer,&blaster);
        if (varia->paused)game_pause_loop(varia,(varia->gameover<0 ? 1 : 0));
        }
}

variable_types: itimer int

variable_types: atimer int

variable_types: ptimer int

variable_types: blaster int


decompiled_code:
int __fastcall game_title_step(__int64 a1)
{
comandi_titolo();
wmove(stdscr, 0, 0);
printw("v 1.2 copyleft agentOfChaos informaniac99<AT>gmail<DOT>com");
overlay_scritta(a1);
titlescreen_leftpanel(a1);
titlescreen_rightpanel(a1);
wrefresh(stdscr);
return usleep(0x2710u);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
comandi_titolo();
wmove(stdscr, 0, 0);
printw("v 1.2 copyleft agentOfChaos informaniac99<AT>gmail<DOT>com");
overlay_scritta(a1);
titlescreen_leftpanel(a1);
titlescreen_rightpanel(a1);
wrefresh(stdscr);
return usleep(0x2710u);
}

original_code:
void game_title_step(vars *varia)
{
    comandi_titolo(varia);
    wmove(stdscr,(0),(0));
    printw("v 1.2  copyleft  agentOfChaos  informaniac99<AT>gmail<DOT>com");
    overlay_scritta(varia);
    titlescreen_leftpanel(varia);
    titlescreen_rightpanel(varia);
    wrefresh(stdscr);
    usleep(1000*10);
}

canonical_original_code:
void game_title_step(struct vars *varia)
{
    comandi_titolo(varia);
    wmove(stdscr,(0),(0));
    printw("v 1.2  copyleft  agentOfChaos  informaniac99<AT>gmail<DOT>com");
    overlay_scritta(varia);
    titlescreen_leftpanel(varia);
    titlescreen_rightpanel(varia);
    wrefresh(stdscr);
    usleep(1000*10);
}


decompiled_code:
int __fastcall title_loop(__int64 a1)
{
int result; // eax

do
{
if ( !*(_DWORD *)(a1 + 140) )
break;
result = game_title_step(a1);
}
while ( !*(_DWORD *)(a1 + 136) );
return result;
}

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

do
{
if ( !*(_DWORD *)(a1 + 140) )
break;
result = func4(a1);
}
while ( !*(_DWORD *)(a1 + 136) );
return result;
}

original_code:
void title_loop(vars *varia)
{
    while (varia->paused)
        {
        game_title_step(varia);
        if (varia->quit) break;
        }
}

canonical_original_code:
void title_loop(struct vars *varia)
{
    while (varia->paused)
        {
        game_title_step(varia);
        if (varia->quit) break;
        }
}


comparaz

decompiled_code:
_BOOL8 __fastcall comparaz(const void *a1, const void *a2)
{
return *(_DWORD *)a1 < *(_DWORD *)a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const void *a1, const void *a2)
{
return *(_DWORD *)a1 < *(_DWORD *)a2;
}

original_code:
int comparaz(const void *a, const void *b)
{
    punteggio *uno=(punteggio *) a;
    punteggio *due=(punteggio *) b;
    return (uno->score<due->score);
}

canonical_original_code:
int comparaz(void *a, void *b)
{
    struct punteggio *uno = (punteggio *) a;
    struct punteggio *due = (punteggio *) b;
    return (uno->score<due->score);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct punteggio { int score; char nome[10]; char flags[6]; } *


trimN

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

result = &a1[(int)strlen(a1) - 1];
if ( *result == 10 )
*result = 0;
return result;
}

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

result = &a1[(int)strlen(a1) - 1];
if ( *result == 10 )
*result = 0;
return result;
}

original_code:
void trimN(char *riga)
{
    int lung=strlen(riga);
    if (riga[lung-1]=='\n')
        riga[lung-1]='\0';
}

canonical_original_code:
void trimN(char *riga)
{
    int lung = strlen(riga);
    if (riga[lung-1]=='\n')
        riga[lung-1]='\0';
}

variable_types:
riga
char *

variable_types: lung int


original_code:
int parse_saveline(leaderboard *board, char *line)
{
    int val;
    board->entry[board->numentry].nome[0]='\0';
    val=sscanf(line,"%s%d%s",&(board->entry[board->numentry].nome),&(board->entry[board->numentry].score),&(board->entry[board->numentry].flags));
    board->numentry++;
    return (val==3);
}

canonical_original_code:
int parse_saveline(struct leaderboard *board, char *line)
{
    int val;
    board->entry[board->numentry].nome[0]='\0';
    val=sscanf(line,"%s%d%s",&(board->entry[board->numentry].nome),&(board->entry[board->numentry].score),&(board->entry[board->numentry].flags));
    board->numentry++;
    return (val==3);
}

variable_types: struct leaderboard { struct punteggio { int score; char nome[10]; char flags[6]; } *entry; int numentry; int curr; } *

variable_types:
line
char *

variable_types: val int