repo: pbrisbin/android-receiver

decompiled_code:
int __fastcall parse_options(int argc, char **argv)
{
int result; // eax
int v3; // eax
char *v4; // [rsp+0h] [rbp-28h] BYREF
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
result = getopt_long(argc, argv, "hp:", &opts_0, longind);
if ( result == -1 )
break;
if ( result == 104 )
{
puts("usage: android-receiver [ -p <port> ]");
exit(0);
}
if ( result != 112 )
{
fwrite("invalid option, try -h or --help\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v3 = strtol(optarg, &v4, 10);
portno = v3;
if ( *v4 || (unsigned int)(v3 - 1) > 0xFFFE )
{
fwrite("invalid port number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int argc, char **argv)
{
int result; // eax
int v3; // eax
char *v4; // [rsp+0h] [rbp-28h] BYREF
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
result = getopt_long(argc, argv, "hp:", &opts_0, longind);
if ( result == -1 )
break;
if ( result == 104 )
{
puts("usage: android-receiver [ -p <port> ]");
exit(0);
}
if ( result != 112 )
{
fwrite("invalid option, try -h or --help\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v3 = strtol(optarg, &v4, 10);
portno = v3;
if ( *v4 || (unsigned int)(v3 - 1) > 0xFFFE )
{
fwrite("invalid port number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
return result;
}

original_code:
static void parse_options(int argc, char *argv[]) {
    int opt, option_index = 0;
    char *token;
    static struct option opts[] = {
        { "port" , 1, 0, 'p'},
        { "help" , 0, 0, 'h'},
        { 0 , 0 , 0, 0 }
    };
    while ((opt = getopt_long(argc, argv, "hp:", opts, &option_index)) != -1) {
        switch (opt) {
            case 'p':
                portno = strtol(optarg, &token, 10);
                if (*token != '\0' || portno <= 0 || portno > 65535) {
                    fprintf(stderr, "invalid port number\n");
                    exit(1);
                }
                break;
            case 'h':
                printf("usage: android-receiver [ -p <port> ]\n");
                exit(0);
            default:
                fprintf(stderr, "invalid option, try -h or --help\n");
                exit(1);
        }
    }
}

canonical_original_code:
static void parse_options(int argc, char *argv[]) {
    int opt; int option_index = 0;
    char *token;
    static struct option opts[] = {
        { "port" , 1, 0, 'p'},
        { "help" , 0, 0, 'h'},
        { 0 , 0 , 0, 0 }
    };
    while ((opt = getopt_long(argc, argv, "hp:", opts, &option_index)) != -1) {
        switch (opt) {
            case 'p':
                portno = strtol(optarg, &token, 10);
                if (*token != '\0' || portno <= 0 || portno > 65535) {
                    fprintf(stderr, "invalid port number\n");
                    exit(1);
                }
                break;
            case 'h':
                printf("usage: android-receiver [ -p <port> ]\n");
                exit(0);
            default:
                fprintf(stderr, "invalid option, try -h or --help\n");
                exit(1);
        }
    }
}

variable_types:
argv
char *[]

variable_types: opt int

variable_types:
token
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-418h] BYREF
char buf[1032]; // [rsp+30h] [rbp-408h] BYREF

addr_len = 16;
parse_options(argc, (char **)argv);
v3 = socket(2, 2, 0);
if ( v3 >= 0 )
{
v4 = v3;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(portno);
if ( bind(v4, &addr, 0x10u) < 0 )
{
perror("error binding to socket");
exit(1);
}
while ( 1 )
{
if ( (int)recvfrom(v4, buf, 0x400uLL, 0, &v6, &addr_len) >= 0 )
{
handle_message(buf);
}
else if ( *__errno_location() != 4 )
{
perror("error receiving from socket");
exit(1);
}
}
}
perror("error opening socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-418h] BYREF
char buf[1032]; // [rsp+30h] [rbp-408h] BYREF

addr_len = 16;
func7(argc, (char **)argv);
v3 = socket(2, 2, 0);
if ( v3 >= 0 )
{
v4 = v3;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func8(portno);
if ( bind(v4, &addr, 0x10u) < 0 )
{
perror("error binding to socket");
exit(1);
}
while ( 1 )
{
if ( (int)recvfrom(v4, buf, 0x400uLL, 0, &v6, &addr_len) >= 0 )
{
func9(buf);
}
else if ( *__errno_location() != 4 )
{
perror("error receiving from socket");
exit(1);
}
}
}
perror("error opening socket");
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
    char buf[1024];
    struct sockaddr_in server, from;
    int sock, n;
    unsigned int fromlen = sizeof from;
    parse_options(argc, argv);
    if ((sock = socket(2, SOCK_DGRAM, 0)) < 0) {
        perror("error opening socket");
        exit(1);
    }
    memset(&server, '\0', sizeof server);
    server.sin_family = 2;
    server.sin_port = htons(portno);
    server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    if (bind(sock, (struct sockaddr *)&server, sizeof server) < 0) {
        perror("error binding to socket");
        exit(1);
    }
    while (1) {
        while ((n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0 && (*__errno_location ()) == 4)
            ;
        if (n < 0) {
            perror("error receiving from socket");
            exit(1);
        }
        handle_message(buf);
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    char buf[1024];
    struct sockaddr_in server; struct sockaddr_in from;
    int sock; int n;
    unsigned int fromlen = sizeof from;
    parse_options(argc, argv);
    if ((sock = socket(2, SOCK_DGRAM, 0)) < 0) {
        perror("error opening socket");
        exit(1);
    }
    memset(&server, '\0', sizeof server);
    server.sin_family = 2;
    server.sin_port = htons(portno);
    server.sin_addr.s_addr = ((unsigned int) 0x00000000);
    if (bind(sock, (struct sockaddr *)&server, sizeof server) < 0) {
        perror("error binding to socket");
        exit(1);
    }
    while (1) {
        while ((n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0 && (*__errno_location ()) == 4)
            ;
        if (n < 0) {
            perror("error receiving from socket");
            exit(1);
        }
        handle_message(buf);
    }
}

variable_types: argc int

variable_types:
buf
char [1024]

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

variable_types: n int

variable_types:
fromlen
unsigned int

return_type: int

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


help

repo: pc-coholic/Quarto

decompiled_code:
int help()
{
puts("\nNutzung des Clienten:\tclient [Game-ID] -p [0|1] -c [dateinname] -l [0|1|2]");
puts(aPGew);
puts("\t-c:\tandere Konfigurationsdatei (Default: client.conf)");
puts(aLLoglevel0F);
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("\nNutzung des Clienten:\tclient [Game-ID] -p [0|1] -c [dateinname] -l [0|1|2]");
puts(aPGew);
puts("\t-c:\tandere Konfigurationsdatei (Default: client.conf)");
puts(aLLoglevel0F);
return putchar(10);
}

original_code:
void help() {
 printf("\nNutzung des Clienten:	client [Game-ID] -p [0|1] -c [dateinname] -l [0|1|2]\n");
 printf("\n	-p:	gewünschte Spielernummer: 0 für Spieler 1, 1 für Spieler 2\n");
 printf("	-c:	andere Konfigurationsdatei (Default: client.conf)\n");
 printf("	-l:	Loglevel: 0 für Errors, 1 für Spielinfo, 2 für Debuginfo (Default steht in Konfigurationsdatei\n");
 printf("\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char v4; // bp
int v5; // eax
__int64 v6; // rbx
__pid_t v7; // eax
_BYTE *v9; // rbx
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
const char *v15; // rsi
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
char v22; // al
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
__int64 v26; // rcx
const char *v27; // rsi
__pid_t v28; // eax
_BYTE v29[3072]; // [rsp+0h] [rbp-C58h] BYREF
int v30; // [rsp+C00h] [rbp-58h]
int pipedes[2]; // [rsp+C18h] [rbp-40h] BYREF
char dest[55]; // [rsp+C21h] [rbp-37h] BYREF

v3 = (char *)malloc(0x100uLL);
strcpy(v3, "client.conf");
log_printf(2LL, "Using config-file %s\n", v3);
get_config(v29, v3);
qmemcpy(configstruct, v29, 0xC00uLL);
configstruct[768] = v30;
log_printf(1LL, "\n");
if ( argc <= 1 )
{
puts("Keine Game-Id angegeben!");
help();
exit(1);
}
strcpy(dest, argv[1]);
if ( strlen(dest) != 11 )
{
puts("Game-Id muss 11-stellig sein!");
help();
exit(1);
}
v4 = 51;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:c:l:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
configstruct[768] = atoi(optarg);
break;
case 'p':
v4 = *optarg;
if ( (unsigned __int8)(*optarg - 48) > 1u )
{
puts("Es gibt nur 2 Spieler! 0 oder 1 eingeben!");
help();
exit(1);
}
break;
case 'c':
strcpy(v3, optarg);
break;
default:
help();
exit(1);
}
}
v6 = (unsigned int)shmSegment(604LL);
shmPtr = shmAnbinden(v6);
shmDelete((unsigned int)v6);
if ( pipe(pipedes) < 0 )
log_printf(0LL, "Fehler bei Pipe anlegen");
v7 = fork();
if ( v7 == -1 )
{
log_printf(0LL, "Fehler bei fork()\n");
}
else
{
if ( v7 )
{
*(_DWORD *)(shmPtr + 40) = v7;
signal(10, (__sighandler_t)&signalHandler);
signal(17, (__sighandler_t)&endHandler);
while ( 1 )
{
pause();
log_printf(2LL, "thinker hat fertig gedacht\n");
pipe_write(pipedes);
}
}
*(_DWORD *)(shmPtr + 44) = 0;
netConnect((unsigned int)((_DWORD)configstruct + 1024), configstruct);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v9 = (_BYTE *)netReadLine();
v10 = memcmp(v9, "+ MNM ", 6uLL) != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
break;
sendVersion();
}
v13 = "+ Clie";
v14 = 6LL;
v15 = v9;
do
{
if ( !v14 )
break;
v11 = *v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) != v11 )
break;
sendGameId(dest, v15);
}
if ( memcmp(v9, "+ PLAY", 6uLL) )
break;
parseGamekind(v9, shmPtr);
sendPlayer((unsigned int)v4, shmPtr);
}
}
while ( !memcmp(v9, "+ ENDP", 6uLL) );
if ( memcmp(v9, "+ MOVE", 6uLL) )
break;
parseMovetimeout(v9, shmPtr);
}
v16 = memcmp(v9, "+ NEXT", 6uLL) != 0;
v17 = 0;
v18 = !v16;
if ( v16 )
break;
parseNext(v9, shmPtr);
}
v19 = "+ FIEL";
v20 = 6LL;
v21 = v9;
do
{
if ( !v20 )
break;
v17 = *v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
v22 = (!v17 && !v18) - v17;
v23 = 0;
v24 = v22 == 0;
if ( v22 )
break;
parseField(v9, v21);
}
v25 = "+ ENDF";
v26 = 6LL;
v27 = v9;
do
{
if ( !v26 )
break;
v23 = *v27 < (unsigned int)*v25;
v24 = *v27++ == *v25++;
--v26;
}
while ( v24 );
if ( (!v23 && !v24) != v23 )
break;
if ( *(_DWORD *)(shmPtr + 600) != 1 )
sendThinking(v25, v27);
}
if ( memcmp(v9, "+ OKTH", 6uLL) )
break;
if ( (unsigned int)ueberwacheFd(pipedes, v9) == 1 )
{
log_printf(2LL, "Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
sendMove(v9);
}
else
{
log_printf(1LL, "Gandalf ist ersoffen\n");
}
}
if ( strncmp(v9, "+ WAIT", 6uLL) )
break;
sendOkwait();
}
if ( strncmp(v9, "+ GAME", 6uLL) )
break;
*(_DWORD *)(shmPtr + 600) = 1;
parseGameover(v9);
}
if ( !strncmp(v9, "+ QUIT", 6uLL) )
break;
if ( *v9 == 45 )
{
netDisconnect();
free(v3);
v28 = getppid();
kill(v28, 17);
return 0;
}
}
netDisconnect();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char v4; // bp
int v5; // eax
__int64 v6; // rbx
__pid_t v7; // eax
_BYTE *v9; // rbx
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
const char *v15; // rsi
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
char v22; // al
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
__int64 v26; // rcx
const char *v27; // rsi
__pid_t v28; // eax
_BYTE v29[3072]; // [rsp+0h] [rbp-C58h] BYREF
int v30; // [rsp+C00h] [rbp-58h]
int pipedes[2]; // [rsp+C18h] [rbp-40h] BYREF
char dest[55]; // [rsp+C21h] [rbp-37h] BYREF

v3 = (char *)malloc(0x100uLL);
strcpy(v3, "client.conf");
log_printf(2LL, "Using config-file %s\n", v3);
get_config(v29, v3);
qmemcpy(configstruct, v29, 0xC00uLL);
configstruct[768] = v30;
log_printf(1LL, "\n");
if ( argc <= 1 )
{
puts("Keine Game-Id angegeben!");
func0();
exit(1);
}
strcpy(dest, argv[1]);
if ( strlen(dest) != 11 )
{
puts("Game-Id muss 11-stellig sein!");
func0();
exit(1);
}
v4 = 51;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:c:l:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
configstruct[768] = atoi(optarg);
break;
case 'p':
v4 = *optarg;
if ( (unsigned __int8)(*optarg - 48) > 1u )
{
puts("Es gibt nur 2 Spieler! 0 oder 1 eingeben!");
func0();
exit(1);
}
break;
case 'c':
strcpy(v3, optarg);
break;
default:
func0();
exit(1);
}
}
v6 = (unsigned int)shmSegment(604LL);
shmPtr = shmAnbinden(v6);
shmDelete((unsigned int)v6);
if ( pipe(pipedes) < 0 )
log_printf(0LL, "Fehler bei Pipe anlegen");
v7 = fork();
if ( v7 == -1 )
{
log_printf(0LL, "Fehler bei fork()\n");
}
else
{
if ( v7 )
{
*(_DWORD *)(shmPtr + 40) = v7;
signal(10, (__sighandler_t)&signalHandler);
signal(17, (__sighandler_t)&endHandler);
while ( 1 )
{
pause();
log_printf(2LL, "thinker hat fertig gedacht\n");
pipe_write(pipedes);
}
}
*(_DWORD *)(shmPtr + 44) = 0;
netConnect((unsigned int)((_DWORD)configstruct + 1024), configstruct);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v9 = (_BYTE *)netReadLine();
v10 = memcmp(v9, "+ MNM ", 6uLL) != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
break;
sendVersion();
}
v13 = "+ Clie";
v14 = 6LL;
v15 = v9;
do
{
if ( !v14 )
break;
v11 = *v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) != v11 )
break;
sendGameId(dest, v15);
}
if ( memcmp(v9, "+ PLAY", 6uLL) )
break;
parseGamekind(v9, shmPtr);
sendPlayer((unsigned int)v4, shmPtr);
}
}
while ( !memcmp(v9, "+ ENDP", 6uLL) );
if ( memcmp(v9, "+ MOVE", 6uLL) )
break;
parseMovetimeout(v9, shmPtr);
}
v16 = memcmp(v9, "+ NEXT", 6uLL) != 0;
v17 = 0;
v18 = !v16;
if ( v16 )
break;
parseNext(v9, shmPtr);
}
v19 = "+ FIEL";
v20 = 6LL;
v21 = v9;
do
{
if ( !v20 )
break;
v17 = *v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
v22 = (!v17 && !v18) - v17;
v23 = 0;
v24 = v22 == 0;
if ( v22 )
break;
parseField(v9, v21);
}
v25 = "+ ENDF";
v26 = 6LL;
v27 = v9;
do
{
if ( !v26 )
break;
v23 = *v27 < (unsigned int)*v25;
v24 = *v27++ == *v25++;
--v26;
}
while ( v24 );
if ( (!v23 && !v24) != v23 )
break;
if ( *(_DWORD *)(shmPtr + 600) != 1 )
sendThinking(v25, v27);
}
if ( memcmp(v9, "+ OKTH", 6uLL) )
break;
if ( (unsigned int)ueberwacheFd(pipedes, v9) == 1 )
{
log_printf(2LL, "Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
sendMove(v9);
}
else
{
log_printf(1LL, "Gandalf ist ersoffen\n");
}
}
if ( strncmp(v9, "+ WAIT", 6uLL) )
break;
sendOkwait();
}
if ( strncmp(v9, "+ GAME", 6uLL) )
break;
*(_DWORD *)(shmPtr + 600) = 1;
parseGameover(v9);
}
if ( !strncmp(v9, "+ QUIT", 6uLL) )
break;
if ( *v9 == 45 )
{
netDisconnect();
free(v3);
v28 = getppid();
kill(v28, 17);
return 0;
}
}
netDisconnect();
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int ret;
 char player = '3';
 char gameId[15];
 char *confDateiName = malloc(256);
 strcpy(confDateiName, "client.conf");
 pid_t pid;
 log_printf(2,"Using config-file %s\n",confDateiName);
 configstruct = get_config(confDateiName);
 log_printf(1,"\n");
 if (argc < 2) {
  printf("Keine Game-Id angegeben!\n");
  help();
  exit(1);
 }
 strcpy(gameId,argv[1]);
 if(strlen(gameId) != 11) {
  printf("Game-Id muss 11-stellig sein!\n");
  help();
  exit(1);
 }
 while ((ret=getopt(argc, argv, "p:c:l:")) != -1) {
 switch (ret) {
 case 'p':
  player = optarg[0];
  if (player!='0' && player != '1') {
   printf("Es gibt nur 2 Spieler! 0 oder 1 eingeben!\n");
   help();
   exit(1);
  }
  break;
 case 'c':
  strcpy(confDateiName, optarg);
  break;
 case 'l':
  configstruct.loglevel = atoi(optarg);
  break;
 default:
  help();
  exit(1);
 }
 }
 int shmid = shmSegment(sizeof(struct shmInfos));
 shmPtr = shmAnbinden(shmid);
 shmDelete(shmid);
 int pipe_fd[2];
 if(pipe(pipe_fd)<0){
  log_printf(0,"Fehler bei Pipe anlegen");
 };
 switch (pid = fork ()) {
 case -1:
  log_printf (0,"Fehler bei fork()\n");
  break;
 case 0:
  shmPtr->pid1=pid;
  char *getText;
  netConnect(configstruct.port, configstruct.hostname);
  while (1) {
   getText = netReadLine();
   if (strncmp(getText, "+ MNM ",6) == 0) {
    sendVersion();
   } else if (strncmp(getText, "+ Clie",6) == 0) {
    sendGameId(gameId);
   } else if (strncmp(getText, "+ PLAY",6) == 0) {
    parseGamekind(getText, shmPtr);
    sendPlayer(player, shmPtr);
   } else if (strncmp(getText, "+ ENDP",6) == 0) {
   } else if (strncmp(getText, "+ MOVE",6) == 0) {
    parseMovetimeout(getText, shmPtr);
   } else if (strncmp(getText, "+ NEXT",6) == 0) {
    parseNext(getText, shmPtr);
   } else if (strncmp(getText, "+ FIEL",6) == 0) {
    parseField(getText);
   } else if (strncmp(getText, "+ ENDF",6) == 0) {
        if (shmPtr->gameover != 1) {
      sendThinking();
        }
   } else if (strncmp(getText, "+ OKTH",6) == 0) {
    if(ueberwacheFd(pipe_fd,getText)==1){
     log_printf(2,"Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
     sendMove(getText);
    }
    else{
     log_printf(1,"Gandalf ist ersoffen\n");
    }
   } else if (strncmp(getText, "+ WAIT",6) == 0) {
    sendOkwait();
   } else if (strncmp(getText, "+ GAME",6) == 0) {
        shmPtr->gameover = 1;
    parseGameover(getText);
   } else if (strncmp(getText, "+ QUIT",6) == 0) {
    netDisconnect();
    break;
   } else if (strncmp(getText, "-",1) == 0) {
    netDisconnect();
    free(confDateiName);
    kill(getppid(),17);
    break;
   }
  }
  break;
 default:
  shmPtr->pid0=pid;
  signal(10, signalHandler);
  signal(17, endHandler);
  while (1){
   pause();
   log_printf(2,"thinker hat fertig gedacht\n");
   pipe_write(pipe_fd);
  }
  if (wait (((void *)0)) != pid) {
   log_printf(0,"Fehler beim Warten auf den Kindprozess\n");
   return 1;
  }
  break;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int ret;
 char player = '3';
 char gameId[15];
 char *confDateiName = malloc(256);
 strcpy(confDateiName, "client.conf");
 int pid;
 log_printf(2,"Using config-file %s\n",confDateiName);
 configstruct = get_config(confDateiName);
 log_printf(1,"\n");
 if (argc < 2) {
  printf("Keine Game-Id angegeben!\n");
  help();
  exit(1);
 }
 strcpy(gameId,argv[1]);
 if(strlen(gameId) != 11) {
  printf("Game-Id muss 11-stellig sein!\n");
  help();
  exit(1);
 }
 while ((ret=getopt(argc, argv, "p:c:l:")) != -1) {
 switch (ret) {
 case 'p':
  player = optarg[0];
  if (player!='0' && player != '1') {
   printf("Es gibt nur 2 Spieler! 0 oder 1 eingeben!\n");
   help();
   exit(1);
  }
  break;
 case 'c':
  strcpy(confDateiName, optarg);
  break;
 case 'l':
  configstruct.loglevel = atoi(optarg);
  break;
 default:
  help();
  exit(1);
 }
 }
 int shmid = shmSegment(sizeof(struct shmInfos));
 shmPtr = shmAnbinden(shmid);
 shmDelete(shmid);
 int pipe_fd[2];
 if(pipe(pipe_fd)<0){
  log_printf(0,"Fehler bei Pipe anlegen");
 };
 switch (pid = fork ()) {
 case -1:
  log_printf (0,"Fehler bei fork()\n");
  break;
 case 0:
  shmPtr->pid1=pid;
  char *getText;
  netConnect(configstruct.port, configstruct.hostname);
  while (1) {
   getText = netReadLine();
   if (strncmp(getText, "+ MNM ",6) == 0) {
    sendVersion();
   } else if (strncmp(getText, "+ Clie",6) == 0) {
    sendGameId(gameId);
   } else if (strncmp(getText, "+ PLAY",6) == 0) {
    parseGamekind(getText, shmPtr);
    sendPlayer(player, shmPtr);
   } else if (strncmp(getText, "+ ENDP",6) == 0) {
   } else if (strncmp(getText, "+ MOVE",6) == 0) {
    parseMovetimeout(getText, shmPtr);
   } else if (strncmp(getText, "+ NEXT",6) == 0) {
    parseNext(getText, shmPtr);
   } else if (strncmp(getText, "+ FIEL",6) == 0) {
    parseField(getText);
   } else if (strncmp(getText, "+ ENDF",6) == 0) {
        if (shmPtr->gameover != 1) {
      sendThinking();
        }
   } else if (strncmp(getText, "+ OKTH",6) == 0) {
    if(ueberwacheFd(pipe_fd,getText)==1){
     log_printf(2,"Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
     sendMove(getText);
    }
    else{
     log_printf(1,"Gandalf ist ersoffen\n");
    }
   } else if (strncmp(getText, "+ WAIT",6) == 0) {
    sendOkwait();
   } else if (strncmp(getText, "+ GAME",6) == 0) {
        shmPtr->gameover = 1;
    parseGameover(getText);
   } else if (strncmp(getText, "+ QUIT",6) == 0) {
    netDisconnect();
    break;
   } else if (strncmp(getText, "-",1) == 0) {
    netDisconnect();
    free(confDateiName);
    kill(getppid(),17);
    break;
   }
  }
  break;
 default:
  shmPtr->pid0=pid;
  signal(10, signalHandler);
  signal(17, endHandler);
  while (1){
   pause();
   log_printf(2,"thinker hat fertig gedacht\n");
   pipe_write(pipe_fd);
  }
  if (wait (((void *)0)) != pid) {
   log_printf(0,"Fehler beim Warten auf den Kindprozess\n");
   return 1;
  }
  break;
 }
 return 0;
}

variable_types: ret int

variable_types: player char

variable_types:
gameId
char [15]

variable_types:
confDateiName
char *

variable_types: pid int

variable_types: shmid int

variable_types:
getText
char *


decompiled_code:
int __fastcall connector2thinker(__pid_t a1)
{
return kill(a1, 10);
}

canonical_decompiled_code:
int __fastcall func0(__pid_t a1)
{
return kill(a1, 10);
}

original_code:
void connector2thinker( pid_t pid ) {
   kill(pid, 10);
}

canonical_original_code:
void connector2thinker(int pid) {
   kill(pid, 10);
}


signalHandler

decompiled_code:
__int64 signalHandler()
{
__int64 result; // rax

result = shmPtr;
if ( *(_DWORD *)(shmPtr + 48LL) )
{
*(_DWORD *)(shmPtr + 48LL) = 0;
result = think();
}
return result;
}

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

result = shmPtr;
if ( *(_DWORD *)(shmPtr + 48LL) )
{
*(_DWORD *)(shmPtr + 48LL) = 0;
result = think();
}
return result;
}

original_code:
void signalHandler(int signum) {
 if (shmPtr->flag == 0) {
  return;
 }
 shmPtr->flag = 0;
 think();
}

variable_types: signum int


endHandler

decompiled_code:
void __noreturn endHandler()
{
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
exit(1);
}

original_code:
void endHandler(int signum) {
 exit(1);
}


sendOkwait

decompiled_code:
__int64 sendOkwait()
{
__int64 v1[33]; // [rsp+0h] [rbp-108h] BYREF

v1[0] = 0xA544941574B4FLL;
netWrite(v1);
return log_printf(1LL, "Warten auf den anderen Spieler\n");
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1[33]; // [rsp+0h] [rbp-108h] BYREF

v1[0] = 0xA544941574B4FLL;
netWrite(v1);
return log_printf(1LL, "Warten auf den anderen Spieler\n");
}

original_code:
void sendOkwait() {
 char sendText[251];
 snprintf(sendText,10,"OKWAIT\n");
 netWrite(sendText);
 log_printf(1,"Warten auf den anderen Spieler\n");
}

variable_types:
sendText
char [251]


sendVersion

decompiled_code:
__int64 sendVersion()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v1, 0x17uLL, "VERSION %s\n", "1.42");
return netWrite(v1);
}

