decompiled_code:
int usage_common_opts()
{
const char *v0; // rdx

v0 = "rtu";
if ( modbus_type )
v0 = "tcp";
return fprintf(
stderr,
"where <options> are:\n"
"\t--debug | -D - enable debug messages (more increase verbosity)\n"
"\t--device | -d <dev> - specify MODBUS device to use (default is %s)\n"
"\t <dev> can be:\n"
"\t - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
"\t default: rtu:%s,%d,%d,%c,%d\n"
"\t - tcp[:<address>[,<port>]]\n"
"\t default: tcp:%s,%d\n"
"\t--help | -h - show this help message\n",
v0,
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5),
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}

canonical_decompiled_code:
int func3()
{
const char *v0; // rdx

v0 = "rtu";
if ( modbus_type )
v0 = "tcp";
return fprintf(
stderr,
"where <options> are:\n"
"\t--debug | -D - enable debug messages (more increase verbosity)\n"
"\t--device | -d <dev> - specify MODBUS device to use (default is %s)\n"
"\t <dev> can be:\n"
"\t - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
"\t default: rtu:%s,%d,%d,%c,%d\n"
"\t - tcp[:<address>[,<port>]]\n"
"\t default: tcp:%s,%d\n"
"\t--help | -h - show this help message\n",
v0,
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5),
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}

original_code:
void usage_common_opts(void)
{
 fprintf(stderr, "where <options> are:\n"
  "\t--debug  | -D        - enable debug messages (more increase verbosity)\n"
  "\t--device | -d <dev>  - specify MODBUS device to use (default is %s)\n"
  "\t                       <dev> can be:\n"
  "\t                       - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
  "\t                            default: rtu:%s,%d,%d,%c,%d\n"
  "\t                       - tcp[:<address>[,<port>]]\n"
  "\t                            default: tcp:%s,%d\n"
  "\t--help   | -h        - show this help message\n",
   modbus_type == RTU ? "rtu" : "tcp",
   modbus_parms.rtu.serial_dev,
   modbus_parms.rtu.baud,
   modbus_parms.rtu.bytes,
   modbus_parms.rtu.parity,
   modbus_parms.rtu.stop,
   modbus_parms.tcp.address,
   modbus_parms.tcp.port);
}

canonical_original_code:
void usage_common_opts()
{
 fprintf(stderr, "where <options> are:\n"
  "\t--debug  | -D        - enable debug messages (more increase verbosity)\n"
  "\t--device | -d <dev>  - specify MODBUS device to use (default is %s)\n"
  "\t                       <dev> can be:\n"
  "\t                       - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
  "\t                            default: rtu:%s,%d,%d,%c,%d\n"
  "\t                       - tcp[:<address>[,<port>]]\n"
  "\t                            default: tcp:%s,%d\n"
  "\t--help   | -h        - show this help message\n",
   modbus_type == RTU ? "rtu" : "tcp",
   modbus_parms.rtu.serial_dev,
   modbus_parms.rtu.baud,
   modbus_parms.rtu.bytes,
   modbus_parms.rtu.parity,
   modbus_parms.rtu.stop,
   modbus_parms.tcp.address,
   modbus_parms.tcp.port);
}


repo: cosino/modbus-utils

