decompiled_code:
int print_usage()
{
return inform_user("Usage: aggregator [options]\n"
" Options:\n"
" -n <num> Number of clients/servers to aggregate\n"
" -p <port> Port number to listen to\n"
" -m <num> Number of measurements to receive (Default: 60)\n"
" -h Display this text\n"
"\n"
"For bug reporting and suggestions, mail peter@torpman.se\n");
}

canonical_decompiled_code:
int func9()
{
return func8("Usage: aggregator [options]\n"
" Options:\n"
" -n <num> Number of clients/servers to aggregate\n"
" -p <port> Port number to listen to\n"
" -m <num> Number of measurements to receive (Default: 60)\n"
" -h Display this text\n"
"\n"
"For bug reporting and suggestions, mail peter@torpman.se\n");
}

original_code:
static void
print_usage(void)
{
    inform_user(
        "Usage: aggregator [options]\n"
        "  Options:\n"
        "  -n <num>    Number of clients/servers to aggregate\n"
        "  -p <port>   Port number to listen to\n"
        "  -m <num>    Number of measurements to receive (Default: 60)\n"
        "  -h          Display this text\n\n"
        "For bug reporting and suggestions, mail peter@torpman.se\n");
}

canonical_original_code:
static void print_usage()
{
    inform_user(
        "Usage: aggregator [options]\n"
        "  Options:\n"
        "  -n <num>    Number of clients/servers to aggregate\n"
        "  -p <port>   Port number to listen to\n"
        "  -m <num>    Number of measurements to receive (Default: 60)\n"
        "  -h          Display this text\n\n"
        "For bug reporting and suggestions, mail peter@torpman.se\n");
}


main

canonical_name: main

repo: ptorpman/threet

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // er13
const char *v5; // rbp
const char *v6; // rdi
int v8; // eax

memset(gClientTp, 0, 0x3F8uLL);
gClientTp[254] = 0;
memset(gClientReported, 0, 0x3F8uLL);
gClientReported[254] = 0;
v3 = argv + 2;
v4 = 3;
if ( argc > 1 )
{
while ( 1 )
{
v5 = *(v3 - 1);
if ( !strcmp(v5, "-h") || !strcmp(*(v3 - 1), "--help") )
break;
if ( !strcmp(*(v3 - 1), "-n") )
{
v6 = *v3;
if ( !*v3 )
goto LABEL_25;
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
inform_user("ERROR: Incorrect number of clients/servers '%s'\n", *v3);
return 1;
}
gNumClients = 0;
v8 = v4;
}
else if ( !strcmp(*(v3 - 1), "-p") )
{
v6 = *v3;
if ( !*v3 )
goto LABEL_25;
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
inform_user("ERROR: Incorrect port number '%s'\n", *v3);
return 1;
}
gPort = 0;
v8 = v4;
}
else
{
if ( strcmp(*(v3 - 1), "-m") )
{
inform_user("Bad parameter! (%s)\n", v5);
print_usage();
return 1;
}
v6 = *v3;
if ( !*v3 )
{
LABEL_25:
print_usage();
return 1;
}
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
inform_user("ERROR: Incorrect measurement limit '%s'\n", *v3);
return 1;
}
gNumMeasurements = 0;
v8 = v4;
}
v4 += 2;
v3 += 2;
if ( v8 >= argc )
{
if ( gPort != -1 )
return start_aggregating(v6, "%d");
inform_user("Bad port number! (%d)\n", 0xFFFFFFFFLL);
print_usage();
return 1;
}
}
}
print_usage();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // er13
const char *v5; // rbp
const char *v6; // rdi
int v8; // eax

memset(gClientTp, 0, 0x3F8uLL);
gClientTp[254] = 0;
memset(gClientReported, 0, 0x3F8uLL);
gClientReported[254] = 0;
v3 = argv + 2;
v4 = 3;
if ( argc > 1 )
{
while ( 1 )
{
v5 = *(v3 - 1);
if ( !strcmp(v5, "-h") || !strcmp(*(v3 - 1), "--help") )
break;
if ( !strcmp(*(v3 - 1), "-n") )
{
v6 = *v3;
if ( !*v3 )
goto LABEL_25;
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
func8("ERROR: Incorrect number of clients/servers '%s'\n", *v3);
return 1;
}
gNumClients = 0;
v8 = v4;
}
else if ( !strcmp(*(v3 - 1), "-p") )
{
v6 = *v3;
if ( !*v3 )
goto LABEL_25;
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
func8("ERROR: Incorrect port number '%s'\n", *v3);
return 1;
}
gPort = 0;
v8 = v4;
}
else
{
if ( strcmp(*(v3 - 1), "-m") )
{
func8("Bad parameter! (%s)\n", v5);
func9();
return 1;
}
v6 = *v3;
if ( !*v3 )
{
LABEL_25:
func9();
return 1;
}
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
func8("ERROR: Incorrect measurement limit '%s'\n", *v3);
return 1;
}
gNumMeasurements = 0;
v8 = v4;
}
v4 += 2;
v3 += 2;
if ( v8 >= argc )
{
if ( gPort != -1 )
return func12(v6, "%d");
func8("Bad port number! (%d)\n", 0xFFFFFFFFLL);
func9();
return 1;
}
}
}
func9();
return 0;
}

original_code:
int
main(int argc, char** argv)
{
    memset(gClientTp, 0, sizeof(gClientTp));
    memset(gClientReported, 0, sizeof(gClientReported));
    int i = 1;
    int val = 0;
    if (argc < 2) {
        print_usage();
        return 0;
    }
    while (i < argc) {
        if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            print_usage();
            return 0;
        }
        else if (!strcmp(argv[i], "-n")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i+1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect number of clients/servers '%s'\n",
                            argv[i+1]);
                return 1;
            }
            gNumClients = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-p")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i+1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect port number '%s'\n",
                            argv[i+1]);
                return 1;
            }
            gPort = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-m")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i+1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect measurement limit '%s'\n",
                            argv[i+1]);
                return 1;
            }
            gNumMeasurements = val;
            i += 2;
            continue;
        }
        else {
            inform_user("Bad parameter! (%s)\n", argv[i]);
            print_usage();
            return 1;
        }
    }
    if (gPort == -1) {
        inform_user("Bad port number! (%d)\n", gPort);
        print_usage();
        return 1;
    }
    return start_aggregating();
}

canonical_original_code:
int main(int argc, char **argv)
{
    memset(gClientTp, 0, sizeof(gClientTp));
    memset(gClientReported, 0, sizeof(gClientReported));
    int i = 1;
    int val = 0;
    if (argc < 2) {
        print_usage();
        return 0;
    }
    while (i < argc) {
        if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            print_usage();
            return 0;
        }
        else if (!strcmp(argv[i], "-n")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i+1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect number of clients/servers '%s'\n",
                            argv[i+1]);
                return 1;
            }
            gNumClients = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-p")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i+1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect port number '%s'\n",
                            argv[i+1]);
                return 1;
            }
            gPort = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-m")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i+1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect measurement limit '%s'\n",
                            argv[i+1]);
                return 1;
            }
            gNumMeasurements = val;
            i += 2;
            continue;
        }
        else {
            inform_user("Bad parameter! (%s)\n", argv[i]);
            print_usage();
            return 1;
        }
    }
    if (gPort == -1) {
        inform_user("Bad port number! (%d)\n", gPort);
        print_usage();
        return 1;
    }
    return start_aggregating();
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: val int

return_type: int