canonical_decompiled_code:
__int64 func2()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v1, 0x17uLL, "VERSION %s\n", "1.42");
return netWrite(v1);
}

original_code:
void sendVersion() {
 char sendText[251];
 snprintf(sendText,23,"VERSION %s\n","1.42");
 netWrite(sendText);
}


sendGameId

decompiled_code:
__int64 __fastcall sendGameId(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x10uLL, "ID %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Game ID: %s\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x10uLL, "ID %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Game ID: %s\n", a1);
}

original_code:
void sendGameId(char* gameId) {
 char sendText[251];
 snprintf(sendText,16,"ID %s\n",gameId);
 netWrite(sendText);
 log_printf(1,"Game ID: %s\n",gameId);
}

canonical_original_code:
void sendGameId(char *gameId) {
 char sendText[251];
 snprintf(sendText,16,"ID %s\n",gameId);
 netWrite(sendText);
 log_printf(1,"Game ID: %s\n",gameId);
}

variable_types:
gameId
char *


parseGamekind

decompiled_code:
__int64 __fastcall parseGamekind(char *src, char *dest)
{
bool v2; // cf
bool v3; // zf
char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx
__int64 v7; // rax

log_printf(1LL, "%s\n\n", src + 2);
strcpy(dest, src);
v4 = src + 10;
v5 = "Quarto";
v6 = 7LL;
do
{
if ( !v6 )
break;
v2 = (unsigned __int8)*v4 < (unsigned int)*v5;
v3 = *v4++ == *v5++;
--v6;
}
while ( v3 );
if ( (!v2 && !v3) != v2 )
{
log_printf(0LL, "Du spielst nicht Quarto, du Depp!");
exit(1);
}
v7 = netReadLine(v5, v4);
return log_printf(1LL, "Name: %s\n", (const char *)(v7 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, char *dest)
{
bool v2; // cf
bool v3; // zf
char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx
__int64 v7; // rax

log_printf(1LL, "%s\n\n", src + 2);
strcpy(dest, src);
v4 = src + 10;
v5 = "Quarto";
v6 = 7LL;
do
{
if ( !v6 )
break;
v2 = (unsigned __int8)*v4 < (unsigned int)*v5;
v3 = *v4++ == *v5++;
--v6;
}
while ( v3 );
if ( (!v2 && !v3) != v2 )
{
log_printf(0LL, "Du spielst nicht Quarto, du Depp!");
exit(1);
}
v7 = netReadLine(v5, v4);
return log_printf(1LL, "Name: %s\n", (const char *)(v7 + 2));
}

original_code:
void parseGamekind(char* getText, struct shmInfos *shmPtr) {
 log_printf(1,"%s\n\n",getText+2);
 strcpy(shmPtr->spielname,getText);
 if(strcmp((getText+10),"Quarto")!=0) {
  log_printf(0,"Du spielst nicht Quarto, du Depp!");
  exit(1);
 }
 getText = netReadLine();
 log_printf(1,"Name: %s\n",getText+2);
}

canonical_original_code:
void parseGamekind(char *getText, struct shmInfos *shmPtr) {
 log_printf(1,"%s\n\n",getText+2);
 strcpy(shmPtr->spielname,getText);
 if(strcmp((getText+10),"Quarto")!=0) {
  log_printf(0,"Du spielst nicht Quarto, du Depp!");
  exit(1);
 }
 getText = netReadLine();
 log_printf(1,"Name: %s\n",getText+2);
}

variable_types: struct shmInfos { char spielname[30]; int eigSpielernummer; int anzahlSpieler; int pid0; int pid1; int flag; struct playerAttr { int spielerNr; char name[256]; int registered; } attr[2]; int moveTimeout; int nextStone; int breite; int hoehe; int shmid_Sf; int gameover; } *

user_defined_types: struct shmInfos { char spielname[30]; int eigSpielernummer; int anzahlSpieler; int pid0; int pid1; int flag; struct playerAttr attr[2]; int moveTimeout; int nextStone; int breite; int hoehe; int shmid_Sf; int gameover; }


sendPlayer

original_code:
void sendPlayer(int player, struct shmInfos *shmPtr) {
 char sendText[251];
 char *getText;
 int i=0;
 if (player!='3') {
  snprintf(sendText,15,"PLAYER %c\n", player);
 }
 else {
  snprintf(sendText,10,"PLAYER\n");
 }
 netWrite(sendText);
 getText = netReadLine();
 shmPtr->eigSpielernummer = getText[6]-'0';
 shmPtr->attr[shmPtr->eigSpielernummer].spielerNr = shmPtr->eigSpielernummer;
 strcpy(shmPtr->attr[shmPtr->eigSpielernummer].name,getText+8);
 shmPtr->attr[shmPtr->eigSpielernummer].registered = 1;
 log_printf(1,"You are Player %i (",getText[6]-'0'+1);
 i=8;
 while(getText[i] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,")\n");
 log_printf(1,"\n");
 getText = netReadLine();
 shmPtr->anzahlSpieler = getText[8]-'0';
 getText = netReadLine();
 int anzSp = (getText[2]-'0')-1;
 shmPtr->attr[anzSp].spielerNr = anzSp;
 strncpy(shmPtr->attr[anzSp].name,getText+4,strlen(getText+4)-2);
 shmPtr->attr[anzSp].name[strlen(getText+4)-2] = '\0';
 shmPtr->attr[anzSp].registered = getText[strlen(getText)-1]-'0';
 log_printf(1,"Player %c (",getText[2]);
 i=4;
 while(getText[i+2] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,") is ");
 if (getText[i+1] == '1') {
  log_printf(1,"ready\n\n");
 } else
 {
  log_printf(1,"not ready\n\n");
 }
}

canonical_original_code:
void sendPlayer(int player, struct shmInfos *shmPtr) {
 char sendText[251];
 char *getText;
 int i = 0;
 if (player!='3') {
  snprintf(sendText,15,"PLAYER %c\n", player);
 }
 else {
  snprintf(sendText,10,"PLAYER\n");
 }
 netWrite(sendText);
 getText = netReadLine();
 shmPtr->eigSpielernummer = getText[6]-'0';
 shmPtr->attr[shmPtr->eigSpielernummer].spielerNr = shmPtr->eigSpielernummer;
 strcpy(shmPtr->attr[shmPtr->eigSpielernummer].name,getText+8);
 shmPtr->attr[shmPtr->eigSpielernummer].registered = 1;
 log_printf(1,"You are Player %i (",getText[6]-'0'+1);
 i=8;
 while(getText[i] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,")\n");
 log_printf(1,"\n");
 getText = netReadLine();
 shmPtr->anzahlSpieler = getText[8]-'0';
 getText = netReadLine();
 int anzSp = (getText[2]-'0')-1;
 shmPtr->attr[anzSp].spielerNr = anzSp;
 strncpy(shmPtr->attr[anzSp].name,getText+4,strlen(getText+4)-2);
 shmPtr->attr[anzSp].name[strlen(getText+4)-2] = '\0';
 shmPtr->attr[anzSp].registered = getText[strlen(getText)-1]-'0';
 log_printf(1,"Player %c (",getText[2]);
 i=4;
 while(getText[i+2] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,") is ");
 if (getText[i+1] == '1') {
  log_printf(1,"ready\n\n");
 } else
 {
  log_printf(1,"not ready\n\n");
 }
}

variable_types: player int

variable_types: i int

variable_types: anzSp int

user_defined_types: struct playerAttr { int spielerNr; char name[256]; int registered; }


parseMovetimeout

decompiled_code:
int __fastcall parseMovetimeout(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 580) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 580) = result;
return result;
}