decompiled_code:
__int64 __fastcall check_common_opts(int argc, char **argv)
{
int v4; // eax
bool v5; // cf
bool v6; // zf
__int64 v7; // rcx
const char *v8; // rsi
const char *v9; // rdi
char v10; // al
bool v11; // cf
bool v12; // zf
__int64 v13; // rcx
const char *v14; // rsi
const char *v15; // rdi
int v16; // eax
int longind; // [rsp+4h] [rbp-A4h] BYREF
void *ptr; // [rsp+8h] [rbp-A0h] BYREF
struct option longopts; // [rsp+10h] [rbp-98h] BYREF
const char *v21; // [rsp+30h] [rbp-78h]
int v22; // [rsp+38h] [rbp-70h]
__int64 v23; // [rsp+40h] [rbp-68h]
int v24; // [rsp+48h] [rbp-60h]
const char *v25; // [rsp+50h] [rbp-58h]
int v26; // [rsp+58h] [rbp-50h]
__int64 v27; // [rsp+60h] [rbp-48h]
int v28; // [rsp+68h] [rbp-40h]

longopts.name = "debug";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 68;
v21 = "device";
v22 = 1;
v23 = 0LL;
v24 = 100;
v25 = "help";
v26 = 0;
v27 = 0LL;
v28 = 104;
while ( 1 )
{
longind = 0;
v16 = getopt_long(argc, argv, "Dd:h", &longopts, &longind);
if ( v16 == -1 )
break;
if ( v16 == 68 )
{
++enable_debug;
}
else if ( v16 > 68 )
{
if ( v16 != 100 )
{
if ( v16 != 104 )
goto LABEL_32;
usage();
goto LABEL_20;
}
v4 = sscanf(optarg, "%m[a-z]", &ptr);
v5 = v4 == 0;
v6 = v4 == 1;
if ( v4 != 1 )
{
fwrite("must specify a MODBUS type\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v7 = 4LL;
v8 = (const char *)ptr;
v9 = "rtu";
do
{
if ( !v7 )
break;
v5 = *v8 < (unsigned int)*v9;
v6 = *v8++ == *v9++;
--v7;
}
while ( v6 );
v10 = (!v5 && !v6) - v5;
v11 = 0;
v12 = v10 == 0;
if ( v10 )
{
v13 = 4LL;
v14 = (const char *)ptr;
v15 = "tcp";
do
{
if ( !v13 )
break;
v11 = *v14 < (unsigned int)*v15;
v12 = *v14++ == *v15++;
--v13;
}
while ( v12 );
if ( (!v11 && !v12) != v11 )
{
fwrite("unknow MODBUS type\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
free(ptr);
modbus_type = 1;
if ( (int)parse_tcp_opts(optarg, v14) < 0 )
{
fwrite("invalid TCP options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
else
{
free(ptr);
modbus_type = 0;
if ( (int)parse_rtu_opts(optarg, v8) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
}
else
{
if ( v16 )
{
if ( v16 < 0 )
goto LABEL_32;
if ( v16 != 58 )
{
if ( v16 == 63 )
exit(1);
LABEL_32:
exit(1);
}
LABEL_20:
exit(1);
}
if ( !*((_QWORD *)&longopts.flag + 4 * longind) )
{
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 143LL);
exit(1);
}
}
}
if ( !enable_debug )
{
if ( !modbus_type || modbus_type == 1 )
return (unsigned int)optind;
LABEL_43:
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 219LL);
exit(1);
}
fprintf(stderr, "%s[%4d]: %s: debug is on\n", "common.c", 200LL, "check_common_opts");
if ( modbus_type )
{
if ( modbus_type != 1 )
goto LABEL_43;
if ( enable_debug )
fprintf(
stderr,
"%s[%4d]: %s: modbus tcp:%s,%d\n",
"common.c",
212LL,
"check_common_opts",
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}
else if ( enable_debug )
{
fprintf(
stderr,
"%s[%4d]: %s: modbus rtu:%s,%d,%d,%c,%d\n",
"common.c",
203LL,
"check_common_opts",
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5));
}
return (unsigned int)optind;
}

canonical_decompiled_code:
__int64 __fastcall func4(int argc, char **argv)
{
int v4; // eax
bool v5; // cf
bool v6; // zf
__int64 v7; // rcx
const char *v8; // rsi
const char *v9; // rdi
char v10; // al
bool v11; // cf
bool v12; // zf
__int64 v13; // rcx
const char *v14; // rsi
const char *v15; // rdi
int v16; // eax
int longind; // [rsp+4h] [rbp-A4h] BYREF
void *ptr; // [rsp+8h] [rbp-A0h] BYREF
struct option longopts; // [rsp+10h] [rbp-98h] BYREF
const char *v21; // [rsp+30h] [rbp-78h]
int v22; // [rsp+38h] [rbp-70h]
__int64 v23; // [rsp+40h] [rbp-68h]
int v24; // [rsp+48h] [rbp-60h]
const char *v25; // [rsp+50h] [rbp-58h]
int v26; // [rsp+58h] [rbp-50h]
__int64 v27; // [rsp+60h] [rbp-48h]
int v28; // [rsp+68h] [rbp-40h]

longopts.name = "debug";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 68;
v21 = "device";
v22 = 1;
v23 = 0LL;
v24 = 100;
v25 = "help";
v26 = 0;
v27 = 0LL;
v28 = 104;
while ( 1 )
{
longind = 0;
v16 = getopt_long(argc, argv, "Dd:h", &longopts, &longind);
if ( v16 == -1 )
break;
if ( v16 == 68 )
{
++enable_debug;
}
else if ( v16 > 68 )
{
if ( v16 != 100 )
{
if ( v16 != 104 )
goto LABEL_32;
usage();
goto LABEL_20;
}
v4 = sscanf(optarg, "%m[a-z]", &ptr);
v5 = v4 == 0;
v6 = v4 == 1;
if ( v4 != 1 )
{
fwrite("must specify a MODBUS type\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v7 = 4LL;
v8 = (const char *)ptr;
v9 = "rtu";
do
{
if ( !v7 )
break;
v5 = *v8 < (unsigned int)*v9;
v6 = *v8++ == *v9++;
--v7;
}
while ( v6 );
v10 = (!v5 && !v6) - v5;
v11 = 0;
v12 = v10 == 0;
if ( v10 )
{
v13 = 4LL;
v14 = (const char *)ptr;
v15 = "tcp";
do
{
if ( !v13 )
break;
v11 = *v14 < (unsigned int)*v15;
v12 = *v14++ == *v15++;
--v13;
}
while ( v12 );
if ( (!v11 && !v12) != v11 )
{
fwrite("unknow MODBUS type\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
free(ptr);
modbus_type = 1;
if ( (int)func2(optarg, v14) < 0 )
{
fwrite("invalid TCP options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
else
{
free(ptr);
modbus_type = 0;
if ( (int)func1(optarg, v8) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
}
else
{
if ( v16 )
{
if ( v16 < 0 )
goto LABEL_32;
if ( v16 != 58 )
{
if ( v16 == 63 )
exit(1);
LABEL_32:
exit(1);
}
LABEL_20:
exit(1);
}
if ( !*((_QWORD *)&longopts.flag + 4 * longind) )
{
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 143LL);
exit(1);
}
}
}
if ( !enable_debug )
{
if ( !modbus_type || modbus_type == 1 )
return (unsigned int)optind;
LABEL_43:
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 219LL);
exit(1);
}
fprintf(stderr, "%s[%4d]: %s: debug is on\n", "common.c", 200LL, "check_common_opts");
if ( modbus_type )
{
if ( modbus_type != 1 )
goto LABEL_43;
if ( enable_debug )
fprintf(
stderr,
"%s[%4d]: %s: modbus tcp:%s,%d\n",
"common.c",
212LL,
"check_common_opts",
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}
else if ( enable_debug )
{
fprintf(
stderr,
"%s[%4d]: %s: modbus rtu:%s,%d,%d,%c,%d\n",
"common.c",
203LL,
"check_common_opts",
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5));
}
return (unsigned int)optind;
}

original_code:
int check_common_opts(int argc, char *argv[])
{
 int c;
 struct option long_options[] = {
  {"debug", 0, 0, 'D'},
  {"device", 1, 0, 'd'},
  {"help", 0, 0, 'h'},
 };
 char *str;
 int ret;
 while (1) {
  int option_index = 0;
  c = getopt_long(argc, argv, "Dd:h",
    long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   do { if (__builtin_expect(!!(long_options[option_index].flag == ((void *)0)), 0)) do { fprintf(stderr, "fatal error in %s():%d" "\n" , __func__, 143); exit(1); } while (0); } while(0);
   break;
  case 'D':
   enable_debug++;
   break;
  case 'd':
   ret = sscanf(optarg, "%m[a-z]", &str);
   if (ret != 1) {
    fprintf(stderr, "must specify a MODBUS type" "\n");
    exit(1);
   }
   if (strcmp(str, "rtu") == 0) {
    free(str);
    modbus_type = RTU;
    ret = parse_rtu_opts(optarg);
    if (ret < 0) {
     fprintf(stderr, "invalid RTU options" "\n");
     exit(1);
    }
   } else if (strcmp(str, "tcp") == 0) {
    free(str);
    modbus_type = TCP;
    ret = parse_tcp_opts(optarg);
    if (ret < 0) {
     fprintf(stderr, "invalid TCP options" "\n");
     exit(1);
    }
   } else {
    fprintf(stderr, "unknow MODBUS type" "\n");
    exit(1);
   }
   break;
  case 'h':
   usage();
  case ':':
   exit(1);
  case '?':
   exit(1);
  default:
   exit(1);
  }
 }
 do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "%s[%4d]: %s: " "debug is on" "\n" , "common.c", 200, __func__); } while (0);
 switch (modbus_type) {
 case RTU:
  do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "%s[%4d]: %s: " "modbus rtu:%s,%d,%d,%c,%d" "\n" , "common.c", 203, __func__ , modbus_parms.rtu.serial_dev, modbus_parms.rtu.baud, modbus_parms.rtu.bytes, modbus_parms.rtu.parity, modbus_parms.rtu.stop); } while (0);
  break;
 case TCP:
  do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "%s[%4d]: %s: " "modbus tcp:%s,%d" "\n" , "common.c", 212, __func__ , modbus_parms.tcp.address, modbus_parms.tcp.port); } while (0);
  break;
 default:
  do { fprintf(stderr, "fatal error in %s():%d" "\n" , __func__, 219); exit(1); } while (0);
 }
 return optind;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
str
char *

variable_types: ret int

return_type: int


decompiled_code:
__int64 __fastcall parse_addr(char *a1)
{
__int64 result; // rax

result = parse_not_negative_int(a1);
if ( (unsigned int)(result - 1) >= 0xFE )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
__int64 result; // rax

result = func0(a1);
if ( (unsigned int)(result - 1) >= 0xFE )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int parse_addr(char *addr)
{
 int val;
 val = parse_not_negative_int(addr);
 if (val < 1 || val > 254)
  return -1;
 return val;
}

variable_types:
addr
char *

variable_types: val int


decompiled_code:
__int64 __fastcall parse_datum(char *a1)
{
__int64 result; // rax

result = parse_not_negative_int(a1);
if ( (unsigned int)result > 0xFFFF )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
__int64 result; // rax

result = func0(a1);
if ( (unsigned int)result > 0xFFFF )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int parse_datum(char *datum)
{
 int val;
 val = parse_not_negative_int(datum);
 if (val < 0 || val > 0xffff)
  return -1;
 return val;
}

variable_types:
datum
char *


usage

repo: cosino/modbusfs

decompiled_code:
int usage()
{
fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
fwrite("where <dev> can be:\n\n\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n", 1uLL, 0x45uLL, stderr);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func0()
{
fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
fwrite("where <dev> can be:\n\n\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n", 1uLL, 0x45uLL, stderr);
return fputc(10, stderr);
}

original_code:
static void usage(void)
{
 fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
 fprintf(stderr, "where <dev> can be:\n\n"
  "\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n");
 fprintf(stderr, "\n");
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
 fprintf(stderr, "where <dev> can be:\n\n"
  "\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n");
 fprintf(stderr, "\n");
}

return_type: void


decompiled_code:
__int64 __fastcall parse_rtu_opts(const char *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 )
{
if ( sscanf(a1, "%32[a-zA-Z0-9/_],%d,%d%c%d", modbus_parms, &dword_2C4, &dword_2C8, &byte_2CC, &dword_2D0) <= 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)enable_debug;
if ( enable_debug )
{
fprintf(
stderr,
"*** %s[%4d]: %s: serial_dev=%s baud=%d bytes=%d parity=%c stop=%d\n",
"modbusfs.c",
60LL,
"parse_rtu_opts",
modbus_parms,
(unsigned int)dword_2C4,
(unsigned int)dword_2C8,
(unsigned int)byte_2CC,
(unsigned int)dword_2D0);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 )
{
if ( sscanf(a1, "%32[a-zA-Z0-9/_],%d,%d%c%d", modbus_parms, &dword_2C4, &dword_2C8, &byte_2CC, &dword_2D0) <= 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)enable_debug;
if ( enable_debug )
{
fprintf(
stderr,
"*** %s[%4d]: %s: serial_dev=%s baud=%d bytes=%d parity=%c stop=%d\n",
"modbusfs.c",
60LL,
"parse_rtu_opts",
modbus_parms,
(unsigned int)dword_2C4,
(unsigned int)dword_2C8,
(unsigned int)byte_2CC,
(unsigned int)dword_2D0);
result = 0LL;
}
}
}
return result;
}

original_code:
static int parse_rtu_opts(char *opts)
{
 int ret;
 if (strlen(opts) == 0)
  return 0;
 ret = sscanf(opts, "%" "32" "[a-zA-Z0-9/_],%d,%d%c%d",
       modbus_parms.rtu.serial_dev,
       &modbus_parms.rtu.baud,
       &modbus_parms.rtu.bytes,
       &modbus_parms.rtu.parity, &modbus_parms.rtu.stop);
 if (ret < 1)
  return -1;
 do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "*** %s[%4d]: %s: " "serial_dev=%s baud=%d bytes=%d parity=%c stop=%d" "\n" , "modbusfs.c", 60, __func__ , modbus_parms.rtu.serial_dev, modbus_parms.rtu.baud, modbus_parms.rtu.bytes, modbus_parms.rtu.parity, modbus_parms.rtu.stop); } while (0);
 return 0;
}

variable_types:
opts
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // r13
char *v5; // rbp
char *v6; // rax
bool v7; // cf
bool v8; // zf
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rdi
__int64 v12; // rcx
char v13; // al
bool v14; // cf
bool v15; // zf
const char *v16; // rdi
__int64 v17; // rcx
__int64 v19[2]; // [rsp+38h] [rbp-48h] BYREF
__int64 v20; // [rsp+48h] [rbp-38h]

LODWORD(v19[0]) = 0;
v19[1] = 0LL;
LODWORD(v20) = 0;
if ( argc > 0 )
{
v3 = argv;
v4 = &argv[(unsigned int)(argc - 1) + 1];
do
{
v5 = (char *)*v3;
if ( !strcmp(*v3, "-h") || !strcmp(*v3, "--help") )
{
usage();
argv = (const char **)"-ho";
fuse_opt_add_arg(v19, "-ho");
}
else
{
v6 = index(*v3, 58);
v7 = 0;
v8 = v6 == 0LL;
if ( !v6 )
goto LABEL_12;
v9 = "rtu";
v10 = 3LL;
argv = (const char **)v5;
do
{
if ( !v10 )
break;
v7 = *(_BYTE *)argv < *v9;
v8 = *(_BYTE *)argv == *v9;
argv = (const char **)((char *)argv + 1);
++v9;
--v10;
}
while ( v8 );
LOBYTE(envp) = (!v7 && !v8) - v7;
v7 = 0;
v8 = (_BYTE)envp == 0;
if ( !(_BYTE)envp )
{
modbus_type = 0;
if ( (int)parse_rtu_opts(v6 + 1) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
else
{
LABEL_12:
v11 = "-d";
v12 = 3LL;
argv = (const char **)v5;
do
{
if ( !v12 )
break;
v7 = *(_BYTE *)argv < *v11;
v8 = *(_BYTE *)argv == *v11;
argv = (const char **)((char *)argv + 1);
++v11;
--v12;
}
while ( v8 );
v13 = (!v7 && !v8) - v7;
v14 = 0;
v15 = v13 == 0;
if ( v13 )
{
v16 = "--debug";
v17 = 8LL;
argv = (const char **)v5;
do
{
if ( !v17 )
break;
v14 = *(_BYTE *)argv < *v16;
v15 = *(_BYTE *)argv == *v16;
argv = (const char **)((char *)argv + 1);
++v16;
--v17;
}
while ( v15 );
if ( (!v14 && !v15) != v14 )
goto LABEL_21;
}
if ( ++enable_debug > 1 )
{
LABEL_21:
argv = (const char **)*v3;
fuse_opt_add_arg(v19, *v3);
}
}
}
++v3;
}
while ( v3 != v4 );
}
return modbusfs_start((unsigned int)modbus_type, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // r13
char *v5; // rbp
char *v6; // rax
bool v7; // cf
bool v8; // zf
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rdi
__int64 v12; // rcx
char v13; // al
bool v14; // cf
bool v15; // zf
const char *v16; // rdi
__int64 v17; // rcx
__int64 v19[2]; // [rsp+38h] [rbp-48h] BYREF
__int64 v20; // [rsp+48h] [rbp-38h]

LODWORD(v19[0]) = 0;
v19[1] = 0LL;
LODWORD(v20) = 0;
if ( argc > 0 )
{
v3 = argv;
v4 = &argv[(unsigned int)(argc - 1) + 1];
do
{
v5 = (char *)*v3;
if ( !strcmp(*v3, "-h") || !strcmp(*v3, "--help") )
{
func0();
argv = (const char **)"-ho";
fuse_opt_add_arg(v19, "-ho");
}
else
{
v6 = index(*v3, 58);
v7 = 0;
v8 = v6 == 0LL;
if ( !v6 )
goto LABEL_12;
v9 = "rtu";
v10 = 3LL;
argv = (const char **)v5;
do
{
if ( !v10 )
break;
v7 = *(_BYTE *)argv < *v9;
v8 = *(_BYTE *)argv == *v9;
argv = (const char **)((char *)argv + 1);
++v9;
--v10;
}
while ( v8 );
LOBYTE(envp) = (!v7 && !v8) - v7;
v7 = 0;
v8 = (_BYTE)envp == 0;
if ( !(_BYTE)envp )
{
modbus_type = 0;
if ( (int)func1(v6 + 1) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
else
{
LABEL_12:
v11 = "-d";
v12 = 3LL;
argv = (const char **)v5;
do
{
if ( !v12 )
break;
v7 = *(_BYTE *)argv < *v11;
v8 = *(_BYTE *)argv == *v11;
argv = (const char **)((char *)argv + 1);
++v11;
--v12;
}
while ( v8 );
v13 = (!v7 && !v8) - v7;
v14 = 0;
v15 = v13 == 0;
if ( v13 )
{
v16 = "--debug";
v17 = 8LL;
argv = (const char **)v5;
do
{
if ( !v17 )
break;
v14 = *(_BYTE *)argv < *v16;
v15 = *(_BYTE *)argv == *v16;
argv = (const char **)((char *)argv + 1);
++v16;
--v17;
}
while ( v15 );
if ( (!v14 && !v15) != v14 )
goto LABEL_21;
}
if ( ++enable_debug > 1 )
{
LABEL_21:
argv = (const char **)*v3;
fuse_opt_add_arg(v19, *v3);
}
}
}
++v3;
}
while ( v3 != v4 );
}
return modbusfs_start((unsigned int)modbus_type, argv, envp);
}

original_code:
int main(int argc, char *argv[])
{
 struct fuse_args args = { 0, ((void *)0), 0 };
 int i;
 char *ptr;
 int ret;
 for (i = 0; i < argc; i++) {
  if (strcmp(argv[i], "-h") == 0 ||
      strcmp(argv[i], "--help") == 0) {
   usage();
   fuse_opt_add_arg(&args, "-ho");
   continue;
  }
  ptr = index(argv[i], ':');
  if (ptr && strncmp(argv[i], "rtu", sizeof("rtu") - 1) == 0) {
   modbus_type = RTU;
   ret = parse_rtu_opts(ptr + 1);
   if (ret < 0) {
    fprintf(stderr, "invalid RTU options" "\n");
    exit(1);
   }
   continue;
  }
  if (strcmp(argv[i], "-d") == 0 ||
      strcmp(argv[i], "--debug") == 0) {
   enable_debug++;
   if (enable_debug < 2)
    continue;
  }
  fuse_opt_add_arg(&args, argv[i]);
 }
 return modbusfs_start(args, modbus_type, modbus_parms);
}

variable_types: struct fuse_args { int argc; char **argv; int allocated; }

variable_types: i int

variable_types:
ptr
char *


pPlaceUniformDisk

original_code:
Error pPlaceUniformDisk(ParticleContainer *particleContainer)
{
  Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double theta = 2 * 3.1415926535897932385 * drand48();
      double r = drand48();
      p->_position[0] = sqrt(r * radius) * cos(theta);
      p->_position[1] = sqrt(r * radius) * sin(theta);
    }
  return NO_ERROR;
}

canonical_original_code:
enum Error pPlaceUniformDisk(struct ParticleContainer *particleContainer)
{
  struct Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double theta = 2 * 3.1415926535897932385 * drand48();
      double r = drand48();
      p->_position[0] = sqrt(r * radius) * cos(theta);
      p->_position[1] = sqrt(r * radius) * sin(theta);
    }
  return NO_ERROR;
}

variable_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape { SQUARE=0, DISK=1 } _shape; double _radius; struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *_particles; struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *_particleStats; } *

variable_types:
numParticles
unsigned int

variable_types: radius double

variable_types:
i
unsigned int

variable_types: theta double

variable_types: r double

return_type: enum Error { MEMORY_ERROR=0, DIVIDE_BY_ZERO_ERROR=1, NO_ERROR=2 }

user_defined_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape _shape; double _radius; struct Particle *_particles; struct ParticleStats *_particleStats; }

user_defined_types: struct Particle { struct ParticleProperties *_properties; double *_position; }


pPlaceUniformSquare

original_code:
Error pPlaceUniformSquare(ParticleContainer *particleContainer)
{
  Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double x = drand48();
      double y = drand48();
      p->_position[0] = 2.0 * radius * (x - 0.5);
      p->_position[1] = 2.0 * radius * (y - 0.5);
    }
  return NO_ERROR;
}

canonical_original_code:
enum Error pPlaceUniformSquare(struct ParticleContainer *particleContainer)
{
  struct Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double x = drand48();
      double y = drand48();
      p->_position[0] = 2.0 * radius * (x - 0.5);
      p->_position[1] = 2.0 * radius * (y - 0.5);
    }
  return NO_ERROR;
}

variable_types: struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *

variable_types: x double

variable_types: y double

user_defined_types: enum Error { MEMORY_ERROR=0, DIVIDE_BY_ZERO_ERROR=1, NO_ERROR=2 }

user_defined_types: struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; }


pPlaceUniform

decompiled_code:
__int64 __fastcall pPlaceUniform(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // eax

v3 = *(_DWORD *)(a1 + 8);
if ( v3 )
{
if ( v3 == 1 )
{
*(_DWORD *)(a1 + 4) = 2;
a3 = pPlaceUniformDisk((double *)a1);
}
}
else
{
*(_DWORD *)(a1 + 4) = 2;
a3 = pPlaceUniformSquare((double *)a1);
}
return a3;
}

original_code:
Error pPlaceUniform(ParticleContainer *particleContainer)
{
  Error error;
  switch (particleContainer->_shape)
    {
    case DISK:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformDisk(particleContainer);
      break;
    case SQUARE:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformSquare(particleContainer);
      break;
    }
  return error;
}

canonical_original_code:
enum Error pPlaceUniform(struct ParticleContainer *particleContainer)
{
  enum Error error;
  switch (particleContainer->_shape)
    {
    case DISK:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformDisk(particleContainer);
      break;
    case SQUARE:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformSquare(particleContainer);
      break;
    }
  return error;
}

variable_types: enum Error { MEMORY_ERROR=0, DIVIDE_BY_ZERO_ERROR=1, NO_ERROR=2 }

user_defined_types: struct ParticleProperties { unsigned int _id; char *_name; }


pCreateParticles

decompiled_code:
__int64 __fastcall pCreateParticles(double **a1, __int64 a2, int a3, double a4)
{
double *v5; // rbx
void *v6; // rax
unsigned int v7; // edx

v5 = (double *)malloc(0x28uLL);
*a1 = v5;
*(_DWORD *)v5 = a2;
*((_DWORD *)v5 + 2) = a3;
v5[2] = a4;
v5[4] = 0.0;
v6 = malloc(16LL * (unsigned int)a2);
*((_QWORD *)v5 + 3) = v6;
if ( !v6 )
return 0LL;
pPlaceUniform((__int64)v5, a2, v7);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(double **a1, __int64 a2, int a3, double a4)
{
double *v5; // rbx
void *v6; // rax
unsigned int v7; // edx

v5 = (double *)malloc(0x28uLL);
*a1 = v5;
*(_DWORD *)v5 = a2;
*((_DWORD *)v5 + 2) = a3;
v5[2] = a4;
v5[4] = 0.0;
v6 = malloc(16LL * (unsigned int)a2);
*((_QWORD *)v5 + 3) = v6;
if ( !v6 )
return 0LL;
func2((__int64)v5, a2, v7);
return 2LL;
}

original_code:
Error pCreateParticles(ParticleContainer **particleContainer, unsigned int numParticles, Shape shape, double radius)
{
  *particleContainer = (ParticleContainer *) malloc(sizeof(ParticleContainer));
  (*particleContainer)->_numParticles = numParticles;
  (*particleContainer)->_shape = shape;
  (*particleContainer)->_radius = radius;
  (*particleContainer)->_particleStats = ((void *)0);
  if (((*particleContainer)->_particles = (Particle *) malloc(sizeof(Particle) * (*particleContainer)->_numParticles)) == ((void *)0))
    {
      return MEMORY_ERROR;
    }
  pPlaceUniform(*particleContainer);
  return NO_ERROR;
}

canonical_original_code:
enum Error pCreateParticles(struct ParticleContainer **particleContainer, unsigned int numParticles, enum Shape shape, double radius)
{
  *particleContainer = (struct ParticleContainer *) malloc(sizeof(ParticleContainer));
  (*particleContainer)->_numParticles = numParticles;
  (*particleContainer)->_shape = shape;
  (*particleContainer)->_radius = radius;
  (*particleContainer)->_particleStats = ((void *)0);
  if (((*particleContainer)->_particles = (struct Particle *) malloc(sizeof(Particle) * (*particleContainer)->_numParticles)) == ((void *)0))
    {
      return MEMORY_ERROR;
    }
  pPlaceUniform(*particleContainer);
  return NO_ERROR;
}

variable_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape { SQUARE=0, DISK=1 } _shape; double _radius; struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *_particles; struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *_particleStats; } **

variable_types:
shape
enum Shape { SQUARE=0, DISK=1 }


pDistance

original_code:
Error pDistance(Particle *p, Particle *q, unsigned int numDimensions, double *distance)
{
  unsigned int i;
  *distance = 0.0;
  for (i = 0; i<numDimensions; i++)
    {
      *distance += pow((p->_position[i] - q->_position[i]), 2);
    }
  *distance = sqrt(*distance);
  return NO_ERROR;
}

canonical_original_code:
enum Error pDistance(struct Particle *p, struct Particle *q, unsigned int numDimensions, double *distance)
{
  unsigned int i;
  *distance = 0.0;
  for (i = 0; i<numDimensions; i++)
    {
      *distance += pow((p->_position[i] - q->_position[i]), 2);
    }
  *distance = sqrt(*distance);
  return NO_ERROR;
}

variable_types:
q
struct Particle *

variable_types:
numDimensions
unsigned int

variable_types:
distance
double *


pInverseSquareDistance

decompiled_code:
__int64 __fastcall pInverseSquareDistance(__int64 a1, __int64 a2, unsigned int a3, double *a4)
{
double v5; // xmm0_8

pDistance(a1, a2, a3, a4);
v5 = *a4;
if ( v5 == 0.0 )
return 1LL;
*a4 = 1.0 / (v5 * v5);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, double *a4)
{
double v5; // xmm0_8

func4(a1, a2, a3, a4);
v5 = *a4;
if ( v5 == 0.0 )
return 1LL;
*a4 = 1.0 / (v5 * v5);
return 2LL;
}

original_code:
Error pInverseSquareDistance(Particle *p, Particle *q, unsigned int numDimensions, double *invSqrDistance)
{
  pDistance(p, q, numDimensions, invSqrDistance);
  if (*invSqrDistance == 0.0)
    {
      return DIVIDE_BY_ZERO_ERROR;
    }
  *invSqrDistance = 1.0 / (*invSqrDistance * *invSqrDistance);
  return NO_ERROR;
}

canonical_original_code:
enum Error pInverseSquareDistance(struct Particle *p, struct Particle *q, unsigned int numDimensions, double *invSqrDistance)
{
  pDistance(p, q, numDimensions, invSqrDistance);
  if (*invSqrDistance == 0.0)
    {
      return DIVIDE_BY_ZERO_ERROR;
    }
  *invSqrDistance = 1.0 / (*invSqrDistance * *invSqrDistance);
  return NO_ERROR;
}

variable_types:
invSqrDistance
double *


pCalcDistanceInvSqrMean

original_code:
Error pCalcDistanceInvSqrMean(ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  Error error;
  double invSqrDistanceMeanSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  Particle *p;
  Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += invSqrDistanceParticle;
 }
      invSqrDistanceMeanSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrMean = invSqrDistanceMeanSum / numParticles;
  return NO_ERROR;
}

canonical_original_code:
enum Error pCalcDistanceInvSqrMean(struct ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  enum Error error;
  double invSqrDistanceMeanSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  struct Particle *p;
  struct Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += invSqrDistanceParticle;
 }
      invSqrDistanceMeanSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrMean = invSqrDistanceMeanSum / numParticles;
  return NO_ERROR;
}

variable_types:
j
unsigned int

variable_types: invSqrDistanceMeanSum double

variable_types: invSqrDistanceParticle double

variable_types: invSqrDistanceParticleSum double


pCalcDistanceInvSqrVariance

original_code:
Error pCalcDistanceInvSqrVariance(ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  double invSqrDistanceMean = particleContainer->_particleStats->_distanceInvSqrMean;
  Error error;
  double invSqrDistanceVarianceSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  Particle *p;
  Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += pow(invSqrDistanceParticle - invSqrDistanceMean, 2);
 }
      invSqrDistanceVarianceSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrVariance = invSqrDistanceVarianceSum / numParticles;
  return NO_ERROR;
}

canonical_original_code:
enum Error pCalcDistanceInvSqrVariance(struct ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  double invSqrDistanceMean = particleContainer->_particleStats->_distanceInvSqrMean;
  enum Error error;
  double invSqrDistanceVarianceSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  struct Particle *p;
  struct Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += pow(invSqrDistanceParticle - invSqrDistanceMean, 2);
 }
      invSqrDistanceVarianceSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrVariance = invSqrDistanceVarianceSum / numParticles;
  return NO_ERROR;
}

variable_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape { SQUARE=0, DISK=1 } _shape; double _radius; struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *_particles; struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *_particleStats; } *

variable_types:
i
unsigned int

variable_types:
numParticles
unsigned int

variable_types: invSqrDistanceMean double

variable_types: invSqrDistanceVarianceSum double


pGenStatistics

decompiled_code:
__int64 __fastcall pGenStatistics(__int64 a1)
{
*(_QWORD *)(a1 + 32) = malloc(0x30uLL);
pCalcPositionMean(a1);
pCalcPositionVariance(a1);
pCalcDistanceMean(a1);
pCalcDistanceVariance(a1);
pCalcDistanceInvSqrMean(a1);
pCalcDistanceInvSqrVariance(a1);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
*(_QWORD *)(a1 + 32) = malloc(0x30uLL);
func0(a1);
func1(a1);
func2(a1);
func3(a1);
func4(a1);
func5(a1);
return 2LL;
}

original_code:
Error pGenStatistics(ParticleContainer *particleContainer)
{
  particleContainer->_particleStats = (ParticleStats *) malloc(sizeof(ParticleStats));
  pCalcPositionMean(particleContainer);
  pCalcPositionVariance(particleContainer);
  pCalcDistanceMean(particleContainer);
  pCalcDistanceVariance(particleContainer);
  pCalcDistanceInvSqrMean(particleContainer);
  pCalcDistanceInvSqrVariance(particleContainer);
  return NO_ERROR;
}

canonical_original_code:
enum Error pGenStatistics(struct ParticleContainer *particleContainer)
{
  particleContainer->_particleStats = (struct ParticleStats *) malloc(sizeof(ParticleStats));
  pCalcPositionMean(particleContainer);
  pCalcPositionVariance(particleContainer);
  pCalcDistanceMean(particleContainer);
  pCalcDistanceVariance(particleContainer);
  pCalcDistanceInvSqrMean(particleContainer);
  pCalcDistanceInvSqrVariance(particleContainer);
  return NO_ERROR;
}


pPrintStatistics

decompiled_code:
int __fastcall pPrintStatistics(unsigned int *a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v7[7]; // [rsp+0h] [rbp-38h]

printf("numParticles %u\n", *a1);
v1 = a1[2];
if ( v1 )
{
if ( v1 == 1 )
puts("shape disk");
}
else
{
puts("shape square");
}
v2 = *((_QWORD *)a1 + 4);
v7[0] = (__int64)aXyzt;
v7[1] = (__int64)&aXyzt[1];
v7[2] = (__int64)&aXyzt[2];
v7[3] = (__int64)&aXyzt[3];
if ( a1[1] )
{
v3 = 0LL;
do
{
printf("%sMean %f\n", (const char *)v7[v3], *(double *)(*(_QWORD *)v2 + 8 * v3));
v4 = a1[1];
++v3;
}
while ( v4 > (unsigned int)v3 );
if ( v4 )
{
v5 = 0LL;
do
{
printf("%sVariance %f\n", (const char *)v7[v5], *(double *)(*(_QWORD *)(v2 + 8) + 8 * v5));
++v5;
}
while ( a1[1] > (unsigned int)v5 );
}
}
printf("distanceMean %f\n", *(double *)(v2 + 16));
printf("distanceVariance %f\n", *(double *)(v2 + 24));
printf("distanceInverseSquareMean %f\n", *(double *)(v2 + 32));
return printf("distanceInverseSquaredVariance %f\n", *(double *)(v2 + 40));
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v7[7]; // [rsp+0h] [rbp-38h]

printf("numParticles %u\n", *a1);
v1 = a1[2];
if ( v1 )
{
if ( v1 == 1 )
puts("shape disk");
}
else
{
puts("shape square");
}
v2 = *((_QWORD *)a1 + 4);
v7[0] = (__int64)aXyzt;
v7[1] = (__int64)&aXyzt[1];
v7[2] = (__int64)&aXyzt[2];
v7[3] = (__int64)&aXyzt[3];
if ( a1[1] )
{
v3 = 0LL;
do
{
printf("%sMean %f\n", (const char *)v7[v3], *(double *)(*(_QWORD *)v2 + 8 * v3));
v4 = a1[1];
++v3;
}
while ( v4 > (unsigned int)v3 );
if ( v4 )
{
v5 = 0LL;
do
{
printf("%sVariance %f\n", (const char *)v7[v5], *(double *)(*(_QWORD *)(v2 + 8) + 8 * v5));
++v5;
}
while ( a1[1] > (unsigned int)v5 );
}
}
printf("distanceMean %f\n", *(double *)(v2 + 16));
printf("distanceVariance %f\n", *(double *)(v2 + 24));
printf("distanceInverseSquareMean %f\n", *(double *)(v2 + 32));
return printf("distanceInverseSquaredVariance %f\n", *(double *)(v2 + 40));
}

original_code:
void pPrintStatistics(ParticleContainer *particleContainer)
{
  printf("numParticles %u\n", particleContainer->_numParticles);
  switch (particleContainer->_shape)
    {
    case DISK:
      printf("shape disk\n");
      break;
    case SQUARE:
      printf("shape square\n");
      break;
    }
  ParticleStats *particleStats = particleContainer->_particleStats;
  char *positions[] = {"x", "y", "z", "t"};
  unsigned int i;
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sMean %f\n", positions[i], particleStats->_positionMean[i]);
    }
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sVariance %f\n", positions[i], particleStats->_positionVariance[i]);
    }
  printf("distanceMean %f\n", particleStats->_distanceMean);
  printf("distanceVariance %f\n", particleStats->_distanceVariance);
  printf("distanceInverseSquareMean %f\n", particleStats->_distanceInvSqrMean);
  printf("distanceInverseSquaredVariance %f\n", particleStats->_distanceInvSqrVariance);
}

