main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int result; // eax
int v6; // eax
int v7; // ebx
__pid_t v8; // eax
int stat_loc; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

stat_loc = 0;
signal(17, (__sighandler_t)SigCatcher);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
{
puts("grrr, can't get the server socket");
result = 1;
}
else
{
v4 = v3;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(5000);
if ( bind(v4, &addr, 0x10u) < 0 )
{
puts("grrr, can't bind server socket");
close(v4);
result = 2;
}
else if ( listen(v4, 5) >= 0 )
{
while ( 1 )
{
addr_len[0] = 16;
v7 = accept(v4, &v11, addr_len);
if ( v7 < 0 )
break;
readPid = fork();
v8 = fork();
writePid = v8;
if ( readPid )
{
if ( !v8 )
{
close(v4);
while ( 1 )
{
while ( feof(stdin) )
;
fgets(&buffer, 0x2000, stdin);
if ( write(v7, &buffer, 0x2000uLL) == -1 )
break;
printf("<<< %s", &buffer);
fflush(stdout);
}
}
}
else
{
close(v4);
while ( 1 )
{
v6 = read(v7, &buffer, 0x2000uLL);
if ( v6 <= 0 )
break;
printf(">>> %s", &buffer);
buffer = 0;
}
if ( v6 )
perror("There was an error with the connection.\n");
else
puts("The client closed the connection.");
}
close(v7);
waitpid(readPid, &stat_loc, 2);
waitpid(writePid, &stat_loc, 2);
}
puts("grrr, can't accept a packet from client");
result = 4;
}
else
{
puts("grrr, can't listen on socket");
close(v4);
result = 3;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int result; // eax
int v6; // eax
int v7; // ebx
__pid_t v8; // eax
int stat_loc; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

stat_loc = 0;
signal(17, (__sighandler_t)SigCatcher);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
{
puts("grrr, can't get the server socket");
result = 1;
}
else
{
v4 = v3;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func8(0);
*(_WORD *)addr.sa_data = func9(5000);
if ( bind(v4, &addr, 0x10u) < 0 )
{
puts("grrr, can't bind server socket");
close(v4);
result = 2;
}
else if ( listen(v4, 5) >= 0 )
{
while ( 1 )
{
addr_len[0] = 16;
v7 = accept(v4, &v11, addr_len);
if ( v7 < 0 )
break;
readPid = fork();
v8 = fork();
writePid = v8;
if ( readPid )
{
if ( !v8 )
{
close(v4);
while ( 1 )
{
while ( feof(stdin) )
;
fgets(&buffer, 0x2000, stdin);
if ( write(v7, &buffer, 0x2000uLL) == -1 )
break;
printf("<<< %s", &buffer);
fflush(stdout);
}
}
}
else
{
close(v4);
while ( 1 )
{
v6 = read(v7, &buffer, 0x2000uLL);
if ( v6 <= 0 )
break;
printf(">>> %s", &buffer);
buffer = 0;
}
if ( v6 )
perror("There was an error with the connection.\n");
else
puts("The client closed the connection.");
}
close(v7);
waitpid(readPid, &stat_loc, 2);
waitpid(writePid, &stat_loc, 2);
}
puts("grrr, can't accept a packet from client");
result = 4;
}
else
{
puts("grrr, can't listen on socket");
close(v4);
result = 3;
}
}
return result;
}

original_code:
int main (void) {
 int server_socket, client_socket;
 int client_len;
 struct sockaddr_in client_addr, server_addr;
 int bytesRead = 0;
 int status = 0;
 signal (17, SigCatcher);
 if ((server_socket = socket (2, SOCK_STREAM, 0)) < 0) {
  printf ("grrr, can't get the server socket\n");
  return 1;
 }
 memset (&server_addr, 0, sizeof (server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = htonl (((in_addr_t) 0x00000000));
 server_addr.sin_port = htons (5000);
 if (bind (server_socket, (struct sockaddr *)&server_addr,
 sizeof (server_addr)) < 0) {
  printf ("grrr, can't bind server socket\n");
  close (server_socket);
  return 2;
 }
 if (listen (server_socket, 5) < 0) {
  printf ("grrr, can't listen on socket\n");
  close (server_socket);
  return 3;
 }
 while (1) {
    client_len = sizeof (client_addr);
  if ((client_socket = accept (server_socket,(struct sockaddr *)&client_addr, &client_len)) < 0) {
   printf ("grrr, can't accept a packet from client\n");
   return 4;
  }
  readPid = fork();
  writePid = fork();
  if ( readPid == 0 ) {
   close( server_socket );
   while (1) {
    if ( ( bytesRead = read( client_socket, buffer, 8192 ) ) <= 0 ) {
     if ( bytesRead == 0 ) {
      printf("The client closed the connection.\n");
     }
     else {
      perror("There was an error with the connection.\n");
     }
     close( client_socket );
     break;
    }
    else {
     printf(">>> %s", buffer);
    }
    strcpy( buffer, "" );
   }
  }
  else if ( writePid == 0 ) {
   close( server_socket );
   while (1) {
    if ( !feof( stdin ) ) {
     fgets( buffer, 8192, stdin );
     if ( write( client_socket, buffer, 8192 ) != -1 ) {
      printf( "<<< %s", buffer );
      fflush( stdout );
     }
     else {
      close( client_socket );
      break;
     }
    }
   }
  }
  else {
   close( client_socket );
  }
  waitpid(readPid, &status, 2);
  waitpid(writePid, &status, 2);
 }
 return 0;
}

canonical_original_code:
int main() {
 int server_socket; int client_socket;
 int client_len;
 struct sockaddr_in client_addr; struct sockaddr_in server_addr;
 int bytesRead = 0;
 int status = 0;
 signal (17, SigCatcher);
 if ((server_socket = socket (2, SOCK_STREAM, 0)) < 0) {
  printf ("grrr, can't get the server socket\n");
  return 1;
 }
 memset (&server_addr, 0, sizeof (server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = htonl (((unsigned int) 0x00000000));
 server_addr.sin_port = htons (5000);
 if (bind (server_socket, (struct sockaddr *)&server_addr,
 sizeof (server_addr)) < 0) {
  printf ("grrr, can't bind server socket\n");
  close (server_socket);
  return 2;
 }
 if (listen (server_socket, 5) < 0) {
  printf ("grrr, can't listen on socket\n");
  close (server_socket);
  return 3;
 }
 while (1) {
    client_len = sizeof (client_addr);
  if ((client_socket = accept (server_socket,(struct sockaddr *)&client_addr, &client_len)) < 0) {
   printf ("grrr, can't accept a packet from client\n");
   return 4;
  }
  readPid = fork();
  writePid = fork();
  if ( readPid == 0 ) {
   close( server_socket );
   while (1) {
    if ( ( bytesRead = read( client_socket, buffer, 8192 ) ) <= 0 ) {
     if ( bytesRead == 0 ) {
      printf("The client closed the connection.\n");
     }
     else {
      perror("There was an error with the connection.\n");
     }
     close( client_socket );
     break;
    }
    else {
     printf(">>> %s", buffer);
    }
    strcpy( buffer, "" );
   }
  }
  else if ( writePid == 0 ) {
   close( server_socket );
   while (1) {
    if ( !feof( stdin ) ) {
     fgets( buffer, 8192, stdin );
     if ( write( client_socket, buffer, 8192 ) != -1 ) {
      printf( "<<< %s", buffer );
      fflush( stdout );
     }
     else {
      close( client_socket );
      break;
     }
    }
   }
  }
  else {
   close( client_socket );
  }
  waitpid(readPid, &status, 2);
  waitpid(writePid, &status, 2);
 }
 return 0;
}

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

variable_types: bytesRead int

variable_types: status 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]; }


handler

decompiled_code:
void __fastcall handler(int a1)
{
if ( a1 == 2 )
keep_playing = 0;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
keep_playing = 0;
}

original_code:
void handler(int signo) {
    switch(signo) {
        case 2:
            keep_playing = 0;
            break;
    }
}

variable_types: signo int

return_type: void


game

original_code:
void
game(int w, int h)
{
  int x, y, rounds, round;
  unsigned univ[h][w];
  for (x = 0; x < w; x++) {
    for (y = 0; y < h; y++) {
      rounds = rand() % 200000;
      for (round = 0; round < rounds; round++) {
        univ[y][x] = rand() < 2147483647 / 10 ? 1 : 0;
      }
    }
  }
  while (keep_playing) {
    show(univ, w, h);
    evolve(univ, w, h);
    usleep(200000);
  }
}

canonical_original_code:
void game(int w, int h)
{
  int x; int y; int rounds; int round;
  unsigned int univ[-1][-1];
  for (x = 0; x < w; x++) {
    for (y = 0; y < h; y++) {
      rounds = rand() % 200000;
      for (round = 0; round < rounds; round++) {
        univ[y][x] = rand() < 2147483647 / 10 ? 1 : 0;
      }
    }
  }
  while (keep_playing) {
    show(univ, w, h);
    evolve(univ, w, h);
    usleep(200000);
  }
}

variable_types: w int

variable_types: h int

variable_types: x int

variable_types: y int

variable_types: rounds int

variable_types: round int

variable_types:
univ
unsigned int [-1][-1]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // esi
struct sigaction v6; // [rsp+0h] [rbp-C0h] BYREF

memset(&v6.sa_mask, 0, 0x90uLL);
v6.sa_handler = handler;
sigaction(2, &v6, 0LL);
v3 = time(0LL);
srand(v3);
if ( argc <= 1 )
{
v4 = 0;
}
else
{
v4 = atoi(argv[1]);
if ( argc > 2 )
{
v5 = atoi(argv[2]);
if ( v4 <= 0 )
v4 = 40;
if ( v5 <= 0 )
v5 = 40;
goto LABEL_7;
}
}
v5 = 40;
if ( v4 <= 0 )
v4 = 40;
LABEL_7:
game(v4, v5);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // esi
struct sigaction v6; // [rsp+0h] [rbp-C0h] BYREF

memset(&v6.sa_mask, 0, 0x90uLL);
v6.sa_handler = handler;
sigaction(2, &v6, 0LL);
v3 = time(0LL);
srand(v3);
if ( argc <= 1 )
{
v4 = 0;
}
else
{
v4 = atoi(argv[1]);
if ( argc > 2 )
{
v5 = atoi(argv[2]);
if ( v4 <= 0 )
v4 = 40;
if ( v5 <= 0 )
v5 = 40;
goto LABEL_7;
}
}
v5 = 40;
if ( v4 <= 0 )
v4 = 40;
LABEL_7:
func1(v4, v5);
exit(0);
}

original_code:
int
main(int argc, char **argv)
{
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.__sigaction_handler.sa_handler = &handler;
  sigaction(2, &sa, ((void *)0));
  srand(time(((void *)0)));
  int w = 0, h = 0;
  if (argc > 1) w = atoi(argv[1]);
  if (argc > 2) h = atoi(argv[2]);
  if (w <= 0) w = 40;
  if (h <= 0) h = 40;
  game(w, h);
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.__sigaction_handler.sa_handler = &handler;
  sigaction(2, &sa, ((void *)0));
  srand(time(((void *)0)));
  int w = 0; int h = 0;
  if (argc > 1) w = atoi(argv[1]);
  if (argc > 2) h = atoi(argv[2]);
  if (w <= 0) w = 40;
  if (h <= 0) h = 40;
  game(w, h);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

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

return_type: int

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

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


convertFirstArgToCommandName

original_code:
void convertFirstArgToCommandName(commandT* cmd) {
 char* command = cmd->argv[0];
 int starting = -1;
 int i;
 for (i = strlen(command); i >= 0; --i) {
  if (command[i] == '/') {
   starting = i;
   break;
  }
 }
 if (starting != -1) {
  char* commandName = malloc((strlen(command) - starting + 1) * sizeof(char));
  memcpy(commandName, command + (starting + 1) * sizeof(char), (strlen(command) - starting + 1) * sizeof(char));
  free(cmd->argv[0]);
  cmd->argv[0] = commandName;
 }
}

canonical_original_code:
void convertFirstArgToCommandName(struct command_t *cmd) {
 char *command = cmd->argv[0];
 int starting = -1;
 int i;
 for (i = strlen(command); i >= 0; --i) {
  if (command[i] == '/') {
   starting = i;
   break;
  }
 }
 if (starting != -1) {
  char *commandName = malloc((strlen(command) - starting + 1) * sizeof(char));
  memcpy(commandName, command + (starting + 1) * sizeof(char), (strlen(command) - starting + 1) * sizeof(char));
  free(cmd->argv[0]);
  cmd->argv[0] = commandName;
 }
}

variable_types: struct command_t { char *name; int argc; char *argv[]; } *

variable_types:
command
char *

variable_types: starting int

variable_types: i int

variable_types:
commandName
char *


getCurrentWorkingDir

decompiled_code:
char *getCurrentWorkingDir()
{
char *v0; // rax

v0 = (char *)malloc(0x8000uLL);
return getcwd(v0, 0x1000uLL);
}

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

v0 = (char *)malloc(0x8000uLL);
return getcwd(v0, 0x1000uLL);
}

original_code:
char*
getCurrentWorkingDir() {
 char* path = malloc(4096*sizeof(char*));
 return getcwd(path, 4096);
}

canonical_original_code:
char *getCurrentWorkingDir() {
 char *path = malloc(4096*sizeof(char*));
 return getcwd(path, 4096);
}

variable_types:
path
char *

return_type: char *


getFullPath

decompiled_code:
char *__fastcall getFullPath(char *src)
{
char *v1; // rbx
char *v2; // r13
char *v3; // rbp
char *v4; // r14
char *v5; // rbp
char *v6; // r15
char *v7; // rbp
char *v8; // rbx
__int16 v10; // [rsp+Eh] [rbp-4Ah]
char *v11; // [rsp+10h] [rbp-48h]
char *ptr; // [rsp+18h] [rbp-40h]

v1 = getenv("PATH");
v2 = (char *)malloc(0x8000uLL);
if ( *src == 47 )
{
if ( (unsigned int)fileExists(src) )
{
strcpy(v2, src);
return v2;
}
goto LABEL_15;
}
v3 = getenv("HOME");
v4 = (char *)malloc(0x8000uLL);
strcpy(v4, v3);
*(_WORD *)&v4[strlen(v4)] = 47;
strcat(v4, src);
if ( (unsigned int)fileExists(v4) )
{
strcpy(v2, v4);
free(v4);
return v2;
}
v5 = getCurrentWorkingDir();
v11 = v5;
v6 = (char *)malloc(0x8000uLL);
strcpy(v6, v5);
*(_WORD *)&v6[strlen(v6)] = 47;
strcat(v6, src);
if ( (unsigned int)fileExists(v6) )
{
strcpy(v2, v6);
free(v6);
free(v5);
free(v4);
return v2;
}
ptr = (char *)malloc(0x8000uLL);
strcpy(ptr, v1);
v7 = strtok(ptr, ":");
if ( v7 )
{
v10 = 0;
do
{
v8 = (char *)malloc(0x8000uLL);
strcpy(v8, v7);
*(_WORD *)&v8[strlen(v8)] = 47;
strcat(v8, src);
if ( (unsigned int)fileExists(v8) )
{
strcpy(v2, v8);
v10 = 1;
}
v7 = strtok(0LL, ":");
free(v8);
}
while ( v7 );
}
else
{
v10 = 0;
}
free(ptr);
free(v6);
free(v11);
free(v4);
if ( !v10 )
{
LABEL_15:
strcpy(v2, "line 1: ");
strcat(v2, src);
PrintPError(v2);
free(v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func11(char *src)
{
char *v1; // rbx
char *v2; // r13
char *v3; // rbp
char *v4; // r14
char *v5; // rbp
char *v6; // r15
char *v7; // rbp
char *v8; // rbx
__int16 v10; // [rsp+Eh] [rbp-4Ah]
char *v11; // [rsp+10h] [rbp-48h]
char *ptr; // [rsp+18h] [rbp-40h]

v1 = getenv("PATH");
v2 = (char *)malloc(0x8000uLL);
if ( *src == 47 )
{
if ( (unsigned int)func2(src) )
{
strcpy(v2, src);
return v2;
}
goto LABEL_15;
}
v3 = getenv("HOME");
v4 = (char *)malloc(0x8000uLL);
strcpy(v4, v3);
*(_WORD *)&v4[strlen(v4)] = 47;
strcat(v4, src);
if ( (unsigned int)func2(v4) )
{
strcpy(v2, v4);
free(v4);
return v2;
}
v5 = func10();
v11 = v5;
v6 = (char *)malloc(0x8000uLL);
strcpy(v6, v5);
*(_WORD *)&v6[strlen(v6)] = 47;
strcat(v6, src);
if ( (unsigned int)func2(v6) )
{
strcpy(v2, v6);
free(v6);
free(v5);
free(v4);
return v2;
}
ptr = (char *)malloc(0x8000uLL);
strcpy(ptr, v1);
v7 = strtok(ptr, ":");
if ( v7 )
{
v10 = 0;
do
{
v8 = (char *)malloc(0x8000uLL);
strcpy(v8, v7);
*(_WORD *)&v8[strlen(v8)] = 47;
strcat(v8, src);
if ( (unsigned int)func2(v8) )
{
strcpy(v2, v8);
v10 = 1;
}
v7 = strtok(0LL, ":");
free(v8);
}
while ( v7 );
}
else
{
v10 = 0;
}
free(ptr);
free(v6);
free(v11);
free(v4);
if ( !v10 )
{
LABEL_15:
strcpy(v2, "line 1: ");
strcat(v2, src);
PrintPError(v2);
free(v2);
v2 = 0LL;
}
return v2;
}

original_code:
char* getFullPath(char* filename) {
 char* paths = getenv("PATH");
 char* result = malloc(4096*sizeof(char*));
 short found = 0;
 if (filename[0] == '/') {
  if (fileExists(filename)) {
   strcpy(result, filename);
   found = 1;
  }
 } else {
  char* home = getenv("HOME");
  char* homePath = malloc(4096*sizeof(char*));
  strcpy(homePath, home);
  strcat(homePath, "/");
  strcat(homePath, filename);
  if (fileExists(homePath)) {
   strcpy(result, homePath);
   found = 1;
  } else {
   char* workingDir = getCurrentWorkingDir();
   char* fullWorkingDir = malloc(4096*sizeof(char*));
   strcpy(fullWorkingDir, workingDir);
   strcat(fullWorkingDir, "/");
   strcat(fullWorkingDir, filename);
   if (fileExists(fullWorkingDir)) {
    strcpy(result, fullWorkingDir);
    found = 1;
   } else {
    char* pathCopy = malloc(4096*sizeof(char*));
    strcpy(pathCopy, paths);
    char* path = strtok(pathCopy, ":");
    while (path != ((void *)0)) {
     char* fullPath = malloc(4096*sizeof(char*));
     strcpy(fullPath, path);
     strcat(fullPath, "/");
     strcat(fullPath, filename);
     if (fileExists(fullPath)) {
      strcpy(result, fullPath);
      found = 1;
     }
     path = strtok(((void *)0), ":");
     free(fullPath);
    }
    free(pathCopy);
   }
   free(fullWorkingDir);
   free(workingDir);
  }
  free(homePath);
 }
 if (found) {
  return result;
 } else {
  strcpy(result, "line 1: ");
  strcat(result, filename);
  PrintPError(result);
  free(result);
  return ((void *)0);
 }
}

canonical_original_code:
char *getFullPath(char *filename) {
 char *paths = getenv("PATH");
 char *result = malloc(4096*sizeof(char*));
 short found = 0;
 if (filename[0] == '/') {
  if (fileExists(filename)) {
   strcpy(result, filename);
   found = 1;
  }
 } else {
  char *home = getenv("HOME");
  char *homePath = malloc(4096*sizeof(char*));
  strcpy(homePath, home);
  strcat(homePath, "/");
  strcat(homePath, filename);
  if (fileExists(homePath)) {
   strcpy(result, homePath);
   found = 1;
  } else {
   char *workingDir = getCurrentWorkingDir();
   char *fullWorkingDir = malloc(4096*sizeof(char*));
   strcpy(fullWorkingDir, workingDir);
   strcat(fullWorkingDir, "/");
   strcat(fullWorkingDir, filename);
   if (fileExists(fullWorkingDir)) {
    strcpy(result, fullWorkingDir);
    found = 1;
   } else {
    char *pathCopy = malloc(4096*sizeof(char*));
    strcpy(pathCopy, paths);
    char *path = strtok(pathCopy, ":");
    while (path != ((void *)0)) {
     char *fullPath = malloc(4096*sizeof(char*));
     strcpy(fullPath, path);
     strcat(fullPath, "/");
     strcat(fullPath, filename);
     if (fileExists(fullPath)) {
      strcpy(result, fullPath);
      found = 1;
     }
     path = strtok(((void *)0), ":");
     free(fullPath);
    }
    free(pathCopy);
   }
   free(fullWorkingDir);
   free(workingDir);
  }
  free(homePath);
 }
 if (found) {
  return result;
 } else {
  strcpy(result, "line 1: ");
  strcat(result, filename);
  PrintPError(result);
  free(result);
  return ((void *)0);
 }
}

variable_types:
filename
char *

variable_types:
paths
char *

variable_types:
result
char *

variable_types: found short

variable_types:
home
char *

variable_types:
homePath
char *

variable_types:
workingDir
char *

variable_types:
fullWorkingDir
char *

variable_types:
pathCopy
char *

variable_types:
fullPath
char *


ResolveExternalCmd

decompiled_code:
__int64 __fastcall ResolveExternalCmd(char **a1)
{
char *v1; // rax
unsigned int v2; // edx

v1 = getFullPath(*a1);
v2 = 0;
if ( v1 )
{
*a1 = v1;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(char **a1)
{
char *v1; // rax
unsigned int v2; // edx

v1 = func11(*a1);
v2 = 0;
if ( v1 )
{
*a1 = v1;
v2 = 1;
}
return v2;
}

original_code:
static short
ResolveExternalCmd(commandT* cmd) {
 char* fullPath = getFullPath(cmd->name);
 if (fullPath != ((void *)0)) {
  cmd->name = fullPath;
  return 1;
 }
 free(fullPath);
 return 0;
}

canonical_original_code:
static short ResolveExternalCmd(struct command_t *cmd) {
 char *fullPath = getFullPath(cmd->name);
 if (fullPath != ((void *)0)) {
  cmd->name = fullPath;
  return 1;
 }
 free(fullPath);
 return 0;
}

return_type: short

user_defined_types: struct command_t { char *name; int argc; char *argv[]; }


RunExternalCmd

decompiled_code:
void __fastcall RunExternalCmd(char **a1, __int16 a2)
{
if ( (unsigned __int16)ResolveExternalCmd(a1) )
Exec((__int64)a1, a2);
}

canonical_decompiled_code:
void __fastcall func13(char **a1, __int16 a2)
{
if ( (unsigned __int16)func12(a1) )
func8((__int64)a1, a2);
}

original_code:
static void
RunExternalCmd(commandT* cmd, short fork) {
 if (ResolveExternalCmd(cmd))
  Exec(cmd, fork);
}

canonical_original_code:
static void RunExternalCmd(struct command_t *cmd, short fork) {
 if (ResolveExternalCmd(cmd))
  Exec(cmd, fork);
}

variable_types: fork short


PrintNewline

decompiled_code:
int PrintNewline()
{
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
return putchar(10);
}

original_code:
void
PrintNewline()
{
 putchar('\n');
}

canonical_original_code:
void PrintNewline()
{
 putchar('\n');
}


Print

decompiled_code:
int __fastcall Print(const char *a1)
{
if ( !a1 )
_assert_fail("msg != NULL", "io.c", 0x64u, "Print");
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
if ( !a1 )
_assert_fail("msg != NULL", "io.c", 0x64u, "Print");
return puts(a1);
}

original_code:
void
Print(char* msg)
{
 ((void) sizeof ((msg != ((void *)0)) ? 1 : 0), __extension__ ({ if (msg != ((void *)0)) ; else __assert_fail ("msg != NULL", "io.c", 100, __extension__ __PRETTY_FUNCTION__); }));
 puts(msg);
}

canonical_original_code:
void Print(char *msg)
{
 ((void) sizeof ((msg != ((void *)0)) ? 1 : 0), __extension__ ({ if (msg != ((void *)0)) ; else __assert_fail ("msg != NULL", "io.c", 100, __extension__ __PRETTY_FUNCTION__); }));
 puts(msg);
}

variable_types:
msg
char *


PrintPError

decompiled_code:
void __fastcall PrintPError(const char *a1)
{
char v1[136]; // [rsp+0h] [rbp-88h] BYREF

if ( a1 )
{
snprintf(v1, 0x77uLL, "%s: %s", "tsh", a1);
perror(v1);
}
else
{
perror("tsh");
}
}

canonical_decompiled_code:
void __fastcall func2(const char *a1)
{
char v1[136]; // [rsp+0h] [rbp-88h] BYREF

if ( a1 )
{
snprintf(v1, 0x77uLL, "%s: %s", "tsh", a1);
perror(v1);
}
else
{
perror("tsh");
}
}

original_code:
void
PrintPError(char* msg)
{
 char* format = "%s: %s";
 char str[120];
 if (msg == ((void *)0))
  {
   perror("tsh");
   return;
  }
 snprintf(str, 120 - 1, format, "tsh", msg);
 perror(str);
}

canonical_original_code:
void PrintPError(char *msg)
{
 char *format = "%s: %s";
 char str[120];
 if (msg == ((void *)0))
  {
   perror("tsh");
   return;
  }
 snprintf(str, 120 - 1, format, "tsh", msg);
 perror(str);
}

variable_types:
format
char *

variable_types:
str
char [120]


IsReading

decompiled_code:
__int64 IsReading()
{
return (unsigned __int16)isReading;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int16)isReading;
}

original_code:
short
IsReading()
{
 return isReading;
}

canonical_original_code:
short IsReading()
{
 return isReading;
}


getCommandLine

decompiled_code:
int __fastcall getCommandLine(_BYTE **a1, int a2)
{
_BYTE *v3; // r12
__int64 i; // rbp
int result; // eax
char v6; // bl

v3 = *a1;
**a1 = 0;
isReading = 1;
for ( i = 0LL; ; v3[i] = 0 )
{
result = getc(stdin);
v6 = result;
if ( (_BYTE)result == 10 || (_BYTE)result == 0xFF )
break;
if ( a2 == i )
{
a2 *= 2;
v3 = realloc(v3, a2 + 1);
}
v3[i++] = v6;
}
isReading = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func4(_BYTE **a1, int a2)
{
_BYTE *v3; // r12
__int64 i; // rbp
int result; // eax
char v6; // bl

v3 = *a1;
**a1 = 0;
isReading = 1;
for ( i = 0LL; ; v3[i] = 0 )
{
result = getc(stdin);
v6 = result;
if ( (_BYTE)result == 10 || (_BYTE)result == 0xFF )
break;
if ( a2 == i )
{
a2 *= 2;
v3 = realloc(v3, a2 + 1);
}
v3[i++] = v6;
}
isReading = 0;
return result;
}

original_code:
void
getCommandLine(char** buf, int size)
{
 char ch;
 size_t used = 0;
 char* cmd = *buf;
 cmd[0] = '\0';
 isReading = 1;
 while (((ch = getc(stdin)) != (-1)) && (ch != '\n'))
  {
   if (used == size)
    {
     size *= 2;
     cmd = realloc(cmd, sizeof(char) * (size + 1));
    }
   cmd[used] = ch;
   used++;
   cmd[used] = '\0';
  }
 isReading = 0;
}

canonical_original_code:
void getCommandLine(char **buf, int size)
{
 char ch;
 unsigned long used = 0;
 char *cmd = *buf;
 cmd[0] = '\0';
 isReading = 1;
 while (((ch = getc(stdin)) != (-1)) && (ch != '\n'))
  {
   if (used == size)
    {
     size *= 2;
     cmd = realloc(cmd, sizeof(char) * (size + 1));
    }
   cmd[used] = ch;
   used++;
   cmd[used] = '\0';
  }
 isReading = 0;
}

variable_types:
buf
char **

variable_types: size int

variable_types: ch char

variable_types:
used
unsigned long

variable_types:
cmd
char *


show

original_code:
void
show(void *u, int w, int h)
{
  int x, y;
  int (*univ)[w] = u;
  printf("\033[H");
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++)
      printf(univ[y][x] ? "\033[44m  \033[m" : "  ");
    printf("\033[E");
  }
  fflush(stdout);
}

canonical_original_code:
void show(void *u, int w, int h)
{
  int x; int y;
  int (*univ)[-1] = u;
  printf("\033[H");
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++)
      printf(univ[y][x] ? "\033[44m  \033[m" : "  ");
    printf("\033[E");
  }
  fflush(stdout);
}

variable_types:
u
void *

variable_types: w int

variable_types: h int

variable_types: x int

variable_types: y int

variable_types:
univ
int (*)[-1]


freeCommand

decompiled_code:
void __fastcall freeCommand(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
{
v3 = (void **)((char *)ptr + 16);
do
{
free(v2);
*v3++ = 0LL;
v2 = *v3;
}
while ( *v3 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
{
v3 = (void **)((char *)ptr + 16);
do
{
free(v2);
*v3++ = 0LL;
v2 = *v3;
}
while ( *v3 );
}
free(ptr);
}

original_code:
void
freeCommand(commandT* cmd)
{
 int i;
 cmd->name = 0;
 for (i = 0; cmd->argv[i] != 0; i++)
  {
   free(cmd->argv[i]);
   cmd->argv[i] = 0;
  }
 free(cmd);
}

canonical_original_code:
void freeCommand(struct command_t *cmd)
{
 int i;
 cmd->name = 0;
 for (i = 0; cmd->argv[i] != 0; i++)
  {
   free(cmd->argv[i]);
   cmd->argv[i] = 0;
  }
 free(cmd);
}

variable_types: struct command_t { char *name; int argc; char *argv[]; } *

variable_types: i int


Interpret

decompiled_code:
void __fastcall Interpret(char *a1)
{
_QWORD *v1; // rbx

v1 = getCommand(a1);
RunCmd(v1);
fflush(stdout);
freeCommand(v1);
}

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

v1 = getCommand(a1);
RunCmd(v1);
fflush(stdout);
func0(v1);
}

original_code:
void
Interpret(char* cmdLine)
{
 commandT* cmd = getCommand(cmdLine);
 RunCmd(cmd);
 fflush(stdout);
 freeCommand(cmd);
}

canonical_original_code:
void Interpret(char *cmdLine)
{
 struct command_t *cmd = getCommand(cmdLine);
 RunCmd(cmd);
 fflush(stdout);
 freeCommand(cmd);
}

variable_types:
cmdLine
char *


repo: b/libdtw

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

*(_DWORD *)(a1 + 12) = a2;
*(_DWORD *)(a1 + 8) = 0;
result = malloc(4LL * a2);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 20) = a2 - 1;
return result;
}

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

*(_DWORD *)(a1 + 12) = a2;
*(_DWORD *)(a1 + 8) = 0;
result = malloc(4LL * a2);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 20) = a2 - 1;
return result;
}

