main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // er13
_BOOL4 v5; // eax
int v6; // er12
__int64 v7; // r13
__int64 v8; // rax
__pid_t v9; // eax
int v10; // [rsp+0h] [rbp-58h]
int v11; // [rsp+0h] [rbp-58h]
int i; // [rsp+0h] [rbp-58h]
int v13; // [rsp+4h] [rbp-54h]
__pid_t v14; // [rsp+10h] [rbp-48h]
__WAIT_STATUS stat_loc; // [rsp+2Ch] [rbp-2Ch] BYREF

v10 = argc - 1;
LODWORD(stat_loc.__uptr) = 0;
v14 = getpid();
if ( getpid() != v14 )
goto LABEL_2;
if ( argc <= 1 )
{
printf("Error de invocacion. Uso: %s [comando a ejecutar]\n", *argv);
exit(1);
}
v3 = 0;
if ( v10 <= 0 )
{
v7 = argc + 2;
aux = (char **)malloc(v7 * 8);
v6 = argc;
v3 = 0;
}
else
{
do
{
v4 = v10;
v5 = esopcion((_BYTE **)&argv[v10]);
++v3;
--v10;
}
while ( !v5 && v4 > 1 );
v6 = argc - v3;
v7 = argc - v3 + 2;
aux = (char **)malloc(v7 * 8);
if ( argc - v3 <= 0 )
{
LABEL_10:
aux[v7 - 1] = 0LL;
v11 = 0;
v13 = v3 - 1;
while ( v13 > v11 )
{
if ( getpid() == v14 )
{
aux[argc - v3] = (char *)(&argv[v11 + 1])[argc - v3];
v9 = vfork();
if ( v9 == -1 )
{
puts("Error al crear hijo ");
}
else
{
if ( !v9 )
{
if ( execvp(*aux, aux) >= 0 )
exit(0);
puts("Error al ejecutar comando ");
exit(1);
}
wait((__WAIT_STATUS)&stat_loc);
}
}
++v11;
}
if ( v13 > 0 )
{
for ( i = 0; i < v13; ++i )
wait((__WAIT_STATUS)&stat_loc);
}
LABEL_2:
exit(0);
}
}
v8 = 0LL;
do
{
aux[v8] = (char *)argv[v8 + 1];
++v8;
}
while ( v6 > (int)v8 );
goto LABEL_10;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // er13
_BOOL4 v5; // eax
int v6; // er12
__int64 v7; // r13
__int64 v8; // rax
__pid_t v9; // eax
int v10; // [rsp+0h] [rbp-58h]
int v11; // [rsp+0h] [rbp-58h]
int i; // [rsp+0h] [rbp-58h]
int v13; // [rsp+4h] [rbp-54h]
__pid_t v14; // [rsp+10h] [rbp-48h]
__WAIT_STATUS stat_loc; // [rsp+2Ch] [rbp-2Ch] BYREF

v10 = argc - 1;
LODWORD(stat_loc.__uptr) = 0;
v14 = getpid();
if ( getpid() != v14 )
goto LABEL_2;
if ( argc <= 1 )
{
printf("Error de invocacion. Uso: %s [comando a ejecutar]\n", *argv);
exit(1);
}
v3 = 0;
if ( v10 <= 0 )
{
v7 = argc + 2;
aux = (char **)malloc(v7 * 8);
v6 = argc;
v3 = 0;
}
else
{
do
{
v4 = v10;
v5 = func0((_BYTE **)&argv[v10]);
++v3;
--v10;
}
while ( !v5 && v4 > 1 );
v6 = argc - v3;
v7 = argc - v3 + 2;
aux = (char **)malloc(v7 * 8);
if ( argc - v3 <= 0 )
{
LABEL_10:
aux[v7 - 1] = 0LL;
v11 = 0;
v13 = v3 - 1;
while ( v13 > v11 )
{
if ( getpid() == v14 )
{
aux[argc - v3] = (char *)(&argv[v11 + 1])[argc - v3];
v9 = vfork();
if ( v9 == -1 )
{
puts("Error al crear hijo ");
}
else
{
if ( !v9 )
{
if ( execvp(*aux, aux) >= 0 )
exit(0);
puts("Error al ejecutar comando ");
exit(1);
}
wait((__WAIT_STATUS)&stat_loc);
}
}
++v11;
}
if ( v13 > 0 )
{
for ( i = 0; i < v13; ++i )
wait((__WAIT_STATUS)&stat_loc);
}
LABEL_2:
exit(0);
}
}
v8 = 0LL;
do
{
aux[v8] = (char *)argv[v8 + 1];
++v8;
}
while ( v6 > (int)v8 );
goto LABEL_10;
}

original_code:
int main (int argc, char *argv[])
{
 int i = argc - 1;
 int opcion = 0;
 int cantarch = 0;
 pid_t padre, hijopid;
 int status = 0;
 int tam = 0;
 int cantopc = 0;
 padre = getpid();
 if (getpid() == padre)
 {
  if (argc < 2)
  {
   printf("Error de invocacion. Uso: %s [comando a ejecutar]\n",argv[0]);
   exit(1);
  }
  while (opcion == 0 && i > 0)
  {
   opcion = esopcion(&argv[i]);
   i--;
   cantarch++;
  }
  cantopc = argc - cantarch - 1;
  tam = cantopc + 3;
  aux = (char **) malloc (tam * sizeof(char *));
  for (i = 0; i <= cantopc; i++)
   aux[i] = argv[i+1];
  aux[tam - 1] = ((void *)0);
  for (i = 0; i < cantarch - 1; i++)
  {
   cantopc = argc - cantarch - 1;
   if (getpid() == padre)
   {
    aux[cantopc + 1] = argv[cantopc + 2 + i];
    hijopid = vfork();
    switch (hijopid)
    {
     case -1: printf("Error al crear hijo \n");
        break;
     case 0: if(execvp(aux[0], &aux[0]) < 0)
        {
         printf("Error al ejecutar comando \n");
         _exit(1);
        }
        _exit(0);
     default: wait(&status);
    }
   }
  }
 }
 for(i = 0; i < cantarch - 1; i++)
  wait(&status);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i = argc - 1;
 int opcion = 0;
 int cantarch = 0;
 int padre; int hijopid;
 int status = 0;
 int tam = 0;
 int cantopc = 0;
 padre = getpid();
 if (getpid() == padre)
 {
  if (argc < 2)
  {
   printf("Error de invocacion. Uso: %s [comando a ejecutar]\n",argv[0]);
   exit(1);
  }
  while (opcion == 0 && i > 0)
  {
   opcion = esopcion(&argv[i]);
   i--;
   cantarch++;
  }
  cantopc = argc - cantarch - 1;
  tam = cantopc + 3;
  aux = (char **) malloc (tam * sizeof(char *));
  for (i = 0; i <= cantopc; i++)
   aux[i] = argv[i+1];
  aux[tam - 1] = ((void *)0);
  for (i = 0; i < cantarch - 1; i++)
  {
   cantopc = argc - cantarch - 1;
   if (getpid() == padre)
   {
    aux[cantopc + 1] = argv[cantopc + 2 + i];
    hijopid = vfork();
    switch (hijopid)
    {
     case -1: printf("Error al crear hijo \n");
        break;
     case 0: if(execvp(aux[0], &aux[0]) < 0)
        {
         printf("Error al ejecutar comando \n");
         _exit(1);
        }
        _exit(0);
     default: wait(&status);
    }
   }
  }
 }
 for(i = 0; i < cantarch - 1; i++)
  wait(&status);
 exit(0);
}

variable_types: opcion int

variable_types: cantarch int

variable_types: padre int

variable_types: hijopid int

variable_types: status int

variable_types: tam int

variable_types: cantopc int


obtenerSemaforo

