recvPlayerInfo

decompiled_code:
char *__fastcall recvPlayerInfo(char *dest, __int64 a2)
{
char *v3; // r12
char *v4; // rax
__int64 v5; // rsi
__int64 v6; // rbx
void *v7; // r12
char *i; // r10
__int64 v9; // rbx
int v10; // er12
__int64 v11; // rcx
__int64 v12; // rsi
const char *v13; // rdx
char *v14; // rax
char *result; // rax

v3 = (char *)malloc(0x100uLL);
addchar(v3);
strcpy(v3, dest);
v4 = strtok(v3, "\n");
_isoc99_sscanf(v4, "%*s %*s %i", a2 + 108);
v5 = *(unsigned int *)(a2 + 108);
if ( (int)v5 > 8 )
{
printf("\nDiese Version des Clients unterstuetzt maximal 8 Spieler, die Anzahl ist jedoch %d Spieler!\n", v5);
result = 0LL;
}
else
{
v6 = a2 + 272;
v7 = malloc(0x32uLL);
addchar(v7);
for ( i = strtok(0LL, "\n"); strcmp(i, "+ ENDPLAYERS"); i = strtok(0LL, "\n") )
{
_isoc99_sscanf(i, "%*s %d %s %d %d", v6 - 56);
v6 += 64LL;
}
v9 = a2 + 220;
printf("\nWir sind Spieler: %s\n", (const char *)(a2 + 156));
printf("\nInsgesamt spielen diese %i Spieler:\n", *(unsigned int *)(a2 + 108));
printf("\n%-15s %-25s %-2s\n", "Spielernummer", "Spielername", "Bereit");
v10 = 1;
printf("%-15d %-25s %-2d\n", *(unsigned int *)(a2 + 152), (const char *)(a2 + 156), 1LL);
if ( *(int *)(a2 + 108) > 1 )
{
do
{
v11 = *(unsigned int *)(v9 + 52);
v12 = *(unsigned int *)(v9 - 4);
v13 = (const char *)v9;
++v10;
v9 += 64LL;
printf("%-15d %-25s %-2d\n", v12, v13, v11);
puts("=================================================");
}
while ( *(_DWORD *)(a2 + 108) > v10 );
}
putchar(10);
v14 = strtok(0LL, &byte_A63);
result = strcpy(dest, v14);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *dest, __int64 a2)
{
char *v3; // r12
char *v4; // rax
__int64 v5; // rsi
__int64 v6; // rbx
void *v7; // r12
char *i; // r10
__int64 v9; // rbx
int v10; // er12
__int64 v11; // rcx
__int64 v12; // rsi
const char *v13; // rdx
char *v14; // rax
char *result; // rax

v3 = (char *)malloc(0x100uLL);
addchar(v3);
strcpy(v3, dest);
v4 = strtok(v3, "\n");
_isoc99_sscanf(v4, "%*s %*s %i", a2 + 108);
v5 = *(unsigned int *)(a2 + 108);
if ( (int)v5 > 8 )
{
printf("\nDiese Version des Clients unterstuetzt maximal 8 Spieler, die Anzahl ist jedoch %d Spieler!\n", v5);
result = 0LL;
}
else
{
v6 = a2 + 272;
v7 = malloc(0x32uLL);
addchar(v7);
for ( i = strtok(0LL, "\n"); strcmp(i, "+ ENDPLAYERS"); i = strtok(0LL, "\n") )
{
_isoc99_sscanf(i, "%*s %d %s %d %d", v6 - 56);
v6 += 64LL;
}
v9 = a2 + 220;
printf("\nWir sind Spieler: %s\n", (const char *)(a2 + 156));
printf("\nInsgesamt spielen diese %i Spieler:\n", *(unsigned int *)(a2 + 108));
printf("\n%-15s %-25s %-2s\n", "Spielernummer", "Spielername", "Bereit");
v10 = 1;
printf("%-15d %-25s %-2d\n", *(unsigned int *)(a2 + 152), (const char *)(a2 + 156), 1LL);
if ( *(int *)(a2 + 108) > 1 )
{
do
{
v11 = *(unsigned int *)(v9 + 52);
v12 = *(unsigned int *)(v9 - 4);
v13 = (const char *)v9;
++v10;
v9 += 64LL;
printf("%-15d %-25s %-2d\n", v12, v13, v11);
puts("=================================================");
}
while ( *(_DWORD *)(a2 + 108) > v10 );
}
putchar(10);
v14 = strtok(0LL, &byte_A63);
result = strcpy(dest, v14);
}
return result;
}

original_code:
char* recvPlayerInfo(char* buffer, sharedmem * shm) {
 char* buffer2;
 buffer2 = malloc(sizeof(char) * 256);
 addchar(buffer2);
 int i = 1;
 strcpy(buffer2, buffer);
 buffer2 = strtok(buffer2, "\n");
 sscanf(buffer2, "%*s %*s %i", &(shm->playerCount));
 if (shm->playerCount > 8) {
  printf("\nDiese Version des Clients unterstuetzt maximal 8 Spieler, die Anzahl ist jedoch %d Spieler!\n", shm->playerCount);
  return ((void *)0) ;
 }
 int rdy = -1;
 char* temp = malloc(sizeof(char) * 50);
 addchar(temp);
 buffer2 = strtok(((void *)0), "\n");
 while (strcmp(buffer2, "+ ENDPLAYERS") != 0) {
  sscanf(buffer2, "%*s %d %s %d %d", &shm->player[i].playerNumber, shm->player[i].playerName, &shm->player[i].playerReady, &rdy);
  if (rdy != -1) {
   snprintf(temp, 50, " %d", shm->player[i].playerReady);
   strcpy(shm->player[i].playerName, strcat(shm->player[i].playerName, temp));
   shm->player[i].playerReady = rdy;
  }
  buffer2 = strtok(((void *)0), "\n");
  i++;
 }
 printf("\nWir sind Spieler: %s\n", shm->player[0].playerName);
 printf("\nInsgesamt spielen diese %i Spieler:\n", shm->playerCount);
 printf("\n%-15s %-25s %-2s\n", "Spielernummer", "Spielername", "Bereit");
 printf("%-15d %-25s %-2d\n", shm->player[0].playerNumber, shm->player[0].playerName, 1);
 for (i = 1; i < shm->playerCount; i++) {
  printf("%-15d %-25s %-2d\n", shm->player[i].playerNumber, shm->player[i].playerName, shm->player[i].playerReady);
  printf("=================================================\n");
 }
 printf("\n");
 buffer2 = strtok(((void *)0), "");
 strcpy(buffer, buffer2);
 return buffer;
}

canonical_original_code:
char *recvPlayerInfo(char *buffer, struct sharedmem *shm) {
 char *buffer2;
 buffer2 = malloc(sizeof(char) * 256);
 addchar(buffer2);
 int i = 1;
 strcpy(buffer2, buffer);
 buffer2 = strtok(buffer2, "\n");
 sscanf(buffer2, "%*s %*s %i", &(shm->playerCount));
 if (shm->playerCount > 8) {
  printf("\nDiese Version des Clients unterstuetzt maximal 8 Spieler, die Anzahl ist jedoch %d Spieler!\n", shm->playerCount);
  return ((void *)0) ;
 }
 int rdy = -1;
 char *temp = malloc(sizeof(char) * 50);
 addchar(temp);
 buffer2 = strtok(((void *)0), "\n");
 while (strcmp(buffer2, "+ ENDPLAYERS") != 0) {
  sscanf(buffer2, "%*s %d %s %d %d", &shm->player[i].playerNumber, shm->player[i].playerName, &shm->player[i].playerReady, &rdy);
  if (rdy != -1) {
   snprintf(temp, 50, " %d", shm->player[i].playerReady);
   strcpy(shm->player[i].playerName, strcat(shm->player[i].playerName, temp));
   shm->player[i].playerReady = rdy;
  }
  buffer2 = strtok(((void *)0), "\n");
  i++;
 }
 printf("\nWir sind Spieler: %s\n", shm->player[0].playerName);
 printf("\nInsgesamt spielen diese %i Spieler:\n", shm->playerCount);
 printf("\n%-15s %-25s %-2s\n", "Spielernummer", "Spielername", "Bereit");
 printf("%-15d %-25s %-2d\n", shm->player[0].playerNumber, shm->player[0].playerName, 1);
 for (i = 1; i < shm->playerCount; i++) {
  printf("%-15d %-25s %-2d\n", shm->player[i].playerNumber, shm->player[i].playerName, shm->player[i].playerReady);
  printf("=================================================\n");
 }
 printf("\n");
 buffer2 = strtok(((void *)0), "");
 strcpy(buffer, buffer2);
 return buffer;
}

variable_types:
buffer
char *

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: i int

variable_types: rdy int

return_type: char *


performConnection

decompiled_code:
_BOOL8 __fastcall performConnection(int fd, __int64 a2, __int64 a3, __int64 a4)
{
const char *v5; // r14
char *v6; // r13
_BYTE *v7; // rbp
int v8; // er14
int v9; // ebx
int v10; // ebx
char *v11; // r8
_BOOL8 result; // rax
int v13; // [rsp+8h] [rbp-50h]
int v14; // [rsp+8h] [rbp-50h]
int v15; // [rsp+8h] [rbp-50h]

v5 = (const char *)malloc(0x14uLL);
addchar(v5);
v6 = (char *)malloc(0x200uLL);
addchar(v6);
v7 = malloc(0x200uLL);
addchar(v7);
v13 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:120");
_isoc99_sscanf(v7, "%*s%*s%*s%s", v5);
if ( v13 > 0 )
v7[v13] = 0;
printf("\nDie Version des Servers ist: %s\n", v5);
antistrcat((char *)(a3 + 120), "VERSION ", v6);
sendReplyFormatted(fd, v6);
v14 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:130");
if ( v14 > 0 )
v7[v14] = 0;
if ( *v7 == 45 )
{
printf("\nDer Server akzeptiert die Version %s dieses Clients nicht!\n", (const char *)(a3 + 120));
result = 1LL;
}
else
{
puts("\nDie Client-Version wurde akzeptiert, uebertrage Spiel-ID...");
antistrcat((char *)(a2 + 8), "ID ", v6);
sendReplyFormatted(fd, v6);
v15 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:147");
if ( v15 > 0 )
v7[v15] = 0;
_isoc99_sscanf(v7, "%*s%*s%s", v5);
if ( *v7 == 45 )
{
puts("\nDie uebergebene Game-ID fehlt oder ist fehlerhaft! Beende Verbindung");
result = 1LL;
}
else if ( !strcmp(v5, "Quarto") )
{
printf("\nDer Server moechte %s spielen. Und wir auch!\n", v5);
v8 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:167");
if ( v8 > 0 )
v7[v8] = 0;
_isoc99_sscanf(v7, "%*s%s", a2 + 50);
printf("\nSpiel: %s\n", (const char *)(a2 + 50));
antistrcat((char *)(a3 + 125), "PLAYER ", v6);
sendReplyFormatted(fd, v6);
v9 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:177");
if ( v9 > 0 )
v7[v9] = 0;
if ( *v7 == 45 )
{
if ( v7[2] == 45 )
puts("\nEs wurde eine ungueltige Spielernummer eingegeben! Beende Verbindung");
else
puts("\nEs wurde kein freier Platz gefunden, versuchen sie es spaeter noch einmal!");
result = 1LL;
}
else
{
_isoc99_sscanf(v7, "%*s %*s %d %[^\n]\n", a2 + 152);
v10 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:199");
if ( v10 > 0 )
v7[v10] = 0;
if ( *v7 == 45 )
{
puts("\nFehler bei Uebermittlung der Spielparameter!");
result = 1LL;
}
else
{
v11 = recvPlayerInfo(v7, a2);
result = 1LL;
if ( v11 )
result = (unsigned int)waitforfds((unsigned int)fd, v7, a2, a4) != 0;
}
}
}
else
{
puts("\nDas Spiel, das der Server spielt, ist nicht Quarto! Beende Verbindung.");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int fd, __int64 a2, __int64 a3, __int64 a4)
{
const char *v5; // r14
char *v6; // r13
_BYTE *v7; // rbp
int v8; // er14
int v9; // ebx
int v10; // ebx
char *v11; // r8
_BOOL8 result; // rax
int v13; // [rsp+8h] [rbp-50h]
int v14; // [rsp+8h] [rbp-50h]
int v15; // [rsp+8h] [rbp-50h]

v5 = (const char *)malloc(0x14uLL);
addchar(v5);
v6 = (char *)malloc(0x200uLL);
addchar(v6);
v7 = malloc(0x200uLL);
addchar(v7);
v13 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:120");
_isoc99_sscanf(v7, "%*s%*s%*s%s", v5);
if ( v13 > 0 )
v7[v13] = 0;
printf("\nDie Version des Servers ist: %s\n", v5);
func1((char *)(a3 + 120), "VERSION ", v6);
func0(fd, v6);
v14 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:130");
if ( v14 > 0 )
v7[v14] = 0;
if ( *v7 == 45 )
{
printf("\nDer Server akzeptiert die Version %s dieses Clients nicht!\n", (const char *)(a3 + 120));
result = 1LL;
}
else
{
puts("\nDie Client-Version wurde akzeptiert, uebertrage Spiel-ID...");
func1((char *)(a2 + 8), "ID ", v6);
func0(fd, v6);
v15 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:147");
if ( v15 > 0 )
v7[v15] = 0;
_isoc99_sscanf(v7, "%*s%*s%s", v5);
if ( *v7 == 45 )
{
puts("\nDie uebergebene Game-ID fehlt oder ist fehlerhaft! Beende Verbindung");
result = 1LL;
}
else if ( !strcmp(v5, "Quarto") )
{
printf("\nDer Server moechte %s spielen. Und wir auch!\n", v5);
v8 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:167");
if ( v8 > 0 )
v7[v8] = 0;
_isoc99_sscanf(v7, "%*s%s", a2 + 50);
printf("\nSpiel: %s\n", (const char *)(a2 + 50));
func1((char *)(a3 + 125), "PLAYER ", v6);
func0(fd, v6);
v9 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:177");
if ( v9 > 0 )
v7[v9] = 0;
if ( *v7 == 45 )
{
if ( v7[2] == 45 )
puts("\nEs wurde eine ungueltige Spielernummer eingegeben! Beende Verbindung");
else
puts("\nEs wurde kein freier Platz gefunden, versuchen sie es spaeter noch einmal!");
result = 1LL;
}
else
{
_isoc99_sscanf(v7, "%*s %*s %d %[^\n]\n", a2 + 152);
v10 = recv(fd, v7, 0x1FFuLL, 0);
writelog(logdatei, "src/PerformConnection.c:199");
if ( v10 > 0 )
v7[v10] = 0;
if ( *v7 == 45 )
{
puts("\nFehler bei Uebermittlung der Spielparameter!");
result = 1LL;
}
else
{
v11 = func2(v7, a2);
result = 1LL;
if ( v11 )
result = (unsigned int)waitforfds((unsigned int)fd, v7, a2, a4) != 0;
}
}
}
else
{
puts("\nDas Spiel, das der Server spielt, ist nicht Quarto! Beende Verbindung.");
result = 1LL;
}
}
return result;
}

original_code:
int performConnection(int sock, sharedmem * shm, config_struct* conf, int fd[]) {
 int err;
 char* reader = malloc(sizeof(char) * 20);
 addchar(reader);
 char* temp = malloc(sizeof(char) * 512);
 addchar(temp);
 char* buffer = malloc(sizeof(char) * 512);
 addchar(buffer);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "120");
 sscanf(buffer, "%*s%*s%*s%s", reader);
 if (err > 0) {
  buffer[err] = '\0';
 }
 printf("\nDie Version des Servers ist: %s\n", reader);
 antistrcat(conf->version, "VERSION ", temp);
 sendReplyFormatted(sock, temp);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "130");
 if (err > 0) {
  buffer[err] = '\0';
 }
 if (buffer[0] == '-') {
  printf("\nDer Server akzeptiert die Version %s dieses Clients nicht!\n", conf->version);
  return 1;
 } else {
  printf("\nDie Client-Version wurde akzeptiert, uebertrage Spiel-ID...\n");
 }
 antistrcat(shm->gameID, "ID ", temp);
 sendReplyFormatted(sock, temp);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "147");
 if (err > 0) {
  buffer[err] = '\0';
 }
 sscanf(buffer, "%*s%*s%s", reader);
 if (buffer[0] == '-') {
  printf("\nDie uebergebene Game-ID fehlt oder ist fehlerhaft! Beende Verbindung\n");
  return 1;
 } else if (strcmp(reader, "Quarto") != 0) {
  printf("\nDas Spiel, das der Server spielt, ist nicht Quarto! Beende Verbindung.\n");
  return 1;
 } else {
  printf("\nDer Server moechte %s spielen. Und wir auch!\n", reader);
 }
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "167");
 if (err > 0) {
  buffer[err] = '\0';
 }
 sscanf(buffer, "%*s%s", shm->gameName);
 printf("\nSpiel: %s\n", shm->gameName);
 antistrcat(conf->playernumber, "PLAYER ", temp);
 sendReplyFormatted(sock, temp);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "177");
 if (err > 0) {
  buffer[err] = '\0';
 }
 if (buffer[0] == '-') {
  if (buffer[2] == '-') {
   printf("\nEs wurde eine ungueltige Spielernummer eingegeben! Beende Verbindung\n");
  } else {
   printf("\nEs wurde kein freier Platz gefunden, versuchen sie es spaeter noch einmal!\n");
  }
  return 1;
 } else {
  sscanf(buffer, "%*s %*s %d %[^\n]\n", &(shm->player[0].playerNumber),
    (shm->player[0].playerName));
 }
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "199");
 if (err > 0) {
  buffer[err] = '\0';
 }
 if (buffer[0] == '-') {
  printf("\nFehler bei Uebermittlung der Spielparameter!\n");
  return 1;
 }
 if (recvPlayerInfo(buffer, shm) == ((void *)0) ) {
  return 1;
 }
 if (waitforfds(sock, buffer, shm, fd) != 0) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int performConnection(int sock, struct sharedmem *shm, struct config_struct *conf, int fd[]) {
 int err;
 char *reader = malloc(sizeof(char) * 20);
 addchar(reader);
 char *temp = malloc(sizeof(char) * 512);
 addchar(temp);
 char *buffer = malloc(sizeof(char) * 512);
 addchar(buffer);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "120");
 sscanf(buffer, "%*s%*s%*s%s", reader);
 if (err > 0) {
  buffer[err] = '\0';
 }
 printf("\nDie Version des Servers ist: %s\n", reader);
 antistrcat(conf->version, "VERSION ", temp);
 sendReplyFormatted(sock, temp);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "130");
 if (err > 0) {
  buffer[err] = '\0';
 }
 if (buffer[0] == '-') {
  printf("\nDer Server akzeptiert die Version %s dieses Clients nicht!\n", conf->version);
  return 1;
 } else {
  printf("\nDie Client-Version wurde akzeptiert, uebertrage Spiel-ID...\n");
 }
 antistrcat(shm->gameID, "ID ", temp);
 sendReplyFormatted(sock, temp);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "147");
 if (err > 0) {
  buffer[err] = '\0';
 }
 sscanf(buffer, "%*s%*s%s", reader);
 if (buffer[0] == '-') {
  printf("\nDie uebergebene Game-ID fehlt oder ist fehlerhaft! Beende Verbindung\n");
  return 1;
 } else if (strcmp(reader, "Quarto") != 0) {
  printf("\nDas Spiel, das der Server spielt, ist nicht Quarto! Beende Verbindung.\n");
  return 1;
 } else {
  printf("\nDer Server moechte %s spielen. Und wir auch!\n", reader);
 }
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "167");
 if (err > 0) {
  buffer[err] = '\0';
 }
 sscanf(buffer, "%*s%s", shm->gameName);
 printf("\nSpiel: %s\n", shm->gameName);
 antistrcat(conf->playernumber, "PLAYER ", temp);
 sendReplyFormatted(sock, temp);
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "177");
 if (err > 0) {
  buffer[err] = '\0';
 }
 if (buffer[0] == '-') {
  if (buffer[2] == '-') {
   printf("\nEs wurde eine ungueltige Spielernummer eingegeben! Beende Verbindung\n");
  } else {
   printf("\nEs wurde kein freier Platz gefunden, versuchen sie es spaeter noch einmal!\n");
  }
  return 1;
 } else {
  sscanf(buffer, "%*s %*s %d %[^\n]\n", &(shm->player[0].playerNumber),
    (shm->player[0].playerName));
 }
 err = recv(sock, buffer, 512 - 1, 0);
 writelog(logdatei, "src/PerformConnection.c" ":" "199");
 if (err > 0) {
  buffer[err] = '\0';
 }
 if (buffer[0] == '-') {
  printf("\nFehler bei Uebermittlung der Spielparameter!\n");
  return 1;
 }
 if (recvPlayerInfo(buffer, shm) == ((void *)0) ) {
  return 1;
 }
 if (waitforfds(sock, buffer, shm, fd) != 0) {
  return 1;
 }
 return 0;
}