original_code:
void parseMovetimeout(char* getText, struct shmInfos *shmPtr) {
 int time = atoi(getText+7);
 shmPtr->moveTimeout = time;
}

canonical_original_code:
void parseMovetimeout(char *getText, struct shmInfos *shmPtr) {
 int time = atoi(getText+7);
 shmPtr->moveTimeout = time;
}

variable_types: time int


parseNext

decompiled_code:
int __fastcall parseNext(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 584) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 584) = result;
return result;
}

original_code:
void parseNext(char* getText, struct shmInfos *shmPtr) {
 int next = atoi(getText+7);
 shmPtr->nextStone = next;
}

canonical_original_code:
void parseNext(char *getText, struct shmInfos *shmPtr) {
 int next = atoi(getText+7);
 shmPtr->nextStone = next;
}

variable_types: next int


parseField

decompiled_code:
__int64 __fastcall parseField(const char *a1, const char *a2)
{
int v2; // ebp
int v3; // eax
char v4; // dl
__int64 v5; // rcx
__int64 v6; // rax
int v7; // eax
int v8; // ebp
__int64 v9; // rbx
unsigned int v10; // er12
__int64 v11; // rax
int i; // ebx
__int64 j; // rbx
char v15; // [rsp+1h] [rbp-39h]
char v16[8]; // [rsp+2h] [rbp-38h] BYREF
char nptr[48]; // [rsp+Ah] [rbp-30h] BYREF

v2 = *(_DWORD *)(shmPtr + 588LL);
if ( v2 )
{
v8 = *(_DWORD *)(shmPtr + 592LL);
}
else
{
v3 = strlen(a1);
v4 = *a1;
if ( *a1 != 44 && v3 > 1 )
{
v5 = (unsigned int)(v3 - 2) + 2LL;
v6 = 1LL;
do
{
*(&v15 + v6) = v4;
v2 = v6;
v4 = a1[v6];
if ( v4 == 44 )
break;
++v6;
}
while ( v6 != v5 );
}
v16[v2] = 0;
v7 = strlen(v16);
v8 = atoi(&a1[v7 + 1]);
v9 = (unsigned int)atoi(nptr);
log_printf(1LL, "Breite: %i\n", v9);
log_printf(1LL, "Hoehe: %i\n", (unsigned int)v8);
v10 = shmSegment((unsigned int)(4 * v9 * v8));
*(_DWORD *)(shmPtr + 596LL) = v10;
shmPtr_Sf = shmSpielfeldAnbinden(v10);
shmDelete(v10);
v11 = shmPtr;
*(_DWORD *)(shmPtr + 588LL) = v9;
*(_DWORD *)(v11 + 592) = v8;
log_printf(2LL, "Hoehe im Shared Memory: %i\n", (unsigned int)v8);
a2 = "Breite im Shared Memory: %i\n";
a1 = (_BYTE *)&loc_2;
log_printf(2LL, "Breite im Shared Memory: %i\n", *(unsigned int *)(shmPtr + 588LL));
}
if ( v8 > 0 )
{
for ( i = 0; i != v8; ++i )
{
a1 = (const char *)netReadLine(a1, a2);
saveField((__int64)a1);
}
}
log_printf(2LL, "Spielfeldarray: ");
for ( j = 0LL; j != 64; j += 4LL )
log_printf(2LL, "%i ", *(unsigned int *)(shmPtr_Sf + j));
log_printf(2LL, "\n");
log_printf(1LL, aN, *(unsigned int *)(shmPtr + 584LL));
printSpielstein(*(unsigned int *)(shmPtr + 584LL));
log_printf(1LL, "\n");
return printField();
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
int v2; // ebp
int v3; // eax
char v4; // dl
__int64 v5; // rcx
__int64 v6; // rax
int v7; // eax
int v8; // ebp
__int64 v9; // rbx
unsigned int v10; // er12
__int64 v11; // rax
int i; // ebx
__int64 j; // rbx
char v15; // [rsp+1h] [rbp-39h]
char v16[8]; // [rsp+2h] [rbp-38h] BYREF
char nptr[48]; // [rsp+Ah] [rbp-30h] BYREF

v2 = *(_DWORD *)(shmPtr + 588LL);
if ( v2 )
{
v8 = *(_DWORD *)(shmPtr + 592LL);
}
else
{
v3 = strlen(a1);
v4 = *a1;
if ( *a1 != 44 && v3 > 1 )
{
v5 = (unsigned int)(v3 - 2) + 2LL;
v6 = 1LL;
do
{
*(&v15 + v6) = v4;
v2 = v6;
v4 = a1[v6];
if ( v4 == 44 )
break;
++v6;
}
while ( v6 != v5 );
}
v16[v2] = 0;
v7 = strlen(v16);
v8 = atoi(&a1[v7 + 1]);
v9 = (unsigned int)atoi(nptr);
log_printf(1LL, "Breite: %i\n", v9);
log_printf(1LL, "Hoehe: %i\n", (unsigned int)v8);
v10 = shmSegment((unsigned int)(4 * v9 * v8));
*(_DWORD *)(shmPtr + 596LL) = v10;
shmPtr_Sf = shmSpielfeldAnbinden(v10);
shmDelete(v10);
v11 = shmPtr;
*(_DWORD *)(shmPtr + 588LL) = v9;
*(_DWORD *)(v11 + 592) = v8;
log_printf(2LL, "Hoehe im Shared Memory: %i\n", (unsigned int)v8);
a2 = "Breite im Shared Memory: %i\n";
a1 = (_BYTE *)&loc_2;
log_printf(2LL, "Breite im Shared Memory: %i\n", *(unsigned int *)(shmPtr + 588LL));
}
if ( v8 > 0 )
{
for ( i = 0; i != v8; ++i )
{
a1 = (const char *)netReadLine(a1, a2);
func0((__int64)a1);
}
}
log_printf(2LL, "Spielfeldarray: ");
for ( j = 0LL; j != 64; j += 4LL )
log_printf(2LL, "%i ", *(unsigned int *)(shmPtr_Sf + j));
log_printf(2LL, "\n");
log_printf(1LL, aN, *(unsigned int *)(shmPtr + 584LL));
printSpielstein(*(unsigned int *)(shmPtr + 584LL));
log_printf(1LL, "\n");
return printField();
}

original_code:
void parseField(char* getText) {
 int hoehe;
 int breite;
 if (shmPtr->breite == 0) {
  int len = strlen(getText);
  char breiteChar[20];
  int i=0;
  while (getText[i] != ',' && i<len-1) {
   breiteChar[i] = getText[i];
   i++;
  }
  breiteChar[i] = '\0';
  int lenB = strlen(breiteChar);
  hoehe = atoi(getText+lenB+1);
  breite = atoi(breiteChar+8);
  log_printf(1,"Breite: %i\n",breite);
  log_printf(1,"Hoehe: %i\n",hoehe);
  int shmid_Sf = shmSegment(hoehe*breite*sizeof(int));
  shmPtr->shmid_Sf = shmid_Sf;
  shmPtr_Sf = shmSpielfeldAnbinden(shmid_Sf);
  shmDelete(shmid_Sf);
  shmPtr->breite = breite;
  shmPtr->hoehe = hoehe;
  log_printf(2,"Hoehe im Shared Memory: %i\n",shmPtr->hoehe);
  log_printf(2,"Breite im Shared Memory: %i\n",shmPtr->breite);
 }
 else {
  breite = shmPtr->breite;
  hoehe = shmPtr->hoehe;
 }
 for (int i=0; i<hoehe; i++) {
  getText = netReadLine();
  saveField(getText);
 }
 log_printf(2,"Spielfeldarray: ");
 for(int i=0; i<16; i++) {
  log_printf(2,"%i ",shmPtr_Sf[i]);
 }
 log_printf(2,"\n");
 log_printf(1,"\nNächster Stein: (%i)",shmPtr->nextStone);
 printSpielstein(shmPtr->nextStone);
 log_printf(1,"\n");
 printField();
}