decompiled_code:
__int64 __fastcall obtenerSemaforo(key_t a1, unsigned int a2)
{
unsigned int v2; // ebp

v2 = semget(a1, 1, 896);
semctl(v2, 0, 16, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(key_t a1, unsigned int a2)
{
unsigned int v2; // ebp

v2 = semget(a1, 1, 896);
semctl(v2, 0, 16, a2);
return v2;
}

original_code:
int obtenerSemaforo(key_t clave, int valor)
{
 int IdSemaforo;
 union semun CtlSem;
 IdSemaforo = semget(clave, 1, 01000 | 0600);
 CtlSem.val = valor;
 semctl(IdSemaforo, 0, 16, CtlSem);
 return IdSemaforo;
}

canonical_original_code:
int obtenerSemaforo(int clave, int valor)
{
 int IdSemaforo;
 union semun CtlSem;
 IdSemaforo = semget(clave, 1, 01000 | 0600);
 CtlSem.val = valor;
 semctl(IdSemaforo, 0, 16, CtlSem);
 return IdSemaforo;
}

variable_types: clave int

variable_types: valor int

variable_types: IdSemaforo int

variable_types: union semun { int val; struct semid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; } *buf; unsigned short *array; struct seminfo { int semmap; int semmni; int semmns; int semmnu; int semmsl; int semopm; int semume; int semusz; int semvmx; int semaem; } *__buf; }

return_type: int

user_defined_types: union semun { int val; struct semid_ds *buf; unsigned short *array; struct seminfo *__buf; }

user_defined_types: struct semid_ds { struct ipc_perm sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; }


pedirSemaforo

decompiled_code:
int __fastcall pedirSemaforo(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 0;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 0;
return semop(a1, &sops, 1uLL);
}

original_code:
void pedirSemaforo(int IdSemaforo)
{
 struct sembuf OpSem;
 OpSem.sem_num = 0;
 OpSem.sem_op = -1;
 OpSem.sem_flg = 0;
 semop(IdSemaforo, &OpSem, 1);
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }

return_type: void


devolverSemaforo

decompiled_code:
int __fastcall devolverSemaforo(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 0;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 0;
return semop(a1, &sops, 1uLL);
}

original_code:
void devolverSemaforo(int IdSemaforo)
{
 struct sembuf OpSem;
 OpSem.sem_num = 0;
 OpSem.sem_op = 1;
 OpSem.sem_flg = 0;
 semop(IdSemaforo, &OpSem, 1);
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


eliminarSemaforo

decompiled_code:
int __fastcall eliminarSemaforo(int a1)
{
return semctl(a1, 0, 0);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
return semctl(a1, 0, 0);
}

original_code:
void eliminarSemaforo(int IdSemaforo)
{
 semctl(IdSemaforo, 0, 0);
}


substr

decompiled_code:
char *__fastcall substr(const char *a1, int a2, int a3)
{
size_t v3; // rbx
char *v4; // rax

if ( !a3 )
a3 = strlen(a1) + ~a2;
v3 = a3;
v4 = (char *)malloc(a3);
return strncpy(v4, &a1[a2], v3);
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, int a2, int a3)
{
size_t v3; // rbx
char *v4; // rax

if ( !a3 )
a3 = strlen(a1) + ~a2;
v3 = a3;
v4 = (char *)malloc(a3);
return strncpy(v4, &a1[a2], v3);
}

original_code:
char * substr(char * cadena, int comienzo, int longitud)
{
 if(longitud == 0)
  longitud = strlen(cadena)-comienzo-1;
 char *nuevo = (char*)malloc(sizeof(char) * longitud);
 strncpy(nuevo, cadena + comienzo, longitud);
 return nuevo;
}

canonical_original_code:
char *substr(char *cadena, int comienzo, int longitud)
{
 if(longitud == 0)
  longitud = strlen(cadena)-comienzo-1;
 char *nuevo = (char*)malloc(sizeof(char) * longitud);
 strncpy(nuevo, cadena + comienzo, longitud);
 return nuevo;
}

variable_types:
cadena
char *

variable_types: comienzo int

variable_types: longitud int

variable_types:
nuevo
char *

return_type: char *


indexOf

decompiled_code:
__int64 __fastcall indexOf(__int64 a1, char a2)
{
__int64 v2; // rax
unsigned int v3; // edx

if ( !a1 )
return (unsigned int)-1;
v2 = 0LL;
do
v3 = v2++;
while ( *(_BYTE *)(a1 + v2 - 1) != a2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
__int64 v2; // rax
unsigned int v3; // edx

if ( !a1 )
return (unsigned int)-1;
v2 = 0LL;
do
v3 = v2++;
while ( *(_BYTE *)(a1 + v2 - 1) != a2 );
return v3;
}

original_code:
int indexOf(char * cadena, char caracter)
{
 int pos=0;
 while(cadena != ((void *)0))
 {
  if(*cadena == caracter)
   return pos;
  cadena++;
  pos++;
 }
 return -1;
}

canonical_original_code:
int indexOf(char *cadena, char caracter)
{
 int pos = 0;
 while(cadena != ((void *)0))
 {
  if(*cadena == caracter)
   return pos;
  cadena++;
  pos++;
 }
 return -1;
}

variable_types: caracter char

variable_types: pos int


decompiled_code:
__int64 __fastcall abrir_socket_escucha(__int16 a1)
{
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = socket(2, 1, 0);
if ( setsockopt(v1, 1, 2, optval, 4u) < 0 )
puts("ERROR AL SETEAR OPCIONES DE SOCKET ESCUCHA");
*(_DWORD *)&v3.sa_data[10] = 0;
v3.sa_family = 2;
*(_WORD *)v3.sa_data = _bswap_16(a1);
*(_QWORD *)&v3.sa_data[2] = (unsigned int)_bswap_32(0);
bind(v1, &v3, 0x10u);
listen(v1, 4);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = socket(2, 1, 0);
if ( setsockopt(v1, 1, 2, optval, 4u) < 0 )
puts("ERROR AL SETEAR OPCIONES DE SOCKET ESCUCHA");
*(_DWORD *)&v3.sa_data[10] = 0;
v3.sa_family = 2;
*(_WORD *)v3.sa_data = func0(a1);
*(_QWORD *)&v3.sa_data[2] = (unsigned int)func1(0);
bind(v1, &v3, 0x10u);
listen(v1, 4);
return v1;
}

original_code:
int abrir_socket_escucha(int puerto)
{
 int listen_socket,reuse=1;
 struct sockaddr_in listen_address;
 unsigned short int listen_port=0;
 unsigned long int listen_ip_address=0;
 listen_socket=socket(2,SOCK_STREAM,0);
 if(setsockopt(listen_socket,1,2,(char*)&reuse,sizeof(reuse))<0)
  printf("ERROR AL SETEAR OPCIONES DE SOCKET ESCUCHA\n");
 bzero(&listen_address,sizeof(listen_address));
 listen_address.sin_family=2;
 listen_port=htons(puerto);
 listen_address.sin_port=listen_port;
 listen_ip_address=htonl(((in_addr_t) 0x00000000));
 listen_address.sin_addr.s_addr=listen_ip_address;
 bind(listen_socket,(struct sockaddr*)&listen_address,sizeof(struct sockaddr));
 listen(listen_socket,4);
 return listen_socket;
}

canonical_original_code:
int abrir_socket_escucha(int puerto)
{
 int listen_socket; int reuse = 1;
 struct sockaddr_in listen_address;
 unsigned short listen_port = 0;
 unsigned long listen_ip_address = 0;
 listen_socket=socket(2,SOCK_STREAM,0);
 if(setsockopt(listen_socket,1,2,(char *)&reuse,sizeof(reuse))<0)
  printf("ERROR AL SETEAR OPCIONES DE SOCKET ESCUCHA\n");
 bzero(&listen_address,sizeof(listen_address));
 listen_address.sin_family=2;
 listen_port=htons(puerto);
 listen_address.sin_port=listen_port;
 listen_ip_address=htonl(((unsigned int) 0x00000000));
 listen_address.sin_addr.s_addr=listen_ip_address;
 bind(listen_socket,(struct sockaddr *)&listen_address,sizeof(struct sockaddr));
 listen(listen_socket,4);
 return listen_socket;
}

variable_types: puerto int

variable_types: reuse int

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

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


decompiled_code:
__int64 __fastcall conectar_al_server(__int16 a1, const char *a2)
{
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_WORD *)v4.sa_data = _bswap_16(a1);
*(_DWORD *)&v4.sa_data[2] = inet_addr(a2);
if ( connect(v2, &v4, 0x10u) == -1 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1, const char *a2)
{
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_WORD *)v4.sa_data = func0(a1);
*(_DWORD *)&v4.sa_data[2] = inet_addr(a2);
if ( connect(v2, &v4, 0x10u) == -1 )
v2 = -1;
return v2;
}

original_code:
int conectar_al_server(int puerto, char *IP_server)
{
 int caller_socket;
 struct sockaddr_in listen_address;
 unsigned short int listen_port=0;
 unsigned long int listen_ip_address=0;
 caller_socket=socket(2,SOCK_STREAM,0);
 bzero(&listen_address,sizeof(listen_address));
 listen_address.sin_family=2;
 listen_port=htons(puerto);
 listen_address.sin_port=listen_port;
 listen_ip_address=htonl(((in_addr_t) 0x00000000));
 listen_address.sin_addr.s_addr=inet_addr(IP_server);
 if((connect(caller_socket,(struct sockaddr*)&listen_address,sizeof(struct sockaddr)))==-1)
  return -1;
 return caller_socket;
}

canonical_original_code:
int conectar_al_server(int puerto, char *IP_server)
{
 int caller_socket;
 struct sockaddr_in listen_address;
 unsigned short listen_port = 0;
 unsigned long listen_ip_address = 0;
 caller_socket=socket(2,SOCK_STREAM,0);
 bzero(&listen_address,sizeof(listen_address));
 listen_address.sin_family=2;
 listen_port=htons(puerto);
 listen_address.sin_port=listen_port;
 listen_ip_address=htonl(((unsigned int) 0x00000000));
 listen_address.sin_addr.s_addr=inet_addr(IP_server);
 if((connect(caller_socket,(struct sockaddr *)&listen_address,sizeof(struct sockaddr)))==-1)
  return -1;
 return caller_socket;
}


decompiled_code:
int __fastcall aceptar_conexion(int a1)
{
return accept(a1, 0LL, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
return accept(a1, 0LL, 0LL);
}

original_code:
int aceptar_conexion(int listen_socket)
{
 int comm_socket=0;
 comm_socket=accept(listen_socket, 0, 0);
 return comm_socket;
}

canonical_original_code:
int aceptar_conexion(int listen_socket)
{
 int comm_socket = 0;
 comm_socket=accept(listen_socket, 0, 0);
 return comm_socket;
}


decompiled_code:
__int64 __fastcall capturar_senal(int a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( a1 == 10 )
{
v2 = contador;
alarma[contador] = *(_DWORD *)(a2 + 16);
result = (unsigned int)(v2 + 1);
contador = result;
}
return result;
}

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

if ( a1 == 10 )
{
v2 = contador;
alarma[contador] = *(_DWORD *)(a2 + 16);
result = (unsigned int)(v2 + 1);
contador = result;
}
return result;
}

original_code:
void capturar_senal(int iNumSen, siginfo_t *info, void *ni) {
if(iNumSen==10)
{
 alarma[contador] =info->_sifields._kill.si_pid;
 contador++;
}
}

canonical_original_code:
void capturar_senal(int iNumSen, struct siginfo_t *info, void *ni) {
if(iNumSen==10)
{
 alarma[contador] =info->_sifields._kill.si_pid;
 contador++;
}
}

variable_types: iNumSen int

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

variable_types:
ni
void *

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


CancelarAlarma

decompiled_code:
int __fastcall CancelarAlarma(__pid_t a1)
{
return kill(a1, 15);
}

canonical_decompiled_code:
int __fastcall func2(__pid_t a1)
{
return kill(a1, 15);
}

original_code:
void CancelarAlarma(pid_t pid)
{
 kill(pid,15);
}

canonical_original_code:
void CancelarAlarma(int pid)
{
 kill(pid,15);
}

variable_types: pid int


SetearActYConjSen

decompiled_code:
void __fastcall SetearActYConjSen(__int64 a1)
{
*(_QWORD *)a1 = handler;
*(_DWORD *)(a1 + 136) = 4;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_QWORD *)a1 = handler;
*(_DWORD *)(a1 + 136) = 4;
}

original_code:
void SetearActYConjSen(struct sigaction * act)
{
 act->__sigaction_handler.sa_sigaction=handler;
 act->sa_flags=4;
}

canonical_original_code:
void SetearActYConjSen(struct sigaction *act)
{
 act->__sigaction_handler.sa_sigaction=handler;
 act->sa_flags=4;
}

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

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


NuevaAlarma

decompiled_code:
__pid_t __fastcall NuevaAlarma(unsigned int seconds, int a2, int a3)
{
__pid_t result; // eax
__pid_t v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
struct sigaction v8; // [rsp+0h] [rbp-B8h] BYREF

result = getpid();
if ( result == a2 )
{
SetearActYConjSen((__int64)&v8);
sigaction(17, &v8, 0LL);
result = fork();
if ( !result )
{
sigaction(14, &v8, 0LL);
sigaction(15, &v8, 0LL);
v5 = getppid();
kill(v5, 10);
if ( a3 == 1 )
{
while ( 1 )
{
v6 = getpid();
printf("\n Comienza la alarma.%d \n", v6);
alarm(seconds);
pause();
}
}
v7 = getpid();
printf("Comienza la alarma: %d \n", v7);
alarm(seconds);
pause();
exit(0);
}
if ( result == -1 )
{
printf("\n Error al crear el proceso hijo.");
exit(1);
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func4(unsigned int seconds, int a2, int a3)
{
__pid_t result; // eax
__pid_t v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
struct sigaction v8; // [rsp+0h] [rbp-B8h] BYREF

result = getpid();
if ( result == a2 )
{
func3((__int64)&v8);
sigaction(17, &v8, 0LL);
result = fork();
if ( !result )
{
sigaction(14, &v8, 0LL);
sigaction(15, &v8, 0LL);
v5 = getppid();
kill(v5, 10);
if ( a3 == 1 )
{
while ( 1 )
{
v6 = getpid();
printf("\n Comienza la alarma.%d \n", v6);
alarm(seconds);
pause();
}
}
v7 = getpid();
printf("Comienza la alarma: %d \n", v7);
alarm(seconds);
pause();
exit(0);
}
if ( result == -1 )
{
printf("\n Error al crear el proceso hijo.");
exit(1);
}
}
return result;
}

original_code:
void NuevaAlarma(int seg,pid_t padre,int recurrente)
{
 pid_t pidHijo;
 int status=0;
 if(getpid()==padre)
 {
  struct sigaction act;
  SetearActYConjSen(&act);
  sigaction(17, &act, ((void *)0));
  pidHijo = fork();
  if(pidHijo == 0)
   {
       sigaction(14, &act, ((void *)0));
              sigaction(15, &act, ((void *)0));
              kill(getppid(),10);
       if(recurrente==1)
   {
          for(;;)
    {
     printf("\n Comienza la alarma.%d \n",getpid());
     alarm(seg);
     pause();
    }
   }
   else
   { printf("Comienza la alarma: %d \n",getpid());
     alarm(seg);
     pause();
     exit(0);
   }
  }
  else
  {
   if(pidHijo == -1)
   {
   printf("\n Error al crear el proceso hijo.");
   exit(1);
   }
  }
 }
}

canonical_original_code:
void NuevaAlarma(int seg, int padre, int recurrente)
{
 int pidHijo;
 int status = 0;
 if(getpid()==padre)
 {
  struct sigaction act;
  SetearActYConjSen(&act);
  sigaction(17, &act, ((void *)0));
  pidHijo = fork();
  if(pidHijo == 0)
   {
       sigaction(14, &act, ((void *)0));
              sigaction(15, &act, ((void *)0));
              kill(getppid(),10);
       if(recurrente==1)
   {
          for(;;)
    {
     printf("\n Comienza la alarma.%d \n",getpid());
     alarm(seg);
     pause();
    }
   }
   else
   { printf("Comienza la alarma: %d \n",getpid());
     alarm(seg);
     pause();
     exit(0);
   }
  }
  else
  {
   if(pidHijo == -1)
   {
   printf("\n Error al crear el proceso hijo.");
   exit(1);
   }
  }
 }
}

variable_types: seg int

variable_types: padre int

variable_types: recurrente int

variable_types: pidHijo int

variable_types: status int

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


handler

decompiled_code:
void __fastcall handler(int a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
int v4; // eax

switch ( a1 )
{
case 14:
v2 = getpid();
printf("\n Ha finalizado el tiempo de la alarma:%d \n", v2);
break;
case 15:
v3 = getpid();
printf("\nAlarma cancelada: %d", v3);
exit(0);
case 17:
v4 = *(_DWORD *)(a2 + 8);
if ( v4 == 1 )
{
puts("\n Finalizo proceso hijo.");
}
else if ( v4 == 5 )
{
puts("\n proceso hijo se detuvo.");
}
break;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
int v4; // eax

switch ( a1 )
{
case 14:
v2 = getpid();
printf("\n Ha finalizado el tiempo de la alarma:%d \n", v2);
break;
case 15:
v3 = getpid();
printf("\nAlarma cancelada: %d", v3);
exit(0);
case 17:
v4 = *(_DWORD *)(a2 + 8);
if ( v4 == 1 )
{
puts("\n Finalizo proceso hijo.");
}
else if ( v4 == 5 )
{
puts("\n proceso hijo se detuvo.");
}
break;
}
}

original_code:
void handler(int sig, siginfo_t *info, void *ni)
{
 if(sig==14)
        {
  printf("\n Ha finalizado el tiempo de la alarma:%d \n",getpid());
 }
 else
 if(sig==15)
 {
  printf("\nAlarma cancelada: %d",getpid());
  exit(0);
 }
 else
 if(sig==17)
 {
  switch(info->si_code)
  {
   case CLD_EXITED:
     printf("\n Finalizo proceso hijo.\n");
     break;
   case CLD_STOPPED:
     printf("\n proceso hijo se detuvo.\n");
     break;
  }
 }
}

canonical_original_code:
void handler(int sig, struct siginfo_t *info, void *ni)
{
 if(sig==14)
        {
  printf("\n Ha finalizado el tiempo de la alarma:%d \n",getpid());
 }
 else
 if(sig==15)
 {
  printf("\nAlarma cancelada: %d",getpid());
  exit(0);
 }
 else
 if(sig==17)
 {
  switch(info->si_code)
  {
   case CLD_EXITED:
     printf("\n Finalizo proceso hijo.\n");
     break;
   case CLD_STOPPED:
     printf("\n proceso hijo se detuvo.\n");
     break;
  }
 }
}

variable_types: sig int

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
struct sigaction v4; // [rsp+0h] [rbp-A8h] BYREF
__WAIT_STATUS stat_loc; // [rsp+9Ch] [rbp-Ch] BYREF

LODWORD(stat_loc.__uptr) = 0;
v3 = getpid();
v4.sa_handler = (__sighandler_t)capturar_senal;
v4.sa_flags = 4;
sigaction(10, &v4, 0LL);
if ( getpid() == v3 )
printf("\n Soy el padre y mi pid es:%d \n", v3);
NuevaAlarma(0xAu, v3, 0);
pause();
NuevaAlarma(2u, v3, 1);
pause();
if ( getpid() == v3 )
{
sleep(0x32u);
CancelarAlarma(alarma[0]);
CancelarAlarma(alarma[1]);
}
wait((__WAIT_STATUS)&stat_loc);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
struct sigaction v4; // [rsp+0h] [rbp-A8h] BYREF
__WAIT_STATUS stat_loc; // [rsp+9Ch] [rbp-Ch] BYREF

LODWORD(stat_loc.__uptr) = 0;
v3 = getpid();
v4.sa_handler = (__sighandler_t)capturar_senal;
v4.sa_flags = 4;
sigaction(10, &v4, 0LL);
if ( getpid() == v3 )
printf("\n Soy el padre y mi pid es:%d \n", v3);
func4(0xAu, v3, 0);
pause();
func4(2u, v3, 1);
pause();
if ( getpid() == v3 )
{
sleep(0x32u);
func2(alarma[0]);
func2(alarma[1]);
}
wait((__WAIT_STATUS)&stat_loc);
exit(0);
}

original_code:
int main()
{
 int status=0;
 pid_t padre=getpid();
 pid_t pidHijo;
 struct sigaction act;
 act.__sigaction_handler.sa_sigaction=capturar_senal;
 act.sa_flags=4;
 sigaction(10, &act, ((void *)0));
 if(getpid()==padre)
  printf("\n Soy el padre y mi pid es:%d \n",padre);
 NuevaAlarma(10,padre,0);
 pause();
 NuevaAlarma(2,padre,1);
 pause();
 if(getpid()==padre)
 {
  sleep(50);
  CancelarAlarma(alarma[0]);
  CancelarAlarma(alarma[1]);
 }
wait(&status);
exit(0);
}

canonical_original_code:
int main()
{
 int status = 0;
 int padre = getpid();
 int pidHijo;
 struct sigaction act;
 act.__sigaction_handler.sa_sigaction=capturar_senal;
 act.sa_flags=4;
 sigaction(10, &act, ((void *)0));
 if(getpid()==padre)
  printf("\n Soy el padre y mi pid es:%d \n",padre);
 NuevaAlarma(10,padre,0);
 pause();
 NuevaAlarma(2,padre,1);
 pause();
 if(getpid()==padre)
 {
  sleep(50);
  CancelarAlarma(alarma[0]);
  CancelarAlarma(alarma[1]);
 }
wait(&status);
exit(0);
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


comparar

decompiled_code:
__int64 __fastcall comparar(__int64 a1, __int64 a2)
{
return (unsigned int)*(_QWORD *)(a1 + 56) - *(_DWORD *)(a2 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return (unsigned int)*(_QWORD *)(a1 + 56) - *(_DWORD *)(a2 + 56);
}

original_code:
int comparar (const t_info *d, const t_info *dnodo)
{
 return d->dni-dnodo->dni;
}

canonical_original_code:
int comparar(struct t_info *d, struct t_info *dnodo)
{
 return d->dni-dnodo->dni;
}

variable_types: struct t_info { char empresa[21]; char apynom[31]; long dni; float sueldo; int antiguedad; char posee_tarjeta[2]; long tel; } *

variable_types:
dnodo
struct t_info *


cargarenArbol

original_code:
int cargarenArbol (t_arbol *p, const t_info *d)
{
 int cmp;
 if (*p)
 {
    cmp=comparar (d, &(*p)->info);
    if (!cmp)
    {
   (*p)->info=*d;
   return 1;
  }
    if (cmp<0)
     return cargarenArbol (&(*p)->izq, d);
    else
     return cargarenArbol (&(*p)->der, d);
 }
 *p=(t_nodo *)malloc(sizeof (t_nodo));
 if (!*p)
  return 0;
 (*p)->info=*d;
 (*p)->izq=(*p)->der=((void *)0);
 return 1;
}

canonical_original_code:
int cargarenArbol(struct s_nodo **p, struct t_info *d)
{
 int cmp;
 if (*p)
 {
    cmp=comparar (d, &(*p)->info);
    if (!cmp)
    {
   (*p)->info=*d;
   return 1;
  }
    if (cmp<0)
     return cargarenArbol (&(*p)->izq, d);
    else
     return cargarenArbol (&(*p)->der, d);
 }
 *p=(struct s_nodo *)malloc(sizeof (t_nodo));
 if (!*p)
  return 0;
 (*p)->info=*d;
 (*p)->izq=(*p)->der=((void *)0);
 return 1;
}

variable_types: struct s_nodo { struct t_info { char empresa[21]; char apynom[31]; long dni; float sueldo; int antiguedad; char posee_tarjeta[2]; long tel; } info; struct s_nodo *izq; } **

variable_types:
d
struct t_info *

variable_types: cmp int

user_defined_types: struct s_nodo { struct t_info info; struct s_nodo *izq; }


eliminarArbol

decompiled_code:
void __fastcall eliminarArbol(__int64 a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rdi

v2 = *(_QWORD **)a1;
if ( v2 )
{
eliminarArbol(v2 + 11);
eliminarArbol(*(_QWORD *)a1 + 96LL);
v3 = *(_QWORD **)a1;
if ( !*(_QWORD *)(*(_QWORD *)a1 + 88LL) && !v3[12] )
{
free(v3);
*(_QWORD *)a1 = 0LL;
}
}
}

original_code:
void eliminarArbol (t_arbol *p)
{
   if (*p)
   {
      eliminarArbol (&(*p)->izq);
      eliminarArbol (&(*p)->der);
      if (!(*p)->izq&&!(*p)->der)
      {
         free (*p);
         *p=((void *)0);
      }
   }
}

canonical_original_code:
void eliminarArbol(struct s_nodo **p)
{
   if (*p)
   {
      eliminarArbol (&(*p)->izq);
      eliminarArbol (&(*p)->der);
      if (!(*p)->izq&&!(*p)->der)
      {
         free (*p);
         *p=((void *)0);
      }
   }
}

user_defined_types: struct t_info { char empresa[21]; char apynom[31]; long dni; float sueldo; int antiguedad; char posee_tarjeta[2]; long tel; }


handlerserver

decompiled_code:
void __fastcall handlerserver(int a1)
{
if ( a1 == 10 )
{
printf("Soy el servidor y termino ");
msj = 1;
send(socketpadre, &msj, 4uLL, 0);
close(socketpadre);
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 10 )
{
printf("Soy el servidor y termino ");
msj = 1;
send(socketpadre, &msj, 4uLL, 0);
close(socketpadre);
exit(0);
}
}

original_code:
void handlerserver(int S)
{
  if (S==10)
{ printf("Soy el servidor y termino ");
  msj=1;
  send(socketpadre,&msj,sizeof(msj),0);
  close(socketpadre);
   exit(0); }
}

variable_types: S int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // eax
int v5; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

signal(10, handlerserver);
v3 = socket(2, 1, 0);
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(51244);
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
bind(v3, &addr, 0x10u);
listen(v3, 10);
puts("Comenzamos a escuchar conexiones");
v4 = getpid();
printf("mi pid es %d\n", v4);
*(_QWORD *)&v7.sa_family = 0LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
socketpadre = accept(v3, &v7, &addr_len);
printf("Conexion padre recibida");
while ( 1 )
{
*(_QWORD *)&v7.sa_family = 0LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
send(socketpadre, &msj, 4uLL, 0);
v5 = accept(v3, &v7, &addr_len);
puts(aConexi);
system("df >logservidor.txt");
comparar_informar();
close(v5);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // eax
int v5; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

signal(10, handlerserver);
v3 = socket(2, 1, 0);
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(51244);
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func2(0);
bind(v3, &addr, 0x10u);
listen(v3, 10);
puts("Comenzamos a escuchar conexiones");
v4 = getpid();
printf("mi pid es %d\n", v4);
*(_QWORD *)&v7.sa_family = 0LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
socketpadre = accept(v3, &v7, &addr_len);
printf("Conexion padre recibida");
while ( 1 )
{
*(_QWORD *)&v7.sa_family = 0LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
send(socketpadre, &msj, 4uLL, 0);
v5 = accept(v3, &v7, &addr_len);
puts(aConexi);
system("df >logservidor.txt");
func3();
close(v5);
}
}

original_code:
int main() {
int listen_socket = 0, comm_socket = 0;
unsigned short int listen_port = 0;
unsigned long int listen_ip_address = 0;
struct sockaddr_in listen_address, con_address;
socklen_t con_addr_len;
char buffer[1024];
signal(10,handlerserver);
listen_socket = socket(2, SOCK_STREAM, 0);
bzero(&listen_address, sizeof(listen_address));
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = htonl(((in_addr_t) 0x00000000));
listen_address.sin_addr.s_addr = listen_ip_address;
bind(listen_socket,(struct sockaddr *)&listen_address,sizeof(struct sockaddr));
listen(listen_socket, 10);
printf("Comenzamos a escuchar conexiones\n");
printf("mi pid es %d\n", getpid());
bzero(&con_address, sizeof(con_address));
socketpadre= accept(listen_socket, (struct sockaddr *)(&con_address),&con_addr_len);
printf("Conexion padre recibida");
while (1) {
bzero(&con_address, sizeof(con_address));
send(socketpadre,&msj,sizeof(msj),0);
comm_socket = accept(listen_socket, (struct sockaddr *)(&con_address),&con_addr_len);
printf("Conexión recibida\n");
system("df >logservidor.txt");
comparar_informar();
close(comm_socket);
}
close(listen_socket);
printf("Se desconectó\n");
return 0;
}

canonical_original_code:
int main() {
int listen_socket = 0; int comm_socket = 0;
unsigned short listen_port = 0;
unsigned long listen_ip_address = 0;
struct sockaddr_in listen_address; struct sockaddr_in con_address;
unsigned int con_addr_len;
char buffer[1024];
signal(10,handlerserver);
listen_socket = socket(2, SOCK_STREAM, 0);
bzero(&listen_address, sizeof(listen_address));
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = htonl(((unsigned int) 0x00000000));
listen_address.sin_addr.s_addr = listen_ip_address;
bind(listen_socket,(struct sockaddr *)&listen_address,sizeof(struct sockaddr));
listen(listen_socket, 10);
printf("Comenzamos a escuchar conexiones\n");
printf("mi pid es %d\n", getpid());
bzero(&con_address, sizeof(con_address));
socketpadre= accept(listen_socket, (struct sockaddr *)(&con_address),&con_addr_len);
printf("Conexion padre recibida");
while (1) {
bzero(&con_address, sizeof(con_address));
send(socketpadre,&msj,sizeof(msj),0);
comm_socket = accept(listen_socket, (struct sockaddr *)(&con_address),&con_addr_len);
printf("Conexión recibida\n");
system("df >logservidor.txt");
comparar_informar();
close(comm_socket);
}
close(listen_socket);
printf("Se desconectó\n");
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:
buffer
char [1024]


threadPromedio

original_code:
void *threadPromedio(void *idHilo)
{
 int i, marc = 0, jTemp, nroHilo;
 float random, max, min, acum = 0.;
 nroHilo = *((int *)idHilo);
 while (j < 23)
 {
  jTemp = j;
  for (i = 0; i < n; i++)
  {
   random = ((float)rand()/2147483647) * 100 + jTemp * 100;
   if (marc == 0)
   {
    max = random;
    min = random;
    marc = 1;
   }
   else if (random > max)
    max = random;
   else if (random < min)
    min = random;
   acum += random;
  }
  printf("HILO %d\nMáximo: %.4f\nMínimo: %.4f\nPromedio: %.4f\n", nroHilo, max, min, acum/n);
  marc = 0;
  acum = 0;
  sleep(1);
  j++;
 }
}

canonical_original_code:
void *threadPromedio(void *idHilo)
{
 int i; int marc = 0; int jTemp; int nroHilo;
 float random; float max; float min; float acum = 0.;
 nroHilo = *((int *)idHilo);
 while (j < 23)
 {
  jTemp = j;
  for (i = 0; i < n; i++)
  {
   random = ((float)rand()/2147483647) * 100 + jTemp * 100;
   if (marc == 0)
   {
    max = random;
    min = random;
    marc = 1;
   }
   else if (random > max)
    max = random;
   else if (random < min)
    min = random;
   acum += random;
  }
  printf("HILO %d\nMáximo: %.4f\nMínimo: %.4f\nPromedio: %.4f\n", nroHilo, max, min, acum/n);
  marc = 0;
  acum = 0;
  sleep(1);
  j++;
 }
}

variable_types:
idHilo
void *

variable_types: i int

variable_types: marc int

variable_types: jTemp int

variable_types: nroHilo int

variable_types: random float

variable_types: max float

variable_types: min float

variable_types: acum float

return_type: void *


activarThread

decompiled_code:
void __fastcall activarThread(int a1)
{
pthread_t newthread[2]; // [rsp+0h] [rbp-10h] BYREF

if ( a1 == 10 )
{
if ( j > 22 )
{
puts("No se pueden crear mas Threads");
}
else
{
++id;
pthread_create(newthread, 0LL, threadPromedio, &id);
}
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
pthread_t newthread[2]; // [rsp+0h] [rbp-10h] BYREF

if ( a1 == 10 )
{
if ( j > 22 )
{
puts("No se pueden crear mas Threads");
}
else
{
++id;
pthread_create(newthread, 0LL, threadPromedio, &id);
}
}
}

original_code:
void activarThread(int sig)
{
 int res;
 pthread_t hilo;
 if (sig == 10)
  if (j < 23)
  {
   id++;
   res = pthread_create(&hilo, ((void *)0), threadPromedio, (void *)&id);
  }
  else
   printf("No se pueden crear mas Threads\n");
}

canonical_original_code:
void activarThread(int sig)
{
 int res;
 unsigned long hilo;
 if (sig == 10)
  if (j < 23)
  {
   id++;
   res = pthread_create(&hilo, ((void *)0), threadPromedio, (void *)&id);
  }
  else
   printf("No se pueden crear mas Threads\n");
}

variable_types: sig int

variable_types: res int

variable_types:
hilo
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
unsigned int v4; // eax
unsigned int v5; // eax
int i; // ebp
int v8; // ebx
int v9; // eax
int v10; // eax
float v11; // xmm0_4
int v12; // ebp
float v13; // [rsp+4h] [rbp-24h]
float v14; // [rsp+8h] [rbp-20h]
float v15; // [rsp+Ch] [rbp-1Ch]

v3 = argv[1];
if ( !v3 )
{
puts("ERROR. Modo: ./EJ4 n (n=cantidad de numeros aleatorios a calcular en cada rango)");
exit(1);
}
n = atoi(v3);
v4 = getpid();
srand(v4);
signal(10, activarThread);
if ( n > 1000000 )
{
puts("Se debe pasar un N menor a 1000000");
exit(1);
}
v5 = getpid();
printf("PID: %d\n", v5);
for ( i = j; i <= 22; j = i )
{
v9 = n;
if ( n <= 0 )
{
v13 = 0.0;
}
else
{
v12 = 100 * i;
v11 = (float)((float)((float)rand() * 4.6566129e-10) * 100.0) + (float)v12;
v14 = v11;
v15 = v11;
v13 = 0.0;
v8 = 0;
while ( 1 )
{
v13 = v11 + v13;
++v8;
v9 = n;
if ( n <= v8 )
break;
v10 = rand();
v11 = (float)((float)((float)v10 * 4.6566129e-10) * 100.0) + (float)v12;
if ( v11 > v14 )
v14 = (float)((float)((float)v10 * 4.6566129e-10) * 100.0) + (float)v12;
else
v15 = fminf(v11, v15);
}
}
printf(aHilo0M, v14, v15, (float)(v13 / (float)v9));
sleep(1u);
i = j + 1;
}
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 int i, marc = 0, jTemp;
 float random, max, min, acum = 0.;
 if (argv[1]==((void *)0))
 {
  printf("ERROR. Modo: ./EJ4 n (n=cantidad de numeros aleatorios a calcular en cada rango)\n");
  exit(1);
 }
 n = atoi(argv[1]);
 srand(getpid());
 signal(10, activarThread);
 if (n <= 1000000)
 {
  printf ("PID: %d\n", getpid());
  while (j < 23)
  {
   jTemp = j;
   for (i = 0; i < n; i++)
   {
    random = ((float)rand()/2147483647) * 100 + jTemp * 100;
    if (marc == 0)
    {
     max = random;
     min = random;
     marc = 1;
    }
    else if (random > max)
     max = random;
    else if (random < min)
     min = random;
    acum += random;
   }
   printf("HILO 0\nMáximo: %.4f\nMínimo: %.4f\nPromedio: %.4f\n", max, min, acum/n);
   marc = 0;
   acum = 0;
   sleep(1);
   j++;
  }
 }
 else
 {
  printf("Se debe pasar un N menor a 1000000\n");
  exit(1);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i; int marc = 0; int jTemp;
 float random; float max; float min; float acum = 0.;
 if (argv[1]==((void *)0))
 {
  printf("ERROR. Modo: ./EJ4 n (n=cantidad de numeros aleatorios a calcular en cada rango)\n");
  exit(1);
 }
 n = atoi(argv[1]);
 srand(getpid());
 signal(10, activarThread);
 if (n <= 1000000)
 {
  printf ("PID: %d\n", getpid());
  while (j < 23)
  {
   jTemp = j;
   for (i = 0; i < n; i++)
   {
    random = ((float)rand()/2147483647) * 100 + jTemp * 100;
    if (marc == 0)
    {
     max = random;
     min = random;
     marc = 1;
    }
    else if (random > max)
     max = random;
    else if (random < min)
     min = random;
    acum += random;
   }
   printf("HILO 0\nMáximo: %.4f\nMínimo: %.4f\nPromedio: %.4f\n", max, min, acum/n);
   marc = 0;
   acum = 0;
   sleep(1);
   j++;
  }
 }
 else
 {
  printf("Se debe pasar un N menor a 1000000\n");
  exit(1);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void __fastcall __noreturn thread_pantalla(void *a1)
{
while ( !FIN_THREAD )
{
recv(caller_socket, &pint, 0xCuLL, 0);
if ( (unsigned int)(pint + 4) <= 0x10 )
{
pintar(pint, *((unsigned int *)&pint + 2));
}
else if ( (unsigned int)(pint - 20) <= 3 )
{
pintar_zona(pint, *((unsigned int *)&pint + 2));
actualizar_puntajes(pint, *((unsigned int *)&pint + 2));
}
else if ( (unsigned int)(pint - 30) <= 3 )
{
actualizar_puntajes(pint, *((unsigned int *)&pint + 2));
}
else if ( (unsigned int)(pint - 40) <= 3 )
{
pintar_puntajes(pint, *((unsigned int *)&pint + 2));
}
else
{
switch ( (_DWORD)pint )
{
case 'c':
terminar("HAS SALIDO DEL JUEGO.. PRESIONE UNA TECLA PARA CONTINUAR");
case 'b':
terminar("HUBO UN PROBLEMA CON EL SERVIDOR.. PRESIONE UNA TECLA PARA CONTINUAR");
case 'a':
terminar("GAME OVER.. PRESIONE UNA TECLA PARA CONTINUAR");
}
}
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
while ( !FIN_THREAD )
{
recv(caller_socket, &pint, 0xCuLL, 0);
if ( (unsigned int)(pint + 4) <= 0x10 )
{
pintar(pint, *((unsigned int *)&pint + 2));
}
else if ( (unsigned int)(pint - 20) <= 3 )
{
pintar_zona(pint, *((unsigned int *)&pint + 2));
actualizar_puntajes(pint, *((unsigned int *)&pint + 2));
}
else if ( (unsigned int)(pint - 30) <= 3 )
{
actualizar_puntajes(pint, *((unsigned int *)&pint + 2));
}
else if ( (unsigned int)(pint - 40) <= 3 )
{
pintar_puntajes(pint, *((unsigned int *)&pint + 2));
}
else
{
switch ( (_DWORD)pint )
{
case 'c':
func1("HAS SALIDO DEL JUEGO.. PRESIONE UNA TECLA PARA CONTINUAR");
case 'b':
func1("HUBO UN PROBLEMA CON EL SERVIDOR.. PRESIONE UNA TECLA PARA CONTINUAR");
case 'a':
func1("GAME OVER.. PRESIONE UNA TECLA PARA CONTINUAR");
}
}
}
pthread_exit(0LL);
}

original_code:
void *thread_pantalla(void)
{
 while(!FIN_THREAD)
 {
  recv(caller_socket, &pint,sizeof(t_pintar),0);
  if (pint.valor>=-4&&pint.valor<=12)
   pintar(pint);
  else if (pint.valor>=20&&pint.valor<=23)
  {
   pintar_zona(pint);
   actualizar_puntajes(pint);
  }
  else if (pint.valor>=30&&pint.valor<=33)
   actualizar_puntajes(pint);
  else if (pint.valor>=40&&pint.valor<=43)
   pintar_puntajes(pint);
  else if (pint.valor==99)
   terminar("HAS SALIDO DEL JUEGO.. PRESIONE UNA TECLA PARA CONTINUAR");
  else if (pint.valor==98)
   terminar("HUBO UN PROBLEMA CON EL SERVIDOR.. PRESIONE UNA TECLA PARA CONTINUAR");
  else if (pint.valor==97)
   terminar("GAME OVER.. PRESIONE UNA TECLA PARA CONTINUAR");
 }
 pthread_exit(0);
}

canonical_original_code:
void *thread_pantalla()
{
 while(!FIN_THREAD)
 {
  recv(caller_socket, &pint,sizeof(t_pintar),0);
  if (pint.valor>=-4&&pint.valor<=12)
   pintar(pint);
  else if (pint.valor>=20&&pint.valor<=23)
  {
   pintar_zona(pint);
   actualizar_puntajes(pint);
  }
  else if (pint.valor>=30&&pint.valor<=33)
   actualizar_puntajes(pint);
  else if (pint.valor>=40&&pint.valor<=43)
   pintar_puntajes(pint);
  else if (pint.valor==99)
   terminar("HAS SALIDO DEL JUEGO.. PRESIONE UNA TECLA PARA CONTINUAR");
  else if (pint.valor==98)
   terminar("HUBO UN PROBLEMA CON EL SERVIDOR.. PRESIONE UNA TECLA PARA CONTINUAR");
  else if (pint.valor==97)
   terminar("GAME OVER.. PRESIONE UNA TECLA PARA CONTINUAR");
 }
 pthread_exit(0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char v9; // [rsp+7h] [rbp-11h] BYREF
int v10; // [rsp+8h] [rbp-10h] BYREF
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

inicializar_pantalla(argc, argv, envp);
signal(2, handler);
signal(15, handler);
if ( !(unsigned int)leer_configuracion() )
{
puts("ERROR CONFIGURACION");
exit(1);
}
v3 = conectar_al_server((unsigned int)puerto_socket, &IPSERVER);
caller_socket = v3;
if ( v3 == -1 )
{
close(-1);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v5 = strlen(error1);
mvprintw(ALTO / 2 - 2, (ANCHO - v5) >> 1, error1);
v6 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v6) >> 1, creditos);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(2);
}
recv(v3, buf, 4uLL, 0);
if ( buf[0] == 4 )
{
v10 = 1;
send(caller_socket, &v10, 4uLL, 0);
close(caller_socket);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v7 = strlen(error2);
mvprintw(ALTO / 2 - 2, (ANCHO - v7) >> 1, error2);
v8 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v8) >> 1, creditos);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(2);
}
v10 = 0;
send(caller_socket, &v10, 4uLL, 0);
presentacion();
sleep(2u);
pthread_create(&IDpantalla, 0LL, thread_pantalla, 0LL);
while ( !FIN_THREAD )
{
v9 = wgetch(stdscr);
send(caller_socket, &v9, 4uLL, 0);
fflush(stdin);
}
pthread_join(IDpantalla, 0LL);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char v9; // [rsp+7h] [rbp-11h] BYREF
int v10; // [rsp+8h] [rbp-10h] BYREF
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

inicializar_pantalla(argc, argv, envp);
signal(2, handler);
signal(15, handler);
if ( !(unsigned int)func0() )
{
puts("ERROR CONFIGURACION");
exit(1);
}
v3 = conectar_al_server((unsigned int)puerto_socket, &IPSERVER);
caller_socket = v3;
if ( v3 == -1 )
{
close(-1);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v5 = strlen(error1);
mvprintw(ALTO / 2 - 2, (ANCHO - v5) >> 1, error1);
v6 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v6) >> 1, creditos);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(2);
}
recv(v3, buf, 4uLL, 0);
if ( buf[0] == 4 )
{
v10 = 1;
send(caller_socket, &v10, 4uLL, 0);
close(caller_socket);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v7 = strlen(error2);
mvprintw(ALTO / 2 - 2, (ANCHO - v7) >> 1, error2);
v8 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v8) >> 1, creditos);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(2);
}
v10 = 0;
send(caller_socket, &v10, 4uLL, 0);
presentacion();
sleep(2u);
pthread_create(&IDpantalla, 0LL, thread_pantalla, 0LL);
while ( !FIN_THREAD )
{
v9 = wgetch(stdscr);
send(caller_socket, &v9, 4uLL, 0);
fflush(stdin);
}
pthread_join(IDpantalla, 0LL);
endwin();
return 0;
}

original_code:
int main()
{
 int cant_player,lleno;
 char c;
 inicializar_pantalla();
 signal(2,((__sighandler_t) 1));
 signal(15,((__sighandler_t) 1));
 if(!leer_configuracion())
 {
  printf("ERROR CONFIGURACION\n");
  exit(1);
 }
 caller_socket=conectar_al_server(puerto_socket,IPSERVER);
 if (caller_socket==-1)
 {
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error1))/2,error1);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 recv(caller_socket,&cant_player,sizeof(int),0);
 if(cant_player == 4)
 {
  lleno = 1;
  send(caller_socket,&lleno,sizeof(int),0);
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error2))/2,error2);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 else
 {
  lleno = 0;
  send(caller_socket,&lleno,sizeof(int),0);
 }
 presentacion();
 sleep(2);
 pthread_create(&IDpantalla,((void *)0),(void*)&thread_pantalla,((void *)0));
 while(!FIN_THREAD)
 {
  c=wgetch(stdscr);
  send(caller_socket, &c,sizeof(int),0);
  fflush(stdin);
 }
 pthread_join(IDpantalla, ((void *)0));
 endwin();
 return 0;
}

