decompiled_code:
__int64 __fastcall sapi_parse_publisherUpdate_request(const char *a1, __int64 a2)
{
char *v2; // rax
__int64 v3; // r12
char *v4; // rax
char *v5; // rbx
const char *v6; // rdi
__int64 v7; // rax
char *v8; // rax
char *v9; // rbx

v2 = strstr(a1, "<string>/master");
v3 = (__int64)v2;
if ( v2 )
{
v4 = strstr(v2, "<string>");
v5 = strstr(v4 + 17, "<string>");
_isoc99_sscanf(v5, "<string>%[^<]", a2);
v6 = v5 + 17;
v3 = list_create();
while ( 1 )
{
v8 = strstr(v6, "http://");
v9 = v8;
if ( !v8 )
break;
v7 = uri_create_from_http_string(v8);
list_insert_item(v3, v7);
v6 = v9 + 10;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2)
{
char *v2; // rax
__int64 v3; // r12
char *v4; // rax
char *v5; // rbx
const char *v6; // rdi
__int64 v7; // rax
char *v8; // rax
char *v9; // rbx

v2 = strstr(a1, "<string>/master");
v3 = (__int64)v2;
if ( v2 )
{
v4 = strstr(v2, "<string>");
v5 = strstr(v4 + 17, "<string>");
_isoc99_sscanf(v5, "<string>%[^<]", a2);
v6 = v5 + 17;
v3 = list_create();
while ( 1 )
{
v8 = strstr(v6, "http://");
v9 = v8;
if ( !v8 )
break;
v7 = uri_create_from_http_string(v8);
list_insert_item(v3, v7);
v6 = v9 + 10;
}
}
return v3;
}

original_code:
list_t* sapi_parse_publisherUpdate_request(const string request, string topic)
{
 char *iter = strstr(request, "<string>/master");
 if (iter == ((void *)0)) return ((void *)0);
 iter = strstr(iter, "<string>");
    iter += 17;
    iter = strstr(iter, "<string>");
 sscanf(iter, "<string>%[^<]", topic);
    iter += 17;
    list_t* l = list_create();
    while((iter = strstr(iter, "http://")) != ((void *)0))
    {
     list_insert_item(l, uri_create_from_http_string(iter));
  iter += 10;
    }
    return l;
}

canonical_original_code:
struct list_t *sapi_parse_publisherUpdate_request(char *request, char *topic)
{
 char *iter = strstr(request, "<string>/master");
 if (iter == ((void *)0)) return ((void *)0);
 iter = strstr(iter, "<string>");
    iter += 17;
    iter = strstr(iter, "<string>");
 sscanf(iter, "<string>%[^<]", topic);
    iter += 17;
    struct list_t *l = list_create();
    while((iter = strstr(iter, "http://")) != ((void *)0))
    {
     list_insert_item(l, uri_create_from_http_string(iter));
  iter += 10;
    }
    return l;
}

variable_types:
request
char *

variable_types:
topic
char *

variable_types:
iter
char *

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


repo: RoboticLtd/pico-ros

decompiled_code:
__int64 __fastcall sapi_call_requestTopic(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
size_t v8; // rax
int v9; // eax
unsigned int v10; // ebp
int v11; // ebx
size_t v12; // rax
size_t v13; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_tag(sapi_body, "methodCall");
xmlmsg_add_tag_with_string(sapi_body, "methodName", "requestTopic");
xmlmsg_open_tag(sapi_body, "params");
xmlmsg_open_tag(sapi_body, "param");
xmlmsg_add_tag_with_string(sapi_body, "value", a2);
xmlmsg_close_tag(sapi_body, "param");
xmlmsg_open_tag(sapi_body, "param");
xmlmsg_add_tag_with_string(sapi_body, "value", a3);
xmlmsg_close_tag(sapi_body, "param");
xmlmsg_open_tag(sapi_body, "param");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_add_tag_with_string(sapi_body, "value", a4);
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "param");
xmlmsg_close_tag(sapi_body, "params");
xmlmsg_close_tag(sapi_body, "methodCall");
v8 = strlen(sapi_body);
sprintf(sapi_header, "POST / HTTP/1.0\nContent-Type: text/xml\nContent-Length: %d\n\n", v8);
v9 = comms_connect(a1);
if ( v9 < 0 )
return FALSE;
v10 = v9;
v11 = 0;
v12 = strlen(sapi_header);
comms_send(v10, sapi_header, v12);
v13 = strlen(sapi_body);
comms_send(v10, sapi_body, v13);
do
v11 += comms_recv(v10, a5 + v11, 2048LL);
while ( v11 <= 99 );
comms_disconnect(v10);
*(_BYTE *)(a5 + v11) = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
size_t v8; // rax
int v9; // eax
unsigned int v10; // ebp
int v11; // ebx
size_t v12; // rax
size_t v13; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_tag(sapi_body, "methodCall");
xmlmsg_add_tag_with_string(sapi_body, "methodName", "requestTopic");
xmlmsg_open_tag(sapi_body, "params");
xmlmsg_open_tag(sapi_body, "param");
xmlmsg_add_tag_with_string(sapi_body, "value", a2);
xmlmsg_close_tag(sapi_body, "param");
xmlmsg_open_tag(sapi_body, "param");
xmlmsg_add_tag_with_string(sapi_body, "value", a3);
xmlmsg_close_tag(sapi_body, "param");
xmlmsg_open_tag(sapi_body, "param");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_add_tag_with_string(sapi_body, "value", a4);
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "param");
xmlmsg_close_tag(sapi_body, "params");
xmlmsg_close_tag(sapi_body, "methodCall");
v8 = strlen(sapi_body);
sprintf(sapi_header, "POST / HTTP/1.0\nContent-Type: text/xml\nContent-Length: %d\n\n", v8);
v9 = comms_connect(a1);
if ( v9 < 0 )
return FALSE;
v10 = v9;
v11 = 0;
v12 = strlen(sapi_header);
comms_send(v10, sapi_header, v12);
v13 = strlen(sapi_body);
comms_send(v10, sapi_body, v13);
do
v11 += comms_recv(v10, a5 + v11, 2048LL);
while ( v11 <= 99 );
comms_disconnect(v10);
*(_BYTE *)(a5 + v11) = 0;
return 1LL;
}

original_code:
bool sapi_call_requestTopic(const uri_t* slave_uri,
                            const string caller_id,
                         const string topic,
                         const string protocols,
                         string response)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_tag(sapi_body, "methodCall");
  xmlmsg_add_tag_with_string(sapi_body, "methodName", "requestTopic");
  xmlmsg_open_tag(sapi_body, "params");
   xmlmsg_open_tag(sapi_body, "param");
    xmlmsg_add_tag_with_string(sapi_body, "value", caller_id);
   xmlmsg_close_tag(sapi_body, "param");
   xmlmsg_open_tag(sapi_body, "param");
    xmlmsg_add_tag_with_string(sapi_body, "value", topic);
   xmlmsg_close_tag(sapi_body, "param");
   xmlmsg_open_tag(sapi_body, "param");
    xmlmsg_open_tag(sapi_body, "value");
     xmlmsg_open_tag(sapi_body, "array");
      xmlmsg_open_tag(sapi_body, "data");
       xmlmsg_open_tag(sapi_body, "value");
        xmlmsg_open_tag(sapi_body, "array");
         xmlmsg_open_tag(sapi_body, "data");
          xmlmsg_add_tag_with_string(sapi_body, "value", protocols);
         xmlmsg_close_tag(sapi_body, "data");
        xmlmsg_close_tag(sapi_body, "array");
       xmlmsg_close_tag(sapi_body, "value");
      xmlmsg_close_tag(sapi_body, "data");
     xmlmsg_close_tag(sapi_body, "array");
    xmlmsg_close_tag(sapi_body, "value");
   xmlmsg_close_tag(sapi_body, "param");
  xmlmsg_close_tag(sapi_body, "params");
 xmlmsg_close_tag(sapi_body, "methodCall");
 sprintf(sapi_header, request_header_prototype, strlen(sapi_body));
 int socket = comms_connect(slave_uri);
 if(socket < 0) return FALSE;
 comms_send(socket, sapi_header, strlen(sapi_header));
 comms_send(socket, sapi_body, strlen(sapi_body));
 int n = 0;
 do
 {
  n += comms_recv(socket, response + n, 2048);
 } while(n < 100);
 comms_disconnect(socket);
 response[n] = '\0';
 return n > 0;
}

