decompiled_code:
size_t print_usage()
{
print_version();
fwrite("Usage: threadnetperf [options] tests\n", 1uLL, 0x25uLL, stderr);
fwrite("Usage: threadnetperf -D [options]\n", 1uLL, 0x22uLL, stderr);
fwrite("Runs a threaded network test\n", 1uLL, 0x1DuLL, stderr);
fputc(10, stderr);
fwrite("\t-c level,interval Confidence level, must be 95 or 99\n", 1uLL, 0x38uLL, stderr);
fwrite("\t-D Use daemon mode (wait for incoming tests)\n", 1uLL, 0x36uLL, stderr);
fwrite("\t-d time Set duration to run the test for\n", 1uLL, 0x2DuLL, stderr);
fwrite("\t-e Eat the data (i.e. dirty it)\n", 1uLL, 0x29uLL, stderr);
fwrite("\t-H host Set the remote host(and port) to connect to\n", 1uLL, 0x38uLL, stderr);
fwrite("\t-h Display this help\n", 1uLL, 0x1EuLL, stderr);
fwrite("\t-i min,max Set the minimum and maximum iterations\n", 1uLL, 0x33uLL, stderr);
fwrite("\t-m [t,p] What programming model to use, [thread or process]\n", 1uLL, 0x3FuLL, stderr);
fwrite("\t-n Disable Nagle's algorithm (e.g no delay)\n", 1uLL, 0x35uLL, stderr);
fwrite("\t-p port Set the port number for the first server thread to use\n", 1uLL, 0x43uLL, stderr);
fwrite(
"\t-q Quiet mode. Don't send any data, just receive, useful when used with pktgen.\n",
1uLL,
0x59uLL,
stderr);
fwrite("\t-s size Set the send/recv size\n", 1uLL, 0x23uLL, stderr);
fwrite("\t-T Timestamp packets, and measure latency (only available on *nix)\n", 1uLL, 0x4CuLL, stderr);
fwrite("\t-t Use TCP\n", 1uLL, 0x14uLL, stderr);
fwrite("\t-R Reverse mode (send from the server instead of from the client\n", 1uLL, 0x4AuLL, stderr);
fwrite("\t-r Packets per second rate (default: ~0)\n", 1uLL, 0x32uLL, stderr);
fwrite("\t-u Use UDP\n", 1uLL, 0x14uLL, stderr);
fwrite("\t-V Display version only\n", 1uLL, 0x21uLL, stderr);
fwrite("\t-v Verbose\n", 1uLL, 0x14uLL, stderr);
fputc(10, stderr);
fwrite("\ttests Combination of cores and clients\n", 1uLL, 0x2DuLL, stderr);
fwrite(
"\ttests Core numbers are masks, for example 1 is core 0, 3 is core 0 and core 1\n",
1uLL,
0x54uLL,
stderr);
fwrite("\t\tN{c-s} N connections\n", 1uLL, 0x19uLL, stderr);
fwrite("\t\t c client cores mask\n", 1uLL, 0x1FuLL, stderr);
fwrite("\t\t s server cores mask\n", 1uLL, 0x1FuLL, stderr);
fputc(10, stderr);
fwrite("Examples:\n", 1uLL, 0xAuLL, stderr);
fwrite("\t> threadnetperf -n -s 10000 1{1-1}\n", 1uLL, 0x24uLL, stderr);
fwrite("\tDisable Nagle's, send size of 10000 with 1 connection from core 0 to core 0\n", 1uLL, 0x4DuLL, stderr);
fputc(10, stderr);
fwrite("\t> threadnetperf 10{1-1} 10{2-2} 10{4-4}\n", 1uLL, 0x29uLL, stderr);
return fwrite(
"\t10 connection from core 0 to core 0, 10 connections from core 1 to core 1, and 10 connections from core 2 to core 2\n",
1uLL,
0x75uLL,
stderr);
}

canonical_decompiled_code:
size_t func2()
{
func1();
fwrite("Usage: threadnetperf [options] tests\n", 1uLL, 0x25uLL, stderr);
fwrite("Usage: threadnetperf -D [options]\n", 1uLL, 0x22uLL, stderr);
fwrite("Runs a threaded network test\n", 1uLL, 0x1DuLL, stderr);
fputc(10, stderr);
fwrite("\t-c level,interval Confidence level, must be 95 or 99\n", 1uLL, 0x38uLL, stderr);
fwrite("\t-D Use daemon mode (wait for incoming tests)\n", 1uLL, 0x36uLL, stderr);
fwrite("\t-d time Set duration to run the test for\n", 1uLL, 0x2DuLL, stderr);
fwrite("\t-e Eat the data (i.e. dirty it)\n", 1uLL, 0x29uLL, stderr);
fwrite("\t-H host Set the remote host(and port) to connect to\n", 1uLL, 0x38uLL, stderr);
fwrite("\t-h Display this help\n", 1uLL, 0x1EuLL, stderr);
fwrite("\t-i min,max Set the minimum and maximum iterations\n", 1uLL, 0x33uLL, stderr);
fwrite("\t-m [t,p] What programming model to use, [thread or process]\n", 1uLL, 0x3FuLL, stderr);
fwrite("\t-n Disable Nagle's algorithm (e.g no delay)\n", 1uLL, 0x35uLL, stderr);
fwrite("\t-p port Set the port number for the first server thread to use\n", 1uLL, 0x43uLL, stderr);
fwrite(
"\t-q Quiet mode. Don't send any data, just receive, useful when used with pktgen.\n",
1uLL,
0x59uLL,
stderr);
fwrite("\t-s size Set the send/recv size\n", 1uLL, 0x23uLL, stderr);
fwrite("\t-T Timestamp packets, and measure latency (only available on *nix)\n", 1uLL, 0x4CuLL, stderr);
fwrite("\t-t Use TCP\n", 1uLL, 0x14uLL, stderr);
fwrite("\t-R Reverse mode (send from the server instead of from the client\n", 1uLL, 0x4AuLL, stderr);
fwrite("\t-r Packets per second rate (default: ~0)\n", 1uLL, 0x32uLL, stderr);
fwrite("\t-u Use UDP\n", 1uLL, 0x14uLL, stderr);
fwrite("\t-V Display version only\n", 1uLL, 0x21uLL, stderr);
fwrite("\t-v Verbose\n", 1uLL, 0x14uLL, stderr);
fputc(10, stderr);
fwrite("\ttests Combination of cores and clients\n", 1uLL, 0x2DuLL, stderr);
fwrite(
"\ttests Core numbers are masks, for example 1 is core 0, 3 is core 0 and core 1\n",
1uLL,
0x54uLL,
stderr);
fwrite("\t\tN{c-s} N connections\n", 1uLL, 0x19uLL, stderr);
fwrite("\t\t c client cores mask\n", 1uLL, 0x1FuLL, stderr);
fwrite("\t\t s server cores mask\n", 1uLL, 0x1FuLL, stderr);
fputc(10, stderr);
fwrite("Examples:\n", 1uLL, 0xAuLL, stderr);
fwrite("\t> threadnetperf -n -s 10000 1{1-1}\n", 1uLL, 0x24uLL, stderr);
fwrite("\tDisable Nagle's, send size of 10000 with 1 connection from core 0 to core 0\n", 1uLL, 0x4DuLL, stderr);
fputc(10, stderr);
fwrite("\t> threadnetperf 10{1-1} 10{2-2} 10{4-4}\n", 1uLL, 0x29uLL, stderr);
return fwrite(
"\t10 connection from core 0 to core 0, 10 connections from core 1 to core 1, and 10 connections from core 2 to core 2\n",
1uLL,
0x75uLL,
stderr);
}

original_code:
void print_usage() {
 print_version();
 fprintf(stderr, "Usage: threadnetperf [options] tests\n" );
 fprintf(stderr, "Usage: threadnetperf -D [options]\n" );
 fprintf(stderr, "Runs a threaded network test\n" );
 fprintf(stderr, "\n" );
 fprintf(stderr, "	-c level,interval   Confidence level, must be 95 or 99\n");
 fprintf(stderr, "	-D         Use daemon mode (wait for incoming tests)\n" );
 fprintf(stderr, "	-d time    Set duration to run the test for\n" );
 fprintf(stderr, "	-e         Eat the data (i.e. dirty it)\n");
 fprintf(stderr, "	-H host    Set the remote host(and port) to connect to\n");
 fprintf(stderr, "	-h         Display this help\n");
 fprintf(stderr, "	-i min,max Set the minimum and maximum iterations\n");
 fprintf(stderr, "	-m [t,p]   What programming model to use, [thread or process]\n" );
 fprintf(stderr, "	-n         Disable Nagle's algorithm (e.g no delay)\n" );
 fprintf(stderr, "	-p port    Set the port number for the first server thread to use\n" );
 fprintf(stderr, "	-q         Quiet mode. Don't send any data, just receive, useful when used with pktgen.\n" );
 fprintf(stderr, "	-s size    Set the send/recv size\n" );
 fprintf(stderr, "	-T         Timestamp packets, and measure latency (only available on *nix)\n" );
 fprintf(stderr, "	-t         Use TCP\n" );
 fprintf(stderr, "	-R         Reverse mode (send from the server instead of from the client\n" );
 fprintf(stderr, "	-r         Packets per second rate (default: ~0)\n" );
 fprintf(stderr, "	-u         Use UDP\n" );
 fprintf(stderr, "	-V         Display version only\n" );
 fprintf(stderr, "	-v         Verbose\n" );
 fprintf(stderr, "\n" );
 fprintf(stderr, "	tests      Combination of cores and clients\n" );
 fprintf(stderr, "	tests      Core numbers are masks, for example 1 is core 0, 3 is core 0 and core 1\n" );
 fprintf(stderr, "		N{c-s}   N connections\n" );
 fprintf(stderr, "		         c client cores mask\n" );
 fprintf(stderr, "		         s server cores mask\n" );
 fprintf(stderr, "\n" );
 fprintf(stderr, "Examples:\n" );
 fprintf(stderr, "	> threadnetperf -n -s 10000 1{1-1}\n" );
 fprintf(stderr, "	Disable Nagle's, send size of 10000 with 1 connection from core 0 to core 0\n" );
 fprintf(stderr, "\n" );
 fprintf(stderr, "	> threadnetperf 10{1-1} 10{2-2} 10{4-4}\n" );
 fprintf(stderr, "	10 connection from core 0 to core 0, 10 connections from core 1 to core 1, and 10 connections from core 2 to core 2\n" );
}


repo: bramp/threadnetperf