original_code:
void deq_new(struct deque *d, int capacity)
{
    d->capacity = capacity;
    d->size = 0;
    d->dq = (int *) malloc(sizeof(int)*d->capacity);
    d->f = 0;
    d->r = d->capacity-1;
}

variable_types: struct deque { int *dq; int size; int f; } *

variable_types: capacity int


decompiled_code:
void __fastcall deq_free(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
free(*a1);
}

original_code:
void deq_free(struct deque *d)
{
    free(d->dq);
}

user_defined_types: struct deque { int *dq; int size; int f; }


decompiled_code:
__int64 __fastcall deq_push_back(__int64 a1, int a2)
{
__int64 result; // rax

*(_DWORD *)(*(_QWORD *)a1 + 4LL * *(int *)(a1 + 20)) = a2;
result = (unsigned int)(*(_DWORD *)(a1 + 20) - 1);
*(_DWORD *)(a1 + 20) = result;
if ( (int)result < 0 )
{
result = (unsigned int)(*(_DWORD *)(a1 + 12) - 1);
*(_DWORD *)(a1 + 20) = result;
}
++*(_DWORD *)(a1 + 8);
return result;
}

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

*(_DWORD *)(*(_QWORD *)a1 + 4LL * *(int *)(a1 + 20)) = a2;
result = (unsigned int)(*(_DWORD *)(a1 + 20) - 1);
*(_DWORD *)(a1 + 20) = result;
if ( (int)result < 0 )
{
result = (unsigned int)(*(_DWORD *)(a1 + 12) - 1);
*(_DWORD *)(a1 + 20) = result;
}
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void deq_push_back(struct deque *d, int v)
{
    d->dq[d->r] = v;
    d->r--;
    if (d->r < 0)
        d->r = d->capacity - 1;
    d->size++;
}