canonical_original_code:
unsigned char sapi_call_requestTopic(struct uri_t *slave_uri, char *caller_id, char *topic, char *protocols, char *response)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_tag(sapi_body, "methodCall");
  xmlmsg_add_tag_with_string(sapi_body, "methodName", "requestTopic");
  xmlmsg_open_tag(sapi_body, "params");
   xmlmsg_open_tag(sapi_body, "param");
    xmlmsg_add_tag_with_string(sapi_body, "value", caller_id);
   xmlmsg_close_tag(sapi_body, "param");
   xmlmsg_open_tag(sapi_body, "param");
    xmlmsg_add_tag_with_string(sapi_body, "value", topic);
   xmlmsg_close_tag(sapi_body, "param");
   xmlmsg_open_tag(sapi_body, "param");
    xmlmsg_open_tag(sapi_body, "value");
     xmlmsg_open_tag(sapi_body, "array");
      xmlmsg_open_tag(sapi_body, "data");
       xmlmsg_open_tag(sapi_body, "value");
        xmlmsg_open_tag(sapi_body, "array");
         xmlmsg_open_tag(sapi_body, "data");
          xmlmsg_add_tag_with_string(sapi_body, "value", protocols);
         xmlmsg_close_tag(sapi_body, "data");
        xmlmsg_close_tag(sapi_body, "array");
       xmlmsg_close_tag(sapi_body, "value");
      xmlmsg_close_tag(sapi_body, "data");
     xmlmsg_close_tag(sapi_body, "array");
    xmlmsg_close_tag(sapi_body, "value");
   xmlmsg_close_tag(sapi_body, "param");
  xmlmsg_close_tag(sapi_body, "params");
 xmlmsg_close_tag(sapi_body, "methodCall");
 sprintf(sapi_header, request_header_prototype, strlen(sapi_body));
 int socket = comms_connect(slave_uri);
 if(socket < 0) return FALSE;
 comms_send(socket, sapi_header, strlen(sapi_header));
 comms_send(socket, sapi_body, strlen(sapi_body));
 int n = 0;
 do
 {
  n += comms_recv(socket, response + n, 2048);
 } while(n < 100);
 comms_disconnect(socket);
 response[n] = '\0';
 return n > 0;
}

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

variable_types:
protocols
char *

variable_types:
response
char *

variable_types: socket int

variable_types: n int

return_type: unsigned char


decompiled_code:
__int64 __fastcall sapi_respond_requestTopic(unsigned int a1, __int64 a2)
{
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_string(sapi_body, "i4", "1");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_add_tag_with_string(sapi_body, "value", "TCPROS");
xmlmsg_add_tag_with_string(sapi_body, "value", *(_QWORD *)a2);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", *(unsigned __int16 *)(a2 + 8));
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v2 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v2);
v3 = strlen(sapi_header);
comms_send(a1, sapi_header, v3);
v4 = strlen(sapi_body);
return comms_send(a1, sapi_body, v4);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2)
{
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_string(sapi_body, "i4", "1");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_add_tag_with_string(sapi_body, "value", "TCPROS");
xmlmsg_add_tag_with_string(sapi_body, "value", *(_QWORD *)a2);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", *(unsigned __int16 *)(a2 + 8));
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v2 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v2);
v3 = strlen(sapi_header);
comms_send(a1, sapi_header, v3);
v4 = strlen(sapi_body);
return comms_send(a1, sapi_body, v4);
}

original_code:
void sapi_respond_requestTopic(int client_socket,
                               const uri_t *tcpros_server_uri)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_string(sapi_body, "i4", "1");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
     xmlmsg_add_tag_with_string(sapi_body, "value", "TCPROS");
     xmlmsg_add_tag_with_string(sapi_body, "value", tcpros_server_uri->ip);
     xmlmsg_open_tag(sapi_body, "value");
     xmlmsg_add_tag_with_ushort(sapi_body, "i4", tcpros_server_uri->port);
     xmlmsg_close_tag(sapi_body, "value");
    xmlmsg_close_tag(sapi_body, "data");
   xmlmsg_close_tag(sapi_body, "array");
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

canonical_original_code:
void sapi_respond_requestTopic(int client_socket, struct uri_t *tcpros_server_uri)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_string(sapi_body, "i4", "1");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
     xmlmsg_add_tag_with_string(sapi_body, "value", "TCPROS");
     xmlmsg_add_tag_with_string(sapi_body, "value", tcpros_server_uri->ip);
     xmlmsg_open_tag(sapi_body, "value");
     xmlmsg_add_tag_with_ushort(sapi_body, "i4", tcpros_server_uri->port);
     xmlmsg_close_tag(sapi_body, "value");
    xmlmsg_close_tag(sapi_body, "data");
   xmlmsg_close_tag(sapi_body, "array");
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

return_type: void

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


decompiled_code:
char *__fastcall sapi_parse_requestTopic_request(const char *a1, bool *a2)
{
char *result; // rax

result = strstr(a1, "TCPROS");
*a2 = result != 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1, bool *a2)
{
char *result; // rax

result = strstr(a1, "TCPROS");
*a2 = result != 0LL;
return result;
}

original_code:
void sapi_parse_requestTopic_request(const string request,
                                     bool *supported_protocol)
{
 *supported_protocol = (strstr(request, "TCPROS") != ((void *)0));
}

canonical_original_code:
void sapi_parse_requestTopic_request(char *request, unsigned char *supported_protocol)
{
 *supported_protocol = (strstr(request, "TCPROS") != ((void *)0));
}


decompiled_code:
int __fastcall sapi_parse_requestTopic_response(const char *a1, __int64 *a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rax
__int64 v5; // rax
unsigned __int16 v7; // [rsp+Eh] [rbp-3Ah] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v2 = strstr(a1, "<value>TCPROS");
if ( v2 )
{
v3 = strstr(v2 + 1, "<value>");
_isoc99_sscanf(v3, "<value>%[^<]", v8);
v4 = strstr(v3 + 1, "<i4>");
_isoc99_sscanf(v4, "<i4>%hu", &v7);
v5 = uri_create(v8, v7);
*a2 = v5;
}
else
{
LODWORD(v5) = printf("Unsupported protocol. Last received response:\n%s\n", a1);
}
return v5;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, __int64 *a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rax
__int64 v5; // rax
unsigned __int16 v7; // [rsp+Eh] [rbp-3Ah] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v2 = strstr(a1, "<value>TCPROS");
if ( v2 )
{
v3 = strstr(v2 + 1, "<value>");
_isoc99_sscanf(v3, "<value>%[^<]", v8);
v4 = strstr(v3 + 1, "<i4>");
_isoc99_sscanf(v4, "<i4>%hu", &v7);
v5 = uri_create(v8, v7);
*a2 = v5;
}
else
{
LODWORD(v5) = printf("Unsupported protocol. Last received response:\n%s\n", a1);
}
return v5;
}

original_code:
void sapi_parse_requestTopic_response(const string response,
                                      uri_t **tcpros_uri)
{
 char hostname[32];
 unsigned short port;
 char *iter = response;
 iter = strstr(iter, "<value>TCPROS");
 if(iter == ((void *)0))
 {
  printf("Unsupported protocol. Last received response:\n%s\n", response);
  return;
 }
 ++iter;
 iter = strstr(iter, "<value>");
 sscanf(iter, "<value>%[^<]", hostname);
 ++iter;
 iter = strstr(iter, "<i4>");
 sscanf(iter, "<i4>%hu", &port);
 *tcpros_uri = uri_create(hostname, port);
}

canonical_original_code:
void sapi_parse_requestTopic_response(char *response, struct uri_t **tcpros_uri)
{
 char hostname[32];
 unsigned short port;
 char *iter = response;
 iter = strstr(iter, "<value>TCPROS");
 if(iter == ((void *)0))
 {
  printf("Unsupported protocol. Last received response:\n%s\n", response);
  return;
 }
 ++iter;
 iter = strstr(iter, "<value>");
 sscanf(iter, "<value>%[^<]", hostname);
 ++iter;
 iter = strstr(iter, "<i4>");
 sscanf(iter, "<i4>%hu", &port);
 *tcpros_uri = uri_create(hostname, port);
}

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

variable_types:
hostname
char [32]

variable_types:
port
unsigned short


decompiled_code:
__int64 __fastcall sapi_respond_getMasterUri(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
v2 = uri_get_http_string(a2);
xmlmsg_add_tag_with_string(sapi_body, "string", v2);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v3 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v3);
v4 = strlen(sapi_header);
comms_send(a1, sapi_header, v4);
v5 = strlen(sapi_body);
return comms_send(a1, sapi_body, v5);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
v2 = uri_get_http_string(a2);
xmlmsg_add_tag_with_string(sapi_body, "string", v2);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v3 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v3);
v4 = strlen(sapi_header);
comms_send(a1, sapi_header, v4);
v5 = strlen(sapi_body);
return comms_send(a1, sapi_body, v5);
}

original_code:
void sapi_respond_getMasterUri(int client_socket, uri_t* uri)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_string(sapi_body, "string", uri_get_http_string(uri));
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

canonical_original_code:
void sapi_respond_getMasterUri(int client_socket, struct uri_t *uri)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_string(sapi_body, "string", uri_get_http_string(uri));
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}