decompiled_code:
__int64 __fastcall get_size(char *s)
{
__int64 result; // rax
unsigned int v2; // eax
int v3; // edx

if ( strchr(s, 107) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
return 0LL;
LABEL_15:
fprintf(stderr, "ERROR: Incorrect value '%s'\n", s);
return 0xFFFFFFFFLL;
}
if ( strchr(s, 77) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
return 0LL;
goto LABEL_15;
}
if ( strchr(s, 71) )
{
v2 = __isoc99_sscanf();
if ( v2 == 1 )
{
result = 0LL;
}
else
{
fprintf(stderr, "ERROR: Incorrect value '%s' (%d)\n", s, v2);
result = 0xFFFFFFFFLL;
}
}
else
{
v3 = __isoc99_sscanf();
result = 0LL;
if ( v3 != 1 )
goto LABEL_15;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s)
{
__int64 result; // rax
unsigned int v2; // eax
int v3; // edx

if ( strchr(s, 107) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
return 0LL;
LABEL_15:
fprintf(stderr, "ERROR: Incorrect value '%s'\n", s);
return 0xFFFFFFFFLL;
}
if ( strchr(s, 77) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
return 0LL;
goto LABEL_15;
}
if ( strchr(s, 71) )
{
v2 = __isoc99_sscanf();
if ( v2 == 1 )
{
result = 0LL;
}
else
{
fprintf(stderr, "ERROR: Incorrect value '%s' (%d)\n", s, v2);
result = 0xFFFFFFFFLL;
}
}
else
{
v3 = __isoc99_sscanf();
result = 0LL;
if ( v3 != 1 )
goto LABEL_15;
}
return result;
}

original_code:
static uint32_t
get_size(char* str)
{
  uint32_t val = 0;
  if (strchr(str, 'k')) {
    if (sscanf(str, "%u%*c", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return (val * 1024);
  }
  else if (strchr(str, 'M')) {
    if (sscanf(str, "%u%*c", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return (val * 1024 * 1024);
  }
  else if (strchr(str, 'G')) {
    int res = sscanf(str, "%uG", &val);
    if (res != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s' (%d)\n", str, res);
      return -1;
    }
    return (val * 1024 * 1024 * 1024);
  }
  else {
    if (sscanf(str, "%u", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return val;
  }
}

canonical_original_code:
static unsigned int get_size(char *str)
{
  unsigned int val = 0;
  if (strchr(str, 'k')) {
    if (sscanf(str, "%u%*c", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return (val * 1024);
  }
  else if (strchr(str, 'M')) {
    if (sscanf(str, "%u%*c", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return (val * 1024 * 1024);
  }
  else if (strchr(str, 'G')) {
    int res = sscanf(str, "%uG", &val);
    if (res != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s' (%d)\n", str, res);
      return -1;
    }
    return (val * 1024 * 1024 * 1024);
  }
  else {
    if (sscanf(str, "%u", &val) != 1) {
      fprintf(stderr, "ERROR: Incorrect value '%s'\n", str);
      return -1;
    }
    return val;
  }
}

variable_types:
str
char *

variable_types:
val
unsigned int

variable_types: res int

return_type: unsigned int


decompiled_code:
size_t print_version()
{
return fwrite(
"fstest (Torpman's Test Tools) 0.1\n"
"Copyright (C) 2012 Peter Torpman (peter@torpman.se)\n"
"This is free software. \n"
"You may redistribute copies of it under the terms of the GNU General Public License \n"
"<http://www.gnu.org/licenses/gpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n",
1uLL,
0x122uLL,
stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite(
"fstest (Torpman's Test Tools) 0.1\n"
"Copyright (C) 2012 Peter Torpman (peter@torpman.se)\n"
"This is free software. \n"
"You may redistribute copies of it under the terms of the GNU General Public License \n"
"<http://www.gnu.org/licenses/gpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n",
1uLL,
0x122uLL,
stderr);
}

original_code:
static void
print_version(void)
{
    fprintf(stderr,
            "fstest (Torpman's Test Tools) 0.1\n"
            "Copyright (C) 2012 Peter Torpman (peter@torpman.se)\n"
            "This is free software.  \nYou may redistribute copies of it under "
            "the terms of the GNU General Public License \n"
            "<http://www.gnu.org/licenses/gpl.html>.\n"
            "There is NO WARRANTY, to the extent permitted by law.\n");
}

canonical_original_code:
static void print_version()
{
    fprintf(stderr,
            "fstest (Torpman's Test Tools) 0.1\n"
            "Copyright (C) 2012 Peter Torpman (peter@torpman.se)\n"
            "This is free software.  \nYou may redistribute copies of it under "
            "the terms of the GNU General Public License \n"
            "<http://www.gnu.org/licenses/gpl.html>.\n"
            "There is NO WARRANTY, to the extent permitted by law.\n");
}

return_type: void


decompiled_code:
size_t print_usage()
{
return fwrite(
"Usage: fstest [options]\n"
" Options:\n"
" -r Read test\n"
" -w Write test\n"
" -d Delete test\n"
" -s <size> Size in bytes. Can specify using k, M and G.\n"
" -b <size> Number of bytes to read/write per operation. Can specify using k, M and G.\n"
" -t <secs> Duration in seconds. \n"
" -f <name> File name (including path)\n"
" -v Display version information\n"
" -h Display this text\n"
"\n"
"For bug reporting and suggestions, mail peter@torpman.se\n",
1uLL,
0x1CAuLL,
stderr);
}

canonical_decompiled_code:
size_t func8()
{
return fwrite(
"Usage: fstest [options]\n"
" Options:\n"
" -r Read test\n"
" -w Write test\n"
" -d Delete test\n"
" -s <size> Size in bytes. Can specify using k, M and G.\n"
" -b <size> Number of bytes to read/write per operation. Can specify using k, M and G.\n"
" -t <secs> Duration in seconds. \n"
" -f <name> File name (including path)\n"
" -v Display version information\n"
" -h Display this text\n"
"\n"
"For bug reporting and suggestions, mail peter@torpman.se\n",
1uLL,
0x1CAuLL,
stderr);
}

original_code:
static void
print_usage(void)
{
    fprintf(stderr,
            "Usage: fstest [options]\n"
            "  Options:\n"
            "  -r         Read test\n"
            "  -w         Write test\n"
            "  -d         Delete test\n"
            "  -s <size>  Size in bytes. Can specify using k, M and G.\n"
            "  -b <size>  Number of bytes to read/write per operation. "
            "Can specify using k, M and G.\n"
            "  -t <secs>  Duration in seconds. \n"
            "  -f <name>  File name (including path)\n"
            "  -v         Display version information\n"
            "  -h         Display this text\n\n"
            "For bug reporting and suggestions, mail peter@torpman.se\n");
}

canonical_original_code:
static void print_usage()
{
    fprintf(stderr,
            "Usage: fstest [options]\n"
            "  Options:\n"
            "  -r         Read test\n"
            "  -w         Write test\n"
            "  -d         Delete test\n"
            "  -s <size>  Size in bytes. Can specify using k, M and G.\n"
            "  -b <size>  Number of bytes to read/write per operation. "
            "Can specify using k, M and G.\n"
            "  -t <secs>  Duration in seconds. \n"
            "  -f <name>  File name (including path)\n"
            "  -v         Display version information\n"
            "  -h         Display this text\n\n"
            "For bug reporting and suggestions, mail peter@torpman.se\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int result; // eax
__int64 v6; // r14
const char *v7; // rbx
const char **v8; // rbx
int v9; // eax
const char **v10; // rbx
int v11; // eax
const char **v12; // rbx
const char *v13; // rsi
int v14; // [rsp+Ch] [rbp-3Ch]

strcpy(gTestFile, "/tmp/fstest.tmp");
v14 = 0;
v4 = 1;
if ( argc > 1 )
{
while ( 1 )
{
v6 = v4;
v7 = argv[v6];
if ( !strcmp(v7, "-h") || !strcmp(argv[v4], "--help") )
break;
if ( !strcmp(argv[v4], "-v") || !strcmp(argv[v4], "--version") )
{
print_version();
return 0;
}
if ( !strcmp(argv[v4], "-r") )
{
gTestType = 0;
++v4;
}
else if ( !strcmp(argv[v4], "-w") )
{
gTestType = 1;
++v4;
}
else if ( !strcmp(argv[v4], "-s") )
{
v8 = &argv[v6 + 1];
if ( !*v8 )
goto LABEL_36;
v9 = get_size((char *)*v8);
v14 = v9;
if ( v9 <= 0 )
{
fprintf(stderr, "ERROR: Incorrect size value '%s'\n", *v8);
return 1;
}
gFileSize = v9;
v4 += 2;
}
else if ( !strcmp(argv[v4], "-b") )
{
v10 = &argv[v6 + 1];
if ( !*v10 )
goto LABEL_36;
v11 = get_size((char *)*v10);
v14 = v11;
if ( v11 <= 0 )
{
fprintf(stderr, "ERROR: Incorrect block size value '%s'\n", *v10);
return 1;
}
gBlockSize = v11;
v4 += 2;
}
else if ( !strcmp(argv[v4], "-t") )
{
v12 = &argv[v6 + 1];
if ( !*v12 )
goto LABEL_36;
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
fprintf(stderr, "ERROR: Incorrect duration value '%s'\n", *v12);
return 1;
}
gDuration = v14;
v4 += 2;
}
else
{
if ( strcmp(argv[v4], "-f") )
{
fprintf(stderr, "Bad parameter! (%s)\n", v7);
print_usage();
return 1;
}
v13 = argv[v6 + 1];
if ( !v13 )
{
LABEL_36:
print_usage();
return 1;
}
strcpy(gTestFile, v13);
if ( !access(gTestFile, 0) )
{
fprintf(stderr, "ERROR: File exists (%s)\n", gTestFile);
return 1;
}
v4 += 2;
}
if ( v4 >= argc )
{
fprintf(
stderr,
"* Using file size %u bytes (%ukB %uMB %uGB). Duration: %u seconds.\n",
gFileSize,
gFileSize >> 10,
gFileSize >> 20,
gFileSize >> 30,
gDuration);
if ( gTestType )
{
if ( gTestType == 1 )
run_write_test();
result = 0;
}
else
{
run_read_test();
result = 0;
}
return result;
}
}
}
print_usage();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int result; // eax
__int64 v6; // r14
const char *v7; // rbx
const char **v8; // rbx
int v9; // eax
const char **v10; // rbx
int v11; // eax
const char **v12; // rbx
const char *v13; // rsi
int v14; // [rsp+Ch] [rbp-3Ch]

strcpy(gTestFile, "/tmp/fstest.tmp");
v14 = 0;
v4 = 1;
if ( argc > 1 )
{
while ( 1 )
{
v6 = v4;
v7 = argv[v6];
if ( !strcmp(v7, "-h") || !strcmp(argv[v4], "--help") )
break;
if ( !strcmp(argv[v4], "-v") || !strcmp(argv[v4], "--version") )
{
func7();
return 0;
}
if ( !strcmp(argv[v4], "-r") )
{
gTestType = 0;
++v4;
}
else if ( !strcmp(argv[v4], "-w") )
{
gTestType = 1;
++v4;
}
else if ( !strcmp(argv[v4], "-s") )
{
v8 = &argv[v6 + 1];
if ( !*v8 )
goto LABEL_36;
v9 = func9((char *)*v8);
v14 = v9;
if ( v9 <= 0 )
{
fprintf(stderr, "ERROR: Incorrect size value '%s'\n", *v8);
return 1;
}
gFileSize = v9;
v4 += 2;
}
else if ( !strcmp(argv[v4], "-b") )
{
v10 = &argv[v6 + 1];
if ( !*v10 )
goto LABEL_36;
v11 = func9((char *)*v10);
v14 = v11;
if ( v11 <= 0 )
{
fprintf(stderr, "ERROR: Incorrect block size value '%s'\n", *v10);
return 1;
}
gBlockSize = v11;
v4 += 2;
}
else if ( !strcmp(argv[v4], "-t") )
{
v12 = &argv[v6 + 1];
if ( !*v12 )
goto LABEL_36;
if ( (unsigned int)__isoc99_sscanf() != 1 )
{
fprintf(stderr, "ERROR: Incorrect duration value '%s'\n", *v12);
return 1;
}
gDuration = v14;
v4 += 2;
}
else
{
if ( strcmp(argv[v4], "-f") )
{
fprintf(stderr, "Bad parameter! (%s)\n", v7);
func8();
return 1;
}
v13 = argv[v6 + 1];
if ( !v13 )
{
LABEL_36:
func8();
return 1;
}
strcpy(gTestFile, v13);
if ( !access(gTestFile, 0) )
{
fprintf(stderr, "ERROR: File exists (%s)\n", gTestFile);
return 1;
}
v4 += 2;
}
if ( v4 >= argc )
{
fprintf(
stderr,
"* Using file size %u bytes (%ukB %uMB %uGB). Duration: %u seconds.\n",
gFileSize,
gFileSize >> 10,
gFileSize >> 20,
gFileSize >> 30,
gDuration);
if ( gTestType )
{
if ( gTestType == 1 )
func11();
result = 0;
}
else
{
func10();
result = 0;
}
return result;
}
}
}
func8();
return 0;
}

original_code:
int
main(int argc, char** argv)
{
  strcpy(gTestFile, "/tmp/fstest.tmp");
  int i = 1;
  int val = 0;
  if (argc < 2) {
    print_usage();
    return 0;
  }
  while (i < argc) {
    if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
      print_usage();
      return 0;
    }
    else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
      print_version();
      return 0;
    }
    else if (!strcmp(argv[i], "-r")) {
      gTestType = TEST_TYPE_READ;
      i++;
      continue;
    }
    else if (!strcmp(argv[i], "-w")) {
      gTestType = TEST_TYPE_WRITE;
      i++;
      continue;
    }
    else if (!strcmp(argv[i], "-s")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      val = get_size(argv[i+1]);
      if (val <= 0) {
        fprintf(stderr, "ERROR: Incorrect size value '%s'\n", argv[i+1]);
        return 1;
      }
      gFileSize = (uint32_t) val;
      i += 2;
    }
    else if (!strcmp(argv[i], "-b")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      val = get_size(argv[i+1]);
      if (val <= 0) {
        fprintf(stderr, "ERROR: Incorrect block size value '%s'\n", argv[i+1]);
        return 1;
      }
      gBlockSize = (uint32_t) val;
      i += 2;
    }
    else if (!strcmp(argv[i], "-t")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      if (sscanf(argv[i+1], "%u", &val) != 1) {
        fprintf(stderr, "ERROR: Incorrect duration value '%s'\n", argv[i+1]);
        return 1;
      }
      gDuration = val;
      i += 2;
    }
    else if (!strcmp(argv[i], "-f")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      strcpy(gTestFile, argv[i+1]);
      if (access(gTestFile, 0) == 0) {
        fprintf(stderr, "ERROR: File exists (%s)\n", gTestFile);
        return 1;
      }
      i += 2;
    }
    else {
      fprintf(stderr, "Bad parameter! (%s)\n", argv[i]);
      print_usage();
      return 1;
    }
  }
  fprintf(stderr, "* Using file size %u bytes (%ukB %uMB %uGB). Duration: %u seconds.\n",
          gFileSize, gFileSize / 1024, gFileSize / (1024 * 1024),
          gFileSize / (1024 * 1024 * 1024), gDuration);
  switch (gTestType) {
  case TEST_TYPE_READ:
    run_read_test();
    break;
  case TEST_TYPE_WRITE:
    run_write_test();
    break;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  strcpy(gTestFile, "/tmp/fstest.tmp");
  int i = 1;
  int val = 0;
  if (argc < 2) {
    print_usage();
    return 0;
  }
  while (i < argc) {
    if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
      print_usage();
      return 0;
    }
    else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
      print_version();
      return 0;
    }
    else if (!strcmp(argv[i], "-r")) {
      gTestType = TEST_TYPE_READ;
      i++;
      continue;
    }
    else if (!strcmp(argv[i], "-w")) {
      gTestType = TEST_TYPE_WRITE;
      i++;
      continue;
    }
    else if (!strcmp(argv[i], "-s")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      val = get_size(argv[i+1]);
      if (val <= 0) {
        fprintf(stderr, "ERROR: Incorrect size value '%s'\n", argv[i+1]);
        return 1;
      }
      gFileSize = (unsigned int) val;
      i += 2;
    }
    else if (!strcmp(argv[i], "-b")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      val = get_size(argv[i+1]);
      if (val <= 0) {
        fprintf(stderr, "ERROR: Incorrect block size value '%s'\n", argv[i+1]);
        return 1;
      }
      gBlockSize = (unsigned int) val;
      i += 2;
    }
    else if (!strcmp(argv[i], "-t")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      if (sscanf(argv[i+1], "%u", &val) != 1) {
        fprintf(stderr, "ERROR: Incorrect duration value '%s'\n", argv[i+1]);
        return 1;
      }
      gDuration = val;
      i += 2;
    }
    else if (!strcmp(argv[i], "-f")) {
      if (argv[i + 1] == ((void *)0)) {
        print_usage();
        return 1;
      }
      strcpy(gTestFile, argv[i+1]);
      if (access(gTestFile, 0) == 0) {
        fprintf(stderr, "ERROR: File exists (%s)\n", gTestFile);
        return 1;
      }
      i += 2;
    }
    else {
      fprintf(stderr, "Bad parameter! (%s)\n", argv[i]);
      print_usage();
      return 1;
    }
  }
  fprintf(stderr, "* Using file size %u bytes (%ukB %uMB %uGB). Duration: %u seconds.\n",
          gFileSize, gFileSize / 1024, gFileSize / (1024 * 1024),
          gFileSize / (1024 * 1024 * 1024), gDuration);
  switch (gTestType) {
  case TEST_TYPE_READ:
    run_read_test();
    break;
  case TEST_TYPE_WRITE:
    run_write_test();
    break;
  }
  return 0;
}


decompiled_code:
void __fastcall allocate_clients(int a1)
{
char *v1; // rbx
char *v2; // rax

if ( a1 > 0 )
{
v1 = (char *)&gClients;
do
{
v2 = (char *)malloc(0x60uLL);
*(_QWORD *)v1 = v2;
pthread_mutex_init((pthread_mutex_t *)(v2 + 24), 0LL);
v1 += 8;
}
while ( v1 != (char *)&gClients + 8 * (unsigned int)(a1 - 1) + 8 );
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
char *v1; // rbx
char *v2; // rax

if ( a1 > 0 )
{
v1 = (char *)&gClients;
do
{
v2 = (char *)malloc(0x60uLL);
*(_QWORD *)v1 = v2;
pthread_mutex_init((pthread_mutex_t *)(v2 + 24), 0LL);
v1 += 8;
}
while ( v1 != (char *)&gClients + 8 * (unsigned int)(a1 - 1) + 8 );
}
}

original_code:
static void
allocate_clients(uint32_t num)
{
    for (int i = 0; i < (int)num; i++) {
        gClients[i] = (client_data_t*)malloc(sizeof(client_data_t));
        pthread_mutex_init(&gClients[i]->mutex, ((void *)0));
    }
}

canonical_original_code:
static void allocate_clients(unsigned int num)
{
    for (int i = 0; i < (int)num; i++) {
        gClients[i] = (struct client_data_t *)malloc(sizeof(client_data_t));
        pthread_mutex_init(&gClients[i]->mutex, ((void *)0));
    }
}

variable_types:
num
unsigned int

user_defined_types: struct client_data_t { int sock; int clientNum; int port; unsigned long thread; union pthread_mutex_t mutex; unsigned long numSinceStart; unsigned long numSinceMeasure; struct sockaddr_in serverAddress; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

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 __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall connect_to_server(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
int *v5; // rax
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
int optval; // [rsp+18h] [rbp-20h] BYREF
struct in_addr inp; // [rsp+1Ch] [rbp-1Ch] BYREF

optval = 1;
*(_QWORD *)&v6.sa_family = 0LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
if ( inet_aton(a1, &inp) )
{
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
{
debug_print("ERROR: Failed to open socket!\n");
v3 = -1;
}
else
{
setsockopt(v2, 1, 2, &optval, 4u);
v6.sa_family = 2;
*(struct in_addr *)&v6.sa_data[2] = inp;
*(_WORD *)v6.sa_data = _bswap_16(a2);
if ( connect(v3, &v6, 0x10u) < 0 )
{
v5 = _errno_location();
debug_print("ERROR: Failed to connect socket! errno=%d\n", (unsigned int)*v5);
perror("Could not connect socket");
v3 = -1;
}
}
}
else
{
debug_print("ERROR: Unknown server address!\n");
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
int *v5; // rax
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
int optval; // [rsp+18h] [rbp-20h] BYREF
struct in_addr inp; // [rsp+1Ch] [rbp-1Ch] BYREF

optval = 1;
*(_QWORD *)&v6.sa_family = 0LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
if ( inet_aton(a1, &inp) )
{
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
{
debug_print("ERROR: Failed to open socket!\n");
v3 = -1;
}
else
{
setsockopt(v2, 1, 2, &optval, 4u);
v6.sa_family = 2;
*(struct in_addr *)&v6.sa_data[2] = inp;
*(_WORD *)v6.sa_data = func1(a2);
if ( connect(v3, &v6, 0x10u) < 0 )
{
v5 = _errno_location();
debug_print("ERROR: Failed to connect socket! errno=%d\n", (unsigned int)*v5);
perror("Could not connect socket");
v3 = -1;
}
}
}
else
{
debug_print("ERROR: Unknown server address!\n");
v3 = -1;
}
return v3;
}

original_code:
static int
connect_to_server(char* serverIp, uint32_t serverPort)
{
    struct hostent* he;
    struct in_addr inAddr;
    int sock = -1;
    int reuse = 1;
    int res = 0;
    struct sockaddr_in sinAddr;
    memset(&sinAddr, 0, sizeof(struct sockaddr_in));
    if (inet_aton(serverIp, &inAddr) == 0) {
        debug_print("ERROR: Unknown server address!\n");
        return -1;
    }
    sock = socket(2, SOCK_STREAM, 0);
    if (sock < 0) {
        debug_print("ERROR: Failed to open socket!\n");
        return -1;
    }
    setsockopt(sock, 1, 2, (char*)&reuse, sizeof(reuse));
    sinAddr.sin_family = 2;
    sinAddr.sin_addr = inAddr;
    sinAddr.sin_port = htons(serverPort);
    res = connect(sock, (struct sockaddr*)&sinAddr, sizeof(struct sockaddr));
    if (res < 0) {
        debug_print("ERROR: Failed to connect socket! errno=%d\n", (*__errno_location ()));
        perror("Could not connect socket");
        return -1;
    }
    return sock;
}

canonical_original_code:
static int connect_to_server(char *serverIp, unsigned int serverPort)
{
    struct hostent *he;
    struct in_addr inAddr;
    int sock = -1;
    int reuse = 1;
    int res = 0;
    struct sockaddr_in sinAddr;
    memset(&sinAddr, 0, sizeof(struct sockaddr_in));
    if (inet_aton(serverIp, &inAddr) == 0) {
        debug_print("ERROR: Unknown server address!\n");
        return -1;
    }
    sock = socket(2, SOCK_STREAM, 0);
    if (sock < 0) {
        debug_print("ERROR: Failed to open socket!\n");
        return -1;
    }
    setsockopt(sock, 1, 2, (char *)&reuse, sizeof(reuse));
    sinAddr.sin_family = 2;
    sinAddr.sin_addr = inAddr;
    sinAddr.sin_port = htons(serverPort);
    res = connect(sock, (struct sockaddr *)&sinAddr, sizeof(struct sockaddr));
    if (res < 0) {
        debug_print("ERROR: Failed to connect socket! errno=%d\n", (*__errno_location ()));
        perror("Could not connect socket");
        return -1;
    }
    return sock;
}

variable_types:
serverIp
char *

variable_types:
serverPort
unsigned int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
inAddr
struct in_addr { unsigned int s_addr; }

variable_types: sock int

variable_types: reuse int

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

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


decompiled_code:
__int64 __fastcall connect_clients(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int v3; // eax

if ( a1 <= 0 )
return 0LL;
v1 = 0LL;
while ( 1 )
{
v2 = gClients[v1];
*(_QWORD *)v2 = 0LL;
*(_QWORD *)(v2 + 88) = 0LL;
memset(
(void *)((v2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 96) >> 3));
*(_DWORD *)(v2 + 4) = v1;
v3 = connect_to_server((const char *)(gAppArgs + 10), *(_WORD *)(gAppArgs + 8));
*(_DWORD *)v2 = v3;
if ( v3 < 0 )
break;
if ( ++v1 == a1 )
return 0LL;
}
debug_print("ERROR: Could not open socket (%d)!\n", (unsigned int)v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int v3; // eax

if ( a1 <= 0 )
return 0LL;
v1 = 0LL;
while ( 1 )
{
v2 = gClients[v1];
*(_QWORD *)v2 = 0LL;
*(_QWORD *)(v2 + 88) = 0LL;
memset(
(void *)((v2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 96) >> 3));
*(_DWORD *)(v2 + 4) = v1;
v3 = func2((const char *)(gAppArgs + 10), *(_WORD *)(gAppArgs + 8));
*(_DWORD *)v2 = v3;
if ( v3 < 0 )
break;
if ( ++v1 == a1 )
return 0LL;
}
debug_print("ERROR: Could not open socket (%d)!\n", (unsigned int)v1);
return 1LL;
}

original_code:
static int
connect_clients(uint32_t num)
{
    for (int i = 0; i < (int)num; i++) {
        client_data_t* cliData = gClients[i];
        memset(cliData, 0, sizeof(client_data_t));
        cliData->clientNum = i;
        cliData->sock = connect_to_server(gAppArgs->serverIp, gAppArgs->serverPort);
        if (cliData->sock < 0) {
            debug_print("ERROR: Could not open socket (%d)!\n", i);
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
static int connect_clients(unsigned int num)
{
    for (int i = 0; i < (int)num; i++) {
        struct client_data_t *cliData = gClients[i];
        memset(cliData, 0, sizeof(client_data_t));
        cliData->clientNum = i;
        cliData->sock = connect_to_server(gAppArgs->serverIp, gAppArgs->serverPort);
        if (cliData->sock < 0) {
            debug_print("ERROR: Could not open socket (%d)!\n", i);
            return 1;
        }
    }
    return 0;
}

variable_types: struct client_data_t { int sock; int clientNum; int port; unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long numSinceStart; unsigned long numSinceMeasure; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } serverAddress; } *


decompiled_code:
__int64 __fastcall create_client_udp_sockets(int a1)
{
__int64 v1; // rbp
int *v2; // rbx
__int64 v3; // rbx
__int64 v4; // r12

if ( !a1 )
return 0LL;
v1 = 0LL;
while ( 1 )
{
v2 = (int *)gClients[v1];
*v2 = socket(2, 2, 17);
v3 = gClients[v1];
if ( *(int *)v3 < 0 )
break;
*(_WORD *)(v3 + 80) = 2;
v4 = gAppArgs;
*(_WORD *)(v3 + 82) = _bswap_16(*(_WORD *)(gAppArgs + 8) + v1);
inet_pton(2, (const char *)(v4 + 10), (void *)(v3 + 84));
if ( ++v1 == a1 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 v1; // rbp
int *v2; // rbx
__int64 v3; // rbx
__int64 v4; // r12

if ( !a1 )
return 0LL;
v1 = 0LL;
while ( 1 )
{
v2 = (int *)gClients[v1];
*v2 = socket(2, 2, 17);
v3 = gClients[v1];
if ( *(int *)v3 < 0 )
break;
*(_WORD *)(v3 + 80) = 2;
v4 = gAppArgs;
*(_WORD *)(v3 + 82) = func1(*(_WORD *)(gAppArgs + 8) + v1);
inet_pton(2, (const char *)(v4 + 10), (void *)(v3 + 84));
if ( ++v1 == a1 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
static int create_client_udp_sockets(uint32_t num)
{
    for (uint32_t i = 0; i < num; i++) {
        gClients[i]->sock = socket(2, SOCK_DGRAM, IPPROTO_UDP);
        if (gClients[i]->sock < 0) {
            return -1;
        }
        struct sockaddr_in* sinAddr = &gClients[i]->serverAddress;
        sinAddr->sin_family = 2;
        sinAddr->sin_port = htons(gAppArgs->serverPort + i);
        inet_pton(2, gAppArgs->serverIp, &sinAddr->sin_addr.s_addr);
    }
    return 0;
}

canonical_original_code:
static int create_client_udp_sockets(unsigned int num)
{
    for (unsigned int i = 0; i < num; i++) {
        gClients[i]->sock = socket(2, SOCK_DGRAM, IPPROTO_UDP);
        if (gClients[i]->sock < 0) {
            return -1;
        }
        struct sockaddr_in *sinAddr = &gClients[i]->serverAddress;
        sinAddr->sin_family = 2;
        sinAddr->sin_port = htons(gAppArgs->serverPort + i);
        inet_pton(2, gAppArgs->serverIp, &sinAddr->sin_addr.s_addr);
    }
    return 0;
}

variable_types:
i
unsigned int

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


decompiled_code:
int __fastcall adjust_traffic(double a1)
{
int result; // eax
double v2; // xmm0_8
double v3; // xmm1_8

result = *(_DWORD *)(gAppArgs + 268);
if ( result )
{
v2 = a1 * 0.0009765625;
v3 = (double)result;
if ( v2 <= (double)result )
{
if ( v3 > v2 && v3 - v2 > v3 * 0.01 )
{
pthread_mutex_lock(&gMutexRate);
gBytesToSend = (unsigned int)(int)((v3 - v2) * 0.25 / (double)*(int *)(gAppArgs + 272)
+ (double)(int)gBytesToSend);
result = pthread_mutex_unlock(&gMutexRate);
}
}
else if ( v2 - v3 > v3 * 0.01 )
{
pthread_mutex_lock(&gMutexRate);
gBytesToSend = (unsigned int)(int)((double)(int)gBytesToSend - (v2 - v3) * 0.25 / (double)*(int *)(gAppArgs + 272));
result = pthread_mutex_unlock(&gMutexRate);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(double a1)
{
int result; // eax
double v2; // xmm0_8
double v3; // xmm1_8

result = *(_DWORD *)(gAppArgs + 268);
if ( result )
{
v2 = a1 * 0.0009765625;
v3 = (double)result;
if ( v2 <= (double)result )
{
if ( v3 > v2 && v3 - v2 > v3 * 0.01 )
{
pthread_mutex_lock(&gMutexRate);
gBytesToSend = (unsigned int)(int)((v3 - v2) * 0.25 / (double)*(int *)(gAppArgs + 272)
+ (double)(int)gBytesToSend);
result = pthread_mutex_unlock(&gMutexRate);
}
}
else if ( v2 - v3 > v3 * 0.01 )
{
pthread_mutex_lock(&gMutexRate);
gBytesToSend = (unsigned int)(int)((double)(int)gBytesToSend - (v2 - v3) * 0.25 / (double)*(int *)(gAppArgs + 272));
result = pthread_mutex_unlock(&gMutexRate);
}
}
return result;
}

original_code:
static void
adjust_traffic(double tPutNow)
{
    double diff;
    if (gAppArgs->wantedThroughput > 0 && (tPutNow / 1024) > gAppArgs->wantedThroughput) {
        diff = (tPutNow / 1024) - gAppArgs->wantedThroughput;
        if (diff > (0.01 * gAppArgs->wantedThroughput)) {
            pthread_mutex_lock(&gMutexRate);
            gBytesToSend = gBytesToSend - ((0.25 * diff) / gAppArgs->numConnections);
            if (gBytesToSend < 0) {
                gBytesToSend = 1;
            }
            pthread_mutex_unlock(&gMutexRate);
        }
    }
    else if (gAppArgs->wantedThroughput > 0 && (tPutNow / 1024) < gAppArgs->wantedThroughput) {
        diff = gAppArgs->wantedThroughput - (tPutNow / 1024);
        if (diff > (0.01 * gAppArgs->wantedThroughput)) {
            pthread_mutex_lock(&gMutexRate);
            gBytesToSend = gBytesToSend + ((0.25 * diff) / gAppArgs->numConnections);
            pthread_mutex_unlock(&gMutexRate);
        }
    }
}

variable_types: tPutNow double

variable_types: diff double


decompiled_code:
__int64 __fastcall create_client_threads(int a1)
{
__int64 v1; // rbp
__int64 result; // rax
_QWORD *v3; // rbx
pthread_attr_t v4[2]; // [rsp+0h] [rbp-78h] BYREF

pthread_mutex_lock(&gMutex);
if ( pthread_create(&gTpThread, 0LL, tp_thread, 0LL) < 0 )
{
debug_print("ERROR: Failed to start throughput thread!\n");
result = 1LL;
}
else
{
v1 = 0LL;
if ( a1 <= 0 )
{
LABEL_5:
pthread_mutex_unlock(&gMutex);
result = 0LL;
}
else
{
while ( 1 )
{
pthread_attr_init(v4);
pthread_attr_setdetachstate(v4, 1);
pthread_attr_setscope(v4, 0);
if ( pthread_create((pthread_t *)(gClients[v1] + 16LL), v4, send_thread, (void *)gClients[v1]) )
break;
if ( ++v1 == a1 )
goto LABEL_5;
}
v3 = gClients;
debug_print("* Failed to create sender #%d\n", *(unsigned int *)(gClients[(int)v1] + 4LL));
perror("Thread error!");
gDoExit = 1;
do
pthread_join(*(_QWORD *)(*v3++ + 16LL), 0LL);
while ( v3 != &gClients[(unsigned int)(a1 - 1) + 1] );
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rbp
__int64 result; // rax
_QWORD *v3; // rbx
pthread_attr_t v4[2]; // [rsp+0h] [rbp-78h] BYREF

pthread_mutex_lock(&gMutex);
if ( pthread_create(&gTpThread, 0LL, tp_thread, 0LL) < 0 )
{
debug_print("ERROR: Failed to start throughput thread!\n");
result = 1LL;
}
else
{
v1 = 0LL;
if ( a1 <= 0 )
{
LABEL_5:
pthread_mutex_unlock(&gMutex);
result = 0LL;
}
else
{
while ( 1 )
{
pthread_attr_init(v4);
pthread_attr_setdetachstate(v4, 1);
pthread_attr_setscope(v4, 0);
if ( pthread_create((pthread_t *)(gClients[v1] + 16LL), v4, send_thread, (void *)gClients[v1]) )
break;
if ( ++v1 == a1 )
goto LABEL_5;
}
v3 = gClients;
debug_print("* Failed to create sender #%d\n", *(unsigned int *)(gClients[(int)v1] + 4LL));
perror("Thread error!");
gDoExit = 1;
do
pthread_join(*(_QWORD *)(*v3++ + 16LL), 0LL);
while ( v3 != &gClients[(unsigned int)(a1 - 1) + 1] );
result = 1LL;
}
}
return result;
}

original_code:
static int
create_client_threads(uint32_t num)
{
    int res = 0;
    pthread_mutex_lock(&gMutex);
    res = pthread_create(&gTpThread, ((void *)0), tp_thread, ((void *)0));
    if (res < 0) {
        debug_print("ERROR: Failed to start throughput thread!\n");
        return 1;
    }
    for (int i = 0; i < (int)num; i++) {
        pthread_t t;
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
        res = pthread_create(&gClients[i]->thread, &attr, send_thread, (void*)gClients[i]);
        if (res != 0) {
            debug_print("* Failed to create sender #%d\n", gClients[i]->clientNum);
            perror("Thread error!");
            gDoExit = 1;
            goto outro;
        }
    }
    pthread_mutex_unlock(&gMutex);
    return 0;
outro:
    for (int i = 0; i < (int)num; i++) {
        pthread_join(gClients[i]->thread, ((void *)0));
    }
    return 1;
}

canonical_original_code:
static int create_client_threads(unsigned int num)
{
    int res = 0;
    pthread_mutex_lock(&gMutex);
    res = pthread_create(&gTpThread, ((void *)0), tp_thread, ((void *)0));
    if (res < 0) {
        debug_print("ERROR: Failed to start throughput thread!\n");
        return 1;
    }
    for (int i = 0; i < (int)num; i++) {
        unsigned long t;
        union pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
        res = pthread_create(&gClients[i]->thread, &attr, send_thread, (void *)gClients[i]);
        if (res != 0) {
            debug_print("* Failed to create sender #%d\n", gClients[i]->clientNum);
            perror("Thread error!");
            gDoExit = 1;
            goto outro;
        }
    }
    pthread_mutex_unlock(&gMutex);
    return 0;
outro:
    for (int i = 0; i < (int)num; i++) {
        pthread_join(gClients[i]->thread, ((void *)0));
    }
    return 1;
}

variable_types: i int

variable_types:
t
unsigned long

variable_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
void __fastcall __noreturn send_thread(void *a1)
{
unsigned int v1; // ebp
int v2; // eax

pthread_mutex_lock(&gMutex);
if ( gDoExit )
pthread_exit(a1);
pthread_mutex_unlock(&gMutex);
if ( *(_WORD *)(gAppArgs + 282) )
v1 = *(unsigned __int16 *)(gAppArgs + 280);
else
v1 = gBytesToSend;
while ( 1 )
{
usleep(0xAu);
if ( gDoExit )
break;
if ( *(_DWORD *)gAppArgs )
v2 = sendto(*(_DWORD *)a1, &gSendBuffer, v1, 0, (const struct sockaddr *)a1 + 5, 0x10u);
else
v2 = send(*(_DWORD *)a1, &gSendBuffer, v1, 0x4000);
if ( v2 > 0 )
{
*((_QWORD *)a1 + 8) += v2;
*((_QWORD *)a1 + 9) += v2;
}
}
debug_print("Client exit\n");
close(*(_DWORD *)a1);
pthread_exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int v1; // ebp
int v2; // eax

pthread_mutex_lock(&gMutex);
if ( gDoExit )
pthread_exit(a1);
pthread_mutex_unlock(&gMutex);
if ( *(_WORD *)(gAppArgs + 282) )
v1 = *(unsigned __int16 *)(gAppArgs + 280);
else
v1 = gBytesToSend;
while ( 1 )
{
usleep(0xAu);
if ( gDoExit )
break;
if ( *(_DWORD *)gAppArgs )
v2 = sendto(*(_DWORD *)a1, &gSendBuffer, v1, 0, (const struct sockaddr *)a1 + 5, 0x10u);
else
v2 = send(*(_DWORD *)a1, &gSendBuffer, v1, 0x4000);
if ( v2 > 0 )
{
*((_QWORD *)a1 + 8) += v2;
*((_QWORD *)a1 + 9) += v2;
}
}
debug_print("Client exit\n");
close(*(_DWORD *)a1);
pthread_exit(a1);
}

original_code:
static void*
send_thread(void* data)
{
    client_data_t* cliData = (client_data_t*)data;
    int res = 0;
    pthread_mutex_lock(&gMutex);
    if (gDoExit) {
        pthread_exit(cliData);
    }
    pthread_mutex_unlock(&gMutex);
    uint32_t bytesToSend = gAppArgs->usedPacketSize > 0 ? gAppArgs->packetSize : gBytesToSend;
    size_t addrSize = sizeof(struct sockaddr_in);
    while (1) {
        usleep(10);
        if (gDoExit) {
            debug_print("Client exit\n");
            close(cliData->sock);
            pthread_exit(cliData);
        }
        if (!gAppArgs->useUdp) {
            res = send(cliData->sock, gSendBuffer, bytesToSend, MSG_NOSIGNAL);
        }
        else {
            res = sendto(cliData->sock, gSendBuffer, bytesToSend, 0, (struct sockaddr*)&cliData->serverAddress, addrSize);
        }
        if (res > 0) {
            cliData->numSinceStart += res;
            cliData->numSinceMeasure += res;
        }
    }
}

canonical_original_code:
static void *send_thread(void *data)
{
    struct client_data_t *cliData = (client_data_t*)data;
    int res = 0;
    pthread_mutex_lock(&gMutex);
    if (gDoExit) {
        pthread_exit(cliData);
    }
    pthread_mutex_unlock(&gMutex);
    unsigned int bytesToSend = gAppArgs->usedPacketSize > 0 ? gAppArgs->packetSize : gBytesToSend;
    unsigned long addrSize = sizeof(struct sockaddr_in);
    while (1) {
        usleep(10);
        if (gDoExit) {
            debug_print("Client exit\n");
            close(cliData->sock);
            pthread_exit(cliData);
        }
        if (!gAppArgs->useUdp) {
            res = send(cliData->sock, gSendBuffer, bytesToSend, MSG_NOSIGNAL);
        }
        else {
            res = sendto(cliData->sock, gSendBuffer, bytesToSend, 0, (struct sockaddr *)&cliData->serverAddress, addrSize);
        }
        if (res > 0) {
            cliData->numSinceStart += res;
            cliData->numSinceMeasure += res;
        }
    }
}

variable_types:
data
void *

variable_types: res int

variable_types:
bytesToSend
unsigned int

variable_types:
addrSize
unsigned long

return_type: void *


decompiled_code:
int __fastcall client_start(__int64 a1)
{
unsigned __int16 v1; // si
__int64 v2; // rax
_DWORD *v3; // rbx
int result; // eax

gAppArgs = a1;
memset(&gSendBuffer, 255, (size_t)&unk_FFFFFF);
v1 = *(_WORD *)(a1 + 280);
if ( v1 )
{
inform_user("* Will send packets of size: %d\n", v1);
v2 = gAppArgs;
*(_DWORD *)(gAppArgs + 268) = 0;
*(_WORD *)(v2 + 282) = *(_WORD *)(v2 + 280) - 18;
}
else
{
inform_user("* Will aim for throughput: %d\n", *(unsigned int *)(a1 + 268));
}
v3 = (_DWORD *)gAppArgs;
allocate_clients(*(_DWORD *)(gAppArgs + 272));
if ( *v3 )
{
if ( (unsigned int)create_client_udp_sockets(v3[68]) )
return inform_user("* Failed to open client sockets\n");
}
else if ( (unsigned int)connect_clients(v3[68]) )
{
return inform_user("* Failed to connect clients\n");
}
if ( (unsigned int)create_client_threads(*(_DWORD *)(gAppArgs + 272)) )
return inform_user("* Failed to create client threads\n");
if ( (unsigned int)get_aggregator_port() )
aggregator_register(*(unsigned int *)(gAppArgs + 284), "127.0.0.1");
debug_print(
"Clients running (conns=%u)...(tp=%u kbps pktsize=%u)\n",
*(unsigned int *)(gAppArgs + 272),
*(unsigned int *)(gAppArgs + 268),
*(unsigned __int16 *)(gAppArgs + 280));
do
result = usleep(0x3E8u);
while ( !gDoExit );
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
unsigned __int16 v1; // si
__int64 v2; // rax
_DWORD *v3; // rbx
int result; // eax

gAppArgs = a1;
memset(&gSendBuffer, 255, (size_t)&unk_FFFFFF);
v1 = *(_WORD *)(a1 + 280);
if ( v1 )
{
inform_user("* Will send packets of size: %d\n", v1);
v2 = gAppArgs;
*(_DWORD *)(gAppArgs + 268) = 0;
*(_WORD *)(v2 + 282) = *(_WORD *)(v2 + 280) - 18;
}
else
{
inform_user("* Will aim for throughput: %d\n", *(unsigned int *)(a1 + 268));
}
v3 = (_DWORD *)gAppArgs;
func0(*(_DWORD *)(gAppArgs + 272));
if ( *v3 )
{
if ( (unsigned int)func4(v3[68]) )
return inform_user("* Failed to open client sockets\n");
}
else if ( (unsigned int)func3(v3[68]) )
{
return inform_user("* Failed to connect clients\n");
}
if ( (unsigned int)func6(*(_DWORD *)(gAppArgs + 272)) )
return inform_user("* Failed to create client threads\n");
if ( (unsigned int)get_aggregator_port() )
aggregator_register(*(unsigned int *)(gAppArgs + 284), "127.0.0.1");
debug_print(
"Clients running (conns=%u)...(tp=%u kbps pktsize=%u)\n",
*(unsigned int *)(gAppArgs + 272),
*(unsigned int *)(gAppArgs + 268),
*(unsigned __int16 *)(gAppArgs + 280));
do
result = usleep(0x3E8u);
while ( !gDoExit );
return result;
}

original_code:
void client_start(app_arg_t* args)
{
    gAppArgs = args;
    int res = 0;
    memset(gSendBuffer, 0xFF, 0xFFFFFF);
    if (gAppArgs->packetSize > 0) {
        inform_user("* Will send packets of size: %d\n", gAppArgs->packetSize);
        gAppArgs->wantedThroughput = 0;
        gAppArgs->usedPacketSize = gAppArgs->packetSize - (14 + 4);
    } else {
        inform_user("* Will aim for throughput: %d\n", gAppArgs->wantedThroughput);
    }
    allocate_clients(gAppArgs->numConnections);
    if (!gAppArgs->useUdp) {
        if (connect_clients(gAppArgs->numConnections) != 0) {
            inform_user("* Failed to connect clients\n");
            return;
        }
    }
    else {
        if (create_client_udp_sockets(gAppArgs->numConnections) != 0) {
            inform_user("* Failed to open client sockets\n");
            return;
        }
    }
    if (create_client_threads(gAppArgs->numConnections) != 0) {
        inform_user("* Failed to create client threads\n");
        return;
    }
    if (get_aggregator_port() != 0) {
        aggregator_register(gAppArgs->processId, "127.0.0.1");
    }
    debug_print("Clients running (conns=%u)...(tp=%u kbps pktsize=%u)\n",
                gAppArgs->numConnections,
                gAppArgs->wantedThroughput,
                gAppArgs->packetSize);
    while (1) {
        usleep(1000);
        if (gDoExit) {
            break;
        }
    }
}

canonical_original_code:
void client_start(struct app_arg_t *args)
{
    gAppArgs = args;
    int res = 0;
    memset(gSendBuffer, 0xFF, 0xFFFFFF);
    if (gAppArgs->packetSize > 0) {
        inform_user("* Will send packets of size: %d\n", gAppArgs->packetSize);
        gAppArgs->wantedThroughput = 0;
        gAppArgs->usedPacketSize = gAppArgs->packetSize - (14 + 4);
    } else {
        inform_user("* Will aim for throughput: %d\n", gAppArgs->wantedThroughput);
    }
    allocate_clients(gAppArgs->numConnections);
    if (!gAppArgs->useUdp) {
        if (connect_clients(gAppArgs->numConnections) != 0) {
            inform_user("* Failed to connect clients\n");
            return;
        }
    }
    else {
        if (create_client_udp_sockets(gAppArgs->numConnections) != 0) {
            inform_user("* Failed to open client sockets\n");
            return;
        }
    }
    if (create_client_threads(gAppArgs->numConnections) != 0) {
        inform_user("* Failed to create client threads\n");
        return;
    }
    if (get_aggregator_port() != 0) {
        aggregator_register(gAppArgs->processId, "127.0.0.1");
    }
    debug_print("Clients running (conns=%u)...(tp=%u kbps pktsize=%u)\n",
                gAppArgs->numConnections,
                gAppArgs->wantedThroughput,
                gAppArgs->packetSize);
    while (1) {
        usleep(1000);
        if (gDoExit) {
            break;
        }
    }
}

variable_types: struct app_arg_t { int useUdp; int isServer; unsigned short serverPort; char serverIp[255]; unsigned int wantedThroughput; int numConnections; int aggregatorPort; unsigned short packetSize; unsigned short usedPacketSize; int processId; } *


decompiled_code:
__int64 client_exit()
{
__int64 result; // rax

result = inform_user("* Client exit\n");
gDoExit = 1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

result = inform_user("* Client exit\n");
gDoExit = 1;
return result;
}

original_code:
void client_exit(int sig)
{
    inform_user("* Client exit\n");
    gDoExit = 1;
}

variable_types: sig int


decompiled_code:
void __fastcall __noreturn tp_thread(void *a1, double a2)
{
struct timeval v2; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
while ( 1 )
{
gettimeofday(&v2, 0LL);
usleep((__useconds_t)&unk_F4240);
if ( gDoExit )
break;
report_statistics(&tv, &v2, gClients, *(unsigned int *)(gAppArgs + 272), *(unsigned int *)(gAppArgs + 284));
if ( !*(_WORD *)(gAppArgs + 280) )
adjust_traffic(a2);
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1, double a2)
{
struct timeval v2; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
while ( 1 )
{
gettimeofday(&v2, 0LL);
usleep((__useconds_t)&unk_F4240);
if ( gDoExit )
break;
report_statistics(&tv, &v2, gClients, *(unsigned int *)(gAppArgs + 272), *(unsigned int *)(gAppArgs + 284));
if ( !*(_WORD *)(gAppArgs + 280) )
func5(a2);
}
pthread_exit(0LL);
}

original_code:
static void*
tp_thread(void* data)
{
    struct timeval startTime;
    struct timeval measurementStartTime;
    gettimeofday(&startTime, ((void *)0));
    while (1) {
        gettimeofday(&measurementStartTime, ((void *)0));
        usleep(1000000);
        if (gDoExit) {
            break;
        }
        double bitsPerSecNow = report_statistics(&startTime, &measurementStartTime,
                                                 gClients, gAppArgs->numConnections,
                                                 gAppArgs->processId);
        if (gAppArgs->packetSize == 0) {
            adjust_traffic(bitsPerSecNow);
        }
    }
    pthread_exit(((void *)0));
}

canonical_original_code:
static void *tp_thread(void *data)
{
    struct timeval startTime;
    struct timeval measurementStartTime;
    gettimeofday(&startTime, ((void *)0));
    while (1) {
        gettimeofday(&measurementStartTime, ((void *)0));
        usleep(1000000);
        if (gDoExit) {
            break;
        }
        double bitsPerSecNow = report_statistics(&startTime, &measurementStartTime,
                                                 gClients, gAppArgs->numConnections,
                                                 gAppArgs->processId);
        if (gAppArgs->packetSize == 0) {
            adjust_traffic(bitsPerSecNow);
        }
    }
    pthread_exit(((void *)0));
}

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

variable_types: bitsPerSecNow double


decompiled_code:
__int64 get_aggregator_port()
{
return (unsigned int)dword_6F4;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)dword_6F4;
}

original_code:
int
get_aggregator_port(void)
{
    return gAppArgs.aggregatorPort;
}

canonical_original_code:
int get_aggregator_port()
{
    return gAppArgs.aggregatorPort;
}


decompiled_code:
__int64 print_version()
{
return inform_user(
"conntest (Torpman's Test Tools) 0.1\n"
"Copyright (C) 2012-2022 Peter Torpman (peter@torpman.se)\n"
"This is free software. \n"
"You may redistribute copies of it under the terms of the GNU General Public License \n"
"<http://www.gnu.org/licenses/gpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n");
}

canonical_decompiled_code:
__int64 func0()
{
return inform_user(
"conntest (Torpman's Test Tools) 0.1\n"
"Copyright (C) 2012-2022 Peter Torpman (peter@torpman.se)\n"
"This is free software. \n"
"You may redistribute copies of it under the terms of the GNU General Public License \n"
"<http://www.gnu.org/licenses/gpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n");
}

original_code:
static void
print_version(void)
{
    inform_user("conntest (Torpman's Test Tools) 0.1\n"
                "Copyright (C) 2012-2022 Peter Torpman (peter@torpman.se)\n"
                "This is free software.  \nYou may redistribute copies of it under "
                "the terms of the GNU General Public License \n"
                "<http://www.gnu.org/licenses/gpl.html>.\n"
                "There is NO WARRANTY, to the extent permitted by law.\n");
}

canonical_original_code:
static void print_version()
{
    inform_user("conntest (Torpman's Test Tools) 0.1\n"
                "Copyright (C) 2012-2022 Peter Torpman (peter@torpman.se)\n"
                "This is free software.  \nYou may redistribute copies of it under "
                "the terms of the GNU General Public License \n"
                "<http://www.gnu.org/licenses/gpl.html>.\n"
                "There is NO WARRANTY, to the extent permitted by law.\n");
}


decompiled_code:
__int64 print_usage()
{
return inform_user(
"Usage: conntest [options]\n"
" Options:\n"
" -id <num> Process ID.\n"
" -s Server mode\n"
" -c Client mode\n"
" -a <port> Aggregator port\n"
" -n <num> Number of connections.\n"
" -t <kbps> Throughput to aim for in kbps\n"
" -l <hostip> Host IP address\n"
" -p <port> Server port number. (Used as base port for UDP communication)\n"
" -z <size> Packet size\n"
" -udp Use UDP communication\n"
" -v Display version information\n"
" -h Display this text\n"
"\n"
"For bug reporting and suggestions, mail peter@torpman.se\n");
}

canonical_decompiled_code:
__int64 func1()
{
return inform_user(
"Usage: conntest [options]\n"
" Options:\n"
" -id <num> Process ID.\n"
" -s Server mode\n"
" -c Client mode\n"
" -a <port> Aggregator port\n"
" -n <num> Number of connections.\n"
" -t <kbps> Throughput to aim for in kbps\n"
" -l <hostip> Host IP address\n"
" -p <port> Server port number. (Used as base port for UDP communication)\n"
" -z <size> Packet size\n"
" -udp Use UDP communication\n"
" -v Display version information\n"
" -h Display this text\n"
"\n"
"For bug reporting and suggestions, mail peter@torpman.se\n");
}

original_code:
static void
print_usage(void)
{
    inform_user("Usage: conntest [options]\n"
                "  Options:\n"
                "  -id <num>   Process ID.\n"
                "  -s          Server mode\n"
                "  -c          Client mode\n"
                "  -a <port>   Aggregator port\n"
                "  -n <num>    Number of connections.\n"
                "  -t <kbps>   Throughput to aim for in kbps\n"
                "  -l <hostip> Host IP address\n"
                "  -p <port>   Server port number. (Used as base port for UDP communication)\n"
                "  -z <size>   Packet size\n"
                "  -udp        Use UDP communication\n"
                "  -v          Display version information\n"
                "  -h          Display this text\n\n"
                "For bug reporting and suggestions, mail peter@torpman.se\n");
}

canonical_original_code:
static void print_usage()
{
    inform_user("Usage: conntest [options]\n"
                "  Options:\n"
                "  -id <num>   Process ID.\n"
                "  -s          Server mode\n"
                "  -c          Client mode\n"
                "  -a <port>   Aggregator port\n"
                "  -n <num>    Number of connections.\n"
                "  -t <kbps>   Throughput to aim for in kbps\n"
                "  -l <hostip> Host IP address\n"
                "  -p <port>   Server port number. (Used as base port for UDP communication)\n"
                "  -z <size>   Packet size\n"
                "  -udp        Use UDP communication\n"
                "  -v          Display version information\n"
                "  -h          Display this text\n\n"
                "For bug reporting and suggestions, mail peter@torpman.se\n");
}


original_code:
int
main(int argc, char **argv)
{
    memset(&gAppArgs, 0, sizeof(app_arg_t));
    strcpy(gAppArgs.serverIp, "127.0.0.1");
    int i = 1;
    int val = 0;
    int procId = -1;
    if (argc < 2)
    {
        print_usage ();
        return 0;
    }
    while (i < argc)
    {
        if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            print_usage ();
            return 0;
        }
        else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
            print_version();
            return 0;
        }
        else if (!strcmp(argv[i], "-s")) {
            gAppArgs.isServer = 1;
            i++;
            continue;
        }
        else if (!strcmp(argv[i], "-c")) {
            gAppArgs.isServer = 0;
            i++;
            continue;
        }
        else if (!strcmp(argv[i], "-udp")) {
            gAppArgs.useUdp = 1;
            i++;
            continue;
        }
        else if (!strcmp(argv[i], "-id")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i + 1], "%d", &val) != 1) {
                inform_user ("ERROR: Incorrect process ID '%s'\n", argv[i + 1]);
                return 1;
            }
            gAppArgs.processId = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-a")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i + 1], "%d", &val) != 1) {
                inform_user("ERROR: Incorrect aggregator port '%s'\n",
                            argv[i + 1]);
                return 1;
            }
            gAppArgs.aggregatorPort = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-n")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i + 1], "%u", &val) != 1) {
                inform_user("ERROR: Incorrect number of connections '%s'\n",
                            argv[i + 1]);
                return 1;
            }
            gAppArgs.numConnections = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-t")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i + 1], "%u", &val) != 1) {
                inform_user("ERROR: Incorrect throughput '%s'\n", argv[i + 1]);
                return 1;
            }
            gAppArgs.wantedThroughput = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-z")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf(argv[i + 1], "%u", &val) != 1) {
                inform_user("ERROR: Incorrect packet size '%s'\n",
                            argv[i + 1]);
                return 1;
            }
            if ((val - (14 + 4)) <= 0) {
                inform_user("ERROR: Packet size minus ethernet header size is <= 0'%s'\n",
                            argv[i + 1]);
                return 1;
            }
            gAppArgs.packetSize = val;
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-l")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            strcpy(gAppArgs.serverIp, argv[i + 1]);
            i += 2;
            continue;
        }
        else if (!strcmp(argv[i], "-p")) {
            if (argv[i + 1] == ((void *)0)) {
                print_usage();
                return 1;
            }
            if (sscanf (argv[i + 1], "%u", &val) != 1) {
                inform_user("ERROR: Incorrect server port '%s'\n",
                            argv[i + 1]);
                return 1;
            }
            gAppArgs.serverPort = val;
            i += 2;
            continue;
        }
        else {
            inform_user("Bad parameter! (%s)\n", argv[i]);
            print_usage();
            return 1;
        }
    }
    if (gAppArgs.processId == -1) {
        inform_user("ERROR: Process ID not specified!\n");
        print_usage();
        return 1;
    }
    if (gAppArgs.isServer) {
        server_start(&gAppArgs);
    }
    else {
        signal(15, client_exit);
        signal(2, client_exit);
        client_start(&gAppArgs);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: val int

variable_types: procId int


decompiled_code:
void __fastcall __noreturn udp_recv_thread(void *a1)
{
int v1; // eax
int v2; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1003Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-10038h] BYREF
char buf[65576]; // [rsp+20h] [rbp-10028h] BYREF

while ( 1 )
{
v1 = recvfrom(*(_DWORD *)a1, buf, 0xFFFFuLL, 0, &addr, &addr_len);
v2 = v1;
if ( v1 > 0 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
*((_QWORD *)a1 + 9) += v2;
*((_QWORD *)a1 + 8) += v2;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 24));
}
else if ( !v1 )
{
pthread_exit(a1);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
int v1; // eax
int v2; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1003Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-10038h] BYREF
char buf[65576]; // [rsp+20h] [rbp-10028h] BYREF

while ( 1 )
{
v1 = recvfrom(*(_DWORD *)a1, buf, 0xFFFFuLL, 0, &addr, &addr_len);
v2 = v1;
if ( v1 > 0 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
*((_QWORD *)a1 + 9) += v2;
*((_QWORD *)a1 + 8) += v2;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 24));
}
else if ( !v1 )
{
pthread_exit(a1);
}
}
}

original_code:
static void*
udp_recv_thread(void* data)
{
    client_data_t* cliData = (client_data_t*)data;
    char buff[0xFFFF];
    size_t buffLen = 0xFFFF;
    int res = 0;
    struct sockaddr_in sockAddr;
    socklen_t addrLen;
    while (1) {
        res = recvfrom(cliData->sock, buff, buffLen, 0, (struct sockaddr*) &sockAddr, &addrLen);
        if (res > 0) {
            pthread_mutex_lock(&cliData->mutex);
            cliData->numSinceMeasure += res;
            cliData->numSinceStart += res;
            pthread_mutex_unlock(&cliData->mutex);
        }
        if (res == 0) {
            pthread_exit(cliData);
        }
    }
    pthread_exit(cliData);
}

canonical_original_code:
static void *udp_recv_thread(void *data)
{
    struct client_data_t *cliData = (client_data_t*)data;
    char buff[65535];
    unsigned long buffLen = 0xFFFF;
    int res = 0;
    struct sockaddr_in sockAddr;
    unsigned int addrLen;
    while (1) {
        res = recvfrom(cliData->sock, buff, buffLen, 0, (struct sockaddr *) &sockAddr, &addrLen);
        if (res > 0) {
            pthread_mutex_lock(&cliData->mutex);
            cliData->numSinceMeasure += res;
            cliData->numSinceStart += res;
            pthread_mutex_unlock(&cliData->mutex);
        }
        if (res == 0) {
            pthread_exit(cliData);
        }
    }
    pthread_exit(cliData);
}

variable_types: struct client_data_t { int sock; int clientNum; int port; unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long numSinceStart; unsigned long numSinceMeasure; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } serverAddress; } *

variable_types:
buff
char [65535]

variable_types:
buffLen
unsigned long

variable_types:
addrLen
unsigned int


decompiled_code:
__int64 __fastcall udp_create_servers(__int64 a1, int a2, unsigned int a3)
{
__int64 v4; // r13
__int64 v5; // rbp
_DWORD *v6; // rbx
__int64 v7; // rdi
int v8; // eax

if ( !a3 )
return 0LL;
v4 = a3;
v5 = 0LL;
while ( 1 )
{
v6 = malloc(0x60uLL);
memset(v6, 0, 0x60uLL);
v6[1] = v5;
pthread_mutex_init((pthread_mutex_t *)(v6 + 6), 0LL);
v7 = (unsigned int)(a2 + v5);
v6[2] = v7;
v8 = server_create_and_bind_socket(v7, 2LL);
*v6 = v8;
if ( v8 < 0 )
return 0xFFFFFFFFLL;
*((_QWORD *)v6 + 8) = 0LL;
*((_QWORD *)v6 + 9) = 0LL;
if ( pthread_create((pthread_t *)v6 + 2, 0LL, (void *(*)(void *))udp_recv_thread, v6) < 0 )
break;
*(_QWORD *)(a1 + 8 * v5++) = v6;
if ( v5 == v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, unsigned int a3)
{
__int64 v4; // r13
__int64 v5; // rbp
_DWORD *v6; // rbx
__int64 v7; // rdi
int v8; // eax

if ( !a3 )
return 0LL;
v4 = a3;
v5 = 0LL;
while ( 1 )
{
v6 = malloc(0x60uLL);
memset(v6, 0, 0x60uLL);
v6[1] = v5;
pthread_mutex_init((pthread_mutex_t *)(v6 + 6), 0LL);
v7 = (unsigned int)(a2 + v5);
v6[2] = v7;
v8 = server_create_and_bind_socket(v7, 2LL);
*v6 = v8;
if ( v8 < 0 )
return 0xFFFFFFFFLL;
*((_QWORD *)v6 + 8) = 0LL;
*((_QWORD *)v6 + 9) = 0LL;
if ( pthread_create((pthread_t *)v6 + 2, 0LL, (void *(*)(void *))udp_recv_thread, v6) < 0 )
break;
*(_QWORD *)(a1 + 8 * v5++) = v6;
if ( v5 == v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int
udp_create_servers(client_data_t** servers, uint32_t basePort, uint32_t numPorts)
{
    for (uint32_t i = 0; i < numPorts; i++) {
        client_data_t* data = (client_data_t*)malloc(sizeof(client_data_t));
        memset(data, 0, sizeof(client_data_t));
        data->clientNum = i;
        pthread_mutex_init(&data->mutex, ((void *)0));
        data->port = basePort + i;
        data->sock = server_create_and_bind_socket(data->port, SOCK_DGRAM);
        if (data->sock < 0)
        {
            return -1;
        }
        data->numSinceStart = 0;
        data->numSinceMeasure = 0;
        if (pthread_create(&data->thread, ((void *)0), udp_recv_thread, (void*)data) < 0) {
            return -1;
        }
        servers[i] = data;
    }
    return 0;
}

canonical_original_code:
int udp_create_servers(struct client_data_t **servers, unsigned int basePort, unsigned int numPorts)
{
    for (unsigned int i = 0; i < numPorts; i++) {
        struct client_data_t *data = (client_data_t*)malloc(sizeof(client_data_t));
        memset(data, 0, sizeof(client_data_t));
        data->clientNum = i;
        pthread_mutex_init(&data->mutex, ((void *)0));
        data->port = basePort + i;
        data->sock = server_create_and_bind_socket(data->port, SOCK_DGRAM);
        if (data->sock < 0)
        {
            return -1;
        }
        data->numSinceStart = 0;
        data->numSinceMeasure = 0;
        if (pthread_create(&data->thread, ((void *)0), udp_recv_thread, (void *)data) < 0) {
            return -1;
        }
        servers[i] = data;
    }
    return 0;
}

variable_types: struct client_data_t { int sock; int clientNum; int port; unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long numSinceStart; unsigned long numSinceMeasure; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } serverAddress; } **

variable_types:
basePort
unsigned int

variable_types:
numPorts
unsigned int

variable_types:
i
unsigned int


repo: ptorpman/toollogger

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
logToolUsage("TestProg", &unk_402004, 0LL, 1LL);
sleep(3u);
logToolUsage("TestProg", &unk_402004, 0LL, 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7("TestProg", &unk_402004, 0LL, 1LL);
sleep(3u);
func7("TestProg", &unk_402004, 0LL, 0LL);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  logToolUsage("TestProg", "1.0", ((void *)0), true);
  sleep(3);
  logToolUsage("TestProg", "1.0", ((void *)0), false);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  logToolUsage("TestProg", "1.0", ((void *)0), true);
  sleep(3);
  logToolUsage("TestProg", "1.0", ((void *)0), false);
  return 0;
}


repo: ptrayal/dungeonworld

original_code:
void do_check( CHAR_DATA *ch, char *argument )
{
    char buf[4608] = {'\0'};
    char arg[256] = {'\0'};
    BUFFER *buffer;
    CHAR_DATA *victim;
    AFFECT_DATA *paf;
    int count = 1;
    int last_room = 0;
    one_argument( argument, arg );
    send_to_char("Syntax: 'check'       display info about players\n\r", ch);
    send_to_char("        'check stats' display info and resume stats\n\r",ch);
    send_to_char("        'check eq'    resume eq of all players\n\r", ch);
    send_to_char("\n\r", ch);
    if ( ((arg) == ((void *)0) || (arg)[0] == '\0') || !str_prefix(arg,"stats"))
    {
        buffer = __new_buf("check.c", __FUNCTION__, 85);
     for (victim = char_list; victim != ((void *)0); victim = victim->next)
     {
         if (((((victim)->act) & ((1)))) || !can_see(ch,victim))
          continue;
     if (victim->desc == ((void *)0))
     {
      snprintf(buf, sizeof(buf), "%3d) %s is linkdead.\n\r", count, victim->name);
      add_buf(buffer, buf);
      count++;
      continue;
     }
     if (victim->desc->connected >= 6
      && victim->desc->connected <= 12)
     {
      snprintf(buf, sizeof(buf), "%3d) %s is being created.\n\r",
           count, victim->name);
      add_buf(buffer, buf);
      count++;
      continue;
     }
     if ( (victim->desc->connected == 2
        || victim->desc->connected >= 13)
      && get_trust(victim) <= get_trust(ch) )
     {
      snprintf(buf, sizeof(buf), "%3d) %s is connecting.\n\r",
           count, victim->name);
      add_buf(buffer, buf);
      count++;
      continue;
     }
     if (victim->desc->connected == 0)
     {
         if (get_trust(victim) > get_trust(ch))
             snprintf(buf, sizeof(buf), "%3d) %s.\n\r", count, victim->name);
         else
         {
      snprintf(buf, sizeof(buf), "%3d) %s, Level %d connected since %d hours (%d total hours)\n\r",
       count, victim->name,victim->level,
                        ((int)(current_time - victim->logon)) /3600,
       (victim->played + (int)(current_time - victim->logon)) /3600 );
      add_buf(buffer, buf);
      if (arg[0]!='\0' && !str_prefix(arg,"stats"))
      {
        snprintf(buf, sizeof(buf), "  %d HP %d Mana (%d %d %d %d %d) %ld golds %d Tr %d Pr.\n\r",
       victim->max_hit, victim->max_mana,victim->perm_stat[0],
       victim->perm_stat[1],victim->perm_stat[2],
       victim->perm_stat[3],victim->perm_stat[4],
       victim->gold + victim->silver/100,
       victim->train, victim->practice);
        add_buf(buffer, buf);
      }
      count++;
  }
         continue;
     }
     snprintf(buf, sizeof(buf), "%3d) bug (oops)...please report to Staff: %s %d\n\r",
      count, victim->name, victim->desc->connected);
     add_buf(buffer, buf);
     count++;
     }
     page_to_char(buf_string(buffer),ch);
     free_buf(buffer);
     return;
    }
    if (!str_prefix(arg,"eq"))
    {
        buffer = __new_buf("check.c", __FUNCTION__, 158);
     for (victim = char_list; victim != ((void *)0); victim = victim->next)
     {
         if (((((victim)->act) & ((1))))
          || victim->desc->connected != 0
          || !can_see(ch,victim)
          || get_trust(victim) > get_trust(ch) )
          continue;
         snprintf(buf, sizeof(buf), "%3d) %s, %d items (weight %d) Hit:%d Dam:%d Save:%d AC:%d %d %d %d.\n\r",
          count, victim->name, victim->carry_number, victim->carry_weight,
          victim->hitroll, victim->damroll, victim->saving_throw,
          victim->armor[0], victim->armor[1],
          victim->armor[2], victim->armor[3]);
         add_buf(buffer, buf);
         count++;
     }
     page_to_char(buf_string(buffer),ch);
     free_buf(buffer);
     return;
    }
  if (!str_prefix(arg,"snoop"))
    {
        char bufsnoop [100];
        if(ch->level < 60 )
          {
            send_to_char("You can't use this check option.\n\r",ch);
            return;
          }
        buffer = __new_buf("check.c", __FUNCTION__, 189);
        for (victim = char_list; victim != ((void *)0); victim = victim->next)
        {
            if (((((victim)->act) & ((1))))
             || victim->desc->connected != 0
             || !can_see(ch,victim)
             || get_trust(victim) > get_trust(ch) )
                continue;
            if(victim->desc->snoop_by != ((void *)0))
              snprintf(bufsnoop, sizeof(bufsnoop)," %15s .",victim->desc->snoop_by->character->name);
            else
              snprintf(bufsnoop,sizeof(bufsnoop), "     (none)      ." );
            snprintf(buf, sizeof(buf), "%3d %15s : %s \n\r",count,victim->name, bufsnoop);
            add_buf(buffer, buf);
            count++;
        }
        page_to_char(buf_string(buffer),ch);
        free_buf(buffer);
        return;
    }
    return;
}

canonical_original_code:
void do_check(struct char_data *ch, char *argument)
{
    char buf[4608] = {'\0'};
    char arg[256] = {'\0'};
    struct buf_type *buffer;
    struct char_data *victim;
    struct affect_data *paf;
    int count = 1;
    int last_room = 0;
    one_argument( argument, arg );
    send_to_char("Syntax: 'check'       display info about players\n\r", ch);
    send_to_char("        'check stats' display info and resume stats\n\r",ch);
    send_to_char("        'check eq'    resume eq of all players\n\r", ch);
    send_to_char("\n\r", ch);
    if ( ((arg) == ((void *)0) || (arg)[0] == '\0') || !str_prefix(arg,"stats"))
    {
        buffer = __new_buf("check.c", __FUNCTION__, 85);
     for (victim = char_list; victim != ((void *)0); victim = victim->next)
     {
         if (((((victim)->act) & ((1)))) || !can_see(ch,victim))
          continue;
     if (victim->desc == ((void *)0))
     {
      snprintf(buf, sizeof(buf), "%3d) %s is linkdead.\n\r", count, victim->name);
      add_buf(buffer, buf);
      count++;
      continue;
     }
     if (victim->desc->connected >= 6
      && victim->desc->connected <= 12)
     {
      snprintf(buf, sizeof(buf), "%3d) %s is being created.\n\r",
           count, victim->name);
      add_buf(buffer, buf);
      count++;
      continue;
     }
     if ( (victim->desc->connected == 2
        || victim->desc->connected >= 13)
      && get_trust(victim) <= get_trust(ch) )
     {
      snprintf(buf, sizeof(buf), "%3d) %s is connecting.\n\r",
           count, victim->name);
      add_buf(buffer, buf);
      count++;
      continue;
     }
     if (victim->desc->connected == 0)
     {
         if (get_trust(victim) > get_trust(ch))
             snprintf(buf, sizeof(buf), "%3d) %s.\n\r", count, victim->name);
         else
         {
      snprintf(buf, sizeof(buf), "%3d) %s, Level %d connected since %d hours (%d total hours)\n\r",
       count, victim->name,victim->level,
                        ((int)(current_time - victim->logon)) /3600,
       (victim->played + (int)(current_time - victim->logon)) /3600 );
      add_buf(buffer, buf);
      if (arg[0]!='\0' && !str_prefix(arg,"stats"))
      {
        snprintf(buf, sizeof(buf), "  %d HP %d Mana (%d %d %d %d %d) %ld golds %d Tr %d Pr.\n\r",
       victim->max_hit, victim->max_mana,victim->perm_stat[0],
       victim->perm_stat[1],victim->perm_stat[2],
       victim->perm_stat[3],victim->perm_stat[4],
       victim->gold + victim->silver/100,
       victim->train, victim->practice);
        add_buf(buffer, buf);
      }
      count++;
  }
         continue;
     }
     snprintf(buf, sizeof(buf), "%3d) bug (oops)...please report to Staff: %s %d\n\r",
      count, victim->name, victim->desc->connected);
     add_buf(buffer, buf);
     count++;
     }
     page_to_char(buf_string(buffer),ch);
     free_buf(buffer);
     return;
    }
    if (!str_prefix(arg,"eq"))
    {
        buffer = __new_buf("check.c", __FUNCTION__, 158);
     for (victim = char_list; victim != ((void *)0); victim = victim->next)
     {
         if (((((victim)->act) & ((1))))
          || victim->desc->connected != 0
          || !can_see(ch,victim)
          || get_trust(victim) > get_trust(ch) )
          continue;
         snprintf(buf, sizeof(buf), "%3d) %s, %d items (weight %d) Hit:%d Dam:%d Save:%d AC:%d %d %d %d.\n\r",
          count, victim->name, victim->carry_number, victim->carry_weight,
          victim->hitroll, victim->damroll, victim->saving_throw,
          victim->armor[0], victim->armor[1],
          victim->armor[2], victim->armor[3]);
         add_buf(buffer, buf);
         count++;
     }
     page_to_char(buf_string(buffer),ch);
     free_buf(buffer);
     return;
    }
  if (!str_prefix(arg,"snoop"))
    {
        char bufsnoop[100];
        if(ch->level < 60 )
          {
            send_to_char("You can't use this check option.\n\r",ch);
            return;
          }
        buffer = __new_buf("check.c", __FUNCTION__, 189);
        for (victim = char_list; victim != ((void *)0); victim = victim->next)
        {
            if (((((victim)->act) & ((1))))
             || victim->desc->connected != 0
             || !can_see(ch,victim)
             || get_trust(victim) > get_trust(ch) )
                continue;
            if(victim->desc->snoop_by != ((void *)0))
              snprintf(bufsnoop, sizeof(bufsnoop)," %15s .",victim->desc->snoop_by->character->name);
            else
              snprintf(bufsnoop,sizeof(bufsnoop), "     (none)      ." );
            snprintf(buf, sizeof(buf), "%3d %15s : %s \n\r",count,victim->name, bufsnoop);
            add_buf(buffer, buf);
            count++;
        }
        page_to_char(buf_string(buffer),ch);
        free_buf(buffer);
        return;
    }
    return;
}

variable_types: struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *leader; struct char_data *fighting; struct char_data *reply; struct char_data *pet; struct char_data *mprog_target; struct mem_data { struct mem_data *next; unsigned char valid; int id; int reaction; long when; } *memory; unsigned char (*spec_fun)(struct char_data *ch); struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch); struct shop_data { struct shop_data *next; short keeper; short buy_type[5]; short profit_buy; short profit_sell; short open_hour; short close_hour; } *pShop; struct mprog_list { int trig_type; char *trig_phrase; short vnum; char *code; struct mprog_list *next; unsigned char valid; } *mprogs; struct area_data { struct area_data *next; struct help_area_data { struct help_area_data *next; struct help_data { struct help_data *next; struct help_data *next_area; short level; char *keyword; char *text; } *first; struct help_data *last; struct area_data *area; char *filename; unsigned char changed; } *helps; char *file_name; char *name; char *credits; short age; short nplayer; short low_range; short high_range; short min_vnum; short max_vnum; unsigned char empty; char *builders; int vnum; int area_flags; int security; } *area; short vnum; short group; unsigned char new_format; short count; short killed; char *player_name; char *short_descr; char *long_descr; char *description; long act; long affected_by; short alignment; short level; short hitroll; short hit[3]; short mana[3]; short damage[3]; short ac[4]; short dam_type; long off_flags; long imm_flags; long res_flags; long vuln_flags; short start_pos; short default_pos; short sex; short race; long wealth; long form; long parts; short size; char *material; long mprog_flags; } *pIndexData; struct descriptor_data { struct descriptor_data *next; struct descriptor_data *snoop_by; struct char_data *character; struct char_data *original; unsigned char valid; char *host; short descriptor; short connected; unsigned char fcommand; char inbuf[-1]; char incomm[256]; char inlast[256]; int repeat; char *outbuf; int outsize; int outtop; char *showstr_head; char *showstr_point; void *pEdit; char **pString; int editor; struct protocol_t { int WriteOOB; enum bool_t { false=0, true=1 } Negotiated[-1]; enum bool_t { false=0, true=1 } bIACMode; enum bool_t { false=0, true=1 } bNegotiated; enum bool_t { false=0, true=1 } bRenegotiate; enum bool_t { false=0, true=1 } bNeedMXPVersion; enum bool_t { false=0, true=1 } bBlockMXP; enum bool_t { false=0, true=1 } bTTYPE; enum bool_t { false=0, true=1 } bECHO; enum bool_t { false=0, true=1 } bNAWS; enum bool_t { false=0, true=1 } bCHARSET; enum bool_t { false=0, true=1 } bMSDP; enum bool_t { false=0, true=1 } bMSSP; enum bool_t { false=0, true=1 } bATCP; enum bool_t { false=0, true=1 } bMSP; enum bool_t { false=0, true=1 } bMXP; enum bool_t { false=0, true=1 } bMCCP; enum support_t { eUNKNOWN=0, eNO=1, eSOMETIMES=2, eYES=3 } b256Support; int ScreenWidth; int ScreenHeight; char *pMXPVersion; char *pLastTTYPE; struct MSDP_t { enum bool_t { false=0, true=1 } bReport; enum bool_t { false=0, true=1 } bDirty; int ValueInt; char *pValueString; } **pVariables; } *pProtocol; } *desc; struct affect_data { struct affect_data *next; unsigned char valid; short where; short type; short level; short duration; short location; short modifier; int bitvector; } *affected; struct note_data { struct note_data *next; unsigned char valid; short type; char *sender; char *date; char *to_list; char *subject; char *text; long date_stamp; } *pnote; struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; struct obj_data *on; struct char_data *carried_by; struct extra_descr_data { struct extra_descr_data *next; unsigned char valid; char *keyword; char *description; } *extra_descr; struct affect_data *affected; struct obj_index_data { struct obj_index_data *next; struct extra_descr_data *extra_descr; struct affect_data *affected; struct area_data *area; unsigned char new_format; char *name; char *short_descr; char *description; short vnum; short reset_num; char *material; short item_type; int extra_flags; int wear_flags; short level; short condition; short count; short weight; int cost; int value[5]; } *pIndexData; struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data *extra_descr; struct area_data *area; struct exit_data { union { struct room_index_data *to_room; short vnum; } u1; int exit_info; short key; char *keyword; char *description; struct exit_data *next; int rs_flags; int orig_door; } *exit[6]; struct reset_data { struct reset_data *next; char command; short arg1; short arg2; short arg3; short arg4; } *reset_first; struct reset_data *reset_last; char *name; char *description; char *owner; short vnum; int room_flags; short light; short sector_type; short heal_rate; short mana_rate; short clan; } *in_room; unsigned char valid; unsigned char enchanted; char *owner; char *name; char *short_descr; char *description; short item_type; int extra_flags; int wear_flags; short wear_loc; short weight; int cost; short level; short condition; char *material; short timer; int value[5]; } *carrying; struct obj_data *on; struct room_index_data *in_room; struct room_index_data *was_in_room; struct area_data *zone; struct pc_data { struct pc_data *next; struct buf_type { struct buf_type *next; unsigned char valid; short state; short size; char *string; char *file; char *function; int line; } *buffer; unsigned char valid; char *pwd; char *bamfin; char *bamfout; char *title; long last_note; long last_idea; long last_penalty; long last_news; long last_changes; short perm_hit; short perm_mana; short perm_move; short true_sex; int last_level; short condition[4]; short learned[151]; unsigned char group_known[30]; short points; unsigned char confirm_delete; char *alias[5]; char *alias_sub[5]; int security; } *pcdata; struct gen_data { struct gen_data *next; unsigned char valid; unsigned char skill_chosen[151]; unsigned char group_chosen[30]; int points_chosen; } *gen_data; unsigned char valid; char *name; long id; short version; char *short_descr; char *long_descr; char *description; char *prompt; char *prefix; short group; short clan; short sex; short iclass; short race; short level; short trust; int played; int lines; long logon; short timer; short wait; short daze; short hit; short max_hit; short mana; short max_mana; short move; short max_move; long gold; long silver; int exp; long act; long comm; long wiznet; long imm_flags; long res_flags; long vuln_flags; short invis_level; short incog_level; long affected_by; short position; short practice; short train; short carry_weight; short carry_number; short saving_throw; short alignment; short hitroll; short damroll; short armor[4]; short wimpy; short perm_stat[5]; short mod_stat[5]; long form; long parts; short size; char *material; long off_flags; short damage[3]; short dam_type; short start_pos; short default_pos; short mprog_delay; } *

variable_types:
argument
char *

variable_types:
buf
char [4608]

variable_types:
arg
char [256]

variable_types: count int

variable_types:
bufsnoop
char [100]

user_defined_types: struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *leader; struct char_data *fighting; struct char_data *reply; struct char_data *pet; struct char_data *mprog_target; struct mem_data *memory; unsigned char (*spec_fun)(struct char_data *ch); struct mob_index_data *pIndexData; struct descriptor_data *desc; struct affect_data *affected; struct note_data *pnote; struct obj_data *carrying; struct obj_data *on; struct room_index_data *in_room; struct room_index_data *was_in_room; struct area_data *zone; struct pc_data *pcdata; struct gen_data *gen_data; unsigned char valid; char *name; long id; short version; char *short_descr; char *long_descr; char *description; char *prompt; char *prefix; short group; short clan; short sex; short iclass; short race; short level; short trust; int played; int lines; long logon; short timer; short wait; short daze; short hit; short max_hit; short mana; short max_mana; short move; short max_move; long gold; long silver; int exp; long act; long comm; long wiznet; long imm_flags; long res_flags; long vuln_flags; short invis_level; short incog_level; long affected_by; short position; short practice; short train; short carry_weight; short carry_number; short saving_throw; short alignment; short hitroll; short damroll; short armor[4]; short wimpy; short perm_stat[5]; short mod_stat[5]; long form; long parts; short size; char *material; long off_flags; short damage[3]; short dam_type; short start_pos; short default_pos; short mprog_delay; }

user_defined_types: struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch); struct shop_data *pShop; struct mprog_list *mprogs; struct area_data *area; short vnum; short group; unsigned char new_format; short count; short killed; char *player_name; char *short_descr; char *long_descr; char *description; long act; long affected_by; short alignment; short level; short hitroll; short hit[3]; short mana[3]; short damage[3]; short ac[4]; short dam_type; long off_flags; long imm_flags; long res_flags; long vuln_flags; short start_pos; short default_pos; short sex; short race; long wealth; long form; long parts; short size; char *material; long mprog_flags; }

user_defined_types: struct descriptor_data { struct descriptor_data *next; struct descriptor_data *snoop_by; struct char_data *character; struct char_data *original; unsigned char valid; char *host; short descriptor; short connected; unsigned char fcommand; char inbuf[-1]; char incomm[256]; char inlast[256]; int repeat; char *outbuf; int outsize; int outtop; char *showstr_head; char *showstr_point; void *pEdit; char **pString; int editor; struct protocol_t *pProtocol; }

user_defined_types: struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; struct obj_data *on; struct char_data *carried_by; struct extra_descr_data *extra_descr; struct affect_data *affected; struct obj_index_data *pIndexData; struct room_index_data *in_room; unsigned char valid; unsigned char enchanted; char *owner; char *name; char *short_descr; char *description; short item_type; int extra_flags; int wear_flags; short wear_loc; short weight; int cost; short level; short condition; char *material; short timer; int value[5]; }

user_defined_types: struct pc_data { struct pc_data *next; struct buf_type *buffer; unsigned char valid; char *pwd; char *bamfin; char *bamfout; char *title; long last_note; long last_idea; long last_penalty; long last_news; long last_changes; short perm_hit; short perm_mana; short perm_move; short true_sex; int last_level; short condition[4]; short learned[151]; unsigned char group_known[30]; short points; unsigned char confirm_delete; char *alias[5]; char *alias_sub[5]; int security; }

user_defined_types: struct area_data { struct area_data *next; struct help_area_data *helps; char *file_name; char *name; char *credits; short age; short nplayer; short low_range; short high_range; short min_vnum; short max_vnum; unsigned char empty; char *builders; int vnum; int area_flags; int security; }

user_defined_types: struct protocol_t { int WriteOOB; enum bool_t Negotiated[-1]; enum bool_t bIACMode; enum bool_t bNegotiated; enum bool_t bRenegotiate; enum bool_t bNeedMXPVersion; enum bool_t bBlockMXP; enum bool_t bTTYPE; enum bool_t bECHO; enum bool_t bNAWS; enum bool_t bCHARSET; enum bool_t bMSDP; enum bool_t bMSSP; enum bool_t bATCP; enum bool_t bMSP; enum bool_t bMXP; enum bool_t bMCCP; enum support_t b256Support; int ScreenWidth; int ScreenHeight; char *pMXPVersion; char *pLastTTYPE; struct MSDP_t **pVariables; }

user_defined_types: struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data *extra_descr; struct area_data *area; struct exit_data *exit[6]; struct reset_data *reset_first; struct reset_data *reset_last; char *name; char *description; char *owner; short vnum; int room_flags; short light; short sector_type; short heal_rate; short mana_rate; short clan; }

user_defined_types: struct help_area_data { struct help_area_data *next; struct help_data *first; struct help_data *last; struct area_data *area; char *filename; unsigned char changed; }

user_defined_types: struct MSDP_t { enum bool_t bReport; enum bool_t bDirty; int ValueInt; char *pValueString; }