canonical_original_code:
int main()
{
 int cant_player; int lleno;
 char c;
 inicializar_pantalla();
 signal(2,((void (*)(int)) 1));
 signal(15,((void (*)(int)) 1));
 if(!leer_configuracion())
 {
  printf("ERROR CONFIGURACION\n");
  exit(1);
 }
 caller_socket=conectar_al_server(puerto_socket,IPSERVER);
 if (caller_socket==-1)
 {
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error1))/2,error1);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 recv(caller_socket,&cant_player,sizeof(int),0);
 if(cant_player == 4)
 {
  lleno = 1;
  send(caller_socket,&lleno,sizeof(int),0);
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error2))/2,error2);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 else
 {
  lleno = 0;
  send(caller_socket,&lleno,sizeof(int),0);
 }
 presentacion();
 sleep(2);
 pthread_create(&IDpantalla,((void *)0),(void *)&thread_pantalla,((void *)0));
 while(!FIN_THREAD)
 {
  c=wgetch(stdscr);
  send(caller_socket, &c,sizeof(int),0);
  fflush(stdin);
 }
 pthread_join(IDpantalla, ((void *)0));
 endwin();
 return 0;
}

variable_types: lleno int

variable_types: c char


terminar

decompiled_code:
void __fastcall __noreturn terminar(char *a1)
{
size_t v1; // rax
size_t v2; // rax

FIN_THREAD = 1;
close(caller_socket);
wclear(stdscr);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v1 = strlen(a1);
mvprintw(ALTO / 2 - 2, (ANCHO - v1) >> 1, a1);
v2 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v2) >> 1, creditos);
wrefresh(stdscr);
pthread_cancel(IDpantalla);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(char *a1)
{
size_t v1; // rax
size_t v2; // rax

FIN_THREAD = 1;
close(caller_socket);
wclear(stdscr);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v1 = strlen(a1);
mvprintw(ALTO / 2 - 2, (ANCHO - v1) >> 1, a1);
v2 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v2) >> 1, creditos);
wrefresh(stdscr);
pthread_cancel(IDpantalla);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(0);
}

