decompiled_code:
int __fastcall vagg_bufeq(void *s1, size_t n, void *s2, __int64 a4, const char *a5)
{
int result; // eax

++test_index;
if ( n != a4 )
failed(a5);
result = memcmp(s1, s2, n);
if ( result )
return failed(a5);
if ( show_success )
result = success(a5);
++success_count;
return result;
}

canonical_decompiled_code:
int __fastcall func5(void *s1, size_t n, void *s2, __int64 a4, const char *a5)
{
int result; // eax

++test_index;
if ( n != a4 )
func1(a5);
result = memcmp(s1, s2, n);
if ( result )
return func1(a5);
if ( show_success )
result = func0(a5);
++success_count;
return result;
}

original_code:
void vagg_bufeq(const void* buf1, size_t buf1_len, const void* buf2, size_t buf2_len, const char* msg) {
  test_index++;
  if(buf1_len != buf2_len) {
    failed(msg);
  }
  if (bcmp(buf1, buf2, buf1_len)) {
    failed(msg);
  } else {
    if (show_success) {
      success(msg);
    }
    success_count++;
  }
}

canonical_original_code:
void vagg_bufeq(void *buf1, unsigned long buf1_len, void *buf2, unsigned long buf2_len, char *msg) {
  test_index++;
  if(buf1_len != buf2_len) {
    failed(msg);
  }
  if (bcmp(buf1, buf2, buf1_len)) {
    failed(msg);
  } else {
    if (show_success) {
      success(msg);
    }
    success_count++;
  }
}


repo: padenot/vagg

decompiled_code:
int vagg_end()
{
pthread_t v0; // rax
int result; // eax
pthread_t v2; // rax

if ( success_count == test_index )
{
v2 = pthread_self();
if ( v2 )
fprintf(stdout, "[%ld] ", v2);
fprintf(stdout, "test suite ended : %u/%u passed. success.", (unsigned int)success_count, (unsigned int)test_index);
result = fputc(10, stdout);
}
else
{
v0 = pthread_self();
if ( v0 )
fprintf(stdout, "[%ld] ", v0);
fprintf(stdout, "test suite ended : %u/%u passed. failed.", (unsigned int)success_count, (unsigned int)test_index);
result = fputc(10, stdout);
}
return result;
}

canonical_decompiled_code:
int func6()
{
pthread_t v0; // rax
int result; // eax
pthread_t v2; // rax

if ( success_count == test_index )
{
v2 = pthread_self();
if ( v2 )
fprintf(stdout, "[%ld] ", v2);
fprintf(stdout, "test suite ended : %u/%u passed. success.", (unsigned int)success_count, (unsigned int)test_index);
result = fputc(10, stdout);
}
else
{
v0 = pthread_self();
if ( v0 )
fprintf(stdout, "[%ld] ", v0);
fprintf(stdout, "test suite ended : %u/%u passed. failed.", (unsigned int)success_count, (unsigned int)test_index);
result = fputc(10, stdout);
}
return result;
}

original_code:
void vagg_end() {
  if (success_count == test_index) {
    do { if(VAGG_LOG_OK <= VAGG_LOG_DEBUG) { size_t i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_OK]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "test suite ended : %u/%u passed. success.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  } else {
    do { if(VAGG_LOG_CRITICAL <= VAGG_LOG_DEBUG) { size_t i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_CRITICAL]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "test suite ended : %u/%u passed. failed.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  }
}

canonical_original_code:
void vagg_end() {
  if (success_count == test_index) {
    do { if(VAGG_LOG_OK <= VAGG_LOG_DEBUG) { unsigned long i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_OK]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "test suite ended : %u/%u passed. success.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  } else {
    do { if(VAGG_LOG_CRITICAL <= VAGG_LOG_DEBUG) { unsigned long i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_CRITICAL]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "test suite ended : %u/%u passed. failed.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  }
}

variable_types:
i
unsigned long

return_type: void


decompiled_code:
__int64 __fastcall sgemm_reference(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-20h] BYREF
int v6; // [rsp+10h] [rbp-10h]
int v7; // [rsp+14h] [rbp-Ch]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(sgemm_reference__omp_fn_0, v5, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-20h] BYREF
int v6; // [rsp+10h] [rbp-10h]
int v7; // [rsp+14h] [rbp-Ch]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(sgemm_reference__omp_fn_0, v5, 0LL, 0LL);
}

original_code:
void sgemm_reference(int m, int n, float *A, float *C) {

#pragma omp parallel for
 for (int i = 0; i < n; i++)
  for (int k = 0; k < m; k++)
   for (int j = 0; j < n; j++)
    C[i + j * n] += A[i + k * (n)] * A[j * (n + 1) + k * (n)];
}

variable_types: m int

variable_types: n int

variable_types:
A
float *

variable_types:
C
float *

variable_types: i int

variable_types: k int

variable_types: j int


main

canonical_name: main

original_code:
int main(int argc, char **argv) {
 srand(time(((void *)0) ));
 int counter = 0;
 float sum = 0;
 int nStart = 401;
 int nEnd = 1500;
 int mStart = 32;
 int mEnd = 150;
 int loopEnd = 1;
 if (argc == 3) {
  nStart = atoi(argv[1]);
  nEnd = nStart + 1;
  mStart = atoi(argv[2]);
  mEnd = mStart + 1;
  loopEnd = 10;
 }
 for (int loop = 0; loop < loopEnd; loop++)
  for (int n = nStart; n < nEnd; n = n + 1 + n/10) {
   for (int m = mStart; m < mEnd; m = m + 1 + m/10) {
    float *A = (float*) malloc((n + m) * n * sizeof(float));
    float *C = (float*) malloc(n * n * sizeof(float));
    float *C_ref = (float*) malloc(n * n * sizeof(float));
    for (int i = 0; i < (n + m) * n; i++)
     A[i] = 2 * drand48() - 1;
    memset( C_ref, 0, sizeof( float ) * n * n);
    sgemm_reference(m, n, A, C_ref);
    memset( C, 0, sizeof( float ) * n * n);
    sgemm(m, n, m, A, C);
    for (int i = 0; i < n * n; i++) {
     C[i] -= C_ref[i];
    }
    for (int i = 0; i < n * n; i++) {
     if (i < 100) {
     }
     if (C[i] * C[i] > 0.0001) {
      printf(
        "FAILURE: error in matrix multiply exceeds an acceptable margin\n");
      printf(
        "Off by: %f, from the reference: %f, at n = %d, m = %d, i = %d\n",
        C[i], C_ref[i], n, m, i);
      return -1;
     }
    }
    double Gflop_s, seconds = -1.0;
    for (int n_iterations = 1; seconds < 0.1; n_iterations *= 2) {
     sgemm(m, n, m, A, C);
     struct timeval start, end;
     gettimeofday(&start, ((void *)0) );
     for (int i = 0; i < n_iterations; i++)
      sgemm(m, n, m, A, C);
     gettimeofday(&end, ((void *)0) );
     seconds = (end.tv_sec - start.tv_sec)
       + 1.0e-6 * (end.tv_usec - start.tv_usec);
     Gflop_s = 2e-9 * n_iterations * m * n * n / seconds;
    }
    printf("n = %d, m =  %d \t %g Gflop/s\n", n, m, Gflop_s);
    counter++;
    sum += Gflop_s;
    free(C_ref);
    free(C);
    free(A);
   }
  }
 printf("Average Gflops: %f\n", sum / counter);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 srand(time(((void *)0) ));
 int counter = 0;
 float sum = 0;
 int nStart = 401;
 int nEnd = 1500;
 int mStart = 32;
 int mEnd = 150;
 int loopEnd = 1;
 if (argc == 3) {
  nStart = atoi(argv[1]);
  nEnd = nStart + 1;
  mStart = atoi(argv[2]);
  mEnd = mStart + 1;
  loopEnd = 10;
 }
 for (int loop = 0; loop < loopEnd; loop++)
  for (int n = nStart; n < nEnd; n = n + 1 + n/10) {
   for (int m = mStart; m < mEnd; m = m + 1 + m/10) {
    float *A = (float*) malloc((n + m) * n * sizeof(float));
    float *C = (float*) malloc(n * n * sizeof(float));
    float *C_ref = (float*) malloc(n * n * sizeof(float));
    for (int i = 0; i < (n + m) * n; i++)
     A[i] = 2 * drand48() - 1;
    memset( C_ref, 0, sizeof( float ) * n * n);
    sgemm_reference(m, n, A, C_ref);
    memset( C, 0, sizeof( float ) * n * n);
    sgemm(m, n, m, A, C);
    for (int i = 0; i < n * n; i++) {
     C[i] -= C_ref[i];
    }
    for (int i = 0; i < n * n; i++) {
     if (i < 100) {
     }
     if (C[i] * C[i] > 0.0001) {
      printf(
        "FAILURE: error in matrix multiply exceeds an acceptable margin\n");
      printf(
        "Off by: %f, from the reference: %f, at n = %d, m = %d, i = %d\n",
        C[i], C_ref[i], n, m, i);
      return -1;
     }
    }
    double Gflop_s; double seconds = -1.0;
    for (int n_iterations = 1; seconds < 0.1; n_iterations *= 2) {
     sgemm(m, n, m, A, C);
     struct timeval start; struct timeval end;
     gettimeofday(&start, ((void *)0) );
     for (int i = 0; i < n_iterations; i++)
      sgemm(m, n, m, A, C);
     gettimeofday(&end, ((void *)0) );
     seconds = (end.tv_sec - start.tv_sec)
       + 1.0e-6 * (end.tv_usec - start.tv_usec);
     Gflop_s = 2e-9 * n_iterations * m * n * n / seconds;
    }
    printf("n = %d, m =  %d \t %g Gflop/s\n", n, m, Gflop_s);
    counter++;
    sum += Gflop_s;
    free(C_ref);
    free(C);
    free(A);
   }
  }
 printf("Average Gflops: %f\n", sum / counter);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: counter int

variable_types: sum float

variable_types: nStart int

variable_types: nEnd int

variable_types: mStart int

variable_types: mEnd int

variable_types: loopEnd int

variable_types: loop int

variable_types: seconds double

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

return_type: int


decompiled_code:
void *__fastcall net_run_server(void *a1)
{
int *v1; // rax
char *v2; // rax
int v3; // eax
socklen_t addr_len; // [rsp+0h] [rbp-43Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-438h] BYREF
char v7[16]; // [rsp+14h] [rbp-428h] BYREF
char buf[1048]; // [rsp+24h] [rbp-418h] BYREF

if ( !*((_BYTE *)a1 + 32) )
return 0LL;
do
{
addr_len = 16;
v3 = recvfrom(*((_DWORD *)a1 + 4), buf, 0x400uLL, 0, &addr, &addr_len);
if ( v3 == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
e2log(2LL, "recvfrom: %s", v2);
}
else
{
buf[v3] = 0;
inet_ntop(2, &addr.sa_data[2], v7, 0x10u);
e2log(1LL, "Message from %s: %s", v7, buf);
}
}
while ( *((_BYTE *)a1 + 32) );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
int *v1; // rax
char *v2; // rax
int v3; // eax
socklen_t addr_len; // [rsp+0h] [rbp-43Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-438h] BYREF
char v7[16]; // [rsp+14h] [rbp-428h] BYREF
char buf[1048]; // [rsp+24h] [rbp-418h] BYREF

if ( !*((_BYTE *)a1 + 32) )
return 0LL;
do
{
addr_len = 16;
v3 = recvfrom(*((_DWORD *)a1 + 4), buf, 0x400uLL, 0, &addr, &addr_len);
if ( v3 == -1 )
{
v1 = _errno_location();
v2 = strerror(*v1);
e2log(2LL, "recvfrom: %s", v2);
}
else
{
buf[v3] = 0;
inet_ntop(2, &addr.sa_data[2], v7, 0x10u);
e2log(1LL, "Message from %s: %s", v7, buf);
}
}
while ( *((_BYTE *)a1 + 32) );
return 0LL;
}

original_code:
static void * net_run_server(void *arg)
{
 char buffer[1024];
 char addrbuff[16];
 net_server *server = (net_server *)arg;
 struct sockaddr from;
 int alen, rlen;
 while(server->running) {
  alen = sizeof(from);
  rlen = recvfrom(server->socket, buffer, 1024, 0, &from, &alen);
  if (rlen == -1)
  {
   e2log(LOG_ERR, "recvfrom: %s", strerror((*__errno_location ())));
  }
  else
  {
   buffer[rlen] = 0;
   inet_ntop(2,
     &((struct sockaddr_in *)&from)->sin_addr,
     addrbuff,
     16);
   e2log(LOG_MON, "Message from %s: %s", addrbuff, buffer);
  }
 }
 return ((void *)0);
}

canonical_original_code:
static void *net_run_server(void *arg)
{
 char buffer[1024];
 char addrbuff[16];
 struct net_srv_t *server = (net_server *)arg;
 struct sockaddr from;
 int alen; int rlen;
 while(server->running) {
  alen = sizeof(from);
  rlen = recvfrom(server->socket, buffer, 1024, 0, &from, &alen);
  if (rlen == -1)
  {
   e2log(LOG_ERR, "recvfrom: %s", strerror((*__errno_location ())));
  }
  else
  {
   buffer[rlen] = 0;
   inet_ntop(2,
     &((struct sockaddr_in *)&from)->sin_addr,
     addrbuff,
     16);
   e2log(LOG_MON, "Message from %s: %s", addrbuff, buffer);
  }
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
buffer
char [1024]

variable_types:
addrbuff
char [16]

variable_types: struct net_srv_t { struct net_cfg_t { short port; char *application_name; } config; int socket; unsigned long net_listener; char running; int connection_count; struct net_con_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } remote; enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 } status; } *connections; } *

variable_types: alen int

variable_types: rlen int

return_type: void *

user_defined_types: struct net_srv_t { struct net_cfg_t config; int socket; unsigned long net_listener; char running; int connection_count; struct net_con_t *connections; }

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

user_defined_types: struct net_con_t { struct sockaddr remote; enum net_status status; }


decompiled_code:
int *__fastcall net_create_server(unsigned int a1, __int64 a2)
{
int *v2; // rbx
int v3; // eax
int v4; // eax
const char *v6; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-68h] BYREF
char s[48]; // [rsp+48h] [rbp-30h] BYREF

v2 = (int *)malloc(0x30uLL);
e2log(1LL, "Creating server on port %u", a1);
*(_WORD *)v2 = _bswap_16(a1);
*((_QWORD *)v2 + 1) = a2;
v3 = socket(2, 2, 0);
v2[4] = v3;
if ( v3 == -1 )
{
perror("socket");
free(v2);
v2 = 0LL;
}
else
{
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
snprintf(s, 8uLL, "%u", a1);
v4 = getaddrinfo(0LL, s, &req, &pai);
if ( v4 )
{
v6 = gai_strerror(v4);
e2log(2LL, "getaddrinfo: %s", v6);
free(v2);
v2 = 0LL;
}
else if ( bind(v2[4], pai->ai_addr, pai->ai_addrlen) == -1 )
{
perror("bind");
free(v2);
freeaddrinfo(pai);
v2 = 0LL;
}
else
{
freeaddrinfo(pai);
}
}
return v2;
}

canonical_decompiled_code:
int *__fastcall func2(unsigned int a1, __int64 a2)
{
int *v2; // rbx
int v3; // eax
int v4; // eax
const char *v6; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-68h] BYREF
char s[48]; // [rsp+48h] [rbp-30h] BYREF

v2 = (int *)malloc(0x30uLL);
e2log(1LL, "Creating server on port %u", a1);
*(_WORD *)v2 = func0(a1);
*((_QWORD *)v2 + 1) = a2;
v3 = socket(2, 2, 0);
v2[4] = v3;
if ( v3 == -1 )
{
perror("socket");
free(v2);
v2 = 0LL;
}
else
{
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
snprintf(s, 8uLL, "%u", a1);
v4 = getaddrinfo(0LL, s, &req, &pai);
if ( v4 )
{
v6 = gai_strerror(v4);
e2log(2LL, "getaddrinfo: %s", v6);
free(v2);
v2 = 0LL;
}
else if ( bind(v2[4], pai->ai_addr, pai->ai_addrlen) == -1 )
{
perror("bind");
free(v2);
freeaddrinfo(pai);
v2 = 0LL;
}
else
{
freeaddrinfo(pai);
}
}
return v2;
}

original_code:
net_server *net_create_server(int port, const char *application_name)
{
 char buff[8];
 int status;
 struct addrinfo hints, *res;
 net_server *ret = malloc(sizeof(net_server));
 e2log(LOG_MON, "Creating server on port %u", (int)port);
 ret->config.port = htons(port);
 ret->config.application_name = application_name;
 ret->socket = socket(2, SOCK_DGRAM, 0);
 if (ret->socket == -1)
 {
  perror("socket");
  free(ret);
  return ((void *)0);
 }
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_DGRAM;
 hints.ai_flags = 0x0001;
 snprintf(buff, 8, "%u", port);
 status = getaddrinfo(((void *)0), buff, &hints, &res);
 if (status != 0)
 {
  e2log(LOG_ERR, "getaddrinfo: %s", gai_strerror(status));
  free(ret);
  return ((void *)0);
 }
 if (bind(ret->socket, res->ai_addr, res->ai_addrlen) == -1)
 {
  perror("bind");
  free(ret);
  freeaddrinfo(res);
  return ((void *)0);
 }
 freeaddrinfo(res);
 return ret;
}

canonical_original_code:
struct net_srv_t *net_create_server(int port, char *application_name)
{
 char buff[8];
 int status;
 struct addrinfo hints; struct addrinfo *res;
 struct net_srv_t *ret = malloc(sizeof(net_server));
 e2log(LOG_MON, "Creating server on port %u", (int)port);
 ret->config.port = htons(port);
 ret->config.application_name = application_name;
 ret->socket = socket(2, SOCK_DGRAM, 0);
 if (ret->socket == -1)
 {
  perror("socket");
  free(ret);
  return ((void *)0);
 }
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_DGRAM;
 hints.ai_flags = 0x0001;
 snprintf(buff, 8, "%u", port);
 status = getaddrinfo(((void *)0), buff, &hints, &res);
 if (status != 0)
 {
  e2log(LOG_ERR, "getaddrinfo: %s", gai_strerror(status));
  free(ret);
  return ((void *)0);
 }
 if (bind(ret->socket, res->ai_addr, res->ai_addrlen) == -1)
 {
  perror("bind");
  free(ret);
  freeaddrinfo(res);
  return ((void *)0);
 }
 freeaddrinfo(res);
 return ret;
}

variable_types: port int

variable_types:
buff
char [8]

variable_types: status int

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

return_type: struct net_srv_t { struct net_cfg_t { short port; char *application_name; } config; int socket; unsigned long net_listener; char running; int connection_count; struct net_con_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } remote; enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 } status; } *connections; } *

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


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

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