original_code:
int parse_test( const struct settings *settings, const char *arg, struct test * test ) {
 char hostname[1025 + 32 + 1] = {0};
 ((void) sizeof ((arg != ((void *)0)) ? 1 : 0), __extension__ ({ if (arg != ((void *)0)) ; else __assert_fail ("arg != NULL", "parse.c", 73, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((test != ((void *)0)) ? 1 : 0), __extension__ ({ if (test != ((void *)0)) ; else __assert_fail ("test != NULL", "parse.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 if ( sscanf( arg, "%u(%u-%u:%1000s)", &test->connections, &test->clientcores, &test->servercores, hostname ) == 4 ) {
  char *c = strchr(hostname, ')');
  if ( c != ((void *)0) )
   *c = '\0';
  goto good;
 }
 if ( sscanf( arg, "%u{%u-%u:%1000s}", &test->connections, &test->clientcores, &test->servercores, hostname ) == 4 ) {
  char *c = strchr(hostname, '}');
  if ( c != ((void *)0) )
   *c = '\0';
  goto good;
 }
 if ( settings->server_host != ((void *)0) )
  strncpy(hostname, settings->server_host, sizeof(hostname));
 if ( sscanf( arg, "%u(%u-%u)", &test->connections, &test->clientcores, &test->servercores ) == 3 ) {
  goto good;
 }
 if ( sscanf( arg, "%u{%u-%u}", &test->connections, &test->clientcores, &test->servercores ) == 3 ) {
  goto good;
 }
 return -1;
good:
 if ( hostname[0] == '\0' ) {
  strcpy(hostname, "127.0.0.1");
 }
 memset( &test->addr, 0, sizeof(test->addr) );
 test->addr_len = sizeof(struct sockaddr_in);
 if ( str_to_addr( hostname, (struct sockaddr *) &test->addr, &test->addr_len ) ) {
  fprintf(stderr, "Invalid host name (%s)\n", hostname );
  return -1;
 }
 ((struct sockaddr_in *)&test->addr)->sin_port = htons( settings->port + test->servercores );
 return 0;
}

canonical_original_code:
int parse_test(struct settings *settings, char *arg, struct test *test) {
 char hostname[-1] = {0};
 ((void) sizeof ((arg != ((void *)0)) ? 1 : 0), __extension__ ({ if (arg != ((void *)0)) ; else __assert_fail ("arg != NULL", "parse.c", 73, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((test != ((void *)0)) ? 1 : 0), __extension__ ({ if (test != ((void *)0)) ; else __assert_fail ("test != NULL", "parse.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 if ( sscanf( arg, "%u(%u-%u:%1000s)", &test->connections, &test->clientcores, &test->servercores, hostname ) == 4 ) {
  char *c = strchr(hostname, ')');
  if ( c != ((void *)0) )
   *c = '\0';
  goto good;
 }
 if ( sscanf( arg, "%u{%u-%u:%1000s}", &test->connections, &test->clientcores, &test->servercores, hostname ) == 4 ) {
  char *c = strchr(hostname, '}');
  if ( c != ((void *)0) )
   *c = '\0';
  goto good;
 }
 if ( settings->server_host != ((void *)0) )
  strncpy(hostname, settings->server_host, sizeof(hostname));
 if ( sscanf( arg, "%u(%u-%u)", &test->connections, &test->clientcores, &test->servercores ) == 3 ) {
  goto good;
 }
 if ( sscanf( arg, "%u{%u-%u}", &test->connections, &test->clientcores, &test->servercores ) == 3 ) {
  goto good;
 }
 return -1;
good:
 if ( hostname[0] == '\0' ) {
  strcpy(hostname, "127.0.0.1");
 }
 memset( &test->addr, 0, sizeof(test->addr) );
 test->addr_len = sizeof(struct sockaddr_in);
 if ( str_to_addr( hostname, (struct sockaddr *) &test->addr, &test->addr_len ) ) {
  fprintf(stderr, "Invalid host name (%s)\n", hostname );
  return -1;
 }
 ((struct sockaddr_in *)&test->addr)->sin_port = htons( settings->port + test->servercores );
 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; } *

variable_types:
arg
char *

variable_types:
test
struct test *

variable_types:
hostname
char [-1]

variable_types:
c
char *

return_type: int

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

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 sockaddr { unsigned short sa_family; char sa_data[14]; }

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 parse_settings(int argc, char **argv, __int64 a3)
{
unsigned int v5; // er12
const char *v7; // rdx
unsigned int v8; // eax
int v9; // eax
int v10; // eax
char v11; // al
char v12; // dl
int v13; // eax
__int16 v14; // ax
char v15; // al
char v16; // al
char v17; // al
int v18; // edx
int v19; // eax
bool v20; // cl
char v21; // al
int v22; // eax
char v23; // al
unsigned int v24; // er12
int v25; // edx
unsigned int v26; // eax
int v27; // esi
char *v28; // rax
__int64 v29; // rdx
char *v30; // r14
__int64 v31; // rdx
int v32; // eax
__int64 v33; // rsi
__int64 v34; // rdi
char *v35; // [rsp+8h] [rbp-D0h]
char *v36; // [rsp+8h] [rbp-D0h]
char *v37; // [rsp+8h] [rbp-D0h]
char *v38; // [rsp+8h] [rbp-D0h]
double v39; // [rsp+18h] [rbp-C0h] BYREF
double v40[23]; // [rsp+20h] [rbp-B8h] BYREF

if ( !a3 )
_assert_fail("settings != NULL", "parse.c", 0x83u, "parse_settings");
*(_BYTE *)(a3 + 12) &= 0x80u;
*(_WORD *)(a3 + 64) = 1234;
*(_QWORD *)(a3 + 32) = 0x100000001LL;
*(_QWORD *)(a3 + 40) = 0xFFFFFFFF00000400LL;
*(_QWORD *)(a3 + 56) = 0LL;
*(_QWORD *)(a3 + 16) = 0LL;
*(_QWORD *)(a3 + 24) = 0LL;
*(_DWORD *)(a3 + 48) = -1;
*(_DWORD *)(a3 + 88) = 0;
*(_QWORD *)a3 = 0x10000000ALL;
*(_DWORD *)(a3 + 8) = 6;
*(_QWORD *)(a3 + 72) = 0LL;
*(_DWORD *)(a3 + 68) = 0;
if ( argc == 1 )
{
LABEL_15:
v5 = -1;
print_usage();
}
else
{
while ( 1 )
{
v5 = getopt(argc, argv, "DhvVtTReunqs:d:p:c:i:H:r:m:");
if ( v5 == -1 )
break;
if ( v5 == 86 )
{
v5 = -1;
print_version();
return v5;
}
if ( (int)v5 > 86 )
{
if ( v5 == 104 )
goto LABEL_15;
if ( v5 == 118 )
*(_BYTE *)(a3 + 12) |= 2u;
}
else
{
switch ( v5 )
{
case '?':
v7 = argv[optind - 1];
LABEL_17:
v5 = -1;
fprintf(stderr, "Unknown argument (%s)\n", v7);
return v5;
case 'D':
*(_BYTE *)(a3 + 12) |= 1u;
break;
case ':':
v5 = -1;
fprintf(stderr, "Missing argument for (%s)\n", argv[optind - 1]);
return v5;
}
}
}
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 && optind < argc )
{
fwrite("Tests can not be specified on the command line in daemon mode\n", 1uLL, 0x3EuLL, stderr);
return v5;
}
optind = 1;
while ( 1 )
{
v8 = getopt(argc, argv, "DhvVtTReunqs:d:p:c:i:H:r:m:");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'D':
case 'V':
case 'h':
case 'v':
continue;
case 'H':
LODWORD(v39) = 128;
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set remote host when in daemon mode\n", 1uLL, 0x2EuLL, stdout);
return v5;
}
if ( (unsigned int)str_to_addr(optarg, v40, &v39) )
{
fprintf(stderr, "Invalid host name (%s)\n", optarg);
return v5;
}
*(_QWORD *)(a3 + 56) = optarg;
continue;
case 'R':
v17 = *(_BYTE *)(a3 + 12);
if ( (v17 & 1) != 0 )
{
fwrite("Unable to set reverse mode when in daemon mode\n", 1uLL, 0x2FuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v17 | 0x20;
continue;
case 'T':
v21 = *(_BYTE *)(a3 + 12);
if ( (v21 & 1) != 0 )
{
fwrite("Unable to set timestamps when in daemon mode\n", 1uLL, 0x2DuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v21 | 8;
continue;
case 'c':
v39 = *(double *)&LC48;
v40[0] = *(double *)&LC49;
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set confidence interval when in daemon mode\n", 1uLL, 0x36uLL, stdout);
return v5;
}
if ( sscanf(optarg, "%lf,%lf", &v39, v40) <= 1 )
fprintf(stdout, "%lf%% Confidence interval defaulted to %lf percent\n", v39, v40[0]);
v12 = 1;
if ( v39 != 99.5 && v39 != 99.0 && v39 != 97.5 && v39 != 95.0 && v39 != 90.0 && v39 != 75.0 )
{
if ( v39 == 99.95 )
v12 = 0;
if ( v12 )
{
fprintf(stderr, "Confidence Level must be {75, 90, 95, 97.5, 99, 99.5, 99.95}. Given (%s)\n", optarg);
return v5;
}
}
*(double *)(a3 + 16) = v39;
*(double *)(a3 + 24) = v40[0];
continue;
case 'd':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set duration when in daemon mode\n", 1uLL, 0x2BuLL, stdout);
return v5;
}
v38 = optarg;
v22 = atoi(optarg);
*(_DWORD *)a3 = v22;
if ( v22 )
continue;
fprintf(stderr, "Invalid duration given (%s)\n", v38);
return v5;
case 'e':
v15 = *(_BYTE *)(a3 + 12);
if ( (v15 & 1) != 0 )
{
fwrite("Unable to eat the data when in daemon mode\n", 1uLL, 0x2BuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v15 | 4;
continue;
case 'i':
LODWORD(v39) = 0;
LODWORD(v40[0]) = 0;
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set iterations when in daemon mode\n", 1uLL, 0x2DuLL, stdout);
return v5;
}
if ( sscanf(optarg, "%u,%u", &v39, v40) <= 1 && sscanf(optarg, "%u", v40) == 1 )
{
v18 = LODWORD(v40[0]);
v20 = 0;
LODWORD(v39) = LODWORD(v40[0]);
v19 = LODWORD(v40[0]);
}
else
{
v18 = LODWORD(v39);
v19 = LODWORD(v40[0]);
v20 = LODWORD(v39) > LODWORD(v40[0]);
}
if ( !v19 || v20 )
{
fprintf(stderr, "Invalid min/max iterations(%s)\n", optarg);
return v5;
}
*(_DWORD *)(a3 + 32) = v18;
*(_DWORD *)(a3 + 36) = v19;
continue;
case 'm':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set threading model when in daemon mode\n", 1uLL, 0x32uLL, stdout);
return v5;
}
v9 = (unsigned __int8)*optarg;
if ( v9 != 112 || optarg[1] )
{
if ( v9 != 116 || optarg[1] )
{
fprintf(stderr, "Invalid threading model set to (%s)\n", optarg);
return v5;
}
*(_DWORD *)(a3 + 88) = 0;
}
else
{
*(_DWORD *)(a3 + 88) = 1;
}
break;
case 'n':
v16 = *(_BYTE *)(a3 + 12);
if ( (v16 & 1) != 0 )
{
fwrite("Unable to disable Nagles when in daemon mode\n", 1uLL, 0x2DuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v16 | 0x10;
continue;
case 'p':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set port when in daemon mode\n", 1uLL, 0x27uLL, stdout);
return v5;
}
v37 = optarg;
v14 = atoi(optarg);
*(_WORD *)(a3 + 64) = v14;
if ( v14 )
continue;
fprintf(stderr, "Invalid port number given (%s)\n", v37);
return v5;
case 'q':
v11 = *(_BYTE *)(a3 + 12);
if ( (v11 & 1) != 0 )
{
fwrite("Unable to set quiet when in daemon mode\n", 1uLL, 0x28uLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v11 | 0x40;
continue;
case 'r':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set send rate when in daemon mode\n", 1uLL, 0x2CuLL, stdout);
return v5;
}
v35 = optarg;
v10 = atoi(optarg);
*(_DWORD *)(a3 + 48) = v10;
if ( v10 )
continue;
fprintf(stderr, "Invalid send rate given (%s)\n", v35);
return v5;
case 's':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set message size when in daemon mode\n", 1uLL, 0x2FuLL, stdout);
return v5;
}
v36 = optarg;
v13 = atoi(optarg);
*(_DWORD *)(a3 + 40) = v13;
if ( v13 )
continue;
fprintf(stderr, "Invalid message size given (%s)\n", v36);
return v5;
case 't':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set TCP when in daemon mode\n", 1uLL, 0x26uLL, stdout);
return v5;
}
*(_QWORD *)(a3 + 4) = 0x600000001LL;
continue;
case 'u':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set UDP when in daemon mode\n", 1uLL, 0x26uLL, stdout);
return v5;
}
*(_QWORD *)(a3 + 4) = 0x1100000002LL;
continue;
default:
fprintf(stderr, "Argument not implemented (yet) (%c)\n", v8);
return v5;
}
}
v23 = *(_BYTE *)(a3 + 12);
if ( (v23 & 0x10) != 0 && *(_DWORD *)(a3 + 8) != 6 )
{
v5 = -1;
fwrite("Must use TCP when disabling Nagles\n", 1uLL, 0x23uLL, stderr);
}
else if ( argc <= optind )
{
v27 = *(_DWORD *)(a3 + 68);
LABEL_93:
if ( v27 || (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
v5 = 0;
v32 = count_client_cores(*(_QWORD *)(a3 + 72));
v33 = *(unsigned int *)(a3 + 68);
v34 = *(_QWORD *)(a3 + 72);
*(_DWORD *)(a3 + 80) = v32;
*(_DWORD *)(a3 + 84) = count_server_cores(v34, v33);
}
else
{
v5 = -1;
fwrite("No tests were specified\n", 1uLL, 0x18uLL, stderr);
}
}
else
{
v24 = max_cores;
while ( 1 )
{
if ( (v23 & 1) != 0 )
_assert_fail("!settings->daemon", "parse.c", 0x1D0u, "parse_settings");
v28 = (char *)realloc(*(void **)(a3 + 72), 152LL * (unsigned int)(*(_DWORD *)(a3 + 68) + 1));
v29 = *(unsigned int *)(a3 + 68);
*(_QWORD *)(a3 + 72) = v28;
v30 = &v28[152 * v29];
if ( (unsigned int)parse_test(a3, argv[optind], (__int64)v30) )
{
v7 = argv[optind];
goto LABEL_17;
}
v25 = optind;
if ( !*(_DWORD *)v30 || (v26 = *((_DWORD *)v30 + 1)) == 0 )
{
v5 = -1;
fprintf(stderr, "Cores of zero will not run on any core (%s)\n", argv[optind]);
return v5;
}
if ( (*(_DWORD *)v30 | v26) >> v24 )
break;
v27 = *(_DWORD *)(a3 + 68) + 1;
*(_DWORD *)(a3 + 68) = v27;
optind = v25 + 1;
if ( v25 + 1 >= argc )
goto LABEL_93;
v23 = *(_BYTE *)(a3 + 12);
}
v31 = v24;
v5 = -1;
fprintf(stderr, "Cores must not be greater than %d (%s)\n", v31, argv[optind]);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int argc, char **argv, __int64 a3)
{
unsigned int v5; // er12
const char *v7; // rdx
unsigned int v8; // eax
int v9; // eax
int v10; // eax
char v11; // al
char v12; // dl
int v13; // eax
__int16 v14; // ax
char v15; // al
char v16; // al
char v17; // al
int v18; // edx
int v19; // eax
bool v20; // cl
char v21; // al
int v22; // eax
char v23; // al
unsigned int v24; // er12
int v25; // edx
unsigned int v26; // eax
int v27; // esi
char *v28; // rax
__int64 v29; // rdx
char *v30; // r14
__int64 v31; // rdx
int v32; // eax
__int64 v33; // rsi
__int64 v34; // rdi
char *v35; // [rsp+8h] [rbp-D0h]
char *v36; // [rsp+8h] [rbp-D0h]
char *v37; // [rsp+8h] [rbp-D0h]
char *v38; // [rsp+8h] [rbp-D0h]
double v39; // [rsp+18h] [rbp-C0h] BYREF
double v40[23]; // [rsp+20h] [rbp-B8h] BYREF

if ( !a3 )
_assert_fail("settings != NULL", "parse.c", 0x83u, "parse_settings");
*(_BYTE *)(a3 + 12) &= 0x80u;
*(_WORD *)(a3 + 64) = 1234;
*(_QWORD *)(a3 + 32) = 0x100000001LL;
*(_QWORD *)(a3 + 40) = 0xFFFFFFFF00000400LL;
*(_QWORD *)(a3 + 56) = 0LL;
*(_QWORD *)(a3 + 16) = 0LL;
*(_QWORD *)(a3 + 24) = 0LL;
*(_DWORD *)(a3 + 48) = -1;
*(_DWORD *)(a3 + 88) = 0;
*(_QWORD *)a3 = 0x10000000ALL;
*(_DWORD *)(a3 + 8) = 6;
*(_QWORD *)(a3 + 72) = 0LL;
*(_DWORD *)(a3 + 68) = 0;
if ( argc == 1 )
{
LABEL_15:
v5 = -1;
func2();
}
else
{
while ( 1 )
{
v5 = getopt(argc, argv, "DhvVtTReunqs:d:p:c:i:H:r:m:");
if ( v5 == -1 )
break;
if ( v5 == 86 )
{
v5 = -1;
func1();
return v5;
}
if ( (int)v5 > 86 )
{
if ( v5 == 104 )
goto LABEL_15;
if ( v5 == 118 )
*(_BYTE *)(a3 + 12) |= 2u;
}
else
{
switch ( v5 )
{
case '?':
v7 = argv[optind - 1];
LABEL_17:
v5 = -1;
fprintf(stderr, "Unknown argument (%s)\n", v7);
return v5;
case 'D':
*(_BYTE *)(a3 + 12) |= 1u;
break;
case ':':
v5 = -1;
fprintf(stderr, "Missing argument for (%s)\n", argv[optind - 1]);
return v5;
}
}
}
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 && optind < argc )
{
fwrite("Tests can not be specified on the command line in daemon mode\n", 1uLL, 0x3EuLL, stderr);
return v5;
}
optind = 1;
while ( 1 )
{
v8 = getopt(argc, argv, "DhvVtTReunqs:d:p:c:i:H:r:m:");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'D':
case 'V':
case 'h':
case 'v':
continue;
case 'H':
LODWORD(v39) = 128;
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set remote host when in daemon mode\n", 1uLL, 0x2EuLL, stdout);
return v5;
}
if ( (unsigned int)str_to_addr(optarg, v40, &v39) )
{
fprintf(stderr, "Invalid host name (%s)\n", optarg);
return v5;
}
*(_QWORD *)(a3 + 56) = optarg;
continue;
case 'R':
v17 = *(_BYTE *)(a3 + 12);
if ( (v17 & 1) != 0 )
{
fwrite("Unable to set reverse mode when in daemon mode\n", 1uLL, 0x2FuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v17 | 0x20;
continue;
case 'T':
v21 = *(_BYTE *)(a3 + 12);
if ( (v21 & 1) != 0 )
{
fwrite("Unable to set timestamps when in daemon mode\n", 1uLL, 0x2DuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v21 | 8;
continue;
case 'c':
v39 = *(double *)&LC48;
v40[0] = *(double *)&LC49;
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set confidence interval when in daemon mode\n", 1uLL, 0x36uLL, stdout);
return v5;
}
if ( sscanf(optarg, "%lf,%lf", &v39, v40) <= 1 )
fprintf(stdout, "%lf%% Confidence interval defaulted to %lf percent\n", v39, v40[0]);
v12 = 1;
if ( v39 != 99.5 && v39 != 99.0 && v39 != 97.5 && v39 != 95.0 && v39 != 90.0 && v39 != 75.0 )
{
if ( v39 == 99.95 )
v12 = 0;
if ( v12 )
{
fprintf(stderr, "Confidence Level must be {75, 90, 95, 97.5, 99, 99.5, 99.95}. Given (%s)\n", optarg);
return v5;
}
}
*(double *)(a3 + 16) = v39;
*(double *)(a3 + 24) = v40[0];
continue;
case 'd':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set duration when in daemon mode\n", 1uLL, 0x2BuLL, stdout);
return v5;
}
v38 = optarg;
v22 = atoi(optarg);
*(_DWORD *)a3 = v22;
if ( v22 )
continue;
fprintf(stderr, "Invalid duration given (%s)\n", v38);
return v5;
case 'e':
v15 = *(_BYTE *)(a3 + 12);
if ( (v15 & 1) != 0 )
{
fwrite("Unable to eat the data when in daemon mode\n", 1uLL, 0x2BuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v15 | 4;
continue;
case 'i':
LODWORD(v39) = 0;
LODWORD(v40[0]) = 0;
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set iterations when in daemon mode\n", 1uLL, 0x2DuLL, stdout);
return v5;
}
if ( sscanf(optarg, "%u,%u", &v39, v40) <= 1 && sscanf(optarg, "%u", v40) == 1 )
{
v18 = LODWORD(v40[0]);
v20 = 0;
LODWORD(v39) = LODWORD(v40[0]);
v19 = LODWORD(v40[0]);
}
else
{
v18 = LODWORD(v39);
v19 = LODWORD(v40[0]);
v20 = LODWORD(v39) > LODWORD(v40[0]);
}
if ( !v19 || v20 )
{
fprintf(stderr, "Invalid min/max iterations(%s)\n", optarg);
return v5;
}
*(_DWORD *)(a3 + 32) = v18;
*(_DWORD *)(a3 + 36) = v19;
continue;
case 'm':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set threading model when in daemon mode\n", 1uLL, 0x32uLL, stdout);
return v5;
}
v9 = (unsigned __int8)*optarg;
if ( v9 != 112 || optarg[1] )
{
if ( v9 != 116 || optarg[1] )
{
fprintf(stderr, "Invalid threading model set to (%s)\n", optarg);
return v5;
}
*(_DWORD *)(a3 + 88) = 0;
}
else
{
*(_DWORD *)(a3 + 88) = 1;
}
break;
case 'n':
v16 = *(_BYTE *)(a3 + 12);
if ( (v16 & 1) != 0 )
{
fwrite("Unable to disable Nagles when in daemon mode\n", 1uLL, 0x2DuLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v16 | 0x10;
continue;
case 'p':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set port when in daemon mode\n", 1uLL, 0x27uLL, stdout);
return v5;
}
v37 = optarg;
v14 = atoi(optarg);
*(_WORD *)(a3 + 64) = v14;
if ( v14 )
continue;
fprintf(stderr, "Invalid port number given (%s)\n", v37);
return v5;
case 'q':
v11 = *(_BYTE *)(a3 + 12);
if ( (v11 & 1) != 0 )
{
fwrite("Unable to set quiet when in daemon mode\n", 1uLL, 0x28uLL, stdout);
return v5;
}
*(_BYTE *)(a3 + 12) = v11 | 0x40;
continue;
case 'r':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set send rate when in daemon mode\n", 1uLL, 0x2CuLL, stdout);
return v5;
}
v35 = optarg;
v10 = atoi(optarg);
*(_DWORD *)(a3 + 48) = v10;
if ( v10 )
continue;
fprintf(stderr, "Invalid send rate given (%s)\n", v35);
return v5;
case 's':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set message size when in daemon mode\n", 1uLL, 0x2FuLL, stdout);
return v5;
}
v36 = optarg;
v13 = atoi(optarg);
*(_DWORD *)(a3 + 40) = v13;
if ( v13 )
continue;
fprintf(stderr, "Invalid message size given (%s)\n", v36);
return v5;
case 't':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set TCP when in daemon mode\n", 1uLL, 0x26uLL, stdout);
return v5;
}
*(_QWORD *)(a3 + 4) = 0x600000001LL;
continue;
case 'u':
if ( (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
fwrite("Unable to set UDP when in daemon mode\n", 1uLL, 0x26uLL, stdout);
return v5;
}
*(_QWORD *)(a3 + 4) = 0x1100000002LL;
continue;
default:
fprintf(stderr, "Argument not implemented (yet) (%c)\n", v8);
return v5;
}
}
v23 = *(_BYTE *)(a3 + 12);
if ( (v23 & 0x10) != 0 && *(_DWORD *)(a3 + 8) != 6 )
{
v5 = -1;
fwrite("Must use TCP when disabling Nagles\n", 1uLL, 0x23uLL, stderr);
}
else if ( argc <= optind )
{
v27 = *(_DWORD *)(a3 + 68);
LABEL_93:
if ( v27 || (*(_BYTE *)(a3 + 12) & 1) != 0 )
{
v5 = 0;
v32 = count_client_cores(*(_QWORD *)(a3 + 72));
v33 = *(unsigned int *)(a3 + 68);
v34 = *(_QWORD *)(a3 + 72);
*(_DWORD *)(a3 + 80) = v32;
*(_DWORD *)(a3 + 84) = count_server_cores(v34, v33);
}
else
{
v5 = -1;
fwrite("No tests were specified\n", 1uLL, 0x18uLL, stderr);
}
}
else
{
v24 = max_cores;
while ( 1 )
{
if ( (v23 & 1) != 0 )
_assert_fail("!settings->daemon", "parse.c", 0x1D0u, "parse_settings");
v28 = (char *)realloc(*(void **)(a3 + 72), 152LL * (unsigned int)(*(_DWORD *)(a3 + 68) + 1));
v29 = *(unsigned int *)(a3 + 68);
*(_QWORD *)(a3 + 72) = v28;
v30 = &v28[152 * v29];
if ( (unsigned int)func3(a3, argv[optind], (__int64)v30) )
{
v7 = argv[optind];
goto LABEL_17;
}
v25 = optind;
if ( !*(_DWORD *)v30 || (v26 = *((_DWORD *)v30 + 1)) == 0 )
{
v5 = -1;
fprintf(stderr, "Cores of zero will not run on any core (%s)\n", argv[optind]);
return v5;
}
if ( (*(_DWORD *)v30 | v26) >> v24 )
break;
v27 = *(_DWORD *)(a3 + 68) + 1;
*(_DWORD *)(a3 + 68) = v27;
optind = v25 + 1;
if ( v25 + 1 >= argc )
goto LABEL_93;
v23 = *(_BYTE *)(a3 + 12);
}
v31 = v24;
v5 = -1;
fprintf(stderr, "Cores must not be greater than %d (%s)\n", v31, argv[optind]);
}
}
return v5;
}

original_code:
int parse_settings( int argc, char *argv[], struct settings *settings ) {
 int c;
 const char *optstring = "DhvVtTReunqs:d:p:c:i:H:r:m:";
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "parse.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 settings->daemon = 0;
 settings->message_size = 1024;
 settings->socket_size = ~0;
 settings->rate = ~0;
 settings->disable_nagles = 0;
 settings->duration = 10;
 settings->server_host = ((void *)0);
 settings->port = 1234;
 settings->verbose = 0;
 settings->dirty = 0;
 settings->timestamp = 0;
 settings->confidence_lvl = 0.0;
 settings->confidence_int = 0.0;
 settings->min_iterations = 1;
 settings->max_iterations = 1;
 settings->threaded_model = 0;
 settings->reverse = 0;
 settings->quiet = 0;
 settings->type = SOCK_STREAM;
 settings->protocol = IPPROTO_TCP;
 settings->test = ((void *)0);
 settings->tests = 0;
 if ( argc == 1 ) {
  print_usage();
  return -1;
 }
 while ((c = getopt(argc, argv, optstring)) != -1) {
  switch ( c ) {
   case 'D':
    settings->daemon = 1;
    break;
   case 'h':
    print_usage();
    return -1;
   case 'v':
    settings->verbose = 1;
    break;
   case 'V':
    print_version();
    return -1;
   case ':':
    fprintf(stderr, "Missing argument for (%s)\n", argv[optind-1] );
    return -1;
   case '?':
    fprintf(stderr, "Unknown argument (%s)\n", argv[optind-1] );
    return -1;
   default:
    break;
  }
 }
 if ( settings->daemon && optind < argc ) {
  fprintf(stderr, "Tests can not be specified on the command line in daemon mode\n" );
  return -1;
 }
 optind = 1;
 while ((c = getopt(argc, argv, optstring)) != -1) {
  switch ( c ) {
   case 'c': {
    double level = 95.0, interval = 5.0;
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set confidence interval when in daemon mode\n");
     return -1;
    }
    if ( sscanf( optarg, "%lf,%lf", &level, &interval ) < 2 ) {
     fprintf(stdout, "%lf%% Confidence interval defaulted to %lf percent\n", level, interval);
    }
    if (level != 75.0 && level != 90.0 && level != 95.0 && level != 97.5 &&
     level != 99.0 && level != 99.5 && level != 99.95) {
     fprintf(stderr, "Confidence Level must be {75, 90, 95, 97.5, 99, 99.5, 99.95}. Given (%s)\n", optarg);
     return -1;
    }
    settings->confidence_lvl = level;
    settings->confidence_int = interval;
    break;
   }
   case 'd':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set duration when in daemon mode\n");
     return -1;
    }
    settings->duration = atoi( optarg );
    if ( settings->duration == 0 ) {
     fprintf(stderr, "Invalid duration given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'i': {
    unsigned int min = 0, max = 0;
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set iterations when in daemon mode\n");
     return -1;
    }
    if ( sscanf( optarg, "%u,%u", &min, &max ) < 2 ) {
     if (sscanf( optarg, "%u", &max ) == 1)
      min = max;
    }
    if ( min > max || max == 0 ) {
     fprintf(stderr, "Invalid min/max iterations(%s)\n", optarg );
     return -1;
    }
    settings->min_iterations = min;
    settings->max_iterations = max;
    break;
   }
   case 'H': {
    struct sockaddr_storage addr;
    socklen_t addr_len = sizeof(addr);
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set remote host when in daemon mode\n");
     return -1;
    }
    if ( str_to_addr( optarg, (struct sockaddr *)&addr, &addr_len ) ) {
     fprintf(stderr, "Invalid host name (%s)\n", optarg );
     return -1;
    }
    settings->server_host = optarg;
    break;
   }
   case 'n':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to disable Nagles when in daemon mode\n");
     return -1;
    }
    settings->disable_nagles = 1;
    break;
   case 'm' :
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set threading model when in daemon mode\n");
     return -1;
    }
    if(strcmp(optarg, "p")==0)
     settings->threaded_model = 1;
    else if( strcmp(optarg, "t")==0)
     settings->threaded_model = 0;
    else {
     fprintf(stderr, "Invalid threading model set to (%s)\n", optarg );
     return -1;
    }
    break;
   case 'q':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set quiet when in daemon mode\n");
     return -1;
    }
    settings->quiet = 1;
    break;
   case 's':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set message size when in daemon mode\n");
     return -1;
    }
    settings->message_size = atoi( optarg );
    if ( settings->message_size == 0 ) {
     fprintf(stderr, "Invalid message size given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'r':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set send rate when in daemon mode\n");
     return -1;
    }
    settings->rate = atoi( optarg );
    if ( settings->rate == 0 ) {
     fprintf(stderr, "Invalid send rate given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'p':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set port when in daemon mode\n");
     return -1;
    }
    settings->port = atoi( optarg );
    if ( settings->port == 0 ) {
     fprintf(stderr, "Invalid port number given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'e':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to eat the data when in daemon mode\n");
     return -1;
    }
    settings->dirty = 1;
    break;
   case 'R':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set reverse mode when in daemon mode\n");
     return -1;
    }
    settings->reverse = 1;
    break;
   case 'T':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set timestamps when in daemon mode\n");
     return -1;
    }
    settings->timestamp = 1;
    break;
   case 't':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set TCP when in daemon mode\n");
     return -1;
    }
    settings->type = SOCK_STREAM;
    settings->protocol = IPPROTO_TCP;
    break;
   case 'u':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set UDP when in daemon mode\n");
     return -1;
    }
    settings->type = SOCK_DGRAM;
    settings->protocol = IPPROTO_UDP;
    break;
   case 'D': case 'h': case 'v': case 'V':
    break;
   default:
    fprintf(stderr, "Argument not implemented (yet) (%c)\n", c );
    return -1;
  }
 }
 if ( settings->disable_nagles && settings->protocol != IPPROTO_TCP ) {
  fprintf(stderr, "Must use TCP when disabling Nagles\n" );
  return -1;
 }
 while (optind < argc) {
  struct test * test;
  ((void) sizeof ((!settings->daemon) ? 1 : 0), __extension__ ({ if (!settings->daemon) ; else __assert_fail ("!settings->daemon", "parse.c", 464, __extension__ __PRETTY_FUNCTION__); }));
  settings->test = realloc ( settings->test, sizeof(*settings->test) * (settings->tests + 1) );
  test = &settings->test [ settings->tests ];
  if ( parse_test ( settings, argv[optind], test ) != 0 ) {
   fprintf(stderr, "Unknown argument (%s)\n", argv[optind] );
   return -1;
  }
  if ( test->clientcores == 0 || test->servercores == 0 ) {
   fprintf(stderr, "Cores of zero will not run on any core (%s)\n", argv[optind] );
   return -1;
  }
  if ( test->clientcores >= (unsigned int)(1 << max_cores) || test->servercores >= (unsigned int)(1 << max_cores) ) {
   fprintf(stderr, "Cores must not be greater than %d (%s)\n", max_cores, argv[optind] );
   return -1;
  }
  settings->tests++;
  optind++;
 }
 if ( settings->tests == 0 && !settings->daemon ) {
  fprintf(stderr, "No tests were specified\n");
  return -1;
 }
 settings->clientcores = count_client_cores ( settings->test, settings->tests );
 settings->servercores = count_server_cores ( settings->test, settings->tests );
 return 0;
}

