decompiled_code:
void __fastcall tcpros_parse_client_request(__int64 a1, int a2, char *a3, char *a4, char *a5, char *a6, _BYTE *a7, _BYTE *a8)
{
const char *v11; // rbp
int v12; // eax
const char *v13; // rbp
__int64 v14; // rbx
char v15; // al
char v16; // al

v11 = (const char *)(a1 + 4);
if ( a2 > 4 )
{
do
{
v12 = utils_get_int_from_bytes(v11, 4LL);
v13 = v11 + 4;
if ( v12 > 511 )
break;
v14 = v12;
strncpy(tcp_package, v13, v12);
tcp_package[v14] = 0;
v11 = &v13[v14];
_isoc99_sscanf(
tcp_package,
"%[^'=']=%s",
(unsigned int)((_DWORD)tcp_package + 512),
(unsigned int)((_DWORD)tcp_package + 1024));
printf(
"[tcpros] name: %s value: %s\n",
(const char *)(unsigned int)((_DWORD)tcp_package + 512),
(const char *)(unsigned int)((_DWORD)tcp_package + 1024));
if ( a3 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "callerid") )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a4 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "service") )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a5 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "md5sum") )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a6 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "type") )
{
strcpy(a6, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a7 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "persistent") )
{
v15 = TRUE;
if ( strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 1024), "1") )
v15 = FALSE;
*a7 = v15;
}
else if ( a8 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "probe") )
{
v16 = TRUE;
if ( strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 1024), "1") )
v16 = FALSE;
*a8 = v16;
}
}
while ( (__int64)&v11[-a1] < a2 );
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2, char *a3, char *a4, char *a5, char *a6, _BYTE *a7, _BYTE *a8)
{
const char *v11; // rbp
int v12; // eax
const char *v13; // rbp
__int64 v14; // rbx
char v15; // al
char v16; // al

v11 = (const char *)(a1 + 4);
if ( a2 > 4 )
{
do
{
v12 = utils_get_int_from_bytes(v11, 4LL);
v13 = v11 + 4;
if ( v12 > 511 )
break;
v14 = v12;
strncpy(tcp_package, v13, v12);
tcp_package[v14] = 0;
v11 = &v13[v14];
_isoc99_sscanf(
tcp_package,
"%[^'=']=%s",
(unsigned int)((_DWORD)tcp_package + 512),
(unsigned int)((_DWORD)tcp_package + 1024));
printf(
"[tcpros] name: %s value: %s\n",
(const char *)(unsigned int)((_DWORD)tcp_package + 512),
(const char *)(unsigned int)((_DWORD)tcp_package + 1024));
if ( a3 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "callerid") )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a4 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "service") )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a5 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "md5sum") )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a6 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "type") )
{
strcpy(a6, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a7 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "persistent") )
{
v15 = TRUE;
if ( strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 1024), "1") )
v15 = FALSE;
*a7 = v15;
}
else if ( a8 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "probe") )
{
v16 = TRUE;
if ( strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 1024), "1") )
v16 = FALSE;
*a8 = v16;
}
}
while ( (__int64)&v11[-a1] < a2 );
}
}

original_code:
void tcpros_parse_client_request(const char* req,
                                 int req_len,
                                 char* callerid,
                                 char* service,
                                 char* md5sum,
                                 char* type,
                                 bool* persistent,
                                 bool* probe)
{
 const char *iter = req + 4;
 char *field = tcp_package;
 char *name = tcp_package + 512;
 char *value = tcp_package + 1024;
 while(iter - req < req_len)
    {
     int field_len = utils_get_int_from_bytes(iter, 4);
     iter += 4;
     if(field_len >= 512) return;
     strncpy(field, iter, field_len);
     field[field_len] = '\0';
     iter += field_len;
  sscanf(field, "%[^'=']=%s", name, value);
  printf("[tcpros] name: %s value: %s\n", name, value);
  if(callerid != ((void *)0) &&
     strcmp(name, "callerid") == 0)
  {
   strcpy(callerid, value);
  }
  else if(service != ((void *)0) &&
     strcmp(name, "service") == 0)
  {
   strcpy(service, value);
  }
  else if(md5sum != ((void *)0) &&
          strcmp(name, "md5sum") == 0)
  {
   strcpy(md5sum, value);
  }
  else if(type != ((void *)0) &&
          strcmp(name, "type") == 0)
  {
   strcpy(type, value);
  }
  else if(persistent != ((void *)0) &&
          strcmp(name, "persistent") == 0)
  {
   *persistent = (strcmp(value, "1") == 0) ? TRUE : FALSE;
  }
  else if(probe != ((void *)0) &&
          strcmp(name, "probe") == 0)
  {
   *probe = (strcmp(value, "1") == 0) ? TRUE : FALSE;
  }
    }
}

canonical_original_code:
void tcpros_parse_client_request(char *req, int req_len, char *callerid, char *service, char *md5sum, char *type, unsigned char *persistent, unsigned char *probe)
{
 char *iter = req + 4;
 char *field = tcp_package;
 char *name = tcp_package + 512;
 char *value = tcp_package + 1024;
 while(iter - req < req_len)
    {
     int field_len = utils_get_int_from_bytes(iter, 4);
     iter += 4;
     if(field_len >= 512) return;
     strncpy(field, iter, field_len);
     field[field_len] = '\0';
     iter += field_len;
  sscanf(field, "%[^'=']=%s", name, value);
  printf("[tcpros] name: %s value: %s\n", name, value);
  if(callerid != ((void *)0) &&
     strcmp(name, "callerid") == 0)
  {
   strcpy(callerid, value);
  }
  else if(service != ((void *)0) &&
     strcmp(name, "service") == 0)
  {
   strcpy(service, value);
  }
  else if(md5sum != ((void *)0) &&
          strcmp(name, "md5sum") == 0)
  {
   strcpy(md5sum, value);
  }
  else if(type != ((void *)0) &&
          strcmp(name, "type") == 0)
  {
   strcpy(type, value);
  }
  else if(persistent != ((void *)0) &&
          strcmp(name, "persistent") == 0)
  {
   *persistent = (strcmp(value, "1") == 0) ? TRUE : FALSE;
  }
  else if(probe != ((void *)0) &&
          strcmp(name, "probe") == 0)
  {
   *probe = (strcmp(value, "1") == 0) ? TRUE : FALSE;
  }
    }
}

variable_types:
persistent
unsigned char *

variable_types:
probe
unsigned char *


repo: RoboticLtd/pico-ros

decompiled_code:
__int64 __fastcall tcpros_send_server_response(unsigned int a1, __int64 a2, _QWORD *a3)
{
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = (__int64)tcp_package;
tcpmsg_init(v5);
tcpmsg_add_field(v5, "callerid", a2);
tcpmsg_add_field(v5, "type", *a3);
tcpmsg_add_field(v5, "md5sum", a3[1]);
tcpmsg_finalize(tcp_package, v5[0] - (_QWORD)tcp_package);
return comms_send(a1, tcp_package, v5[0] - (_QWORD)tcp_package);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2, _QWORD *a3)
{
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = (__int64)tcp_package;
tcpmsg_init(v5);
tcpmsg_add_field(v5, "callerid", a2);
tcpmsg_add_field(v5, "type", *a3);
tcpmsg_add_field(v5, "md5sum", a3[1]);
tcpmsg_finalize(tcp_package, v5[0] - (_QWORD)tcp_package);
return comms_send(a1, tcp_package, v5[0] - (_QWORD)tcp_package);
}

original_code:
void tcpros_send_server_response(const int socketfd,
                                 const string callerid,
                                 const service_type_t* srv)
{
 char* iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "type", srv->type);
 tcpmsg_add_field(&iter, "md5sum", srv->md5sum);
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
}

canonical_original_code:
void tcpros_send_server_response(int socketfd, char *callerid, struct service_type_t *srv)
{
 char *iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "type", srv->type);
 tcpmsg_add_field(&iter, "md5sum", srv->md5sum);
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
}

variable_types: socketfd int

variable_types:
callerid
char *

variable_types: struct service_type_t { char *type; char *md5sum; int (*serialize_req)(char *, void *); void *(*deserialize_req)(char *); int (*serialize_resp)(char *, void *); void (*deserialize_resp)(char *, void *); void (*free_srv)(void *srv); } *

variable_types:
iter
char *

return_type: void


decompiled_code:
void __fastcall tcpros_parse_server_response(__int64 a1, int a2, char *a3, char *a4, char *a5)
{
const char *v8; // rbp
int v9; // eax
const char *v10; // rbp
__int64 v11; // rbx

v8 = (const char *)(a1 + 4);
if ( a2 > 4 )
{
do
{
v9 = utils_get_int_from_bytes(v8, 4LL);
v10 = v8 + 4;
if ( v9 > 511 )
break;
v11 = v9;
strncpy(tcp_package, v10, v9);
tcp_package[v11] = 0;
v8 = &v10[v11];
_isoc99_sscanf(
tcp_package,
"%[^'=']=%s",
(unsigned int)((_DWORD)tcp_package + 512),
(unsigned int)((_DWORD)tcp_package + 1024));
printf(
"[tcpros] name: %s value: %s\n",
(const char *)(unsigned int)((_DWORD)tcp_package + 512),
(const char *)(unsigned int)((_DWORD)tcp_package + 1024));
if ( a3 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "callerid") )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a4 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "md5sum") )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a5 )
{
if ( !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "type") )
strcpy(a5, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
}
while ( (__int64)&v8[-a1] < a2 );
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, char *a3, char *a4, char *a5)
{
const char *v8; // rbp
int v9; // eax
const char *v10; // rbp
__int64 v11; // rbx

v8 = (const char *)(a1 + 4);
if ( a2 > 4 )
{
do
{
v9 = utils_get_int_from_bytes(v8, 4LL);
v10 = v8 + 4;
if ( v9 > 511 )
break;
v11 = v9;
strncpy(tcp_package, v10, v9);
tcp_package[v11] = 0;
v8 = &v10[v11];
_isoc99_sscanf(
tcp_package,
"%[^'=']=%s",
(unsigned int)((_DWORD)tcp_package + 512),
(unsigned int)((_DWORD)tcp_package + 1024));
printf(
"[tcpros] name: %s value: %s\n",
(const char *)(unsigned int)((_DWORD)tcp_package + 512),
(const char *)(unsigned int)((_DWORD)tcp_package + 1024));
if ( a3 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "callerid") )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a4 && !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "md5sum") )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
else if ( a5 )
{
if ( !strcmp((const char *)(unsigned int)((_DWORD)tcp_package + 512), "type") )
strcpy(a5, (const char *)(unsigned int)((_DWORD)tcp_package + 1024));
}
}
while ( (__int64)&v8[-a1] < a2 );
}
}

original_code:
void tcpros_parse_server_response(const char* resp,
                                  int resp_len,
                                  char* callerid,
                                  char* md5sum,
                                  char* type)
{
 const char *iter = resp + 4;
 char *field = tcp_package;
 char *name = tcp_package + 512;
 char *value = tcp_package + 1024;
 while(iter - resp < resp_len)
    {
     int field_len = utils_get_int_from_bytes(iter, 4);
     iter += 4;
     if(field_len >= 512) return;
     strncpy(field, iter, field_len);
     field[field_len] = '\0';
     iter += field_len;
  sscanf(field, "%[^'=']=%s", name, value);
  printf("[tcpros] name: %s value: %s\n", name, value);
  if(callerid != ((void *)0) &&
     strcmp(name, "callerid") == 0)
  {
   strcpy(callerid, value);
  }
  else if(md5sum != ((void *)0) &&
          strcmp(name, "md5sum") == 0)
  {
   strcpy(md5sum, value);
  }
  else if(type != ((void *)0) &&
          strcmp(name, "type") == 0)
  {
   strcpy(type, value);
  }
    }
}

canonical_original_code:
void tcpros_parse_server_response(char *resp, int resp_len, char *callerid, char *md5sum, char *type)
{
 char *iter = resp + 4;
 char *field = tcp_package;
 char *name = tcp_package + 512;
 char *value = tcp_package + 1024;
 while(iter - resp < resp_len)
    {
     int field_len = utils_get_int_from_bytes(iter, 4);
     iter += 4;
     if(field_len >= 512) return;
     strncpy(field, iter, field_len);
     field[field_len] = '\0';
     iter += field_len;
  sscanf(field, "%[^'=']=%s", name, value);
  printf("[tcpros] name: %s value: %s\n", name, value);
  if(callerid != ((void *)0) &&
     strcmp(name, "callerid") == 0)
  {
   strcpy(callerid, value);
  }
  else if(md5sum != ((void *)0) &&
          strcmp(name, "md5sum") == 0)
  {
   strcpy(md5sum, value);
  }
  else if(type != ((void *)0) &&
          strcmp(name, "type") == 0)
  {
   strcpy(type, value);
  }
    }
}

variable_types:
resp
char *

variable_types:
type
char *

variable_types:
field
char *

variable_types:
name
char *

variable_types:
value
char *


