decompiled_code:
__int64 __fastcall read_settings(__int64 fd, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
char v4; // bp
unsigned int v5; // er13
void *v6; // rax
unsigned int v7; // ebp
int v8; // edx
__int64 result; // rax
unsigned int v10; // eax
int *v11; // rbx
char *v12; // rax
socklen_t len; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-158h] BYREF
__int64 v15; // [rsp+110h] [rbp-58h] BYREF
__int64 v16; // [rsp+118h] [rbp-50h]
__int64 v17; // [rsp+120h] [rbp-48h]
__int64 v18; // [rsp+128h] [rbp-40h]
__int64 v19; // [rsp+130h] [rbp-38h]

if ( (_DWORD)fd == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0x57u, "read_settings");
if ( !a2 )
_assert_fail("settings != NULL", "serialise.c", 0x58u, "read_settings");
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v2 = recv_ign_signal(fd, &v15, 40LL, 0LL);
v3 = v2;
if ( v2 != 40 )
{
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
goto LABEL_20;
}
if ( (_DWORD)v15 != (unsigned int)_bswap_32(7u) )
{
LABEL_20:
v10 = _bswap_32(v15);
fprintf(stderr, "Invalid setting struct received (size:%d vs %d, ver:%d vs %d\n", v3, 40LL, v10, 7LL);
return 0xFFFFFFFFLL;
}
*(_DWORD *)a2 = _bswap_32(HIDWORD(v15));
*(_DWORD *)(a2 + 4) = _bswap_32(v16);
*(_DWORD *)(a2 + 8) = _bswap_32(HIDWORD(v16));
v4 = (32 * (BYTE4(v17) & 1)) | ((16 * (BYTE3(v17) & 1)) | (8 * (BYTE2(v17) & 1)) | ((4 * (BYTE1(v17) & 1)) | (2 * (v17 & 1)) | *(_BYTE *)(a2 + 12) & 0xF9) & 0xE7) & 0xDF;
*(_BYTE *)(a2 + 12) = v4;
*(_DWORD *)(a2 + 88) = BYTE5(v17);
*(_DWORD *)(a2 + 40) = _bswap_32(v18);
*(_DWORD *)(a2 + 44) = _bswap_32(HIDWORD(v18));
*(_DWORD *)(a2 + 48) = _bswap_32(v19);
*(_WORD *)(a2 + 64) = _bswap_16(SWORD2(v19));
*(_DWORD *)(a2 + 68) = BYTE6(v19);
*(_BYTE *)(a2 + 12) = v4 & 0xFE;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_DWORD *)(a2 + 32) = 1;
*(_DWORD *)(a2 + 36) = 1;
*(_QWORD *)(a2 + 56) = 0LL;
if ( (v4 & 0x20) == 0 )
goto LABEL_9;
len = 128;
if ( getpeername(fd, &addr, &len) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s:%d read_settings() getpeername error (%d) %s\n", "serialise.c", 135LL, (unsigned int)*v11, v12);
return 0xFFFFFFFFLL;
}
*(_WORD *)addr.sa_data = 0;
if ( !addr_to_ipstr(&addr, len, &reverse_host, 1025LL) )
{
fprintf(stderr, "%s:%d read_settings() addr_to_ipstr error\n", "serialise.c", 145LL);
return 0xFFFFFFFFLL;
}
*(_QWORD *)(a2 + 56) = &reverse_host;
LABEL_9:
v5 = *(_DWORD *)(a2 + 68);
v6 = calloc(v5, 0x98uLL);
*(_QWORD *)(a2 + 72) = v6;
if ( v6 )
{
v7 = 0;
if ( v5 )
{
while ( (unsigned int)recv_ign_signal((unsigned int)fd, &len, 1LL, 0LL) == 1 )
{
v8 = recv_ign_signal((unsigned int)fd, &addr, (unsigned __int8)len, 0LL);
if ( (unsigned __int8)len != v8 )
break;
*((_BYTE *)&addr.sa_family + (unsigned __int8)len) = 0;
if ( (unsigned int)parse_test(a2, &addr, *(_QWORD *)(a2 + 72) + 152LL * v7) )
break;
++v7;
v5 = *(_DWORD *)(a2 + 68);
if ( v5 <= v7 )
goto LABEL_15;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_15:
*(_DWORD *)(a2 + 84) = count_server_cores(*(_QWORD *)(a2 + 72), v5);
*(_DWORD *)(a2 + 80) = count_client_cores(*(_QWORD *)(a2 + 72), *(unsigned int *)(a2 + 68));
result = 0LL;
}
}
else
{
fprintf(stderr, "%s:%d read_settings() calloc error\n", "serialise.c", 155LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 fd, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
char v4; // bp
unsigned int v5; // er13
void *v6; // rax
unsigned int v7; // ebp
int v8; // edx
__int64 result; // rax
unsigned int v10; // eax
int *v11; // rbx
char *v12; // rax
socklen_t len; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-158h] BYREF
__int64 v15; // [rsp+110h] [rbp-58h] BYREF
__int64 v16; // [rsp+118h] [rbp-50h]
__int64 v17; // [rsp+120h] [rbp-48h]
__int64 v18; // [rsp+128h] [rbp-40h]
__int64 v19; // [rsp+130h] [rbp-38h]

if ( (_DWORD)fd == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0x57u, "read_settings");
if ( !a2 )
_assert_fail("settings != NULL", "serialise.c", 0x58u, "read_settings");
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v2 = recv_ign_signal(fd, &v15, 40LL, 0LL);
v3 = v2;
if ( v2 != 40 )
{
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
goto LABEL_20;
}
if ( (_DWORD)v15 != (unsigned int)func0(7u) )
{
LABEL_20:
v10 = func0(v15);
fprintf(stderr, "Invalid setting struct received (size:%d vs %d, ver:%d vs %d\n", v3, 40LL, v10, 7LL);
return 0xFFFFFFFFLL;
}
*(_DWORD *)a2 = func0(HIDWORD(v15));
*(_DWORD *)(a2 + 4) = func0(v16);
*(_DWORD *)(a2 + 8) = func0(HIDWORD(v16));
v4 = (32 * (BYTE4(v17) & 1)) | ((16 * (BYTE3(v17) & 1)) | (8 * (BYTE2(v17) & 1)) | ((4 * (BYTE1(v17) & 1)) | (2 * (v17 & 1)) | *(_BYTE *)(a2 + 12) & 0xF9) & 0xE7) & 0xDF;
*(_BYTE *)(a2 + 12) = v4;
*(_DWORD *)(a2 + 88) = BYTE5(v17);
*(_DWORD *)(a2 + 40) = func0(v18);
*(_DWORD *)(a2 + 44) = func0(HIDWORD(v18));
*(_DWORD *)(a2 + 48) = func0(v19);
*(_WORD *)(a2 + 64) = func1(SWORD2(v19));
*(_DWORD *)(a2 + 68) = BYTE6(v19);
*(_BYTE *)(a2 + 12) = v4 & 0xFE;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_DWORD *)(a2 + 32) = 1;
*(_DWORD *)(a2 + 36) = 1;
*(_QWORD *)(a2 + 56) = 0LL;
if ( (v4 & 0x20) == 0 )
goto LABEL_9;
len = 128;
if ( getpeername(fd, &addr, &len) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s:%d read_settings() getpeername error (%d) %s\n", "serialise.c", 135LL, (unsigned int)*v11, v12);
return 0xFFFFFFFFLL;
}
*(_WORD *)addr.sa_data = 0;
if ( !addr_to_ipstr(&addr, len, &reverse_host, 1025LL) )
{
fprintf(stderr, "%s:%d read_settings() addr_to_ipstr error\n", "serialise.c", 145LL);
return 0xFFFFFFFFLL;
}
*(_QWORD *)(a2 + 56) = &reverse_host;
LABEL_9:
v5 = *(_DWORD *)(a2 + 68);
v6 = calloc(v5, 0x98uLL);
*(_QWORD *)(a2 + 72) = v6;
if ( v6 )
{
v7 = 0;
if ( v5 )
{
while ( (unsigned int)recv_ign_signal((unsigned int)fd, &len, 1LL, 0LL) == 1 )
{
v8 = recv_ign_signal((unsigned int)fd, &addr, (unsigned __int8)len, 0LL);
if ( (unsigned __int8)len != v8 )
break;
*((_BYTE *)&addr.sa_family + (unsigned __int8)len) = 0;
if ( (unsigned int)parse_test(a2, &addr, *(_QWORD *)(a2 + 72) + 152LL * v7) )
break;
++v7;
v5 = *(_DWORD *)(a2 + 68);
if ( v5 <= v7 )
goto LABEL_15;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_15:
*(_DWORD *)(a2 + 84) = count_server_cores(*(_QWORD *)(a2 + 72), v5);
*(_DWORD *)(a2 + 80) = count_client_cores(*(_QWORD *)(a2 + 72), *(unsigned int *)(a2 + 68));
result = 0LL;
}
}
else
{
fprintf(stderr, "%s:%d read_settings() calloc error\n", "serialise.c", 155LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int read_settings( int s, struct settings * settings ) {
 int ret;
 unsigned int i = 0;
 struct network_settings net_settings;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "serialise.c", 88, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_settings, 0, sizeof(net_settings) );
 ret = recv_ign_signal(s, (char *)&net_settings, sizeof(net_settings), 0);
 if ( ret != sizeof(net_settings) || net_settings.version != htonl(7) ) {
  if ( ret > 0 )
   fprintf(stderr, "Invalid setting struct received (size:%d vs %d, ver:%d vs %d\n", ret, (int)sizeof(net_settings), ntohl(net_settings.version), 7 );
  return -1;
 }
 settings->duration = ntohl( net_settings.duration );
 settings->type = ntohl( net_settings.type );
 settings->protocol = ntohl( net_settings.protocol );
 settings->verbose = net_settings.verbose;
 settings->dirty = net_settings.dirty;
 settings->timestamp = net_settings.timestamp;
 settings->disable_nagles = net_settings.disable_nagles;
 settings->reverse = net_settings.reverse;
 settings->threaded_model = net_settings.threaded_model;
 settings->message_size = ntohl( net_settings.message_size );
 settings->socket_size = ntohl( net_settings.socket_size );
 settings->rate = ntohl( net_settings.rate );
 settings->port = ntohs( net_settings.port );
 settings->tests = net_settings.tests;
 settings->daemon = 0;
 settings->confidence_lvl = 0.0;
 settings->confidence_int = 0.0;
 settings->min_iterations = 1;
 settings->max_iterations = 1;
 settings->server_host = ((void *)0);
 if (settings->reverse) {
         struct sockaddr_storage addr;
         socklen_t addr_len = sizeof(addr);
  if ( getpeername(s, (struct sockaddr *)&addr, &addr_len) ) {
   fprintf(stderr, "%s:%d read_settings() getpeername error (%d) %s\n", "serialise.c", 135, (*__errno_location ()), strerror((*__errno_location ())) );
   return -1;
  }
  ((struct sockaddr_in *)&addr)->sin_port = 0;
  if ( !addr_to_ipstr((struct sockaddr *)&addr, addr_len, reverse_host, sizeof(reverse_host)) ) {
   fprintf(stderr, "%s:%d read_settings() addr_to_ipstr error\n", "serialise.c", 145);
   return -1;
  }
  settings->server_host = reverse_host;
 }
 settings->test = calloc( settings->tests, sizeof(*settings->test) );
 if ( !settings->test ) {
  fprintf(stderr, "%s:%d read_settings() calloc error\n", "serialise.c", 155 );
  return -1;
 }
 for (i = 0; i < settings->tests; i++) {
  char buffer[ 256 ];
  unsigned char buflen;
  ret = recv_ign_signal(s, &buflen, sizeof(buflen), 0);
  if ( ret != sizeof(buflen) ) {
   return -1;
  }
  ret = recv_ign_signal(s, buffer, buflen, 0);
  if ( ret != buflen ) {
   return -1;
  }
  buffer [ buflen ] = '\0';
  if ( parse_test(settings, buffer, &settings->test[i]) )
   return -1;
 }
 settings->servercores = count_server_cores( settings->test, settings->tests);
 settings->clientcores = count_client_cores( settings->test, settings->tests);
 return 0;
}

canonical_original_code:
int read_settings(int s, struct settings *settings) {
 int ret;
 unsigned int i = 0;
 struct network_settings net_settings;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "serialise.c", 88, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_settings, 0, sizeof(net_settings) );
 ret = recv_ign_signal(s, (char *)&net_settings, sizeof(net_settings), 0);
 if ( ret != sizeof(net_settings) || net_settings.version != htonl(7) ) {
  if ( ret > 0 )
   fprintf(stderr, "Invalid setting struct received (size:%d vs %d, ver:%d vs %d\n", ret, (int)sizeof(net_settings), ntohl(net_settings.version), 7 );
  return -1;
 }
 settings->duration = ntohl( net_settings.duration );
 settings->type = ntohl( net_settings.type );
 settings->protocol = ntohl( net_settings.protocol );
 settings->verbose = net_settings.verbose;
 settings->dirty = net_settings.dirty;
 settings->timestamp = net_settings.timestamp;
 settings->disable_nagles = net_settings.disable_nagles;
 settings->reverse = net_settings.reverse;
 settings->threaded_model = net_settings.threaded_model;
 settings->message_size = ntohl( net_settings.message_size );
 settings->socket_size = ntohl( net_settings.socket_size );
 settings->rate = ntohl( net_settings.rate );
 settings->port = ntohs( net_settings.port );
 settings->tests = net_settings.tests;
 settings->daemon = 0;
 settings->confidence_lvl = 0.0;
 settings->confidence_int = 0.0;
 settings->min_iterations = 1;
 settings->max_iterations = 1;
 settings->server_host = ((void *)0);
 if (settings->reverse) {
         struct sockaddr_storage addr;
         unsigned int addr_len = sizeof(addr);
  if ( getpeername(s, (struct sockaddr *)&addr, &addr_len) ) {
   fprintf(stderr, "%s:%d read_settings() getpeername error (%d) %s\n", "serialise.c", 135, (*__errno_location ()), strerror((*__errno_location ())) );
   return -1;
  }
  ((struct sockaddr_in *)&addr)->sin_port = 0;
  if ( !addr_to_ipstr((struct sockaddr *)&addr, addr_len, reverse_host, sizeof(reverse_host)) ) {
   fprintf(stderr, "%s:%d read_settings() addr_to_ipstr error\n", "serialise.c", 145);
   return -1;
  }
  settings->server_host = reverse_host;
 }
 settings->test = calloc( settings->tests, sizeof(*settings->test) );
 if ( !settings->test ) {
  fprintf(stderr, "%s:%d read_settings() calloc error\n", "serialise.c", 155 );
  return -1;
 }
 for (i = 0; i < settings->tests; i++) {
  char buffer[256];
  unsigned char buflen;
  ret = recv_ign_signal(s, &buflen, sizeof(buflen), 0);
  if ( ret != sizeof(buflen) ) {
   return -1;
  }
  ret = recv_ign_signal(s, buffer, buflen, 0);
  if ( ret != buflen ) {
   return -1;
  }
  buffer [ buflen ] = '\0';
  if ( parse_test(settings, buffer, &settings->test[i]) )
   return -1;
 }
 settings->servercores = count_server_cores( settings->test, settings->tests);
 settings->clientcores = count_client_cores( settings->test, settings->tests);
 return 0;
}

variable_types: s int

variable_types: struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; } *

variable_types: ret int

variable_types:
i
unsigned int

variable_types: struct network_settings { unsigned int version; unsigned int duration; unsigned int type; unsigned int protocol; unsigned char verbose; unsigned char dirty; unsigned char timestamp; unsigned char disable_nagles; unsigned char reverse; unsigned char threaded_model; unsigned int message_size; unsigned int socket_size; unsigned int rate; unsigned short port; unsigned char tests; }

variable_types:
buffer
char [256]

variable_types:
buflen
unsigned char

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


repo: bramp/threadnetperf

original_code:
int send_settings( int s, const struct settings * settings ) {
 int ret;
 struct network_settings net_settings;
 unsigned int i;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 191, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "serialise.c", 192, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_settings, 0, sizeof(net_settings) );
 net_settings.version = htonl( 7 );
 net_settings.duration = htonl( settings->duration );
 net_settings.type = htonl( (unsigned int)settings->type );
 net_settings.protocol = htonl( (unsigned int)settings->protocol );
 net_settings.verbose = settings->verbose;
 net_settings.dirty = settings->dirty;
 net_settings.timestamp = settings->timestamp;
 net_settings.disable_nagles = settings->disable_nagles;
 net_settings.reverse = settings->reverse;
 net_settings.threaded_model = settings->threaded_model;
 net_settings.message_size = htonl( settings->message_size );
 net_settings.socket_size = htonl( settings->socket_size );
 net_settings.rate = htonl( settings->rate );
 net_settings.port = htons( settings->port );
 net_settings.tests = settings->tests;
 ret = send_ign_signal(s, (char *)&net_settings, sizeof(net_settings), 0);
 if ( ret != sizeof(net_settings) ) {
  return -1;
 }
 for (i = 0; i < settings->tests; i++) {
  char buffer[256 + 1];
  const struct test * test = &settings->test[i];
  sprintf(&buffer[1], "%u(%u-%u) ", test->connections, test->clientcores, test->servercores);
  ((void) sizeof ((strlen(&buffer[1]) < 256) ? 1 : 0), __extension__ ({ if (strlen(&buffer[1]) < 256) ; else __assert_fail ("strlen(&buffer[1]) < 256", "serialise.c", 228, __extension__ __PRETTY_FUNCTION__); }));
  buffer[0] = (char)strlen(&buffer[1]);
  ret = send_ign_signal(s, buffer, *buffer + 1, 0);
  if ( ret != *buffer + 1 ) {
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int send_settings(int s, struct settings *settings) {
 int ret;
 struct network_settings net_settings;
 unsigned int i;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 191, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "serialise.c", 192, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_settings, 0, sizeof(net_settings) );
 net_settings.version = htonl( 7 );
 net_settings.duration = htonl( settings->duration );
 net_settings.type = htonl( (unsigned int)settings->type );
 net_settings.protocol = htonl( (unsigned int)settings->protocol );
 net_settings.verbose = settings->verbose;
 net_settings.dirty = settings->dirty;
 net_settings.timestamp = settings->timestamp;
 net_settings.disable_nagles = settings->disable_nagles;
 net_settings.reverse = settings->reverse;
 net_settings.threaded_model = settings->threaded_model;
 net_settings.message_size = htonl( settings->message_size );
 net_settings.socket_size = htonl( settings->socket_size );
 net_settings.rate = htonl( settings->rate );
 net_settings.port = htons( settings->port );
 net_settings.tests = settings->tests;
 ret = send_ign_signal(s, (char *)&net_settings, sizeof(net_settings), 0);
 if ( ret != sizeof(net_settings) ) {
  return -1;
 }
 for (i = 0; i < settings->tests; i++) {
  char buffer[-1];
  struct test *test = &settings->test[i];
  sprintf(&buffer[1], "%u(%u-%u) ", test->connections, test->clientcores, test->servercores);
  ((void) sizeof ((strlen(&buffer[1]) < 256) ? 1 : 0), __extension__ ({ if (strlen(&buffer[1]) < 256) ; else __assert_fail ("strlen(&buffer[1]) < 256", "serialise.c", 228, __extension__ __PRETTY_FUNCTION__); }));
  buffer[0] = (char)strlen(&buffer[1]);
  ret = send_ign_signal(s, buffer, *buffer + 1, 0);
  if ( ret != *buffer + 1 ) {
   return -1;
  }
 }
 return 0;
}

variable_types:
buffer
char [-1]

variable_types: struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *

return_type: int

user_defined_types: struct network_settings { unsigned int version; unsigned int duration; unsigned int type; unsigned int protocol; unsigned char verbose; unsigned char dirty; unsigned char timestamp; unsigned char disable_nagles; unsigned char reverse; unsigned char threaded_model; unsigned int message_size; unsigned int socket_size; unsigned int rate; unsigned short port; unsigned char tests; }

user_defined_types: struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; }

user_defined_types: struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage addr; unsigned int addr_len; }