canonical_original_code:
void parseField(char *getText) {
 int hoehe;
 int breite;
 if (shmPtr->breite == 0) {
  int len = strlen(getText);
  char breiteChar[20];
  int i = 0;
  while (getText[i] != ',' && i<len-1) {
   breiteChar[i] = getText[i];
   i++;
  }
  breiteChar[i] = '\0';
  int lenB = strlen(breiteChar);
  hoehe = atoi(getText+lenB+1);
  breite = atoi(breiteChar+8);
  log_printf(1,"Breite: %i\n",breite);
  log_printf(1,"Hoehe: %i\n",hoehe);
  int shmid_Sf = shmSegment(hoehe*breite*sizeof(int));
  shmPtr->shmid_Sf = shmid_Sf;
  shmPtr_Sf = shmSpielfeldAnbinden(shmid_Sf);
  shmDelete(shmid_Sf);
  shmPtr->breite = breite;
  shmPtr->hoehe = hoehe;
  log_printf(2,"Hoehe im Shared Memory: %i\n",shmPtr->hoehe);
  log_printf(2,"Breite im Shared Memory: %i\n",shmPtr->breite);
 }
 else {
  breite = shmPtr->breite;
  hoehe = shmPtr->hoehe;
 }
 for (int i = 0; i<hoehe; i++) {
  getText = netReadLine();
  saveField(getText);
 }
 log_printf(2,"Spielfeldarray: ");
 for(int i = 0; i<16; i++) {
  log_printf(2,"%i ",shmPtr_Sf[i]);
 }
 log_printf(2,"\n");
 log_printf(1,"\nNächster Stein: (%i)",shmPtr->nextStone);
 printSpielstein(shmPtr->nextStone);
 log_printf(1,"\n");
 printField();
}

variable_types: hoehe int

variable_types: breite int

variable_types: len int

variable_types:
breiteChar
char [20]

variable_types: lenB int


sendThinking

decompiled_code:
__int64 sendThinking()
{
unsigned int v0; // eax
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

*(_DWORD *)(shmPtr + 48LL) = 1;
v0 = getppid();
connector2thinker(v0);
strcpy(v2, "THINKING\n");
netWrite(v2);
return log_printf(1LL, "\nSpielzug wird berechnet...");
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // eax
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

*(_DWORD *)(shmPtr + 48LL) = 1;
v0 = getppid();
connector2thinker(v0);
strcpy(v2, "THINKING\n");
netWrite(v2);
return log_printf(1LL, "\nSpielzug wird berechnet...");
}

original_code:
void sendThinking() {
 shmPtr->flag = 1;
 connector2thinker(getppid());
 char sendText[251];
 snprintf(sendText,12,"THINKING\n");
 netWrite(sendText);
 log_printf(1,"\nSpielzug wird berechnet...");
}


parseGameover

decompiled_code:
__int64 __fastcall parseGameover(__int64 a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax

v1 = atoi((const char *)(a1 + 11)) - 1;
v2 = *(_DWORD *)(shmPtr + 32LL);
if ( v1 == v2 )
result = log_printf(1LL, "\x1B[1m\x1B[32mYou, %s, won the game.\n\x1B[0m", (const char *)(shmPtr + 264LL * v2 + 56));
else
result = log_printf(
1LL,
"\x1B[1m\x1B[31mYou lost the game. %s won.\n\x1B[0m",
(const char *)(shmPtr + 264LL * v1 + 56));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax

v1 = atoi((const char *)(a1 + 11)) - 1;
v2 = *(_DWORD *)(shmPtr + 32LL);
if ( v1 == v2 )
result = log_printf(1LL, "\x1B[1m\x1B[32mYou, %s, won the game.\n\x1B[0m", (const char *)(shmPtr + 264LL * v2 + 56));
else
result = log_printf(
1LL,
"\x1B[1m\x1B[31mYou lost the game. %s won.\n\x1B[0m",
(const char *)(shmPtr + 264LL * v1 + 56));
return result;
}

original_code:
void parseGameover(char* getText) {
  int winnerid = atoi(getText+11);
  if (winnerid - 1 == shmPtr->eigSpielernummer) {
    log_printf(1, "\033[1m\033[32m""You, %s, won the game.\n""\033[0m", shmPtr->attr[shmPtr->eigSpielernummer].name);
  } else {
    log_printf(1, "\033[1m\033[31m""You lost the game. %s won.\n""\033[0m", shmPtr->attr[winnerid - 1].name);
  }
}

canonical_original_code:
void parseGameover(char *getText) {
  int winnerid = atoi(getText+11);
  if (winnerid - 1 == shmPtr->eigSpielernummer) {
    log_printf(1, "\033[1m\033[32m""You, %s, won the game.\n""\033[0m", shmPtr->attr[shmPtr->eigSpielernummer].name);
  } else {
    log_printf(1, "\033[1m\033[31m""You lost the game. %s won.\n""\033[0m", shmPtr->attr[winnerid - 1].name);
  }
}

variable_types: winnerid int


sendMove

decompiled_code:
__int64 __fastcall sendMove(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0xFuLL, "PLAY %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Done: %s\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0xFuLL, "PLAY %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Done: %s\n", a1);
}

original_code:
void sendMove(char *spielzug) {
 char sendText[251];
 snprintf(sendText,15,"PLAY %s\n", spielzug);
 netWrite(sendText);
 log_printf(1,"Done: %s\n",spielzug);
}

variable_types:
spielzug
char *


saveField

original_code:
void saveField(char *getText) {
  int breite = shmPtr->breite;
 char charHelp[255];
  int i = 2;
  int j =0;
 while (getText[i] != ' ') {
  charHelp[j] = getText[i];
  j++;
  i++;
 }
 charHelp[j] = '\0';
 i++;
 int zeile = breite-atoi(charHelp);
  int currentField = zeile*breite;
 while (breite) {
   if (getText[i] == '*') {
     shmPtr_Sf[currentField]= -1;
   i++;
  }
  else if(getText[i] !=' ') {
   j=0;
   while(getText[i] != ' ') {
    charHelp[j] = getText[i];
    j++;
    i++;
   }
   charHelp[j] = '\0';
   shmPtr_Sf[currentField] = atoi(charHelp);
  }
  currentField++;
  i++;
  breite--;
 }
}

canonical_original_code:
void saveField(char *getText) {
  int breite = shmPtr->breite;
 char charHelp[255];
  int i = 2;
  int j = 0;
 while (getText[i] != ' ') {
  charHelp[j] = getText[i];
  j++;
  i++;
 }
 charHelp[j] = '\0';
 i++;
 int zeile = breite-atoi(charHelp);
  int currentField = zeile*breite;
 while (breite) {
   if (getText[i] == '*') {
     shmPtr_Sf[currentField]= -1;
   i++;
  }
  else if(getText[i] !=' ') {
   j=0;
   while(getText[i] != ' ') {
    charHelp[j] = getText[i];
    j++;
    i++;
   }
   charHelp[j] = '\0';
   shmPtr_Sf[currentField] = atoi(charHelp);
  }
  currentField++;
  i++;
  breite--;
 }
}

variable_types:
getText
char *

variable_types:
charHelp
char [255]

variable_types: j int

variable_types: zeile int

variable_types: currentField int


decompiled_code:
int log_printf(int a1, const char *a2, ...)
{
int result; // eax
char v3[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

if ( configstruct[768] >= a1 )
{
va_start(arg, a2);
vsnprintf(v3, 0x400uLL, a2, arg);
if ( !a1 )
printf("\x1B[1m\x1B[31m");
result = printf("%s\x1B[0m", v3);
}
return result;
}

canonical_decompiled_code:
int func0(int a1, const char *a2, ...)
{
int result; // eax
char v3[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

if ( configstruct[768] >= a1 )
{
va_start(arg, a2);
vsnprintf(v3, 0x400uLL, a2, arg);
if ( !a1 )
printf("\x1B[1m\x1B[31m");
result = printf("%s\x1B[0m", v3);
}
return result;
}

original_code:
void log_printf(int level, const char *fmt, ...)
{
    if (level > configstruct.loglevel) return;
    va_list ap;
    char msg[1024];
    __builtin_va_start(ap,fmt);
    vsnprintf(msg, sizeof(msg), fmt, ap);
    __builtin_va_end(ap);
    if (level == 0) {
 printf("\033[1m\033[31m");
    }
    printf("%s""\033[0m", msg);
}

canonical_original_code:
void log_printf(int level, char *fmt, ...)
{
    if (level > configstruct.loglevel) return;
    __builtin_va_list ap;
    char msg[1024];
    __builtin_va_start(ap,fmt);
    vsnprintf(msg, sizeof(msg), fmt, ap);
    __builtin_va_end(ap);
    if (level == 0) {
 printf("\033[1m\033[31m");
    }
    printf("%s""\033[0m", msg);
}

variable_types: level int

variable_types:
fmt
char *

variable_types:
msg
char [1024]


trimwhitespace

decompiled_code:
char *__fastcall trimwhitespace(char *s)
{
const unsigned __int16 *v2; // rbp
char *v3; // rax

v2 = *_ctype_b_loc();
while ( (v2[*s] & 0x2000) != 0 )
++s;
if ( *s )
{
v3 = &s[strlen(s) - 1];
if ( s < v3 )
{
do
{
if ( (v2[*v3] & 0x2000) == 0 )
break;
--v3;
}
while ( s != v3 );
}
v3[1] = 0;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
const unsigned __int16 *v2; // rbp
char *v3; // rax

v2 = *_ctype_b_loc();
while ( (v2[*s] & 0x2000) != 0 )
++s;
if ( *s )
{
v3 = &s[strlen(s) - 1];
if ( s < v3 )
{
do
{
if ( (v2[*v3] & 0x2000) == 0 )
break;
--v3;
}
while ( s != v3 );
}
v3[1] = 0;
}
return s;
}

original_code:
char *trimwhitespace(char *str)
{
  char *end;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
  if(*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
  *(end+1) = 0;
  return str;
}

canonical_original_code:
char *trimwhitespace(char *str)
{
  char *end;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
  if(*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
  *(end+1) = 0;
  return str;
}

variable_types:
str
char *

variable_types:
end
char *

return_type: char *


decompiled_code:
size_t __fastcall trimwhitespace2(void *dest, size_t a2, const char *a3)
{
size_t v3; // rbp
const unsigned __int16 *v5; // rbp
const char *v6; // rax
unsigned __int64 v7; // rax

v3 = a2;
if ( a2 )
{
v5 = *_ctype_b_loc();
while ( (v5[*a3] & 0x2000) != 0 )
++a3;
if ( *a3 )
{
v6 = &a3[strlen(a3) - 1];
if ( a3 < v6 )
{
do
{
if ( (v5[*v6] & 0x2000) == 0 )
break;
--v6;
}
while ( a3 != v6 );
}
v7 = v6 + 1 - a3;
v3 = a2 - 1;
if ( v7 <= a2 - 1 )
v3 = v7;
memcpy(dest, a3, v3);
*((_BYTE *)dest + v3) = 0;
}
else
{
*(_BYTE *)dest = 0;
v3 = 1LL;
}
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func1(void *dest, size_t a2, const char *a3)
{
size_t v3; // rbp
const unsigned __int16 *v5; // rbp
const char *v6; // rax
unsigned __int64 v7; // rax

v3 = a2;
if ( a2 )
{
v5 = *_ctype_b_loc();
while ( (v5[*a3] & 0x2000) != 0 )
++a3;
if ( *a3 )
{
v6 = &a3[strlen(a3) - 1];
if ( a3 < v6 )
{
do
{
if ( (v5[*v6] & 0x2000) == 0 )
break;
--v6;
}
while ( a3 != v6 );
}
v7 = v6 + 1 - a3;
v3 = a2 - 1;
if ( v7 <= a2 - 1 )
v3 = v7;
memcpy(dest, a3, v3);
*((_BYTE *)dest + v3) = 0;
}
else
{
*(_BYTE *)dest = 0;
v3 = 1LL;
}
}
return v3;
}

original_code:
size_t trimwhitespace2(char *out, size_t len, const char *str)
{
  if(len == 0)
    return 0;
  const char *end;
  size_t out_size;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
  if(*str == 0)
  {
    *out = 0;
    return 1;
  }
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
  end++;
  out_size = (end - str) < len-1 ? (end - str) : len-1;
  memcpy(out, str, out_size);
  out[out_size] = 0;
  return out_size;
}

canonical_original_code:
unsigned long trimwhitespace2(char *out, unsigned long len, char *str)
{
  if(len == 0)
    return 0;
  char *end;
  unsigned long out_size;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
  if(*str == 0)
  {
    *out = 0;
    return 1;
  }
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
  end++;
  out_size = (end - str) < len-1 ? (end - str) : len-1;
  memcpy(out, str, out_size);
  out[out_size] = 0;
  return out_size;
}

variable_types:
out
char *

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
int __fastcall trimwhitespace2ToInt(const char *a1)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

trimwhitespace2(v2, 0x400uLL, a1);
return atoi(v2);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

func1(v2, 0x400uLL, a1);
return atoi(v2);
}

original_code:
int trimwhitespace2ToInt(const char *str)
{
 char outline[1024];
 trimwhitespace2(outline, 1024, str);
 return atoi(outline);
}

canonical_original_code:
int trimwhitespace2ToInt(char *str)
{
 char outline[1024];
 trimwhitespace2(outline, 1024, str);
 return atoi(outline);
}

variable_types:
outline
char [1024]


cmpTwoInvertBits

decompiled_code:
__int64 __fastcall cmpTwoInvertBits(int a1, int a2)
{
int v2; // esi
__int64 result; // rax
int v4; // eax
unsigned int v5; // esi

v2 = a1 & a2;
result = v2 & 1;
if ( (v2 & 1) == 0 )
{
result = (v2 >> 1) & 1;
if ( ((v2 >> 1) & 1) == 0 )
{
v4 = v2 >> 2;
v5 = (v2 >> 3) & 1;
result = v4 & 1;
if ( !(_DWORD)result )
result = v5;
}
}
return result;
}

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

v2 = a1 & a2;
result = v2 & 1;
if ( (v2 & 1) == 0 )
{
result = (v2 >> 1) & 1;
if ( ((v2 >> 1) & 1) == 0 )
{
v4 = v2 >> 2;
v5 = (v2 >> 3) & 1;
result = v4 & 1;
if ( !(_DWORD)result )
result = v5;
}
}
return result;
}

original_code:
int cmpTwoInvertBits(int a, int b) {
 int i = 4;
 int zwerg = a&b;
 while(i) {
  if(zwerg & 1) {
   return 1;
  }
  zwerg >>= 1;
  i--;
 }
 return 0;
}

variable_types: a int

variable_types: b int

variable_types: i int

variable_types: zwerg int


compareFourStones

decompiled_code:
_BOOL8 __fastcall compareFourStones(int a1, unsigned int a2, unsigned int a3, int a4)
{
int v5; // eax
_BOOL4 v6; // ecx
int v8; // eax
int v10; // eax

v5 = a2 & a4 & a3;
v6 = 1;
if ( (a1 & v5) <= 0 )
{
v8 = cmpTwoInvertBits(~a1, ~a2);
v6 = 0;
if ( v8 == 1 )
{
v10 = cmpTwoInvertBits(~(a1 | a2), ~a3);
v6 = 0;
if ( v10 == 1 )
v6 = cmpTwoInvertBits(~(a1 | a2 | a3), ~a4) == 1;
}
}
return v6;
}

original_code:
int compareFourStones(int a, int b, int c, int d) {
 int zwerg;
 if ((a&b&c&d) >0) {
  return 1;
 }
 a = ~a;
 b = ~b;
 c = ~c;
 d = ~d;
 if (cmpTwoInvertBits(a,b) ==1) {
  zwerg = a & b;
  if (cmpTwoInvertBits(zwerg,c) == 1) {
   zwerg = zwerg & c;
   if (cmpTwoInvertBits(zwerg,d) ==1) {
    return 1;
   }
  }
 }
 return 0;
}

variable_types: c int

variable_types: d int


checkFreiesFeld

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

result = a1;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a1) >= 0 )
{
result = a2;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a2) >= 0 )
{
result = a3;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a3) >= 0 )
result = a4 & (unsigned int)(*(int *)(shmPtr_Sf + 4LL * a4) >> 31);
}
}
return result;
}

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