variable_types: sock 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: err int

variable_types:
reader
char *

variable_types:
temp
char *

return_type: int

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

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


freeall

decompiled_code:
__int64 freeall()
{
__int64 v0; // rbx
void *v1; // rdi
__int64 v2; // rbx
void *v3; // rdi

if ( countint >= 0 )
{
v0 = 0LL;
do
{
v1 = (void *)varadr_int[v0++];
free(v1);
}
while ( countint >= (int)v0 );
}
if ( countchar >= 0 )
{
v2 = 0LL;
do
{
v3 = (void *)varadr_char[v2++];
free(v3);
}
while ( countchar >= (int)v2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
void *v1; // rdi
__int64 v2; // rbx
void *v3; // rdi

if ( countint >= 0 )
{
v0 = 0LL;
do
{
v1 = (void *)varadr_int[v0++];
free(v1);
}
while ( countint >= (int)v0 );
}
if ( countchar >= 0 )
{
v2 = 0LL;
do
{
v3 = (void *)varadr_char[v2++];
free(v3);
}
while ( countchar >= (int)v2 );
}
return 0LL;
}

original_code:
int freeall() {
 int i;
 for (i = 0; i <= countint; i++) {
  free(varadr_int[i]);
 }
 for (i = 0; i <= countchar; i++) {
  free(varadr_char[i]);
 }
 return 0;
}


addint

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

if ( !a1 )
{
perror("\nFehler bei Malloc eines int pointers! \n");
freeall("\nFehler bei Malloc eines int pointers! \n");
exit(1);
}
v1 = countint;
varadr_int[countint] = a1;
countint = v1 + 1;
return 0LL;
}

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

if ( !a1 )
{
perror("\nFehler bei Malloc eines int pointers! \n");
func0("\nFehler bei Malloc eines int pointers! \n");
exit(1);
}
v1 = countint;
varadr_int[countint] = a1;
countint = v1 + 1;
return 0LL;
}

