decompiled_code:
int __fastcall print_info(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8)
{
return printf("player at %d, %d with direction %d\n", (unsigned int)a7, HIDWORD(a7), a8);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8)
{
return printf("player at %d, %d with direction %d\n", (unsigned int)a7, HIDWORD(a7), a8);
}

original_code:
void print_info ( struct mazegame game )
{
    printf ( "player at %d, %d with direction %d\n", game.player.p.x, game.player.p.y, game.player.d );
}

canonical_original_code:
void print_info(struct mazegame game)
{
    printf ( "player at %d, %d with direction %d\n", game.player.p.x, game.player.p.y, game.player.d );
}

variable_types: struct mazegame { struct player { struct DR_position { int x; int y; } p; enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 } d; int battery; int flashlight_switch; } player; struct maze { struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position p; } *tiles; struct DR_position start_position; struct DR_position goal_position; int size; } *maze; }


repo: RoboticLtd/pico-ros

decompiled_code:
__int64 __fastcall sapi_respond_getBusInfo(unsigned int a1, __int64 a2, __int64 a3)
{
_QWORD *i; // rbx
_QWORD *j; // rbx
size_t v6; // rax
size_t v7; // rax
size_t v8; // 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");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(_QWORD **)(a2 + 8); i; i = (_QWORD *)i[1] )
xmlmsg_add_topic(sapi_body, *i);
for ( j = *(_QWORD **)(a3 + 8); j; j = (_QWORD *)j[1] )
xmlmsg_add_topic(sapi_body, *j);
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v6 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v6);
v7 = strlen(sapi_header);
comms_send(a1, sapi_header, v7);
v8 = strlen(sapi_body);
return comms_send(a1, sapi_body, v8);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, __int64 a3)
{
_QWORD *i; // rbx
_QWORD *j; // rbx
size_t v6; // rax
size_t v7; // rax
size_t v8; // 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");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(_QWORD **)(a2 + 8); i; i = (_QWORD *)i[1] )
xmlmsg_add_topic(sapi_body, *i);
for ( j = *(_QWORD **)(a3 + 8); j; j = (_QWORD *)j[1] )
xmlmsg_add_topic(sapi_body, *j);
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v6 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v6);
v7 = strlen(sapi_header);
comms_send(a1, sapi_header, v7);
v8 = strlen(sapi_body);
return comms_send(a1, sapi_body, v8);
}

original_code:
void sapi_respond_getBusInfo(int client_socket, list_t* sub, list_t* pub)
{
 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_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    list_item_t* it;
    for(it = sub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (topic_t*)it->data);
    for(it = pub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (topic_t*)it->data);
    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_getBusInfo(int client_socket, struct list_t *sub, struct list_t *pub)
{
 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_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    struct list_item_t *it;
    for(it = sub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (struct topic_t *)it->data);
    for(it = pub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (struct topic_t *)it->data);
    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));
}

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:
pub
struct list_t *

return_type: void

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

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

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

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


decompiled_code:
__int64 __fastcall sapi_respond_getPid(unsigned int a1, unsigned int 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_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");
xmlmsg_add_tag_with_uint(sapi_body, "i4", a2);
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 func1(unsigned int a1, unsigned int 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_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");
xmlmsg_add_tag_with_uint(sapi_body, "i4", a2);
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_getPid(int client_socket, unsigned int pid)
{
 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_uint(sapi_body, "i4", pid);
  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));
}

variable_types:
pid
unsigned int