canonical_original_code:
int parse_settings(int argc, char *argv[], struct settings *settings) {
 int c;
 char *optstring = "DhvVtTReunqs:d:p:c:i:H:r:m:";
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "parse.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 settings->daemon = 0;
 settings->message_size = 1024;
 settings->socket_size = ~0;
 settings->rate = ~0;
 settings->disable_nagles = 0;
 settings->duration = 10;
 settings->server_host = ((void *)0);
 settings->port = 1234;
 settings->verbose = 0;
 settings->dirty = 0;
 settings->timestamp = 0;
 settings->confidence_lvl = 0.0;
 settings->confidence_int = 0.0;
 settings->min_iterations = 1;
 settings->max_iterations = 1;
 settings->threaded_model = 0;
 settings->reverse = 0;
 settings->quiet = 0;
 settings->type = SOCK_STREAM;
 settings->protocol = IPPROTO_TCP;
 settings->test = ((void *)0);
 settings->tests = 0;
 if ( argc == 1 ) {
  print_usage();
  return -1;
 }
 while ((c = getopt(argc, argv, optstring)) != -1) {
  switch ( c ) {
   case 'D':
    settings->daemon = 1;
    break;
   case 'h':
    print_usage();
    return -1;
   case 'v':
    settings->verbose = 1;
    break;
   case 'V':
    print_version();
    return -1;
   case ':':
    fprintf(stderr, "Missing argument for (%s)\n", argv[optind-1] );
    return -1;
   case '?':
    fprintf(stderr, "Unknown argument (%s)\n", argv[optind-1] );
    return -1;
   default:
    break;
  }
 }
 if ( settings->daemon && optind < argc ) {
  fprintf(stderr, "Tests can not be specified on the command line in daemon mode\n" );
  return -1;
 }
 optind = 1;
 while ((c = getopt(argc, argv, optstring)) != -1) {
  switch ( c ) {
   case 'c': {
    double level = 95.0; double interval = 5.0;
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set confidence interval when in daemon mode\n");
     return -1;
    }
    if ( sscanf( optarg, "%lf,%lf", &level, &interval ) < 2 ) {
     fprintf(stdout, "%lf%% Confidence interval defaulted to %lf percent\n", level, interval);
    }
    if (level != 75.0 && level != 90.0 && level != 95.0 && level != 97.5 &&
     level != 99.0 && level != 99.5 && level != 99.95) {
     fprintf(stderr, "Confidence Level must be {75, 90, 95, 97.5, 99, 99.5, 99.95}. Given (%s)\n", optarg);
     return -1;
    }
    settings->confidence_lvl = level;
    settings->confidence_int = interval;
    break;
   }
   case 'd':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set duration when in daemon mode\n");
     return -1;
    }
    settings->duration = atoi( optarg );
    if ( settings->duration == 0 ) {
     fprintf(stderr, "Invalid duration given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'i': {
    unsigned int min = 0; unsigned int max = 0;
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set iterations when in daemon mode\n");
     return -1;
    }
    if ( sscanf( optarg, "%u,%u", &min, &max ) < 2 ) {
     if (sscanf( optarg, "%u", &max ) == 1)
      min = max;
    }
    if ( min > max || max == 0 ) {
     fprintf(stderr, "Invalid min/max iterations(%s)\n", optarg );
     return -1;
    }
    settings->min_iterations = min;
    settings->max_iterations = max;
    break;
   }
   case 'H': {
    struct sockaddr_storage addr;
    unsigned int addr_len = sizeof(addr);
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set remote host when in daemon mode\n");
     return -1;
    }
    if ( str_to_addr( optarg, (struct sockaddr *)&addr, &addr_len ) ) {
     fprintf(stderr, "Invalid host name (%s)\n", optarg );
     return -1;
    }
    settings->server_host = optarg;
    break;
   }
   case 'n':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to disable Nagles when in daemon mode\n");
     return -1;
    }
    settings->disable_nagles = 1;
    break;
   case 'm' :
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set threading model when in daemon mode\n");
     return -1;
    }
    if(strcmp(optarg, "p")==0)
     settings->threaded_model = 1;
    else if( strcmp(optarg, "t")==0)
     settings->threaded_model = 0;
    else {
     fprintf(stderr, "Invalid threading model set to (%s)\n", optarg );
     return -1;
    }
    break;
   case 'q':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set quiet when in daemon mode\n");
     return -1;
    }
    settings->quiet = 1;
    break;
   case 's':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set message size when in daemon mode\n");
     return -1;
    }
    settings->message_size = atoi( optarg );
    if ( settings->message_size == 0 ) {
     fprintf(stderr, "Invalid message size given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'r':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set send rate when in daemon mode\n");
     return -1;
    }
    settings->rate = atoi( optarg );
    if ( settings->rate == 0 ) {
     fprintf(stderr, "Invalid send rate given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'p':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set port when in daemon mode\n");
     return -1;
    }
    settings->port = atoi( optarg );
    if ( settings->port == 0 ) {
     fprintf(stderr, "Invalid port number given (%s)\n", optarg );
     return -1;
    }
    break;
   case 'e':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to eat the data when in daemon mode\n");
     return -1;
    }
    settings->dirty = 1;
    break;
   case 'R':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set reverse mode when in daemon mode\n");
     return -1;
    }
    settings->reverse = 1;
    break;
   case 'T':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set timestamps when in daemon mode\n");
     return -1;
    }
    settings->timestamp = 1;
    break;
   case 't':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set TCP when in daemon mode\n");
     return -1;
    }
    settings->type = SOCK_STREAM;
    settings->protocol = IPPROTO_TCP;
    break;
   case 'u':
    if ( settings->daemon ) {
     fprintf(stdout, "Unable to set UDP when in daemon mode\n");
     return -1;
    }
    settings->type = SOCK_DGRAM;
    settings->protocol = IPPROTO_UDP;
    break;
   case 'D': case 'h': case 'v': case 'V':
    break;
   default:
    fprintf(stderr, "Argument not implemented (yet) (%c)\n", c );
    return -1;
  }
 }
 if ( settings->disable_nagles && settings->protocol != IPPROTO_TCP ) {
  fprintf(stderr, "Must use TCP when disabling Nagles\n" );
  return -1;
 }
 while (optind < argc) {
  struct test *test;
  ((void) sizeof ((!settings->daemon) ? 1 : 0), __extension__ ({ if (!settings->daemon) ; else __assert_fail ("!settings->daemon", "parse.c", 464, __extension__ __PRETTY_FUNCTION__); }));
  settings->test = realloc ( settings->test, sizeof(*settings->test) * (settings->tests + 1) );
  test = &settings->test [ settings->tests ];
  if ( parse_test ( settings, argv[optind], test ) != 0 ) {
   fprintf(stderr, "Unknown argument (%s)\n", argv[optind] );
   return -1;
  }
  if ( test->clientcores == 0 || test->servercores == 0 ) {
   fprintf(stderr, "Cores of zero will not run on any core (%s)\n", argv[optind] );
   return -1;
  }
  if ( test->clientcores >= (unsigned int)(1 << max_cores) || test->servercores >= (unsigned int)(1 << max_cores) ) {
   fprintf(stderr, "Cores must not be greater than %d (%s)\n", max_cores, argv[optind] );
   return -1;
  }
  settings->tests++;
  optind++;
 }
 if ( settings->tests == 0 && !settings->daemon ) {
  fprintf(stderr, "No tests were specified\n");
  return -1;
 }
 settings->clientcores = count_client_cores ( settings->test, settings->tests );
 settings->servercores = count_server_cores ( settings->test, settings->tests );
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
optstring
char *