original_code:
int addint(int* intadr) {
 if (intadr == ((void *)0) ) {
  perror("\nFehler bei Malloc eines int pointers! \n");
  freeall();
  exit(1);
 }
 varadr_int[countint] = intadr;
 countint++;
 return 0;
}

canonical_original_code:
int addint(int *intadr) {
 if (intadr == ((void *)0) ) {
  perror("\nFehler bei Malloc eines int pointers! \n");
  freeall();
  exit(1);
 }
 varadr_int[countint] = intadr;
 countint++;
 return 0;
}

variable_types:
intadr
int *


addchar

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

if ( !a1 )
{
perror("\nFehler bei Malloc eines char pointers! \n");
freeall("\nFehler bei Malloc eines char pointers! \n");
exit(1);
}
v1 = countchar;
varadr_char[countchar] = a1;
countchar = v1 + 1;
return 0LL;
}

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

if ( !a1 )
{
perror("\nFehler bei Malloc eines char pointers! \n");
func0("\nFehler bei Malloc eines char pointers! \n");
exit(1);
}
v1 = countchar;
varadr_char[countchar] = a1;
countchar = v1 + 1;
return 0LL;
}

original_code:
int addchar(char* charadr) {
 if (charadr == ((void *)0) ) {
  perror("\nFehler bei Malloc eines char pointers! \n");
  freeall();
  exit(1);
 }
 varadr_char[countchar] = charadr;
 countchar++;
 return 0;
}