result = a1;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a1) >= 0 )
{
result = a2;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a2) >= 0 )
{
result = a3;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a3) >= 0 )
result = a4 & (unsigned int)(*(int *)(shmPtr_Sf + 4LL * a4) >> 31);
}
}
return result;
}

original_code:
int checkFreiesFeld(int a, int b, int c, int d) {
 if (shmPtr_Sf[a] <0 ) return a;
 if (shmPtr_Sf[b] <0 ) return b;
 if (shmPtr_Sf[c] <0 ) return c;
 if (shmPtr_Sf[d] <0 ) return d;
 return 0;
}


checkReihe

decompiled_code:
__int64 __fastcall checkReihe(signed int a1, signed int a2, signed int a3, int a4, __int64 a5, __int64 a6)
{
__int64 v6; // r14
__int64 v7; // rbx
__int64 v8; // rbp
int v9; // er15
unsigned int v10; // er14
unsigned int v11; // er13
int v12; // er12
__int64 v13; // rbx
__int64 v15; // [rsp+8h] [rbp-70h]
__int64 v16; // [rsp+18h] [rbp-60h]

v6 = a3;
v16 = 4LL * a3;
v7 = a4;
v15 = 4LL * a4;
if ( *(_DWORD *)(a5 + v15) + *(_DWORD *)(a5 + v16) + *(_DWORD *)(a5 + 4LL * a1) + *(_DWORD *)(a5 + 4LL * a2) == 3 )
{
v8 = (unsigned int)checkFreiesFeld(a1, a2, a3, a4);
log_printf(2LL, "freies Feld: %i\n", v8);
if ( a1 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr + 584LL);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a2 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr + 584LL);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a3 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr + 584LL);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a4 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr + 584LL);
}
else
{
v9 = 0;
v10 = 0;
v11 = 0;
v12 = 0;
}
v13 = 0LL;
if ( compareFourStones(v12, v11, v10, v9) )
{
saveField(v8);
log_printf(2LL, "gewonnen!\n");
LODWORD(v8) = 16;
}
else
{
do
{
if ( a1 == (_DWORD)v8 )
{
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + v16);
v9 = *(_DWORD *)(shmPtr_Sf + v15);
v12 = v13;
}
else if ( a2 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v10 = *(_DWORD *)(shmPtr_Sf + v16);
v9 = *(_DWORD *)(shmPtr_Sf + v15);
v11 = v13;
}
else if ( a3 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v9 = *(_DWORD *)(shmPtr_Sf + v15);
v10 = v13;
}
else if ( a4 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + v16);
v9 = v13;
}
if ( compareFourStones(v12, v11, v10, v9) )
*(_DWORD *)(a6 + 4 * v13) = 1;
++v13;
}
while ( v13 != 16 );
}
}
else
{
LODWORD(v8) = -1;
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(signed int a1, signed int a2, signed int a3, int a4, __int64 a5, __int64 a6)
{
__int64 v6; // r14
__int64 v7; // rbx
__int64 v8; // rbp
int v9; // er15
unsigned int v10; // er14
unsigned int v11; // er13
int v12; // er12
__int64 v13; // rbx
__int64 v15; // [rsp+8h] [rbp-70h]
__int64 v16; // [rsp+18h] [rbp-60h]

v6 = a3;
v16 = 4LL * a3;
v7 = a4;
v15 = 4LL * a4;
if ( *(_DWORD *)(a5 + v15) + *(_DWORD *)(a5 + v16) + *(_DWORD *)(a5 + 4LL * a1) + *(_DWORD *)(a5 + 4LL * a2) == 3 )
{
v8 = (unsigned int)func3(a1, a2, a3, a4);
log_printf(2LL, "freies Feld: %i\n", v8);
if ( a1 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr + 584LL);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a2 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr + 584LL);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a3 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr + 584LL);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a4 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr + 584LL);
}
else
{
v9 = 0;
v10 = 0;
v11 = 0;
v12 = 0;
}
v13 = 0LL;
if ( func2(v12, v11, v10, v9) )
{
func0(v8);
log_printf(2LL, "gewonnen!\n");
LODWORD(v8) = 16;
}
else
{
do
{
if ( a1 == (_DWORD)v8 )
{
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + v16);
v9 = *(_DWORD *)(shmPtr_Sf + v15);
v12 = v13;
}
else if ( a2 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v10 = *(_DWORD *)(shmPtr_Sf + v16);
v9 = *(_DWORD *)(shmPtr_Sf + v15);
v11 = v13;
}
else if ( a3 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v9 = *(_DWORD *)(shmPtr_Sf + v15);
v10 = v13;
}
else if ( a4 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr_Sf + v16);
v9 = v13;
}
if ( func2(v12, v11, v10, v9) )
*(_DWORD *)(a6 + 4 * v13) = 1;
++v13;
}
while ( v13 != 16 );
}
}
else
{
LODWORD(v8) = -1;
}
return (unsigned int)v8;
}

original_code:
int checkReihe(int a, int b, int c, int d, int felder[], int badStones[]) {
 if (felder[a]+felder[b]+felder[c]+felder[d] == 3) {
  int frei = checkFreiesFeld(a,b,c,d);
  int stein1,stein2,stein3,stein4;
  stein1 =0; stein2 =0; stein3 =0; stein4 =0;
  log_printf(2,"freies Feld: %i\n",frei);
  if (frei == a) {
   stein1 = shmPtr->nextStone;
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == b) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr->nextStone;
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == c) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr->nextStone;
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == d) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr->nextStone;
  }
  if (compareFourStones(stein1,stein2,stein3,stein4) == 1) {
   saveField(frei);
   log_printf(2,"gewonnen!\n");
   return 16;
  }
  for(int i=0;i<16;i++) {
   if (frei == a) {
    stein1 = i;
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == b) {
    stein1 = shmPtr_Sf[a];
    stein2 = i;
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == c) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = i;
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == d) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = i;
   }
   if (compareFourStones(stein1,stein2,stein3,stein4) ==1) {
    badStones[i] = 1;
   }
  }
  return frei;
 }
 return -1;
}

canonical_original_code:
int checkReihe(int a, int b, int c, int d, int felder[], int badStones[]) {
 if (felder[a]+felder[b]+felder[c]+felder[d] == 3) {
  int frei = checkFreiesFeld(a,b,c,d);
  int stein1; int stein2; int stein3; int stein4;
  stein1 =0; stein2 =0; stein3 =0; stein4 =0;
  log_printf(2,"freies Feld: %i\n",frei);
  if (frei == a) {
   stein1 = shmPtr->nextStone;
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == b) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr->nextStone;
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == c) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr->nextStone;
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == d) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr->nextStone;
  }
  if (compareFourStones(stein1,stein2,stein3,stein4) == 1) {
   saveField(frei);
   log_printf(2,"gewonnen!\n");
   return 16;
  }
  for(int i = 0;i<16;i++) {
   if (frei == a) {
    stein1 = i;
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == b) {
    stein1 = shmPtr_Sf[a];
    stein2 = i;
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == c) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = i;
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == d) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = i;
   }
   if (compareFourStones(stein1,stein2,stein3,stein4) ==1) {
    badStones[i] = 1;
   }
  }
  return frei;
 }
 return -1;
}

variable_types:
felder
int []

variable_types:
badStones
int []

variable_types: frei int


randomStone

decompiled_code:
__int64 __fastcall randomStone(__int64 a1)
{
unsigned int i; // ebp

for ( i = rand() % 16; *(_DWORD *)(a1 + 4LL * (int)i); i = rand() % 16 )
;
log_printf(2LL, "Naechster Stein: %i\n", i);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int i; // ebp

for ( i = rand() % 16; *(_DWORD *)(a1 + 4LL * (int)i); i = rand() % 16 )
;
log_printf(2LL, "Naechster Stein: %i\n", i);
return i;
}

original_code:
int randomStone(int stones[]) {
 int nextStein = rand() % 16;
while(1){
 if (stones[nextStein] ==0){
   log_printf(2,"Naechster Stein: %i\n",nextStein);
   return nextStein;
  }
 else{
   nextStein = rand() % 16;
  }
 }
 log_printf(2,"Naechster Stein: %i\n",nextStein);
 return -1;
}

variable_types:
stones
int []

variable_types: nextStein int


randomField

decompiled_code:
__int64 __fastcall randomField(_DWORD *a1)
{
int v1; // ebx
_DWORD *v2; // rax
int v3; // ecx
int v4; // edx
void *v5; // rsp
__int64 v6; // rax
int v7; // edx
void *v8; // rsp
unsigned int v9; // ebx
_DWORD v11[4]; // [rsp+0h] [rbp-10h]

v1 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
if ( v1 <= 0 )
{
v8 = alloca(4LL * v1);
}
else
{
v2 = a1;
v3 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
v4 = 0;
do
v4 += *v2++;
while ( v2 != &a1[v1 - 1 + 1] );
v1 -= v4;
v5 = alloca(4LL * v1);
v6 = 0LL;
v7 = 0;
do
{
if ( !a1[v6] )
v11[v7++] = v6;
++v6;
}
while ( v6 != v3 );
}
v9 = v11[rand() % v1];
log_printf(2LL, "Tolles freies Feld: %i\n", v9);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
int v1; // ebx
_DWORD *v2; // rax
int v3; // ecx
int v4; // edx
void *v5; // rsp
__int64 v6; // rax
int v7; // edx
void *v8; // rsp
unsigned int v9; // ebx
_DWORD v11[4]; // [rsp+0h] [rbp-10h]

v1 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
if ( v1 <= 0 )
{
v8 = alloca(4LL * v1);
}
else
{
v2 = a1;
v3 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
v4 = 0;
do
v4 += *v2++;
while ( v2 != &a1[v1 - 1 + 1] );
v1 -= v4;
v5 = alloca(4LL * v1);
v6 = 0LL;
v7 = 0;
do
{
if ( !a1[v6] )
v11[v7++] = v6;
++v6;
}
while ( v6 != v3 );
}
v9 = v11[rand() % v1];
log_printf(2LL, "Tolles freies Feld: %i\n", v9);
return v9;
}

original_code:
int randomField(int felder[]) {
 int len = shmPtr->hoehe * shmPtr->breite;
 int anzahlBesetzt = 0;
 for(int i = 0; i<len;i++){
  anzahlBesetzt += felder[i];
 }
 int freieFelder = len-anzahlBesetzt;
 int freieFelderArray[freieFelder];
 int j = 0;
 for(int i = 0; i<len;i++){
  if(felder[i] == 0){
   freieFelderArray[j] = i;
   j++;
  }
 }
 int random = rand() % freieFelder;
 int index = freieFelderArray[random];
 log_printf(2,"Tolles freies Feld: %i\n",index);
 return index;
}