variable_types: level double

variable_types: interval double

variable_types:
min
unsigned int

variable_types:
max
unsigned int

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


bit

repo: brandt/network-patricia

original_code:
static __inline unsigned long bit(int i, unsigned long key) {
  return key & (1 << (31 - i));
}

variable_types: i int

variable_types:
key
unsigned long

return_type: unsigned long


insertR

original_code:
static struct ptree *insertR(struct ptree *h, struct ptree *n, int d,
                             struct ptree *p) {
  if ((h->p_b >= d) || (h->p_b <= p->p_b)) {
    n->p_b = d;
    n->p_left = bit(d, n->p_key) ? h : n;
    n->p_right = bit(d, n->p_key) ? n : h;
    return n;
  }
  if (bit(h->p_b, n->p_key)) {
    h->p_right = insertR(h->p_right, n, d, h);
  } else {
    h->p_left = insertR(h->p_left, n, d, h);
  }
  return h;
}

variable_types:
h
struct ptree *

variable_types:
n
struct ptree *

variable_types: d int

variable_types:
p
struct ptree *

return_type: struct ptree { unsigned long p_key; struct ptree_mask { unsigned long pm_mask; void *pm_data; } *p_m; unsigned char p_mlen; char p_b; struct ptree *p_left; struct ptree *p_right; } *