original_code:
void terminar(char *cad)
{
 FIN_THREAD=1;
 close(caller_socket);
 wclear(stdscr);
 wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
 wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
 mvprintw(ALTO/2-2,(ANCHO-strlen(cad))/2,cad);
 mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
 wrefresh(stdscr);
 pthread_cancel(IDpantalla);
 wgetch(stdscr);
 wclear(stdscr);
 wrefresh(stdscr);
 endwin();
 exit(0);
}

variable_types:
cad
char *


decompiled_code:
void __fastcall __noreturn rutina_hilo(void *a1)
{
int v1; // ebx
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v1 = socket(2, 1, 0);
v2.sa_family = 2;
*(_WORD *)v2.sa_data = _bswap_16(51244);
*(_DWORD *)&v2.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&v2.sa_data[6] = 0LL;
connect(v1, &v2, 0x10u);
system("df >log.txt && cat log.txt");
close(v1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
int v1; // ebx
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v1 = socket(2, 1, 0);
v2.sa_family = 2;
*(_WORD *)v2.sa_data = func1(51244);
*(_DWORD *)&v2.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&v2.sa_data[6] = 0LL;
connect(v1, &v2, 0x10u);
system("df >log.txt && cat log.txt");
close(v1);
pthread_exit(0LL);
}

original_code:
void* rutina_hilo(void *param)
{
int caller_socket = 0;
unsigned short int listen_port = 0;
unsigned long int listen_ip_address = 0;
struct sockaddr_in listen_address;
caller_socket = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
 system("df >log.txt && cat log.txt");
close(caller_socket);
pthread_exit(0);
}

canonical_original_code:
void *rutina_hilo(void *param)
{
int caller_socket = 0;
unsigned short listen_port = 0;
unsigned long listen_ip_address = 0;
struct sockaddr_in listen_address;
caller_socket = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
 system("df >log.txt && cat log.txt");
close(caller_socket);
pthread_exit(0);
}

variable_types:
param
void *

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


handler

decompiled_code:
void __fastcall handler(int a1)
{
if ( a1 == 10 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 10 )
exit(0);
}

original_code:
void handler (int S)
{
  if(S==10)
 {
   exit(0);
 }
}

canonical_original_code:
void handler(int S)
{
  if(S==10)
 {
   exit(0);
 }
}

variable_types: S int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
int v5; // eax
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

signal(10, handler);
v3 = socket(2, 1, 0);
v6.sa_family = 2;
*(_WORD *)v6.sa_data = _bswap_16(51244);
*(_DWORD *)&v6.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&v6.sa_data[6] = 0LL;
connect(v3, &v6, 0x10u);
v4 = getpid();
srand(v4);
while ( !msj )
{
recv(v3, &msj, 4uLL, 0);
v5 = rand();
sleep(v5 % 10 + 1);
if ( !msj )
{
if ( pthread_create(newthread, 0LL, (void *(*)(void *))rutina_hilo, 0LL) )
{
printf("\n Error al crear el hilo");
exit(1);
}
printf("\nHilo creado.\n ");
}
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
int v5; // eax
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

signal(10, handler);
v3 = socket(2, 1, 0);
v6.sa_family = 2;
*(_WORD *)v6.sa_data = func1(51244);
*(_DWORD *)&v6.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&v6.sa_data[6] = 0LL;
connect(v3, &v6, 0x10u);
v4 = getpid();
srand(v4);
while ( !msj )
{
recv(v3, &msj, 4uLL, 0);
v5 = rand();
sleep(v5 % 10 + 1);
if ( !msj )
{
if ( pthread_create(newthread, 0LL, (void *(*)(void *))rutina_hilo, 0LL) )
{
printf("\n Error al crear el hilo");
exit(1);
}
printf("\nHilo creado.\n ");
}
}
exit(0);
}

original_code:
int main(int argc, const char *argv[]) {
pthread_t hilo;
pid_t pid;
int caller_socket1 = 0;
unsigned short int listen_port = 0;
unsigned long int listen_ip_address = 0;
struct sockaddr_in listen_address;
signal(10,handler);
caller_socket1 = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket1, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
pid=getpid();
srand(pid);
while(!msj)
{ recv(caller_socket1,&msj,sizeof(msj),0);
 sleep(rand()%10+1);
   if(!msj)
   {
  if(pthread_create(&hilo,((void *)0),rutina_hilo,((void *)0))!=0)
  {
   printf("\n Error al crear el hilo");
   exit(1);
  }
      else
       printf("\nHilo creado.\n ");
   }
}
exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
unsigned long hilo;
int pid;
int caller_socket1 = 0;
unsigned short listen_port = 0;
unsigned long listen_ip_address = 0;
struct sockaddr_in listen_address;
signal(10,handler);
caller_socket1 = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket1, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
pid=getpid();
srand(pid);
while(!msj)
{ recv(caller_socket1,&msj,sizeof(msj),0);
 sleep(rand()%10+1);
   if(!msj)
   {
  if(pthread_create(&hilo,((void *)0),rutina_hilo,((void *)0))!=0)
  {
   printf("\n Error al crear el hilo");
   exit(1);
  }
      else
       printf("\nHilo creado.\n ");
   }
}
exit(0);
}

variable_types: pid int


sighandler

decompiled_code:
void sighandler()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void sighandler(int signum)
{
  return;
}

canonical_original_code:
void sighandler(int signum)
{
  return;
}

variable_types: signum int


recvicmp

decompiled_code:
__int64 __fastcall recvicmp(int fd, struct sockaddr *addr, __int16 a3, __int16 a4, struct timeval *a5)
{
int v7; // eax
int v8; // ebx
__int64 v9; // rax
__int16 *v10; // r14
char *v11; // rax
char buf[1036]; // [rsp+10h] [rbp-448h] BYREF
socklen_t addr_len[15]; // [rsp+41Ch] [rbp-3Ch] BYREF

signal(14, (__sighandler_t)sighandler);
siginterrupt(14, 1);
alarm(3u);
while ( 1 )
{
addr_len[0] = 16;
v7 = recvfrom(fd, buf, 0x400uLL, 0, addr, addr_len);
if ( v7 < 0 )
break;
if ( v7 <= 27 )
{
puts("error in receiving ip packet");
exit(1);
}
gettimeofday(a5, 0LL);
v8 = 4 * (buf[0] & 0xF);
if ( v8 <= 19 )
{
puts("ip header length is error");
exit(1);
}
v9 = v8 + 8;
if ( buf[v9 + 9] == 17 )
{
v10 = (__int16 *)&buf[((4 * buf[v9]) & 0x3C) + v9];
if ( _bswap_16(*v10) == a3 && _bswap_16(v10[1]) == a4 )
{
v11 = &buf[v8];
if ( *(_WORD *)v11 == 11 )
return 4294967294LL;
if ( *v11 == 3 )
return 0xFFFFFFFFLL;
}
}
}
if ( *__errno_location() != 4 )
exit(1);
return 4294967293LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, struct sockaddr *addr, __int16 a3, __int16 a4, struct timeval *a5)
{
int v7; // eax
int v8; // ebx
__int64 v9; // rax
__int16 *v10; // r14
char *v11; // rax
char buf[1036]; // [rsp+10h] [rbp-448h] BYREF
socklen_t addr_len[15]; // [rsp+41Ch] [rbp-3Ch] BYREF

signal(14, (__sighandler_t)sighandler);
siginterrupt(14, 1);
alarm(3u);
while ( 1 )
{
addr_len[0] = 16;
v7 = recvfrom(fd, buf, 0x400uLL, 0, addr, addr_len);
if ( v7 < 0 )
break;
if ( v7 <= 27 )
{
puts("error in receiving ip packet");
exit(1);
}
gettimeofday(a5, 0LL);
v8 = 4 * (buf[0] & 0xF);
if ( v8 <= 19 )
{
puts("ip header length is error");
exit(1);
}
v9 = v8 + 8;
if ( buf[v9 + 9] == 17 )
{
v10 = (__int16 *)&buf[((4 * buf[v9]) & 0x3C) + v9];
if ( func9(*v10) == a3 && func9(v10[1]) == a4 )
{
v11 = &buf[v8];
if ( *(_WORD *)v11 == 11 )
return 4294967294LL;
if ( *v11 == 3 )
return 0xFFFFFFFFLL;
}
}
}
if ( *__errno_location() != 4 )
exit(1);
return 4294967293LL;
}

original_code:
int recvicmp(int sockfd,
             struct sockaddr_in *hopaddr,
             unsigned short s_port,
             unsigned short d_port,
             struct timeval *tv)
{
   socklen_t socklen;
   char recv_buf[1024];
   int recv_len;
   struct iphdr *ip;
   struct udphdr *udp;
   struct icmp *icmp;
   int ip_len;
   int ip_len2;
   signal(14, sighandler);
   siginterrupt(14, 1);
   alarm(3);
   for(;;)
   {
     socklen = sizeof(struct sockaddr);
     recv_len = recvfrom(sockfd, recv_buf, 1024, 0,
               (struct sockaddr *)hopaddr, &socklen);
     if (recv_len < 0 )
     {
        if ((*__errno_location ()) == 4)
        {
           return -3;
        }
        else
        {
           exit(1);
        }
     }
     if (recv_len < 28)
     {
        printf("error in receiving ip packet\n");
        exit(1);
     }
     gettimeofday(tv, ((void *)0));
     ip = (struct iphdr *)recv_buf;
     ip_len = (ip->ihl) << 2;
     if (ip_len < 20)
     {
        printf("ip header length is error\n");
        exit(1);
     }
     icmp = (struct icmp *)(recv_buf + ip_len);
     ip = (struct iphdr *)(recv_buf + ip_len + sizeof(struct icmphdr));
     ip_len2 = ip->ihl << 2;
     udp = (struct udphdr *)(recv_buf + ip_len +
                            sizeof(struct icmphdr)+ ip_len2);
     if ((ip->protocol == IPPROTO_UDP) &&
          (ntohs(udp->source) == (s_port)) &&
          (ntohs(udp->dest) == (d_port)))
     {
       if ((icmp->icmp_type == 11) &&
           (icmp->icmp_code == 0))
       {
           return -2;
       }
       else if(icmp->icmp_type == 3)
       {
           return -1;
       }
     }
   }
   return 0;
}

canonical_original_code:
int recvicmp(int sockfd, struct sockaddr_in *hopaddr, unsigned short s_port, unsigned short d_port, struct timeval *tv)
{
   unsigned int socklen;
   char recv_buf[1024];
   int recv_len;
   struct iphdr *ip;
   struct udphdr *udp;
   struct icmp *icmp;
   int ip_len;
   int ip_len2;
   signal(14, sighandler);
   siginterrupt(14, 1);
   alarm(3);
   for(;;)
   {
     socklen = sizeof(struct sockaddr);
     recv_len = recvfrom(sockfd, recv_buf, 1024, 0,
               (struct sockaddr *)hopaddr, &socklen);
     if (recv_len < 0 )
     {
        if ((*__errno_location ()) == 4)
        {
           return -3;
        }
        else
        {
           exit(1);
        }
     }
     if (recv_len < 28)
     {
        printf("error in receiving ip packet\n");
        exit(1);
     }
     gettimeofday(tv, ((void *)0));
     ip = (struct iphdr *)recv_buf;
     ip_len = (ip->ihl) << 2;
     if (ip_len < 20)
     {
        printf("ip header length is error\n");
        exit(1);
     }
     icmp = (struct icmp *)(recv_buf + ip_len);
     ip = (struct iphdr *)(recv_buf + ip_len + sizeof(struct icmphdr));
     ip_len2 = ip->ihl << 2;
     udp = (struct udphdr *)(recv_buf + ip_len +
                            sizeof(struct icmphdr)+ ip_len2);
     if ((ip->protocol == IPPROTO_UDP) &&
          (ntohs(udp->source) == (s_port)) &&
          (ntohs(udp->dest) == (d_port)))
     {
       if ((icmp->icmp_type == 11) &&
           (icmp->icmp_code == 0))
       {
           return -2;
       }
       else if(icmp->icmp_type == 3)
       {
           return -1;
       }
     }
   }
   return 0;
}

variable_types: sockfd int

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

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types:
socklen
unsigned int

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

user_defined_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __glibc_reserved; unsigned short mtu; } frag; } un; }

