main

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

pthread_mutex_init(&mutexListaNuevos, 0LL);
pthread_mutex_init(&mutexListaReanudados, 0LL);
pthread_mutex_init(&mutexListaSuspendidos, 0LL);
pthread_mutex_init(&mutexListaBloqueados, 0LL);
pthread_mutex_init(&mutexListaFinQuantum, 0LL);
pthread_mutex_init(&mutexListaFinIO, 0LL);
pthread_mutex_init(&mutexListaListos, 0LL);
pthread_mutex_init(&mutexListaDemorados, 0LL);
sem_ej = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_ej, 0, 0);
sem_sts = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_sts, 0, 0);
sem_procer = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_procer, 0, 0);
sem_io = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_io, 0, 0);
sem_lts_suspendido = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_lts_suspendido, 0, 0);
sem_lts_demorado = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_lts_demorado, 0, 0);
pthread_mutex_init(&mutexVarMaxMMP, 0LL);
pthread_mutex_init(&mutexVarMaxMPS, 0LL);
pthread_mutex_init(&mutexVarMMP, 0LL);
pthread_mutex_init(&mutexVarMPS, 0LL);
pthread_mutex_init(&mutexVarLPL, 0LL);
pthread_mutex_init(&mutexVarLPN, 0LL);
pthread_mutex_init(&mutexVarLPR, 0LL);
pthread_mutex_init(&mutexVarFinQuantum, 0LL);
pthread_mutex_init(&mutexVarFinIO, 0LL);
pthread_mutex_init(&mutexVarSuspendido, 0LL);
pthread_mutex_init(&mutexVarEsperaEstandar, 0LL);
pthread_mutex_init(&mutexVarCantIOTDisponibles, 0LL);
pthread_mutex_init(&mutexVarAlfa, 0LL);
pthread_mutex_init(&mutexVarCantInstruccionesEjecutadas, 0LL);
logx(1LL, "HILO", 1244LL, "tipo", "log");
cargar_archivo_configuracion();
puts("Creando hilo de LTS");
pthread_create(&v4, 0LL, (void *(*)(void *))&LTS_funcion, 0LL);
puts("Creando hilo de STS");
pthread_create(&newthread, 0LL, (void *(*)(void *))&STS_funcion, 0LL);
puts("Creando hilo de PROCER");
pthread_create(&v6, 0LL, (void *(*)(void *))&PROCER_funcion, 0LL);
if ( cantidad_hilos_iot )
{
v3 = 0;
do
{
printf("Creando hilo de IOT numero:%d\n", ++v3);
pthread_create(v7, 0LL, (void *(*)(void *))&IOT_funcion, 0LL);
}
while ( cantidad_hilos_iot > v3 );
}
while ( 1 )
{
comprobar_archivo_configuracion();
signal(10, (__sighandler_t)SIGhandler);
sleep(1u);
}
}

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

pthread_mutex_init(&mutexListaNuevos, 0LL);
pthread_mutex_init(&mutexListaReanudados, 0LL);
pthread_mutex_init(&mutexListaSuspendidos, 0LL);
pthread_mutex_init(&mutexListaBloqueados, 0LL);
pthread_mutex_init(&mutexListaFinQuantum, 0LL);
pthread_mutex_init(&mutexListaFinIO, 0LL);
pthread_mutex_init(&mutexListaListos, 0LL);
pthread_mutex_init(&mutexListaDemorados, 0LL);
sem_ej = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_ej, 0, 0);
sem_sts = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_sts, 0, 0);
sem_procer = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_procer, 0, 0);
sem_io = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_io, 0, 0);
sem_lts_suspendido = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_lts_suspendido, 0, 0);
sem_lts_demorado = (__int64)malloc(0x20uLL);
sem_init((sem_t *)sem_lts_demorado, 0, 0);
pthread_mutex_init(&mutexVarMaxMMP, 0LL);
pthread_mutex_init(&mutexVarMaxMPS, 0LL);
pthread_mutex_init(&mutexVarMMP, 0LL);
pthread_mutex_init(&mutexVarMPS, 0LL);
pthread_mutex_init(&mutexVarLPL, 0LL);
pthread_mutex_init(&mutexVarLPN, 0LL);
pthread_mutex_init(&mutexVarLPR, 0LL);
pthread_mutex_init(&mutexVarFinQuantum, 0LL);
pthread_mutex_init(&mutexVarFinIO, 0LL);
pthread_mutex_init(&mutexVarSuspendido, 0LL);
pthread_mutex_init(&mutexVarEsperaEstandar, 0LL);
pthread_mutex_init(&mutexVarCantIOTDisponibles, 0LL);
pthread_mutex_init(&mutexVarAlfa, 0LL);
pthread_mutex_init(&mutexVarCantInstruccionesEjecutadas, 0LL);
logx(1LL, "HILO", 1244LL, "tipo", "log");
func2();
puts("Creando hilo de LTS");
pthread_create(&v4, 0LL, (void *(*)(void *))&LTS_funcion, 0LL);
puts("Creando hilo de STS");
pthread_create(&newthread, 0LL, (void *(*)(void *))&STS_funcion, 0LL);
puts("Creando hilo de PROCER");
pthread_create(&v6, 0LL, (void *(*)(void *))&PROCER_funcion, 0LL);
if ( cantidad_hilos_iot )
{
v3 = 0;
do
{
printf("Creando hilo de IOT numero:%d\n", ++v3);
pthread_create(v7, 0LL, (void *(*)(void *))&IOT_funcion, 0LL);
}
while ( cantidad_hilos_iot > v3 );
}
while ( 1 )
{
func1();
signal(10, (__sighandler_t)SIGhandler);
sleep(1u);
}
}