canonical_original_code:
int addchar(char *charadr) {
 if (charadr == ((void *)0) ) {
  perror("\nFehler bei Malloc eines char pointers! \n");
  freeall();
  exit(1);
 }
 varadr_char[countchar] = charadr;
 countchar++;
 return 0;
}

variable_types:
charadr
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
_DWORD *v4; // rax
__pid_t v5; // eax
int result; // eax
void *v7; // rdi
int v8; // edi
int stat_loc; // [rsp+Ch] [rbp-7Ch] BYREF
void *ptr; // [rsp+10h] [rbp-78h] BYREF
void *shmaddr; // [rsp+18h] [rbp-70h]
int shmid; // [rsp+20h] [rbp-68h]
int pipedes[2]; // [rsp+24h] [rbp-64h] BYREF
__int16 v14; // [rsp+2Ch] [rbp-5Ch] BYREF
unsigned int v15; // [rsp+2Eh] [rbp-5Ah]
__int16 v16; // [rsp+32h] [rbp-56h]
void **v17; // [rsp+34h] [rbp-54h]
int v18; // [rsp+3Ch] [rbp-4Ch]
__int16 v19; // [rsp+48h] [rbp-40h] BYREF
int v20; // [rsp+4Ah] [rbp-3Eh]
__int16 v21; // [rsp+4Eh] [rbp-3Ah]
void **v22; // [rsp+50h] [rbp-38h]
int v23; // [rsp+58h] [rbp-30h]
char *v24; // [rsp+68h] [rbp-20h]
char v25; // [rsp+90h] [rbp+8h] BYREF

v19 = -17599;
v24 = &v25;
v20 = (int)signal_handler_1;
v14 = -17599;
v16 = -17847;
v21 = -17847;
v15 = (unsigned int)signal_handler_0;
v22 = &ptr;
v23 = -1864106167;
v17 = &ptr;
v18 = -1864106167;
logdatei = fopen("log.txt", "w+");
ptr = calloc(5uLL, 0x88uLL);
v3 = shmget(0, 0x298uLL, 2045);
shmid = v3;
if ( v3 <= 0 )
{
perror("\nNo SHM\n");
LABEL_14:
free(ptr);
fclose(logdatei);
return 1;
}
v4 = shmat(v3, 0LL, 0);
shmaddr = v4;
if ( v4 == (_DWORD *)-1LL )
{
perror("Fehler, shm");
writelog(logdatei, "src/Main.c:46");
result = 1;
}
else
{
v4[35] = 0;
if ( pipe(pipedes) < 0 )
{
perror("\nFehler beim Einrichten der Pipe.\n");
result = 1;
}
else
{
v5 = fork();
if ( v5 >= 0 )
{
if ( v5 )
{
close(pipedes[0]);
if ( signal(2, (__sighandler_t)&v14) != (__sighandler_t)-1LL
&& signal(10, (__sighandler_t)&v14) != (__sighandler_t)-1LL )
{
do
usleep(0xC350u);
while ( !waitpid(*((_DWORD *)shmaddr + 1), &stat_loc, 1) );
v7 = shmaddr;
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");
v7 = shmaddr;
}
shmdt(v7);
if ( shmctl(shmid, 0, 0LL) == -1 )
perror("\nParent: Fehler bei Zerstoerung von shm \n");
freeall();
goto LABEL_12;
}
perror("\nFehler beim Aufsetzen des Signal Handlers\n");
v8 = pipedes[1];
}
else
{
close(pipedes[1]);
if ( signal(2, (__sighandler_t)&v19) == (__sighandler_t)-1LL )
{
perror("\nFehler beim aufsetzen des Signal Handlers!\n");
v8 = pipedes[0];
}
else if ( argc == 1 || strlen(argv[1]) > 0x29 )
{
puts("\nDer uebergebene Parameter hat nicht die korrekte Laenge!");
v8 = pipedes[0];
}
else
{
if ( argc == 3 )
{
if ( !(unsigned int)openConfig(argv[2], ptr) )
goto LABEL_11;
}
else if ( !(unsigned int)openConfig("client.conf", ptr) )
{
LABEL_11:
strcpy((char *)shmaddr + 8, argv[1]);
initConnection(shmaddr, ptr, pipedes);
freeall();
LABEL_12:
close(pipedes[0]);
close(pipedes[1]);
free(ptr);
fclose(logdatei);
return 0;
}
v8 = pipedes[0];
}
}
close(v8);
goto LABEL_14;
}
perror("\nFehler bei fork()");
writelog(logdatei, "src/Main.c:64");
shmdt(shmaddr);
fclose(logdatei);
close(pipedes[0]);
close(pipedes[1]);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char** argv) {
 config_struct *conf;
 int fd[2];
 logdatei = fopen("log.txt", "w+");
 conf = calloc(5, sizeof(config_struct));
 sharedmem *shm;
 int shmID;
 int shmSize = sizeof(struct sharedmem);
 shmID = shmget(((__key_t) 0), shmSize, 01000 | 02000 | 0775);
 if (shmID < 1) {
  perror("\nNo SHM\n");
  free(conf);
  fclose(logdatei);
  return 1;
 }
 shm = shmat(shmID, 0, 0);
 if (shm == (void *) -1) {
  perror("Fehler, shm");
  writelog(logdatei, "src/Main.c" ":" "46");
  return 1;
 }
 shm->pfID = 0;
 if (pipe(fd) < 0) {
  perror("\nFehler beim Einrichten der Pipe.\n");
  return 1;
 }
 pid_t pid = 0;
 pid = fork();
 if ((pid) < 0) {
  perror("\nFehler bei fork()");
  writelog(logdatei, "src/Main.c" ":" "64");
  shmdt(shm);
  fclose(logdatei);
  close(fd[0]);
  close(fd[1]);
  return 1;
 } else if (pid == 0) {
  close(fd[1]);
  void signal_handler(int signum) {
   if (signum == 2) {
    reactToSig(shm, 1, conf, fd, shmID);
   }
  }
  if (signal(2, signal_handler) == ((__sighandler_t) -1) ) {
   perror("\nFehler beim aufsetzen des Signal Handlers!\n");
   close(fd[0]);
   free(conf);
   fclose(logdatei);
   return 1;
  }
  if (argc == 1 || (strlen(argv[1])) >= 42) {
   printf("\nDer uebergebene Parameter hat nicht die korrekte Laenge!\n");
   close(fd[0]);
   free(conf);
   fclose(logdatei);
   return 1;
  } else {
   if (argc == 3) {
    if (openConfig(argv[2], conf) != 0) {
     close(fd[0]);
     free(conf);
     fclose(logdatei);
     return 1;
    }
   } else {
    if (openConfig("client.conf", conf) != 0) {
     close(fd[0]);
     free(conf);
     fclose(logdatei);
     return 1;
    }
   }
   strcpy(shm->gameID, argv[1]);
  }
  initConnection(shm, conf, fd);
  freeall();
 } else {
  close(fd[0]);
  void signal_handler(int signum) {
   if (signum == 10) {
    reactToSig(shm, 0, conf, fd, shmID);
   }
   else if (signum == 2) {
    reactToSig(shm, 1, conf, fd, shmID);
   }
  }
  if (signal(2, signal_handler) == ((__sighandler_t) -1)
    || signal(10, signal_handler) == ((__sighandler_t) -1) ) {
   perror("\nFehler beim Aufsetzen des Signal Handlers\n");
   close(fd[1]);
   free(conf);
   fclose(logdatei);
   return 1;
  }
  int status;
  pid_t result;
  do {
   usleep(50000);
   result = waitpid(shm->pidKid, &status, 1);
  } while (result == 0);
  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");
  }
  freeall();
 }
 close(fd[0]);
 close(fd[1]);
 free(conf);
 fclose(logdatei);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct config_struct *conf;
 int fd[2];
 logdatei = fopen("log.txt", "w+");
 conf = calloc(5, sizeof(config_struct));
 struct sharedmem *shm;
 int shmID;
 int shmSize = sizeof(struct sharedmem);
 shmID = shmget(((int) 0), shmSize, 01000 | 02000 | 0775);
 if (shmID < 1) {
  perror("\nNo SHM\n");
  free(conf);
  fclose(logdatei);
  return 1;
 }
 shm = shmat(shmID, 0, 0);
 if (shm == (void *) -1) {
  perror("Fehler, shm");
  writelog(logdatei, "src/Main.c" ":" "46");
  return 1;
 }
 shm->pfID = 0;
 if (pipe(fd) < 0) {
  perror("\nFehler beim Einrichten der Pipe.\n");
  return 1;
 }
 int pid = 0;
 pid = fork();
 if ((pid) < 0) {
  perror("\nFehler bei fork()");
  writelog(logdatei, "src/Main.c" ":" "64");
  shmdt(shm);
  fclose(logdatei);
  close(fd[0]);
  close(fd[1]);
  return 1;
 } else if (pid == 0) {
  close(fd[1]);
  void signal_handler(int signum) {
   if (signum == 2) {
    reactToSig(shm, 1, conf, fd, shmID);
   }
  }
  if (signal(2, signal_handler) == ((__sighandler_t) -1) ) {
   perror("\nFehler beim aufsetzen des Signal Handlers!\n");
   close(fd[0]);
   free(conf);
   fclose(logdatei);
   return 1;
  }
  if (argc == 1 || (strlen(argv[1])) >= 42) {
   printf("\nDer uebergebene Parameter hat nicht die korrekte Laenge!\n");
   close(fd[0]);
   free(conf);
   fclose(logdatei);
   return 1;
  } else {
   if (argc == 3) {
    if (openConfig(argv[2], conf) != 0) {
     close(fd[0]);
     free(conf);
     fclose(logdatei);
     return 1;
    }
   } else {
    if (openConfig("client.conf", conf) != 0) {
     close(fd[0]);
     free(conf);
     fclose(logdatei);
     return 1;
    }
   }
   strcpy(shm->gameID, argv[1]);
  }
  initConnection(shm, conf, fd);
  freeall();
 } else {
  close(fd[0]);
  void signal_handler(int signum) {
   if (signum == 10) {
    reactToSig(shm, 0, conf, fd, shmID);
   }
   else if (signum == 2) {
    reactToSig(shm, 1, conf, fd, shmID);
   }
  }
  if (signal(2, signal_handler) == ((__sighandler_t) -1)
    || signal(10, signal_handler) == ((__sighandler_t) -1) ) {
   perror("\nFehler beim Aufsetzen des Signal Handlers\n");
   close(fd[1]);
   free(conf);
   fclose(logdatei);
   return 1;
  }
  int status;
  int result;
  do {
   usleep(50000);
   result = waitpid(shm->pidKid, &status, 1);
  } while (result == 0);
  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");
  }
  freeall();
 }
 close(fd[0]);
 close(fd[1]);
 free(conf);
 fclose(logdatei);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fd