original_code:
void net_free_server(net_server *server)
{
 if (server)
 {
  free(server);
 }
}

canonical_original_code:
void net_free_server(struct net_srv_t *server)
{
 if (server)
 {
  free(server);
 }
}

user_defined_types: struct net_cfg_t { short port; char *application_name; }

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

user_defined_types: enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 }


decompiled_code:
int __fastcall net_start_server(void *arg)
{
int result; // eax

if ( !arg )
return e2log(2LL, "net_start_server: null server");
*((_BYTE *)arg + 32) = 1;
result = pthread_create((pthread_t *)arg + 3, 0LL, net_run_server, arg);
if ( result )
result = e2log(2LL, "net_start_server: failed creating thread");
return result;
}

canonical_decompiled_code:
int __fastcall func4(void *arg)
{
int result; // eax

if ( !arg )
return e2log(2LL, "net_start_server: null server");
*((_BYTE *)arg + 32) = 1;
result = pthread_create((pthread_t *)arg + 3, 0LL, net_run_server, arg);
if ( result )
result = e2log(2LL, "net_start_server: failed creating thread");
return result;
}

original_code:
void net_start_server(net_server *server, int backlog)
{
 if (!server)
 {
  e2log(LOG_ERR, "net_start_server: null server");
  return;
 }
 server->running = 1;
 if (pthread_create(&server->net_listener, ((void *)0), &net_run_server, server)) {
  e2log(LOG_ERR, "net_start_server: failed creating thread");
  return;
 }
}

canonical_original_code:
void net_start_server(struct net_srv_t *server, int backlog)
{
 if (!server)
 {
  e2log(LOG_ERR, "net_start_server: null server");
  return;
 }
 server->running = 1;
 if (pthread_create(&server->net_listener, ((void *)0), &net_run_server, server)) {
  e2log(LOG_ERR, "net_start_server: failed creating thread");
  return;
 }
}

variable_types: backlog int


decompiled_code:
int __fastcall net_stop_server(__int64 a1)
{
*(_BYTE *)(a1 + 32) = 0;
return pthread_join(*(_QWORD *)(a1 + 24), 0LL);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
*(_BYTE *)(a1 + 32) = 0;
return pthread_join(*(_QWORD *)(a1 + 24), 0LL);
}

original_code:
void net_stop_server(net_server *server, const char *reason)
{
 server->running = 0;
 pthread_join(server->net_listener, ((void *)0));
}

canonical_original_code:
void net_stop_server(struct net_srv_t *server, char *reason)
{
 server->running = 0;
 pthread_join(server->net_listener, ((void *)0));
}

variable_types:
reason
char *


decompiled_code:
int e2log(int a1, const char *a2, ...)
{
struct tm *v2; // rax
time_t v4; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v4 = time(0LL);
v2 = localtime(&v4);
printf(
"[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min,
(unsigned int)v2->tm_sec,
log_level_names[a1]);
vprintf(a2, arg);
return putchar(10);
}

canonical_decompiled_code:
int func0(int a1, const char *a2, ...)
{
struct tm *v2; // rax
time_t v4; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v4 = time(0LL);
v2 = localtime(&v4);
printf(
"[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min,
(unsigned int)v2->tm_sec,
log_level_names[a1]);
vprintf(a2, arg);
return putchar(10);
}

original_code:
void e2log(enum LOG_LEVEL lvl, const char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 time_t t;
 t = time(((void *)0));
 struct tm *tm = localtime(&t);
 printf("[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
  tm->tm_year+1900,
  tm->tm_mon+1,
  tm->tm_mday,
  tm->tm_hour,
  tm->tm_min,
  tm->tm_sec,
  log_level_names[lvl]
 );
 vprintf(fmt, ap);
 printf("\n");
 __builtin_va_end(ap);
}

canonical_original_code:
void e2log(enum LOG_LEVEL lvl, char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 long t;
 t = time(((void *)0));
 struct tm *tm = localtime(&t);
 printf("[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
  tm->tm_year+1900,
  tm->tm_mon+1,
  tm->tm_mday,
  tm->tm_hour,
  tm->tm_min,
  tm->tm_sec,
  log_level_names[lvl]
 );
 vprintf(fmt, ap);
 printf("\n");
 __builtin_va_end(ap);
}

variable_types: enum LOG_LEVEL { LOG_DBG=0, LOG_MON=1, LOG_ERR=2 }

variable_types:
fmt
char *

variable_types: t long

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


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

if ( *(_DWORD *)(a1 + 8) + a2 > *(_DWORD *)(a1 + 4) )
result = resize_message();
return result;
}

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

if ( *(_DWORD *)(a1 + 8) + a2 > *(_DWORD *)(a1 + 4) )
result = resize_message();
return result;
}

original_code:
static void require_len(net_outgoing_message *msg, int len)
{
 if (msg->pos + len <= msg->allocated_length) return;
 resize_message(msg);
}

canonical_original_code:
static void require_len(struct net_msgo_t *msg, int len)
{
 if (msg->pos + len <= msg->allocated_length) return;
 resize_message(msg);
}

variable_types: struct net_msgo_t { char flags; int allocated_length; int pos; char *buffer; } *

variable_types: len int