canonical_original_code:
int randomField(int felder[]) {
 int len = shmPtr->hoehe * shmPtr->breite;
 int anzahlBesetzt = 0;
 for(int i = 0; i<len;i++){
  anzahlBesetzt += felder[i];
 }
 int freieFelder = len-anzahlBesetzt;
 int freieFelderArray[-1];
 int j = 0;
 for(int i = 0; i<len;i++){
  if(felder[i] == 0){
   freieFelderArray[j] = i;
   j++;
  }
 }
 int random = rand() % freieFelder;
 int index = freieFelderArray[random];
 log_printf(2,"Tolles freies Feld: %i\n",index);
 return index;
}

variable_types: len int

variable_types: anzahlBesetzt int

variable_types: freieFelder int

variable_types:
freieFelderArray
int [-1]

variable_types: j int

variable_types: random int

variable_types: index int


thinkbetter

original_code:
void thinkbetter() {
 int besetzteFelder[16]={0};
 int guteFelder[16]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
 int spielsteineSchlecht[16]={0};
 int frei = -1;
 int stein;
 int isThereAStone=0;
 int isThereAField=0;
 srand(time(((void *)0)));
 besetzteSteine[shmPtr->nextStone] = 1;
 for(int i=0; i<16; i++) {
  spielsteineSchlecht[i]=besetzteSteine[i];
  if (shmPtr_Sf[i] >-1) {
   besetzteFelder[i] =1;
  }
 }
 if ((frei = checkReihe(0,1,2,3,besetzteFelder,spielsteineSchlecht))!= 16){
    if (frei >0) guteFelder[frei]=0;
    if ((frei = checkReihe(4,5,6,7,besetzteFelder,spielsteineSchlecht))!= 16){
       if (frei >0) guteFelder[frei]=0;
       if ((frei = checkReihe(8,9,10,11,besetzteFelder,spielsteineSchlecht))!= 16){
          if (frei >0) guteFelder[frei]=0;
          if ((frei = checkReihe(12,13,14,15,besetzteFelder,spielsteineSchlecht))!= 16){
             if (frei >0) guteFelder[frei]=0;
             if ((frei = checkReihe(0,4,8,12,besetzteFelder,spielsteineSchlecht))!= 16){
                if (frei >0) guteFelder[frei]=0;
                if ((frei = checkReihe(1,5,9,13,besetzteFelder,spielsteineSchlecht))!= 16){
                   if (frei >0) guteFelder[frei]=0;
                   if ((frei = checkReihe(2,6,10,14,besetzteFelder,spielsteineSchlecht))!= 16){
                      if (frei >0) guteFelder[frei]=0;
                      if ((frei = checkReihe(3,7,11,15,besetzteFelder,spielsteineSchlecht))!= 16){
                         if (frei >0) guteFelder[frei]=0;
                         if ((frei = checkReihe(0,5,10,15,besetzteFelder,spielsteineSchlecht))!= 16){
                            if (frei >0) guteFelder[frei]=0;
                            frei = checkReihe(3,6,9,12,besetzteFelder,spielsteineSchlecht);
                            if (frei >0) guteFelder[frei]=0;
         }
               }
              }
             }
            }
           }
   }
  }
 }
 log_printf(2,"guteFelder: ");
 for (int i=0; i<16; i++) {
  log_printf(2,"%i ",guteFelder[i]);
  if (guteFelder[i] == 0) {
   isThereAField = 1;
  }
 }
 log_printf(2,"\n");
 log_printf(2,"isThereAField: %i\n",isThereAField);
 if(frei < 16) {
  if(isThereAField==1){
   log_printf(2,"there is\n");
   saveField(randomField(guteFelder));
  } else{
   log_printf(2,"Nope, there isn't\n");
   saveField(randomField(besetzteFelder));
  }
 }
 spielzug[2] = ',';
 log_printf(2,"schlechte Steine: ");
 if(frei < 16) {
  for (int i=0; i<16; i++) {
   log_printf(2,"%i ",spielsteineSchlecht[i]);
   if (spielsteineSchlecht[i] == 0) {
    isThereAStone = 1;
   }
  }
 }
 log_printf(2,"\n");
 log_printf(2,"isThereAStone: %i\n",isThereAStone);
 if(isThereAStone==1){
  log_printf(2,"there is\n");
  stein = randomStone(spielsteineSchlecht);
 } else{
  log_printf(2,"Nope, there isn't\n");
  stein = randomStone(besetzteSteine);
 }
 log_printf(2,"stein: %i\n",stein);
 sprintf(spielzug+3,"%i",stein);
 log_printf(2,"Spielzug: %s\n",spielzug);
}

canonical_original_code:
void thinkbetter() {
 int besetzteFelder[16] = {0};
 int guteFelder[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
 int spielsteineSchlecht[16] = {0};
 int frei = -1;
 int stein;
 int isThereAStone = 0;
 int isThereAField = 0;
 srand(time(((void *)0)));
 besetzteSteine[shmPtr->nextStone] = 1;
 for(int i = 0; i<16; i++) {
  spielsteineSchlecht[i]=besetzteSteine[i];
  if (shmPtr_Sf[i] >-1) {
   besetzteFelder[i] =1;
  }
 }
 if ((frei = checkReihe(0,1,2,3,besetzteFelder,spielsteineSchlecht))!= 16){
    if (frei >0) guteFelder[frei]=0;
    if ((frei = checkReihe(4,5,6,7,besetzteFelder,spielsteineSchlecht))!= 16){
       if (frei >0) guteFelder[frei]=0;
       if ((frei = checkReihe(8,9,10,11,besetzteFelder,spielsteineSchlecht))!= 16){
          if (frei >0) guteFelder[frei]=0;
          if ((frei = checkReihe(12,13,14,15,besetzteFelder,spielsteineSchlecht))!= 16){
             if (frei >0) guteFelder[frei]=0;
             if ((frei = checkReihe(0,4,8,12,besetzteFelder,spielsteineSchlecht))!= 16){
                if (frei >0) guteFelder[frei]=0;
                if ((frei = checkReihe(1,5,9,13,besetzteFelder,spielsteineSchlecht))!= 16){
                   if (frei >0) guteFelder[frei]=0;
                   if ((frei = checkReihe(2,6,10,14,besetzteFelder,spielsteineSchlecht))!= 16){
                      if (frei >0) guteFelder[frei]=0;
                      if ((frei = checkReihe(3,7,11,15,besetzteFelder,spielsteineSchlecht))!= 16){
                         if (frei >0) guteFelder[frei]=0;
                         if ((frei = checkReihe(0,5,10,15,besetzteFelder,spielsteineSchlecht))!= 16){
                            if (frei >0) guteFelder[frei]=0;
                            frei = checkReihe(3,6,9,12,besetzteFelder,spielsteineSchlecht);
                            if (frei >0) guteFelder[frei]=0;
         }
               }
              }
             }
            }
           }
   }
  }
 }
 log_printf(2,"guteFelder: ");
 for (int i = 0; i<16; i++) {
  log_printf(2,"%i ",guteFelder[i]);
  if (guteFelder[i] == 0) {
   isThereAField = 1;
  }
 }
 log_printf(2,"\n");
 log_printf(2,"isThereAField: %i\n",isThereAField);
 if(frei < 16) {
  if(isThereAField==1){
   log_printf(2,"there is\n");
   saveField(randomField(guteFelder));
  } else{
   log_printf(2,"Nope, there isn't\n");
   saveField(randomField(besetzteFelder));
  }
 }
 spielzug[2] = ',';
 log_printf(2,"schlechte Steine: ");
 if(frei < 16) {
  for (int i = 0; i<16; i++) {
   log_printf(2,"%i ",spielsteineSchlecht[i]);
   if (spielsteineSchlecht[i] == 0) {
    isThereAStone = 1;
   }
  }
 }
 log_printf(2,"\n");
 log_printf(2,"isThereAStone: %i\n",isThereAStone);
 if(isThereAStone==1){
  log_printf(2,"there is\n");
  stein = randomStone(spielsteineSchlecht);
 } else{
  log_printf(2,"Nope, there isn't\n");
  stein = randomStone(besetzteSteine);
 }
 log_printf(2,"stein: %i\n",stein);
 sprintf(spielzug+3,"%i",stein);
 log_printf(2,"Spielzug: %s\n",spielzug);
}

variable_types:
besetzteFelder
int [16]

variable_types:
guteFelder
int [16]

variable_types:
spielsteineSchlecht
int [16]

variable_types: stein int

variable_types: isThereAStone int

variable_types: isThereAField int


think

decompiled_code:
__int64 think()
{
int v0; // ebx
_DWORD *v1; // rsi
__int64 v2; // rcx
__int64 i; // rdx
_DWORD *v4; // rax

v0 = *(_DWORD *)(shmPtr + 592LL) * *(_DWORD *)(shmPtr + 588LL);
if ( !shmPtr_Sf )
{
shmPtr_Sf = shmSpielfeldAnbinden(*(unsigned int *)(shmPtr + 596LL));
shmDelete(*(unsigned int *)(shmPtr + 596LL));
}
if ( v0 > 0 )
{
v1 = (_DWORD *)shmPtr_Sf;
v2 = shmPtr_Sf + 4LL * (unsigned int)(v0 - 1) + 4;
for ( i = 0LL; i != v0; ++i )
{
besetzteSteine[i] = 0;
v4 = v1;
while ( *v4 != (_DWORD)i )
{
if ( ++v4 == (_DWORD *)v2 )
goto LABEL_6;
}
besetzteSteine[i] = 1;
LABEL_6:
;
}
}
log_printf(2LL, asc_1912);
return thinkbetter();
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
_DWORD *v1; // rsi
__int64 v2; // rcx
__int64 i; // rdx
_DWORD *v4; // rax

v0 = *(_DWORD *)(shmPtr + 592LL) * *(_DWORD *)(shmPtr + 588LL);
if ( !shmPtr_Sf )
{
shmPtr_Sf = shmSpielfeldAnbinden(*(unsigned int *)(shmPtr + 596LL));
shmDelete(*(unsigned int *)(shmPtr + 596LL));
}
if ( v0 > 0 )
{
v1 = (_DWORD *)shmPtr_Sf;
v2 = shmPtr_Sf + 4LL * (unsigned int)(v0 - 1) + 4;
for ( i = 0LL; i != v0; ++i )
{
besetzteSteine[i] = 0;
v4 = v1;
while ( *v4 != (_DWORD)i )
{
if ( ++v4 == (_DWORD *)v2 )
goto LABEL_6;
}
besetzteSteine[i] = 1;
LABEL_6:
;
}
}
log_printf(2LL, asc_1912);
return func7();
}

original_code:
void think() {
 int groesse = shmPtr->breite * shmPtr->hoehe;
 if(shmPtr_Sf == ((void *)0)) {
  shmPtr_Sf = shmSpielfeldAnbinden(shmPtr->shmid_Sf);
  shmDelete(shmPtr->shmid_Sf);
 }
 for(int i=0;i<groesse;i++) {
  besetzteSteine[i]=0;
  for(int j=0;j<groesse;j++) {
   if (shmPtr_Sf[j] ==i) {
    besetzteSteine[i]=1;
    break;
   }
  }
 }
 log_printf(2,"fängt an zu denken\n");
 thinkbetter();
}

canonical_original_code:
void think() {
 int groesse = shmPtr->breite * shmPtr->hoehe;
 if(shmPtr_Sf == ((void *)0)) {
  shmPtr_Sf = shmSpielfeldAnbinden(shmPtr->shmid_Sf);
  shmDelete(shmPtr->shmid_Sf);
 }
 for(int i = 0;i<groesse;i++) {
  besetzteSteine[i]=0;
  for(int j = 0;j<groesse;j++) {
   if (shmPtr_Sf[j] ==i) {
    besetzteSteine[i]=1;
    break;
   }
  }
 }
 log_printf(2,"fängt an zu denken\n");
 thinkbetter();
}

variable_types: groesse int

variable_types: i int


saveField

decompiled_code:
__int64 __fastcall saveField(int a1)
{
int v1; // edi
__int64 result; // rax

spielzug = a1 % *(_DWORD *)(shmPtr + 588LL) + 65;
v1 = a1 / *(_DWORD *)(shmPtr + 592LL);
result = (unsigned int)(52 - v1);
*(&spielzug + 1) = 52 - v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // edi
__int64 result; // rax

spielzug = a1 % *(_DWORD *)(shmPtr + 588LL) + 65;
v1 = a1 / *(_DWORD *)(shmPtr + 592LL);
result = (unsigned int)(52 - v1);
*(&spielzug + 1) = 52 - v1;
return result;
}

original_code:
void saveField(int index) {
 spielzug[0] ='A' +(index % shmPtr->breite);
 spielzug[1] ='4' -(index/shmPtr->hoehe);
}


shmSegment

decompiled_code:
__int64 shmSegment()
{
unsigned int v0; // ebx

v0 = shmget(0, 4uLL, 950);
if ( v0 == -1 )
perror("Fehler beim Segment erstellen");
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx

v0 = shmget(0, 4uLL, 950);
if ( v0 == -1 )
perror("Fehler beim Segment erstellen");
return v0;
}

original_code:
int shmSegment(int size){
 int shmid;
 if((shmid = shmget(((__key_t) 0), sizeof(size), 01000 | 0666) )==-1){
  perror("Fehler beim Segment erstellen");
 }
 return shmid;
}

canonical_original_code:
int shmSegment(int size){
 int shmid;
 if((shmid = shmget(((int) 0), sizeof(size), 01000 | 0666) )==-1){
  perror("Fehler beim Segment erstellen");
 }
 return shmid;
}

variable_types: size int

variable_types: shmid int


shmAnbinden

decompiled_code:
void *__fastcall shmAnbinden(int a1)
{
void *v1; // rbx

v1 = shmat(a1, 0LL, 0);
if ( v1 == (void *)-1LL )
perror("Fehler beim Binden des SHM an einen Prozess");
return v1;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
void *v1; // rbx

v1 = shmat(a1, 0LL, 0);
if ( v1 == (void *)-1LL )
perror("Fehler beim Binden des SHM an einen Prozess");
return v1;
}

original_code:
struct shmInfos* shmAnbinden(int shmid){
 struct shmInfos *shm_ptr = shmat(shmid, ((void *)0), 0);
 if (shm_ptr==(struct shmInfos*)-1) {
  perror("Fehler beim Binden des SHM an einen Prozess");
 }
 return shm_ptr;
}

canonical_original_code:
struct shmInfos *shmAnbinden(int shmid){
 struct shmInfos *shm_ptr = shmat(shmid, ((void *)0), 0);
 if (shm_ptr==(struct shmInfos *)-1) {
  perror("Fehler beim Binden des SHM an einen Prozess");
 }
 return shm_ptr;
}

variable_types: struct shmInfos { char spielname[30]; int eigSpielernummer; int anzahlSpieler; int pid0; int pid1; int flag; struct playerAttr { int spielerNr; char name[256]; int registered; } attr[2]; int moveTimeout; int nextStone; int breite; int hoehe; int shmid_Sf; int gameover; } *


shmSpielfeldAnbinden

decompiled_code:
void *__fastcall shmSpielfeldAnbinden(int a1)
{
void *v1; // rbx

v1 = shmat(a1, 0LL, 0);
if ( v1 == (void *)-1LL )
perror("Fehler beim Binden des SHM an einen Prozess");
return v1;
}

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
void *v1; // rbx

v1 = shmat(a1, 0LL, 0);
if ( v1 == (void *)-1LL )
perror("Fehler beim Binden des SHM an einen Prozess");
return v1;
}