variable_types: v int


original_code:
int deq_front(struct deque *d)
{
    int aux = d->f - 1;
    if (aux < 0)
        aux = d->capacity - 1;
    return d->dq[aux];
}

variable_types: aux int


original_code:
int deq_back(struct deque *d)
{
    int aux = (d->r + 1) % d->capacity;
    return d->dq[aux];
}


decompiled_code:
_BOOL8 __fastcall deq_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

original_code:
int deq_empty(struct deque *d)
{
    return d->size == 0;
}


display

decompiled_code:
__int64 display()
{
glLoadIdentity();
glScalef(0.25, 0.25);
glClear(16640LL);
drawPoints();
glFlush();
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func0()
{
glLoadIdentity();
glScalef(0.25, 0.25);
glClear(16640LL);
drawPoints();
glFlush();
return glutSwapBuffers();
}

original_code:
void display(void)
{
    glLoadIdentity();
 glScalef( 0.25f, 0.25f, 0.25f );
    glClear(0x00004000 | 0x00000100);
    drawPoints();
    glFlush();
    glutSwapBuffers();
}

canonical_original_code:
void display()
{
    glLoadIdentity();
 glScalef( 0.25f, 0.25f, 0.25f );
    glClear(0x00004000 | 0x00000100);
    drawPoints();
    glFlush();
    glutSwapBuffers();
}


key

decompiled_code:
void __fastcall key(char a1)
{
if ( a1 == 113 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
if ( a1 == 113 )
exit(0);
}

original_code:
void key( unsigned char keyPressed, int x, int y )
{
    switch( keyPressed )
    {
        case 'q':
            exit( 0 );
            break;
        default:
            break;
    }
}

canonical_original_code:
void key(unsigned char keyPressed, int x, int y)
{
    switch( keyPressed )
    {
        case 'q':
            exit( 0 );
            break;
        default:
            break;
    }
}

variable_types:
keyPressed
unsigned char


reshape

decompiled_code:
__int64 __fastcall reshape(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glFrustum(
-0.800000011920929,
0.800000011920929,
(float)(-0.80000001 / (float)((float)a1 / (float)a2)),
(float)(0.80000001 / (float)((float)a1 / (float)a2)),
3.0,
10.0);
gluLookAt(3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5889LL);
glMatrixMode(5888LL);
glLoadIdentity();
return glTranslatef(0.0, 0.0, -5.0);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glFrustum(
-0.800000011920929,
0.800000011920929,
(float)(-0.80000001 / (float)((float)a1 / (float)a2)),
(float)(0.80000001 / (float)((float)a1 / (float)a2)),
3.0,
10.0);
gluLookAt(3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5889LL);
glMatrixMode(5888LL);
glLoadIdentity();
return glTranslatef(0.0, 0.0, -5.0);
}

original_code:
void reshape(int wid, int ht)
{
    float vp = 0.8f;
    float aspect = (float) wid / (float) ht;
    glViewport(0, 0, wid, ht);
    glMatrixMode(0x1701);
    glLoadIdentity();
    glViewport(0, 0, wid, ht);
    glMatrixMode(0x1701);
    glLoadIdentity();
    glFrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10.0);
 gluLookAt( 3.0f,
               3.0f,
               3.0f,
               0.0f,
               0.0f,
               0.0f,
               0.0f,
               1.0f,
               0.0f );
    glMatrixMode(0x1700);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -5.0);
}

variable_types: wid int

variable_types: ht int

variable_types: vp float

variable_types: aspect float


printOglError

decompiled_code:
__int64 __fastcall printOglError(const char *a1, unsigned int a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
const char *v5; // rax
unsigned int v6; // eax

v3 = glGetError();
v4 = v3;
if ( !v3 )
return 0LL;
do
{
v5 = (const char *)gluErrorString(v4);
printf("glError in file %s @ line %d: %s\n", a1, a2, v5);
v6 = glGetError();
v4 = v6;
}
while ( v6 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, unsigned int a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
const char *v5; // rax
unsigned int v6; // eax

v3 = glGetError();
v4 = v3;
if ( !v3 )
return 0LL;
do
{
v5 = (const char *)gluErrorString(v4);
printf("glError in file %s @ line %d: %s\n", a1, a2, v5);
v6 = glGetError();
v4 = v6;
}
while ( v6 );
return 1LL;
}

original_code:
int printOglError(char *file, int line)
{
    GLenum glErr;
    int retCode = 0;
    glErr = glGetError();
    while (glErr != 0)
    {
        printf("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
        retCode = 1;
        glErr = glGetError();
    }
    return retCode;
}

canonical_original_code:
int printOglError(char *file, int line)
{
    unsigned int glErr;
    int retCode = 0;
    glErr = glGetError();
    while (glErr != 0)
    {
        printf("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
        retCode = 1;
        glErr = glGetError();
    }
    return retCode;
}

variable_types:
file
char *

variable_types: line int

variable_types:
glErr
unsigned int

variable_types: retCode int


Args

decompiled_code:
_BOOL8 __fastcall Args(int a1, __int64 a2)
{
const char **v2; // rax
int v3; // edx
const char **v4; // r10
bool v5; // zf
_BOOL4 v6; // ebx

v2 = (const char **)(a2 + 8);
v3 = 1;
while ( v3 < a1 )
{
v4 = v2;
v5 = strcmp(*v2, "-loop") == 0;
v6 = !v5;
if ( !v5 )
{
printf("%s (Bad option)\n", *v2);
return 0;
}
if ( ++v3 < a1 )
{
++v2;
if ( *v4[1] != 45 )
continue;
}
puts("-loop no count given.");
return v6;
}
return 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, __int64 a2)
{
const char **v2; // rax
int v3; // edx
const char **v4; // r10
bool v5; // zf
_BOOL4 v6; // ebx

v2 = (const char **)(a2 + 8);
v3 = 1;
while ( v3 < a1 )
{
v4 = v2;
v5 = strcmp(*v2, "-loop") == 0;
v6 = !v5;
if ( !v5 )
{
printf("%s (Bad option)\n", *v2);
return 0;
}
if ( ++v3 < a1 )
{
++v2;
if ( *v4[1] != 45 )
continue;
}
puts("-loop no count given.");
return v6;
}
return 1;
}

original_code:
int Args(int argc, char **argv)
{
    int i;
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "-loop") == 0)
        {
            if (i+1 >= argc || argv[i+1][0] == '-')
            {
                printf("-loop no count given.\n");
                return 0;
            }
        }
        else
        {
            printf("%s (Bad option)\n", argv[i]);
            return 0;
        }
    }
    return 1;
}