decompiled_code:
__int64 __fastcall read_results(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 *v3; // rbp
int v4; // eax
int *v6; // rbx
char *v7; // rax
__int64 v8; // [rsp+0h] [rbp-58h] BYREF
__int64 v9; // [rsp+8h] [rbp-50h]
__int64 v10; // [rsp+10h] [rbp-48h]
__int64 v11; // [rsp+18h] [rbp-40h]
__int64 v12; // [rsp+20h] [rbp-38h]
__int64 v13; // [rsp+28h] [rbp-30h]

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0xF8u, "read_results");
if ( !a2 )
_assert_fail("stats != NULL", "serialise.c", 0xF9u, "read_results");
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v2 = 48LL;
v3 = &v8;
while ( 1 )
{
v4 = recv_ign_signal(a1, v3, v2, 0LL);
if ( v4 <= 0 )
break;
if ( v4 > v2 )
_assert_fail("ret <= p_len", "serialise.c", 0x105u, "read_results");
v3 = (__int64 *)((char *)v3 + v4);
v2 -= v4;
if ( !v2 )
{
*(_DWORD *)a2 = _bswap_32(v8);
*(_QWORD *)(a2 + 8) = v9;
*(_QWORD *)(a2 + 16) = v10;
*(_QWORD *)(a2 + 24) = v11;
*(_QWORD *)(a2 + 32) = v12;
*(_QWORD *)(a2 + 40) = v13;
return 0LL;
}
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "serialise.c", 258LL, a1, (unsigned int)*v6, v7);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 *v3; // rbp
int v4; // eax
int *v6; // rbx
char *v7; // rax
__int64 v8; // [rsp+0h] [rbp-58h] BYREF
__int64 v9; // [rsp+8h] [rbp-50h]
__int64 v10; // [rsp+10h] [rbp-48h]
__int64 v11; // [rsp+18h] [rbp-40h]
__int64 v12; // [rsp+20h] [rbp-38h]
__int64 v13; // [rsp+28h] [rbp-30h]

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0xF8u, "read_results");
if ( !a2 )
_assert_fail("stats != NULL", "serialise.c", 0xF9u, "read_results");
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v2 = 48LL;
v3 = &v8;
while ( 1 )
{
v4 = recv_ign_signal(a1, v3, v2, 0LL);
if ( v4 <= 0 )
break;
if ( v4 > v2 )
_assert_fail("ret <= p_len", "serialise.c", 0x105u, "read_results");
v3 = (__int64 *)((char *)v3 + v4);
v2 -= v4;
if ( !v2 )
{
*(_DWORD *)a2 = func0(v8);
*(_QWORD *)(a2 + 8) = v9;
*(_QWORD *)(a2 + 16) = v10;
*(_QWORD *)(a2 + 24) = v11;
*(_QWORD *)(a2 + 32) = v12;
*(_QWORD *)(a2 + 40) = v13;
return 0LL;
}
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "serialise.c", 258LL, a1, (unsigned int)*v6, v7);
return 0xFFFFFFFFLL;
}