original_code:
int* shmSpielfeldAnbinden(int shmid){
 int *shm_ptr_Sf = shmat(shmid, ((void *)0), 0);
 if (shm_ptr_Sf==(int*)-1) {
  perror("Fehler beim Binden des SHM an einen Prozess");
 }
 return shm_ptr_Sf;
}

canonical_original_code:
int *shmSpielfeldAnbinden(int shmid){
 int *shm_ptr_Sf = shmat(shmid, ((void *)0), 0);
 if (shm_ptr_Sf==(int *)-1) {
  perror("Fehler beim Binden des SHM an einen Prozess");
 }
 return shm_ptr_Sf;
}

return_type: int *


shmDelete

decompiled_code:
void __fastcall shmDelete(int a1)
{
if ( shmctl(a1, 0, 0LL) == -1 )
perror("Fehler beim Loeschen des Shared Memory Segments");
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
if ( shmctl(a1, 0, 0LL) == -1 )
perror("Fehler beim Loeschen des Shared Memory Segments");
}

original_code:
void shmDelete(int shmid){
 if(shmctl(shmid, 0, ((void *)0))==-1) {
 perror("Fehler beim Loeschen des Shared Memory Segments");
 }
}


netRecv

decompiled_code:
ssize_t __fastcall netRecv(void *buf, size_t n)
{
ssize_t result; // rax

result = recv(socke, buf, n, 0);
if ( (int)result <= 0 )
{
log_printf(0LL, "Fehler beim Empfangen der Daten vom Server!\n");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(void *buf, size_t n)
{
ssize_t result; // rax

result = recv(socke, buf, n, 0);
if ( (int)result <= 0 )
{
log_printf(0LL, "Fehler beim Empfangen der Daten vom Server!\n");
exit(1);
}
return result;
}

original_code:
static int netRecv(char* bufAnf, size_t bufRestLen){
 int len = recv(socke, bufAnf, bufRestLen,0);
 if(len <= 0) {
  log_printf(0,"Fehler beim Empfangen der Daten vom Server!\n");
  exit(1);
 }
 return len;
}

canonical_original_code:
static int netRecv(char *bufAnf, unsigned long bufRestLen){
 int len = recv(socke, bufAnf, bufRestLen,0);
 if(len <= 0) {
  log_printf(0,"Fehler beim Empfangen der Daten vom Server!\n");
  exit(1);
 }
 return len;
}

variable_types:
bufAnf
char *

variable_types:
bufRestLen
unsigned long

variable_types: len int


netReadLine

decompiled_code:
char *netReadLine()
{
int v0; // ebx
__int64 v1; // rax

v0 = bufferBenutzt_2;
if ( bufferBenutzt_2 > 0 && bufferEnde_1 > 0 )
bufferBenutzt_2 = v0 - netUpdateBuffer(bufferGet_0, bufferBenutzt_2, bufferEnde_1);
while ( bufferBenutzt_2 <= 0 )
LABEL_5:
bufferBenutzt_2 += netRecv(&bufferGet_0[bufferBenutzt_2], 251 - bufferBenutzt_2);
v1 = 0LL;
while ( bufferGet_0[v1] != 10 )
{
if ( ++v1 == bufferBenutzt_2 )
goto LABEL_5;
}
bufferGet_0[(int)v1] = 0;
bufferEnde_1 = v1;
log_printf(2LL, "\x1B[1m\x1B[33mS: \x1B[0m%s\n", bufferGet_0);
return bufferGet_0;
}

canonical_decompiled_code:
char *func2()
{
int v0; // ebx
__int64 v1; // rax

v0 = bufferBenutzt_2;
if ( bufferBenutzt_2 > 0 && bufferEnde_1 > 0 )
bufferBenutzt_2 = v0 - func0(bufferGet_0, bufferBenutzt_2, bufferEnde_1);
while ( bufferBenutzt_2 <= 0 )
LABEL_5:
bufferBenutzt_2 += func1(&bufferGet_0[bufferBenutzt_2], 251 - bufferBenutzt_2);
v1 = 0LL;
while ( bufferGet_0[v1] != 10 )
{
if ( ++v1 == bufferBenutzt_2 )
goto LABEL_5;
}
bufferGet_0[(int)v1] = 0;
bufferEnde_1 = v1;
log_printf(2LL, "\x1B[1m\x1B[33mS: \x1B[0m%s\n", bufferGet_0);
return bufferGet_0;
}

original_code:
char* netReadLine() {
 static int bufferBenutzt = 0;
 static int bufferEnde = 0;
 static char bufferGet[251];
 if (bufferBenutzt > 0 && bufferEnde > 0) {
    bufferBenutzt -= netUpdateBuffer(bufferGet, bufferBenutzt, bufferEnde);
 }
 while(1) {
 for (int i=0; i<bufferBenutzt; i++) {
  if(bufferGet[i]=='\n') {
    bufferGet[i] = '\0';
     bufferEnde = i;
     log_printf(2,"\033[1m\033[33m""S: ""\033[0m""%s\n",bufferGet);
     return bufferGet;
   }
 }
 bufferBenutzt += netRecv(bufferGet + bufferBenutzt, 251 -bufferBenutzt);
 }
}

canonical_original_code:
char *netReadLine() {
 static int bufferBenutzt = 0;
 static int bufferEnde = 0;
 static char bufferGet[251];
 if (bufferBenutzt > 0 && bufferEnde > 0) {
    bufferBenutzt -= netUpdateBuffer(bufferGet, bufferBenutzt, bufferEnde);
 }
 while(1) {
 for (int i = 0; i<bufferBenutzt; i++) {
  if(bufferGet[i]=='\n') {
    bufferGet[i] = '\0';
     bufferEnde = i;
     log_printf(2,"\033[1m\033[33m""S: ""\033[0m""%s\n",bufferGet);
     return bufferGet;
   }
 }
 bufferBenutzt += netRecv(bufferGet + bufferBenutzt, 251 -bufferBenutzt);
 }
}

variable_types: bufferBenutzt int

variable_types: bufferEnde int

variable_types:
bufferGet
char [251]


netWrite

decompiled_code:
__int64 __fastcall netWrite(void *buf)
{
int v1; // eax
__int64 result; // rax

v1 = strlen((const char *)buf);
if ( write(socke, buf, v1) < 0 )
{
log_printf(0LL, "Fehler beim Schreiben in den Socket\n");
result = 0LL;
}
else
{
log_printf(2LL, "\x1B[1m\x1B[36mC: \x1B[0m%s", (const char *)buf);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *buf)
{
int v1; // eax
__int64 result; // rax

v1 = strlen((const char *)buf);
if ( write(socke, buf, v1) < 0 )
{
log_printf(0LL, "Fehler beim Schreiben in den Socket\n");
result = 0LL;
}
else
{
log_printf(2LL, "\x1B[1m\x1B[36mC: \x1B[0m%s", (const char *)buf);
result = 1LL;
}
return result;
}

original_code:
int netWrite(char *bufferSend) {
 int len = strlen(bufferSend);
 if(write(socke, bufferSend, len*sizeof(char)) < 0) {
  log_printf(0,"Fehler beim Schreiben in den Socket\n");
  return 0;
 }
 log_printf(2,"\033[1m\033[36m""C: ""\033[0m""%s",bufferSend);
 return 1;
}

variable_types:
bufferSend
char *


netConnect

decompiled_code:
__int64 __fastcall netConnect(char *service, char *name)
{
struct addrinfo *v2; // rbx
int v3; // edi
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
log_printf(0LL, "Fehler beim Servernamen\n");
exit(1);
}
v2 = pai;
if ( !pai )
{
LABEL_9:
log_printf(0LL, "Client konnte nicht verbunden werden.\n");
exit(1);
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
socke = v3;
if ( v3 != -1 )
break;
log_printf(0LL, "Socket konnte nicht angelegt werden.\n");
LABEL_8:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_9;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(socke);
log_printf(0LL, "Verbindung mit Socket fehlgeschlagen.\n");
goto LABEL_8;
}
freeaddrinfo(pai);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *service, char *name)
{
struct addrinfo *v2; // rbx
int v3; // edi
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
log_printf(0LL, "Fehler beim Servernamen\n");
exit(1);
}
v2 = pai;
if ( !pai )
{
LABEL_9:
log_printf(0LL, "Client konnte nicht verbunden werden.\n");
exit(1);
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
socke = v3;
if ( v3 != -1 )
break;
log_printf(0LL, "Socket konnte nicht angelegt werden.\n");
LABEL_8:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_9;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(socke);
log_printf(0LL, "Verbindung mit Socket fehlgeschlagen.\n");
goto LABEL_8;
}
freeaddrinfo(pai);
return 1LL;
}

original_code:
int netConnect(char* port, char* hostname ) {
  struct addrinfo hints, *servinfo, *p;
 memset(&hints, 0, sizeof hints);
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if (getaddrinfo(hostname, port, &hints, &servinfo) != 0) {
    log_printf(0, "Fehler beim Servernamen\n");
    exit(1);
  }
  for(p = servinfo; p != ((void *)0); p = p->ai_next) {
    if ((socke = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      log_printf(0, "Socket konnte nicht angelegt werden.\n");
        continue;
    }
    if (connect(socke, p->ai_addr, p->ai_addrlen) == -1) {
      close(socke);
      log_printf(0, "Verbindung mit Socket fehlgeschlagen.\n");
      continue;
    }
    break;
  }
 if (p == ((void *)0)) {
  log_printf(0, "Client konnte nicht verbunden werden.\n");
  exit(1);
 }
 freeaddrinfo(servinfo);
 return 1;
}

canonical_original_code:
int netConnect(char *port, char *hostname) {
  struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
 memset(&hints, 0, sizeof hints);
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if (getaddrinfo(hostname, port, &hints, &servinfo) != 0) {
    log_printf(0, "Fehler beim Servernamen\n");
    exit(1);
  }
  for(p = servinfo; p != ((void *)0); p = p->ai_next) {
    if ((socke = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      log_printf(0, "Socket konnte nicht angelegt werden.\n");
        continue;
    }
    if (connect(socke, p->ai_addr, p->ai_addrlen) == -1) {
      close(socke);
      log_printf(0, "Verbindung mit Socket fehlgeschlagen.\n");
      continue;
    }
    break;
  }
 if (p == ((void *)0)) {
  log_printf(0, "Client konnte nicht verbunden werden.\n");
  exit(1);
 }
 freeaddrinfo(servinfo);
 return 1;
}

variable_types:
port
char *

variable_types:
hostname
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


getSocketFd

decompiled_code:
__int64 getSocketFd()
{
return (unsigned int)socke;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)socke;
}

original_code:
int getSocketFd(){
 return socke;
}

canonical_original_code:
int getSocketFd(){
 return socke;
}


netDisconnect

decompiled_code:
__int64 netDisconnect()
{
close(socke);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
close(socke);
return 0LL;
}

original_code:
int netDisconnect() {
 close(socke);
 return 0;
}


decompiled_code:
__int64 __fastcall pipe_read(int *a1, char *a2)
{
__int64 result; // rax

close(a1[1]);
if ( read(*a1, a2, 0xAuLL) < 0 )
{
log_printf(0LL, "Fehler beim Lesen der Pipe");
perror("Error: ");
result = 0LL;
}
else
{
log_printf(2LL, "Pipe gelesen: %s\n", a2);
result = 1LL;
}
return result;
}

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

close(a1[1]);
if ( read(*a1, a2, 0xAuLL) < 0 )
{
log_printf(0LL, "Fehler beim Lesen der Pipe");
perror("Error: ");
result = 0LL;
}
else
{
log_printf(2LL, "Pipe gelesen: %s\n", a2);
result = 1LL;
}
return result;
}

original_code:
int pipe_read(int pipe_fd[],char * getText){
 close(pipe_fd[1]);
 if((read(pipe_fd[0],getText,10)) < 0) {
  log_printf(0,"Fehler beim Lesen der Pipe");
  perror("Error: ");
  return 0;
 }
 log_printf(2,"Pipe gelesen: %s\n", getText);
 return 1;
}

canonical_original_code:
int pipe_read(int pipe_fd[], char *getText){
 close(pipe_fd[1]);
 if((read(pipe_fd[0],getText,10)) < 0) {
  log_printf(0,"Fehler beim Lesen der Pipe");
  perror("Error: ");
  return 0;
 }
 log_printf(2,"Pipe gelesen: %s\n", getText);
 return 1;
}

variable_types:
getText
char *


decompiled_code:
__int64 __fastcall pipe_write(int *a1)
{
__int64 result; // rax

close(*a1);
if ( write(a1[1], &spielzug, 6uLL) == 6 )
{
log_printf(2LL, "Pipe geschrieben\n");
result = 1LL;
}
else
{
log_printf(0LL, "Fehler beim Schreiben in die Pipe\n");
result = 0LL;
}
return result;
}

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

close(*a1);
if ( write(a1[1], &spielzug, 6uLL) == 6 )
{
log_printf(2LL, "Pipe geschrieben\n");
result = 1LL;
}
else
{
log_printf(0LL, "Fehler beim Schreiben in die Pipe\n");
result = 0LL;
}
return result;
}