user_defined_types: struct ptree { unsigned long p_key; struct ptree_mask *p_m; unsigned char p_mlen; char p_b; struct ptree *p_left; struct ptree *p_right; }


original_code:
struct ptree *pat_insert(struct ptree *n, struct ptree *head) {
  struct ptree *t;
  struct ptree_mask *buf, *pm;
  int i, copied;
  if (!head || !n || !n->p_m) {
    return 0;
  }
  n->p_key &= n->p_m->pm_mask;
  t = head;
  do {
    i = t->p_b;
    t = bit(t->p_b, n->p_key) ? t->p_right : t->p_left;
  } while (i < t->p_b);
  if (n->p_key == t->p_key) {
    for (i = 0; i < t->p_mlen; i++) {
      if (n->p_m->pm_mask == t->p_m[i].pm_mask) {
        t->p_m[i].pm_data = n->p_m->pm_data;
        free(n->p_m);
        free(n);
        n = 0;
        return t;
      }
    }
    buf = (struct ptree_mask *)malloc(sizeof(struct ptree_mask) *
                                      (t->p_mlen + 1));
    copied = 0;
    for (i = 0, pm = buf; i < t->p_mlen; pm++) {
      if (n->p_m->pm_mask > t->p_m[i].pm_mask) {
        bcopy(t->p_m + i, pm, sizeof(struct ptree_mask));
        i++;
      } else {
        bcopy(n->p_m, pm, sizeof(struct ptree_mask));
        n->p_m->pm_mask = 0xffffffff;
        copied = 1;
      }
    }
    if (!copied) {
      bcopy(n->p_m, pm, sizeof(struct ptree_mask));
    }
    free(n->p_m);
    free(n);
    n = 0;
    t->p_mlen++;
    free(t->p_m);
    t->p_m = buf;
    return t;
  }
  for (i = 1; i < 32 && bit(i, n->p_key) == bit(i, t->p_key); i++)
    ;
  if (bit(head->p_b, n->p_key)) {
    head->p_right = insertR(head->p_right, n, i, head);
  } else {
    head->p_left = insertR(head->p_left, n, i, head);
  }
  return n;
}

canonical_original_code:
struct ptree *pat_insert(struct ptree *n, struct ptree *head) {
  struct ptree *t;
  struct ptree_mask *buf; struct ptree_mask *pm;
  int i; int copied;
  if (!head || !n || !n->p_m) {
    return 0;
  }
  n->p_key &= n->p_m->pm_mask;
  t = head;
  do {
    i = t->p_b;
    t = bit(t->p_b, n->p_key) ? t->p_right : t->p_left;
  } while (i < t->p_b);
  if (n->p_key == t->p_key) {
    for (i = 0; i < t->p_mlen; i++) {
      if (n->p_m->pm_mask == t->p_m[i].pm_mask) {
        t->p_m[i].pm_data = n->p_m->pm_data;
        free(n->p_m);
        free(n);
        n = 0;
        return t;
      }
    }
    buf = (struct ptree_mask *)malloc(sizeof(struct ptree_mask) *
                                      (t->p_mlen + 1));
    copied = 0;
    for (i = 0, pm = buf; i < t->p_mlen; pm++) {
      if (n->p_m->pm_mask > t->p_m[i].pm_mask) {
        bcopy(t->p_m + i, pm, sizeof(struct ptree_mask));
        i++;
      } else {
        bcopy(n->p_m, pm, sizeof(struct ptree_mask));
        n->p_m->pm_mask = 0xffffffff;
        copied = 1;
      }
    }
    if (!copied) {
      bcopy(n->p_m, pm, sizeof(struct ptree_mask));
    }
    free(n->p_m);
    free(n);
    n = 0;
    t->p_mlen++;
    free(t->p_m);
    t->p_m = buf;
    return t;
  }
  for (i = 1; i < 32 && bit(i, n->p_key) == bit(i, t->p_key); i++)
    ;
  if (bit(head->p_b, n->p_key)) {
    head->p_right = insertR(head->p_right, n, i, head);
  } else {
    head->p_left = insertR(head->p_left, n, i, head);
  }
  return n;
}

variable_types:
head
struct ptree *

variable_types: struct ptree { unsigned long p_key; struct ptree_mask { unsigned long pm_mask; void *pm_data; } *p_m; unsigned char p_mlen; char p_b; struct ptree *p_left; struct ptree *p_right; } *

variable_types: copied int


decompiled_code:
__int64 pat_remove()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
int pat_remove(struct ptree *n, struct ptree *head) {
  struct ptree *p, *g, *pt, *pp, *t = ((void *)0);
  struct ptree_mask *buf, *pm;
  int i;
  if (!n || !n->p_m || !t) {
    return 0;
  }
  g = p = t = head;
  do {
    i = t->p_b;
    g = p;
    p = t;
    t = bit(t->p_b, n->p_key) ? t->p_right : t->p_left;
  } while (i < t->p_b);
  if (t->p_key != n->p_key) {
    return 0;
  }
  if (t->p_mlen == 1) {
    if (t->p_b == 0) {
      return 0;
    }
    if (t->p_m->pm_mask != n->p_m->pm_mask) {
      return 0;
    }
    pp = pt = p;
    do {
      i = pt->p_b;
      pp = pt;
      pt = bit(pt->p_b, p->p_key) ? pt->p_right : pt->p_left;
    } while (i < pt->p_b);
    if (bit(pp->p_b, p->p_key)) {
      pp->p_right = t;
    } else {
      pp->p_left = t;
    }
    if (bit(g->p_b, n->p_key))
      g->p_right = bit(p->p_b, n->p_key) ? p->p_left : p->p_right;
    else
      g->p_left = bit(p->p_b, n->p_key) ? p->p_left : p->p_right;
    if (t->p_m->pm_data) {
      free(t->p_m->pm_data);
    }
    free(t->p_m);
    if (t != p) {
      t->p_key = p->p_key;
      t->p_m = p->p_m;
      t->p_mlen = p->p_mlen;
    }
    free(p);
    return 1;
  }
  for (i = 0; i < t->p_mlen; i++)
    if (n->p_m->pm_mask == t->p_m[i].pm_mask) {
      break;
    }
  if (i >= t->p_mlen) {
    return 0;
  }
  buf = (struct ptree_mask *)malloc(sizeof(struct ptree_mask) * (t->p_mlen - 1));
  for (i = 0, pm = buf; i < t->p_mlen; i++) {
    if (n->p_m->pm_mask != t->p_m[i].pm_mask) {
      bcopy(t->p_m + i, pm++, sizeof(struct ptree_mask));
    }
  }
  t->p_mlen--;
  free(t->p_m);
  t->p_m = buf;
  return 1;
}

canonical_original_code:
int pat_remove(struct ptree *n, struct ptree *head) {
  struct ptree *p; struct ptree *g; struct ptree *pt; struct ptree *pp; struct ptree *t = ((void *)0);
  struct ptree_mask *buf; struct ptree_mask *pm;
  int i;
  if (!n || !n->p_m || !t) {
    return 0;
  }
  g = p = t = head;
  do {
    i = t->p_b;
    g = p;
    p = t;
    t = bit(t->p_b, n->p_key) ? t->p_right : t->p_left;
  } while (i < t->p_b);
  if (t->p_key != n->p_key) {
    return 0;
  }
  if (t->p_mlen == 1) {
    if (t->p_b == 0) {
      return 0;
    }
    if (t->p_m->pm_mask != n->p_m->pm_mask) {
      return 0;
    }
    pp = pt = p;
    do {
      i = pt->p_b;
      pp = pt;
      pt = bit(pt->p_b, p->p_key) ? pt->p_right : pt->p_left;
    } while (i < pt->p_b);
    if (bit(pp->p_b, p->p_key)) {
      pp->p_right = t;
    } else {
      pp->p_left = t;
    }
    if (bit(g->p_b, n->p_key))
      g->p_right = bit(p->p_b, n->p_key) ? p->p_left : p->p_right;
    else
      g->p_left = bit(p->p_b, n->p_key) ? p->p_left : p->p_right;
    if (t->p_m->pm_data) {
      free(t->p_m->pm_data);
    }
    free(t->p_m);
    if (t != p) {
      t->p_key = p->p_key;
      t->p_m = p->p_m;
      t->p_mlen = p->p_mlen;
    }
    free(p);
    return 1;
  }
  for (i = 0; i < t->p_mlen; i++)
    if (n->p_m->pm_mask == t->p_m[i].pm_mask) {
      break;
    }
  if (i >= t->p_mlen) {
    return 0;
  }
  buf = (struct ptree_mask *)malloc(sizeof(struct ptree_mask) * (t->p_mlen - 1));
  for (i = 0, pm = buf; i < t->p_mlen; i++) {
    if (n->p_m->pm_mask != t->p_m[i].pm_mask) {
      bcopy(t->p_m + i, pm++, sizeof(struct ptree_mask));
    }
  }
  t->p_mlen--;
  free(t->p_m);
  t->p_m = buf;
  return 1;
}

variable_types: struct ptree_mask { unsigned long pm_mask; void *pm_data; } *


original_code:
struct ptree *pat_search(unsigned long key, struct ptree *head) {
  struct ptree *p = 0, *t = head;
  int i;
  if (!t) {
    return 0;
  }
  do {
    if (t->p_key == (key & t->p_m->pm_mask)) {
      p = t;
    }
    i = t->p_b;
    t = bit(t->p_b, key) ? t->p_right : t->p_left;
  } while (i < t->p_b);
  return (t->p_key == (key & t->p_m->pm_mask)) ? t : p;
}