original_code:
int read_results( int s, struct stats * stats ) {
 struct network_stats net_stats;
 char *p = (char *)&net_stats;
 size_t p_len = sizeof(net_stats);
 int ret;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((stats != ((void *)0)) ? 1 : 0), __extension__ ({ if (stats != ((void *)0)) ; else __assert_fail ("stats != NULL", "serialise.c", 249, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_stats, 0, sizeof(net_stats) );
 do {
  ret = recv_ign_signal(s, p, p_len, 0);
  if ( ret <= 0 ) {
   fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "serialise.c", 258, s, (*__errno_location ()), strerror((*__errno_location ())));
   return -1;
  }
  ((void) sizeof ((ret <= p_len) ? 1 : 0), __extension__ ({ if (ret <= p_len) ; else __assert_fail ("ret <= p_len", "serialise.c", 261, __extension__ __PRETTY_FUNCTION__); }));
  p_len -= ret;
  p += ret;
 } while ( p_len > 0 );
 stats->cores = ntohl(net_stats.cores);
 stats->bytes_received = (net_stats.bytes_received);
 stats->pkts_received = (net_stats.pkts_received);
 stats->pkts_time = (net_stats.pkts_time);
 stats->timestamps = (net_stats.timestamps);
 stats->duration = (net_stats.duration);
 return 0;
}

canonical_original_code:
int read_results(int s, struct stats *stats) {
 struct network_stats net_stats;
 char *p = (char *)&net_stats;
 unsigned long p_len = sizeof(net_stats);
 int ret;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((stats != ((void *)0)) ? 1 : 0), __extension__ ({ if (stats != ((void *)0)) ; else __assert_fail ("stats != NULL", "serialise.c", 249, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_stats, 0, sizeof(net_stats) );
 do {
  ret = recv_ign_signal(s, p, p_len, 0);
  if ( ret <= 0 ) {
   fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "serialise.c", 258, s, (*__errno_location ()), strerror((*__errno_location ())));
   return -1;
  }
  ((void) sizeof ((ret <= p_len) ? 1 : 0), __extension__ ({ if (ret <= p_len) ; else __assert_fail ("ret <= p_len", "serialise.c", 261, __extension__ __PRETTY_FUNCTION__); }));
  p_len -= ret;
  p += ret;
 } while ( p_len > 0 );
 stats->cores = ntohl(net_stats.cores);
 stats->bytes_received = (net_stats.bytes_received);
 stats->pkts_received = (net_stats.pkts_received);
 stats->pkts_time = (net_stats.pkts_time);
 stats->timestamps = (net_stats.timestamps);
 stats->duration = (net_stats.duration);
 return 0;
}

variable_types: struct stats { unsigned int cores; unsigned long long bytes_received; unsigned long long pkts_received; unsigned long long pkts_time; unsigned long long timestamps; unsigned long long duration; } *

variable_types: struct network_stats { unsigned int cores; unsigned long bytes_received; unsigned long pkts_received; unsigned long pkts_time; unsigned long timestamps; unsigned long duration; }

variable_types:
p
char *


decompiled_code:
__int64 __fastcall send_results(unsigned int a1, __int64 a2)
{
int v3[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+8h] [rbp-40h]
__int64 v5; // [rsp+10h] [rbp-38h]
__int64 v6; // [rsp+18h] [rbp-30h]
__int64 v7; // [rsp+20h] [rbp-28h]
__int64 v8; // [rsp+28h] [rbp-20h]

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0x11Bu, "send_results");
if ( !a2 )
_assert_fail("stats != NULL", "serialise.c", 0x11Cu, "send_results");
v3[1] = 0;
v3[0] = _bswap_32(*(_DWORD *)a2);
v4 = *(_QWORD *)(a2 + 8);
v5 = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(a2 + 24);
v7 = *(_QWORD *)(a2 + 32);
v8 = *(_QWORD *)(a2 + 40);
return (unsigned int)-((unsigned int)send_ign_signal(a1, v3, 48LL, 0LL) != 48);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
int v3[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+8h] [rbp-40h]
__int64 v5; // [rsp+10h] [rbp-38h]
__int64 v6; // [rsp+18h] [rbp-30h]
__int64 v7; // [rsp+20h] [rbp-28h]
__int64 v8; // [rsp+28h] [rbp-20h]

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0x11Bu, "send_results");
if ( !a2 )
_assert_fail("stats != NULL", "serialise.c", 0x11Cu, "send_results");
v3[1] = 0;
v3[0] = func0(*(_DWORD *)a2);
v4 = *(_QWORD *)(a2 + 8);
v5 = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(a2 + 24);
v7 = *(_QWORD *)(a2 + 32);
v8 = *(_QWORD *)(a2 + 40);
return (unsigned int)-((unsigned int)send_ign_signal(a1, v3, 48LL, 0LL) != 48);
}

