main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // eax
__int64 v5; // rax
__int64 v6; // rsi
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v10; // r12
void *v11; // rax
char v12; // [rsp+13h] [rbp-2Dh] BYREF
__pid_t pid; // [rsp+14h] [rbp-2Ch] BYREF
int v14; // [rsp+18h] [rbp-28h] BYREF
int v15; // [rsp+1Ch] [rbp-24h] BYREF
int v16; // [rsp+20h] [rbp-20h] BYREF
int v17[7]; // [rsp+24h] [rbp-1Ch] BYREF

v15 = 0;
v16 = 0;
parse_cmdline(argc, argv, &v14, &v15, &pid, &v16, v17);
v4 = getpid();
v5 = libc_posiz(v4);
if ( v16 )
{
v10 = v5;
v11 = self_discover();
printf("%lx +4 - %lx = ", v11, v10);
v6 = (__int64)self_discover() - v10 + 4;
offset = v6;
}
else
{
offset = 233044LL;
v6 = 233044LL;
}
printf("Function offset: %lx\n", v6);
if ( v15 )
{
if ( (unsigned int)spawn(argv[2], &pid) == -1 )
{
puts("Cannot spawn the process.");
exit(-3);
}
printf("Spawned process with pid=%d\n", (unsigned int)pid);
}
if ( !(unsigned int)controlla_pid((unsigned int)pid) )
{
puts("unexistent process.");
exit(-4);
}
v7 = libc_posiz(pid);
printf("Process' base (libc): %lx\n", v7);
v8 = offset + v7;
printf("Injection target: %lx\n", v8);
if ( (unsigned int)aggancia(pid) == -1 )
{
puts("Cannot attach the process. Try running in as sudo.");
exit(-5);
}
puts("Process successfully attached.");
if ( !(unsigned int)safecheck((unsigned int)pid, v8) && v14 != 2 )
{
puts("Unexpected result! Recognitions report a target memory word that does not match the expected one.");
printf("Do you wish to continue, my master? (y/n) ");
scanf("%c", &v12);
getchar();
if ( (v12 & 0xDF) != 89 )
exit(-3);
}
do
{
v12 = 110;
if ( v14 )
{
if ( v14 == 1 )
customnum((unsigned int)pid, v8, (unsigned int)v17[0]);
else
restore((unsigned int)pid, v8);
}
else
{
nopmode((unsigned int)pid, v8);
}
puts("Done injection!");
if ( v15 )
{
ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
printf("inject again? (y/n) ");
scanf("%c", &v12);
getchar();
if ( (v12 & 0xDF) == 89 )
{
printf("mode? 0=nop 1=num 2=fix : ");
scanf("%d", &v14);
if ( v14 == 1 )
{
printf("Return value? ");
scanf("%d", v17);
getchar();
}
}
if ( (unsigned int)aggancia(pid) == -1 )
{
puts("Cannot attach the process. (Did it terminate?).");
exit(-5);
}
}
}
while ( (v12 & 0xDF) == 89 );
if ( !v15 )
goto LABEL_28;
printf("Kill the child process on exit? (y/n) ");
scanf("%c", &v12);
getchar();
if ( (v12 & 0xDF) != 89 )
{
puts("Init will do it for you.");
LABEL_28:
ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
goto LABEL_29;
}
ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
kill(pid, 9);
puts("Done!");
LABEL_29:
printf("Process %d detached. Exiting.\n", (unsigned int)pid);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // eax
__int64 v5; // rax
__int64 v6; // rsi
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v10; // r12
void *v11; // rax
char v12; // [rsp+13h] [rbp-2Dh] BYREF
__pid_t pid; // [rsp+14h] [rbp-2Ch] BYREF
int v14; // [rsp+18h] [rbp-28h] BYREF
int v15; // [rsp+1Ch] [rbp-24h] BYREF
int v16; // [rsp+20h] [rbp-20h] BYREF
int v17[7]; // [rsp+24h] [rbp-1Ch] BYREF