canonical_original_code:
struct ptree *pat_search(unsigned long key, struct ptree *head) {
  struct ptree *p = 0; struct ptree *t = head;
  int i;
  if (!t) {
    return 0;
  }
  do {
    if (t->p_key == (key & t->p_m->pm_mask)) {
      p = t;
    }
    i = t->p_b;
    t = bit(t->p_b, key) ? t->p_right : t->p_left;
  } while (i < t->p_b);
  return (t->p_key == (key & t->p_m->pm_mask)) ? t : p;
}

user_defined_types: struct ptree_mask { unsigned long pm_mask; void *pm_data; }


remmean

repo: brandtd/eyeblink

decompiled_code:
float *__fastcall remmean(void *a1, __int64 *a2, __int64 *a3)
{
float *result; // rax
int v6; // er10
int v7; // er9
float *v8; // rdi
int i; // er11
__int64 v10; // r8
float *v11; // rdx
int v12; // esi
__int64 v13; // rcx
float v14; // xmm0_4
float v15; // xmm0_4
int j; // er12
__int64 v17; // r11
float *v18; // rdx
__int64 v19; // r8
int v20; // esi
__int64 v21; // rcx

result = (float *)memset(a1, 0, 4LL * *((int *)a3 + 2));
v6 = *((_DWORD *)a3 + 3);
v7 = *((_DWORD *)a3 + 2);
v8 = result;
if ( !v6 )
{
if ( !v7 )
return result;
LABEL_8:
result = v8;
do
{
v15 = *result++;
*(result - 1) = v15 / (float)v6;
}
while ( &v8[v7 - 1 + 1] != result );
if ( !v6 )
return result;
goto LABEL_11;
}
for ( i = 0; i != v6; ++i )
{
if ( v7 )
{
v10 = *a3;
v11 = v8;
LODWORD(result) = i * *((_DWORD *)a3 + 4);
v12 = (_DWORD)result + v7;
do
{
v13 = (unsigned int)result;
v14 = *v11;
result = (float *)(unsigned int)((_DWORD)result + 1);
*v11++ = v14 + *(float *)(v10 + 4 * v13);
}
while ( v12 != (_DWORD)result );
}
}
if ( v7 )
goto LABEL_8;
LABEL_11:
for ( j = 0; j != v6; ++j )
{
if ( v7 )
{
v17 = *a3;
v18 = v8;
v19 = *a2;
LODWORD(result) = j * *((_DWORD *)a3 + 4);
v20 = v7 + (_DWORD)result;
do
{
v21 = (unsigned int)result;
result = (float *)(unsigned int)((_DWORD)result + 1);
*(float *)(v19 + 4 * v21) = *(float *)(v17 + 4 * v21) - *v18++;
}
while ( (_DWORD)result != v20 );
}
}
return result;
}

canonical_decompiled_code:
float *__fastcall func0(void *a1, __int64 *a2, __int64 *a3)
{
float *result; // rax
int v6; // er10
int v7; // er9
float *v8; // rdi
int i; // er11
__int64 v10; // r8
float *v11; // rdx
int v12; // esi
__int64 v13; // rcx
float v14; // xmm0_4
float v15; // xmm0_4
int j; // er12
__int64 v17; // r11
float *v18; // rdx
__int64 v19; // r8
int v20; // esi
__int64 v21; // rcx

result = (float *)memset(a1, 0, 4LL * *((int *)a3 + 2));
v6 = *((_DWORD *)a3 + 3);
v7 = *((_DWORD *)a3 + 2);
v8 = result;
if ( !v6 )
{
if ( !v7 )
return result;
LABEL_8:
result = v8;
do
{
v15 = *result++;
*(result - 1) = v15 / (float)v6;
}
while ( &v8[v7 - 1 + 1] != result );
if ( !v6 )
return result;
goto LABEL_11;
}
for ( i = 0; i != v6; ++i )
{
if ( v7 )
{
v10 = *a3;
v11 = v8;
LODWORD(result) = i * *((_DWORD *)a3 + 4);
v12 = (_DWORD)result + v7;
do
{
v13 = (unsigned int)result;
v14 = *v11;
result = (float *)(unsigned int)((_DWORD)result + 1);
*v11++ = v14 + *(float *)(v10 + 4 * v13);
}
while ( v12 != (_DWORD)result );
}
}
if ( v7 )
goto LABEL_8;
LABEL_11:
for ( j = 0; j != v6; ++j )
{
if ( v7 )
{
v17 = *a3;
v18 = v8;
v19 = *a2;
LODWORD(result) = j * *((_DWORD *)a3 + 4);
v20 = v7 + (_DWORD)result;
do
{
v21 = (unsigned int)result;
result = (float *)(unsigned int)((_DWORD)result + 1);
*(float *)(v19 + 4 * v21) = *(float *)(v17 + 4 * v21) - *v18++;
}
while ( (_DWORD)result != v20 );
}
}
return result;
}

original_code:
void remmean( float *means, Matrix *Z, Matrix const *X )
{
  unsigned int row, col, i;
  memset( means, 0, sizeof(float) * X->rows );
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      means[row] += X->elem[col*X->ld + row];
    }
  }
  for (row = 0; row < X->rows; row++) {
    means[row] /= X->cols;
  }
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      i = col*X->ld + row;
      Z->elem[i] = X->elem[i] - means[row];
    }
  }
}

canonical_original_code:
void remmean(float *means, struct Matrix *Z, struct Matrix *X)
{
  unsigned int row; unsigned int col; unsigned int i;
  memset( means, 0, sizeof(float) * X->rows );
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      means[row] += X->elem[col*X->ld + row];
    }
  }
  for (row = 0; row < X->rows; row++) {
    means[row] /= X->cols;
  }
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      i = col*X->ld + row;
      Z->elem[i] = X->elem[i] - means[row];
    }
  }
}

variable_types:
means
float *

variable_types: struct Matrix { float *elem; int rows; int cols; int ld; int lag; } *

variable_types:
X
struct Matrix *

variable_types:
row
unsigned int

variable_types:
col
unsigned int

variable_types:
i
unsigned int

return_type: void


remmeanTranspose

decompiled_code:
float *__fastcall remmeanTranspose(void *a1, __int64 *a2, __int64 *a3)
{
float *result; // rax
int v6; // er12
int v7; // er11
float *v8; // r9
int i; // er8
__int64 v10; // rdi
float *v11; // rdx
int v12; // esi
__int64 v13; // rcx
float v14; // xmm0_4
float v15; // xmm0_4
unsigned int j; // er14
int v17; // er13
float *v18; // rcx
unsigned int v19; // edx
__int64 v20; // r10
__int64 v21; // r8
int v22; // edi
__int64 v23; // r15
__int64 v24; // rsi

result = (float *)memset(a1, 0, 4LL * *((int *)a3 + 2));
v6 = *((_DWORD *)a3 + 3);
v7 = *((_DWORD *)a3 + 2);
v8 = result;
if ( !v6 )
{
if ( !v7 )
return result;
LABEL_8:
result = v8;
do
{
v15 = *result++;
*(result - 1) = v15 / (float)v6;
}
while ( &v8[v7 - 1 + 1] != result );
if ( !v6 )
return result;
goto LABEL_11;
}
for ( i = 0; i != v6; ++i )
{
if ( v7 )
{
v10 = *a3;
v11 = v8;
LODWORD(result) = i * *((_DWORD *)a3 + 4);
v12 = (_DWORD)result + v7;
do
{
v13 = (unsigned int)result;
v14 = *v11;
result = (float *)(unsigned int)((_DWORD)result + 1);
*v11++ = v14 + *(float *)(v10 + 4 * v13);
}
while ( v12 != (_DWORD)result );
}
}
if ( v7 )
goto LABEL_8;
LABEL_11:
for ( j = 0; j != v6; ++j )
{
if ( v7 )
{
v17 = *((_DWORD *)a2 + 4);
v18 = v8;
v19 = j;
v20 = *a3;
v21 = *a2;
LODWORD(result) = j * *((_DWORD *)a3 + 4);
v22 = v7 + (_DWORD)result;
do
{
v23 = (unsigned int)result;
v24 = v19;
result = (float *)(unsigned int)((_DWORD)result + 1);
++v18;
v19 += v17;
*(float *)(v21 + 4 * v24) = *(float *)(v20 + 4 * v23) - *(v18 - 1);
}
while ( (_DWORD)result != v22 );
}
}
return result;
}

canonical_decompiled_code:
float *__fastcall func1(void *a1, __int64 *a2, __int64 *a3)
{
float *result; // rax
int v6; // er12
int v7; // er11
float *v8; // r9
int i; // er8
__int64 v10; // rdi
float *v11; // rdx
int v12; // esi
__int64 v13; // rcx
float v14; // xmm0_4
float v15; // xmm0_4
unsigned int j; // er14
int v17; // er13
float *v18; // rcx
unsigned int v19; // edx
__int64 v20; // r10
__int64 v21; // r8
int v22; // edi
__int64 v23; // r15
__int64 v24; // rsi

result = (float *)memset(a1, 0, 4LL * *((int *)a3 + 2));
v6 = *((_DWORD *)a3 + 3);
v7 = *((_DWORD *)a3 + 2);
v8 = result;
if ( !v6 )
{
if ( !v7 )
return result;
LABEL_8:
result = v8;
do
{
v15 = *result++;
*(result - 1) = v15 / (float)v6;
}
while ( &v8[v7 - 1 + 1] != result );
if ( !v6 )
return result;
goto LABEL_11;
}
for ( i = 0; i != v6; ++i )
{
if ( v7 )
{
v10 = *a3;
v11 = v8;
LODWORD(result) = i * *((_DWORD *)a3 + 4);
v12 = (_DWORD)result + v7;
do
{
v13 = (unsigned int)result;
v14 = *v11;
result = (float *)(unsigned int)((_DWORD)result + 1);
*v11++ = v14 + *(float *)(v10 + 4 * v13);
}
while ( v12 != (_DWORD)result );
}
}
if ( v7 )
goto LABEL_8;
LABEL_11:
for ( j = 0; j != v6; ++j )
{
if ( v7 )
{
v17 = *((_DWORD *)a2 + 4);
v18 = v8;
v19 = j;
v20 = *a3;
v21 = *a2;
LODWORD(result) = j * *((_DWORD *)a3 + 4);
v22 = v7 + (_DWORD)result;
do
{
v23 = (unsigned int)result;
v24 = v19;
result = (float *)(unsigned int)((_DWORD)result + 1);
++v18;
v19 += v17;
*(float *)(v21 + 4 * v24) = *(float *)(v20 + 4 * v23) - *(v18 - 1);
}
while ( (_DWORD)result != v22 );
}
}
return result;
}

original_code:
void remmeanTranspose( float *means, Matrix *Z, Matrix const *X )
{
  unsigned int row, col, z_i, x_i;
  memset( means, 0, sizeof(float) * X->rows );
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      means[row] += X->elem[col*X->ld + row];
    }
  }
  for (row = 0; row < X->rows; row++) {
    means[row] /= X->cols;
  }
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      x_i = col*X->ld + row;
      z_i = row*Z->ld + col;
      Z->elem[z_i] = X->elem[x_i] - means[row];
    }
  }
}

canonical_original_code:
void remmeanTranspose(float *means, struct Matrix *Z, struct Matrix *X)
{
  unsigned int row; unsigned int col; unsigned int z_i; unsigned int x_i;
  memset( means, 0, sizeof(float) * X->rows );
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      means[row] += X->elem[col*X->ld + row];
    }
  }
  for (row = 0; row < X->rows; row++) {
    means[row] /= X->cols;
  }
  for (col = 0; col < X->cols; col++) {
    for (row = 0; row < X->rows; row++) {
      x_i = col*X->ld + row;
      z_i = row*Z->ld + col;
      Z->elem[z_i] = X->elem[x_i] - means[row];
    }
  }
}

user_defined_types: struct Matrix { float *elem; int rows; int cols; int ld; int lag; }


computeWhiten