decompiled_code:
// attributes: thunk
__int64 __fastcall sapi_respond_shutdown(unsigned int a1)
{
return sapi_respond_publisherUpdate(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
return func3(a1);
}

original_code:
void sapi_respond_shutdown(int client_socket)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0);
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}


decompiled_code:
char *__fastcall sapi_parse_shutdown_request(const char *a1, __int64 a2)
{
char *result; // rax
char *v3; // rax
char *v4; // rax

result = strstr(a1, "<string>");
if ( result )
{
v3 = strstr(result, "<string>");
v4 = strstr(v3 + 17, "<string>");
result = (char *)_isoc99_sscanf(v4, "<string>%[^<]", a2);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(const char *a1, __int64 a2)
{
char *result; // rax
char *v3; // rax
char *v4; // rax

result = strstr(a1, "<string>");
if ( result )
{
v3 = strstr(result, "<string>");
v4 = strstr(v3 + 17, "<string>");
result = (char *)_isoc99_sscanf(v4, "<string>%[^<]", a2);
}
return result;
}

original_code:
void sapi_parse_shutdown_request(const string request, string msg)
{
 char *iter = strstr(request, "<string>");
 if (iter == ((void *)0)) return;
 iter = strstr(iter, "<string>");
    iter += 17;
    iter = strstr(iter, "<string>");
 sscanf(iter, "<string>%[^<]", msg);
}

canonical_original_code:
void sapi_parse_shutdown_request(char *request, char *msg)
{
 char *iter = strstr(request, "<string>");
 if (iter == ((void *)0)) return;
 iter = strstr(iter, "<string>");
    iter += 17;
    iter = strstr(iter, "<string>");
 sscanf(iter, "<string>%[^<]", msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall serialize_std_msgs__string(__int64 a1, const char **a2)
{
const char *v2; // rbp
unsigned int v3; // eax
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = *a2;
v3 = strlen(*a2);
v6[0] = a1;
v5 = v3;
tcpmsg_init(v6);
tcpmsg_add_raw_data(v6, &v5, 4LL);
tcpmsg_add_raw_data(v6, v2, v5);
tcpmsg_finalize(a1, v6[0] - a1);
return v6[0] - a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char **a2)
{
const char *v2; // rbp
unsigned int v3; // eax
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = *a2;
v3 = strlen(*a2);
v6[0] = a1;
v5 = v3;
tcpmsg_init(v6);
tcpmsg_add_raw_data(v6, &v5, 4LL);
tcpmsg_add_raw_data(v6, v2, v5);
tcpmsg_finalize(a1, v6[0] - a1);
return v6[0] - a1;
}

original_code:
int serialize_std_msgs__string(char* const buf, const void* msg)
{
 char* data = ((std_msgs__string*)msg)->data;
 uint32_t len = strlen(data);
 char* iter = buf;
 tcpmsg_init(&iter);
 tcpmsg_add_raw_data(&iter, &len, 4); tcpmsg_add_raw_data(&iter, data, len);;
 tcpmsg_finalize(buf, iter - buf);
 return iter-buf;
}

canonical_original_code:
int serialize_std_msgs__string(char *buf, void *msg)
{
 char *data = ((std_msgs__string*)msg)->data;
 unsigned int len = strlen(data);
 char *iter = buf;
 tcpmsg_init(&iter);
 tcpmsg_add_raw_data(&iter, &len, 4); tcpmsg_add_raw_data(&iter, data, len);;
 tcpmsg_finalize(buf, iter - buf);
 return iter-buf;
}

variable_types:
buf
char *

variable_types:
msg
void *

variable_types:
data
char *

variable_types:
len
unsigned int

return_type: int


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

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

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

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

original_code:
void free_std_msgs__string(void* msg)
{
 if(((std_msgs__string*)msg)->data != ((void *)0))
  free(((std_msgs__string*)msg)->data);
 if(msg != ((void *)0)) free(msg);
}

canonical_original_code:
void free_std_msgs__string(void *msg)
{
 if(((struct std_msgs__string *)msg)->data != ((void *)0))
  free(((struct std_msgs__string *)msg)->data);
 if(msg != ((void *)0)) free(msg);
}


decompiled_code:
__int64 __fastcall param_server_set_int32(__int64 a1, unsigned int a2)
{
char v3[24]; // [rsp+0h] [rbp-18h] BYREF

sprintf(v3, "%d", a2);
return mapi_call_setParam(pico_node[1], a1, "int", v3, &response);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
char v3[24]; // [rsp+0h] [rbp-18h] BYREF

sprintf(v3, "%d", a2);
return mapi_call_setParam(pico_node[1], a1, "int", v3, &response);
}

original_code:
void param_server_set_int32(const string name, const int32_t param)
{
 char value[16];
 sprintf(value, "%d", param);
 mapi_call_setParam(pico_node.name, name, "int", value, response);
}

canonical_original_code:
void param_server_set_int32(char *name, int param)
{
 char value[16];
 sprintf(value, "%d", param);
 mapi_call_setParam(pico_node.name, name, "int", value, response);
}

variable_types:
name
char *

variable_types: param int

variable_types:
value
char [16]


decompiled_code:
__int64 __fastcall param_server_set_double(__int64 a1, double a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v3, "%.16lf", a2);
return mapi_call_setParam(pico_node[1], a1, "double", v3, &response);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, double a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v3, "%.16lf", a2);
return mapi_call_setParam(pico_node[1], a1, "double", v3, &response);
}

original_code:
void param_server_set_double(const string name, const double param)
{
 char value[32];
 sprintf(value, "%.16lf", param);
 mapi_call_setParam(pico_node.name, name, "double", value, response);
}

canonical_original_code:
void param_server_set_double(char *name, double param)
{
 char value[32];
 sprintf(value, "%.16lf", param);
 mapi_call_setParam(pico_node.name, name, "double", value, response);
}

variable_types: param double

variable_types:
value
char [32]


decompiled_code:
__int64 __fastcall param_server_set_bool(__int64 a1, char a2)
{
const char *v2; // rcx

v2 = "1";
if ( !a2 )
v2 = "0";
return mapi_call_setParam(pico_node[1], a1, "boolean", v2, &response);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2)
{
const char *v2; // rcx

v2 = "1";
if ( !a2 )
v2 = "0";
return mapi_call_setParam(pico_node[1], a1, "boolean", v2, &response);
}

original_code:
void param_server_set_bool(const string name, const bool param)
{
 char* value = (param) ? "1" : "0";
 mapi_call_setParam(pico_node.name, name, "boolean", value, response);
}

canonical_original_code:
void param_server_set_bool(char *name, unsigned char param)
{
 char *value = (param) ? "1" : "0";
 mapi_call_setParam(pico_node.name, name, "boolean", value, response);
}

variable_types:
param
unsigned char

variable_types:
value
char *


decompiled_code:
__int64 __fastcall param_server_set_string(__int64 a1, __int64 a2)
{
return mapi_call_setParam(pico_node[1], a1, "string", a2, &response);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return mapi_call_setParam(pico_node[1], a1, "string", a2, &response);
}

original_code:
void param_server_set_string(const string name, const string param)
{
 mapi_call_setParam(pico_node.name, name, "string", param, response);
}

canonical_original_code:
void param_server_set_string(char *name, char *param)
{
 mapi_call_setParam(pico_node.name, name, "string", param, response);
}

variable_types:
param
char *


decompiled_code:
__int64 __fastcall param_server_get_int32(__int64 a1, __int64 a2)
{
__int64 v2; // rax

mapi_call_getParam(pico_node[1], a1, &response);
v2 = mapi_parse_getParam_response(&response);
if ( !v2 )
return FALSE;
_isoc99_sscanf(v2, "<int>%d", a2);
return TRUE;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax

mapi_call_getParam(pico_node[1], a1, &response);
v2 = mapi_parse_getParam_response(&response);
if ( !v2 )
return FALSE;
_isoc99_sscanf(v2, "<int>%d", a2);
return TRUE;
}

original_code:
bool param_server_get_int32(const string name, int32_t* res)
{
 mapi_call_getParam(pico_node.name, name, response);
 string value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 sscanf(value, "<int>%d", res);
 return TRUE;
}

canonical_original_code:
unsigned char param_server_get_int32(char *name, int *res)
{
 mapi_call_getParam(pico_node.name, name, response);
 char *value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 sscanf(value, "<int>%d", res);
 return TRUE;
}

variable_types:
res
int *


decompiled_code:
__int64 __fastcall param_server_get_double(__int64 a1, __int64 a2)
{
__int64 v2; // rax

mapi_call_getParam(pico_node[1], a1, &response);
v2 = mapi_parse_getParam_response(&response);
if ( !v2 )
return FALSE;
_isoc99_sscanf(v2, "<double>%lf", a2);
return TRUE;
}

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

mapi_call_getParam(pico_node[1], a1, &response);
v2 = mapi_parse_getParam_response(&response);
if ( !v2 )
return FALSE;
_isoc99_sscanf(v2, "<double>%lf", a2);
return TRUE;
}

original_code:
bool param_server_get_double(const string name, double* res)
{
 mapi_call_getParam(pico_node.name, name, response);
 string value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 sscanf(value, "<double>%lf", res);
 return TRUE;
}

canonical_original_code:
unsigned char param_server_get_double(char *name, double *res)
{
 mapi_call_getParam(pico_node.name, name, response);
 char *value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 sscanf(value, "<double>%lf", res);
 return TRUE;
}

variable_types:
res
double *


decompiled_code:
__int64 __fastcall param_server_get_bool(__int64 a1, __int64 a2)
{
__int64 v2; // rax

mapi_call_getParam(pico_node[1], a1, &response);
v2 = mapi_parse_getParam_response(&response);
if ( !v2 )
return FALSE;
_isoc99_sscanf(v2, "<boolean>%hhd", a2);
return TRUE;
}

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

mapi_call_getParam(pico_node[1], a1, &response);
v2 = mapi_parse_getParam_response(&response);
if ( !v2 )
return FALSE;
_isoc99_sscanf(v2, "<boolean>%hhd", a2);
return TRUE;
}