decompiled_code:
__int64 __fastcall sapi_respond_getPublications_getSubscriptions(unsigned int a1, __int64 a2)
{
__int64 *i; // rbx
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
size_t v6; // 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");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(__int64 **)(a2 + 8); i; i = (__int64 *)i[1] )
{
v3 = *i;
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", *(_QWORD *)v3);
xmlmsg_add_tag_with_string(sapi_body, "value", **(_QWORD **)(v3 + 16));
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_method_response(sapi_body);
v4 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v4);
v5 = strlen(sapi_header);
comms_send(a1, sapi_header, v5);
v6 = strlen(sapi_body);
return comms_send(a1, sapi_body, v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
__int64 *i; // rbx
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
size_t v6; // 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");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(__int64 **)(a2 + 8); i; i = (__int64 *)i[1] )
{
v3 = *i;
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", *(_QWORD *)v3);
xmlmsg_add_tag_with_string(sapi_body, "value", **(_QWORD **)(v3 + 16));
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_method_response(sapi_body);
v4 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v4);
v5 = strlen(sapi_header);
comms_send(a1, sapi_header, v5);
v6 = strlen(sapi_body);
return comms_send(a1, sapi_body, v6);
}

original_code:
void sapi_respond_getPublications_getSubscriptions(int client_socket, list_t* pub)
{
 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_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    list_item_t* it;
    for(it = pub->begin; it != ((void *)0); it = it->next)
    {
     topic_t* t = it->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", t->name);
        xmlmsg_add_tag_with_string(sapi_body, "value", (string)(t->msg_type->type));
       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_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_getPublications_getSubscriptions(int client_socket, struct list_t *pub)
{
 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_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    struct list_item_t *it;
    for(it = pub->begin; it != ((void *)0); it = it->next)
    {
     struct topic_t *t = it->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", t->name);
        xmlmsg_add_tag_with_string(sapi_body, "value", (string)(t->msg_type->type));
       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_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));
}

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


decompiled_code:
__int64 __fastcall sapi_respond_publisherUpdate(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // 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");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v1 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v1);
v2 = strlen(sapi_header);
comms_send(a1, sapi_header, v2);
v3 = strlen(sapi_body);
return comms_send(a1, sapi_body, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // 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");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v1 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v1);
v2 = strlen(sapi_header);
comms_send(a1, sapi_header, v2);
v3 = strlen(sapi_body);
return comms_send(a1, sapi_body, v3);
}

original_code:
void sapi_respond_publisherUpdate(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:
__int64 __fastcall sapi_parse_publisherUpdate_request(const char *a1, __int64 a2)
{
char *v2; // rax
__int64 v3; // rbp
char *v4; // rax
char *v5; // rbx
const char *v6; // rbx
__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; // rbp
char *v4; // rax
char *v5; // rbx
const char *v6; // rbx
__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; } *


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
size_t v11; // rax
size_t v12; // rax
int i; // ebx

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 = strlen(sapi_header);
comms_send(v10, sapi_header, v11);
v12 = strlen(sapi_body);
comms_send(v10, sapi_body, v12);
for ( i = 0; i <= 99; i += comms_recv(v10, a5 + i, 2048LL) )
;
comms_disconnect(v10);
*(_BYTE *)(a5 + i) = 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
size_t v11; // rax
size_t v12; // rax
int i; // ebx

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 = strlen(sapi_header);
comms_send(v10, sapi_header, v11);
v12 = strlen(sapi_body);
comms_send(v10, sapi_body, v12);
for ( i = 0; i <= 99; i += comms_recv(v10, a5 + i, 2048LL) )
;
comms_disconnect(v10);
*(_BYTE *)(a5 + i) = 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));
}

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:
__int64 __fastcall sapi_respond_shutdown(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // 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");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v1 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v1);
v2 = strlen(sapi_header);
comms_send(a1, sapi_header, v2);
v3 = strlen(sapi_body);
return comms_send(a1, sapi_body, v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // 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");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v1 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v1);
v2 = strlen(sapi_header);
comms_send(a1, sapi_header, v2);
v3 = strlen(sapi_body);
return comms_send(a1, sapi_body, v3);
}

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
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char **a2)
{
const char *v2; // rbp
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = *a2;
v5[0] = strlen(*a2);
v4 = a1;
tcpmsg_init(&v4);
tcpmsg_add_raw_data(&v4, v5, 4LL);
tcpmsg_add_raw_data(&v4, v2, v5[0]);
tcpmsg_finalize(a1, v4 - a1);
return v4 - 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)
{
char v1; // dl
__int64 result; // rax

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

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

v1 = mapi_call_deleteParam(pico_node[1], a1, &response);
result = FALSE;
if ( v1 )
result = mapi_parse_deleteParam_response(&response);
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)
{
unsigned int v3; // er13
struct ifaddrs *v4; // rbx
struct sockaddr *v5; // rsi
char v7[24]; // [rsp+0h] [rbp-48h] BYREF
struct ifaddrs *ifap; // [rsp+18h] [rbp-30h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func3(char **a1, const char *a2)
{
unsigned int v3; // er13
struct ifaddrs *v4; // rbx
struct sockaddr *v5; // rsi
char v7[24]; // [rsp+0h] [rbp-48h] BYREF
struct ifaddrs *ifap; // [rsp+18h] [rbp-30h] BYREF

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

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 v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_DWORD *)&v4.sa_data[2] = inet_addr(*(const char **)a1);
*(_WORD *)v4.sa_data = _bswap_16(*(_WORD *)(a1 + 8));
if ( connect(v2, &v4, 0x10u) < 0 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_DWORD *)&v4.sa_data[2] = inet_addr(*(const char **)a1);
*(_WORD *)v4.sa_data = func0(*(_WORD *)(a1 + 8));
if ( connect(v2, &v4, 0x10u) < 0 )
v2 = -1;
return v2;
}

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:
int __fastcall comms_disconnect(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
return close(a1);
}

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; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
socklen_t len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_DWORD *)&v4.sa_data[10] = 0;
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v4.sa_data = _bswap_16(0);
len[0] = 16;
if ( bind(v2, &v4, 0x10u) < 0 )
return (unsigned int)-1;
if ( getsockname(v2, &v4, len) < 0 )
return (unsigned int)-1;
*(_WORD *)(a1 + 8) = _bswap_16(*(__int16 *)v4.sa_data);
if ( listen(v2, 5) < 0 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
socklen_t len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_DWORD *)&v4.sa_data[10] = 0;
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)func1(0);
*(_WORD *)v4.sa_data = func0(0);
len[0] = 16;
if ( bind(v2, &v4, 0x10u) < 0 )
return (unsigned int)-1;
if ( getsockname(v2, &v4, len) < 0 )
return (unsigned int)-1;
*(_WORD *)(a1 + 8) = func0(*(__int16 *)v4.sa_data);
if ( 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; // r12
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-BCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-B8h] BYREF
struct timeval timeout; // [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 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v1;
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) <= 0 )
return -1;
if ( (readfds.fds_bits[fd / 64] & v1) == 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; // r12
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-BCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-B8h] BYREF
struct timeval timeout; // [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 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v1;
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) <= 0 )
return -1;
if ( (readfds.fds_bits[fd / 64] & v1) == 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(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
__int64 i; // rdx
__int64 v6; // rax
__int64 j; // r13
int v8; // edi
socklen_t addr_len; // [rsp+Ch] [rbp-CCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-A8h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 1LL;
addr_len = 16;
memset(&readfds, 0, sizeof(readfds));
if ( a3 <= 0 )
{
LODWORD(v6) = select(1024, &readfds, 0LL, 0LL, &timeout);
}
else
{
v4 = (unsigned int)a3;
for ( i = 0LL; i != v4; ++i )
{
readfds.fds_bits[*(_DWORD *)(a1 + 4 * i) / 64] |= 1LL << (*(_DWORD *)(a1 + 4 * i) % 64);
*(_DWORD *)(a2 + 4 * i) = -1;
}
LODWORD(v6) = select(1024, &readfds, 0LL, 0LL, &timeout);
if ( (int)v6 > 0 )
{
for ( j = 0LL; j != v4; ++j )
{
v8 = *(_DWORD *)(a1 + 4 * j);
v6 = v8 / 64;
if ( (readfds.fds_bits[v6] & (1LL << (v8 % 64))) != 0 )
{
LODWORD(v6) = accept(v8, &addr, &addr_len);
*(_DWORD *)(a2 + 4 * j) = v6;
}
}
}
}
return v6;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
__int64 i; // rdx
__int64 v6; // rax
__int64 j; // r13
int v8; // edi
socklen_t addr_len; // [rsp+Ch] [rbp-CCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-A8h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 1LL;
addr_len = 16;
memset(&readfds, 0, sizeof(readfds));
if ( a3 <= 0 )
{
LODWORD(v6) = select(1024, &readfds, 0LL, 0LL, &timeout);
}
else
{
v4 = (unsigned int)a3;
for ( i = 0LL; i != v4; ++i )
{
readfds.fds_bits[*(_DWORD *)(a1 + 4 * i) / 64] |= 1LL << (*(_DWORD *)(a1 + 4 * i) % 64);
*(_DWORD *)(a2 + 4 * i) = -1;
}
LODWORD(v6) = select(1024, &readfds, 0LL, 0LL, &timeout);
if ( (int)v6 > 0 )
{
for ( j = 0LL; j != v4; ++j )
{
v8 = *(_DWORD *)(a1 + 4 * j);
v6 = v8 / 64;
if ( (readfds.fds_bits[v6] & (1LL << (v8 % 64))) != 0 )
{
LODWORD(v6) = accept(v8, &addr, &addr_len);
*(_DWORD *)(a2 + 4 * j) = v6;
}
}
}
}
return v6;
}

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)
{
_QWORD *i; // rsi
_QWORD *j; // rsi
struct timeval v4; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_QWORD *i; // rsi
_QWORD *j; // rsi
struct timeval v4; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v4.tv_sec = 0LL;
v4.tv_usec = 1LL;
memset(&readfds, 0, sizeof(readfds));
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
readfds.fds_bits[*(_DWORD *)(*i + 16LL) / 64] |= 1LL << (*(_DWORD *)(*i + 16LL) % 64);
if ( select(1024, &readfds, 0LL, 0LL, &v4) <= 0 )
return FALSE;
for ( j = *(_QWORD **)(a1 + 8); j; j = (_QWORD *)j[1] )
*(_BYTE *)(*j + 20LL) = (readfds.fds_bits[*(_DWORD *)(*j + 16LL) / 64] & (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 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 *v9; // rbp
int v10; // eax
const char *v11; // rbp
__int64 v12; // rbx

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

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

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

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


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

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

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

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

original_code:
void tcpros_parse_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