original_code:
int pipe_write(int pipe_fd[]){
 close(pipe_fd[0]);
 if((write(pipe_fd[1],spielzug,6))!=6){
  log_printf(0,"Fehler beim Schreiben in die Pipe\n");
  return 0;
 }
 log_printf(2,"Pipe geschrieben\n");
 return 1;
}


ueberwacheFd

decompiled_code:
__int64 __fastcall ueberwacheFd(int *a1, char *a2)
{
int v3; // edx
int v4; // edi
int v5; // eax
__int64 result; // rax
fd_set v7; // [rsp+0h] [rbp-98h] BYREF

v3 = getSocketFd();
memset(&v7, 0, sizeof(v7));
v4 = *a1;
v7.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
v7.fds_bits[v3 / 64] |= 1LL << (v3 % 64);
if ( v4 < v3 )
v4 = v3;
if ( select(v4 + 1, &v7, 0LL, 0LL, 0LL) <= 0 )
{
log_printf(0LL, "Fehler bei Select\n");
perror("error");
result = 0LL;
}
else
{
v5 = *a1 + 63;
if ( *a1 >= 0 )
v5 = *a1;
if ( (v7.fds_bits[v5 >> 6] & (1LL << (*a1 % 64))) != 0 )
{
log_printf(2LL, "Gandalf hat gedacht.\n");
result = pipe_read(a1, a2);
}
else
{
log_printf(2LL, "Gandalf denkt zu langsam.\n");
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, char *a2)
{
int v3; // edx
int v4; // edi
int v5; // eax
__int64 result; // rax
fd_set v7; // [rsp+0h] [rbp-98h] BYREF

v3 = getSocketFd();
memset(&v7, 0, sizeof(v7));
v4 = *a1;
v7.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
v7.fds_bits[v3 / 64] |= 1LL << (v3 % 64);
if ( v4 < v3 )
v4 = v3;
if ( select(v4 + 1, &v7, 0LL, 0LL, 0LL) <= 0 )
{
log_printf(0LL, "Fehler bei Select\n");
perror("error");
result = 0LL;
}
else
{
v5 = *a1 + 63;
if ( *a1 >= 0 )
v5 = *a1;
if ( (v7.fds_bits[v5 >> 6] & (1LL << (*a1 % 64))) != 0 )
{
log_printf(2LL, "Gandalf hat gedacht.\n");
result = func0(a1, a2);
}
else
{
log_printf(2LL, "Gandalf denkt zu langsam.\n");
result = 2LL;
}
}
return result;
}

original_code:
int ueberwacheFd(int pipe_fd[],char *getText){
 int socket_fd = getSocketFd();
 fd_set set;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((pipe_fd[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((pipe_fd[0]) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&set)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
 int max = pipe_fd[0];
 if (max < socket_fd) {
  max = socket_fd;
 }
 int ret = select(max+1,&set,((void *)0),((void *)0),((void *)0));
 if(ret < 1){
  log_printf(0,"Fehler bei Select\n");
  perror("error");
  return 0;
 }
 else if (((((&set)->__fds_bits)[((pipe_fd[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((pipe_fd[0]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   log_printf(2,"Gandalf hat gedacht.\n");
   return pipe_read(pipe_fd, getText); }
 log_printf(2,"Gandalf denkt zu langsam.\n");
 return 2;
}

canonical_original_code:
int ueberwacheFd(int pipe_fd[], char *getText){
 int socket_fd = getSocketFd();
 struct fd_set set;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((pipe_fd[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((pipe_fd[0]) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&set)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
 int max = pipe_fd[0];
 if (max < socket_fd) {
  max = socket_fd;
 }
 int ret = select(max+1,&set,((void *)0),((void *)0),((void *)0));
 if(ret < 1){
  log_printf(0,"Fehler bei Select\n");
  perror("error");
  return 0;
 }
 else if (((((&set)->__fds_bits)[((pipe_fd[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((pipe_fd[0]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   log_printf(2,"Gandalf hat gedacht.\n");
   return pipe_read(pipe_fd, getText); }
 log_printf(2,"Gandalf denkt zu langsam.\n");
 return 2;
}

variable_types:
set
struct fd_set { long __fds_bits[-1]; }

variable_types: max int

variable_types: ret int


printSteinNummern

decompiled_code:
__int64 __fastcall printSteinNummern(__int64 a1, int a2, int a3)
{
int *v4; // rbp
__int64 v5; // r13
int i; // ebx
__int64 v7; // rdx

log_printf(1LL, " | \x1B[2m");
if ( a2 )
{
v4 = (int *)(a1 + 4LL * a3);
v5 = a1 + 4 * ((unsigned int)(a2 - 1) + (__int64)a3) + 4;
do
{
v7 = (unsigned int)*v4;
if ( (_DWORD)v7 == -1 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
log_printf(1LL, " ");
}
}
else
{
log_printf(1LL, "\x1B[2m(%i)\x1B[0m", v7);
if ( *v4 <= 9 )
log_printf(1LL, " ");
}
log_printf(1LL, " ");
++v4;
}
while ( v4 != (int *)v5 );
}
return log_printf(1LL, "|\n");
}

original_code:
void printSteinNummern(int field[],int breite, int currentPlace) {
 int n = breite;
 log_printf(1,"  | ""\033[2m");
 while (n) {
  if (field[currentPlace] == -1) {
   for (int i=0; i<breite; i++) {
       log_printf(1," ");
      }
    }
    else {
     log_printf(1,"\033[2m""(%i)""\033[0m",field[currentPlace]);
   if(field[currentPlace] < 10) {
    log_printf(1," ");
   }
    }
    log_printf(1," ");
    currentPlace++;
    n--;
 }
 log_printf(1,"|\n");
 currentPlace = currentPlace - breite;
 n= breite;
}

canonical_original_code:
void printSteinNummern(int field[], int breite, int currentPlace) {
 int n = breite;
 log_printf(1,"  | ""\033[2m");
 while (n) {
  if (field[currentPlace] == -1) {
   for (int i = 0; i<breite; i++) {
       log_printf(1," ");
      }
    }
    else {
     log_printf(1,"\033[2m""(%i)""\033[0m",field[currentPlace]);
   if(field[currentPlace] < 10) {
    log_printf(1," ");
   }
    }
    log_printf(1," ");
    currentPlace++;
    n--;
 }
 log_printf(1,"|\n");
 currentPlace = currentPlace - breite;
 n= breite;
}

variable_types:
field
int []

variable_types: breite int

variable_types: currentPlace int

variable_types: n int

variable_types: i int


printSpaltenNamen

decompiled_code:
__int64 __fastcall printSpaltenNamen(int a1)
{
int v1; // ebx

if ( a1 )
{
v1 = a1;
do
log_printf(1LL, " %c", (unsigned int)(char)(a1 + 65 - v1--));
while ( v1 );
}
return log_printf(1LL, "\n");
}

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

if ( a1 )
{
v1 = a1;
do
log_printf(1LL, " %c", (unsigned int)(char)(a1 + 65 - v1--));
while ( v1 );
}
return log_printf(1LL, "\n");
}

original_code:
void printSpaltenNamen(int breite) {
 char c = 'A';
 while (breite) {
  log_printf(1,"    %c",c);
  c++;
  breite--;
 }
 log_printf(1,"\n");
}

variable_types: c char


printSpielstein

decompiled_code:
__int64 __fastcall printSpielstein(int a1)
{
__int64 result; // rax
int i; // ebp

result = shmPtr;
for ( i = *(_DWORD *)(shmPtr + 588LL); i; --i )
{
if ( (a1 & 1) != 0 )
log_printf(1LL, "\x1B[41m ");
else
log_printf(1LL, "\x1B[42m ");
result = log_printf(1LL, "\x1B[0m");
a1 >>= 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 result; // rax
int i; // ebp

result = shmPtr;
for ( i = *(_DWORD *)(shmPtr + 588LL); i; --i )
{
if ( (a1 & 1) != 0 )
log_printf(1LL, "\x1B[41m ");
else
log_printf(1LL, "\x1B[42m ");
result = log_printf(1LL, "\x1B[0m");
a1 >>= 1;
}
return result;
}

original_code:
void printSpielstein(int i) {
 int breite = shmPtr->breite;
 while (breite) {
  if (i & 1) {
   log_printf(1,"\033[41m"" ");
  } else {
   log_printf(1,"\033[42m"" ");
  }
 log_printf(1,"\033[0m");
 i >>= 1;
 breite--;
 }
}


printField

decompiled_code:
__int64 printField()
{
int v0; // er12
unsigned int v1; // er14
int v2; // er15
int i; // ebx
int *v4; // rbp
__int64 v6; // [rsp+8h] [rbp-40h]

v0 = *(_DWORD *)(shmPtr + 588LL);
v1 = *(_DWORD *)(shmPtr + 592LL);
v6 = shmPtr_Sf;
log_printf(1LL, "\n");
printSpaltenNamen(v0);
printMultiZeichen(v0, 43, 45);
if ( v1 )
{
v2 = 0;
do
{
printSteinNummern(v6, v0, v2);
log_printf(1LL, "%i | ", v1);
if ( v0 )
{
v4 = (int *)(v6 + 4LL * v2);
do
{
if ( *v4 == -1 )
{
if ( v0 > 0 )
{
for ( i = 0; i != v0; ++i )
log_printf(1LL, "*");
}
}
else
{
printSpielstein(*v4);
}
log_printf(1LL, " ");
++v4;
}
while ( v4 != (int *)(v6 + 4 * (v2 + (unsigned __int64)(unsigned int)(v0 - 1)) + 4) );
v2 += v0;
}
log_printf(1LL, "| %i\n", v1--);
}
while ( v1 );
}
printMultiZeichen(v0, 43, 45);
return printSpaltenNamen(v0);
}

original_code:
void printField() {
 int breite= shmPtr->breite;
 int hoehe = shmPtr->hoehe;
 int *field = shmPtr_Sf;
 int currentPlace = 0;
 log_printf(1,"\n");
 printSpaltenNamen(breite);
 printMultiZeichen(breite,'+','-');
 while (hoehe) {
  int n=breite;
  if(1) {printSteinNummern(field,breite,currentPlace);}
  log_printf(1,"%i | ",hoehe);
  while (n) {
   if (field[currentPlace] == -1) {
    for (int i=0; i<breite; i++) {
     log_printf(1,"*");
    }
   }
   else {
    printSpielstein(field[currentPlace]);
   }
   log_printf(1," ");
   currentPlace++;
   n--;
  }
  log_printf(1,"| %i\n",hoehe);
  hoehe--;
 }
 printMultiZeichen(breite,'+','-');
 printSpaltenNamen(breite);
}

canonical_original_code:
void printField() {
 int breite = shmPtr->breite;
 int hoehe = shmPtr->hoehe;
 int *field = shmPtr_Sf;
 int currentPlace = 0;
 log_printf(1,"\n");
 printSpaltenNamen(breite);
 printMultiZeichen(breite,'+','-');
 while (hoehe) {
  int n = breite;
  if(1) {printSteinNummern(field,breite,currentPlace);}
  log_printf(1,"%i | ",hoehe);
  while (n) {
   if (field[currentPlace] == -1) {
    for (int i = 0; i<breite; i++) {
     log_printf(1,"*");
    }
   }
   else {
    printSpielstein(field[currentPlace]);
   }
   log_printf(1," ");
   currentPlace++;
   n--;
  }
  log_printf(1,"| %i\n",hoehe);
  hoehe--;
 }
 printMultiZeichen(breite,'+','-');
 printSpaltenNamen(breite);
}

variable_types: hoehe int

variable_types:
field
int *


repo: pcazade/MDBas

decompiled_code:
double __fastcall coulomb_none(__int64 a1, _QWORD *a2)
{
*a2 = 0LL;
return 0.0;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, _QWORD *a2)
{
*a2 = 0LL;
return 0.0;
}

original_code:
double coulomb_none(const PARAM *param,double *delec,const double qel,
      const double r2,const double rt)
{
  *delec=0.;
  return 0.;
}

canonical_original_code:
double coulomb_none(struct PARAM *param, double *delec, double qel, double r2, double rt)
{
  *delec=0.;
  return 0.;
}

variable_types: struct PARAM { int step; double timeStep; int nAtom; int nBond; int nConst; double tolShake; double chargeConst; double cutOff; double cutOn; double temp0; double tolMinim; } *

variable_types:
delec
double *

variable_types: qel double

variable_types: rt double

return_type: double