original_code:
void computeWhiten( Matrix *whiten, Matrix *dewhiten, Matrix const *Z,
                    int transpose )
{
  unsigned int row, col, i;
  float eig_inv_sqr, eig_sqr, *eig_vals;
  if (transpose) {
    eig_vals = (float*) malloc( sizeof(float) * Z->rows );
  } else {
    eig_vals = (float*) malloc( sizeof(float) * Z->cols );
  }
  if (transpose) {
    _alpha = 1.0 / (float) ((*Z).rows - 1); sgemm_( &_transpose, &_not_transpose, &((*Z).cols), &((*Z).cols), &((*Z).rows), &_alpha, (*Z).elem, &((*Z).ld), (*Z).elem, &((*Z).ld), &_beta, (*dewhiten).elem, &((*dewhiten).ld) ); _alpha = 1.0;;
  } else {
    _alpha = 1.0 / (float) ((*Z).cols - 1); sgemm_( &_not_transpose, &_transpose, &((*Z).rows), &((*Z).rows), &((*Z).cols), &_alpha, (*Z).elem, &((*Z).ld), (*Z).elem, &((*Z).ld), &_beta, (*dewhiten).elem, &((*dewhiten).ld) ); _alpha = 1.0;;
  }
  if (_work == ((void *)0)) { _work = (float*) malloc(sizeof(float)); _lwork = 1; } ssyev_( &_jobz,&_uplo,&((*dewhiten).rows),(*dewhiten).elem,&((*dewhiten).ld), (eig_vals), _work, &_n1, &_info ); if ((int) _work[0] > _lwork) { _lwork = (int) _work[0]; if (_work) { free( _work ); } _work = (float*) malloc( sizeof(float) * _lwork ); } ssyev_( &_jobz,&_uplo,&((*dewhiten).rows),(*dewhiten).elem,&((*dewhiten).ld), (eig_vals), _work, &_lwork, &_info );
  for (col = 0; col < whiten->cols; col++) {
    eig_inv_sqr = 1.0 / sqrt( eig_vals[col] );
    eig_sqr = sqrt( eig_vals[col] );
    for (row = 0; row < whiten->rows; row++) {
      i = col * dewhiten->ld + row;
      whiten->elem[row*whiten->ld + col] = eig_inv_sqr * dewhiten->elem[i];
      dewhiten->elem[i] = eig_sqr * dewhiten->elem[i];
    }
  }
  free( eig_vals );
}

canonical_original_code:
void computeWhiten(struct Matrix *whiten, struct Matrix *dewhiten, struct Matrix *Z, int transpose)
{
  unsigned int row; unsigned int col; unsigned int i;
  float eig_inv_sqr; float eig_sqr; float *eig_vals;
  if (transpose) {
    eig_vals = (float *) malloc( sizeof(float) * Z->rows );
  } else {
    eig_vals = (float *) malloc( sizeof(float) * Z->cols );
  }
  if (transpose) {
    _alpha = 1.0 / (float) ((*Z).rows - 1); sgemm_( &_transpose, &_not_transpose, &((*Z).cols), &((*Z).cols), &((*Z).rows), &_alpha, (*Z).elem, &((*Z).ld), (*Z).elem, &((*Z).ld), &_beta, (*dewhiten).elem, &((*dewhiten).ld) ); _alpha = 1.0;;
  } else {
    _alpha = 1.0 / (float) ((*Z).cols - 1); sgemm_( &_not_transpose, &_transpose, &((*Z).rows), &((*Z).rows), &((*Z).cols), &_alpha, (*Z).elem, &((*Z).ld), (*Z).elem, &((*Z).ld), &_beta, (*dewhiten).elem, &((*dewhiten).ld) ); _alpha = 1.0;;
  }
  if (_work == ((void *)0)) { _work = (float *) malloc(sizeof(float)); _lwork = 1; } ssyev_( &_jobz,&_uplo,&((*dewhiten).rows),(*dewhiten).elem,&((*dewhiten).ld), (eig_vals), _work, &_n1, &_info ); if ((int) _work[0] > _lwork) { _lwork = (int) _work[0]; if (_work) { free( _work ); } _work = (float *) malloc( sizeof(float) * _lwork ); } ssyev_( &_jobz,&_uplo,&((*dewhiten).rows),(*dewhiten).elem,&((*dewhiten).ld), (eig_vals), _work, &_lwork, &_info );
  for (col = 0; col < whiten->cols; col++) {
    eig_inv_sqr = 1.0 / sqrt( eig_vals[col] );
    eig_sqr = sqrt( eig_vals[col] );
    for (row = 0; row < whiten->rows; row++) {
      i = col * dewhiten->ld + row;
      whiten->elem[row*whiten->ld + col] = eig_inv_sqr * dewhiten->elem[i];
      dewhiten->elem[i] = eig_sqr * dewhiten->elem[i];
    }
  }
  free( eig_vals );
}

variable_types:
dewhiten
struct Matrix *

variable_types:
Z
struct Matrix *

variable_types: transpose int


whiten