user_defined_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }


trace

decompiled_code:
int __fastcall trace(__int64 a1)
{
__int16 v1; // bx
__int16 v2; // r14
int v3; // eax
int v4; // er12
int v5; // er15
int v6; // er13
__int64 v7; // rsi
int v8; // ebp
int v9; // ebx
const char *v10; // rax
__int16 v12; // [rsp+4h] [rbp-B4h]
int v13; // [rsp+Ch] [rbp-ACh]
char buf[16]; // [rsp+10h] [rbp-A8h] BYREF
struct timeval v15; // [rsp+20h] [rbp-98h] BYREF
struct timeval tv; // [rsp+30h] [rbp-88h] BYREF
struct sockaddr cp; // [rsp+40h] [rbp-78h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-68h] BYREF
struct sockaddr v19; // [rsp+60h] [rbp-58h] BYREF
int optval[15]; // [rsp+7Ch] [rbp-3Ch] BYREF

optval[0] = 0;
v1 = getpid() | 0x8000;
*(_QWORD *)&v19.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
v12 = v1;
*(_WORD *)addr.sa_data = _bswap_16(v1);
v19.sa_family = 2;
*(_DWORD *)&v19.sa_data[2] = HIDWORD(a1);
v2 = v1 + 200;
*(_WORD *)v19.sa_data = _bswap_16(v1 + 200);
v3 = socket(2, 2, 0);
if ( v3 == -1 )
{
perror("udp socket");
exit(1);
}
v4 = v3;
v5 = socket(2, 3, 1);
if ( v5 == -1 )
{
perror("recvfd");
exit(1);
}
if ( bind(v4, &addr, 0x10u) == -1 )
{
perror("bind");
exit(1);
}
optval[0] = 1;
v6 = 0;
v7 = 1LL;
while ( 2 )
{
printf("%2d ", v7);
fflush(stdout);
v8 = 3;
do
{
if ( setsockopt(v4, 0, 2, optval, 4u) == -1 )
{
perror("setsockopt");
exit(1);
}
gettimeofday(&tv, 0LL);
if ( sendto(v4, 0LL, 0LL, 0, &v19, 0x10u) == -1 )
{
perror("sendto");
exit(1);
}
v9 = recvicmp(v5, &cp, v12, v2, &v15);
alarm(0);
if ( v9 == -3 )
{
printf(" *");
LABEL_11:
if ( v9 != -2 && !v6 )
goto LABEL_13;
goto LABEL_19;
}
if ( v9 != -1 )
goto LABEL_11;
v6 = 1;
LABEL_19:
if ( *(_DWORD *)&cp.sa_data[2] != v13 )
{
v10 = inet_ntop(2, &cp.sa_data[2], buf, 0x10u);
printf(" %s", v10);
v13 = *(_DWORD *)&cp.sa_data[2];
}
timesub(&tv, &v15);
printf(" %3f ms", (double)SLODWORD(v15.tv_sec) * 1000.0 + (double)SLODWORD(v15.tv_usec) / 1000.0);
LABEL_13:
fflush(stdout);
--v8;
}
while ( v8 );
putchar(10);
v7 = (unsigned int)(optval[0] + 1);
optval[0] = v7;
if ( (int)v7 <= 30 && !v6 )
continue;
break;
}
close(v4);
return close(v5);
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
__int16 v1; // bx
__int16 v2; // r14
int v3; // eax
int v4; // er12
int v5; // er15
int v6; // er13
__int64 v7; // rsi
int v8; // ebp
int v9; // ebx
const char *v10; // rax
__int16 v12; // [rsp+4h] [rbp-B4h]
int v13; // [rsp+Ch] [rbp-ACh]
char buf[16]; // [rsp+10h] [rbp-A8h] BYREF
struct timeval v15; // [rsp+20h] [rbp-98h] BYREF
struct timeval tv; // [rsp+30h] [rbp-88h] BYREF
struct sockaddr cp; // [rsp+40h] [rbp-78h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-68h] BYREF
struct sockaddr v19; // [rsp+60h] [rbp-58h] BYREF
int optval[15]; // [rsp+7Ch] [rbp-3Ch] BYREF

optval[0] = 0;
v1 = getpid() | 0x8000;
*(_QWORD *)&v19.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func8(0);
v12 = v1;
*(_WORD *)addr.sa_data = func9(v1);
v19.sa_family = 2;
*(_DWORD *)&v19.sa_data[2] = HIDWORD(a1);
v2 = v1 + 200;
*(_WORD *)v19.sa_data = func9(v1 + 200);
v3 = socket(2, 2, 0);
if ( v3 == -1 )
{
perror("udp socket");
exit(1);
}
v4 = v3;
v5 = socket(2, 3, 1);
if ( v5 == -1 )
{
perror("recvfd");
exit(1);
}
if ( bind(v4, &addr, 0x10u) == -1 )
{
perror("bind");
exit(1);
}
optval[0] = 1;
v6 = 0;
v7 = 1LL;
while ( 2 )
{
printf("%2d ", v7);
fflush(stdout);
v8 = 3;
do
{
if ( setsockopt(v4, 0, 2, optval, 4u) == -1 )
{
perror("setsockopt");
exit(1);
}
gettimeofday(&tv, 0LL);
if ( sendto(v4, 0LL, 0LL, 0, &v19, 0x10u) == -1 )
{
perror("sendto");
exit(1);
}
v9 = func11(v5, &cp, v12, v2, &v15);
alarm(0);
if ( v9 == -3 )
{
printf(" *");
LABEL_11:
if ( v9 != -2 && !v6 )
goto LABEL_13;
goto LABEL_19;
}
if ( v9 != -1 )
goto LABEL_11;
v6 = 1;
LABEL_19:
if ( *(_DWORD *)&cp.sa_data[2] != v13 )
{
v10 = inet_ntop(2, &cp.sa_data[2], buf, 0x10u);
printf(" %s", v10);
v13 = *(_DWORD *)&cp.sa_data[2];
}
func10(&tv, &v15);
printf(" %3f ms", (double)SLODWORD(v15.tv_sec) * 1000.0 + (double)SLODWORD(v15.tv_usec) / 1000.0);
LABEL_13:
fflush(stdout);
--v8;
}
while ( v8 );
putchar(10);
v7 = (unsigned int)(optval[0] + 1);
optval[0] = v7;
if ( (int)v7 <= 30 && !v6 )
continue;
break;
}
close(v4);
return close(v5);
}