canonical_original_code:
void pPrintStatistics(struct ParticleContainer *particleContainer)
{
  printf("numParticles %u\n", particleContainer->_numParticles);
  switch (particleContainer->_shape)
    {
    case DISK:
      printf("shape disk\n");
      break;
    case SQUARE:
      printf("shape square\n");
      break;
    }
  struct ParticleStats *particleStats = particleContainer->_particleStats;
  char *positions[] = {"x", "y", "z", "t"};
  unsigned int i;
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sMean %f\n", positions[i], particleStats->_positionMean[i]);
    }
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sVariance %f\n", positions[i], particleStats->_positionVariance[i]);
    }
  printf("distanceMean %f\n", particleStats->_distanceMean);
  printf("distanceVariance %f\n", particleStats->_distanceVariance);
  printf("distanceInverseSquareMean %f\n", particleStats->_distanceInvSqrMean);
  printf("distanceInverseSquaredVariance %f\n", particleStats->_distanceInvSqrVariance);
}

variable_types: struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *

variable_types:
positions
char *[]


Compute

decompiled_code:
int __fastcall Compute(float a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

requested_time.tv_sec = (unsigned int)(int)a1;
requested_time.tv_nsec = (unsigned int)(int)(float)((float)(a1 - (float)SLODWORD(requested_time.tv_sec)) * 1000000000.0);
return nanosleep(&requested_time, &v2);
}