decompiled_code:
__int64 __fastcall net_msg_write_byte(__int64 a1, char a2)
{
__int64 result; // rax

require_len(a1, 1);
result = *(int *)(a1 + 8);
*(_BYTE *)(*(_QWORD *)(a1 + 16) + result) = a2;
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
__int64 result; // rax

func0(a1, 1);
result = *(int *)(a1 + 8);
*(_BYTE *)(*(_QWORD *)(a1 + 16) + result) = a2;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void net_msg_write_byte(net_outgoing_message *msg, char data)
{
 require_len(msg, sizeof(char));
 msg->buffer[msg->pos] = data;
 msg->pos += sizeof(char);
}

canonical_original_code:
void net_msg_write_byte(struct net_msgo_t *msg, char data)
{
 require_len(msg, sizeof(char));
 msg->buffer[msg->pos] = data;
 msg->pos += sizeof(char);
}

variable_types: data char

user_defined_types: struct net_msgo_t { char flags; int allocated_length; int pos; char *buffer; }


decompiled_code:
__int64 __fastcall net_msg_write_int16(__int64 a1, __int16 a2)
{
__int16 v2; // cx
__int64 result; // rax

require_len(a1, 2);
v2 = _bswap_16(a2);
result = *(int *)(a1 + 8);
*(_WORD *)(*(_QWORD *)(a1 + 16) + result) = v2;
*(_DWORD *)(a1 + 8) += 2;
return result;
}

original_code:
void net_msg_write_int16(net_outgoing_message *msg, int16_t data)
{
 require_len(msg, sizeof(int16_t));
 *((int16_t *)(msg->buffer + msg->pos)) = htons(data);
 msg->pos += sizeof(int16_t);
}

canonical_original_code:
void net_msg_write_int16(struct net_msgo_t *msg, short data)
{
 require_len(msg, sizeof(short));
 *((short *)(msg->buffer + msg->pos)) = htons(data);
 msg->pos += sizeof(short);
}

variable_types: data short


decompiled_code:
__int64 __fastcall net_msg_write_int32(__int64 a1, unsigned int a2)
{
int v2; // ecx
__int64 result; // rax

require_len(a1, 4);
v2 = _bswap_32(a2);
result = *(int *)(a1 + 8);
*(_DWORD *)(*(_QWORD *)(a1 + 16) + result) = v2;
*(_DWORD *)(a1 + 8) += 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
int v2; // ecx
__int64 result; // rax

func0(a1, 4);
v2 = func2(a2);
result = *(int *)(a1 + 8);
*(_DWORD *)(*(_QWORD *)(a1 + 16) + result) = v2;
*(_DWORD *)(a1 + 8) += 4;
return result;
}

original_code:
void net_msg_write_int32(net_outgoing_message *msg, int32_t data)
{
 require_len(msg, sizeof(int32_t));
 *((int32_t *)(msg->buffer + msg->pos)) = htonl(data);
 msg->pos += sizeof(int32_t);
}

canonical_original_code:
void net_msg_write_int32(struct net_msgo_t *msg, int data)
{
 require_len(msg, sizeof(int));
 *((int *)(msg->buffer + msg->pos)) = htonl(data);
 msg->pos += sizeof(int);
}

variable_types: data int


decompiled_code:
char *__fastcall net_msg_write_string(__int64 a1, const char *a2)
{
__int16 v2; // bp
char *result; // rax

v2 = strlen(a2);
require_len(a1, v2 + 2);
net_msg_write_int16(a1, v2);
result = strncpy((char *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 8)), a2, v2);
*(_DWORD *)(a1 + 8) += v2;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, const char *a2)
{
__int16 v2; // bp
char *result; // rax

v2 = strlen(a2);
func0(a1, v2 + 2);
func4(a1, v2);
result = strncpy((char *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 8)), a2, v2);
*(_DWORD *)(a1 + 8) += v2;
return result;
}

original_code:
void net_msg_write_string(net_outgoing_message *msg, const char *data)
{
 short slen = strlen(data);
 require_len(msg, slen + sizeof(int16_t));
 net_msg_write_int16(msg, slen);
 strncpy(msg->buffer + msg->pos, data, (size_t)slen);
 msg->pos += slen;
}

canonical_original_code:
void net_msg_write_string(struct net_msgo_t *msg, char *data)
{
 short slen = strlen(data);
 require_len(msg, slen + sizeof(short));
 net_msg_write_int16(msg, slen);
 strncpy(msg->buffer + msg->pos, data, (unsigned long)slen);
 msg->pos += slen;
}

variable_types:
data
char *

variable_types: slen short


decompiled_code:
__int64 __fastcall net_msg_write_fix(__int64 a1, unsigned int a2)
{
return net_msg_write_int32(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return func5(a1, a2);
}

original_code:
void net_msg_write_fix(net_outgoing_message *msg, fix data)
{
 net_msg_write_int32(msg, (int32_t)data);
}

canonical_original_code:
void net_msg_write_fix(struct net_msgo_t *msg, int data)
{
 net_msg_write_int32(msg, (int)data);
}


original_code:
char net_msg_read_byte(net_incoming_message *msg)
{
 return msg->buffer[msg->pos++];
}

canonical_original_code:
char net_msg_read_byte(struct net_msgi_t *msg)
{
 return msg->buffer[msg->pos++];
}

variable_types: struct net_msgi_t { enum message_type { NetMsg_Error=0, NetMsg_Connect=1, NetMsg_ConnectResponse=2, NetMsg_StatusChanged=3, NetMsg_Data=4 } type; char flags; struct net_con_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } remote; enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 } status; } *connection; int len; int pos; char *buffer; } *

return_type: char

user_defined_types: struct net_msgi_t { enum message_type type; char flags; struct net_con_t *connection; int len; int pos; char *buffer; }