original_code:
void trace(struct sockaddr_in target_addr)
{
   int sockfd;
   int recvfd;
   int ttl = 0;
   int probe = 0;
   struct sockaddr_in udpaddr;
   struct sockaddr_in local_addr;
   struct sockaddr_in hopaddr;
   struct sockaddr_in oldaddr;
   struct timeval tv;
   struct timeval tv2;
   int code;
   int done = 0;
   unsigned short s_port;
   unsigned short d_port;
   char ip_str[16];
   s_port = (getpid() & 0xffff) | 0x8000;
   d_port = s_port + 200;
   bzero(&udpaddr, sizeof(struct sockaddr_in));
   bzero(&local_addr, sizeof(struct sockaddr_in));
   local_addr.sin_family = 2;
   local_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
   local_addr.sin_port = htons(s_port);
   udpaddr.sin_family = 2;
   udpaddr.sin_addr = target_addr.sin_addr;
   udpaddr.sin_port = htons(d_port);
   sockfd = socket(2, SOCK_DGRAM, 0);
   if (sockfd == -1)
   {
     perror("udp socket");
     exit(1);
   }
   recvfd = socket(2, SOCK_RAW, IPPROTO_ICMP);
   if (recvfd == -1)
   {
     perror("recvfd");
     exit(1);
   }
   if (bind(sockfd, (struct sockaddr *)&local_addr, sizeof(struct sockaddr)) == -1)
   {
     perror("bind");
     exit(1);
   }
   for (ttl = 1; ttl <= 30 && (done == 0); ttl++)
   {
      printf("%2d ",ttl);
      fflush(stdout);
      for (probe = 0; probe < 3; probe++)
      {
          if (setsockopt(sockfd, IPPROTO_IP, 2, &ttl, sizeof(int)) == -1)
          {
             perror("setsockopt");
             exit(1);
          }
         gettimeofday(&tv,((void *)0));
         if (sendto(sockfd, ((void *)0), 0, 0, (struct sockaddr *)&udpaddr,
                sizeof(struct sockaddr)) == -1)
         {
            perror("sendto");
            exit(1);
         }
         code = recvicmp(recvfd, &hopaddr, s_port, d_port, &tv2);
         alarm(0);
         if (code == -3 )
         {
            printf(" *");
         }
         if (code == -1 )
         {
            done = 1;
         }
         if ((code == -2) || (done == 1))
         {
             if (oldaddr.sin_addr.s_addr != hopaddr.sin_addr.s_addr)
             {
                printf(" %s",inet_ntop(2,
                                       &(hopaddr.sin_addr),
                                       ip_str, 16));
                memcpy(&oldaddr, &hopaddr,sizeof(struct sockaddr_in));
             }
             timesub(&tv, &tv2);
             printf(" %3f ms", tv2.tv_sec * 1000.0 + tv2.tv_usec / 1000.0);
         }
         code = 0;
         fflush(stdout);
      }
      printf("\n");
   }
   close(sockfd);
   close(recvfd);
}