decompiled_code:
char **__fastcall uri_create(char *src, __int16 a2)
{
char **v2; // rbx
char *v3; // rbp
struct hostent *v4; // rbp

v2 = (char **)malloc(0x10uLL);
v3 = (char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
strcpy(v3, src);
v4 = gethostbyname(v3);
printf("Resolved addr: %d \r\n", *v4->h_addr_list);
inet_ntop(2, *(const void **)v4->h_addr_list, *v2, 0x40u);
*((_WORD *)v2 + 4) = a2;
return v2;
}

canonical_decompiled_code:
char **__fastcall func0(char *src, __int16 a2)
{
char **v2; // rbx
char *v3; // rbp
struct hostent *v4; // rbp

v2 = (char **)malloc(0x10uLL);
v3 = (char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
strcpy(v3, src);
v4 = gethostbyname(v3);
printf("Resolved addr: %d \r\n", *v4->h_addr_list);
inet_ntop(2, *(const void **)v4->h_addr_list, *v2, 0x40u);
*((_WORD *)v2 + 4) = a2;
return v2;
}

original_code:
uri_t* uri_create(const string _hostname, const unsigned short _port)
{
 uri_t* uri;
 uri = (uri_t*)malloc(sizeof(uri_t));
 uri->ip = (string)calloc(sizeof(char*), 64);
 strcpy(uri->ip, _hostname);
 struct hostent *lh = gethostbyname(uri->ip);
 printf("Resolved addr: %d \r\n", lh->h_addr_list[0]);
 inet_ntop(2, lh->h_addr_list[0], uri->ip, 64);
 uri->port = _port;
 return uri;
}

canonical_original_code:
struct uri_t *uri_create(char *_hostname, unsigned short _port)
{
 struct uri_t *uri;
 uri = (struct uri_t *)malloc(sizeof(uri_t));
 uri->ip = (char *)calloc(sizeof(char *), 64);
 strcpy(uri->ip, _hostname);
 struct hostent *lh = gethostbyname(uri->ip);
 printf("Resolved addr: %d \r\n", lh->h_addr_list[0]);
 inet_ntop(2, lh->h_addr_list[0], uri->ip, 64);
 uri->port = _port;
 return uri;
}

variable_types: struct uri_t { char *ip; unsigned short port; } *

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


decompiled_code:
const char **__fastcall uri_create_from_http_string(const char *a1)
{
char *v1; // rbp
const char **v2; // rbx
const char *v3; // rax
struct hostent *v4; // rax

v1 = strstr(a1, "http://");
if ( !v1 )
return 0LL;
v2 = (const char **)malloc(0x10uLL);
v3 = (const char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
_isoc99_sscanf(v1, "http://%[^:]:%hu", v3, v2 + 1);
v4 = gethostbyname(*v2);
inet_ntop(2, *(const void **)v4->h_addr_list, (char *)*v2, 0x20u);
return v2;
}

canonical_decompiled_code:
const char **__fastcall func1(const char *a1)
{
char *v1; // rbp
const char **v2; // rbx
const char *v3; // rax
struct hostent *v4; // rax

v1 = strstr(a1, "http://");
if ( !v1 )
return 0LL;
v2 = (const char **)malloc(0x10uLL);
v3 = (const char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
_isoc99_sscanf(v1, "http://%[^:]:%hu", v3, v2 + 1);
v4 = gethostbyname(*v2);
inet_ntop(2, *(const void **)v4->h_addr_list, (char *)*v2, 0x20u);
return v2;
}

original_code:
uri_t* uri_create_from_http_string(const string str)
{
 char* iter = strstr(str, "http://");
 if(iter == ((void *)0)) return ((void *)0);
 uri_t* uri;
 uri = (uri_t*)malloc(sizeof(uri_t));
 uri->ip = (string)calloc(sizeof(char*), 64);
 sscanf(iter, "http://%[^:]:%hu", uri->ip, &(uri->port));
 struct hostent *lh = gethostbyname(uri->ip);
 inet_ntop(2, lh->h_addr_list[0], uri->ip, 32);
 return uri;
}

canonical_original_code:
struct uri_t *uri_create_from_http_string(char *str)
{
 char *iter = strstr(str, "http://");
 if(iter == ((void *)0)) return ((void *)0);
 struct uri_t *uri;
 uri = (struct uri_t *)malloc(sizeof(uri_t));
 uri->ip = (char *)calloc(sizeof(char *), 64);
 sscanf(iter, "http://%[^:]:%hu", uri->ip, &(uri->port));
 struct hostent *lh = gethostbyname(uri->ip);
 inet_ntop(2, lh->h_addr_list[0], uri->ip, 32);
 return uri;
}

variable_types:
str
char *

return_type: struct uri_t { char *ip; unsigned short port; } *

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


decompiled_code:
const char **__fastcall uri_create_from_rosrpc_string(const char *a1)
{
char *v1; // rbp
const char **v2; // rbx
const char *v3; // rax
struct hostent *v4; // rax

v1 = strstr(a1, "rosrpc://");
if ( !v1 )
return 0LL;
v2 = (const char **)malloc(0x10uLL);
v3 = (const char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
_isoc99_sscanf(v1, "rosrpc://%[^:]:%hu", v3, v2 + 1);
v4 = gethostbyname(*v2);
inet_ntop(2, *(const void **)v4->h_addr_list, (char *)*v2, 0x20u);
return v2;
}

canonical_decompiled_code:
const char **__fastcall func2(const char *a1)
{
char *v1; // rbp
const char **v2; // rbx
const char *v3; // rax
struct hostent *v4; // rax

v1 = strstr(a1, "rosrpc://");
if ( !v1 )
return 0LL;
v2 = (const char **)malloc(0x10uLL);
v3 = (const char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
_isoc99_sscanf(v1, "rosrpc://%[^:]:%hu", v3, v2 + 1);
v4 = gethostbyname(*v2);
inet_ntop(2, *(const void **)v4->h_addr_list, (char *)*v2, 0x20u);
return v2;
}

original_code:
uri_t* uri_create_from_rosrpc_string(const string str)
{
 char* iter = strstr(str, "rosrpc://");
 if(iter == ((void *)0)) return ((void *)0);
 uri_t* uri;
 uri = (uri_t*)malloc(sizeof(uri_t));
 uri->ip = (string)calloc(sizeof(char*), 64);
 sscanf(iter, "rosrpc://%[^:]:%hu", uri->ip, &(uri->port));
 struct hostent *lh = gethostbyname(uri->ip);
 inet_ntop(2, lh->h_addr_list[0], uri->ip, 32);
 return uri;
}

canonical_original_code:
struct uri_t *uri_create_from_rosrpc_string(char *str)
{
 char *iter = strstr(str, "rosrpc://");
 if(iter == ((void *)0)) return ((void *)0);
 struct uri_t *uri;
 uri = (struct uri_t *)malloc(sizeof(uri_t));
 uri->ip = (char *)calloc(sizeof(char *), 64);
 sscanf(iter, "rosrpc://%[^:]:%hu", uri->ip, &(uri->port));
 struct hostent *lh = gethostbyname(uri->ip);
 inet_ntop(2, lh->h_addr_list[0], uri->ip, 32);
 return uri;
}

user_defined_types: struct uri_t { char *ip; unsigned short port; }


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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void uri_free(uri_t* uri)
{
 if(uri->ip != ((void *)0)) free(uri->ip);
 free(uri);
}

canonical_original_code:
void uri_free(struct uri_t *uri)
{
 if(uri->ip != ((void *)0)) free(uri->ip);
 free(uri);
}


decompiled_code:
char *__fastcall uri_get_string(__int64 a1)
{
char *v1; // rbx

v1 = (char *)calloc(1uLL, 0x40uLL);
sprintf(v1, "%s:%u", *(const char **)a1, *(unsigned __int16 *)(a1 + 8));
return v1;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *v1; // rbx

v1 = (char *)calloc(1uLL, 0x40uLL);
sprintf(v1, "%s:%u", *(const char **)a1, *(unsigned __int16 *)(a1 + 8));
return v1;
}

original_code:
string uri_get_string(uri_t* uri)
{
 string res = (char*)calloc(sizeof(char), 64);
 sprintf(res, "%s:%u", uri->ip, uri->port);
 return res;
}

canonical_original_code:
char *uri_get_string(struct uri_t *uri)
{
 char *res = (char*)calloc(sizeof(char), 64);
 sprintf(res, "%s:%u", uri->ip, uri->port);
 return res;
}

variable_types:
res
char *

return_type: char *


decompiled_code:
char *__fastcall uri_get_http_string(__int64 a1)
{
char *v1; // rbx

v1 = (char *)calloc(1uLL, 0x40uLL);
sprintf(v1, "http://%s:%u/", *(const char **)a1, *(unsigned __int16 *)(a1 + 8));
return v1;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
char *v1; // rbx

v1 = (char *)calloc(1uLL, 0x40uLL);
sprintf(v1, "http://%s:%u/", *(const char **)a1, *(unsigned __int16 *)(a1 + 8));
return v1;
}

original_code:
string uri_get_http_string(uri_t* uri)
{
 string res = (char*)calloc(sizeof(char), 64);
 sprintf(res, "http://%s:%u/", uri->ip, uri->port);
 return res;
}

canonical_original_code:
char *uri_get_http_string(struct uri_t *uri)
{
 char *res = (char*)calloc(sizeof(char), 64);
 sprintf(res, "http://%s:%u/", uri->ip, uri->port);
 return res;
}


decompiled_code:
char *__fastcall uri_get_rosrpc_string(__int64 a1)
{
char *v1; // rbx

v1 = (char *)calloc(1uLL, 0x40uLL);
sprintf(v1, "rosrpc://%s:%u/", *(const char **)a1, *(unsigned __int16 *)(a1 + 8));
return v1;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
char *v1; // rbx

v1 = (char *)calloc(1uLL, 0x40uLL);
sprintf(v1, "rosrpc://%s:%u/", *(const char **)a1, *(unsigned __int16 *)(a1 + 8));
return v1;
}

original_code:
string uri_get_rosrpc_string(uri_t* uri)
{
 string res = (char*)calloc(sizeof(char), 64);
 sprintf(res, "rosrpc://%s:%u/", uri->ip, uri->port);
 return res;
}

canonical_original_code:
char *uri_get_rosrpc_string(struct uri_t *uri)
{
 char *res = (char*)calloc(sizeof(char), 64);
 sprintf(res, "rosrpc://%s:%u/", uri->ip, uri->port);
 return res;
}


decompiled_code:
_BOOL8 __fastcall uri_equals(__int64 a1, __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax

v2 = strcmp(*(const char **)a1, *(const char **)a2);
result = 0LL;
if ( !v2 )
result = *(_WORD *)(a1 + 8) == *(_WORD *)(a2 + 8);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax

v2 = strcmp(*(const char **)a1, *(const char **)a2);
result = 0LL;
if ( !v2 )
result = *(_WORD *)(a1 + 8) == *(_WORD *)(a2 + 8);
return result;
}

original_code:
bool uri_equals(const uri_t* a, const uri_t* b)
{
 return (strcmp(a->ip, b->ip) == 0 && (a->port == b->port));
}

canonical_original_code:
unsigned char uri_equals(struct uri_t *a, struct uri_t *b)
{
 return (strcmp(a->ip, b->ip) == 0 && (a->port == b->port));
}

variable_types:
b
struct uri_t *

return_type: unsigned char


decompiled_code:
_QWORD *list_create()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
list_t* list_create()
{
 list_t* l = (list_t*)malloc(sizeof(list_t));
 l->size = 0;
 l->begin = ((void *)0);
 l->end = ((void *)0);
 return l;
}

canonical_original_code:
struct list_t *list_create()
{
 struct list_t *l = (list_t*)malloc(sizeof(list_t));
 l->size = 0;
 l->begin = ((void *)0);
 l->end = ((void *)0);
 return l;
}

variable_types: struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *

user_defined_types: struct list_t { int size; struct list_item_t *begin; struct list_item_t *end; }


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

comms_disconnect(*((unsigned int *)ptr + 4));
if ( *(_QWORD *)ptr )
uri_free();
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

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

comms_disconnect(*((unsigned int *)ptr + 4));
if ( *(_QWORD *)ptr )
uri_free();
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void connection_free(connection_t* con)
{
 comms_disconnect(con->socketfd);
 if(con->uri != ((void *)0)) uri_free(con->uri);
 if(con->name != ((void *)0)) free(con->name);
 free(con);
}

canonical_original_code:
void connection_free(struct connection_t *con)
{
 comms_disconnect(con->socketfd);
 if(con->uri != ((void *)0)) uri_free(con->uri);
 if(con->name != ((void *)0)) free(con->name);
 free(con);
}

variable_types: struct connection_t { struct uri_t { char *ip; unsigned short port; } *uri; char *name; int socketfd; unsigned char pending; } *

user_defined_types: struct connection_t { struct uri_t *uri; char *name; int socketfd; unsigned char pending; }


decompiled_code:
__int64 __fastcall serialize_req_roscpp_tutorials__TwoInts(__int64 a1, __int64 a2)
{
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v3[0] = a1;
tcpmsg_init(v3);
tcpmsg_add_raw_data(v3, a2, 8LL);
tcpmsg_add_raw_data(v3, a2 + 8, 8LL);
tcpmsg_finalize(a1, v3[0] - a1);
return v3[0] - a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v3[0] = a1;
tcpmsg_init(v3);
tcpmsg_add_raw_data(v3, a2, 8LL);
tcpmsg_add_raw_data(v3, a2 + 8, 8LL);
tcpmsg_finalize(a1, v3[0] - a1);
return v3[0] - a1;
}

original_code:
int serialize_req_roscpp_tutorials__TwoInts(char* const buf, const void* srv)
{
 const roscpp_tutorials__TwoInts* data = srv;
 char* iter = buf;
 tcpmsg_init(&iter);
 tcpmsg_add_raw_data(&iter, (char*)(&data->request.x), 8);
 tcpmsg_add_raw_data(&iter, (char*)(&data->request.y), 8);
 tcpmsg_finalize(buf, iter - buf);
 return iter-buf;
}

canonical_original_code:
int serialize_req_roscpp_tutorials__TwoInts(char *buf, void *srv)
{
 struct roscpp_tutorials__TwoInts *data = srv;
 char *iter = buf;
 tcpmsg_init(&iter);
 tcpmsg_add_raw_data(&iter, (char *)(&data->request.x), 8);
 tcpmsg_add_raw_data(&iter, (char *)(&data->request.y), 8);
 tcpmsg_finalize(buf, iter - buf);
 return iter-buf;
}

variable_types:
buf
char *

variable_types:
srv
void *

variable_types: struct roscpp_tutorials__TwoInts { struct roscpp_tutorials__TwoInts_req { long x; long y; } request; struct roscpp_tutorials__TwoInts_resp { long sum; } response; } *

return_type: int

user_defined_types: struct roscpp_tutorials__TwoInts { struct roscpp_tutorials__TwoInts_req request; struct roscpp_tutorials__TwoInts_resp response; }


decompiled_code:
__int64 __fastcall serialize_resp_roscpp_tutorials__TwoInts(_BYTE *a1, __int64 a2)
{
int v3; // [rsp+4h] [rbp-24h] BYREF
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

*a1 = 1;
v4[0] = (__int64)(a1 + 1);
v3 = 8;
tcpmsg_add_raw_data(v4, &v3, 4LL);
tcpmsg_add_raw_data(v4, a2 + 16, 8LL);
return v4[0] - (_QWORD)a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2)
{
int v3; // [rsp+4h] [rbp-24h] BYREF
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

*a1 = 1;
v4[0] = (__int64)(a1 + 1);
v3 = 8;
tcpmsg_add_raw_data(v4, &v3, 4LL);
tcpmsg_add_raw_data(v4, a2 + 16, 8LL);
return v4[0] - (_QWORD)a1;
}

original_code:
int serialize_resp_roscpp_tutorials__TwoInts(char* const buf, const void* srv)
{
 const roscpp_tutorials__TwoInts* data = srv;
 buf[0] = 1;
 char* iter = buf + 1;
 int len = sizeof(int64_t);
 tcpmsg_add_raw_data(&iter, &len, 4);;
 tcpmsg_add_raw_data(&iter, (char*)(&data->response.sum), 8);;
 return iter - buf;
}

canonical_original_code:
int serialize_resp_roscpp_tutorials__TwoInts(char *buf, void *srv)
{
 struct roscpp_tutorials__TwoInts *data = srv;
 buf[0] = 1;
 char *iter = buf + 1;
 int len = sizeof(int64_t);
 tcpmsg_add_raw_data(&iter, &len, 4);;
 tcpmsg_add_raw_data(&iter, (char *)(&data->response.sum), 8);;
 return iter - buf;
}

variable_types: len int

user_defined_types: struct roscpp_tutorials__TwoInts_req { long x; long y; }

user_defined_types: struct roscpp_tutorials__TwoInts_resp { long sum; }


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

result = utils_get_long_from_bytes(a1 + 4, 8LL);
*(_QWORD *)(a2 + 16) = result;
return result;
}

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

result = utils_get_long_from_bytes(a1 + 4, 8LL);
*(_QWORD *)(a2 + 16) = result;
return result;
}

original_code:
void deserialize_resp_roscpp_tutorials__TwoInts(char* const buf, void* srv)
{
 roscpp_tutorials__TwoInts* data = srv;
 char* iter = buf + 4;
 data->response.sum = utils_get_long_from_bytes(iter, 8);
}

canonical_original_code:
void deserialize_resp_roscpp_tutorials__TwoInts(char *buf, void *srv)
{
 struct roscpp_tutorials__TwoInts *data = srv;
 char *iter = buf + 4;
 data->response.sum = utils_get_long_from_bytes(iter, 8);
}

variable_types:
iter
char *


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

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

original_code:
void free_roscpp_tutorials__TwoInts(void* srv)
{
 if(srv != ((void *)0)) free(srv);
}

canonical_original_code:
void free_roscpp_tutorials__TwoInts(void *srv)
{
 if(srv != ((void *)0)) free(srv);
}


decompiled_code:
char __fastcall pico_ros_init(__int64 a1)
{
char v1; // bl

v1 = comms_init();
return TRUE & v1 & node_init(&pico_node, a1);
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1)
{
char v1; // bl

v1 = comms_init();
return TRUE & v1 & node_init(&pico_node, a1);
}

original_code:
bool pico_ros_init(string node_name)
{
 bool res = TRUE;
 res &= comms_init();
 res &= node_init(&pico_node, node_name);
 return res;
}

canonical_original_code:
unsigned char pico_ros_init(char *node_name)
{
 unsigned char res = TRUE;
 res &= comms_init();
 res &= node_init(&pico_node, node_name);
 return res;
}

variable_types:
res
unsigned char


decompiled_code:
__int64 pico_ros_spin()
{
return node_spin(&pico_node);
}

canonical_decompiled_code:
__int64 func1()
{
return node_spin(&pico_node);
}

original_code:
void pico_ros_spin()
{
 node_spin(&pico_node);
}


decompiled_code:
bool pico_ros_ok()
{
return pico_node[16] == 0;
}

canonical_decompiled_code:
bool func2()
{
return pico_node[16] == 0;
}

original_code:
bool pico_ros_ok()
{
 return !pico_node.exit;
}

canonical_original_code:
unsigned char pico_ros_ok()
{
 return !pico_node.exit;
}


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

result = TRUE;
pico_node[16] = TRUE;
return result;
}

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

result = TRUE;
pico_node[16] = TRUE;
return result;
}

original_code:
void pico_ros_request_shutdown()
{
 pico_node.exit = TRUE;
}


decompiled_code:
__int64 pico_ros_shutdown()
{
return node_stop(pico_node);
}

canonical_decompiled_code:
__int64 func4()
{
return node_stop(pico_node);
}

original_code:
void pico_ros_shutdown()
{
 node_stop(&pico_node);
}


decompiled_code:
__int64 __fastcall pico_ros_advertise(__int64 a1, __int64 a2)
{
return node_advertise(pico_node, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return node_advertise(pico_node, a1, a2);
}

original_code:
topic_t* pico_ros_advertise(string name, string type)
{
 return node_advertise(&pico_node, name, type);
}

canonical_original_code:
struct topic_t *pico_ros_advertise(char *name, char *type)
{
 return node_advertise(&pico_node, name, type);
}

variable_types:
type
char *

return_type: struct topic_t { char *name; enum direction_t { INBOUND=0, OUTBOUND=1, UNKNOWN=2 } dir; struct message_type_t { char *type; char *md5sum; int (*serialize)(char *, void *); void *(*deserialize)(char *buf); void (*free_msg)(void *msg); } *msg_type; void (*callback)(void *); struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *conns; } *

user_defined_types: struct topic_t { char *name; enum direction_t dir; struct message_type_t *msg_type; void (*callback)(void *); struct list_t *conns; }


decompiled_code:
__int64 pico_ros_publish_topic()
{
return node_publish_topic();
}

canonical_decompiled_code:
__int64 func6()
{
return node_publish_topic();
}

original_code:
void pico_ros_publish_topic(topic_t* t, const void* msg)
{
 node_publish_topic(t, msg);
}

canonical_original_code:
void pico_ros_publish_topic(struct topic_t *t, void *msg)
{
 node_publish_topic(t, msg);
}

variable_types: struct topic_t { char *name; enum direction_t { INBOUND=0, OUTBOUND=1, UNKNOWN=2 } dir; struct message_type_t { char *type; char *md5sum; int (*serialize)(char *, void *); void *(*deserialize)(char *buf); void (*free_msg)(void *msg); } *msg_type; void (*callback)(void *); struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *conns; } *

variable_types:
msg
void *


decompiled_code:
__int64 __fastcall pico_ros_service_client(__int64 a1, __int64 a2, unsigned __int8 a3)
{
return node_service_client(pico_node, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned __int8 a3)
{
return node_service_client(pico_node, a1, a2, a3);
}

original_code:
service_client_t* pico_ros_service_client(string name, string type, bool persistent)
{
 return node_service_client(&pico_node, name, type, persistent);
}

canonical_original_code:
struct service_t *pico_ros_service_client(char *name, char *type, unsigned char persistent)
{
 return node_service_client(&pico_node, name, type, persistent);
}

variable_types:
name
char *

variable_types:
persistent
unsigned char

return_type: struct service_t { char *name; struct service_type_t { char *type; char *md5sum; int (*serialize_req)(char *, void *); void *(*deserialize_req)(char *); int (*serialize_resp)(char *, void *); void (*deserialize_resp)(char *, void *); void (*free_srv)(void *srv); } *srv_type; void (*callback)(void *); struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *conns; unsigned char persistent; } *

user_defined_types: struct service_t { char *name; struct service_type_t *srv_type; void (*callback)(void *); struct list_t *conns; unsigned char persistent; }


decompiled_code:
__int64 __fastcall pico_ros_call_service(__int64 a1, __int64 a2)
{
return node_call_service(pico_node, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
return node_call_service(pico_node, a1, a2);
}

original_code:
bool pico_ros_call_service(service_client_t* client, void* srv)
{
 return node_call_service(&pico_node, client, srv);
}

canonical_original_code:
unsigned char pico_ros_call_service(struct service_t *client, void *srv)
{
 return node_call_service(&pico_node, client, srv);
}

variable_types: struct service_t { char *name; struct service_type_t { char *type; char *md5sum; int (*serialize_req)(char *, void *); void *(*deserialize_req)(char *); int (*serialize_resp)(char *, void *); void (*deserialize_resp)(char *, void *); void (*free_srv)(void *srv); } *srv_type; void (*callback)(void *); struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *conns; unsigned char persistent; } *


decompiled_code:
void __fastcall topic_free(void *ptr)
{
if ( !*((_QWORD *)ptr + 4) )
list_free(0LL, &connection_free);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( !*((_QWORD *)ptr + 4) )
list_free(0LL, &connection_free);
free(ptr);
}

original_code:
void topic_free(topic_t* t)
{
 if(t->name == ((void *)0)) free(t->name);
 if(t->conns == ((void *)0)) list_free(t->conns, (void (*)(void*))connection_free);
 free(t);
}

canonical_original_code:
void topic_free(struct topic_t *t)
{
 if(t->name == ((void *)0)) free(t->name);
 if(t->conns == ((void *)0)) list_free(t->conns, (void (*)(void *))connection_free);
 free(t);
}

user_defined_types: enum direction_t { INBOUND=0, OUTBOUND=1, UNKNOWN=2 }

user_defined_types: struct message_type_t { char *type; char *md5sum; int (*serialize)(char *, void *); void *(*deserialize)(char *buf); void (*free_msg)(void *msg); }

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


decompiled_code:
__int64 __fastcall topic_get_connection_by_name(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // rbp

v2 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 8LL);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *v2;
if ( !strcmp(*(const char **)(*v2 + 8LL), a2) )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // rbp

v2 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 8LL);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *v2;
if ( !strcmp(*(const char **)(*v2 + 8LL), a2) )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
connection_t* topic_get_connection_by_name(topic_t* t, string name)
{
 list_item_t* item = t->conns->begin;
 connection_t* con;
 while(item != ((void *)0))
 {
  con = item->data;
  if(strcmp(con->name, name) == 0)
  {
   return con;
  }
  item = item->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct connection_t *topic_get_connection_by_name(struct topic_t *t, char *name)
{
 struct list_item_t *item = t->conns->begin;
 struct connection_t *con;
 while(item != ((void *)0))
 {
  con = item->data;
  if(strcmp(con->name, name) == 0)
  {
   return con;
  }
  item = item->next;
 }
 return ((void *)0);
}

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

return_type: struct connection_t { struct uri_t { char *ip; unsigned short port; } *uri; char *name; int socketfd; unsigned char pending; } *


decompiled_code:
__int64 __fastcall topic_add_connection(__int64 a1)
{
return list_insert_item(*(_QWORD *)(a1 + 32));
}

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

original_code:
void topic_add_connection(topic_t* t, connection_t* con)
{
 list_insert_item(t->conns, con);
}

canonical_original_code:
void topic_add_connection(struct topic_t *t, struct connection_t *con)
{
 list_insert_item(t->conns, con);
}


decompiled_code:
__int64 __fastcall topic_remove_connection(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rbx

comms_disconnect(*(unsigned int *)(a2 + 16));
result = *(_QWORD *)(a1 + 32);
v3 = *(_QWORD **)(result + 8);
if ( v3 )
{
while ( *v3 != a2 )
{
v3 = (_QWORD *)v3[1];
if ( !v3 )
return result;
}
connection_free(a2);
result = list_remove_item(*(_QWORD *)(a1 + 32), v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rbx

comms_disconnect(*(unsigned int *)(a2 + 16));
result = *(_QWORD *)(a1 + 32);
v3 = *(_QWORD **)(result + 8);
if ( v3 )
{
while ( *v3 != a2 )
{
v3 = (_QWORD *)v3[1];
if ( !v3 )
return result;
}
connection_free(a2);
result = list_remove_item(*(_QWORD *)(a1 + 32), v3);
}
return result;
}

original_code:
void topic_remove_connection(topic_t* t, connection_t* con)
{
 comms_disconnect(con->socketfd);
 list_item_t* item = t->conns->begin;
 while(item != ((void *)0))
 {
  if(item->data == con)
  {
   connection_free(con);
   list_remove_item(t->conns, item);
   return;
  }
  item = item->next;
 }
}

canonical_original_code:
void topic_remove_connection(struct topic_t *t, struct connection_t *con)
{
 comms_disconnect(con->socketfd);
 struct list_item_t *item = t->conns->begin;
 while(item != ((void *)0))
 {
  if(item->data == con)
  {
   connection_free(con);
   list_remove_item(t->conns, item);
   return;
  }
  item = item->next;
 }
}


decompiled_code:
void __fastcall service_free(void *ptr)
{
if ( !*((_QWORD *)ptr + 3) )
list_free(0LL, &connection_free);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( !*((_QWORD *)ptr + 3) )
list_free(0LL, &connection_free);
free(ptr);
}

original_code:
void service_free(service_t* s)
{
 if(s->name == ((void *)0)) free(s->name);
 if(s->conns == ((void *)0)) list_free(s->conns, (void (*)(void*))connection_free);
 free(s);
}

canonical_original_code:
void service_free(struct service_t *s)
{
 if(s->name == ((void *)0)) free(s->name);
 if(s->conns == ((void *)0)) list_free(s->conns, (void (*)(void *))connection_free);
 free(s);
}

user_defined_types: struct service_type_t { char *type; char *md5sum; int (*serialize_req)(char *, void *); void *(*deserialize_req)(char *); int (*serialize_resp)(char *, void *); void (*deserialize_resp)(char *, void *); void (*free_srv)(void *srv); }


decompiled_code:
__int64 __fastcall service_add_connection(__int64 a1)
{
return list_insert_item(*(_QWORD *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return list_insert_item(*(_QWORD *)(a1 + 24));
}

original_code:
void service_add_connection(service_t* s, connection_t* con)
{
 list_insert_item(s->conns, con);
}

canonical_original_code:
void service_add_connection(struct service_t *s, struct connection_t *con)
{
 list_insert_item(s->conns, con);
}


decompiled_code:
__int64 __fastcall service_remove_connection(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rbx

comms_disconnect(*(unsigned int *)(a2 + 16));
result = *(_QWORD *)(a1 + 24);
v3 = *(_QWORD **)(result + 8);
if ( v3 )
{
while ( *v3 != a2 )
{
v3 = (_QWORD *)v3[1];
if ( !v3 )
return result;
}
connection_free(a2);
result = list_remove_item(*(_QWORD *)(a1 + 24), v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rbx

comms_disconnect(*(unsigned int *)(a2 + 16));
result = *(_QWORD *)(a1 + 24);
v3 = *(_QWORD **)(result + 8);
if ( v3 )
{
while ( *v3 != a2 )
{
v3 = (_QWORD *)v3[1];
if ( !v3 )
return result;
}
connection_free(a2);
result = list_remove_item(*(_QWORD *)(a1 + 24), v3);
}
return result;
}

original_code:
void service_remove_connection(service_t* t, connection_t* con)
{
 comms_disconnect(con->socketfd);
 list_item_t* item = t->conns->begin;
 while(item != ((void *)0))
 {
  if(item->data == con)
  {
   connection_free(con);
   list_remove_item(t->conns, item);
   return;
  }
  item = item->next;
 }
}

canonical_original_code:
void service_remove_connection(struct service_t *t, struct connection_t *con)
{
 comms_disconnect(con->socketfd);
 struct list_item_t *item = t->conns->begin;
 while(item != ((void *)0))
 {
  if(item->data == con)
  {
   connection_free(con);
   list_remove_item(t->conns, item);
   return;
  }
  item = item->next;
 }
}


decompiled_code:
char **__fastcall message_get_type(const char *a1)
{
bool v1; // zf
_BOOL4 v2; // eax
char **v3; // rdx

v1 = strcmp("std_msgs/String", a1) == 0;
v2 = !v1;
if ( v1 )
goto LABEL_5;
v3 = 0LL;
if ( !strcmp("std_msgs/Byte", a1) )
{
v2 = 1;
LABEL_5:
v3 = &supported_msgs[5 * v2];
}
return v3;
}

canonical_decompiled_code:
char **__fastcall func0(const char *a1)
{
bool v1; // zf
_BOOL4 v2; // eax
char **v3; // rdx

v1 = strcmp("std_msgs/String", a1) == 0;
v2 = !v1;
if ( v1 )
goto LABEL_5;
v3 = 0LL;
if ( !strcmp("std_msgs/Byte", a1) )
{
v2 = 1;
LABEL_5:
v3 = &supported_msgs[5 * v2];
}
return v3;
}

original_code:
const message_type_t* message_get_type(string type)
{
 int i;
 for(i = 0; i < ( 1 + 1 ); ++i)
 {
  if(strcmp(supported_msgs[i].type, type) == 0)
  {
   return supported_msgs + i;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct message_type_t *message_get_type(char *type)
{
 int i;
 for(i = 0; i < ( 1 + 1 ); ++i)
 {
  if(strcmp(supported_msgs[i].type, type) == 0)
  {
   return supported_msgs + i;
  }
 }
 return ((void *)0);
}

variable_types: i int

return_type: struct message_type_t { char *type; char *md5sum; int (*serialize)(char *, void *); void *(*deserialize)(char *buf); void (*free_msg)(void *msg); } *


original_code:
int32_t utils_get_int_from_bytes(const char* bytes, int nbytes)
{
 int32_t res = 0, i;
 if(nbytes == 4)
 {
  res = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
 }
 else
 {
  for(i = 0; i < nbytes; ++i)
  {
   res |= bytes[i] << (i * 8);
  }
 }
 return res;
}

canonical_original_code:
int utils_get_int_from_bytes(char *bytes, int nbytes)
{
 int res = 0; int i;
 if(nbytes == 4)
 {
  res = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
 }
 else
 {
  for(i = 0; i < nbytes; ++i)
  {
   res |= bytes[i] << (i * 8);
  }
 }
 return res;
}

variable_types:
bytes
char *

variable_types: nbytes int

variable_types: res int


original_code:
int64_t utils_get_long_from_bytes(const char* bytes, int nbytes)
{
 int64_t res = 0l;
 int i;
 if(nbytes == 8)
 {
  res = ((int64_t)(0xff & bytes[7]) << 56) |
      ((int64_t)(0xff & bytes[6]) << 48) |
      ((int64_t)(0xff & bytes[5]) << 40) |
      ((int64_t)(0xff & bytes[4]) << 32) |
     ((int64_t)(0xff & bytes[3]) << 24) |
      ((int64_t)(0xff & bytes[2]) << 16) |
      ((int64_t)(0xff & bytes[1]) << 8) |
       (int64_t)(0xff & bytes[0]);
 }
 else
 {
  for(i = 0; i < nbytes; ++i)
  {
   res |= (int64_t)(0xff & bytes[i]) << (i * 8);
  }
 }
 return res;
}

canonical_original_code:
long utils_get_long_from_bytes(char *bytes, int nbytes)
{
 long res = 0l;
 int i;
 if(nbytes == 8)
 {
  res = ((long)(0xff & bytes[7]) << 56) |
      ((long)(0xff & bytes[6]) << 48) |
      ((long)(0xff & bytes[5]) << 40) |
      ((long)(0xff & bytes[4]) << 32) |
     ((long)(0xff & bytes[3]) << 24) |
      ((long)(0xff & bytes[2]) << 16) |
      ((long)(0xff & bytes[1]) << 8) |
       (long)(0xff & bytes[0]);
 }
 else
 {
  for(i = 0; i < nbytes; ++i)
  {
   res |= (long)(0xff & bytes[i]) << (i * 8);
  }
 }
 return res;
}

variable_types: res long

return_type: long


decompiled_code:
__pid_t utils_get_pid()
{
return getpid();
}

canonical_decompiled_code:
__pid_t func2()
{
return getpid();
}

original_code:
int utils_get_pid()
{
 return getpid();
}


decompiled_code:
__int64 __fastcall xmlmsg_init(char *a1)
{
__int64 result; // rax

result = 0x6576206C6D783F3CLL;
strcpy(a1, "<?xml version=\"1.0\"?>\n");
return result;
}

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

result = 0x6576206C6D783F3CLL;
strcpy(a1, "<?xml version=\"1.0\"?>\n");
return result;
}

original_code:
void xmlmsg_init(string msg)
{
 sprintf(msg, "<?xml version=\"1.0\"?>\n");
}

canonical_original_code:
void xmlmsg_init(char *msg)
{
 sprintf(msg, "<?xml version=\"1.0\"?>\n");
}

variable_types:
msg
char *


decompiled_code:
int __fastcall xmlmsg_open_tag(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a1);
return sprintf((char *)&a1[v2], "<%s>\n", a2);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a1);
return sprintf((char *)&a1[v2], "<%s>\n", a2);
}

original_code:
void xmlmsg_open_tag(string msg, string tag)
{
 sprintf(msg + strlen(msg), "<%s>\n", tag);
}

canonical_original_code:
void xmlmsg_open_tag(char *msg, char *tag)
{
 sprintf(msg + strlen(msg), "<%s>\n", tag);
}

variable_types:
tag
char *


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

v4 = strlen(a1);
return sprintf((char *)&a1[v4], "<%s>%s</%s>\n", a2, a3, a2);
}

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

v4 = strlen(a1);
return sprintf((char *)&a1[v4], "<%s>%s</%s>\n", a2, a3, a2);
}

original_code:
void xmlmsg_add_tag_with_string(string msg, string tag, string value)
{
 sprintf(msg + strlen(msg), "<%s>%s</%s>\n", tag, value, tag);
}

canonical_original_code:
void xmlmsg_add_tag_with_string(char *msg, char *tag, char *value)
{
 sprintf(msg + strlen(msg), "<%s>%s</%s>\n", tag, value, tag);
}

variable_types:
value
char *


decompiled_code:
int __fastcall xmlmsg_add_tag_with_ushort(const char *a1, const char *a2, unsigned __int16 a3)
{
size_t v4; // rax

v4 = strlen(a1);
return sprintf((char *)&a1[v4], "<%s>%hu</%s>\n", a2, a3, a2);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, const char *a2, unsigned __int16 a3)
{
size_t v4; // rax

v4 = strlen(a1);
return sprintf((char *)&a1[v4], "<%s>%hu</%s>\n", a2, a3, a2);
}

original_code:
void xmlmsg_add_tag_with_ushort(string msg, string tag, unsigned short value)
{
 sprintf(msg + strlen(msg), "<%s>%hu</%s>\n", tag, value, tag);
}

canonical_original_code:
void xmlmsg_add_tag_with_ushort(char *msg, char *tag, unsigned short value)
{
 sprintf(msg + strlen(msg), "<%s>%hu</%s>\n", tag, value, tag);
}

variable_types:
value
unsigned short


decompiled_code:
int __fastcall xmlmsg_add_tag_with_uint(const char *a1, const char *a2, unsigned int a3)
{
size_t v4; // rax

v4 = strlen(a1);
return sprintf((char *)&a1[v4], "<%s>%u</%s>\n", a2, a3, a2);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, const char *a2, unsigned int a3)
{
size_t v4; // rax

v4 = strlen(a1);
return sprintf((char *)&a1[v4], "<%s>%u</%s>\n", a2, a3, a2);
}

original_code:
void xmlmsg_add_tag_with_uint(string msg, string tag, unsigned int value)
{
 sprintf(msg + strlen(msg), "<%s>%u</%s>\n", tag, value, tag);
}

canonical_original_code:
void xmlmsg_add_tag_with_uint(char *msg, char *tag, unsigned int value)
{
 sprintf(msg + strlen(msg), "<%s>%u</%s>\n", tag, value, tag);
}

variable_types:
value
unsigned int


decompiled_code:
int __fastcall xmlmsg_close_tag(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a1);
return sprintf((char *)&a1[v2], "</%s>\n", a2);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a1);
return sprintf((char *)&a1[v2], "</%s>\n", a2);
}

original_code:
void xmlmsg_close_tag(string msg, string tag)
{
 sprintf(msg + strlen(msg), "</%s>\n", tag);
}

canonical_original_code:
void xmlmsg_close_tag(char *msg, char *tag)
{
 sprintf(msg + strlen(msg), "</%s>\n", tag);
}


decompiled_code:
int __fastcall xmlmsg_open_method_response(const char *a1)
{
xmlmsg_open_tag(a1, "methodResponse");
xmlmsg_open_tag(a1, "params");
xmlmsg_open_tag(a1, "param");
xmlmsg_open_tag(a1, "value");
xmlmsg_open_tag(a1, "array");
return xmlmsg_open_tag(a1, "data");
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
func1(a1, "methodResponse");
func1(a1, "params");
func1(a1, "param");
func1(a1, "value");
func1(a1, "array");
return func1(a1, "data");
}

original_code:
void xmlmsg_open_method_response(string msg)
{
 xmlmsg_open_tag(msg, "methodResponse");
  xmlmsg_open_tag(msg, "params");
   xmlmsg_open_tag(msg, "param");
    xmlmsg_open_tag(msg, "value");
     xmlmsg_open_tag(msg, "array");
      xmlmsg_open_tag(msg, "data");
}

canonical_original_code:
void xmlmsg_open_method_response(char *msg)
{
 xmlmsg_open_tag(msg, "methodResponse");
  xmlmsg_open_tag(msg, "params");
   xmlmsg_open_tag(msg, "param");
    xmlmsg_open_tag(msg, "value");
     xmlmsg_open_tag(msg, "array");
      xmlmsg_open_tag(msg, "data");
}


decompiled_code:
int __fastcall xmlmsg_close_method_response(const char *a1)
{
xmlmsg_close_tag(a1, "data");
xmlmsg_close_tag(a1, "array");
xmlmsg_close_tag(a1, "value");
xmlmsg_close_tag(a1, "param");
xmlmsg_close_tag(a1, "params");
return xmlmsg_close_tag(a1, "methodResponse");
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
func5(a1, "data");
func5(a1, "array");
func5(a1, "value");
func5(a1, "param");
func5(a1, "params");
return func5(a1, "methodResponse");
}

original_code:
void xmlmsg_close_method_response(string msg)
{
      xmlmsg_close_tag(msg, "data");
     xmlmsg_close_tag(msg, "array");
    xmlmsg_close_tag(msg, "value");
   xmlmsg_close_tag(msg, "param");
  xmlmsg_close_tag(msg, "params");
 xmlmsg_close_tag(msg, "methodResponse");
}

canonical_original_code:
void xmlmsg_close_method_response(char *msg)
{
      xmlmsg_close_tag(msg, "data");
     xmlmsg_close_tag(msg, "array");
    xmlmsg_close_tag(msg, "value");
   xmlmsg_close_tag(msg, "param");
  xmlmsg_close_tag(msg, "params");
 xmlmsg_close_tag(msg, "methodResponse");
}


decompiled_code:
int __fastcall tcpmsg_add_field(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebp
int v5; // ebp
int result; // eax

v4 = strlen(a2);
v5 = v4 + strlen(a3) + 1;
**(_DWORD **)a1 = v5;
result = sprintf((char *)(*(_QWORD *)a1 + 4LL), "%s=%s", a2, a3);
*(_QWORD *)a1 += v5 + 4LL;
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebp
int v5; // ebp
int result; // eax

v4 = strlen(a2);
v5 = v4 + strlen(a3) + 1;
**(_DWORD **)a1 = v5;
result = sprintf((char *)(*(_QWORD *)a1 + 4LL), "%s=%s", a2, a3);
*(_QWORD *)a1 += v5 + 4LL;
return result;
}

original_code:
void tcpmsg_add_field(char **buf, string name, const char* value)
{
 int field_len = strlen(name) + strlen(value) + 1;
 memcpy(*buf,(char*)&field_len, 4);
 sprintf(*buf + 4,"%s=%s", name, value);
 *buf += field_len + 4;
}

canonical_original_code:
void tcpmsg_add_field(char **buf, char *name, char *value)
{
 int field_len = strlen(name) + strlen(value) + 1;
 memcpy(*buf,(char *)&field_len, 4);
 sprintf(*buf + 4,"%s=%s", name, value);
 *buf += field_len + 4;
}

variable_types:
buf
char **


decompiled_code:
void *__fastcall tcpmsg_add_raw_data(void **a1, const void *a2, int a3)
{
__int64 v3; // rbp
void *result; // rax

v3 = a3;
result = memcpy(*a1, a2, a3);
*a1 = (char *)*a1 + v3;
return result;
}

canonical_decompiled_code:
void *__fastcall func11(void **a1, const void *a2, int a3)
{
__int64 v3; // rbp
void *result; // rax

v3 = a3;
result = memcpy(*a1, a2, a3);
*a1 = (char *)*a1 + v3;
return result;
}

original_code:
void tcpmsg_add_raw_data(char **buf, const void* data, int data_len)
{
 memcpy(*buf, data, data_len);
 *buf += data_len;
}

canonical_original_code:
void tcpmsg_add_raw_data(char **buf, void *data, int data_len)
{
 memcpy(*buf, data, data_len);
 *buf += data_len;
}

variable_types:
data
void *


decompiled_code:
int __fastcall listener_callback(const char **a1)
{
return printf("I heard: [%s]\n", *a1);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
return printf("I heard: [%s]\n", *a1);
}

original_code:
void listener_callback(const std_msgs__string* msg)
{
 printf("I heard: [%s]\n", msg->data);
}

canonical_original_code:
void listener_callback(struct std_msgs__string *msg)
{
 printf("I heard: [%s]\n", msg->data);
}

variable_types: struct std_msgs__string { char *data; } *


decompiled_code:
__int64 sigint_handler()
{
return pico_ros_request_shutdown();
}

canonical_decompiled_code:
__int64 func1()
{
return pico_ros_request_shutdown();
}

original_code:
void sigint_handler(int sig)
{
 pico_ros_request_shutdown();
}

variable_types: sig int


decompiled_code:
__int64 __fastcall serialize_std_msgs__byte(__int64 a1, char *a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
char v4[9]; // [rsp+Fh] [rbp-9h] BYREF

v4[0] = *a2;
v3 = a1;
tcpmsg_init(&v3);
tcpmsg_add_raw_data(&v3, v4, 1LL);
tcpmsg_finalize(a1, v3 - a1);
return v3 - a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
char v4[9]; // [rsp+Fh] [rbp-9h] BYREF

v4[0] = *a2;
v3 = a1;
tcpmsg_init(&v3);
tcpmsg_add_raw_data(&v3, v4, 1LL);
tcpmsg_finalize(a1, v3 - a1);
return v3 - a1;
}

original_code:
int serialize_std_msgs__byte(char* const buf, const void* msg)
{
 uint8_t data = ((std_msgs__byte*)msg)->data;
 char* iter = buf;
 tcpmsg_init(&iter);
 tcpmsg_add_raw_data(&iter, &data, 1);;
 tcpmsg_finalize(buf, iter - buf);
 return iter-buf;
}

canonical_original_code:
int serialize_std_msgs__byte(char *buf, void *msg)
{
 unsigned char data = ((std_msgs__byte*)msg)->data;
 char *iter = buf;
 tcpmsg_init(&iter);
 tcpmsg_add_raw_data(&iter, &data, 1);;
 tcpmsg_finalize(buf, iter - buf);
 return iter-buf;
}

variable_types:
buf
char *

variable_types:
msg
void *

variable_types:
data
unsigned char

variable_types:
iter
char *


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

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

original_code:
void free_std_msgs__byte(void* msg)
{
 if(msg != ((void *)0)) free(msg);
}

canonical_original_code:
void free_std_msgs__byte(void *msg)
{
 if(msg != ((void *)0)) free(msg);
}


decompiled_code:
char **__fastcall services_get_type(const char *a1)
{
char **result; // rax

result = supported_srvs;
if ( strcmp("roscpp_tutorials/TwoInts", a1) )
result = 0LL;
return result;
}

canonical_decompiled_code:
char **__fastcall func0(const char *a1)
{
char **result; // rax

result = supported_srvs;
if ( strcmp("roscpp_tutorials/TwoInts", a1) )
result = 0LL;
return result;
}

original_code:
const service_type_t* services_get_type(string type)
{
 int i;
 for(i = 0; i < ( 1 ); ++i)
 {
  if(strcmp(supported_srvs[i].type, type) == 0)
  {
   return supported_srvs + i;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct service_type_t *services_get_type(char *type)
{
 int i;
 for(i = 0; i < ( 1 ); ++i)
 {
  if(strcmp(supported_srvs[i].type, type) == 0)
  {
   return supported_srvs + i;
  }
 }
 return ((void *)0);
}

variable_types:
type
char *

variable_types: i int

return_type: struct service_type_t { char *type; char *md5sum; int (*serialize_req)(char *, void *); void *(*deserialize_req)(char *); int (*serialize_resp)(char *, void *); void (*deserialize_resp)(char *, void *); void (*free_srv)(void *srv); } *


canonical_original_code:
void sigint_handler(int sig)
{
 pico_ros_request_shutdown();
}


main

canonical_name: main

repo: RoboticsatUCD/SUMOcode

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

v3 = time(0LL);
srand(v3);
add_robot(&robot1, 0LL);
add_robot(&robot2, 0LL);
start_simulator();
return 0;
}

original_code:
int main()
{
 srand(time(((void *)0)));
 add_robot(robot1, ((void *)0));
 add_robot(robot2, ((void *)0));
 start_simulator();
 return 0;
}


original_code:
void set_active_wheels(uint8 wheels)
{
 robot_t * robot = get_robot();
 const double v = 10.0;
 const double rotv = 45.0;
 int num_active_wheels = (wheels & 1) + ((wheels & 2) >> 1)
  + ((wheels & 4) >> 2) + ((wheels & 8) >> 3);
 robot->rotv = robot->v = 0.0;
 if(wheels & FRONT_LEFT)
 {
  robot->v += v;
  robot->rotv -= rotv;
 }
 if(wheels & FRONT_RIGHT)
 {
  robot->v += v;
  robot->rotv += rotv;
 }
 if(wheels & BACK_LEFT)
 {
  robot->v += v;
  robot->rotv -= rotv;
 }
 if(wheels & BACK_RIGHT)
 {
  robot->v += v;
  robot->rotv += rotv;
 }
 robot->v *= num_active_wheels / 4.0;
}

canonical_original_code:
void set_active_wheels(unsigned char wheels)
{
 struct robot_t *robot = get_robot();
 double v = 10.0;
 double rotv = 45.0;
 int num_active_wheels = (wheels & 1) + ((wheels & 2) >> 1)
  + ((wheels & 4) >> 2) + ((wheels & 8) >> 3);
 robot->rotv = robot->v = 0.0;
 if(wheels & FRONT_LEFT)
 {
  robot->v += v;
  robot->rotv -= rotv;
 }
 if(wheels & FRONT_RIGHT)
 {
  robot->v += v;
  robot->rotv += rotv;
 }
 if(wheels & BACK_LEFT)
 {
  robot->v += v;
  robot->rotv -= rotv;
 }
 if(wheels & BACK_RIGHT)
 {
  robot->v += v;
  robot->rotv += rotv;
 }
 robot->v *= num_active_wheels / 4.0;
}

variable_types:
wheels
unsigned char

variable_types: struct robot_t { struct point_t { double x; } pos; double v; double rot; double rotv; double width; double mass; struct color_t { unsigned char r; } color; } *

variable_types: v double

variable_types: rotv double

user_defined_types: struct robot_t { struct point_t pos; double v; double rot; double rotv; double width; double mass; struct color_t color; }


decompiled_code:
int __fastcall sleep_us(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_nsec = 1000 * (a1 % 0xF4240);
return nanosleep(&v2, &v2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_nsec = 1000 * (a1 % 0xF4240);
return nanosleep(&v2, &v2);
}

original_code:
void sleep_us(uint32 us)
{
 struct timespec t;
 t.tv_sec = us / 1000000;
 t.tv_nsec = 1000 * (us % 1000000);
 nanosleep(&t, &t);
}

canonical_original_code:
void sleep_us(unsigned int us)
{
 struct timespec t;
 t.tv_sec = us / 1000000;
 t.tv_nsec = 1000 * (us % 1000000);
 nanosleep(&t, &t);
}

variable_types:
us
unsigned int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int init_robot()
{
return sleep_us(0x1E8480u);
}

canonical_decompiled_code:
int func2()
{
return func1(0x1E8480u);
}


decompiled_code:
__int64 fake_line_sensor_reading()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = magnitude();
result = 0LL;
if ( v0 <= 79.5 )
{
LOBYTE(result) = v0 >= 74.5;
result = (unsigned int)-(int)result;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = magnitude();
result = 0LL;
if ( v0 <= 79.5 )
{
LOBYTE(result) = v0 >= 74.5;
result = (unsigned int)-(int)result;
}
return result;
}

original_code:
uint8 fake_line_sensor_reading(point_t pos)
{
 double d = magnitude(pos.x, pos.y);
 if(d <= 159.0 / 2.0 && d >= 159.0 / 2.0 - 5.0)
  return 255;
 else
  return 0;
}

canonical_original_code:
unsigned char fake_line_sensor_reading(struct point_t pos)
{
 double d = magnitude(pos.x, pos.y);
 if(d <= 159.0 / 2.0 && d >= 159.0 / 2.0 - 5.0)
  return 255;
 else
  return 0;
}

variable_types:
pos
struct point_t { double x; }

variable_types: d double


decompiled_code:
__int64 __fastcall read_line_sensors(_BYTE *a1)
{
__int64 v1; // rbx
double v2; // xmm0_8
__int64 result; // rax

v1 = get_robot();
v2 = 0.5 * *(double *)(v1 + 40);
offset_from_robot(v1, COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8), v2);
*a1 = fake_line_sensor_reading();
offset_from_robot(v1, v2, v2);
a1[1] = fake_line_sensor_reading();
offset_from_robot(v1, COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8), COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8));
a1[2] = fake_line_sensor_reading();
offset_from_robot(v1, v2, COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8));
result = fake_line_sensor_reading();
a1[3] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
__int64 v1; // rbx
double v2; // xmm0_8
__int64 result; // rax

v1 = get_robot();
v2 = 0.5 * *(double *)(v1 + 40);
offset_from_robot(v1, COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8), v2);
*a1 = func3();
offset_from_robot(v1, v2, v2);
a1[1] = func3();
offset_from_robot(v1, COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8), COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8));
a1[2] = func3();
offset_from_robot(v1, v2, COERCE_DOUBLE(*(_QWORD *)&v2 ^ LC8));
result = func3();
a1[3] = result;
return result;
}

original_code:
void read_line_sensors(line_sensor_readings_t * readings)
{
 robot_t * robot = get_robot();
 double half_width = robot->width / 2.0;
 readings->front_left = fake_line_sensor_reading(
  offset_from_robot(robot, -half_width, half_width));
 readings->front_right = fake_line_sensor_reading(
  offset_from_robot(robot, half_width, half_width));
 readings->back_left = fake_line_sensor_reading(
  offset_from_robot(robot, -half_width, -half_width));
 readings->back_right = fake_line_sensor_reading(
  offset_from_robot(robot, half_width, -half_width));
}

canonical_original_code:
void read_line_sensors(struct line_sensor_readings_t *readings)
{
 struct robot_t *robot = get_robot();
 double half_width = robot->width / 2.0;
 readings->front_left = fake_line_sensor_reading(
  offset_from_robot(robot, -half_width, half_width));
 readings->front_right = fake_line_sensor_reading(
  offset_from_robot(robot, half_width, half_width));
 readings->back_left = fake_line_sensor_reading(
  offset_from_robot(robot, -half_width, -half_width));
 readings->back_right = fake_line_sensor_reading(
  offset_from_robot(robot, half_width, -half_width));
}

variable_types: struct line_sensor_readings_t { unsigned char front_left; unsigned char front_right; unsigned char back_left; unsigned char back_right; } *


decompiled_code:
void __noreturn robot1()
{
char v0[12]; // [rsp+Ch] [rbp-Ch] BYREF

init_robot();
while ( 1 )
{
read_line_sensors(v0);
set_active_wheels(15LL);
while ( v0[0] >= 0 )
read_line_sensors(v0);
set_active_wheels(10LL);
sleep_us(1000000LL);
}
}

canonical_decompiled_code:
void __noreturn func0()
{
char v0[12]; // [rsp+Ch] [rbp-Ch] BYREF

init_robot();
while ( 1 )
{
read_line_sensors(v0);
set_active_wheels(15LL);
while ( v0[0] >= 0 )
read_line_sensors(v0);
set_active_wheels(10LL);
sleep_us(1000000LL);
}
}

original_code:
void robot1()
{
 line_sensor_readings_t line_sensors;
 init_robot();
 for(;;)
 {
  read_line_sensors(&line_sensors);
  set_active_wheels(ALL);
  for(; line_sensors.front_left < 128; read_line_sensors(&line_sensors));
  set_active_wheels(RIGHT);
  sleep_us(1 * 1000 * 1000);
 }
}

canonical_original_code:
void robot1()
{
 struct line_sensor_readings_t line_sensors;
 init_robot();
 for(;;)
 {
  read_line_sensors(&line_sensors);
  set_active_wheels(ALL);
  for(; line_sensors.front_left < 128; read_line_sensors(&line_sensors));
  set_active_wheels(RIGHT);
  sleep_us(1 * 1000 * 1000);
 }
}

variable_types: struct line_sensor_readings_t { unsigned char front_left; unsigned char front_right; unsigned char back_left; unsigned char back_right; }


decompiled_code:
void __noreturn robot2()
{
char v0[12]; // [rsp+Ch] [rbp-Ch] BYREF

init_robot();
while ( 1 )
{
read_line_sensors(v0);
set_active_wheels(15LL);
while ( v0[0] >= 0 )
read_line_sensors(v0);
set_active_wheels(5LL);
while ( v0[0] > 0x80u )
read_line_sensors(v0);
if ( v0[0] >= 0 )
{
do
read_line_sensors(v0);
while ( v0[0] >= 0 );
while ( v0[0] > 0x80u )
read_line_sensors(v0);
}
}
}

canonical_decompiled_code:
void __noreturn func1()
{
char v0[12]; // [rsp+Ch] [rbp-Ch] BYREF

init_robot();
while ( 1 )
{
read_line_sensors(v0);
set_active_wheels(15LL);
while ( v0[0] >= 0 )
read_line_sensors(v0);
set_active_wheels(5LL);
while ( v0[0] > 0x80u )
read_line_sensors(v0);
if ( v0[0] >= 0 )
{
do
read_line_sensors(v0);
while ( v0[0] >= 0 );
while ( v0[0] > 0x80u )
read_line_sensors(v0);
}
}
}

original_code:
void robot2()
{
 line_sensor_readings_t line_sensors;
 init_robot();
 for(;;)
 {
  read_line_sensors(&line_sensors);
  set_active_wheels(ALL);
  for(; line_sensors.front_left < 128; read_line_sensors(&line_sensors));
  set_active_wheels(LEFT);
  for(; line_sensors.front_left > 128; read_line_sensors(&line_sensors));
  for(; line_sensors.front_left < 128; read_line_sensors(&line_sensors));
  for(; line_sensors.front_left > 128; read_line_sensors(&line_sensors));
 }
}

canonical_original_code:
void robot2()
{
 struct line_sensor_readings_t line_sensors;
 init_robot();
 for(;;)
 {
  read_line_sensors(&line_sensors);
  set_active_wheels(ALL);
  for(; line_sensors.front_left < 128; read_line_sensors(&line_sensors));
  set_active_wheels(LEFT);
  for(; line_sensors.front_left > 128; read_line_sensors(&line_sensors));
  for(; line_sensors.front_left < 128; read_line_sensors(&line_sensors));
  for(; line_sensors.front_left > 128; read_line_sensors(&line_sensors));
 }
}

user_defined_types: struct line_sensor_readings_t { unsigned char front_left; unsigned char front_right; unsigned char back_left; unsigned char back_right; }


repo: Robotregent/system-soft

decompiled_code:
void __fastcall create_cluster(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)a1 = get_cluster;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)a1 = get_cluster;
}

original_code:
static void create_cluster (struct profile * p)
{
 p->status[0] = 0;
 p->status[1] = 0;
 p->get = &get_cluster;
}

canonical_original_code:
static void create_cluster(struct profile *p)
{
 p->status[0] = 0;
 p->status[1] = 0;
 p->get = &get_cluster;
}

variable_types: struct profile { int (*get)(struct profile *p); int status[10]; } *


original_code:
static int get_increase (struct profile * p)
{
 if (!p->status[0]) {
  p->status[0] = 5000;
  p->status[1] += 8;
  if (p->status[1] > 256)
   p->status[1] = 8;
 }
 p->status[0]--;
 return p->status[1];
}

canonical_original_code:
static int get_increase(struct profile *p)
{
 if (!p->status[0]) {
  p->status[0] = 5000;
  p->status[1] += 8;
  if (p->status[1] > 256)
   p->status[1] = 8;
 }
 p->status[0]--;
 return p->status[1];
}

user_defined_types: struct profile { int (*get)(struct profile *p); int status[10]; }


original_code:
static int get_decrease (struct profile * p)
{
 if (!p->status[0]) {
  p->status[0] = 5000;
  p->status[1] -= 8;
  if (p->status[1] < 8)
   p->status[1] = 256;
 }
 p->status[0]--;
 return p->status[1];
}

canonical_original_code:
static int get_decrease(struct profile *p)
{
 if (!p->status[0]) {
  p->status[0] = 5000;
  p->status[1] -= 8;
  if (p->status[1] < 8)
   p->status[1] = 256;
 }
 p->status[0]--;
 return p->status[1];
}


decompiled_code:
void __fastcall create_increase(__int64 a1)
{
*(_QWORD *)a1 = get_increase;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
*(_QWORD *)a1 = get_increase;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
static void create_increase (struct profile * p)
{
 p->get = &get_increase;
 p->status[0] = p->status[1] = 0;
}

canonical_original_code:
static void create_increase(struct profile *p)
{
 p->get = &get_increase;
 p->status[0] = p->status[1] = 0;
}


decompiled_code:
void __fastcall create_decrease(__int64 a1)
{
*(_QWORD *)a1 = get_decrease;
*(_DWORD *)(a1 + 8) = 5000;
*(_DWORD *)(a1 + 12) = 256;
}

original_code:
static void create_decrease (struct profile * p)
{
 p->get = &get_decrease;
 p->status[0] = 5000;
 p->status[1] = 256;
}

canonical_original_code:
static void create_decrease(struct profile *p)
{
 p->get = &get_decrease;
 p->status[0] = 5000;
 p->status[1] = 256;
}


decompiled_code:
__int64 __fastcall get_fixed(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

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

original_code:
static int get_fixed (struct profile * p)
{
 return p->status[0];
}

canonical_original_code:
static int get_fixed(struct profile *p)
{
 return p->status[0];
}


decompiled_code:
void __fastcall create_fixed8(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 8;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 8;
}

original_code:
static void create_fixed8 (struct profile * p)
{
 p->get = &get_fixed;
 p->status[0] = 8;
}

canonical_original_code:
static void create_fixed8(struct profile *p)
{
 p->get = &get_fixed;
 p->status[0] = 8;
}


decompiled_code:
void __fastcall create_fixed16(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 16;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 16;
}

original_code:
static void create_fixed16 (struct profile * p)
{
 p->get = &get_fixed;
 p->status[0] = 16;
}

canonical_original_code:
static void create_fixed16(struct profile *p)
{
 p->get = &get_fixed;
 p->status[0] = 16;
}


decompiled_code:
void __fastcall create_fixed24(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 24;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 24;
}

original_code:
static void create_fixed24 (struct profile * p)
{
 p->get = &get_fixed;
 p->status[0] = 24;
}

canonical_original_code:
static void create_fixed24(struct profile *p)
{
 p->get = &get_fixed;
 p->status[0] = 24;
}


decompiled_code:
void __fastcall create_fixed104(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 104;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 104;
}

original_code:
static void create_fixed104 (struct profile * p)
{
 p->get = &get_fixed;
 p->status[0] = 104;
}

canonical_original_code:
static void create_fixed104(struct profile *p)
{
 p->get = &get_fixed;
 p->status[0] = 104;
}


decompiled_code:
void __fastcall create_fixed200(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 200;
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
*(_QWORD *)a1 = get_fixed;
*(_DWORD *)(a1 + 8) = 200;
}

original_code:
static void create_fixed200 (struct profile * p)
{
 p->get = &get_fixed;
 p->status[0] = 200;
}

canonical_original_code:
static void create_fixed200(struct profile *p)
{
 p->get = &get_fixed;
 p->status[0] = 200;
}


original_code:
static int get_cluster (struct profile * p)
{
 if (p->status[0] == 0) {
  p->status[0] = 1+lrand48 () % 1000;
  if (lrand48 () % 2) {
   p->status[1] = -1;
  } else {
   p->status[1] = 1;
  }
 }
 p->status[0]--;
 return p->status[1];
}

canonical_original_code:
static int get_cluster(struct profile *p)
{
 if (p->status[0] == 0) {
  p->status[0] = 1+lrand48 () % 1000;
  if (lrand48 () % 2) {
   p->status[1] = -1;
  } else {
   p->status[1] = 1;
  }
 }
 p->status[0]--;
 return p->status[1];
}


decompiled_code:
__int64 get_oneinthree()
{
return lrand48() % 3 == 0 ? -1 : 1;
}

original_code:
static int get_oneinthree (struct profile * p)
{
 if (lrand48() % 3) {
  return 1;
 }
 return -1;
}

canonical_original_code:
static int get_oneinthree(struct profile *p)
{
 if (lrand48() % 3) {
  return 1;
 }
 return -1;
}


decompiled_code:
__int64 get_uniform()
{
return 8 * (unsigned int)(lrand48() % 32) + 8;
}

canonical_decompiled_code:
__int64 func16()
{
return 8 * (unsigned int)(lrand48() % 32) + 8;
}

original_code:
static int get_uniform (struct profile * p)
{
 return 8 + 8 * (lrand48()%32);
}

canonical_original_code:
static int get_uniform(struct profile *p)
{
 return 8 + 8 * (lrand48()%32);
}


decompiled_code:
__int64 get_normal1()
{
__int64 v0; // rbx
__int64 v1; // kr00_8
int v2; // eax

v0 = lrand48();
v1 = (int)(v0 % 32 + lrand48() % 32 - 31);
v2 = (HIDWORD(v1) ^ v1) - HIDWORD(v1);
if ( (unsigned int)(8 * v2) > 0xF8 )
_assert_fail("8 <= val && val <= 256", "testit.c", 0x78u, "get_normal1");
return (unsigned int)(8 * v2 + 8);
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // rbx
__int64 v1; // kr00_8
int v2; // eax

v0 = lrand48();
v1 = (int)(v0 % 32 + lrand48() % 32 - 31);
v2 = (HIDWORD(v1) ^ v1) - HIDWORD(v1);
if ( (unsigned int)(8 * v2) > 0xF8 )
_assert_fail("8 <= val && val <= 256", "testit.c", 0x78u, "get_normal1");
return (unsigned int)(8 * v2 + 8);
}

original_code:
int get_normal1 (struct profile * p)
{
 int val = -31 + lrand48() % 32 + lrand48()%32;
 if (val < 0)
  val = -val;
 val = 8 + 8*val;
 ((void) sizeof ((8 <= val && val <= 256) ? 1 : 0), __extension__ ({ if (8 <= val && val <= 256) ; else __assert_fail ("8 <= val && val <= 256", "testit.c", 120, __extension__ __PRETTY_FUNCTION__); }));
 return val;
}

canonical_original_code:
int get_normal1(struct profile *p)
{
 int val = -31 + lrand48() % 32 + lrand48()%32;
 if (val < 0)
  val = -val;
 val = 8 + 8*val;
 ((void) sizeof ((8 <= val && val <= 256) ? 1 : 0), __extension__ ({ if (8 <= val && val <= 256) ; else __assert_fail ("8 <= val && val <= 256", "testit.c", 120, __extension__ __PRETTY_FUNCTION__); }));
 return val;
}

variable_types: val int


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
__int64 v1; // rbx
char **v2; // rbx

fprintf(stderr, "usage: %s seed count [ size_profile alloc_profile ]\n", a1);
fwrite(" Known size profiles:", 1uLL, 0x16uLL, stderr);
if ( size_profiles )
{
v1 = (unsigned int)((_DWORD)&size_profiles + 16);
do
{
fprintf(stderr, off_16E9017);
v1 += 16LL;
}
while ( *(_QWORD *)(v1 - 16) );
}
putchar(10);
fwrite(" Known alloc profiles:", 1uLL, 0x17uLL, stderr);
if ( alloc_profiles )
{
v2 = &alloc_profiles;
do
{
fprintf(stderr, off_16E9017);
v2 += 2;
}
while ( *v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func18(const char *a1)
{
__int64 v1; // rbx
char **v2; // rbx

fprintf(stderr, "usage: %s seed count [ size_profile alloc_profile ]\n", a1);
fwrite(" Known size profiles:", 1uLL, 0x16uLL, stderr);
if ( size_profiles )
{
v1 = (unsigned int)((_DWORD)&size_profiles + 16);
do
{
fprintf(stderr, off_16E9017);
v1 += 16LL;
}
while ( *(_QWORD *)(v1 - 16) );
}
putchar(10);
fwrite(" Known alloc profiles:", 1uLL, 0x17uLL, stderr);
if ( alloc_profiles )
{
v2 = &alloc_profiles;
do
{
fprintf(stderr, off_16E9017);
v2 += 2;
}
while ( *v2 );
}
return putchar(10);
}

original_code:
void usage (char * prog) {
 int i;
 fprintf (stderr, "usage: %s seed count [ size_profile alloc_profile ]\n", prog);
 fprintf (stderr, "  Known size profiles:");
 for (i=0; size_profiles[i].name; ++i) {
  fprintf (stderr, " %s", size_profiles[i].name);
 }
 printf ("\n");
 fprintf (stderr, "  Known alloc profiles:");
 for (i=0; alloc_profiles[i].name; ++i) {
  fprintf (stderr, " %s", alloc_profiles[i].name);
 }
 printf ("\n");
}

canonical_original_code:
void usage(char *prog) {
 int i;
 fprintf (stderr, "usage: %s seed count [ size_profile alloc_profile ]\n", prog);
 fprintf (stderr, "  Known size profiles:");
 for (i=0; size_profiles[i].name; ++i) {
  fprintf (stderr, " %s", size_profiles[i].name);
 }
 printf ("\n");
 fprintf (stderr, "  Known alloc profiles:");
 for (i=0; alloc_profiles[i].name; ++i) {
  fprintf (stderr, " %s", alloc_profiles[i].name);
 }
 printf ("\n");
}

variable_types:
prog
char *


decompiled_code:
__int64 __fastcall get_idx(const char **a1, const char *a2)
{
const char *v3; // rdi
const char **v4; // rbx
unsigned int v5; // ebp

v3 = *a1;
if ( !v3 )
return (unsigned int)-1;
v4 = a1 + 2;
v5 = 0;
while ( strcasecmp(v3, a2) )
{
++v5;
v4 += 2;
v3 = *(v4 - 2);
if ( !v3 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func19(const char **a1, const char *a2)
{
const char *v3; // rdi
const char **v4; // rbx
unsigned int v5; // ebp

v3 = *a1;
if ( !v3 )
return (unsigned int)-1;
v4 = a1 + 2;
v5 = 0;
while ( strcasecmp(v3, a2) )
{
++v5;
v4 += 2;
v3 = *(v4 - 2);
if ( !v3 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int get_idx (struct profile_list * l, char * name)
{
 int i;
 for (i=0; l[i].name; ++i) {
  if (strcasecmp (l[i].name, name) == 0)
   return i;
 }
 return -1;
}

canonical_original_code:
int get_idx(struct profile_list *l, char *name)
{
 int i;
 for (i=0; l[i].name; ++i) {
  if (strcasecmp (l[i].name, name) == 0)
   return i;
 }
 return -1;
}

variable_types: struct profile_list { char *name; void (*create)(struct profile { int (*get)(struct profile *p); int status[10]; } *p); } *

variable_types:
name
char *

user_defined_types: struct profile_list { char *name; void (*create)(struct profile *p); }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
char *v4; // rbx
int v5; // ebp
int v6; // eax
int v7; // er12
int v8; // ebx
int v10; // er12
int v11; // eax
int v12; // er14
int v13; // ebx
int v14; // eax
int v15; // eax
int v16; // er12
__int64 v17; // rbp
int v18; // edx
int v19; // eax
__int64 v20; // r13
int v21; // er14
__int64 v22; // rcx
char *v23; // rsi
void *v24; // rbp
_QWORD *v25; // r12
__int64 v26; // rbp
__int64 v27; // r13
int v28; // er15
char *v29; // r13
__int64 v30; // r12
__int64 v31; // rsi
__int64 v32; // rdx
__int64 v33; // rax
unsigned int v34; // eax
int v35; // eax
double v36; // xmm0_8
__int64 v37; // [rsp+0h] [rbp-D8h]
double v38; // [rsp+0h] [rbp-D8h]
void *v39; // [rsp+8h] [rbp-D0h]
double v40; // [rsp+8h] [rbp-D0h]
struct timeval tv; // [rsp+10h] [rbp-C8h] BYREF
struct timeval v42; // [rsp+20h] [rbp-B8h] BYREF
__int64 v43[6]; // [rsp+30h] [rbp-A8h] BYREF
__int64 v44[6]; // [rsp+60h] [rbp-78h] BYREF
int v45; // [rsp+90h] [rbp-48h] BYREF
char v46; // [rsp+97h] [rbp-41h] BYREF
__int64 seedval; // [rsp+98h] [rbp-40h] BYREF

init_my_alloc(argc, argv, envp);
areas = create_avl();
v3 = open("/dev/urandom", 0);
v4 = (char *)&randdata;
v5 = 20000;
if ( v3 < 0 )
{
perror("open");
v8 = 1;
}
else
{
do
{
v6 = read(v3, v4, v5);
if ( v6 <= 0 )
{
perror("read");
return 1;
}
v4 += v6;
v5 -= v6;
}
while ( v5 );
if ( argc <= 2 )
{
usage(*argv);
v8 = 1;
}
else
{
v7 = _isoc99_sscanf(argv[1], "%ld%c", &seedval, &v46);
if ( v7 != 1 )
{
usage(*argv);
return 1;
}
v8 = _isoc99_sscanf(argv[2], "%d%c", &v45, &v46);
if ( v8 == 1 )
{
if ( argc <= 3 )
{
v10 = 0;
v12 = 0;
}
else if ( argc != 5
|| (v10 = get_idx((const char **)&size_profiles, argv[3]),
v11 = get_idx((const char **)&alloc_profiles, argv[4]),
v12 = v11,
v10 < 0)
|| v11 < 0 )
{
usage(*argv);
return v8;
}
srand48(seedval);
((void (__fastcall *)(__int64 *))(&size_profiles)[2 * v10 + 1])(v43);
((void (__fastcall *)(__int64 *))(&alloc_profiles)[2 * v12 + 1])(v44);
v37 = 0LL;
while ( 1 )
{
if ( v45 <= v5 )
{
v8 = nptr;
if ( !nptr )
break;
}
v13 = v5 + 1;
if ( v13 == 10000 * (v13 / 10000) )
{
putchar(46);
if ( v13 == 100000 * (v13 / 100000) )
putchar(10);
fflush(stdout);
}
v14 = ((__int64 (__fastcall *)(__int64 *))v44[0])(v44);
if ( v45 <= v5 || nptr && v14 <= 0 )
{
v26 = lrand48() % nptr;
v27 = lrand48() % 19500;
if ( memcmp(*(&data + 3 * (int)v26), *(&s2 + 3 * (int)v26), *((int *)&data + 6 * (int)v26 + 2)) )
_my_assert("Allokierter Speicherbereich wurde zwischenzeitlich veraendert");
v28 = *((_DWORD *)&data + 6 * (int)v26 + 2);
v29 = (char *)&randdata + (int)v27;
v39 = *(&data + 3 * (int)v26);
memcpy(v39, v29, v28);
*(&s2 + 3 * (int)v26) = v29;
alloc -= v28;
--nalloc;
gettimeofday(&tv, 0LL);
my_free(v39);
gettimeofday(&v42, 0LL);
v37 += v42.tv_usec + 1000000 * (v42.tv_sec - tv.tv_sec) - tv.tv_usec;
v30 = (__int64)*(&data + 3 * (int)v26);
v31 = find_avl(areas, v30);
if ( *(_QWORD *)(v31 + 40) != v30 )
_assert_fail("n->start == ptr", "testit.c", 0x166u, "main");
if ( *(_QWORD *)(v31 + 48) != *((_DWORD *)&data + 6 * (int)v26 + 2) )
_assert_fail("n->len == data[idx].len", "testit.c", 0x167u, "main");
remove_avl(&areas);
--nptr;
v32 = 3LL * (int)v26;
v33 = 3LL * nptr;
*(__m128i *)(&data + v32) = _mm_loadu_si128((const __m128i *)(&data + 3 * nptr));
*(&s2 + v32) = *(&s2 + v33);
}
else
{
v15 = ((__int64 (__fastcall *)(__int64 *))v43[0])(v43);
v16 = v15;
if ( !v15 || (v15 & 7) != 0 )
_assert_fail("sz && sz % 8 == 0", "testit.c", 0x11Bu, "main");
v17 = lrand48() % 19500;
if ( nptr > (int)&unk_F423F )
_my_assert("Anzahl der Operationen zu gross");
v18 = alloc + v16;
alloc += v16;
v19 = nalloc + 1;
nalloc = v19;
if ( v19 > maxnalloc )
maxnalloc = v19;
if ( v18 > maxalloc )
maxalloc = v18;
gettimeofday(&tv, 0LL);
v20 = v16;
v21 = nptr;
*(&data + 3 * v21) = (void *)my_alloc(v16);
gettimeofday(&v42, 0LL);
v37 += v42.tv_usec + 1000000 * (v42.tv_sec - tv.tv_sec) - tv.tv_usec;
v22 = 3LL * nptr;
*((_DWORD *)&data + 2 * v22 + 2) = v16;
v23 = (char *)&randdata + (int)v17;
*(&s2 + v22) = v23;
v24 = *(&data + v22);
memcpy(v24, v23, v16);
if ( !(unsigned int)valid_area(v24, v16) )
_my_assert(
"Speicher nicht auf einer 8 Byte Kante oder nicht in einem Block, den get_block_from_system geliefert hat");
v25 = (_QWORD *)find_avl(areas, v24);
if ( v25[5] + v25[6] > (unsigned __int64)v24 )
_my_assert("Ueberlappende Speicherbereiche");
if ( *v25 && *(_QWORD *)(*v25 + 40LL) < (unsigned __int64)v24 + v20 )
_my_assert("Ueberlappende Speicherbereiche");
insert_avl(&areas, v24, v20);
++nptr;
}
v5 = v13;
}
putchar(10);
v34 = get_sys_blockcount();
printf("%d %d %d %lld\n", (unsigned int)maxalloc, (unsigned int)maxnalloc, v34, v37);
v40 = (double)(int)get_sys_blockcount() * 8192.0 / (double)(maxalloc + 8 * maxnalloc) - 1.0;
v38 = (double)(int)v37 / (double)v5;
v35 = get_sys_blockcount();
printf("Relative size overhead: %lf\n", (double)v35 * 8192.0 / (double)(maxalloc + 8 * maxnalloc) - 1.0);
printf("Runtime per operation: %lf\n", v38);
v36 = 100.0 - (v38 + v38) - 100.0 * v40;
if ( v36 < 0.0 )
v36 = 0.0;
printf("Points for this test: %lf\n", v36);
}
else
{
usage(*argv);
v8 = v7;
}
}
}
return v8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
char *v4; // rbx
int v5; // ebp
int v6; // eax
int v7; // er12
int v8; // ebx
int v10; // er12
int v11; // eax
int v12; // er14
int v13; // ebx
int v14; // eax
int v15; // eax
int v16; // er12
__int64 v17; // rbp
int v18; // edx
int v19; // eax
__int64 v20; // r13
int v21; // er14
__int64 v22; // rcx
char *v23; // rsi
void *v24; // rbp
_QWORD *v25; // r12
__int64 v26; // rbp
__int64 v27; // r13
int v28; // er15
char *v29; // r13
__int64 v30; // r12
__int64 v31; // rsi
__int64 v32; // rdx
__int64 v33; // rax
unsigned int v34; // eax
int v35; // eax
double v36; // xmm0_8
__int64 v37; // [rsp+0h] [rbp-D8h]
double v38; // [rsp+0h] [rbp-D8h]
void *v39; // [rsp+8h] [rbp-D0h]
double v40; // [rsp+8h] [rbp-D0h]
struct timeval tv; // [rsp+10h] [rbp-C8h] BYREF
struct timeval v42; // [rsp+20h] [rbp-B8h] BYREF
__int64 v43[6]; // [rsp+30h] [rbp-A8h] BYREF
__int64 v44[6]; // [rsp+60h] [rbp-78h] BYREF
int v45; // [rsp+90h] [rbp-48h] BYREF
char v46; // [rsp+97h] [rbp-41h] BYREF
__int64 seedval; // [rsp+98h] [rbp-40h] BYREF

init_my_alloc(argc, argv, envp);
areas = create_avl();
v3 = open("/dev/urandom", 0);
v4 = (char *)&randdata;
v5 = 20000;
if ( v3 < 0 )
{
perror("open");
v8 = 1;
}
else
{
do
{
v6 = read(v3, v4, v5);
if ( v6 <= 0 )
{
perror("read");
return 1;
}
v4 += v6;
v5 -= v6;
}
while ( v5 );
if ( argc <= 2 )
{
func18(*argv);
v8 = 1;
}
else
{
v7 = _isoc99_sscanf(argv[1], "%ld%c", &seedval, &v46);
if ( v7 != 1 )
{
func18(*argv);
return 1;
}
v8 = _isoc99_sscanf(argv[2], "%d%c", &v45, &v46);
if ( v8 == 1 )
{
if ( argc <= 3 )
{
v10 = 0;
v12 = 0;
}
else if ( argc != 5
|| (v10 = func19((const char **)&size_profiles, argv[3]),
v11 = func19((const char **)&alloc_profiles, argv[4]),
v12 = v11,
v10 < 0)
|| v11 < 0 )
{
func18(*argv);
return v8;
}
srand48(seedval);
((void (__fastcall *)(__int64 *))(&size_profiles)[2 * v10 + 1])(v43);
((void (__fastcall *)(__int64 *))(&alloc_profiles)[2 * v12 + 1])(v44);
v37 = 0LL;
while ( 1 )
{
if ( v45 <= v5 )
{
v8 = nptr;
if ( !nptr )
break;
}
v13 = v5 + 1;
if ( v13 == 10000 * (v13 / 10000) )
{
putchar(46);
if ( v13 == 100000 * (v13 / 100000) )
putchar(10);
fflush(stdout);
}
v14 = ((__int64 (__fastcall *)(__int64 *))v44[0])(v44);
if ( v45 <= v5 || nptr && v14 <= 0 )
{
v26 = lrand48() % nptr;
v27 = lrand48() % 19500;
if ( memcmp(*(&data + 3 * (int)v26), *(&s2 + 3 * (int)v26), *((int *)&data + 6 * (int)v26 + 2)) )
_my_assert("Allokierter Speicherbereich wurde zwischenzeitlich veraendert");
v28 = *((_DWORD *)&data + 6 * (int)v26 + 2);
v29 = (char *)&randdata + (int)v27;
v39 = *(&data + 3 * (int)v26);
memcpy(v39, v29, v28);
*(&s2 + 3 * (int)v26) = v29;
alloc -= v28;
--nalloc;
gettimeofday(&tv, 0LL);
my_free(v39);
gettimeofday(&v42, 0LL);
v37 += v42.tv_usec + 1000000 * (v42.tv_sec - tv.tv_sec) - tv.tv_usec;
v30 = (__int64)*(&data + 3 * (int)v26);
v31 = find_avl(areas, v30);
if ( *(_QWORD *)(v31 + 40) != v30 )
_assert_fail("n->start == ptr", "testit.c", 0x166u, "main");
if ( *(_QWORD *)(v31 + 48) != *((_DWORD *)&data + 6 * (int)v26 + 2) )
_assert_fail("n->len == data[idx].len", "testit.c", 0x167u, "main");
remove_avl(&areas);
--nptr;
v32 = 3LL * (int)v26;
v33 = 3LL * nptr;
*(__m128i *)(&data + v32) = _mm_loadu_si128((const __m128i *)(&data + 3 * nptr));
*(&s2 + v32) = *(&s2 + v33);
}
else
{
v15 = ((__int64 (__fastcall *)(__int64 *))v43[0])(v43);
v16 = v15;
if ( !v15 || (v15 & 7) != 0 )
_assert_fail("sz && sz % 8 == 0", "testit.c", 0x11Bu, "main");
v17 = lrand48() % 19500;
if ( nptr > (int)&unk_F423F )
_my_assert("Anzahl der Operationen zu gross");
v18 = alloc + v16;
alloc += v16;
v19 = nalloc + 1;
nalloc = v19;
if ( v19 > maxnalloc )
maxnalloc = v19;
if ( v18 > maxalloc )
maxalloc = v18;
gettimeofday(&tv, 0LL);
v20 = v16;
v21 = nptr;
*(&data + 3 * v21) = (void *)my_alloc(v16);
gettimeofday(&v42, 0LL);
v37 += v42.tv_usec + 1000000 * (v42.tv_sec - tv.tv_sec) - tv.tv_usec;
v22 = 3LL * nptr;
*((_DWORD *)&data + 2 * v22 + 2) = v16;
v23 = (char *)&randdata + (int)v17;
*(&s2 + v22) = v23;
v24 = *(&data + v22);
memcpy(v24, v23, v16);
if ( !(unsigned int)valid_area(v24, v16) )
_my_assert(
"Speicher nicht auf einer 8 Byte Kante oder nicht in einem Block, den get_block_from_system geliefert hat");
v25 = (_QWORD *)find_avl(areas, v24);
if ( v25[5] + v25[6] > (unsigned __int64)v24 )
_my_assert("Ueberlappende Speicherbereiche");
if ( *v25 && *(_QWORD *)(*v25 + 40LL) < (unsigned __int64)v24 + v20 )
_my_assert("Ueberlappende Speicherbereiche");
insert_avl(&areas, v24, v20);
++nptr;
}
v5 = v13;
}
putchar(10);
v34 = get_sys_blockcount();
printf("%d %d %d %lld\n", (unsigned int)maxalloc, (unsigned int)maxnalloc, v34, v37);
v40 = (double)(int)get_sys_blockcount() * 8192.0 / (double)(maxalloc + 8 * maxnalloc) - 1.0;
v38 = (double)(int)v37 / (double)v5;
v35 = get_sys_blockcount();
printf("Relative size overhead: %lf\n", (double)v35 * 8192.0 / (double)(maxalloc + 8 * maxnalloc) - 1.0);
printf("Runtime per operation: %lf\n", v38);
v36 = 100.0 - (v38 + v38) - 100.0 * v40;
if ( v36 < 0.0 )
v36 = 0.0;
printf("Points for this test: %lf\n", v36);
}
else
{
func18(*argv);
v8 = v7;
}
}
}
return v8;
}

original_code:
int main (int argc, char * argv[])
{
 int i;
 long seed;
 char ch;
 long long usecs = 0;
 int count;
 struct profile ap;
 struct profile sp;
 int apidx = 0, spidx = 0;
 double v1, v2, pts;
 int k, fd;
 char * p = randdata;
 init_my_alloc ();
 areas = create_avl ();
 fd = open ("/dev/urandom", 00);
 if (fd < 0) {
  perror ("open");
  return 1;
 }
 k = 20000;
 while (k) {
  int ret = read (fd, p, k);
  if (ret <= 0) {
   perror ("read");
   return 1;
  }
  p += ret;
  k -= ret;
 }
 if (argc < 3) {
  usage (argv[0]);
  return 1;
 }
 if (sscanf (argv[1], "%ld%c", &seed, &ch) != 1) {
  usage (argv[0]);
  return 1;
 }
 if (sscanf (argv[2], "%d%c", &count, &ch) != 1) {
  usage (argv[0]);
  return 1;
 }
 if (argc > 3) {
  if (argc != 5) {
   usage (argv[0]);
   return 1;
  }
  spidx = get_idx (size_profiles, argv[3]);
  apidx = get_idx (alloc_profiles, argv[4]);
  if (spidx < 0 || apidx < 0) {
   usage (argv[0]);
   return 1;
  }
 }
 srand48 (seed);
 (*size_profiles[spidx].create)(&sp);
 (*alloc_profiles[apidx].create)(&ap);
 for (i=0; i<count || nptr; ++i) {
  if ((i+1) % 10000 == 0) {
   putchar('.');
   if ((i+1) % 100000 == 0) putchar('\n');
   fflush(stdout);
  }
  struct timeval tp1, tp2;
  int isalloc = ap.get (&ap);
  if (i < count && (nptr == 0 || isalloc > 0)) {
   int sz = sp.get (&sp);
   ((void) sizeof ((sz && sz % 8 == 0) ? 1 : 0), __extension__ ({ if (sz && sz % 8 == 0) ; else __assert_fail ("sz && sz % 8 == 0", "testit.c", 283, __extension__ __PRETTY_FUNCTION__); }));
   int offset = lrand48() % 19500;
   do { if(!(nptr < 1000000)) __my_assert("Anzahl der Operationen zu gross"); } while (0);
   alloc += sz;
   nalloc++;
   if (nalloc > maxnalloc)
    maxnalloc = nalloc;
   if (alloc > maxalloc)
    maxalloc = alloc;
   gettimeofday (&tp1, 0);
   data[nptr].ptr = my_alloc (sz);
   gettimeofday (&tp2, 0);
   usecs += (tp2.tv_sec - tp1.tv_sec) * 1000000
     + tp2.tv_usec - tp1.tv_usec;
   data[nptr].len = sz;
   data[nptr].contents = randdata+offset;
   memcpy (data[nptr].ptr, data[nptr].contents, sz);
   {
    struct avl_node * n;
    unsigned long ptr, ptr2;
    ptr2 = ptr = (unsigned long)data[nptr].ptr;
    do { if(!(valid_area (ptr, sz))) __my_assert("Speicher nicht auf einer 8 Byte Kante oder nicht in einem Block, den get_block_from_system geliefert hat"); } while (0);
    n = find_avl (areas, ptr);
    do { if(!(n->start + n->len <= ptr)) __my_assert("Ueberlappende Speicherbereiche"); } while (0);
    if (n->next) {
     ptr2 += sz;
     do { if(!(ptr2 <= n->next->start)) __my_assert("Ueberlappende Speicherbereiche"); } while (0);
    }
    insert_avl (&areas, ptr, sz);
   }
   nptr++;
  } else {
   int idx = lrand48() % nptr;
   int offset = lrand48() % 19500;
   int ret = memcmp (data[idx].ptr, data[idx].contents,
       data[idx].len);
   do { if(!(ret == 0)) __my_assert("Allokierter Speicherbereich wurde zwischenzeitlich veraendert"); } while (0);
   memcpy (data[idx].ptr, randdata+offset,
    data[idx].len);
   data[idx].contents = randdata+offset;
   alloc -= data[idx].len;
   nalloc--;
   gettimeofday (&tp1, 0);
   my_free (data[idx].ptr);
   gettimeofday (&tp2, 0);
   usecs += (tp2.tv_sec - tp1.tv_sec) * 1000000
     + tp2.tv_usec - tp1.tv_usec;
   {
    unsigned long ptr;
    struct avl_node * n;
    ptr = (unsigned long)data[idx].ptr;
    n = find_avl (areas, ptr);
    ((void) sizeof ((n->start == ptr) ? 1 : 0), __extension__ ({ if (n->start == ptr) ; else __assert_fail ("n->start == ptr", "testit.c", 358, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->len == data[idx].len) ? 1 : 0), __extension__ ({ if (n->len == data[idx].len) ; else __assert_fail ("n->len == data[idx].len", "testit.c", 359, __extension__ __PRETTY_FUNCTION__); }));
    remove_avl (&areas, n);
   }
   data[idx] = data[--nptr];
  }
 }
 putchar('\n');
 printf ("%d %d %d %lld\n", maxalloc, maxnalloc, get_sys_blockcount(), usecs);
 v1 = -1.0 + ((double) 8192 * get_sys_blockcount ())/((double)(maxalloc+8*maxnalloc));
 v2 = (double)usecs/(double)i;
 printf ("Relative size overhead: %lf\n", -1.0 + ((double) 8192 * get_sys_blockcount ())/((double)(maxalloc+8*maxnalloc)));
 printf ("Runtime per operation:  %lf\n", (double)usecs/(double)i);
 pts = 100.0 - 2.0*v2 - 100.0*v1;
 if (pts < 0) {
  pts = 0;
 }
 printf ("Points for this test: %lf\n", pts);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i;
 long seed;
 char ch;
 long long usecs = 0;
 int count;
 struct profile ap;
 struct profile sp;
 int apidx = 0; int spidx = 0;
 double v1; double v2; double pts;
 int k; int fd;
 char *p = randdata;
 init_my_alloc ();
 areas = create_avl ();
 fd = open ("/dev/urandom", 00);
 if (fd < 0) {
  perror ("open");
  return 1;
 }
 k = 20000;
 while (k) {
  int ret = read (fd, p, k);
  if (ret <= 0) {
   perror ("read");
   return 1;
  }
  p += ret;
  k -= ret;
 }
 if (argc < 3) {
  usage (argv[0]);
  return 1;
 }
 if (sscanf (argv[1], "%ld%c", &seed, &ch) != 1) {
  usage (argv[0]);
  return 1;
 }
 if (sscanf (argv[2], "%d%c", &count, &ch) != 1) {
  usage (argv[0]);
  return 1;
 }
 if (argc > 3) {
  if (argc != 5) {
   usage (argv[0]);
   return 1;
  }
  spidx = get_idx (size_profiles, argv[3]);
  apidx = get_idx (alloc_profiles, argv[4]);
  if (spidx < 0 || apidx < 0) {
   usage (argv[0]);
   return 1;
  }
 }
 srand48 (seed);
 (*size_profiles[spidx].create)(&sp);
 (*alloc_profiles[apidx].create)(&ap);
 for (i=0; i<count || nptr; ++i) {
  if ((i+1) % 10000 == 0) {
   putchar('.');
   if ((i+1) % 100000 == 0) putchar('\n');
   fflush(stdout);
  }
  struct timeval tp1; struct timeval tp2;
  int isalloc = ap.get (&ap);
  if (i < count && (nptr == 0 || isalloc > 0)) {
   int sz = sp.get (&sp);
   ((void) sizeof ((sz && sz % 8 == 0) ? 1 : 0), __extension__ ({ if (sz && sz % 8 == 0) ; else __assert_fail ("sz && sz % 8 == 0", "testit.c", 283, __extension__ __PRETTY_FUNCTION__); }));
   int offset = lrand48() % 19500;
   do { if(!(nptr < 1000000)) __my_assert("Anzahl der Operationen zu gross"); } while (0);
   alloc += sz;
   nalloc++;
   if (nalloc > maxnalloc)
    maxnalloc = nalloc;
   if (alloc > maxalloc)
    maxalloc = alloc;
   gettimeofday (&tp1, 0);
   data[nptr].ptr = my_alloc (sz);
   gettimeofday (&tp2, 0);
   usecs += (tp2.tv_sec - tp1.tv_sec) * 1000000
     + tp2.tv_usec - tp1.tv_usec;
   data[nptr].len = sz;
   data[nptr].contents = randdata+offset;
   memcpy (data[nptr].ptr, data[nptr].contents, sz);
   {
    struct avl_node *n;
    unsigned long ptr; unsigned long ptr2;
    ptr2 = ptr = (unsigned long)data[nptr].ptr;
    do { if(!(valid_area (ptr, sz))) __my_assert("Speicher nicht auf einer 8 Byte Kante oder nicht in einem Block, den get_block_from_system geliefert hat"); } while (0);
    n = find_avl (areas, ptr);
    do { if(!(n->start + n->len <= ptr)) __my_assert("Ueberlappende Speicherbereiche"); } while (0);
    if (n->next) {
     ptr2 += sz;
     do { if(!(ptr2 <= n->next->start)) __my_assert("Ueberlappende Speicherbereiche"); } while (0);
    }
    insert_avl (&areas, ptr, sz);
   }
   nptr++;
  } else {
   int idx = lrand48() % nptr;
   int offset = lrand48() % 19500;
   int ret = memcmp (data[idx].ptr, data[idx].contents,
       data[idx].len);
   do { if(!(ret == 0)) __my_assert("Allokierter Speicherbereich wurde zwischenzeitlich veraendert"); } while (0);
   memcpy (data[idx].ptr, randdata+offset,
    data[idx].len);
   data[idx].contents = randdata+offset;
   alloc -= data[idx].len;
   nalloc--;
   gettimeofday (&tp1, 0);
   my_free (data[idx].ptr);
   gettimeofday (&tp2, 0);
   usecs += (tp2.tv_sec - tp1.tv_sec) * 1000000
     + tp2.tv_usec - tp1.tv_usec;
   {
    unsigned long ptr;
    struct avl_node *n;
    ptr = (unsigned long)data[idx].ptr;
    n = find_avl (areas, ptr);
    ((void) sizeof ((n->start == ptr) ? 1 : 0), __extension__ ({ if (n->start == ptr) ; else __assert_fail ("n->start == ptr", "testit.c", 358, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->len == data[idx].len) ? 1 : 0), __extension__ ({ if (n->len == data[idx].len) ; else __assert_fail ("n->len == data[idx].len", "testit.c", 359, __extension__ __PRETTY_FUNCTION__); }));
    remove_avl (&areas, n);
   }
   data[idx] = data[--nptr];
  }
 }
 putchar('\n');
 printf ("%d %d %d %lld\n", maxalloc, maxnalloc, get_sys_blockcount(), usecs);
 v1 = -1.0 + ((double) 8192 * get_sys_blockcount ())/((double)(maxalloc+8*maxnalloc));
 v2 = (double)usecs/(double)i;
 printf ("Relative size overhead: %lf\n", -1.0 + ((double) 8192 * get_sys_blockcount ())/((double)(maxalloc+8*maxnalloc)));
 printf ("Runtime per operation:  %lf\n", (double)usecs/(double)i);
 pts = 100.0 - 2.0*v2 - 100.0*v1;
 if (pts < 0) {
  pts = 0;
 }
 printf ("Points for this test: %lf\n", pts);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: seed long

variable_types: ch char

variable_types:
usecs
long long

variable_types: count int

variable_types: struct profile { int (*get)(struct profile *p); int status[10]; }

variable_types: apidx int

variable_types: spidx int

variable_types: pts double

variable_types: k int

variable_types: fd int

variable_types:
p
char *

variable_types: ret int

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

variable_types: isalloc int

variable_types: sz int

variable_types: offset int

variable_types: struct avl_node { struct avl_node *next; struct avl_node *left; struct avl_node *parent; unsigned long start; int height; } *

variable_types:
ptr
unsigned long

variable_types: idx int