decompiled_code:
__int16 __fastcall net_msg_read_int16(__int64 a1)
{
int v1; // ebp
__int16 result; // ax

v1 = *(_DWORD *)(a1 + 20);
result = _bswap_16(*(_WORD *)(*(_QWORD *)(a1 + 24) + v1));
*(_DWORD *)(a1 + 20) = v1 + 2;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func9(__int64 a1)
{
int v1; // ebp
__int16 result; // ax

v1 = *(_DWORD *)(a1 + 20);
result = func1(*(_WORD *)(*(_QWORD *)(a1 + 24) + v1));
*(_DWORD *)(a1 + 20) = v1 + 2;
return result;
}

original_code:
int16_t net_msg_read_int16(net_incoming_message *msg)
{
 int16_t ret = ntohs(*((int16_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(int16_t);
 return ret;
}

canonical_original_code:
short net_msg_read_int16(struct net_msgi_t *msg)
{
 short ret = ntohs(*((int16_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(short);
 return ret;
}

variable_types: ret short

return_type: short

user_defined_types: enum message_type { NetMsg_Error=0, NetMsg_Connect=1, NetMsg_ConnectResponse=2, NetMsg_StatusChanged=3, NetMsg_Data=4 }


decompiled_code:
__int64 __fastcall net_msg_read_int32(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 20);
result = _bswap_32(*(_DWORD *)(*(_QWORD *)(a1 + 24) + v1));
*(_DWORD *)(a1 + 20) = v1 + 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 20);
result = func2(*(_DWORD *)(*(_QWORD *)(a1 + 24) + v1));
*(_DWORD *)(a1 + 20) = v1 + 4;
return result;
}

original_code:
int32_t net_msg_read_int32(net_incoming_message *msg)
{
 int32_t ret = ntohl(*((int32_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(int32_t);
 return ret;
}

canonical_original_code:
int net_msg_read_int32(struct net_msgi_t *msg)
{
 int ret = ntohl(*((int32_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(int);
 return ret;
}

variable_types: ret int


decompiled_code:
char *__fastcall net_msg_read_string(__int64 a1)
{
__int16 v1; // bx
char *v2; // r13
int v3; // ebp
char *result; // rax

v1 = net_msg_read_int16(a1);
v2 = (char *)malloc(v1 + 1);
v3 = *(_DWORD *)(a1 + 20);
result = strncpy(v2, (const char *)(*(_QWORD *)(a1 + 24) + v3), v1);
v2[v1] = 0;
*(_DWORD *)(a1 + 20) = v1 + v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1)
{
__int16 v1; // bx
char *v2; // r13
int v3; // ebp
char *result; // rax

v1 = func9(a1);
v2 = (char *)malloc(v1 + 1);
v3 = *(_DWORD *)(a1 + 20);
result = strncpy(v2, (const char *)(*(_QWORD *)(a1 + 24) + v3), v1);
v2[v1] = 0;
*(_DWORD *)(a1 + 20) = v1 + v3;
return result;
}

original_code:
char *net_msg_read_string(net_incoming_message *msg)
{
 int slen;
 char *buff;
 slen = net_msg_read_int16(msg);
 buff = malloc(slen+1);
 strncpy(buff, msg->buffer+msg->pos, slen);
 buff[slen] = 0;
 msg->pos += slen;
 return buff;
}

canonical_original_code:
char *net_msg_read_string(struct net_msgi_t *msg)
{
 int slen;
 char *buff;
 slen = net_msg_read_int16(msg);
 buff = malloc(slen+1);
 strncpy(buff, msg->buffer+msg->pos, slen);
 buff[slen] = 0;
 msg->pos += slen;
 return buff;
}

variable_types: slen int

variable_types:
buff
char *

return_type: char *


decompiled_code:
__int64 __fastcall net_msg_read_fix(__int64 a1)
{
return net_msg_read_int32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func10(a1);
}

original_code:
fix net_msg_read_fix(net_incoming_message *msg)
{
 return (fix)(net_msg_read_int32(msg));
}

canonical_original_code:
int net_msg_read_fix(struct net_msgi_t *msg)
{
 return (fix)(net_msg_read_int32(msg));
}


original_code:
int resize_message(net_outgoing_message *msg)
{
 char *b;
 int new_size = msg->allocated_length << 1;
 b = realloc(msg->buffer, new_size);
 if (b == ((void *)0))
  return 1;
 msg->allocated_length = new_size;
 if (b == msg->buffer) return 0;
 msg->buffer = b;
 return 0;
}

canonical_original_code:
int resize_message(struct net_msgo_t *msg)
{
 char *b;
 int new_size = msg->allocated_length << 1;
 b = realloc(msg->buffer, new_size);
 if (b == ((void *)0))
  return 1;
 msg->allocated_length = new_size;
 if (b == msg->buffer) return 0;
 msg->buffer = b;
 return 0;
}

variable_types:
b
char *


decompiled_code:
void __fastcall net_free_outgoing_message(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void net_free_outgoing_message(net_outgoing_message *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}

canonical_original_code:
void net_free_outgoing_message(struct net_msgo_t *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}


decompiled_code:
void __fastcall net_free_incoming_message(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void net_free_incoming_message(net_incoming_message *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}

canonical_original_code:
void net_free_incoming_message(struct net_msgi_t *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}


repo: palexster/Genetic

original_code:
void parent_selection(long *parents,population_t *pop){
    char *chosen=(char *)malloc(sizeof(char)*pop->pop_dim);
    long i,tmp;
    for(i=0;i<pop->pop_dim;i++)
        chosen[i]=FALSE;
    for(i=0;i<pop->elite;i++)
        parents[i]=-i-1;
    for(;i<pop->gen_n;i++){
        tmp=rand()%(pop->pop_dim-pop->elite)+pop->elite;
        while(chosen[tmp])
            tmp=((tmp+1)%pop->pop_dim)+(pop->elite*(tmp/pop->pop_dim));
        parents[i]=-(tmp+1);
        chosen[tmp]=TRUE;
    }
    free(chosen);
    return;
}

canonical_original_code:
void parent_selection(long *parents, struct population_s *pop){
    char *chosen = (char *)malloc(sizeof(char)*pop->pop_dim);
    long i; long tmp;
    for(i=0;i<pop->pop_dim;i++)
        chosen[i]=FALSE;
    for(i=0;i<pop->elite;i++)
        parents[i]=-i-1;
    for(;i<pop->gen_n;i++){
        tmp=rand()%(pop->pop_dim-pop->elite)+pop->elite;
        while(chosen[tmp])
            tmp=((tmp+1)%pop->pop_dim)+(pop->elite*(tmp/pop->pop_dim));
        parents[i]=-(tmp+1);
        chosen[tmp]=TRUE;
    }
    free(chosen);
    return;
}

variable_types:
parents
long *

variable_types: struct population_s { struct solution_s { unsigned char ***matrice_pezzi; unsigned short fitness; } *soluzioni; double bests[2][3]; long current_iteration; long pop_dim; long gen_n; long elite; long mutation; } *

variable_types:
chosen
char *

variable_types: i long

variable_types: tmp long

user_defined_types: struct population_s { struct solution_s *soluzioni; double bests[2][3]; long current_iteration; long pop_dim; long gen_n; long elite; long mutation; }


original_code:
void offspring_generation(int **pieces,int npieces,population_t *pop,long *parents,solution_t *offspring,int row, int col){
    long i,j,tmp;
    long cnt;
    long gen[2];

#pragma omp parallel default(none) shared(pieces,npieces,pop,parents,offspring,row,col) firstprivate(i,j,cnt,tmp,gen)
{

#pragma omp for
    for(i=0;i<pop->gen_n;i+=2){
        j=i+1;

#pragma omp critical (print_tid)
      {
        for(cnt=0;cnt<2;cnt++){
                tmp=rand()%pop->gen_n;
                while(parents[tmp]>0)
                        tmp=((tmp+1)%pop->gen_n);
                gen[cnt]=tmp;
                parents[tmp]*=-1;
        }
      }
        offspring[i].matrice_pezzi=matalloc(row,col);
        offspring[j].matrice_pezzi=matalloc(row,col);
        crossover(&pop->soluzioni[parents[gen[0]]-1],&pop->soluzioni[parents[gen[1]]-1],&offspring[i],&offspring[j],pieces,npieces,row,col);
        offspring[i].fitness=fitness_solution_evaluation(pieces,&offspring[i],npieces,row,col);
        offspring[j].fitness=fitness_solution_evaluation(pieces,&offspring[j],npieces,row,col);
    }
    }
    return;
}

canonical_original_code:
void offspring_generation(int **pieces, int npieces, struct population_s *pop, long *parents, struct solution_s *offspring, int row, int col){
    long i; long j; long tmp;
    long cnt;
    long gen[2];

#pragma omp parallel default(none) shared(pieces,npieces,pop,parents,offspring,row,col) firstprivate(i,j,cnt,tmp,gen)
{

#pragma omp for
    for(i=0;i<pop->gen_n;i+=2){
        j=i+1;

#pragma omp critical (print_tid)
      {
        for(cnt=0;cnt<2;cnt++){
                tmp=rand()%pop->gen_n;
                while(parents[tmp]>0)
                        tmp=((tmp+1)%pop->gen_n);
                gen[cnt]=tmp;
                parents[tmp]*=-1;
        }
      }
        offspring[i].matrice_pezzi=matalloc(row,col);
        offspring[j].matrice_pezzi=matalloc(row,col);
        crossover(&pop->soluzioni[parents[gen[0]]-1],&pop->soluzioni[parents[gen[1]]-1],&offspring[i],&offspring[j],pieces,npieces,row,col);
        offspring[i].fitness=fitness_solution_evaluation(pieces,&offspring[i],npieces,row,col);
        offspring[j].fitness=fitness_solution_evaluation(pieces,&offspring[j],npieces,row,col);
    }
    }
    return;
}

variable_types:
pieces
int **

variable_types: npieces int

variable_types:
offspring
struct solution_s *

variable_types: row int

variable_types: col int

variable_types: j long

variable_types: cnt long

variable_types:
gen
long [2]

user_defined_types: struct solution_s { unsigned char ***matrice_pezzi; unsigned short fitness; }


original_code:
void sub1(population_t *pop,solution_t *offspring,int row, int col){
    char *chosen=(char *)malloc(sizeof(char)*pop->pop_dim);
    long i,cnt;
    float tmp_rnd,
            sum_inv_fit,
            pi;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(float)1/(float)pop->soluzioni[i].fitness;
    }
    cnt=0;
    for(i=0;cnt<pop->gen_n;i=((i+1)%pop->pop_dim)){
        tmp_rnd=(float)rand()/(float)2147483647;
        pi=((float)1/(float)pop->soluzioni[i].fitness);
        if((!chosen[i])&&(tmp_rnd<pi)){
            dealloc_soluzioni(&pop->soluzioni[i],row,col);
            pop->soluzioni[i]=offspring[cnt++];
            chosen[i]=TRUE;
        }
    }
    free(chosen);
}

canonical_original_code:
void sub1(struct population_s *pop, struct solution_s *offspring, int row, int col){
    char *chosen = (char *)malloc(sizeof(char)*pop->pop_dim);
    long i; long cnt;
    float tmp_rnd; float sum_inv_fit; float pi;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(float)1/(float)pop->soluzioni[i].fitness;
    }
    cnt=0;
    for(i=0;cnt<pop->gen_n;i=((i+1)%pop->pop_dim)){
        tmp_rnd=(float)rand()/(float)2147483647;
        pi=((float)1/(float)pop->soluzioni[i].fitness);
        if((!chosen[i])&&(tmp_rnd<pi)){
            dealloc_soluzioni(&pop->soluzioni[i],row,col);
            pop->soluzioni[i]=offspring[cnt++];
            chosen[i]=TRUE;
        }
    }
    free(chosen);
}

variable_types: pi float


original_code:
void sub2(population_t *pop,solution_t *offspring,int row, int col){
    char *chosen=(char *)malloc(sizeof(char)*pop->pop_dim);
    long i,cnt;
    double tmp_rnd,
            sum_inv_fit;
    double *distribution=(double *)malloc(sizeof(double)*pop->pop_dim);;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(double)1/(double)pop->soluzioni[i].fitness;
    }
    distribution[0]=(double)1/(double)pop->soluzioni[0].fitness/sum_inv_fit;
    for(i=1;i<pop->pop_dim;i++){
        distribution[i]=distribution[i-1]+((double)1/(double)pop->soluzioni[i].fitness)/sum_inv_fit;
    }
    for(cnt=0;cnt<pop->gen_n;cnt++){
        tmp_rnd=(double)rand()/(double)2147483647;
        for(i=0;(distribution[i]<tmp_rnd)&&(i<pop->pop_dim);i++);
        while(chosen[i])
            i=(i+1)%pop->pop_dim;
        dealloc_soluzioni(&pop->soluzioni[i],row,col);
        pop->soluzioni[i]=offspring[cnt];
        chosen[i]=TRUE;
    }
    free(chosen);
    free(distribution);
}

canonical_original_code:
void sub2(struct population_s *pop, struct solution_s *offspring, int row, int col){
    char *chosen = (char *)malloc(sizeof(char)*pop->pop_dim);
    long i; long cnt;
    double tmp_rnd; double sum_inv_fit;
    double *distribution = (double *)malloc(sizeof(double)*pop->pop_dim);;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(double)1/(double)pop->soluzioni[i].fitness;
    }
    distribution[0]=(double)1/(double)pop->soluzioni[0].fitness/sum_inv_fit;
    for(i=1;i<pop->pop_dim;i++){
        distribution[i]=distribution[i-1]+((double)1/(double)pop->soluzioni[i].fitness)/sum_inv_fit;
    }
    for(cnt=0;cnt<pop->gen_n;cnt++){
        tmp_rnd=(double)rand()/(double)2147483647;
        for(i=0;(distribution[i]<tmp_rnd)&&(i<pop->pop_dim);i++);
        while(chosen[i])
            i=(i+1)%pop->pop_dim;
        dealloc_soluzioni(&pop->soluzioni[i],row,col);
        pop->soluzioni[i]=offspring[cnt];
        chosen[i]=TRUE;
    }
    free(chosen);
    free(distribution);
}

variable_types:
distribution
double *


substitution

decompiled_code:
void __fastcall substitution(_QWORD *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
sub2(a1, a2, a3, a4);
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
func4(a1, a2, a3, a4);
}

original_code:
void substitution(population_t *pop,solution_t *offspring,int row, int col){
    sub2(pop,offspring,row,col);
}

canonical_original_code:
void substitution(struct population_s *pop, struct solution_s *offspring, int row, int col){
    sub2(pop,offspring,row,col);
}


decompiled_code:
void __fastcall light_mutation(__int64 a1, __int64 a2, _QWORD *a3, unsigned int a4, unsigned int a5)
{
__int64 v8; // rbx
int v9; // eax
__int64 v10; // rdi

if ( (__int64)a3[8] > 0 )
{
v8 = 0LL;
do
{
v9 = rand();
v10 = *a3 + 16 * v8;
if ( 1.0 / (double)*(unsigned __int16 *)(v10 + 8) > (double)v9 / 2147483647.0 )
random_rotate(v10, a4, a5);
++v8;
}
while ( a3[8] > v8 );
}
}

original_code:
void light_mutation(int **pieces,int npieces,population_t *pop,int row, int col,int *border){
    long i;
    double tmp_rnd,
            pi;
    for(i=0;i<pop->pop_dim;i++){
        tmp_rnd=(double)rand()/(double)2147483647;
        pi=((double)1/(double)pop->soluzioni[i].fitness);
        if(tmp_rnd<pi){
            random_rotate(&(pop->soluzioni[i]),row,col);
        }
    }
}

canonical_original_code:
void light_mutation(int **pieces, int npieces, struct population_s *pop, int row, int col, int *border){
    long i;
    double tmp_rnd; double pi;
    for(i=0;i<pop->pop_dim;i++){
        tmp_rnd=(double)rand()/(double)2147483647;
        pi=((double)1/(double)pop->soluzioni[i].fitness);
        if(tmp_rnd<pi){
            random_rotate(&(pop->soluzioni[i]),row,col);
        }
    }
}

variable_types:
border
int *

variable_types: pi double


repo: pamolloy/pong

decompiled_code:
int __fastcall set_ticker(int a1)
{
int result; // eax
int *v2; // rax
struct itimerval v3; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

newa.it_interval.tv_sec = a1 / 1000;
newa.it_interval.tv_usec = 1000LL * (a1 % 1000);
newa.it_value = newa.it_interval;
result = setitimer(ITIMER_REAL, &newa, &v3);
if ( result )
{
v2 = _errno_location();
printf("Error with timer..errno=%d\n", (unsigned int)*v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax
int *v2; // rax
struct itimerval v3; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

newa.it_interval.tv_sec = a1 / 1000;
newa.it_interval.tv_usec = 1000LL * (a1 % 1000);
newa.it_value = newa.it_interval;
result = setitimer(ITIMER_REAL, &newa, &v3);
if ( result )
{
v2 = _errno_location();
printf("Error with timer..errno=%d\n", (unsigned int)*v2);
exit(1);
}
return result;
}

original_code:
void set_ticker( int n_msecs )
{
    struct itimerval new_timeset, old_timeset;
    long n_sec, n_usecs;
    n_sec = n_msecs / 1000 ;
    n_usecs = ( n_msecs % 1000 ) * 1000L ;
    new_timeset.it_interval.tv_sec = n_sec;
    new_timeset.it_interval.tv_usec = n_usecs;
    new_timeset.it_value.tv_sec = n_sec ;
    new_timeset.it_value.tv_usec = n_usecs ;
    if ( setitimer( ITIMER_REAL, &new_timeset, &old_timeset ) != 0 ){
        printf("Error with timer..errno=%d\n", (*__errno_location ()) );
        exit(1);
    }
}

canonical_original_code:
void set_ticker(int n_msecs)
{
    struct itimerval new_timeset; struct itimerval old_timeset;
    long n_sec; long n_usecs;
    n_sec = n_msecs / 1000 ;
    n_usecs = ( n_msecs % 1000 ) * 1000L ;
    new_timeset.it_interval.tv_sec = n_sec;
    new_timeset.it_interval.tv_usec = n_usecs;
    new_timeset.it_value.tv_sec = n_sec ;
    new_timeset.it_value.tv_usec = n_usecs ;
    if ( setitimer( ITIMER_REAL, &new_timeset, &old_timeset ) != 0 ){
        printf("Error with timer..errno=%d\n", (*__errno_location ()) );
        exit(1);
    }
}

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
void my_handler()
{
set_ticker(0);
}

canonical_decompiled_code:
void func1()
{
func0(0);
}

original_code:
static void
my_handler(int s)
{
    set_ticker( 0 );
}

variable_types: s int


millisleep

decompiled_code:
int __fastcall millisleep(int a1)
{
signal(14, (__sighandler_t)my_handler);
set_ticker(a1);
return pause();
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
signal(14, (__sighandler_t)my_handler);
func0(a1);
return pause();
}

original_code:
void millisleep( int n )
{
    signal( 14 , my_handler);
    set_ticker( n );
    pause();
}

canonical_original_code:
void millisleep(int n)
{
    signal( 14 , my_handler);
    set_ticker( n );
    pause();
}

variable_types: n int


pong

decompiled_code:
_BOOL8 __fastcall pong(_DWORD *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1[1] < a2 )
result = *a1 > a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1[1] < a2 )
result = *a1 > a2;
return result;
}

original_code:
int pong ( struct bar *paddle, int x )
{
    if ( paddle->lower < x && x < paddle->upper )
        return 1;
    else
        return 0;
}

canonical_original_code:
int pong(struct bar *paddle, int x)
{
    if ( paddle->lower < x && x < paddle->upper )
        return 1;
    else
        return 0;
}

variable_types: struct bar { int upper; int lower; int len; } *

variable_types: x int


decompiled_code:
void add_tick()
{
++ticks;
}

canonical_decompiled_code:
void func0()
{
++ticks;
}

original_code:
void add_tick( int signal )
{
    ticks++;
}

canonical_original_code:
void add_tick(int signal)
{
    ticks++;
}

variable_types: signal int


decompiled_code:
__int64 setup_signal()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

signal(2, (__sighandler_t)((char *)add_tick + 1));
v1.sa_flags = 0;
v1.sa_handler = (__sighandler_t)add_tick;
sigemptyset(&v1.sa_mask);
sigaction(14, &v1, 0LL);
return set_ticker(20LL);
}

canonical_decompiled_code:
__int64 func2()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

signal(2, (__sighandler_t)((char *)add_tick + 1));
v1.sa_flags = 0;
v1.sa_handler = (__sighandler_t)add_tick;
sigemptyset(&v1.sa_mask);
sigaction(14, &v1, 0LL);
return set_ticker(20LL);
}

original_code:
void setup_signal()
{
    struct sigaction siginfo;
    signal(2, ((__sighandler_t) 1));
    siginfo.sa_flags = 0;
    siginfo.__sigaction_handler.sa_handler = add_tick;
    sigemptyset(&siginfo.sa_mask);
    sigaction(14, &siginfo, ((void *)0));
    set_ticker( 1000 / 50 );
}

canonical_original_code:
void setup_signal()
{
    struct sigaction siginfo;
    signal(2, ((void (*)(int)) 1));
    siginfo.sa_flags = 0;
    siginfo.__sigaction_handler.sa_handler = add_tick;
    sigemptyset(&siginfo.sa_mask);
    sigaction(14, &siginfo, ((void *)0));
    set_ticker( 1000 / 50 );
}

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

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

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


start

decompiled_code:
void start()
{
unsigned int v0; // eax

if ( !initscr() )
{
fwrite("initscr: failed to initialize curses", 1uLL, 0x24uLL, stderr);
exit(1);
}
noecho();
cbreak();
halfdelay(1);
nonl();
intrflush(0LL, 0);
if ( curs_set(0) == -1 )
{
fwrite("curs_set: failed to set cursor to invisible", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v0 = getpid();
srand(v0);
}

canonical_decompiled_code:
void func3()
{
unsigned int v0; // eax

if ( !initscr() )
{
fwrite("initscr: failed to initialize curses", 1uLL, 0x24uLL, stderr);
exit(1);
}
noecho();
cbreak();
halfdelay(1);
nonl();
intrflush(0LL, 0);
if ( curs_set(0) == -1 )
{
fwrite("curs_set: failed to set cursor to invisible", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v0 = getpid();
srand(v0);
}

original_code:
void start()
{
    if ( initscr() == ((void *)0) ) {
        fprintf(stderr, "initscr: failed to initialize curses");
        exit(1);
    }
    noecho();
    cbreak();
    halfdelay(1);
    nonl();
    intrflush(((void *)0), 0);
    if ( curs_set(0) == (-1) ) {
        fprintf(stderr, "curs_set: failed to set cursor to invisible");
        exit(1);
    }
    srand(getpid());
}


end

decompiled_code:
int end()
{
int result; // eax

result = endwin();
if ( result == -1 )
{
fwrite("endwin: failed to restore terminal settings", 1uLL, 0x2BuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

result = endwin();
if ( result == -1 )
{
fwrite("endwin: failed to restore terminal settings", 1uLL, 0x2BuLL, stderr);
exit(1);
}
return result;
}

original_code:
void end()
{
    if ( endwin() == (-1) ) {
        fprintf(stderr, "endwin: failed to restore terminal settings");
        exit(1);
    }
}


repo: pamolloy/sttyl

decompiled_code:
__int64 __fastcall print_all(__int64 a1)
{
print_speed();
print_special(a1);
return print_setting(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
func29();
func15(a1);
return func22(a1);
}

original_code:
void print_all( struct termios *ttyopts )
{
 print_speed(ttyopts);
 print_special(ttyopts);
 print_setting(ttyopts);
}

canonical_original_code:
void print_all(struct termios *ttyopts)
{
 print_speed(ttyopts);
 print_special(ttyopts);
 print_setting(ttyopts);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *


decompiled_code:
__int64 __fastcall check_speed(struct termios *termios_p, char *s2)
{
__int64 result; // rax

result = is_speed(s2);
if ( (_DWORD)result != -1 )
{
set_speed(termios_p);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(struct termios *termios_p, char *s2)
{
__int64 result; // rax

result = func27(s2);
if ( (_DWORD)result != -1 )
{
func28(termios_p);
result = 0LL;
}
return result;
}

original_code:
int check_speed( struct termios *ttyopts, char *av )
{
 int i = is_speed(av);
 if ( i != -1 ) {
  set_speed(ttyopts, i);
  return 0;
 }
 else {
  return -1;
 }
}

canonical_original_code:
int check_speed(struct termios *ttyopts, char *av)
{
 int i = is_speed(av);
 if ( i != -1 ) {
  set_speed(ttyopts, i);
  return 0;
 }
 else {
  return -1;
 }
}

variable_types:
av
char *

variable_types: i int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall check_special(struct termios *termios_p, char *s2, const char *a3)
{
__int64 result; // rax

result = is_special(s2);
if ( (_DWORD)result != -1 )
{
if ( !a3 )
{
fprintf(_bss_start, "%s: missing argument to `erase'\n", (const char *)program_name);
exit(1);
}
if ( (unsigned int)set_special(termios_p) == -1 )
{
fprintf(_bss_start, "%s: Invalid integer argument `%s'\n", (const char *)program_name, a3);
exit(1);
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(struct termios *termios_p, char *s2, const char *a3)
{
__int64 result; // rax

result = func12(s2);
if ( (_DWORD)result != -1 )
{
if ( !a3 )
{
fprintf(_bss_start, "%s: missing argument to `erase'\n", (const char *)program_name);
exit(1);
}
if ( (unsigned int)func13(termios_p) == -1 )
{
fprintf(_bss_start, "%s: Invalid integer argument `%s'\n", (const char *)program_name, a3);
exit(1);
}
result = 0LL;
}
return result;
}

original_code:
int check_special( struct termios *ttyopts, char *av, char *next)
{
 int i = is_special(av);
 if ( i != -1) {
  if ( next == ((void *)0) ) {
   fprintf(stderr, "%s: missing argument to `erase'\n",
     program_name);
   exit(1);
  }
  if ( set_special(ttyopts, i, next) == -1 ) {
   fprintf(stderr, "%s: Invalid integer argument `%s'\n",
     program_name, next);
   exit(1);
  }
  return 0;
 }
 return -1;
}

canonical_original_code:
int check_special(struct termios *ttyopts, char *av, char *next)
{
 int i = is_special(av);
 if ( i != -1) {
  if ( next == ((void *)0) ) {
   fprintf(stderr, "%s: missing argument to `erase'\n",
     program_name);
   exit(1);
  }
  if ( set_special(ttyopts, i, next) == -1 ) {
   fprintf(stderr, "%s: Invalid integer argument `%s'\n",
     program_name, next);
   exit(1);
  }
  return 0;
 }
 return -1;
}

variable_types:
next
char *


decompiled_code:
__int64 __fastcall check_setting(__int64 a1, char *a2)
{
char *v3; // rdi
unsigned int v4; // ebp
__int64 result; // rax

v3 = a2;
v4 = 1;
if ( *a2 == 45 )
{
v3 = a2 + 1;
v4 = 0;
}
result = is_setting(v3);
if ( (_DWORD)result != -1 )
{
set_setting(a1, (unsigned int)result, v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2)
{
char *v3; // rdi
unsigned int v4; // ebp
__int64 result; // rax

v3 = a2;
v4 = 1;
if ( *a2 == 45 )
{
v3 = a2 + 1;
v4 = 0;
}
result = func16(v3);
if ( (_DWORD)result != -1 )
{
func17(a1, (unsigned int)result, v4);
result = 0LL;
}
return result;
}

original_code:
int check_setting( struct termios *ttyopts, char *av )
{
 int on = 1;
 if (av[0] == '-') {
  on = 0;
  av++;
 }
 int i = is_setting(av);
 if ( i != -1 ) {
  set_setting(ttyopts, i, on);
  return 0;
 }
 return -1;
}

canonical_original_code:
int check_setting(struct termios *ttyopts, char *av)
{
 int on = 1;
 if (av[0] == '-') {
  on = 0;
  av++;
 }
 int i = is_setting(av);
 if ( i != -1 ) {
  set_setting(ttyopts, i, on);
  return 0;
 }
 return -1;
}

variable_types: on int


decompiled_code:
void __fastcall set_argvs(struct termios *termios_p, int a2, __int64 a3)
{
int i; // ebx
__int64 v5; // rbp
char **v6; // r12

if ( a2 > 1 )
{
for ( i = 1; i < a2; ++i )
{
v5 = 8LL * i;
v6 = (char **)(a3 + v5);
if ( (unsigned int)check_speed(termios_p, *(char **)(a3 + v5)) )
{
if ( (unsigned int)check_special(termios_p, *v6, *(const char **)(a3 + v5 + 8)) )
{
if ( (unsigned int)check_setting((__int64)termios_p, *v6) )
fprintf(_bss_start, "%s: invalid argument `%s'\n", (const char *)program_name, *v6);
}
else
{
++i;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func11(struct termios *termios_p, int a2, __int64 a3)
{
int i; // ebx
__int64 v5; // rbp
char **v6; // r12

if ( a2 > 1 )
{
for ( i = 1; i < a2; ++i )
{
v5 = 8LL * i;
v6 = (char **)(a3 + v5);
if ( (unsigned int)func8(termios_p, *(char **)(a3 + v5)) )
{
if ( (unsigned int)func9(termios_p, *v6, *(const char **)(a3 + v5 + 8)) )
{
if ( (unsigned int)func10((__int64)termios_p, *v6) )
fprintf(_bss_start, "%s: invalid argument `%s'\n", (const char *)program_name, *v6);
}
else
{
++i;
}
}
}
}
}

original_code:
void set_argvs( struct termios *ttyopts, int ac, char *av[] )
{
 int i;
 for (i = 1; i < ac; i++) {
  if ( check_speed(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else if ( check_special(ttyopts, av[i], av[i+1]) == 0 ) {
   i++;
   continue;
  }
  else if ( check_setting(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else {
   fprintf(stderr, "%s: invalid argument `%s'\n",
    program_name, av[i]);
  }
 }
}

canonical_original_code:
void set_argvs(struct termios *ttyopts, int ac, char *av[])
{
 int i;
 for (i = 1; i < ac; i++) {
  if ( check_speed(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else if ( check_special(ttyopts, av[i], av[i+1]) == 0 ) {
   i++;
   continue;
  }
  else if ( check_setting(ttyopts, av[i]) == 0 ) {
   continue;
  }
  else {
   fprintf(stderr, "%s: invalid argument `%s'\n",
    program_name, av[i]);
  }
 }
}

variable_types: ac int

variable_types:
av
char *[]


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

program_name = (__int64)*argv;
if ( tcgetattr(0, &v3) != -1 )
{
if ( argc <= 1 )
print_all((__int64)&v3);
else
set_argvs(&v3, argc, (__int64)argv);
exit(0);
}
perror("tcgetattr of stdin");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

program_name = (__int64)*argv;
if ( tcgetattr(0, &v3) != -1 )
{
if ( argc <= 1 )
func7((__int64)&v3);
else
func11(&v3, argc, (__int64)argv);
exit(0);
}
perror("tcgetattr of stdin");
exit(1);
}

original_code:
int main( int ac, char **av )
{
 struct termios ttyopts;
 program_name = av[0];
 if ( tcgetattr(0, &ttyopts) == -1 ) {
  perror("tcgetattr of stdin");
  exit(1);
 }
 if ( ac <= 1 ) {
  print_all(&ttyopts);
 }
 else {
  set_argvs(&ttyopts, ac, av);
 }
 exit(0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct termios ttyopts;
 program_name = av[0];
 if ( tcgetattr(0, &ttyopts) == -1 ) {
  perror("tcgetattr of stdin");
  exit(1);
 }
 if ( ac <= 1 ) {
  print_all(&ttyopts);
 }
 else {
  set_argvs(&ttyopts, ac, av);
 }
 exit(0);
}

variable_types:
av
char **

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall is_special(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
unsigned int v4; // er12

v2 = s1;
if ( !s1 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( !strcmp(v2, s2) )
break;
++v3;
v2 = (&s1)[2 * v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
unsigned int v4; // er12

v2 = s1;
if ( !s1 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( !strcmp(v2, s2) )
break;
++v3;
v2 = (&s1)[2 * v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
int is_special( char *av )
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  if ( strcmp(special_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int is_special(char *av)
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  if ( strcmp(special_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall set_special(struct termios *termios_p, int a2, char *a3)
{
if ( *a3 < 0 )
return 0xFFFFFFFFLL;
termios_p->c_cc[special_table[4 * a2]] = *a3;
if ( tcsetattr(0, 0, termios_p) == -1 )
{
perror("tcsetattr");
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(struct termios *termios_p, int a2, char *a3)
{
if ( *a3 < 0 )
return 0xFFFFFFFFLL;
termios_p->c_cc[special_table[4 * a2]] = *a3;
if ( tcsetattr(0, 0, termios_p) == -1 )
{
perror("tcsetattr");
exit(1);
}
return 0LL;
}

original_code:
int set_special( struct termios *ttyopts, int i, char *c)
{
 if ( (((*c) & ~0x7f) == 0) == 0 ) {
  return -1;
 }
 ttyopts->c_cc[special_table[i].constant] = *c;
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
 return 0;
}

canonical_original_code:
int set_special(struct termios *ttyopts, int i, char *c)
{
 if ( (((*c) & ~0x7f) == 0) == 0 ) {
  return -1;
 }
 ttyopts->c_cc[special_table[i].constant] = *c;
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
 return 0;
}

variable_types:
c
char *


decompiled_code:
int __fastcall print_character(int c)
{
int result; // eax

result = (*__ctype_b_loc())[c];
if ( (result & 0x4000) != 0 )
return putchar(c);
if ( c == 127 )
return printf("^?");
if ( (result & 2) != 0 )
result = printf("^%c", (unsigned int)(c + 64));
return result;
}

canonical_decompiled_code:
int __fastcall func14(int c)
{
int result; // eax

result = (*__ctype_b_loc())[c];
if ( (result & 0x4000) != 0 )
return putchar(c);
if ( c == 127 )
return printf("^?");
if ( (result & 2) != 0 )
result = printf("^%c", (unsigned int)(c + 64));
return result;
}

original_code:
void print_character( int c )
{
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint) != 0 ) {
  putchar(c);
 }
 else if ( c == 127 ) {
  printf("^?");
 }
 else if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _IScntrl) != 0 ) {
  printf("^%c", c - 1 + 'A');
 }
}

canonical_original_code:
void print_character(int c)
{
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint) != 0 ) {
  putchar(c);
 }
 else if ( c == 127 ) {
  printf("^?");
 }
 else if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _IScntrl) != 0 ) {
  printf("^%c", c - 1 + 'A');
 }
}

variable_types: c int


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

v2 = s1;
if ( s1 )
{
v3 = special_table;
do
{
printf(v2);
printf(" = ");
print_character(*(unsigned __int8 *)(a1 + (unsigned int)*v3 + 17));
printf("; ");
v3 += 4;
v2 = (const char *)*((_QWORD *)v3 + 1);
}
while ( v2 );
}
return putchar(10);
}

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

v2 = s1;
if ( s1 )
{
v3 = special_table;
do
{
printf(v2);
printf(" = ");
func14(*(unsigned __int8 *)(a1 + (unsigned int)*v3 + 17));
printf("; ");
v3 += 4;
v2 = (const char *)*((_QWORD *)v3 + 1);
}
while ( v2 );
}
return putchar(10);
}

original_code:
void print_special( struct termios *ttyopts )
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  printf(special_table[i].name);
  printf(" = ");
  print_character(ttyopts->c_cc[special_table[i].constant]);
  printf("; ");
 }
 printf("\n");
}

canonical_original_code:
void print_special(struct termios *ttyopts)
{
 int i;
 for (i = 0; special_table[i].name; i++) {
  printf(special_table[i].name);
  printf(" = ");
  print_character(ttyopts->c_cc[special_table[i].constant]);
  printf("; ");
 }
 printf("\n");
}


decompiled_code:
__int64 __fastcall is_setting(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
unsigned int v4; // er12

v2 = off_4040E8;
if ( !off_4040E8 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( !strcmp(v2, s2) )
break;
++v3;
v2 = (&off_4040E8)[4 * v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
unsigned int v4; // er12

v2 = off_4040E8;
if ( !off_4040E8 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( !strcmp(v2, s2) )
break;
++v3;
v2 = (&off_4040E8)[4 * v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
int is_setting( char *av )
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  if ( strcmp(setting_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int is_setting(char *av)
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  if ( strcmp(setting_table[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall set_setting(__int64 a1, int a2)
{
return (*((__int64 (__fastcall **)(char *, __int64))&setting_table + 4 * a2 + 3))(
(char *)&setting_table + 32 * a2,
a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2)
{
return (*((__int64 (__fastcall **)(char *, __int64))&setting_table + 4 * a2 + 3))(
(char *)&setting_table + 32 * a2,
a1);
}

original_code:
void set_setting( struct termios *ttyopts, int i, int on )
{
 setting_table[i].setter(&setting_table[i], ttyopts, on);
}

canonical_original_code:
void set_setting(struct termios *ttyopts, int i, int on)
{
 setting_table[i].setter(&setting_table[i], ttyopts, on);
}


decompiled_code:
int __fastcall s_opt(_DWORD *a1, const struct termios *a2, int *a3, int a4)
{
int v4; // eax
int result; // eax

if ( a4 == 1 )
v4 = *a1 | *a3;
else
v4 = *a3 & ~*a1;
*a3 = v4;
result = tcsetattr(0, 0, a2);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(_DWORD *a1, const struct termios *a2, int *a3, int a4)
{
int v4; // eax
int result; // eax

if ( a4 == 1 )
v4 = *a1 | *a3;
else
v4 = *a3 & ~*a1;
*a3 = v4;
result = tcsetattr(0, 0, a2);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

original_code:
void s_opt( struct option *row,
   struct termios *ttyopts,
   tcflag_t *flag_p,
   int on )
{
 if ( on == 1 )
  *flag_p |= row->constant;
 else
  *flag_p &= ~(row->constant);
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}

canonical_original_code:
void s_opt(struct option *row, struct termios *ttyopts, unsigned int *flag_p, int on)
{
 if ( on == 1 )
  *flag_p |= row->constant;
 else
  *flag_p &= ~(row->constant);
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}

variable_types: struct option { unsigned int constant; char *name; void (*printer)(struct option *, struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *); void (*setter)(struct option *, struct termios *, int); } *

variable_types:
ttyopts
struct termios *

user_defined_types: struct option { unsigned int constant; char *name; void (*printer)(struct option *, struct termios *); void (*setter)(struct option *, struct termios *, int); }


decompiled_code:
int __fastcall s_in(_DWORD *a1, struct termios *a2, int a3)
{
return s_opt(a1, a2, (int *)a2, a3);
}

canonical_decompiled_code:
int __fastcall func19(_DWORD *a1, struct termios *a2, int a3)
{
return func18(a1, a2, (int *)a2, a3);
}

original_code:
void s_in( struct option *row, struct termios *ttyopts, int on )
{
 s_opt(row, ttyopts, &ttyopts->c_iflag, on);
}

canonical_original_code:
void s_in(struct option *row, struct termios *ttyopts, int on)
{
 s_opt(row, ttyopts, &ttyopts->c_iflag, on);
}


decompiled_code:
int __fastcall s_out(_DWORD *a1, const struct termios *a2, int a3)
{
return s_opt(a1, a2, (int *)&a2->c_oflag, a3);
}

canonical_decompiled_code:
int __fastcall func20(_DWORD *a1, const struct termios *a2, int a3)
{
return func18(a1, a2, (int *)&a2->c_oflag, a3);
}

original_code:
void s_out( struct option *row, struct termios *ttyopts, int on )
{
 s_opt(row, ttyopts, &ttyopts->c_oflag, on);
}

canonical_original_code:
void s_out(struct option *row, struct termios *ttyopts, int on)
{
 s_opt(row, ttyopts, &ttyopts->c_oflag, on);
}


decompiled_code:
int __fastcall s_local(_DWORD *a1, const struct termios *a2, int a3)
{
return s_opt(a1, a2, (int *)&a2->c_lflag, a3);
}

canonical_decompiled_code:
int __fastcall func21(_DWORD *a1, const struct termios *a2, int a3)
{
return func18(a1, a2, (int *)&a2->c_lflag, a3);
}

original_code:
void s_local( struct option *row, struct termios *ttyopts, int on )
{
 s_opt(row, ttyopts, &ttyopts->c_lflag, on);
}

canonical_original_code:
void s_local(struct option *row, struct termios *ttyopts, int on)
{
 s_opt(row, ttyopts, &ttyopts->c_lflag, on);
}


decompiled_code:
int __fastcall print_setting(__int64 a1)
{
void (__fastcall **v1)(void *, _QWORD); // rbx

if ( off_4040E8 )
{
v1 = (void (__fastcall **)(void *, _QWORD))&setting_table;
do
{
v1[2](v1, a1);
putchar(32);
v1 += 4;
}
while ( v1[1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func22(__int64 a1)
{
void (__fastcall **v1)(void *, _QWORD); // rbx

if ( off_4040E8 )
{
v1 = (void (__fastcall **)(void *, _QWORD))&setting_table;
do
{
v1[2](v1, a1);
putchar(32);
v1 += 4;
}
while ( v1[1] );
}
return putchar(10);
}

original_code:
void print_setting( struct termios *ttyopts )
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  setting_table[i].printer(&setting_table[i], ttyopts);
  printf(" ");
 }
 printf("\n");
}

canonical_original_code:
void print_setting(struct termios *ttyopts)
{
 int i;
 for ( i = 0; setting_table[i].name; i++ ) {
  setting_table[i].printer(&setting_table[i], ttyopts);
  printf(" ");
 }
 printf("\n");
}


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

if ( (*(_DWORD *)a1 & a2) != 0 )
result = printf(*(const char **)(a1 + 8));
else
result = printf("-%s", *(const char **)(a1 + 8));
return result;
}

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

if ( (*(_DWORD *)a1 & a2) != 0 )
result = printf(*(const char **)(a1 + 8));
else
result = printf("-%s", *(const char **)(a1 + 8));
return result;
}

original_code:
void p_opt ( struct option *row, int flag)
{
 if ( flag & row->constant )
  printf(row->name);
 else
  printf("-%s", row->name);
}

canonical_original_code:
void p_opt(struct option *row, int flag)
{
 if ( flag & row->constant )
  printf(row->name);
 else
  printf("-%s", row->name);
}

variable_types: flag int


decompiled_code:
int __fastcall p_in(__int64 a1, int *a2)
{
return p_opt(a1, *a2);
}

canonical_decompiled_code:
int __fastcall func24(__int64 a1, int *a2)
{
return func23(a1, *a2);
}

original_code:
void p_in( struct option *row, struct termios *ttyopts )
{
 p_opt(row, ttyopts->c_iflag);
}

canonical_original_code:
void p_in(struct option *row, struct termios *ttyopts)
{
 p_opt(row, ttyopts->c_iflag);
}


decompiled_code:
int __fastcall p_out(__int64 a1, __int64 a2)
{
return p_opt(a1, *(_DWORD *)(a2 + 4));
}

canonical_decompiled_code:
int __fastcall func25(__int64 a1, __int64 a2)
{
return func23(a1, *(_DWORD *)(a2 + 4));
}

original_code:
void p_out( struct option *row, struct termios *ttyopts )
{
 p_opt(row, ttyopts->c_oflag);
}

canonical_original_code:
void p_out(struct option *row, struct termios *ttyopts)
{
 p_opt(row, ttyopts->c_oflag);
}


decompiled_code:
int __fastcall p_local(__int64 a1, __int64 a2)
{
return p_opt(a1, *(_DWORD *)(a2 + 12));
}

canonical_decompiled_code:
int __fastcall func26(__int64 a1, __int64 a2)
{
return func23(a1, *(_DWORD *)(a2 + 12));
}

original_code:
void p_local( struct option *row, struct termios *ttyopts )
{
 p_opt(row, ttyopts->c_lflag);
}

canonical_original_code:
void p_local(struct option *row, struct termios *ttyopts)
{
 p_opt(row, ttyopts->c_lflag);
}


decompiled_code:
__int64 __fastcall is_speed(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
unsigned int v4; // er12

v2 = off_4041E8;
if ( !off_4041E8 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( !strcmp(v2, s2) )
break;
++v3;
v2 = (&off_4041E8)[2 * v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func27(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
unsigned int v4; // er12

v2 = off_4041E8;
if ( !off_4041E8 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( !strcmp(v2, s2) )
break;
++v3;
v2 = (&off_4041E8)[2 * v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
int is_speed( char *av )
{
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( strcmp(baud[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int is_speed(char *av)
{
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( strcmp(baud[i].name, av) == 0 ) {
   return i;
  }
 }
 return -1;
}


decompiled_code:
int __fastcall set_speed(struct termios *termios_p, int a2)
{
int result; // eax

if ( cfsetospeed(termios_p, baud[4 * a2]) == -1 )
{
perror("cfsetospeed");
exit(1);
}
result = tcsetattr(0, 0, termios_p);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func28(struct termios *termios_p, int a2)
{
int result; // eax

if ( cfsetospeed(termios_p, baud[4 * a2]) == -1 )
{
perror("cfsetospeed");
exit(1);
}
result = tcsetattr(0, 0, termios_p);
if ( result == -1 )
{
perror("tcsetattr");
exit(1);
}
return result;
}

original_code:
void set_speed( struct termios *ttyopts, int i )
{
 if ( cfsetospeed(ttyopts, baud[i].constant) == -1 ) {
  perror("cfsetospeed");
  exit(1);
 }
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}

canonical_original_code:
void set_speed(struct termios *ttyopts, int i)
{
 if ( cfsetospeed(ttyopts, baud[i].constant) == -1 ) {
  perror("cfsetospeed");
  exit(1);
 }
 if (tcsetattr(0, 0, ttyopts) == -1) {
  perror("tcsetattr");
  exit(1);
 }
}


decompiled_code:
speed_t __fastcall print_speed(const struct termios *a1)
{
speed_t result; // eax
const char *v2; // rsi
speed_t v3; // ebp
int *v4; // rbx

result = cfgetospeed(a1);
v2 = off_4041E8;
if ( off_4041E8 )
{
v3 = result;
v4 = baud;
do
{
if ( v3 == *v4 )
result = printf("speed %s baud;\n", v2);
v4 += 4;
v2 = (const char *)*((_QWORD *)v4 + 1);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
speed_t __fastcall func29(const struct termios *a1)
{
speed_t result; // eax
const char *v2; // rsi
speed_t v3; // ebp
int *v4; // rbx

result = cfgetospeed(a1);
v2 = off_4041E8;
if ( off_4041E8 )
{
v3 = result;
v4 = baud;
do
{
if ( v3 == *v4 )
result = printf("speed %s baud;\n", v2);
v4 += 4;
v2 = (const char *)*((_QWORD *)v4 + 1);
}
while ( v2 );
}
return result;
}

original_code:
void print_speed( struct termios *ttyopts )
{
 int cfospeed = cfgetospeed(ttyopts);
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( cfospeed == baud[i].constant ) {
   printf("speed %s baud;\n", baud[i].name);
  }
 }
}

canonical_original_code:
void print_speed(struct termios *ttyopts)
{
 int cfospeed = cfgetospeed(ttyopts);
 int i;
 for ( i = 0; baud[i].name; i++ ) {
  if ( cfospeed == baud[i].constant ) {
   printf("speed %s baud;\n", baud[i].name);
  }
 }
}

variable_types: cfospeed int


contar

decompiled_code:
__int64 __fastcall contar(__int64 a1)
{
__int64 result; // rax
int v2; // ebp

result = 0LL;
if ( a1 )
{
v2 = contar(*(_QWORD *)(a1 + 8));
result = v2 + (unsigned int)contar(*(_QWORD *)(a1 + 16)) + 1;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
v2 = func0(*(_QWORD *)(a1 + 8));
result = v2 + (unsigned int)func0(*(_QWORD *)(a1 + 16)) + 1;
}
return result;
}

original_code:
int contar(Nodo* raiz)
{
    if(raiz==((void *)0))
    {
        return 0;
    }
    return 1+contar(raiz->der)+contar(raiz->izq);
}

canonical_original_code:
int contar(struct NodoArbol *raiz)
{
    if(raiz==((void *)0))
    {
        return 0;
    }
    return 1+contar(raiz->der)+contar(raiz->izq);
}

variable_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


decompiled_code:
__int64 __fastcall insertar_ordenado(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
unsigned int v6; // er13
__int64 v7; // rax
__int64 v8; // rax

result = a4;
if ( (int)(a2 - a1) > 2 )
{
v6 = (int)(a2 - a1) / 2 + a1;
v7 = insertar_elemento(a4, *(unsigned int *)(a3 + 4LL * (int)v6));
v8 = insertar_ordenado(a1, v6, a3, v7);
result = insertar_ordenado(v6, a2, a3, v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
unsigned int v6; // er13
__int64 v7; // rax
__int64 v8; // rax

result = a4;
if ( (int)(a2 - a1) > 2 )
{
v6 = (int)(a2 - a1) / 2 + a1;
v7 = insertar_elemento(a4, *(unsigned int *)(a3 + 4LL * (int)v6));
v8 = func1(a1, v6, a3, v7);
result = func1(v6, a2, a3, v8);
}
return result;
}

original_code:
Nodo* insertar_ordenado(int inicio,int final,int *datos,Nodo* raiz)
{
    int mitad;
    mitad=(final-inicio)/2+inicio;
    if(final-inicio>2)
    {
        raiz=insertar_elemento(raiz,datos[mitad]);
        raiz=insertar_ordenado(inicio,mitad,datos,raiz);
        raiz=insertar_ordenado(mitad,final,datos,raiz);
    }
    return raiz;
}

canonical_original_code:
struct NodoArbol *insertar_ordenado(int inicio, int final, int *datos, struct NodoArbol *raiz)
{
    int mitad;
    mitad=(final-inicio)/2+inicio;
    if(final-inicio>2)
    {
        raiz=insertar_elemento(raiz,datos[mitad]);
        raiz=insertar_ordenado(inicio,mitad,datos,raiz);
        raiz=insertar_ordenado(mitad,final,datos,raiz);
    }
    return raiz;
}

variable_types: inicio int

variable_types: final int

variable_types:
datos
int *

variable_types:
raiz
struct NodoArbol *

variable_types: mitad int

return_type: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


decompiled_code:
int __fastcall inicializar_cola(const char *a1, char a2)
{
int v2; // eax
int result; // eax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
fwrite("\nError creando token de cola.\n\n", 1uLL, 0x1FuLL, stderr);
result = -1;
}
else
{
result = msgget(v2, 896);
if ( result < 0 )
{
fwrite(&unk_938, 1uLL, 0x29uLL, stderr);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, char a2)
{
int v2; // eax
int result; // eax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
fwrite("\nError creando token de cola.\n\n", 1uLL, 0x1FuLL, stderr);
result = -1;
}
else
{
result = msgget(v2, 896);
if ( result < 0 )
{
fwrite(&unk_938, 1uLL, 0x29uLL, stderr);
result = -1;
}
}
return result;
}

original_code:
int inicializar_cola(char nombre[], char id)
{
    int cola;
    key_t llave = ftok(nombre, id);
    if(llave < 0)
    {
        fprintf(stderr, "\nError creando token de cola.\n\n");
        return -1;
    }
    cola = msgget(llave, 0600 | 01000);
    if(cola < 0)
    {
        fprintf(stderr, "\nError durante la creación de la cola.\n\n");
        return -1;
    }
    return cola;
}

canonical_original_code:
int inicializar_cola(char nombre[], char id)
{
    int cola;
    int llave = ftok(nombre, id);
    if(llave < 0)
    {
        fprintf(stderr, "\nError creando token de cola.\n\n");
        return -1;
    }
    cola = msgget(llave, 0600 | 01000);
    if(cola < 0)
    {
        fprintf(stderr, "\nError durante la creación de la cola.\n\n");
        return -1;
    }
    return cola;
}

variable_types:
nombre
char []

variable_types: id char

variable_types: cola int

variable_types: llave int


decompiled_code:
_BOOL8 __fastcall es_cola_correcta(int a1)
{
return a1 >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
return a1 >= 0;
}

original_code:
int es_cola_correcta(int cola)
{
    return cola >= 0;
}


decompiled_code:
int __fastcall inicializar_memoria_compartida(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
result = -1;
}
else
{
result = shmget(v2, 4uLL, 896);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_9B0, (unsigned int)*v5);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
result = -1;
}
else
{
result = shmget(v2, 4uLL, 896);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_9B0, (unsigned int)*v5);
result = -1;
}
}
return result;
}

original_code:
int inicializar_memoria_compartida(char nombre[], char id)
{
    int memoria;
    key_t keymemo=ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    memoria = shmget(keymemo, sizeof(int), 01000 | 0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    return memoria;
}

canonical_original_code:
int inicializar_memoria_compartida(char nombre[], char id)
{
    int memoria;
    int keymemo = ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    memoria = shmget(keymemo, sizeof(int), 01000 | 0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        return -1;
    }
    return memoria;
}

variable_types: memoria int

variable_types: keymemo int


decompiled_code:
_BOOL8 __fastcall es_memoria_correcta(int a1)
{
return a1 >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return a1 >= 0;
}

original_code:
int es_memoria_correcta(int memoria_compartida)
{
    return memoria_compartida >= 0;
}


decompiled_code:
_BOOL8 __fastcall es_semaforo_correcto(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return a1 != 0;
}

original_code:
int es_semaforo_correcto(sem_t *semaforo)
{
    return semaforo != ((void *)0);
}

canonical_original_code:
int es_semaforo_correcto(union sem_t *semaforo)
{
    return semaforo != ((void *)0);
}

variable_types: union sem_t { char __size[32]; long __align; } *


decompiled_code:
void *__fastcall inicializar_clientes(int a1)
{
return malloc(40LL * a1);
}

canonical_decompiled_code:
void *__fastcall func5(int a1)
{
return malloc(40LL * a1);
}

original_code:
int *inicializar_clientes(int numero_clientes)
{
    size_t tamanyo_memoria = 10 * sizeof(pid_t) * (size_t)numero_clientes;
    return (int *)malloc(tamanyo_memoria);
}

canonical_original_code:
int *inicializar_clientes(int numero_clientes)
{
    unsigned long tamanyo_memoria = 10 * sizeof(pid_t) * (size_t)numero_clientes;
    return (int *)malloc(tamanyo_memoria);
}

return_type: int *


decompiled_code:
_BOOL8 __fastcall son_clientes_correctos(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return a1 != 0;
}

original_code:
int son_clientes_correctos(int *clientes)
{
    return clientes != ((void *)0);
}

variable_types:
clientes
int *


decompiled_code:
void *__fastcall get_inicio_memoria_compartida(int a1)
{
return shmat(a1, 0LL, 0);
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
return shmat(a1, 0LL, 0);
}

original_code:
int *get_inicio_memoria_compartida(int memoria_compartida)
{
    return (int *)shmat(memoria_compartida, 0, 0);
}


decompiled_code:
_BOOL8 __fastcall es_arbol_correcto(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1)
{
return a1 != 0;
}

original_code:
int es_arbol_correcto(Nodo *arbol)
{
    return arbol != ((void *)0);
}

canonical_original_code:
int es_arbol_correcto(struct NodoArbol *arbol)
{
    return arbol != ((void *)0);
}

user_defined_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; }


decompiled_code:
int __fastcall borrar_cola(int a1)
{
return msgctl(a1, 0, 0LL);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return msgctl(a1, 0, 0LL);
}

original_code:
void borrar_cola(int cola)
{
    msgctl(cola, 0, 0);
}


decompiled_code:
void __fastcall cerrar_clientes(__int64 a1, int a2)
{
__pid_t *v2; // rbx

if ( son_clientes_correctos(a1) )
{
if ( a2 > 0 )
{
v2 = (__pid_t *)a1;
do
kill(*v2++, 2);
while ( v2 != (__pid_t *)(a1 + 4LL * (unsigned int)(a2 - 1) + 4) );
}
free(vector_clientes);
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2)
{
__pid_t *v2; // rbx

if ( func6(a1) )
{
if ( a2 > 0 )
{
v2 = (__pid_t *)a1;
do
kill(*v2++, 2);
while ( v2 != (__pid_t *)(a1 + 4LL * (unsigned int)(a2 - 1) + 4) );
}
free(vector_clientes);
}
}

original_code:
void cerrar_clientes(int *clientes, int numero_clientes)
{
    if (!son_clientes_correctos(clientes))
        return;
    int i;
    for(i = 0; i < numero_clientes; i++)
    {
        kill(clientes[i], 2);
    }
    free(vector_clientes);
}

variable_types: i int


decompiled_code:
int __fastcall cerrar_semaforo(sem_t *sem, char *name)
{
int result; // eax

result = es_semaforo_correcto((__int64)sem);
if ( result )
{
sem_close(sem);
result = sem_unlink(name);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(sem_t *sem, char *name)
{
int result; // eax

result = func4((__int64)sem);
if ( result )
{
sem_close(sem);
result = sem_unlink(name);
}
return result;
}

original_code:
void cerrar_semaforo(sem_t *semaforo, char nombre[])
{
    if (!es_semaforo_correcto(semaforo))
        return;
    sem_close(semaforo);
    sem_unlink(nombre);
}

canonical_original_code:
void cerrar_semaforo(union sem_t *semaforo, char nombre[])
{
    if (!es_semaforo_correcto(semaforo))
        return;
    sem_close(semaforo);
    sem_unlink(nombre);
}

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
int __fastcall liberar_memoria_compartida(int shmid)
{
int result; // eax

result = es_memoria_correcta(shmid);
if ( result )
result = shmctl(shmid, 0, 0LL);
return result;
}

canonical_decompiled_code:
int __fastcall func12(int shmid)
{
int result; // eax

result = func3(shmid);
if ( result )
result = shmctl(shmid, 0, 0LL);
return result;
}

original_code:
void liberar_memoria_compartida(int memoria_compartida)
{
    if (!es_memoria_correcta(memoria_compartida))
        return;
    shmctl(memoria_compartida, 0, 0);
}


decompiled_code:
int __fastcall registrando_en_logfile(int a1)
{
struct tm *v1; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v1 = gmtime(&timer);
result = strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v1);
switch ( a1 )
{
case 2:
return fprintf(
logfile,
aSClienteLdOper,
s,
peticion,
*((unsigned int *)&peticion + 2),
*(unsigned int *)dato,
respuesta[2]);
case 3:
return fprintf(logfile, "\n******************%s SERVIDOR CERRADO******************\n\n", s);
case 1:
result = fprintf(
logfile,
"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",
s,
(unsigned int)max_clientes);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
struct tm *v1; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v1 = gmtime(&timer);
result = strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v1);
switch ( a1 )
{
case 2:
return fprintf(
logfile,
aSClienteLdOper,
s,
peticion,
*((unsigned int *)&peticion + 2),
*(unsigned int *)dato,
respuesta[2]);
case 3:
return fprintf(logfile, "\n******************%s SERVIDOR CERRADO******************\n\n", s);
case 1:
result = fprintf(
logfile,
"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",
s,
(unsigned int)max_clientes);
break;
}
return result;
}

original_code:
void registrando_en_logfile(int tipo_operacion)
{
    char buff[20];
    struct tm *sTm;
    time_t now = time (0);
    sTm = gmtime (&now);
    strftime (buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", sTm);
    switch(tipo_operacion)
    {
        case 1:
        fprintf(logfile,"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",buff,max_clientes);
        break;
        case 2:
        fprintf(logfile,"%s: Cliente: %ld -> Operación: %d -> Dato: %d -> Respuesta del servidor: %d   \n", buff, peticion.tipo,peticion.codigo_operacion, *dato, respuesta.codigo_error);
        break;
        case 3:
                fprintf(logfile,"\n******************%s SERVIDOR CERRADO******************\n\n",buff);
        break;
    }
    return;
}

canonical_original_code:
void registrando_en_logfile(int tipo_operacion)
{
    char buff[20];
    struct tm *sTm;
    long now = time (0);
    sTm = gmtime (&now);
    strftime (buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", sTm);
    switch(tipo_operacion)
    {
        case 1:
        fprintf(logfile,"\n\n*****%s SERVIDOR INICIADO CON %d CLIENTES MAXIMOS*****\n",buff,max_clientes);
        break;
        case 2:
        fprintf(logfile,"%s: Cliente: %ld -> Operación: %d -> Dato: %d -> Respuesta del servidor: %d   \n", buff, peticion.tipo,peticion.codigo_operacion, *dato, respuesta.codigo_error);
        break;
        case 3:
                fprintf(logfile,"\n******************%s SERVIDOR CERRADO******************\n\n",buff);
        break;
    }
    return;
}

variable_types:
buff
char [20]

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

variable_types: now long


decompiled_code:
_BOOL8 preparar_entorno()
{
_BOOL4 v0; // ebx

puts("Creando colas...");
Q1 = inicializar_cola("/bin", 51);
if ( es_cola_correcta(Q1) )
{
Q2 = inicializar_cola("/bin", 52);
v0 = es_cola_correcta(Q2);
if ( v0 )
{
Q_clientes_activos = inicializar_cola("/bin", 55);
v0 = es_cola_correcta(Q_clientes_activos);
if ( v0 )
{
puts("Creando memoria compartida...");
memo = inicializar_memoria_compartida("/bin", 53);
v0 = es_memoria_correcta(memo);
if ( v0 )
{
puts("Creando semaforos...");
mutex = inicializar_semaforo("/semMUTEX", 1u);
v0 = es_semaforo_correcto((__int64)mutex);
if ( v0 )
{
s1 = inicializar_semaforo("/semS1", max_clientes);
v0 = es_semaforo_correcto((__int64)s1);
if ( v0 )
{
sclientes = inicializar_semaforo("/semSCLIENTES", 1u);
v0 = es_semaforo_correcto((__int64)sclientes);
if ( v0 )
{
vector_clientes = inicializar_clientes(max_clientes);
v0 = son_clientes_correctos((__int64)vector_clientes);
if ( v0 )
{
puts("Cargando datos del arbol desde el fichero...");
raizarbol = cargar_ordenado(raizarbol);
v0 = es_arbol_correcto(raizarbol);
if ( v0 )
{
signal(2, cerrar_programa);
dato = (__int64)get_inicio_memoria_compartida(memo);
puts("Creando fichero para guardar el log del sistema...");
logfile = fopen("servidor.log", "a");
if ( logfile )
{
registrando_en_logfile(1);
v0 = 1;
}
else
{
puts(asc_CB0);
v0 = 0;
}
}
else
{
puts(&byte_C50);
}
}
else
{
puts("\nError inicializando espacio de clientes.\n");
}
}
else
{
puts("\nError inicializando semaforo SCLIENTES.\n");
}
}
else
{
puts("\nError inicializando semaforo S1.\n");
}
}
else
{
puts("\nError inicializando semaforo MutEx.\n");
}
}
else
{
puts("\nNo se pudo inicializar la memoria compartida.\n");
}
}
else
{
puts("\nNo se pudo crear la cola clientes-activos.\n");
}
}
else
{
puts("\nNo se pudo crear la cola 2.\n");
}
}
else
{
v0 = 0;
puts("\nNo se pudo crear la cola 1.\n");
}
return v0;
}

canonical_decompiled_code:
_BOOL8 func14()
{
_BOOL4 v0; // ebx

puts("Creando colas...");
Q1 = func0("/bin", 51);
if ( func1(Q1) )
{
Q2 = func0("/bin", 52);
v0 = func1(Q2);
if ( v0 )
{
Q_clientes_activos = func0("/bin", 55);
v0 = func1(Q_clientes_activos);
if ( v0 )
{
puts("Creando memoria compartida...");
memo = func2("/bin", 53);
v0 = func3(memo);
if ( v0 )
{
puts("Creando semaforos...");
mutex = inicializar_semaforo("/semMUTEX", 1u);
v0 = func4((__int64)mutex);
if ( v0 )
{
s1 = inicializar_semaforo("/semS1", max_clientes);
v0 = func4((__int64)s1);
if ( v0 )
{
sclientes = inicializar_semaforo("/semSCLIENTES", 1u);
v0 = func4((__int64)sclientes);
if ( v0 )
{
vector_clientes = func5(max_clientes);
v0 = func6((__int64)vector_clientes);
if ( v0 )
{
puts("Cargando datos del arbol desde el fichero...");
raizarbol = cargar_ordenado(raizarbol);
v0 = func8(raizarbol);
if ( v0 )
{
signal(2, cerrar_programa);
dato = (__int64)func7(memo);
puts("Creando fichero para guardar el log del sistema...");
logfile = fopen("servidor.log", "a");
if ( logfile )
{
func13(1);
v0 = 1;
}
else
{
puts(asc_CB0);
v0 = 0;
}
}
else
{
puts(&byte_C50);
}
}
else
{
puts("\nError inicializando espacio de clientes.\n");
}
}
else
{
puts("\nError inicializando semaforo SCLIENTES.\n");
}
}
else
{
puts("\nError inicializando semaforo S1.\n");
}
}
else
{
puts("\nError inicializando semaforo MutEx.\n");
}
}
else
{
puts("\nNo se pudo inicializar la memoria compartida.\n");
}
}
else
{
puts("\nNo se pudo crear la cola clientes-activos.\n");
}
}
else
{
puts("\nNo se pudo crear la cola 2.\n");
}
}
else
{
v0 = 0;
puts("\nNo se pudo crear la cola 1.\n");
}
return v0;
}

original_code:
int preparar_entorno()
{
    printf("Creando colas...\n");
    Q1 = inicializar_cola("/bin", '3');
    if(!es_cola_correcta(Q1))
    {
        printf("\nNo se pudo crear la cola 1.\n\n");
        return 0;
    }
    Q2 = inicializar_cola("/bin", '4');
    if (!es_cola_correcta(Q2))
    {
        printf("\nNo se pudo crear la cola 2.\n\n");
        return 0;
    }
    Q_clientes_activos = inicializar_cola("/bin", '7');
    if (!es_cola_correcta(Q_clientes_activos))
    {
        printf("\nNo se pudo crear la cola clientes-activos.\n\n");
        return 0;
    }
    printf("Creando memoria compartida...\n");
    memo = inicializar_memoria_compartida("/bin", '5');
    if(!es_memoria_correcta(memo))
    {
        printf("\nNo se pudo inicializar la memoria compartida.\n\n");
        return 0;
    }
    printf("Creando semaforos...\n");
    mutex = inicializar_semaforo("/semMUTEX", 1);
    if (!es_semaforo_correcto(mutex))
    {
        printf("\nError inicializando semaforo MutEx.\n\n");
        return 0;
    }
    s1 = inicializar_semaforo("/semS1", max_clientes);
    if(!es_semaforo_correcto(s1))
    {
        printf("\nError inicializando semaforo S1.\n\n");
        return 0;
    }
    sclientes = inicializar_semaforo("/semSCLIENTES", 1);
    if(!es_semaforo_correcto(sclientes))
    {
        printf("\nError inicializando semaforo SCLIENTES.\n\n");
        return 0;
    }
    vector_clientes = inicializar_clientes(max_clientes);
    if (!son_clientes_correctos(vector_clientes))
    {
        printf("\nError inicializando espacio de clientes.\n\n");
        return 0;
    }
    printf("Cargando datos del arbol desde el fichero...\n");
    raizarbol=cargar_ordenado(raizarbol);
    if(!es_arbol_correcto(raizarbol))
    {
        printf("¡Error! No se pudo cargar el arbol.\n");
        return 0;
    }
    signal (2,cerrar_programa);
    dato = get_inicio_memoria_compartida(memo);
    printf("Creando fichero para guardar el log del sistema...\n");
    logfile=fopen("servidor.log","a");
    if(logfile==((void *)0))
    {
        printf("\nError en la apertura/creación del log.\n\n");
        return 0;
    }
    registrando_en_logfile(1);
    return 1;
}


decompiled_code:
void __noreturn cerrar_programa()
{
puts("Cerrando el control de clientes inactivos...");
puts("Guardando datos del arbol en el fichero...");
guardar_fichero(raizarbol);
puts("Cerrando log del servidor...");
registrando_en_logfile(3);
fclose(logfile);
puts("Cerrando clientes...");
cerrar_clientes((__int64)vector_clientes, num_clientes);
puts("Cerrando colas...");
borrar_cola(Q1);
borrar_cola(Q2);
borrar_cola(Q_clientes_activos);
puts("Cerrando semaforos...");
cerrar_semaforo(mutex, "/semMUTEX");
cerrar_semaforo(s1, "/semS1");
cerrar_semaforo(sclientes, "/semSCLIENTES");
puts("Cerrando memoria compartida...");
liberar_memoria_compartida(memo);
exit(0);
}

canonical_decompiled_code:
void __noreturn func15()
{
puts("Cerrando el control de clientes inactivos...");
puts("Guardando datos del arbol en el fichero...");
guardar_fichero(raizarbol);
puts("Cerrando log del servidor...");
func13(3);
fclose(logfile);
puts("Cerrando clientes...");
func10((__int64)vector_clientes, num_clientes);
puts("Cerrando colas...");
func9(Q1);
func9(Q2);
func9(Q_clientes_activos);
puts("Cerrando semaforos...");
func11(mutex, "/semMUTEX");
func11(s1, "/semS1");
func11(sclientes, "/semSCLIENTES");
puts("Cerrando memoria compartida...");
func12(memo);
exit(0);
}

original_code:
void cerrar_programa(int sig)
{
    printf("Cerrando el control de clientes inactivos...\n");
    printf("Guardando datos del arbol en el fichero...\n");
    guardar_fichero(raizarbol);
    printf("Cerrando log del servidor...\n");
    registrando_en_logfile(3);
    fclose(logfile);
    printf("Cerrando clientes...\n");
    cerrar_clientes(vector_clientes, num_clientes);
    printf("Cerrando colas...\n");
    borrar_cola(Q1);
    borrar_cola(Q2);
    borrar_cola(Q_clientes_activos);
    printf("Cerrando semaforos...\n");
    cerrar_semaforo(mutex, "/semMUTEX");
    cerrar_semaforo(s1, "/semS1");
    cerrar_semaforo(sclientes,"/semSCLIENTES");
    printf("Cerrando memoria compartida...\n");
    liberar_memoria_compartida(memo);
    exit(0);
}

variable_types: sig int