original_code:
bool param_server_get_bool(const string name, bool* res)
{
 mapi_call_getParam(pico_node.name, name, response);
 string value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 sscanf(value, "<boolean>%hhd", res);
 return TRUE;
}

canonical_original_code:
unsigned char param_server_get_bool(char *name, unsigned char *res)
{
 mapi_call_getParam(pico_node.name, name, response);
 char *value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 sscanf(value, "<boolean>%hhd", res);
 return TRUE;
}

variable_types:
res
unsigned char *


decompiled_code:
__int64 __fastcall param_server_get_string(__int64 a1, char *a2)
{
char *v2; // r12
const char *v3; // rax
const char *v4; // rbx
int v5; // eax
int v6; // ebp

v2 = a2;
mapi_call_getParam(pico_node[1], a1, &response);
v3 = (const char *)mapi_parse_getParam_response(&response);
if ( !v3 )
return FALSE;
v4 = v3;
v5 = strlen(v3);
v6 = v5;
if ( !a2 )
v2 = (char *)calloc(1uLL, v5 - 16);
strncpy(v2, v4 + 8, v6 - 17);
return TRUE;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2)
{
char *v2; // r12
const char *v3; // rax
const char *v4; // rbx
int v5; // eax
int v6; // ebp

v2 = a2;
mapi_call_getParam(pico_node[1], a1, &response);
v3 = (const char *)mapi_parse_getParam_response(&response);
if ( !v3 )
return FALSE;
v4 = v3;
v5 = strlen(v3);
v6 = v5;
if ( !a2 )
v2 = (char *)calloc(1uLL, v5 - 16);
strncpy(v2, v4 + 8, v6 - 17);
return TRUE;
}

original_code:
bool param_server_get_string(const string name, string res)
{
 mapi_call_getParam(pico_node.name, name, response);
 string value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 int res_len = strlen(value) - 16;
 if(res == ((void *)0)) res = (string)calloc(sizeof(char), res_len);
 strncpy(res, value + 8, res_len - 1);
 return TRUE;
}

canonical_original_code:
unsigned char param_server_get_string(char *name, char *res)
{
 mapi_call_getParam(pico_node.name, name, response);
 char *value = mapi_parse_getParam_response(response);
 if(value == ((void *)0)) return FALSE;
 int res_len = strlen(value) - 16;
 if(res == ((void *)0)) res = (char *)calloc(sizeof(char), res_len);
 strncpy(res, value + 8, res_len - 1);
 return TRUE;
}

variable_types:
res
char *


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

if ( (unsigned __int8)mapi_call_deleteParam(pico_node[1], a1, &response) )
result = mapi_parse_deleteParam_response(&response);
else
result = FALSE;
return result;
}

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

if ( (unsigned __int8)mapi_call_deleteParam(pico_node[1], a1, &response) )
result = mapi_parse_deleteParam_response(&response);
else
result = FALSE;
return result;
}

original_code:
bool param_server_delete_param(const string name)
{
 return mapi_call_deleteParam(pico_node.name, name, response) ?
     mapi_parse_deleteParam_response(response) :
     FALSE;
}

canonical_original_code:
unsigned char param_server_delete_param(char *name)
{
 return mapi_call_deleteParam(pico_node.name, name, response) ?
     mapi_parse_deleteParam_response(response) :
     FALSE;
}


decompiled_code:
__int64 comms_init()
{
return TRUE;
}

canonical_decompiled_code:
__int64 func2()
{
return TRUE;
}

original_code:
bool comms_init()
{
 return TRUE;
}

canonical_original_code:
unsigned char comms_init()
{
 return TRUE;
}


decompiled_code:
__int64 __fastcall comms_get_own_ip(char **a1, const char *a2)
{
struct ifaddrs *v3; // rbx
unsigned int v4; // er13
struct sockaddr *v5; // rsi
struct ifaddrs *ifap; // [rsp+8h] [rbp-40h] BYREF
char buf[56]; // [rsp+10h] [rbp-38h] BYREF

ifap = 0LL;
*a1 = (char *)calloc(0x10uLL, 1uLL);
getifaddrs(&ifap);
v3 = ifap;
v4 = FALSE;
if ( ifap )
{
while ( 1 )
{
v5 = v3->ifa_addr;
if ( v5->sa_family == 2 )
{
inet_ntop(2, &v5->sa_data[2], buf, 0x10u);
if ( !strcmp(a2, v3->ifa_name) )
break;
}
v3 = v3->ifa_next;
if ( !v3 )
goto LABEL_7;
}
v4 = TRUE;
strcpy(*a1, buf);
LABEL_7:
if ( ifap )
freeifaddrs(ifap);
}
if ( !(_BYTE)v4 )
printf("Cannot find interface \"%s\" \n", a2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1, const char *a2)
{
struct ifaddrs *v3; // rbx
unsigned int v4; // er13
struct sockaddr *v5; // rsi
struct ifaddrs *ifap; // [rsp+8h] [rbp-40h] BYREF
char buf[56]; // [rsp+10h] [rbp-38h] BYREF

ifap = 0LL;
*a1 = (char *)calloc(0x10uLL, 1uLL);
getifaddrs(&ifap);
v3 = ifap;
v4 = FALSE;
if ( ifap )
{
while ( 1 )
{
v5 = v3->ifa_addr;
if ( v5->sa_family == 2 )
{
inet_ntop(2, &v5->sa_data[2], buf, 0x10u);
if ( !strcmp(a2, v3->ifa_name) )
break;
}
v3 = v3->ifa_next;
if ( !v3 )
goto LABEL_7;
}
v4 = TRUE;
strcpy(*a1, buf);
LABEL_7:
if ( ifap )
freeifaddrs(ifap);
}
if ( !(_BYTE)v4 )
printf("Cannot find interface \"%s\" \n", a2);
return v4;
}

original_code:
bool comms_get_own_ip(char** ip_addr, const string interface)
{
 struct ifaddrs* ifAddrStruct = ((void *)0);
 struct ifaddrs* ifa = ((void *)0);
 void* tmpAddrPtr = ((void *)0);
 *ip_addr = calloc(16, sizeof(char));
 getifaddrs(&ifAddrStruct);
 bool interface_found = FALSE;
 for (ifa = ifAddrStruct; ifa != ((void *)0); ifa = ifa->ifa_next)
 {
  if (ifa->ifa_addr->sa_family == 2)
  {
   tmpAddrPtr = &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr;
   char addressBuffer[16];
   inet_ntop(2, tmpAddrPtr, addressBuffer, 16);
   if (strcmp(interface, ifa->ifa_name) == 0)
   {
    interface_found = TRUE;
    strcpy(*ip_addr, addressBuffer);
    break;
   }
  }
 }
 if (ifAddrStruct != ((void *)0)) freeifaddrs(ifAddrStruct);
 if (!interface_found)
 {
  printf("Cannot find interface \"%s\" \n", interface);
 }
 return interface_found;
}

canonical_original_code:
unsigned char comms_get_own_ip(char **ip_addr, char *interface)
{
 struct ifaddrs *ifAddrStruct = ((void *)0);
 struct ifaddrs *ifa = ((void *)0);
 void *tmpAddrPtr = ((void *)0);
 *ip_addr = calloc(16, sizeof(char));
 getifaddrs(&ifAddrStruct);
 unsigned char interface_found = FALSE;
 for (ifa = ifAddrStruct; ifa != ((void *)0); ifa = ifa->ifa_next)
 {
  if (ifa->ifa_addr->sa_family == 2)
  {
   tmpAddrPtr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
   char addressBuffer[16];
   inet_ntop(2, tmpAddrPtr, addressBuffer, 16);
   if (strcmp(interface, ifa->ifa_name) == 0)
   {
    interface_found = TRUE;
    strcpy(*ip_addr, addressBuffer);
    break;
   }
  }
 }
 if (ifAddrStruct != ((void *)0)) freeifaddrs(ifAddrStruct);
 if (!interface_found)
 {
  printf("Cannot find interface \"%s\" \n", interface);
 }
 return interface_found;
}

variable_types:
interface
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types:
tmpAddrPtr
void *

variable_types:
addressBuffer
char [16]

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

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


decompiled_code:
__int64 __fastcall comms_connect(__int64 a1)
{
int v2; // eax
const char *v3; // rdi
unsigned int v4; // er12
in_addr_t v5; // eax
socklen_t v6; // edx
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 6);
if ( v2 < 0 )
return -1;
v3 = *(const char **)a1;
v4 = v2;
v8 = 0LL;
v8.sa_family = 2;
v5 = inet_addr(v3);
LOWORD(v3) = *(_WORD *)(a1 + 8);
*(_DWORD *)&v8.sa_data[2] = v5;
*(_WORD *)v8.sa_data = _bswap_16((__int16)v3);
if ( connect(v4, &v8, v6) < 0 )
return -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v2; // eax
const char *v3; // rdi
unsigned int v4; // er12
in_addr_t v5; // eax
socklen_t v6; // edx
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 6);
if ( v2 < 0 )
return -1;
v3 = *(const char **)a1;
v4 = v2;
v8 = 0LL;
v8.sa_family = 2;
v5 = inet_addr(v3);
LOWORD(v3) = *(_WORD *)(a1 + 8);
*(_DWORD *)&v8.sa_data[2] = v5;
*(_WORD *)v8.sa_data = func0((__int16)v3);
if ( connect(v4, &v8, v6) < 0 )
return -1;
return v4;
}