canonical_decompiled_code:
int __fastcall func10(float a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

requested_time.tv_sec = (unsigned int)(int)a1;
requested_time.tv_nsec = (unsigned int)(int)(float)((float)(a1 - (float)SLODWORD(requested_time.tv_sec)) * 1000000000.0);
return nanosleep(&requested_time, &v2);
}

original_code:
void Compute ( float effort )
{
  struct timespec rqtp;
  struct timespec rmtp;
  rqtp.tv_sec = (long) effort;
  rqtp.tv_nsec = (effort - ((long) effort) ) * 1000000000 ;
  nanosleep(&rqtp, &rmtp);
}

canonical_original_code:
void Compute(float effort)
{
  struct timespec rqtp;
  struct timespec rmtp;
  rqtp.tv_sec = (long) effort;
  rqtp.tv_nsec = (effort - ((long) effort) ) * 1000000000 ;
  nanosleep(&rqtp, &rmtp);
}

variable_types: effort float

variable_types: struct timespec { long tv_sec; long tv_nsec; }


thread

repo: cota/atomictest

decompiled_code:
void *__fastcall thread(void *a1)
{
__int64 v1; // rbx

v1 = 0x80000LL;
do
{
atomic_inc((volatile signed __int32 *)&val);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
__int64 v1; // rbx

v1 = 0x80000LL;
do
{
func8((volatile signed __int32 *)&val);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
static void *thread(void *args)
{
 unsigned long i;
 for (i = 0; i < ops; i++)
  atomic_inc(&val);
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
i
unsigned long

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
size_t v4; // r13
pthread_t *v5; // r12
pthread_t *v6; // rbx
size_t v7; // rbp
size_t v8; // rbx
__int64 v9; // rbx
__int64 v10; // rax
struct timeval v12; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v3 = argc - 1;
if ( v3 )
n_threads = strtoul(argv[v3], 0LL, 0);
else
n_threads = 1LL;
printf("%lu n_threads\n", n_threads);
v4 = n_threads;
v5 = (pthread_t *)calloc(n_threads, 8uLL);
if ( !v5 )
{
perror("threads");
exit(1);
}
if ( gettimeofday(&tv, 0LL) )
{
perror("gettimeofday");
exit(1);
}
v6 = v5;
v7 = 0LL;
if ( v4 )
{
do
{
if ( pthread_create(v6, 0LL, thread, 0LL) )
{
perror("thread_create");
exit(1);
}
++v7;
++v6;
}
while ( n_threads > v7 );
if ( n_threads )
{
v8 = 0LL;
do
pthread_join(v5[v8++], 0LL);
while ( n_threads > v8 );
}
}
if ( gettimeofday(&v12, 0LL) )
perror("gettimeofday");
v9 = tv_to_ul(&tv);
v10 = tv_to_ul(&v12);
printf("%lu ns\n%lu ops\n%lu ns/access\n", 1000 * (v10 - v9), 0x80000LL, (unsigned __int64)(1000 * (v10 - v9)) >> 19);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
size_t v4; // r13
pthread_t *v5; // r12
pthread_t *v6; // rbx
size_t v7; // rbp
size_t v8; // rbx
__int64 v9; // rbx
__int64 v10; // rax
struct timeval v12; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v3 = argc - 1;
if ( v3 )
n_threads = strtoul(argv[v3], 0LL, 0);
else
n_threads = 1LL;
printf("%lu n_threads\n", n_threads);
v4 = n_threads;
v5 = (pthread_t *)calloc(n_threads, 8uLL);
if ( !v5 )
{
perror("threads");
exit(1);
}
if ( gettimeofday(&tv, 0LL) )
{
perror("gettimeofday");
exit(1);
}
v6 = v5;
v7 = 0LL;
if ( v4 )
{
do
{
if ( pthread_create(v6, 0LL, thread, 0LL) )
{
perror("thread_create");
exit(1);
}
++v7;
++v6;
}
while ( n_threads > v7 );
if ( n_threads )
{
v8 = 0LL;
do
pthread_join(v5[v8++], 0LL);
while ( n_threads > v8 );
}
}
if ( gettimeofday(&v12, 0LL) )
perror("gettimeofday");
v9 = func7(&tv);
v10 = func7(&v12);
printf("%lu ns\n%lu ops\n%lu ns/access\n", 1000 * (v10 - v9), 0x80000LL, (unsigned __int64)(1000 * (v10 - v9)) >> 19);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t *threads;
 struct timeval tv_start, tv_end;
 unsigned long start, end;
 unsigned long ns;
 int rc;
 int i;
 argc--;
 if (argc == 0)
  n_threads = 1;
 else
  n_threads = strtoul(argv[argc], ((void *)0), 0);
 printf("%lu n_threads\n", n_threads);
 threads = calloc(n_threads, sizeof(pthread_t));
 if (threads == ((void *)0)) {
  perror("threads");
  exit(1);
 }
 rc = gettimeofday(&tv_start, ((void *)0));
 if (rc) {
  perror("gettimeofday");
  exit(1);
 }
 for (i = 0; i < n_threads; i++) {
  rc = pthread_create(&threads[i], ((void *)0), thread, ((void *)0));
  if (rc) {
   perror("thread_create");
   exit(1);
  }
 }
 for (i = 0; i < n_threads; i++)
  pthread_join(threads[i], ((void *)0));
 rc = gettimeofday(&tv_end, ((void *)0));
 if (rc)
  perror("gettimeofday");
 start = tv_to_ul(&tv_start);
 end = tv_to_ul(&tv_end);
 ns = (end - start) * 1000;
 printf("%lu ns\n%lu ops\n%lu ns/access\n", ns, ops, ns / ops);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long *threads;
 struct timeval tv_start; struct timeval tv_end;
 unsigned long start; unsigned long end;
 unsigned long ns;
 int rc;
 int i;
 argc--;
 if (argc == 0)
  n_threads = 1;
 else
  n_threads = strtoul(argv[argc], ((void *)0), 0);
 printf("%lu n_threads\n", n_threads);
 threads = calloc(n_threads, sizeof(pthread_t));
 if (threads == ((void *)0)) {
  perror("threads");
  exit(1);
 }
 rc = gettimeofday(&tv_start, ((void *)0));
 if (rc) {
  perror("gettimeofday");
  exit(1);
 }
 for (i = 0; i < n_threads; i++) {
  rc = pthread_create(&threads[i], ((void *)0), thread, ((void *)0));
  if (rc) {
   perror("thread_create");
   exit(1);
  }
 }
 for (i = 0; i < n_threads; i++)
  pthread_join(threads[i], ((void *)0));
 rc = gettimeofday(&tv_end, ((void *)0));
 if (rc)
  perror("gettimeofday");
 start = tv_to_ul(&tv_start);
 end = tv_to_ul(&tv_end);
 ns = (end - start) * 1000;
 printf("%lu ns\n%lu ops\n%lu ns/access\n", ns, ops, ns / ops);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
threads
unsigned long *

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

variable_types:
start
unsigned long

variable_types:
end
unsigned long

variable_types:
ns
unsigned long

variable_types: rc int

variable_types: i int


JKISS

repo: cotillion/cd-gamedriver

variable_types:
t
unsigned long long

return_type: unsigned int


decompiled_code:
__int64 secure_rand()
{
int v0; // eax
int v1; // ebx
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 )
exit(-1);
v1 = v0;
if ( read(v0, buf, 4uLL) != 4 )
exit(-1);
close(v1);
return buf[0];
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // ebx
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 )
exit(-1);
v1 = v0;
if ( read(v0, buf, 4uLL) != 4 )
exit(-1);
close(v1);
return buf[0];
}

original_code:
unsigned int
secure_rand(void)
{
    int fn;
    unsigned int r;
    fn = open("/dev/urandom", 00);
    if (fn == -1)
        exit(-1);
    if (read(fn, &r, 4) != 4)
        exit(-1);
    close(fn);
    return r;
}

canonical_original_code:
unsigned int secure_rand()
{
    int fn;
    unsigned int r;
    fn = open("/dev/urandom", 00);
    if (fn == -1)
        exit(-1);
    if (read(fn, &r, 4) != 4)
        exit(-1);
    close(fn);
    return r;
}

variable_types: fn int

variable_types:
r
unsigned int


decompiled_code:
__int64 init_random()
{
unsigned int v0; // edx
__int64 result; // rax

x = secure_rand();
do
y = secure_rand();
while ( !y );
z = secure_rand();
v0 = secure_rand();
result = 698769068 * (v0 / 0x29A65EAC);
c = v0 % 0x29A65EAC + 1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // edx
__int64 result; // rax

x = func1();
do
y = func1();
while ( !y );
z = func1();
v0 = func1();
result = 698769068 * (v0 / 0x29A65EAC);
c = v0 % 0x29A65EAC + 1;
return result;
}

original_code:
void
init_random()
{
    x = secure_rand();
    while (!(y = secure_rand()));
    z = secure_rand();
    c = secure_rand() % 698769068 + 1;
}


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

x_save = x;
y_save = y;
z_save = z;
result = (unsigned int)c;
c_save = c;
x = 123456789;
y = a1;
z = 43219876;
c = 6543217;
return result;
}

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

x_save = x;
y_save = y;
z_save = z;
result = (unsigned int)c;
c_save = c;
x = 123456789;
y = a1;
z = 43219876;
c = 6543217;
return result;
}