canonical_original_code:
void trace(struct sockaddr_in target_addr)
{
   int sockfd;
   int recvfd;
   int ttl = 0;
   int probe = 0;
   struct sockaddr_in udpaddr;
   struct sockaddr_in local_addr;
   struct sockaddr_in hopaddr;
   struct sockaddr_in oldaddr;
   struct timeval tv;
   struct timeval tv2;
   int code;
   int done = 0;
   unsigned short s_port;
   unsigned short d_port;
   char ip_str[16];
   s_port = (getpid() & 0xffff) | 0x8000;
   d_port = s_port + 200;
   bzero(&udpaddr, sizeof(struct sockaddr_in));
   bzero(&local_addr, sizeof(struct sockaddr_in));
   local_addr.sin_family = 2;
   local_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
   local_addr.sin_port = htons(s_port);
   udpaddr.sin_family = 2;
   udpaddr.sin_addr = target_addr.sin_addr;
   udpaddr.sin_port = htons(d_port);
   sockfd = socket(2, SOCK_DGRAM, 0);
   if (sockfd == -1)
   {
     perror("udp socket");
     exit(1);
   }
   recvfd = socket(2, SOCK_RAW, IPPROTO_ICMP);
   if (recvfd == -1)
   {
     perror("recvfd");
     exit(1);
   }
   if (bind(sockfd, (struct sockaddr *)&local_addr, sizeof(struct sockaddr)) == -1)
   {
     perror("bind");
     exit(1);
   }
   for (ttl = 1; ttl <= 30 && (done == 0); ttl++)
   {
      printf("%2d ",ttl);
      fflush(stdout);
      for (probe = 0; probe < 3; probe++)
      {
          if (setsockopt(sockfd, IPPROTO_IP, 2, &ttl, sizeof(int)) == -1)
          {
             perror("setsockopt");
             exit(1);
          }
         gettimeofday(&tv,((void *)0));
         if (sendto(sockfd, ((void *)0), 0, 0, (struct sockaddr *)&udpaddr,
                sizeof(struct sockaddr)) == -1)
         {
            perror("sendto");
            exit(1);
         }
         code = recvicmp(recvfd, &hopaddr, s_port, d_port, &tv2);
         alarm(0);
         if (code == -3 )
         {
            printf(" *");
         }
         if (code == -1 )
         {
            done = 1;
         }
         if ((code == -2) || (done == 1))
         {
             if (oldaddr.sin_addr.s_addr != hopaddr.sin_addr.s_addr)
             {
                printf(" %s",inet_ntop(2,
                                       &(hopaddr.sin_addr),
                                       ip_str, 16));
                memcpy(&oldaddr, &hopaddr,sizeof(struct sockaddr_in));
             }
             timesub(&tv, &tv2);
             printf(" %3f ms", tv2.tv_sec * 1000.0 + tv2.tv_usec / 1000.0);
         }
         code = 0;
         fflush(stdout);
      }
      printf("\n");
   }
   close(sockfd);
   close(recvfd);
}

variable_types: recvfd int

variable_types: ttl int

variable_types: probe int

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: code int

variable_types: done int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct hostent *v3; // rax
const char *v4; // rdx
char v6[16]; // [rsp+0h] [rbp-28h] BYREF
__int128 cp; // [rsp+10h] [rbp-18h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage %s <hostname>\n", *argv);
exit(1);
}
v3 = gethostbyname(argv[1]);
if ( !v3 )
{
perror("gethostbyname");
exit(1);
}
cp = 2uLL;
*(_QWORD *)((char *)&cp + 4) = **(unsigned int **)v3->h_addr_list;
v4 = inet_ntop(2, (char *)&cp + 4, v6, 0x10u);
if ( !v4 )
{
perror("inet_ntop");
exit(1);
}
printf("traceroute to %s (%s), %d hops max, %d byte packets\n", argv[1], v4, 30LL, 28LL);
trace(cp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct hostent *v3; // rax
const char *v4; // rdx
char v6[16]; // [rsp+0h] [rbp-28h] BYREF
__int128 cp; // [rsp+10h] [rbp-18h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage %s <hostname>\n", *argv);
exit(1);
}
v3 = gethostbyname(argv[1]);
if ( !v3 )
{
perror("gethostbyname");
exit(1);
}
cp = 2uLL;
*(_QWORD *)((char *)&cp + 4) = **(unsigned int **)v3->h_addr_list;
v4 = inet_ntop(2, (char *)&cp + 4, v6, 0x10u);
if ( !v4 )
{
perror("inet_ntop");
exit(1);
}
printf("traceroute to %s (%s), %d hops max, %d byte packets\n", argv[1], v4, 30LL, 28LL);
func12(cp);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
   struct hostent *host;
   struct sockaddr_in target_addr;
   char ip_str[16];
   const char *p;
   if (argc != 2)
   {
      fprintf(stderr, "Usage %s <hostname>\n", argv[0]);
      exit(1);
   }
   if ((host = gethostbyname(argv[1])) == ((void *)0))
   {
     perror("gethostbyname");
     exit(1);
   }
   bzero(&target_addr, sizeof(struct sockaddr_in));
   target_addr.sin_family = 2;
   target_addr.sin_addr = *(struct in_addr *)(host->h_addr_list[0]);
   p = inet_ntop(2, &target_addr.sin_addr, ip_str, 16);
   if (p == ((void *)0)){
     perror("inet_ntop");
     exit(1);
   }
   printf("traceroute to %s (%s), %d hops max, %d byte packets\n",
    argv[1], p, 30, sizeof(struct iphdr) + sizeof(struct udphdr));
   trace(target_addr);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   struct hostent *host;
   struct sockaddr_in target_addr;
   char ip_str[16];
   char *p;
   if (argc != 2)
   {
      fprintf(stderr, "Usage %s <hostname>\n", argv[0]);
      exit(1);
   }
   if ((host = gethostbyname(argv[1])) == ((void *)0))
   {
     perror("gethostbyname");
     exit(1);
   }
   bzero(&target_addr, sizeof(struct sockaddr_in));
   target_addr.sin_family = 2;
   target_addr.sin_addr = *(struct in_addr *)(host->h_addr_list[0]);
   p = inet_ntop(2, &target_addr.sin_addr, ip_str, 16);
   if (p == ((void *)0)){
     perror("inet_ntop");
     exit(1);
   }
   printf("traceroute to %s (%s), %d hops max, %d byte packets\n",
    argv[1], p, 30, sizeof(struct iphdr) + sizeof(struct udphdr));
   trace(target_addr);
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

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

user_defined_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; }


decompiled_code:
void __fastcall __noreturn client_handler(void *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
int v3; // ebp
size_t v4; // rax
pthread_mutex_t v5; // [rsp+0h] [rbp-458h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

pthread_mutex_init(&v5, 0LL);
while ( recv((int)a1, s, 0x400uLL, 0) > 0 )
{
printf("receive message: %s\n", s);
pthread_mutex_lock(&v5);
if ( max_index >= 0 )
{
v2 = 0LL;
do
{
v3 = client[v2];
if ( v3 != (_DWORD)a1 && v3 >= 0 )
{
v4 = strlen(s);
send(v3, s, v4 + 1, 0);
}
++v2;
}
while ( max_index >= (int)v2 );
}
pthread_mutex_unlock(&v5);
}
close((int)a1);
pthread_mutex_lock(&v5);
if ( max_index > 0 )
{
v1 = 0LL;
while ( client[v1] != (_DWORD)a1 )
{
if ( ++v1 == max_index )
goto LABEL_8;
}
client[(int)v1] = -1;
}
LABEL_8:
pthread_mutex_unlock(&v5);
printf("%d connection finished\n", (unsigned int)a1);
pthread_mutex_destroy(&v5);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
int v3; // ebp
size_t v4; // rax
pthread_mutex_t v5; // [rsp+0h] [rbp-458h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

pthread_mutex_init(&v5, 0LL);
while ( recv((int)a1, s, 0x400uLL, 0) > 0 )
{
printf("receive message: %s\n", s);
pthread_mutex_lock(&v5);
if ( max_index >= 0 )
{
v2 = 0LL;
do
{
v3 = client[v2];
if ( v3 != (_DWORD)a1 && v3 >= 0 )
{
v4 = strlen(s);
send(v3, s, v4 + 1, 0);
}
++v2;
}
while ( max_index >= (int)v2 );
}
pthread_mutex_unlock(&v5);
}
close((int)a1);
pthread_mutex_lock(&v5);
if ( max_index > 0 )
{
v1 = 0LL;
while ( client[v1] != (_DWORD)a1 )
{
if ( ++v1 == max_index )
goto LABEL_8;
}
client[(int)v1] = -1;
}
LABEL_8:
pthread_mutex_unlock(&v5);
printf("%d connection finished\n", (unsigned int)a1);
pthread_mutex_destroy(&v5);
pthread_exit(0LL);
}

original_code:
void *client_handler(void *arg)
{
    int i;
    char msg_buf[1024];
    int connect_socket = (int)arg;
    pthread_mutex_t lock;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        if (recv(connect_socket, msg_buf, 1024, 0) <= 0)
        {
            close(connect_socket);
            pthread_mutex_lock(&lock);
            for (i = 0; i < max_index; i++)
            {
                if (client[i] == connect_socket)
                {
                    client[i] = -1;
                    break;
                }
            }
            pthread_mutex_unlock(&lock);
            printf("%d connection finished\n", connect_socket);
            pthread_mutex_destroy(&lock);
            pthread_exit(((void *)0));
        }
        else
        {
            printf("receive message: %s\n", msg_buf);
            pthread_mutex_lock(&lock);
            for (i = 0; i <= max_index; i++)
            {
                if (client[i] >= 0 && client[i] != connect_socket)
                {
                    send(client[i], msg_buf, strlen(msg_buf) + 1, 0);
                }
            }
            pthread_mutex_unlock(&lock);
        }
    }
}

canonical_original_code:
void *client_handler(void *arg)
{
    int i;
    char msg_buf[1024];
    int connect_socket = (int)arg;
    union pthread_mutex_t lock;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        if (recv(connect_socket, msg_buf, 1024, 0) <= 0)
        {
            close(connect_socket);
            pthread_mutex_lock(&lock);
            for (i = 0; i < max_index; i++)
            {
                if (client[i] == connect_socket)
                {
                    client[i] = -1;
                    break;
                }
            }
            pthread_mutex_unlock(&lock);
            printf("%d connection finished\n", connect_socket);
            pthread_mutex_destroy(&lock);
            pthread_exit(((void *)0));
        }
        else
        {
            printf("receive message: %s\n", msg_buf);
            pthread_mutex_lock(&lock);
            for (i = 0; i <= max_index; i++)
            {
                if (client[i] >= 0 && client[i] != connect_socket)
                {
                    send(client[i], msg_buf, strlen(msg_buf) + 1, 0);
                }
            }
            pthread_mutex_unlock(&lock);
        }
    }
}

variable_types:
arg
void *