variable_types: argc int

variable_types:
argv
char **


updateAnim

decompiled_code:
__int64 updateAnim()
{
__int64 v0; // rdi

v0 = (unsigned int)getUniLoc(ProgramObject, "currentTime");
if ( (float)(*(float *)&ParticleTime + 0.0020000001) > 15.0 )
ParticleTime = 0;
else
*(float *)&ParticleTime = *(float *)&ParticleTime + 0.0020000001;
glUniform1fARB(v0, *(float *)&ParticleTime);
return printOglError("ogl2particle.c", 0x85u);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi

v0 = (unsigned int)getUniLoc(ProgramObject, "currentTime");
if ( (float)(*(float *)&ParticleTime + 0.0020000001) > 15.0 )
ParticleTime = 0;
else
*(float *)&ParticleTime = *(float *)&ParticleTime + 0.0020000001;
glUniform1fARB(v0, *(float *)&ParticleTime);
return func3("ogl2particle.c", 0x85u);
}

original_code:
void updateAnim()
{
    int location;
    location = getUniLoc(ProgramObject, "currentTime");
    ParticleTime += 0.002f;
    if (ParticleTime > 15.0)
        ParticleTime = 0.0;
    glUniform1fARB(location, ParticleTime);
    printOglError("ogl2particle.c", 133);
}

variable_types: location int


play

decompiled_code:
__int64 play()
{
updateAnim();
printOglError("ogl2particle.c", 0x8Du);
glutPostRedisplay();
return printOglError("ogl2particle.c", 0x8Fu);
}

canonical_decompiled_code:
__int64 func6()
{
func5();
func3("ogl2particle.c", 0x8Du);
glutPostRedisplay();
return func3("ogl2particle.c", 0x8Fu);
}

original_code:
void play(void)
{
    updateAnim();
    printOglError("ogl2particle.c", 141);
    glutPostRedisplay();
    printOglError("ogl2particle.c", 143);
}

canonical_original_code:
void play()
{
    updateAnim();
    printOglError("ogl2particle.c", 141);
    glutPostRedisplay();
    printOglError("ogl2particle.c", 143);
}


isExtensionSupported

decompiled_code:
__int64 __fastcall isExtensionSupported(char *s)
{
char *v1; // rdx
__int64 result; // rax
const char *v3; // r12
char *v4; // rbx
const char *v5; // rax

v1 = strchr(s, 32);
result = 0LL;
if ( !v1 && *s )
{
v3 = (const char *)glGetString(7939LL);
while ( 1 )
{
v4 = strstr(v3, s);
if ( !v4 )
break;
v5 = &v4[strlen(s)];
if ( v3 != v4 )
{
v3 = v5;
if ( *(v4 - 1) != 32 )
continue;
}
if ( (*v5 & 0xDF) == 0 )
return 1LL;
v3 = v5;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s)
{
char *v1; // rdx
__int64 result; // rax
const char *v3; // r12
char *v4; // rbx
const char *v5; // rax

v1 = strchr(s, 32);
result = 0LL;
if ( !v1 && *s )
{
v3 = (const char *)glGetString(7939LL);
while ( 1 )
{
v4 = strstr(v3, s);
if ( !v4 )
break;
v5 = &v4[strlen(s)];
if ( v3 != v4 )
{
v3 = v5;
if ( *(v4 - 1) != 32 )
continue;
}
if ( (*v5 & 0xDF) == 0 )
return 1LL;
v3 = v5;
}
result = 0LL;
}
return result;
}

original_code:
int isExtensionSupported( const char *extension )
{
    const GLubyte *extensions = ((void *)0);
    const GLubyte *start;
    GLubyte *where, *terminator;
    where = (GLubyte *) strchr(extension, ' ');
    if (where || *extension == '\0')
        return 0;
    extensions = glGetString(0x1F03);
    start = extensions;
    for (;;) {
        where = (GLubyte *) strstr((const char *) start, extension);
        if (!where)
            break;
        terminator = where + strlen(extension);
        if (where == start || *(where - 1) == ' ')
            if (*terminator == ' ' || *terminator == '\0')
                return 1;
        start = terminator;
    }
    return 0;
}

canonical_original_code:
int isExtensionSupported(char *extension)
{
    unsigned char *extensions = ((void *)0);
    unsigned char *start;
    unsigned char *where; unsigned char *terminator;
    where = (unsigned char *) strchr(extension, ' ');
    if (where || *extension == '\0')
        return 0;
    extensions = glGetString(0x1F03);
    start = extensions;
    for (;;) {
        where = (unsigned char *) strstr((char *) start, extension);
        if (!where)
            break;
        terminator = where + strlen(extension);
        if (where == start || *(where - 1) == ' ')
            if (*terminator == ' ' || *terminator == '\0')
                return 1;
        start = terminator;
    }
    return 0;
}

variable_types:
extension
char *

variable_types:
extensions
unsigned char *

variable_types:
start
unsigned char *

variable_types:
where
unsigned char *

variable_types:
terminator
unsigned char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // rsi
int v6; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-18h] BYREF
__int64 v8; // [rsp+18h] [rbp-10h] BYREF

v6 = argc;
if ( !Args(argc, (__int64)argv) )
exit(0);
glutInit(&v6, argv);
glutInitDisplayMode(18LL);
glutInitWindowSize(500LL, 500LL);
glutCreateWindow("Fire and Smoke");
glutIdleFunc(play);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutReshapeFunc(reshape);
printOglError("ogl2particle.c", 0xFDu);
if ( (unsigned int)isExtensionSupported("GL_ARB_shader_objects")
&& (unsigned int)isExtensionSupported("GL_ARB_fragment_shader")
&& (unsigned int)isExtensionSupported("GL_ARB_vertex_shader")
&& (unsigned int)isExtensionSupported("GL_ARB_shading_language_100") )
{
createPoints(50000LL);
glDepthFunc(513LL);
glEnable(2929LL);
glClearColor(0.0, 0.67000002, 0.94, 1.0);
ParticleTime = 0;
readShaderSource("smoke", &v8, &v7);
v5 = v7;
v3 = installParticleShaders(v8, v7);
if ( v3 )
{
glutMainLoop();
v3 = 0;
}
else
{
printf("Error installing particle shaders");
_isoc99_scanf("%d", v5);
}
}
else
{
puts("OpenGL Shading Language extensions not available");
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // rsi
int v6; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-18h] BYREF
__int64 v8; // [rsp+18h] [rbp-10h] BYREF

v6 = argc;
if ( !func4(argc, (__int64)argv) )
exit(0);
glutInit(&v6, argv);
glutInitDisplayMode(18LL);
glutInitWindowSize(500LL, 500LL);
glutCreateWindow("Fire and Smoke");
glutIdleFunc(play);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutReshapeFunc(reshape);
func3("ogl2particle.c", 0xFDu);
if ( (unsigned int)func7("GL_ARB_shader_objects")
&& (unsigned int)func7("GL_ARB_fragment_shader")
&& (unsigned int)func7("GL_ARB_vertex_shader")
&& (unsigned int)func7("GL_ARB_shading_language_100") )
{
createPoints(50000LL);
glDepthFunc(513LL);
glEnable(2929LL);
glClearColor(0.0, 0.67000002, 0.94, 1.0);
ParticleTime = 0;
readShaderSource("smoke", &v8, &v7);
v5 = v7;
v3 = installParticleShaders(v8, v7);
if ( v3 )
{
glutMainLoop();
v3 = 0;
}
else
{
printf("Error installing particle shaders");
_isoc99_scanf("%d", v5);
}
}
else
{
puts("OpenGL Shading Language extensions not available");
v3 = 1;
}
return v3;
}

original_code:
int main( int argc, char **argv )
{
    int success = 0;
    GLcharARB *VertexShaderSource, *FragmentShaderSource;
    int error = 0;
    if (Args(argc, argv) == 0)
        exit(0);
    glutInit( &argc, argv );
    glutInitDisplayMode( 0x0000 | 0x0010 | 0x0002 );
    glutInitWindowSize(500, 500);
    window = glutCreateWindow( "Fire and Smoke" );
    glutIdleFunc( play );
    glutDisplayFunc( display );
    glutKeyboardFunc( key );
    glutReshapeFunc( reshape );
    printOglError("ogl2particle.c", 253);
    if ( !isExtensionSupported( "GL_ARB_shader_objects" ) ||
         !isExtensionSupported( "GL_ARB_fragment_shader" ) ||
         !isExtensionSupported( "GL_ARB_vertex_shader" ) ||
         !isExtensionSupported( "GL_ARB_shading_language_100" ) )
    {
        printf("OpenGL Shading Language extensions not available\n" );
        return 1;
    }
    if( error )
    {
        printf( "ERROR from wglGetProcAddress\n" );
    }
    createPoints( numParticles );
    glDepthFunc( 0x0201 );
    glEnable( 0x0B71 );
 glClearColor( 0.0f, 0.67f, 0.94f, 1.0f );
 ParticleTime = 0.0f;
    readShaderSource( "smoke", &VertexShaderSource, &FragmentShaderSource );
    success = installParticleShaders( VertexShaderSource, FragmentShaderSource );
    if ( success )
 {
  glutMainLoop();
 }
 else
 {
  printf( "Error installing particle shaders" );
  scanf( "%d", ParticleTime );
 }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int success = 0;
    char *VertexShaderSource; char *FragmentShaderSource;
    int error = 0;
    if (Args(argc, argv) == 0)
        exit(0);
    glutInit( &argc, argv );
    glutInitDisplayMode( 0x0000 | 0x0010 | 0x0002 );
    glutInitWindowSize(500, 500);
    window = glutCreateWindow( "Fire and Smoke" );
    glutIdleFunc( play );
    glutDisplayFunc( display );
    glutKeyboardFunc( key );
    glutReshapeFunc( reshape );
    printOglError("ogl2particle.c", 253);
    if ( !isExtensionSupported( "GL_ARB_shader_objects" ) ||
         !isExtensionSupported( "GL_ARB_fragment_shader" ) ||
         !isExtensionSupported( "GL_ARB_vertex_shader" ) ||
         !isExtensionSupported( "GL_ARB_shading_language_100" ) )
    {
        printf("OpenGL Shading Language extensions not available\n" );
        return 1;
    }
    if( error )
    {
        printf( "ERROR from wglGetProcAddress\n" );
    }
    createPoints( numParticles );
    glDepthFunc( 0x0201 );
    glEnable( 0x0B71 );
 glClearColor( 0.0f, 0.67f, 0.94f, 1.0f );
 ParticleTime = 0.0f;
    readShaderSource( "smoke", &VertexShaderSource, &FragmentShaderSource );
    success = installParticleShaders( VertexShaderSource, FragmentShaderSource );
    if ( success )
 {
  glutMainLoop();
 }
 else
 {
  printf( "Error installing particle shaders" );
  scanf( "%d", ParticleTime );
 }
    return 0;
}

variable_types: success int

variable_types:
VertexShaderSource
char *

variable_types:
FragmentShaderSource
char *

variable_types: error int


getUniLoc

