think

decompiled_code:
__int64 __fastcall think(__int64 a1)
{
unsigned int v2; // eax
char *v3; // r12
void *v4; // rax
const char *v5; // rax
unsigned int v6; // er14
__int64 v8; // rax
const char *v9; // rax
int v10; // ebp
int v11; // er13
const char *v12; // rax
int v13; // edi
const char *v14; // rax
int v15; // [rsp+4h] [rbp-44h]
char *dest; // [rsp+8h] [rbp-40h]

v2 = time(0LL);
srand(v2);
if ( !strcasecmp((const char *)(a1 + 50), "Quarto") || *(_DWORD *)(a1 + 124) == *(_DWORD *)(a1 + 128) )
{
v3 = (char *)malloc(0x50uLL);
addchar(v3);
v4 = malloc(4uLL);
addchar(v4);
if ( strcasecmp((const char *)(a1 + 50), "Quarto") && *(_DWORD *)(a1 + 124) == 4 )
{
convertGameFieldQuarto4x4(a1, v3);
printGameFieldQuarto4x4((__int64)v3);
puts("\n\nWir denken...");
v6 = checkField(v3);
if ( v6 )
{
v8 = 0LL;
while ( *(_DWORD *)(*(_QWORD *)(a1 + 144) + 4 * v8) != -1 )
{
if ( ++v8 == 16 )
{
puts("\nDas Spielfeld ist bereits voll, das ist aber komisch!");
return 1;
}
}
v9 = (const char *)formatMove(v8);
strcpy((char *)(a1 + 100), v9);
*(_DWORD *)(a1 + 136) = -1;
v6 = 0;
}
else
{
v10 = calculateMove(a1, (__int64)v3, 1);
v11 = 100;
dest = (char *)(a1 + 100);
if ( v10 == -1 )
{
do
{
v13 = rand() % 16;
if ( *(_DWORD *)(*(_QWORD *)(a1 + 144) + 4LL * v13) == -1 )
{
v14 = (const char *)formatMove(v13);
strcpy(dest, v14);
v15 = *(_DWORD *)(a1 + 132);
*(_DWORD *)(*(_QWORD *)(a1 + 144) + 4LL * v13) = v15;
convertGameFieldQuarto4x4(a1, v3);
chooseStone(a1);
*(_DWORD *)(a1 + 132) = *(_DWORD *)(a1 + 136);
if ( (unsigned int)calculateMove(a1, (__int64)v3, 1) == -1 )
{
*(_DWORD *)(a1 + 132) = v15;
*(_DWORD *)(*(_QWORD *)(a1 + 144) + 4LL * v13) = -1;
convertGameFieldQuarto4x4(a1, v3);
printf("\nMit Stein %d kann der Gegner nicht gewinnen!\n", *(unsigned int *)(a1 + 136));
return v6;
}
*(_DWORD *)(a1 + 132) = v15;
*(_DWORD *)(*(_QWORD *)(a1 + 144) + 4LL * v13) = -1;
convertGameFieldQuarto4x4(a1, v3);
}
--v11;
}
while ( v11 );
printf("\n#============================================================#");
printf("\n# Oh nein, wir haben keine Alternative und werden verlieren! #");
puts("\n#============================================================#");
fflush(stdout);
}
else
{
printf("\n#=====================#");
printf("\n# Wir gewinnen jetzt! #");
puts("\n#=====================#");
v12 = (const char *)formatMove(v10 / 4);
strcpy((char *)(a1 + 100), v12);
chooseStone(a1);
}
}
}
else
{
printGameField(a1);
if ( **(_DWORD **)(a1 + 144) == -1 )
v5 = (const char *)formatMove(0);
else
v5 = (const char *)formatMove(1);
strcpy((char *)(a1 + 100), v5);
v6 = *(_DWORD *)(a1 + 132);
if ( v6 )
{
*(_DWORD *)(a1 + 136) = 0;
v6 = 0;
}
else
{
*(_DWORD *)(a1 + 136) = 1;
}
}
}
else
{
perror("\nBei Quarto muss die Spielfeldhoehe gleich der breite sein!\n");
v6 = 1;
}
return v6;
}

original_code:
int think(sharedmem * shm) {
 srand(time(((void *)0)));
 if (strcasecmp(shm->gameName, "Quarto") && (shm->fieldX != shm->fieldY)) {
  perror("\nBei Quarto muss die Spielfeldhoehe gleich der breite sein!\n");
  return 1;
 }
 int i;
 int move = -1;
 int backupStone = 0;
 char* field = malloc(sizeof(char) * 5 * 16);
 addchar(field);
 char* backupField = malloc(sizeof(char) * 4);
 addchar(backupField);
 if (strcasecmp(shm->gameName, "Quarto") && shm->fieldX == 4) {
  convertGameFieldQuarto4x4(shm, field);
  printGameFieldQuarto4x4(field);
 } else {
  printGameField(shm);
  if (*(shm->pf) == -1) {
   strcpy(shm->nextField, formatMove(0));
  } else {
   strcpy(shm->nextField, formatMove(1));
  }
  if (shm->StoneToPlace == 0) {
   shm->nextStone = 1;
  } else {
   shm->nextStone = 0;
  }
  return 0;
 }
 printf("\n\nWir denken...\n");
 if (checkField(field) != 0) {
  for (i = 0; i < 16; i++) {
   move = i;
   if (*(shm->pf + move) == -1) {
    strcpy(shm->nextField, formatMove(move));
    shm->nextStone = -1;
    return 0;
   }
  }
  printf("\nDas Spielfeld ist bereits voll, das ist aber komisch!\n");
  return 1;
 }
 move = calculateMove(shm, field, 1);
 if (move != -1) {
  printf("\n#=====================#");
  printf("\n# Wir gewinnen jetzt! #");
  printf("\n#=====================#\n");
  strcpy(shm->nextField, formatMove(move / 4));
  chooseStone(shm);
 } else {
  for (i = 0; i < 100; i++) {
   move = rand() % 16;
   if (*(shm->pf + move) == -1) {
    strcpy(shm->nextField, formatMove(move));
    if (formatMove(move) == ((void *)0) ) {
     perror("\nFehler bei der Konvertierung eines Spielzuges!\n");
     return 1;
    }
    backupStone = shm->StoneToPlace;
    *(shm->pf + move) = shm->StoneToPlace;
    convertGameFieldQuarto4x4(shm, field);
    chooseStone(shm);
    shm->StoneToPlace = shm->nextStone;
    if (calculateMove(shm, field, 1) == -1) {
     shm->StoneToPlace = backupStone;
     *(shm->pf + move) = -1;
     convertGameFieldQuarto4x4(shm, field);
     printf("\nMit Stein %d kann der Gegner nicht gewinnen!\n", shm->nextStone);
     return 0;
    } else {
     shm->StoneToPlace = backupStone;
     *(shm->pf + move) = -1;
     convertGameFieldQuarto4x4(shm, field);
    }
   }
  }
  printf("\n#============================================================#");
  printf("\n# Oh nein, wir haben keine Alternative und werden verlieren! #");
  printf("\n#============================================================#\n");
  fflush(stdout);
 }
 return 0;
}

canonical_original_code:
int think(struct sharedmem *shm) {
 srand(time(((void *)0)));
 if (strcasecmp(shm->gameName, "Quarto") && (shm->fieldX != shm->fieldY)) {
  perror("\nBei Quarto muss die Spielfeldhoehe gleich der breite sein!\n");
  return 1;
 }
 int i;
 int move = -1;
 int backupStone = 0;
 char *field = malloc(sizeof(char) * 5 * 16);
 addchar(field);
 char *backupField = malloc(sizeof(char) * 4);
 addchar(backupField);
 if (strcasecmp(shm->gameName, "Quarto") && shm->fieldX == 4) {
  convertGameFieldQuarto4x4(shm, field);
  printGameFieldQuarto4x4(field);
 } else {
  printGameField(shm);
  if (*(shm->pf) == -1) {
   strcpy(shm->nextField, formatMove(0));
  } else {
   strcpy(shm->nextField, formatMove(1));
  }
  if (shm->StoneToPlace == 0) {
   shm->nextStone = 1;
  } else {
   shm->nextStone = 0;
  }
  return 0;
 }
 printf("\n\nWir denken...\n");
 if (checkField(field) != 0) {
  for (i = 0; i < 16; i++) {
   move = i;
   if (*(shm->pf + move) == -1) {
    strcpy(shm->nextField, formatMove(move));
    shm->nextStone = -1;
    return 0;
   }
  }
  printf("\nDas Spielfeld ist bereits voll, das ist aber komisch!\n");
  return 1;
 }
 move = calculateMove(shm, field, 1);
 if (move != -1) {
  printf("\n#=====================#");
  printf("\n# Wir gewinnen jetzt! #");
  printf("\n#=====================#\n");
  strcpy(shm->nextField, formatMove(move / 4));
  chooseStone(shm);
 } else {
  for (i = 0; i < 100; i++) {
   move = rand() % 16;
   if (*(shm->pf + move) == -1) {
    strcpy(shm->nextField, formatMove(move));
    if (formatMove(move) == ((void *)0) ) {
     perror("\nFehler bei der Konvertierung eines Spielzuges!\n");
     return 1;
    }
    backupStone = shm->StoneToPlace;
    *(shm->pf + move) = shm->StoneToPlace;
    convertGameFieldQuarto4x4(shm, field);
    chooseStone(shm);
    shm->StoneToPlace = shm->nextStone;
    if (calculateMove(shm, field, 1) == -1) {
     shm->StoneToPlace = backupStone;
     *(shm->pf + move) = -1;
     convertGameFieldQuarto4x4(shm, field);
     printf("\nMit Stein %d kann der Gegner nicht gewinnen!\n", shm->nextStone);
     return 0;
    } else {
     shm->StoneToPlace = backupStone;
     *(shm->pf + move) = -1;
     convertGameFieldQuarto4x4(shm, field);
    }
   }
  }
  printf("\n#============================================================#");
  printf("\n# Oh nein, wir haben keine Alternative und werden verlieren! #");
  printf("\n#============================================================#\n");
  fflush(stdout);
 }
 return 0;
}

variable_types: backupStone int

variable_types:
backupField
char *


reactToSig