original_code:
int comms_connect(const uri_t* server)
{
 int socketfd;
 struct sockaddr_in server_addr;
 socketfd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (socketfd < 0) return -1;
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = inet_addr(server->ip);
 server_addr.sin_port = htons(server->port);
 if (connect(socketfd, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0)
  return -1;
 return socketfd;
}

canonical_original_code:
int comms_connect(struct uri_t *server)
{
 int socketfd;
 struct sockaddr_in server_addr;
 socketfd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (socketfd < 0) return -1;
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = inet_addr(server->ip);
 server_addr.sin_port = htons(server->port);
 if (connect(socketfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0)
  return -1;
 return socketfd;
}

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

variable_types: socketfd int

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

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


decompiled_code:
ssize_t __fastcall comms_send(int a1, const void *a2, int a3)
{
return send(a1, a2, a3, 0x4000);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, const void *a2, int a3)
{
return send(a1, a2, a3, 0x4000);
}

original_code:
int comms_send(int socketfd, char* data, int data_len)
{
 return send(socketfd, data, data_len, MSG_NOSIGNAL);
}

canonical_original_code:
int comms_send(int socketfd, char *data, int data_len)
{
 return send(socketfd, data, data_len, MSG_NOSIGNAL);
}

variable_types:
data
char *


decompiled_code:
ssize_t __fastcall comms_recv(int a1, void *a2, int a3)
{
return recv(a1, a2, a3, 0x4000);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int a1, void *a2, int a3)
{
return recv(a1, a2, a3, 0x4000);
}

original_code:
int comms_recv(int socketfd, char* data, int data_len)
{
 return recv(socketfd, data, data_len, MSG_NOSIGNAL);
}

canonical_original_code:
int comms_recv(int socketfd, char *data, int data_len)
{
 return recv(socketfd, data, data_len, MSG_NOSIGNAL);
}


decompiled_code:
// attributes: thunk
int comms_disconnect(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func7(int fd)
{
return close(fd);
}

original_code:
void comms_disconnect(int socketfd)
{
 close(socketfd);
}


decompiled_code:
__int64 __fastcall comms_init_local_server(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0
|| (v2 = v1,
*(_QWORD *)&addr.sa_data[6] = 0LL,
addr.sa_family = 2,
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0(0LL, &addr, 16LL),
len = 16,
*(_WORD *)addr.sa_data = _bswap_16(0),
bind(v2, &addr, v3) < 0)
|| getsockname(v2, &addr, &len) < 0
|| (*(_WORD *)(a1 + 8) = _bswap_16(*(__int16 *)addr.sa_data), listen(v2, 5) < 0) )
{
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0
|| (v2 = v1,
*(_QWORD *)&addr.sa_data[6] = 0LL,
addr.sa_family = 2,
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func1(0LL, &addr, 16LL),
len = 16,
*(_WORD *)addr.sa_data = func0(0),
bind(v2, &addr, v3) < 0)
|| getsockname(v2, &addr, &len) < 0
|| (*(_WORD *)(a1 + 8) = func0(*(__int16 *)addr.sa_data), listen(v2, 5) < 0) )
{
v2 = -1;
}
return v2;
}

original_code:
int comms_init_local_server(uri_t* server)
{
 int socketfd;
 socklen_t server_addr_len;
 struct sockaddr_in server_addr;
 socketfd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (socketfd < 0) return -1;
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 server_addr.sin_port = htons(0);
 server_addr_len = sizeof(server_addr);
 if (bind(socketfd,
          (struct sockaddr*) &server_addr,
          server_addr_len) < 0)
  return -1;
 if (getsockname(socketfd,
                 (struct sockaddr*) &server_addr,
                 &server_addr_len) < 0)
  return -1;
 server->port = (unsigned)ntohs(server_addr.sin_port);
 if (listen(socketfd, 5) < 0)
  return -1;
 return socketfd;
}

canonical_original_code:
int comms_init_local_server(struct uri_t *server)
{
 int socketfd;
 unsigned int server_addr_len;
 struct sockaddr_in server_addr;
 socketfd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (socketfd < 0) return -1;
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 server_addr.sin_port = htons(0);
 server_addr_len = sizeof(server_addr);
 if (bind(socketfd,
          (struct sockaddr *) &server_addr,
          server_addr_len) < 0)
  return -1;
 if (getsockname(socketfd,
                 (struct sockaddr *) &server_addr,
                 &server_addr_len) < 0)
  return -1;
 server->port = (unsigned int)ntohs(server_addr.sin_port);
 if (listen(socketfd, 5) < 0)
  return -1;
 return socketfd;
}


decompiled_code:
int __fastcall comms_accept_client(int fd)
{
__int64 v1; // rbx
__int64 v2; // r12
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-BCh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-B8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
v1 = fd / 64;
v2 = 1LL << (fd % 64);
readfds.fds_bits[v1] |= v2;
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) <= 0 || (readfds.fds_bits[v1] & v2) == 0 )
return -1;
addr_len = 16;
result = accept(fd, &addr, &addr_len);
if ( result < 0 )
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
__int64 v1; // rbx
__int64 v2; // r12
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-BCh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-B8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
v1 = fd / 64;
v2 = 1LL << (fd % 64);
readfds.fds_bits[v1] |= v2;
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) <= 0 || (readfds.fds_bits[v1] & v2) == 0 )
return -1;
addr_len = 16;
result = accept(fd, &addr, &addr_len);
if ( result < 0 )
result = -1;
return result;
}