decompiled_code:
__int64 __fastcall getUniLoc(__int64 a1, const char *a2)
{
unsigned int v2; // ebx

v2 = glGetUniformLocationARB();
if ( v2 == -1 )
printf("No such uniform named \"%s\"\n", a2);
printOglError("shader.c", 62LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
unsigned int v2; // ebx

v2 = glGetUniformLocationARB();
if ( v2 == -1 )
printf("No such uniform named \"%s\"\n", a2);
printOglError("shader.c", 62LL);
return v2;
}

original_code:
GLint getUniLoc(GLhandleARB program, const GLcharARB *name)
{
    GLint loc;
    loc = glGetUniformLocationARB(program, name);
    if (loc == -1)
        printf("No such uniform named \"%s\"\n", name);
    printOglError("shader.c", 62);
    return loc;
}

canonical_original_code:
int getUniLoc(unsigned int program, char *name)
{
    int loc;
    loc = glGetUniformLocationARB(program, name);
    if (loc == -1)
        printf("No such uniform named \"%s\"\n", name);
    printOglError("shader.c", 62);
    return loc;
}

variable_types:
program
unsigned int

variable_types:
name
char *

variable_types: loc int


printInfoLog

decompiled_code:
__int64 __fastcall printInfoLog(unsigned int a1)
{
unsigned int v1; // er12
char *v2; // rax
char *v3; // rbp
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
printOglError("shader.c", 75LL);
glGetObjectParameterivARB(a1, 35716LL, v6);
printOglError("shader.c", 79LL);
v1 = v6[0];
if ( v6[0] > 0 )
{
v2 = (char *)malloc(v6[0]);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
glGetInfoLogARB(a1, v1, &v5, v2);
printf("InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 93LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned int v1; // er12
char *v2; // rax
char *v3; // rbp
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
printOglError("shader.c", 75LL);
glGetObjectParameterivARB(a1, 35716LL, v6);
printOglError("shader.c", 79LL);
v1 = v6[0];
if ( v6[0] > 0 )
{
v2 = (char *)malloc(v6[0]);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
glGetInfoLogARB(a1, v1, &v5, v2);
printf("InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 93LL);
}

original_code:
void printInfoLog(GLhandleARB obj)
{
    int infologLength = 0;
    int charsWritten = 0;
    GLcharARB *infoLog;
    printOglError("shader.c", 75);
    glGetObjectParameterivARB(obj, 0x8B84,
                                         &infologLength);
    printOglError("shader.c", 79);
    if (infologLength > 0)
    {
        infoLog = (GLcharARB*)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
        printf("InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 93);
}

canonical_original_code:
void printInfoLog(unsigned int obj)
{
    int infologLength = 0;
    int charsWritten = 0;
    char *infoLog;
    printOglError("shader.c", 75);
    glGetObjectParameterivARB(obj, 0x8B84,
                                         &infologLength);
    printOglError("shader.c", 79);
    if (infologLength > 0)
    {
        infoLog = (char *)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
        printf("InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 93);
}

variable_types:
obj
unsigned int

variable_types: infologLength int

variable_types: charsWritten int

variable_types:
infoLog
char *


shaderSize

decompiled_code:
__int64 __fastcall shaderSize(char *src, int a2)
{
int v2; // eax
int v3; // ebx
unsigned int v4; // ebp
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

strcpy(v6, src);
if ( a2 )
{
if ( a2 != 1 )
_assert_fail("0", "shader.c", 0x7Bu, "shaderSize");
strcat(v6, ".frag");
}
else
{
strcat(v6, ".vert");
}
v2 = open(v6, 0);
v3 = v2;
if ( v2 == -1 )
return (unsigned int)-1;
v4 = lseek(v2, 0LL, 2);
close(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2)
{
int v2; // eax
int v3; // ebx
unsigned int v4; // ebp
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

strcpy(v6, src);
if ( a2 )
{
if ( a2 != 1 )
_assert_fail("0", "shader.c", 0x7Bu, "shaderSize");
strcat(v6, ".frag");
}
else
{
strcat(v6, ".vert");
}
v2 = open(v6, 0);
v3 = v2;
if ( v2 == -1 )
return (unsigned int)-1;
v4 = lseek(v2, 0LL, 2);
close(v3);
return v4;
}

original_code:
int shaderSize(char *fileName, EShaderType shaderType)
{
    int shader;
    char name[100];
    int count;
    strcpy(name, fileName);
    switch (shaderType)
    {
        case EVertexShader:
            strcat(name, ".vert");
            break;
        case EFragmentShader:
            strcat(name, ".frag");
            break;
        default:
            ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "shader.c", 123, __extension__ __PRETTY_FUNCTION__); }));
            break;
    }
    shader = open(name, 00);
    if (shader == -1)
        return -1;
    count = lseek(shader, 0, 2);
    close(shader);
    return count;
}

canonical_original_code:
int shaderSize(char *fileName, enum EShaderType shaderType)
{
    int shader;
    char name[100];
    int count;
    strcpy(name, fileName);
    switch (shaderType)
    {
        case EVertexShader:
            strcat(name, ".vert");
            break;
        case EFragmentShader:
            strcat(name, ".frag");
            break;
        default:
            ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "shader.c", 123, __extension__ __PRETTY_FUNCTION__); }));
            break;
    }
    shader = open(name, 00);
    if (shader == -1)
        return -1;
    count = lseek(shader, 0, 2);
    close(shader);
    return count;
}

variable_types:
fileName
char *

variable_types: enum EShaderType { EVertexShader=0, EFragmentShader=1 }

variable_types: shader int

variable_types:
name
char [100]

variable_types: count int


readShaderSource

decompiled_code:
__int64 __fastcall readShaderSource(char *src, void **a2, void **a3)
{
int v4; // ebp
int v5; // eax
int v6; // er12
unsigned int v7; // ebp

v4 = shaderSize(src, 0);
v5 = shaderSize(src, 1);
if ( v4 == -1 || (v6 = v5, v5 == -1) )
{
printf("Cannot determine size of the shader %s\n", src);
v7 = 0;
}
else
{
*a2 = malloc(v4);
*a3 = malloc(v6);
v7 = readShader(src, 0, *a2, v4);
if ( v7 )
{
v7 = readShader(src, 1, *a3, v6);
if ( v7 )
v7 = 1;
else
printf("Cannot read the file %s.frag\n", src);
}
else
{
printf("Cannot read the file %s.vert\n", src);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, void **a2, void **a3)
{
int v4; // ebp
int v5; // eax
int v6; // er12
unsigned int v7; // ebp

v4 = func2(src, 0);
v5 = func2(src, 1);
if ( v4 == -1 || (v6 = v5, v5 == -1) )
{
printf("Cannot determine size of the shader %s\n", src);
v7 = 0;
}
else
{
*a2 = malloc(v4);
*a3 = malloc(v6);
v7 = func3(src, 0, *a2, v4);
if ( v7 )
{
v7 = func3(src, 1, *a3, v6);
if ( v7 )
v7 = 1;
else
printf("Cannot read the file %s.frag\n", src);
}
else
{
printf("Cannot read the file %s.vert\n", src);
}
}
return v7;
}

original_code:
int readShaderSource(char *fileName, GLcharARB **vertexShader, GLcharARB **fragmentShader)
{
    int vSize, fSize;
    vSize = shaderSize(fileName, EVertexShader);
    fSize = shaderSize(fileName, EFragmentShader);
    if ((vSize == -1) || (fSize == -1))
    {
        printf("Cannot determine size of the shader %s\n", fileName);
        return 0;
    }
    *vertexShader = (GLcharARB *) malloc(vSize);
    *fragmentShader = (GLcharARB *) malloc(fSize);
    if (!readShader(fileName, EVertexShader, *vertexShader, vSize))
    {
        printf("Cannot read the file %s.vert\n", fileName);
        return 0;
    }
    if (!readShader(fileName, EFragmentShader, *fragmentShader, fSize)) {
        printf("Cannot read the file %s.frag\n", fileName);
        return 0;
    }
    return 1;
}

canonical_original_code:
int readShaderSource(char *fileName, char **vertexShader, char **fragmentShader)
{
    int vSize; int fSize;
    vSize = shaderSize(fileName, EVertexShader);
    fSize = shaderSize(fileName, EFragmentShader);
    if ((vSize == -1) || (fSize == -1))
    {
        printf("Cannot determine size of the shader %s\n", fileName);
        return 0;
    }
    *vertexShader = (char *) malloc(vSize);
    *fragmentShader = (char *) malloc(fSize);
    if (!readShader(fileName, EVertexShader, *vertexShader, vSize))
    {
        printf("Cannot read the file %s.vert\n", fileName);
        return 0;
    }
    if (!readShader(fileName, EFragmentShader, *fragmentShader, fSize)) {
        printf("Cannot read the file %s.frag\n", fileName);
        return 0;
    }
    return 1;
}

variable_types:
vertexShader
char **

variable_types:
fragmentShader
char **

variable_types: vSize int

variable_types: fSize int


installParticleShaders

decompiled_code:
__int64 __fastcall installParticleShaders(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6; // [rsp+14h] [rbp-14h] BYREF
unsigned int v7; // [rsp+18h] [rbp-10h] BYREF
unsigned int v8[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = a1;
v4 = a2;
VertexShaderObject = glCreateShaderObjectARB(35633LL);
FragmentShaderObject = glCreateShaderObjectARB(35632LL);
glShaderSourceARB((unsigned int)VertexShaderObject, 1LL, &v5, 0LL);
glShaderSourceARB((unsigned int)FragmentShaderObject, 1LL, &v4, 0LL);
glCompileShaderARB((unsigned int)VertexShaderObject);
printOglError("shader.c", 251LL);
glGetObjectParameterivARB((unsigned int)VertexShaderObject, 35713LL, v8);
printInfoLog(VertexShaderObject);
glCompileShaderARB((unsigned int)FragmentShaderObject);
printOglError("shader.c", 260LL);
glGetObjectParameterivARB((unsigned int)FragmentShaderObject, 35713LL, &v7);
printInfoLog(FragmentShaderObject);
result = v8[0];
if ( v8[0] )
{
result = v7;
if ( v7 )
{
ProgramObject = glCreateProgramObjectARB();
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)VertexShaderObject);
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)FragmentShaderObject);
glBindAttribLocationARB((unsigned int)ProgramObject, 6LL, "velocity");
glBindAttribLocationARB((unsigned int)ProgramObject, 4LL, "startTime");
glBindAttribLocationARB((unsigned int)ProgramObject, 5LL, "random");
glLinkProgramARB((unsigned int)ProgramObject);
printOglError("shader.c", 283LL);
glGetObjectParameterivARB((unsigned int)ProgramObject, 35714LL, &v6);
printInfoLog(ProgramObject);
result = v6;
if ( v6 )
{
glUseProgramObjectARB((unsigned int)ProgramObject);
v3 = getUniLoc((unsigned int)ProgramObject, "currentTime");
glUniform1fARB(v3, -5.0);
printOglError("shader.c", 298LL);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6; // [rsp+14h] [rbp-14h] BYREF
unsigned int v7; // [rsp+18h] [rbp-10h] BYREF
unsigned int v8[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = a1;
v4 = a2;
VertexShaderObject = glCreateShaderObjectARB(35633LL);
FragmentShaderObject = glCreateShaderObjectARB(35632LL);
glShaderSourceARB((unsigned int)VertexShaderObject, 1LL, &v5, 0LL);
glShaderSourceARB((unsigned int)FragmentShaderObject, 1LL, &v4, 0LL);
glCompileShaderARB((unsigned int)VertexShaderObject);
printOglError("shader.c", 251LL);
glGetObjectParameterivARB((unsigned int)VertexShaderObject, 35713LL, v8);
func1(VertexShaderObject);
glCompileShaderARB((unsigned int)FragmentShaderObject);
printOglError("shader.c", 260LL);
glGetObjectParameterivARB((unsigned int)FragmentShaderObject, 35713LL, &v7);
func1(FragmentShaderObject);
result = v8[0];
if ( v8[0] )
{
result = v7;
if ( v7 )
{
ProgramObject = glCreateProgramObjectARB();
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)VertexShaderObject);
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)FragmentShaderObject);
glBindAttribLocationARB((unsigned int)ProgramObject, 6LL, "velocity");
glBindAttribLocationARB((unsigned int)ProgramObject, 4LL, "startTime");
glBindAttribLocationARB((unsigned int)ProgramObject, 5LL, "random");
glLinkProgramARB((unsigned int)ProgramObject);
printOglError("shader.c", 283LL);
glGetObjectParameterivARB((unsigned int)ProgramObject, 35714LL, &v6);
func1(ProgramObject);
result = v6;
if ( v6 )
{
glUseProgramObjectARB((unsigned int)ProgramObject);
v3 = func0((unsigned int)ProgramObject, "currentTime");
glUniform1fARB(v3, -5.0);
printOglError("shader.c", 298LL);
result = 1LL;
}
}
}
return result;
}

original_code:
int installParticleShaders(GLcharARB *particleVertex,
                           GLcharARB *particleFragment)
{
    GLint vertCompiled, fragCompiled;
    GLint linked;
    VertexShaderObject = glCreateShaderObjectARB(0x8B31);
    FragmentShaderObject = glCreateShaderObjectARB(0x8B30);
    glShaderSourceARB(VertexShaderObject, 1, &particleVertex, ((void *)0));
    glShaderSourceARB(FragmentShaderObject, 1, &particleFragment, ((void *)0));
    glCompileShaderARB(VertexShaderObject);
    printOglError("shader.c", 251);
    glGetObjectParameterivARB(VertexShaderObject,
                0x8B81, &vertCompiled);
    printInfoLog(VertexShaderObject);
    glCompileShaderARB(FragmentShaderObject);
    printOglError("shader.c", 260);
    glGetObjectParameterivARB(FragmentShaderObject,
                0x8B81, &fragCompiled);
    printInfoLog(FragmentShaderObject);
    if (!vertCompiled || !fragCompiled)
        return 0;
    ProgramObject = glCreateProgramObjectARB();
    glAttachObjectARB(ProgramObject, VertexShaderObject);
    glAttachObjectARB(ProgramObject, FragmentShaderObject);
    glBindAttribLocationARB( ProgramObject, 6, "velocity" );
    glBindAttribLocationARB( ProgramObject, 4, "startTime" );
 glBindAttribLocationARB( ProgramObject, 5, "random" );
    glLinkProgramARB(ProgramObject);
    printOglError("shader.c", 283);
    glGetObjectParameterivARB(ProgramObject,
                0x8B82, &linked);
    printInfoLog(ProgramObject);
    if (!linked)
        return 0;
    glUseProgramObjectARB(ProgramObject);
    glUniform1fARB(getUniLoc(ProgramObject, "currentTime"), -5.0);
    printOglError("shader.c", 298);
    return 1;
}

canonical_original_code:
int installParticleShaders(char *particleVertex, char *particleFragment)
{
    int vertCompiled; int fragCompiled;
    int linked;
    VertexShaderObject = glCreateShaderObjectARB(0x8B31);
    FragmentShaderObject = glCreateShaderObjectARB(0x8B30);
    glShaderSourceARB(VertexShaderObject, 1, &particleVertex, ((void *)0));
    glShaderSourceARB(FragmentShaderObject, 1, &particleFragment, ((void *)0));
    glCompileShaderARB(VertexShaderObject);
    printOglError("shader.c", 251);
    glGetObjectParameterivARB(VertexShaderObject,
                0x8B81, &vertCompiled);
    printInfoLog(VertexShaderObject);
    glCompileShaderARB(FragmentShaderObject);
    printOglError("shader.c", 260);
    glGetObjectParameterivARB(FragmentShaderObject,
                0x8B81, &fragCompiled);
    printInfoLog(FragmentShaderObject);
    if (!vertCompiled || !fragCompiled)
        return 0;
    ProgramObject = glCreateProgramObjectARB();
    glAttachObjectARB(ProgramObject, VertexShaderObject);
    glAttachObjectARB(ProgramObject, FragmentShaderObject);
    glBindAttribLocationARB( ProgramObject, 6, "velocity" );
    glBindAttribLocationARB( ProgramObject, 4, "startTime" );
 glBindAttribLocationARB( ProgramObject, 5, "random" );
    glLinkProgramARB(ProgramObject);
    printOglError("shader.c", 283);
    glGetObjectParameterivARB(ProgramObject,
                0x8B82, &linked);
    printInfoLog(ProgramObject);
    if (!linked)
        return 0;
    glUseProgramObjectARB(ProgramObject);
    glUniform1fARB(getUniLoc(ProgramObject, "currentTime"), -5.0);
    printOglError("shader.c", 298);
    return 1;
}

variable_types:
particleVertex
char *

variable_types:
particleFragment
char *

variable_types: vertCompiled int

variable_types: fragCompiled int

variable_types: linked int


myrandom

decompiled_code:
float __fastcall myrandom(float a1, float a2)
{
return (float)((float)((float)rand() * 4.6566129e-10) * (float)(a2 - a1)) + a1;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return (float)((float)((float)rand() * 4.6566129e-10) * (float)(a2 - a1)) + a1;
}

original_code:
float myrandom( float low, float high )
{
 float range = high - low;
 float multiplier = ( float ) rand() / 2147483647;
 return range * multiplier + low;
}

canonical_original_code:
float myrandom(float low, float high)
{
 float range = high - low;
 float multiplier = ( float ) rand() / 2147483647;
 return range * multiplier + low;
}

variable_types: low float

variable_types: high float

variable_types: range float

variable_types: multiplier float

return_type: float


fireRed

decompiled_code:
float fireRed()
{
return 1.0 - myrandom(0.0, 0.2);
}

original_code:
float fireRed()
{
 return 1.0 - myrandom( 0.0f, 0.2f );
}


fireGreen

decompiled_code:
float fireGreen()
{
return myrandom(0.0, 0.5);
}

canonical_decompiled_code:
float func2()
{
return func0(0.0, 0.5);
}

original_code:
float fireGreen()
{
 return myrandom( 0.0f, 0.5f );
}


fireBlue

decompiled_code:
double fireBlue()
{
return 0.0;
}

canonical_decompiled_code:
double func3()
{
return 0.0;
}

original_code:
float fireBlue()
{
 return 0.0f;
}

canonical_original_code:
float fireBlue()
{
 return 0.0f;
}


fillRandom

decompiled_code:
void __fastcall fillRandom(int a1)
{
float *v1; // rbx
__int64 v2; // rbp

if ( !myrandoms )
myrandoms = (__int64)malloc(12LL * a1);
v1 = (float *)myrandoms;
if ( 3 * a1 > 0 )
{
v2 = myrandoms + 4LL * (unsigned int)(3 * a1);
do
*v1++ = myrandom(-1.0, 1.0);
while ( v1 != (float *)v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
float *v1; // rbx
__int64 v2; // rbp

if ( !myrandoms )
myrandoms = (__int64)malloc(12LL * a1);
v1 = (float *)myrandoms;
if ( 3 * a1 > 0 )
{
v2 = myrandoms + 4LL * (unsigned int)(3 * a1);
do
*v1++ = func0(-1.0, 1.0);
while ( v1 != (float *)v2 );
}
}

original_code:
void fillRandom( int numPoints )
{
 GLfloat* myrandomPointer;
 int counter;
 if ( myrandoms == ((void *)0) )
 {
  myrandoms = malloc( numPoints * 3 * sizeof( float ) );
 }
 myrandomPointer = myrandoms;
 for ( counter = 0; counter < numPoints * 3; counter++ )
 {
  *myrandomPointer = myrandom( -1.0f, 1.0f );
  myrandomPointer++;
 }
}

canonical_original_code:
void fillRandom(int numPoints)
{
 float *myrandomPointer;
 int counter;
 if ( myrandoms == ((void *)0) )
 {
  myrandoms = malloc( numPoints * 3 * sizeof( float ) );
 }
 myrandomPointer = myrandoms;
 for ( counter = 0; counter < numPoints * 3; counter++ )
 {
  *myrandomPointer = myrandom( -1.0f, 1.0f );
  myrandomPointer++;
 }
}

variable_types: numPoints int

variable_types:
myrandomPointer
float *

variable_types: counter int


createPoints

decompiled_code:
void __fastcall createPoints(int a1)
{
size_t v1; // r12
float *v2; // rbx
float *v3; // rbp
float *v4; // r12
float *v5; // r13
float *v6; // r14
float v7; // xmm0_4
float v8; // xmm0_4
float v9; // xmm0_4
double v10; // xmm0_8
float v11; // [rsp+8h] [rbp-50h]
double v12; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+10h] [rbp-48h] BYREF
double sinx[8]; // [rsp+18h] [rbp-40h] BYREF

if ( vertices )
free(vertices);
v1 = 12LL * a1;
v2 = (float *)malloc(v1);
vertices = v2;
v3 = (float *)malloc(v1);
colors = (__int64)v3;
v4 = (float *)malloc(v1);
velocities = (__int64)v4;
v5 = (float *)malloc(4LL * a1);
startTimes = (__int64)v5;
if ( a1 > 0 )
{
v6 = &v5[a1];
do
{
v11 = myrandom(0.0, 1.0);
v7 = myrandom(0.0, 360.0);
*v2 = 0.0;
v12 = (float)(v11 * 0.40000001);
sincos(v7, sinx, &cosx);
v8 = v12 * sinx[0];
v2[1] = v8;
v9 = v12 * cosx;
v2[2] = v9;
v2 += 3;
*v3 = fireRed();
v3[1] = fireGreen();
v10 = fireBlue();
v3[2] = *(float *)&v10;
v3 += 3;
*v4 = myrandom(2.0, 10.0);
v4[1] = myrandom(0.5, 1.0);
v4[2] = myrandom(0.5, 1.0);
v4 += 3;
*v5++ = myrandom(0.0, 10.0);
}
while ( v5 != v6 );
}
fillRandom(a1);
}

original_code:
void createPoints( int numPoints )
{
 GLfloat* vertexPointer;
 GLfloat* colorPointer;
 GLfloat* velocityPointer;
 GLfloat* startTimePointer;
 float newRadius;
 float angle;
 GLint counter;
 if ( vertices != ((void *)0) )
 {
  free( vertices );
 }
 vertices = malloc( numPoints * 3 * sizeof( float ) );
 colors = malloc( numPoints * 3 * sizeof( float ) );
 velocities = malloc( numPoints * 3 * sizeof( float ) );
 startTimes = malloc( numPoints * sizeof( float ) );
 vertexPointer = vertices;
 colorPointer = colors;
 velocityPointer = velocities;
 startTimePointer = startTimes;
 for ( counter = 0; counter < numPoints; counter++ )
 {
  newRadius = myrandom( 0.0f, 1.0f ) * emitterRadius;
  angle = myrandom( 0.0f, 360.0f );
  *vertexPointer = 0.0f;
  *( vertexPointer + 1 ) = newRadius * sin( angle );
  *( vertexPointer + 2 ) = newRadius * cos( angle );
  vertexPointer += 3;
  *colorPointer = fireRed();
  *( colorPointer + 1 ) = fireGreen();
  *( colorPointer + 2 ) = fireBlue();
  colorPointer += 3;
  *velocityPointer = myrandom( 2.0f, 10.0f );
  *( velocityPointer + 1 ) = myrandom( 0.5f, 1.0f );
  *( velocityPointer + 2 ) = myrandom( 0.5f, 1.0f );
  velocityPointer += 3;
  *startTimePointer = myrandom( 0.0f, 10.0f );
  startTimePointer++;
 }
 fillRandom( numPoints );
}

canonical_original_code:
void createPoints(int numPoints)
{
 float *vertexPointer;
 float *colorPointer;
 float *velocityPointer;
 float *startTimePointer;
 float newRadius;
 float angle;
 int counter;
 if ( vertices != ((void *)0) )
 {
  free( vertices );
 }
 vertices = malloc( numPoints * 3 * sizeof( float ) );
 colors = malloc( numPoints * 3 * sizeof( float ) );
 velocities = malloc( numPoints * 3 * sizeof( float ) );
 startTimes = malloc( numPoints * sizeof( float ) );
 vertexPointer = vertices;
 colorPointer = colors;
 velocityPointer = velocities;
 startTimePointer = startTimes;
 for ( counter = 0; counter < numPoints; counter++ )
 {
  newRadius = myrandom( 0.0f, 1.0f ) * emitterRadius;
  angle = myrandom( 0.0f, 360.0f );
  *vertexPointer = 0.0f;
  *( vertexPointer + 1 ) = newRadius * sin( angle );
  *( vertexPointer + 2 ) = newRadius * cos( angle );
  vertexPointer += 3;
  *colorPointer = fireRed();
  *( colorPointer + 1 ) = fireGreen();
  *( colorPointer + 2 ) = fireBlue();
  colorPointer += 3;
  *velocityPointer = myrandom( 2.0f, 10.0f );
  *( velocityPointer + 1 ) = myrandom( 0.5f, 1.0f );
  *( velocityPointer + 2 ) = myrandom( 0.5f, 1.0f );
  velocityPointer += 3;
  *startTimePointer = myrandom( 0.0f, 10.0f );
  startTimePointer++;
 }
 fillRandom( numPoints );
}

variable_types:
vertexPointer
float *

variable_types:
colorPointer
float *

variable_types:
velocityPointer
float *

variable_types:
startTimePointer
float *

variable_types: newRadius float

variable_types: angle float


drawPoints

decompiled_code:
__int64 drawPoints()
{
fillRandom(50000);
glPointSize(2.0);
glVertexPointer(3LL, 5126LL, 0LL, vertices);
glColorPointer(3LL, 5126LL, 0LL, colors);
glVertexAttribPointerARB(6LL, 3LL, 5126LL, 0LL, 0LL, velocities);
glVertexAttribPointerARB(4LL, 1LL, 5126LL, 0LL, 0LL, startTimes);
glVertexAttribPointerARB(5LL, 3LL, 5126LL, 0LL, 0LL, myrandoms);
glEnableClientState(32884LL);
glEnableClientState(32886LL);
glEnableVertexAttribArrayARB(6LL);
glEnableVertexAttribArrayARB(4LL);
glEnableVertexAttribArrayARB(5LL);
glDrawArrays(0LL, 0LL, 50000LL);
glDisableClientState(32884LL);
glDisableClientState(32886LL);
glDisableVertexAttribArrayARB(6LL);
glDisableVertexAttribArrayARB(4LL);
return glDisableVertexAttribArrayARB(5LL);
}

canonical_decompiled_code:
__int64 func6()
{
func4(50000);
glPointSize(2.0);
glVertexPointer(3LL, 5126LL, 0LL, vertices);
glColorPointer(3LL, 5126LL, 0LL, colors);
glVertexAttribPointerARB(6LL, 3LL, 5126LL, 0LL, 0LL, velocities);
glVertexAttribPointerARB(4LL, 1LL, 5126LL, 0LL, 0LL, startTimes);
glVertexAttribPointerARB(5LL, 3LL, 5126LL, 0LL, 0LL, myrandoms);
glEnableClientState(32884LL);
glEnableClientState(32886LL);
glEnableVertexAttribArrayARB(6LL);
glEnableVertexAttribArrayARB(4LL);
glEnableVertexAttribArrayARB(5LL);
glDrawArrays(0LL, 0LL, 50000LL);
glDisableClientState(32884LL);
glDisableClientState(32886LL);
glDisableVertexAttribArrayARB(6LL);
glDisableVertexAttribArrayARB(4LL);
return glDisableVertexAttribArrayARB(5LL);
}

original_code:
void drawPoints()
{
 fillRandom( numParticles );
 glPointSize( 2.0 );
 glVertexPointer( 3, 0x1406, 0, vertices );
 glColorPointer( 3, 0x1406, 0, colors );
 glVertexAttribPointerARB( 6, 3, 0x1406, 0, 0, velocities );
 glVertexAttribPointerARB( 4, 1, 0x1406, 0, 0, startTimes );
 glVertexAttribPointerARB( 5, 3, 0x1406, 0, 0, myrandoms );
 glEnableClientState( 0x8074 );
 glEnableClientState( 0x8076 );
 glEnableVertexAttribArrayARB( 6 );
 glEnableVertexAttribArrayARB( 4 );
 glEnableVertexAttribArrayARB( 5 );
 glDrawArrays( 0x0000, 0, numParticles );
 glDisableClientState( 0x8074 );
 glDisableClientState( 0x8076 );
 glDisableVertexAttribArrayARB( 6 );
 glDisableVertexAttribArrayARB( 4 );
 glDisableVertexAttribArrayARB( 5 );
}


decompiled_code:
__int64 __fastcall md_get(const char *a1, void *a2)
{
return tt_get(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, void *a2)
{
return func1(a1, a2, 1);
}

original_code:
u32 md_get(u8 * path,u8 *md)
{
 return tt_get(path,md,META_DATA);
}

canonical_original_code:
unsigned int md_get(unsigned char *path, unsigned char *md)
{
 return tt_get(path,md,META_DATA);
}

variable_types:
path
unsigned char *

variable_types:
md
unsigned char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall md_out(const char *a1)
{
return tt_out(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
return func2(a1, 1);
}

original_code:
u32 md_out(u8 *path)
{
 return tt_out(path,META_DATA);
}

canonical_original_code:
unsigned int md_out(unsigned char *path)
{
 return tt_out(path,META_DATA);
}


decompiled_code:
__int64 __fastcall md_put(const char *a1, __int64 a2)
{
return tt_put(a1, a2, 0xC20u, 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
return func3(a1, a2, 0xC20u, 1);
}

original_code:
u32 md_put(u8 *path,u8 *md)
{
 return tt_put(path,md,sizeof(Meta_Data),META_DATA);
}

canonical_original_code:
unsigned int md_put(unsigned char *path, unsigned char *md)
{
 return tt_put(path,md,sizeof(Meta_Data),META_DATA);
}


decompiled_code:
__int64 __fastcall ion_get(const char *a1, void *a2)
{
return tt_get(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, void *a2)
{
return func1(a1, a2, 2);
}

original_code:
u32 ion_get(u8 * path,u8 *ion)
{
 return tt_get(path,ion,IO_NODE);
}

canonical_original_code:
unsigned int ion_get(unsigned char *path, unsigned char *ion)
{
 return tt_get(path,ion,IO_NODE);
}

variable_types:
ion
unsigned char *


decompiled_code:
__int64 __fastcall ion_out(const char *a1)
{
return tt_out(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
return func2(a1, 2);
}

original_code:
u32 ion_out(u8 *path)
{
 return tt_out(path,IO_NODE);
}

canonical_original_code:
unsigned int ion_out(unsigned char *path)
{
 return tt_out(path,IO_NODE);
}


decompiled_code:
__int64 __fastcall ion_put(const char *a1, __int64 a2)
{
return tt_put(a1, a2, 0x220u, 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
return func3(a1, a2, 0x220u, 2);
}

original_code:
u32 ion_put(u8 *path,u8 *ion)
{
 return tt_put(path,ion,sizeof(IO_Node),IO_NODE);
}

canonical_original_code:
unsigned int ion_put(unsigned char *path, unsigned char *ion)
{
 return tt_put(path,ion,sizeof(IO_Node),IO_NODE);
}


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

switch ( a1 )
{
case 1:
result = 11211LL;
break;
case 2:
result = 11212LL;
break;
case 3:
result = 11213LL;
break;
case 4:
result = 11214LL;
break;
case 5:
result = 11215LL;
break;
default:
fwrite("UNRECOGNIZED VALUE TYPE!\n", 1uLL, 0x19uLL, stderr);
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = 11211LL;
break;
case 2:
result = 11212LL;
break;
case 3:
result = 11213LL;
break;
case 4:
result = 11214LL;
break;
case 5:
result = 11215LL;
break;
default:
fwrite("UNRECOGNIZED VALUE TYPE!\n", 1uLL, 0x19uLL, stderr);
result = 0LL;
break;
}
return result;
}

original_code:
u32 get_db_port(value_t vt)
{
 u32 db_port;
 switch(vt){
  case META_DATA:
   db_port = 11211;
   break;
  case IO_NODE:
   db_port = 11212;
   break;
  case FILE_NODE:
   db_port = 11213;
   break;
  case SWAP_NODE:
   db_port = 11214;
   break;
  case IO_DATA:
   db_port = 11215;
   break;
  default:
   fprintf(stderr,"UNRECOGNIZED VALUE TYPE!\n");
   db_port = 0;
   break;
 }
 return db_port;
}

canonical_original_code:
unsigned int get_db_port(enum value_t vt)
{
 unsigned int db_port;
 switch(vt){
  case META_DATA:
   db_port = 11211;
   break;
  case IO_NODE:
   db_port = 11212;
   break;
  case FILE_NODE:
   db_port = 11213;
   break;
  case SWAP_NODE:
   db_port = 11214;
   break;
  case IO_DATA:
   db_port = 11215;
   break;
  default:
   fprintf(stderr,"UNRECOGNIZED VALUE TYPE!\n");
   db_port = 0;
   break;
 }
 return db_port;
}

variable_types: enum value_t { META_DATA=1, IO_NODE=2, FILE_NODE=3, SWAP_NODE=4, IO_DATA=5 }


decompiled_code:
__int64 __fastcall tt_get(const char *a1, void *a2, int a3)
{
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // ebp
void *v11; // rbp
unsigned int v12; // eax
const char *v13; // rax
size_t n[5]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = strlen(a1);
v5 = tcrdbnew();
v6 = (unsigned int)get_db_port(a3);
printf("db_port -- %d\n", v6);
if ( (unsigned __int8)tcrdbopen(v5, "192.168.0.18", (unsigned int)v6) )
{
v11 = (void *)tcrdbget(v5, a1, v4, n);
if ( v11 )
{
printf("(key=%s) tt_get success!\n", a1);
printf("%d bytes read\n", LODWORD(n[0]));
memcpy(a2, v11, LODWORD(n[0]));
free(v11);
v9 = 0;
}
else
{
v12 = tcrdbecode(v5);
v13 = (const char *)tcrdberrmsg(v12);
fprintf(stderr, "(key=%s) tt_get error:%s\n", a1, v13);
v9 = 2;
}
}
else
{
v7 = tcrdbecode(v5);
v8 = (const char *)tcrdberrmsg(v7);
fprintf(stderr, "tt_get:open %d error -- %s\n", (unsigned int)v6, v8);
v9 = 1;
}
tcrdbdel(v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, void *a2, int a3)
{
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // ebp
void *v11; // rbp
unsigned int v12; // eax
const char *v13; // rax
size_t n[5]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = strlen(a1);
v5 = tcrdbnew();
v6 = (unsigned int)func0(a3);
printf("db_port -- %d\n", v6);
if ( (unsigned __int8)tcrdbopen(v5, "192.168.0.18", (unsigned int)v6) )
{
v11 = (void *)tcrdbget(v5, a1, v4, n);
if ( v11 )
{
printf("(key=%s) tt_get success!\n", a1);
printf("%d bytes read\n", LODWORD(n[0]));
memcpy(a2, v11, LODWORD(n[0]));
free(v11);
v9 = 0;
}
else
{
v12 = tcrdbecode(v5);
v13 = (const char *)tcrdberrmsg(v12);
fprintf(stderr, "(key=%s) tt_get error:%s\n", a1, v13);
v9 = 2;
}
}
else
{
v7 = tcrdbecode(v5);
v8 = (const char *)tcrdberrmsg(v7);
fprintf(stderr, "tt_get:open %d error -- %s\n", (unsigned int)v6, v8);
v9 = 1;
}
tcrdbdel(v5);
return v9;
}

original_code:
u32 tt_get(u8 *key,u8 *zv,value_t vt)
{
 u32 ecode;
 u32 nv;
 u32 rt = 0;
 u32 nk = strlen(key);
 u8 * value;
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if((value = tcrdbget(rdb,key,nk,&nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
      printf("(key=%s) tt_get success!\n",key);
   printf("%d bytes read\n",nv);
   memcpy(zv,value,nv);
   free(value);
     }
 }
 tcrdbdel(rdb);
 return rt;
}

canonical_original_code:
unsigned int tt_get(unsigned char *key, unsigned char *zv, enum value_t vt)
{
 unsigned int ecode;
 unsigned int nv;
 unsigned int rt = 0;
 unsigned int nk = strlen(key);
 unsigned char *value;
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if((value = tcrdbget(rdb,key,nk,&nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
      printf("(key=%s) tt_get success!\n",key);
   printf("%d bytes read\n",nv);
   memcpy(zv,value,nv);
   free(value);
     }
 }
 tcrdbdel(rdb);
 return rt;
}

variable_types:
key
unsigned char *

variable_types:
zv
unsigned char *

variable_types:
ecode
unsigned int

variable_types:
nv
unsigned int

variable_types:
rt
unsigned int

variable_types:
nk
unsigned int

variable_types:
value
unsigned char *

variable_types: struct TCRDB { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mmtx; unsigned int eckey; char *host; int port; char *expr; int fd; struct TTSOCK { int fd; char buf[65536]; char *rp; char *ep; _Bool end; double to; double dl; } *sock; double timeout; int opts; } *

user_defined_types: enum value_t { META_DATA=1, IO_NODE=2, FILE_NODE=3, SWAP_NODE=4, IO_DATA=5 }

user_defined_types: struct TCRDB { union pthread_mutex_t mmtx; unsigned int eckey; char *host; int port; char *expr; int fd; struct TTSOCK *sock; double timeout; int opts; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall tt_out(const char *a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
unsigned int v4; // eax
const char *v5; // rax
unsigned int v6; // ebp
unsigned int v8; // eax
const char *v9; // rax

v2 = tcrdbnew();
v3 = (unsigned int)get_db_port(a2);
printf("db_port -- %d\n", v3);
if ( (unsigned __int8)tcrdbopen(v2, "192.168.0.18", (unsigned int)v3) )
{
if ( (unsigned __int8)tcrdbout2(v2, a1) )
{
printf("(key=%s) tt_out success!\n", a1);
v6 = 0;
}
else
{
v8 = tcrdbecode(v2);
v9 = (const char *)tcrdberrmsg(v8);
fprintf(stderr, "(key=%s) tt_out error:%s\n", a1, v9);
v6 = 2;
}
}
else
{
v4 = tcrdbecode(v2);
v5 = (const char *)tcrdberrmsg(v4);
fprintf(stderr, "tt_out:open %d error -- %s\n", (unsigned int)v3, v5);
v6 = 1;
}
tcrdbdel(v2);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
unsigned int v4; // eax
const char *v5; // rax
unsigned int v6; // ebp
unsigned int v8; // eax
const char *v9; // rax

v2 = tcrdbnew();
v3 = (unsigned int)func0(a2);
printf("db_port -- %d\n", v3);
if ( (unsigned __int8)tcrdbopen(v2, "192.168.0.18", (unsigned int)v3) )
{
if ( (unsigned __int8)tcrdbout2(v2, a1) )
{
printf("(key=%s) tt_out success!\n", a1);
v6 = 0;
}
else
{
v8 = tcrdbecode(v2);
v9 = (const char *)tcrdberrmsg(v8);
fprintf(stderr, "(key=%s) tt_out error:%s\n", a1, v9);
v6 = 2;
}
}
else
{
v4 = tcrdbecode(v2);
v5 = (const char *)tcrdberrmsg(v4);
fprintf(stderr, "tt_out:open %d error -- %s\n", (unsigned int)v3, v5);
v6 = 1;
}
tcrdbdel(v2);
return v6;
}

original_code:
u32 tt_out(u8 *key,value_t vt)
{
 u32 ecode;
 u32 rt = 0;
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_out:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(tcrdbout2(rdb,key)){
         printf("(key=%s) tt_out success!\n",key);
     }else{
         ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_out error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }
 }
 tcrdbdel(rdb);
 return rt;
}

canonical_original_code:
unsigned int tt_out(unsigned char *key, enum value_t vt)
{
 unsigned int ecode;
 unsigned int rt = 0;
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_out:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(tcrdbout2(rdb,key)){
         printf("(key=%s) tt_out success!\n",key);
     }else{
         ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_out error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }
 }
 tcrdbdel(rdb);
 return rt;
}

user_defined_types: struct TTSOCK { int fd; char buf[65536]; char *rp; char *ep; _Bool end; double to; double dl; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall tt_put(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // er13
__int64 v7; // rbx
__int64 v8; // rbp
unsigned int v9; // eax
const char *v10; // rax
unsigned int v11; // ebp
unsigned int v13; // eax
const char *v14; // rax

v6 = strlen(a1);
v7 = tcrdbnew();
v8 = (unsigned int)get_db_port(a4);
printf("db_port -- %d\n", v8);
if ( (unsigned __int8)tcrdbopen(v7, "192.168.0.18", (unsigned int)v8) )
{
if ( (unsigned __int8)tcrdbput(v7, a1, v6, a2, a3) )
{
printf("(key=%s) tt_put success!\n", a1);
v11 = 0;
}
else
{
v13 = tcrdbecode(v7);
v14 = (const char *)tcrdberrmsg(v13);
fprintf(stderr, "(key=%s) tt_put error:%s\n", a1, v14);
v11 = 2;
}
}
else
{
v9 = tcrdbecode(v7);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "tt_put:open %d error -- %s\n", (unsigned int)v8, v10);
v11 = 1;
}
tcrdbdel(v7);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // er13
__int64 v7; // rbx
__int64 v8; // rbp
unsigned int v9; // eax
const char *v10; // rax
unsigned int v11; // ebp
unsigned int v13; // eax
const char *v14; // rax

v6 = strlen(a1);
v7 = tcrdbnew();
v8 = (unsigned int)func0(a4);
printf("db_port -- %d\n", v8);
if ( (unsigned __int8)tcrdbopen(v7, "192.168.0.18", (unsigned int)v8) )
{
if ( (unsigned __int8)tcrdbput(v7, a1, v6, a2, a3) )
{
printf("(key=%s) tt_put success!\n", a1);
v11 = 0;
}
else
{
v13 = tcrdbecode(v7);
v14 = (const char *)tcrdberrmsg(v13);
fprintf(stderr, "(key=%s) tt_put error:%s\n", a1, v14);
v11 = 2;
}
}
else
{
v9 = tcrdbecode(v7);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "tt_put:open %d error -- %s\n", (unsigned int)v8, v10);
v11 = 1;
}
tcrdbdel(v7);
return v11;
}

original_code:
u32 tt_put(u8 * key,u8 *zv,u32 nv,value_t vt)
{
 u32 ecode;
 u32 rt = 0;
 u32 nk = strlen(key);
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_put:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(!tcrdbput(rdb,key,nk,zv,nv)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_put error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
   printf("(key=%s) tt_put success!\n",key);
     }
 }
 tcrdbdel(rdb);
 return rt;
}

canonical_original_code:
unsigned int tt_put(unsigned char *key, unsigned char *zv, unsigned int nv, enum value_t vt)
{
 unsigned int ecode;
 unsigned int rt = 0;
 unsigned int nk = strlen(key);
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_put:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(!tcrdbput(rdb,key,nk,zv,nv)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_put error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
   printf("(key=%s) tt_put success!\n",key);
     }
 }
 tcrdbdel(rdb);
 return rt;
}


decompiled_code:
__int64 __fastcall iod_get(const char *a1, unsigned int *a2)
{
unsigned int v2; // er14
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // r12
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // eax
const char *v10; // rax

v2 = strlen(a1);
v3 = tcrdbnew();
v4 = (unsigned int)get_db_port(5);
printf("db_port -- %d\n", v4);
if ( (unsigned __int8)tcrdbopen(v3, "192.168.0.18", (unsigned int)v4) )
{
v5 = tcrdbget(v3, a1, v2, a2);
if ( v5 )
{
printf("(key=%s) iod_get success!\n", a1);
printf("%d bytes read\n", *a2);
tcrdbdel(v3);
}
else
{
v9 = tcrdbecode(v3);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "(key=%s) iod_get error:%s\n", a1, v10);
}
}
else
{
v7 = tcrdbecode(v3);
v8 = (const char *)tcrdberrmsg(v7);
fprintf(stderr, "iod_get:open %d error -- %s\n", (unsigned int)v4, v8);
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, unsigned int *a2)
{
unsigned int v2; // er14
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // r12
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // eax
const char *v10; // rax

v2 = strlen(a1);
v3 = tcrdbnew();
v4 = (unsigned int)func0(5);
printf("db_port -- %d\n", v4);
if ( (unsigned __int8)tcrdbopen(v3, "192.168.0.18", (unsigned int)v4) )
{
v5 = tcrdbget(v3, a1, v2, a2);
if ( v5 )
{
printf("(key=%s) iod_get success!\n", a1);
printf("%d bytes read\n", *a2);
tcrdbdel(v3);
}
else
{
v9 = tcrdbecode(v3);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "(key=%s) iod_get error:%s\n", a1, v10);
}
}
else
{
v7 = tcrdbecode(v3);
v8 = (const char *)tcrdberrmsg(v7);
fprintf(stderr, "iod_get:open %d error -- %s\n", (unsigned int)v4, v8);
v5 = 0LL;
}
return v5;
}

original_code:
u8 *iod_get(u8 *key,u32 *nv)
{
 u32 ecode;
 u32 nk = strlen(key);
 u8 *value;
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(IO_DATA);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"iod_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  return ((void *)0);
 }else{
     if((value = tcrdbget(rdb,key,nk,nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) iod_get error:%s\n",key,tcrdberrmsg(ecode));
   return ((void *)0);
  }else{
      printf("(key=%s) iod_get success!\n",key);
   printf("%d bytes read\n",*nv);
     }
 }
 tcrdbdel(rdb);
 return value;
}

canonical_original_code:
unsigned char *iod_get(unsigned char *key, unsigned int *nv)
{
 unsigned int ecode;
 unsigned int nk = strlen(key);
 unsigned char *value;
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(IO_DATA);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"iod_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  return ((void *)0);
 }else{
     if((value = tcrdbget(rdb,key,nk,nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) iod_get error:%s\n",key,tcrdberrmsg(ecode));
   return ((void *)0);
  }else{
      printf("(key=%s) iod_get success!\n",key);
   printf("%d bytes read\n",*nv);
     }
 }
 tcrdbdel(rdb);
 return value;
}

variable_types:
nv
unsigned int *

return_type: unsigned char *


decompiled_code:
__int64 __fastcall iod_out(const char *a1)
{
return tt_out(a1, 5);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
return func2(a1, 5);
}

original_code:
u32 iod_out(u8 *key)
{
 return tt_out(key,IO_DATA);
}

canonical_original_code:
unsigned int iod_out(unsigned char *key)
{
 return tt_out(key,IO_DATA);
}


decompiled_code:
__int64 __fastcall iod_put(const char *a1, __int64 a2, unsigned int a3)
{
return tt_put(a1, a2, a3, 5);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, __int64 a2, unsigned int a3)
{
return func3(a1, a2, a3, 5);
}

original_code:
u32 iod_put(u8 *key,u8 *value, u32 count)
{
 return tt_put(key,value,count,IO_DATA);
}

canonical_original_code:
unsigned int iod_put(unsigned char *key, unsigned char *value, unsigned int count)
{
 return tt_put(key,value,count,IO_DATA);
}

variable_types:
count
unsigned int


decompiled_code:
__int64 mutex_hash_init()
{
__int64 *v0; // rax

v0 = &mutex_hash;
do
*v0++ = 0LL;
while ( v0 != (__int64 *)&unk_AC8 );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 *v0; // rax

v0 = &mutex_hash;
do
*v0++ = 0LL;
while ( v0 != (__int64 *)&unk_AC8 );
return 0LL;
}

original_code:
int mutex_hash_init()
{
 int i;
 for(i = 0;i < 101;i++)
 {
  mutex_hash[i] = (zz_mutex*)0;
 }
 return 0;
}

canonical_original_code:
int mutex_hash_init()
{
 int i;
 for(i = 0;i < 101;i++)
 {
  mutex_hash[i] = (struct _mutex *)0;
 }
 return 0;
}

variable_types: i int

user_defined_types: struct _mutex { int count; union pthread_mutex_t p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; }


decompiled_code:
__int64 show_mutex_hash()
{
unsigned int v0; // er14
__int64 i; // r12
const char *v2; // rbx
unsigned int v3; // ebp

v0 = pthread_mutex_lock(&glob_mutex);
if ( v0 )
{
perror("glob_mutex thread_mutex_lock");
v0 = 1;
}
for ( i = 0LL; i != 101; ++i )
{
v2 = (const char *)mutex_hash[i];
if ( v2 )
{
printf("--------Hash%3d ---------\n", (unsigned int)i);
v3 = 0;
do
{
++v3;
printf(" %3d %s\n", *(unsigned int *)v2, v2 + 48);
v2 = (const char *)*((_QWORD *)v2 + 40);
}
while ( v2 );
printf("--------Hash%3d over---len%3d------\n", (unsigned int)i, v3);
}
}
if ( pthread_mutex_unlock(&glob_mutex) )
{
perror("glob_mutex thread_mutex_unlock");
v0 = 2;
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er14
__int64 i; // r12
const char *v2; // rbx
unsigned int v3; // ebp

v0 = pthread_mutex_lock(&glob_mutex);
if ( v0 )
{
perror("glob_mutex thread_mutex_lock");
v0 = 1;
}
for ( i = 0LL; i != 101; ++i )
{
v2 = (const char *)mutex_hash[i];
if ( v2 )
{
printf("--------Hash%3d ---------\n", (unsigned int)i);
v3 = 0;
do
{
++v3;
printf(" %3d %s\n", *(unsigned int *)v2, v2 + 48);
v2 = (const char *)*((_QWORD *)v2 + 40);
}
while ( v2 );
printf("--------Hash%3d over---len%3d------\n", (unsigned int)i, v3);
}
}
if ( pthread_mutex_unlock(&glob_mutex) )
{
perror("glob_mutex thread_mutex_unlock");
v0 = 2;
}
return v0;
}

original_code:
int show_mutex_hash()
{
 int r = 0;
 int i,hash_len;
 zz_mutex * my_mutex;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 for(i = 0;i < 101;i++)
 {
  if((my_mutex = mutex_hash[i]) == (zz_mutex*)0){continue;}
  printf("--------Hash%3d ---------\n",i);
  hash_len = 0;
  while(my_mutex)
  {
   hash_len++;
   printf("  %3d   %s\n",my_mutex->count,my_mutex->file_name);
   my_mutex = my_mutex->next;
  }
  printf("--------Hash%3d over---len%3d------\n",i,hash_len);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

canonical_original_code:
int show_mutex_hash()
{
 int r = 0;
 int i; int hash_len;
 struct _mutex *my_mutex;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 for(i = 0;i < 101;i++)
 {
  if((my_mutex = mutex_hash[i]) == (struct _mutex *)0){continue;}
  printf("--------Hash%3d ---------\n",i);
  hash_len = 0;
  while(my_mutex)
  {
   hash_len++;
   printf("  %3d   %s\n",my_mutex->count,my_mutex->file_name);
   my_mutex = my_mutex->next;
  }
  printf("--------Hash%3d over---len%3d------\n",i,hash_len);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

variable_types: r int

variable_types: struct _mutex { int count; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; } *


decompiled_code:
char *alloc_zz_mutex()
{
char *v0; // rbx

v0 = (char *)malloc(0x148uLL);
if ( pthread_mutex_init((pthread_mutex_t *)(v0 + 8), 0LL) )
{
perror("pthread_mutex initialize fail");
free(v0);
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
char *func3()
{
char *v0; // rbx

v0 = (char *)malloc(0x148uLL);
if ( pthread_mutex_init((pthread_mutex_t *)(v0 + 8), 0LL) )
{
perror("pthread_mutex initialize fail");
free(v0);
v0 = 0LL;
}
return v0;
}

original_code:
zz_mutex * alloc_zz_mutex()
{
 zz_mutex * mtx = (zz_mutex*)malloc(sizeof(zz_mutex));
 if(pthread_mutex_init(&mtx->p_mutex,((void *)0)) != 0)
 {
  perror("pthread_mutex initialize fail");
  free(mtx);
  mtx = (zz_mutex*)0;
 }
 return mtx;
}

canonical_original_code:
struct _mutex *alloc_zz_mutex()
{
 struct _mutex *mtx = (zz_mutex*)malloc(sizeof(zz_mutex));
 if(pthread_mutex_init(&mtx->p_mutex,((void *)0)) != 0)
 {
  perror("pthread_mutex initialize fail");
  free(mtx);
  mtx = (struct _mutex *)0;
 }
 return mtx;
}

return_type: struct _mutex { int count; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; } *


decompiled_code:
__int64 __fastcall free_zz_mutex(void *ptr)
{
unsigned int v1; // ebx

v1 = pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 8));
if ( v1 )
{
perror("pthread_mutex_destroy");
v1 = 1;
}
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
unsigned int v1; // ebx

v1 = pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 8));
if ( v1 )
{
perror("pthread_mutex_destroy");
v1 = 1;
}
free(ptr);
return v1;
}

original_code:
int free_zz_mutex(zz_mutex * mtx)
{
 int r = 0;
 if(pthread_mutex_destroy(&mtx->p_mutex) != 0)
 {
  perror("pthread_mutex_destroy");
  r = 1;
 }
 free(mtx);
 return r;
}

canonical_original_code:
int free_zz_mutex(struct _mutex *mtx)
{
 int r = 0;
 if(pthread_mutex_destroy(&mtx->p_mutex) != 0)
 {
  perror("pthread_mutex_destroy");
  r = 1;
 }
 free(mtx);
 return r;
}