v15 = 0;
v16 = 0;
parse_cmdline(argc, argv, &v14, &v15, &pid, &v16, v17);
v4 = getpid();
v5 = func0(v4);
if ( v16 )
{
v10 = v5;
v11 = func2();
printf("%lx +4 - %lx = ", v11, v10);
v6 = (__int64)func2() - v10 + 4;
offset = v6;
}
else
{
offset = 233044LL;
v6 = 233044LL;
}
printf("Function offset: %lx\n", v6);
if ( v15 )
{
if ( (unsigned int)spawn(argv[2], &pid) == -1 )
{
puts("Cannot spawn the process.");
exit(-3);
}
printf("Spawned process with pid=%d\n", (unsigned int)pid);
}
if ( !(unsigned int)controlla_pid((unsigned int)pid) )
{
puts("unexistent process.");
exit(-4);
}
v7 = func0(pid);
printf("Process' base (libc): %lx\n", v7);
v8 = offset + v7;
printf("Injection target: %lx\n", v8);
if ( (unsigned int)func1(pid) == -1 )
{
puts("Cannot attach the process. Try running in as sudo.");
exit(-5);
}
puts("Process successfully attached.");
if ( !(unsigned int)safecheck((unsigned int)pid, v8) && v14 != 2 )
{
puts("Unexpected result! Recognitions report a target memory word that does not match the expected one.");
printf("Do you wish to continue, my master? (y/n) ");
scanf("%c", &v12);
getchar();
if ( (v12 & 0xDF) != 89 )
exit(-3);
}
do
{
v12 = 110;
if ( v14 )
{
if ( v14 == 1 )
customnum((unsigned int)pid, v8, (unsigned int)v17[0]);
else
restore((unsigned int)pid, v8);
}
else
{
nopmode((unsigned int)pid, v8);
}
puts("Done injection!");
if ( v15 )
{
ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
printf("inject again? (y/n) ");
scanf("%c", &v12);
getchar();
if ( (v12 & 0xDF) == 89 )
{
printf("mode? 0=nop 1=num 2=fix : ");
scanf("%d", &v14);
if ( v14 == 1 )
{
printf("Return value? ");
scanf("%d", v17);
getchar();
}
}
if ( (unsigned int)func1(pid) == -1 )
{
puts("Cannot attach the process. (Did it terminate?).");
exit(-5);
}
}
}
while ( (v12 & 0xDF) == 89 );
if ( !v15 )
goto LABEL_28;
printf("Kill the child process on exit? (y/n) ");
scanf("%c", &v12);
getchar();
if ( (v12 & 0xDF) != 89 )
{
puts("Init will do it for you.");
LABEL_28:
ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
goto LABEL_29;
}
ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
kill(pid, 9);
puts("Done!");
LABEL_29:
printf("Process %d detached. Exiting.\n", (unsigned int)pid);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    pid_t pid;
    int mode;
    char ans;
    int forkmode=0;
    int offsetmode=0;
    unsigned long long int libc_addr,bersaglio,my_libc,recalc;
    int valore_eax;
    parse_cmdline(argc,argv,&mode,&forkmode,&pid,&offsetmode,&valore_eax);
    my_libc=libc_posiz(getpid());
    if (offsetmode==0)offset=0x38E54;
    else
        {
        printf("%lx +4 - %lx = ",self_discover(),my_libc);
        recalc=(self_discover()+4)-my_libc;
        offset=(long)recalc;
        }
    printf("Function offset: %lx\n",offset);
    if (forkmode)
        {
        if (spawn(argv[2],&pid)==-1)
            {
            printf("Cannot spawn the process.\n");
            exit(-3);
            }
        printf("Spawned process with pid=%d\n",pid);
        }
    if (controlla_pid(pid)==0)
        {
        printf("unexistent process.\n");
        exit(-4);
        }
    libc_addr=libc_posiz(pid);
    printf("Process' base (libc): %lx\n",libc_addr);
    bersaglio=libc_addr+offset;
    printf("Injection target: %lx\n",bersaglio);
    if (aggancia(pid)==-1)
        {
        printf("Cannot attach the process. Try running in as sudo.\n");
        exit(-5);
        }
    else printf("Process successfully attached.\n");
    if (!safecheck(pid,bersaglio) && (mode!=2))
        {
        printf("Unexpected result! Recognitions report a target memory word that does not match the expected one.\n");
        printf("Do you wish to continue, my master? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans!='y' && ans!='Y')exit(-3);
        }
    do
        {
        ans='n';
        switch (mode)
            {
            case 0: nopmode(pid,bersaglio); break;
            case 1: customnum(pid,bersaglio,valore_eax); break;
            default: restore(pid,bersaglio);
            }
        printf("Done injection!\n");
        if (forkmode)
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            printf("inject again? (y/n) ");
            scanf("%c",&ans); getchar();
            if (ans=='y' || ans=='Y')
                {
                printf("mode? 0=nop 1=num 2=fix : ");
                scanf("%d",&mode);
                if (mode==1)
                    {
                    printf("Return value? ");
                    scanf("%d",&valore_eax); getchar();
                    }
                }
            if (aggancia(pid)==-1)
                {
                printf("Cannot attach the process. (Did it terminate?).\n");
                exit(-5);
                }
            }
        } while (ans=='y' || ans=='Y');
    if (forkmode)
        {
        printf("Kill the child process on exit? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans=='y' || ans=='Y')
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            kill(pid,9);
            printf("Done!\n");
            }
        else
            {
            printf("Init will do it for you.\n");
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            }
        }
    else ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
    printf("Process %d detached. Exiting.\n",pid);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int pid;
    int mode;
    char ans;
    int forkmode = 0;
    int offsetmode = 0;
    unsigned long long libc_addr; unsigned long long bersaglio; unsigned long long my_libc; unsigned long long recalc;
    int valore_eax;
    parse_cmdline(argc,argv,&mode,&forkmode,&pid,&offsetmode,&valore_eax);
    my_libc=libc_posiz(getpid());
    if (offsetmode==0)offset=0x38E54;
    else
        {
        printf("%lx +4 - %lx = ",self_discover(),my_libc);
        recalc=(self_discover()+4)-my_libc;
        offset=(long)recalc;
        }
    printf("Function offset: %lx\n",offset);
    if (forkmode)
        {
        if (spawn(argv[2],&pid)==-1)
            {
            printf("Cannot spawn the process.\n");
            exit(-3);
            }
        printf("Spawned process with pid=%d\n",pid);
        }
    if (controlla_pid(pid)==0)
        {
        printf("unexistent process.\n");
        exit(-4);
        }
    libc_addr=libc_posiz(pid);
    printf("Process' base (libc): %lx\n",libc_addr);
    bersaglio=libc_addr+offset;
    printf("Injection target: %lx\n",bersaglio);
    if (aggancia(pid)==-1)
        {
        printf("Cannot attach the process. Try running in as sudo.\n");
        exit(-5);
        }
    else printf("Process successfully attached.\n");
    if (!safecheck(pid,bersaglio) && (mode!=2))
        {
        printf("Unexpected result! Recognitions report a target memory word that does not match the expected one.\n");
        printf("Do you wish to continue, my master? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans!='y' && ans!='Y')exit(-3);
        }
    do
        {
        ans='n';
        switch (mode)
            {
            case 0: nopmode(pid,bersaglio); break;
            case 1: customnum(pid,bersaglio,valore_eax); break;
            default: restore(pid,bersaglio);
            }
        printf("Done injection!\n");
        if (forkmode)
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            printf("inject again? (y/n) ");
            scanf("%c",&ans); getchar();
            if (ans=='y' || ans=='Y')
                {
                printf("mode? 0=nop 1=num 2=fix : ");
                scanf("%d",&mode);
                if (mode==1)
                    {
                    printf("Return value? ");
                    scanf("%d",&valore_eax); getchar();
                    }
                }
            if (aggancia(pid)==-1)
                {
                printf("Cannot attach the process. (Did it terminate?).\n");
                exit(-5);
                }
            }
        } while (ans=='y' || ans=='Y');
    if (forkmode)
        {
        printf("Kill the child process on exit? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans=='y' || ans=='Y')
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            kill(pid,9);
            printf("Done!\n");
            }
        else
            {
            printf("Init will do it for you.\n");
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            }
        }
    else ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
    printf("Process %d detached. Exiting.\n",pid);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: mode int

