decompiled_code:
__int64 __fastcall read_settings(__int64 fd, __int64 a2)
{
unsigned int v3; // er12
int v4; // eax
int v5; // eax
unsigned int v6; // er8
int v7; // eax
unsigned int v8; // edi
int v9; // eax
unsigned int v10; // edi
int v11; // eax
unsigned int v12; // edi
int v13; // eax
unsigned int v14; // edi
int v15; // eax
unsigned int v16; // edi
int v17; // eax
__int16 v18; // ax
char v19; // dl
unsigned int v20; // er14
__int64 v21; // rcx
char v22; // dl
void *v23; // rax
unsigned int v24; // ebp
int v25; // eax
int v27; // eax
__int64 v28; // rsi
__int64 v29; // rdi
unsigned int v30; // eax
__int64 v31; // rdx
__int64 v32; // rcx
__int64 v33; // r9
int *v34; // rbx
char *v35; // rax
socklen_t len; // [rsp+Ch] [rbp-15Ch] BYREF
__int128 v37; // [rsp+10h] [rbp-158h] BYREF
__int128 v38; // [rsp+20h] [rbp-148h]
__int64 v39; // [rsp+30h] [rbp-138h]
struct sockaddr addr; // [rsp+40h] [rbp-128h] BYREF

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");
v3 = fd;
v37 = 0LL;
v39 = 0LL;
v38 = 0LL;
v4 = recv_ign_signal(fd, &v37, 40LL, 0LL);
if ( v4 != 40 )
{
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v6 = v37;
goto LABEL_21;
}
v5 = _bswap_32(7u);
if ( v6 != v5 )
{
LABEL_21:
v30 = _bswap_32(v6);
fprintf(stderr, "Invalid setting struct received (size:%d vs %d, ver:%d vs %d\n", v31, v32, v30, v33);
return 0xFFFFFFFFLL;
}
v7 = _bswap_32(DWORD1(v37));
v8 = DWORD2(v37);
*(_DWORD *)a2 = v7;
v9 = _bswap_32(v8);
v10 = HIDWORD(v37);
*(_DWORD *)(a2 + 4) = v9;
v11 = _bswap_32(v10);
v12 = DWORD2(v38);
*(_DWORD *)(a2 + 8) = v11;
*(_DWORD *)(a2 + 88) = BYTE5(v38);
v13 = _bswap_32(v12);
v14 = HIDWORD(v38);
*(_DWORD *)(a2 + 40) = v13;
v15 = _bswap_32(v14);
v16 = v39;
*(_DWORD *)(a2 + 44) = v15;
v17 = _bswap_32(v16);
LOWORD(v16) = WORD2(v39);
*(_DWORD *)(a2 + 48) = v17;
v18 = _bswap_16(v16);
v19 = v38;
v20 = BYTE6(v39);
*(_QWORD *)(a2 + 16) = 0LL;
*(_WORD *)(a2 + 64) = v18;
LOBYTE(v18) = BYTE1(v38);
*(_DWORD *)(a2 + 68) = v20;
*(_QWORD *)(a2 + 32) = v21;
*(_QWORD *)(a2 + 24) = 0LL;
LOBYTE(v18) = (2 * v19) & 2 | (4 * v18) & 4;
v22 = BYTE2(v38);
*(_QWORD *)(a2 + 56) = 0LL;
LOBYTE(v18) = *(_BYTE *)(a2 + 12) & 0xC0 | (32 * BYTE4(v38)) & 0x20 | (16 * BYTE3(v38)) & 0x10 | (8 * v22) & 8 | v18;
*(_BYTE *)(a2 + 12) = v18;
if ( (v18 & 0x20) != 0 )
{
len = 128;
if ( getpeername(v3, &addr, &len) )
{
v34 = _errno_location();
v35 = strerror(*v34);
fprintf(
stderr,
"%s:%d read_settings() getpeername error (%d) %s\n",
"serialise.c",
135LL,
(unsigned int)*v34,
v35);
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;
v20 = *(_DWORD *)(a2 + 68);
}
v23 = calloc(v20, 0x98uLL);
*(_QWORD *)(a2 + 72) = v23;
if ( v23 )
{
v24 = 0;
if ( !v20 )
{
LABEL_18:
v27 = count_server_cores(v23, v20);
v28 = *(unsigned int *)(a2 + 68);
v29 = *(_QWORD *)(a2 + 72);
*(_DWORD *)(a2 + 84) = v27;
*(_DWORD *)(a2 + 80) = count_client_cores(v29, v28);
return 0LL;
}
while ( (unsigned int)recv_ign_signal(v3, &len, 1LL, 0LL) == 1 )
{
v25 = recv_ign_signal(v3, &addr, (unsigned __int8)len, 0LL);
if ( (unsigned __int8)len != v25 )
break;
*((_BYTE *)&addr.sa_family + (unsigned __int8)len) = 0;
if ( (unsigned int)parse_test(a2, &addr, *(_QWORD *)(a2 + 72) + 152LL * v24) )
break;
v20 = *(_DWORD *)(a2 + 68);
if ( v20 <= ++v24 )
{
v23 = *(void **)(a2 + 72);
goto LABEL_18;
}
}
return 0xFFFFFFFFLL;
}
fprintf(stderr, "%s:%d read_settings() calloc error\n", "serialise.c", 155LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 fd, __int64 a2)
{
unsigned int v3; // er12
int v4; // eax
int v5; // eax
unsigned int v6; // er8
int v7; // eax
unsigned int v8; // edi
int v9; // eax
unsigned int v10; // edi
int v11; // eax
unsigned int v12; // edi
int v13; // eax
unsigned int v14; // edi
int v15; // eax
unsigned int v16; // edi
int v17; // eax
__int16 v18; // ax
char v19; // dl
unsigned int v20; // er14
__int64 v21; // rcx
char v22; // dl
void *v23; // rax
unsigned int v24; // ebp
int v25; // eax
int v27; // eax
__int64 v28; // rsi
__int64 v29; // rdi
unsigned int v30; // eax
__int64 v31; // rdx
__int64 v32; // rcx
__int64 v33; // r9
int *v34; // rbx
char *v35; // rax
socklen_t len; // [rsp+Ch] [rbp-15Ch] BYREF
__int128 v37; // [rsp+10h] [rbp-158h] BYREF
__int128 v38; // [rsp+20h] [rbp-148h]
__int64 v39; // [rsp+30h] [rbp-138h]
struct sockaddr addr; // [rsp+40h] [rbp-128h] BYREF

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");
v3 = fd;
v37 = 0LL;
v39 = 0LL;
v38 = 0LL;
v4 = recv_ign_signal(fd, &v37, 40LL, 0LL);
if ( v4 != 40 )
{
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v6 = v37;
goto LABEL_21;
}
v5 = func0(7u);
if ( v6 != v5 )
{
LABEL_21:
v30 = func0(v6);
fprintf(stderr, "Invalid setting struct received (size:%d vs %d, ver:%d vs %d\n", v31, v32, v30, v33);
return 0xFFFFFFFFLL;
}
v7 = func0(DWORD1(v37));
v8 = DWORD2(v37);
*(_DWORD *)a2 = v7;
v9 = func0(v8);
v10 = HIDWORD(v37);
*(_DWORD *)(a2 + 4) = v9;
v11 = func0(v10);
v12 = DWORD2(v38);
*(_DWORD *)(a2 + 8) = v11;
*(_DWORD *)(a2 + 88) = BYTE5(v38);
v13 = func0(v12);
v14 = HIDWORD(v38);
*(_DWORD *)(a2 + 40) = v13;
v15 = func0(v14);
v16 = v39;
*(_DWORD *)(a2 + 44) = v15;
v17 = func0(v16);
LOWORD(v16) = WORD2(v39);
*(_DWORD *)(a2 + 48) = v17;
v18 = func1(v16);
v19 = v38;
v20 = BYTE6(v39);
*(_QWORD *)(a2 + 16) = 0LL;
*(_WORD *)(a2 + 64) = v18;
LOBYTE(v18) = BYTE1(v38);
*(_DWORD *)(a2 + 68) = v20;
*(_QWORD *)(a2 + 32) = v21;
*(_QWORD *)(a2 + 24) = 0LL;
LOBYTE(v18) = (2 * v19) & 2 | (4 * v18) & 4;
v22 = BYTE2(v38);
*(_QWORD *)(a2 + 56) = 0LL;
LOBYTE(v18) = *(_BYTE *)(a2 + 12) & 0xC0 | (32 * BYTE4(v38)) & 0x20 | (16 * BYTE3(v38)) & 0x10 | (8 * v22) & 8 | v18;
*(_BYTE *)(a2 + 12) = v18;
if ( (v18 & 0x20) != 0 )
{
len = 128;
if ( getpeername(v3, &addr, &len) )
{
v34 = _errno_location();
v35 = strerror(*v34);
fprintf(
stderr,
"%s:%d read_settings() getpeername error (%d) %s\n",
"serialise.c",
135LL,
(unsigned int)*v34,
v35);
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;
v20 = *(_DWORD *)(a2 + 68);
}
v23 = calloc(v20, 0x98uLL);
*(_QWORD *)(a2 + 72) = v23;
if ( v23 )
{
v24 = 0;
if ( !v20 )
{
LABEL_18:
v27 = count_server_cores(v23, v20);
v28 = *(unsigned int *)(a2 + 68);
v29 = *(_QWORD *)(a2 + 72);
*(_DWORD *)(a2 + 84) = v27;
*(_DWORD *)(a2 + 80) = count_client_cores(v29, v28);
return 0LL;
}
while ( (unsigned int)recv_ign_signal(v3, &len, 1LL, 0LL) == 1 )
{
v25 = recv_ign_signal(v3, &addr, (unsigned __int8)len, 0LL);
if ( (unsigned __int8)len != v25 )
break;
*((_BYTE *)&addr.sa_family + (unsigned __int8)len) = 0;
if ( (unsigned int)parse_test(a2, &addr, *(_QWORD *)(a2 + 72) + 152LL * v24) )
break;
v20 = *(_DWORD *)(a2 + 68);
if ( v20 <= ++v24 )
{
v23 = *(void **)(a2 + 72);
goto LABEL_18;
}
}
return 0xFFFFFFFFLL;
}
fprintf(stderr, "%s:%d read_settings() calloc error\n", "serialise.c", 155LL);
return 0xFFFFFFFFLL;
}

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

decompiled_code:
__int64 __fastcall send_settings(unsigned int a1, __int64 a2)
{
int v3; // eax
unsigned int v4; // edi
int v5; // eax
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // edi
int v9; // eax
unsigned int v10; // edi
char v11; // dl
int v12; // eax
int v13; // eax
unsigned int v14; // edi
int v15; // eax
unsigned int v16; // edi
int v17; // eax
unsigned int v18; // ebp
unsigned int *v19; // rax
int v20; // eax
int v22[4]; // [rsp+0h] [rbp-158h] BYREF
__int128 v23; // [rsp+10h] [rbp-148h]
__int64 v24; // [rsp+20h] [rbp-138h]
char v25; // [rsp+30h] [rbp-128h] BYREF
char s[295]; // [rsp+31h] [rbp-127h] BYREF

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0xBFu, "send_settings");
if ( !a2 )
_assert_fail("settings != NULL", "serialise.c", 0xC0u, "send_settings");
v24 = 0LL;
v23 = 0LL;
v3 = _bswap_32(7u);
v4 = *(_DWORD *)a2;
v22[0] = v3;
v5 = _bswap_32(v4);
v6 = *(_DWORD *)(a2 + 4);
v22[1] = v5;
v7 = _bswap_32(v6);
v8 = *(_DWORD *)(a2 + 8);
v22[2] = v7;
v9 = _bswap_32(v8);
v10 = *(_DWORD *)(a2 + 40);
v22[3] = v9;
LOBYTE(v9) = *(_BYTE *)(a2 + 12);
LOBYTE(v23) = (v9 & 2) != 0;
BYTE1(v23) = (v9 & 4) != 0;
BYTE2(v23) = (v9 & 8) != 0;
v11 = v9;
BYTE4(v23) = (v9 & 0x20) != 0;
v12 = *(_DWORD *)(a2 + 88);
BYTE3(v23) = (v11 & 0x10) != 0;
BYTE5(v23) = v12;
v13 = _bswap_32(v10);
v14 = *(_DWORD *)(a2 + 44);
DWORD2(v23) = v13;
v15 = _bswap_32(v14);
v16 = *(_DWORD *)(a2 + 48);
HIDWORD(v23) = v15;
v17 = _bswap_32(v16);
LOWORD(v16) = *(_WORD *)(a2 + 64);
LODWORD(v24) = v17;
WORD2(v24) = _bswap_16(v16);
HIWORD(v24) = (unsigned __int8)*(_DWORD *)(a2 + 68);
if ( (unsigned int)send_ign_signal(a1, v22) != 40 )
return 0xFFFFFFFFLL;
v18 = 0;
if ( *(_DWORD *)(a2 + 68) )
{
while ( 1 )
{
v19 = (unsigned int *)(*(_QWORD *)(a2 + 72) + 152LL * v18);
sprintf(s, "%u(%u-%u) ", v19[2], *v19, v19[1]);
v25 = strlen(s);
v20 = send_ign_signal(a1, &v25);
if ( v25 + 1 != v20 )
break;
if ( *(_DWORD *)(a2 + 68) <= ++v18 )
return 0LL;
}
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
int v3; // eax
unsigned int v4; // edi
int v5; // eax
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // edi
int v9; // eax
unsigned int v10; // edi
char v11; // dl
int v12; // eax
int v13; // eax
unsigned int v14; // edi
int v15; // eax
unsigned int v16; // edi
int v17; // eax
unsigned int v18; // ebp
unsigned int *v19; // rax
int v20; // eax
int v22[4]; // [rsp+0h] [rbp-158h] BYREF
__int128 v23; // [rsp+10h] [rbp-148h]
__int64 v24; // [rsp+20h] [rbp-138h]
char v25; // [rsp+30h] [rbp-128h] BYREF
char s[295]; // [rsp+31h] [rbp-127h] BYREF

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0xBFu, "send_settings");
if ( !a2 )
_assert_fail("settings != NULL", "serialise.c", 0xC0u, "send_settings");
v24 = 0LL;
v23 = 0LL;
v3 = func0(7u);
v4 = *(_DWORD *)a2;
v22[0] = v3;
v5 = func0(v4);
v6 = *(_DWORD *)(a2 + 4);
v22[1] = v5;
v7 = func0(v6);
v8 = *(_DWORD *)(a2 + 8);
v22[2] = v7;
v9 = func0(v8);
v10 = *(_DWORD *)(a2 + 40);
v22[3] = v9;
LOBYTE(v9) = *(_BYTE *)(a2 + 12);
LOBYTE(v23) = (v9 & 2) != 0;
BYTE1(v23) = (v9 & 4) != 0;
BYTE2(v23) = (v9 & 8) != 0;
v11 = v9;
BYTE4(v23) = (v9 & 0x20) != 0;
v12 = *(_DWORD *)(a2 + 88);
BYTE3(v23) = (v11 & 0x10) != 0;
BYTE5(v23) = v12;
v13 = func0(v10);
v14 = *(_DWORD *)(a2 + 44);
DWORD2(v23) = v13;
v15 = func0(v14);
v16 = *(_DWORD *)(a2 + 48);
HIDWORD(v23) = v15;
v17 = func0(v16);
LOWORD(v16) = *(_WORD *)(a2 + 64);
LODWORD(v24) = v17;
WORD2(v24) = func1(v16);
HIWORD(v24) = (unsigned __int8)*(_DWORD *)(a2 + 68);
if ( (unsigned int)send_ign_signal(a1, v22) != 40 )
return 0xFFFFFFFFLL;
v18 = 0;
if ( *(_DWORD *)(a2 + 68) )
{
while ( 1 )
{
v19 = (unsigned int *)(*(_QWORD *)(a2 + 72) + 152LL * v18);
sprintf(s, "%u(%u-%u) ", v19[2], *v19, v19[1]);
v25 = strlen(s);
v20 = send_ign_signal(a1, &v25);
if ( v25 + 1 != v20 )
break;
if ( *(_DWORD *)(a2 + 68) <= ++v18 )
return 0LL;
}
return 0xFFFFFFFFLL;
}
return 0LL;
}

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
__int128 *v3; // rbp
int v4; // eax
int *v5; // rbx
char *v6; // rax
__int128 v8; // [rsp+0h] [rbp-58h] BYREF
__int128 v9; // [rsp+10h] [rbp-48h]
__int128 v10; // [rsp+20h] [rbp-38h]

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int128 *v3; // rbp
int v4; // eax
int *v5; // rbx
char *v6; // rax
__int128 v8; // [rsp+0h] [rbp-58h] BYREF
__int128 v9; // [rsp+10h] [rbp-48h]
__int128 v10; // [rsp+20h] [rbp-38h]

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

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(int a1, __int64 a2)
{
unsigned int v2; // edi
unsigned int v3; // er8
int v5[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+8h] [rbp-30h]
__int64 v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+18h] [rbp-20h]
__int64 v9; // [rsp+20h] [rbp-18h]
__int64 v10; // [rsp+28h] [rbp-10h]

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

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

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "serialise.c", 0x11Bu, "send_results");
if ( !a2 )
_assert_fail("stats != NULL", "serialise.c", 0x11Cu, "send_results");
v2 = *(_DWORD *)a2;
v5[1] = 0;
v5[0] = func0(v2);
v6 = *(_QWORD *)(a2 + 8);
v7 = *(_QWORD *)(a2 + 16);
v8 = *(_QWORD *)(a2 + 24);
v9 = *(_QWORD *)(a2 + 32);
v10 = *(_QWORD *)(a2 + 40);
return (unsigned int)-((unsigned int)send_ign_signal(v3, v5) != 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)
{
__int64 v1; // r12
size_t v3; // rbp
char *v4; // r8
int v5; // eax
unsigned int v6; // er10
__int64 v7; // r11
char *v8; // rsi
int *v9; // rcx
__int64 v10; // r9
char *v11; // rdx
int v12; // eax
__int16 v13; // di
__int16 v14; // ax
int v15; // eax
int v16; // eax

if ( !a1 )
_assert_fail("settings != NULL", "server.c", 0x15u, "prepare_servers");
v1 = *(_QWORD *)(a1 + 72);
if ( !v1 )
_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");
v3 = *(unsigned int *)(a1 + 84);
sreq_size = v3;
sreq = calloc(v3, 0x48uLL);
v4 = (char *)sreq;
if ( !sreq )
{
fprintf(stderr, "%s:%d calloc() error\n", "server.c", 32LL);
v6 = -1;
sreq_size = 0LL;
return v6;
}
v5 = *(_DWORD *)(a1 + 68);
v6 = 0;
v7 = 72 * v3;
if ( !v5 )
goto LABEL_16;
v8 = (char *)sreq + v7;
v9 = (int *)(v1 + 4);
v6 = 0;
v10 = v1 + 152LL * (unsigned int)(v5 - 1) + 156;
do
{
if ( v4 >= v8 )
goto LABEL_22;
v11 = v4;
while ( 1 )
{
if ( !*((_QWORD *)v11 + 2) )
{
if ( v8 > v11 )
{
v12 = *v9;
v13 = *((_WORD *)v9 + 7);
*((_QWORD *)v11 + 2) = a1;
*((_DWORD *)v11 + 2) = v12;
v14 = _bswap_16(v13);
*((_DWORD *)v11 + 1) = 0;
*(_WORD *)v11 = v14;
v15 = 0;
goto LABEL_15;
}
LABEL_22:
_assert_fail("s < &sreq[sreq_size]", "server.c", 0x2Fu, "prepare_servers");
}
if ( *((_DWORD *)v11 + 2) == *v9 )
break;
v11 += 72;
if ( v11 >= v8 )
goto LABEL_22;
}
if ( v8 <= v11 )
goto LABEL_22;
v15 = *((_DWORD *)v11 + 1);
LABEL_15:
v16 = v9[1] + v15;
v9 += 38;
*((_DWORD *)v11 + 1) = v16;
}
while ( v9 != (int *)v10 );
LABEL_16:
if ( !*(_QWORD *)&v4[v7 - 56] )
_assert_fail("sreq[sreq_size - 1].settings != NULL", "server.c", 0x41u, "prepare_servers");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
size_t v3; // rbp
char *v4; // r8
int v5; // eax
unsigned int v6; // er10
__int64 v7; // r11
char *v8; // rsi
int *v9; // rcx
__int64 v10; // r9
char *v11; // rdx
int v12; // eax
__int16 v13; // di
__int16 v14; // ax
int v15; // eax
int v16; // eax

if ( !a1 )
_assert_fail("settings != NULL", "server.c", 0x15u, "prepare_servers");
v1 = *(_QWORD *)(a1 + 72);
if ( !v1 )
_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");
v3 = *(unsigned int *)(a1 + 84);
sreq_size = v3;
sreq = calloc(v3, 0x48uLL);
v4 = (char *)sreq;
if ( !sreq )
{
fprintf(stderr, "%s:%d calloc() error\n", "server.c", 32LL);
v6 = -1;
sreq_size = 0LL;
return v6;
}
v5 = *(_DWORD *)(a1 + 68);
v6 = 0;
v7 = 72 * v3;
if ( !v5 )
goto LABEL_16;
v8 = (char *)sreq + v7;
v9 = (int *)(v1 + 4);
v6 = 0;
v10 = v1 + 152LL * (unsigned int)(v5 - 1) + 156;
do
{
if ( v4 >= v8 )
goto LABEL_22;
v11 = v4;
while ( 1 )
{
if ( !*((_QWORD *)v11 + 2) )
{
if ( v8 > v11 )
{
v12 = *v9;
v13 = *((_WORD *)v9 + 7);
*((_QWORD *)v11 + 2) = a1;
*((_DWORD *)v11 + 2) = v12;
v14 = func0(v13);
*((_DWORD *)v11 + 1) = 0;
*(_WORD *)v11 = v14;
v15 = 0;
goto LABEL_15;
}
LABEL_22:
_assert_fail("s < &sreq[sreq_size]", "server.c", 0x2Fu, "prepare_servers");
}
if ( *((_DWORD *)v11 + 2) == *v9 )
break;
v11 += 72;
if ( v11 >= v8 )
goto LABEL_22;
}
if ( v8 <= v11 )
goto LABEL_22;
v15 = *((_DWORD *)v11 + 1);
LABEL_15:
v16 = v9[1] + v15;
v9 += 38;
*((_DWORD *)v11 + 1) = v16;
}
while ( v9 != (int *)v10 );
LABEL_16:
if ( !*(_QWORD *)&v4[v7 - 56] )
_assert_fail("sreq[sreq_size - 1].settings != NULL", "server.c", 0x41u, "prepare_servers");
return v6;
}

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)
{
unsigned int v1; // er12
__int64 v2; // rax
__int64 v3; // rbx
int *v4; // rbx
char *v5; // rax
_BYTE v7[152]; // [rsp+0h] [rbp-98h] BYREF

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

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

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

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


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)
{
char *v1; // rax
unsigned int v2; // er12
__int64 v3; // rdx
__int64 v4; // rbx
char *v5; // rax
__int64 v6; // rdx
_BYTE v8[152]; // [rsp+0h] [rbp-98h] BYREF

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

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

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

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()
{
_QWORD *v0; // rdi
unsigned int v1; // ebp
__int64 v2; // rax
_QWORD *v3; // rbx
void *v4; // rdi

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

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

v0 = creq;
if ( creq )
{
if ( !creq_size )
_assert_fail("creq_size != 0", "client.c", 0x6Du, "cleanup_clients");
v1 = 0;
v2 = 0LL;
do
{
v3 = (_QWORD *)v0[3 * v2 + 2];
if ( v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[17];
free(v4);
}
while ( v3 );
v0 = creq;
}
v2 = ++v1;
}
while ( v1 < (unsigned __int64)creq_size );
free(v0);
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 v4; // r12
__int64 v7; // r14
unsigned int v8; // eax
unsigned int v9; // er15
int v10; // er14
int v11; // eax
__int64 v12; // rdx
char v13; // al
void *v14; // rcx
__int64 v15; // rdx
int *v16; // rbx
char *v17; // rax
int *v19; // rbx
char *v20; // rax
int v21; // edi
int *v22; // rbx
char *v23; // rax
int *v24; // rbx
char *v25; // rax
int *v26; // rbx
char *v27; // rax
int *v28; // rbx
char *v29; // rax
int *v30; // rbx
char *v31; // rax
int *v32; // rbx
char *v33; // rax
_DWORD *v34; // [rsp+0h] [rbp-478h]
char v35[1128]; // [rsp+10h] [rbp-468h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
__int64 v4; // r12
__int64 v7; // r14
unsigned int v8; // eax
unsigned int v9; // er15
int v10; // er14
int v11; // eax
__int64 v12; // rdx
char v13; // al
void *v14; // rcx
__int64 v15; // rdx
int *v16; // rbx
char *v17; // rax
int *v19; // rbx
char *v20; // rax
int v21; // edi
int *v22; // rbx
char *v23; // rax
int *v24; // rbx
char *v25; // rax
int *v26; // rbx
char *v27; // rax
int *v28; // rbx
char *v29; // rax
int *v30; // rbx
char *v31; // rax
int *v32; // rbx
char *v33; // rax
_DWORD *v34; // [rsp+0h] [rbp-478h]
char v35[1128]; // [rsp+10h] [rbp-468h] BYREF

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

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; // r12
const __m128i *v2; // rax
_DWORD *v3; // r15
unsigned int v4; // er14
int *v5; // rax
int *v6; // rbp
char *v7; // rbx
unsigned int v8; // er13
unsigned int *v9; // r12
unsigned int v10; // er14
void *v12; // rax
int *v13; // r8
int *v14; // r12
int v15; // edx
int *v16; // r12
char *v17; // rax
size_t v18; // r8
char *v19; // r15
int v20; // eax
char *v21; // rbx
unsigned int v22; // er13
int v23; // eax
int v24; // eax
int *v25; // rax
int *v26; // rax
int v27; // edi
char *v28; // rax
int *v29; // r12
char *v30; // rax
char *v31; // rax
__int64 v32; // [rsp+0h] [rbp-E8h]
unsigned int *v33; // [rsp+0h] [rbp-E8h]
unsigned int v34; // [rsp+0h] [rbp-E8h]
void *ptr; // [rsp+8h] [rbp-E0h]
size_t nmemb; // [rsp+10h] [rbp-D8h]
unsigned int *nmemba; // [rsp+10h] [rbp-D8h]
size_t n; // [rsp+18h] [rbp-D0h]
size_t na; // [rsp+18h] [rbp-D0h]
size_t nb; // [rsp+18h] [rbp-D0h]
char *v41; // [rsp+20h] [rbp-C8h]
unsigned int v42; // [rsp+30h] [rbp-B8h]
unsigned int v43; // [rsp+34h] [rbp-B4h]
unsigned int v44; // [rsp+40h] [rbp-A8h] BYREF
struct epoll_event event; // [rsp+44h] [rbp-A4h] BYREF
__int128 v46[2]; // [rsp+50h] [rbp-98h] BYREF
size_t size[2]; // [rsp+70h] [rbp-78h]
__m128i v48; // [rsp+80h] [rbp-68h]
__m128i v49; // [rsp+90h] [rbp-58h]
__m128i v50; // [rsp+A0h] [rbp-48h]

v1 = a1;
v2 = (const __m128i *)*((_QWORD *)a1 + 1);
v3 = (_DWORD *)*((_QWORD *)a1 + 2);
v32 = 0LL;
v46[0] = (__int128)_mm_loadu_si128(v2);
v46[1] = (__int128)_mm_loadu_si128(v2 + 1);
*(__m128i *)size = _mm_loadu_si128(v2 + 2);
v48 = _mm_loadu_si128(v2 + 3);
v49 = _mm_loadu_si128(v2 + 4);
v50 = _mm_loadu_si128(v2 + 5);
if ( v48.m128i_i32[0] )
v32 = 0xF4240u / v48.m128i_i32[0];
v44 = 0;
if ( !v3 )
_assert_fail("details != NULL", "client_thread.c", 0xA9u, "client_thread");
v4 = 0;
do
{
v4 += v3[33];
v3 = (_DWORD *)*((_QWORD *)v3 + 17);
}
while ( v3 );
if ( !v4 )
{
v6 = 0LL;
v8 = -1;
fprintf(stderr, "%s:%d Must have more than zero clients!\n", "client_thread.c", 178LL);
goto LABEL_21;
}
v5 = (int *)calloc(v4, 4uLL);
v6 = v5;
if ( !v5 )
{
v8 = -1;
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 192LL);
goto LABEL_21;
}
v7 = (char *)&v5[v4];
if ( v7 > (char *)v5 )
memset(v5, 255, 4LL * v4);
if ( (BYTE12(v46[0]) & 2) != 0 )
printf("Core %d: Started client thread\n", *a1);
if ( (unsigned int)connect_connections((__int64)v46, a1, v6, &v44) )
{
v8 = -1;
free(0LL);
LABEL_16:
if ( v6 >= (int *)v7 )
goto LABEL_21;
goto LABEL_17;
}
if ( v44 != v4 )
{
v8 = -1;
fprintf(
stderr,
"%s:%d Requested number of clients does not match actual clients (%d != %d)\n",
"client_thread.c",
208LL,
v4,
v44);
ptr = 0LL;
goto LABEL_15;
}
n = LODWORD(size[1]);
v12 = malloc(LODWORD(size[1]));
ptr = v12;
if ( !v12 )
{
v3 = 0LL;
v8 = -1;
fprintf(stderr, "%s:%d malloc error\n", "client_thread.c", 215LL);
goto LABEL_15;
}
memset(v12, 65, n);
v8 = epoll_create(v4);
if ( v8 == -1 )
{
v29 = _errno_location();
v30 = strerror(*v29);
fprintf(stderr, "%s:%d epoll_create() error (%d) %s\n", "client_thread.c", 223LL, (unsigned int)*v29, v30);
goto LABEL_15;
}
v3 = calloc(v4, 0xCuLL);
if ( !v3 )
{
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 229LL);
LABEL_15:
free(ptr);
goto LABEL_16;
}
v13 = v6;
if ( v7 <= (char *)v6 )
{
LABEL_34:
na = (size_t)v13;
threads_signal_parent(2LL, v50.m128i_u32[2]);
wait_for_nonzero(&go_mutex, &go_cond, &bGo);
nmemb = get_microseconds();
if ( !bRunning )
goto LABEL_15;
v18 = na;
v42 = v8;
nb = (size_t)v3;
v43 = ((unsigned __int64)((__int64)(v18 - (_QWORD)v6) >> 2) >> 2) + 1;
v41 = (char *)(v3 + 3);
while ( 1 )
{
v19 = (char *)nb;
v20 = epoll_wait_ign_signal(v42, nb, v4, 1000LL);
if ( v20 > 0 )
break;
LABEL_61:
if ( !bRunning )
{
v3 = (_DWORD *)nb;
v8 = v42;
v7 = (char *)&v6[v4];
goto LABEL_15;
}
}
v21 = &v41[12 * (v20 - 1)];
while ( 1 )
{
v22 = *((_DWORD *)v19 + 1);
if ( v22 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0x120u, "client_thread");
v23 = *(_DWORD *)v19;
if ( (*(_DWORD *)v19 & 0x18) != 0 )
{
close(v22);
goto LABEL_43;
}
if ( (v23 & 1) != 0 )
{
v24 = recv_ign_signal(v22, ptr, LODWORD(size[1]), 0LL);
if ( v24 == -1 )
{
v25 = _errno_location();
if ( *v25 != 104 )
{
v3 = (_DWORD *)nb;
v34 = v22;
nmemba = (unsigned int *)v25;
v8 = v42;
v31 = strerror(*v25);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "client_thread.c", 330LL, v34, *nmemba, v31);
v7 = (char *)&v6[v4];
goto LABEL_15;
}
LABEL_52:
if ( (BYTE12(v46[0]) & 2) != 0 )
printf(" Client: %d Removed client (%d/%d)\n", *v1, v43, v4);
close_ign_signal(v22);
if ( !--v4 )
{
v3 = (_DWORD *)nb;
v8 = v42;
free(ptr);
goto LABEL_21;
}
goto LABEL_43;
}
if ( v24 <= 0 )
goto LABEL_52;
v23 = *(_DWORD *)v19;
}
if ( (v23 & 4) != 0 )
{
if ( v32 )
{
if ( nmemb > get_microseconds() )
goto LABEL_43;
nmemb += v32;
}
if ( send_ign_signal(v22, ptr, LODWORD(size[1]), 0LL) == -1 )
{
v26 = _errno_location();
v27 = *v26;
if ( *v26 != 11 && v27 != 32 )
{
v3 = (_DWORD *)nb;
v33 = (unsigned int *)v26;
v8 = v42;
v28 = strerror(v27);
fprintf(stderr, "%s:%d send() error (%d) %s\n", "client_thread.c", 397LL, *v33, v28);
v7 = (char *)&v6[v4];
goto LABEL_15;
}
}
}
LABEL_43:
v19 += 12;
if ( v21 == v19 )
goto LABEL_61;
}
}
v14 = v6;
while ( 1 )
{
v15 = *v14;
HIDWORD(event.data.u64) = 0;
*(_QWORD *)&event.events = 0LL;
if ( v15 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0xF5u, "client_thread");
event.events = 5;
event.data.fd = v15;
if ( epoll_ctl(v8, 1, v15, &event) == -1 )
break;
if ( v7 <= (char *)++v14 )
{
v13 = v14;
v1 = a1;
goto LABEL_34;
}
}
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(ptr);
LABEL_17:
v9 = (unsigned int *)v6;
do
{
v10 = *v9;
if ( *v9 != -1 )
{
shutdown(v10, 2);
close_ign_signal(v10);
}
++v9;
}
while ( v7 > (char *)v9 );
LABEL_21:
close_ign_signal(v8);
free(v3);
free(v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
unsigned int *v1; // r12
const __m128i *v2; // rax
_DWORD *v3; // r15
unsigned int v4; // er14
int *v5; // rax
int *v6; // rbp
char *v7; // rbx
unsigned int v8; // er13
unsigned int *v9; // r12
unsigned int v10; // er14
void *v12; // rax
int *v13; // r8
int *v14; // r12
int v15; // edx
int *v16; // r12
char *v17; // rax
size_t v18; // r8
char *v19; // r15
int v20; // eax
char *v21; // rbx
unsigned int v22; // er13
int v23; // eax
int v24; // eax
int *v25; // rax
int *v26; // rax
int v27; // edi
char *v28; // rax
int *v29; // r12
char *v30; // rax
char *v31; // rax
__int64 v32; // [rsp+0h] [rbp-E8h]
unsigned int *v33; // [rsp+0h] [rbp-E8h]
unsigned int v34; // [rsp+0h] [rbp-E8h]
void *ptr; // [rsp+8h] [rbp-E0h]
size_t nmemb; // [rsp+10h] [rbp-D8h]
unsigned int *nmemba; // [rsp+10h] [rbp-D8h]
size_t n; // [rsp+18h] [rbp-D0h]
size_t na; // [rsp+18h] [rbp-D0h]
size_t nb; // [rsp+18h] [rbp-D0h]
char *v41; // [rsp+20h] [rbp-C8h]
unsigned int v42; // [rsp+30h] [rbp-B8h]
unsigned int v43; // [rsp+34h] [rbp-B4h]
unsigned int v44; // [rsp+40h] [rbp-A8h] BYREF
struct epoll_event event; // [rsp+44h] [rbp-A4h] BYREF
__int128 v46[2]; // [rsp+50h] [rbp-98h] BYREF
size_t size[2]; // [rsp+70h] [rbp-78h]
__m128i v48; // [rsp+80h] [rbp-68h]
__m128i v49; // [rsp+90h] [rbp-58h]
__m128i v50; // [rsp+A0h] [rbp-48h]

v1 = a1;
v2 = (const __m128i *)*((_QWORD *)a1 + 1);
v3 = (_DWORD *)*((_QWORD *)a1 + 2);
v32 = 0LL;
v46[0] = (__int128)_mm_loadu_si128(v2);
v46[1] = (__int128)_mm_loadu_si128(v2 + 1);
*(__m128i *)size = _mm_loadu_si128(v2 + 2);
v48 = _mm_loadu_si128(v2 + 3);
v49 = _mm_loadu_si128(v2 + 4);
v50 = _mm_loadu_si128(v2 + 5);
if ( v48.m128i_i32[0] )
v32 = 0xF4240u / v48.m128i_i32[0];
v44 = 0;
if ( !v3 )
_assert_fail("details != NULL", "client_thread.c", 0xA9u, "client_thread");
v4 = 0;
do
{
v4 += v3[33];
v3 = (_DWORD *)*((_QWORD *)v3 + 17);
}
while ( v3 );
if ( !v4 )
{
v6 = 0LL;
v8 = -1;
fprintf(stderr, "%s:%d Must have more than zero clients!\n", "client_thread.c", 178LL);
goto LABEL_21;
}
v5 = (int *)calloc(v4, 4uLL);
v6 = v5;
if ( !v5 )
{
v8 = -1;
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 192LL);
goto LABEL_21;
}
v7 = (char *)&v5[v4];
if ( v7 > (char *)v5 )
memset(v5, 255, 4LL * v4);
if ( (BYTE12(v46[0]) & 2) != 0 )
printf("Core %d: Started client thread\n", *a1);
if ( (unsigned int)func0((__int64)v46, a1, v6, &v44) )
{
v8 = -1;
free(0LL);
LABEL_16:
if ( v6 >= (int *)v7 )
goto LABEL_21;
goto LABEL_17;
}
if ( v44 != v4 )
{
v8 = -1;
fprintf(
stderr,
"%s:%d Requested number of clients does not match actual clients (%d != %d)\n",
"client_thread.c",
208LL,
v4,
v44);
ptr = 0LL;
goto LABEL_15;
}
n = LODWORD(size[1]);
v12 = malloc(LODWORD(size[1]));
ptr = v12;
if ( !v12 )
{
v3 = 0LL;
v8 = -1;
fprintf(stderr, "%s:%d malloc error\n", "client_thread.c", 215LL);
goto LABEL_15;
}
memset(v12, 65, n);
v8 = epoll_create(v4);
if ( v8 == -1 )
{
v29 = _errno_location();
v30 = strerror(*v29);
fprintf(stderr, "%s:%d epoll_create() error (%d) %s\n", "client_thread.c", 223LL, (unsigned int)*v29, v30);
goto LABEL_15;
}
v3 = calloc(v4, 0xCuLL);
if ( !v3 )
{
fprintf(stderr, "%s:%d calloc error\n", "client_thread.c", 229LL);
LABEL_15:
free(ptr);
goto LABEL_16;
}
v13 = v6;
if ( v7 <= (char *)v6 )
{
LABEL_34:
na = (size_t)v13;
threads_signal_parent(2LL, v50.m128i_u32[2]);
wait_for_nonzero(&go_mutex, &go_cond, &bGo);
nmemb = get_microseconds();
if ( !bRunning )
goto LABEL_15;
v18 = na;
v42 = v8;
nb = (size_t)v3;
v43 = ((unsigned __int64)((__int64)(v18 - (_QWORD)v6) >> 2) >> 2) + 1;
v41 = (char *)(v3 + 3);
while ( 1 )
{
v19 = (char *)nb;
v20 = epoll_wait_ign_signal(v42, nb, v4, 1000LL);
if ( v20 > 0 )
break;
LABEL_61:
if ( !bRunning )
{
v3 = (_DWORD *)nb;
v8 = v42;
v7 = (char *)&v6[v4];
goto LABEL_15;
}
}
v21 = &v41[12 * (v20 - 1)];
while ( 1 )
{
v22 = *((_DWORD *)v19 + 1);
if ( v22 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0x120u, "client_thread");
v23 = *(_DWORD *)v19;
if ( (*(_DWORD *)v19 & 0x18) != 0 )
{
close(v22);
goto LABEL_43;
}
if ( (v23 & 1) != 0 )
{
v24 = recv_ign_signal(v22, ptr, LODWORD(size[1]), 0LL);
if ( v24 == -1 )
{
v25 = _errno_location();
if ( *v25 != 104 )
{
v3 = (_DWORD *)nb;
v34 = v22;
nmemba = (unsigned int *)v25;
v8 = v42;
v31 = strerror(*v25);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "client_thread.c", 330LL, v34, *nmemba, v31);
v7 = (char *)&v6[v4];
goto LABEL_15;
}
LABEL_52:
if ( (BYTE12(v46[0]) & 2) != 0 )
printf(" Client: %d Removed client (%d/%d)\n", *v1, v43, v4);
close_ign_signal(v22);
if ( !--v4 )
{
v3 = (_DWORD *)nb;
v8 = v42;
free(ptr);
goto LABEL_21;
}
goto LABEL_43;
}
if ( v24 <= 0 )
goto LABEL_52;
v23 = *(_DWORD *)v19;
}
if ( (v23 & 4) != 0 )
{
if ( v32 )
{
if ( nmemb > get_microseconds() )
goto LABEL_43;
nmemb += v32;
}
if ( send_ign_signal(v22, ptr, LODWORD(size[1]), 0LL) == -1 )
{
v26 = _errno_location();
v27 = *v26;
if ( *v26 != 11 && v27 != 32 )
{
v3 = (_DWORD *)nb;
v33 = (unsigned int *)v26;
v8 = v42;
v28 = strerror(v27);
fprintf(stderr, "%s:%d send() error (%d) %s\n", "client_thread.c", 397LL, *v33, v28);
v7 = (char *)&v6[v4];
goto LABEL_15;
}
}
}
LABEL_43:
v19 += 12;
if ( v21 == v19 )
goto LABEL_61;
}
}
v14 = v6;
while ( 1 )
{
v15 = *v14;
HIDWORD(event.data.u64) = 0;
*(_QWORD *)&event.events = 0LL;
if ( v15 == -1 )
_assert_fail("s != INVALID_SOCKET", "client_thread.c", 0xF5u, "client_thread");
event.events = 5;
event.data.fd = v15;
if ( epoll_ctl(v8, 1, v15, &event) == -1 )
break;
if ( v7 <= (char *)++v14 )
{
v13 = v14;
v1 = a1;
goto LABEL_34;
}
}
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(ptr);
LABEL_17:
v9 = (unsigned int *)v6;
do
{
v10 = *v9;
if ( *v9 != -1 )
{
shutdown(v10, 2);
close_ign_signal(v10);
}
++v9;
}
while ( v7 > (char *)v9 );
LABEL_21:
close_ign_signal(v8);
free(v3);
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" );
}