variable_types: i int

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

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:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int16 v4; // ax
unsigned __int16 v5; // ax
int *v6; // rax
unsigned int v7; // eax
int v8; // ebx
__int64 v9; // rax
int v10; // edx
char v11[16]; // [rsp+0h] [rbp-A8h] BYREF
pthread_mutex_t mutex; // [rsp+10h] [rbp-98h] BYREF
pthread_t newthread; // [rsp+38h] [rbp-70h] BYREF
struct sockaddr cp; // [rsp+40h] [rbp-68h] BYREF
socklen_t len; // [rsp+5Ch] [rbp-4Ch] BYREF
struct sockaddr v16; // [rsp+60h] [rbp-48h] BYREF
socklen_t addr_len; // [rsp+7Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-28h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage: %s port\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("socket error");
exit(1);
}
*(_DWORD *)&addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[10] = 0;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
v4 = atoi(argv[1]);
*(_WORD *)addr.sa_data = _bswap_16(v4);
if ( bind(v3, &addr, 0x10u) == -1 )
{
perror("bind error");
exit(1);
}
if ( listen(v3, 10) == -1 )
{
perror("listen error");
exit(1);
}
len = 16;
if ( getsockname(v3, &cp, &len) == -1 )
{
perror("getsockname error");
exit(1);
}
inet_ntop(2, &cp.sa_data[2], v11, 0x10u);
v5 = _bswap_16(*(__int16 *)cp.sa_data);
printf("server is listenning at %s:%d\n", v11, v5);
v6 = client;
do
*v6++ = -1;
while ( v6 != &max_index );
max_index = -1;
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
addr_len = 16;
v7 = accept(v3, &v16, &addr_len);
v8 = v7;
if ( v7 == -1 )
{
perror("accept error");
exit(1);
}
printf("%d connection begin\n", v7);
pthread_mutex_lock(&mutex);
v9 = 0LL;
while ( 1 )
{
v10 = v9;
if ( client[v9] < 0 )
break;
v10 = ++v9;
if ( v9 == 100 )
goto LABEL_16;
}
client[(int)v9] = v8;
LABEL_16:
if ( max_index < v10 )
max_index = v10;
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, (void *(*)(void *))client_handler, (void *)v8);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int16 v4; // ax
unsigned __int16 v5; // ax
int *v6; // rax
unsigned int v7; // eax
int v8; // ebx
__int64 v9; // rax
int v10; // edx
char v11[16]; // [rsp+0h] [rbp-A8h] BYREF
pthread_mutex_t mutex; // [rsp+10h] [rbp-98h] BYREF
pthread_t newthread; // [rsp+38h] [rbp-70h] BYREF
struct sockaddr cp; // [rsp+40h] [rbp-68h] BYREF
socklen_t len; // [rsp+5Ch] [rbp-4Ch] BYREF
struct sockaddr v16; // [rsp+60h] [rbp-48h] BYREF
socklen_t addr_len; // [rsp+7Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-28h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage: %s port\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("socket error");
exit(1);
}
*(_DWORD *)&addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[10] = 0;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func8(0);
v4 = atoi(argv[1]);
*(_WORD *)addr.sa_data = func9(v4);
if ( bind(v3, &addr, 0x10u) == -1 )
{
perror("bind error");
exit(1);
}
if ( listen(v3, 10) == -1 )
{
perror("listen error");
exit(1);
}
len = 16;
if ( getsockname(v3, &cp, &len) == -1 )
{
perror("getsockname error");
exit(1);
}
inet_ntop(2, &cp.sa_data[2], v11, 0x10u);
v5 = func9(*(__int16 *)cp.sa_data);
printf("server is listenning at %s:%d\n", v11, v5);
v6 = client;
do
*v6++ = -1;
while ( v6 != &max_index );
max_index = -1;
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
addr_len = 16;
v7 = accept(v3, &v16, &addr_len);
v8 = v7;
if ( v7 == -1 )
{
perror("accept error");
exit(1);
}
printf("%d connection begin\n", v7);
pthread_mutex_lock(&mutex);
v9 = 0LL;
while ( 1 )
{
v10 = v9;
if ( client[v9] < 0 )
break;
v10 = ++v9;
if ( v9 == 100 )
goto LABEL_16;
}
client[(int)v9] = v8;
LABEL_16:
if ( max_index < v10 )
max_index = v10;
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, (void *(*)(void *))client_handler, (void *)v8);
}
}

original_code:
int main(int argc, char *argv[])
{
    int listen_socket;
    int connect_socket;
    struct sockaddr_in serv_addr;
    socklen_t client_addr_len;
    struct sockaddr_in client_addr;
    socklen_t serv_disp_addr_len;
    struct sockaddr_in serv_disp_addr;
    pthread_t ntid;
    pthread_mutex_t lock;
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s port\n", argv[0]);
        exit(1);
    }
    if ((listen_socket = socket(2, SOCK_STREAM, 0)) == -1)
    {
        perror("socket error");
        exit(1);
    }
    bzero(&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    serv_addr.sin_port = htons(atoi(argv[1]));
    if (bind(listen_socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
    {
        perror("bind error");
        exit(1);
    }
    if (listen(listen_socket, 10) == -1)
    {
        perror("listen error");
        exit(1);
    }
    serv_disp_addr_len = sizeof(serv_disp_addr);
    if (getsockname(listen_socket, (struct sockaddr *)&serv_disp_addr, &serv_disp_addr_len) == -1)
    {
        perror("getsockname error");
        exit(1);
    }
    char serv_disp_addr_str[16];
    inet_ntop(2, &serv_disp_addr.sin_addr, serv_disp_addr_str, 16);
    printf("server is listenning at %s:%d\n", serv_disp_addr_str, ntohs(serv_disp_addr.sin_port));
    int i;
    for (i = 0; i < 100; i++)
    {
        client[i] = -1;
    }
    max_index = -1;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        client_addr_len = sizeof(client_addr);
        if ((connect_socket = accept(listen_socket, (struct sockaddr *)&client_addr, &client_addr_len)) == -1)
        {
            perror("accept error");
            exit(1);
        }
        printf("%d connection begin\n", connect_socket);
        pthread_mutex_lock(&lock);
        for (i = 0; i < 100; i++)
        {
            if (client[i] < 0)
            {
                client[i] = connect_socket;
                break;
            }
        }
        if (i > max_index)
        {
            max_index = i;
        }
        pthread_mutex_unlock(&lock);
        pthread_create(&ntid, ((void *)0), client_handler, (void *)connect_socket);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int listen_socket;
    int connect_socket;
    struct sockaddr_in serv_addr;
    unsigned int client_addr_len;
    struct sockaddr_in client_addr;
    unsigned int serv_disp_addr_len;
    struct sockaddr_in serv_disp_addr;
    unsigned long ntid;
    union pthread_mutex_t lock;
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s port\n", argv[0]);
        exit(1);
    }
    if ((listen_socket = socket(2, SOCK_STREAM, 0)) == -1)
    {
        perror("socket error");
        exit(1);
    }
    bzero(&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    serv_addr.sin_port = htons(atoi(argv[1]));
    if (bind(listen_socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
    {
        perror("bind error");
        exit(1);
    }
    if (listen(listen_socket, 10) == -1)
    {
        perror("listen error");
        exit(1);
    }
    serv_disp_addr_len = sizeof(serv_disp_addr);
    if (getsockname(listen_socket, (struct sockaddr *)&serv_disp_addr, &serv_disp_addr_len) == -1)
    {
        perror("getsockname error");
        exit(1);
    }
    char serv_disp_addr_str[16];
    inet_ntop(2, &serv_disp_addr.sin_addr, serv_disp_addr_str, 16);
    printf("server is listenning at %s:%d\n", serv_disp_addr_str, ntohs(serv_disp_addr.sin_port));
    int i;
    for (i = 0; i < 100; i++)
    {
        client[i] = -1;
    }
    max_index = -1;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        client_addr_len = sizeof(client_addr);
        if ((connect_socket = accept(listen_socket, (struct sockaddr *)&client_addr, &client_addr_len)) == -1)
        {
            perror("accept error");
            exit(1);
        }
        printf("%d connection begin\n", connect_socket);
        pthread_mutex_lock(&lock);
        for (i = 0; i < 100; i++)
        {
            if (client[i] < 0)
            {
                client[i] = connect_socket;
                break;
            }
        }
        if (i > max_index)
        {
            max_index = i;
        }
        pthread_mutex_unlock(&lock);
        pthread_create(&ntid, ((void *)0), client_handler, (void *)connect_socket);
    }
    return 0;
}

variable_types:
ntid
unsigned long

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


repo: joewing/csort

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rbx
int v5; // ebp
void (__fastcall *v6)(void *, _QWORD); // r14
void *v7; // r12
int v8; // ebx
int v9; // ebp
const char **v10; // rbx
int result; // eax
unsigned int *v12; // rbp
__int64 v13; // rbx

if ( argc == 2 )
{
v3 = argv[1];
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !strcmp(v3, (&ALGORITHMS)[2 * v4]) )
break;
v5 = ++v4;
if ( v4 == 8 )
{
v6 = 0LL;
goto LABEL_6;
}
}
v6 = (void (__fastcall *)(void *, _QWORD))*(&off_4020A8 + 2 * (int)v4);
LABEL_6:
if ( v5 == 8 )
{
printf("ERROR: unknown algorithm specified: %s\n", v3);
result = -1;
}
else
{
v7 = malloc(0x200uLL);
v8 = 0;
v9 = 128;
while ( (unsigned int)__isoc99_fscanf() == 1 )
{
if ( v9 <= v8 + 1 )
{
v9 *= 2;
v7 = realloc(v7, 4LL * v9);
}
++v8;
}
v6(v7, (unsigned int)v8);
if ( v8 > 0 )
{
v12 = (unsigned int *)v7;
v13 = (__int64)v7 + 4 * (unsigned int)(v8 - 1) + 4;
do
printf("%d\n", *v12++);
while ( v12 != (unsigned int *)v13 );
}
free(v7);
result = 0;
}
}
else
{
printf("usage: %s <algorithm>\n", *argv);
puts("algorithms:");
v10 = (const char **)&ALGORITHMS;
do
{
printf(" %s\n", *v10);
v10 += 2;
}
while ( v10 != (const char **)&_GNU_EH_FRAME_HDR );
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
   SortFunc func = ((void *)0);
   int *data = ((void *)0);
   int max_count = 128;
   int count = 0;
   int i;
   if(argc != 2) {
      printf("usage: %s <algorithm>\n", argv[0]);
      printf("algorithms:\n");
      for(i = 0; i < ALGORITHM_COUNT; i++) {
         printf("   %s\n", ALGORITHMS[i].name);
      }
      return -1;
   }
   for(i = 0; i < ALGORITHM_COUNT; i++) {
      if(!strcmp(argv[1], ALGORITHMS[i].name)) {
         func = ALGORITHMS[i].func;
         break;
      }
   }
   if(i == ALGORITHM_COUNT) {
      printf("ERROR: unknown algorithm specified: %s\n", argv[1]);
      return -1;
   }
   data = (int*)malloc(sizeof(int) * max_count);
   for(;;) {
      if(count >= max_count) {
         max_count *= 2;
         data = (int*)realloc(data, sizeof(int) * max_count);
      }
      if(fscanf(stdin, " %d", &data[count]) != 1) {
         break;
      }
      count += 1;
   }
   (func)(data, count);
   for(i = 0; i < count; i++) {
      printf("%d\n", data[i]);
   }
   free(data);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   void (*func)(int *array, int size) = ((void *)0);
   int *data = ((void *)0);
   int max_count = 128;
   int count = 0;
   int i;
   if(argc != 2) {
      printf("usage: %s <algorithm>\n", argv[0]);
      printf("algorithms:\n");
      for(i = 0; i < ALGORITHM_COUNT; i++) {
         printf("   %s\n", ALGORITHMS[i].name);
      }
      return -1;
   }
   for(i = 0; i < ALGORITHM_COUNT; i++) {
      if(!strcmp(argv[1], ALGORITHMS[i].name)) {
         func = ALGORITHMS[i].func;
         break;
      }
   }
   if(i == ALGORITHM_COUNT) {
      printf("ERROR: unknown algorithm specified: %s\n", argv[1]);
      return -1;
   }
   data = (int *)malloc(sizeof(int) * max_count);
   for(;;) {
      if(count >= max_count) {
         max_count *= 2;
         data = (int *)realloc(data, sizeof(int) * max_count);
      }
      if(fscanf(stdin, " %d", &data[count]) != 1) {
         break;
      }
      count += 1;
   }
   (func)(data, count);
   for(i = 0; i < count; i++) {
      printf("%d\n", data[i]);
   }
   free(data);
   return 0;
}

variable_types:
func
void (*)(int *array, int size)

variable_types:
data
int *

variable_types: count int


ldb

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

result = (unsigned __int8)memory[(unsigned __int16)operand];
regb = memory[(unsigned __int16)operand];
return result;
}

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

result = (unsigned __int8)memory[(unsigned __int16)operand];
regb = memory[(unsigned __int16)operand];
return result;
}

original_code:
static void ldb() {
   regb = memory[operand];
}


ldc

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

result = (unsigned __int8)memory[(unsigned __int16)operand];
regc = memory[(unsigned __int16)operand];
return result;
}

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

result = (unsigned __int8)memory[(unsigned __int16)operand];
regc = memory[(unsigned __int16)operand];
return result;
}

original_code:
static void ldc() {
   regc = memory[operand];
}