variable_types: ans char

variable_types: forkmode int

variable_types: offsetmode int

variable_types:
bersaglio
unsigned long long

variable_types:
recalc
unsigned long long


isname

repo: agentOfChaos/chaos-controller

decompiled_code:
int __fastcall isname(const char *a1)
{
const char *v1; // rbx
int v2; // eax
__int64 v3; // rbp
int result; // eax

v1 = a1;
v2 = strlen(a1);
if ( v2 <= 0 )
return 0;
v3 = (__int64)&a1[v2 - 1 + 1];
while ( 1 )
{
result = isalpha(*v1);
if ( result )
break;
if ( ++v1 == (const char *)v3 )
return result;
}
return 1;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
const char *v1; // rbx
int v2; // eax
__int64 v3; // rbp
int result; // eax

v1 = a1;
v2 = strlen(a1);
if ( v2 <= 0 )
return 0;
v3 = (__int64)&a1[v2 - 1 + 1];
while ( 1 )
{
result = isalpha(*v1);
if ( result )
break;
if ( ++v1 == (const char *)v3 )
return result;
}
return 1;
}

original_code:
int isname(char *text)
{
    int l=strlen(text);
    int z;
    for (z=0; z<l; z++)
        {
        if (isalpha(text[z]))return 1;
        }
    return 0;
}

canonical_original_code:
int isname(char *text)
{
    int l = strlen(text);
    int z;
    for (z=0; z<l; z++)
        {
        if (isalpha(text[z]))return 1;
        }
    return 0;
}

variable_types:
text
char *

variable_types: l int

variable_types: z int

return_type: int


spawn