original_code:
int send_results( int s, const struct stats * stats ) {
 struct network_stats net_stats;
 int ret;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 283, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((stats != ((void *)0)) ? 1 : 0), __extension__ ({ if (stats != ((void *)0)) ; else __assert_fail ("stats != NULL", "serialise.c", 284, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_stats, 0, sizeof(net_stats) );
 net_stats.cores = htonl(stats->cores);
 net_stats.bytes_received = (stats->bytes_received);
 net_stats.pkts_received = (stats->pkts_received);
 net_stats.pkts_time = (stats->pkts_time);
 net_stats.timestamps = (stats->timestamps);
 net_stats.duration = (stats->duration);
 ret = send_ign_signal(s, (char *)&net_stats, sizeof(net_stats), 0);
 if ( ret != sizeof(net_stats) )
  return -1;
 return 0;
}

canonical_original_code:
int send_results(int s, struct stats *stats) {
 struct network_stats net_stats;
 int ret;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "serialise.c", 283, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((stats != ((void *)0)) ? 1 : 0), __extension__ ({ if (stats != ((void *)0)) ; else __assert_fail ("stats != NULL", "serialise.c", 284, __extension__ __PRETTY_FUNCTION__); }));
 memset( &net_stats, 0, sizeof(net_stats) );
 net_stats.cores = htonl(stats->cores);
 net_stats.bytes_received = (stats->bytes_received);
 net_stats.pkts_received = (stats->pkts_received);
 net_stats.pkts_time = (stats->pkts_time);
 net_stats.timestamps = (stats->timestamps);
 net_stats.duration = (stats->duration);
 ret = send_ign_signal(s, (char *)&net_stats, sizeof(net_stats), 0);
 if ( ret != sizeof(net_stats) )
  return -1;
 return 0;
}

user_defined_types: struct network_stats { unsigned int cores; unsigned long bytes_received; unsigned long pkts_received; unsigned long pkts_time; unsigned long timestamps; unsigned long duration; }

user_defined_types: struct stats { unsigned int cores; unsigned long long bytes_received; unsigned long long pkts_received; unsigned long long pkts_time; unsigned long long timestamps; unsigned long long duration; }


decompiled_code:
__int64 __fastcall prepare_servers(__int64 a1)
{
unsigned int v1; // er14
unsigned int i; // er12
__int64 v4; // rbp
char *v5; // rbx
char *v6; // rax

if ( !a1 )
_assert_fail("settings != NULL", "server.c", 0x15u, "prepare_servers");
if ( !*(_QWORD *)(a1 + 72) )
_assert_fail("settings->test != NULL", "server.c", 0x16u, "prepare_servers");
if ( sreq )
_assert_fail("sreq == NULL", "server.c", 0x18u, "prepare_servers");
if ( sreq_size )
_assert_fail("sreq_size == 0", "server.c", 0x19u, "prepare_servers");
sreq_size = *(unsigned int *)(a1 + 84);
sreq = calloc(sreq_size, 0x48uLL);
if ( sreq )
{
v1 = 0;
for ( i = 0; *(_DWORD *)(a1 + 68) > i; ++i )
{
v4 = *(_QWORD *)(a1 + 72) + 152LL * i;
v5 = (char *)sreq;
v6 = (char *)sreq + 72 * sreq_size;
if ( sreq >= v6 )
goto LABEL_21;
while ( *((_QWORD *)v5 + 2) )
{
if ( *((_DWORD *)v5 + 2) == *(_DWORD *)(v4 + 4) )
{
if ( v6 > v5 )
goto LABEL_16;
LABEL_21:
_assert_fail("s < &sreq[sreq_size]", "server.c", 0x2Fu, "prepare_servers");
}
v5 += 72;
if ( v5 >= v6 )
goto LABEL_21;
}
if ( v6 <= v5 )
goto LABEL_21;
*((_QWORD *)v5 + 2) = a1;
*((_DWORD *)v5 + 2) = *(_DWORD *)(v4 + 4);
*(_WORD *)v5 = _bswap_16(*(_WORD *)(v4 + 18));
*((_DWORD *)v5 + 1) = 0;
++v1;
LABEL_16:
*((_DWORD *)v5 + 1) += *(_DWORD *)(v4 + 8);
}
if ( !*((_QWORD *)sreq + 9 * sreq_size - 7) )
_assert_fail("sreq[sreq_size - 1].settings != NULL", "server.c", 0x41u, "prepare_servers");
}
else
{
fprintf(stderr, "%s:%d calloc() error\n", "server.c", 32LL);
sreq_size = 0LL;
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er14
unsigned int i; // er12
__int64 v4; // rbp
char *v5; // rbx
char *v6; // rax

if ( !a1 )
_assert_fail("settings != NULL", "server.c", 0x15u, "prepare_servers");
if ( !*(_QWORD *)(a1 + 72) )
_assert_fail("settings->test != NULL", "server.c", 0x16u, "prepare_servers");
if ( sreq )
_assert_fail("sreq == NULL", "server.c", 0x18u, "prepare_servers");
if ( sreq_size )
_assert_fail("sreq_size == 0", "server.c", 0x19u, "prepare_servers");
sreq_size = *(unsigned int *)(a1 + 84);
sreq = calloc(sreq_size, 0x48uLL);
if ( sreq )
{
v1 = 0;
for ( i = 0; *(_DWORD *)(a1 + 68) > i; ++i )
{
v4 = *(_QWORD *)(a1 + 72) + 152LL * i;
v5 = (char *)sreq;
v6 = (char *)sreq + 72 * sreq_size;
if ( sreq >= v6 )
goto LABEL_21;
while ( *((_QWORD *)v5 + 2) )
{
if ( *((_DWORD *)v5 + 2) == *(_DWORD *)(v4 + 4) )
{
if ( v6 > v5 )
goto LABEL_16;
LABEL_21:
_assert_fail("s < &sreq[sreq_size]", "server.c", 0x2Fu, "prepare_servers");
}
v5 += 72;
if ( v5 >= v6 )
goto LABEL_21;
}
if ( v6 <= v5 )
goto LABEL_21;
*((_QWORD *)v5 + 2) = a1;
*((_DWORD *)v5 + 2) = *(_DWORD *)(v4 + 4);
*(_WORD *)v5 = func0(*(_WORD *)(v4 + 18));
*((_DWORD *)v5 + 1) = 0;
++v1;
LABEL_16:
*((_DWORD *)v5 + 1) += *(_DWORD *)(v4 + 8);
}
if ( !*((_QWORD *)sreq + 9 * sreq_size - 7) )
_assert_fail("sreq[sreq_size - 1].settings != NULL", "server.c", 0x41u, "prepare_servers");
}
else
{
fprintf(stderr, "%s:%d calloc() error\n", "server.c", 32LL);
sreq_size = 0LL;
v1 = -1;
}
return v1;
}

original_code:
int prepare_servers(const struct settings * settings, void *data) {
 unsigned int i;
 int serverthreads = 0;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "server.c", 21, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings->test != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings->test != ((void *)0)) ; else __assert_fail ("settings->test != NULL", "server.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sreq == ((void *)0)) ? 1 : 0), __extension__ ({ if (sreq == ((void *)0)) ; else __assert_fail ("sreq == NULL", "server.c", 24, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sreq_size == 0) ? 1 : 0), __extension__ ({ if (sreq_size == 0) ; else __assert_fail ("sreq_size == 0", "server.c", 25, __extension__ __PRETTY_FUNCTION__); }));
 sreq_size = settings->servercores;
 sreq = calloc (sreq_size , sizeof(*sreq) );
 if ( !sreq ) {
  fprintf(stderr, "%s:%d calloc() error\n", "server.c", 32 );
  sreq_size = 0;
  return -1;
 }
 for ( i = 0; i < settings->tests; i++) {
  struct server_request *s;
  const struct test * test = &settings->test[i];
  for ( s = sreq; s < &sreq[sreq_size]; s++) {
   if ( s->settings == ((void *)0) || s->cores == test->servercores )
    break;
  }
  ((void) sizeof ((s < &sreq[sreq_size]) ? 1 : 0), __extension__ ({ if (s < &sreq[sreq_size]) ; else __assert_fail ("s < &sreq[sreq_size]", "server.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  if ( s->settings == ((void *)0) ) {
   s->settings = settings;
   s->cores = test->servercores;
   s->port = ntohs( ((struct sockaddr_in *)&test->addr)->sin_port );
   s->n = 0;
   serverthreads++;
  }
  s->n += test->connections;
 }
 ((void) sizeof ((sreq[sreq_size - 1].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (sreq[sreq_size - 1].settings != ((void *)0)) ; else __assert_fail ("sreq[sreq_size - 1].settings != NULL", "server.c", 65, __extension__ __PRETTY_FUNCTION__); }));
 return serverthreads;
}

canonical_original_code:
int prepare_servers(struct settings *settings, void *data) {
 unsigned int i;
 int serverthreads = 0;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "server.c", 21, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings->test != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings->test != ((void *)0)) ; else __assert_fail ("settings->test != NULL", "server.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sreq == ((void *)0)) ? 1 : 0), __extension__ ({ if (sreq == ((void *)0)) ; else __assert_fail ("sreq == NULL", "server.c", 24, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sreq_size == 0) ? 1 : 0), __extension__ ({ if (sreq_size == 0) ; else __assert_fail ("sreq_size == 0", "server.c", 25, __extension__ __PRETTY_FUNCTION__); }));
 sreq_size = settings->servercores;
 sreq = calloc (sreq_size , sizeof(*sreq) );
 if ( !sreq ) {
  fprintf(stderr, "%s:%d calloc() error\n", "server.c", 32 );
  sreq_size = 0;
  return -1;
 }
 for ( i = 0; i < settings->tests; i++) {
  struct server_request *s;
  struct test *test = &settings->test[i];
  for ( s = sreq; s < &sreq[sreq_size]; s++) {
   if ( s->settings == ((void *)0) || s->cores == test->servercores )
    break;
  }
  ((void) sizeof ((s < &sreq[sreq_size]) ? 1 : 0), __extension__ ({ if (s < &sreq[sreq_size]) ; else __assert_fail ("s < &sreq[sreq_size]", "server.c", 47, __extension__ __PRETTY_FUNCTION__); }));
  if ( s->settings == ((void *)0) ) {
   s->settings = settings;
   s->cores = test->servercores;
   s->port = ntohs( ((struct sockaddr_in *)&test->addr)->sin_port );
   s->n = 0;
   serverthreads++;
  }
  s->n += test->connections;
 }
 ((void) sizeof ((sreq[sreq_size - 1].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (sreq[sreq_size - 1].settings != ((void *)0)) ; else __assert_fail ("sreq[sreq_size - 1].settings != NULL", "server.c", 65, __extension__ __PRETTY_FUNCTION__); }));
 return serverthreads;
}

variable_types:
data
void *

variable_types: serverthreads int

variable_types: struct server_request { unsigned short port; unsigned int n; unsigned int cores; struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; } *settings; struct stats { unsigned int cores; unsigned long long bytes_received; unsigned long long pkts_received; unsigned long long pkts_time; unsigned long long timestamps; unsigned long long duration; } stats; } *

user_defined_types: struct server_request { unsigned short port; unsigned int n; unsigned int cores; struct settings *settings; struct stats stats; }


decompiled_code:
__int64 __fastcall create_servers(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebp
__int64 v3; // rdx
__int64 v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
_BYTE v8[152]; // [rsp+0h] [rbp-98h] BYREF

result = sreq_size;
if ( *(_DWORD *)(a1 + 84) != sreq_size )
_assert_fail("sreq_size == settings->servercores", "server.c", 0x49u, "create_servers");
v2 = 0;
v3 = 0LL;
if ( sreq_size )
{
while ( 1 )
{
v4 = 72 * v3;
v5 = (char *)sreq + 72 * v3;
if ( !*((_QWORD *)v5 + 2) )
_assert_fail("sreq[i].settings != NULL", "server.c", 0x50u, "create_servers");
cpu_setup(v8, *((unsigned int *)v5 + 2));
result = create_thread(&server_thread, (char *)sreq + v4, 128LL, v8, *(unsigned int *)(a1 + 88));
if ( (_DWORD)result )
break;
v3 = ++v2;
if ( v2 >= (unsigned __int64)sreq_size )
return result;
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%d create_thread() error (%d) %s\n", "server.c", 86LL, (unsigned int)*v6, v7);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebp
__int64 v3; // rdx
__int64 v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
_BYTE v8[152]; // [rsp+0h] [rbp-98h] BYREF

result = sreq_size;
if ( *(_DWORD *)(a1 + 84) != sreq_size )
_assert_fail("sreq_size == settings->servercores", "server.c", 0x49u, "create_servers");
v2 = 0;
v3 = 0LL;
if ( sreq_size )
{
while ( 1 )
{
v4 = 72 * v3;
v5 = (char *)sreq + 72 * v3;
if ( !*((_QWORD *)v5 + 2) )
_assert_fail("sreq[i].settings != NULL", "server.c", 0x50u, "create_servers");
cpu_setup(v8, *((unsigned int *)v5 + 2));
result = create_thread(&server_thread, (char *)sreq + v4, 128LL, v8, *(unsigned int *)(a1 + 88));
if ( (_DWORD)result )
break;
v3 = ++v2;
if ( v2 >= (unsigned __int64)sreq_size )
return result;
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%d create_thread() error (%d) %s\n", "server.c", 86LL, (unsigned int)*v6, v7);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int create_servers(const struct settings *settings, void *data) {
 unsigned int i;
 ((void) sizeof ((sreq_size == settings->servercores) ? 1 : 0), __extension__ ({ if (sreq_size == settings->servercores) ; else __assert_fail ("sreq_size == settings->servercores", "server.c", 73, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < sreq_size; i++) {
  cpu_set_t cpus;
  ((void) sizeof ((sreq[i].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (sreq[i].settings != ((void *)0)) ; else __assert_fail ("sreq[i].settings != NULL", "server.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  cpu_setup( &cpus, sreq[i].cores );
  if ( create_thread( server_thread, &sreq[i] , sizeof(cpus), &cpus, settings->threaded_model) ) {
   fprintf(stderr, "%s:%d create_thread() error (%d) %s\n", "server.c", 86, (*__errno_location ()), strerror((*__errno_location ())));
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int create_servers(struct settings *settings, void *data) {
 unsigned int i;
 ((void) sizeof ((sreq_size == settings->servercores) ? 1 : 0), __extension__ ({ if (sreq_size == settings->servercores) ; else __assert_fail ("sreq_size == settings->servercores", "server.c", 73, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < sreq_size; i++) {
  struct cpu_set_t cpus;
  ((void) sizeof ((sreq[i].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (sreq[i].settings != ((void *)0)) ; else __assert_fail ("sreq[i].settings != NULL", "server.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  cpu_setup( &cpus, sreq[i].cores );
  if ( create_thread( server_thread, &sreq[i] , sizeof(cpus), &cpus, settings->threaded_model) ) {
   fprintf(stderr, "%s:%d create_thread() error (%d) %s\n", "server.c", 86, (*__errno_location ()), strerror((*__errno_location ())));
   return -1;
  }
 }
 return 0;
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


decompiled_code:
void cleanup_servers()
{
free(sreq);
sreq = 0LL;
sreq_size = 0LL;
}

canonical_decompiled_code:
void func3()
{
free(sreq);
sreq = 0LL;
sreq_size = 0LL;
}

original_code:
void cleanup_servers() {
 free( sreq );
 sreq = ((void *)0);
 sreq_size = 0;
}

return_type: void


decompiled_code:
__int64 __fastcall prepare_clients(__int64 a1)
{
unsigned int v1; // er14
unsigned int v2; // er12
__int64 result; // rax
__m128i *v4; // rax
const __m128i *v5; // rbp
char *v6; // rbx
char *v7; // rax

if ( !a1 )
_assert_fail("settings != NULL", "client.c", 0x11u, "prepare_clients");
if ( !*(_QWORD *)(a1 + 72) )
_assert_fail("settings->test != NULL", "client.c", 0x12u, "prepare_clients");
if ( creq )
_assert_fail("creq == NULL", "client.c", 0x13u, "prepare_clients");
if ( creq_size )
_assert_fail("creq_size == 0", "client.c", 0x14u, "prepare_clients");
creq_size = *(unsigned int *)(a1 + 80);
creq = calloc(creq_size, 0x18uLL);
if ( creq )
{
v1 = *(_DWORD *)(a1 + 68);
if ( v1 )
{
v2 = 0;
v1 = 0;
while ( 1 )
{
v5 = (const __m128i *)(*(_QWORD *)(a1 + 72) + 152LL * v2);
v6 = (char *)creq;
v7 = (char *)creq + 24 * creq_size;
if ( creq >= v7 )
goto LABEL_24;
while ( *((_QWORD *)v6 + 1) )
{
if ( *(_DWORD *)v6 == v5->m128i_i32[0] )
{
if ( v7 > v6 )
goto LABEL_18;
LABEL_24:
_assert_fail("c < &creq[creq_size]", "client.c", 0x2Cu, "prepare_clients");
}
v6 += 24;
if ( v6 >= v7 )
goto LABEL_24;
}
if ( v7 <= v6 )
goto LABEL_24;
*((_QWORD *)v6 + 1) = a1;
*(_DWORD *)v6 = v5->m128i_i32[0];
++v1;
LABEL_18:
v4 = (__m128i *)calloc(1uLL, 0x90uLL);
if ( !v4 )
break;
v4[8].m128i_i64[1] = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v4;
v4[8].m128i_i32[1] = v5->m128i_i32[2];
*v4 = _mm_loadu_si128(v5 + 1);
v4[1] = _mm_loadu_si128(v5 + 2);
v4[2] = _mm_loadu_si128(v5 + 3);
v4[3] = _mm_loadu_si128(v5 + 4);
v4[4] = _mm_loadu_si128(v5 + 5);
v4[5] = _mm_loadu_si128(v5 + 6);
v4[6] = _mm_loadu_si128(v5 + 7);
v4[7] = _mm_loadu_si128(v5 + 8);
v4[8].m128i_i32[0] = v5[9].m128i_i32[0];
if ( *(_DWORD *)(a1 + 68) <= ++v2 )
goto LABEL_14;
}
fprintf(stderr, "%s:%d calloc() error\n", "client.c", 57LL);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_14:
if ( !*((_QWORD *)creq + 3 * creq_size - 2) )
_assert_fail("creq[creq_size - 1].settings != NULL", "client.c", 0x47u, "prepare_clients");
result = v1;
}
}
else
{
creq_size = 0LL;
fprintf(stderr, "%s:%d calloc() error\n", "client.c", 29LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er14
unsigned int v2; // er12
__int64 result; // rax
__m128i *v4; // rax
const __m128i *v5; // rbp
char *v6; // rbx
char *v7; // rax

if ( !a1 )
_assert_fail("settings != NULL", "client.c", 0x11u, "prepare_clients");
if ( !*(_QWORD *)(a1 + 72) )
_assert_fail("settings->test != NULL", "client.c", 0x12u, "prepare_clients");
if ( creq )
_assert_fail("creq == NULL", "client.c", 0x13u, "prepare_clients");
if ( creq_size )
_assert_fail("creq_size == 0", "client.c", 0x14u, "prepare_clients");
creq_size = *(unsigned int *)(a1 + 80);
creq = calloc(creq_size, 0x18uLL);
if ( creq )
{
v1 = *(_DWORD *)(a1 + 68);
if ( v1 )
{
v2 = 0;
v1 = 0;
while ( 1 )
{
v5 = (const __m128i *)(*(_QWORD *)(a1 + 72) + 152LL * v2);
v6 = (char *)creq;
v7 = (char *)creq + 24 * creq_size;
if ( creq >= v7 )
goto LABEL_24;
while ( *((_QWORD *)v6 + 1) )
{
if ( *(_DWORD *)v6 == v5->m128i_i32[0] )
{
if ( v7 > v6 )
goto LABEL_18;
LABEL_24:
_assert_fail("c < &creq[creq_size]", "client.c", 0x2Cu, "prepare_clients");
}
v6 += 24;
if ( v6 >= v7 )
goto LABEL_24;
}
if ( v7 <= v6 )
goto LABEL_24;
*((_QWORD *)v6 + 1) = a1;
*(_DWORD *)v6 = v5->m128i_i32[0];
++v1;
LABEL_18:
v4 = (__m128i *)calloc(1uLL, 0x90uLL);
if ( !v4 )
break;
v4[8].m128i_i64[1] = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v4;
v4[8].m128i_i32[1] = v5->m128i_i32[2];
*v4 = _mm_loadu_si128(v5 + 1);
v4[1] = _mm_loadu_si128(v5 + 2);
v4[2] = _mm_loadu_si128(v5 + 3);
v4[3] = _mm_loadu_si128(v5 + 4);
v4[4] = _mm_loadu_si128(v5 + 5);
v4[5] = _mm_loadu_si128(v5 + 6);
v4[6] = _mm_loadu_si128(v5 + 7);
v4[7] = _mm_loadu_si128(v5 + 8);
v4[8].m128i_i32[0] = v5[9].m128i_i32[0];
if ( *(_DWORD *)(a1 + 68) <= ++v2 )
goto LABEL_14;
}
fprintf(stderr, "%s:%d calloc() error\n", "client.c", 57LL);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_14:
if ( !*((_QWORD *)creq + 3 * creq_size - 2) )
_assert_fail("creq[creq_size - 1].settings != NULL", "client.c", 0x47u, "prepare_clients");
result = v1;
}
}
else
{
creq_size = 0LL;
fprintf(stderr, "%s:%d calloc() error\n", "client.c", 29LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int prepare_clients(const struct settings * settings, void *data) {
 unsigned int clientthreads = 0;
 unsigned int i;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "client.c", 17, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings->test != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings->test != ((void *)0)) ; else __assert_fail ("settings->test != NULL", "client.c", 18, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((creq == ((void *)0)) ? 1 : 0), __extension__ ({ if (creq == ((void *)0)) ; else __assert_fail ("creq == NULL", "client.c", 19, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((creq_size == 0) ? 1 : 0), __extension__ ({ if (creq_size == 0) ; else __assert_fail ("creq_size == 0", "client.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 creq_size = settings->clientcores;
 creq = calloc ( creq_size, sizeof(*creq) );
 if ( !creq ) {
  creq_size = 0;
  fprintf(stderr, "%s:%d calloc() error\n", "client.c", 29 );
  return -1;
 }
 for ( i = 0; i < settings->tests; i++) {
  const struct test * test = &settings->test[i];
  struct client_request *c;
  struct client_request_details *details;
  for ( c = creq; c < &creq[creq_size]; c++) {
   if ( c->settings == ((void *)0) || c->cores == test->clientcores )
    break;
  }
  ((void) sizeof ((c < &creq[creq_size]) ? 1 : 0), __extension__ ({ if (c < &creq[creq_size]) ; else __assert_fail ("c < &creq[creq_size]", "client.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  if ( c->settings == ((void *)0) ) {
   c->settings = settings;
   c->cores = test->clientcores;
   clientthreads++;
  }
  details = calloc( 1, sizeof( *details ) );
  if ( !details ) {
   fprintf(stderr, "%s:%d calloc() error\n", "client.c", 57 );
   return -1;
  }
  details->next =c->details;
  c->details = details;
  details->n = test->connections;
  details->addr = test->addr;
  details->addr_len = test->addr_len;
 }
 ((void) sizeof ((creq[creq_size - 1].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (creq[creq_size - 1].settings != ((void *)0)) ; else __assert_fail ("creq[creq_size - 1].settings != NULL", "client.c", 71, __extension__ __PRETTY_FUNCTION__); }));
 return clientthreads;
}

canonical_original_code:
int prepare_clients(struct settings *settings, void *data) {
 unsigned int clientthreads = 0;
 unsigned int i;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "client.c", 17, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings->test != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings->test != ((void *)0)) ; else __assert_fail ("settings->test != NULL", "client.c", 18, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((creq == ((void *)0)) ? 1 : 0), __extension__ ({ if (creq == ((void *)0)) ; else __assert_fail ("creq == NULL", "client.c", 19, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((creq_size == 0) ? 1 : 0), __extension__ ({ if (creq_size == 0) ; else __assert_fail ("creq_size == 0", "client.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 creq_size = settings->clientcores;
 creq = calloc ( creq_size, sizeof(*creq) );
 if ( !creq ) {
  creq_size = 0;
  fprintf(stderr, "%s:%d calloc() error\n", "client.c", 29 );
  return -1;
 }
 for ( i = 0; i < settings->tests; i++) {
  struct test *test = &settings->test[i];
  struct client_request *c;
  struct client_request_details *details;
  for ( c = creq; c < &creq[creq_size]; c++) {
   if ( c->settings == ((void *)0) || c->cores == test->clientcores )
    break;
  }
  ((void) sizeof ((c < &creq[creq_size]) ? 1 : 0), __extension__ ({ if (c < &creq[creq_size]) ; else __assert_fail ("c < &creq[creq_size]", "client.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  if ( c->settings == ((void *)0) ) {
   c->settings = settings;
   c->cores = test->clientcores;
   clientthreads++;
  }
  details = calloc( 1, sizeof( *details ) );
  if ( !details ) {
   fprintf(stderr, "%s:%d calloc() error\n", "client.c", 57 );
   return -1;
  }
  details->next =c->details;
  c->details = details;
  details->n = test->connections;
  details->addr = test->addr;
  details->addr_len = test->addr_len;
 }
 ((void) sizeof ((creq[creq_size - 1].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (creq[creq_size - 1].settings != ((void *)0)) ; else __assert_fail ("creq[creq_size - 1].settings != NULL", "client.c", 71, __extension__ __PRETTY_FUNCTION__); }));
 return clientthreads;
}

variable_types:
clientthreads
unsigned int

variable_types: struct client_request { unsigned int cores; struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; } *settings; struct client_request_details { struct sockaddr_storage addr; unsigned int addr_len; unsigned int n; struct client_request_details *next; } *details; } *

variable_types: struct client_request_details { struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; unsigned int n; struct client_request_details *next; } *

user_defined_types: struct client_request { unsigned int cores; struct settings *settings; struct client_request_details *details; }


decompiled_code:
__int64 __fastcall create_clients(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
__int64 v3; // rbx
unsigned int *v4; // rdx
__int64 v5; // rax
_BYTE v6[152]; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("settings != NULL", "client.c", 0x4Fu, "create_clients");
if ( !creq )
_assert_fail("creq != NULL", "client.c", 0x50u, "create_clients");
v1 = 0;
result = 0LL;
if ( creq_size )
{
do
{
v3 = 24 * result;
v4 = (unsigned int *)((char *)creq + 24 * result);
v5 = *((_QWORD *)v4 + 1);
if ( !v5 )
_assert_fail("creq[i].settings != NULL", "client.c", 0x55u, "create_clients");
if ( (*(_BYTE *)(v5 + 12) & 0x40) != 0 )
{
threads_signal_parent(2LL, *(unsigned int *)(a1 + 88));
}
else
{
cpu_setup(v6, *v4);
if ( (unsigned int)create_thread(&client_thread, (char *)creq + v3, 128LL, v6, *(unsigned int *)(a1 + 88)) )
{
fprintf(stderr, "%s:%d create_thread() error\n", "client.c", 98LL);
return 0xFFFFFFFFLL;
}
}
result = ++v1;
}
while ( v1 < (unsigned __int64)creq_size );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
__int64 v3; // rbx
unsigned int *v4; // rdx
__int64 v5; // rax
_BYTE v6[152]; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("settings != NULL", "client.c", 0x4Fu, "create_clients");
if ( !creq )
_assert_fail("creq != NULL", "client.c", 0x50u, "create_clients");
v1 = 0;
result = 0LL;
if ( creq_size )
{
do
{
v3 = 24 * result;
v4 = (unsigned int *)((char *)creq + 24 * result);
v5 = *((_QWORD *)v4 + 1);
if ( !v5 )
_assert_fail("creq[i].settings != NULL", "client.c", 0x55u, "create_clients");
if ( (*(_BYTE *)(v5 + 12) & 0x40) != 0 )
{
threads_signal_parent(2LL, *(unsigned int *)(a1 + 88));
}
else
{
cpu_setup(v6, *v4);
if ( (unsigned int)create_thread(&client_thread, (char *)creq + v3, 128LL, v6, *(unsigned int *)(a1 + 88)) )
{
fprintf(stderr, "%s:%d create_thread() error\n", "client.c", 98LL);
return 0xFFFFFFFFLL;
}
}
result = ++v1;
}
while ( v1 < (unsigned __int64)creq_size );
result = 0LL;
}
return result;
}

original_code:
int create_clients(const struct settings *settings, void *data) {
 unsigned int i;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "client.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((creq != ((void *)0)) ? 1 : 0), __extension__ ({ if (creq != ((void *)0)) ; else __assert_fail ("creq != NULL", "client.c", 80, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < creq_size; i++) {
  cpu_set_t cpus;
  ((void) sizeof ((creq[i].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (creq[i].settings != ((void *)0)) ; else __assert_fail ("creq[i].settings != NULL", "client.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  if (creq[i].settings->quiet) {
   threads_signal_parent ( 2, settings->threaded_model );
   continue;
  }
  cpu_setup( &cpus, creq[i].cores );
  if ( create_thread( client_thread, &creq [i] , sizeof(cpus), &cpus, settings->threaded_model) ) {
   fprintf(stderr, "%s:%d create_thread() error\n", "client.c", 98 );
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int create_clients(struct settings *settings, void *data) {
 unsigned int i;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "client.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((creq != ((void *)0)) ? 1 : 0), __extension__ ({ if (creq != ((void *)0)) ; else __assert_fail ("creq != NULL", "client.c", 80, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < creq_size; i++) {
  struct cpu_set_t cpus;
  ((void) sizeof ((creq[i].settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (creq[i].settings != ((void *)0)) ; else __assert_fail ("creq[i].settings != NULL", "client.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  if (creq[i].settings->quiet) {
   threads_signal_parent ( 2, settings->threaded_model );
   continue;
  }
  cpu_setup( &cpus, creq[i].cores );
  if ( create_thread( client_thread, &creq [i] , sizeof(cpus), &cpus, settings->threaded_model) ) {
   fprintf(stderr, "%s:%d create_thread() error\n", "client.c", 98 );
   return -1;
  }
 }
 return 0;
}

variable_types: struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; } *

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
void cleanup_clients()
{
unsigned int v0; // ebp
__int64 v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

if ( creq )
{
if ( !creq_size )
_assert_fail("creq_size != 0", "client.c", 0x6Du, "cleanup_clients");
v0 = 0;
v1 = 0LL;
do
{
v2 = (_QWORD *)*((_QWORD *)creq + 3 * v1 + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[17];
free(v3);
}
v1 = ++v0;
}
while ( v0 < (unsigned __int64)creq_size );
free(creq);
creq = 0LL;
creq_size = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
unsigned int v0; // ebp
__int64 v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

if ( creq )
{
if ( !creq_size )
_assert_fail("creq_size != 0", "client.c", 0x6Du, "cleanup_clients");
v0 = 0;
v1 = 0LL;
do
{
v2 = (_QWORD *)*((_QWORD *)creq + 3 * v1 + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[17];
free(v3);
}
v1 = ++v0;
}
while ( v0 < (unsigned __int64)creq_size );
free(creq);
creq = 0LL;
creq_size = 0LL;
}
}

original_code:
void cleanup_clients() {
 unsigned int i;
 if ( creq ) {
  ((void) sizeof ((creq_size != 0) ? 1 : 0), __extension__ ({ if (creq_size != 0) ; else __assert_fail ("creq_size != 0", "client.c", 109, __extension__ __PRETTY_FUNCTION__); }));
  for (i = 0; i < creq_size; i++) {
   struct client_request_details *c = creq[i].details;
   while ( c != ((void *)0) ) {
    struct client_request_details *nextC = c->next;
    free ( c );
    c = nextC;
   }
  }
  free( creq );
  creq = ((void *)0);
  creq_size = 0;
 }
}

variable_types:
i
unsigned int

user_defined_types: struct client_request_details { struct sockaddr_storage addr; unsigned int addr_len; unsigned int n; struct client_request_details *next; }


decompiled_code:
__int64 __fastcall connect_connections(__int64 a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
__int64 v6; // r14
int v7; // ebx
__int64 v8; // rdx
const char *v9; // rcx
int *v10; // rbp
char *v11; // rax
int *v12; // rbp
char *v13; // rax
unsigned int v14; // ebx
int *v16; // rbp
char *v17; // rax
int *v18; // rbp
char *v19; // rax
unsigned int v20; // eax
int v21; // er13
int v22; // eax
int *v23; // rbp
char *v24; // rax
int *v25; // rbp
char *v26; // rax
int *v27; // rbp
char *v28; // rax
int *v29; // rbp
char *v30; // rax
_DWORD *v31; // [rsp+0h] [rbp-478h]
char v32[1128]; // [rsp+10h] [rbp-468h] BYREF

v6 = *((_QWORD *)a2 + 2);
if ( !v6 )
return 0;
do
{
v7 = *(_DWORD *)(v6 + 132);
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
{
addr_to_ipstr(v6, *(unsigned int *)(v6 + 128), v32, 1058LL);
v8 = *(unsigned int *)(v6 + 132);
v9 = (const char *)&unk_A29;
if ( (unsigned int)v8 <= 1 )
v9 = (const char *)&unk_A2B;
printf(" Core %d: Connecting %d client%s to %s\n", *a2, v8, v9, v32);
}
if ( v7 )
{
v31 = &a3[v7];
while ( 1 )
{
v20 = socket(2, *(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8));
v14 = v20;
if ( v20 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s:%d socket() error (%d) %s\n", "client_thread.c", 49LL, (unsigned int)*v10, v11);
return v14;
}
v21 = set_socket_send_buffer(v20, *(unsigned int *)(a1 + 44));
if ( v21 < 0 )
break;
v22 = set_socket_recv_buffer(v14, *(unsigned int *)(a1 + 44));
if ( v22 < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(
stderr,
"%s:%d set_socket_recv_buffer() error (%d) %s\n",
"client_thread.c",
71LL,
(unsigned int)*v16,
v17);
goto LABEL_10;
}
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
printf("client socket size: %d/%d\n", (unsigned int)v21, (unsigned int)v22);
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
{
if ( (unsigned int)disable_nagle(v14) == -1 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "%s:%d disable_nagle() error (%d) %s\n", "client_thread.c", 83LL, (unsigned int)*v18, v19);
goto LABEL_10;
}
if ( (unsigned int)enable_maxseq(v14, *(unsigned int *)(a1 + 40)) == -1 )
{
v23 = _errno_location();
v24 = strerror(*v23);
fprintf(stderr, "%s:%d enable_maxseq() error (%d) %s\n", "client_thread.c", 91LL, (unsigned int)*v23, v24);
goto LABEL_10;
}
}
if ( (unsigned int)set_socket_timeout(v14, 30000LL) )
{
v25 = _errno_location();
v26 = strerror(*v25);
fprintf(
stderr,
"%s:%d set_socket_timeout() error (%d) %s\n",
"client_thread.c",
97LL,
(unsigned int)*v25,
v26);
goto LABEL_10;
}
if ( (unsigned int)connect_ign_signal(v14, v6, *(unsigned int *)(v6 + 128)) == -1 )
{
v27 = _errno_location();
v28 = strerror(*v27);
fprintf(stderr, "%s:%d connect() error (%d) %s\n", "client_thread.c", 102LL, (unsigned int)*v27, v28);
goto LABEL_10;
}
if ( (unsigned int)disable_blocking(v14) == -1 )
{
v29 = _errno_location();
v30 = strerror(*v29);
fprintf(stderr, "%s:%d disable_blocking() error (%d) %s\n", "client_thread.c", 108LL, (unsigned int)*v29, v30);
goto LABEL_10;
}
if ( *a3 != -1 )
_assert_fail("*client == INVALID_SOCKET", "client_thread.c", 0x71u, "connect_connections");
*a3++ = v14;
++*a4;
if ( a3 == v31 )
{
a3 = v31;
goto LABEL_33;
}
}
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(
stderr,
"%s:%d set_socket_send_buffer() error (%d) %s\n",
"client_thread.c",
65LL,
(unsigned int)*v12,
v13);
LABEL_10:
close(v14);
return (unsigned int)-1;
}
LABEL_33:
v6 = *(_QWORD *)(v6 + 136);
}
while ( v6 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
__int64 v6; // r14
int v7; // ebx
__int64 v8; // rdx
const char *v9; // rcx
int *v10; // rbp
char *v11; // rax
int *v12; // rbp
char *v13; // rax
unsigned int v14; // ebx
int *v16; // rbp
char *v17; // rax
int *v18; // rbp
char *v19; // rax
unsigned int v20; // eax
int v21; // er13
int v22; // eax
int *v23; // rbp
char *v24; // rax
int *v25; // rbp
char *v26; // rax
int *v27; // rbp
char *v28; // rax
int *v29; // rbp
char *v30; // rax
_DWORD *v31; // [rsp+0h] [rbp-478h]
char v32[1128]; // [rsp+10h] [rbp-468h] BYREF

v6 = *((_QWORD *)a2 + 2);
if ( !v6 )
return 0;
do
{
v7 = *(_DWORD *)(v6 + 132);
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
{
addr_to_ipstr(v6, *(unsigned int *)(v6 + 128), v32, 1058LL);
v8 = *(unsigned int *)(v6 + 132);
v9 = (const char *)&unk_A29;
if ( (unsigned int)v8 <= 1 )
v9 = (const char *)&unk_A2B;
printf(" Core %d: Connecting %d client%s to %s\n", *a2, v8, v9, v32);
}
if ( v7 )
{
v31 = &a3[v7];
while ( 1 )
{
v20 = socket(2, *(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8));
v14 = v20;
if ( v20 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s:%d socket() error (%d) %s\n", "client_thread.c", 49LL, (unsigned int)*v10, v11);
return v14;
}
v21 = set_socket_send_buffer(v20, *(unsigned int *)(a1 + 44));
if ( v21 < 0 )
break;
v22 = set_socket_recv_buffer(v14, *(unsigned int *)(a1 + 44));
if ( v22 < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(
stderr,
"%s:%d set_socket_recv_buffer() error (%d) %s\n",
"client_thread.c",
71LL,
(unsigned int)*v16,
v17);
goto LABEL_10;
}
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
printf("client socket size: %d/%d\n", (unsigned int)v21, (unsigned int)v22);
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
{
if ( (unsigned int)disable_nagle(v14) == -1 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "%s:%d disable_nagle() error (%d) %s\n", "client_thread.c", 83LL, (unsigned int)*v18, v19);
goto LABEL_10;
}
if ( (unsigned int)enable_maxseq(v14, *(unsigned int *)(a1 + 40)) == -1 )
{
v23 = _errno_location();
v24 = strerror(*v23);
fprintf(stderr, "%s:%d enable_maxseq() error (%d) %s\n", "client_thread.c", 91LL, (unsigned int)*v23, v24);
goto LABEL_10;
}
}
if ( (unsigned int)set_socket_timeout(v14, 30000LL) )
{
v25 = _errno_location();
v26 = strerror(*v25);
fprintf(
stderr,
"%s:%d set_socket_timeout() error (%d) %s\n",
"client_thread.c",
97LL,
(unsigned int)*v25,
v26);
goto LABEL_10;
}
if ( (unsigned int)connect_ign_signal(v14, v6, *(unsigned int *)(v6 + 128)) == -1 )
{
v27 = _errno_location();
v28 = strerror(*v27);
fprintf(stderr, "%s:%d connect() error (%d) %s\n", "client_thread.c", 102LL, (unsigned int)*v27, v28);
goto LABEL_10;
}
if ( (unsigned int)disable_blocking(v14) == -1 )
{
v29 = _errno_location();
v30 = strerror(*v29);
fprintf(stderr, "%s:%d disable_blocking() error (%d) %s\n", "client_thread.c", 108LL, (unsigned int)*v29, v30);
goto LABEL_10;
}
if ( *a3 != -1 )
_assert_fail("*client == INVALID_SOCKET", "client_thread.c", 0x71u, "connect_connections");
*a3++ = v14;
++*a4;
if ( a3 == v31 )
{
a3 = v31;
goto LABEL_33;
}
}
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(
stderr,
"%s:%d set_socket_send_buffer() error (%d) %s\n",
"client_thread.c",
65LL,
(unsigned int)*v12,
v13);
LABEL_10:
close(v14);
return (unsigned int)-1;
}
LABEL_33:
v6 = *(_QWORD *)(v6 + 136);
}
while ( v6 );
return 0;
}

original_code:
int connect_connections(const struct settings *settings,
  const struct client_request * req, int *client,
  unsigned int *clients) {
 const struct client_request_details * details = req->details;
 while (details != ((void *)0)) {
  unsigned int i = details->n;
  if (settings->verbose) {
   char addr[1025 + 32 + 1];
   addr_to_ipstr((const struct sockaddr *)&details->addr,
     details->addr_len, addr, sizeof(addr));
   printf("  Core %d: Connecting %d client%s to %s\n", req->cores,
     details->n, details->n > 1 ? "s" : "", addr);
  }
  while (i > 0) {
   int send_socket_size, recv_socket_size;
   int s = socket( 2, settings->type, settings->protocol);
   if (s == (-1)) {
    fprintf(stderr, "%s:%d socket() error (%d) %s\n", "client_thread.c", 49, (*__errno_location ()), strerror((*__errno_location ())));
    return -1;
   }
   send_socket_size = set_socket_send_buffer(s, settings->socket_size);
   if (send_socket_size < 0) {
    fprintf(stderr, "%s:%d set_socket_send_buffer() error (%d) %s\n", "client_thread.c", 65, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   recv_socket_size = set_socket_recv_buffer(s, settings->socket_size);
   if (recv_socket_size < 0) {
    fprintf(stderr, "%s:%d set_socket_recv_buffer() error (%d) %s\n", "client_thread.c", 71, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   if (settings->verbose) {
    printf("client socket size: %d/%d\n", send_socket_size,
      recv_socket_size);
   }
   if (settings->disable_nagles) {
    if (disable_nagle(s) == (-1)) {
     fprintf(stderr, "%s:%d disable_nagle() error (%d) %s\n", "client_thread.c", 83, (*__errno_location ()), strerror((*__errno_location ())));
     goto cleanup;
    }
    if ( enable_maxseq ( s , settings->message_size ) == (-1) ) {
     fprintf(stderr, "%s:%d enable_maxseq() error (%d) %s\n", "client_thread.c", 91, (*__errno_location ()), strerror((*__errno_location ())));
     goto cleanup;
    }
   }
   if (set_socket_timeout(s, 30000) ) {
    fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "client_thread.c", 97, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   if (connect_ign_signal(s, (const struct sockaddr *)&details->addr, (int)details->addr_len ) == (-1)) {
    fprintf(stderr, "%s:%d connect() error (%d) %s\n", "client_thread.c", 102, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   if (disable_blocking(s) == (-1)) {
    fprintf(stderr, "%s:%d disable_blocking() error (%d) %s\n", "client_thread.c", 108, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "client_thread.c", 112, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((*client == (-1)) ? 1 : 0), __extension__ ({ if (*client == (-1)) ; else __assert_fail ("*client == INVALID_SOCKET", "client_thread.c", 113, __extension__ __PRETTY_FUNCTION__); }));
   *client++ = s;
   (*clients)++;
   i--;
   continue;
cleanup:
   close(s);
   return -1;
  }
  details = details->next;
 }
 return 0;
}

canonical_original_code:
int connect_connections(struct settings *settings, struct client_request *req, int *client, unsigned int *clients) {
 struct client_request_details *details = req->details;
 while (details != ((void *)0)) {
  unsigned int i = details->n;
  if (settings->verbose) {
   char addr[-1];
   addr_to_ipstr((struct sockaddr *)&details->addr,
     details->addr_len, addr, sizeof(addr));
   printf("  Core %d: Connecting %d client%s to %s\n", req->cores,
     details->n, details->n > 1 ? "s" : "", addr);
  }
  while (i > 0) {
   int send_socket_size; int recv_socket_size;
   int s = socket( 2, settings->type, settings->protocol);
   if (s == (-1)) {
    fprintf(stderr, "%s:%d socket() error (%d) %s\n", "client_thread.c", 49, (*__errno_location ()), strerror((*__errno_location ())));
    return -1;
   }
   send_socket_size = set_socket_send_buffer(s, settings->socket_size);
   if (send_socket_size < 0) {
    fprintf(stderr, "%s:%d set_socket_send_buffer() error (%d) %s\n", "client_thread.c", 65, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   recv_socket_size = set_socket_recv_buffer(s, settings->socket_size);
   if (recv_socket_size < 0) {
    fprintf(stderr, "%s:%d set_socket_recv_buffer() error (%d) %s\n", "client_thread.c", 71, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   if (settings->verbose) {
    printf("client socket size: %d/%d\n", send_socket_size,
      recv_socket_size);
   }
   if (settings->disable_nagles) {
    if (disable_nagle(s) == (-1)) {
     fprintf(stderr, "%s:%d disable_nagle() error (%d) %s\n", "client_thread.c", 83, (*__errno_location ()), strerror((*__errno_location ())));
     goto cleanup;
    }
    if ( enable_maxseq ( s , settings->message_size ) == (-1) ) {
     fprintf(stderr, "%s:%d enable_maxseq() error (%d) %s\n", "client_thread.c", 91, (*__errno_location ()), strerror((*__errno_location ())));
     goto cleanup;
    }
   }
   if (set_socket_timeout(s, 30000) ) {
    fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "client_thread.c", 97, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   if (connect_ign_signal(s, (struct sockaddr *)&details->addr, (int)details->addr_len ) == (-1)) {
    fprintf(stderr, "%s:%d connect() error (%d) %s\n", "client_thread.c", 102, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   if (disable_blocking(s) == (-1)) {
    fprintf(stderr, "%s:%d disable_blocking() error (%d) %s\n", "client_thread.c", 108, (*__errno_location ()), strerror((*__errno_location ())));
    goto cleanup;
   }
   ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "client_thread.c", 112, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((*client == (-1)) ? 1 : 0), __extension__ ({ if (*client == (-1)) ; else __assert_fail ("*client == INVALID_SOCKET", "client_thread.c", 113, __extension__ __PRETTY_FUNCTION__); }));
   *client++ = s;
   (*clients)++;
   i--;
   continue;
cleanup:
   close(s);
   return -1;
  }
  details = details->next;
 }
 return 0;
}

variable_types: struct client_request { unsigned int cores; struct settings *settings; struct client_request_details { struct sockaddr_storage addr; unsigned int addr_len; unsigned int n; struct client_request_details *next; } *details; } *

variable_types:
client
int *

variable_types:
clients
unsigned int *

variable_types:
addr
char [-1]

variable_types: s int

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


decompiled_code:
__int64 __fastcall client_thread(unsigned int *a1)
{
unsigned int *v1; // r15
_DWORD *v2; // rbx
const __m128i *v3; // rax
unsigned int v4; // ebp
int *v5; // rax
int *v6; // r13
int *i; // r12
int *v9; // r14
int v10; // edx
_DWORD *v11; // r12
int v12; // eax
__int64 v13; // r15
int *v14; // r12
char *v15; // rax
int *v16; // r12
char *v17; // rax
int *v18; // r14
unsigned int v19; // er14
int *v20; // rax
int v21; // edi
unsigned int *v22; // r14
char *v23; // rax
int v24; // eax
int *v25; // rax
unsigned int *v26; // r15
char *v27; // rax
unsigned int *v28; // rbp
unsigned int v29; // er12
void *s; // [rsp+0h] [rbp-E8h]
unsigned int n; // [rsp+8h] [rbp-E0h]
size_t na; // [rsp+8h] [rbp-E0h]
__int64 v33; // [rsp+10h] [rbp-D8h]
unsigned __int64 v34; // [rsp+18h] [rbp-D0h]
unsigned int v35; // [rsp+34h] [rbp-B4h]
unsigned int *v36; // [rsp+38h] [rbp-B0h]
struct epoll_event event; // [rsp+40h] [rbp-A8h] BYREF
unsigned int v38; // [rsp+4Ch] [rbp-9Ch] BYREF
__int128 v39[2]; // [rsp+50h] [rbp-98h] BYREF
size_t size[2]; // [rsp+70h] [rbp-78h]
__m128i v41; // [rsp+80h] [rbp-68h]
__m128i v42; // [rsp+90h] [rbp-58h]
__m128i v43; // [rsp+A0h] [rbp-48h]

v1 = a1;
v2 = (_DWORD *)*((_QWORD *)a1 + 2);
v3 = (const __m128i *)*((_QWORD *)a1 + 1);
v39[0] = (__int128)_mm_loadu_si128(v3);
v39[1] = (__int128)_mm_loadu_si128(v3 + 1);
*(__m128i *)size = _mm_loadu_si128(v3 + 2);
v41 = _mm_loadu_si128(v3 + 3);
v42 = _mm_loadu_si128(v3 + 4);
v43 = _mm_loadu_si128(v3 + 5);
v33 = 0LL;
if ( v41.m128i_i32[0] )
v33 = 0xF4240u / v41.m128i_i32[0];
v38 = 0;
if ( !v2 )
_assert_fail("details != NULL", "client_thread.c", 0xA9u, "client_thread");
v4 = 0;
do
{
v4 += v2[33];
v2 = (_DWORD *)*((_QWORD *)v2 + 17);
}
while ( v2 );
if ( !v4 )
{
fprintf(stderr, "%s:%d Must have more than zero clients!\n", "client_thread.c", 178LL);
LABEL_17:
v6 = 0LL;
n = -1;
goto LABEL_18;
}
v5 = (int *)calloc(v4, 4uLL);
v6 = v5;
if ( !v5 )
{
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 192LL);
goto LABEL_17;
}
for ( i = &v5[v4]; v5 < i; ++v5 )
*v5 = -1;
if ( (BYTE12(v39[0]) & 2) != 0 )
printf("Core %d: Started client thread\n", *a1);
if ( (unsigned int)connect_connections((__int64)v39, a1, v6, &v38) )
{
s = 0LL;
n = -1;
LABEL_66:
free(s);
LABEL_67:
v18 = &v6[v4];
if ( v6 >= v18 )
goto LABEL_18;
goto LABEL_68;
}
if ( v38 != v4 )
{
fprintf(
stderr,
"%s:%d Requested number of clients does not match actual clients (%d != %d)\n",
"client_thread.c",
208LL,
v4,
v38);
n = -1;
free(0LL);
goto LABEL_67;
}
na = LODWORD(size[1]);
s = malloc(LODWORD(size[1]));
if ( !s )
{
fprintf(stderr, "%s:%d malloc error\n", "client_thread.c", 215LL);
v2 = 0LL;
n = -1;
goto LABEL_66;
}
memset(s, 65, na);
n = epoll_create(v4);
if ( n == -1 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "%s:%d epoll_create() error (%d) %s\n", "client_thread.c", 223LL, (unsigned int)*v14, v15);
goto LABEL_66;
}
v2 = calloc(v4, 0xCuLL);
if ( !v2 )
{
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 229LL);
goto LABEL_66;
}
v9 = v6;
if ( v6 >= i )
goto LABEL_28;
while ( 1 )
{
v10 = *v9;
*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
if ( v10 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0xF5u, "client_thread");
event.events = 5;
event.data.fd = v10;
if ( epoll_ctl(n, 1, v10, &event) == -1 )
break;
if ( ++v9 >= i )
{
v1 = a1;
LABEL_28:
threads_signal_parent(2LL, v43.m128i_u32[2]);
wait_for_nonzero(&go_mutex, &go_cond, &bGo);
v34 = get_microseconds();
if ( !bRunning )
goto LABEL_66;
v35 = ((unsigned __int64)(v9 - v6) >> 2) + 1;
v36 = v1;
while ( 1 )
{
v11 = v2;
v12 = epoll_wait_ign_signal(n, v2, v4, 1000LL);
if ( v12 > 0 )
break;
LABEL_60:
if ( !bRunning )
goto LABEL_66;
}
v13 = (__int64)&v2[3 * (v12 - 1) + 3];
while ( 2 )
{
v19 = v11[1];
if ( v19 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0x120u, "client_thread");
if ( (*v11 & 0x18) != 0 )
{
close(v19);
}
else
{
if ( (*v11 & 1) == 0 )
goto LABEL_43;
v24 = recv_ign_signal(v19, s, LODWORD(size[1]), 0LL);
if ( v24 == -1 )
{
v25 = _errno_location();
if ( *v25 != 104 )
{
v26 = (unsigned int *)v25;
v27 = strerror(*v25);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "client_thread.c", 330LL, v19, *v26, v27);
goto LABEL_66;
}
LABEL_55:
if ( (BYTE12(v39[0]) & 2) != 0 )
printf(" Client: %d Removed client (%d/%d)\n", *v36, v35, v4);
close_ign_signal(v19);
if ( !--v4 )
{
free(s);
goto LABEL_18;
}
}
else
{
if ( v24 <= 0 )
goto LABEL_55;
LABEL_43:
if ( (*(_BYTE *)v11 & 4) != 0 )
{
if ( !v33 )
goto LABEL_47;
if ( get_microseconds() >= v34 )
{
v34 += v33;
LABEL_47:
if ( send_ign_signal(v19, s, LODWORD(size[1]), 0LL) == -1 )
{
v20 = _errno_location();
v21 = *v20;
if ( *v20 != 11 && v21 != 32 )
{
v22 = (unsigned int *)v20;
v23 = strerror(v21);
fprintf(stderr, "%s:%d send() error (%d) %s\n", "client_thread.c", 397LL, *v22, v23);
goto LABEL_66;
}
}
}
}
}
}
v11 += 3;
if ( (_DWORD *)v13 == v11 )
goto LABEL_60;
continue;
}
}
}
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "%s:%d epoll() error adding client (%d) %s\n", "client_thread.c", 251LL, (unsigned int)*v16, v17);
free(s);
v18 = &v6[v4];
LABEL_68:
v28 = (unsigned int *)v6;
do
{
v29 = *v28;
if ( *v28 != -1 )
{
shutdown(v29, 2);
close_ign_signal(v29);
}
++v28;
}
while ( v28 < (unsigned int *)v18 );
LABEL_18:
close_ign_signal(n);
free(v2);
free(v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
unsigned int *v1; // r15
_DWORD *v2; // rbx
const __m128i *v3; // rax
unsigned int v4; // ebp
int *v5; // rax
int *v6; // r13
int *i; // r12
int *v9; // r14
int v10; // edx
_DWORD *v11; // r12
int v12; // eax
__int64 v13; // r15
int *v14; // r12
char *v15; // rax
int *v16; // r12
char *v17; // rax
int *v18; // r14
unsigned int v19; // er14
int *v20; // rax
int v21; // edi
unsigned int *v22; // r14
char *v23; // rax
int v24; // eax
int *v25; // rax
unsigned int *v26; // r15
char *v27; // rax
unsigned int *v28; // rbp
unsigned int v29; // er12
void *s; // [rsp+0h] [rbp-E8h]
unsigned int n; // [rsp+8h] [rbp-E0h]
size_t na; // [rsp+8h] [rbp-E0h]
__int64 v33; // [rsp+10h] [rbp-D8h]
unsigned __int64 v34; // [rsp+18h] [rbp-D0h]
unsigned int v35; // [rsp+34h] [rbp-B4h]
unsigned int *v36; // [rsp+38h] [rbp-B0h]
struct epoll_event event; // [rsp+40h] [rbp-A8h] BYREF
unsigned int v38; // [rsp+4Ch] [rbp-9Ch] BYREF
__int128 v39[2]; // [rsp+50h] [rbp-98h] BYREF
size_t size[2]; // [rsp+70h] [rbp-78h]
__m128i v41; // [rsp+80h] [rbp-68h]
__m128i v42; // [rsp+90h] [rbp-58h]
__m128i v43; // [rsp+A0h] [rbp-48h]

v1 = a1;
v2 = (_DWORD *)*((_QWORD *)a1 + 2);
v3 = (const __m128i *)*((_QWORD *)a1 + 1);
v39[0] = (__int128)_mm_loadu_si128(v3);
v39[1] = (__int128)_mm_loadu_si128(v3 + 1);
*(__m128i *)size = _mm_loadu_si128(v3 + 2);
v41 = _mm_loadu_si128(v3 + 3);
v42 = _mm_loadu_si128(v3 + 4);
v43 = _mm_loadu_si128(v3 + 5);
v33 = 0LL;
if ( v41.m128i_i32[0] )
v33 = 0xF4240u / v41.m128i_i32[0];
v38 = 0;
if ( !v2 )
_assert_fail("details != NULL", "client_thread.c", 0xA9u, "client_thread");
v4 = 0;
do
{
v4 += v2[33];
v2 = (_DWORD *)*((_QWORD *)v2 + 17);
}
while ( v2 );
if ( !v4 )
{
fprintf(stderr, "%s:%d Must have more than zero clients!\n", "client_thread.c", 178LL);
LABEL_17:
v6 = 0LL;
n = -1;
goto LABEL_18;
}
v5 = (int *)calloc(v4, 4uLL);
v6 = v5;
if ( !v5 )
{
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 192LL);
goto LABEL_17;
}
for ( i = &v5[v4]; v5 < i; ++v5 )
*v5 = -1;
if ( (BYTE12(v39[0]) & 2) != 0 )
printf("Core %d: Started client thread\n", *a1);
if ( (unsigned int)func0((__int64)v39, a1, v6, &v38) )
{
s = 0LL;
n = -1;
LABEL_66:
free(s);
LABEL_67:
v18 = &v6[v4];
if ( v6 >= v18 )
goto LABEL_18;
goto LABEL_68;
}
if ( v38 != v4 )
{
fprintf(
stderr,
"%s:%d Requested number of clients does not match actual clients (%d != %d)\n",
"client_thread.c",
208LL,
v4,
v38);
n = -1;
free(0LL);
goto LABEL_67;
}
na = LODWORD(size[1]);
s = malloc(LODWORD(size[1]));
if ( !s )
{
fprintf(stderr, "%s:%d malloc error\n", "client_thread.c", 215LL);
v2 = 0LL;
n = -1;
goto LABEL_66;
}
memset(s, 65, na);
n = epoll_create(v4);
if ( n == -1 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "%s:%d epoll_create() error (%d) %s\n", "client_thread.c", 223LL, (unsigned int)*v14, v15);
goto LABEL_66;
}
v2 = calloc(v4, 0xCuLL);
if ( !v2 )
{
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 229LL);
goto LABEL_66;
}
v9 = v6;
if ( v6 >= i )
goto LABEL_28;
while ( 1 )
{
v10 = *v9;
*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
if ( v10 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0xF5u, "client_thread");
event.events = 5;
event.data.fd = v10;
if ( epoll_ctl(n, 1, v10, &event) == -1 )
break;
if ( ++v9 >= i )
{
v1 = a1;
LABEL_28:
threads_signal_parent(2LL, v43.m128i_u32[2]);
wait_for_nonzero(&go_mutex, &go_cond, &bGo);
v34 = get_microseconds();
if ( !bRunning )
goto LABEL_66;
v35 = ((unsigned __int64)(v9 - v6) >> 2) + 1;
v36 = v1;
while ( 1 )
{
v11 = v2;
v12 = epoll_wait_ign_signal(n, v2, v4, 1000LL);
if ( v12 > 0 )
break;
LABEL_60:
if ( !bRunning )
goto LABEL_66;
}
v13 = (__int64)&v2[3 * (v12 - 1) + 3];
while ( 2 )
{
v19 = v11[1];
if ( v19 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0x120u, "client_thread");
if ( (*v11 & 0x18) != 0 )
{
close(v19);
}
else
{
if ( (*v11 & 1) == 0 )
goto LABEL_43;
v24 = recv_ign_signal(v19, s, LODWORD(size[1]), 0LL);
if ( v24 == -1 )
{
v25 = _errno_location();
if ( *v25 != 104 )
{
v26 = (unsigned int *)v25;
v27 = strerror(*v25);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "client_thread.c", 330LL, v19, *v26, v27);
goto LABEL_66;
}
LABEL_55:
if ( (BYTE12(v39[0]) & 2) != 0 )
printf(" Client: %d Removed client (%d/%d)\n", *v36, v35, v4);
close_ign_signal(v19);
if ( !--v4 )
{
free(s);
goto LABEL_18;
}
}
else
{
if ( v24 <= 0 )
goto LABEL_55;
LABEL_43:
if ( (*(_BYTE *)v11 & 4) != 0 )
{
if ( !v33 )
goto LABEL_47;
if ( get_microseconds() >= v34 )
{
v34 += v33;
LABEL_47:
if ( send_ign_signal(v19, s, LODWORD(size[1]), 0LL) == -1 )
{
v20 = _errno_location();
v21 = *v20;
if ( *v20 != 11 && v21 != 32 )
{
v22 = (unsigned int *)v20;
v23 = strerror(v21);
fprintf(stderr, "%s:%d send() error (%d) %s\n", "client_thread.c", 397LL, *v22, v23);
goto LABEL_66;
}
}
}
}
}
}
v11 += 3;
if ( (_DWORD *)v13 == v11 )
goto LABEL_60;
continue;
}
}
}
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "%s:%d epoll() error adding client (%d) %s\n", "client_thread.c", 251LL, (unsigned int)*v16, v17);
free(s);
v18 = &v6[v4];
LABEL_68:
v28 = (unsigned int *)v6;
do
{
v29 = *v28;
if ( *v28 != -1 )
{
shutdown(v29, 2);
close_ign_signal(v29);
}
++v28;
}
while ( v28 < (unsigned int *)v18 );
LABEL_18:
close_ign_signal(n);
free(v2);
free(v6);
return 0LL;
}

original_code:
void* client_thread(void *data) {
 const struct client_request * const req = data;
 const struct client_request_details * details = req->details;
 const struct settings settings = *req->settings;
 const unsigned long long time_between_sends = settings.rate> 0 ? 1000000 / settings.rate : 0;
 unsigned long long next_send_time = 0;
 int *client = ((void *)0);
 unsigned int clients = 0;
 unsigned int clients_temp = 0;
 int *c = ((void *)0);
 char *buffer= ((void *)0);
 int readFD_epoll = -1;
 struct epoll_event *events = ((void *)0);
 ((void) sizeof ((req != ((void *)0)) ? 1 : 0), __extension__ ({ if (req != ((void *)0)) ; else __assert_fail ("req != NULL", "client_thread.c", 168, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((details != ((void *)0)) ? 1 : 0), __extension__ ({ if (details != ((void *)0)) ; else __assert_fail ("details != NULL", "client_thread.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 while (details != ((void *)0)) {
  clients += details->n;
  details = details->next;
 }
 if (clients == 0) {
  fprintf(stderr, "%s:%d Must have more than zero clients!\n", "client_thread.c", 178 );
  goto cleanup;
 }
 client = calloc(clients, sizeof(*client));
 if ( client == ((void *)0) ) {
  fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 192 );
  goto cleanup;
 }
 for ( c = client; c < &client[ clients ]; c++)
  *c = (-1);
 if ( settings.verbose )
  printf("Core %d: Started client thread\n", req->cores);
 if ( connect_connections(&settings, req, client, &clients_temp) ) {
  goto cleanup;
 }
 if ( clients != clients_temp ) {
  fprintf(stderr, "%s:%d Requested number of clients does not match actual clients (%d != %d)\n", "client_thread.c", 208, clients, clients_temp );
  goto cleanup;
 }
 buffer = malloc( settings.message_size );
 if ( buffer == ((void *)0) ) {
  fprintf(stderr, "%s:%d malloc error\n", "client_thread.c", 215 );
  goto cleanup;
 }
 memset( buffer, 0x41, settings.message_size );
 readFD_epoll = epoll_create(clients);
 if(readFD_epoll == -1) {
  fprintf(stderr, "%s:%d epoll_create() error (%d) %s\n", "client_thread.c", 223, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 events = calloc( clients, sizeof(*events) );
 if ( events == ((void *)0) ) {
  fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 229 );
  goto cleanup;
 }
 for (c = client; c < &client [ clients ]; c++) {
  int s = *c;
  struct epoll_event event = {0};
  ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "client_thread.c", 245, __extension__ __PRETTY_FUNCTION__); }));
  event.events = EPOLLIN | EPOLLOUT;
  event.data.fd = s;
  if (epoll_ctl(readFD_epoll, 1, s, &event) == -1) {
   fprintf(stderr, "%s:%d epoll() error adding client (%d) %s\n", "client_thread.c", 251, (*__errno_location ()), strerror((*__errno_location ())) );
   goto cleanup;
  }
 }
 threads_signal_parent ( 2, settings.threaded_model );
 wait_for_nonzero( &go_mutex, &go_cond, &bGo );
 next_send_time = get_microseconds();
 while ( bRunning ) {
  int i;
  int ready = epoll_wait_ign_signal(readFD_epoll, events, clients, 1000);
  for ( i = 0; i < ready; i++ ) {
   int s = events[i].data.fd;
   ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "client_thread.c", 288, __extension__ __PRETTY_FUNCTION__); }));
   if (events[i].events & (EPOLLHUP | EPOLLERR)) {
    close(s);
    continue;
   }
   if( events[i].events & EPOLLIN) {
      int len = recv_ign_signal( s, buffer, settings.message_size, 0);
      if ( len == (-1) ) {
       if ( (*__errno_location ()) != 104 ) {
        fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "client_thread.c", 330, s, (*__errno_location ()), strerror((*__errno_location ())) );
        goto cleanup;
       }
      }
      if ( len <= 0 ) {
       if ( settings.verbose )
        printf("  Client: %d Removed client (%d/%d)\n", req->cores, (int)((c - client) / sizeof(*c)) + 1, clients );
       close_ign_signal(s);
       clients--;
       if ( clients == 0 )
        goto cleanup;
       continue;
      }
     }
     if( events[i].events & EPOLLOUT) {
      if ( time_between_sends> 0 ) {
       const unsigned long long now = get_microseconds();
       if ( next_send_time > now )
        continue;
       next_send_time += time_between_sends;
      }
      if ( send_ign_signal( s, buffer, settings.message_size, 0 ) == (-1) ) {
       if ( (*__errno_location ()) != 11 && (*__errno_location ()) != 32 ) {
        fprintf(stderr, "%s:%d send() error (%d) %s\n", "client_thread.c", 397, (*__errno_location ()), strerror((*__errno_location ())) );
        goto cleanup;
       }
      }
     }
   }
  }
cleanup:
 free( buffer );
 if ( client != ((void *)0) ) {
  for (c = client; c < &client [ clients ]; c++) {
   int s = *c;
   if ( s != (-1) ) {
    shutdown ( s, SHUT_RDWR );
    close_ign_signal(s);
   }
  }
 }
 close_ign_signal(readFD_epoll);
 free( events );
 free ( client );
 return ((void *)0);
}

canonical_original_code:
void *client_thread(void *data) {
 struct client_request *req = data;
 struct client_request_details *details = req->details;
 struct settings settings = *req->settings;
 unsigned long long time_between_sends = settings.rate> 0 ? 1000000 / settings.rate : 0;
 unsigned long long next_send_time = 0;
 int *client = ((void *)0);
 unsigned int clients = 0;
 unsigned int clients_temp = 0;
 int *c = ((void *)0);
 char *buffer = ((void *)0);
 int readFD_epoll = -1;
 struct epoll_event *events = ((void *)0);
 ((void) sizeof ((req != ((void *)0)) ? 1 : 0), __extension__ ({ if (req != ((void *)0)) ; else __assert_fail ("req != NULL", "client_thread.c", 168, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((details != ((void *)0)) ? 1 : 0), __extension__ ({ if (details != ((void *)0)) ; else __assert_fail ("details != NULL", "client_thread.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 while (details != ((void *)0)) {
  clients += details->n;
  details = details->next;
 }
 if (clients == 0) {
  fprintf(stderr, "%s:%d Must have more than zero clients!\n", "client_thread.c", 178 );
  goto cleanup;
 }
 client = calloc(clients, sizeof(*client));
 if ( client == ((void *)0) ) {
  fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 192 );
  goto cleanup;
 }
 for ( c = client; c < &client[ clients ]; c++)
  *c = (-1);
 if ( settings.verbose )
  printf("Core %d: Started client thread\n", req->cores);
 if ( connect_connections(&settings, req, client, &clients_temp) ) {
  goto cleanup;
 }
 if ( clients != clients_temp ) {
  fprintf(stderr, "%s:%d Requested number of clients does not match actual clients (%d != %d)\n", "client_thread.c", 208, clients, clients_temp );
  goto cleanup;
 }
 buffer = malloc( settings.message_size );
 if ( buffer == ((void *)0) ) {
  fprintf(stderr, "%s:%d malloc error\n", "client_thread.c", 215 );
  goto cleanup;
 }
 memset( buffer, 0x41, settings.message_size );
 readFD_epoll = epoll_create(clients);
 if(readFD_epoll == -1) {
  fprintf(stderr, "%s:%d epoll_create() error (%d) %s\n", "client_thread.c", 223, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 events = calloc( clients, sizeof(*events) );
 if ( events == ((void *)0) ) {
  fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 229 );
  goto cleanup;
 }
 for (c = client; c < &client [ clients ]; c++) {
  int s = *c;
  struct epoll_event event = {0};
  ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "client_thread.c", 245, __extension__ __PRETTY_FUNCTION__); }));
  event.events = EPOLLIN | EPOLLOUT;
  event.data.fd = s;
  if (epoll_ctl(readFD_epoll, 1, s, &event) == -1) {
   fprintf(stderr, "%s:%d epoll() error adding client (%d) %s\n", "client_thread.c", 251, (*__errno_location ()), strerror((*__errno_location ())) );
   goto cleanup;
  }
 }
 threads_signal_parent ( 2, settings.threaded_model );
 wait_for_nonzero( &go_mutex, &go_cond, &bGo );
 next_send_time = get_microseconds();
 while ( bRunning ) {
  int i;
  int ready = epoll_wait_ign_signal(readFD_epoll, events, clients, 1000);
  for ( i = 0; i < ready; i++ ) {
   int s = events[i].data.fd;
   ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "client_thread.c", 288, __extension__ __PRETTY_FUNCTION__); }));
   if (events[i].events & (EPOLLHUP | EPOLLERR)) {
    close(s);
    continue;
   }
   if( events[i].events & EPOLLIN) {
      int len = recv_ign_signal( s, buffer, settings.message_size, 0);
      if ( len == (-1) ) {
       if ( (*__errno_location ()) != 104 ) {
        fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "client_thread.c", 330, s, (*__errno_location ()), strerror((*__errno_location ())) );
        goto cleanup;
       }
      }
      if ( len <= 0 ) {
       if ( settings.verbose )
        printf("  Client: %d Removed client (%d/%d)\n", req->cores, (int)((c - client) / sizeof(*c)) + 1, clients );
       close_ign_signal(s);
       clients--;
       if ( clients == 0 )
        goto cleanup;
       continue;
      }
     }
     if( events[i].events & EPOLLOUT) {
      if ( time_between_sends> 0 ) {
       unsigned long long now = get_microseconds();
       if ( next_send_time > now )
        continue;
       next_send_time += time_between_sends;
      }
      if ( send_ign_signal( s, buffer, settings.message_size, 0 ) == (-1) ) {
       if ( (*__errno_location ()) != 11 && (*__errno_location ()) != 32 ) {
        fprintf(stderr, "%s:%d send() error (%d) %s\n", "client_thread.c", 397, (*__errno_location ()), strerror((*__errno_location ())) );
        goto cleanup;
       }
      }
     }
   }
  }
cleanup:
 free( buffer );
 if ( client != ((void *)0) ) {
  for (c = client; c < &client [ clients ]; c++) {
   int s = *c;
   if ( s != (-1) ) {
    shutdown ( s, SHUT_RDWR );
    close_ign_signal(s);
   }
  }
 }
 close_ign_signal(readFD_epoll);
 free( events );
 free ( client );
 return ((void *)0);
}

variable_types: struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; }

variable_types:
clients
unsigned int

variable_types:
c
int *

variable_types:
buffer
char *

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *

variable_types: i int

variable_types: ready int

variable_types: len int

variable_types:
now
unsigned long long

return_type: void *

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }


decompiled_code:
int print_version()
{
return fprintf(stderr, "threadnetperf r%s by bramp 2007-2010\n", "Unversioned directory");
}

canonical_decompiled_code:
int func1()
{
return fprintf(stderr, "threadnetperf r%s by bramp 2007-2010\n", "Unversioned directory");
}

original_code:
void print_version() {
 fprintf(stderr, "threadnetperf r%s by bramp 2007-2010\n", "Unversioned directory" );
}