original_code:
int main(int argc, char *argv[])
{
   int i;
   pthread_t LTS_hilo;
   pthread_t STS_hilo;
   pthread_t PROCER_hilo;
   pthread_mutex_init(&mutexListaNuevos,((void *)0));
   pthread_mutex_init(&mutexListaReanudados,((void *)0));
   pthread_mutex_init(&mutexListaSuspendidos,((void *)0));
   pthread_mutex_init(&mutexListaBloqueados,((void *)0));
   pthread_mutex_init(&mutexListaFinQuantum,((void *)0));
   pthread_mutex_init(&mutexListaFinIO,((void *)0));
   pthread_mutex_init(&mutexListaListos,((void *)0));
   pthread_mutex_init(&mutexListaDemorados,((void *)0));
   sem_ej = malloc(sizeof(sem_t));
   sem_init(sem_ej, 0, 0);
   sem_sts = malloc(sizeof(sem_t));
   sem_init(sem_sts, 0, 0);
   sem_procer = malloc(sizeof(sem_t));
   sem_init(sem_procer, 0, 0);
   sem_io = malloc(sizeof(sem_t));
   sem_init(sem_io, 0, 0);
   sem_lts_suspendido = malloc(sizeof(sem_t));
   sem_init(sem_lts_suspendido, 0, 0);
   sem_lts_demorado = malloc(sizeof(sem_t));
   sem_init(sem_lts_demorado, 0, 0);
   pthread_mutex_init(&mutexVarMaxMMP,((void *)0));
   pthread_mutex_init(&mutexVarMaxMPS,((void *)0));
   pthread_mutex_init(&mutexVarMMP,((void *)0));
   pthread_mutex_init(&mutexVarMPS,((void *)0));
   pthread_mutex_init(&mutexVarLPL,((void *)0));
   pthread_mutex_init(&mutexVarLPN,((void *)0));
   pthread_mutex_init(&mutexVarLPR ,((void *)0));
   pthread_mutex_init(&mutexVarFinQuantum,((void *)0));
   pthread_mutex_init(&mutexVarFinIO,((void *)0));
   pthread_mutex_init(&mutexVarSuspendido,((void *)0));
   pthread_mutex_init(&mutexVarEsperaEstandar,((void *)0));
   pthread_mutex_init(&mutexVarCantIOTDisponibles,((void *)0));
   pthread_mutex_init(&mutexVarAlfa,((void *)0));
   pthread_mutex_init(&mutexVarCantInstruccionesEjecutadas,((void *)0));
   logx(1,"HILO",1244,"tipo","log");
   cargar_archivo_configuracion();
   printf("Creando hilo de LTS\n");
   pthread_create(&(LTS_hilo), ((void *)0), LTS_funcion, ((void *)0));
   printf("Creando hilo de STS\n");
   pthread_create(&(STS_hilo), ((void *)0), STS_funcion, ((void *)0));
   printf("Creando hilo de PROCER\n");
   pthread_create(&(PROCER_hilo), ((void *)0), PROCER_funcion, ((void *)0));
   for (i=0; i < cantidad_hilos_iot; i++){
    pthread_t IOT_hilo;
    printf("Creando hilo de IOT numero:%d\n", i+1);
    pthread_create(&(IOT_hilo), ((void *)0), IOT_funcion, ((void *)0));
   }
       while (1){
        comprobar_archivo_configuracion();
      signal(10, SIGhandler);
     sleep(1);
     }
   pthread_exit(((void *)0));
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int i;
   unsigned long LTS_hilo;
   unsigned long STS_hilo;
   unsigned long PROCER_hilo;
   pthread_mutex_init(&mutexListaNuevos,((void *)0));
   pthread_mutex_init(&mutexListaReanudados,((void *)0));
   pthread_mutex_init(&mutexListaSuspendidos,((void *)0));
   pthread_mutex_init(&mutexListaBloqueados,((void *)0));
   pthread_mutex_init(&mutexListaFinQuantum,((void *)0));
   pthread_mutex_init(&mutexListaFinIO,((void *)0));
   pthread_mutex_init(&mutexListaListos,((void *)0));
   pthread_mutex_init(&mutexListaDemorados,((void *)0));
   sem_ej = malloc(sizeof(sem_t));
   sem_init(sem_ej, 0, 0);
   sem_sts = malloc(sizeof(sem_t));
   sem_init(sem_sts, 0, 0);
   sem_procer = malloc(sizeof(sem_t));
   sem_init(sem_procer, 0, 0);
   sem_io = malloc(sizeof(sem_t));
   sem_init(sem_io, 0, 0);
   sem_lts_suspendido = malloc(sizeof(sem_t));
   sem_init(sem_lts_suspendido, 0, 0);
   sem_lts_demorado = malloc(sizeof(sem_t));
   sem_init(sem_lts_demorado, 0, 0);
   pthread_mutex_init(&mutexVarMaxMMP,((void *)0));
   pthread_mutex_init(&mutexVarMaxMPS,((void *)0));
   pthread_mutex_init(&mutexVarMMP,((void *)0));
   pthread_mutex_init(&mutexVarMPS,((void *)0));
   pthread_mutex_init(&mutexVarLPL,((void *)0));
   pthread_mutex_init(&mutexVarLPN,((void *)0));
   pthread_mutex_init(&mutexVarLPR ,((void *)0));
   pthread_mutex_init(&mutexVarFinQuantum,((void *)0));
   pthread_mutex_init(&mutexVarFinIO,((void *)0));
   pthread_mutex_init(&mutexVarSuspendido,((void *)0));
   pthread_mutex_init(&mutexVarEsperaEstandar,((void *)0));
   pthread_mutex_init(&mutexVarCantIOTDisponibles,((void *)0));
   pthread_mutex_init(&mutexVarAlfa,((void *)0));
   pthread_mutex_init(&mutexVarCantInstruccionesEjecutadas,((void *)0));
   logx(1,"HILO",1244,"tipo","log");
   cargar_archivo_configuracion();
   printf("Creando hilo de LTS\n");
   pthread_create(&(LTS_hilo), ((void *)0), LTS_funcion, ((void *)0));
   printf("Creando hilo de STS\n");
   pthread_create(&(STS_hilo), ((void *)0), STS_funcion, ((void *)0));
   printf("Creando hilo de PROCER\n");
   pthread_create(&(PROCER_hilo), ((void *)0), PROCER_funcion, ((void *)0));
   for (i=0; i < cantidad_hilos_iot; i++){
    unsigned long IOT_hilo;
    printf("Creando hilo de IOT numero:%d\n", i+1);
    pthread_create(&(IOT_hilo), ((void *)0), IOT_funcion, ((void *)0));
   }
       while (1){
        comprobar_archivo_configuracion();
      signal(10, SIGhandler);
     sleep(1);
     }
   pthread_exit(((void *)0));
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


recvall

decompiled_code:
__int64 __fastcall recvall(int fd, __int64 a2, int *a3, int a4)
{
int v5; // edx
int v7; // er14
int v8; // eax
int v9; // edx

v5 = *a3;
if ( v5 <= 0 )
{
v7 = 0;
LABEL_7:
*a3 = v7;
v7 = 0;
}
else
{
v7 = 0;
while ( 1 )
{
v8 = recv(fd, (void *)(a2 + v7), v5, a4);
v9 = v7;
v7 = v8;
if ( v8 == -1 )
break;
v5 = -v8;
if ( *a3 <= v8 )
goto LABEL_7;
}
*a3 = v9;
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, int *a3, int a4)
{
int v5; // edx
int v7; // er14
int v8; // eax
int v9; // edx

v5 = *a3;
if ( v5 <= 0 )
{
v7 = 0;
LABEL_7:
*a3 = v7;
v7 = 0;
}
else
{
v7 = 0;
while ( 1 )
{
v8 = recv(fd, (void *)(a2 + v7), v5, a4);
v9 = v7;
v7 = v8;
if ( v8 == -1 )
break;
v5 = -v8;
if ( *a3 <= v8 )
goto LABEL_7;
}
*a3 = v9;
}
return (unsigned int)v7;
}

original_code:
int recvall(int client_fd,char *buffer,int *header,int flag){
 int total=0;
 int bytes_left=*header;
 int nbytes = 0;
 while( total < *header){
  nbytes = recv(client_fd,buffer+total, bytes_left,flag);
  if( nbytes == -1){break;}
  total =+ nbytes;
  bytes_left =- nbytes;
 }
 *header = total;
 return nbytes==-1?-1:0;
 return 0;
}

canonical_original_code:
int recvall(int client_fd, char *buffer, int *header, int flag){
 int total = 0;
 int bytes_left = *header;
 int nbytes = 0;
 while( total < *header){
  nbytes = recv(client_fd,buffer+total, bytes_left,flag);
  if( nbytes == -1){break;}
  total =+ nbytes;
  bytes_left =- nbytes;
 }
 *header = total;
 return nbytes==-1?-1:0;
 return 0;
}

variable_types:
buffer
char *

variable_types:
header
int *

variable_types: flag int

variable_types: total int

variable_types: nbytes int

return_type: int


decompiled_code:
__int64 __fastcall recibir_mensaje(void **a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = recv(a2, buf, 4uLL, 0);
if ( v2 > 0 )
{
memset(*a1, 0, buf[0]);
v3 = recvall(a2, (__int64)*a1, buf, 0);
if ( v3 == -1 )
{
printf("Error al recibir datos del archivo");
return v3;
}
result = 0LL;
}
else
{
if ( v2 )
{
v3 = -1;
printf("Error al recibir datos del header");
return v3;
}
printf("El socket %d cerro la conexion\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = recv(a2, buf, 4uLL, 0);
if ( v2 > 0 )
{
memset(*a1, 0, buf[0]);
v3 = func0(a2, (__int64)*a1, buf, 0);
if ( v3 == -1 )
{
printf("Error al recibir datos del archivo");
return v3;
}
result = 0LL;
}
else
{
if ( v2 )
{
v3 = -1;
printf("Error al recibir datos del header");
return v3;
}
printf("El socket %d cerro la conexion\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int recibir_mensaje(char** mensaje,int socket_client){
 int nbytes;
 int header;
  if( (nbytes = recv(socket_client,&header,sizeof(header),0)) <= 0){
    if( nbytes == 0){
     printf("El socket %d cerro la conexion\n",socket_client);
     return -1;
    }else{
     printf("Error al recibir datos del header");
     return -1;
    }
  }
   bzero(*mensaje,header);
   if (( recvall(socket_client,*mensaje,&header,0)) == -1){
    printf("Error al recibir datos del archivo");
    return -1;
   }
 return 0;
}

canonical_original_code:
int recibir_mensaje(char **mensaje, int socket_client){
 int nbytes;
 int header;
  if( (nbytes = recv(socket_client,&header,sizeof(header),0)) <= 0){
    if( nbytes == 0){
     printf("El socket %d cerro la conexion\n",socket_client);
     return -1;
    }else{
     printf("Error al recibir datos del header");
     return -1;
    }
  }
   bzero(*mensaje,header);
   if (( recvall(socket_client,*mensaje,&header,0)) == -1){
    printf("Error al recibir datos del archivo");
    return -1;
   }
 return 0;
}

variable_types:
mensaje
char **

variable_types: header int


sendall

decompiled_code:
__int64 __fastcall sendall(int fd, __int64 a2, int *a3)
{
int v4; // edx
int v5; // er13
int v6; // eax
int v7; // edx

v4 = *a3;
if ( v4 <= 0 )
{
v5 = 0;
LABEL_7:
*a3 = v5;
v5 = 0;
}
else
{
v5 = 0;
while ( 1 )
{
v6 = send(fd, (const void *)(a2 + v5), v4, 0);
v7 = v5;
v5 = v6;
if ( v6 == -1 )
break;
v4 = -v6;
if ( *a3 <= v6 )
goto LABEL_7;
}
*a3 = v7;
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2, int *a3)
{
int v4; // edx
int v5; // er13
int v6; // eax
int v7; // edx

v4 = *a3;
if ( v4 <= 0 )
{
v5 = 0;
LABEL_7:
*a3 = v5;
v5 = 0;
}
else
{
v5 = 0;
while ( 1 )
{
v6 = send(fd, (const void *)(a2 + v5), v4, 0);
v7 = v5;
v5 = v6;
if ( v6 == -1 )
break;
v4 = -v6;
if ( *a3 <= v6 )
goto LABEL_7;
}
*a3 = v7;
}
return (unsigned int)v5;
}

original_code:
int sendall(int sockfd,char *buffer, int *len){
 int total=0;
 int bytes_left=*len;
 int n = 0;
 while( total < *len){
  n = send(sockfd,buffer+total, bytes_left,0);
  if( n == -1){break;}
  total =+ n;
  bytes_left =- n;
 }
 *len = total;
 return n==-1?-1:0;
}

canonical_original_code:
int sendall(int sockfd, char *buffer, int *len){
 int total = 0;
 int bytes_left = *len;
 int n = 0;
 while( total < *len){
  n = send(sockfd,buffer+total, bytes_left,0);
  if( n == -1){break;}
  total =+ n;
  bytes_left =- n;
 }
 *len = total;
 return n==-1?-1:0;
}

variable_types: sockfd int

variable_types:
len
int *

variable_types: n int


decompiled_code:
__int64 __fastcall enviar_mensaje(const char *a1, int a2)
{
unsigned int v2; // er12
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

buf[0] = strlen(a1);
if ( send(a2, buf, 4uLL, 0) == -1 )
{
v2 = -1;
puts("Error al enviar el header");
}
else
{
v2 = sendall(a2, (__int64)a1, buf);
if ( v2 == -1 )
puts("Error al enviar el paquete");
else
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, int a2)
{
unsigned int v2; // er12
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

buf[0] = strlen(a1);
if ( send(a2, buf, 4uLL, 0) == -1 )
{
v2 = -1;
puts("Error al enviar el header");
}
else
{
v2 = func2(a2, (__int64)a1, buf);
if ( v2 == -1 )
puts("Error al enviar el paquete");
else
v2 = 0;
}
return v2;
}

original_code:
int enviar_mensaje(char* mensaje,int socket_client){
  int header = (strlen(mensaje));
  if( send(socket_client,&header,sizeof(header),0) == -1){
   printf("Error al enviar el header\n");
   return -1;
  }
  if( sendall(socket_client,&(*mensaje),&header) == -1){
   printf("Error al enviar el paquete\n");
   return -1;
  }
  return 0;
}

canonical_original_code:
int enviar_mensaje(char *mensaje, int socket_client){
  int header = (strlen(mensaje));
  if( send(socket_client,&header,sizeof(header),0) == -1){
   printf("Error al enviar el header\n");
   return -1;
  }
  if( sendall(socket_client,&(*mensaje),&header) == -1){
   printf("Error al enviar el paquete\n");
   return -1;
  }
  return 0;
}

variable_types:
mensaje
char *


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

result = finQ;
if ( lpn >= finQ )
result = lpn;
if ( (unsigned int)result < finIO )
result = finIO;
if ( (unsigned int)result < lpr )
result = lpr;
return result;
}

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

result = finQ;
if ( lpn >= finQ )
result = lpn;
if ( (unsigned int)result < finIO )
result = finIO;
if ( (unsigned int)result < lpr )
result = lpr;
return result;
}

original_code:
int prioridad_maxima(){
 int prioridad_max=lpn;
 if( prioridad_max < finQ ){
  prioridad_max=finQ;
 }
 if( prioridad_max < finIO ){
  prioridad_max=finIO;
 }
 if( prioridad_max < lpr ){
  prioridad_max=lpr;
 }
 return prioridad_max;
}

canonical_original_code:
int prioridad_maxima(){
 int prioridad_max = lpn;
 if( prioridad_max < finQ ){
  prioridad_max=finQ;
 }
 if( prioridad_max < finIO ){
  prioridad_max=finIO;
 }
 if( prioridad_max < lpr ){
  prioridad_max=lpr;
 }
 return prioridad_max;
}


decompiled_code:
void __fastcall __noreturn STS_funcion(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
unsigned int v10; // ebx

while ( 1 )
{
v10 = 0;
sem_wait(sem_sts);
while ( (unsigned int)prioridad_maxima() + 1 > v10 )
{
pthread_mutex_lock(&mutexVarLPN);
if ( lpn == v10 && listaProcesosNuevos )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaNuevos);
agregar_lista_de_procesos_log(listaProcesosListos, listaProcesosNuevos, "Nuevos", "Listos", prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaNuevos);
pthread_mutex_unlock(&mutexListaListos);
}
pthread_mutex_unlock(&mutexVarLPN);
pthread_mutex_lock(&mutexVarLPR);
if ( lpr == v10 && listaProcesosReanudados )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaReanudados);
agregar_lista_de_procesos_log(
listaProcesosListos,
listaProcesosReanudados,
"Reanudados",
"Listos",
prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaReanudados);
pthread_mutex_unlock(&mutexListaListos);
}
pthread_mutex_unlock(&mutexVarLPR);
pthread_mutex_lock(&mutexVarFinQuantum);
if ( finQ == v10 && listaFinQuantum )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaFinQuantum);
agregar_lista_de_procesos_log(listaProcesosListos, listaFinQuantum, "FinQuantum", "Listos", prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaFinQuantum);
pthread_mutex_unlock(&mutexListaListos);
}
pthread_mutex_unlock(&mutexVarFinQuantum);
pthread_mutex_lock(&mutexVarFinIO);
if ( finIO == v10 )
{
if ( listaFinIO )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaFinIO);
agregar_lista_de_procesos_log(listaProcesosListos, listaFinIO, "FinIO", "Listos", prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaFinIO);
pthread_mutex_unlock(&mutexListaListos);
}
}
++v10;
pthread_mutex_unlock(&mutexVarFinIO);
}
pthread_mutex_lock(&mutexListaListos);
planificar(listaProcesosListos, a1, a2, a3, a4, v8, v9, a7, a8);
pthread_mutex_unlock(&mutexListaListos);
sem_post(sem_procer);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
unsigned int v10; // ebx

while ( 1 )
{
v10 = 0;
sem_wait(sem_sts);
while ( (unsigned int)func3() + 1 > v10 )
{
pthread_mutex_lock(&mutexVarLPN);
if ( lpn == v10 && listaProcesosNuevos )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaNuevos);
agregar_lista_de_procesos_log(listaProcesosListos, listaProcesosNuevos, "Nuevos", "Listos", prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaNuevos);
pthread_mutex_unlock(&mutexListaListos);
}
pthread_mutex_unlock(&mutexVarLPN);
pthread_mutex_lock(&mutexVarLPR);
if ( lpr == v10 && listaProcesosReanudados )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaReanudados);
agregar_lista_de_procesos_log(
listaProcesosListos,
listaProcesosReanudados,
"Reanudados",
"Listos",
prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaReanudados);
pthread_mutex_unlock(&mutexListaListos);
}
pthread_mutex_unlock(&mutexVarLPR);
pthread_mutex_lock(&mutexVarFinQuantum);
if ( finQ == v10 && listaFinQuantum )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaFinQuantum);
agregar_lista_de_procesos_log(listaProcesosListos, listaFinQuantum, "FinQuantum", "Listos", prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaFinQuantum);
pthread_mutex_unlock(&mutexListaListos);
}
pthread_mutex_unlock(&mutexVarFinQuantum);
pthread_mutex_lock(&mutexVarFinIO);
if ( finIO == v10 )
{
if ( listaFinIO )
{
pthread_mutex_lock(&mutexListaListos);
pthread_mutex_lock(&mutexListaFinIO);
agregar_lista_de_procesos_log(listaProcesosListos, listaFinIO, "FinIO", "Listos", prioridad_FIFO_RR);
pthread_mutex_unlock(&mutexListaFinIO);
pthread_mutex_unlock(&mutexListaListos);
}
}
++v10;
pthread_mutex_unlock(&mutexVarFinIO);
}
pthread_mutex_lock(&mutexListaListos);
func2(listaProcesosListos, a1, a2, a3, a4, v8, v9, a7, a8);
pthread_mutex_unlock(&mutexListaListos);
sem_post(sem_procer);
}
}