original_code:
void
set_random_seed(unsigned int seed) {
    x_save = x; y_save = y; z_save = z; c_save = c;
    x = 123456789; y = seed; z = 43219876; c = 6543217;
}

variable_types:
seed
unsigned int


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

x = x_save;
y = y_save;
z = z_save;
result = (unsigned int)c_save;
c = c_save;
return result;
}

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

x = x_save;
y = y_save;
z = z_save;
result = (unsigned int)c_save;
c = c_save;
return result;
}

original_code:
void
clear_random_seed() {
    x = x_save; y = y_save; z = z_save; c = c_save;
}


decompiled_code:
unsigned __int64 __fastcall random_number(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx

if ( a1 <= 0 )
return 0LL;
v2 = (unsigned int)JKISS(a1, a2, 0LL);
return ((v2 << 32) + (unsigned __int64)(unsigned int)JKISS(a1, a2, v3)) % a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx

if ( a1 <= 0 )
return 0LL;
v2 = (unsigned int)func0(a1, a2, 0LL);
return ((v2 << 32) + (unsigned __int64)(unsigned int)func0(a1, a2, v3)) % a1;
}

original_code:
long long
random_number(long long n)
{
    if (n <= 0)
        return 0;
    return ((unsigned long long)JKISS() * 4294967296 + (unsigned long long)JKISS()) % n;
}

variable_types:
n
long long

return_type: long long


decompiled_code:
double __fastcall random_double(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ebx
__int64 v4; // rdx

v3 = JKISS(a1, a2, a3);
return ((double)(v3 >> 6) * 134217728.0 + (double)((unsigned int)JKISS(a1, a2, v4) >> 5)) * 1.110223024625157e-16;
}

original_code:
double
random_double()
{
    double x;
    unsigned int a, b;
    a = JKISS() >> 6;
    b = JKISS() >> 5;
    x = (a * 134217728.0 + b) / 9007199254740992.0;
    return x;
}

canonical_original_code:
double random_double()
{
    double x;
    unsigned int a; unsigned int b;
    a = JKISS() >> 6;
    b = JKISS() >> 5;
    x = (a * 134217728.0 + b) / 9007199254740992.0;
    return x;
}

variable_types: x double

variable_types:
a
unsigned int

variable_types:
b
unsigned int

return_type: double