int [2]

variable_types: shmID int

variable_types: shmSize int

variable_types: pid int

variable_types: status int

variable_types: result int

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


formatMove

decompiled_code:
void *__fastcall formatMove(int a1)
{
void *result; // rax

result = &unk_D5B;
if ( a1 )
{
result = &unk_D5E;
if ( a1 != 1 )
{
result = &unk_D61;
if ( a1 != 2 )
{
result = &unk_D64;
if ( a1 != 3 )
{
result = &unk_D67;
if ( a1 != 4 )
{
result = &unk_D6A;
if ( a1 != 5 )
{
result = &unk_D6D;
if ( a1 != 6 )
{
result = &unk_D70;
if ( a1 != 7 )
{
result = &unk_D73;
if ( a1 != 8 )
{
result = &unk_D76;
if ( a1 != 9 )
{
result = &unk_D79;
if ( a1 != 10 )
{
result = &unk_D7C;
if ( a1 != 11 )
{
result = &unk_D7F;
if ( a1 != 12 )
{
result = &unk_D58;
if ( a1 != 13 )
{
result = &unk_D82;
if ( a1 != 14 )
{
result = &unk_D85;
if ( a1 != 15 )
result = 0LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = &unk_D5B;
if ( a1 )
{
result = &unk_D5E;
if ( a1 != 1 )
{
result = &unk_D61;
if ( a1 != 2 )
{
result = &unk_D64;
if ( a1 != 3 )
{
result = &unk_D67;
if ( a1 != 4 )
{
result = &unk_D6A;
if ( a1 != 5 )
{
result = &unk_D6D;
if ( a1 != 6 )
{
result = &unk_D70;
if ( a1 != 7 )
{
result = &unk_D73;
if ( a1 != 8 )
{
result = &unk_D76;
if ( a1 != 9 )
{
result = &unk_D79;
if ( a1 != 10 )
{
result = &unk_D7C;
if ( a1 != 11 )
{
result = &unk_D7F;
if ( a1 != 12 )
{
result = &unk_D58;
if ( a1 != 13 )
{
result = &unk_D82;
if ( a1 != 14 )
{
result = &unk_D85;
if ( a1 != 15 )
result = 0LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
char* formatMove(int move) {
 if (move == 0)
  { return "A4"; }
 if (move == 1)
  { return "B4"; }
 if (move == 2)
  { return "C4"; }
 if (move == 3)
  { return "D4"; }
 if (move == 4)
  { return "A3"; }
 if (move == 5)
  { return "B3"; }
 if (move == 6)
  { return "C3"; }
 if (move == 7)
  { return "D3"; }
 if (move == 8)
  { return "A2"; }
 if (move == 9)
  { return "B2"; }
 if (move == 10)
  { return "C2"; }
 if (move == 11)
  { return "D2"; }
 if (move == 12)
  { return "A1"; }
 if (move == 13)
  { return "B1"; }
 if (move == 14)
  { return "C1"; }
 if (move == 15)
  { return "D1"; }
 return ((void *)0) ;
}

canonical_original_code:
char *formatMove(int move) {
 if (move == 0)
  { return "A4"; }
 if (move == 1)
  { return "B4"; }
 if (move == 2)
  { return "C4"; }
 if (move == 3)
  { return "D4"; }
 if (move == 4)
  { return "A3"; }
 if (move == 5)
  { return "B3"; }
 if (move == 6)
  { return "C3"; }
 if (move == 7)
  { return "D3"; }
 if (move == 8)
  { return "A2"; }
 if (move == 9)
  { return "B2"; }
 if (move == 10)
  { return "C2"; }
 if (move == 11)
  { return "D2"; }
 if (move == 12)
  { return "A1"; }
 if (move == 13)
  { return "B1"; }
 if (move == 14)
  { return "C1"; }
 if (move == 15)
  { return "D1"; }
 return ((void *)0) ;
}

variable_types: move int


testStone

original_code:
int testStone(sharedmem * shm, int stone) {
 int i = 0;
 for (i = 0; i < 16; i++) {
  if (stone == *(shm->pf + i) || stone == shm->StoneToPlace) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int testStone(struct sharedmem *shm, int stone) {
 int i = 0;
 for (i = 0; i < 16; i++) {
  if (stone == *(shm->pf + i) || stone == shm->StoneToPlace) {
   return 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: stone int

variable_types: i int


chooseStone

decompiled_code:
__int64 __fastcall chooseStone(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3; // ecx

do
{
v1 = rand();
result = testStone(a1, v1 % 16);
}
while ( (_DWORD)result );
*(_DWORD *)(a1 + 136) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3; // ecx

do
{
v1 = rand();
result = func1(a1, v1 % 16);
}
while ( (_DWORD)result );
*(_DWORD *)(a1 + 136) = v3;
return result;
}

original_code:
void chooseStone(sharedmem * shm) {
 int check = 0;
 int stone;
 while (check == 0) {
  stone = rand() % 16;
  if (testStone(shm, stone) == 0) {
   check = 1;
  }
 }
 shm->nextStone = stone;
}

canonical_original_code:
void chooseStone(struct sharedmem *shm) {
 int check = 0;
 int stone;
 while (check == 0) {
  stone = rand() % 16;
  if (testStone(shm, stone) == 0) {
   check = 1;
  }
 }
 shm->nextStone = stone;
}

variable_types: check int

return_type: void


checkField

decompiled_code:
_BOOL8 __fastcall checkField(_BYTE *a1)
{
_BYTE *v1; // rcx
int v2; // eax
int v3; // edx

v1 = a1 + 64;
v2 = 0;
do
{
v3 = *a1 != 42;
a1 += 4;
v2 += v3;
}
while ( a1 != v1 );
return v2 == 15;
}

original_code:
int checkField(char * field) {
 int i;
 int occupied = 0;
 for (i = 0; i < 64; i = i + 4) {
  if (field[i] != '*') {
   occupied++;
  }
 }
 if (occupied == 15) {
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
int checkField(char *field) {
 int i;
 int occupied = 0;
 for (i = 0; i < 64; i = i + 4) {
  if (field[i] != '*') {
   occupied++;
  }
 }
 if (occupied == 15) {
  return 1;
 } else {
  return 0;
 }
}

variable_types:
field
char *

variable_types: occupied int


decompiled_code:
__int64 __fastcall byte_to_binary(int a1, _BYTE *a2)
{
_BYTE *v2; // rdx
unsigned int i; // eax

if ( !a2 )
return 1LL;
v2 = a2;
for ( i = 3; i != -1; --i )
{
if ( _bittest(&a1, i) )
*v2 = 49;
else
*v2 = 48;
++v2;
}
a2[4] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, _BYTE *a2)
{
_BYTE *v2; // rdx
unsigned int i; // eax

if ( !a2 )
return 1LL;
v2 = a2;
for ( i = 3; i != -1; --i )
{
if ( _bittest(&a1, i) )
*v2 = 49;
else
*v2 = 48;
++v2;
}
a2[4] = 0;
return 0LL;
}

original_code:
int byte_to_binary(int n, char* pointer) {
 int c, d, count;
 count = 0;
 if (pointer == ((void *)0) ) {
  return 1;
 }
 for (c = 3; c >= 0; c--) {
  d = n >> c;
  if (d & 1) {
   *(pointer + count) = 1 + '0';
  } else {
   *(pointer + count) = 0 + '0';
  }
  count++;
 }
 *(pointer + count) = '\0';
 return 0;
}

canonical_original_code:
int byte_to_binary(int n, char *pointer) {
 int c; int d; int count;
 count = 0;
 if (pointer == ((void *)0) ) {
  return 1;
 }
 for (c = 3; c >= 0; c--) {
  d = n >> c;
  if (d & 1) {
   *(pointer + count) = 1 + '0';
  } else {
   *(pointer + count) = 0 + '0';
  }
  count++;
 }
 *(pointer + count) = '\0';
 return 0;
}

variable_types: n int

variable_types:
pointer
char *

variable_types: c int

variable_types: d int

variable_types: count int


calculateMove

decompiled_code:
__int64 __fastcall calculateMove(__int64 a1, __int64 a2, int a3)
{
char v3; // r13
char v4; // bp
char v5; // bl
__int64 v6; // r15
_BYTE *v7; // rcx
__int64 v8; // rax
char v9; // dl
unsigned int v10; // er14
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
char *v15; // [rsp+0h] [rbp-68h]

v3 = 48;
v4 = 32;
v15 = (char *)malloc(5uLL);
addchar(v15);
v5 = 16;
v6 = 0LL;
byte_to_binary(*(_DWORD *)(a1 + 132), v15);
while ( 1 )
{
if ( *(_BYTE *)(a2 + v6) != 42 )
goto LABEL_2;
v7 = (_BYTE *)(a2 + (int)((v6 & 0xFFFFFFF0) + (((_BYTE)v6 + 4) & 0xF)));
v8 = 0LL;
v9 = *v15;
if ( *v15 == *v7 )
break;
while ( 1 )
{
LABEL_5:
if ( v9 == *(_BYTE *)(a2 + (v5 & 0x3F) + v8)
&& v9 == *(_BYTE *)(a2 + (unsigned int)v8 + (v4 & 0x3F))
&& v9 == *(_BYTE *)(a2 + (v3 & 0x3F) + (unsigned int)v8) )
{
v10 = v6;
if ( a3 != 1 )
{
v12 = (const char *)formatMove((int)v6 >> 2);
printf("\nVertikale Loesung gefunden (%s)! ", v12);
}
return v10;
}
if ( !((unsigned int)v6 % 0x14)
&& v9 == *(_BYTE *)(a2 + ((int)v6 + 20) % 0x50u + (unsigned int)v8)
&& v9 == *(_BYTE *)(a2 + ((int)v6 + 40) % 0x50u + (unsigned int)v8)
&& v9 == *(_BYTE *)(a2 + (unsigned int)v8 + ((int)v6 + 60) % 0x50u)
|| v6
&& !((unsigned int)v6 % 0xC)
&& v9 == *(_BYTE *)(a2 + (unsigned int)v8 + (unsigned int)v6 % 0x30 + 12)
&& v9 == *(_BYTE *)(a2 + (unsigned int)v8 + ((int)v6 + 12) % 0x30u + 12)
&& v9 == *(_BYTE *)(a2 + (unsigned int)v8 + ((int)v6 + 24) % 0x30u + 12) )
{
v10 = v6;
if ( a3 != 1 )
{
v13 = (const char *)formatMove((int)v6 >> 2);
printf("\nDiagonale Loesung gefunden! %s\n", v13);
}
return v10;
}
if ( ++v8 == 4 )
break;
v9 = v15[v8];
if ( v9 == v7[v8] )
goto LABEL_13;
}
LABEL_2:
v6 += 4LL;
v3 += 4;
v4 += 4;
v5 += 4;
if ( v6 == 64 )
return (unsigned int)-1;
}
LABEL_13:
if ( v9 != *(_BYTE *)(a2 + (unsigned int)v8 + (((_BYTE)v6 + 8) & 0xF) + (v6 & 0xFFFFFFF0))
|| v9 != *(_BYTE *)(a2 + (((_BYTE)v6 + 12) & 0xF) + (v6 & 0xFFFFFFF0) + (unsigned int)v8) )
{
goto LABEL_5;
}
v10 = v6;
if ( a3 != 1 )
{
v11 = (const char *)formatMove((int)v6 >> 2);
printf("\nHorizontale Loesung gefunden (%s)! ", v11);
}
return v10;
}

original_code:
int calculateMove(sharedmem *shm, char* stones, int silent) {
 char* stone = malloc(sizeof(char) * 5);
 addchar(stone);
 int i, j;
 byte_to_binary(shm->StoneToPlace, stone);
 for (i = 0; i < 64; i = i + 4) {
  if (stones[i] == '*') {
   for (j = 0; j < 4; j++) {
    if (((stone[j]) == (stones[((i + 4) % 16) + (i / 16) * 16 + j]))
      && ((stone[j]) == (stones[((i + 8) % 16) + (i / 16) * 16 + j]))
      && ((stone[j]) == (stones[((i + 12) % 16) + (i / 16) * 16 + j]))) {
     if (silent != 1) {
      printf("\nHorizontale Loesung gefunden (%s)! ", formatMove(i / 4));
     }
     return i;
    }
    if (((stone[j]) == (stones[(i + 16) % 64 + j]))
      && ((stone[j]) == (stones[(i + 32) % 64 + j]))
      && ((stone[j]) == (stones[(i + 48) % 64 + j]))) {
     if (silent != 1) {
      printf("\nVertikale Loesung gefunden (%s)! ", formatMove(i / 4));
     }
     return i;
    }
    if (i % 20 == 0) {
     if (((stone[j]) == (stones[(i + 20) % 80 + j]))
       && ((stone[j]) == (stones[(i + 40) % 80 + j]))
       && ((stone[j]) == (stones[(i + 60) % 80 + j]))) {
      if (silent != 1) {
       printf("\nDiagonale Loesung gefunden! %s\n", formatMove(i / 4));
      }
      return i;
     }
    }
    if ((i != 0) && (i % 12) == 0) {
     if (((stone[j]) == (stones[i % 48 + 12 + j]))
       && ((stone[j]) == (stones[(i + 12) % 48 + 12 + j]))
       && ((stone[j]) == (stones[(i + 24) % 48 + 12 + j]))) {
      if (silent != 1) {
       printf("\nDiagonale Loesung gefunden! %s\n", formatMove(i / 4));
      }
      return i;
     }
    }
   }
  }
 }
 return -1;
}

canonical_original_code:
int calculateMove(struct sharedmem *shm, char *stones, int silent) {
 char *stone = malloc(sizeof(char) * 5);
 addchar(stone);
 int i; int j;
 byte_to_binary(shm->StoneToPlace, stone);
 for (i = 0; i < 64; i = i + 4) {
  if (stones[i] == '*') {
   for (j = 0; j < 4; j++) {
    if (((stone[j]) == (stones[((i + 4) % 16) + (i / 16) * 16 + j]))
      && ((stone[j]) == (stones[((i + 8) % 16) + (i / 16) * 16 + j]))
      && ((stone[j]) == (stones[((i + 12) % 16) + (i / 16) * 16 + j]))) {
     if (silent != 1) {
      printf("\nHorizontale Loesung gefunden (%s)! ", formatMove(i / 4));
     }
     return i;
    }
    if (((stone[j]) == (stones[(i + 16) % 64 + j]))
      && ((stone[j]) == (stones[(i + 32) % 64 + j]))
      && ((stone[j]) == (stones[(i + 48) % 64 + j]))) {
     if (silent != 1) {
      printf("\nVertikale Loesung gefunden (%s)! ", formatMove(i / 4));
     }
     return i;
    }
    if (i % 20 == 0) {
     if (((stone[j]) == (stones[(i + 20) % 80 + j]))
       && ((stone[j]) == (stones[(i + 40) % 80 + j]))
       && ((stone[j]) == (stones[(i + 60) % 80 + j]))) {
      if (silent != 1) {
       printf("\nDiagonale Loesung gefunden! %s\n", formatMove(i / 4));
      }
      return i;
     }
    }
    if ((i != 0) && (i % 12) == 0) {
     if (((stone[j]) == (stones[i % 48 + 12 + j]))
       && ((stone[j]) == (stones[(i + 12) % 48 + 12 + j]))
       && ((stone[j]) == (stones[(i + 24) % 48 + 12 + j]))) {
      if (silent != 1) {
       printf("\nDiagonale Loesung gefunden! %s\n", formatMove(i / 4));
      }
      return i;
     }
    }
   }
  }
 }
 return -1;
}

variable_types:
stones
char *

variable_types: silent int

variable_types:
stone
char *

variable_types: j int


original_code:
int convertGameFieldQuarto4x4(sharedmem * shm, char* stones) {
 stones[0] = '\0';
 char* stone = malloc(sizeof(char) * 5);
 int i, j;
 for (i = 0; i < shm->fieldY; i++) {
  for (j = 0; j < shm->fieldX; j++) {
   if (*(shm->pf + j + i * shm->fieldY) == -1) {
    strcat(stones, "****");
   } else {
    byte_to_binary(*(shm->pf + j + i * shm->fieldY), stone);
    strcat(stones, stone);
   }
  }
 }
 free(stone);
 return 0;
}

canonical_original_code:
int convertGameFieldQuarto4x4(struct sharedmem *shm, char *stones) {
 stones[0] = '\0';
 char *stone = malloc(sizeof(char) * 5);
 int i; int j;
 for (i = 0; i < shm->fieldY; i++) {
  for (j = 0; j < shm->fieldX; j++) {
   if (*(shm->pf + j + i * shm->fieldY) == -1) {
    strcat(stones, "****");
   } else {
    byte_to_binary(*(shm->pf + j + i * shm->fieldY), stone);
    strcat(stones, stone);
   }
  }
 }
 free(stone);
 return 0;
}


think

decompiled_code:
__int64 __fastcall think(__int64 a1)
{
unsigned int v2; // eax
char *v3; // rbp
void *v4; // rax
const char *v5; // rax
char *v6; // r8
unsigned int v7; // er12
__int64 v9; // rax
__int64 v10; // rdi
int v11; // ebx
int v12; // er15
const char *v13; // rax
const char *v14; // rax
bool v15; // zf
__int64 v16; // rax
int v17; // edi
const char *v18; // rax
int v19; // [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...");
v7 = checkField(v3);
if ( v7 )
{
v9 = *(_QWORD *)(a1 + 144);
v10 = 0LL;
while ( *(_DWORD *)(v9 + 4 * v10) != -1 )
{
if ( ++v10 == 16 )
{
v7 = 1;
puts("\nDas Spielfeld ist bereits voll, das ist aber komisch!");
return v7;
}
}
v18 = (const char *)formatMove(v10);
v7 = 0;
strcpy((char *)(a1 + 100), v18);
*(_DWORD *)(a1 + 136) = -1;
}
else
{
v11 = 100;
v12 = calculateMove(a1, (__int64)v3, 1);
dest = (char *)(a1 + 100);
if ( v12 == -1 )
{
do
{
v17 = rand() % 16;
if ( *(_DWORD *)(*(_QWORD *)(a1 + 144) + 4LL * v17) == -1 )
{
v14 = (const char *)formatMove(v17);
strcpy(dest, v14);
v19 = *(_DWORD *)(a1 + 132);
*(_DWORD *)(*(_QWORD *)(a1 + 144) + 4LL * v17) = v19;
convertGameFieldQuarto4x4(a1, v3);
chooseStone(a1);
*(_DWORD *)(a1 + 132) = *(_DWORD *)(a1 + 136);
v15 = (unsigned int)calculateMove(a1, (__int64)v3, 1) == -1;
v16 = *(_QWORD *)(a1 + 144);
*(_DWORD *)(a1 + 132) = v19;
if ( v15 )
{
*(_DWORD *)(v16 + 4LL * v17) = -1;
convertGameFieldQuarto4x4(a1, v3);
printf("\nMit Stein %d kann der Gegner nicht gewinnen!\n", *(unsigned int *)(a1 + 136));
return v7;
}
*(_DWORD *)(v16 + 4LL * v17) = -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#=====================#");
v13 = (const char *)formatMove(v12 / 4);
strcpy((char *)(a1 + 100), v13);
chooseStone(a1);
}
}
}
else
{
printGameField(a1);
if ( **(_DWORD **)(a1 + 144) == -1 )
v5 = (const char *)formatMove(0);
else
v5 = (const char *)formatMove(1);
strcpy(v6, v5);
v7 = *(_DWORD *)(a1 + 132);
if ( v7 )
{
*(_DWORD *)(a1 + 136) = 0;
v7 = 0;
}
else
{
*(_DWORD *)(a1 + 136) = 1;
}
}
}
else
{
v7 = 1;
perror("\nBei Quarto muss die Spielfeldhoehe gleich der breite sein!\n");
}
return v7;
}

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, int a2, void *a3, int *a4, int a5)
{
unsigned int v6; // er12
void *v8; // rax
char *v9; // r13
__int64 v10; // rcx
const char *v11; // rdx
int v12; // er12
int v13; // er8
int v14; // eax
int ptra; // [rsp+0h] [rbp-38h]

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

canonical_decompiled_code:
__int64 __fastcall func0(void *shmaddr, int a2, void *a3, int *a4, int a5)
{
unsigned int v6; // er12
void *v8; // rax
char *v9; // r13
__int64 v10; // rcx
const char *v11; // rdx
int v12; // er12
int v13; // er8
int v14; // eax
int ptra; // [rsp+0h] [rbp-38h]

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

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 *


initConnection

decompiled_code:
_BOOL8 __fastcall initConnection(__pid_t *a1, __int64 a2, __int64 a3)
{
struct hostent *v5; // rbp
__int16 v6; // di
__int16 v7; // ax
int v8; // edi
socklen_t v9; // edx
__pid_t v10; // eax
__int64 v11; // rdi
int v12; // er12
_BOOL8 result; // rax
struct sockaddr v14[3]; // [rsp+0h] [rbp-38h] BYREF

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

canonical_decompiled_code:
_BOOL8 __fastcall func1(__pid_t *a1, __int64 a2, __int64 a3)
{
struct hostent *v5; // rbp
__int16 v6; // di
__int16 v7; // ax
int v8; // edi
socklen_t v9; // edx
__pid_t v10; // eax
__int64 v11; // rdi
int v12; // er12
_BOOL8 result; // rax
struct sockaddr v14[3]; // [rsp+0h] [rbp-38h] BYREF

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

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


checkName

decompiled_code:
__int64 __fastcall checkName(char *s1, char *nptr, void *dest)
{
size_t v4; // rax
__int64 result; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, char *nptr, void *dest)
{
size_t v4; // rax
__int64 result; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax

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

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

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 )
{
puts(Usage);
exit(0);
}
v3 = fork();
if ( v3 == -1 )
{
perror("fork()");
exit(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 )
goto LABEL_11;
if ( !v5 )
break;
waitpid(v5, stat_loc, 0);
sleep(1u);
}
execvp(argv[1], (char *const *)argv + 1);
LABEL_11:
exit(1);
}

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 __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
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; // rbp
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;
}

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

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


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:
first
char *

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


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


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; // rbp
void *v3; // r13
void *v5; // r12
_QWORD *v6; // r13

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

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
__int64 *v2; // rbp
void *v3; // r13
void *v5; // r12
_QWORD *v6; // r13

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

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


canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
__int64 *v2; // rbp
void *v3; // r13
void *v5; // r12
_QWORD *v6; // r13

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

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 v0; // rbx
__int64 v1; // rsi
_QWORD *v2; // rdx
int i; // eax
_QWORD *v5[2]; // [rsp+8h] [rbp-10h] BYREF

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

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

v0 = 0LL;
v5[0] = 0LL;
do
{
v1 = v0++;
List_append((__int64 *)v5, v1);
}
while ( v0 != 10 );
v2 = v5[0];
for ( i = 0; i != 10; ++i )
{
if ( *(_DWORD *)v2 != i )
__assert_fail("(int)np->data == i", "list.c", 0x32u, "List_test");
v2 = (_QWORD *)v2[1];
}
func7(v5, 0LL);
v5[0] = 0LL;
func7(v5, 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 = (unsigned __int8)key_to_char_map[2 * a2];
if ( a1 )
result = (unsigned __int8)byte_41[2 * a2];
}
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 = (unsigned __int8)key_to_char_map[2 * a2];
if ( a1 )
result = (unsigned __int8)byte_41[2 * a2];
}
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:
// attributes: thunk
__int64 __fastcall screen_y(float a1)
{
return screen_x_localalias(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(float a1)
{
return func0(a1);
}

variable_types: y int


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

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

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

v5 = *a1;
sincos(a2, sinx, &cosx);
v2 = a1[1];
v3 = v5 * sinx[0] + cosx * v2;
v4 = v5 * cosx - v2 * sinx[0];
*a1 = v4;
*(float *)&v3 = v3;
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(__m128i a1)
{
float v1; // er14
float *v2; // rbp
double v3; // xmm1_8
float v4; // xmm0_4
float v5; // xmm0_4
float *v6; // rdi
double v7; // [rsp+0h] [rbp-38h]
double v8; // [rsp+8h] [rbp-30h]
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

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

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:
void __fastcall update(__m128i a1)
{
float v1; // xmm1_4
float *v2; // rbx
unsigned int v3; // er12
float v4; // xmm5_4
float v5; // xmm4_4
float v6; // xmm0_4
float v7; // xmm1_4
float v8; // xmm3_4
__int64 v9; // rcx
float v10; // xmm4_4
float v11; // xmm0_4
float v12; // xmm1_4
float v13; // xmm2_4

v1 = *(float *)a1.m128i_i32;
if ( rotate_planes )
{
updatePlanes(a1);
v1 = *(float *)a1.m128i_i32;
}
v2 = (float *)&_planes;
v3 = 0;
v4 = particles[2];
v5 = particles[3];
v6 = (float)(v4 * v1) + particles[0];
v7 = (float)(v1 * v5) + particles[1];
particles[0] = v6;
particles[1] = v7;
while ( 1 )
{
v8 = v2[1];
if ( (float)((float)((float)(v6 * *v2) + (float)(v7 * v8)) + v2[2]) < 0.0
&& (float)((float)(*v2 * v4) + (float)(v8 * v5)) < 0.0 )
{
break;
}
++v3;
v2 += 7;
if ( v3 == 4 )
return;
LABEL_6:
v6 = particles[0];
v7 = particles[1];
v4 = particles[2];
v5 = particles[3];
}
v9 = v3++;
v2 += 7;
fprintf(stderr, "particle %d collided on plane %d\n", 0LL, v9);
v10 = particles[3];
v11 = *(v2 - 7);
v12 = *(v2 - 6);
v13 = particles[2] - (float)((float)((float)(particles[2] * v11) + (float)(v10 * v12)) * (float)(v11 + v11));
particles[2] = v13;
particles[3] = v10 - (float)((float)((float)(v11 * v13) + (float)(v10 * v12)) * (float)(v12 + v12));
if ( v3 != 4 )
goto LABEL_6;
}

canonical_decompiled_code:
void __fastcall func4(__m128i a1)
{
float v1; // xmm1_4
float *v2; // rbx
unsigned int v3; // er12
float v4; // xmm5_4
float v5; // xmm4_4
float v6; // xmm0_4
float v7; // xmm1_4
float v8; // xmm3_4
__int64 v9; // rcx
float v10; // xmm4_4
float v11; // xmm0_4
float v12; // xmm1_4
float v13; // xmm2_4

v1 = *(float *)a1.m128i_i32;
if ( rotate_planes )
{
func3(a1);
v1 = *(float *)a1.m128i_i32;
}
v2 = (float *)&_planes;
v3 = 0;
v4 = particles[2];
v5 = particles[3];
v6 = (float)(v4 * v1) + particles[0];
v7 = (float)(v1 * v5) + particles[1];
particles[0] = v6;
particles[1] = v7;
while ( 1 )
{
v8 = v2[1];
if ( (float)((float)((float)(v6 * *v2) + (float)(v7 * v8)) + v2[2]) < 0.0
&& (float)((float)(*v2 * v4) + (float)(v8 * v5)) < 0.0 )
{
break;
}
++v3;
v2 += 7;
if ( v3 == 4 )
return;
LABEL_6:
v6 = particles[0];
v7 = particles[1];
v4 = particles[2];
v5 = particles[3];
}
v9 = v3++;
v2 += 7;
fprintf(stderr, "particle %d collided on plane %d\n", 0LL, v9);
v10 = particles[3];
v11 = *(v2 - 7);
v12 = *(v2 - 6);
v13 = particles[2] - (float)((float)((float)(particles[2] * v11) + (float)(v10 * v12)) * (float)(v11 + v11));
particles[2] = v13;
particles[3] = v10 - (float)((float)((float)(v11 * v13) + (float)(v10 * v12)) * (float)(v12 + v12));
if ( v3 != 4 )
goto LABEL_6;
}

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:
// attributes: thunk
__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; // eax
int v1; // ebp
__int64 buf; // [rsp+5h] [rbp-13h] BYREF
__int16 v4; // [rsp+Dh] [rbp-Bh]
char v5; // [rsp+Fh] [rbp-9h]

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

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

if ( remove("input.bin") >= 0 || *__errno_location() == 2 )
{
v0 = open("input.bin", 193);
v1 = v0;
if ( v0 >= 0 )
{
v5 = 5;
buf = 0x602090501040103LL;
v4 = 773;
if ( write(v0, &buf, 0xBuLL) >= 0 )
return close(v1);
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; // r12
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; // r12
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 *