original_code:
int comms_accept_client(int socketfd)
{
 fd_set fds;
 struct timeval timeout;
 struct sockaddr_in client_addr;
 socklen_t client_len;
 int client_socket;
 timeout.tv_sec = 0;
 timeout.tv_usec = 1;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((socketfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socketfd) % (8 * (int) sizeof (__fd_mask)))))));
 if (select(socketfd + 1, &fds, ((void *)0), ((void *)0), &timeout) <= 0) return -1;
 if (!((((&fds)->__fds_bits)[((socketfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socketfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) return -1;
 client_len = sizeof(client_addr);
 client_socket = accept(socketfd,
                        (struct sockaddr*) &client_addr,
                        &client_len);
 if (client_socket < 0) return -1;
 return client_socket;
}

canonical_original_code:
int comms_accept_client(int socketfd)
{
 struct fd_set fds;
 struct timeval timeout;
 struct sockaddr_in client_addr;
 unsigned int client_len;
 int client_socket;
 timeout.tv_sec = 0;
 timeout.tv_usec = 1;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((socketfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socketfd) % (8 * (int) sizeof (__fd_mask)))))));
 if (select(socketfd + 1, &fds, ((void *)0), ((void *)0), &timeout) <= 0) return -1;
 if (!((((&fds)->__fds_bits)[((socketfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socketfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) return -1;
 client_len = sizeof(client_addr);
 client_socket = accept(socketfd,
                        (struct sockaddr *) &client_addr,
                        &client_len);
 if (client_socket < 0) return -1;
 return client_socket;
}

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

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


decompiled_code:
int __fastcall comms_check_for_clients(int *a1, int *a2, int a3)
{
int *v3; // r12
__int64 v4; // rbp
__int64 v6; // rcx
size_t v7; // r8
int *v8; // rdx
__int64 v9; // rdi
int v10; // ecx
int v11; // eax
int v12; // er9
__int64 v13; // rax
__int64 i; // r13
int v15; // edi
int v16; // eax
__int64 v17; // rsi
int v18; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-CCh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-A8h] BYREF

v3 = a1;
addr_len = 16;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
if ( a3 <= 0 )
{
LODWORD(v13) = select(1024, &readfds, 0LL, 0LL, &timeout);
}
else
{
v4 = (unsigned int)a3;
v6 = (unsigned int)(a3 - 1);
v7 = (unsigned int)a3;
if ( a1 < &a2[v7] && a2 < &a1[v7] )
{
v17 = 0LL;
do
{
v18 = a1[v17];
a2[v17++] = -1;
readfds.fds_bits[v18 / 64] |= 1LL << (v18 % 64);
}
while ( v17 != a3 );
}
else
{
v8 = a1;
v9 = (__int64)&a1[v6 + 1];
do
{
v10 = *v8;
v11 = *v8 + 63;
v12 = *v8;
if ( *v8 >= 0 )
v11 = *v8;
++v8;
readfds.fds_bits[v11 >> 6] |= 1LL << (((((unsigned int)(v12 >> 31) >> 26) + v10) & 0x3F)
- ((unsigned int)(v12 >> 31) >> 26));
}
while ( v8 != (int *)v9 );
memset(a2, 255, v7 * 4);
}
LODWORD(v13) = select(1024, &readfds, 0LL, 0LL, &timeout);
if ( (int)v13 > 0 )
{
for ( i = 0LL; i != v4; ++i )
{
while ( 1 )
{
v15 = v3[i];
v16 = v15 + 63;
if ( v15 >= 0 )
v16 = v3[i];
v13 = v16 >> 6;
if ( (readfds.fds_bits[v13] & (1LL << (v3[i] % 64))) != 0 )
break;
if ( ++i == v4 )
return v13;
}
LODWORD(v13) = accept(v15, &addr, &addr_len);
a2[i] = v13;
}
}
}
return v13;
}

canonical_decompiled_code:
int __fastcall func10(int *a1, int *a2, int a3)
{
int *v3; // r12
__int64 v4; // rbp
__int64 v6; // rcx
size_t v7; // r8
int *v8; // rdx
__int64 v9; // rdi
int v10; // ecx
int v11; // eax
int v12; // er9
__int64 v13; // rax
__int64 i; // r13
int v15; // edi
int v16; // eax
__int64 v17; // rsi
int v18; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-CCh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-A8h] BYREF

v3 = a1;
addr_len = 16;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
if ( a3 <= 0 )
{
LODWORD(v13) = select(1024, &readfds, 0LL, 0LL, &timeout);
}
else
{
v4 = (unsigned int)a3;
v6 = (unsigned int)(a3 - 1);
v7 = (unsigned int)a3;
if ( a1 < &a2[v7] && a2 < &a1[v7] )
{
v17 = 0LL;
do
{
v18 = a1[v17];
a2[v17++] = -1;
readfds.fds_bits[v18 / 64] |= 1LL << (v18 % 64);
}
while ( v17 != a3 );
}
else
{
v8 = a1;
v9 = (__int64)&a1[v6 + 1];
do
{
v10 = *v8;
v11 = *v8 + 63;
v12 = *v8;
if ( *v8 >= 0 )
v11 = *v8;
++v8;
readfds.fds_bits[v11 >> 6] |= 1LL << (((((unsigned int)(v12 >> 31) >> 26) + v10) & 0x3F)
- ((unsigned int)(v12 >> 31) >> 26));
}
while ( v8 != (int *)v9 );
memset(a2, 255, v7 * 4);
}
LODWORD(v13) = select(1024, &readfds, 0LL, 0LL, &timeout);
if ( (int)v13 > 0 )
{
for ( i = 0LL; i != v4; ++i )
{
while ( 1 )
{
v15 = v3[i];
v16 = v15 + 63;
if ( v15 >= 0 )
v16 = v3[i];
v13 = v16 >> 6;
if ( (readfds.fds_bits[v13] & (1LL << (v3[i] % 64))) != 0 )
break;
if ( ++i == v4 )
return v13;
}
LODWORD(v13) = accept(v15, &addr, &addr_len);
a2[i] = v13;
}
}
}
return v13;
}

original_code:
void comms_check_for_clients(const int* servers, int* clients, const int n)
{
 fd_set fds;
 struct timeval timeout;
 timeout.tv_sec = 0;
 timeout.tv_usec = 1;
 struct sockaddr_in client_addr;
 socklen_t client_len = sizeof(client_addr);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 int i;
 for(i = 0; i < n; ++i)
 {
  ((void) (((&fds)->__fds_bits)[((servers[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((servers[i]) % (8 * (int) sizeof (__fd_mask)))))));
  clients[i] = -1;
 }
 if (select(1024, &fds, ((void *)0), ((void *)0), &timeout) <= 0) return;
 for(i = 0; i < n; ++i)
 {
  if (((((&fds)->__fds_bits)[((servers[i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((servers[i]) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   clients[i] = accept(servers[i],
                          (struct sockaddr*) &client_addr,
                          &client_len);
  }
 }
}

canonical_original_code:
void comms_check_for_clients(int *servers, int *clients, int n)
{
 struct fd_set fds;
 struct timeval timeout;
 timeout.tv_sec = 0;
 timeout.tv_usec = 1;
 struct sockaddr_in client_addr;
 unsigned int client_len = sizeof(client_addr);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 int i;
 for(i = 0; i < n; ++i)
 {
  ((void) (((&fds)->__fds_bits)[((servers[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((servers[i]) % (8 * (int) sizeof (__fd_mask)))))));
  clients[i] = -1;
 }
 if (select(1024, &fds, ((void *)0), ((void *)0), &timeout) <= 0) return;
 for(i = 0; i < n; ++i)
 {
  if (((((&fds)->__fds_bits)[((servers[i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((servers[i]) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   clients[i] = accept(servers[i],
                          (struct sockaddr *) &client_addr,
                          &client_len);
  }
 }
}

variable_types:
servers
int *

variable_types:
clients
int *

variable_types: n int

variable_types: i int

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


decompiled_code:
__int64 __fastcall comms_check_for_data(__int64 a1)
{
__int64 *i; // rdi
__int64 v3; // rax
_QWORD *j; // rsi
int v5; // ecx
int v6; // eax
struct timeval v8; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v8.tv_sec = 0LL;
v8.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
for ( i = *(__int64 **)(a1 + 8); i; readfds.fds_bits[*(_DWORD *)(v3 + 16) / 64] |= 1LL << (*(_DWORD *)(v3 + 16) % 64) )
{
v3 = *i;
i = (__int64 *)i[1];
}
if ( select(1024, &readfds, 0LL, 0LL, &v8) <= 0 )
return FALSE;
for ( j = *(_QWORD **)(a1 + 8); j; j = (_QWORD *)j[1] )
{
v5 = *(_DWORD *)(*j + 16LL);
v6 = v5 + 63;
if ( v5 >= 0 )
v6 = *(_DWORD *)(*j + 16LL);
*(_BYTE *)(*j + 20LL) = (readfds.fds_bits[v6 >> 6] & (1LL << (*(_DWORD *)(*j + 16LL) % 64))) != 0;
}
return TRUE;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 *i; // rdi
__int64 v3; // rax
_QWORD *j; // rsi
int v5; // ecx
int v6; // eax
struct timeval v8; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v8.tv_sec = 0LL;
v8.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
for ( i = *(__int64 **)(a1 + 8); i; readfds.fds_bits[*(_DWORD *)(v3 + 16) / 64] |= 1LL << (*(_DWORD *)(v3 + 16) % 64) )
{
v3 = *i;
i = (__int64 *)i[1];
}
if ( select(1024, &readfds, 0LL, 0LL, &v8) <= 0 )
return FALSE;
for ( j = *(_QWORD **)(a1 + 8); j; j = (_QWORD *)j[1] )
{
v5 = *(_DWORD *)(*j + 16LL);
v6 = v5 + 63;
if ( v5 >= 0 )
v6 = *(_DWORD *)(*j + 16LL);
*(_BYTE *)(*j + 20LL) = (readfds.fds_bits[v6 >> 6] & (1LL << (*(_DWORD *)(*j + 16LL) % 64))) != 0;
}
return TRUE;
}

original_code:
bool comms_check_for_data(list_t* conns)
{
 fd_set fds;
 struct timeval timeout;
 timeout.tv_sec = 0;
 timeout.tv_usec = 1;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 list_item_t* it;
 for (it = conns->begin; it != ((void *)0); it = it->next)
 {
  connection_t* con = it->data;
  ((void) (((&fds)->__fds_bits)[((con->socketfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->socketfd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 if (select(1024, &fds, ((void *)0), ((void *)0), &timeout) <= 0) return FALSE;
 for (it = conns->begin; it != ((void *)0); it = it->next)
 {
  connection_t* con = it->data;
  con->pending = ((((&fds)->__fds_bits)[((con->socketfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->socketfd) % (8 * (int) sizeof (__fd_mask)))))) != 0);
 }
 return TRUE;
}

canonical_original_code:
unsigned char comms_check_for_data(struct list_t *conns)
{
 struct fd_set fds;
 struct timeval timeout;
 timeout.tv_sec = 0;
 timeout.tv_usec = 1;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 struct list_item_t *it;
 for (it = conns->begin; it != ((void *)0); it = it->next)
 {
  struct connection_t *con = it->data;
  ((void) (((&fds)->__fds_bits)[((con->socketfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->socketfd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 if (select(1024, &fds, ((void *)0), ((void *)0), &timeout) <= 0) return FALSE;
 for (it = conns->begin; it != ((void *)0); it = it->next)
 {
  struct connection_t *con = it->data;
  con->pending = ((((&fds)->__fds_bits)[((con->socketfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->socketfd) % (8 * (int) sizeof (__fd_mask)))))) != 0);
 }
 return TRUE;
}

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

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 list_t { int size; struct list_item_t *begin; struct list_item_t *end; }

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


decompiled_code:
__int64 __fastcall tcpros_send_subscriber_request(unsigned int a1, __int64 a2, __int64 a3, _QWORD *a4, __int64 a5, _DWORD *a6)
{
__int64 result; // rax
__int64 v11[8]; // [rsp+8h] [rbp-40h] BYREF

v11[0] = (__int64)&tcp_package;
tcpmsg_init(v11);
tcpmsg_add_field(v11, "callerid", a2);
tcpmsg_add_field(v11, "topic", a3);
tcpmsg_add_field(v11, "md5sum", a4[1]);
tcpmsg_add_field(v11, "type", *a4);
tcpmsg_finalize(&tcp_package, v11[0] - (_QWORD)&tcp_package);
comms_send(a1, &tcp_package, v11[0] - (_QWORD)&tcp_package);
result = comms_recv(a1, a5, 2048LL);
*a6 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, __int64 a3, _QWORD *a4, __int64 a5, _DWORD *a6)
{
__int64 result; // rax
__int64 v11[8]; // [rsp+8h] [rbp-40h] BYREF

v11[0] = (__int64)&tcp_package;
tcpmsg_init(v11);
tcpmsg_add_field(v11, "callerid", a2);
tcpmsg_add_field(v11, "topic", a3);
tcpmsg_add_field(v11, "md5sum", a4[1]);
tcpmsg_add_field(v11, "type", *a4);
tcpmsg_finalize(&tcp_package, v11[0] - (_QWORD)&tcp_package);
comms_send(a1, &tcp_package, v11[0] - (_QWORD)&tcp_package);
result = comms_recv(a1, a5, 2048LL);
*a6 = result;
return result;
}

original_code:
void tcpros_send_subscriber_request(const int socketfd,
                                    const string callerid,
                                    const string topic,
                                    const message_type_t* msg,
                                    char* response,
                                    int* response_len)
{
 char* iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "topic", topic);
 tcpmsg_add_field(&iter, "md5sum", msg->md5sum);
 tcpmsg_add_field(&iter, "type", msg->type);
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
 *response_len = comms_recv(socketfd, response, 2048);
}

canonical_original_code:
void tcpros_send_subscriber_request(int socketfd, char *callerid, char *topic, struct message_type_t *msg, char *response, int *response_len)
{
 char *iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "topic", topic);
 tcpmsg_add_field(&iter, "md5sum", msg->md5sum);
 tcpmsg_add_field(&iter, "type", msg->type);
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
 *response_len = comms_recv(socketfd, response, 2048);
}

variable_types:
callerid
char *

variable_types:
topic
char *

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

variable_types:
response
char *

variable_types:
iter
char *


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

if ( a2 > 4 )
{
v8 = (const char *)(a1 + 4);
while ( 1 )
{
v9 = v8 + 4;
v10 = utils_get_int_from_bytes(v8, 4LL);
if ( v10 > 511 )
break;
v11 = v10;
strncpy(&tcp_package, v9, v10);
*(&tcp_package + v11) = 0;
v8 = &v9[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 && *((_QWORD *)&tcp_package + 64) == 0x646972656C6C6163LL && !*(&tcp_package + 520) )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
if ( (__int64)&v8[-a1] >= a2 )
return;
}
else
{
if ( a4 && *((_DWORD *)&tcp_package + 128) == 1768976244 && *((_WORD *)&tcp_package + 258) == 99 )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a5
&& *((_DWORD *)&tcp_package + 128) == 1932878957
&& *((_WORD *)&tcp_package + 258) == 28021
&& !*(&tcp_package + 518) )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a6 && *((_DWORD *)&tcp_package + 128) == 1701869940 && !*(&tcp_package + 516) )
{
strcpy(a6, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
if ( (__int64)&v8[-a1] >= a2 )
return;
}
}
}
}

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

if ( a2 > 4 )
{
v8 = (const char *)(a1 + 4);
while ( 1 )
{
v9 = v8 + 4;
v10 = utils_get_int_from_bytes(v8, 4LL);
if ( v10 > 511 )
break;
v11 = v10;
strncpy(&tcp_package, v9, v10);
*(&tcp_package + v11) = 0;
v8 = &v9[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 && *((_QWORD *)&tcp_package + 64) == 0x646972656C6C6163LL && !*(&tcp_package + 520) )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
if ( (__int64)&v8[-a1] >= a2 )
return;
}
else
{
if ( a4 && *((_DWORD *)&tcp_package + 128) == 1768976244 && *((_WORD *)&tcp_package + 258) == 99 )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a5
&& *((_DWORD *)&tcp_package + 128) == 1932878957
&& *((_WORD *)&tcp_package + 258) == 28021
&& !*(&tcp_package + 518) )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a6 && *((_DWORD *)&tcp_package + 128) == 1701869940 && !*(&tcp_package + 516) )
{
strcpy(a6, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
if ( (__int64)&v8[-a1] >= a2 )
return;
}
}
}
}

original_code:
void tcpros_parse_subscriber_request(const char* req,
                                     int req_len,
                                     char* callerid,
                                     char* topic,
                                     char* md5sum,
                                     char* type)
{
 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(topic != ((void *)0) &&
          strcmp(name, "topic") == 0)
  {
   strcpy(topic, 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_subscriber_request(char *req, int req_len, char *callerid, char *topic, char *md5sum, char *type)
{
 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(topic != ((void *)0) &&
          strcmp(name, "topic") == 0)
  {
   strcpy(topic, 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:
req
char *

variable_types:
type
char *

variable_types:
field
char *

variable_types:
name
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall tcpros_send_publisher_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, "md5sum", a3[1]);
tcpmsg_add_field(v5, "type", *a3);
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 func2(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, "md5sum", a3[1]);
tcpmsg_add_field(v5, "type", *a3);
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_publisher_response(const int socketfd,
                                    const string callerid,
                                    const message_type_t* msg)
{
 char* iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "md5sum", msg->md5sum);
 tcpmsg_add_field(&iter, "type", msg->type);
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
}

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

variable_types: socketfd int

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


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

if ( a2 > 4 )
{
v7 = (const char *)(a1 + 4);
while ( 1 )
{
v8 = v7 + 4;
v9 = utils_get_int_from_bytes(v7, 4LL);
if ( v9 > 511 )
break;
v10 = v9;
strncpy(&tcp_package, v8, v9);
*(&tcp_package + v10) = 0;
v7 = &v8[v10];
_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 && *((_QWORD *)&tcp_package + 64) == 0x646972656C6C6163LL && !*(&tcp_package + 520) )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
if ( (__int64)&v7[-a1] >= a2 )
return;
}
else
{
if ( a4
&& *((_DWORD *)&tcp_package + 128) == 1932878957
&& *((_WORD *)&tcp_package + 258) == 28021
&& !*(&tcp_package + 518) )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a5 && *((_DWORD *)&tcp_package + 128) == 1701869940 && !*(&tcp_package + 516) )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
if ( (__int64)&v7[-a1] >= a2 )
return;
}
}
}
}

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

if ( a2 > 4 )
{
v7 = (const char *)(a1 + 4);
while ( 1 )
{
v8 = v7 + 4;
v9 = utils_get_int_from_bytes(v7, 4LL);
if ( v9 > 511 )
break;
v10 = v9;
strncpy(&tcp_package, v8, v9);
*(&tcp_package + v10) = 0;
v7 = &v8[v10];
_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 && *((_QWORD *)&tcp_package + 64) == 0x646972656C6C6163LL && !*(&tcp_package + 520) )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
if ( (__int64)&v7[-a1] >= a2 )
return;
}
else
{
if ( a4
&& *((_DWORD *)&tcp_package + 128) == 1932878957
&& *((_WORD *)&tcp_package + 258) == 28021
&& !*(&tcp_package + 518) )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a5 && *((_DWORD *)&tcp_package + 128) == 1701869940 && !*(&tcp_package + 516) )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
if ( (__int64)&v7[-a1] >= a2 )
return;
}
}
}
}

original_code:
void tcpros_parse_publisher_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_publisher_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 *


decompiled_code:
__int64 __fastcall tcpros_send_client_request(unsigned int a1, __int64 a2, __int64 a3, _QWORD *a4, char a5, __int64 a6, _DWORD *a7)
{
const char *v11; // rdx
__int64 result; // rax
__int64 v13[8]; // [rsp+8h] [rbp-40h] BYREF

v13[0] = (__int64)&tcp_package;
tcpmsg_init(v13);
tcpmsg_add_field(v13, "callerid", a2);
tcpmsg_add_field(v13, "service", a3);
tcpmsg_add_field(v13, "md5sum", a4[1]);
tcpmsg_add_field(v13, "type", *a4);
v11 = "1";
if ( !a5 )
v11 = "0";
tcpmsg_add_field(v13, "persistent", v11);
tcpmsg_finalize(&tcp_package, v13[0] - (_QWORD)&tcp_package);
comms_send(a1, &tcp_package, v13[0] - (_QWORD)&tcp_package);
result = comms_recv(a1, a6, 2048LL);
*a7 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, __int64 a3, _QWORD *a4, char a5, __int64 a6, _DWORD *a7)
{
const char *v11; // rdx
__int64 result; // rax
__int64 v13[8]; // [rsp+8h] [rbp-40h] BYREF

v13[0] = (__int64)&tcp_package;
tcpmsg_init(v13);
tcpmsg_add_field(v13, "callerid", a2);
tcpmsg_add_field(v13, "service", a3);
tcpmsg_add_field(v13, "md5sum", a4[1]);
tcpmsg_add_field(v13, "type", *a4);
v11 = "1";
if ( !a5 )
v11 = "0";
tcpmsg_add_field(v13, "persistent", v11);
tcpmsg_finalize(&tcp_package, v13[0] - (_QWORD)&tcp_package);
comms_send(a1, &tcp_package, v13[0] - (_QWORD)&tcp_package);
result = comms_recv(a1, a6, 2048LL);
*a7 = result;
return result;
}

original_code:
void tcpros_send_client_request(const int socketfd,
                                const string callerid,
                                const string service,
                                const service_type_t* srv,
                                const bool persistent,
                                char* response,
                                int* response_len)
{
 char* iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "service", service);
 tcpmsg_add_field(&iter, "md5sum", srv->md5sum);
 tcpmsg_add_field(&iter, "type", srv->type);
 tcpmsg_add_field(&iter, "persistent", (persistent) ? "1" : "0");
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
 *response_len = comms_recv(socketfd, response, 2048);
}

canonical_original_code:
void tcpros_send_client_request(int socketfd, char *callerid, char *service, struct service_type_t *srv, unsigned char persistent, char *response, int *response_len)
{
 char *iter = tcp_package;
 tcpmsg_init(&iter);
 tcpmsg_add_field(&iter, "callerid", callerid);
 tcpmsg_add_field(&iter, "service", service);
 tcpmsg_add_field(&iter, "md5sum", srv->md5sum);
 tcpmsg_add_field(&iter, "type", srv->type);
 tcpmsg_add_field(&iter, "persistent", (persistent) ? "1" : "0");
 tcpmsg_finalize(tcp_package, iter - tcp_package);
 comms_send(socketfd, tcp_package, iter - tcp_package);
 *response_len = comms_recv(socketfd, response, 2048);
}

variable_types:
service
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:
persistent
unsigned char


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 *v10; // rbx
const char *v11; // r15
int v12; // eax
__int64 v13; // rbx
char v14; // al
char v15; // al

if ( a2 > 4 )
{
v10 = (const char *)(a1 + 4);
while ( 1 )
{
v11 = v10 + 4;
v12 = utils_get_int_from_bytes(v10, 4LL);
if ( v12 > 511 )
break;
v13 = v12;
strncpy(&tcp_package, v11, v12);
*(&tcp_package + v13) = 0;
v10 = &v11[v13];
_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 && *((_QWORD *)&tcp_package + 64) == 0x646972656C6C6163LL && !*(&tcp_package + 520) )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
if ( (__int64)&v10[-a1] >= a2 )
return;
}
else
{
if ( a4 && *((_QWORD *)&tcp_package + 64) == 0x65636976726573LL )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a5
&& *((_DWORD *)&tcp_package + 128) == 1932878957
&& *((_WORD *)&tcp_package + 258) == 28021
&& !*(&tcp_package + 518) )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a6 && *((_DWORD *)&tcp_package + 128) == 1701869940 && !*(&tcp_package + 516) )
{
strcpy(a6, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a7
&& *((_QWORD *)&tcp_package + 64) == 0x6574736973726570LL
&& *((_WORD *)&tcp_package + 260) == 29806
&& !*(&tcp_package + 522) )
{
v14 = TRUE;
if ( *((_WORD *)&tcp_package + 512) != 49 )
v14 = FALSE;
*a7 = v14;
}
else if ( a8 && *((_DWORD *)&tcp_package + 128) == 1651470960 && *((_WORD *)&tcp_package + 258) == 101 )
{
v15 = TRUE;
if ( *((_WORD *)&tcp_package + 512) != 49 )
v15 = FALSE;
*a8 = v15;
}
if ( (__int64)&v10[-a1] >= a2 )
return;
}
}
}
}

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

if ( a2 > 4 )
{
v10 = (const char *)(a1 + 4);
while ( 1 )
{
v11 = v10 + 4;
v12 = utils_get_int_from_bytes(v10, 4LL);
if ( v12 > 511 )
break;
v13 = v12;
strncpy(&tcp_package, v11, v12);
*(&tcp_package + v13) = 0;
v10 = &v11[v13];
_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 && *((_QWORD *)&tcp_package + 64) == 0x646972656C6C6163LL && !*(&tcp_package + 520) )
{
strcpy(a3, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
if ( (__int64)&v10[-a1] >= a2 )
return;
}
else
{
if ( a4 && *((_QWORD *)&tcp_package + 64) == 0x65636976726573LL )
{
strcpy(a4, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a5
&& *((_DWORD *)&tcp_package + 128) == 1932878957
&& *((_WORD *)&tcp_package + 258) == 28021
&& !*(&tcp_package + 518) )
{
strcpy(a5, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a6 && *((_DWORD *)&tcp_package + 128) == 1701869940 && !*(&tcp_package + 516) )
{
strcpy(a6, (const char *)(unsigned int)((_DWORD)&tcp_package + 1024));
}
else if ( a7
&& *((_QWORD *)&tcp_package + 64) == 0x6574736973726570LL
&& *((_WORD *)&tcp_package + 260) == 29806
&& !*(&tcp_package + 522) )
{
v14 = TRUE;
if ( *((_WORD *)&tcp_package + 512) != 49 )
v14 = FALSE;
*a7 = v14;
}
else if ( a8 && *((_DWORD *)&tcp_package + 128) == 1651470960 && *((_WORD *)&tcp_package + 258) == 101 )
{
v15 = TRUE;
if ( *((_WORD *)&tcp_package + 512) != 49 )
v15 = FALSE;
*a8 = v15;
}
if ( (__int64)&v10[-a1] >= a2 )
return;
}
}
}
}

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 *


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

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:
// attributes: thunk
void __fastcall tcpros_parse_server_response(__int64 a1, int a2, char *a3, char *a4, char *a5)
{
tcpros_parse_publisher_response(a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, char *a3, char *a4, char *a5)
{
func3(a1, a2, a3, a4, a5);
}

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


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

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

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

v2 = (char **)malloc(0x10uLL);
v3 = (char *)calloc(8uLL, 0x40uLL);
*v2 = v3;
v4 = strcpy(v3, src);
v5 = gethostbyname(v4);
printf("Resolved addr: %d \r\n", *v5->h_addr_list);
inet_ntop(2, *(const void **)v5->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; // rax
char *v2; // rbp
const char **v3; // r12
const char *v4; // rax
struct hostent *v5; // rax

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

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

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

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; // rax
char *v2; // rbp
const char **v3; // r12
const char *v4; // rax
struct hostent *v5; // rax

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

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

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

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

variable_types:
iter
char *


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; // r12

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; // r12

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; // r12

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; // r12

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; // r12

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; // r12

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:
bool __fastcall uri_equals(__int64 a1, __int64 a2)
{
int v2; // er8
bool result; // al

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

canonical_decompiled_code:
bool __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // er8
bool result; // al

v2 = strcmp(*(const char **)a1, *(const char **)a2);
result = 0;
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 *


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


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