decompiled_code:
__int64 __fastcall spawn(char *arg, __pid_t *a2)
{
__pid_t v2; // eax
__int64 result; // rax

v2 = fork();
if ( v2 < 0 )
{
puts("Fork error.");
result = 0xFFFFFFFFLL;
}
else
{
if ( !v2 )
{
execl(arg, arg, 0LL);
puts("Exec error.");
exit(-1);
}
*a2 = v2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *arg, __pid_t *a2)
{
__pid_t v2; // eax
__int64 result; // rax

v2 = fork();
if ( v2 < 0 )
{
puts("Fork error.");
result = 0xFFFFFFFFLL;
}
else
{
if ( !v2 )
{
execl(arg, arg, 0LL);
puts("Exec error.");
exit(-1);
}
*a2 = v2;
result = 1LL;
}
return result;
}

original_code:
int spawn(char *nomefile,pid_t *pid)
{
    pid_t child=fork();
    if (child<0)
        {
        printf("Fork error.\n");
        return -1;
        }
    if (child==0)
        {
        execl(nomefile,nomefile,((void *)0));
        printf("Exec error.\n");
        exit(-1);
        }
    else
        {
        *pid=child;
        return 1;
        }
}

canonical_original_code:
int spawn(char *nomefile, int *pid)
{
    int child = fork();
    if (child<0)
        {
        printf("Fork error.\n");
        return -1;
        }
    if (child==0)
        {
        execl(nomefile,nomefile,((void *)0));
        printf("Exec error.\n");
        exit(-1);
        }
    else
        {
        *pid=child;
        return 1;
        }
}

variable_types:
nomefile
char *

variable_types:
pid
int *

variable_types: child int


putdata

decompiled_code:
__int64 __fastcall putdata(unsigned int a1, __int64 a2, char *a3, int a4)
{
unsigned int v4; // er13
char *v5; // rbx
signed __int64 v6; // rdx
void *v7; // rsp
__int64 v8; // r14
size_t v9; // r13
const void *v10; // rsi
__int64 v11; // rdx
size_t v12; // r15
__int64 result; // rax
unsigned __int64 v14; // [rsp+0h] [rbp-60h] BYREF
__int64 v15; // [rsp+8h] [rbp-58h]
int v16; // [rsp+14h] [rbp-4Ch]
void *src; // [rsp+18h] [rbp-48h]
unsigned int v18; // [rsp+20h] [rbp-40h]
unsigned int v19; // [rsp+24h] [rbp-3Ch]
__int64 v20; // [rsp+28h] [rbp-38h]

v4 = a1;
v5 = a3;
src = a3;
v6 = 8LL;
v15 = a2;
if ( (unsigned __int64)long_size >= 8 )
v6 = long_size;
v7 = alloca(v6);
v14 = ((unsigned __int64)&v14 + 7) >> 3;
v19 = a4 % long_size;
v18 = a4 / long_size;
v16 = a4 / long_size;
if ( a4 / long_size <= 0 )
{
v16 = 0;
}
else
{
v8 = a2;
v20 = a2 + 4LL * (unsigned int)(a4 / long_size - 1) + 4;
v9 = long_size;
do
{
v10 = v5;
v5 += v9;
memcpy(&v14, v10, v9);
v11 = v8;
v8 += 4LL;
ptrace(PTRACE_POKEDATA, a1, v11, v14);
}
while ( v8 != v20 );
v12 = v9;
v4 = a1;
src = (char *)src + v12 * v18;
}
result = v19;
if ( v19 )
{
memcpy(&v14, src, (int)v19);
result = ptrace(PTRACE_POKEDATA, v4, v15 + 4 * v16, *(_QWORD *)(8 * v14));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, char *a3, int a4)
{
unsigned int v4; // er13
char *v5; // rbx
signed __int64 v6; // rdx
void *v7; // rsp
__int64 v8; // r14
size_t v9; // r13
const void *v10; // rsi
__int64 v11; // rdx
size_t v12; // r15
__int64 result; // rax
unsigned __int64 v14; // [rsp+0h] [rbp-60h] BYREF
__int64 v15; // [rsp+8h] [rbp-58h]
int v16; // [rsp+14h] [rbp-4Ch]
void *src; // [rsp+18h] [rbp-48h]
unsigned int v18; // [rsp+20h] [rbp-40h]
unsigned int v19; // [rsp+24h] [rbp-3Ch]
__int64 v20; // [rsp+28h] [rbp-38h]

v4 = a1;
v5 = a3;
src = a3;
v6 = 8LL;
v15 = a2;
if ( (unsigned __int64)long_size >= 8 )
v6 = long_size;
v7 = alloca(v6);
v14 = ((unsigned __int64)&v14 + 7) >> 3;
v19 = a4 % long_size;
v18 = a4 / long_size;
v16 = a4 / long_size;
if ( a4 / long_size <= 0 )
{
v16 = 0;
}
else
{
v8 = a2;
v20 = a2 + 4LL * (unsigned int)(a4 / long_size - 1) + 4;
v9 = long_size;
do
{
v10 = v5;
v5 += v9;
memcpy(&v14, v10, v9);
v11 = v8;
v8 += 4LL;
ptrace(PTRACE_POKEDATA, a1, v11, v14);
}
while ( v8 != v20 );
v12 = v9;
v4 = a1;
src = (char *)src + v12 * v18;
}
result = v19;
if ( v19 )
{
memcpy(&v14, src, (int)v19);
result = ptrace(PTRACE_POKEDATA, v4, v15 + 4 * v16, *(_QWORD *)(8 * v14));
}
return result;
}

original_code:
void putdata(pid_t child, long addr,
             char *str, int len)
{ char *laddr;
    int i, j;
    union u {
            long val;
            char chars[long_size];
    }data;
    i = 0;
    j = len / long_size;
    laddr = str;
    while(i < j) {
        memcpy(data.chars, laddr, long_size);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
        ++i;
        laddr += long_size;
    }
    j = len % long_size;
    if(j != 0) {
        memcpy(data.chars, laddr, j);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
    }
}

canonical_original_code:
void putdata(int child, long addr, char *str, int len)
{ char *laddr;
    int i; int j;
    union u data;
    i = 0;
    j = len / long_size;
    laddr = str;
    while(i < j) {
        memcpy(data.chars, laddr, long_size);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
        ++i;
        laddr += long_size;
    }
    j = len % long_size;
    if(j != 0) {
        memcpy(data.chars, laddr, j);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
    }
}

variable_types: addr long

variable_types:
str
char *

variable_types: len int

variable_types:
laddr
char *

variable_types: i int

variable_types: j int

variable_types:
data
union u { long val; char chars[-1]; }

return_type: void


customnum

decompiled_code:
__int64 __fastcall customnum(unsigned int a1, __int64 a2, int a3)
{
signed __int64 v4; // rax
int v5; // ebx
void *v6; // rsp
char *v7; // r15
__int64 v8; // rsi
__int64 v9; // r12
__int64 i; // rsi
__int64 v12; // [rsp+0h] [rbp-60h] BYREF
void *src; // [rsp+8h] [rbp-58h]
unsigned __int64 v14; // [rsp+10h] [rbp-50h]
int v15; // [rsp+1Ch] [rbp-44h]
char v16; // [rsp+21h] [rbp-3Fh]
char dest[5]; // [rsp+22h] [rbp-3Eh] BYREF
char v18[8]; // [rsp+27h] [rbp-39h] BYREF
char v19; // [rsp+2Fh] [rbp-31h] BYREF

v15 = a3;
printf(" ---> %lx\n", a2);
v4 = int_size;
v5 = int_size;
if ( (unsigned __int64)int_size < 4 )
v4 = 4LL;
v6 = alloca(v4);
src = &v12;
v7 = v18;
v14 = ((unsigned __int64)&v12 + 3) >> 2;
getdata(a1, a2, v18, 8LL);
printf("prima: ");
do
{
v8 = (unsigned int)*v7++;
printf("%x ", v8);
}
while ( v7 != &v19 );
*(_DWORD *)(4 * v14) = v15;
if ( v5 <= 0 )
{
dest[0] = 0;
printf("\n(custom mode) dopo: ");
if ( !v5 )
{
v18[0] = -72;
printf("%x ", 4294967224LL);
}
}
else
{
v9 = 0LL;
memcpy(dest, src, (unsigned int)v5);
*(&v16 + v5 + 1) = 0;
printf("\n(custom mode) dopo: ");
for ( i = 4294967224LL; ; i = (unsigned int)*(&v16 + v9) )
{
v18[v9++] = i;
printf("%x ", i);
if ( v5 < (int)v9 )
break;
}
}
putchar(10);
return putdata(a1, a2, v18, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, int a3)
{
signed __int64 v4; // rax
int v5; // ebx
void *v6; // rsp
char *v7; // r15
__int64 v8; // rsi
__int64 v9; // r12
__int64 i; // rsi
__int64 v12; // [rsp+0h] [rbp-60h] BYREF
void *src; // [rsp+8h] [rbp-58h]
unsigned __int64 v14; // [rsp+10h] [rbp-50h]
int v15; // [rsp+1Ch] [rbp-44h]
char v16; // [rsp+21h] [rbp-3Fh]
char dest[5]; // [rsp+22h] [rbp-3Eh] BYREF
char v18[8]; // [rsp+27h] [rbp-39h] BYREF
char v19; // [rsp+2Fh] [rbp-31h] BYREF

v15 = a3;
printf(" ---> %lx\n", a2);
v4 = int_size;
v5 = int_size;
if ( (unsigned __int64)int_size < 4 )
v4 = 4LL;
v6 = alloca(v4);
src = &v12;
v7 = v18;
v14 = ((unsigned __int64)&v12 + 3) >> 2;
getdata(a1, a2, v18, 8LL);
printf("prima: ");
do
{
v8 = (unsigned int)*v7++;
printf("%x ", v8);
}
while ( v7 != &v19 );
*(_DWORD *)(4 * v14) = v15;
if ( v5 <= 0 )
{
dest[0] = 0;
printf("\n(custom mode) dopo: ");
if ( !v5 )
{
v18[0] = -72;
printf("%x ", 4294967224LL);
}
}
else
{
v9 = 0LL;
memcpy(dest, src, (unsigned int)v5);
*(&v16 + v5 + 1) = 0;
printf("\n(custom mode) dopo: ");
for ( i = 4294967224LL; ; i = (unsigned int)*(&v16 + v9) )
{
v18[v9++] = i;
printf("%x ", i);
if ( v5 < (int)v9 )
break;
}
}
putchar(10);
return putdata(a1, a2, v18, 8LL);
}

original_code:
void customnum(pid_t pid,unsigned long long int bersaglio, int valore_eax)
{
    printf(" ---> %lx\n",bersaglio);
    union u {
            int val;
            char chars[int_size];
    }data;
    char salvato[9];
    char iniettando[6];
    int i;
    char opcode=0xb8;
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",(int)salvato[i]);
    data.val=valore_eax;
    iniettando[0]=opcode;
    for (i=0; i<int_size; i++)iniettando[i+1]=data.chars[i];
    iniettando[i+1]=0;
    printf("\n(custom mode) dopo: ");
    for (i=0; i<int_size+1; i++){salvato[i]=iniettando[i]; printf("%x ",(int)iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

canonical_original_code:
void customnum(int pid, unsigned long long bersaglio, int valore_eax)
{
    printf(" ---> %lx\n",bersaglio);
    union u data;
    char salvato[9];
    char iniettando[6];
    int i;
    char opcode = 0xb8;
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",(int)salvato[i]);
    data.val=valore_eax;
    iniettando[0]=opcode;
    for (i=0; i<int_size; i++)iniettando[i+1]=data.chars[i];
    iniettando[i+1]=0;
    printf("\n(custom mode) dopo: ");
    for (i=0; i<int_size+1; i++){salvato[i]=iniettando[i]; printf("%x ",(int)iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

variable_types: pid int

variable_types:
data
union u { int val; char chars[-1]; }

variable_types:
salvato
char [9]

variable_types:
iniettando
char [6]

variable_types: opcode char


restore

decompiled_code:
__int64 __fastcall restore(__int64 a1, __int64 a2)
{
char *v3; // rbx
__int64 v4; // rsi
__int64 v5; // rbx
__int64 i; // rsi
int v8; // [rsp+2h] [rbp-36h]
char v9; // [rsp+6h] [rbp-32h]
char v10[8]; // [rsp+7h] [rbp-31h] BYREF
char v11; // [rsp+Fh] [rbp-29h] BYREF

v9 = -1;
v3 = v10;
v8 = -346136;
getdata(a1, a2, v10, 8LL);
printf("prima: ");
do
{
v4 = (unsigned int)*v3++;
printf("%x ", v4);
}
while ( v3 != &v11 );
v5 = 0LL;
printf("\n (restore mode)dopo: ");
for ( i = 4294967272LL; ; i = (unsigned int)*((char *)&v8 + v5) )
{
v10[v5++] = i;
printf("%x ", i);
if ( v5 == 5 )
break;
}
putchar(10);
return putdata((unsigned int)a1, a2, v10, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char *v3; // rbx
__int64 v4; // rsi
__int64 v5; // rbx
__int64 i; // rsi
int v8; // [rsp+2h] [rbp-36h]
char v9; // [rsp+6h] [rbp-32h]
char v10[8]; // [rsp+7h] [rbp-31h] BYREF
char v11; // [rsp+Fh] [rbp-29h] BYREF

v9 = -1;
v3 = v10;
v8 = -346136;
getdata(a1, a2, v10, 8LL);
printf("prima: ");
do
{
v4 = (unsigned int)*v3++;
printf("%x ", v4);
}
while ( v3 != &v11 );
v5 = 0LL;
printf("\n (restore mode)dopo: ");
for ( i = 4294967272LL; ; i = (unsigned int)*((char *)&v8 + v5) )
{
v10[v5++] = i;
printf("%x ", i);
if ( v5 == 5 )
break;
}
putchar(10);
return putdata((unsigned int)a1, a2, v10, 8LL);
}

original_code:
void restore(pid_t pid,unsigned long long int bersaglio)
{
    char iniettando[]={0xe8,0xb7,0xfa,0xff,0xff};
    int i;
    char salvato[9];
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",salvato[i]);
    printf("\n (restore mode)dopo: ");
    for (i=0; i<5; i++){salvato[i]=iniettando[i]; printf("%x ",iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

canonical_original_code:
void restore(int pid, unsigned long long bersaglio)
{
    char iniettando[] = {0xe8,0xb7,0xfa,0xff,0xff};
    int i;
    char salvato[9];
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",salvato[i]);
    printf("\n (restore mode)dopo: ");
    for (i=0; i<5; i++){salvato[i]=iniettando[i]; printf("%x ",iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

variable_types:
bersaglio
unsigned long long

variable_types:
iniettando
char []


safecheck

decompiled_code:
_BOOL8 __fastcall safecheck(__int64 a1, __int64 a2)
{
char s1[4]; // [rsp+4h] [rbp-14h] BYREF
__int16 v4; // [rsp+8h] [rbp-10h]
char s2[14]; // [rsp+Ah] [rbp-Eh] BYREF

v4 = 255;
*(_DWORD *)s1 = -346136;
getdata(a1, a2, s2, 5LL);
return strcmp(s1, s2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2)
{
char s1[4]; // [rsp+4h] [rbp-14h] BYREF
__int16 v4; // [rsp+8h] [rbp-10h]
char s2[14]; // [rsp+Ah] [rbp-Eh] BYREF

v4 = 255;
*(_DWORD *)s1 = -346136;
getdata(a1, a2, s2, 5LL);
return strcmp(s1, s2) == 0;
}

original_code:
int safecheck(pid_t pid,unsigned long long int bersaglio)
{
    char normale[]={0xe8,0xb7,0xfa,0xff,0xff,'\0'};
    char leggi[6];
    getdata(pid, bersaglio, leggi, 5);
    if (strcmp(normale,leggi)!=0) return 0;
    return 1;
}

canonical_original_code:
int safecheck(int pid, unsigned long long bersaglio)
{
    char normale[] = {0xe8,0xb7,0xfa,0xff,0xff,'\0'};
    char leggi[6];
    getdata(pid, bersaglio, leggi, 5);
    if (strcmp(normale,leggi)!=0) return 0;
    return 1;
}

variable_types:
normale
char []

variable_types:
leggi
char [6]


printhelpNquit

decompiled_code:
void __fastcall __noreturn printhelpNquit(const char *a1)
{
puts("Chaos controller v1.3 by agentOfChaos informaniac99<AT>gmail<DOT>com");
puts(
"Small linux utility that lets you hack the libc random number generator, bypassing the C random() function and alter"
"ing the rand()'s return value.");
puts("In layman terms: if random number is god, you can be god too!\n");
printf("Usage: %s [arguments]\n", a1);
puts("Mandatory arguments: offset_mode target inject_mode");
printf("--help -h -?\tprint this help screen\n.");
puts("[offset_mode]\t\"auto\" OR \"preset\"");
puts("How the program will know the memory offset (from libc beginning) where to find rand() entry point.");
puts("\tpreset will use the value defined at compile time.");
puts("\tauto will guess it based on it's location in the current program.");
puts("[target]\tpid OR absolute_path");
puts("The target process to manipulate");
puts("\tpid of a running process. keep in mind however that you might require root privilege for that");
puts("\tabsolute_path of a child process to spawn");
puts("[inject_mode]\tnop OR num OR fix");
puts("How the program will alterate target's memory");
puts("\tnop will replace the call-to-random with NOPs (assembly opcode that does nothing)");
puts("\tfix will restore the default value (a call to the random subroutine)");
puts(
"\tnum [my_number] will replace the call-to-random with MOV [my_number] to eax, basically making rand return your own"
" number of choice.");
printf("\nExample usage (sudo may be required):\n\t%s auto $(pidof killbots) num 4\n", a1);
printf("Then, to restore the program's unaltered memory: \n\t%s auto $(pidof killbots) fix\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
puts("Chaos controller v1.3 by agentOfChaos informaniac99<AT>gmail<DOT>com");
puts(
"Small linux utility that lets you hack the libc random number generator, bypassing the C random() function and alter"
"ing the rand()'s return value.");
puts("In layman terms: if random number is god, you can be god too!\n");
printf("Usage: %s [arguments]\n", a1);
puts("Mandatory arguments: offset_mode target inject_mode");
printf("--help -h -?\tprint this help screen\n.");
puts("[offset_mode]\t\"auto\" OR \"preset\"");
puts("How the program will know the memory offset (from libc beginning) where to find rand() entry point.");
puts("\tpreset will use the value defined at compile time.");
puts("\tauto will guess it based on it's location in the current program.");
puts("[target]\tpid OR absolute_path");
puts("The target process to manipulate");
puts("\tpid of a running process. keep in mind however that you might require root privilege for that");
puts("\tabsolute_path of a child process to spawn");
puts("[inject_mode]\tnop OR num OR fix");
puts("How the program will alterate target's memory");
puts("\tnop will replace the call-to-random with NOPs (assembly opcode that does nothing)");
puts("\tfix will restore the default value (a call to the random subroutine)");
puts(
"\tnum [my_number] will replace the call-to-random with MOV [my_number] to eax, basically making rand return your own"
" number of choice.");
printf("\nExample usage (sudo may be required):\n\t%s auto $(pidof killbots) num 4\n", a1);
printf("Then, to restore the program's unaltered memory: \n\t%s auto $(pidof killbots) fix\n", a1);
exit(0);
}

original_code:
void printhelpNquit(char *name)
{
    printf("Chaos controller  v1.3  by agentOfChaos  informaniac99<AT>gmail<DOT>com\n");
    printf("Small linux utility that lets you hack the libc random number generator, bypassing the C random() function and altering the rand()'s return value.\n");
    printf("In layman terms: if random number is god, you can be god too!\n\n");
    printf("Usage: %s [arguments]\n",name);
    printf("Mandatory arguments: offset_mode target inject_mode\n");
    printf("--help -h -?\tprint this help screen\n.");
    printf("[offset_mode]\t\"auto\" OR \"preset\"\n");
    printf("How the program will know the memory offset (from libc beginning) where to find rand() entry point.\n");
    printf("\tpreset will use the value defined at compile time.\n");
    printf("\tauto will guess it based on it's location in the current program.\n");
    printf("[target]\tpid OR absolute_path\n");
    printf("The target process to manipulate\n");
    printf("\tpid of a running process. keep in mind however that you might require root privilege for that\n");
    printf("\tabsolute_path of a child process to spawn\n");
    printf("[inject_mode]\tnop OR num OR fix\n");
    printf("How the program will alterate target's memory\n");
    printf("\tnop will replace the call-to-random with NOPs (assembly opcode that does nothing)\n");
    printf("\tfix will restore the default value (a call to the random subroutine)\n");
    printf("\tnum [my_number] will replace the call-to-random with MOV [my_number] to eax, basically making rand return your own number of choice.\n");
    printf("\nExample usage (sudo may be required):\n\t%s auto $(pidof killbots) num 4\n",name);
    printf("Then, to restore the program's unaltered memory: \n\t%s auto $(pidof killbots) fix\n",name);
    exit(0);
}

variable_types:
name
char *


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;
}

variable_types:
opt
char *


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:
// attributes: thunk
int endNcurses(void)
{
return endwin();
}

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

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

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


decompiled_code:
__int64 __fastcall crea_snacache(_QWORD *a1, int a2, int a3)
{
size_t v3; // rbx
_QWORD *v4; // rax
_QWORD *v5; // rbp
__int64 v6; // r15
void *v7; // rax
int v9; // ebx

v3 = a3;
v4 = malloc(8LL * a2);
*a1 = v4;
if ( v4 )
{
v5 = v4;
v6 = 0LL;
if ( a2 <= 0 )
return 1LL;
while ( 1 )
{
v7 = malloc(v3);
v5[v6] = v7;
if ( !v7 )
break;
if ( ++v6 == a2 )
return 1LL;
}
v9 = 0;
while ( 1 )
{
++v9;
free(v7);
if ( (_DWORD)v6 + 1 == v9 )
break;
v7 = *(void **)(*a1 + 8 * v6);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2, int a3)
{
size_t v3; // rbx
_QWORD *v4; // rax
_QWORD *v5; // rbp
__int64 v6; // r15
void *v7; // rax
int v9; // ebx

v3 = a3;
v4 = malloc(8LL * a2);
*a1 = v4;
if ( v4 )
{
v5 = v4;
v6 = 0LL;
if ( a2 <= 0 )
return 1LL;
while ( 1 )
{
v7 = malloc(v3);
v5[v6] = v7;
if ( !v7 )
break;
if ( ++v6 == a2 )
return 1LL;
}
v9 = 0;
while ( 1 )
{
++v9;
free(v7);
if ( (_DWORD)v6 + 1 == v9 )
break;
v7 = *(void **)(*a1 + 8 * v6);
}
}
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


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

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

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

if ( a3 > 0 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = a1;
if ( a2 > 0 )
{
do
{
v6 = *v5++;
printw("%d", (unsigned int)*(char *)(v6 + i));
}
while ( &a1[(unsigned int)(a2 - 1) + 1] != v5 );
}
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 func5(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
_DWORD *v10; // rax

*(_QWORD *)(a1 + 8) = 1LL;
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
v8 = malloc(8 * a5 * (__int64)a4);
*(_QWORD *)a1 = v8;
if ( !v8 || !(unsigned int)crea_snacache((_QWORD *)(a1 + 40), a4, a5) )
return 0xFFFFFFFFLL;
v10 = *(_DWORD **)a1;
*v10 = a2;
v10[1] = a3;
regen_snacache(a1, a4, a5);
return 1LL;
}

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)
{
__int64 v1; // rax
int v2; // ebx
__int64 v3; // r12
void *v4; // rax
__int64 result; // rax

v1 = *(int *)(a1 + 88);
*(_DWORD *)(a1 + 80) = 0;
*(_DWORD *)(a1 + 64) = 0;
v2 = v1;
*(_QWORD *)(a1 + 96) = 0LL;
v3 = *(int *)(a1 + 84);
v4 = malloc(8 * v1 * v3);
*(_QWORD *)(a1 + 72) = v4;
if ( v4 )
result = 3 * (unsigned int)((int)creaserpente(a1, (int)v3 / 2, v2 / 2, v3, 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 func9(void **a1)
{
func5(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 func10(__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, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax

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

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

initscr();
wclear(stdscr);
wtimeout(stdscr, 0);
noecho();
keypad(stdscr, 1);
if ( stdscr )
{
v2 = stdscr->_maxx;
*a2 = stdscr->_maxy + 1;
*a1 = v2 + 1;
if ( ((v2 + 1) & 1) == 0 )
goto LABEL_3;
}
else
{
*a2 = -1;
v2 = -2;
}
*a1 = v2;
LABEL_3:
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

v2 = a1 + 112;
*(_DWORD *)(a1 + 144) = a2;
*(_DWORD *)(a1 + 140) = 1;
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 func15(__int64 a1, int a2)
{
__int64 v2; // rbp

v2 = a1 + 112;
*(_DWORD *)(a1 + 144) = a2;
*(_DWORD *)(a1 + 140) = 1;
if ( (unsigned int)open_savefile(a1 + 112, "scoreboard.txt") == -3 )
{
++*(_DWORD *)(a1 + 160);
if ( (unsigned int)func13("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);
func13("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 func16(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)(a1[22] * a1[21]);
if ( a1[2] == (_DWORD)result )
result = func15((__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), (_DWORD *)(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((__int64)globali);
}
else
{
start_gioco((__int64)globali);
*(_QWORD *)&globali[140] = 0x100000001LL;
title_loop(globali);
*(_QWORD *)&globali[140] = 0LL;
}
atexit((void (*)(void))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);
func11((int *)(unsigned int)((_DWORD)globali + 84), (_DWORD *)(unsigned int)((_DWORD)globali + 88));
v4 = getenv("USER");
snprintf((char *)(unsigned int)((_DWORD)globali + 164), 0xAuLL, "%s", v4);
func10((__int64)globali);
*(_DWORD *)&globali[132] = 2;
*(_DWORD *)&globali[36] = 0;
*(_DWORD *)&globali[156] = 0;
if ( (unsigned int)parse_cmdline((unsigned int)argc, argv, globali) )
{
func8((__int64)globali);
}
else
{
func8((__int64)globali);
*(_QWORD *)&globali[140] = 0x100000001LL;
title_loop(globali);
*(_QWORD *)&globali[140] = 0LL;
}
atexit((void (*)(void))endNcurses);
wclear(stdscr);
wrefresh(stdscr);
game_loop(globali);
func9((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

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

result = 0LL;
if ( a2 >= 0 && a3 >= 0 && *(_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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 115 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--start") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 115 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--start") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 100 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--double") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 100 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--double") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 114 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--russian") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 114 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--russian") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 101 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--exponential") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 101 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--exponential") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 118 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--velocity") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 118 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--velocity") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 86 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--version") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 86 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--version") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 97 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--aperture") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 97 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--aperture") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 112 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--paused") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 112 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--paused") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 108 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--leaderboard") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 108 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--leaderboard") == 0;
return result;
}

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


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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 110 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--name") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 110 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--name") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 109 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--map") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 109 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--map") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 83 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--simple-graphic") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 83 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--simple-graphic") == 0;
return result;
}

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(__int64 a1)
{
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 99 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--computer") == 0;
return result;
}

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

if ( *(_BYTE *)a1 != 45 || *(_BYTE *)(a1 + 1) != 99 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
result = strcmp((const char *)a1, "--computer") == 0;
return result;
}

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(__int64 a1)
{
return opt_speed(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 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 ( s[0] == 105 && s[1] == 116 && !s[2] )
{
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 ( s[0] == 105 && s[1] == 116 && !s[2] )
{
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]; } *


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(void *a1, int a2)
{
void *result; // rax

if ( a2 > 0 )
result = memset(a1, 0, a2);
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, int a2)
{
void *result; // rax

if ( a2 > 0 )
result = memset(a1, 0, a2);
return result;
}

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