decompiled_code:
__int64 __fastcall reactToSig(void *shmaddr, unsigned int a2, void *a3, int *a4, int a5)
{
unsigned int v8; // er13
unsigned int v10; // ebx
char *v11; // r14
__int64 v12; // rcx
int v13; // ebx

if ( a2 )
{
if ( a2 == 1 )
{
fclose(logdatei);
free(a3);
freeall();
v13 = *((_DWORD *)shmaddr + 1);
if ( v13 == getpid() )
{
close(*a4);
close(*((_DWORD *)shmaddr + 26));
shmdt(*((const void **)shmaddr + 18));
shmdt(shmaddr);
}
else
{
close(a4[1]);
if ( *((_DWORD *)shmaddr + 35) )
{
shmdt(*((const void **)shmaddr + 18));
if ( shmctl(*((_DWORD *)shmaddr + 35), 0, 0LL) == -1 )
perror("\nParent: Fehler bei Zerstoerung von pf \n");
}
shmdt(shmaddr);
if ( shmctl(a5, 0, 0LL) == -1 )
perror("\nParent: Fehler bei Zerstoerung von shm \n");
}
exit(1);
}
v8 = 0;
}
else
{
*((_QWORD *)shmaddr + 18) = shmat(*((_DWORD *)shmaddr + 35), 0LL, 0);
v8 = *((_DWORD *)shmaddr + 30);
if ( v8 == 1 )
{
*((_DWORD *)shmaddr + 30) = 0;
v10 = think(shmaddr);
if ( !v10 )
{
v11 = (char *)calloc(0xFuLL, 1uLL);
addchar(v11);
v12 = *((unsigned int *)shmaddr + 34);
if ( (_DWORD)v12 == -1 )
sprintf(v11, "PLAY %s", (const char *)shmaddr + 100);
else
sprintf(v11, "PLAY %s,%d", (const char *)shmaddr + 100, v12);
if ( (int)write(a4[1], v11, 0xFuLL) < 0 )
{
perror("\nFehler beim Schreiben in die Pipe\n");
}
else
{
*((_DWORD *)shmaddr + 29) = 0;
v8 = v10;
}
}
}
else
{
v8 = a2;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *shmaddr, unsigned int a2, void *a3, int *a4, int a5)
{
unsigned int v8; // er13
unsigned int v10; // ebx
char *v11; // r14
__int64 v12; // rcx
int v13; // ebx

if ( a2 )
{
if ( a2 == 1 )
{
fclose(logdatei);
free(a3);
freeall();
v13 = *((_DWORD *)shmaddr + 1);
if ( v13 == getpid() )
{
close(*a4);
close(*((_DWORD *)shmaddr + 26));
shmdt(*((const void **)shmaddr + 18));
shmdt(shmaddr);
}
else
{
close(a4[1]);
if ( *((_DWORD *)shmaddr + 35) )
{
shmdt(*((const void **)shmaddr + 18));
if ( shmctl(*((_DWORD *)shmaddr + 35), 0, 0LL) == -1 )
perror("\nParent: Fehler bei Zerstoerung von pf \n");
}
shmdt(shmaddr);
if ( shmctl(a5, 0, 0LL) == -1 )
perror("\nParent: Fehler bei Zerstoerung von shm \n");
}
exit(1);
}
v8 = 0;
}
else
{
*((_QWORD *)shmaddr + 18) = shmat(*((_DWORD *)shmaddr + 35), 0LL, 0);
v8 = *((_DWORD *)shmaddr + 30);
if ( v8 == 1 )
{
*((_DWORD *)shmaddr + 30) = 0;
v10 = think(shmaddr);
if ( !v10 )
{
v11 = (char *)calloc(0xFuLL, 1uLL);
addchar(v11);
v12 = *((unsigned int *)shmaddr + 34);
if ( (_DWORD)v12 == -1 )
sprintf(v11, "PLAY %s", (const char *)shmaddr + 100);
else
sprintf(v11, "PLAY %s,%d", (const char *)shmaddr + 100, v12);
if ( (int)write(a4[1], v11, 0xFuLL) < 0 )
{
perror("\nFehler beim Schreiben in die Pipe\n");
}
else
{
*((_DWORD *)shmaddr + 29) = 0;
v8 = v10;
}
}
}
else
{
v8 = a2;
}
}
return v8;
}

original_code:
int reactToSig(sharedmem* shm, int signal, config_struct *conf, int fd[], int shmID) {
 if (signal == 0) {
  int err;
  (void) signal;
  shm->pf = shmat(shm->pfID, 0, 0);
  if (shm->pleaseThink == 1) {
   shm->pleaseThink = 0;
   if (think(shm) != 0) {
    return 1;
   }
   char* reply = calloc(15, sizeof(char));
   addchar(reply);
   if (shm->nextStone == -1) {
    sprintf(reply, "PLAY %s", shm->nextField);
   } else {
    sprintf(reply, "PLAY %s,%d", shm->nextField, shm->nextStone);
   }
   err = write(fd[1], reply, 15);
   if (err < 0) {
    perror("\nFehler beim Schreiben in die Pipe\n");
    return 1;
   }
   shm->thinking = 0;
  }
 } else if (signal == 1) {
  fclose(logdatei);
  free(conf);
  freeall();
  if (shm->pidKid == getpid()) {
   close(fd[0]);
   close(shm->sock);
   shmdt(shm->pf);
   shmdt(shm);
  } else {
   close(fd[1]);
   if (shm->pfID != 0) {
    shmdt(shm->pf);
    if (shmctl(shm->pfID, 0, ((void *)0) ) == -1) {
     perror("\nParent: Fehler bei Zerstoerung von pf \n");
    }
   }
   shmdt(shm);
   if (shmctl(shmID, 0, ((void *)0) ) == -1) {
    perror("\nParent: Fehler bei Zerstoerung von shm \n");
   }
  }
  exit(1);
 }
 return 0;
}

canonical_original_code:
int reactToSig(struct sharedmem *shm, int signal, struct config_struct *conf, int fd[], int shmID) {
 if (signal == 0) {
  int err;
  (void) signal;
  shm->pf = shmat(shm->pfID, 0, 0);
  if (shm->pleaseThink == 1) {
   shm->pleaseThink = 0;
   if (think(shm) != 0) {
    return 1;
   }
   char *reply = calloc(15, sizeof(char));
   addchar(reply);
   if (shm->nextStone == -1) {
    sprintf(reply, "PLAY %s", shm->nextField);
   } else {
    sprintf(reply, "PLAY %s,%d", shm->nextField, shm->nextStone);
   }
   err = write(fd[1], reply, 15);
   if (err < 0) {
    perror("\nFehler beim Schreiben in die Pipe\n");
    return 1;
   }
   shm->thinking = 0;
  }
 } else if (signal == 1) {
  fclose(logdatei);
  free(conf);
  freeall();
  if (shm->pidKid == getpid()) {
   close(fd[0]);
   close(shm->sock);
   shmdt(shm->pf);
   shmdt(shm);
  } else {
   close(fd[1]);
   if (shm->pfID != 0) {
    shmdt(shm->pf);
    if (shmctl(shm->pfID, 0, ((void *)0) ) == -1) {
     perror("\nParent: Fehler bei Zerstoerung von pf \n");
    }
   }
   shmdt(shm);
   if (shmctl(shmID, 0, ((void *)0) ) == -1) {
    perror("\nParent: Fehler bei Zerstoerung von shm \n");
   }
  }
  exit(1);
 }
 return 0;
}

variable_types: struct sharedmem { int pidDad; int pidKid; char gameID[42]; int sock; int *pf; struct player { int playerNumber; char playerName[50]; int playerReady; int playerRegisterd; } player[8]; } *

variable_types: signal int

variable_types: struct config_struct { char hostname[100]; char gamekindname[20]; char version[5]; char playernumber[5]; int portnumber; } *

variable_types:
fd
int []

variable_types: shmID int

variable_types: err int

variable_types:
reply
char *

return_type: int

user_defined_types: struct sharedmem { int pidDad; int pidKid; char gameID[42]; int sock; int *pf; struct player player[8]; }


initConnection

decompiled_code:
_BOOL8 __fastcall initConnection(__pid_t *a1, __int64 a2, __int64 a3)
{
struct hostent *v4; // r12
int v5; // ebp
_BOOL4 v6; // ebp
struct sockaddr v8[3]; // [rsp+0h] [rbp-38h] BYREF

a1[26] = socket(2, 1, 0);
v4 = gethostbyname((const char *)a2);
if ( !v4 )
{
perror("\nFehler beim Anfordern der IP");
writelog(logdatei, "src/InitConnection.c:27");
}
memcpy(&v8[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
v8[0].sa_family = 2;
*(_WORD *)v8[0].sa_data = _bswap_16(*(_WORD *)(a2 + 132));
if ( connect(a1[26], v8, 0x10u) )
{
perror("\n Fehler beim Verbindungsaufbau");
v6 = 1;
}
else
{
printf("\nVerbindung mit %s hergestellt!\n", (const char *)a2);
writelog(logdatei, "src/InitConnection.c:36");
*a1 = getppid();
a1[1] = getpid();
v5 = performConnection((unsigned int)a1[26], a1, a2, a3);
close(a1[26]);
v6 = v5 != 0;
}
return v6;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__pid_t *a1, __int64 a2, __int64 a3)
{
struct hostent *v4; // r12
int v5; // ebp
_BOOL4 v6; // ebp
struct sockaddr v8[3]; // [rsp+0h] [rbp-38h] BYREF

a1[26] = socket(2, 1, 0);
v4 = gethostbyname((const char *)a2);
if ( !v4 )
{
perror("\nFehler beim Anfordern der IP");
writelog(logdatei, "src/InitConnection.c:27");
}
memcpy(&v8[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
v8[0].sa_family = 2;
*(_WORD *)v8[0].sa_data = func0(*(_WORD *)(a2 + 132));
if ( connect(a1[26], v8, 0x10u) )
{
perror("\n Fehler beim Verbindungsaufbau");
v6 = 1;
}
else
{
printf("\nVerbindung mit %s hergestellt!\n", (const char *)a2);
writelog(logdatei, "src/InitConnection.c:36");
*a1 = getppid();
a1[1] = getpid();
v5 = performConnection((unsigned int)a1[26], a1, a2, a3);
close(a1[26]);
v6 = v5 != 0;
}
return v6;
}

original_code:
int initConnection(sharedmem * shm, config_struct* conf, int fd[]) {
 shm->sock = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in host;
 struct hostent* ip;
 ip = (gethostbyname(conf->hostname));
 if (ip == ((void *)0) ) {
  perror("\nFehler beim Anfordern der IP");
  writelog(logdatei, "src/InitConnection.c" ":" "27");
 }
 memcpy(&(host.sin_addr), ip->h_addr_list[0],ip ->h_length);
 host.sin_family = 2;
 host.sin_port = htons(conf->portnumber);
 if (connect(shm->sock, (struct sockaddr*) &host, sizeof(host)) == 0) {
  printf("\nVerbindung mit %s hergestellt!\n", conf->hostname);
  writelog(logdatei, "src/InitConnection.c" ":" "36");
 } else {
  perror("\n Fehler beim Verbindungsaufbau");
  return 1;
 }
 shm->pidDad = getppid();
 shm->pidKid = getpid();
 if (performConnection(shm->sock, shm, conf, fd) != 0) {
  close(shm->sock);
  return 1;
 }
 close(shm->sock);
 return 0;
}

canonical_original_code:
int initConnection(struct sharedmem *shm, struct config_struct *conf, int fd[]) {
 shm->sock = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in host;
 struct hostent *ip;
 ip = (gethostbyname(conf->hostname));
 if (ip == ((void *)0) ) {
  perror("\nFehler beim Anfordern der IP");
  writelog(logdatei, "src/InitConnection.c" ":" "27");
 }
 memcpy(&(host.sin_addr), ip->h_addr_list[0],ip ->h_length);
 host.sin_family = 2;
 host.sin_port = htons(conf->portnumber);
 if (connect(shm->sock, (struct sockaddr *) &host, sizeof(host)) == 0) {
  printf("\nVerbindung mit %s hergestellt!\n", conf->hostname);
  writelog(logdatei, "src/InitConnection.c" ":" "36");
 } else {
  perror("\n Fehler beim Verbindungsaufbau");
  return 1;
 }
 shm->pidDad = getppid();
 shm->pidKid = getpid();
 if (performConnection(shm->sock, shm, conf, fd) != 0) {
  close(shm->sock);
  return 1;
 }
 close(shm->sock);
 return 0;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct config_struct { char hostname[100]; char gamekindname[20]; char version[5]; char playernumber[5]; int portnumber; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct player { int playerNumber; char playerName[50]; int playerReady; int playerRegisterd; }


checkName

decompiled_code:
__int64 __fastcall checkName(char *s1, char *nptr, void *dest)
{
unsigned int v4; // ebx
size_t v5; // rax
size_t v6; // rax
size_t v8; // rax
size_t v9; // rax

if ( !strcasecmp(s1, "Hostname") )
{
v4 = 0;
v6 = strlen(nptr);
memcpy(dest, nptr, v6);
}
else
{
v4 = strcasecmp(s1, "Version");
if ( v4 )
{
v4 = strcasecmp(s1, "Spieltyp");
if ( v4 )
{
v4 = strcasecmp(s1, "Portnummer");
if ( v4 )
{
v4 = strcasecmp(s1, "Spielernummer");
if ( v4 )
{
puts(
"Parameter nicht gefunden! Bitte pruefen ob die Namen korrekt geschrieben oder die Konfigurationsdatei sauber ist!");
v4 = 1;
}
else
{
v5 = strlen(nptr);
memcpy((char *)dest + 125, nptr, v5);
}
}
else
{
*((_DWORD *)dest + 33) = strtol(nptr, 0LL, 10);
}
}
else
{
v9 = strlen(nptr);
memcpy((char *)dest + 100, nptr, v9);
}
}
else
{
v8 = strlen(nptr);
memcpy((char *)dest + 120, nptr, v8);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, char *nptr, void *dest)
{
unsigned int v4; // ebx
size_t v5; // rax
size_t v6; // rax
size_t v8; // rax
size_t v9; // rax

if ( !strcasecmp(s1, "Hostname") )
{
v4 = 0;
v6 = strlen(nptr);
memcpy(dest, nptr, v6);
}
else
{
v4 = strcasecmp(s1, "Version");
if ( v4 )
{
v4 = strcasecmp(s1, "Spieltyp");
if ( v4 )
{
v4 = strcasecmp(s1, "Portnummer");
if ( v4 )
{
v4 = strcasecmp(s1, "Spielernummer");
if ( v4 )
{
puts(
"Parameter nicht gefunden! Bitte pruefen ob die Namen korrekt geschrieben oder die Konfigurationsdatei sauber ist!");
v4 = 1;
}
else
{
v5 = strlen(nptr);
memcpy((char *)dest + 125, nptr, v5);
}
}
else
{
*((_DWORD *)dest + 33) = strtol(nptr, 0LL, 10);
}
}
else
{
v9 = strlen(nptr);
memcpy((char *)dest + 100, nptr, v9);
}
}
else
{
v8 = strlen(nptr);
memcpy((char *)dest + 120, nptr, v8);
}
}
return v4;
}

original_code:
int checkName(char* name, char* wert, config_struct* conf) {
 if (strcasecmp(name, "Hostname") == 0) {
  memcpy(conf->hostname, wert, strlen(wert));
  return 0;
 } else if (strcasecmp(name, "Version") == 0) {
  memcpy(conf->version, wert, strlen(wert));
  return 0;
 } else if (strcasecmp(name, "Spieltyp") == 0) {
  memcpy(conf->gamekindname, wert, strlen(wert));
  return 0;
 } else if (strcasecmp(name, "Portnummer") == 0) {
  conf->portnumber = strtol(wert, (char**) ((void *)0), 10);
  return 0;
 } else if (strcasecmp(name, "Spielernummer") == 0) {
  memcpy(conf->playernumber, wert, strlen(wert));
  return 0;
 } else {
  printf("Parameter nicht gefunden! Bitte pruefen ob die Namen korrekt geschrieben oder die Konfigurationsdatei sauber ist!\n");
  return 1;
 }
}

canonical_original_code:
int checkName(char *name, char *wert, struct config_struct *conf) {
 if (strcasecmp(name, "Hostname") == 0) {
  memcpy(conf->hostname, wert, strlen(wert));
  return 0;
 } else if (strcasecmp(name, "Version") == 0) {
  memcpy(conf->version, wert, strlen(wert));
  return 0;
 } else if (strcasecmp(name, "Spieltyp") == 0) {
  memcpy(conf->gamekindname, wert, strlen(wert));
  return 0;
 } else if (strcasecmp(name, "Portnummer") == 0) {
  conf->portnumber = strtol(wert, (char **) ((void *)0), 10);
  return 0;
 } else if (strcasecmp(name, "Spielernummer") == 0) {
  memcpy(conf->playernumber, wert, strlen(wert));
  return 0;
 } else {
  printf("Parameter nicht gefunden! Bitte pruefen ob die Namen korrekt geschrieben oder die Konfigurationsdatei sauber ist!\n");
  return 1;
 }
}

variable_types:
name
char *

variable_types:
wert
char *


main

canonical_name: main

repo: eddix/supervisor

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // ebp
__pid_t v5; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc > 1 )
{
v3 = fork();
if ( v3 != -1 )
{
if ( v3 )
exit(0);
v4 = open("/dev/null", 2);
dup2(v4, 0);
dup2(v4, 1);
dup2(v4, 2);
if ( v4 > 2 )
close(v4);
while ( 1 )
{
v5 = fork();
if ( v5 == -1 )
break;
if ( !v5 )
{
execvp(argv[1], (char *const *)argv + 1);
exit(1);
}
waitpid(v5, stat_loc, 0);
sleep(1u);
}
exit(1);
}
perror("fork()");
exit(1);
}
puts(Usage);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
    pid_t childpid;
    int status, fd;
    if (argc < 2) {
        puts(Usage);
        exit(0);
    }
    childpid = fork();
    if (-1 == childpid) {
        perror("fork()");
        exit(1);
    } else if (0 != childpid) {
        exit(0);
    }
    fd = open("/dev/null", 02);
    dup2(fd, 0);
    dup2(fd, 1);
    dup2(fd, 2);
    if (fd > 2) {
        close(fd);
    }
    while (1) {
        childpid = fork();
        if (-1 == childpid) {
            exit(1);
        } else if (0 != childpid) {
            waitpid(childpid, &status, 0);
            sleep(1);
        } else {
            execvp(argv[1], &argv[1]);
            exit(1);
        }
    }
}

canonical_original_code:
int main(int argc, char **argv)
{
    int childpid;
    int status; int fd;
    if (argc < 2) {
        puts(Usage);
        exit(0);
    }
    childpid = fork();
    if (-1 == childpid) {
        perror("fork()");
        exit(1);
    } else if (0 != childpid) {
        exit(0);
    }
    fd = open("/dev/null", 02);
    dup2(fd, 0);
    dup2(fd, 1);
    dup2(fd, 2);
    if (fd > 2) {
        close(fd);
    }
    while (1) {
        childpid = fork();
        if (-1 == childpid) {
            exit(1);
        } else if (0 != childpid) {
            waitpid(childpid, &status, 0);
            sleep(1);
        } else {
            execvp(argv[1], &argv[1]);
            exit(1);
        }
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: childpid int

variable_types: status int

variable_types: fd int


decompiled_code:
int __fastcall display_both(__int64 a1, const char *a2)
{
const char *v2; // rax
const char *v3; // rax

v2 = (const char *)map_get();
printf("Std: %s %s\n", a2, v2);
v3 = (const char *)map_get_def(a1, a2, "Default Value");
return printf("Def: %s %s\n", a2, v3);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, const char *a2)
{
const char *v2; // rax
const char *v3; // rax

v2 = (const char *)map_get();
printf("Std: %s %s\n", a2, v2);
v3 = (const char *)map_get_def(a1, a2, "Default Value");
return printf("Def: %s %s\n", a2, v3);
}

original_code:
void display_both(struct map_head *m, char *first)
{
    printf("Std: %s %s\n", first, map_get(m, first));
    printf("Def: %s %s\n", first, map_get_def(m, first, "Default Value"));
}

variable_types: struct map_head { char *name; struct map_t { struct map_t *nxt; char *name; char *value; } *first; } *

variable_types:
first
char *

return_type: void

user_defined_types: struct map_head { char *name; struct map_t *first; }


decompiled_code:
int __fastcall map_test(__int64 a1)
{
puts("==============================================");
display_both(a1, "One");
display_both(a1, "Two");
display_both(a1, "Three");
display_both(a1, "Four");
display_both(a1, "Five");
display_both(a1, "Six");
display_both(a1, "Seven");
display_both(a1, "Eight");
return putchar(10);
}

original_code:
void map_test(struct map_head *test)
{
    printf("==============================================\n");
    display_both(test, "One");
    display_both(test, "Two");
    display_both(test, "Three");
    display_both(test, "Four");
    display_both(test, "Five");
    display_both(test, "Six");
    display_both(test, "Seven");
    display_both(test, "Eight");
    printf("\n");
}

user_defined_types: struct map_t { struct map_t *nxt; char *name; char *value; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v3 = map_create("Test");
map_set(v3, "One", "Won");
map_set(v3, "Two", "Too");
map_set(v3, "Four", "Fore");
map_test(v3);
map_set(v3, "Two", "To");
map_test(v3);
map_set(v3, "Eight", "Ate");
map_test(v3);
v4 = map_del(v3, "Two");
printf("Delete 'Two': %d\n", v4);
map_test(v3);
v5 = map_del(v3, "Two");
printf("Delete 'Two': %d\n", v5);
v6 = map_del(v3, "Eight");
printf("Delete 'Eight': %d\n", v6);
v7 = map_del(v3, "Four");
printf("Delete 'Four': %d\n", v7);
map_test(v3);
v8 = map_del(v3, "One");
printf("Delete 'One': %d\n", v8);
map_test(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v3 = map_create("Test");
func9(v3, "One", "Won");
func9(v3, "Two", "Too");
func9(v3, "Four", "Fore");
func8(v3);
func9(v3, "Two", "To");
func8(v3);
func9(v3, "Eight", "Ate");
func8(v3);
v4 = func10(v3, "Two");
printf("Delete 'Two': %d\n", v4);
func8(v3);
v5 = func10(v3, "Two");
printf("Delete 'Two': %d\n", v5);
v6 = func10(v3, "Eight");
printf("Delete 'Eight': %d\n", v6);
v7 = func10(v3, "Four");
printf("Delete 'Four': %d\n", v7);
func8(v3);
v8 = func10(v3, "One");
printf("Delete 'One': %d\n", v8);
func8(v3);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    struct map_head *test_map;
    test_map = map_create("Test");
    map_set(test_map, "One", "Won");
    map_set(test_map, "Two", "Too");
    map_set(test_map, "Four", "Fore");
    map_test(test_map);
    map_set(test_map, "Two", "To");
    map_test(test_map);
    map_set(test_map, "Eight", "Ate");
    map_test(test_map);
    printf("Delete 'Two': %d\n", map_del(test_map, "Two"));
    map_test(test_map);
    printf("Delete 'Two': %d\n", map_del(test_map, "Two"));
    printf("Delete 'Eight': %d\n", map_del(test_map, "Eight"));
    printf("Delete 'Four': %d\n", map_del(test_map, "Four"));
    map_test(test_map);
    printf("Delete 'One': %d\n", map_del(test_map, "One"));
    map_test(test_map);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct map_head *test_map;
    test_map = map_create("Test");
    map_set(test_map, "One", "Won");
    map_set(test_map, "Two", "Too");
    map_set(test_map, "Four", "Fore");
    map_test(test_map);
    map_set(test_map, "Two", "To");
    map_test(test_map);
    map_set(test_map, "Eight", "Ate");
    map_test(test_map);
    printf("Delete 'Two': %d\n", map_del(test_map, "Two"));
    map_test(test_map);
    printf("Delete 'Two': %d\n", map_del(test_map, "Two"));
    printf("Delete 'Eight': %d\n", map_del(test_map, "Eight"));
    printf("Delete 'Four': %d\n", map_del(test_map, "Four"));
    map_test(test_map);
    printf("Delete 'One': %d\n", map_del(test_map, "One"));
    map_test(test_map);
    return 0;
}


original_code:
void map_set(struct map_head *m, char *name, char *value)
{
    if ((((void *)0) == m) || (((void *)0) == name) || (((void *)0) == value))
    {
        return;
    }
    if (((void *)0) == m->first)
    {
        struct map_t *e = (struct map_t *) malloc(sizeof(struct map_t));
        if (((void *)0) == e)
        {
            return;
        }
        e->nxt = ((void *)0);
        e->name = (char *) malloc(strlen(name) + 1);
        if (((void *)0) == e->name)
        {
            free(e);
            return;
        }
        strcpy(e->name, name);
        e->value = (char *) malloc(strlen(value) + 1);
        if (((void *)0) == e->value)
        {
            free(e->name);
            free(e);
            return;
        }
        strcpy(e->value, value);
        m->first = e;
        return;
    }
    struct map_t *ptr;
    struct map_t *last;
    for (ptr = m->first; ptr != ((void *)0); ptr = ptr->nxt)
    {
        if (0 == strcmp(ptr->name, name))
        {
            if (((void *)0) != ptr->value)
            {
                free(ptr->value);
            }
            ptr->value = (char *) malloc(strlen(value) + 1);
            strcpy(ptr->value, value);
            return;
        }
        last = ptr;
    }
    struct map_t *e = (struct map_t *) malloc(sizeof(struct map_t));
    if (((void *)0) == e)
    {
        return;
    }
    e->nxt = ((void *)0);
    e->name = (char *) malloc(strlen(name) + 1);
    if (((void *)0) == e->name)
    {
        free(e);
        return;
    }
    strcpy(e->name, name);
    e->value = (char *) malloc(strlen(value) + 1);
    if (((void *)0) == e->value)
    {
        free(e->name);
        free(e);
        return;
    }
    strcpy(e->value, value);
    last->nxt = e;
}

variable_types:
value
char *

variable_types: struct map_t { struct map_t *nxt; char *name; char *value; } *


decompiled_code:
__int64 __fastcall map_del(__int64 a1, const char *a2)
{
__int64 *v2; // rbx
void *v3; // r13
_QWORD *v4; // r13
void *v5; // r12
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(__int64 **)(a1 + 8);
if ( !a2 || !v2 )
return 0LL;
v3 = (void *)v2[1];
if ( !strcmp((const char *)v3, a2) )
{
free(v3);
free((void *)v2[2]);
*(_QWORD *)(a1 + 8) = *v2;
free(v2);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v2;
v2 = (__int64 *)*v2;
if ( !v2 )
break;
v5 = (void *)v2[1];
if ( !strcmp((const char *)v5, a2) )
{
free(v5);
free((void *)v2[2]);
*v4 = *v2;
free(v2);
return 1LL;
}
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
__int64 *v2; // rbx
void *v3; // r13
_QWORD *v4; // r13
void *v5; // r12
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(__int64 **)(a1 + 8);
if ( !a2 || !v2 )
return 0LL;
v3 = (void *)v2[1];
if ( !strcmp((const char *)v3, a2) )
{
free(v3);
free((void *)v2[2]);
*(_QWORD *)(a1 + 8) = *v2;
free(v2);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v2;
v2 = (__int64 *)*v2;
if ( !v2 )
break;
v5 = (void *)v2[1];
if ( !strcmp((const char *)v5, a2) )
{
free(v5);
free((void *)v2[2]);
*v4 = *v2;
free(v2);
return 1LL;
}
}
result = 0LL;
}
return result;
}

original_code:
int map_del(struct map_head *m, char *name)
{
    if ((((void *)0) == m) || (((void *)0) == m->first) || (((void *)0) == name))
    {
        return 0;
    }
    struct map_t *mx;
    mx = m->first;
    if (0 == strcmp(mx->name, name))
    {
        free(mx->name);
        free(mx->value);
        m->first = mx->nxt;
        free(mx);
        return 1;
    }
    struct map_t *flwr;
    for (mx = m->first; mx != ((void *)0); mx = mx->nxt)
    {
        flwr = mx->nxt;
        if (((void *)0) == flwr)
        {
            break;
        }
        if (0 == strcmp(flwr->name, name))
        {
            free(flwr->name);
            free(flwr->value);
            mx->nxt = flwr->nxt;
            free(flwr);
            return 1;
        }
    }
    return 0;
}


canonical_original_code:
void map_set(struct map_head *m, char *name, char *value)
{
    if ((((void *)0) == m) || (((void *)0) == name) || (((void *)0) == value))
    {
        return;
    }
    if (((void *)0) == m->first)
    {
        struct map_t *e = (struct map_t *) malloc(sizeof(struct map_t));
        if (((void *)0) == e)
        {
            return;
        }
        e->nxt = ((void *)0);
        e->name = (char *) malloc(strlen(name) + 1);
        if (((void *)0) == e->name)
        {
            free(e);
            return;
        }
        strcpy(e->name, name);
        e->value = (char *) malloc(strlen(value) + 1);
        if (((void *)0) == e->value)
        {
            free(e->name);
            free(e);
            return;
        }
        strcpy(e->value, value);
        m->first = e;
        return;
    }
    struct map_t *ptr;
    struct map_t *last;
    for (ptr = m->first; ptr != ((void *)0); ptr = ptr->nxt)
    {
        if (0 == strcmp(ptr->name, name))
        {
            if (((void *)0) != ptr->value)
            {
                free(ptr->value);
            }
            ptr->value = (char *) malloc(strlen(value) + 1);
            strcpy(ptr->value, value);
            return;
        }
        last = ptr;
    }
    struct map_t *e = (struct map_t *) malloc(sizeof(struct map_t));
    if (((void *)0) == e)
    {
        return;
    }
    e->nxt = ((void *)0);
    e->name = (char *) malloc(strlen(name) + 1);
    if (((void *)0) == e->name)
    {
        free(e);
        return;
    }
    strcpy(e->name, name);
    e->value = (char *) malloc(strlen(value) + 1);
    if (((void *)0) == e->value)
    {
        free(e->name);
        free(e);
        return;
    }
    strcpy(e->value, value);
    last->nxt = e;
}


decompiled_code:
__int64 map_get()
{
return map_get_def();
}

canonical_decompiled_code:
__int64 func7()
{
return map_get_def();
}

original_code:
char *map_get(struct map_head *m, char *name)
{
    return map_get_def(m, name, ((void *)0));
}

return_type: char *


canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
__int64 *v2; // rbx
void *v3; // r13
_QWORD *v4; // r13
void *v5; // r12
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(__int64 **)(a1 + 8);
if ( !a2 || !v2 )
return 0LL;
v3 = (void *)v2[1];
if ( !strcmp((const char *)v3, a2) )
{
free(v3);
free((void *)v2[2]);
*(_QWORD *)(a1 + 8) = *v2;
free(v2);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v2;
v2 = (__int64 *)*v2;
if ( !v2 )
break;
v5 = (void *)v2[1];
if ( !strcmp((const char *)v5, a2) )
{
free(v5);
free((void *)v2[2]);
*v4 = *v2;
free(v2);
return 1LL;
}
}
result = 0LL;
}
return result;
}

canonical_original_code:
int map_del(struct map_head *m, char *name)
{
    if ((((void *)0) == m) || (((void *)0) == m->first) || (((void *)0) == name))
    {
        return 0;
    }
    struct map_t *mx;
    mx = m->first;
    if (0 == strcmp(mx->name, name))
    {
        free(mx->name);
        free(mx->value);
        m->first = mx->nxt;
        free(mx);
        return 1;
    }
    struct map_t *flwr;
    for (mx = m->first; mx != ((void *)0); mx = mx->nxt)
    {
        flwr = mx->nxt;
        if (((void *)0) == flwr)
        {
            break;
        }
        if (0 == strcmp(flwr->name, name))
        {
            free(flwr->name);
            free(flwr->value);
            mx->nxt = flwr->nxt;
            free(flwr);
            return 1;
        }
    }
    return 0;
}


decompiled_code:
int List_test()
{
__int64 i; // rbx
_QWORD *v1; // rdx
int j; // eax
_QWORD *v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = 0LL;
for ( i = 0LL; i != 10; ++i )
List_append((__int64 *)v4, i);
v1 = v4[0];
for ( j = 0; j != 10; ++j )
{
if ( *(_DWORD *)v1 != j )
__assert_fail("(int)np->data == i", "list.c", 0x32u, "List_test");
v1 = (_QWORD *)v1[1];
}
List_free(v4, 0LL);
v4[0] = 0LL;
List_free(v4, 0LL);
return printf("%s: All tests pass.\n", "list.c");
}

canonical_decompiled_code:
int func8()
{
__int64 i; // rbx
_QWORD *v1; // rdx
int j; // eax
_QWORD *v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = 0LL;
for ( i = 0LL; i != 10; ++i )
List_append((__int64 *)v4, i);
v1 = v4[0];
for ( j = 0; j != 10; ++j )
{
if ( *(_DWORD *)v1 != j )
__assert_fail("(int)np->data == i", "list.c", 0x32u, "List_test");
v1 = (_QWORD *)v1[1];
}
func7(v4, 0LL);
v4[0] = 0LL;
func7(v4, 0LL);
return printf("%s: All tests pass.\n", "list.c");
}

original_code:
void List_test(void) {
  List *np, *head = ((void *)0);
  int i;
  for (i = 0; i < 10; i++) {
    List_append(&head, (void *)i);
  }
  np = head;
  for (i = 0; i < 10; i++) {
    ((void) sizeof (((int)np->data == i) ? 1 : 0), __extension__ ({ if ((int)np->data == i) ; else __assert_fail ("(int)np->data == i", "list.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    np = np->next;
  }
  List_free(&head, ((void *)0));
  head = ((void *)0);
  List_free(&head, ((void *)0));
  printf("%s: All tests pass.\n", "list.c");
}

canonical_original_code:
void List_test() {
  struct List *np; struct List *head = ((void *)0);
  int i;
  for (i = 0; i < 10; i++) {
    List_append(&head, (void *)i);
  }
  np = head;
  for (i = 0; i < 10; i++) {
    ((void) sizeof (((int)np->data == i) ? 1 : 0), __extension__ ({ if ((int)np->data == i) ; else __assert_fail ("(int)np->data == i", "list.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    np = np->next;
  }
  List_free(&head, ((void *)0));
  head = ((void *)0);
  List_free(&head, ((void *)0));
  printf("%s: All tests pass.\n", "list.c");
}

variable_types: struct List { void *data; struct List *next; } *

variable_types: i int


repo: edorfaus/keytemper

decompiled_code:
__int64 __fastcall get_char_for_key(char a1, unsigned __int8 a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0x67u && (a1 & 0xDD) == 0 )
{
result = key_to_char_map[2 * a2];
if ( (a1 & 0x22) != 0 )
result = key_to_char_map[2 * a2 + 1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, unsigned __int8 a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0x67u && (a1 & 0xDD) == 0 )
{
result = key_to_char_map[2 * a2];
if ( (a1 & 0x22) != 0 )
result = key_to_char_map[2 * a2 + 1];
}
return result;
}

original_code:
char get_char_for_key(unsigned char modifiers, unsigned char key_code)
{
 if ( key_code >= sizeof(key_to_char_map)/sizeof(struct keydesc) )
 {
  return '\0';
 }
 if ( ( modifiers & 0x22 ) != modifiers )
 {
  return '\0';
 }
 const struct keydesc key = key_to_char_map[key_code];
 if ( modifiers & 0x22 )
 {
  return key.shifted;
 }
 return key.normal;
}

canonical_original_code:
char get_char_for_key(unsigned char modifiers, unsigned char key_code)
{
 if ( key_code >= sizeof(key_to_char_map)/sizeof(struct keydesc) )
 {
  return '\0';
 }
 if ( ( modifiers & 0x22 ) != modifiers )
 {
  return '\0';
 }
 struct keydesc key = key_to_char_map[key_code];
 if ( modifiers & 0x22 )
 {
  return key.shifted;
 }
 return key.normal;
}

variable_types:
modifiers
unsigned char

variable_types:
key
struct keydesc { char normal; }

return_type: char


repo: eduardovra/particles

decompiled_code:
__int64 __fastcall screen_y(float a1)
{
return (unsigned int)(int)((double)(int)((float)(a1 * 440.0) * 0.5) + 320.0);
}

canonical_decompiled_code:
__int64 __fastcall func1(float a1)
{
return (unsigned int)(int)((double)(int)((float)(a1 * 440.0) * 0.5) + 320.0);
}

variable_types: y int


decompiled_code:
void __fastcall rotate_point(float *a1, float a2)
{
double v2; // xmm2_8
double v3; // xmm0_8
double v4; // xmm3_8
float v5; // xmm1_4
double v6; // [rsp+8h] [rbp-20h]
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

v6 = *a1;
sincos(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
v4 = a1[1];
v5 = v6 * cosx - v4 * sinx[0];
*a1 = v5;
*(float *)&v3 = v3 * v6 + v2 * v4;
a1[1] = *(float *)&v3;
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float a2)
{
double v2; // xmm2_8
double v3; // xmm0_8
double v4; // xmm3_8
float v5; // xmm1_4
double v6; // [rsp+8h] [rbp-20h]
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

v6 = *a1;
sincos(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
v4 = a1[1];
v5 = v6 * cosx - v4 * sinx[0];
*a1 = v5;
*(float *)&v3 = v3 * v6 + v2 * v4;
a1[1] = *(float *)&v3;
}

original_code:
void rotate_point(st_point * point, const float angle)
{
 float x = point->x, y = point->y;
 point->x = (x * cos(angle)) - (y * sin(angle));
 point->y = (x * sin(angle)) + (y * cos(angle));
}

canonical_original_code:
void rotate_point(struct s_point *point, float angle)
{
 float x = point->x; float y = point->y;
 point->x = (x * cos(angle)) - (y * sin(angle));
 point->y = (x * sin(angle)) + (y * cos(angle));
}

variable_types:
point
struct s_point { float x; float y; } *

variable_types: angle float

variable_types: x float

variable_types: y float


updatePlanes

decompiled_code:
void __fastcall updatePlanes(float a1)
{
float *v1; // rbx
double v2; // xmm1_8
float v3; // xmm0_4
float v4; // xmm0_4
float v5; // [rsp+Ch] [rbp-3Ch]
double v6; // [rsp+10h] [rbp-38h]
double v7; // [rsp+18h] [rbp-30h]
double cosx; // [rsp+20h] [rbp-28h] BYREF
double sinx[4]; // [rsp+28h] [rbp-20h] BYREF

v5 = a1 * 0.17453292;
sincos((float)(a1 * 0.17453292), sinx, &cosx);
v6 = cosx;
v7 = sinx[0];
v1 = (float *)((char *)&_planes + 12);
do
{
v2 = *(v1 - 2);
v3 = *(v1 - 3) * v6 - v7 * v2;
*(v1 - 3) = v3;
v4 = v3 * v7 + v2 * v6;
*(v1 - 2) = v4;
rotate_point(v1, v5);
rotate_point(v1 + 2, v5);
v1 += 7;
}
while ( v1 != (float *)((char *)&_planes + 124) );
}

original_code:
void updatePlanes(const float delta)
{
 int i;
 const float angle = rotation_step * delta;
 for (i = 0; i < ( sizeof(__planes) / sizeof(__planes[0]) ); i++) {
  __planes[i].a = (__planes[i].a * cos(angle)) - (__planes[i].b * sin(angle));
  __planes[i].b = (__planes[i].a * sin(angle)) + (__planes[i].b * cos(angle));
  rotate_point(&__planes[i].line.p1, angle);
  rotate_point(&__planes[i].line.p2, angle);
 }
}

canonical_original_code:
void updatePlanes(float delta)
{
 int i;
 float angle = rotation_step * delta;
 for (i = 0; i < ( sizeof(__planes) / sizeof(__planes[0]) ); i++) {
  __planes[i].a = (__planes[i].a * cos(angle)) - (__planes[i].b * sin(angle));
  __planes[i].b = (__planes[i].a * sin(angle)) + (__planes[i].b * cos(angle));
  rotate_point(&__planes[i].line.p1, angle);
  rotate_point(&__planes[i].line.p2, angle);
 }
}

variable_types: delta float


update

decompiled_code:
float *__fastcall update(float a1)
{
float *result; // rax
float *v2; // rbx
unsigned int i; // ebp
float v4; // xmm0_4
float v5; // xmm4_4
float v6; // xmm2_4
float v7; // xmm1_4

if ( rotate_planes )
updatePlanes(a1);
result = particles;
particles[0] = (float)(a1 * particles[2]) + particles[0];
particles[1] = (float)(a1 * particles[3]) + particles[1];
v2 = (float *)&_planes;
for ( i = 0; i != 4; ++i )
{
if ( (float)((float)((float)(*v2 * particles[0]) + (float)(v2[1] * particles[1])) + v2[2]) < 0.0 )
{
result = particles;
if ( (float)((float)(v2[1] * particles[3]) + (float)(*v2 * particles[2])) < 0.0 )
{
fprintf(stderr, "particle %d collided on plane %d\n", 0LL, i);
result = particles;
v4 = *v2;
v5 = particles[3];
v6 = v2[1];
v7 = particles[2] - (float)((float)((float)(particles[2] * v4) + (float)(v5 * v6)) * (float)(*v2 + v4));
particles[2] = v7;
particles[3] = v5 - (float)((float)((float)(v7 * v4) + (float)(v5 * v6)) * (float)(v6 + v6));
}
}
v2 += 7;
}
return result;
}

canonical_decompiled_code:
float *__fastcall func4(float a1)
{
float *result; // rax
float *v2; // rbx
unsigned int i; // ebp
float v4; // xmm0_4
float v5; // xmm4_4
float v6; // xmm2_4
float v7; // xmm1_4

if ( rotate_planes )
func3(a1);
result = particles;
particles[0] = (float)(a1 * particles[2]) + particles[0];
particles[1] = (float)(a1 * particles[3]) + particles[1];
v2 = (float *)&_planes;
for ( i = 0; i != 4; ++i )
{
if ( (float)((float)((float)(*v2 * particles[0]) + (float)(v2[1] * particles[1])) + v2[2]) < 0.0 )
{
result = particles;
if ( (float)((float)(v2[1] * particles[3]) + (float)(*v2 * particles[2])) < 0.0 )
{
fprintf(stderr, "particle %d collided on plane %d\n", 0LL, i);
result = particles;
v4 = *v2;
v5 = particles[3];
v6 = v2[1];
v7 = particles[2] - (float)((float)((float)(particles[2] * v4) + (float)(v5 * v6)) * (float)(*v2 + v4));
particles[2] = v7;
particles[3] = v5 - (float)((float)((float)(v7 * v4) + (float)(v5 * v6)) * (float)(v6 + v6));
}
}
v2 += 7;
}
return result;
}

original_code:
void update(const float delta)
{
 int i, j;
 if ( rotate_planes )
  updatePlanes(delta);
 for (i = 0; i < 1; i++) {
  particles[i].pos.x += particles[i].vel.x * delta;
  particles[i].pos.y += particles[i].vel.y * delta;
  for (j = 0; j < ( sizeof(__planes) / sizeof(__planes[0]) ); j++) {
   float distance = (particles[i].pos.x * __planes[j].a) + (particles[i].pos.y * __planes[j].b) + __planes[j].c;
   float norm_vel = (particles[i].vel.x * __planes[j].a) + (particles[i].vel.y * __planes[j].b);
   if ( (distance < 0) && (norm_vel < 0) ) {
    fprintf(stderr, "particle %d collided on plane %d\n", i, j);
    particles[i].vel.x -= 2 * __planes[j].a * ((particles[i].vel.x * __planes[j].a) + (particles[i].vel.y * __planes[j].b));
    particles[i].vel.y -= 2 * __planes[j].b * ((particles[i].vel.x * __planes[j].a) + (particles[i].vel.y * __planes[j].b));
   }
  }
 }
}

canonical_original_code:
void update(float delta)
{
 int i; int j;
 if ( rotate_planes )
  updatePlanes(delta);
 for (i = 0; i < 1; i++) {
  particles[i].pos.x += particles[i].vel.x * delta;
  particles[i].pos.y += particles[i].vel.y * delta;
  for (j = 0; j < ( sizeof(__planes) / sizeof(__planes[0]) ); j++) {
   float distance = (particles[i].pos.x * __planes[j].a) + (particles[i].pos.y * __planes[j].b) + __planes[j].c;
   float norm_vel = (particles[i].vel.x * __planes[j].a) + (particles[i].vel.y * __planes[j].b);
   if ( (distance < 0) && (norm_vel < 0) ) {
    fprintf(stderr, "particle %d collided on plane %d\n", i, j);
    particles[i].vel.x -= 2 * __planes[j].a * ((particles[i].vel.x * __planes[j].a) + (particles[i].vel.y * __planes[j].b));
    particles[i].vel.y -= 2 * __planes[j].b * ((particles[i].vel.x * __planes[j].a) + (particles[i].vel.y * __planes[j].b));
   }
  }
 }
}

variable_types: j int

variable_types: distance float


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

*(float *)a1 = get_random_float(-1.0, 1.0);
*(float *)(a1 + 4) = get_random_float(-1.0, 1.0);
*(float *)(a1 + 8) = get_random_float(-0.5, 0.5);
*(float *)(a1 + 12) = get_random_float(-0.5, 0.5);
*(_DWORD *)(a1 + 16) = (int)get_random(0.0, 255.0);
*(_DWORD *)(a1 + 20) = (int)get_random(0.0, 255.0);
result = (unsigned int)(int)get_random(0.0, 255.0);
*(_DWORD *)(a1 + 24) = result;
return result;
}

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

*(float *)a1 = get_random_float(-1.0, 1.0);
*(float *)(a1 + 4) = get_random_float(-1.0, 1.0);
*(float *)(a1 + 8) = get_random_float(-0.5, 0.5);
*(float *)(a1 + 12) = get_random_float(-0.5, 0.5);
*(_DWORD *)(a1 + 16) = (int)get_random(0.0, 255.0);
*(_DWORD *)(a1 + 20) = (int)get_random(0.0, 255.0);
result = (unsigned int)(int)get_random(0.0, 255.0);
*(_DWORD *)(a1 + 24) = result;
return result;
}

original_code:
void init_particles(st_particle * particles, ssize_t num_of_particles)
{
 int i;
 for (i = 0; i < 1; i++) {
  particles[i].pos.x = get_random_float(-1, 1);
  particles[i].pos.y = get_random_float(-1, 1);
  particles[i].vel.x = get_random_float(-0.5, 0.5);
  particles[i].vel.y = get_random_float(-0.5, 0.5);
  particles[i].color.R = get_random(0, 0xFF);
  particles[i].color.G = get_random(0, 0xFF);
  particles[i].color.B = get_random(0, 0xFF);
 }
}

canonical_original_code:
void init_particles(struct s_particle *particles, long num_of_particles)
{
 int i;
 for (i = 0; i < 1; i++) {
  particles[i].pos.x = get_random_float(-1, 1);
  particles[i].pos.y = get_random_float(-1, 1);
  particles[i].vel.x = get_random_float(-0.5, 0.5);
  particles[i].vel.y = get_random_float(-0.5, 0.5);
  particles[i].color.R = get_random(0, 0xFF);
  particles[i].color.G = get_random(0, 0xFF);
  particles[i].color.B = get_random(0, 0xFF);
 }
}

variable_types: struct s_particle { struct s_position { float x; float y; } pos; struct s_velocity { float x; float y; } vel; struct s_color { int R; int G; int B; } color; } *

user_defined_types: struct s_particle { struct s_position pos; struct s_velocity vel; struct s_color color; }


decompiled_code:
__int64 map_to_screen()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
Sint32 map_to_screen(int i, float p)
{
 return 0;
}

canonical_original_code:
int map_to_screen(int i, float p)
{
 return 0;
}

variable_types: p float


decompiled_code:
__int64 get_ticks()
{
return (unsigned int)SDL_GetTicks();
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)SDL_GetTicks();
}

original_code:
uint64_t get_ticks(void)
{
 return SDL_GetTicks();
}

canonical_original_code:
unsigned long get_ticks()
{
 return SDL_GetTicks();
}

return_type: unsigned long


decompiled_code:
__int64 sleep_ticks()
{
return SDL_Delay();
}

canonical_decompiled_code:
__int64 func1()
{
return SDL_Delay();
}

original_code:
void sleep_ticks(const uint64_t ticks)
{
 SDL_Delay(ticks);
}

canonical_original_code:
void sleep_ticks(unsigned long ticks)
{
 SDL_Delay(ticks);
}

variable_types:
ticks
unsigned long


decompiled_code:
float __fastcall get_random(float a1, float a2)
{
return (double)rand() * 4.656612873077393e-10 * (float)((float)(a2 - a1) + 1.0) + a1;
}

canonical_decompiled_code:
float __fastcall func2(float a1, float a2)
{
return (double)rand() * 4.656612873077393e-10 * (float)((float)(a2 - a1) + 1.0) + a1;
}

original_code:
float get_random(float min, float max)
{
 float range = ( max - min ) + 1;
 return ((rand() / (2147483647 + 1.0)) * range) + min;
}

variable_types: min float

variable_types: max float

variable_types: range float

return_type: float


decompiled_code:
float __fastcall get_random_float(float a1, float a2)
{
return (float)((float)rand() / (float)(2147483600.0 / (float)(a2 - a1))) + a1;
}

canonical_decompiled_code:
float __fastcall func3(float a1, float a2)
{
return (float)((float)rand() / (float)(2147483600.0 / (float)(a2 - a1))) + a1;
}

original_code:
float get_random_float(float min, float max)
{
 return min + (float)rand()/((float)2147483647/(max-min));
}


writeFile

decompiled_code:
int writeFile()
{
int v0; // ebx
__int64 buf; // [rsp+5h] [rbp-13h] BYREF
__int16 v3; // [rsp+Dh] [rbp-Bh]
char v4; // [rsp+Fh] [rbp-9h]

if ( remove("input.bin") < 0 && *__errno_location() != 2 )
return -1;
v0 = open("input.bin", 193);
if ( v0 < 0 )
return -1;
buf = 0x602090501040103LL;
v3 = 773;
v4 = 5;
if ( write(v0, &buf, 0xBuLL) >= 0 )
return close(v0);
printf("Error");
return -1;
}

canonical_decompiled_code:
int func7()
{
int v0; // ebx
__int64 buf; // [rsp+5h] [rbp-13h] BYREF
__int16 v3; // [rsp+Dh] [rbp-Bh]
char v4; // [rsp+Fh] [rbp-9h]

if ( remove("input.bin") < 0 && *__errno_location() != 2 )
return -1;
v0 = open("input.bin", 193);
if ( v0 < 0 )
return -1;
buf = 0x602090501040103LL;
v3 = 773;
v4 = 5;
if ( write(v0, &buf, 0xBuLL) >= 0 )
return close(v0);
printf("Error");
return -1;
}

original_code:
static int writeFile() {
     if(remove("input.bin")<0 && (*__errno_location ()) != 2)
     {
        return -1;
     }
     int fileDescr=open("input.bin", 0100 | 0200 | 01);
     if(fileDescr<0)
     {
        return -1;
     }
     char buffer[11]={3,1,4,1,5,9,2,6,5,3,5};
     ssize_t numBytesWritten=write(fileDescr,buffer,11);
     if(numBytesWritten<0)
     {
printf("Error");
       return -1;
     }
     return close(fileDescr);
 }

canonical_original_code:
static int writeFile() {
     if(remove("input.bin")<0 && (*__errno_location ()) != 2)
     {
        return -1;
     }
     int fileDescr = open("input.bin", 0100 | 0200 | 01);
     if(fileDescr<0)
     {
        return -1;
     }
     char buffer[11] = {3,1,4,1,5,9,2,6,5,3,5};
     long numBytesWritten = write(fileDescr,buffer,11);
     if(numBytesWritten<0)
     {
printf("Error");
       return -1;
     }
     return close(fileDescr);
 }

variable_types: fileDescr int

variable_types:
buffer
char [11]

variable_types: numBytesWritten long


decompiled_code:
char *__fastcall build_failure_message(const char *a1)
{
char *v1; // rbx
int *v2; // rax
char *v3; // rax

v1 = (char *)malloc(0x64uLL);
v2 = __errno_location();
v3 = strerror(*v2);
if ( sprintf(v1, "%s: %s", a1, v3) < 0 )
v1 = "unable to sprintf";
return v1;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1)
{
char *v1; // rbx
int *v2; // rax
char *v3; // rax

v1 = (char *)malloc(0x64uLL);
v2 = __errno_location();
v3 = strerror(*v2);
if ( sprintf(v1, "%s: %s", a1, v3) < 0 )
v1 = "unable to sprintf";
return v1;
}

original_code:
static char* build_failure_message(const char* explanation)
{
     char* failing_assert=(char*)malloc(100*sizeof(char));
     if(sprintf(failing_assert, "%s: %s",
       explanation,
strerror((*__errno_location ())))<0)
{
       return "unable to sprintf";
}
return failing_assert;
}

canonical_original_code:
static char *build_failure_message(char *explanation)
{
     char *failing_assert = (char*)malloc(100*sizeof(char));
     if(sprintf(failing_assert, "%s: %s",
       explanation,
strerror((*__errno_location ())))<0)
{
       return "unable to sprintf";
}
return failing_assert;
}

variable_types:
explanation
char *


decompiled_code:
char *test_fseek()
{
int v0; // eax
int v1; // ebx
int buf; // [rsp+Ch] [rbp-Ch] BYREF

if ( writeFile() < 0 )
return build_failure_message("error in creating file");
v0 = open("input.bin", 0);
v1 = v0;
if ( v0 < 0 )
return build_failure_message("error in opening file");
buf = 0;
lseek(v0, 3LL, 0);
if ( read(v1, &buf, 4uLL) != 4 )
return build_failure_message("error in reading file");
printf(
"buffer content %i %i %i %i\n",
(unsigned int)(char)buf,
(unsigned int)SBYTE1(buf),
(unsigned int)SBYTE2(buf),
(unsigned int)SHIBYTE(buf));
if ( (_WORD)buf != 1281 || !BYTE2(buf) || !HIBYTE(buf) )
return build_failure_message("wrong content");
close(v1);
return 0LL;
}

canonical_decompiled_code:
char *func9()
{
int v0; // eax
int v1; // ebx
int buf; // [rsp+Ch] [rbp-Ch] BYREF

if ( func7() < 0 )
return func8("error in creating file");
v0 = open("input.bin", 0);
v1 = v0;
if ( v0 < 0 )
return func8("error in opening file");
buf = 0;
lseek(v0, 3LL, 0);
if ( read(v1, &buf, 4uLL) != 4 )
return func8("error in reading file");
printf(
"buffer content %i %i %i %i\n",
(unsigned int)(char)buf,
(unsigned int)SBYTE1(buf),
(unsigned int)SBYTE2(buf),
(unsigned int)SHIBYTE(buf));
if ( (_WORD)buf != 1281 || !BYTE2(buf) || !HIBYTE(buf) )
return func8("wrong content");
close(v1);
return 0LL;
}

original_code:
static char * test_fseek() {
     do { if (!(writeFile()>=0)) return build_failure_message("error in creating file"); } while (0);
     int fileDescr=open("input.bin", 00);
     do { if (!(fileDescr>=0)) return build_failure_message("error in opening file"); } while (0);
     char buffer[4];
     bzero(buffer, 4);
     lseek(fileDescr,3, 0);
     ssize_t bytesRead=read(fileDescr, buffer, 4);
     do { if (!(bytesRead==4)) return build_failure_message("error in reading file"); } while (0);
printf("buffer content %i %i %i %i\n", buffer[0], buffer[1], buffer[2],
buffer[3]);
do { if (!(buffer[0]==1 && buffer[1]==5 && buffer[2] && buffer[3])) return build_failure_message("wrong content"); } while (0);
     close(fileDescr);
     return 0;
 }

canonical_original_code:
static char *test_fseek() {
     do { if (!(writeFile()>=0)) return build_failure_message("error in creating file"); } while (0);
     int fileDescr = open("input.bin", 00);
     do { if (!(fileDescr>=0)) return build_failure_message("error in opening file"); } while (0);
     char buffer[4];
     bzero(buffer, 4);
     lseek(fileDescr,3, 0);
     long bytesRead = read(fileDescr, buffer, 4);
     do { if (!(bytesRead==4)) return build_failure_message("error in reading file"); } while (0);
printf("buffer content %i %i %i %i\n", buffer[0], buffer[1], buffer[2],
buffer[3]);
do { if (!(buffer[0]==1 && buffer[1]==5 && buffer[2] && buffer[3])) return build_failure_message("wrong content"); } while (0);
     close(fileDescr);
     return 0;
 }

variable_types:
buffer
char [4]

variable_types: bytesRead long


decompiled_code:
char *all_tests()
{
char *result; // rax

result = test_fseek();
++tests_run;
return result;
}

canonical_decompiled_code:
char *func10()
{
char *result; // rax

result = func9();
++tests_run;
return result;
}

original_code:
static char * all_tests() {
     do { char *message = test_fseek(); tests_run++; if (message) return message; } while (0);
     return 0;
 }

canonical_original_code:
static char *all_tests() {
     do { char *message = test_fseek(); tests_run++; if (message) return message; } while (0);
     return 0;
 }

variable_types:
message
char *


main

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

v3 = all_tests();
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

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

v3 = func10();
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

original_code:
int main(int argc, char **argv) {
     char *result = all_tests();
     if (result != 0) {
         printf("%s\n", result);
     }
     else {
         printf("ALL TESTS PASSED\n");
     }
     printf("Tests run: %d\n", tests_run);
     return result != 0;
 }

variable_types: argc int

variable_types:
argv
char **

variable_types:
result
char *


decompiled_code:
const char *test_foo()
{
const char *result; // rax

result = "error, foo != 7";
if ( foo == 7 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func7()
{
const char *result; // rax

result = "error, foo != 7";
if ( foo == 7 )
result = 0LL;
return result;
}

original_code:
static char * test_foo() {
     do { if (!(foo == 7)) return "error, foo != 7"; } while (0);
     return 0;
 }

canonical_original_code:
static char *test_foo() {
     do { if (!(foo == 7)) return "error, foo != 7"; } while (0);
     return 0;
 }


decompiled_code:
const char *test_bar()
{
const char *result; // rax

result = "error, bar != 5";
if ( bar == 5 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func8()
{
const char *result; // rax

result = "error, bar != 5";
if ( bar == 5 )
result = 0LL;
return result;
}

original_code:
static char * test_bar() {
     do { if (!(bar == 5)) return "error, bar != 5"; } while (0);
     return 0;
 }

canonical_original_code:
static char *test_bar() {
     do { if (!(bar == 5)) return "error, bar != 5"; } while (0);
     return 0;
 }


decompiled_code:
const char *all_tests()
{
const char *result; // rax
int v1; // ebx

result = test_foo();
v1 = tests_run++;
if ( !result )
{
result = test_bar();
tests_run = v1 + 2;
}
return result;
}

canonical_decompiled_code:
const char *func9()
{
const char *result; // rax
int v1; // ebx

result = func7();
v1 = tests_run++;
if ( !result )
{
result = func8();
tests_run = v1 + 2;
}
return result;
}

original_code:
static char * all_tests() {
     do { char *message = test_foo(); tests_run++; if (message) return message; } while (0);
     do { char *message = test_bar(); tests_run++; if (message) return message; } while (0);
     return 0;
 }

canonical_original_code:
static char *all_tests() {
     do { char *message = test_foo(); tests_run++; if (message) return message; } while (0);
     do { char *message = test_bar(); tests_run++; if (message) return message; } while (0);
     return 0;
 }


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

v3 = all_tests();
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

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

v3 = func9();
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

canonical_original_code:
int main(int argc, char **argv) {
     char *result = all_tests();
     if (result != 0) {
         printf("%s\n", result);
     }
     else {
         printf("ALL TESTS PASSED\n");
     }
     printf("Tests run: %d\n", tests_run);
     return result != 0;
 }


decompiled_code:
const char *get_string()
{
return "get_string\n";
}

canonical_decompiled_code:
const char *func7()
{
return "get_string\n";
}

original_code:
char* get_string()
{
  return "get_string\n";
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

puts("Ciao");
v3 = get_string();
printf("%s", v3);
strcpy(v5, v3);
printf("%s", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

puts("Ciao");
v3 = func7();
printf("%s", v3);
strcpy(v5, v3);
printf("%s", v5);
return 0;
}

original_code:
int main(int argc, char **argv) {
  printf("Ciao\n");
  printf("%s", get_string());
  char fmt[50];
  sprintf(fmt, "%s",get_string());
  printf("%s",fmt);
  return 0;
 }

variable_types:
fmt
char [50]


repo: eeezyy/FileTransfer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
__int16 v4; // ax
char *v5; // rax
int v6; // eax
size_t v7; // rdx
char *v8; // rax
size_t v9; // rax
int v10; // eax
size_t v12; // rax
size_t v13; // rax
size_t v14; // rax
size_t v15; // rax
int v16; // ebp
char *v17; // rsi
size_t v18; // rax
int v19; // eax
__int64 v20; // rax
__int64 v21; // r12
size_t v22; // rax
bool v23; // zf
int v24; // er14
int v25; // eax
int v26; // er13
size_t v27; // rax
int i; // er15
size_t v29; // rax
int v30; // er14
int v31; // eax
int v32; // er13
int j; // ebp
__off_t v34; // r14
size_t v35; // rax
__off_t v36; // r13
__int64 v37; // r15
size_t v38; // rax
double v39; // xmm0_8
double v40; // xmm1_8
int v41; // er12
__int64 v42; // rbp
int k; // ebp
int v44; // er14
int v45; // eax
int v46; // er13
int v47; // [rsp+4h] [rbp-30F4h]
int v48; // [rsp+8h] [rbp-30F0h]
int v49; // [rsp+8h] [rbp-30F0h]
int fd; // [rsp+Ch] [rbp-30ECh]
int fda; // [rsp+Ch] [rbp-30ECh]
FILE *s; // [rsp+10h] [rbp-30E8h]
int v53; // [rsp+18h] [rbp-30E0h]
struct stat v54; // [rsp+20h] [rbp-30D8h] BYREF
char file[8]; // [rsp+B0h] [rbp-3048h] BYREF
__int64 v56; // [rsp+B8h] [rbp-3040h]
char v57[1008]; // [rsp+C0h] [rbp-3038h] BYREF
char nptr[2048]; // [rsp+4B0h] [rbp-2C48h] BYREF
char v59[2048]; // [rsp+CB0h] [rbp-2448h] BYREF
char filename[8]; // [rsp+14B0h] [rbp-1C48h] BYREF
__int64 v61; // [rsp+14B8h] [rbp-1C40h]
char v62[1008]; // [rsp+14C0h] [rbp-1C38h] BYREF
char dest[8]; // [rsp+1CB0h] [rbp-1448h] BYREF
__int64 v64; // [rsp+1CB8h] [rbp-1440h]
char v65[2032]; // [rsp+1CC0h] [rbp-1438h] BYREF
char v66[1024]; // [rsp+24B0h] [rbp-C48h] BYREF
struct sockaddr inp; // [rsp+28B0h] [rbp-848h] BYREF
int buf[526]; // [rsp+28C0h] [rbp-838h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "Usage: %s IP-Adresse Port-Nummer\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("Socket error");
v47 = 1;
}
else
{
v4 = strtol(argv[2], 0LL, 10);
*(_QWORD *)&inp.sa_family = 2LL;
*(_QWORD *)&inp.sa_data[6] = 0LL;
*(_WORD *)inp.sa_data = _bswap_16(v4);
inet_aton(argv[1], (struct in_addr *)&inp.sa_data[2]);
v47 = connect(v3, &inp, 0x10u);
if ( v47 )
{
perror("Connect error - no server available");
v47 = 1;
}
else
{
v5 = inet_ntoa(*(struct in_addr *)&inp.sa_data[2]);
printf("Connection with server(%s) established\n", v5);
v6 = recv(v3, buf, 0x7FFuLL, 0);
if ( v6 > 0 )
{
*((_BYTE *)buf + v6) = 0;
printf("%s", (const char *)buf);
}
printf("Username: ");
fgets((char *)buf, 2047, stdin);
v7 = strlen((const char *)buf);
if ( v7 <= 1 )
{
strcpy((char *)buf, "null");
v12 = strlen((const char *)buf);
send(v3, buf, v12, 0);
v13 = strlen((const char *)buf);
send(v3, buf, v13, 0);
close(v3);
fwrite("User invalid\n", 1uLL, 0xDuLL, stderr);
v47 = 1;
}
else
{
send(v3, buf, v7, 0);
v8 = getpass("Password: ");
strcpy((char *)buf, v8);
if ( LOBYTE(buf[0]) )
{
v9 = strlen((const char *)buf);
send(v3, buf, v9, 0);
v10 = recv(v3, buf, 0x7FFuLL, 0);
if ( v10 > 0 )
{
*((_BYTE *)buf + v10) = 0;
puts((const char *)buf);
}
if ( strcmp((const char *)buf, "Username or password invalid\n")
&& strcmp((const char *)buf, "User is blocked!\n") )
{
while ( 1 )
{
LABEL_31:
printf("Send command: ");
fgets((char *)buf, 2047, stdin);
if ( !memcmp(buf, "list", 4uLL) )
{
v16 = 1;
goto LABEL_23;
}
if ( !memcmp(buf, "get", 3uLL) )
break;
if ( memcmp(buf, "send", 4uLL) )
{
if ( !memcmp(buf, "blocklist", 9uLL) )
{
v16 = 4;
}
else
{
v23 = memcmp(buf, "quit", 4uLL) == 0;
v16 = !v23;
if ( !v23 )
continue;
}
goto LABEL_23;
}
*(_QWORD *)dest = 0LL;
v64 = 0LL;
memset(v65, 0, sizeof(v65));
v15 = strlen((const char *)buf);
v16 = 3;
if ( v15 != 4 )
{
strncpy(dest, (const char *)&buf[1], v15 - 4);
v17 = strtok(dest, " \n\r");
if ( !v17 )
continue;
LABEL_22:
strcpy(v66, v17);
}
LABEL_23:
v18 = strlen((const char *)buf);
send(v3, buf, v18, 0);
v19 = recv(v3, nptr, 0x7FFuLL, 0);
if ( v19 > 0 )
nptr[v19] = 0;
v20 = strtol(nptr, 0LL, 10);
v21 = v20;
if ( v20 == -1 )
{
if ( v16 == 2 )
puts("File not found!");
goto LABEL_30;
}
if ( v16 == 1 )
{
send(v3, buf, 1uLL, 0);
if ( v21 <= 0 )
goto LABEL_52;
v24 = 0;
while ( 1 )
{
v25 = recv(v3, buf, 0x7FFuLL, 0);
v26 = v25;
if ( v25 > 0 )
{
*((_BYTE *)buf + v25) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
}
else
{
if ( !v25 )
{
puts("connect to socket failed");
goto LABEL_52;
}
if ( v25 == -1 )
puts("error in socket");
}
v24 += v26;
if ( v24 >= v21 )
goto LABEL_52;
}
}
if ( v16 == 2 )
{
printf("Size of selected File is %ld bytes\nDo you want to download the file? (y/n)", v20);
while ( 1 )
{
fgets((char *)buf, 2047, stdin);
if ( LOBYTE(buf[0]) == 121 )
break;
if ( LOBYTE(buf[0]) == 110 )
{
LOWORD(buf[0]) = 110;
v29 = strlen((const char *)buf);
send(v3, buf, v29, 0);
goto LABEL_30;
}
printf("Invalid input. (y/n) ");
}
LOWORD(buf[0]) = 121;
v27 = strlen((const char *)buf);
send(v3, buf, v27, 0);
*(_QWORD *)filename = 12078LL;
v61 = 0LL;
memset(v62, 0, sizeof(v62));
strcat(filename, v66);
s = fopen(filename, "wb");
v48 = 0;
fd = v3;
for ( i = v21; ; i -= v32 )
{
if ( i <= 0 )
{
v16 = 2;
v3 = fd;
goto LABEL_97;
}
*(_QWORD *)dest = 0LL;
v64 = 0LL;
memset(v65, 0, sizeof(v65));
v31 = recv(fd, dest, 0x7FFuLL, 0);
v32 = v31;
if ( v31 > 0 )
{
fwrite(dest, 1uLL, v31, s);
}
else
{
if ( !v31 )
{
v16 = 2;
v3 = fd;
puts("connect to socket failed");
goto LABEL_97;
}
if ( v31 == -1 )
{
v16 = 2;
v3 = fd;
puts("error in socket");
goto LABEL_97;
}
}
v30 = (int)((double)(v32 + (int)v21 - i) / (double)(int)v21 * 20.0) - v48;
if ( v30 >= 0 )
{
if ( v30 > 0 )
{
for ( j = 0; j != v30; ++j )
{
putchar(35);
fflush(stdout);
}
v48 = (int)((double)(v32 + (int)v21 - i) / (double)(int)v21 * 20.0);
}
if ( v48 == 20 )
puts("!");
}
}
}
if ( v16 == 3 )
{
*(_QWORD *)file = 12078LL;
v56 = 0LL;
memset(v57, 0, sizeof(v57));
strcat(file, v66);
if ( stat(file, &v54) == -1 )
{
sprintf(v59, "%ld", -1LL);
v38 = strlen(v59);
send(v3, v59, v38, 0);
puts("File not found!");
goto LABEL_30;
}
v34 = v54.st_size;
sprintf(v59, "%ld", v54.st_size);
v35 = strlen(v59);
send(v3, v59, v35, 0);
recv(v3, filename, 1uLL, 0);
s = fopen(file, "rb");
if ( !s )
{
puts("can't open file");
goto LABEL_30;
}
if ( (int)v34 > 0 )
{
v36 = v34 - (int)v34;
v49 = 0;
fda = 2047;
v53 = v3;
v37 = v34;
do
{
if ( (int)v34 <= 2046 )
fda = (int)v34 % 2047;
fread(dest, fda, 1uLL, s);
send(v53, dest, fda, 0);
v42 = v36 + fda;
if ( v42 < 0 )
v39 = (double)(int)(v42 & 1 | ((unsigned __int64)v42 >> 1))
+ (double)(int)(v42 & 1 | ((unsigned __int64)v42 >> 1));
else
v39 = (double)(int)v42;
if ( v37 < 0 )
v40 = (double)(int)(v37 & 1 | ((unsigned __int64)v37 >> 1))
+ (double)(int)(v37 & 1 | ((unsigned __int64)v37 >> 1));
else
v40 = (double)(int)v37;
v41 = (int)(v39 / v40 * 20.0) - v49;
if ( v41 >= 0 )
{
if ( v41 > 0 )
{
for ( k = 0; k != v41; ++k )
{
putchar(35);
fflush(stdout);
}
v49 = (int)(v39 / v40 * 20.0);
}
if ( v49 == 20 )
puts("!");
}
LODWORD(v34) = v34 - 2047;
v36 += 2047LL;
}
while ( (int)v34 > 0 );
v16 = 3;
v3 = v53;
}
LABEL_97:
putchar(10);
fclose(s);
goto LABEL_30;
}
if ( v16 != 4 )
goto LABEL_30;
send(v3, buf, 1uLL, 0);
if ( v21 <= 0 )
goto LABEL_52;
v44 = 0;
while ( 1 )
{
v45 = recv(v3, buf, 0x7FFuLL, 0);
v46 = v45;
if ( v45 <= 0 )
break;
*((_BYTE *)buf + v45) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
LABEL_102:
v44 += v46;
if ( v44 >= v21 )
goto LABEL_52;
}
if ( v45 )
{
if ( v45 == -1 )
puts("error in socket");
goto LABEL_102;
}
puts("connect to socket failed");
LABEL_52:
putchar(10);
LABEL_30:
if ( !v16 )
goto LABEL_109;
}
*(_QWORD *)dest = 0LL;
v64 = 0LL;
memset(v65, 0, sizeof(v65));
v22 = strlen((const char *)buf);
v16 = 2;
if ( v22 == 3 )
goto LABEL_23;
strncpy(dest, (const char *)buf + 3, v22 - 3);
v17 = strtok(dest, " \n\r");
if ( !v17 )
goto LABEL_31;
goto LABEL_22;
}
LABEL_109:
close(v3);
}
else
{
strcpy((char *)buf, "null");
v14 = strlen((const char *)buf);
send(v3, buf, v14, 0);
close(v3);
fwrite("User or password invalid\n", 1uLL, 0x19uLL, stderr);
v47 = 1;
}
}
}
}
return v47;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
__int16 v4; // ax
char *v5; // rax
int v6; // eax
size_t v7; // rdx
char *v8; // rax
size_t v9; // rax
int v10; // eax
size_t v12; // rax
size_t v13; // rax
size_t v14; // rax
size_t v15; // rax
int v16; // ebp
char *v17; // rsi
size_t v18; // rax
int v19; // eax
__int64 v20; // rax
__int64 v21; // r12
size_t v22; // rax
bool v23; // zf
int v24; // er14
int v25; // eax
int v26; // er13
size_t v27; // rax
int i; // er15
size_t v29; // rax
int v30; // er14
int v31; // eax
int v32; // er13
int j; // ebp
__off_t v34; // r14
size_t v35; // rax
__off_t v36; // r13
__int64 v37; // r15
size_t v38; // rax
double v39; // xmm0_8
double v40; // xmm1_8
int v41; // er12
__int64 v42; // rbp
int k; // ebp
int v44; // er14
int v45; // eax
int v46; // er13
int v47; // [rsp+4h] [rbp-30F4h]
int v48; // [rsp+8h] [rbp-30F0h]
int v49; // [rsp+8h] [rbp-30F0h]
int fd; // [rsp+Ch] [rbp-30ECh]
int fda; // [rsp+Ch] [rbp-30ECh]
FILE *s; // [rsp+10h] [rbp-30E8h]
int v53; // [rsp+18h] [rbp-30E0h]
struct stat v54; // [rsp+20h] [rbp-30D8h] BYREF
char file[8]; // [rsp+B0h] [rbp-3048h] BYREF
__int64 v56; // [rsp+B8h] [rbp-3040h]
char v57[1008]; // [rsp+C0h] [rbp-3038h] BYREF
char nptr[2048]; // [rsp+4B0h] [rbp-2C48h] BYREF
char v59[2048]; // [rsp+CB0h] [rbp-2448h] BYREF
char filename[8]; // [rsp+14B0h] [rbp-1C48h] BYREF
__int64 v61; // [rsp+14B8h] [rbp-1C40h]
char v62[1008]; // [rsp+14C0h] [rbp-1C38h] BYREF
char dest[8]; // [rsp+1CB0h] [rbp-1448h] BYREF
__int64 v64; // [rsp+1CB8h] [rbp-1440h]
char v65[2032]; // [rsp+1CC0h] [rbp-1438h] BYREF
char v66[1024]; // [rsp+24B0h] [rbp-C48h] BYREF
struct sockaddr inp; // [rsp+28B0h] [rbp-848h] BYREF
int buf[526]; // [rsp+28C0h] [rbp-838h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "Usage: %s IP-Adresse Port-Nummer\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("Socket error");
v47 = 1;
}
else
{
v4 = strtol(argv[2], 0LL, 10);
*(_QWORD *)&inp.sa_family = 2LL;
*(_QWORD *)&inp.sa_data[6] = 0LL;
*(_WORD *)inp.sa_data = func0(v4);
inet_aton(argv[1], (struct in_addr *)&inp.sa_data[2]);
v47 = connect(v3, &inp, 0x10u);
if ( v47 )
{
perror("Connect error - no server available");
v47 = 1;
}
else
{
v5 = inet_ntoa(*(struct in_addr *)&inp.sa_data[2]);
printf("Connection with server(%s) established\n", v5);
v6 = recv(v3, buf, 0x7FFuLL, 0);
if ( v6 > 0 )
{
*((_BYTE *)buf + v6) = 0;
printf("%s", (const char *)buf);
}
printf("Username: ");
fgets((char *)buf, 2047, stdin);
v7 = strlen((const char *)buf);
if ( v7 <= 1 )
{
strcpy((char *)buf, "null");
v12 = strlen((const char *)buf);
send(v3, buf, v12, 0);
v13 = strlen((const char *)buf);
send(v3, buf, v13, 0);
close(v3);
fwrite("User invalid\n", 1uLL, 0xDuLL, stderr);
v47 = 1;
}
else
{
send(v3, buf, v7, 0);
v8 = getpass("Password: ");
strcpy((char *)buf, v8);
if ( LOBYTE(buf[0]) )
{
v9 = strlen((const char *)buf);
send(v3, buf, v9, 0);
v10 = recv(v3, buf, 0x7FFuLL, 0);
if ( v10 > 0 )
{
*((_BYTE *)buf + v10) = 0;
puts((const char *)buf);
}
if ( strcmp((const char *)buf, "Username or password invalid\n")
&& strcmp((const char *)buf, "User is blocked!\n") )
{
while ( 1 )
{
LABEL_31:
printf("Send command: ");
fgets((char *)buf, 2047, stdin);
if ( !memcmp(buf, "list", 4uLL) )
{
v16 = 1;
goto LABEL_23;
}
if ( !memcmp(buf, "get", 3uLL) )
break;
if ( memcmp(buf, "send", 4uLL) )
{
if ( !memcmp(buf, "blocklist", 9uLL) )
{
v16 = 4;
}
else
{
v23 = memcmp(buf, "quit", 4uLL) == 0;
v16 = !v23;
if ( !v23 )
continue;
}
goto LABEL_23;
}
*(_QWORD *)dest = 0LL;
v64 = 0LL;
memset(v65, 0, sizeof(v65));
v15 = strlen((const char *)buf);
v16 = 3;
if ( v15 != 4 )
{
strncpy(dest, (const char *)&buf[1], v15 - 4);
v17 = strtok(dest, " \n\r");
if ( !v17 )
continue;
LABEL_22:
strcpy(v66, v17);
}
LABEL_23:
v18 = strlen((const char *)buf);
send(v3, buf, v18, 0);
v19 = recv(v3, nptr, 0x7FFuLL, 0);
if ( v19 > 0 )
nptr[v19] = 0;
v20 = strtol(nptr, 0LL, 10);
v21 = v20;
if ( v20 == -1 )
{
if ( v16 == 2 )
puts("File not found!");
goto LABEL_30;
}
if ( v16 == 1 )
{
send(v3, buf, 1uLL, 0);
if ( v21 <= 0 )
goto LABEL_52;
v24 = 0;
while ( 1 )
{
v25 = recv(v3, buf, 0x7FFuLL, 0);
v26 = v25;
if ( v25 > 0 )
{
*((_BYTE *)buf + v25) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
}
else
{
if ( !v25 )
{
puts("connect to socket failed");
goto LABEL_52;
}
if ( v25 == -1 )
puts("error in socket");
}
v24 += v26;
if ( v24 >= v21 )
goto LABEL_52;
}
}
if ( v16 == 2 )
{
printf("Size of selected File is %ld bytes\nDo you want to download the file? (y/n)", v20);
while ( 1 )
{
fgets((char *)buf, 2047, stdin);
if ( LOBYTE(buf[0]) == 121 )
break;
if ( LOBYTE(buf[0]) == 110 )
{
LOWORD(buf[0]) = 110;
v29 = strlen((const char *)buf);
send(v3, buf, v29, 0);
goto LABEL_30;
}
printf("Invalid input. (y/n) ");
}
LOWORD(buf[0]) = 121;
v27 = strlen((const char *)buf);
send(v3, buf, v27, 0);
*(_QWORD *)filename = 12078LL;
v61 = 0LL;
memset(v62, 0, sizeof(v62));
strcat(filename, v66);
s = fopen(filename, "wb");
v48 = 0;
fd = v3;
for ( i = v21; ; i -= v32 )
{
if ( i <= 0 )
{
v16 = 2;
v3 = fd;
goto LABEL_97;
}
*(_QWORD *)dest = 0LL;
v64 = 0LL;
memset(v65, 0, sizeof(v65));
v31 = recv(fd, dest, 0x7FFuLL, 0);
v32 = v31;
if ( v31 > 0 )
{
fwrite(dest, 1uLL, v31, s);
}
else
{
if ( !v31 )
{
v16 = 2;
v3 = fd;
puts("connect to socket failed");
goto LABEL_97;
}
if ( v31 == -1 )
{
v16 = 2;
v3 = fd;
puts("error in socket");
goto LABEL_97;
}
}
v30 = (int)((double)(v32 + (int)v21 - i) / (double)(int)v21 * 20.0) - v48;
if ( v30 >= 0 )
{
if ( v30 > 0 )
{
for ( j = 0; j != v30; ++j )
{
putchar(35);
fflush(stdout);
}
v48 = (int)((double)(v32 + (int)v21 - i) / (double)(int)v21 * 20.0);
}
if ( v48 == 20 )
puts("!");
}
}
}
if ( v16 == 3 )
{
*(_QWORD *)file = 12078LL;
v56 = 0LL;
memset(v57, 0, sizeof(v57));
strcat(file, v66);
if ( stat(file, &v54) == -1 )
{
sprintf(v59, "%ld", -1LL);
v38 = strlen(v59);
send(v3, v59, v38, 0);
puts("File not found!");
goto LABEL_30;
}
v34 = v54.st_size;
sprintf(v59, "%ld", v54.st_size);
v35 = strlen(v59);
send(v3, v59, v35, 0);
recv(v3, filename, 1uLL, 0);
s = fopen(file, "rb");
if ( !s )
{
puts("can't open file");
goto LABEL_30;
}
if ( (int)v34 > 0 )
{
v36 = v34 - (int)v34;
v49 = 0;
fda = 2047;
v53 = v3;
v37 = v34;
do
{
if ( (int)v34 <= 2046 )
fda = (int)v34 % 2047;
fread(dest, fda, 1uLL, s);
send(v53, dest, fda, 0);
v42 = v36 + fda;
if ( v42 < 0 )
v39 = (double)(int)(v42 & 1 | ((unsigned __int64)v42 >> 1))
+ (double)(int)(v42 & 1 | ((unsigned __int64)v42 >> 1));
else
v39 = (double)(int)v42;
if ( v37 < 0 )
v40 = (double)(int)(v37 & 1 | ((unsigned __int64)v37 >> 1))
+ (double)(int)(v37 & 1 | ((unsigned __int64)v37 >> 1));
else
v40 = (double)(int)v37;
v41 = (int)(v39 / v40 * 20.0) - v49;
if ( v41 >= 0 )
{
if ( v41 > 0 )
{
for ( k = 0; k != v41; ++k )
{
putchar(35);
fflush(stdout);
}
v49 = (int)(v39 / v40 * 20.0);
}
if ( v49 == 20 )
puts("!");
}
LODWORD(v34) = v34 - 2047;
v36 += 2047LL;
}
while ( (int)v34 > 0 );
v16 = 3;
v3 = v53;
}
LABEL_97:
putchar(10);
fclose(s);
goto LABEL_30;
}
if ( v16 != 4 )
goto LABEL_30;
send(v3, buf, 1uLL, 0);
if ( v21 <= 0 )
goto LABEL_52;
v44 = 0;
while ( 1 )
{
v45 = recv(v3, buf, 0x7FFuLL, 0);
v46 = v45;
if ( v45 <= 0 )
break;
*((_BYTE *)buf + v45) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
LABEL_102:
v44 += v46;
if ( v44 >= v21 )
goto LABEL_52;
}
if ( v45 )
{
if ( v45 == -1 )
puts("error in socket");
goto LABEL_102;
}
puts("connect to socket failed");
LABEL_52:
putchar(10);
LABEL_30:
if ( !v16 )
goto LABEL_109;
}
*(_QWORD *)dest = 0LL;
v64 = 0LL;
memset(v65, 0, sizeof(v65));
v22 = strlen((const char *)buf);
v16 = 2;
if ( v22 == 3 )
goto LABEL_23;
strncpy(dest, (const char *)buf + 3, v22 - 3);
v17 = strtok(dest, " \n\r");
if ( !v17 )
goto LABEL_31;
goto LABEL_22;
}
LABEL_109:
close(v3);
}
else
{
strcpy((char *)buf, "null");
v14 = strlen((const char *)buf);
send(v3, buf, v14, 0);
close(v3);
fwrite("User or password invalid\n", 1uLL, 0x19uLL, stderr);
v47 = 1;
}
}
}
}
return v47;
}

original_code:
int main(int argc, char **argv) {
 int sockFd, connFd;
 socklen_t addrlen;
 struct sockaddr_in address, cliaddress;
 long port;
 struct thrdData* data;
 pthread_t socketThread;
 if(argc < 2) {
  fprintf(stderr, "USAGE: %s PORT Directory\n", argv[0]);
  return 1;
 }
 if(argc == 3) {
  strcpy(dirname, argv[2]);
  if(opendir(dirname) == ((void *)0)) {
   fprintf(stderr, "%s: %s is not a directory!\n", argv[0], argv[2]);
   return 1;
  }
 } else {
  getcwd(dirname, sizeof(dirname));
 }
 port = strtol(argv[1], ((void *)0), 10);
 sockFd = socket(2, SOCK_STREAM, 0);
 memset(&address,0,sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 address.sin_port = htons(port);
 if(bind( sockFd,(struct sockaddr *) &address, sizeof(address)) != 0) {
  perror("bind error");
  return 1;
 }
 listen(sockFd, 5);
 addrlen = sizeof(struct sockaddr_in);
 while(1) {
  printf("Waiting for connections...\n");
  connFd = accept( sockFd,(struct sockaddr *) &cliaddress, &addrlen );
  if(connFd > 0) {
   printf("Client connected from %s:%d...\n", inet_ntoa(cliaddress.sin_addr),ntohs(cliaddress.sin_port));
   data =(struct thrdData*)malloc(sizeof(struct thrdData));
   strcpy(data->ipAddress,inet_ntoa(cliaddress.sin_addr));
   data->socket = connFd;
   pthread_create(&socketThread,((void *)0),session,(void*)data);
   }
   else {
   printf("Error with accept \n");
   return 1;
  }
 }
 close(sockFd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int sockFd; int connFd;
 unsigned int addrlen;
 struct sockaddr_in address; struct sockaddr_in cliaddress;
 long port;
 struct thrdData *data;
 unsigned long socketThread;
 if(argc < 2) {
  fprintf(stderr, "USAGE: %s PORT Directory\n", argv[0]);
  return 1;
 }
 if(argc == 3) {
  strcpy(dirname, argv[2]);
  if(opendir(dirname) == ((void *)0)) {
   fprintf(stderr, "%s: %s is not a directory!\n", argv[0], argv[2]);
   return 1;
  }
 } else {
  getcwd(dirname, sizeof(dirname));
 }
 port = strtol(argv[1], ((void *)0), 10);
 sockFd = socket(2, SOCK_STREAM, 0);
 memset(&address,0,sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = ((unsigned int) 0x00000000);
 address.sin_port = htons(port);
 if(bind( sockFd,(struct sockaddr *) &address, sizeof(address)) != 0) {
  perror("bind error");
  return 1;
 }
 listen(sockFd, 5);
 addrlen = sizeof(struct sockaddr_in);
 while(1) {
  printf("Waiting for connections...\n");
  connFd = accept( sockFd,(struct sockaddr *) &cliaddress, &addrlen );
  if(connFd > 0) {
   printf("Client connected from %s:%d...\n", inet_ntoa(cliaddress.sin_addr),ntohs(cliaddress.sin_port));
   data =(struct thrdData *)malloc(sizeof(struct thrdData));
   strcpy(data->ipAddress,inet_ntoa(cliaddress.sin_addr));
   data->socket = connFd;
   pthread_create(&socketThread,((void *)0),session,(void *)data);
   }
   else {
   printf("Error with accept \n");
   return 1;
  }
 }
 close(sockFd);
 return 0;
}

variable_types: sockFd int

variable_types: connFd int

variable_types:
addrlen
unsigned int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: port long

variable_types: struct thrdData { char ipAddress[16]; int socket; } *

variable_types:
socketThread
unsigned long


repo: eerpini/N-way-Pipe

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // rsp
int *v5; // r14
int *v6; // r13
int *v7; // rbx
int *v8; // rsi
const char **v9; // rbx
__int64 v10; // rbx
int *v11; // rsi
int v12; // ebx
unsigned __int64 v13; // r14
int *v14; // r12
__int64 *v15; // r13
int *v16; // rbx
int *v17; // r12
int *v18; // rbx
int v20; // [rsp+0h] [rbp-70h] BYREF
__int64 v21; // [rsp+8h] [rbp-68h] BYREF
unsigned __int64 v22; // [rsp+10h] [rbp-60h] BYREF
char **argva; // [rsp+18h] [rbp-58h]
__int64 v24; // [rsp+20h] [rbp-50h]
int v25; // [rsp+2Ch] [rbp-44h]
char buf; // [rsp+37h] [rbp-39h] BYREF
__WAIT_STATUS stat_loc; // [rsp+38h] [rbp-38h] BYREF

v25 = argc;
if ( argc <= 2 )
{
fwrite("Invalid args\n", 1uLL, 0xDuLL, _bss_start);
v12 = 1;
}
else
{
stat_loc.__uptr = 0LL;
v4 = alloca(8LL * (v25 - 1));
v22 = ((unsigned __int64)&v20 + 3) >> 2;
buf = 0;
v5 = &v20;
v6 = &v20 + 2 * (unsigned int)(v25 - 1);
v7 = &v20;
do
{
if ( pipe(v7) < 0 )
{
perror("pipe");
exit(1);
}
v7 += 2;
}
while ( v7 != v6 );
v8 = break_by_spaces((char *)argv[1], (_DWORD *)&stat_loc.__iptr + 1);
if ( v8 )
{
v9 = (const char **)build_argv((__int64)argv[1], v8, SHIDWORD(stat_loc.__iptr));
if ( !fork() )
{
if ( dup2(*(_DWORD *)(4 * v22 + 4), 1) != -1 )
{
v13 = v22;
close(*(_DWORD *)(4 * v22));
close(*(_DWORD *)(4 * v13 + 4));
v14 = (int *)&v21;
v15 = (__int64 *)(&v22 + (unsigned int)(v25 - 3));
do
{
close(*v14);
close(v14[1]);
v14 += 2;
}
while ( v15 != (__int64 *)v14 );
if ( execvp(*v9, (char *const *)v9) != -1 )
exit(1);
perror("execvp");
exit(1);
}
perror("dup2");
exit(1);
}
v21 = (unsigned int)(v25 - 3);
v24 = (unsigned int)(v25 - 1);
v10 = 1LL;
while ( 1 )
{
v25 = v10;
HIDWORD(stat_loc.__iptr) = 0;
v11 = break_by_spaces((char *)argv[v10 + 1], (_DWORD *)&stat_loc.__iptr + 1);
if ( !v11 )
break;
argva = (char **)build_argv((__int64)argv[v10 + 1], v11, SHIDWORD(stat_loc.__iptr));
if ( !fork() )
{
v16 = &v20;
if ( dup2(*(&v20 + 2 * v25), 0) == -1 )
{
perror("dup2");
exit(1);
}
do
{
close(*v16);
close(v16[1]);
v16 += 2;
}
while ( v16 != v6 );
if ( execvp(*argva, argva) == -1 )
{
perror("execvp");
exit(1);
}
LABEL_26:
close(*(_DWORD *)(4 * v22 + 4));
v25 += 2;
v17 = &v20 + 2 * v21 + 5;
while ( 1 )
{
v12 = read(v20, &buf, 1uLL);
if ( !v12 )
break;
v18 = (int *)&v21 + 1;
do
{
write(*v18, &buf, 1uLL);
v18 += 2;
}
while ( v18 != v17 );
}
do
{
close(*v5);
close(v5[1]);
v5 += 2;
}
while ( v5 != v6 );
do
{
wait((__WAIT_STATUS)&stat_loc);
--v25;
}
while ( v25 > 0 );
return v12;
}
if ( ++v10 == v24 )
goto LABEL_26;
}
}
fwrite("Cannot exec program specified as first arg\n", 1uLL, 0x2BuLL, _bss_start);
v12 = 1;
}
return v12;
}

original_code:
int main(int argc, char *argv[]){
        char buf = 0;
        if(argc == 1){
                while(read(0, &buf, 1)){
                        write(1, &buf, 1);
                }
        }
        else{
                if(argc > 2){
                        fprintf(stderr, "Usage : %s [filename]\n", argv[0]);
                }
                int fd = open(argv[1], 0100|02, 0400|0200|(0400 >> 3)|(0200 >> 3));
                while(read(0, &buf, 1)){
                        write(fd, &buf, 1);
                }
                close(fd);
        }
        return 0;
}

variable_types:
argv
char *[]

variable_types: buf char

variable_types: fd int


getfile

repo: efficient/ffbf

decompiled_code:
__int64 __fastcall getfile(char *s, __off_t *a2)
{
int v2; // eax
unsigned int v3; // ebx
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(s, 0);
if ( v2 < 0 )
{
perror(s);
exit(-1);
}
v3 = v2;
if ( fstat(v2, &v5) < 0 )
{
perror("fstat");
exit(-1);
}
*a2 = v5.st_size;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, __off_t *a2)
{
int v2; // eax
unsigned int v3; // ebx
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(s, 0);
if ( v2 < 0 )
{
perror(s);
exit(-1);
}
v3 = v2;
if ( fstat(v2, &v5) < 0 )
{
perror("fstat");
exit(-1);
}
*a2 = v5.st_size;
return v3;
}

original_code:
int getfile(char *infile, size_t *filesize) {
    int f;
    if ((f = open(infile, 00)) < 0) {
      perror(infile);
      exit(-1);
    }
    struct stat sb;
    if (fstat(f, &sb) < 0) {
      perror("fstat");
      exit(-1);
    }
    *filesize = sb.st_size;
    return f;
}

canonical_original_code:
int getfile(char *infile, unsigned long *filesize) {
    int f;
    if ((f = open(infile, 00)) < 0) {
      perror(infile);
      exit(-1);
    }
    struct stat sb;
    if (fstat(f, &sb) < 0) {
      perror("fstat");
      exit(-1);
    }
    *filesize = sb.st_size;
    return f;
}

variable_types:
infile
char *

variable_types:
filesize
unsigned long *

variable_types: f int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


sighandler

repo: efficios/memleak-finder

decompiled_code:
void sighandler()
{
malloc_stats();
}

canonical_decompiled_code:
void func6()
{
malloc_stats();
}

original_code:
static void sighandler(int signo, siginfo_t *siginfo, void *context)
{
 malloc_stats();
}

canonical_original_code:
static void sighandler(int signo, struct siginfo_t *siginfo, void *context)
{
 malloc_stats();
}

variable_types: signo int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
context
void *

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int print_stats_init()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sighandler;
v1.sa_flags = 268435460;
sigemptyset(&v1.sa_mask);
result = sigaction(12, &v1, 0LL);
if ( result )
__assert_fail("!ret", "malloc-stats.c", 0x30u, "print_stats_init");
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sighandler;
v1.sa_flags = 268435460;
sigemptyset(&v1.sa_mask);
result = sigaction(12, &v1, 0LL);
if ( result )
__assert_fail("!ret", "malloc-stats.c", 0x30u, "print_stats_init");
return result;
}

original_code:
static __attribute__((constructor))
void print_stats_init(void)
{
 struct sigaction act;
 int ret;
 act.__sigaction_handler.sa_sigaction = sighandler;
 act.sa_flags = 4 | 0x10000000;
 sigemptyset(&act.sa_mask);
 ret = sigaction(12, &act, ((void *)0));
 ((void) sizeof ((!ret) ? 1 : 0), __extension__ ({ if (!ret) ; else __assert_fail ("!ret", "malloc-stats.c", 48, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void print_stats_init()
{
 struct sigaction act;
 int ret;
 act.__sigaction_handler.sa_sigaction = sighandler;
 act.sa_flags = 4 | 0x10000000;
 sigemptyset(&act.sa_mask);
 ret = sigaction(12, &act, ((void *)0));
 ((void) sizeof ((!ret) ? 1 : 0), __extension__ ({ if (!ret) ; else __assert_fail ("!ret", "malloc-stats.c", 48, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: ret int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }


getch

repo: efficios/urcu-tutorial

decompiled_code:
__int64 __fastcall getch(_BYTE *a1)
{
ssize_t v1; // rax
unsigned int v2; // ebp
struct termios v4; // [rsp+0h] [rbp-58h] BYREF
char buf[25]; // [rsp+3Fh] [rbp-19h] BYREF

buf[0] = 0;
*(_QWORD *)&v4.c_iflag = 0LL;
*(_QWORD *)&v4.c_cflag = 0LL;
*(_QWORD *)&v4.c_line = 0LL;
*(_QWORD *)&v4.c_cc[7] = 0LL;
*(_QWORD *)&v4.c_cc[15] = 0LL;
*(_QWORD *)&v4.c_cc[23] = 0LL;
*(_QWORD *)&v4.c_cc[31] = 0LL;
v4.c_ospeed = 0;
if ( tcgetattr(0, &v4) < 0 )
{
perror("tcsetattr()");
v2 = -1;
}
else
{
v4.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v4.c_cc[5] = 256;
if ( tcsetattr(0, 0, &v4) < 0 )
{
perror("tcsetattr ICANON");
v2 = -1;
}
else
{
while ( 1 )
{
v1 = read(0, buf, 1uLL);
if ( v1 >= 0 )
break;
if ( *_errno_location() != 4 )
{
perror("read()");
v2 = -1;
goto LABEL_9;
}
}
v2 = -(v1 == 0);
LABEL_9:
v4.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &v4) < 0 )
{
perror("tcsetattr ~ICANON");
v2 = -1;
}
*a1 = buf[0];
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
ssize_t v1; // rax
unsigned int v2; // ebp
struct termios v4; // [rsp+0h] [rbp-58h] BYREF
char buf[25]; // [rsp+3Fh] [rbp-19h] BYREF

buf[0] = 0;
*(_QWORD *)&v4.c_iflag = 0LL;
*(_QWORD *)&v4.c_cflag = 0LL;
*(_QWORD *)&v4.c_line = 0LL;
*(_QWORD *)&v4.c_cc[7] = 0LL;
*(_QWORD *)&v4.c_cc[15] = 0LL;
*(_QWORD *)&v4.c_cc[23] = 0LL;
*(_QWORD *)&v4.c_cc[31] = 0LL;
v4.c_ospeed = 0;
if ( tcgetattr(0, &v4) < 0 )
{
perror("tcsetattr()");
v2 = -1;
}
else
{
v4.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v4.c_cc[5] = 256;
if ( tcsetattr(0, 0, &v4) < 0 )
{
perror("tcsetattr ICANON");
v2 = -1;
}
else
{
while ( 1 )
{
v1 = read(0, buf, 1uLL);
if ( v1 >= 0 )
break;
if ( *_errno_location() != 4 )
{
perror("read()");
v2 = -1;
goto LABEL_9;
}
}
v2 = -(v1 == 0);
LABEL_9:
v4.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &v4) < 0 )
{
perror("tcsetattr ~ICANON");
v2 = -1;
}
*a1 = buf[0];
}
}
return v2;
}

original_code:
static
int getch(char *_key)
{
 char key = 0;
 struct termios old = { 0 };
 ssize_t len;
 int ret = 0;
 if (tcgetattr(0, &old) < 0) {
  perror("tcsetattr()");
  ret = -1;
  goto end;
 }
 old.c_lflag &= ~0000002;
 old.c_lflag &= ~0000010;
 old.c_cc[6] = 1;
 old.c_cc[5] = 0;
 if (tcsetattr(0, 0, &old) < 0) {
  perror("tcsetattr ICANON");
  ret = -1;
  goto end;
 }
 do {
  len = read(0, &key, sizeof(key));
 } while (len < 0 && (*__errno_location ()) == 4);
 if (len < 0) {
  perror("read()");
  ret = -1;
 }
 if (len == 0) {
  ret = -1;
 }
 old.c_lflag |= 0000002;
 old.c_lflag |= 0000010;
 if (tcsetattr(0, 1, &old) < 0) {
  perror("tcsetattr ~ICANON");
  ret = -1;
 }
 *_key = key;
end:
 return ret;
}

canonical_original_code:
static int getch(char *_key)
{
 char key = 0;
 struct termios old = { 0 };
 long len;
 int ret = 0;
 if (tcgetattr(0, &old) < 0) {
  perror("tcsetattr()");
  ret = -1;
  goto end;
 }
 old.c_lflag &= ~0000002;
 old.c_lflag &= ~0000010;
 old.c_cc[6] = 1;
 old.c_cc[5] = 0;
 if (tcsetattr(0, 0, &old) < 0) {
  perror("tcsetattr ICANON");
  ret = -1;
  goto end;
 }
 do {
  len = read(0, &key, sizeof(key));
 } while (len < 0 && (*__errno_location ()) == 4);
 if (len < 0) {
  perror("read()");
  ret = -1;
 }
 if (len == 0) {
  ret = -1;
 }
 old.c_lflag |= 0000002;
 old.c_lflag |= 0000010;
 if (tcsetattr(0, 1, &old) < 0) {
  perror("tcsetattr ~ICANON");
  ret = -1;
 }
 *_key = key;
end:
 return ret;
}

variable_types: key char

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: len long


decompiled_code:
__int64 wait_for_key()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

puts("Press any key to continue...");
return getch(v1);
}

canonical_decompiled_code:
__int64 func2()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

puts("Press any key to continue...");
return func0(v1);
}

original_code:
static
void wait_for_key(void)
{
 char key;
 printf("Press any key to continue...\n");
 (void) getch(&key);
}

canonical_original_code:
static void wait_for_key()
{
 char key;
 printf("Press any key to continue...\n");
 (void) getch(&key);
}


decompiled_code:
int clear_screen()
{
int result; // eax

result = putchar(10);
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

result = putchar(10);
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

original_code:
static inline
void clear_screen(void)
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}

canonical_original_code:
static inline void clear_screen()
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}


decompiled_code:
int show_menu()
{
clear_screen();
puts("[ root ]");
puts(" key\tDescription");
puts("---------------------------------");
puts(" c\tConfiguration menu");
puts(" g\tPlay god");
return puts(" x\tExit root menu");
}

canonical_decompiled_code:
int func4()
{
func3();
puts("[ root ]");
puts(" key\tDescription");
puts("---------------------------------");
puts(" c\tConfiguration menu");
puts(" g\tPlay god");
return puts(" x\tExit root menu");
}

original_code:
static
void show_menu(void)
{
 clear_screen();
 printf("[ root ]\n");
 printf(" key	Description\n");
 printf("---------------------------------\n");
 printf("  c	Configuration menu\n");
 printf("  g	Play god\n");
 printf("  x	Exit root menu\n");
}

canonical_original_code:
static void show_menu()
{
 clear_screen();
 printf("[ root ]\n");
 printf(" key	Description\n");
 printf("---------------------------------\n");
 printf("  c	Configuration menu\n");
 printf("  g	Play god\n");
 printf("  x	Exit root menu\n");
}