decompiled_code:
__int64 __fastcall whiten(_QWORD *a1, __int64 *a2, _QWORD *a3, __int64 *a4, int a5)
{
__int64 *v7; // rax
char *v8; // r8
__int64 *v9; // rdx
__int64 result; // rax

computeWhiten(a2, a3, a4, a5);
v7 = a2 + 2;
v8 = (char *)a2 + 12;
v9 = a2 + 1;
if ( a5 )
result = sgemm_(&not_transpose, &transpose, v9, a4 + 1, v8, &alpha, *a2, v7, *a4, a4 + 2, &beta, *a1, a1 + 2);
else
result = sgemm_(
&not_transpose,
&not_transpose,
v9,
(char *)a4 + 12,
v8,
&alpha,
*a2,
v7,
*a4,
a4 + 2,
&beta,
*a1,
a1 + 2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 *a2, _QWORD *a3, __int64 *a4, int a5)
{
__int64 *v7; // rax
char *v8; // r8
__int64 *v9; // rdx
__int64 result; // rax

func2(a2, a3, a4, a5);
v7 = a2 + 2;
v8 = (char *)a2 + 12;
v9 = a2 + 1;
if ( a5 )
result = sgemm_(&not_transpose, &transpose, v9, a4 + 1, v8, &alpha, *a2, v7, *a4, a4 + 2, &beta, *a1, a1 + 2);
else
result = sgemm_(
&not_transpose,
&not_transpose,
v9,
(char *)a4 + 12,
v8,
&alpha,
*a2,
v7,
*a4,
a4 + 2,
&beta,
*a1,
a1 + 2);
return result;
}

original_code:
void whiten( Matrix *white_Z, Matrix *whiten, Matrix *dewhiten,
             Matrix const *Z, int transpose )
{
  computeWhiten( whiten, dewhiten, Z, transpose );
  if (transpose) {
    sgemm_( &_not_transpose, &_transpose, &((*whiten).rows), &((*Z).rows), &((*whiten).cols), &_alpha, (*whiten).elem, &((*whiten).ld), (*Z).elem, &((*Z).ld), &_beta, (*white_Z).elem, &((*white_Z).ld) );
  } else {
    sgemm_( &_not_transpose, &_not_transpose, &((*whiten).rows), &((*Z).cols), &((*whiten).cols), &_alpha, (*whiten).elem, &((*whiten).ld), (*Z).elem, &((*Z).ld), &_beta, (*white_Z).elem, &((*white_Z).ld) );
  }
}

canonical_original_code:
void whiten(struct Matrix *white_Z, struct Matrix *whiten, struct Matrix *dewhiten, struct Matrix *Z, int transpose)
{
  computeWhiten( whiten, dewhiten, Z, transpose );
  if (transpose) {
    sgemm_( &_not_transpose, &_transpose, &((*whiten).rows), &((*Z).rows), &((*whiten).cols), &_alpha, (*whiten).elem, &((*whiten).ld), (*Z).elem, &((*Z).ld), &_beta, (*white_Z).elem, &((*white_Z).ld) );
  } else {
    sgemm_( &_not_transpose, &_not_transpose, &((*whiten).rows), &((*Z).cols), &((*whiten).cols), &_alpha, (*whiten).elem, &((*whiten).ld), (*Z).elem, &((*Z).ld), &_beta, (*white_Z).elem, &((*white_Z).ld) );
  }
}

variable_types:
whiten
struct Matrix *


decompiled_code:
int __fastcall xltek_printErdHeaderS8(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 4112);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 8.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}
}
return printf(
"ERD schema 8.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 4112);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 8.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}
}
return printf(
"ERD schema 8.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}

original_code:
void xltek_printErdHeaderS8( const xltek_erd_s8_t *head )
{
  unsigned int i, boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 8.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

canonical_original_code:
void xltek_printErdHeaderS8(struct xltek_erd_s8_t *head)
{
  unsigned int i; unsigned int boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 8.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

variable_types: struct xltek_erd_s8_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[1024]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; unsigned short m_shorted[1024]; unsigned short m_frequency_factor[1024]; } *

variable_types:
boxtype
unsigned int [4]


variable_types:
retval
unsigned int

variable_types: epsilon float


decompiled_code:
__int64 __fastcall floorLog2(unsigned int a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 > 0xFFFF )
{
a1 >>= 16;
result = 16LL;
}
if ( a1 > 0xFF )
{
a1 >>= 8;
result = (unsigned int)(result + 8);
}
if ( a1 > 0xF )
{
a1 >>= 4;
result = (unsigned int)(result + 4);
}
if ( a1 <= 3 )
{
if ( a1 > 1 )
return (unsigned int)(result + 1);
if ( !a1 )
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(result + 2);
if ( a1 >> 2 != 1 )
return (unsigned int)(result + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 > 0xFFFF )
{
a1 >>= 16;
result = 16LL;
}
if ( a1 > 0xFF )
{
a1 >>= 8;
result = (unsigned int)(result + 8);
}
if ( a1 > 0xF )
{
a1 >>= 4;
result = (unsigned int)(result + 4);
}
if ( a1 <= 3 )
{
if ( a1 > 1 )
return (unsigned int)(result + 1);
if ( !a1 )
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(result + 2);
if ( a1 >> 2 != 1 )
return (unsigned int)(result + 1);
}
return result;
}

variable_types:
num
unsigned int

variable_types:
log
unsigned int


idwtResultLength

decompiled_code:
__int64 __fastcall idwtResultLength(int a1, int a2)
{
return (unsigned int)(2 - a2 + 2 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)(2 - a2 + 2 * a1);
}

original_code:
inline unsigned int idwtResultLength( unsigned int len_coef,
                                      unsigned int len_filter )
{
  return 2 * len_coef - len_filter + 2;
}

canonical_original_code:
inline unsigned int idwtResultLength(unsigned int len_coef, unsigned int len_filter)
{
  return 2 * len_coef - len_filter + 2;
}

return_type: unsigned int


wavedecMaxLevel

decompiled_code:
__int64 __fastcall wavedecMaxLevel(unsigned int a1, unsigned int a2)
{
return floorLog2(a1 / a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return func0(a1 / a2);
}

original_code:
unsigned int wavedecMaxLevel( unsigned int len_signal,
                              unsigned int len_filter )
{
  return floorLog2( len_signal / len_filter );
}

canonical_original_code:
unsigned int wavedecMaxLevel(unsigned int len_signal, unsigned int len_filter)
{
  return floorLog2( len_signal / len_filter );
}


wavedecResultLength

decompiled_code:
__int64 __fastcall wavedecResultLength(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
int v3; // ecx
unsigned int v4; // er8
unsigned int v5; // edi
unsigned int v6; // esi
unsigned int v7; // eax
unsigned int v8; // ecx
int i; // edx

v2 = wavedecMaxLevel(a1, a2);
v5 = v4;
if ( v2 <= v4 )
v5 = v2;
v6 = a2 - 1;
v7 = (v6 + v3) >> 1;
v8 = v7;
if ( v5 > 1 )
{
for ( i = 1; i != v5; ++i )
{
v7 = (v6 + v7) >> 1;
v8 += v7;
}
}
return v8 + v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
int v3; // ecx
unsigned int v4; // er8
unsigned int v5; // edi
unsigned int v6; // esi
unsigned int v7; // eax
unsigned int v8; // ecx
int i; // edx

v2 = func2(a1, a2);
v5 = v4;
if ( v2 <= v4 )
v5 = v2;
v6 = a2 - 1;
v7 = (v6 + v3) >> 1;
v8 = v7;
if ( v5 > 1 )
{
for ( i = 1; i != v5; ++i )
{
v7 = (v6 + v7) >> 1;
v8 += v7;
}
}
return v8 + v7;
}

original_code:
unsigned int wavedecResultLength( unsigned int len_signal,
                                  unsigned int len_filter,
                                  unsigned int max_level )
{
  unsigned int i, g, k;
  i = wavedecMaxLevel( len_signal, len_filter );
  if (max_level > i) {
    max_level = i;
  }
  g = (len_signal + len_filter - 1) / 2;
  k = g;
  for (i = 1; i < max_level; i++) {
    g = (g + len_filter - 1) / 2;
    k += g;
  }
  k += g;
  return k;
}

canonical_original_code:
unsigned int wavedecResultLength(unsigned int len_signal, unsigned int len_filter, unsigned int max_level)
{
  unsigned int i; unsigned int g; unsigned int k;
  i = wavedecMaxLevel( len_signal, len_filter );
  if (max_level > i) {
    max_level = i;
  }
  g = (len_signal + len_filter - 1) / 2;
  k = g;
  for (i = 1; i < max_level; i++) {
    g = (g + len_filter - 1) / 2;
    k += g;
  }
  k += g;
  return k;
}

variable_types:
g
unsigned int

variable_types:
k
unsigned int


wavedec

original_code:
void wavedec( float *coefs, unsigned int *lengths,
              float const *signal, unsigned int len_signal,
              Wavelet wavelet, unsigned int level )
{
  unsigned int i;
  unsigned int len_coef;
  unsigned int i_detail;
  float *(scratch[2]);
  i = wavedecMaxLevel( len_signal, wavelet.len_filter );
  if (level > i) {
    level = i;
  }
  len_coef = wavedecResultLength( len_signal, wavelet.len_filter, level );
  lengths[level] = (len_signal + wavelet.len_filter - 1) / 2;
  i_detail = len_coef - lengths[level];
  scratch[0] = (float*) malloc( sizeof(float) * lengths[level] );
  scratch[1] = (float*) malloc( sizeof(float) * lengths[level] );
  conv_mirrorDown( scratch[0],
                   signal, len_signal,
                   wavelet.filter[ 0 ], wavelet.len_filter );
  conv_mirrorDown( coefs + i_detail,
                   signal, len_signal,
                   wavelet.filter[ 1 ], wavelet.len_filter );
  lengths[ level - 1 ] = lengths[level];
  for (i = 1; i < level; i++) {
    lengths[level - i] = (lengths[level-i+1] + wavelet.len_filter - 1) / 2;
    i_detail -= lengths[level-i];
    conv_mirrorDown( coefs + i_detail,
                     scratch[ (i-1)&0x01 ], lengths[level-i+1],
                     wavelet.filter[ 1 ], wavelet.len_filter );
    conv_mirrorDown( scratch[ i & 0x01 ],
                     scratch[ (i-1)&0x01 ], lengths[level-i+1],
                     wavelet.filter[ 0 ], wavelet.len_filter );
  }
  lengths[0] = lengths[1];
  memcpy( coefs, scratch[ (i-1)&0x01 ], sizeof(float) * lengths[1] );
  free( scratch[0] ); free( scratch[1] );
}

canonical_original_code:
void wavedec(float *coefs, unsigned int *lengths, float *signal, unsigned int len_signal, struct Wavelet wavelet, unsigned int level)
{
  unsigned int i;
  unsigned int len_coef;
  unsigned int i_detail;
  float *scratch[2];
  i = wavedecMaxLevel( len_signal, wavelet.len_filter );
  if (level > i) {
    level = i;
  }
  len_coef = wavedecResultLength( len_signal, wavelet.len_filter, level );
  lengths[level] = (len_signal + wavelet.len_filter - 1) / 2;
  i_detail = len_coef - lengths[level];
  scratch[0] = (float *) malloc( sizeof(float) * lengths[level] );
  scratch[1] = (float *) malloc( sizeof(float) * lengths[level] );
  conv_mirrorDown( scratch[0],
                   signal, len_signal,
                   wavelet.filter[ 0 ], wavelet.len_filter );
  conv_mirrorDown( coefs + i_detail,
                   signal, len_signal,
                   wavelet.filter[ 1 ], wavelet.len_filter );
  lengths[ level - 1 ] = lengths[level];
  for (i = 1; i < level; i++) {
    lengths[level - i] = (lengths[level-i+1] + wavelet.len_filter - 1) / 2;
    i_detail -= lengths[level-i];
    conv_mirrorDown( coefs + i_detail,
                     scratch[ (i-1)&0x01 ], lengths[level-i+1],
                     wavelet.filter[ 1 ], wavelet.len_filter );
    conv_mirrorDown( scratch[ i & 0x01 ],
                     scratch[ (i-1)&0x01 ], lengths[level-i+1],
                     wavelet.filter[ 0 ], wavelet.len_filter );
  }
  lengths[0] = lengths[1];
  memcpy( coefs, scratch[ (i-1)&0x01 ], sizeof(float) * lengths[1] );
  free( scratch[0] ); free( scratch[1] );
}

variable_types:
coefs
float *

variable_types:
lengths
unsigned int *

variable_types:
signal
float *

variable_types: struct Wavelet { float *filter[4]; unsigned int len_filter; }

variable_types:
level
unsigned int

variable_types:
scratch
float *[2]


idwt

decompiled_code:
void __fastcall idwt(void *a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6, int a7, int a8, __int64 a9, __int64 a10, unsigned int a11)
{
__int64 v12; // rbx
float *v13; // r12
float *v14; // rbp
__int64 i; // rax
unsigned int v16; // [rsp+4h] [rbp-54h]

v12 = a11 + 2 * a4 - 1;
v16 = idwtResultLength(a4, a11);
v13 = (float *)malloc(4 * v12);
v14 = (float *)malloc(4 * v12);
conv_mirrorUp(v13, a2, a4, a9, a11);
conv_mirrorUp(v14, a3, a4, a10, a11);
if ( (_DWORD)v12 )
{
for ( i = 0LL; i != v12; ++i )
v14[i] = v14[i] + v13[i];
}
memcpy(a1, &v14[a11 - 1], 4LL * v16);
free(v13);
free(v14);
}

original_code:
void idwt( float *result, float const *coef_approx,
           float const *coef_detail, unsigned int coef_length,
           Wavelet wavelet )
{
  unsigned int i, len_conv, len_result;
  len_conv = 2 * coef_length + wavelet.len_filter - 1;
  len_result = idwtResultLength( coef_length, wavelet.len_filter );
  float *(scratch[2]);
  scratch[0] = (float*) malloc( sizeof(float) * len_conv );
  scratch[1] = (float*) malloc( sizeof(float) * len_conv );
  conv_mirrorUp( scratch[0], coef_approx, coef_length,
                 wavelet.filter[ 2 ], wavelet.len_filter );
  conv_mirrorUp( scratch[1], coef_detail, coef_length,
                 wavelet.filter[ 3 ], wavelet.len_filter );
  for (i = 0; i < len_conv; i++) {
    scratch[1][i] += scratch[0][i];
  }
  memcpy( result, scratch[1] + wavelet.len_filter - 1,
          sizeof(float) * len_result );
  free( scratch[0] ); free( scratch[1] );
}

canonical_original_code:
void idwt(float *result, float *coef_approx, float *coef_detail, unsigned int coef_length, struct Wavelet wavelet)
{
  unsigned int i; unsigned int len_conv; unsigned int len_result;
  len_conv = 2 * coef_length + wavelet.len_filter - 1;
  len_result = idwtResultLength( coef_length, wavelet.len_filter );
  float *scratch[2];
  scratch[0] = (float *) malloc( sizeof(float) * len_conv );
  scratch[1] = (float *) malloc( sizeof(float) * len_conv );
  conv_mirrorUp( scratch[0], coef_approx, coef_length,
                 wavelet.filter[ 2 ], wavelet.len_filter );
  conv_mirrorUp( scratch[1], coef_detail, coef_length,
                 wavelet.filter[ 3 ], wavelet.len_filter );
  for (i = 0; i < len_conv; i++) {
    scratch[1][i] += scratch[0][i];
  }
  memcpy( result, scratch[1] + wavelet.len_filter - 1,
          sizeof(float) * len_result );
  free( scratch[0] ); free( scratch[1] );
}

variable_types:
result
float *

variable_types:
i
unsigned int

user_defined_types: struct Wavelet { float *filter[4]; unsigned int len_filter; }


wrcoef

original_code:
void wrcoef( float *result,
             float const *coefs, unsigned int const *lengths,
             unsigned int len_lengths, ReconType type, Wavelet wavelet,
             unsigned int level )
{
  unsigned int i, i_coefs;
  unsigned int max_level = len_lengths - 1;
  size_t coef_mem_size;
  float *cA, *cD, *scratch;
  if (level > max_level) {
    level = max_level;
  } else if (level == 0 && type == RECON_DETAIL) {
    level = 1;
  }
  coef_mem_size = sizeof(float) * lengths[len_lengths - 1];
  cA = (float*) malloc( coef_mem_size );
  scratch = (float*) malloc( coef_mem_size );
  if (type == RECON_APPROX) {
    memcpy( cA, coefs, sizeof(float) * lengths[0] );
    i_coefs = lengths[0];
    for (i = max_level; i > level; i--) {
      cD = (float*) coefs + i_coefs;
      i_coefs += lengths[ len_lengths - i ];
      idwt( result, cA, cD, lengths[ len_lengths - i ], wavelet );
      if (i != 1) {
        memcpy( cA, result, sizeof(float) * lengths[ len_lengths - i + 1 ] );
      }
    }
  } else {
    i_coefs = lengths[0];
    for (i = max_level; i > level; i--) {
      i_coefs += lengths[ len_lengths - i ];
    }
    cD = (float*) coefs + i_coefs;
    memset( cA, 0x00, coef_mem_size );
    idwt( result, cA, cD, lengths[ len_lengths - level ], wavelet );
    if (i != 1) {
      memcpy( cA, result, sizeof(float) * lengths[ len_lengths - i + 1 ] );
    }
    i--;
  }
  cD = scratch;
  memset( cD, 0x00, coef_mem_size );
  for (; i > 0; i--) {
    idwt( result, cA, cD, lengths[ len_lengths - i ], wavelet );
    if (i != 1) {
      memcpy( cA, result, sizeof(float) * lengths[ len_lengths - i + 1 ] );
    }
  }
  free( cA ); free( cD );
}

canonical_original_code:
void wrcoef(float *result, float *coefs, unsigned int *lengths, unsigned int len_lengths, enum ReconType type, struct Wavelet wavelet, unsigned int level)
{
  unsigned int i; unsigned int i_coefs;
  unsigned int max_level = len_lengths - 1;
  unsigned long coef_mem_size;
  float *cA; float *cD; float *scratch;
  if (level > max_level) {
    level = max_level;
  } else if (level == 0 && type == RECON_DETAIL) {
    level = 1;
  }
  coef_mem_size = sizeof(float) * lengths[len_lengths - 1];
  cA = (float *) malloc( coef_mem_size );
  scratch = (float *) malloc( coef_mem_size );
  if (type == RECON_APPROX) {
    memcpy( cA, coefs, sizeof(float) * lengths[0] );
    i_coefs = lengths[0];
    for (i = max_level; i > level; i--) {
      cD = (float *) coefs + i_coefs;
      i_coefs += lengths[ len_lengths - i ];
      idwt( result, cA, cD, lengths[ len_lengths - i ], wavelet );
      if (i != 1) {
        memcpy( cA, result, sizeof(float) * lengths[ len_lengths - i + 1 ] );
      }
    }
  } else {
    i_coefs = lengths[0];
    for (i = max_level; i > level; i--) {
      i_coefs += lengths[ len_lengths - i ];
    }
    cD = (float *) coefs + i_coefs;
    memset( cA, 0x00, coef_mem_size );
    idwt( result, cA, cD, lengths[ len_lengths - level ], wavelet );
    if (i != 1) {
      memcpy( cA, result, sizeof(float) * lengths[ len_lengths - i + 1 ] );
    }
    i--;
  }
  cD = scratch;
  memset( cD, 0x00, coef_mem_size );
  for (; i > 0; i--) {
    idwt( result, cA, cD, lengths[ len_lengths - i ], wavelet );
    if (i != 1) {
      memcpy( cA, result, sizeof(float) * lengths[ len_lengths - i + 1 ] );
    }
  }
  free( cA ); free( cD );
}

variable_types: enum ReconType { RECON_DETAIL=0, RECON_APPROX=1 }

variable_types:
cA
float *

variable_types:
cD
float *

variable_types:
scratch
float *


variable_types:
uuid
unsigned char [16]

variable_types:
str
char *


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

v2 = 0LL;
while ( *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2) )
{
if ( ++v2 == 16 )
return 1LL;
}
return 0LL;
}

original_code:
int xltek_uuidEqual( const uuid_t u1, const uuid_t u2 )
{
  int i;
  for (i = 0; i < 16; i++) {
    if (u1[i] != u2[i]) {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int xltek_uuidEqual(unsigned char u1[16], unsigned char u2[16])
{
  int i;
  for (i = 0; i < 16; i++) {
    if (u1[i] != u2[i]) {
      return 0;
    }
  }
  return 1;
}

variable_types: i int