decompiled_code:
__int64 __fastcall evaluar_msj(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
char v5; // al
char v6; // al
char v7; // al

if ( *(_BYTE *)(a2 + 1) == 49 )
{
switch ( *(_BYTE *)a2 )
{
case 'c':
v6 = *(_BYTE *)(a2 + 2);
if ( v6 == 102 )
{
nuevo_archivo(a3, a4);
enviar(a1[1], 99LL, 48LL, 48LL, 0LL);
result = 1LL;
}
else if ( v6 == 116 )
{
enviar(a1[1], 99LL, 48LL, 49LL, 0LL);
result = 1LL;
}
else
{
if ( v6 == 101 )
enviar(a1[1], 99LL, 48LL, 50LL, 0LL);
result = 1LL;
}
break;
case 'd':
v5 = *(_BYTE *)(a2 + 2);
if ( v5 == 102 )
{
enviar(a1[1], 100LL, 48LL, 49LL, 0LL);
result = 1LL;
}
else
{
if ( v5 == 116 )
enviar(a1[1], 100LL, 48LL, 48LL, 0LL);
else
enviar(a1[1], 100LL, 48LL, 50LL, 0LL);
result = 1LL;
}
break;
case 'l':
enviar(a1[1], 108LL, 48LL, 102LL, *(_QWORD *)(a2 + 8));
result = 1LL;
break;
case 'o':
v7 = *(_BYTE *)(a2 + 2);
if ( v7 == 101 )
{
enviar(a1[1], 111LL, 48LL, 49LL, 0LL);
result = 1LL;
}
else
{
if ( v7 == 102 )
enviar(a1[1], 111LL, 48LL, 50LL, 0LL);
else
enviar(a1[1], 111LL, (unsigned int)v7, 48LL, 0LL);
result = 1LL;
}
break;
case 'r':
result = 1LL;
if ( *(_BYTE *)(a2 + 2) == 116 )
{
enviarWR(a1[1], 114LL, 48LL, 48LL, *(unsigned int *)(a2 + 4), *(_QWORD *)(a2 + 8), 0LL);
result = 1LL;
}
break;
case 's':
result = 1LL;
if ( *(_BYTE *)(a2 + 2) == 116 )
{
enviar(a1[1], 115LL, 48LL, 48LL, 0LL);
result = 1LL;
}
break;
case 'w':
result = 1LL;
if ( *(_BYTE *)(a2 + 2) == 116 )
{
enviar(a1[1], 119LL, 48LL, 48LL, 0LL);
result = 1LL;
}
break;
default:
result = 1LL;
break;
}
}
else
{
envio_por_anillo(a1, (_BYTE *)a2, a3, 0LL);
liberar_msj(a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
char v5; // al
char v6; // al
char v7; // al

if ( *(_BYTE *)(a2 + 1) == 49 )
{
switch ( *(_BYTE *)a2 )
{
case 'c':
v6 = *(_BYTE *)(a2 + 2);
if ( v6 == 102 )
{
nuevo_archivo(a3, a4);
enviar(a1[1], 99LL, 48LL, 48LL, 0LL);
result = 1LL;
}
else if ( v6 == 116 )
{
enviar(a1[1], 99LL, 48LL, 49LL, 0LL);
result = 1LL;
}
else
{
if ( v6 == 101 )
enviar(a1[1], 99LL, 48LL, 50LL, 0LL);
result = 1LL;
}
break;
case 'd':
v5 = *(_BYTE *)(a2 + 2);
if ( v5 == 102 )
{
enviar(a1[1], 100LL, 48LL, 49LL, 0LL);
result = 1LL;
}
else
{
if ( v5 == 116 )
enviar(a1[1], 100LL, 48LL, 48LL, 0LL);
else
enviar(a1[1], 100LL, 48LL, 50LL, 0LL);
result = 1LL;
}
break;
case 'l':
enviar(a1[1], 108LL, 48LL, 102LL, *(_QWORD *)(a2 + 8));
result = 1LL;
break;
case 'o':
v7 = *(_BYTE *)(a2 + 2);
if ( v7 == 101 )
{
enviar(a1[1], 111LL, 48LL, 49LL, 0LL);
result = 1LL;
}
else
{
if ( v7 == 102 )
enviar(a1[1], 111LL, 48LL, 50LL, 0LL);
else
enviar(a1[1], 111LL, (unsigned int)v7, 48LL, 0LL);
result = 1LL;
}
break;
case 'r':
result = 1LL;
if ( *(_BYTE *)(a2 + 2) == 116 )
{
enviarWR(a1[1], 114LL, 48LL, 48LL, *(unsigned int *)(a2 + 4), *(_QWORD *)(a2 + 8), 0LL);
result = 1LL;
}
break;
case 's':
result = 1LL;
if ( *(_BYTE *)(a2 + 2) == 116 )
{
enviar(a1[1], 115LL, 48LL, 48LL, 0LL);
result = 1LL;
}
break;
case 'w':
result = 1LL;
if ( *(_BYTE *)(a2 + 2) == 116 )
{
enviar(a1[1], 119LL, 48LL, 48LL, 0LL);
result = 1LL;
}
break;
default:
result = 1LL;
break;
}
}
else
{
func11(a1, (_BYTE *)a2, a3, 0LL);
liberar_msj(a2);
result = 0LL;
}
return result;
}

original_code:
int evaluar_msj(DescriptorColas *cola, Msj *msj, ListaArchivos *lista, char *candidato)
{
  if(msj->contador == '1') {
    switch(msj->tipo) {
      case 'l':
        enviar(cola->disp, 'l', '0', 'f', msj->nombre);
        break;
      case 'd':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp, 'd', '0', '0', ((void *)0));
            break;
          case 'f':
            enviar(cola->disp, 'd', '0', '1', ((void *)0));
            break;
          default:
            enviar(cola->disp, 'd', '0', '2', ((void *)0));
            break;
        }
        break;
      case 'c':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp, 'c', '0', '1', ((void *)0));
            break;
          case 'f':
            nuevo_archivo(lista, candidato);
            enviar(cola->disp, 'c', '0', '0', ((void *)0));
            break;
          case 'e':
            enviar(cola->disp, 'c', '0', '2', ((void *)0));
            break;
        }
        break;
      case 'o':
        switch(msj->dato) {
          case 'f':
            enviar(cola->disp, 'o', '0', '2', ((void *)0));
            break;
          case 'e':
            enviar(cola->disp, 'o', '0', '1', ((void *)0));
            break;
          default:
            enviar(cola->disp, 'o', msj->dato, '0', ((void *)0));
            break;
        }
        break;
      case 'w':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp, 'w', '0', '0', ((void *)0));
            break;
        }
        break;
      case 'r':
        switch(msj->dato) {
          case 't':
            enviarWR(cola->disp, 'r', '0', '0', msj->otrodato, msj->nombre, ((void *)0));
            break;
        }
        break;
      case 's':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp,'s', '0', '0', ((void *)0));
            break;
        }
        break;
    }
    return 1;
  }
  envio_por_anillo(cola, msj, lista, ((void *)0));
  liberar_msj(msj);
  return 0;
}

canonical_original_code:
int evaluar_msj(struct colas *cola, struct msj_ *msj, struct lista_ *lista, char *candidato)
{
  if(msj->contador == '1') {
    switch(msj->tipo) {
      case 'l':
        enviar(cola->disp, 'l', '0', 'f', msj->nombre);
        break;
      case 'd':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp, 'd', '0', '0', ((void *)0));
            break;
          case 'f':
            enviar(cola->disp, 'd', '0', '1', ((void *)0));
            break;
          default:
            enviar(cola->disp, 'd', '0', '2', ((void *)0));
            break;
        }
        break;
      case 'c':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp, 'c', '0', '1', ((void *)0));
            break;
          case 'f':
            nuevo_archivo(lista, candidato);
            enviar(cola->disp, 'c', '0', '0', ((void *)0));
            break;
          case 'e':
            enviar(cola->disp, 'c', '0', '2', ((void *)0));
            break;
        }
        break;
      case 'o':
        switch(msj->dato) {
          case 'f':
            enviar(cola->disp, 'o', '0', '2', ((void *)0));
            break;
          case 'e':
            enviar(cola->disp, 'o', '0', '1', ((void *)0));
            break;
          default:
            enviar(cola->disp, 'o', msj->dato, '0', ((void *)0));
            break;
        }
        break;
      case 'w':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp, 'w', '0', '0', ((void *)0));
            break;
        }
        break;
      case 'r':
        switch(msj->dato) {
          case 't':
            enviarWR(cola->disp, 'r', '0', '0', msj->otrodato, msj->nombre, ((void *)0));
            break;
        }
        break;
      case 's':
        switch(msj->dato) {
          case 't':
            enviar(cola->disp,'s', '0', '0', ((void *)0));
            break;
        }
        break;
    }
    return 1;
  }
  envio_por_anillo(cola, msj, lista, ((void *)0));
  liberar_msj(msj);
  return 0;
}