original_code:
void * STS_funcion (){
 unsigned int prioridad;
 while(1){
  sem_wait(sem_sts);
   for (prioridad = 0; prioridad < prioridad_maxima()+1; ++prioridad) {
    pthread_mutex_lock(&mutexVarLPN);
    if(prioridad == lpn){
     if (listaProcesosNuevos != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaNuevos);
      agregar_lista_de_procesos_log(listaProcesosListos,listaProcesosNuevos,"Nuevos","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaNuevos);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarLPN);
    pthread_mutex_lock(&mutexVarLPR);
    if (prioridad == lpr ){
     if (listaProcesosReanudados != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaReanudados);
      agregar_lista_de_procesos_log(listaProcesosListos,listaProcesosReanudados,"Reanudados","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaReanudados);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarLPR);
    pthread_mutex_lock(&mutexVarFinQuantum);
    if (prioridad == finQ ){
     if (listaFinQuantum != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaFinQuantum);
      agregar_lista_de_procesos_log(listaProcesosListos,listaFinQuantum,"FinQuantum","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaFinQuantum);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarFinQuantum);
    pthread_mutex_lock(&mutexVarFinIO);
    if (prioridad == finIO){
     if (listaFinIO != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaFinIO);
      agregar_lista_de_procesos_log(listaProcesosListos,listaFinIO,"FinIO","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaFinIO);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarFinIO);
   }
   pthread_mutex_lock(&mutexListaListos);
   planificar(listaProcesosListos);
   pthread_mutex_unlock(&mutexListaListos);
   sem_post(sem_procer);
 }
 return 0;
}

canonical_original_code:
void *STS_funcion(){
 unsigned int prioridad;
 while(1){
  sem_wait(sem_sts);
   for (prioridad = 0; prioridad < prioridad_maxima()+1; ++prioridad) {
    pthread_mutex_lock(&mutexVarLPN);
    if(prioridad == lpn){
     if (listaProcesosNuevos != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaNuevos);
      agregar_lista_de_procesos_log(listaProcesosListos,listaProcesosNuevos,"Nuevos","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaNuevos);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarLPN);
    pthread_mutex_lock(&mutexVarLPR);
    if (prioridad == lpr ){
     if (listaProcesosReanudados != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaReanudados);
      agregar_lista_de_procesos_log(listaProcesosListos,listaProcesosReanudados,"Reanudados","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaReanudados);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarLPR);
    pthread_mutex_lock(&mutexVarFinQuantum);
    if (prioridad == finQ ){
     if (listaFinQuantum != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaFinQuantum);
      agregar_lista_de_procesos_log(listaProcesosListos,listaFinQuantum,"FinQuantum","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaFinQuantum);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarFinQuantum);
    pthread_mutex_lock(&mutexVarFinIO);
    if (prioridad == finIO){
     if (listaFinIO != ((void *)0)){
      pthread_mutex_lock(&mutexListaListos);
      pthread_mutex_lock(&mutexListaFinIO);
      agregar_lista_de_procesos_log(listaProcesosListos,listaFinIO,"FinIO","Listos",prioridad_FIFO_RR);
      pthread_mutex_unlock(&mutexListaFinIO);
      pthread_mutex_unlock(&mutexListaListos);
     }
    }
    pthread_mutex_unlock(&mutexVarFinIO);
   }
   pthread_mutex_lock(&mutexListaListos);
   planificar(listaProcesosListos);
   pthread_mutex_unlock(&mutexListaListos);
   sem_post(sem_procer);
 }
 return 0;
}

variable_types:
prioridad
unsigned int

return_type: void *


decompiled_code:
__int64 __fastcall esperar_semaforo(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 0xFFFF;
semop(a1, &sops, 1uLL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 0xFFFF;
semop(a1, &sops, 1uLL);
return 0LL;
}

original_code:
int esperar_semaforo(int id_semaforo, int posicion_en_array){
 struct sembuf Operacion;
 Operacion.sem_num = posicion_en_array;
 Operacion.sem_op = -1;
 Operacion.sem_flg = 0;
 semop (id_semaforo, &Operacion, 1);
 return 0;
}

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


decompiled_code:
__int64 __fastcall liberar_semaforo(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 1;
semop(a1, &sops, 1uLL);
return 0LL;
}

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

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 1;
semop(a1, &sops, 1uLL);
return 0LL;
}

original_code:
int liberar_semaforo(int id_semaforo, int posicion_en_array){
 struct sembuf Operacion;
 Operacion.sem_num = posicion_en_array;
 Operacion.sem_op = 1;
 Operacion.sem_flg = 0;
 semop (id_semaforo, &Operacion, 1);
 return 0;
}

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


decompiled_code:
__int64 __fastcall inicializar_semaforos(int nsems)
{
key_t v1; // eax
unsigned int v2; // er12
int v3; // ebx
int v4; // esi
int v5; // ebp
int v6; // ebx
int v7; // eax
int v9[12]; // [rsp+8h] [rbp-30h] BYREF

v1 = ftok("/home/utnso/hola3", 0);
if ( v1 == -1 )
{
puts(s);
exit(0);
}
v2 = semget(v1, nsems, 896);
if ( v2 == -1 )
{
puts(aNoPuedoCrearSe);
exit(0);
}
v3 = 0;
if ( nsems > 0 )
{
do
{
v4 = v3;
v5 = v3++;
v9[0] = 0;
semctl(v2, v4, 16, v9);
}
while ( nsems != v3 );
v6 = 0;
do
{
liberar_semaforo(v2, v6);
v7 = v6++;
}
while ( v5 != v7 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int nsems)
{
key_t v1; // eax
unsigned int v2; // er12
int v3; // ebx
int v4; // esi
int v5; // ebp
int v6; // ebx
int v7; // eax
int v9[12]; // [rsp+8h] [rbp-30h] BYREF

v1 = ftok("/home/utnso/hola3", 0);
if ( v1 == -1 )
{
puts(s);
exit(0);
}
v2 = semget(v1, nsems, 896);
if ( v2 == -1 )
{
puts(aNoPuedoCrearSe);
exit(0);
}
v3 = 0;
if ( nsems > 0 )
{
do
{
v4 = v3;
v5 = v3++;
v9[0] = 0;
semctl(v2, v4, 16, v9);
}
while ( nsems != v3 );
v6 = 0;
do
{
func1(v2, v6);
v7 = v6++;
}
while ( v5 != v7 );
}
return v2;
}

original_code:
int inicializar_semaforos(int cant_semaforos_a_crear){
 key_t Clave;
 int id_semaforo;
 union semun arg;
 int i;
 Clave = ftok ("/home/utnso/hola3", 0);
 if (Clave == (key_t)-1)
 {
  printf("No puedo conseguir clave de semáforo\n");
  exit(0);
 }
 id_semaforo = semget (Clave, cant_semaforos_a_crear, 0600 | 01000);
 if (id_semaforo == -1)
 {
  printf("No puedo crear semáforo\n");
  exit (0);
 }
 for( i=0;i<cant_semaforos_a_crear;i++){
  arg.val = 0;
  semctl (id_semaforo, i, 16, &arg);
 }
 for( i=0;i<cant_semaforos_a_crear;i++){
  liberar_semaforo(id_semaforo,i);
 }
 return id_semaforo;
}

canonical_original_code:
int inicializar_semaforos(int cant_semaforos_a_crear){
 int Clave;
 int id_semaforo;
 union semun arg;
 int i;
 Clave = ftok ("/home/utnso/hola3", 0);
 if (Clave == (key_t)-1)
 {
  printf("No puedo conseguir clave de semáforo\n");
  exit(0);
 }
 id_semaforo = semget (Clave, cant_semaforos_a_crear, 0600 | 01000);
 if (id_semaforo == -1)
 {
  printf("No puedo crear semáforo\n");
  exit (0);
 }
 for( i=0;i<cant_semaforos_a_crear;i++){
  arg.val = 0;
  semctl (id_semaforo, i, 16, &arg);
 }
 for( i=0;i<cant_semaforos_a_crear;i++){
  liberar_semaforo(id_semaforo,i);
 }
 return id_semaforo;
}

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

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


cGetDate

decompiled_code:
char *cGetDate()
{
struct tm *v0; // rbx
char *v1; // rax
char *v2; // r12
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(0xBuLL);
if ( v1 )
{
v2 = v1;
sprintf(
v1,
"%4d-%02d-%02d",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday);
}
else
{
v2 = (char *)&unk_2A2;
perror("No hay memoria");
}
return v2;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rbx
char *v1; // rax
char *v2; // r12
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(0xBuLL);
if ( v1 )
{
v2 = v1;
sprintf(
v1,
"%4d-%02d-%02d",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday);
}
else
{
v2 = (char *)&unk_2A2;
perror("No hay memoria");
}
return v2;
}

original_code:
char *cGetDate() {
 time_t hora;
 struct tm *tiempo;
 char *fecha;
 hora = time(((void *)0));
 tiempo = localtime(&hora);
 fecha = (char *)malloc(sizeof(char)*11);
 if (fecha==((void *)0)) {
  perror ("No hay memoria");
  return "";
 }
 sprintf (fecha,"%4d-%02d-%02d", tiempo->tm_year+1900,tiempo->tm_mon+1,tiempo->tm_mday);
 return fecha;
}

canonical_original_code:
char *cGetDate() {
 long hora;
 struct tm *tiempo;
 char *fecha;
 hora = time(((void *)0));
 tiempo = localtime(&hora);
 fecha = (char *)malloc(sizeof(char)*11);
 if (fecha==((void *)0)) {
  perror ("No hay memoria");
  return "";
 }
 sprintf (fecha,"%4d-%02d-%02d", tiempo->tm_year+1900,tiempo->tm_mon+1,tiempo->tm_mday);
 return fecha;
}

variable_types: hora long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
fecha
char *

return_type: char *


cGetTime

decompiled_code:
char *cGetTime()
{
struct tm *v0; // rbx
char *v1; // rax
char *v2; // r12
char *result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(9uLL);
if ( v0 )
{
v2 = v1;
sprintf(v1, "%02d-%02d-%02d", (unsigned int)v0->tm_hour, (unsigned int)v0->tm_min, (unsigned int)v0->tm_sec);
result = v2;
}
else
{
perror("No hay memoria");
result = (char *)&unk_2A2;
}
return result;
}

canonical_decompiled_code:
char *func1()
{
struct tm *v0; // rbx
char *v1; // rax
char *v2; // r12
char *result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(9uLL);
if ( v0 )
{
v2 = v1;
sprintf(v1, "%02d-%02d-%02d", (unsigned int)v0->tm_hour, (unsigned int)v0->tm_min, (unsigned int)v0->tm_sec);
result = v2;
}
else
{
perror("No hay memoria");
result = (char *)&unk_2A2;
}
return result;
}

original_code:
char *cGetTime() {
 time_t hora;
 struct tm *tiempo;
 hora = time(((void *)0));
 tiempo = localtime(&hora);
 char *tiempo_c;
 tiempo_c = (char *)malloc(sizeof(char)*9);
 if (tiempo==((void *)0)) {perror ("No hay memoria"); return "";}
 sprintf (tiempo_c,"%02d-%02d-%02d", tiempo->tm_hour, tiempo->tm_min, tiempo->tm_sec);
 return tiempo_c;
}

canonical_original_code:
char *cGetTime() {
 long hora;
 struct tm *tiempo;
 hora = time(((void *)0));
 tiempo = localtime(&hora);
 char *tiempo_c;
 tiempo_c = (char *)malloc(sizeof(char)*9);
 if (tiempo==((void *)0)) {perror ("No hay memoria"); return "";}
 sprintf (tiempo_c,"%02d-%02d-%02d", tiempo->tm_hour, tiempo->tm_min, tiempo->tm_sec);
 return tiempo_c;
}

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


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

pthread_mutex_lock(&mutexVarMaxMMP);
pthread_mutex_lock(&mutexVarMMP);
if ( mmp >= max_mmp )
{
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
pthread_mutex_lock(&mutexListaDemorados);
encolar_solicitud(listaConeccionesDemoradas, a1);
pthread_mutex_unlock(&mutexListaDemorados);
sem_post(sem_lts_demorado);
result = 4294967294LL;
}
else
{
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
result = 0LL;
}
return result;
}

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

pthread_mutex_lock(&mutexVarMaxMMP);
pthread_mutex_lock(&mutexVarMMP);
if ( mmp >= max_mmp )
{
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
pthread_mutex_lock(&mutexListaDemorados);
encolar_solicitud(listaConeccionesDemoradas, a1);
pthread_mutex_unlock(&mutexListaDemorados);
sem_post(sem_lts_demorado);
result = 4294967294LL;
}
else
{
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
result = 0LL;
}
return result;
}

original_code:
int validar_mmp_demorado(int cliente_sock){
 pthread_mutex_lock(&mutexVarMaxMMP);
 pthread_mutex_lock(&mutexVarMMP);
 if( mmp >= max_mmp){
  pthread_mutex_unlock(&mutexVarMMP);
  pthread_mutex_unlock(&mutexVarMaxMMP);
  pthread_mutex_lock(&mutexListaDemorados);
  encolar_solicitud(listaConeccionesDemoradas,cliente_sock);
  pthread_mutex_unlock(&mutexListaDemorados);
  sem_post(sem_lts_demorado);
  return -2;
 }else{
  pthread_mutex_unlock(&mutexVarMMP);
  pthread_mutex_unlock(&mutexVarMaxMMP);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall validar_mps_mmp(int fd)
{
__int64 result; // rax

pthread_mutex_lock(&mutexVarMaxMPS);
pthread_mutex_lock(&mutexVarMaxMMP);
pthread_mutex_lock(&mutexVarMPS);
pthread_mutex_lock(&mutexVarMMP);
if ( mps < max_mps && mmp < max_mmp )
{
pthread_mutex_unlock(&mutexVarMPS);
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
pthread_mutex_unlock(&mutexVarMaxMPS);
result = 0LL;
}
else
{
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
if ( mps < max_mps )
{
pthread_mutex_unlock(&mutexVarMPS);
pthread_mutex_unlock(&mutexVarMaxMPS);
enviar_mensaje("Se sobrepaso el maximo de multiprogramacion(mmp), se encolara su solicitud.\n", (unsigned int)fd);
pthread_mutex_lock(&mutexListaDemorados);
encolar_solicitud(listaConeccionesDemoradas, (unsigned int)fd);
pthread_mutex_unlock(&mutexListaDemorados);
sem_post(sem_lts_demorado);
result = 4294967294LL;
}
else
{
pthread_mutex_unlock(&mutexVarMPS);
pthread_mutex_unlock(&mutexVarMaxMPS);
enviar_mensaje("Se sobrepaso el maximo de prosesos en el sistema(mps).\n", (unsigned int)fd);
close(fd);
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

pthread_mutex_lock(&mutexVarMaxMPS);
pthread_mutex_lock(&mutexVarMaxMMP);
pthread_mutex_lock(&mutexVarMPS);
pthread_mutex_lock(&mutexVarMMP);
if ( mps < max_mps && mmp < max_mmp )
{
pthread_mutex_unlock(&mutexVarMPS);
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
pthread_mutex_unlock(&mutexVarMaxMPS);
result = 0LL;
}
else
{
pthread_mutex_unlock(&mutexVarMMP);
pthread_mutex_unlock(&mutexVarMaxMMP);
if ( mps < max_mps )
{
pthread_mutex_unlock(&mutexVarMPS);
pthread_mutex_unlock(&mutexVarMaxMPS);
enviar_mensaje("Se sobrepaso el maximo de multiprogramacion(mmp), se encolara su solicitud.\n", (unsigned int)fd);
pthread_mutex_lock(&mutexListaDemorados);
encolar_solicitud(listaConeccionesDemoradas, (unsigned int)fd);
pthread_mutex_unlock(&mutexListaDemorados);
sem_post(sem_lts_demorado);
result = 4294967294LL;
}
else
{
pthread_mutex_unlock(&mutexVarMPS);
pthread_mutex_unlock(&mutexVarMaxMPS);
enviar_mensaje("Se sobrepaso el maximo de prosesos en el sistema(mps).\n", (unsigned int)fd);
close(fd);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int validar_mps_mmp(int cliente_sock){
 pthread_mutex_lock(&mutexVarMaxMPS);
 pthread_mutex_lock(&mutexVarMaxMMP);
 pthread_mutex_lock(&mutexVarMPS);
 pthread_mutex_lock(&mutexVarMMP);
 if( mps >= max_mps || mmp >= max_mmp){
  pthread_mutex_unlock(&mutexVarMMP);
  pthread_mutex_unlock(&mutexVarMaxMMP);
  if( mps >= max_mps){
   pthread_mutex_unlock(&mutexVarMPS);
   pthread_mutex_unlock(&mutexVarMaxMPS);
   enviar_mensaje("Se sobrepaso el maximo de prosesos en el sistema(mps).\n",cliente_sock);
   close(cliente_sock);
   return -1;
  }else{
   pthread_mutex_unlock(&mutexVarMPS);
   pthread_mutex_unlock(&mutexVarMaxMPS);
   enviar_mensaje("Se sobrepaso el maximo de multiprogramacion(mmp), se encolara su solicitud.\n",cliente_sock);
   pthread_mutex_lock(&mutexListaDemorados);
   encolar_solicitud(listaConeccionesDemoradas,cliente_sock);
   pthread_mutex_unlock(&mutexListaDemorados);
   sem_post(sem_lts_demorado);
   return -2;
  }
 }else{
  pthread_mutex_unlock(&mutexVarMPS);
  pthread_mutex_unlock(&mutexVarMMP);
  pthread_mutex_unlock(&mutexVarMaxMMP);
  pthread_mutex_unlock(&mutexVarMaxMPS);
 }
 return 0;
}


decompiled_code:
void __fastcall __noreturn server_socket(char *nptr)
{
const char *v1; // rdx
int v2; // er14
const char *v3; // rdx
__int16 v4; // ax
__int16 v5; // ax
socklen_t v6; // edx
const char *v7; // rdx
const char *v8; // rdx
int v9; // eax
int v10; // ebx
int v11; // er12
__m128i v12; // xmm2
__m128i v13; // xmm3
__m128i v14; // xmm4
__m128i v15; // xmm5
__m128i v16; // xmm6
__m128i v17; // xmm7
__m128i v18; // xmm0
const char *v19; // rdx
int i; // er12
int v21; // eax
const char *v22; // rdx
socklen_t addr_len; // [rsp+8h] [rbp-160h] BYREF
int optval; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr v25; // [rsp+10h] [rbp-158h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-148h] BYREF
__m128i v27[8]; // [rsp+30h] [rbp-138h] BYREF
fd_set readfds; // [rsp+B0h] [rbp-B8h] BYREF

memset(v27, 0, sizeof(v27));
memset(&readfds, 0, sizeof(readfds));
optval = 1;
if ( nptr )
{
v2 = socket(2, 1, 0);
if ( v2 < 0 )
error((int)"ERROR opening socket", 1, v1);
if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
error((int)"ERROR on setsockopt", 1, v3);
v25 = 0LL;
v4 = atoi(nptr);
v25.sa_family = 2;
v5 = _bswap_16(v4);
*(_QWORD *)&v25.sa_data[6] = 0LL;
*(_WORD *)v25.sa_data = v5;
if ( bind(v2, &v25, v6) < 0 )
error((int)"ERROR on binding", (int)&v25, v7);
if ( listen(v2, 20) == -1 )
error((int)"Error al escuchar", 20, v8);
v9 = v2 + 63;
v10 = v2;
if ( v2 >= 0 )
v9 = v2;
v11 = v2 + 1;
v27[0].m128i_i64[v9 >> 6] |= 1LL << (v2 % 64);
while ( 1 )
{
v12 = _mm_loadu_si128(&v27[1]);
v13 = _mm_loadu_si128(&v27[2]);
v14 = _mm_loadu_si128(&v27[3]);
v15 = _mm_loadu_si128(&v27[4]);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v27);
v16 = _mm_loadu_si128(&v27[5]);
*(__m128i *)&readfds.fds_bits[2] = v12;
v17 = _mm_loadu_si128(&v27[6]);
v18 = _mm_loadu_si128(&v27[7]);
*(__m128i *)&readfds.fds_bits[4] = v13;
*(__m128i *)&readfds.fds_bits[6] = v14;
*(__m128i *)&readfds.fds_bits[8] = v15;
*(__m128i *)&readfds.fds_bits[10] = v16;
*(__m128i *)&readfds.fds_bits[12] = v17;
*(__m128i *)&readfds.fds_bits[14] = v18;
if ( select(v11, &readfds, 0LL, 0LL, 0LL) == -1 )
error((int)"Error en el select", (int)&readfds, v19);
if ( v10 >= 0 )
{
for ( i = 0; i <= v10; ++i )
{
if ( (readfds.fds_bits[i >> 6] & (1LL << i)) != 0 )
{
if ( v2 == i )
{
addr_len = 16;
v21 = accept(v2, &addr, &addr_len);
if ( v21 == -1 )
{
error((int)"Error al aceptar conexion", (int)&addr, v22);
}
else
{
v27[0].m128i_i64[v21 / 64] |= 1LL << (v21 % 64);
if ( v10 < v21 )
v10 = v21;
}
}
else
{
administrar_conexion(i, (__int64)v27);
}
}
}
v11 = v10 + 1;
}
}
}
fwrite("ERROR, no port provided\n", 1uLL, 0x18uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(char *nptr)
{
const char *v1; // rdx
int v2; // er14
const char *v3; // rdx
__int16 v4; // ax
__int16 v5; // ax
socklen_t v6; // edx
const char *v7; // rdx
const char *v8; // rdx
int v9; // eax
int v10; // ebx
int v11; // er12
__m128i v12; // xmm2
__m128i v13; // xmm3
__m128i v14; // xmm4
__m128i v15; // xmm5
__m128i v16; // xmm6
__m128i v17; // xmm7
__m128i v18; // xmm0
const char *v19; // rdx
int i; // er12
int v21; // eax
const char *v22; // rdx
socklen_t addr_len; // [rsp+8h] [rbp-160h] BYREF
int optval; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr v25; // [rsp+10h] [rbp-158h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-148h] BYREF
__m128i v27[8]; // [rsp+30h] [rbp-138h] BYREF
fd_set readfds; // [rsp+B0h] [rbp-B8h] BYREF

memset(v27, 0, sizeof(v27));
memset(&readfds, 0, sizeof(readfds));
optval = 1;
if ( nptr )
{
v2 = socket(2, 1, 0);
if ( v2 < 0 )
error((int)"ERROR opening socket", 1, v1);
if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
error((int)"ERROR on setsockopt", 1, v3);
v25 = 0LL;
v4 = atoi(nptr);
v25.sa_family = 2;
v5 = func0(v4);
*(_QWORD *)&v25.sa_data[6] = 0LL;
*(_WORD *)v25.sa_data = v5;
if ( bind(v2, &v25, v6) < 0 )
error((int)"ERROR on binding", (int)&v25, v7);
if ( listen(v2, 20) == -1 )
error((int)"Error al escuchar", 20, v8);
v9 = v2 + 63;
v10 = v2;
if ( v2 >= 0 )
v9 = v2;
v11 = v2 + 1;
v27[0].m128i_i64[v9 >> 6] |= 1LL << (v2 % 64);
while ( 1 )
{
v12 = _mm_loadu_si128(&v27[1]);
v13 = _mm_loadu_si128(&v27[2]);
v14 = _mm_loadu_si128(&v27[3]);
v15 = _mm_loadu_si128(&v27[4]);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v27);
v16 = _mm_loadu_si128(&v27[5]);
*(__m128i *)&readfds.fds_bits[2] = v12;
v17 = _mm_loadu_si128(&v27[6]);
v18 = _mm_loadu_si128(&v27[7]);
*(__m128i *)&readfds.fds_bits[4] = v13;
*(__m128i *)&readfds.fds_bits[6] = v14;
*(__m128i *)&readfds.fds_bits[8] = v15;
*(__m128i *)&readfds.fds_bits[10] = v16;
*(__m128i *)&readfds.fds_bits[12] = v17;
*(__m128i *)&readfds.fds_bits[14] = v18;
if ( select(v11, &readfds, 0LL, 0LL, 0LL) == -1 )
error((int)"Error en el select", (int)&readfds, v19);
if ( v10 >= 0 )
{
for ( i = 0; i <= v10; ++i )
{
if ( (readfds.fds_bits[i >> 6] & (1LL << i)) != 0 )
{
if ( v2 == i )
{
addr_len = 16;
v21 = accept(v2, &addr, &addr_len);
if ( v21 == -1 )
{
error((int)"Error al aceptar conexion", (int)&addr, v22);
}
else
{
v27[0].m128i_i64[v21 / 64] |= 1LL << (v21 % 64);
if ( v10 < v21 )
v10 = v21;
}
}
else
{
func2(i, (__int64)v27);
}
}
}
v11 = v10 + 1;
}
}
}
fwrite("ERROR, no port provided\n", 1uLL, 0x18uLL, stderr);
exit(1);
}

original_code:
int server_socket(char *port)
{
  fd_set master;
  fd_set read_fds;
  int fdmax;
  int listener;
  int newfd;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&master)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  int cliente_sock;
     int portno;
     socklen_t clilen;
     struct sockaddr_in serv_addr, cli_addr;
     int yes=1;
     if (port == ((void *)0)) {
         fprintf(stderr,"ERROR, no port provided\n");
         exit(1);
     }
     listener = socket(2, SOCK_STREAM, 0);
     if (listener < 0){
        error("ERROR opening socket");
     }
     if( setsockopt(listener,1,2,&yes,sizeof(int)) == -1){
      error("ERROR on setsockopt");
     }
     bzero((char *) &serv_addr, sizeof(serv_addr));
     portno = atoi(port);
     serv_addr.sin_family = 2;
     serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
     serv_addr.sin_port = htons(portno);
     memset(&(serv_addr.sin_zero),'\0',8);
     if (bind(listener, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0){
      error("ERROR on binding");
     }
     if(listen(listener,20) == -1){
      error("Error al escuchar");
     }
     ((void) (((&master)->__fds_bits)[((listener) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listener) % (8 * (int) sizeof (__fd_mask)))))));
     fdmax = listener;
     while (1) {
      read_fds = master;
      if(select(fdmax+1, &read_fds, ((void *)0), ((void *)0), ((void *)0)) == -1){
       error("Error en el select");
      }
      for(cliente_sock=0;cliente_sock<=fdmax;cliente_sock++){
           if(((((&read_fds)->__fds_bits)[((cliente_sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cliente_sock) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
            if( cliente_sock == listener ){
      clilen = sizeof(cli_addr);
      if((newfd = accept(listener,(struct sockaddr *) &cli_addr, &clilen)) == -1){
       error("Error al aceptar conexion");
      }else{
       ((void) (((&master)->__fds_bits)[((newfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((newfd) % (8 * (int) sizeof (__fd_mask)))))));
       if( newfd > fdmax){
        fdmax = newfd;
       }
      }
           }else{
              administrar_conexion(cliente_sock,&master);
        }
       }
     }
     }
     return 0;
}

canonical_original_code:
int server_socket(char *port)
{
  struct fd_set master;
  struct fd_set read_fds;
  int fdmax;
  int listener;
  int newfd;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&master)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  int cliente_sock;
     int portno;
     unsigned int clilen;
     struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
     int yes = 1;
     if (port == ((void *)0)) {
         fprintf(stderr,"ERROR, no port provided\n");
         exit(1);
     }
     listener = socket(2, SOCK_STREAM, 0);
     if (listener < 0){
        error("ERROR opening socket");
     }
     if( setsockopt(listener,1,2,&yes,sizeof(int)) == -1){
      error("ERROR on setsockopt");
     }
     bzero((char *) &serv_addr, sizeof(serv_addr));
     portno = atoi(port);
     serv_addr.sin_family = 2;
     serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
     serv_addr.sin_port = htons(portno);
     memset(&(serv_addr.sin_zero),'\0',8);
     if (bind(listener, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0){
      error("ERROR on binding");
     }
     if(listen(listener,20) == -1){
      error("Error al escuchar");
     }
     ((void) (((&master)->__fds_bits)[((listener) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listener) % (8 * (int) sizeof (__fd_mask)))))));
     fdmax = listener;
     while (1) {
      read_fds = master;
      if(select(fdmax+1, &read_fds, ((void *)0), ((void *)0), ((void *)0)) == -1){
       error("Error en el select");
      }
      for(cliente_sock=0;cliente_sock<=fdmax;cliente_sock++){
           if(((((&read_fds)->__fds_bits)[((cliente_sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cliente_sock) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
            if( cliente_sock == listener ){
      clilen = sizeof(cli_addr);
      if((newfd = accept(listener,(struct sockaddr *) &cli_addr, &clilen)) == -1){
       error("Error al aceptar conexion");
      }else{
       ((void) (((&master)->__fds_bits)[((newfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((newfd) % (8 * (int) sizeof (__fd_mask)))))));
       if( newfd > fdmax){
        fdmax = newfd;
       }
      }
           }else{
              administrar_conexion(cliente_sock,&master);
        }
       }
     }
     }
     return 0;
}

variable_types:
port
char *

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

variable_types: fdmax int

variable_types: listener int

variable_types: newfd int

variable_types: portno int

variable_types:
clilen
unsigned int

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

variable_types: yes int

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

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


decompiled_code:
void __noreturn LTS_funcion()
{
pthread_t v0; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(&v0, 0LL, (void *(*)(void *))&LTS_suspendido, 0LL);
pthread_create(newthread, 0LL, (void *(*)(void *))&LTS_demorado, 0LL);
server_socket(puerto);
}

canonical_decompiled_code:
void __noreturn func4()
{
pthread_t v0; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(&v0, 0LL, (void *(*)(void *))&LTS_suspendido, 0LL);
pthread_create(newthread, 0LL, (void *(*)(void *))&LTS_demorado, 0LL);
func3(puerto);
}

original_code:
void * LTS_funcion(void * var){
 pthread_t LTS_suspendido_hilo;
 pthread_t LTS_demorado_hilo;
 pthread_create(&(LTS_suspendido_hilo), ((void *)0), LTS_suspendido, ((void *)0));
 pthread_create(&(LTS_demorado_hilo), ((void *)0), LTS_demorado, ((void *)0));
 server_socket(puerto);
 return 0;
}

canonical_original_code:
void *LTS_funcion(void *var){
 unsigned long LTS_suspendido_hilo;
 unsigned long LTS_demorado_hilo;
 pthread_create(&(LTS_suspendido_hilo), ((void *)0), LTS_suspendido, ((void *)0));
 pthread_create(&(LTS_demorado_hilo), ((void *)0), LTS_demorado, ((void *)0));
 server_socket(puerto);
 return 0;
}

variable_types:
var
void *


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void error(const char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void error(char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *

return_type: void


decompiled_code:
__int64 __fastcall tengo_que_contar_quantum(void *src)
{
size_t v1; // r12
void *v2; // rbp
char *v3; // r12
__int64 result; // rax

v1 = strlen((const char *)src);
v2 = malloc(v1);
memset(v2, 0, v1);
memcpy(v2, src, v1);
while ( 1 )
{
v3 = strtok((char *)v2, " ");
v2 = strtok(0LL, byte_9D6);
result = es_un_token_nulo(v3);
if ( (_DWORD)result )
break;
if ( !v2 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src)
{
size_t v1; // r12
void *v2; // rbp
char *v3; // r12
__int64 result; // rax

v1 = strlen((const char *)src);
v2 = malloc(v1);
memset(v2, 0, v1);
memcpy(v2, src, v1);
while ( 1 )
{
v3 = strtok((char *)v2, " ");
v2 = strtok(0LL, byte_9D6);
result = es_un_token_nulo(v3);
if ( (_DWORD)result )
break;
if ( !v2 )
return result;
}
return 1LL;
}

original_code:
int tengo_que_contar_quantum(char* instruccion){
 char *palabra;
 char *resto=(char *)malloc(strlen(instruccion));
 bzero(resto,strlen(instruccion));
 memcpy(resto,instruccion,strlen(instruccion));
 while( resto != ((void *)0)){
  palabra = strtok(resto," ");
  resto = strtok(((void *)0),"\0");
  if( es_un_token_nulo(palabra)){
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int tengo_que_contar_quantum(char *instruccion){
 char *palabra;
 char *resto = (char *)malloc(strlen(instruccion));
 bzero(resto,strlen(instruccion));
 memcpy(resto,instruccion,strlen(instruccion));
 while( resto != ((void *)0)){
  palabra = strtok(resto," ");
  resto = strtok(((void *)0),"\0");
  if( es_un_token_nulo(palabra)){
   return 1;
  }
 }
 return 0;
}

variable_types:
instruccion
char *

variable_types:
palabra
char *

variable_types:
resto
char *


test

decompiled_code:
int test()
{
return puts("Linking Works");
}

canonical_decompiled_code:
int func7()
{
return puts("Linking Works");
}

original_code:
void test(){
  printf("Linking Works\n");
  return;
}


printBranch

decompiled_code:
int __fastcall printBranch(__int64 a1, int a2)
{
int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
putchar(45);
}
return printf("<%c%i\n", (unsigned int)*(char *)(a1 + 28), *(unsigned int *)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2)
{
int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
putchar(45);
}
return printf("<%c%i\n", (unsigned int)*(char *)(a1 + 28), *(unsigned int *)(a1 + 24));
}

original_code:
void printBranch(node* node, int depth){
  int i = 0;
  for(i = 0; i < depth; i++){
    printf("-");
  }
  printf("<%c%i\n", node->color, node->value);
}

canonical_original_code:
void printBranch(struct node *node, int depth){
  int i = 0;
  for(i = 0; i < depth; i++){
    printf("-");
  }
  printf("<%c%i\n", node->color, node->value);
}

variable_types: struct node { struct node *parent; struct node *left; struct node *right; int value; char color; } *

variable_types: depth int

variable_types: i int


printTree

decompiled_code:
int __fastcall printTree(__int64 a1, int a2)
{
__int64 v3; // rbx
__int64 v4; // rdi
int result; // eax

v3 = a1;
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
LABEL_2:
printTree(v4);
while ( 1 )
{
result = printBranch(v3, a2);
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return result;
v4 = *(_QWORD *)(v3 + 8);
++a2;
if ( v4 )
goto LABEL_2;
}
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2)
{
__int64 v3; // rbx
__int64 v4; // rdi
int result; // eax

v3 = a1;
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
LABEL_2:
func9(v4);
while ( 1 )
{
result = func8(v3, a2);
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return result;
v4 = *(_QWORD *)(v3 + 8);
++a2;
if ( v4 )
goto LABEL_2;
}
}

original_code:
void printTree(node* node, int depth){
 if (node->left){
   printTree(node->left, depth + 1);
 }
 printBranch(node, depth);
 if (node->right){
   printTree(node->right, depth + 1);
 }
}

canonical_original_code:
void printTree(struct node *node, int depth){
 if (node->left){
   printTree(node->left, depth + 1);
 }
 printBranch(node, depth);
 if (node->right){
   printTree(node->right, depth + 1);
 }
}

user_defined_types: struct node { struct node *parent; struct node *left; struct node *right; int value; char color; }


main

canonical_name: main

repo: phantomfive/starcraft

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("%s", explanation);
printTerranTable();
printZergTable();
printProtossTable();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("%s", explanation);
func10();
func11();
func7();
return 0;
}

original_code:
int main(int argc, char **argv) {
 parseCommandLineArgs(argc, argv);
 printf("%s", explanation);
 if(shouldPrintTerranTable) printTerranTable ();
 if(shouldPrintZergTable) printZergTable ();
 if(shouldPrintProtossTable) printProtossTable();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


printProtossTable

decompiled_code:
int printProtossTable()
{
puts("+---------+");
puts("| PROTOSS |");
puts("+---------+");
return puts(" -> Coming Soon <-");
}

original_code:
static void printProtossTable() {
 printf("+---------+\n");
 printf("| PROTOSS |\n");
 printf("+---------+\n");
 printf(" -> Coming Soon <-\n");
}


printUnitTable

decompiled_code:
int __fastcall printUnitTable(_BYTE *a1)
{
puts("---->Table with single base saturated (24 workers):");
printUnitTableFlexible_constprop_0(a1, 816);
puts("\n\n---->Table with single base semi-saturated (16 workers):");
return printUnitTableFlexible_constprop_0(a1, 660);
}

canonical_decompiled_code:
int __fastcall func9(_BYTE *a1)
{
puts("---->Table with single base saturated (24 workers):");
func8(a1, 816);
puts("\n\n---->Table with single base semi-saturated (16 workers):");
return func8(a1, 660);
}

original_code:
static void printUnitTable(const Unit *table) {
 printf("---->Table with single base saturated (24 workers):\n");
 printUnitTableFlexible(table, 114 * 2, 816);
 printf("\n\n---->Table with single base semi-saturated (16 workers):\n");
 printUnitTableFlexible(table, 114 * 2, 660);
}

canonical_original_code:
static void printUnitTable(struct unit_struct *table) {
 printf("---->Table with single base saturated (24 workers):\n");
 printUnitTableFlexible(table, 114 * 2, 816);
 printf("\n\n---->Table with single base semi-saturated (16 workers):\n");
 printUnitTableFlexible(table, 114 * 2, 660);
}

variable_types: struct unit_struct { char name[100]; int minerals; int gas; int time; } *


printTerranTable

decompiled_code:
int printTerranTable()
{
puts("+--------+");
puts("| TERRAN |");
puts("+--------+");
return printUnitTable(terranHOTS);
}

original_code:
static void printTerranTable() {
 printf("+--------+\n");
 printf("| TERRAN |\n");
 printf("+--------+\n");
 printUnitTable(terranHOTS);
}


printZergTable

decompiled_code:
int printZergTable()
{
puts("+------+");
puts("| ZERG |");
puts("+------+");
return printUnitTable(zergHOTS);
}

original_code:
static void printZergTable() {
 printf("+------+\n");
 printf("| ZERG |\n");
 printf("+------+\n");
 printUnitTable(zergHOTS);
}


first

repo: phatio/phatio

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

result = a1 + 1;
if ( !a1 )
result = 0LL;
return result;
}

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

result = a1 + 1;
if ( !a1 )
result = 0LL;
return result;
}

original_code:
Item *first(List *item)
{
    return (item == 0) ? 0 : &(item->first);
}

canonical_original_code:
struct Item *first(struct List *item)
{
    return (item == 0) ? 0 : &(item->first);
}

variable_types: struct List { unsigned char rest; struct Item first; } *

return_type: struct Item { unsigned char type; unsigned char value; } *


decompiled_code:
void *__fastcall uint8_retval(char a1)
{
byte_A25 = a1;
return &returnHolder_1;
}

canonical_decompiled_code:
void *__fastcall func1(char a1)
{
byte_A25 = a1;
return &returnHolder_1;
}

original_code:
Item *uint8_retval(uint8_t value)
{
    static UInt8_Item returnHolder = { .type = 6 };
    returnHolder.value = value;
    return (Item *)&returnHolder;
}

canonical_original_code:
struct Item *uint8_retval(unsigned char value)
{
    static struct UInt8_Item returnHolder = { .type = 6 };
    returnHolder.value = value;
    return (struct Item *)&returnHolder;
}

variable_types:
value
unsigned char

variable_types: struct UInt8_Item { unsigned char type; unsigned char value; }

user_defined_types: struct Item { unsigned char type; unsigned char value; }


decompiled_code:
void *__fastcall uint16_retval(__int16 a1)
{
word_A22 = a1;
return &returnHolder_0;
}

canonical_decompiled_code:
void *__fastcall func2(__int16 a1)
{
word_A22 = a1;
return &returnHolder_0;
}

original_code:
Item *uint16_retval(uint16_t value)
{
    static UInt16_Item returnHolder = { .type = 7 };
    returnHolder.value = value;
    return (Item *)&returnHolder;
}

canonical_original_code:
struct Item *uint16_retval(unsigned short value)
{
    static struct UInt16_Item returnHolder = { .type = 7 };
    returnHolder.value = value;
    return (struct Item *)&returnHolder;
}

variable_types:
value
unsigned short

variable_types: struct UInt16_Item { unsigned char type; unsigned short value; }


decompiled_code:
void *string_retval()
{
return &stringHolder;
}

canonical_decompiled_code:
void *func3()
{
return &stringHolder;
}

original_code:
Item *string_retval(void)
{
    return (Item *)&stringHolder;
}

canonical_original_code:
struct Item *string_retval()
{
    return (struct Item *)&stringHolder;
}


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

if ( a1 <= 0x67FF )
result = *(_QWORD *)(a1 + 1);
else
result = *(unsigned __int8 *)(a1 + 1);
return result;
}

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

if ( a1 <= 0x67FF )
result = *(_QWORD *)(a1 + 1);
else
result = *(unsigned __int8 *)(a1 + 1);
return result;
}

original_code:
void *read_pointer(Item *item)
{
    return ((void *)item>=(void*)0x6800) ? (void **)*(((uint8_t *)item+(sizeof(uint8_t)))) : *((void **)((uint8_t *)item+(sizeof(uint8_t))));
}

canonical_original_code:
void *read_pointer(struct Item *item)
{
    return ((void *)item>=(void *)0x6800) ? (void **)*(((unsigned char *)item+(sizeof(unsigned char)))) : *((void **)((unsigned char *)item+(sizeof(unsigned char))));
}

variable_types: struct Item { unsigned char type; unsigned char value; } *


second

decompiled_code:
__int64 __fastcall second(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax

v1 = rest(a1);
return first((__int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax

v1 = func5(a1);
return func0((__int64)v1);
}

original_code:
Item *second(List *list)
{
    return first(rest(list));
}

canonical_original_code:
struct Item *second(struct List *list)
{
    return first(rest(list));
}

user_defined_types: struct List { unsigned char rest; struct Item first; }


third

decompiled_code:
__int64 __fastcall third(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rax

v1 = rest(a1);
v2 = rest(v1);
return first((__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rax

v1 = func5(a1);
v2 = func5(v1);
return func0((__int64)v2);
}

original_code:
Item *third(List *list)
{
    return first(rest(rest(list)));
}

canonical_original_code:
struct Item *third(struct List *list)
{
    return first(rest(rest(list)));
}


fourth

decompiled_code:
__int64 __fastcall fourth(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rax

v1 = rest(a1);
v2 = rest(v1);
v3 = rest(v2);
return first((__int64)v3);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rax

v1 = func5(a1);
v2 = func5(v1);
v3 = func5(v2);
return func0((__int64)v3);
}

original_code:
Item *fourth(List *list)
{
    return first(rest(rest(rest(list))));
}

canonical_original_code:
struct Item *fourth(struct List *list)
{
    return first(rest(rest(rest(list))));
}


fifth

decompiled_code:
__int64 __fastcall fifth(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rax
unsigned __int8 *v4; // rax

v1 = rest(a1);
v2 = rest(v1);
v3 = rest(v2);
v4 = rest(v3);
return first((__int64)v4);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rax
unsigned __int8 *v4; // rax

v1 = func5(a1);
v2 = func5(v1);
v3 = func5(v2);
v4 = func5(v3);
return func0((__int64)v4);
}

original_code:
Item *fifth(List *list)
{
    return first(rest(rest(rest(rest(list)))));
}

canonical_original_code:
struct Item *fifth(struct List *list)
{
    return first(rest(rest(rest(rest(list)))));
}


decompiled_code:
__int64 continue_evaluating()
{
if ( !time_started || (unsigned int)(time_started + 2000) >= timeSinceStart )
return (unsigned __int8)lio_stopped ^ 1u;
lio_stop("possible runaway script");
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
if ( !time_started || (unsigned int)(time_started + 2000) >= timeSinceStart )
return (unsigned __int8)lio_stopped ^ 1u;
lio_stop("possible runaway script");
return 0LL;
}

original_code:
_Bool continue_evaluating(void)
{
    if (time_started != 0 && time_started+2000 < _timeSinceStart) {
        lio_stop("possible runaway script");
        return 0;
    } else {
        return !lio_stopped;
 }
}

canonical_original_code:
_Bool continue_evaluating()
{
    if (time_started != 0 && time_started+2000 < _timeSinceStart) {
        lio_stop("possible runaway script");
        return 0;
    } else {
        return !lio_stopped;
 }
}


decompiled_code:
__int64 __fastcall item_type(unsigned __int8 *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *a1;
return result;
}

original_code:
uint8_t item_type(Item *item)
{
    if (item == 0) {
        return 0;
    } else {
        return ((void *)item>=(void*)0x6800) ? *(&item->type) : item->type;
    }
}

canonical_original_code:
unsigned char item_type(struct Item *item)
{
    if (item == 0) {
        return 0;
    } else {
        return ((void *)item>=(void *)0x6800) ? *(&item->type) : item->type;
    }
}

return_type: unsigned char


eval

decompiled_code:
__int64 __fastcall eval(__int64 a1)
{
unsigned __int8 *v2; // rdi
char v3; // al
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64); // rax

if ( !(unsigned __int8)continue_evaluating() )
return 0LL;
v2 = (unsigned __int8 *)first(a1);
v3 = item_type(v2);
if ( v3 == 1 )
return eval_expressions(a1);
if ( v3 != 3 )
{
if ( v3 == 4 )
{
v5 = get_variable_ref();
if ( *(_BYTE *)(v5 + 24) == 1 )
return eval_expressions(*(_QWORD *)(v5 + 16));
}
return 0LL;
}
v6 = (__int64 (__fastcall *)(__int64))read_pointer((unsigned __int64)v2);
return v6(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned __int8 *v2; // rdi
char v3; // al
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64); // rax

if ( !(unsigned __int8)func10() )
return 0LL;
v2 = (unsigned __int8 *)func0(a1);
v3 = func11(v2);
if ( v3 == 1 )
return func13(a1);
if ( v3 != 3 )
{
if ( v3 == 4 )
{
v5 = get_variable_ref();
if ( *(_BYTE *)(v5 + 24) == 1 )
return func13(*(_QWORD *)(v5 + 16));
}
return 0LL;
}
v6 = (__int64 (__fastcall *)(__int64))func4((unsigned __int64)v2);
return v6(a1);
}

original_code:
Item *eval(List *expression)
{
    if (!continue_evaluating()) {
        return 0;
    }
    Item *head = first(expression);
    lio_type type = item_type(head);
    if (type == 1) {
        return eval_expressions(expression);
    } else if (type == 3) {
        builtin_handler *handler = read_pointer(head);
        return handler(expression);
    } else if (type == 4) {
        reference *ref = get_variable_ref(head);
        if (ref->type == 1) {
            return eval_expressions((List *)ref->data);
        }
    }
    return 0;
}

canonical_original_code:
struct Item *eval(struct List *expression)
{
    if (!continue_evaluating()) {
        return 0;
    }
    struct Item *head = first(expression);
    unsigned char type = item_type(head);
    if (type == 1) {
        return eval_expressions(expression);
    } else if (type == 3) {
        struct Item *(*handler)(struct List *expression) = read_pointer(head);
        return handler(expression);
    } else if (type == 4) {
        struct reference *ref = get_variable_ref(head);
        if (ref->type == 1) {
            return eval_expressions((struct List *)ref->data);
        }
    }
    return 0;
}

variable_types:
type
unsigned char

variable_types: struct Item { unsigned char type; unsigned char value; } *(*)(struct List { unsigned char rest; struct Item first; } *expression)

variable_types: struct reference { struct reference *next; char *name; void *data; unsigned char type; unsigned char length; } *


decompiled_code:
__int64 __fastcall eval_expressions(unsigned __int8 *a1)
{
__int64 v1; // r12
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rdi

if ( !a1 )
return v1;
v2 = a1;
while ( (unsigned __int8)continue_evaluating() )
{
v3 = (unsigned __int8 *)first((__int64)v2);
if ( (unsigned __int8)item_type(v3) == 1 )
{
v1 = eval((__int64)(v3 + 1));
v2 = rest(v2);
if ( !v2 )
return v1;
}
else
{
v2 = rest(v2);
if ( !v2 )
return v1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 *a1)
{
__int64 v1; // r12
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rdi

if ( !a1 )
return v1;
v2 = a1;
while ( (unsigned __int8)func10() )
{
v3 = (unsigned __int8 *)func0((__int64)v2);
if ( (unsigned __int8)func11(v3) == 1 )
{
v1 = func12((__int64)(v3 + 1));
v2 = func5(v2);
if ( !v2 )
return v1;
}
else
{
v2 = func5(v2);
if ( !v2 )
return v1;
}
}
return v1;
}

original_code:
Item *eval_expressions(List *expression)
{
    Item *retVal;
    for (List *remaining = expression; remaining && continue_evaluating(); remaining = rest(remaining)) {
        Item *expr = first(remaining);
        if (1 == item_type(expr)) {
            retVal = eval(((List *)((uint8_t *)expr+(sizeof(uint8_t)))));
        }
    }
    return retVal;
}

canonical_original_code:
struct Item *eval_expressions(struct List *expression)
{
    struct Item *retVal;
    for (struct List *remaining = expression; remaining && continue_evaluating(); remaining = rest(remaining)) {
        struct Item *expr = first(remaining);
        if (1 == item_type(expr)) {
            retVal = eval(((struct List *)((unsigned char *)expr+(sizeof(unsigned char)))));
        }
    }
    return retVal;
}

variable_types: struct List { unsigned char rest; struct Item { unsigned char type; unsigned char value; } first; } *


decompiled_code:
__int64 __fastcall safe_evalexpressions(unsigned __int8 *a1)
{
__int64 result; // rax

time_started = timeSinceStart;
result = eval_expressions(a1);
time_started = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 *a1)
{
__int64 result; // rax

time_started = timeSinceStart;
result = func13(a1);
time_started = 0;
return result;
}

original_code:
Item *safe_evalexpressions(List *expressions)
{
    time_started = _timeSinceStart;
    Item *value = eval_expressions(expressions);
    time_started = 0;
    return value;
}

canonical_original_code:
struct Item *safe_evalexpressions(struct List *expressions)
{
    time_started = _timeSinceStart;
    struct Item *value = eval_expressions(expressions);
    time_started = 0;
    return value;
}


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

time_started = timeSinceStart;
result = eval(a1);
time_started = 0;
return result;
}

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

time_started = timeSinceStart;
result = func12(a1);
time_started = 0;
return result;
}

original_code:
Item *safe_eval(List *expressions)
{
    time_started = _timeSinceStart;
    Item *value = eval(expressions);
    time_started = 0;
    return value;
}

canonical_original_code:
struct Item *safe_eval(struct List *expressions)
{
    time_started = _timeSinceStart;
    struct Item *value = eval(expressions);
    time_started = 0;
    return value;
}


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

if ( a1 <= 0x67FF )
result = *(unsigned __int16 *)(a1 + 1);
else
result = *(unsigned __int8 *)(a1 + 1);
return result;
}

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

if ( a1 <= 0x67FF )
result = *(unsigned __int16 *)(a1 + 1);
else
result = *(unsigned __int8 *)(a1 + 1);
return result;
}

original_code:
uint16_t getuint16_value(Item *item)
{
    return ((void *)item>=(void*)0x6800) ? *(((uint8_t *)item+(sizeof(uint8_t)))) : *((uint16_t *)((uint8_t *)item+(sizeof(uint8_t))));
}

canonical_original_code:
unsigned short getuint16_value(struct Item *item)
{
    return ((void *)item>=(void *)0x6800) ? *(((unsigned char *)item+(sizeof(unsigned char)))) : *((unsigned short *)((unsigned char *)item+(sizeof(unsigned char))));
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall getuint8_value(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 1);
}

original_code:
uint16_t getuint8_value(Item *item)
{
    return ((void *)item>=(void*)0x6800) ? *(((uint8_t *)item+(sizeof(uint8_t)))) : *((uint8_t *)((uint8_t *)item+(sizeof(uint8_t))));
}

canonical_original_code:
unsigned short getuint8_value(struct Item *item)
{
    return ((void *)item>=(void *)0x6800) ? *(((unsigned char *)item+(sizeof(unsigned char)))) : *((unsigned char *)((unsigned char *)item+(sizeof(unsigned char))));
}


decompiled_code:
char *__fastcall eval_as_string(unsigned __int8 *a1)
{
char v1; // al
const char *v2; // r8
char *result; // rax
unsigned __int16 v4; // ax
unsigned __int16 v5; // ax

while ( 1 )
{
v1 = item_type(a1);
if ( v1 != 4 )
break;
LABEL_4:
a1 = (unsigned __int8 *)get_variable_item();
}
while ( v1 == 1 )
{
a1 = (unsigned __int8 *)eval((__int64)(a1 + 1));
v1 = item_type(a1);
if ( v1 == 4 )
goto LABEL_4;
}
if ( v1 == 2 || v1 == 5 )
{
v2 = (const char *)(a1 + 1);
if ( (unsigned __int64)a1 <= 0x67FF )
return (char *)v2;
strncpy(str_buf, v2, 0x30uLL);
result = str_buf;
}
else
{
if ( v1 == 6 )
{
v5 = getuint8_value((__int64)a1);
print_number(str_buf, v5);
return str_buf;
}
v2 = 0LL;
if ( v1 != 7 )
return (char *)v2;
v4 = getuint16_value((unsigned __int64)a1);
print_number(str_buf, v4);
result = str_buf;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func18(unsigned __int8 *a1)
{
char v1; // al
const char *v2; // r8
char *result; // rax
unsigned __int16 v4; // ax
unsigned __int16 v5; // ax

while ( 1 )
{
v1 = func11(a1);
if ( v1 != 4 )
break;
LABEL_4:
a1 = (unsigned __int8 *)get_variable_item();
}
while ( v1 == 1 )
{
a1 = (unsigned __int8 *)func12((__int64)(a1 + 1));
v1 = func11(a1);
if ( v1 == 4 )
goto LABEL_4;
}
if ( v1 == 2 || v1 == 5 )
{
v2 = (const char *)(a1 + 1);
if ( (unsigned __int64)a1 <= 0x67FF )
return (char *)v2;
strncpy(str_buf, v2, 0x30uLL);
result = str_buf;
}
else
{
if ( v1 == 6 )
{
v5 = func17((__int64)a1);
print_number(str_buf, v5);
return str_buf;
}
v2 = 0LL;
if ( v1 != 7 )
return (char *)v2;
v4 = func16((unsigned __int64)a1);
print_number(str_buf, v4);
result = str_buf;
}
return result;
}

original_code:
const char *eval_as_string(Item *item)
{
    uint8_t type = item_type(item);
    if (type == 4) {
        return eval_as_string(get_variable_item(item));
    }
    if (type == 1) {
        return eval_as_string(eval(((List *)((uint8_t *)item+(sizeof(uint8_t))))));
    }
    if (type == 2 || type == 5) {
        if (((void *)item>=(void*)0x6800)) {
            strncpy(str_buf,((uint8_t *)item+(sizeof(uint8_t))),48);
            return str_buf;
        } else {
            return ((uint8_t *)item+(sizeof(uint8_t)));
        }
    }
    if (type == 6) {
        print_number(str_buf, getuint8_value(item));
        return str_buf;
    }
    if (type == 7) {
        print_number(str_buf, getuint16_value(item));
        return str_buf;
    }
    return 0;
}

canonical_original_code:
char *eval_as_string(struct Item *item)
{
    unsigned char type = item_type(item);
    if (type == 4) {
        return eval_as_string(get_variable_item(item));
    }
    if (type == 1) {
        return eval_as_string(eval(((struct List *)((unsigned char *)item+(sizeof(unsigned char))))));
    }
    if (type == 2 || type == 5) {
        if (((void *)item>=(void *)0x6800)) {
            strncpy(str_buf,((unsigned char *)item+(sizeof(unsigned char))),48);
            return str_buf;
        } else {
            return ((unsigned char *)item+(sizeof(unsigned char)));
        }
    }
    if (type == 6) {
        print_number(str_buf, getuint8_value(item));
        return str_buf;
    }
    if (type == 7) {
        print_number(str_buf, getuint16_value(item));
        return str_buf;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall eval_as_uint8(unsigned __int8 *a1)
{
__int64 result; // rax

if ( (unsigned __int8)item_type(a1) == 6 )
result = getuint8_value((__int64)a1);
else
result = eval_as_uint16();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned __int8 *a1)
{
__int64 result; // rax

if ( (unsigned __int8)func11(a1) == 6 )
result = func17((__int64)a1);
else
result = func20();
return result;
}

original_code:
uint8_t eval_as_uint8(Item *item)
{
    uint8_t type = item_type(item);
    if (type == 6) {
        return getuint8_value(item);
    } else {
        return 0xFF & eval_as_uint16(item);
    }
}

canonical_original_code:
unsigned char eval_as_uint8(struct Item *item)
{
    unsigned char type = item_type(item);
    if (type == 6) {
        return getuint8_value(item);
    } else {
        return 0xFF & eval_as_uint16(item);
    }
}


decompiled_code:
__int64 __fastcall eval_as_uint16(unsigned __int8 *a1)
{
char v1; // al
unsigned int v2; // er8
char *v4; // rax
unsigned __int16 v5[5]; // [rsp+Eh] [rbp-Ah] BYREF

while ( 1 )
{
v1 = item_type(a1);
if ( v1 != 4 )
break;
LABEL_4:
a1 = (unsigned __int8 *)get_variable_item();
}
while ( v1 == 1 )
{
a1 = (unsigned __int8 *)eval((__int64)(a1 + 1));
v1 = item_type(a1);
if ( v1 == 4 )
goto LABEL_4;
}
if ( v1 == 7 )
return getuint16_value((unsigned __int64)a1);
if ( v1 == 6 )
return (unsigned __int8)eval_as_uint8(a1);
if ( v1 != 2 )
{
v2 = 0;
if ( v1 != 5 )
return v2;
}
v5[0] = -1;
v4 = eval_as_string(a1);
parse_number(v4, v5);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned __int8 *a1)
{
char v1; // al
unsigned int v2; // er8
char *v4; // rax
unsigned __int16 v5[5]; // [rsp+Eh] [rbp-Ah] BYREF

while ( 1 )
{
v1 = func11(a1);
if ( v1 != 4 )
break;
LABEL_4:
a1 = (unsigned __int8 *)get_variable_item();
}
while ( v1 == 1 )
{
a1 = (unsigned __int8 *)func12((__int64)(a1 + 1));
v1 = func11(a1);
if ( v1 == 4 )
goto LABEL_4;
}
if ( v1 == 7 )
return func16((unsigned __int64)a1);
if ( v1 == 6 )
return (unsigned __int8)func19(a1);
if ( v1 != 2 )
{
v2 = 0;
if ( v1 != 5 )
return v2;
}
v5[0] = -1;
v4 = func18(a1);
parse_number(v4, v5);
return v5[0];
}

original_code:
uint16_t eval_as_uint16(Item *item)
{
    uint8_t type = item_type(item);
    if (type == 4) {
        return eval_as_uint16(get_variable_item(item));
    }
    if (type == 1) {
        return eval_as_uint16(eval(((List *)((uint8_t *)item+(sizeof(uint8_t))))));
    }
    if (type == 7) {
        return getuint16_value(item);
    }
    if (type == 6) {
        return eval_as_uint8(item);
    }
    if (type == 2 || type == 5) {
        uint16_t ret = -1;
        const char *val = eval_as_string(item);
        parse_number(val, &ret);
        return ret;
    }
    return 0;
}

canonical_original_code:
unsigned short eval_as_uint16(struct Item *item)
{
    unsigned char type = item_type(item);
    if (type == 4) {
        return eval_as_uint16(get_variable_item(item));
    }
    if (type == 1) {
        return eval_as_uint16(eval(((struct List *)((unsigned char *)item+(sizeof(unsigned char))))));
    }
    if (type == 7) {
        return getuint16_value(item);
    }
    if (type == 6) {
        return eval_as_uint8(item);
    }
    if (type == 2 || type == 5) {
        unsigned short ret = -1;
        char *val = eval_as_string(item);
        parse_number(val, &ret);
        return ret;
    }
    return 0;
}

variable_types:
ret
unsigned short

variable_types:
val
char *


decompiled_code:
__int64 __fastcall list_size(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbp
unsigned int v2; // er12
__int64 v3; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0;
do
{
v3 = first((__int64)v1);
v2 += item_size(v3) + 1;
v1 = rest(v1);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbp
unsigned int v2; // er12
__int64 v3; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0;
do
{
v3 = func0((__int64)v1);
v2 += func22(v3) + 1;
v1 = func5(v1);
}
while ( v1 );
return v2;
}

original_code:
uint16_t list_size(List *list)
{
    uint16_t size = 0;
    while (list) {
        size += 1+item_size(first(list));
        list = rest(list);
    }
    return size;
}

canonical_original_code:
unsigned short list_size(struct List *list)
{
    unsigned short size = 0;
    while (list) {
        size += 1+item_size(first(list));
        list = rest(list);
    }
    return size;
}

variable_types:
size
unsigned short


decompiled_code:
__int64 __fastcall item_size(unsigned __int8 *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
switch ( (unsigned __int8)item_type(a1) )
{
case 1u:
result = (unsigned int)list_size(a1 + 1) + 1;
break;
case 2u:
case 5u:
result = (unsigned int)strlen((const char *)a1 + 1) + 2;
break;
case 3u:
case 4u:
case 7u:
result = 3LL;
break;
case 6u:
result = 2LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned __int8 *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
switch ( (unsigned __int8)func11(a1) )
{
case 1u:
result = (unsigned int)func21(a1 + 1) + 1;
break;
case 2u:
case 5u:
result = (unsigned int)strlen((const char *)a1 + 1) + 2;
break;
case 3u:
case 4u:
case 7u:
result = 3LL;
break;
case 6u:
result = 2LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
uint16_t item_size(Item *item)
{
    if (item == 0) {
        return 0;
    }
    switch (item_type(item)) {
    case 1:
        return 1+list_size(((List *)((uint8_t *)item+(sizeof(uint8_t)))));
     case 3:
     case 4:
         return 3;
    case 2:
    case 5:
        return 2+ (((void *)item>=(void*)0x6800) ? strlen(((uint8_t *)item+(sizeof(uint8_t)))) : strlen(((uint8_t *)item+(sizeof(uint8_t)))));
    case 6:
        return 2;
    case 7:
        return 3;
    default:
        return 0;
    }
}

canonical_original_code:
unsigned short item_size(struct Item *item)
{
    if (item == 0) {
        return 0;
    }
    switch (item_type(item)) {
    case 1:
        return 1+list_size(((struct List *)((unsigned char *)item+(sizeof(unsigned char)))));
     case 3:
     case 4:
         return 3;
    case 2:
    case 5:
        return 2+ (((void *)item>=(void *)0x6800) ? strlen(((unsigned char *)item+(sizeof(unsigned char)))) : strlen(((unsigned char *)item+(sizeof(unsigned char)))));
    case 6:
        return 2;
    case 7:
        return 3;
    default:
        return 0;
    }
}


decompiled_code:
bool __fastcall set_current(unsigned __int8 *a1, char a2, unsigned __int8 a3, unsigned __int64 a4)
{
unsigned __int8 v4; // si

v4 = a2 + 2;
a1[1] = a3;
*a1 = v4;
return a4 > (unsigned __int64)&a1[v4];
}

canonical_decompiled_code:
bool __fastcall func23(unsigned __int8 *a1, char a2, unsigned __int8 a3, unsigned __int64 a4)
{
unsigned __int8 v4; // si

v4 = a2 + 2;
a1[1] = a3;
*a1 = v4;
return a4 > (unsigned __int64)&a1[v4];
}

original_code:
_Bool set_current(List *current, uint16_t size, lio_type type, uint8_t *end)
{
    current->rest = size + (sizeof(uint8_t)+(sizeof(uint8_t)));
    current->first.type = type;
    if ((uint8_t *)current + current->rest >= end) {
        return 0;
    }
    return 1;
}

canonical_original_code:
_Bool set_current(struct List *current, unsigned short size, unsigned char type, unsigned char *end)
{
    current->rest = size + (sizeof(unsigned char)+(sizeof(unsigned char)));
    current->first.type = type;
    if ((unsigned char *)current + current->rest >= end) {
        return 0;
    }
    return 1;
}

variable_types:
end
unsigned char *


decompiled_code:
__int64 __fastcall is_number(_BYTE *a1, _WORD *a2)
{
if ( *a1 != 39 || a1[2] != 39 )
return parse_number(a1, a2);
*a2 = (unsigned __int8)a1[1];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func24(_BYTE *a1, _WORD *a2)
{
if ( *a1 != 39 || a1[2] != 39 )
return parse_number(a1, a2);
*a2 = (unsigned __int8)a1[1];
return 1LL;
}

original_code:
_Bool is_number(const uint8_t *buf, uint16_t *value)
{
    if (buf[0] == '\'' && buf[2] == '\'') {
        *value = buf[1];
        return 1;
    } else {
        return parse_number(buf, value);
    }
}

canonical_original_code:
_Bool is_number(unsigned char *buf, unsigned short *value)
{
    if (buf[0] == '\'' && buf[2] == '\'') {
        *value = buf[1];
        return 1;
    } else {
        return parse_number(buf, value);
    }
}

variable_types:
buf
unsigned char *

variable_types:
value
unsigned short *


decompiled_code:
__int64 __fastcall next_token(__int64 a1, _BYTE *a2)
{
unsigned int v2; // er12
char v4; // al
char v5; // al
__int64 result; // rax
char i; // r12
char v8; // al

v2 = (unsigned __int8)lio_stopped;
if ( !lio_stopped )
{
while ( 2 )
{
v4 = (*(__int64 (**)(void))a1)();
*a2 = v4;
if ( v4 )
{
switch ( v4 )
{
case 9:
case 10:
case 13:
case 32:
if ( (_BYTE)v2 )
goto LABEL_17;
if ( lio_stopped )
return 0LL;
continue;
case 34:
if ( (_BYTE)v2 )
{
(*(void (__fastcall **)(__int64))(a1 + 8))(34LL);
LABEL_17:
*a2 = 0;
result = v2;
}
else
{
++a2;
for ( i = 0; ; i = v8 )
{
v8 = (*(__int64 (**)(void))a1)();
*a2 = v8;
if ( !v8 || i != 92 && v8 == 34 )
break;
++a2;
}
LABEL_23:
a2[1] = 0;
result = 1LL;
}
return result;
case 35:
case 59:
do
{
v5 = (*(__int64 (**)(void))a1)();
*a2 = v5;
}
while ( v5 != 10 && v5 );
if ( lio_stopped )
return 0LL;
continue;
case 40:
case 41:
if ( !(_BYTE)v2 )
goto LABEL_23;
(*(void (__fastcall **)(_QWORD))(a1 + 8))((unsigned int)v4);
*a2 = 0;
return v2;
default:
++a2;
v2 = 1;
if ( lio_stopped )
return 0LL;
continue;
}
}
break;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, _BYTE *a2)
{
unsigned int v2; // er12
char v4; // al
char v5; // al
__int64 result; // rax
char i; // r12
char v8; // al

v2 = (unsigned __int8)lio_stopped;
if ( !lio_stopped )
{
while ( 2 )
{
v4 = (*(__int64 (**)(void))a1)();
*a2 = v4;
if ( v4 )
{
switch ( v4 )
{
case 9:
case 10:
case 13:
case 32:
if ( (_BYTE)v2 )
goto LABEL_17;
if ( lio_stopped )
return 0LL;
continue;
case 34:
if ( (_BYTE)v2 )
{
(*(void (__fastcall **)(__int64))(a1 + 8))(34LL);
LABEL_17:
*a2 = 0;
result = v2;
}
else
{
++a2;
for ( i = 0; ; i = v8 )
{
v8 = (*(__int64 (**)(void))a1)();
*a2 = v8;
if ( !v8 || i != 92 && v8 == 34 )
break;
++a2;
}
LABEL_23:
a2[1] = 0;
result = 1LL;
}
return result;
case 35:
case 59:
do
{
v5 = (*(__int64 (**)(void))a1)();
*a2 = v5;
}
while ( v5 != 10 && v5 );
if ( lio_stopped )
return 0LL;
continue;
case 40:
case 41:
if ( !(_BYTE)v2 )
goto LABEL_23;
(*(void (__fastcall **)(_QWORD))(a1 + 8))((unsigned int)v4);
*a2 = 0;
return v2;
default:
++a2;
v2 = 1;
if ( lio_stopped )
return 0LL;
continue;
}
}
break;
}
}
return 0LL;
}

original_code:
_Bool next_token(char_source *source, char *buf, uint16_t tmp_len)
{
    _Bool started_token = 0;
    while(!lio_stopped && (*buf = source->read()) != 0) {
        switch (*buf) {
            case '#':
            case ';':
                while (*buf != '\n' && *buf != 0) {
                    *buf = source->read();
                }
                break;
            case ' ':
            case '\n':
            case '\t':
            case 0x0D:
                if (started_token) {
                    *buf = 0;
                    return 1;
                }
                break;
            case ')':
            case '(':
                if (started_token) {
                    source->putback(*buf);
                    *buf = 0;
                } else {
                    *(++buf) = 0;
                }
                return 1;
                break;
            case '"':
                if (started_token) {
                    source->putback(*buf);
                    *buf = 0;
                } else {
                    buf++;
                    for (char last = 0; !((*buf = source->read()) == 0 || (*buf == '"' && last != '\\')); buf++) {
                        last = *buf;
                    }
                    *(buf+1) = 0;
                }
                return 1;
                break;
            default:
                started_token = 1;
                buf++;
                break;
        }
    }
    return 0;
}

canonical_original_code:
_Bool next_token(struct char_source *source, char *buf, unsigned short tmp_len)
{
    _Bool started_token = 0;
    while(!lio_stopped && (*buf = source->read()) != 0) {
        switch (*buf) {
            case '#':
            case ';':
                while (*buf != '\n' && *buf != 0) {
                    *buf = source->read();
                }
                break;
            case ' ':
            case '\n':
            case '\t':
            case 0x0D:
                if (started_token) {
                    *buf = 0;
                    return 1;
                }
                break;
            case ')':
            case '(':
                if (started_token) {
                    source->putback(*buf);
                    *buf = 0;
                } else {
                    *(++buf) = 0;
                }
                return 1;
                break;
            case '"':
                if (started_token) {
                    source->putback(*buf);
                    *buf = 0;
                } else {
                    buf++;
                    for (char last = 0; !((*buf = source->read()) == 0 || (*buf == '"' && last != '\\')); buf++) {
                        last = *buf;
                    }
                    *(buf+1) = 0;
                }
                return 1;
                break;
            default:
                started_token = 1;
                buf++;
                break;
        }
    }
    return 0;
}

variable_types: struct char_source { char (*read)(); void (*putback)(char c); } *

variable_types:
buf
char *

variable_types: last char


decompiled_code:
int test_string_char_source()
{
char *v0; // rbx
__int64 (**v1)(void); // rbp
char v2; // al
__int64 v3; // rax
char v4; // dl
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = v6;
v1 = (__int64 (**)(void))string_source("this is a test");
do
{
v2 = (*v1)();
*v0++ = v2;
}
while ( v2 );
if ( v6[0] != 116 )
LABEL_8:
_assert_fail("0", "test_util.c", 0xCu, "test_string_char_source");
v3 = 1LL;
do
{
v4 = v6[v3];
if ( v4 != aThisIsATest[v3] )
goto LABEL_8;
++v3;
}
while ( v4 );
return putchar(46);
}

canonical_decompiled_code:
int func0()
{
char *v0; // rbx
__int64 (**v1)(void); // rbp
char v2; // al
__int64 v3; // rax
char v4; // dl
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = v6;
v1 = (__int64 (**)(void))string_source("this is a test");
do
{
v2 = (*v1)();
*v0++ = v2;
}
while ( v2 );
if ( v6[0] != 116 )
LABEL_8:
_assert_fail("0", "test_util.c", 0xCu, "test_string_char_source");
v3 = 1LL;
do
{
v4 = v6[v3];
if ( v4 != aThisIsATest[v3] )
goto LABEL_8;
++v3;
}
while ( v4 );
return putchar(46);
}

original_code:
void test_string_char_source()
{
    const char *test = "this is a test";
    char temp[64];
    char_source *src = string_source(test);
    for (int i=0; (temp[i] = src->read()) != 0; i++);
    {const char *e = temp; const char *g = test; if (g == 0 && e != 0) ((0) ? (void) (0) : __assert_fail ("0", "test_util.c", 12, __extension__ __PRETTY_FUNCTION__)); for (int i=0; ; i++) { if (e[i] != g[i]) ((0) ? (void) (0) : __assert_fail ("0", "test_util.c", 12, __extension__ __PRETTY_FUNCTION__)); if (e[i] == 0 && g[i] == 0) break; } printf(".");};
}

canonical_original_code:
void test_string_char_source()
{
    char *test = "this is a test";
    char temp[64];
    struct char_source *src = string_source(test);
    for (int i = 0; (temp[i] = src->read()) != 0; i++);
    {char *e = temp; char *g = test; if (g == 0 && e != 0) ((0) ? (void) (0) : __assert_fail ("0", "test_util.c", 12, __extension__ __PRETTY_FUNCTION__)); for (int i = 0; ; i++) { if (e[i] != g[i]) ((0) ? (void) (0) : __assert_fail ("0", "test_util.c", 12, __extension__ __PRETTY_FUNCTION__)); if (e[i] == 0 && g[i] == 0) break; } printf(".");};
}

variable_types:
test
char *

variable_types:
temp
char [64]

variable_types: i int

variable_types:
e
char *

variable_types:
g
char *

user_defined_types: struct char_source { char (*read)(); void (*putback)(char c); }