decompiled_code:
__int64 init_hash()
{
__int64 i; // rbx
unsigned int v1; // edx
__int64 result; // rax
char v3; // cl

for ( i = 4LL; i != 20; i += 4LL )
{
v1 = secure_rand();
result = i - 4;
do
{
v3 = v1;
v1 >>= 8;
key[result++] = v3;
}
while ( result != i );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 i; // rbx
unsigned int v1; // edx
__int64 result; // rax
char v3; // cl

for ( i = 4LL; i != 20; i += 4LL )
{
v1 = secure_rand();
result = i - 4;
do
{
v3 = v1;
v1 >>= 8;
key[result++] = v3;
}
while ( result != i );
}
return result;
}

original_code:
void
init_hash() {
    int i = 0;
    while (i < sizeof(key)) {
        unsigned int rnd = secure_rand();
        for (int bit = 0; bit < sizeof(rnd); bit++) {
            unsigned char c = rnd & 0xff;
            rnd >>= 8;
            key[i] = c;
            i++;
        }
    }
}

variable_types:
rnd
unsigned int

variable_types: bit int

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall hash_string(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
return siphash(key, a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
return siphash(key, a1, v1);
}

original_code:
unsigned long long
hash_string(const char *s) {
    return siphash(key, (unsigned char *)s, strlen(s));
}

canonical_original_code:
unsigned long long hash_string(char *s) {
    return siphash(key, (unsigned char *)s, strlen(s));
}

variable_types:
s
char *

return_type: unsigned long long


decompiled_code:
__int64 f_upper_case()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_2A0;
if ( *qword_2A0 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_2A0 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_toupper_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_2A0;
if ( *qword_2A0 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_2A0 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_toupper_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

original_code:
void
f_upper_case(int num_arg)
{
    char *str;
    int i;
    if (sp->type == 0x2)
 return;
    str = make_mstring(sp->u.string);
    for (i = strlen(str)-1; i>=0; i--)
 str[i] = toupper(str[i]);
    pop_stack();
    push_mstring(str);
}

variable_types:
str
char *


decompiled_code:
__int64 f_lower_case()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_2A0;
if ( *qword_2A0 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_2A0 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_tolower_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_2A0;
if ( *qword_2A0 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_2A0 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_tolower_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

original_code:
void
f_lower_case(int num_arg)
{
    char *str;
    int i;
    if (sp->type == 0x2)
 return;
    str = make_mstring(sp->u.string);
    for (i = strlen(str)-1; i>=0; i--)
 str[i] = tolower(str[i]);
    pop_stack();
    push_mstring(str);
}


decompiled_code:
__int64 f_readable_string()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const unsigned __int16 **v3; // rsi
__int64 v4; // rax

result = qword_2A0;
if ( *qword_2A0 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_2A0 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_b_loc();
v4 = v2;
do
{
if ( ((*v3)[(unsigned __int8)v1[v4]] & 0x4000) == 0 )
v1[v4] = 46;
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const unsigned __int16 **v3; // rsi
__int64 v4; // rax

result = qword_2A0;
if ( *qword_2A0 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_2A0 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_b_loc();
v4 = v2;
do
{
if ( ((*v3)[(unsigned __int8)v1[v4]] & 0x4000) == 0 )
v1[v4] = 46;
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

original_code:
void
f_readable_string(int num_arg)
{
    if (sp->type == 0x2)
        return;
    char *str = make_mstring(sp->u.string);
    for (int i = strlen(str) - 1; i >= 0; i--) {
        unsigned char c = str[i];
        if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint))
            str[i] = '.';
    }
    pop_stack();
    push_mstring(str);
}

canonical_original_code:
void f_readable_string(int num_arg)
{
    if (sp->type == 0x2)
        return;
    char *str = make_mstring(sp->u.string);
    for (int i = strlen(str) - 1; i >= 0; i--) {
        unsigned char c = str[i];
        if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint))
            str[i] = '.';
    }
    pop_stack();
    push_mstring(str);
}


decompiled_code:
__int64 f_strlen()
{
int v0; // ebx

v0 = 0;
if ( *qword_2A0 != 2 )
v0 = strlen(*(const char **)(qword_2A0 + 8LL));
pop_stack();
return push_number(v0);
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx

v0 = 0;
if ( *qword_2A0 != 2 )
v0 = strlen(*(const char **)(qword_2A0 + 8LL));
pop_stack();
return push_number(v0);
}

original_code:
void
f_strlen(int xxx)
{
    int i;
    if (sp->type == 0x2)
 i = 0;
    else
 i = strlen(sp->u.string);
    pop_stack();
    push_number(i);
}

variable_types: xxx int


decompiled_code:
const char *__fastcall get_auth_name(const char *a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
unsigned int v5; // ebp
struct addrinfo *v6; // r12
const char *result; // rax
const char *v8; // rax
int v9; // eax
int v10; // ebx
int v11; // er15
char v12; // al
bool v13; // zf
int v14; // er15
unsigned int v15; // eax
int v16; // er12
__int64 v17; // r13
int v18; // er14
fd_set v19; // [rsp+0h] [rbp-508h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-488h] BYREF
char buf[1032]; // [rsp+90h] [rbp-478h] BYREF
struct addrinfo *pai; // [rsp+498h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+4A0h] [rbp-68h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v4 = getaddrinfo(a1, "113", &req, &pai);
v5 = v4;
if ( v4 )
{
v8 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo failed: %s\n", v8);
return 0LL;
}
v6 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
return "";
}
while ( 1 )
{
v9 = socket(v6->ai_family, v6->ai_socktype, v6->ai_protocol);
v10 = v9;
if ( v9 != -1 )
break;
LABEL_5:
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_3;
}
if ( connect(v9, v6->ai_addr, v6->ai_addrlen) == -1 )
{
close(v10);
goto LABEL_5;
}
freeaddrinfo(pai);
sprintf(buf, "%u , %u\r\n", a3, a2);
v14 = strlen(buf);
v15 = fcntl(v10, 3);
BYTE1(v15) |= 8u;
fcntl(v10, 4, v15);
memset(&v19, 0, sizeof(v19));
v16 = v10 / 64;
v17 = 1LL << (v10 % 64);
v19.fds_bits[v10 / 64] |= v17;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
v18 = v10 + 1;
if ( select(v10 + 1, 0LL, &v19, 0LL, &timeout) && (v19.fds_bits[v16] & v17) != 0 )
{
if ( write(v10, buf, v14) == v14
&& (memset(&v19, 0, sizeof(v19)),
v19.fds_bits[v16] |= v17,
timeout.tv_sec = 10LL,
timeout.tv_usec = 0LL,
select(v18, &v19, 0LL, 0LL, &timeout))
&& (v11 = 2002, (v19.fds_bits[v16] & v17) != 0) )
{
do
{
memset(&v19, 0, sizeof(v19));
v19.fds_bits[v16] |= v17;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
if ( !select(v18, &v19, 0LL, 0LL, &timeout) )
break;
if ( (v19.fds_bits[v16] & v17) == 0 )
break;
if ( read(v10, &buf[v5], 1uLL) != 1 )
break;
v12 = buf[v5];
if ( v12 == 10 )
break;
v5 += (v12 & 0xFB) != 9;
if ( !--v11 )
goto LABEL_10;
}
while ( v5 <= 0x3FE );
buf[v5] = 0;
close(v10);
v13 = (unsigned int)__isoc99_sscanf() == 1;
result = "";
if ( v13 )
result = (const char *)&user_name_1;
}
else
{
LABEL_10:
close(v10);
result = "";
}
}
else
{
close(v10);
result = "%u , %u\r\n" + 9;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
unsigned int v5; // ebp
struct addrinfo *v6; // r12
const char *result; // rax
const char *v8; // rax
int v9; // eax
int v10; // ebx
int v11; // er15
char v12; // al
bool v13; // zf
int v14; // er15
unsigned int v15; // eax
int v16; // er12
__int64 v17; // r13
int v18; // er14
fd_set v19; // [rsp+0h] [rbp-508h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-488h] BYREF
char buf[1032]; // [rsp+90h] [rbp-478h] BYREF
struct addrinfo *pai; // [rsp+498h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+4A0h] [rbp-68h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v4 = getaddrinfo(a1, "113", &req, &pai);
v5 = v4;
if ( v4 )
{
v8 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo failed: %s\n", v8);
return 0LL;
}
v6 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
return "";
}
while ( 1 )
{
v9 = socket(v6->ai_family, v6->ai_socktype, v6->ai_protocol);
v10 = v9;
if ( v9 != -1 )
break;
LABEL_5:
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_3;
}
if ( connect(v9, v6->ai_addr, v6->ai_addrlen) == -1 )
{
close(v10);
goto LABEL_5;
}
freeaddrinfo(pai);
sprintf(buf, "%u , %u\r\n", a3, a2);
v14 = strlen(buf);
v15 = fcntl(v10, 3);
BYTE1(v15) |= 8u;
fcntl(v10, 4, v15);
memset(&v19, 0, sizeof(v19));
v16 = v10 / 64;
v17 = 1LL << (v10 % 64);
v19.fds_bits[v10 / 64] |= v17;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
v18 = v10 + 1;
if ( select(v10 + 1, 0LL, &v19, 0LL, &timeout) && (v19.fds_bits[v16] & v17) != 0 )
{
if ( write(v10, buf, v14) == v14
&& (memset(&v19, 0, sizeof(v19)),
v19.fds_bits[v16] |= v17,
timeout.tv_sec = 10LL,
timeout.tv_usec = 0LL,
select(v18, &v19, 0LL, 0LL, &timeout))
&& (v11 = 2002, (v19.fds_bits[v16] & v17) != 0) )
{
do
{
memset(&v19, 0, sizeof(v19));
v19.fds_bits[v16] |= v17;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
if ( !select(v18, &v19, 0LL, 0LL, &timeout) )
break;
if ( (v19.fds_bits[v16] & v17) == 0 )
break;
if ( read(v10, &buf[v5], 1uLL) != 1 )
break;
v12 = buf[v5];
if ( v12 == 10 )
break;
v5 += (v12 & 0xFB) != 9;
if ( !--v11 )
goto LABEL_10;
}
while ( v5 <= 0x3FE );
buf[v5] = 0;
close(v10);
v13 = (unsigned int)__isoc99_sscanf() == 1;
result = "";
if ( v13 )
result = (const char *)&user_name_1;
}
else
{
LABEL_10:
close(v10);
result = "";
}
}
else
{
close(v10);
result = "%u , %u\r\n" + 9;
}
return result;
}

original_code:
char *
get_auth_name(char *addr, int local_port, int remote_port)
{
    struct addrinfo hints;
    struct addrinfo *result, *rp;
    int s, flags;
    char buf[1024];
    static char user_name[1024];
    int buflen;
    int i, n;
    struct timeval timeout;
    fd_set fs;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    s = getaddrinfo(addr, "113", &hints, &result);
    if (s != 0)
    {
        fprintf (stderr, "getaddrinfo failed: %s\n", gai_strerror(s));
        return ((void *)0);
    }
    for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
        s = socket(rp->ai_family, rp->ai_socktype,
                     rp->ai_protocol);
        if (s == -1)
            continue;
        if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
            break;
        close(s);
    }
    freeaddrinfo(result);
    if (rp == ((void *)0))
        return "";
   (void)sprintf(buf, "%u , %u\r\n", remote_port, local_port);
    buflen = strlen(buf);
    flags = fcntl(s, 3);
    (void)fcntl(s, 4, flags | 04000);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    if (select(s + 1, ((void *)0), &fs, ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    if (write(s, buf, buflen) != buflen) {
        (void)close(s);
        return "";
    }
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    for (n = i = 0; i < sizeof buf - 1; n++) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
        if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
            !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            break;
        if (read(s, buf + i, 1) != 1)
            break;
        if (buf[i] == '\n')
            break;
        if ( buf[i] != '\t' && buf[i] != '\r')
            i++;
        if (n > 2000) {
            (void)close(s);
            return "";
        }
    }
    buf[i] = 0;
    (void)close(s);
    if(sscanf(buf, "%*u , %*u : USERID :%*[^:]:%s", user_name) != 1)
        return "";
    else
        return user_name;
}

canonical_original_code:
char *get_auth_name(char *addr, int local_port, int remote_port)
{
    struct addrinfo hints;
    struct addrinfo *result; struct addrinfo *rp;
    int s; int flags;
    char buf[1024];
    static char user_name[1024];
    int buflen;
    int i; int n;
    struct timeval timeout;
    struct fd_set fs;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    s = getaddrinfo(addr, "113", &hints, &result);
    if (s != 0)
    {
        fprintf (stderr, "getaddrinfo failed: %s\n", gai_strerror(s));
        return ((void *)0);
    }
    for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
        s = socket(rp->ai_family, rp->ai_socktype,
                     rp->ai_protocol);
        if (s == -1)
            continue;
        if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
            break;
        close(s);
    }
    freeaddrinfo(result);
    if (rp == ((void *)0))
        return "";
   (void)sprintf(buf, "%u , %u\r\n", remote_port, local_port);
    buflen = strlen(buf);
    flags = fcntl(s, 3);
    (void)fcntl(s, 4, flags | 04000);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    if (select(s + 1, ((void *)0), &fs, ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    if (write(s, buf, buflen) != buflen) {
        (void)close(s);
        return "";
    }
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    for (n = i = 0; i < sizeof buf - 1; n++) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
        if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
            !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            break;
        if (read(s, buf + i, 1) != 1)
            break;
        if (buf[i] == '\n')
            break;
        if ( buf[i] != '\t' && buf[i] != '\r')
            i++;
        if (n > 2000) {
            (void)close(s);
            return "";
        }
    }
    buf[i] = 0;
    (void)close(s);
    if(sscanf(buf, "%*u , %*u : USERID :%*[^:]:%s", user_name) != 1)
        return "";
    else
        return user_name;
}

variable_types:
addr
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: s int

variable_types: flags int

variable_types:
buf
char [1024]

variable_types: buflen int

variable_types: n int

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

variable_types:
fs
struct fd_set { long __fds_bits[-1]; }

return_type: char *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
char *__fastcall reverse_lookup(const char *a1)
{
int v1; // eax
int v2; // ebx
char *result; // rax
const char *v4; // rax
struct addrinfo v5; // [rsp+0h] [rbp-48h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-10h] BYREF

*(_QWORD *)&v5.ai_flags = 0LL;
*(_QWORD *)&v5.ai_socktype = 1LL;
*(_QWORD *)&v5.ai_addrlen = 0LL;
v5.ai_addr = 0LL;
v5.ai_canonname = 0LL;
v5.ai_next = 0LL;
v1 = getaddrinfo(a1, 0LL, &v5, &pai);
if ( v1 )
{
v4 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo failed: %s\n", v4);
result = 0LL;
}
else
{
v2 = getnameinfo(pai->ai_addr, pai->ai_addrlen, buf_0, 0x401u, 0LL, 0, 8);
freeaddrinfo(pai);
result = buf_0;
if ( v2 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1)
{
int v1; // eax
int v2; // ebx
char *result; // rax
const char *v4; // rax
struct addrinfo v5; // [rsp+0h] [rbp-48h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-10h] BYREF

*(_QWORD *)&v5.ai_flags = 0LL;
*(_QWORD *)&v5.ai_socktype = 1LL;
*(_QWORD *)&v5.ai_addrlen = 0LL;
v5.ai_addr = 0LL;
v5.ai_canonname = 0LL;
v5.ai_next = 0LL;
v1 = getaddrinfo(a1, 0LL, &v5, &pai);
if ( v1 )
{
v4 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo failed: %s\n", v4);
result = 0LL;
}
else
{
v2 = getnameinfo(pai->ai_addr, pai->ai_addrlen, buf_0, 0x401u, 0LL, 0, 8);
freeaddrinfo(pai);
result = buf_0;
if ( v2 )
result = 0LL;
}
return result;
}

original_code:
char *
reverse_lookup(char *ip)
{
    static char buf[1025];
    struct addrinfo *addrs;
    struct addrinfo hints;
    int ret;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    ret = getaddrinfo(ip, ((void *)0), &hints, &addrs);
    if (ret != 0)
    {
        fprintf (stderr, "getaddrinfo failed: %s\n", gai_strerror (ret));
        return ((void *)0);
    }
    ret = getnameinfo(addrs->ai_addr, addrs->ai_addrlen, buf, sizeof(buf), ((void *)0), 0, 8);
    freeaddrinfo (addrs);
    if (ret != 0)
    {
        return ((void *)0);
    }
    return buf;
}

canonical_original_code:
char *reverse_lookup(char *ip)
{
    static char buf[1025];
    struct addrinfo *addrs;
    struct addrinfo hints;
    int ret;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    ret = getaddrinfo(ip, ((void *)0), &hints, &addrs);
    if (ret != 0)
    {
        fprintf (stderr, "getaddrinfo failed: %s\n", gai_strerror (ret));
        return ((void *)0);
    }
    ret = getnameinfo(addrs->ai_addr, addrs->ai_addrlen, buf, sizeof(buf), ((void *)0), 0, 8);
    freeaddrinfo (addrs);
    if (ret != 0)
    {
        return ((void *)0);
    }
    return buf;
}

variable_types:
ip
char *

variable_types:
buf
char [1025]

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

variable_types: ret int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rax
char *v5; // rbx
char *v6; // rbp
char *v7; // r12
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

setlinebuf(stdout);
putchar(10);
while ( fgets(v9, 256, stdin) )
{
v4 = strrchr(v9, 10);
if ( v4 )
*v4 = 0;
v5 = strtok(v9, ",");
v6 = strtok(0LL, ",");
v7 = strtok(0LL, ",");
if ( v6 != 0LL && v5 != 0LL && v7 )
{
v3 = reverse_lookup(v5);
if ( !v3 )
v3 = v5;
printf("%s,%s,%s,%s,%s\n", v5, v6, v7, v3, "");
}
else
{
fprintf(stderr, "Invalid input format: %s\n", v9);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rax
char *v5; // rbx
char *v6; // rbp
char *v7; // r12
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

setlinebuf(stdout);
putchar(10);
while ( fgets(v9, 256, stdin) )
{
v4 = strrchr(v9, 10);
if ( v4 )
*v4 = 0;
v5 = strtok(v9, ",");
v6 = strtok(0LL, ",");
v7 = strtok(0LL, ",");
if ( v6 != 0LL && v5 != 0LL && v7 )
{
v3 = func8(v5);
if ( !v3 )
v3 = v5;
printf("%s,%s,%s,%s,%s\n", v5, v6, v7, v3, "");
}
else
{
fprintf(stderr, "Invalid input format: %s\n", v9);
}
}
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
    char buf[0x100];
    char *local_port;
    char *remote_port;
    char *addr;
    char *ptr;
    char *ident = "";
    char *reverse;
    (void)setlinebuf(stdout);
    (void)printf("\n");
    while (1)
    {
        if (fgets(buf, sizeof(buf), stdin) == ((void *)0))
            break;
        if ((ptr = strrchr(buf, '\n')))
            *ptr = '\0';
        addr = strtok(buf, ",");
        local_port = strtok(((void *)0), ",");
        remote_port = strtok(((void *)0), ",");
        if (addr == ((void *)0) || local_port == ((void *)0) || remote_port == ((void *)0))
        {
            fprintf(stderr, "Invalid input format: %s\n", buf);
            continue;
        }
        reverse = reverse_lookup(addr);
        if (reverse == ((void *)0))
            reverse = addr;
        printf("%s,%s,%s,%s,%s\n", addr, local_port, remote_port, reverse, ident);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char buf[256];
    char *local_port;
    char *remote_port;
    char *addr;
    char *ptr;
    char *ident = "";
    char *reverse;
    (void)setlinebuf(stdout);
    (void)printf("\n");
    while (1)
    {
        if (fgets(buf, sizeof(buf), stdin) == ((void *)0))
            break;
        if ((ptr = strrchr(buf, '\n')))
            *ptr = '\0';
        addr = strtok(buf, ",");
        local_port = strtok(((void *)0), ",");
        remote_port = strtok(((void *)0), ",");
        if (addr == ((void *)0) || local_port == ((void *)0) || remote_port == ((void *)0))
        {
            fprintf(stderr, "Invalid input format: %s\n", buf);
            continue;
        }
        reverse = reverse_lookup(addr);
        if (reverse == ((void *)0))
            reverse = addr;
        printf("%s,%s,%s,%s,%s\n", addr, local_port, remote_port, reverse, ident);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
char [256]

variable_types:
ptr
char *

variable_types:
ident
char *

variable_types:
reverse
char *


decompiled_code:
int update_snoop_file()
{
__int64 v0; // rbx
bool v1; // dl
__int64 v2; // rax
int v3; // edi
__int64 *v4; // r12
int result; // eax
__int64 v6; // rbx
__int64 v7; // rax
const char *v8; // rdi
__int64 v9; // rbp

if ( num_super_snooped )
{
v0 = 1LL;
do
{
v2 = *((_QWORD *)&all_players + v0 - 1);
if ( v2 )
{
v3 = *(_DWORD *)(v2 + 256);
if ( v3 >= 0 )
{
close(v3);
*(_DWORD *)(*((_QWORD *)&all_players + v0 - 1) + 256LL) = -1;
--num_super_snooped;
}
}
v1 = (int)v0++ <= 3999;
}
while ( num_super_snooped != 0 && v1 );
}
read_snoop_file();
v4 = (__int64 *)&all_players;
do
{
result = num_super_snooped;
if ( num_super_snooped > 0 )
{
v9 = *v4;
v6 = 0LL;
while ( 1 )
{
if ( v9 )
{
v7 = *(_QWORD *)(v9 + 8);
if ( v7 )
{
v8 = *(const char **)(v7 + 152);
if ( v8 )
{
if ( !strcmp(v8, &super_snooped[16 * v6]) )
break;
}
}
}
result = num_super_snooped;
if ( num_super_snooped <= (int)++v6 )
goto LABEL_14;
}
result = open((const char *)&super_snoopfile[4 * (int)v6], 1089, 384LL);
*(_DWORD *)(v9 + 256) = result;
}
LABEL_14:
++v4;
}
while ( v4 != (__int64 *)(unsigned int)((_DWORD)&all_players + 32000) );
return result;
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbx
bool v1; // dl
__int64 v2; // rax
int v3; // edi
__int64 *v4; // r12
int result; // eax
__int64 v6; // rbx
__int64 v7; // rax
const char *v8; // rdi
__int64 v9; // rbp

if ( num_super_snooped )
{
v0 = 1LL;
do
{
v2 = *((_QWORD *)&all_players + v0 - 1);
if ( v2 )
{
v3 = *(_DWORD *)(v2 + 256);
if ( v3 >= 0 )
{
close(v3);
*(_DWORD *)(*((_QWORD *)&all_players + v0 - 1) + 256LL) = -1;
--num_super_snooped;
}
}
v1 = (int)v0++ <= 3999;
}
while ( num_super_snooped != 0 && v1 );
}
func0();
v4 = (__int64 *)&all_players;
do
{
result = num_super_snooped;
if ( num_super_snooped > 0 )
{
v9 = *v4;
v6 = 0LL;
while ( 1 )
{
if ( v9 )
{
v7 = *(_QWORD *)(v9 + 8);
if ( v7 )
{
v8 = *(const char **)(v7 + 152);
if ( v8 )
{
if ( !strcmp(v8, &super_snooped[16 * v6]) )
break;
}
}
}
result = num_super_snooped;
if ( num_super_snooped <= (int)++v6 )
goto LABEL_14;
}
result = open((const char *)&super_snoopfile[4 * (int)v6], 1089, 384LL);
*(_DWORD *)(v9 + 256) = result;
}
LABEL_14:
++v4;
}
while ( v4 != (__int64 *)(unsigned int)((_DWORD)&all_players + 32000) );
return result;
}

original_code:
void
update_snoop_file()
{
    int i, j;
    for (i = 0; num_super_snooped && i < 4000; i++)
 if (all_players[i] && all_players[i]->snoop_fd >= 0) {
     (void)close(all_players[i]->snoop_fd);
     all_players[i]->snoop_fd = -1;
     num_super_snooped--;
 }
    read_snoop_file();
    for (i = 0; i < 4000; i++)
 for (j = 0; j < num_super_snooped; j++)
     if (all_players[i] && all_players[i]->ob &&
  all_players[i]->ob->living_name &&
  strcmp(all_players[i]->ob->living_name, super_snooped[j]) == 0) {
  all_players[i]->snoop_fd = open(super_snoopfile[j],
       01 | 02000 | 0100,
       0600);
  break;
     }
}

canonical_original_code:
void update_snoop_file()
{
    int i; int j;
    for (i = 0; num_super_snooped && i < 4000; i++)
 if (all_players[i] && all_players[i]->snoop_fd >= 0) {
     (void)close(all_players[i]->snoop_fd);
     all_players[i]->snoop_fd = -1;
     num_super_snooped--;
 }
    read_snoop_file();
    for (i = 0; i < 4000; i++)
 for (j = 0; j < num_super_snooped; j++)
     if (all_players[i] && all_players[i]->ob &&
  all_players[i]->ob->living_name &&
  strcmp(all_players[i]->ob->living_name, super_snooped[j]) == 0) {
  all_players[i]->snoop_fd = open(super_snoopfile[j],
       01 | 02000 | 0100,
       0600);
  break;
     }
}

variable_types: i int

variable_types: j int


siphash

variable_types:
key
unsigned char [16]

variable_types:
m
unsigned char *

variable_types:
len
unsigned long

variable_types:
mi
unsigned long

variable_types:
i
unsigned long

variable_types:
blocks
unsigned long

return_type: unsigned long


lower

decompiled_code:
void __fastcall lower(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 **v3; // r12

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = __ctype_b_loc();
do
{
if ( ((*v3)[v1] & 0x100) != 0 )
*v2 = (*__ctype_tolower_loc())[v1];
v1 = *++v2;
}
while ( *v2 );
}
}

original_code:
void
lower(char *string)
{
    while (*string) {
        if (((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short int) _ISupper))
     *string = tolower(*string);
 string++;
    }
}

canonical_original_code:
void lower(char *string)
{
    while (*string) {
        if (((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short) _ISupper))
     *string = tolower(*string);
 string++;
    }
}

variable_types:
string
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
FILE *v4; // rax
FILE *v5; // rbx
int v6; // er12
int v7; // er13
char *v8; // rax
const char *v9; // r14
char *v10; // rdi
int v11; // eax
char v13; // [rsp+0h] [rbp-2028h] BYREF
char s[8231]; // [rsp+1h] [rbp-2027h] BYREF

if ( argc != 3 )
{
fwrite("Usage: make_table input.h output.h\n", 1uLL, 0x23uLL, _bss_start);
exit(1);
}
v3 = fopen(argv[1], "r");
if ( !v3 )
{
perror("fopen");
exit(1);
}
v4 = fopen(argv[2], "w");
v5 = v4;
if ( !v4 )
{
perror("fopen");
exit(1);
}
fwrite("/*\n", 1uLL, 3uLL, v4);
fwrite(" * This file is automatically generated; do not edit.\n", 1uLL, 0x36uLL, v5);
fwrite(" */\n\n", 1uLL, 5uLL, v5);
fwrite("#ifdef EFUN_TABLE\n", 1uLL, 0x12uLL, v5);
fwrite("static void (*efun_table[])(int) = {\n", 1uLL, 0x25uLL, v5);
v6 = 0;
v7 = 0x7FFFFFFF;
while ( fgets(&v13, 0x2000, v3) )
{
if ( v13 == 35 && !strcmp(strtok(s, " \t\n"), "define") )
{
v8 = strtok(0LL, " \t\n");
v9 = v8;
if ( v8 )
{
if ( *v8 == 70 && v8[1] == 95 )
{
lower(v8);
fprintf(v5, "\t%s,\n", v9);
v10 = strtok(0LL, " \t\n");
if ( v10 )
{
v11 = atoi(v10);
if ( v7 > v11 )
v7 = v11;
if ( v6 < v11 )
v6 = v11;
}
}
}
}
}
fwrite("};\n", 1uLL, 3uLL, v5);
fwrite("#else /* EFUN_TABLE */\n", 1uLL, 0x17uLL, v5);
fprintf(v5, "#define EFUN_FIRST %4d\n", (unsigned int)v7);
fprintf(v5, "#define EFUN_LAST %4d\n", (unsigned int)v6);
fwrite("#endif /* EFUN_TABLE */\n", 1uLL, 0x18uLL, v5);
fclose(v5);
fclose(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
FILE *v4; // rax
FILE *v5; // rbx
int v6; // er12
int v7; // er13
char *v8; // rax
const char *v9; // r14
char *v10; // rdi
int v11; // eax
char v13; // [rsp+0h] [rbp-2028h] BYREF
char s[8231]; // [rsp+1h] [rbp-2027h] BYREF

if ( argc != 3 )
{
fwrite("Usage: make_table input.h output.h\n", 1uLL, 0x23uLL, _bss_start);
exit(1);
}
v3 = fopen(argv[1], "r");
if ( !v3 )
{
perror("fopen");
exit(1);
}
v4 = fopen(argv[2], "w");
v5 = v4;
if ( !v4 )
{
perror("fopen");
exit(1);
}
fwrite("/*\n", 1uLL, 3uLL, v4);
fwrite(" * This file is automatically generated; do not edit.\n", 1uLL, 0x36uLL, v5);
fwrite(" */\n\n", 1uLL, 5uLL, v5);
fwrite("#ifdef EFUN_TABLE\n", 1uLL, 0x12uLL, v5);
fwrite("static void (*efun_table[])(int) = {\n", 1uLL, 0x25uLL, v5);
v6 = 0;
v7 = 0x7FFFFFFF;
while ( fgets(&v13, 0x2000, v3) )
{
if ( v13 == 35 && !strcmp(strtok(s, " \t\n"), "define") )
{
v8 = strtok(0LL, " \t\n");
v9 = v8;
if ( v8 )
{
if ( *v8 == 70 && v8[1] == 95 )
{
func7(v8);
fprintf(v5, "\t%s,\n", v9);
v10 = strtok(0LL, " \t\n");
if ( v10 )
{
v11 = atoi(v10);
if ( v7 > v11 )
v7 = v11;
if ( v6 < v11 )
v6 = v11;
}
}
}
}
}
fwrite("};\n", 1uLL, 3uLL, v5);
fwrite("#else /* EFUN_TABLE */\n", 1uLL, 0x17uLL, v5);
fprintf(v5, "#define EFUN_FIRST %4d\n", (unsigned int)v7);
fprintf(v5, "#define EFUN_LAST %4d\n", (unsigned int)v6);
fwrite("#endif /* EFUN_TABLE */\n", 1uLL, 0x18uLL, v5);
fclose(v5);
fclose(v3);
return 0;
}

variable_types:
addr
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rsi
struct _IO_FILE *v4; // rdi
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
char **v8; // rax
char **v9; // rbx
__int64 v10; // rax
__int64 v12; // rdi
__int64 v13; // rax
unsigned int *v14; // rax
unsigned int v15; // ebx
unsigned int *v16; // rax
char **v17; // rbp
__int64 v18; // rax
int v19; // edx
__int64 v20; // [rsp+10h] [rbp-F8h] BYREF
int v21; // [rsp+18h] [rbp-F0h]
jmp_buf env; // [rsp+20h] [rbp-E8h] BYREF
int v23; // [rsp+ECh] [rbp-1Ch]

v23 = 0;
setlinebuf(stdout);
parse_args(argc, (char **)argv);
LOWORD(const0) = 2;
*((_QWORD *)&const0 + 1) = 0LL;
const1 = 2;
*((_QWORD *)&const1 + 1) = 1LL;
constempty = 128;
*((_QWORD *)&constempty + 1) = funcempty;
funcempty[4] = 6;
catch_value = _mm_load_si128((const __m128i *)&const0);
LOBYTE(v23) = -10;
if ( !setlocale(6, "C") )
fprintf(stderr, "Unable to set LC_ALL to: %s.\n", "C");
v3 = "en_US.ISO-8859-1";
v4 = 0LL;
if ( !setlocale(0, "en_US.ISO-8859-1") )
{
v3 = "Unable to set LC_CTYPE to: %s.\n";
v4 = stderr;
fprintf(stderr, "Unable to set LC_CTYPE to: %s.\n", "en_US.ISO-8859-1");
}
set_current_time();
set_profile_timebase(v4, v3);
reserved_area = (__int64)malloc(0x1000000uLL);
init_random();
init_tasks();
query_load_av();
init_num_args();
init_machine();
init_cfuns();
init_hash();
init_signals();
if ( chdir(mudlib_path) == -1 )
{
fprintf(stderr, "Bad mudlib directory: %s\n", "/home/mud/genesis/lib");
exit(1);
}
if ( setjmp(env) )
{
clear_state();
add_message("Anomaly in the fabric of world space.\n");
}
else
{
v20 = 0LL;
v21 = 0;
exception = &v20;
auto_ob = 0LL;
master_ob = 0LL;
v12 = load_object("secure/auto", 1LL, 0LL, 0LL);
auto_ob = v12;
if ( v12 )
{
add_ref(v12, "main");
*(_BYTE *)(*(_QWORD *)(auto_ob + 16LL) + 232LL) |= 8u;
}
get_simul_efun(v12);
v13 = load_object("secure/master", 1LL, 0LL, 0LL);
master_ob = v13;
if ( v13 )
{
add_ref(v13, "main");
*(_BYTE *)(*(_QWORD *)(master_ob + 16LL) + 232LL) |= 8u;
resolve_master_fkntab();
create_object(master_ob);
load_parse_information();
clear_state();
}
}
exception = 0LL;
if ( !auto_ob )
{
fwrite("The file secure/auto must be loadable.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
if ( !master_ob )
{
fwrite("The file secure/master must be loadable.\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
v5 = apply_master_ob(35LL, 0LL);
set_inc_list(v5);
v6 = apply_master_ob(36LL, 0LL);
v7 = v6;
if ( v6 )
{
if ( *(_WORD *)v6 == 8 )
{
v14 = *(unsigned int **)(v6 + 8);
if ( *v14 )
{
v15 = 0;
do
{
v16 = &v14[4 * v15];
if ( *((_WORD *)v16 + 4) == 4 )
add_pre_define(*((_QWORD *)v16 + 2));
++v15;
v14 = *(unsigned int **)(v7 + 8);
}
while ( *v14 > v15 );
}
}
}
if ( flag )
{
printf("Applying driver flag: %s\n", (const char *)flag);
push_string(flag, 0LL);
apply_master_ob(0LL, 1LL);
if ( game_is_being_shut_down )
{
fwrite("Shutdown by master object.\n", 1uLL, 0x1BuLL, stderr);
exit(0);
}
}
v8 = (char **)apply_master_ob(34LL, 0LL);
v9 = v8;
if ( v8 && *(_WORD *)v8 == 4 )
{
v17 = (char **)xalloc(16LL);
if ( !v17 )
{
v10 = fatal("xalloc failed\n");
goto LABEL_37;
}
*v17 = string_copy(v9[1]);
v17[1] = (char *)lpc_predefs;
lpc_predefs = v17;
}
v10 = apply_master_ob(44LL, 0LL);
if ( !v10 || *(_WORD *)v10 != 16 )
{
vbfc_object = 0LL;
goto LABEL_19;
}
LABEL_37:
v18 = *(_QWORD *)(v10 + 8);
vbfc_object = v18;
v19 = *(_DWORD *)(v18 + 12);
if ( v19 )
*(_DWORD *)(v18 + 12) = v19 + 1;
LABEL_19:
if ( game_is_being_shut_down )
exit(1);
init_call_out();
preload_objects((unsigned int)e_flag);
apply_master_ob(3LL, 0LL);
mainloop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rsi
struct _IO_FILE *v4; // rdi
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
char **v8; // rax
char **v9; // rbx
__int64 v10; // rax
__int64 v12; // rdi
__int64 v13; // rax
unsigned int *v14; // rax
unsigned int v15; // ebx
unsigned int *v16; // rax
char **v17; // rbp
__int64 v18; // rax
int v19; // edx
__int64 v20; // [rsp+10h] [rbp-F8h] BYREF
int v21; // [rsp+18h] [rbp-F0h]
jmp_buf env; // [rsp+20h] [rbp-E8h] BYREF
int v23; // [rsp+ECh] [rbp-1Ch]

v23 = 0;
setlinebuf(stdout);
func1(argc, (char **)argv);
LOWORD(const0) = 2;
*((_QWORD *)&const0 + 1) = 0LL;
const1 = 2;
*((_QWORD *)&const1 + 1) = 1LL;
constempty = 128;
*((_QWORD *)&constempty + 1) = funcempty;
funcempty[4] = 6;
catch_value = _mm_load_si128((const __m128i *)&const0);
LOBYTE(v23) = -10;
if ( !setlocale(6, "C") )
fprintf(stderr, "Unable to set LC_ALL to: %s.\n", "C");
v3 = "en_US.ISO-8859-1";
v4 = 0LL;
if ( !setlocale(0, "en_US.ISO-8859-1") )
{
v3 = "Unable to set LC_CTYPE to: %s.\n";
v4 = stderr;
fprintf(stderr, "Unable to set LC_CTYPE to: %s.\n", "en_US.ISO-8859-1");
}
set_current_time();
set_profile_timebase(v4, v3);
reserved_area = (__int64)malloc(0x1000000uLL);
init_random();
init_tasks();
query_load_av();
init_num_args();
init_machine();
init_cfuns();
init_hash();
init_signals();
if ( chdir(mudlib_path) == -1 )
{
fprintf(stderr, "Bad mudlib directory: %s\n", "/home/mud/genesis/lib");
exit(1);
}
if ( setjmp(env) )
{
clear_state();
add_message("Anomaly in the fabric of world space.\n");
}
else
{
v20 = 0LL;
v21 = 0;
exception = &v20;
auto_ob = 0LL;
master_ob = 0LL;
v12 = load_object("secure/auto", 1LL, 0LL, 0LL);
auto_ob = v12;
if ( v12 )
{
add_ref(v12, "main");
*(_BYTE *)(*(_QWORD *)(auto_ob + 16LL) + 232LL) |= 8u;
}
get_simul_efun(v12);
v13 = load_object("secure/master", 1LL, 0LL, 0LL);
master_ob = v13;
if ( v13 )
{
add_ref(v13, "main");
*(_BYTE *)(*(_QWORD *)(master_ob + 16LL) + 232LL) |= 8u;
resolve_master_fkntab();
create_object(master_ob);
load_parse_information();
clear_state();
}
}
exception = 0LL;
if ( !auto_ob )
{
fwrite("The file secure/auto must be loadable.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
if ( !master_ob )
{
fwrite("The file secure/master must be loadable.\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
v5 = apply_master_ob(35LL, 0LL);
set_inc_list(v5);
v6 = apply_master_ob(36LL, 0LL);
v7 = v6;
if ( v6 )
{
if ( *(_WORD *)v6 == 8 )
{
v14 = *(unsigned int **)(v6 + 8);
if ( *v14 )
{
v15 = 0;
do
{
v16 = &v14[4 * v15];
if ( *((_WORD *)v16 + 4) == 4 )
add_pre_define(*((_QWORD *)v16 + 2));
++v15;
v14 = *(unsigned int **)(v7 + 8);
}
while ( *v14 > v15 );
}
}
}
if ( flag )
{
printf("Applying driver flag: %s\n", (const char *)flag);
push_string(flag, 0LL);
apply_master_ob(0LL, 1LL);
if ( game_is_being_shut_down )
{
fwrite("Shutdown by master object.\n", 1uLL, 0x1BuLL, stderr);
exit(0);
}
}
v8 = (char **)apply_master_ob(34LL, 0LL);
v9 = v8;
if ( v8 && *(_WORD *)v8 == 4 )
{
v17 = (char **)xalloc(16LL);
if ( !v17 )
{
v10 = fatal("xalloc failed\n");
goto LABEL_37;
}
*v17 = func2(v9[1]);
v17[1] = (char *)lpc_predefs;
lpc_predefs = v17;
}
v10 = apply_master_ob(44LL, 0LL);
if ( !v10 || *(_WORD *)v10 != 16 )
{
vbfc_object = 0LL;
goto LABEL_19;
}
LABEL_37:
v18 = *(_QWORD *)(v10 + 8);
vbfc_object = v18;
v19 = *(_DWORD *)(v18 + 12);
if ( v19 )
*(_DWORD *)(v18 + 12) = v19 + 1;
LABEL_19:
if ( game_is_being_shut_down )
exit(1);
init_call_out();
preload_objects((unsigned int)e_flag);
apply_master_ob(3LL, 0LL);
mainloop();
return 0;
}


lower

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

result = a1 + 32;
if ( (char)a1 >= 96 )
result = a1;
return result;
}

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

result = a1 + 32;
if ( (char)a1 >= 96 )
result = a1;
return result;
}


LoadTGA

repo: courtc/imager

original_code:
int LoadTGA(void *pRaw, int rawlen, unsigned int *puWidth, unsigned int *puHeight, void **ppData)
{
 TGAHDR_t hdr;
 memcpy(&hdr,pRaw,sizeof(TGAHDR_t));
 if( hdr.colourmaptype != 0 ) {
  return -10;
 }
 if( hdr.imagetype != 2 ) {
  return -11;
 }
 if( hdr.bits != 32 ) {
  return -12;
 }
 *puWidth = hdr.width;
 *puHeight = hdr.height;
 *ppData = malloc(hdr.width*hdr.height*4);
 memcpy(*ppData,(uint8*)pRaw + sizeof(TGAHDR_t) + hdr.identsize,rawlen - (sizeof(TGAHDR_t) + hdr.identsize));
 return 0;
}

canonical_original_code:
int LoadTGA(void *pRaw, int rawlen, unsigned int *puWidth, unsigned int *puHeight, void **ppData)
{
 struct TGAHDR_t hdr;
 memcpy(&hdr,pRaw,sizeof(TGAHDR_t));
 if( hdr.colourmaptype != 0 ) {
  return -10;
 }
 if( hdr.imagetype != 2 ) {
  return -11;
 }
 if( hdr.bits != 32 ) {
  return -12;
 }
 *puWidth = hdr.width;
 *puHeight = hdr.height;
 *ppData = malloc(hdr.width*hdr.height*4);
 memcpy(*ppData,(unsigned char *)pRaw + sizeof(TGAHDR_t) + hdr.identsize,rawlen - (sizeof(TGAHDR_t) + hdr.identsize));
 return 0;
}

variable_types:
pRaw
void *

variable_types: rawlen int

variable_types:
puWidth
unsigned int *

variable_types:
puHeight
unsigned int *

variable_types:
ppData
void **

variable_types: struct TGAHDR_t { unsigned char identsize; unsigned char colourmaptype; unsigned char imagetype; unsigned short colourmapstart; unsigned short colourmaplength; unsigned char colourmapbits; short xstart; short ystart; unsigned short width; unsigned short height; unsigned char bits; unsigned char descriptor; }


decompiled_code:
__int64 __fastcall ringbuffer_create(__int64 a1, unsigned int a2)
{
void *v2; // rax

v2 = malloc(a2);
*(_QWORD *)(a1 + 16) = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
void *v2; // rax

v2 = malloc(a2);
*(_QWORD *)(a1 + 16) = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
return 0LL;
}

original_code:
int ringbuffer_create(ringbuffer_t *buf, unsigned int size)
{
 buf->data = malloc(size);
 if (buf->data == ((void *)0))
  return -1;
 buf->size = size;
 buf->in = 0;
 buf->out = 0;
 return 0;
}

canonical_original_code:
int ringbuffer_create(struct ringbuffer *buf, unsigned int size)
{
 buf->data = malloc(size);
 if (buf->data == ((void *)0))
  return -1;
 buf->size = size;
 buf->in = 0;
 buf->out = 0;
 return 0;
}

variable_types: struct ringbuffer { unsigned int size; unsigned int in; unsigned int out; void *data; } *

variable_types:
size
unsigned int


decompiled_code:
void __fastcall ringbuffer_destroy(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void ringbuffer_destroy(ringbuffer_t *buf)
{
 free(buf->data);
}

canonical_original_code:
void ringbuffer_destroy(struct ringbuffer *buf)
{
 free(buf->data);
}

user_defined_types: struct ringbuffer { unsigned int size; unsigned int in; unsigned int out; void *data; }


decompiled_code:
void __fastcall ringbuffer_flush(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void ringbuffer_flush(ringbuffer_t *buf)
{
 buf->in = 0;
 buf->out = 0;
}

canonical_original_code:
void ringbuffer_flush(struct ringbuffer *buf)
{
 buf->in = 0;
 buf->out = 0;
}


decompiled_code:
__int64 __fastcall ringbuffer_empty(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int v2; // eax

v1 = a1[1];
v2 = a1[2];
if ( v1 >= v2 )
v2 += *a1;
return v2 - v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int v2; // eax

v1 = a1[1];
v2 = a1[2];
if ( v1 >= v2 )
v2 += *a1;
return v2 - v1;
}

original_code:
unsigned int ringbuffer_empty(ringbuffer_t *buf)
{
 if (buf->in < buf->out)
  return buf->out - buf->in;
 else
  return buf->size - (buf->in - buf->out);
}

canonical_original_code:
unsigned int ringbuffer_empty(struct ringbuffer *buf)
{
 if (buf->in < buf->out)
  return buf->out - buf->in;
 else
  return buf->size - (buf->in - buf->out);
}


decompiled_code:
__int64 __fastcall ringbuffer_full(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = a1[1];
v2 = a1[2];
if ( v1 < v2 )
v1 += *a1;
return v1 - v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = a1[1];
v2 = a1[2];
if ( v1 < v2 )
v1 += *a1;
return v1 - v2;
}

original_code:
unsigned int ringbuffer_full(ringbuffer_t *buf)
{
 if (buf->in >= buf->out)
  return buf->in - buf->out;
 else
  return buf->size - (buf->out - buf->in);
}

canonical_original_code:
unsigned int ringbuffer_full(struct ringbuffer *buf)
{
 if (buf->in >= buf->out)
  return buf->in - buf->out;
 else
  return buf->size - (buf->out - buf->in);
}