decompiled_code:
ssize_t __fastcall responder_al_cliente(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

original_code:
void responder_al_cliente(int conn_s, char mensaje[])
{
  write(conn_s, mensaje, strlen(mensaje));
}

variable_types:
mensaje
char []

return_type: void


decompiled_code:
__int64 eleccion_worker()
{
__int64 v0; // rdx
__int64 v1; // rax
int v2; // ebx
int v3; // ebx
__int64 v5[2]; // [rsp+0h] [rbp-28h]
int v6; // [rsp+10h] [rbp-18h]

v5[0] = 0LL;
v5[1] = 0LL;
v6 = 0;
v0 = bitmap_worker;
v1 = 0LL;
v2 = 0;
do
{
if ( !*(_BYTE *)(v0 + v1) )
*((_DWORD *)v5 + v2++) = v1;
++v1;
}
while ( v1 != 5 );
if ( v2 )
{
v3 = *((_DWORD *)v5 + rand() % v2);
pthread_mutex_lock(&m);
*(_BYTE *)(bitmap_worker + v3) = 1;
pthread_mutex_unlock(&m);
}
else
{
v3 = -1;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdx
__int64 v1; // rax
int v2; // ebx
int v3; // ebx
__int64 v5[2]; // [rsp+0h] [rbp-28h]
int v6; // [rsp+10h] [rbp-18h]

v5[0] = 0LL;
v5[1] = 0LL;
v6 = 0;
v0 = bitmap_worker;
v1 = 0LL;
v2 = 0;
do
{
if ( !*(_BYTE *)(v0 + v1) )
*((_DWORD *)v5 + v2++) = v1;
++v1;
}
while ( v1 != 5 );
if ( v2 )
{
v3 = *((_DWORD *)v5 + rand() % v2);
pthread_mutex_lock(&m);
*(_BYTE *)(bitmap_worker + v3) = 1;
pthread_mutex_unlock(&m);
}
else
{
v3 = -1;
}
return (unsigned int)v3;
}

original_code:
int eleccion_worker()
{
  int i,j,n;
  int aux[5] = {0};
  for(i=0,j=0;i<5;i++) {
    if(bitmap_worker[i]== 0) {
      aux[j] = i;
      j++;
    }
  }
  if(j==0)
    return -1;
  i = rand() % j;
  n = aux[i];
  pthread_mutex_lock(&m);
  bitmap_worker[n] = 1;
  pthread_mutex_unlock(&m);
  return n;
}

canonical_original_code:
int eleccion_worker()
{
  int i; int j; int n;
  int aux[5] = {0};
  for(i=0,j=0;i<5;i++) {
    if(bitmap_worker[i]== 0) {
      aux[j] = i;
      j++;
    }
  }
  if(j==0)
    return -1;
  i = rand() % j;
  n = aux[i];
  pthread_mutex_lock(&m);
  bitmap_worker[n] = 1;
  pthread_mutex_unlock(&m);
  return n;
}

variable_types: i int

variable_types: j int

variable_types: n int

variable_types:
aux
int [5]

return_type: int


decompiled_code:
__int64 __fastcall PS_operadorLSD(unsigned int *a1, int a2)
{
__int64 v2; // rbx
char v4[536]; // [rsp+0h] [rbp-218h] BYREF

enviar(*a1, 108LL, 48LL, 109LL, 0LL);
v2 = recibir(a1[1]);
strcpy(v4, "OK");
strcat(v4, *(const char **)(v2 + 8));
*(_WORD *)&v4[strlen(v4)] = 10;
responder_al_cliente(a2, v4);
return liberar_msj(v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, int a2)
{
__int64 v2; // rbx
char v4[536]; // [rsp+0h] [rbp-218h] BYREF

enviar(*a1, 108LL, 48LL, 109LL, 0LL);
v2 = recibir(a1[1]);
strcpy(v4, "OK");
strcat(v4, *(const char **)(v2 + 8));
*(_WORD *)&v4[strlen(v4)] = 10;
func0(a2, v4);
return liberar_msj(v2);
}

original_code:
void PS_operadorLSD(DescriptorColas *cola, long conn_s)
{
  char buffer[512];
  Msj *msj;
  enviar(cola->worker,'l','0','m',((void *)0));
  msj = recibir(cola->disp);
  sprintf(buffer,"OK");
  strcat(buffer,msj->nombre);
  strcat(buffer,"\n");
  responder_al_cliente(conn_s, buffer);
  liberar_msj(msj);
}

canonical_original_code:
void PS_operadorLSD(struct colas *cola, long conn_s)
{
  char buffer[512];
  struct msj_ *msj;
  enviar(cola->worker,'l','0','m',((void *)0));
  msj = recibir(cola->disp);
  sprintf(buffer,"OK");
  strcat(buffer,msj->nombre);
  strcat(buffer,"\n");
  responder_al_cliente(conn_s, buffer);
  liberar_msj(msj);
}

variable_types: struct colas { int worker; int disp; int anillo; } *

variable_types:
buffer
char [512]

variable_types: struct msj_ { char tipo; char contador; char dato; int otrodato; char *nombre; char *texto; } *


decompiled_code:
__int64 __fastcall PS_operadorDEL(unsigned int *a1, int a2)
{
char *v2; // rax
char *v3; // rbx
__int64 v5; // rbx
char v6; // al
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(0LL, delim);
if ( !v2 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v3 = v2;
if ( !strcmp(v2, "\r\n") || strtok(0LL, delim) )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
enviar(*a1, 100LL, 48LL, 109LL, v3);
v5 = recibir(a1[1]);
v6 = *(_BYTE *)(v5 + 2);
if ( v6 == 48 )
{
responder_al_cliente(a2, &unk_D6B);
}
else if ( v6 == 49 )
{
responder_al_cliente(a2, "ERROR EL ARCHIVO NO EXISTE\n");
}
else
{
responder_al_cliente(a2, "ERROR EL ARCHIVO ESTA ABIERTO\n");
}
return liberar_msj(v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, int a2)
{
char *v2; // rax
char *v3; // rbx
__int64 v5; // rbx
char v6; // al
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(0LL, delim);
if ( !v2 )
return func0(a2, "ERROR DE SINTAXIS\n");
v3 = v2;
if ( !strcmp(v2, "\r\n") || strtok(0LL, delim) )
return func0(a2, "ERROR DE SINTAXIS\n");
enviar(*a1, 100LL, 48LL, 109LL, v3);
v5 = recibir(a1[1]);
v6 = *(_BYTE *)(v5 + 2);
if ( v6 == 48 )
{
func0(a2, &unk_D6B);
}
else if ( v6 == 49 )
{
func0(a2, "ERROR EL ARCHIVO NO EXISTE\n");
}
else
{
func0(a2, "ERROR EL ARCHIVO ESTA ABIERTO\n");
}
return liberar_msj(v5);
}

original_code:
void PS_operadorDEL(DescriptorColas *cola, long conn_s)
{
  char *token;
  char delims[] = " ";
  Msj *msj;
  if (((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0)
      && (strtok(((void *)0), delims) == ((void *)0))) {
    enviar(cola->worker,'d','0','m',token);
    msj = recibir(cola->disp);
    switch(msj->dato) {
      case '0':
        responder_al_cliente(conn_s, "OK\n");
        break;
      case '1':
        responder_al_cliente(conn_s, "ERROR EL ARCHIVO NO EXISTE\n");
        break;
      default:
        responder_al_cliente(conn_s, "ERROR EL ARCHIVO ESTA ABIERTO\n");
        break;
    }
    liberar_msj(msj);
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

canonical_original_code:
void PS_operadorDEL(struct colas *cola, long conn_s)
{
  char *token;
  char delims[] = " ";
  struct msj_ *msj;
  if (((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0)
      && (strtok(((void *)0), delims) == ((void *)0))) {
    enviar(cola->worker,'d','0','m',token);
    msj = recibir(cola->disp);
    switch(msj->dato) {
      case '0':
        responder_al_cliente(conn_s, "OK\n");
        break;
      case '1':
        responder_al_cliente(conn_s, "ERROR EL ARCHIVO NO EXISTE\n");
        break;
      default:
        responder_al_cliente(conn_s, "ERROR EL ARCHIVO ESTA ABIERTO\n");
        break;
    }
    liberar_msj(msj);
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

variable_types:
token
char *

variable_types:
delims
char []

user_defined_types: struct colas { int worker; int disp; int anillo; }

user_defined_types: struct msj_ { char tipo; char contador; char dato; int otrodato; char *nombre; char *texto; }


decompiled_code:
__int64 __fastcall PS_operadorCRE(unsigned int *a1, int a2)
{
char *v2; // rax
char *v3; // rbx
__int64 v5; // rbx
char v6; // al
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(0LL, delim);
if ( !v2 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v3 = v2;
if ( !strcmp(v2, "\r\n") || strtok(0LL, delim) )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
enviar(*a1, 99LL, 48LL, 109LL, v3);
v5 = recibir(a1[1]);
v6 = *(_BYTE *)(v5 + 2);
switch ( v6 )
{
case '1':
responder_al_cliente(a2, "ERROR EL ARCHIVO YA EXISTE\n");
break;
case '2':
responder_al_cliente(a2, "ERROR INTENTE DE NUEVO\n");
break;
case '0':
responder_al_cliente(a2, &unk_D6B);
break;
}
return liberar_msj(v5);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2)
{
char *v2; // rax
char *v3; // rbx
__int64 v5; // rbx
char v6; // al
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(0LL, delim);
if ( !v2 )
return func0(a2, "ERROR DE SINTAXIS\n");
v3 = v2;
if ( !strcmp(v2, "\r\n") || strtok(0LL, delim) )
return func0(a2, "ERROR DE SINTAXIS\n");
enviar(*a1, 99LL, 48LL, 109LL, v3);
v5 = recibir(a1[1]);
v6 = *(_BYTE *)(v5 + 2);
switch ( v6 )
{
case '1':
func0(a2, "ERROR EL ARCHIVO YA EXISTE\n");
break;
case '2':
func0(a2, "ERROR INTENTE DE NUEVO\n");
break;
case '0':
func0(a2, &unk_D6B);
break;
}
return liberar_msj(v5);
}

original_code:
void PS_operadorCRE(DescriptorColas *cola, long conn_s)
{
  char *token;
  char delims[] = " ";
  Msj *msj;
  if (((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0)
      && (strtok(((void *)0), delims) == ((void *)0))) {
    enviar(cola->worker,'c','0','m',token);
    msj = recibir(cola->disp);
    switch(msj->dato) {
      case '0':
        responder_al_cliente(conn_s, "OK\n");
        break;
      case '1':
        responder_al_cliente(conn_s, "ERROR EL ARCHIVO YA EXISTE\n");
        break;
      case '2':
        responder_al_cliente(conn_s, "ERROR INTENTE DE NUEVO\n");
        break;
    }
    liberar_msj(msj);
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

canonical_original_code:
void PS_operadorCRE(struct colas *cola, long conn_s)
{
  char *token;
  char delims[] = " ";
  struct msj_ *msj;
  if (((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0)
      && (strtok(((void *)0), delims) == ((void *)0))) {
    enviar(cola->worker,'c','0','m',token);
    msj = recibir(cola->disp);
    switch(msj->dato) {
      case '0':
        responder_al_cliente(conn_s, "OK\n");
        break;
      case '1':
        responder_al_cliente(conn_s, "ERROR EL ARCHIVO YA EXISTE\n");
        break;
      case '2':
        responder_al_cliente(conn_s, "ERROR INTENTE DE NUEVO\n");
        break;
    }
    liberar_msj(msj);
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}


decompiled_code:
__int64 __fastcall PS_operadorOPN(unsigned int *a1, int a2, unsigned int a3)
{
char *v4; // rax
char *v5; // rbx
__int64 v7; // r12
char v8; // al
unsigned int v9; // eax
char s[10]; // [rsp+4h] [rbp-34h] BYREF
char delim[2]; // [rsp+Eh] [rbp-2Ah] BYREF

strcpy(delim, " ");
v4 = strtok(0LL, delim);
if ( !v4 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v5 = v4;
if ( !strcmp(v4, "\r\n") || strtok(0LL, delim) )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( buscar_descriptor(descriptores, v5, 0LL, 0LL) )
return responder_al_cliente(a2, "ERROR EL ARCHIVO ESTA ABIERTO\n");
enviar(*a1, 111LL, 48LL, 109LL, v5);
v7 = recibir(a1[1]);
v8 = *(_BYTE *)(v7 + 2);
switch ( v8 )
{
case '1':
responder_al_cliente(a2, "ERROR EL ARCHIVO ESTA ABIERTO\n");
break;
case '2':
responder_al_cliente(a2, "ERROR EL ARCHIVO NO EXISTE\n");
break;
case '0':
v9 = nuevo_descriptor(descriptores, v5, (unsigned int)(*(char *)(v7 + 1) - 48), a3);
sprintf(s, "OK FD %d\n", v9);
responder_al_cliente(a2, s);
break;
}
return liberar_msj(v7);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int a2, unsigned int a3)
{
char *v4; // rax
char *v5; // rbx
__int64 v7; // r12
char v8; // al
unsigned int v9; // eax
char s[10]; // [rsp+4h] [rbp-34h] BYREF
char delim[2]; // [rsp+Eh] [rbp-2Ah] BYREF

strcpy(delim, " ");
v4 = strtok(0LL, delim);
if ( !v4 )
return func0(a2, "ERROR DE SINTAXIS\n");
v5 = v4;
if ( !strcmp(v4, "\r\n") || strtok(0LL, delim) )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( buscar_descriptor(descriptores, v5, 0LL, 0LL) )
return func0(a2, "ERROR EL ARCHIVO ESTA ABIERTO\n");
enviar(*a1, 111LL, 48LL, 109LL, v5);
v7 = recibir(a1[1]);
v8 = *(_BYTE *)(v7 + 2);
switch ( v8 )
{
case '1':
func0(a2, "ERROR EL ARCHIVO ESTA ABIERTO\n");
break;
case '2':
func0(a2, "ERROR EL ARCHIVO NO EXISTE\n");
break;
case '0':
v9 = nuevo_descriptor(descriptores, v5, (unsigned int)(*(char *)(v7 + 1) - 48), a3);
sprintf(s, "OK FD %d\n", v9);
func0(a2, s);
break;
}
return liberar_msj(v7);
}

original_code:
void PS_operadorOPN(DescriptorColas *cola, long conn_s, int worker)
{
  char *token;
  char delims[] = " ";
  char buffer[10];
  Msj *msj;
  if (((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0) && (strtok(((void *)0), delims) == ((void *)0))) {
    if (buscar_descriptor(descriptores, token, 0, 0) != ((void *)0)) {
      responder_al_cliente(conn_s, "ERROR EL ARCHIVO ESTA ABIERTO\n");
    }
    else {
      enviar(cola->worker,'o','0','m',token);
      msj = recibir(cola->disp);
      switch(msj->dato) {
        case '0':
          sprintf(buffer,"OK FD %d\n", nuevo_descriptor(descriptores, token, msj->contador - '0', worker));
          responder_al_cliente(conn_s, buffer);
          break;
        case '1':
          responder_al_cliente(conn_s, "ERROR EL ARCHIVO ESTA ABIERTO\n");
          break;
        case '2':
          responder_al_cliente(conn_s, "ERROR EL ARCHIVO NO EXISTE\n");
          break;
      }
      liberar_msj(msj);
    }
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

canonical_original_code:
void PS_operadorOPN(struct colas *cola, long conn_s, int worker)
{
  char *token;
  char delims[] = " ";
  char buffer[10];
  struct msj_ *msj;
  if (((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0) && (strtok(((void *)0), delims) == ((void *)0))) {
    if (buscar_descriptor(descriptores, token, 0, 0) != ((void *)0)) {
      responder_al_cliente(conn_s, "ERROR EL ARCHIVO ESTA ABIERTO\n");
    }
    else {
      enviar(cola->worker,'o','0','m',token);
      msj = recibir(cola->disp);
      switch(msj->dato) {
        case '0':
          sprintf(buffer,"OK FD %d\n", nuevo_descriptor(descriptores, token, msj->contador - '0', worker));
          responder_al_cliente(conn_s, buffer);
          break;
        case '1':
          responder_al_cliente(conn_s, "ERROR EL ARCHIVO ESTA ABIERTO\n");
          break;
        case '2':
          responder_al_cliente(conn_s, "ERROR EL ARCHIVO NO EXISTE\n");
          break;
      }
      liberar_msj(msj);
    }
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

variable_types: worker int

variable_types:
buffer
char [10]


decompiled_code:
__int64 __fastcall iniciar_conexion(const char *a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
char v5[10]; // [rsp+0h] [rbp-28h] BYREF
char s2[30]; // [rsp+Ah] [rbp-1Eh] BYREF

strcpy(s2, "CON\r\n");
if ( strcmp(a1, s2) )
return (unsigned int)-1;
v2 = eleccion_worker();
v3 = v2;
if ( v2 == -1 )
{
responder_al_cliente(a2, "ERROR SERVIDOR SATURADO\n");
}
else
{
sprintf(v5, "OK ID %d\n", v2);
responder_al_cliente(a2, v5);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
char v5[10]; // [rsp+0h] [rbp-28h] BYREF
char s2[30]; // [rsp+Ah] [rbp-1Eh] BYREF

strcpy(s2, "CON\r\n");
if ( strcmp(a1, s2) )
return (unsigned int)-1;
v2 = func1();
v3 = v2;
if ( v2 == -1 )
{
func0(a2, "ERROR SERVIDOR SATURADO\n");
}
else
{
sprintf(v5, "OK ID %d\n", v2);
func0(a2, v5);
}
return v3;
}

original_code:
int iniciar_conexion(char *a, long conn_s)
{
  char con[6] = "CON\r\n";
  char buffer[10];
  int i;
  if(strcmp (a, con) == 0) {
    i = eleccion_worker();
    if(i == -1) {
      responder_al_cliente(conn_s, "ERROR SERVIDOR SATURADO\n");
    }
    else {
      sprintf(buffer,"OK ID %d\n", i);
      responder_al_cliente(conn_s, buffer);
      return i;
    }
  }
  return -1;
}

variable_types:
a
char *

variable_types:
con
char [6]


decompiled_code:
unsigned __int64 __fastcall string_to_integer(char *nptr)
{
int *v1; // rbp
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = nptr;
v1 = _errno_location();
*v1 = 0;
result = strtoul(nptr, &endptr, 10);
if ( *v1 )
return 0xFFFFFFFFLL;
if ( endptr == nptr )
return 0xFFFFFFFFLL;
if ( *endptr )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(char *nptr)
{
int *v1; // rbp
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = nptr;
v1 = _errno_location();
*v1 = 0;
result = strtoul(nptr, &endptr, 10);
if ( *v1 )
return 0xFFFFFFFFLL;
if ( endptr == nptr )
return 0xFFFFFFFFLL;
if ( *endptr )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int string_to_integer(char *s)
{
    char* p = s;
    (*__errno_location ()) = 0;
    unsigned int val;
    val = strtoul(s, &p, 10);
    if ((*__errno_location ()) != 0 || s == p || *p != 0)
      return -1;
    return val;
}

canonical_original_code:
int string_to_integer(char *s)
{
    char *p = s;
    (*__errno_location ()) = 0;
    unsigned int val;
    val = strtoul(s, &p, 10);
    if ((*__errno_location ()) != 0 || s == p || *p != 0)
      return -1;
    return val;
}

variable_types:
s
char *

variable_types:
p
char *

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall integer_to_char(int a1)
{
return (unsigned int)(a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)(a1 + 48);
}

original_code:
char integer_to_char(int n)
{
  return (char) (((int)'0') + n);
}

return_type: char


decompiled_code:
__int64 __fastcall PS_operadorWRT(unsigned int *a1, int a2, int a3)
{
char *v5; // rax
char *v6; // rax
int v7; // er14
char *v8; // rsi
bool v9; // zf
_BOOL4 v10; // er13
unsigned int v11; // er15
__int64 v13; // rax
__int64 v14; // r13
const char *v15; // rbp
char v16; // al
__int64 v17; // rbp
char *v18; // rax
int v19; // eax
char *v20; // [rsp+0h] [rbp-58h]
char *v21; // [rsp+8h] [rbp-50h]
char delim[2]; // [rsp+1Eh] [rbp-3Ah] BYREF

strcpy(delim, " ");
v5 = strtok(0LL, delim);
if ( !v5 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v5, "FD") )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v6 = strtok(0LL, delim);
v7 = string_to_integer(v6);
v8 = strtok(0LL, delim);
if ( !v8 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v9 = strcmp(v8, "SIZE") == 0;
v10 = !v9;
if ( !v9 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v21 = strtok(0LL, delim);
v11 = string_to_integer(v21);
v20 = strtok(0LL, delim);
if ( v20 )
{
v10 = v7 > 0 && (int)v11 > 0;
LABEL_7:
if ( !v10 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v13 = buscar_descriptor(descriptores, 0LL, (unsigned int)v7, 1LL);
v14 = v13;
if ( !v13 || *(_DWORD *)(v13 + 12) != a3 )
return responder_al_cliente(a2, "ERROR FD INCORRECTO\n");
v15 = (const char *)cola_cadena(v20);
if ( strlen(v15) != v11 )
return responder_al_cliente(a2, &unk_E1C);
v16 = integer_to_char(*(_DWORD *)(v14 + 8));
enviarWR(*a1, 119LL, (unsigned int)v16, 109LL, v11, *(_QWORD *)v14, v15);
v17 = recibir(a1[1]);
responder_al_cliente(a2, &unk_D6B);
return liberar_msj(v17);
}
v18 = (char *)sacar_nueva_linea(v21);
v19 = string_to_integer(v18);
if ( v7 <= 0 || v19 )
goto LABEL_7;
if ( !buscar_descriptor(descriptores, 0LL, (unsigned int)v7, 1LL) )
return responder_al_cliente(a2, "ERROR FD INCORRECTO\n");
return responder_al_cliente(a2, &unk_D6B);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, int a2, int a3)
{
char *v5; // rax
char *v6; // rax
int v7; // er14
char *v8; // rsi
bool v9; // zf
_BOOL4 v10; // er13
unsigned int v11; // er15
__int64 v13; // rax
__int64 v14; // r13
const char *v15; // rbp
char v16; // al
__int64 v17; // rbp
char *v18; // rax
int v19; // eax
char *v20; // [rsp+0h] [rbp-58h]
char *v21; // [rsp+8h] [rbp-50h]
char delim[2]; // [rsp+1Eh] [rbp-3Ah] BYREF

strcpy(delim, " ");
v5 = strtok(0LL, delim);
if ( !v5 )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v5, "FD") )
return func0(a2, "ERROR DE SINTAXIS\n");
v6 = strtok(0LL, delim);
v7 = func7(v6);
v8 = strtok(0LL, delim);
if ( !v8 )
return func0(a2, "ERROR DE SINTAXIS\n");
v9 = strcmp(v8, "SIZE") == 0;
v10 = !v9;
if ( !v9 )
return func0(a2, "ERROR DE SINTAXIS\n");
v21 = strtok(0LL, delim);
v11 = func7(v21);
v20 = strtok(0LL, delim);
if ( v20 )
{
v10 = v7 > 0 && (int)v11 > 0;
LABEL_7:
if ( !v10 )
return func0(a2, "ERROR DE SINTAXIS\n");
v13 = buscar_descriptor(descriptores, 0LL, (unsigned int)v7, 1LL);
v14 = v13;
if ( !v13 || *(_DWORD *)(v13 + 12) != a3 )
return func0(a2, "ERROR FD INCORRECTO\n");
v15 = (const char *)cola_cadena(v20);
if ( strlen(v15) != v11 )
return func0(a2, &unk_E1C);
v16 = func8(*(_DWORD *)(v14 + 8));
enviarWR(*a1, 119LL, (unsigned int)v16, 109LL, v11, *(_QWORD *)v14, v15);
v17 = recibir(a1[1]);
func0(a2, &unk_D6B);
return liberar_msj(v17);
}
v18 = (char *)sacar_nueva_linea(v21);
v19 = func7(v18);
if ( v7 <= 0 || v19 )
goto LABEL_7;
if ( !buscar_descriptor(descriptores, 0LL, (unsigned int)v7, 1LL) )
return func0(a2, "ERROR FD INCORRECTO\n");
return func0(a2, &unk_D6B);
}

original_code:
void PS_operadorWRT(DescriptorColas *cola, long conn_s, int worker)
{
  int i = 0, fd, size;
  char *token, *size_token;
  char delims[] = " ";
  DescriptorArchivo *archivo;
  Msj *msj;
  if(((token = strtok(((void *)0), delims)) != ((void *)0) ) && (strcmp(token, "FD") == 0)) {
    fd = string_to_integer(strtok(((void *)0), delims));
    if(((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "SIZE") == 0)) {
      size_token = strtok(((void *)0), delims);
      size = string_to_integer(size_token);
      if(((token = strtok(((void *)0), delims)) != ((void *)0)) && (fd > 0) && (size > 0))
        i = 1;
      if((token == ((void *)0)) && (string_to_integer(sacar_nueva_linea(size_token)) == 0) && (fd > 0))
        i = 2;
    }
  }
  switch(i) {
    case 1:
      if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
      else {
        if(archivo->worker_a == worker) {
          token = cola_cadena(token);
          if(strlen(token) == size) {
            enviarWR(cola->worker,'w',integer_to_char(archivo->worker_c),'m',size,archivo->nombre,token);
            msj = recibir(cola->disp);
            responder_al_cliente(conn_s, "OK\n");
            liberar_msj(msj);
          }
          else {
            responder_al_cliente(conn_s, "ERROR TAMAÑO INCORRECTO\n");
          }
        }
        else {
          responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
        }
      }
      break;
    case 2:
      if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
      else {
        responder_al_cliente(conn_s, "OK\n");
      }
      break;
    case 0:
      responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
      break;
  }
}

canonical_original_code:
void PS_operadorWRT(struct colas *cola, long conn_s, int worker)
{
  int i = 0; int fd; int size;
  char *token; char *size_token;
  char delims[] = " ";
  struct des_ *archivo;
  struct msj_ *msj;
  if(((token = strtok(((void *)0), delims)) != ((void *)0) ) && (strcmp(token, "FD") == 0)) {
    fd = string_to_integer(strtok(((void *)0), delims));
    if(((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "SIZE") == 0)) {
      size_token = strtok(((void *)0), delims);
      size = string_to_integer(size_token);
      if(((token = strtok(((void *)0), delims)) != ((void *)0)) && (fd > 0) && (size > 0))
        i = 1;
      if((token == ((void *)0)) && (string_to_integer(sacar_nueva_linea(size_token)) == 0) && (fd > 0))
        i = 2;
    }
  }
  switch(i) {
    case 1:
      if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
      else {
        if(archivo->worker_a == worker) {
          token = cola_cadena(token);
          if(strlen(token) == size) {
            enviarWR(cola->worker,'w',integer_to_char(archivo->worker_c),'m',size,archivo->nombre,token);
            msj = recibir(cola->disp);
            responder_al_cliente(conn_s, "OK\n");
            liberar_msj(msj);
          }
          else {
            responder_al_cliente(conn_s, "ERROR TAMAÑO INCORRECTO\n");
          }
        }
        else {
          responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
        }
      }
      break;
    case 2:
      if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
      else {
        responder_al_cliente(conn_s, "OK\n");
      }
      break;
    case 0:
      responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
      break;
  }
}

variable_types: fd int

variable_types: size int

variable_types: struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; } *


decompiled_code:
__int64 __fastcall PS_operadorREA(unsigned int *a1, int a2, int a3)
{
char *v5; // rax
char *v7; // rax
int v8; // er13
char *v9; // rsi
char *v10; // rax
char *v11; // rax
int v12; // er14
__int64 v13; // rax
_QWORD *v14; // r13
char v15; // al
__int64 v16; // rax
__int64 v17; // rbp
const char *v18; // rcx
char delim[2]; // [rsp+Eh] [rbp-22Ah] BYREF
char s[552]; // [rsp+10h] [rbp-228h] BYREF

strcpy(delim, " ");
v5 = strtok(0LL, delim);
if ( !v5 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v5, "FD") )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v7 = strtok(0LL, delim);
v8 = string_to_integer(v7);
v9 = strtok(0LL, delim);
if ( !v9 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v9, "SIZE") )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v10 = strtok(0LL, delim);
v11 = (char *)sacar_nueva_linea(v10);
v12 = string_to_integer(v11);
if ( strtok(0LL, delim) || v8 <= 0 || v12 < 0 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v13 = buscar_descriptor(descriptores, 0LL, (unsigned int)v8, 1LL);
v14 = (_QWORD *)v13;
if ( !v13 || *(_DWORD *)(v13 + 12) != a3 )
return responder_al_cliente(a2, "ERROR FD INCORRECTO\n");
v15 = integer_to_char(*(_DWORD *)(v13 + 8));
enviarWR(*a1, 114LL, (unsigned int)v15, 109LL, (unsigned int)v12, *v14, 0LL);
v16 = recibir(a1[1]);
v17 = v16;
v18 = *(const char **)(v16 + 8);
if ( v18 )
{
sprintf(s, "OK SIZE %d %s\n", *(unsigned int *)(v16 + 4), v18);
responder_al_cliente(a2, s);
}
else
{
responder_al_cliente(a2, "OK SIZE 0\n");
}
return liberar_msj(v17);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, int a2, int a3)
{
char *v5; // rax
char *v7; // rax
int v8; // er13
char *v9; // rsi
char *v10; // rax
char *v11; // rax
int v12; // er14
__int64 v13; // rax
_QWORD *v14; // r13
char v15; // al
__int64 v16; // rax
__int64 v17; // rbp
const char *v18; // rcx
char delim[2]; // [rsp+Eh] [rbp-22Ah] BYREF
char s[552]; // [rsp+10h] [rbp-228h] BYREF

strcpy(delim, " ");
v5 = strtok(0LL, delim);
if ( !v5 )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v5, "FD") )
return func0(a2, "ERROR DE SINTAXIS\n");
v7 = strtok(0LL, delim);
v8 = func7(v7);
v9 = strtok(0LL, delim);
if ( !v9 )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v9, "SIZE") )
return func0(a2, "ERROR DE SINTAXIS\n");
v10 = strtok(0LL, delim);
v11 = (char *)sacar_nueva_linea(v10);
v12 = func7(v11);
if ( strtok(0LL, delim) || v8 <= 0 || v12 < 0 )
return func0(a2, "ERROR DE SINTAXIS\n");
v13 = buscar_descriptor(descriptores, 0LL, (unsigned int)v8, 1LL);
v14 = (_QWORD *)v13;
if ( !v13 || *(_DWORD *)(v13 + 12) != a3 )
return func0(a2, "ERROR FD INCORRECTO\n");
v15 = func8(*(_DWORD *)(v13 + 8));
enviarWR(*a1, 114LL, (unsigned int)v15, 109LL, (unsigned int)v12, *v14, 0LL);
v16 = recibir(a1[1]);
v17 = v16;
v18 = *(const char **)(v16 + 8);
if ( v18 )
{
sprintf(s, "OK SIZE %d %s\n", *(unsigned int *)(v16 + 4), v18);
func0(a2, s);
}
else
{
func0(a2, "OK SIZE 0\n");
}
return liberar_msj(v17);
}

original_code:
void PS_operadorREA(DescriptorColas *cola, long conn_s, int worker)
{
  int i = 0, fd, size;
  char *token;
  char buffer[512], delims[] = " ";
  DescriptorArchivo *archivo;
  Msj *msj;
  if(((token = strtok(((void *)0), delims)) != ((void *)0) ) && (strcmp(token, "FD") == 0)) {
    fd = string_to_integer(strtok(((void *)0), delims));
    if(((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "SIZE") == 0)) {
      size = string_to_integer(sacar_nueva_linea(strtok(((void *)0), delims)));
      if(((strtok(((void *)0), delims)) == ((void *)0)) && (fd > 0) && (size >= 0))
        i = 1;
    }
  }
  if(i) {
    if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
      responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
    }
    else {
      if(archivo->worker_a == worker) {
        enviarWR(cola->worker,'r',integer_to_char(archivo->worker_c),'m', size, archivo->nombre, ((void *)0));
        msj = recibir(cola->disp);
        if(msj->nombre == ((void *)0)) {
          responder_al_cliente(conn_s, "OK SIZE 0\n");
        }
        else {
          sprintf(buffer,"OK SIZE %d %s\n",msj->otrodato, msj->nombre);
          responder_al_cliente(conn_s, buffer);
        }
        liberar_msj(msj);
      }
      else {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
    }
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

canonical_original_code:
void PS_operadorREA(struct colas *cola, long conn_s, int worker)
{
  int i = 0; int fd; int size;
  char *token;
  char buffer[512]; char delims[] = " ";
  struct des_ *archivo;
  struct msj_ *msj;
  if(((token = strtok(((void *)0), delims)) != ((void *)0) ) && (strcmp(token, "FD") == 0)) {
    fd = string_to_integer(strtok(((void *)0), delims));
    if(((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "SIZE") == 0)) {
      size = string_to_integer(sacar_nueva_linea(strtok(((void *)0), delims)));
      if(((strtok(((void *)0), delims)) == ((void *)0)) && (fd > 0) && (size >= 0))
        i = 1;
    }
  }
  if(i) {
    if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
      responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
    }
    else {
      if(archivo->worker_a == worker) {
        enviarWR(cola->worker,'r',integer_to_char(archivo->worker_c),'m', size, archivo->nombre, ((void *)0));
        msj = recibir(cola->disp);
        if(msj->nombre == ((void *)0)) {
          responder_al_cliente(conn_s, "OK SIZE 0\n");
        }
        else {
          sprintf(buffer,"OK SIZE %d %s\n",msj->otrodato, msj->nombre);
          responder_al_cliente(conn_s, buffer);
        }
        liberar_msj(msj);
      }
      else {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
    }
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

variable_types: i int

user_defined_types: struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; }


decompiled_code:
__int64 __fastcall PS_operadorCLO(unsigned int *a1, int a2, int a3)
{
char *v4; // rax
char *v6; // rax
char *v7; // r13
char *v8; // rax
int v9; // eax
__int64 v10; // rax
_QWORD *v11; // r13
char v12; // al
__int64 v13; // rbp
char delim[2]; // [rsp+Eh] [rbp-2Ah] BYREF

strcpy(delim, " ");
v4 = strtok(0LL, delim);
if ( !v4 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v4, "FD") )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v6 = strtok(0LL, delim);
v7 = v6;
if ( !v6 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( !strcmp(v6, "\r\n") )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
if ( strtok(0LL, delim) )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v8 = (char *)sacar_nueva_linea(v7);
v9 = string_to_integer(v8);
if ( v9 <= 0 )
return responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
v10 = buscar_descriptor(descriptores, 0LL, (unsigned int)v9, 1LL);
v11 = (_QWORD *)v10;
if ( !v10 || *(_DWORD *)(v10 + 12) != a3 )
return responder_al_cliente(a2, "ERROR FD INCORRECTO\n");
v12 = integer_to_char(*(_DWORD *)(v10 + 8));
enviar(*a1, 115LL, (unsigned int)v12, 109LL, *v11);
v13 = recibir(a1[1]);
borrar_descriptor(descriptores, *v11);
responder_al_cliente(a2, &unk_D6B);
return liberar_msj(v13);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, int a2, int a3)
{
char *v4; // rax
char *v6; // rax
char *v7; // r13
char *v8; // rax
int v9; // eax
__int64 v10; // rax
_QWORD *v11; // r13
char v12; // al
__int64 v13; // rbp
char delim[2]; // [rsp+Eh] [rbp-2Ah] BYREF

strcpy(delim, " ");
v4 = strtok(0LL, delim);
if ( !v4 )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( strcmp(v4, "FD") )
return func0(a2, "ERROR DE SINTAXIS\n");
v6 = strtok(0LL, delim);
v7 = v6;
if ( !v6 )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( !strcmp(v6, "\r\n") )
return func0(a2, "ERROR DE SINTAXIS\n");
if ( strtok(0LL, delim) )
return func0(a2, "ERROR DE SINTAXIS\n");
v8 = (char *)sacar_nueva_linea(v7);
v9 = func7(v8);
if ( v9 <= 0 )
return func0(a2, "ERROR DE SINTAXIS\n");
v10 = buscar_descriptor(descriptores, 0LL, (unsigned int)v9, 1LL);
v11 = (_QWORD *)v10;
if ( !v10 || *(_DWORD *)(v10 + 12) != a3 )
return func0(a2, "ERROR FD INCORRECTO\n");
v12 = func8(*(_DWORD *)(v10 + 8));
enviar(*a1, 115LL, (unsigned int)v12, 109LL, *v11);
v13 = recibir(a1[1]);
borrar_descriptor(descriptores, *v11);
func0(a2, &unk_D6B);
return liberar_msj(v13);
}

original_code:
void PS_operadorCLO(DescriptorColas *cola, long conn_s, int worker)
{
  int i = 0, fd;
  char *token;
  char delims[] = " ";
  DescriptorArchivo *archivo;
  Msj *msj;
  if(((token = strtok(((void *)0), delims)) != ((void *)0) ) && (strcmp(token, "FD") == 0) &&
     ((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0)) {
    if(((strtok(((void *)0), delims)) == ((void *)0)) && ((fd = string_to_integer(sacar_nueva_linea(token))) > 0))
      i = 1;
  }
  if(i) {
    if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
      responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
    }
    else {
      if(archivo->worker_a == worker) {
        enviar(cola->worker,'s',integer_to_char(archivo->worker_c),'m',archivo->nombre);
        msj = recibir(cola->disp);
        borrar_descriptor(descriptores, archivo->nombre);
        responder_al_cliente(conn_s, "OK\n");
        liberar_msj(msj);
      }
      else {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
    }
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}

canonical_original_code:
void PS_operadorCLO(struct colas *cola, long conn_s, int worker)
{
  int i = 0; int fd;
  char *token;
  char delims[] = " ";
  struct des_ *archivo;
  struct msj_ *msj;
  if(((token = strtok(((void *)0), delims)) != ((void *)0) ) && (strcmp(token, "FD") == 0) &&
     ((token = strtok(((void *)0), delims)) != ((void *)0)) && (strcmp(token, "\r\n") != 0)) {
    if(((strtok(((void *)0), delims)) == ((void *)0)) && ((fd = string_to_integer(sacar_nueva_linea(token))) > 0))
      i = 1;
  }
  if(i) {
    if((archivo = buscar_descriptor(descriptores, ((void *)0), fd, 1)) == ((void *)0)) {
      responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
    }
    else {
      if(archivo->worker_a == worker) {
        enviar(cola->worker,'s',integer_to_char(archivo->worker_c),'m',archivo->nombre);
        msj = recibir(cola->disp);
        borrar_descriptor(descriptores, archivo->nombre);
        responder_al_cliente(conn_s, "OK\n");
        liberar_msj(msj);
      }
      else {
        responder_al_cliente(conn_s, "ERROR FD INCORRECTO\n");
      }
    }
  }
  else {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
}


decompiled_code:
int __fastcall PS_operadorBYE(unsigned int *a1, int a2, int a3)
{
__int64 v4; // rbx
char v6; // al
__int64 v7; // rax

v4 = *descriptores;
while ( v4 )
{
if ( *(_DWORD *)(v4 + 12) == a3 )
{
v6 = integer_to_char(*(_DWORD *)(v4 + 8));
enviar(*a1, 115LL, (unsigned int)v6, 109LL, *(_QWORD *)v4);
v7 = recibir(a1[1]);
liberar_msj(v7);
v4 = borrar_descriptor(descriptores, *(_QWORD *)v4);
}
else
{
v4 = *(_QWORD *)(v4 + 24);
}
}
responder_al_cliente(a2, &unk_D6B);
return close(a2);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1, int a2, int a3)
{
__int64 v4; // rbx
char v6; // al
__int64 v7; // rax

v4 = *descriptores;
while ( v4 )
{
if ( *(_DWORD *)(v4 + 12) == a3 )
{
v6 = func8(*(_DWORD *)(v4 + 8));
enviar(*a1, 115LL, (unsigned int)v6, 109LL, *(_QWORD *)v4);
v7 = recibir(a1[1]);
liberar_msj(v7);
v4 = borrar_descriptor(descriptores, *(_QWORD *)v4);
}
else
{
v4 = *(_QWORD *)(v4 + 24);
}
}
func0(a2, &unk_D6B);
return close(a2);
}

original_code:
void PS_operadorBYE(DescriptorColas *cola, long conn_s, int worker)
{
  DescriptorArchivo *archivo;
  Msj *msj;
  archivo = descriptores->inicio;
  while(archivo != ((void *)0)) {
    if(archivo->worker_a == worker) {
      enviar(cola->worker,'s',integer_to_char(archivo->worker_c),'m',archivo->nombre);
      msj = recibir(cola->disp);
      liberar_msj(msj);
      archivo = borrar_descriptor(descriptores, archivo->nombre);
      continue;
    }
    archivo = archivo->proximo;
  }
  responder_al_cliente(conn_s, "OK\n");
  close(conn_s);
}

canonical_original_code:
void PS_operadorBYE(struct colas *cola, long conn_s, int worker)
{
  struct des_ *archivo;
  struct msj_ *msj;
  archivo = descriptores->inicio;
  while(archivo != ((void *)0)) {
    if(archivo->worker_a == worker) {
      enviar(cola->worker,'s',integer_to_char(archivo->worker_c),'m',archivo->nombre);
      msj = recibir(cola->disp);
      liberar_msj(msj);
      archivo = borrar_descriptor(descriptores, archivo->nombre);
      continue;
    }
    archivo = archivo->proximo;
  }
  responder_al_cliente(conn_s, "OK\n");
  close(conn_s);
}


decompiled_code:
__int64 __fastcall evaluar_pedido(char *a1, int a2, unsigned int a3, unsigned int *a4)
{
char *v5; // r12
__int64 v6; // rbx
unsigned int v7; // ebp
char delim[2]; // [rsp+1Eh] [rbp-3Ah] BYREF

strcpy(delim, " ");
v5 = strtok(a1, delim);
v6 = 0LL;
while ( 1 )
{
v7 = strcmp(v5, operaciones[v6]);
if ( !v7 )
break;
if ( ++v6 == 9 )
{
responder_al_cliente(a2, "ERROR DE SINTAXIS\n");
return 0;
}
}
switch ( (int)v6 )
{
case 0:
responder_al_cliente(a2, "ERROR YA ESTA CONECTADO\n");
v7 = v6;
break;
case 1:
PS_operadorLSD(a4, a2);
break;
case 2:
PS_operadorDEL(a4, a2);
break;
case 3:
PS_operadorCRE(a4, a2);
break;
case 4:
PS_operadorOPN(a4, a2, a3);
break;
case 5:
PS_operadorWRT(a4, a2, a3);
break;
case 6:
PS_operadorREA(a4, a2, a3);
break;
case 7:
PS_operadorCLO(a4, a2, a3);
break;
case 8:
PS_operadorBYE(a4, a2, a3);
v7 = 1;
break;
default:
return v7;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1, int a2, unsigned int a3, unsigned int *a4)
{
char *v5; // r12
__int64 v6; // rbx
unsigned int v7; // ebp
char delim[2]; // [rsp+1Eh] [rbp-3Ah] BYREF

strcpy(delim, " ");
v5 = strtok(a1, delim);
v6 = 0LL;
while ( 1 )
{
v7 = strcmp(v5, operaciones[v6]);
if ( !v7 )
break;
if ( ++v6 == 9 )
{
func0(a2, "ERROR DE SINTAXIS\n");
return 0;
}
}
switch ( (int)v6 )
{
case 0:
func0(a2, "ERROR YA ESTA CONECTADO\n");
v7 = v6;
break;
case 1:
func2(a4, a2);
break;
case 2:
func3(a4, a2);
break;
case 3:
func4(a4, a2);
break;
case 4:
func5(a4, a2, a3);
break;
case 5:
func9(a4, a2, a3);
break;
case 6:
func10(a4, a2, a3);
break;
case 7:
func11(a4, a2, a3);
break;
case 8:
func12(a4, a2, a3);
v7 = 1;
break;
default:
return v7;
}
return v7;
}

original_code:
int evaluar_pedido(char *pedido, long conn_s, int worker, DescriptorColas* cola)
{
  int i;
  char *token;
  char delims[] = " ";
  token = strtok(pedido, delims);
  for(i = 0; i <= 8; i++) {
    if (strcmp (token, operaciones[i]) == 0) {
      switch(i) {
        case 0:
          responder_al_cliente(conn_s, "ERROR YA ESTA CONECTADO\n");
          break;
        case 1:
          PS_operadorLSD(cola, conn_s);
          break;
        case 2:
          PS_operadorDEL(cola, conn_s);
          break;
        case 3:
          PS_operadorCRE(cola, conn_s);
          break;
        case 4:
          PS_operadorOPN(cola, conn_s, worker);
          break;
        case 5:
          PS_operadorWRT(cola, conn_s, worker);
          break;
        case 6:
          PS_operadorREA(cola, conn_s, worker);
          break;
        case 7:
          PS_operadorCLO(cola, conn_s, worker);
          break;
        case 8:
          PS_operadorBYE(cola, conn_s, worker);
          return 1;
          break;
      }
    i = 0;
    break;
    }
  }
  if(i > 0) {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
  return 0;
}

canonical_original_code:
int evaluar_pedido(char *pedido, long conn_s, int worker, struct colas *cola)
{
  int i;
  char *token;
  char delims[] = " ";
  token = strtok(pedido, delims);
  for(i = 0; i <= 8; i++) {
    if (strcmp (token, operaciones[i]) == 0) {
      switch(i) {
        case 0:
          responder_al_cliente(conn_s, "ERROR YA ESTA CONECTADO\n");
          break;
        case 1:
          PS_operadorLSD(cola, conn_s);
          break;
        case 2:
          PS_operadorDEL(cola, conn_s);
          break;
        case 3:
          PS_operadorCRE(cola, conn_s);
          break;
        case 4:
          PS_operadorOPN(cola, conn_s, worker);
          break;
        case 5:
          PS_operadorWRT(cola, conn_s, worker);
          break;
        case 6:
          PS_operadorREA(cola, conn_s, worker);
          break;
        case 7:
          PS_operadorCLO(cola, conn_s, worker);
          break;
        case 8:
          PS_operadorBYE(cola, conn_s, worker);
          return 1;
          break;
      }
    i = 0;
    break;
    }
  }
  if(i > 0) {
    responder_al_cliente(conn_s, "ERROR DE SINTAXIS\n");
  }
  return 0;
}

variable_types:
pedido
char *


decompiled_code:
__int64 __fastcall proceso_socket(__int64 *a1)
{
__int64 v1; // r12
int v2; // ebp
int v3; // eax
int v4; // eax
unsigned int v5; // ebx
unsigned int *v6; // r13
int v7; // eax
char s[7]; // [rsp+9h] [rbp-22Fh] BYREF
char buf[552]; // [rsp+10h] [rbp-228h] BYREF

v1 = *a1;
v2 = *a1;
do
{
v3 = read(v2, buf, 0x200uLL);
if ( v3 <= 0 )
{
close(v2);
goto LABEL_9;
}
buf[v3] = 0;
v4 = iniciar_conexion(buf, v1);
v5 = v4;
}
while ( v4 < 0 );
printf("-> Cliente con ID %d conectado\n", (unsigned int)v4);
v6 = (unsigned int *)nueva_cola_mensaje(v5, 100LL);
sprintf(s, "/cola%d", v5);
*v6 = abrir(s);
while ( 1 )
{
v7 = read(v2, buf, 0x200uLL);
if ( v7 <= 0 )
break;
buf[v7] = 0;
if ( (unsigned int)evaluar_pedido(buf, v1, v5, v6) )
goto LABEL_11;
}
PS_operadorBYE(v6, v1, v5);
LABEL_11:
close(v2);
pthread_mutex_lock(&m);
*(_BYTE *)(bitmap_worker + (int)v5) = 0;
pthread_mutex_unlock(&m);
borrar_cola_mensaje(v6, v5, 100LL);
printf("<- Cliente con ID %d desconectado\n", v5);
LABEL_9:
close(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 *a1)
{
__int64 v1; // r12
int v2; // ebp
int v3; // eax
int v4; // eax
unsigned int v5; // ebx
unsigned int *v6; // r13
int v7; // eax
char s[7]; // [rsp+9h] [rbp-22Fh] BYREF
char buf[552]; // [rsp+10h] [rbp-228h] BYREF

v1 = *a1;
v2 = *a1;
do
{
v3 = read(v2, buf, 0x200uLL);
if ( v3 <= 0 )
{
close(v2);
goto LABEL_9;
}
buf[v3] = 0;
v4 = func6(buf, v1);
v5 = v4;
}
while ( v4 < 0 );
printf("-> Cliente con ID %d conectado\n", (unsigned int)v4);
v6 = (unsigned int *)nueva_cola_mensaje(v5, 100LL);
sprintf(s, "/cola%d", v5);
*v6 = abrir(s);
while ( 1 )
{
v7 = read(v2, buf, 0x200uLL);
if ( v7 <= 0 )
break;
buf[v7] = 0;
if ( (unsigned int)func13(buf, v1, v5, v6) )
goto LABEL_11;
}
func12(v6, v1, v5);
LABEL_11:
close(v2);
pthread_mutex_lock(&m);
*(_BYTE *)(bitmap_worker + (int)v5) = 0;
pthread_mutex_unlock(&m);
borrar_cola_mensaje(v6, v5, 100LL);
printf("<- Cliente con ID %d desconectado\n", v5);
LABEL_9:
close(v2);
return 0LL;
}

original_code:
void *proceso_socket(void *arg)
{
  long conn_s = *(long *)arg;
  char pedido[512], cola_w[7];
  int res, worker;
  DescriptorColas *cola;
  while(1) {
    res=read(conn_s,pedido,512);
    if (res<=0) {
      close(conn_s);
      break;
    }
    pedido[res]='\0';
    if((worker = iniciar_conexion(pedido, conn_s)) >= 0) {
      printf("-> Cliente con ID %d conectado\n", worker);
      cola = nueva_cola_mensaje(worker, 'd');
      sprintf(cola_w, "/cola%d", worker);
      cola->worker = abrir(cola_w);
      while(1) {
        res=read(conn_s,pedido,512);
        if(res<=0) {
          PS_operadorBYE(cola, conn_s, worker);
          break;
        }
        pedido[res]='\0';
        if(evaluar_pedido(pedido, conn_s, worker, cola))
          break;
      }
      close(conn_s);
      pthread_mutex_lock(&m);
      bitmap_worker[worker] = 0;
      pthread_mutex_unlock(&m);
      borrar_cola_mensaje(cola, worker, 'd');
      printf("<- Cliente con ID %d desconectado\n",worker);
      break;
    }
  }
  close(conn_s);
  return ((void *)0);
}

canonical_original_code:
void *proceso_socket(void *arg)
{
  long conn_s = *(long *)arg;
  char pedido[512]; char cola_w[7];
  int res; int worker;
  struct colas *cola;
  while(1) {
    res=read(conn_s,pedido,512);
    if (res<=0) {
      close(conn_s);
      break;
    }
    pedido[res]='\0';
    if((worker = iniciar_conexion(pedido, conn_s)) >= 0) {
      printf("-> Cliente con ID %d conectado\n", worker);
      cola = nueva_cola_mensaje(worker, 'd');
      sprintf(cola_w, "/cola%d", worker);
      cola->worker = abrir(cola_w);
      while(1) {
        res=read(conn_s,pedido,512);
        if(res<=0) {
          PS_operadorBYE(cola, conn_s, worker);
          break;
        }
        pedido[res]='\0';
        if(evaluar_pedido(pedido, conn_s, worker, cola))
          break;
      }
      close(conn_s);
      pthread_mutex_lock(&m);
      bitmap_worker[worker] = 0;
      pthread_mutex_unlock(&m);
      borrar_cola_mensaje(cola, worker, 'd');
      printf("<- Cliente con ID %d desconectado\n",worker);
      break;
    }
  }
  close(conn_s);
  return ((void *)0);
}

variable_types:
arg
void *

variable_types:
pedido
char [512]

variable_types: res int

variable_types: struct colas { int worker; int disp; int anillo; } *

return_type: void *


nueva

decompiled_code:
__int64 __fastcall nueva(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[9]; // [rsp+0h] [rbp-48h] BYREF

v3[1] = 5LL;
v3[2] = 24LL;
v3[0] = 0LL;
v1 = mq_open(a1, 66LL, 448LL, v3);
if ( v1 == -1 )
perror("mq_open");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[9]; // [rsp+0h] [rbp-48h] BYREF

v3[1] = 5LL;
v3[2] = 24LL;
v3[0] = 0LL;
v1 = mq_open(a1, 66LL, 448LL, v3);
if ( v1 == -1 )
perror("mq_open");
return v1;
}

original_code:
mqd_t nueva(char *nombre)
{
  struct mq_attr atributos;
  mqd_t cola;
  atributos.mq_maxmsg = 5;
  atributos.mq_msgsize = sizeof(Msj);
  atributos.mq_flags = 0;
  if ((cola = mq_open(nombre, 0100 | 02, (0400|0200|0100), &atributos)) == (mqd_t)-1)
    perror ("mq_open");
  return cola;
}

canonical_original_code:
int nueva(char *nombre)
{
  struct mq_attr atributos;
  int cola;
  atributos.mq_maxmsg = 5;
  atributos.mq_msgsize = sizeof(Msj);
  atributos.mq_flags = 0;
  if ((cola = mq_open(nombre, 0100 | 02, (0400|0200|0100), &atributos)) == (mqd_t)-1)
    perror ("mq_open");
  return cola;
}

variable_types:
nombre
char *

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

variable_types: cola int


abrir

decompiled_code:
__int64 __fastcall abrir(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebx

v4 = mq_open(a1, 2LL, a3, a4);
if ( v4 == -1 )
perror("mq_open");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebx

v4 = mq_open(a1, 2LL, a3, a4);
if ( v4 == -1 )
perror("mq_open");
return v4;
}

original_code:
mqd_t abrir(char *nombre)
{
  mqd_t cola;
  if ((cola = mq_open(nombre, 02)) == (mqd_t)-1)
    perror("mq_open");
  return cola;
}

canonical_original_code:
int abrir(char *nombre)
{
  int cola;
  if ((cola = mq_open(nombre, 02)) == (mqd_t)-1)
    perror("mq_open");
  return cola;
}


decompiled_code:
__int64 __fastcall enviar_msj(__int64 a1, __int64 a2)
{
if ( (unsigned int)mq_send(a1, a2, 24LL, 0LL) == -1 )
perror("mq_send");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
if ( (unsigned int)mq_send(a1, a2, 24LL, 0LL) == -1 )
perror("mq_send");
return 0LL;
}

original_code:
int enviar_msj(mqd_t cola, char *mensaje)
{
  if(mq_send(cola, mensaje, sizeof(Msj), 0) == -1)
    perror("mq_send");
  return 0;
}

canonical_original_code:
int enviar_msj(int cola, char *mensaje)
{
  if(mq_send(cola, mensaje, sizeof(Msj), 0) == -1)
    perror("mq_send");
  return 0;
}

variable_types:
mensaje
char *


decompiled_code:
__int64 __fastcall recibir_msj(__int64 a1, __int64 a2)
{
if ( mq_receive(a1, a2, 24LL, 0LL) == -1 )
perror("mq_receive");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( mq_receive(a1, a2, 24LL, 0LL) == -1 )
perror("mq_receive");
return 0LL;
}

original_code:
int recibir_msj(mqd_t cola, char *buf)
{
  if (mq_receive(cola, buf, sizeof(Msj), ((void *)0)) == -1)
    perror("mq_receive");
  return 0;
}

canonical_original_code:
int recibir_msj(int cola, char *buf)
{
  if (mq_receive(cola, buf, sizeof(Msj), ((void *)0)) == -1)
    perror("mq_receive");
  return 0;
}

variable_types:
buf
char *


cerrar

decompiled_code:
__int64 cerrar()
{
mq_close();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
mq_close();
return 0LL;
}

original_code:
int cerrar(mqd_t cola)
{
  mq_close(cola);
  return 0;
}

canonical_original_code:
int cerrar(int cola)
{
  mq_close(cola);
  return 0;
}


borrar

decompiled_code:
__int64 borrar()
{
mq_unlink();
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
mq_unlink();
return 0LL;
}

original_code:
int borrar(char *nombre_cola)
{
  mq_unlink(nombre_cola);
  return 0;
}


atributos

decompiled_code:
__int64 __fastcall atributos(__int64 a1, __int64 a2)
{
const char *v2; // r9
_BYTE v4[8]; // [rsp+0h] [rbp-48h] BYREF
__int64 v5; // [rsp+8h] [rbp-40h]
__int64 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+18h] [rbp-30h]

if ( (int)mq_getattr(a1, v4) < 0 )
{
perror("mq_getattr");
}
else
{
v2 = "sin-bloqueo";
if ( (v4[1] & 8) == 0 )
v2 = "bloqueo";
printf(format, a2, v7, v5, v6, v2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
const char *v2; // r9
_BYTE v4[8]; // [rsp+0h] [rbp-48h] BYREF
__int64 v5; // [rsp+8h] [rbp-40h]
__int64 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+18h] [rbp-30h]

if ( (int)mq_getattr(a1, v4) < 0 )
{
perror("mq_getattr");
}
else
{
v2 = "sin-bloqueo";
if ( (v4[1] & 8) == 0 )
v2 = "bloqueo";
printf(format, a2, v7, v5, v6, v2);
}
return 0LL;
}

original_code:
int atributos(mqd_t cola, char *nombre)
{
  struct mq_attr mqa;
  if (mq_getattr(cola, &mqa) < 0)
    perror("mq_getattr");
  else {
    printf("MQD: %s tiene %ld msjs (max %ld, max tamaño %ld, modo %s)\n",
    nombre, mqa.mq_curmsgs, mqa.mq_maxmsg, mqa.mq_msgsize, (mqa.mq_flags & 04000) ? "sin-bloqueo" : "bloqueo");
  }
  return 0;
}

canonical_original_code:
int atributos(int cola, char *nombre)
{
  struct mq_attr mqa;
  if (mq_getattr(cola, &mqa) < 0)
    perror("mq_getattr");
  else {
    printf("MQD: %s tiene %ld msjs (max %ld, max tamaño %ld, modo %s)\n",
    nombre, mqa.mq_curmsgs, mqa.mq_maxmsg, mqa.mq_msgsize, (mqa.mq_flags & 04000) ? "sin-bloqueo" : "bloqueo");
  }
  return 0;
}

user_defined_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }


decompiled_code:
__int64 __fastcall crear_cola(unsigned int a1)
{
char *v1; // rbx

v1 = (char *)malloc(7uLL);
if ( !v1 )
printf("Error al crear cola de mensajes");
sprintf(v1, "/cola%d", a1);
mq_unlink(v1);
return nueva((__int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
char *v1; // rbx

v1 = (char *)malloc(7uLL);
if ( !v1 )
printf("Error al crear cola de mensajes");
sprintf(v1, "/cola%d", a1);
mq_unlink(v1);
return func0((__int64)v1);
}

original_code:
mqd_t crear_cola(int cola)
{
  mqd_t mqd;
  char *buff;
  if((buff = (char *) malloc(7*sizeof(char))) == ((void *)0))
     printf("Error al crear cola de mensajes");
  sprintf(buff, "/cola%d", cola);
  mq_unlink(buff);
  mqd = nueva(buff);
  return mqd;
}

canonical_original_code:
int crear_cola(int cola)
{
  int mqd;
  char *buff;
  if((buff = (char *) malloc(7*sizeof(char))) == ((void *)0))
     printf("Error al crear cola de mensajes");
  sprintf(buff, "/cola%d", cola);
  mq_unlink(buff);
  mqd = nueva(buff);
  return mqd;
}

variable_types: mqd int

variable_types:
buff
char *


enviar

decompiled_code:
__int64 __fastcall enviar(unsigned int a1, char a2, char a3, char a4, __int64 a5)
{
_BYTE *v8; // rbx

v8 = calloc(1uLL, 0x18uLL);
if ( !v8 )
puts("Error al enviar mensaje");
*v8 = a2;
v8[1] = a3;
v8[2] = a4;
*((_DWORD *)v8 + 1) = 48;
*((_QWORD *)v8 + 1) = a5;
*((_QWORD *)v8 + 2) = 0LL;
return enviar_msj(a1, (__int64)v8);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char a2, char a3, char a4, __int64 a5)
{
_BYTE *v8; // rbx

v8 = calloc(1uLL, 0x18uLL);
if ( !v8 )
puts("Error al enviar mensaje");
*v8 = a2;
v8[1] = a3;
v8[2] = a4;
*((_DWORD *)v8 + 1) = 48;
*((_QWORD *)v8 + 1) = a5;
*((_QWORD *)v8 + 2) = 0LL;
return func2(a1, (__int64)v8);
}

original_code:
void enviar(mqd_t mqd, char tipo, char contador, char dato, char *nombre)
{
  Msj *msj;
  if((msj = (Msj *) calloc(1, sizeof(Msj))) == ((void *)0))
    printf("Error al enviar mensaje\n");
  msj->tipo = tipo;
  msj->contador = contador;
  msj->dato = dato;
  msj->otrodato = '0';
  msj->nombre = nombre;
  msj->texto = ((void *)0);
  enviar_msj(mqd, (char *)msj);
}

canonical_original_code:
void enviar(int mqd, char tipo, char contador, char dato, char *nombre)
{
  struct msj_ *msj;
  if((msj = (struct msj_ *) calloc(1, sizeof(Msj))) == ((void *)0))
    printf("Error al enviar mensaje\n");
  msj->tipo = tipo;
  msj->contador = contador;
  msj->dato = dato;
  msj->otrodato = '0';
  msj->nombre = nombre;
  msj->texto = ((void *)0);
  enviar_msj(mqd, (char *)msj);
}

variable_types: tipo char

variable_types: contador char

variable_types: dato char

variable_types: struct msj_ { char tipo; char contador; char dato; int otrodato; char *nombre; char *texto; } *


enviarWR

decompiled_code:
__int64 __fastcall enviarWR(unsigned int a1, char a2, char a3, char a4, int a5, __int64 a6, __int64 a7)
{
_BYTE *v11; // rax

v11 = calloc(1uLL, 0x18uLL);
*v11 = a2;
v11[1] = a3;
v11[2] = a4;
*((_DWORD *)v11 + 1) = a5;
*((_QWORD *)v11 + 1) = a6;
*((_QWORD *)v11 + 2) = a7;
return enviar_msj(a1, (__int64)v11);
}

original_code:
void enviarWR(mqd_t mqd, char tipo, char contador, char dato, int otrodato, char *nombre, char *texto)
{
  Msj *msj = (Msj *)calloc(1, sizeof(Msj));
  msj->tipo = tipo;
  msj->contador = contador;
  msj->dato = dato;
  msj->otrodato = otrodato;
  msj->nombre = nombre;
  msj->texto = texto;
  enviar_msj(mqd, (char *)msj);
}

canonical_original_code:
void enviarWR(int mqd, char tipo, char contador, char dato, int otrodato, char *nombre, char *texto)
{
  struct msj_ *msj = (Msj *)calloc(1, sizeof(Msj));
  msj->tipo = tipo;
  msj->contador = contador;
  msj->dato = dato;
  msj->otrodato = otrodato;
  msj->nombre = nombre;
  msj->texto = texto;
  enviar_msj(mqd, (char *)msj);
}

variable_types: otrodato int

variable_types:
texto
char *


original_code:
void reenvio_msj(mqd_t mqd, Msj *msj, char tipo)
{
  switch(tipo) {
    case 'w':
      enviarWR(mqd, 'w', msj->contador-1, msj->dato, msj->otrodato, msj->nombre, msj->texto);
      break;
    case 'r':
      enviarWR(mqd, 'r', msj->contador-1, msj->dato, msj->otrodato, msj->nombre, msj->texto);
      break;
    default:
      enviar(mqd,tipo,msj->contador-1,msj->dato,msj->nombre);
      break;
  }
}

canonical_original_code:
void reenvio_msj(int mqd, struct msj_ *msj, char tipo)
{
  switch(tipo) {
    case 'w':
      enviarWR(mqd, 'w', msj->contador-1, msj->dato, msj->otrodato, msj->nombre, msj->texto);
      break;
    case 'r':
      enviarWR(mqd, 'r', msj->contador-1, msj->dato, msj->otrodato, msj->nombre, msj->texto);
      break;
    default:
      enviar(mqd,tipo,msj->contador-1,msj->dato,msj->nombre);
      break;
  }
}


recibir

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

v1 = malloc(0x18uLL);
if ( !v1 )
puts("Error no es posible recibir un msj por el anillo");
recibir_msj(a1, (__int64)v1);
return v1;
}

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

v1 = malloc(0x18uLL);
if ( !v1 )
puts("Error no es posible recibir un msj por el anillo");
func3(a1, (__int64)v1);
return v1;
}

original_code:
Msj* recibir(mqd_t mqd)
{
  char *buff;
  if ((buff = (char *)malloc(sizeof(Msj))) == ((void *)0))
    printf("Error no es posible recibir un msj por el anillo\n");
  recibir_msj(mqd, buff);
  return (Msj *)buff;
}

canonical_original_code:
struct msj_ *recibir(int mqd)
{
  char *buff;
  if ((buff = (char *)malloc(sizeof(Msj))) == ((void *)0))
    printf("Error no es posible recibir un msj por el anillo\n");
  recibir_msj(mqd, buff);
  return (struct msj_ *)buff;
}

return_type: struct msj_ { char tipo; char contador; char dato; int otrodato; char *nombre; char *texto; } *


decompiled_code:
void __fastcall liberar_msj(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void liberar_msj(Msj *msj)
{
  if(msj == ((void *)0))
    return;
  free(msj->nombre);
  free(msj->texto);
  free(msj);
  msj = ((void *)0);
}

canonical_original_code:
void liberar_msj(struct msj_ *msj)
{
  if(msj == ((void *)0))
    return;
  free(msj->nombre);
  free(msj->texto);
  free(msj);
  msj = ((void *)0);
}


decompiled_code:
int __fastcall imprimir_msj(char *a1)
{
const char *v2; // rdi
const char *v3; // rdi

printf("El tipo: %c\n", (unsigned int)*a1);
printf("El contador: %c\n", (unsigned int)a1[1]);
printf("El dato: %c\n", (unsigned int)a1[2]);
printf("El otrodato: %d\n", *((unsigned int *)a1 + 1));
v2 = (const char *)*((_QWORD *)a1 + 1);
if ( v2 )
puts(v2);
else
puts("sin nombre");
v3 = (const char *)*((_QWORD *)a1 + 2);
if ( v3 )
puts(v3);
else
puts("sin texto");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func13(char *a1)
{
const char *v2; // rdi
const char *v3; // rdi

printf("El tipo: %c\n", (unsigned int)*a1);
printf("El contador: %c\n", (unsigned int)a1[1]);
printf("El dato: %c\n", (unsigned int)a1[2]);
printf("El otrodato: %d\n", *((unsigned int *)a1 + 1));
v2 = (const char *)*((_QWORD *)a1 + 1);
if ( v2 )
puts(v2);
else
puts("sin nombre");
v3 = (const char *)*((_QWORD *)a1 + 2);
if ( v3 )
puts(v3);
else
puts("sin texto");
return putchar(10);
}

original_code:
void imprimir_msj(Msj *msj)
{
  printf("El tipo: %c\n",msj->tipo);
  printf("El contador: %c\n",msj->contador);
  printf("El dato: %c\n",msj->dato);
  printf("El otrodato: %d\n",msj->otrodato);
  if(msj->nombre == ((void *)0))
    printf("sin nombre\n");
  else
    printf("%s\n",msj->nombre);
  if(msj->texto == ((void *)0))
    printf("sin texto\n");
  else
    printf("%s\n",msj->texto);
  printf("\n");
}

canonical_original_code:
void imprimir_msj(struct msj_ *msj)
{
  printf("El tipo: %c\n",msj->tipo);
  printf("El contador: %c\n",msj->contador);
  printf("El dato: %c\n",msj->dato);
  printf("El otrodato: %d\n",msj->otrodato);
  if(msj->nombre == ((void *)0))
    printf("sin nombre\n");
  else
    printf("%s\n",msj->nombre);
  if(msj->texto == ((void *)0))
    printf("sin texto\n");
  else
    printf("%s\n",msj->texto);
  printf("\n");
}


decompiled_code:
void __fastcall borrar_cola_mensaje(void *ptr, unsigned int a2, char a3)
{
char s[31]; // [rsp+9h] [rbp-1Fh] BYREF

if ( a3 == 100 )
{
cerrar(*((unsigned int *)ptr + 1));
cerrar(*(unsigned int *)ptr);
sprintf(s, "/cola%d", (unsigned int)((int)(a2 + 5) % 10));
borrar(s);
}
else if ( a3 == 119 )
{
cerrar(*(unsigned int *)ptr);
cerrar(*((unsigned int *)ptr + 2));
sprintf(s, "/cola%d", a2);
borrar(s);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func14(void *ptr, unsigned int a2, char a3)
{
char s[31]; // [rsp+9h] [rbp-1Fh] BYREF

if ( a3 == 100 )
{
func4(*((unsigned int *)ptr + 1));
func4(*(unsigned int *)ptr);
sprintf(s, "/cola%d", (unsigned int)((int)(a2 + 5) % 10));
func5(s);
}
else if ( a3 == 119 )
{
func4(*(unsigned int *)ptr);
func4(*((unsigned int *)ptr + 2));
sprintf(s, "/cola%d", a2);
func5(s);
}
free(ptr);
}

original_code:
void borrar_cola_mensaje(DescriptorColas* cola, int worker, char tipo)
{
  char nombre[7];
  switch(tipo) {
    case 'w':
      cerrar(cola->worker);
      cerrar(cola->anillo);
      sprintf(nombre, "/cola%d", worker);
      borrar(nombre);
      break;
    case 'd':
      cerrar(cola->disp);
      cerrar(cola->worker);
      sprintf(nombre, "/cola%d", (worker+5)%(2*5));
      borrar(nombre);
      break;
  }
  free(cola);
}

canonical_original_code:
void borrar_cola_mensaje(struct colas *cola, int worker, char tipo)
{
  char nombre[7];
  switch(tipo) {
    case 'w':
      cerrar(cola->worker);
      cerrar(cola->anillo);
      sprintf(nombre, "/cola%d", worker);
      borrar(nombre);
      break;
    case 'd':
      cerrar(cola->disp);
      cerrar(cola->worker);
      sprintf(nombre, "/cola%d", (worker+5)%(2*5));
      borrar(nombre);
      break;
  }
  free(cola);
}

variable_types: worker int

variable_types:
nombre
char [7]


decompiled_code:
int __fastcall imprimir_cola(unsigned int *a1)
{
__int64 v1; // rsi
__int64 v2; // rsi
__int64 v3; // rsi
int result; // eax

if ( a1 )
{
v1 = *a1;
if ( (_DWORD)v1 )
printf("Cola worker: %d\n", v1);
v2 = a1[2];
if ( (_DWORD)v2 )
printf("Cola anillo: %d\n", v2);
v3 = a1[1];
if ( (_DWORD)v3 )
printf("Cola dispatcher: %d\n", v3);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(unsigned int *a1)
{
__int64 v1; // rsi
__int64 v2; // rsi
__int64 v3; // rsi
int result; // eax

if ( a1 )
{
v1 = *a1;
if ( (_DWORD)v1 )
printf("Cola worker: %d\n", v1);
v2 = a1[2];
if ( (_DWORD)v2 )
printf("Cola anillo: %d\n", v2);
v3 = a1[1];
if ( (_DWORD)v3 )
printf("Cola dispatcher: %d\n", v3);
result = putchar(10);
}
return result;
}

original_code:
void imprimir_cola(DescriptorColas* cola)
{
  if(cola != ((void *)0)) {
    if(cola->worker != 0)
      printf("Cola worker: %d\n",(int)cola->worker);
    if(cola->anillo != 0)
      printf("Cola anillo: %d\n",(int)cola->anillo);
    if(cola->disp != 0)
      printf("Cola dispatcher: %d\n",(int)cola->disp);
    printf("\n");
  }
}

canonical_original_code:
void imprimir_cola(struct colas *cola)
{
  if(cola != ((void *)0)) {
    if(cola->worker != 0)
      printf("Cola worker: %d\n",(int)cola->worker);
    if(cola->anillo != 0)
      printf("Cola anillo: %d\n",(int)cola->anillo);
    if(cola->disp != 0)
      printf("Cola dispatcher: %d\n",(int)cola->disp);
    printf("\n");
  }
}


repo: JohnAnthony/Structures

decompiled_code:
__int64 __fastcall dlist_get_head(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
struct dlist_elem* dlist_get_head( const struct dlist *dlist) {
    return dlist->head;
}

canonical_original_code:
struct dlist_elem *dlist_get_head(struct dlist *dlist) {
    return dlist->head;
}

variable_types: struct dlist { struct dlist_elem *head; } *

return_type: struct dlist_elem { struct dlist_elem *next; struct dlist_elem *prev; void *data; } *


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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

original_code:
int dlist_get_size( const struct dlist *dlist) {
    int count = 0;
    for (struct dlist_elem * elem = (dlist)->head; elem; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int dlist_get_size(struct dlist *dlist) {
    int count = 0;
    for (struct dlist_elem *elem = (dlist)->head; elem; elem = elem->next)
        count++;
    return count;
}

variable_types: struct dlist { struct dlist_elem { struct dlist_elem *next; struct dlist_elem *prev; void *data; } *head; } *

variable_types: count int

user_defined_types: struct dlist { struct dlist_elem *head; }


decompiled_code:
_BOOL8 __fastcall dlist_is_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int dlist_is_empty( const struct dlist *dlist) {
    return !! dlist->head;
}

canonical_original_code:
int dlist_is_empty(struct dlist *dlist) {
    return !! dlist->head;
}

user_defined_types: struct dlist_elem { struct dlist_elem *next; struct dlist_elem *prev; void *data; }


decompiled_code:
__int64 __fastcall dlist_ins_head(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
v2[1] = 0LL;
v2[2] = a2;
*a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
v2[1] = 0LL;
v2[2] = a2;
*a1 = v2;
return 0LL;
}

original_code:
int dlist_ins_head( struct dlist *dlist,
                              void *data) {
    struct dlist_elem *elem;
    elem = malloc(sizeof(struct dlist_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = dlist->head;
    elem->prev = ((void *)0);
    elem->data = data;
    dlist->head = elem;
    return 0;
}

canonical_original_code:
int dlist_ins_head(struct dlist *dlist, void *data) {
    struct dlist_elem *elem;
    elem = malloc(sizeof(struct dlist_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = dlist->head;
    elem->prev = ((void *)0);
    elem->data = data;
    dlist->head = elem;
    return 0;
}

variable_types:
data
void *

variable_types: struct dlist_elem { struct dlist_elem *next; struct dlist_elem *prev; void *data; } *


decompiled_code:
__int64 __fastcall dlist_ins_next(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
*v2 = *a1;
v2[1] = a1;
*(_QWORD *)(v3 + 8) = v2;
*(_QWORD *)v2[1] = v2;
v2[2] = a2;
return 0LL;
}

original_code:
int dlist_ins_next( struct dlist_elem *elem,
                              void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem_new->prev = elem;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}

canonical_original_code:
int dlist_ins_next(struct dlist_elem *elem, void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem_new->prev = elem;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}


decompiled_code:
__int64 __fastcall dlist_ins_prev(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
_QWORD *v5; // rdx

v4 = malloc(0x18uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
if ( *a1 == a2 )
*a1 = v4;
*v4 = a2;
v5 = *(_QWORD **)(a2 + 8);
v4[1] = v5;
*(_QWORD *)(a2 + 8) = v4;
*v5 = v4;
v4[2] = a3;
return 0LL;
}

original_code:
int dlist_ins_prev( struct dlist *dlist,
                                 struct dlist_elem *elem,
                              void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    if (dlist->head == elem)
        dlist->head = elem_new;
    elem_new->next = elem;
    elem_new->prev = elem->prev;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}

canonical_original_code:
int dlist_ins_prev(struct dlist *dlist, struct dlist_elem *elem, void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    if (dlist->head == elem)
        dlist->head = elem_new;
    elem_new->next = elem;
    elem_new->prev = elem->prev;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}

variable_types:
elem
struct dlist_elem *


decompiled_code:
__int64 __fastcall dlist_ins_tail(_QWORD **a1, __int64 a2)
{
__int64 *v2; // rax

v2 = dlist_get_tail(a1);
return dlist_ins_next(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD **a1, __int64 a2)
{
__int64 *v2; // rax

v2 = dlist_get_tail(a1);
return func6(v2, a2);
}

original_code:
int dlist_ins_tail( struct dlist *dlist,
                              void *data) {
    return dlist_ins_next(dlist_get_tail(dlist), data);
}

canonical_original_code:
int dlist_ins_tail(struct dlist *dlist, void *data) {
    return dlist_ins_next(dlist_get_tail(dlist), data);
}


decompiled_code:
__int64 __fastcall dlist_rem_elem(_QWORD *a1, _QWORD *a2, void (__fastcall *a3)(_QWORD))
{
_QWORD *v3; // rax

if ( *a2 )
*(_QWORD *)(*a2 + 8LL) = a2[1];
v3 = (_QWORD *)a2[1];
if ( v3 )
*v3 = *a2;
if ( (_QWORD *)*a1 == a2 )
*a1 = *a2;
if ( a3 )
a3(a2[2]);
free(a2);
return 0LL;
}

original_code:
int dlist_rem_elem( struct dlist *dlist,
                                 struct dlist_elem *elem,
                              void (*destroy)(void *data)) {
    if (elem->next)
        elem->next->prev = elem->prev;
    if (elem->prev)
        elem->prev->next = elem->next;
    if (dlist->head == elem)
        dlist->head = elem->next;
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}

canonical_original_code:
int dlist_rem_elem(struct dlist *dlist, struct dlist_elem *elem, void (*destroy)(void *data)) {
    if (elem->next)
        elem->next->prev = elem->prev;
    if (elem->prev)
        elem->prev->next = elem->next;
    if (dlist->head == elem)
        dlist->head = elem->next;
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}

variable_types:
destroy
void (*)(void *data)


decompiled_code:
__int64 __fastcall dlist_rem_head(_QWORD **a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
_QWORD *v3; // rax

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = (_QWORD *)*v2;
*a1 = (_QWORD *)*v2;
if ( v3 )
v3[1] = 0LL;
if ( a2 )
a2(v2[2]);
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
_QWORD *v3; // rax

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = (_QWORD *)*v2;
*a1 = (_QWORD *)*v2;
if ( v3 )
v3[1] = 0LL;
if ( a2 )
a2(v2[2]);
free(v2);
return 0LL;
}

original_code:
int dlist_rem_head( struct dlist *dlist,
                              void (*destroy)(void *data)) {
    struct dlist_elem *elem;
    elem = dlist->head;
    if (elem == ((void *)0))
        return -1;
    dlist->head = elem->next;
    if (dlist->head != ((void *)0))
        dlist->head->prev = ((void *)0);
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}

canonical_original_code:
int dlist_rem_head(struct dlist *dlist, void (*destroy)(void *data)) {
    struct dlist_elem *elem;
    elem = dlist->head;
    if (elem == ((void *)0))
        return -1;
    dlist->head = elem->next;
    if (dlist->head != ((void *)0))
        dlist->head->prev = ((void *)0);
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}


decompiled_code:
__int64 __fastcall dlist_rem_tail(_QWORD **a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rax

v2 = dlist_get_tail(a1);
return dlist_rem_elem(a1, v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD **a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rax

v2 = dlist_get_tail(a1);
return func9(a1, v2, a2);
}

original_code:
int dlist_rem_tail( struct dlist *dlist,
                              void (*destroy)(void *data)) {
    return dlist_rem_elem(dlist, dlist_get_tail(dlist), destroy);
}

canonical_original_code:
int dlist_rem_tail(struct dlist *dlist, void (*destroy)(void *data)) {
    return dlist_rem_elem(dlist, dlist_get_tail(dlist), destroy);
}


decompiled_code:
__int64 __fastcall list_get_head(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
struct list_elem* list_get_head( const struct list *list) {
    return list->head;
}

canonical_original_code:
struct list_elem *list_get_head(struct list *list) {
    return list->head;
}

variable_types: struct list { struct list_elem *head; } *

return_type: struct list_elem { struct list_elem *next; void *data; } *


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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

original_code:
int list_get_size( const struct list *list) {
    int count = 0;
    for (struct list_elem * elem = (list)->head; elem; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int list_get_size(struct list *list) {
    int count = 0;
    for (struct list_elem *elem = (list)->head; elem; elem = elem->next)
        count++;
    return count;
}

variable_types: struct list { struct list_elem { struct list_elem *next; void *data; } *head; } *


decompiled_code:
_BOOL8 __fastcall list_is_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int list_is_empty( const struct list *list) {
    return !! list->head;
}

canonical_original_code:
int list_is_empty(struct list *list) {
    return !! list->head;
}

user_defined_types: struct list_elem { struct list_elem *next; void *data; }


decompiled_code:
__int64 __fastcall list_ins_head(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
v2[1] = a2;
*a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
v2[1] = a2;
*a1 = v2;
return 0LL;
}

original_code:
int list_ins_head( struct list *list,
                             void *data) {
    struct list_elem *elem;
    elem = malloc(sizeof(struct list_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = list->head;
    elem->data = data;
    list->head = elem;
    return 0;
}

canonical_original_code:
int list_ins_head(struct list *list, void *data) {
    struct list_elem *elem;
    elem = malloc(sizeof(struct list_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = list->head;
    elem->data = data;
    list->head = elem;
    return 0;
}

variable_types: struct list_elem { struct list_elem *next; void *data; } *


decompiled_code:
__int64 __fastcall list_ins_next(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
v2[1] = a2;
*a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
v2[1] = a2;
*a1 = v2;
return 0LL;
}

original_code:
int list_ins_next( struct list_elem *elem,
                             void *data) {
    struct list_elem *elem_new;
    elem_new = malloc(sizeof(struct list_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem_new->data = data;
    elem->next = elem_new;
    return 0;
}

canonical_original_code:
int list_ins_next(struct list_elem *elem, void *data) {
    struct list_elem *elem_new;
    elem_new = malloc(sizeof(struct list_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem_new->data = data;
    elem->next = elem_new;
    return 0;
}


decompiled_code:
__int64 __fastcall list_ins_tail(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = list_get_tail(a1);
return list_ins_next(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = list_get_tail(a1);
return func6(v2, a2);
}

original_code:
int list_ins_tail( struct list *list,
                             void *data) {
    return list_ins_next(list_get_tail(list), data);
}

canonical_original_code:
int list_ins_tail(struct list *list, void *data) {
    return list_ins_next(list_get_tail(list), data);
}


decompiled_code:
__int64 __fastcall list_rem_head(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
unsigned int v2; // ebp
_QWORD *v3; // r13

if ( list_is_empty(a1) )
return (unsigned int)-1;
v2 = 0;
v3 = (_QWORD *)*a1;
*a1 = *(_QWORD *)*a1;
if ( a2 )
a2(v3[1]);
free(v3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
unsigned int v2; // ebp
_QWORD *v3; // r13

if ( func4(a1) )
return (unsigned int)-1;
v2 = 0;
v3 = (_QWORD *)*a1;
*a1 = *(_QWORD *)*a1;
if ( a2 )
a2(v3[1]);
free(v3);
return v2;
}

original_code:
int list_rem_head( struct list *list,
                             void (*destroy)(void *data)) {
    struct list_elem *elem;
    if (list_is_empty(list))
        return -1;
    elem = list->head;
    list->head = elem->next;
    if (destroy != ((void *)0))
        destroy(elem->data);
    free(elem);
    return 0;
}

canonical_original_code:
int list_rem_head(struct list *list, void (*destroy)(void *data)) {
    struct list_elem *elem;
    if (list_is_empty(list))
        return -1;
    elem = list->head;
    list->head = elem->next;
    if (destroy != ((void *)0))
        destroy(elem->data);
    free(elem);
    return 0;
}


decompiled_code:
__int64 __fastcall list_rem_next(__int64 a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = *v2;
if ( a2 )
a2(*(_QWORD *)(a1 + 8));
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = *v2;
if ( a2 )
a2(*(_QWORD *)(a1 + 8));
free(v2);
return 0LL;
}

original_code:
int list_rem_next( struct list_elem *elem,
                             void (*destroy)(void *data)) {
    struct list_elem *target;
    target = elem->next;
    if (target == ((void *)0))
        return -1;
    elem->next = target->next;
    if (destroy)
        destroy(elem->data);
    free(target);
    return 0;
}

canonical_original_code:
int list_rem_next(struct list_elem *elem, void (*destroy)(void *data)) {
    struct list_elem *target;
    target = elem->next;
    if (target == ((void *)0))
        return -1;
    elem->next = target->next;
    if (destroy)
        destroy(elem->data);
    free(target);
    return 0;
}


decompiled_code:
__int64 __fastcall list_rem_tail(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rax
__int64 v3; // rdi

v2 = (_QWORD *)list_get_head((__int64)a1);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*v2 )
return list_rem_head(a1, a2);
do
{
v3 = (__int64)v2;
v2 = (_QWORD *)*v2;
}
while ( *v2 );
return list_rem_next(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rax
__int64 v3; // rdi

v2 = (_QWORD *)func2((__int64)a1);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*v2 )
return func8(a1, a2);
do
{
v3 = (__int64)v2;
v2 = (_QWORD *)*v2;
}
while ( *v2 );
return func9(v3, a2);
}

original_code:
int list_rem_tail( struct list *list,
                             void (*destroy)(void *data)){
    struct list_elem *elem;
    elem = list_get_head(list);
    if (elem == ((void *)0))
        return -1;
    if (elem->next == ((void *)0))
        return list_rem_head(list, destroy);
    while(elem->next->next != ((void *)0))
        elem = elem->next;
    return list_rem_next(elem, destroy);
}

canonical_original_code:
int list_rem_tail(struct list *list, void (*destroy)(void *data)){
    struct list_elem *elem;
    elem = list_get_head(list);
    if (elem == ((void *)0))
        return -1;
    if (elem->next == ((void *)0))
        return list_rem_head(list, destroy);
    while(elem->next->next != ((void *)0))
        elem = elem->next;
    return list_rem_next(elem, destroy);
}


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

v1 = *a1;
if ( *a1 == a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 != a1 );
return v2;
}

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

v1 = *a1;
if ( *a1 == a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 != a1 );
return v2;
}

original_code:
int clist_get_size( const struct clist *clist) {
    int count = 0;
    for (struct clist_elem * elem = clist->link.next; elem != &clist->link; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int clist_get_size(struct clist *clist) {
    int count = 0;
    for (struct clist_elem *elem = clist->link.next; elem != &clist->link; elem = elem->next)
        count++;
    return count;
}

variable_types: struct clist { struct clist_elem { struct clist_elem *next; void *data; } link; } *

variable_types: struct clist_elem { struct clist_elem *next; void *data; } *

user_defined_types: struct clist { struct clist_elem link; }


decompiled_code:
_BOOL8 __fastcall clist_is_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
int clist_is_empty( const struct clist *clist) {
    return clist->link.next == &clist->link;
}

canonical_original_code:
int clist_is_empty(struct clist *clist) {
    return clist->link.next == &clist->link;
}

user_defined_types: struct clist_elem { struct clist_elem *next; void *data; }


decompiled_code:
__int64 __fastcall clist_get_head(__int64 *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

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

original_code:
struct clist_elem* clist_get_head( const struct clist *clist) {
    return clist_is_empty(clist) ? ((void *)0) : clist->link.next;
}

canonical_original_code:
struct clist_elem *clist_get_head(struct clist *clist) {
    return clist_is_empty(clist) ? ((void *)0) : clist->link.next;
}

variable_types: struct clist { struct clist_elem link; } *

return_type: struct clist_elem { struct clist_elem *next; void *data; } *


decompiled_code:
__int64 __fastcall clist_ins_next(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
*a1 = v2;
v2[1] = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = *a1;
*a1 = v2;
v2[1] = a2;
return 0LL;
}

original_code:
int clist_ins_next( struct clist_elem *elem,
                              void *data) {
    struct clist_elem *elem_new;
    elem_new = malloc(sizeof(struct clist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem->next = elem_new;
    elem_new->data = data;
    return 0;
}

canonical_original_code:
int clist_ins_next(struct clist_elem *elem, void *data) {
    struct clist_elem *elem_new;
    elem_new = malloc(sizeof(struct clist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem->next = elem_new;
    elem_new->data = data;
    return 0;
}


decompiled_code:
__int64 __fastcall clist_ins_head(_QWORD *a1, __int64 a2)
{
return clist_ins_next(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
return func5(a1, a2);
}

original_code:
int clist_ins_head( struct clist *clist,
                              void *data) {
    return clist_ins_next(&clist->link, data);
}

canonical_original_code:
int clist_ins_head(struct clist *clist, void *data) {
    return clist_ins_next(&clist->link, data);
}


decompiled_code:
__int64 __fastcall clist_ins_tail(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = clist_get_tail(a1);
if ( v2 )
result = clist_ins_next(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = clist_get_tail(a1);
if ( v2 )
result = func5(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int clist_ins_tail( struct clist *clist,
                              void *data) {
    struct clist_elem *elem;
    elem = clist_get_tail(clist);
    if (elem == ((void *)0))
        return -1;
    return clist_ins_next(elem, data);
}

canonical_original_code:
int clist_ins_tail(struct clist *clist, void *data) {
    struct clist_elem *elem;
    elem = clist_get_tail(clist);
    if (elem == ((void *)0))
        return -1;
    return clist_ins_next(elem, data);
}


decompiled_code:
__int64 __fastcall clist_rem_next(_QWORD *a1, void **a2, void (__fastcall *a3)(_QWORD))
{
unsigned int v4; // ebp
_QWORD *v5; // rax

if ( clist_is_empty(a1) )
return (unsigned int)-1;
v4 = 0;
*(_QWORD *)*a2 = a2;
v5 = *(_QWORD **)*a2;
*a2 = v5;
if ( a3 )
a3(v5[1]);
free(*a2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, void **a2, void (__fastcall *a3)(_QWORD))
{
unsigned int v4; // ebp
_QWORD *v5; // rax

if ( func3(a1) )
return (unsigned int)-1;
v4 = 0;
*(_QWORD *)*a2 = a2;
v5 = *(_QWORD **)*a2;
*a2 = v5;
if ( a3 )
a3(v5[1]);
free(*a2);
return v4;
}

original_code:
int clist_rem_next( struct clist *clist,
                                 struct clist_elem *elem,
                              void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    elem->next->next = elem;
    elem->next = elem->next->next;
    if (destroy != ((void *)0))
        destroy(elem->next->data);
    free(elem->next);
    return 0;
}

canonical_original_code:
int clist_rem_next(struct clist *clist, struct clist_elem *elem, void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    elem->next->next = elem;
    elem->next = elem->next->next;
    if (destroy != ((void *)0))
        destroy(elem->next->data);
    free(elem->next);
    return 0;
}

variable_types:
elem
struct clist_elem *


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

if ( clist_is_empty(a1) )
result = 0xFFFFFFFFLL;
else
result = clist_rem_next(a1, a1, a2);
return result;
}

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

if ( func3(a1) )
result = 0xFFFFFFFFLL;
else
result = func8(a1, a1, a2);
return result;
}

original_code:
int clist_rem_head( struct clist *clist,
                              void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    return clist_rem_next(clist, &clist->link, destroy);
}

canonical_original_code:
int clist_rem_head(struct clist *clist, void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    return clist_rem_next(clist, &clist->link, destroy);
}


decompiled_code:
__int64 __fastcall clist_rem_tail(void ***a1, void (__fastcall *a2)(_QWORD))
{
void **v3; // rax
void **v4; // rsi

if ( clist_is_empty(a1) )
return 0xFFFFFFFFLL;
v3 = *a1;
do
{
v4 = v3;
v3 = (void **)*v3;
}
while ( *v3 != a1 );
return clist_rem_next(a1, v4, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(void ***a1, void (__fastcall *a2)(_QWORD))
{
void **v3; // rax
void **v4; // rsi

if ( func3(a1) )
return 0xFFFFFFFFLL;
v3 = *a1;
do
{
v4 = v3;
v3 = (void **)*v3;
}
while ( *v3 != a1 );
return func8(a1, v4, a2);
}

original_code:
int clist_rem_tail( struct clist *clist,
                              void (*destroy)(void *data)) {
    struct clist_elem *pretail;
    if (clist_is_empty(clist))
        return -1;
    for(pretail = clist->link.next;
        pretail->next->next != &clist->link;
        pretail = pretail->next);
    return clist_rem_next(clist, pretail, destroy);
}

canonical_original_code:
int clist_rem_tail(struct clist *clist, void (*destroy)(void *data)) {
    struct clist_elem *pretail;
    if (clist_is_empty(clist))
        return -1;
    for(pretail = clist->link.next;
        pretail->next->next != &clist->link;
        pretail = pretail->next);
    return clist_rem_next(clist, pretail, destroy);
}


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

v1 = *a1;
if ( *a1 == a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 != a1 );
return v2;
}

original_code:
int cdlist_get_size( const struct cdlist *cdlist) {
    int count = 0;
    for (struct cdlist_elem * elem = cdlist->link.next; elem != &cdlist->link; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int cdlist_get_size(struct cdlist *cdlist) {
    int count = 0;
    for (struct cdlist_elem *elem = cdlist->link.next; elem != &cdlist->link; elem = elem->next)
        count++;
    return count;
}

variable_types: struct cdlist { struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; } link; } *

variable_types: struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; } *

user_defined_types: struct cdlist { struct cdlist_elem link; }


decompiled_code:
_BOOL8 __fastcall cdlist_is_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
int cdlist_is_empty( const struct cdlist *cdlist) {
    return cdlist->link.next == &cdlist->link;
}

canonical_original_code:
int cdlist_is_empty(struct cdlist *cdlist) {
    return cdlist->link.next == &cdlist->link;
}

user_defined_types: struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; }


decompiled_code:
__int64 __fastcall cdlist_get_head(__int64 *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

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

original_code:
struct cdlist_elem* cdlist_get_head( const struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}

canonical_original_code:
struct cdlist_elem *cdlist_get_head(struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}

variable_types: struct cdlist { struct cdlist_elem link; } *

return_type: struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; } *


decompiled_code:
__int64 __fastcall cdlist_get_tail(__int64 *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

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

original_code:
struct cdlist_elem* cdlist_get_tail( const struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}

canonical_original_code:
struct cdlist_elem *cdlist_get_tail(struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}