decompiled_code:
__int64 __fastcall cmd_key(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
char **v4; // rbx
const char *v5; // rcx
const char *v6; // rdx
int v7; // er13
__int64 v9; // rbp
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v7 = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
return (unsigned int)v7;
}
if ( v7 > 0 )
{
v9 = 0LL;
do
{
if ( (unsigned int)zdo_key(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v9), v2) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v9));
++v9;
}
while ( *(_DWORD *)a1 > (int)v9 );
}
}
else
{
if ( v3 != 104 )
{
v7 = -1;
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
return (unsigned int)v7;
}
v4 = off_5D8;
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
zdo_alert(103LL, "\nAvailable keys:\n");
zdo_alert(103LL, "Meaning\t\tkey_name\n");
v5 = "ampersand";
v6 = "&";
while ( 1 )
{
zdo_alert(98LL, "%-15s%-10s\n", v6, v5);
v6 = v4[1];
if ( !v6 )
break;
v5 = *v4;
v4 += 3;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
char **v4; // rbx
const char *v5; // rcx
const char *v6; // rdx
int v7; // er13
__int64 v9; // rbp
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v7 = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
return (unsigned int)v7;
}
if ( v7 > 0 )
{
v9 = 0LL;
do
{
if ( (unsigned int)zdo_key(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v9), v2) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v9));
++v9;
}
while ( *(_DWORD *)a1 > (int)v9 );
}
}
else
{
if ( v3 != 104 )
{
v7 = -1;
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
return (unsigned int)v7;
}
v4 = off_5D8;
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help] <key>\x1B[0m \n"
"\x1B[32mPress a key or a list of key(devided by '+').\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
zdo_alert(103LL, "\nAvailable keys:\n");
zdo_alert(103LL, "Meaning\t\tkey_name\n");
v5 = "ampersand";
v6 = "&";
while ( 1 )
{
zdo_alert(98LL, "%-15s%-10s\n", v6, v5);
v6 = v4[1];
if ( !v6 )
break;
v5 = *v4;
v4 += 3;
}
}
return 0;
}

original_code:
int cmd_key(context_t *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <key>\x1b[0m \n"
    "\x1b[32mPress a key or a list of key(devided by '+').\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
    static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    int i;
    zdo_alert('g', "\nAvailable keys:\n");
    zdo_alert('g', "Meaning\t\tkey_name\n");
    for (i = 0; keysym_charmap[i].meaning != ((void *)0); i++) {
     zdo_alert('b', "%-15s%-10s\n", keysym_charmap[i].meaning,
       keysym_charmap[i].keysym);
    }
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
    if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_key(context->argv[i], cmd);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 0;
}

canonical_original_code:
int cmd_key(struct context *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help] <key>\x1b[0m \n"
    "\x1b[32mPress a key or a list of key(devided by '+').\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
    static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    int i;
    zdo_alert('g', "\nAvailable keys:\n");
    zdo_alert('g', "Meaning\t\tkey_name\n");
    for (i = 0; keysym_charmap[i].meaning != ((void *)0); i++) {
     zdo_alert('b', "%-15s%-10s\n", keysym_charmap[i].meaning,
       keysym_charmap[i].keysym);
    }
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
    if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_key(context->argv[i], cmd);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 0;
}

variable_types: struct context { int argc; char **argv; } *

variable_types: ret int

variable_types:
cmd
char *


repo: zxhhs/Button-Wizard

decompiled_code:
__int64 cmd_version()
{
zdo_alert(103LL, "About Us :\n");
zdo_alert(98LL, "Program Name : ZMagic\n");
zdo_alert(98LL, "Version : 1.0.0\n");
zdo_alert(114LL, "Created By : Zhang Xiang & Zhong Guang Pei\n");
zdo_alert(98LL, "Copyright : 2012-2020\n");
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
zdo_alert(103LL, "About Us :\n");
zdo_alert(98LL, "Program Name : ZMagic\n");
zdo_alert(98LL, "Version : 1.0.0\n");
zdo_alert(114LL, "Created By : Zhang Xiang & Zhong Guang Pei\n");
zdo_alert(98LL, "Copyright : 2012-2020\n");
return 1LL;
}

original_code:
int cmd_version(context_t *context) {
 zdo_alert('g', "About Us     :\n");
 zdo_alert('b', "Program Name : ZMagic\n");
 zdo_alert('b', "Version      : 1.0.0\n");
 zdo_alert('r', "Created By   : Zhang Xiang & Zhong Guang Pei\n");
 zdo_alert('b', "Copyright    : 2012-2020\n");
 return 1;
}

canonical_original_code:
int cmd_version(struct context *context) {
 zdo_alert('g', "About Us     :\n");
 zdo_alert('b', "Program Name : ZMagic\n");
 zdo_alert('b', "Version      : 1.0.0\n");
 zdo_alert('r', "Created By   : Zhang Xiang & Zhong Guang Pei\n");
 zdo_alert('b', "Copyright    : 2012-2020\n");
 return 1;
}

return_type: int

user_defined_types: struct context { int argc; char **argv; }


decompiled_code:
__int64 __fastcall cmd_click(__int64 a1)
{
unsigned __int64 v1; // r12
int v2; // ebp
char *const *v3; // rsi
const char *v4; // r13
char v5; // al
unsigned int v6; // er12
char *v8; // r14
__int64 v9; // r12
int v10; // eax
unsigned int v11; // eax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = 100LL;
v2 = 1;
v3 = *(char *const **)(a1 + 8);
v4 = *v3;
while ( 1 )
{
v5 = getopt_long_only(*(_DWORD *)a1, v3, "r:d:h", &longopts_0, longind);
if ( v5 == -1 )
{
v9 = 1000 * v1;
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v11 = atoi(**(const char ***)(a1 + 8));
v10 = zdo_click(v11, (unsigned int)v2, v9);
}
else
{
v10 = zdo_click(1LL, (unsigned int)v2, v9);
}
v6 = 1;
if ( v10 == -1 )
zdo_alert(114LL, "zdo_click reported an error.\n");
return v6;
}
if ( v5 == 104 )
break;
if ( v5 == 114 )
{
v8 = optarg;
v2 = atoi(optarg);
if ( v2 <= 0 )
{
zdo_alert(114LL, "Invalid repeat value '%s' (must be >= 1).\n", v8);
LABEL_7:
v6 = -1;
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v4);
return v6;
}
}
else
{
if ( v5 != 100 )
{
zdo_alert(114LL, "unknown option.\n");
goto LABEL_7;
}
v1 = strtoul(optarg, 0LL, 10);
}
v3 = *(char *const **)(a1 + 8);
}
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v1; // r12
int v2; // ebp
char *const *v3; // rsi
const char *v4; // r13
char v5; // al
unsigned int v6; // er12
char *v8; // r14
__int64 v9; // r12
int v10; // eax
unsigned int v11; // eax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = 100LL;
v2 = 1;
v3 = *(char *const **)(a1 + 8);
v4 = *v3;
while ( 1 )
{
v5 = getopt_long_only(*(_DWORD *)a1, v3, "r:d:h", &longopts_0, longind);
if ( v5 == -1 )
{
v9 = 1000 * v1;
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
v11 = atoi(**(const char ***)(a1 + 8));
v10 = zdo_click(v11, (unsigned int)v2, v9);
}
else
{
v10 = zdo_click(1LL, (unsigned int)v2, v9);
}
v6 = 1;
if ( v10 == -1 )
zdo_alert(114LL, "zdo_click reported an error.\n");
return v6;
}
if ( v5 == 104 )
break;
if ( v5 == 114 )
{
v8 = optarg;
v2 = atoi(optarg);
if ( v2 <= 0 )
{
zdo_alert(114LL, "Invalid repeat value '%s' (must be >= 1).\n", v8);
LABEL_7:
v6 = -1;
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v4);
return v6;
}
}
else
{
if ( v5 != 100 )
{
zdo_alert(114LL, "unknown option.\n");
goto LABEL_7;
}
v1 = strtoul(optarg, 0LL, 10);
}
v3 = *(char *const **)(a1 + 8);
}
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N] [--delay MS] [--help] <button>\x1B[0m \n"
"\x1B[32mClick a mouse button.\x1B[0m\n"
"\x1B[32m1 for left(default).\x1B[0m\n"
"\x1B[32m2 for middle.\x1B[0m\n"
"\x1B[32m3 for right.\x1B[0m\n"
"\x1B[32m4 for wheel up.\x1B[0m\n"
"\x1B[32m5 for wheel down.\x1B[0m\n"
"\x1B[1;34m--repeat -r N\x1B[0m \x1B[32m- repeat N times to click. Default is 1.\x1B[0m\n"
"\x1B[1;34m--delay -d MS\x1B[0m \x1B[32m- delay in MS between clicks. Default is 100ms.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v4);
return 0LL;
}

original_code:
int cmd_click(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int repeat = 1;
 unsigned long delay = 100;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N] [--delay MS] [--help] <button>\x1b[0m \n"
    "\x1b[32mClick a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--repeat   -r N\x1b[0m         \x1b[32m- repeat N times to click. Default is 1.\x1b[0m\n"
    "\x1b[1;34m--delay    -d MS\x1b[0m        \x1b[32m- delay in MS between clicks. Default is 100ms.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "repeat", 1, ((void *)0), 'r'},
  { "delay", 1, ((void *)0), 'd' },
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "r:d:h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'r':
    repeat = atoi(optarg);
    if (repeat <= 0) {
     zdo_alert('r', "Invalid repeat value '%s' (must be >= 1).\n", optarg);
     fprintf(stderr, usage, cmd);
     return -1;
    }
    break;
      case 'd':
    delay = strtoul(optarg, ((void *)0), 10);
    break;
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_click(atoi(context->argv[0]), repeat, delay * 1000);
 else
  ret = zdo_click(1, repeat, delay * 1000);
 if (ret == -1) {
  zdo_alert('r', "zdo_click reported an error.\n");
 }
 return 1;
}

canonical_original_code:
int cmd_click(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int repeat = 1;
 unsigned long delay = 100;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N] [--delay MS] [--help] <button>\x1b[0m \n"
    "\x1b[32mClick a mouse button.\x1b[0m\n"
    "\x1b[32m1     for     left(default).\x1b[0m\n"
    "\x1b[32m2     for     middle.\x1b[0m\n"
    "\x1b[32m3     for     right.\x1b[0m\n"
    "\x1b[32m4     for     wheel up.\x1b[0m\n"
    "\x1b[32m5     for     wheel down.\x1b[0m\n"
    "\x1b[1;34m--repeat   -r N\x1b[0m         \x1b[32m- repeat N times to click. Default is 1.\x1b[0m\n"
    "\x1b[1;34m--delay    -d MS\x1b[0m        \x1b[32m- delay in MS between clicks. Default is 100ms.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "repeat", 1, ((void *)0), 'r'},
  { "delay", 1, ((void *)0), 'd' },
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "r:d:h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'r':
    repeat = atoi(optarg);
    if (repeat <= 0) {
     zdo_alert('r', "Invalid repeat value '%s' (must be >= 1).\n", optarg);
     fprintf(stderr, usage, cmd);
     return -1;
    }
    break;
      case 'd':
    delay = strtoul(optarg, ((void *)0), 10);
    break;
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0)
  ret = zdo_click(atoi(context->argv[0]), repeat, delay * 1000);
 else
  ret = zdo_click(1, repeat, delay * 1000);
 if (ret == -1) {
  zdo_alert('r', "zdo_click reported an error.\n");
 }
 return 1;
}

variable_types: c char

variable_types: repeat int

variable_types:
delay
unsigned long

variable_types:
usage
char *

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


decompiled_code:
__int64 __fastcall cmd_type(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
__int64 result; // rax
__int64 i; // rbp
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
for ( i = 0LL; *(_DWORD *)a1 > (int)i; ++i )
{
if ( (unsigned int)zdo_type(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * i)) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * i));
}
}
else
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
}
result = 1LL;
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
const char *v2; // r12
char v3; // al
__int64 result; // rax
__int64 i; // rbp
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
if ( *(_DWORD *)a1 )
{
for ( i = 0LL; *(_DWORD *)a1 > (int)i; ++i )
{
if ( (unsigned int)zdo_type(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * i)) == -1 )
zdo_alert(
114LL,
"zdo_key reported an error for string '%s'.\n",
*(const char **)(*(_QWORD *)(a1 + 8) + 8 * i));
}
}
else
{
zdo_alert(114LL, "No keys.\n");
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
}
result = 1LL;
}
else if ( v3 == 104 )
{
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0LL;
}
else
{
zdo_alert(114LL, "unknown option.\n");
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--repeat N][--help] <button>\x1B[0m \n"
"\x1B[32mSend keystrokes.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_type(context_t *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N][--help] <button>\x1b[0m \n"
    "\x1b[32mSend keystrokes.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_type(context->argv[i]);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 1;
}

canonical_original_code:
int cmd_type(struct context *context) {
 int i;
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--repeat N][--help] <button>\x1b[0m \n"
    "\x1b[32mSend keystrokes.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m           \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
     case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 if (context->argc != 0) {
  for (i=0; i<context->argc; i++) {
   ret = zdo_type(context->argv[i]);
   if (ret == -1) {
    zdo_alert('r', "zdo_key reported an error for string '%s'.\n",
     context->argv[i]);
   }
  }
 }
 else {
  zdo_alert('r', "No keys.\n");
  printf(usage, cmd);
 }
 return 1;
}

variable_types: i int

user_defined_types: struct option { char *name; int has_arg; int *flag; int val; }


decompiled_code:
__int64 __fastcall cmd_getmouselocation(__int64 a1)
{
char *const *v1; // rsi
char *v2; // r12
char v3; // al
const char *v4; // rsi
unsigned int v5; // er12
const char *v7; // rdx
int longind; // [rsp+4h] [rbp-24h] BYREF
unsigned int v9; // [rsp+8h] [rbp-20h] BYREF
unsigned int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, &longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v5 = zdo_getmouselocation(&v9, v10);
if ( v5 )
{
zdo_alert(114LL, "X=%d\n", v9);
zdo_alert(114LL, "Y=%d\n", v10[0]);
}
}
else if ( v3 == 104 )
{
v4 = v2;
v5 = 0;
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v4);
}
else
{
zdo_alert(114LL, "unknown option.\n");
v7 = v2;
v5 = -1;
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v7);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *const *v1; // rsi
char *v2; // r12
char v3; // al
const char *v4; // rsi
unsigned int v5; // er12
const char *v7; // rdx
int longind; // [rsp+4h] [rbp-24h] BYREF
unsigned int v9; // [rsp+8h] [rbp-20h] BYREF
unsigned int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(char *const **)(a1 + 8);
v2 = *v1;
v3 = getopt_long_only(*(_DWORD *)a1, v1, "h", &longopts_1, &longind);
if ( v3 == -1 )
{
consume_args(a1, (unsigned int)optind);
v5 = zdo_getmouselocation(&v9, v10);
if ( v5 )
{
zdo_alert(114LL, "X=%d\n", v9);
zdo_alert(114LL, "Y=%d\n", v10[0]);
}
}
else if ( v3 == 104 )
{
v4 = v2;
v5 = 0;
printf(
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v4);
}
else
{
zdo_alert(114LL, "unknown option.\n");
v7 = v2;
v5 = -1;
fprintf(
stderr,
"\x1B[1;32mUsage:\x1B[0m \x1B[31m%s\x1B[0m \x1B[1;34m[--help]\x1B[0m \n"
"\x1B[32mGet locations of the mouse.\x1B[0m\n"
"\x1B[1;34m--help -h\x1B[0m \x1B[32m- get help\x1B[0m\n",
v7);
}
return v5;
}

original_code:
int cmd_getmouselocation(context_t *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int x, y;
 static const char *usage =
 "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help]\x1b[0m \n"
    "\x1b[32mGet locations of the mouse.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 ret = zdo_getmouselocation(&x, &y);
 if (ret) {
  zdo_alert('r', "X=%d\n", x);
  zdo_alert('r', "Y=%d\n", y);
 }
 return ret;
}

canonical_original_code:
int cmd_getmouselocation(struct context *context) {
 int ret;
 int option_index;
 char *cmd = *context->argv;
 char c;
 int x; int y;
 static char *usage = "\x1b[1;32mUsage:\x1b[0m \x1b[31m%s\x1b[0m \x1b[1;34m[--help]\x1b[0m \n"
    "\x1b[32mGet locations of the mouse.\x1b[0m\n"
    "\x1b[1;34m--help     -h\x1b[0m        \x1b[32m- get help\x1b[0m\n";
 static struct option longopts[] = {
  { "help", 0, ((void *)0), 'h'},
  { 0, 0, 0, 0 },
 };
 while ((c = getopt_long_only(context->argc, context->argv, "h",
                               longopts, &option_index)) != -1) {
  switch (c) {
   case 'h':
    printf(usage, cmd);
    return 0;
    break;
     default:
    zdo_alert('r', "unknown option.\n");
    fprintf(stderr, usage, cmd);
    return -1;
  }
 }
 consume_args(context, optind);
 ret = zdo_getmouselocation(&x, &y);
 if (ret) {
  zdo_alert('r', "X=%d\n", x);
  zdo_alert('r', "Y=%d\n", y);
 }
 return ret;
}

variable_types: x int

variable_types: y int


getifaddr

repo: zyclonite/dlnaproxy

decompiled_code:
__int64 __fastcall getifaddr(char *src, char *s, socklen_t len)
{
int v4; // eax
int v5; // ebp
int v6; // ebx
int v7; // eax
int v8; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int v18; // [rsp+Ch] [rbp-5Ch] BYREF
char dest[20]; // [rsp+10h] [rbp-58h] BYREF
unsigned int cp[17]; // [rsp+24h] [rbp-44h] BYREF

v18 = 40;
v4 = socket(2, 2, 0);
if ( v4 < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_err(2LL, 0LL, "getifaddr.c", 64LL, "socket(PF_INET, SOCK_DGRAM): %s\n", v15);
return 0xFFFFFFFFLL;
}
v5 = v4;
strncpy(dest, src, 0x10uLL);
if ( ioctl(v5, 0x8915uLL, dest, &v18) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
log_err(2LL, 0LL, "getifaddr.c", 70LL, "ioctl(s, SIOCGIFADDR, ...): %s\n", v13);
LABEL_12:
close(v5);
return 0xFFFFFFFFLL;
}
if ( !inet_ntop(2, cp, s, len) )
{
v16 = _errno_location();
v17 = strerror(*v16);
log_err(2LL, 0LL, "getifaddr.c", 77LL, "inet_ntop(): %s\n", v17);
goto LABEL_12;
}
v6 = ioctl(v5, 0x891BuLL, dest, &v18);
if ( v6 )
{
v10 = _errno_location();
v11 = strerror(*v10);
log_err(2LL, 0LL, "getifaddr.c", 98LL, "ioctl(s, SIOCGIFNETMASK, ...): %s\n", v11);
}
else
{
v7 = _bswap_32(cp[0]);
while ( !_bittest(&v7, v6) )
{
if ( ++v6 == 32 )
goto LABEL_9;
}
v8 = strlen(s);
snprintf(&s[v8], (int)(len - v8), "/%u", (unsigned int)(32 - v6));
}
LABEL_9:
close(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *s, socklen_t len)
{
int v4; // eax
int v5; // ebp
int v6; // ebx
int v7; // eax
int v8; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int v18; // [rsp+Ch] [rbp-5Ch] BYREF
char dest[20]; // [rsp+10h] [rbp-58h] BYREF
unsigned int cp[17]; // [rsp+24h] [rbp-44h] BYREF

v18 = 40;
v4 = socket(2, 2, 0);
if ( v4 < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_err(2LL, 0LL, "getifaddr.c", 64LL, "socket(PF_INET, SOCK_DGRAM): %s\n", v15);
return 0xFFFFFFFFLL;
}
v5 = v4;
strncpy(dest, src, 0x10uLL);
if ( ioctl(v5, 0x8915uLL, dest, &v18) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
log_err(2LL, 0LL, "getifaddr.c", 70LL, "ioctl(s, SIOCGIFADDR, ...): %s\n", v13);
LABEL_12:
close(v5);
return 0xFFFFFFFFLL;
}
if ( !inet_ntop(2, cp, s, len) )
{
v16 = _errno_location();
v17 = strerror(*v16);
log_err(2LL, 0LL, "getifaddr.c", 77LL, "inet_ntop(): %s\n", v17);
goto LABEL_12;
}
v6 = ioctl(v5, 0x891BuLL, dest, &v18);
if ( v6 )
{
v10 = _errno_location();
v11 = strerror(*v10);
log_err(2LL, 0LL, "getifaddr.c", 98LL, "ioctl(s, SIOCGIFNETMASK, ...): %s\n", v11);
}
else
{
v7 = func0(cp[0]);
while ( !_bittest(&v7, v6) )
{
if ( ++v6 == 32 )
goto LABEL_9;
}
v8 = strlen(s);
snprintf(&s[v8], (int)(len - v8), "/%u", (unsigned int)(32 - v6));
}
LABEL_9:
close(v5);
return 0LL;
}

original_code:
int
getifaddr(const char * ifname, char * buf, int len)
{
 int s;
 struct ifreq ifr;
 int ifrlen;
 struct sockaddr_in * addr;
 uint32_t mask;
 int i;
 ifrlen = sizeof(ifr);
 s = socket(2, SOCK_DGRAM, 0);
 if(s < 0)
 {
  { log_err(2, L_GENERAL, "getifaddr.c", 64, "socket(PF_INET, SOCK_DGRAM): %s\n", strerror((*__errno_location ()))); };
  return -1;
 }
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, 16);
 if(ioctl(s, 0x8915, &ifr, &ifrlen) < 0)
 {
  { log_err(2, L_GENERAL, "getifaddr.c", 70, "ioctl(s, SIOCGIFADDR, ...): %s\n", strerror((*__errno_location ()))); };
  close(s);
  return -1;
 }
 addr = (struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr;
 if(!inet_ntop(2, &addr->sin_addr, buf, len))
 {
  { log_err(2, L_GENERAL, "getifaddr.c", 77, "inet_ntop(): %s\n", strerror((*__errno_location ()))); };
  close(s);
  return -1;
 }
 if(ioctl(s, 0x891b, &ifr, &ifrlen) == 0)
 {
  addr = (struct sockaddr_in *)&ifr.ifr_ifru.ifru_netmask;
  mask = ntohl(addr->sin_addr.s_addr);
  for (i = 0; i < 32; i++)
  {
   if ((mask >> i) & 1)
    break;
  }
  mask = 32 - i;
  if (mask)
  {
   i = strlen(buf);
   snprintf(buf+i, len-i, "/%u", mask);
  }
 }
 else
  { log_err(2, L_GENERAL, "getifaddr.c", 98, "ioctl(s, SIOCGIFNETMASK, ...): %s\n", strerror((*__errno_location ()))); };
 close(s);
 return 0;
}

canonical_original_code:
int getifaddr(char *ifname, char *buf, int len)
{
 int s;
 struct ifreq ifr;
 int ifrlen;
 struct sockaddr_in *addr;
 unsigned int mask;
 int i;
 ifrlen = sizeof(ifr);
 s = socket(2, SOCK_DGRAM, 0);
 if(s < 0)
 {
  { log_err(2, L_GENERAL, "getifaddr.c", 64, "socket(PF_INET, SOCK_DGRAM): %s\n", strerror((*__errno_location ()))); };
  return -1;
 }
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, 16);
 if(ioctl(s, 0x8915, &ifr, &ifrlen) < 0)
 {
  { log_err(2, L_GENERAL, "getifaddr.c", 70, "ioctl(s, SIOCGIFADDR, ...): %s\n", strerror((*__errno_location ()))); };
  close(s);
  return -1;
 }
 addr = (struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr;
 if(!inet_ntop(2, &addr->sin_addr, buf, len))
 {
  { log_err(2, L_GENERAL, "getifaddr.c", 77, "inet_ntop(): %s\n", strerror((*__errno_location ()))); };
  close(s);
  return -1;
 }
 if(ioctl(s, 0x891b, &ifr, &ifrlen) == 0)
 {
  addr = (struct sockaddr_in *)&ifr.ifr_ifru.ifru_netmask;
  mask = ntohl(addr->sin_addr.s_addr);
  for (i = 0; i < 32; i++)
  {
   if ((mask >> i) & 1)
    break;
  }
  mask = 32 - i;
  if (mask)
  {
   i = strlen(buf);
   snprintf(buf+i, len-i, "/%u", mask);
  }
 }
 else
  { log_err(2, L_GENERAL, "getifaddr.c", 98, "ioctl(s, SIOCGIFNETMASK, ...): %s\n", strerror((*__errno_location ()))); };
 close(s);
 return 0;
}

variable_types:
ifname
char *

variable_types:
buf
char *

variable_types: len int

variable_types: s int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: ifrlen int

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

variable_types:
mask
unsigned int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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


getsysaddr

decompiled_code:
__int64 __fastcall getsysaddr(char *s, socklen_t len)
{
__int32 v4; // ebx
int v5; // ebp
unsigned int v6; // ebx
int v7; // eax
int v8; // eax
unsigned int v9; // er12
int *v11; // rax
char *v12; // rax
struct in_addr in[4]; // [rsp+0h] [rbp-68h] BYREF
char v14[16]; // [rsp+10h] [rbp-58h] BYREF
__m128i v15; // [rsp+20h] [rbp-48h] BYREF

v4 = 1;
v5 = socket(2, 1, 0);
while ( 1 )
{
v15.m128i_i32[0] = v4;
if ( ioctl(v5, 0x8910uLL, v14) < 0 )
{
v9 = -1;
goto LABEL_12;
}
if ( ioctl(v5, 0x8915uLL, v14, 40LL) >= 0 )
{
*(__m128i *)&in[0].s_addr = _mm_loadu_si128(&v15);
if ( memcmp(inet_ntoa(in[1]), "127.", 4uLL) )
{
if ( ioctl(v5, 0x891BuLL, v14, 40LL) >= 0 )
break;
}
}
++v4;
}
if ( inet_ntop(2, &in[1], s, len) )
{
v6 = 0;
*(__m128i *)&in[0].s_addr = v15;
v7 = _bswap_32(v15.m128i_u32[1]);
while ( !_bittest(&v7, v6) )
{
if ( ++v6 == 32 )
goto LABEL_11;
}
v8 = strlen(s);
snprintf(&s[v8], (int)(len - v8), "/%u", 32 - v6);
LABEL_11:
v9 = 0;
}
else
{
v11 = _errno_location();
v9 = -1;
v12 = strerror(*v11);
log_err(2LL, 0LL, "getifaddr.c", 127LL, "inet_ntop(): %s\n", v12);
close(v5);
}
LABEL_12:
close(v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s, socklen_t len)
{
__int32 v4; // ebx
int v5; // ebp
unsigned int v6; // ebx
int v7; // eax
int v8; // eax
unsigned int v9; // er12
int *v11; // rax
char *v12; // rax
struct in_addr in[4]; // [rsp+0h] [rbp-68h] BYREF
char v14[16]; // [rsp+10h] [rbp-58h] BYREF
__m128i v15; // [rsp+20h] [rbp-48h] BYREF

v4 = 1;
v5 = socket(2, 1, 0);
while ( 1 )
{
v15.m128i_i32[0] = v4;
if ( ioctl(v5, 0x8910uLL, v14) < 0 )
{
v9 = -1;
goto LABEL_12;
}
if ( ioctl(v5, 0x8915uLL, v14, 40LL) >= 0 )
{
*(__m128i *)&in[0].s_addr = _mm_loadu_si128(&v15);
if ( memcmp(inet_ntoa(in[1]), "127.", 4uLL) )
{
if ( ioctl(v5, 0x891BuLL, v14, 40LL) >= 0 )
break;
}
}
++v4;
}
if ( inet_ntop(2, &in[1], s, len) )
{
v6 = 0;
*(__m128i *)&in[0].s_addr = v15;
v7 = func0(v15.m128i_u32[1]);
while ( !_bittest(&v7, v6) )
{
if ( ++v6 == 32 )
goto LABEL_11;
}
v8 = strlen(s);
snprintf(&s[v8], (int)(len - v8), "/%u", 32 - v6);
LABEL_11:
v9 = 0;
}
else
{
v11 = _errno_location();
v9 = -1;
v12 = strerror(*v11);
log_err(2LL, 0LL, "getifaddr.c", 127LL, "inet_ntop(): %s\n", v12);
close(v5);
}
LABEL_12:
close(v5);
return v9;
}

original_code:
int
getsysaddr(char * buf, int len)
{
 int i;
 int s = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in addr;
 struct ifreq ifr;
 uint32_t mask;
 int ret = -1;
 for (i=1; i > 0; i++)
 {
  ifr.ifr_ifru.ifru_ivalue = i;
  if( ioctl(s, 0x8910, &ifr) < 0 )
   break;
  if(ioctl(s, 0x8915, &ifr, sizeof(struct ifreq)) < 0)
   continue;
  memcpy(&addr, &ifr.ifr_ifru.ifru_addr, sizeof(addr));
  if(strncmp(inet_ntoa(addr.sin_addr), "127.", 4) == 0)
   continue;
  if(ioctl(s, 0x891b, &ifr, sizeof(struct ifreq)) < 0)
   continue;
  if(!inet_ntop(2, &addr.sin_addr, buf, len))
  {
   { log_err(2, L_GENERAL, "getifaddr.c", 127, "inet_ntop(): %s\n", strerror((*__errno_location ()))); };
   close(s);
   break;
  }
  ret = 0;
  memcpy(&addr, &ifr.ifr_ifru.ifru_netmask, sizeof(addr));
  mask = ntohl(addr.sin_addr.s_addr);
  for (i = 0; i < 32; i++)
  {
   if ((mask >> i) & 1)
    break;
  }
  mask = 32 - i;
  if (mask)
  {
   i = strlen(buf);
   snprintf(buf+i, len-i, "/%u", mask);
  }
  break;
 }
 close(s);
 return(ret);
}

canonical_original_code:
int getsysaddr(char *buf, int len)
{
 int i;
 int s = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in addr;
 struct ifreq ifr;
 unsigned int mask;
 int ret = -1;
 for (i=1; i > 0; i++)
 {
  ifr.ifr_ifru.ifru_ivalue = i;
  if( ioctl(s, 0x8910, &ifr) < 0 )
   break;
  if(ioctl(s, 0x8915, &ifr, sizeof(struct ifreq)) < 0)
   continue;
  memcpy(&addr, &ifr.ifr_ifru.ifru_addr, sizeof(addr));
  if(strncmp(inet_ntoa(addr.sin_addr), "127.", 4) == 0)
   continue;
  if(ioctl(s, 0x891b, &ifr, sizeof(struct ifreq)) < 0)
   continue;
  if(!inet_ntop(2, &addr.sin_addr, buf, len))
  {
   { log_err(2, L_GENERAL, "getifaddr.c", 127, "inet_ntop(): %s\n", strerror((*__errno_location ()))); };
   close(s);
   break;
  }
  ret = 0;
  memcpy(&addr, &ifr.ifr_ifru.ifru_netmask, sizeof(addr));
  mask = ntohl(addr.sin_addr.s_addr);
  for (i = 0; i < 32; i++)
  {
   if ((mask >> i) & 1)
    break;
  }
  mask = 32 - i;
  if (mask)
  {
   i = strlen(buf);
   snprintf(buf+i, len-i, "/%u", mask);
  }
  break;
 }
 close(s);
 return(ret);
}

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

variable_types: ret int

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


getsyshwaddr

decompiled_code:
__int64 __fastcall getsyshwaddr(char *s, int a2)
{
int v2; // eax
int v3; // ebp
struct if_nameindex *v4; // rax
struct if_nameindex *v5; // r12
struct if_nameindex *v6; // rbx
__int64 result; // rax
unsigned int v8; // ecx
char dest[16]; // [rsp+10h] [rbp-58h] BYREF
__int64 v10; // [rsp+20h] [rbp-48h]

v2 = socket(2, 2, 0);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = if_nameindex();
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
if ( !v4->if_index )
{
LABEL_14:
if_freenameindex(v5);
close(v3);
return 0xFFFFFFFFLL;
}
v6 = v4;
while ( 1 )
{
strncpy(dest, v6->if_name, 0x10uLL);
if ( ioctl(v3, 0x8913uLL, dest) >= 0
&& (v10 & 8) == 0
&& ioctl(v3, 0x8927uLL, dest) >= 0
&& (v10 & 0xFFFFFFFFFFFF0000LL) != 0 )
{
break;
}
v8 = v6[1].if_index;
++v6;
if ( !v8 )
goto LABEL_14;
}
if_freenameindex(v5);
close(v3);
if ( a2 > 12 )
{
sprintf(
s,
"%02x%02x%02x%02x%02x%02x",
BYTE2(v10),
BYTE3(v10),
BYTE4(v10),
HIBYTE(*(_DWORD *)((char *)&v10 + 2)),
BYTE6(v10),
HIBYTE(v10));
result = 0LL;
}
else
{
result = 0LL;
if ( a2 == 6 )
{
*(_DWORD *)s = *(_DWORD *)((char *)&v10 + 2);
*((_WORD *)s + 2) = HIWORD(v10);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, int a2)
{
int v2; // eax
int v3; // ebp
struct if_nameindex *v4; // rax
struct if_nameindex *v5; // r12
struct if_nameindex *v6; // rbx
__int64 result; // rax
unsigned int v8; // ecx
char dest[16]; // [rsp+10h] [rbp-58h] BYREF
__int64 v10; // [rsp+20h] [rbp-48h]

v2 = socket(2, 2, 0);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = if_nameindex();
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
if ( !v4->if_index )
{
LABEL_14:
if_freenameindex(v5);
close(v3);
return 0xFFFFFFFFLL;
}
v6 = v4;
while ( 1 )
{
strncpy(dest, v6->if_name, 0x10uLL);
if ( ioctl(v3, 0x8913uLL, dest) >= 0
&& (v10 & 8) == 0
&& ioctl(v3, 0x8927uLL, dest) >= 0
&& (v10 & 0xFFFFFFFFFFFF0000LL) != 0 )
{
break;
}
v8 = v6[1].if_index;
++v6;
if ( !v8 )
goto LABEL_14;
}
if_freenameindex(v5);
close(v3);
if ( a2 > 12 )
{
sprintf(
s,
"%02x%02x%02x%02x%02x%02x",
BYTE2(v10),
BYTE3(v10),
BYTE4(v10),
HIBYTE(*(_DWORD *)((char *)&v10 + 2)),
BYTE6(v10),
HIBYTE(v10));
result = 0LL;
}
else
{
result = 0LL;
if ( a2 == 6 )
{
*(_DWORD *)s = *(_DWORD *)((char *)&v10 + 2);
*((_WORD *)s + 2) = HIWORD(v10);
}
}
return result;
}

original_code:
int
getsyshwaddr(char * buf, int len)
{
 struct if_nameindex *ifaces, *if_idx;
 unsigned char mac[6];
 struct ifreq ifr;
 int fd;
 int ret = -1;
 memset(&mac, '\0', sizeof(mac));
 fd = socket(2, SOCK_DGRAM, 0);
 if( fd < 0 )
  return(ret);
 ifaces = if_nameindex();
 if(!ifaces)
  return(ret);
 for(if_idx = ifaces; if_idx->if_index; if_idx++)
 {
  strncpy(ifr.ifr_ifrn.ifrn_name, if_idx->if_name, 16);
  if(ioctl(fd, 0x8913, &ifr) < 0)
   continue;
  if(ifr.ifr_ifru.ifru_flags & IFF_LOOPBACK)
   continue;
  if( ioctl(fd, 0x8927, &ifr) < 0 )
   continue;
  if( ((ifr.ifr_ifru.ifru_hwaddr.sa_data[0] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[1] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[2] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[3] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[4] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[5] == 0x00)) )
   continue;
  ret = 0;
  break;
 }
 if_freenameindex(ifaces);
 close(fd);
 if(ret == 0)
 {
  if(len > 12)
  {
   memmove(mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
   sprintf(buf, "%02x%02x%02x%02x%02x%02x",
           mac[0]&0xFF, mac[1]&0xFF, mac[2]&0xFF,
           mac[3]&0xFF, mac[4]&0xFF, mac[5]&0xFF);
  }
  else if(len == 6)
  {
   memmove(buf, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
  }
 }
 return ret;
}

canonical_original_code:
int getsyshwaddr(char *buf, int len)
{
 struct if_nameindex *ifaces; struct if_nameindex *if_idx;
 unsigned char mac[6];
 struct ifreq ifr;
 int fd;
 int ret = -1;
 memset(&mac, '\0', sizeof(mac));
 fd = socket(2, SOCK_DGRAM, 0);
 if( fd < 0 )
  return(ret);
 ifaces = if_nameindex();
 if(!ifaces)
  return(ret);
 for(if_idx = ifaces; if_idx->if_index; if_idx++)
 {
  strncpy(ifr.ifr_ifrn.ifrn_name, if_idx->if_name, 16);
  if(ioctl(fd, 0x8913, &ifr) < 0)
   continue;
  if(ifr.ifr_ifru.ifru_flags & IFF_LOOPBACK)
   continue;
  if( ioctl(fd, 0x8927, &ifr) < 0 )
   continue;
  if( ((ifr.ifr_ifru.ifru_hwaddr.sa_data[0] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[1] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[2] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[3] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[4] == 0x00) && (ifr.ifr_ifru.ifru_hwaddr.sa_data[5] == 0x00)) )
   continue;
  ret = 0;
  break;
 }
 if_freenameindex(ifaces);
 close(fd);
 if(ret == 0)
 {
  if(len > 12)
  {
   memmove(mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
   sprintf(buf, "%02x%02x%02x%02x%02x%02x",
           mac[0]&0xFF, mac[1]&0xFF, mac[2]&0xFF,
           mac[3]&0xFF, mac[4]&0xFF, mac[5]&0xFF);
  }
  else if(len == 6)
  {
   memmove(buf, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
  }
 }
 return ret;
}

variable_types: struct if_nameindex { unsigned int if_index; char *if_name; } *

variable_types:
mac
unsigned char [6]

variable_types: fd int


original_code:
static char *
strcat_str(char * str, int * len, int * tmplen, const char * s2)
{
 char *p;
 int s2len;
 s2len = (int)strlen(s2);
 if(*tmplen <= (*len + s2len))
 {
  if(s2len < 256)
   *tmplen += 256;
  else
   *tmplen += s2len + 1;
  p = realloc(str, *tmplen);
  if (!p)
  {
   if(s2len < 256)
    *tmplen -= 256;
   else
    *tmplen -= s2len + 1;
   return str;
  }
  else
   str = p;
 }
 memcpy(str + *len, s2, s2len + 1);
 *len += s2len;
 return str;
}

canonical_original_code:
static char *strcat_str(char *str, int *len, int *tmplen, char *s2)
{
 char *p;
 int s2len;
 s2len = (int)strlen(s2);
 if(*tmplen <= (*len + s2len))
 {
  if(s2len < 256)
   *tmplen += 256;
  else
   *tmplen += s2len + 1;
  p = realloc(str, *tmplen);
  if (!p)
  {
   if(s2len < 256)
    *tmplen -= 256;
   else
    *tmplen -= s2len + 1;
   return str;
  }
  else
   str = p;
 }
 memcpy(str + *len, s2, s2len + 1);
 *len += s2len;
 return str;
}

variable_types:
str
char *

variable_types:
len
int *

variable_types:
tmplen
int *

variable_types:
p
char *

return_type: char *


genEventVars

decompiled_code:
void *__fastcall genEventVars(int *a1, __int64 a2, const char *a3)
{
void *result; // rax
void *v5; // rbp
__int64 v6; // rbx
char *v7; // rax
const char *v8; // rcx
char *v9; // rbp
char *v10; // rbp
__int64 v11; // rax
const char *v12; // r8
char *v13; // rax
char *v14; // rcx
int v15; // [rsp+Ch] [rbp-22Ch] BYREF
char s[552]; // [rsp+10h] [rbp-228h] BYREF

v15 = 512;
result = malloc(0x200uLL);
v5 = result;
if ( result )
{
v6 = *(_QWORD *)(a2 + 8);
*a1 = 0;
snprintf(s, 0x200uLL, "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\" xmlns:s=\"%s\">", a3);
v7 = strcat_str(v5, a1, &v15, s);
v8 = *(const char **)v6;
v9 = v7;
if ( !*(_QWORD *)v6 )
{
LABEL_10:
result = strcat_str(v9, a1, &v15, "</e:propertyset>");
*((_BYTE *)result + *a1) = 0;
return result;
}
while ( 1 )
{
while ( *(char *)(v6 + 8) >= 0 )
{
v8 = *(const char **)(v6 + 16);
v6 += 16LL;
if ( !v8 )
goto LABEL_10;
}
snprintf(s, 0x200uLL, "<e:property><%s>", v8);
v10 = strcat_str(v9, a1, &v15, s);
v11 = *(unsigned __int8 *)(v6 + 11);
if ( !(_BYTE)v11 )
goto LABEL_14;
if ( (_BYTE)v11 != 0xFF )
break;
v12 = *(const char **)v6;
if ( !strcmp(*(const char **)v6, "SystemUpdateID") )
{
snprintf(s, 0x200uLL, "%d", updateID);
v14 = s;
goto LABEL_13;
}
LABEL_9:
v6 += 16LL;
snprintf(s, 0x200uLL, "</%s></e:property>", v12);
v13 = strcat_str(v10, a1, &v15, s);
v8 = *(const char **)v6;
v9 = v13;
if ( !*(_QWORD *)v6 )
goto LABEL_10;
}
v14 = (char *)upnpallowedvalues[v11];
LABEL_13:
v10 = strcat_str(v10, a1, &v15, v14);
LABEL_14:
v12 = *(const char **)v6;
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int *a1, __int64 a2, const char *a3)
{
void *result; // rax
void *v5; // rbp
__int64 v6; // rbx
char *v7; // rax
const char *v8; // rcx
char *v9; // rbp
char *v10; // rbp
__int64 v11; // rax
const char *v12; // r8
char *v13; // rax
char *v14; // rcx
int v15; // [rsp+Ch] [rbp-22Ch] BYREF
char s[552]; // [rsp+10h] [rbp-228h] BYREF

v15 = 512;
result = malloc(0x200uLL);
v5 = result;
if ( result )
{
v6 = *(_QWORD *)(a2 + 8);
*a1 = 0;
snprintf(s, 0x200uLL, "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\" xmlns:s=\"%s\">", a3);
v7 = func0(v5, a1, &v15, s);
v8 = *(const char **)v6;
v9 = v7;
if ( !*(_QWORD *)v6 )
{
LABEL_10:
result = func0(v9, a1, &v15, "</e:propertyset>");
*((_BYTE *)result + *a1) = 0;
return result;
}
while ( 1 )
{
while ( *(char *)(v6 + 8) >= 0 )
{
v8 = *(const char **)(v6 + 16);
v6 += 16LL;
if ( !v8 )
goto LABEL_10;
}
snprintf(s, 0x200uLL, "<e:property><%s>", v8);
v10 = func0(v9, a1, &v15, s);
v11 = *(unsigned __int8 *)(v6 + 11);
if ( !(_BYTE)v11 )
goto LABEL_14;
if ( (_BYTE)v11 != 0xFF )
break;
v12 = *(const char **)v6;
if ( !strcmp(*(const char **)v6, "SystemUpdateID") )
{
snprintf(s, 0x200uLL, "%d", updateID);
v14 = s;
goto LABEL_13;
}
LABEL_9:
v6 += 16LL;
snprintf(s, 0x200uLL, "</%s></e:property>", v12);
v13 = func0(v10, a1, &v15, s);
v8 = *(const char **)v6;
v9 = v13;
if ( !*(_QWORD *)v6 )
goto LABEL_10;
}
v14 = (char *)upnpallowedvalues[v11];
LABEL_13:
v10 = func0(v10, a1, &v15, v14);
LABEL_14:
v12 = *(const char **)v6;
goto LABEL_9;
}
return result;
}

original_code:
static char *
genEventVars(int * len, const struct serviceDesc * s, const char * servns)
{
 const struct stateVar * v;
 char * str;
 int tmplen;
 char buf[512];
 tmplen = 512;
 str = (char *)malloc(tmplen);
 if(str == ((void *)0))
  return ((void *)0);
 *len = 0;
 v = s->serviceStateTable;
 snprintf(buf, sizeof(buf), "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\" xmlns:s=\"%s\">", servns);
 str = strcat_str(str, len, &tmplen, buf);
 while(v->name) {
  if(v->itype & 0x80) {
   snprintf(buf, sizeof(buf), "<e:property><%s>", v->name);
   str = strcat_str(str, len, &tmplen, buf);
   switch(v->ieventvalue) {
   case 0:
    break;
   case 255:
    if( strcmp(v->name, "SystemUpdateID") == 0 )
    {
     snprintf(buf, sizeof(buf), "%d", updateID);
     str = strcat_str(str, len, &tmplen, buf);
    }
    break;
   default:
    str = strcat_str(str, len, &tmplen, upnpallowedvalues[v->ieventvalue]);
   }
   snprintf(buf, sizeof(buf), "</%s></e:property>", v->name);
   str = strcat_str(str, len, &tmplen, buf);
  }
  v++;
 }
 str = strcat_str(str, len, &tmplen, "</e:propertyset>");
 str[*len] = '\0';
 return str;
}

canonical_original_code:
static char *genEventVars(int *len, struct serviceDesc *s, char *servns)
{
 struct stateVar *v;
 char *str;
 int tmplen;
 char buf[512];
 tmplen = 512;
 str = (char *)malloc(tmplen);
 if(str == ((void *)0))
  return ((void *)0);
 *len = 0;
 v = s->serviceStateTable;
 snprintf(buf, sizeof(buf), "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\" xmlns:s=\"%s\">", servns);
 str = strcat_str(str, len, &tmplen, buf);
 while(v->name) {
  if(v->itype & 0x80) {
   snprintf(buf, sizeof(buf), "<e:property><%s>", v->name);
   str = strcat_str(str, len, &tmplen, buf);
   switch(v->ieventvalue) {
   case 0:
    break;
   case 255:
    if( strcmp(v->name, "SystemUpdateID") == 0 )
    {
     snprintf(buf, sizeof(buf), "%d", updateID);
     str = strcat_str(str, len, &tmplen, buf);
    }
    break;
   default:
    str = strcat_str(str, len, &tmplen, upnpallowedvalues[v->ieventvalue]);
   }
   snprintf(buf, sizeof(buf), "</%s></e:property>", v->name);
   str = strcat_str(str, len, &tmplen, buf);
  }
  v++;
 }
 str = strcat_str(str, len, &tmplen, "</e:propertyset>");
 str[*len] = '\0';
 return str;
}

variable_types: struct serviceDesc { struct action { char *name; struct argument { char *name; unsigned char dir; unsigned char relatedVar; } *args; } *actionList; struct stateVar { char *name; unsigned char itype; unsigned char idefault; unsigned char iallowedlist; unsigned char ieventvalue; } *serviceStateTable; } *

variable_types:
servns
char *

variable_types: tmplen int

variable_types:
buf
char [512]

user_defined_types: struct serviceDesc { struct action *actionList; struct stateVar *serviceStateTable; }

user_defined_types: struct action { char *name; struct argument *args; }


getVarsContentDirectory

decompiled_code:
void *__fastcall getVarsContentDirectory(int *a1)
{
return genEventVars(a1, (__int64)scpdContentDirectory, "urn:schemas-upnp-org:service:ContentDirectory:1");
}

canonical_decompiled_code:
void *__fastcall func2(int *a1)
{
return func1(a1, (__int64)scpdContentDirectory, "urn:schemas-upnp-org:service:ContentDirectory:1");
}

original_code:
char *
getVarsContentDirectory(int * l)
{
 return genEventVars(l,
                        &scpdContentDirectory,
                     "urn:schemas-upnp-org:service:ContentDirectory:1");
}

canonical_original_code:
char *getVarsContentDirectory(int *l)
{
 return genEventVars(l,
                        &scpdContentDirectory,
                     "urn:schemas-upnp-org:service:ContentDirectory:1");
}

variable_types:
l
int *


getVarsConnectionManager

decompiled_code:
void *__fastcall getVarsConnectionManager(int *a1)
{
return genEventVars(a1, (__int64)scpdConnectionManager, "urn:schemas-upnp-org:service:ConnectionManager:1");
}

canonical_decompiled_code:
void *__fastcall func3(int *a1)
{
return func1(a1, (__int64)scpdConnectionManager, "urn:schemas-upnp-org:service:ConnectionManager:1");
}

original_code:
char *
getVarsConnectionManager(int * l)
{
 return genEventVars(l,
                        &scpdConnectionManager,
                     "urn:schemas-upnp-org:service:ConnectionManager:1");
}

canonical_original_code:
char *getVarsConnectionManager(int *l)
{
 return genEventVars(l,
                        &scpdConnectionManager,
                     "urn:schemas-upnp-org:service:ConnectionManager:1");
}


decompiled_code:
void *__fastcall getVarsX_MS_MediaReceiverRegistrar(int *a1)
{
return genEventVars(
a1,
(__int64)scpdX_MS_MediaReceiverRegistrar,
"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1");
}

canonical_decompiled_code:
void *__fastcall func4(int *a1)
{
return func1(
a1,
(__int64)scpdX_MS_MediaReceiverRegistrar,
"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1");
}

original_code:
char *
getVarsX_MS_MediaReceiverRegistrar(int * l)
{
 return genEventVars(l,
                        &scpdX_MS_MediaReceiverRegistrar,
                     "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1");
}

canonical_original_code:
char *getVarsX_MS_MediaReceiverRegistrar(int *l)
{
 return genEventVars(l,
                        &scpdX_MS_MediaReceiverRegistrar,
                     "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1");
}


NameValueParserGetData

original_code:
static void
NameValueParserGetData(void * d, const char * datas, int l)
{
    struct NameValueParserData * data = (struct NameValueParserData *)d;
    struct NameValue * nv;
    if(l>1975)
        l = 1975;
    nv = malloc(sizeof(struct NameValue)+l+1);
    strncpy(nv->name, data->curelt, 64);
    nv->name[63] = '\0';
    memcpy(nv->value, datas, l);
    nv->value[l] = '\0';
    do { if (((nv)->entries.le_next = (&(data->head))->lh_first) != ((void *)0)) (&(data->head))->lh_first->entries.le_prev = &(nv)->entries.le_next; (&(data->head))->lh_first = (nv); (nv)->entries.le_prev = &(&(data->head))->lh_first; } while ( 0);
}

canonical_original_code:
static void NameValueParserGetData(void *d, char *datas, int l)
{
    struct NameValueParserData *data = (struct NameValueParserData *)d;
    struct NameValue *nv;
    if(l>1975)
        l = 1975;
    nv = malloc(sizeof(struct NameValue)+l+1);
    strncpy(nv->name, data->curelt, 64);
    nv->name[63] = '\0';
    memcpy(nv->value, datas, l);
    nv->value[l] = '\0';
    do { if (((nv)->entries.le_next = (&(data->head))->lh_first) != ((void *)0)) (&(data->head))->lh_first->entries.le_prev = &(nv)->entries.le_next; (&(data->head))->lh_first = (nv); (nv)->entries.le_prev = &(&(data->head))->lh_first; } while ( 0);
}

variable_types:
d
void *

variable_types:
datas
char *

variable_types: l int

variable_types: struct NameValueParserData { struct listhead { struct NameValue { struct { struct NameValue *le_next; struct NameValue **le_prev; } entries; char name[64]; char value[]; } *lh_first; } head; char curelt[64]; } *

return_type: void

user_defined_types: struct NameValueParserData { struct listhead head; char curelt[64]; }

user_defined_types: struct listhead { struct NameValue *lh_first; }


NameValueParserStartElt

decompiled_code:
unsigned __int64 __fastcall NameValueParserStartElt(unsigned __int64 *a1, unsigned __int64 *a2, int a3)
{
int v5; // edi
unsigned __int64 result; // rax
unsigned __int64 v7; // rcx
unsigned __int64 v8; // rax
char *v9; // r8
unsigned __int64 v10; // rdx
unsigned __int64 v11; // rsi
unsigned __int64 v12; // rdx

v5 = 63;
if ( a3 <= 63 )
v5 = a3;
result = (unsigned __int64)(a1 + 1);
if ( (unsigned __int64)v5 >= 8 )
{
v7 = (unsigned __int64)(a1 + 2) & 0xFFFFFFFFFFFFFFF8LL;
a1[1] = *a2;
*(unsigned __int64 *)((char *)a1 + v5) = *(unsigned __int64 *)((char *)a2 + v5 - 8);
v8 = result - v7;
v9 = (char *)a2 - v8;
result = (v5 + v8) & 0xFFFFFFFFFFFFFFF8LL;
if ( result >= 8 )
{
result &= 0xFFFFFFFFFFFFFFF8LL;
v10 = 0LL;
do
{
*(_QWORD *)(v7 + v10) = *(_QWORD *)&v9[v10];
v10 += 8LL;
}
while ( v10 < result );
*((_BYTE *)a1 + v5 + 8) = 0;
if ( *a1 )
return result;
goto LABEL_14;
}
}
else if ( (v5 & 4) != 0 )
{
*((_DWORD *)a1 + 2) = *(_DWORD *)a2;
*(_DWORD *)(result + v5 - 4) = *(_DWORD *)((char *)a2 + v5 - 4);
}
else if ( v5 )
{
*((_BYTE *)a1 + 8) = *(_BYTE *)a2;
if ( (v5 & 2) != 0 )
*(_WORD *)(result + v5 - 2) = *(_WORD *)((char *)a2 + v5 - 2);
}
*((_BYTE *)a1 + v5 + 8) = 0;
if ( *a1 )
return result;
LABEL_14:
result = (unsigned __int64)malloc(v5 + 81);
*(_QWORD *)(result + 16) = 0x6D656C45746F6F72LL;
v11 = result + 80;
*(_DWORD *)(result + 24) = 7630437;
if ( (unsigned __int64)v5 >= 8 )
{
*(_QWORD *)(v11 + v5 - 8) = *(unsigned __int64 *)((char *)a2 + v5 - 8);
if ( (unsigned __int64)(v5 - 1LL) >= 8 )
{
v12 = 0LL;
do
{
*(_QWORD *)(v11 + v12) = a2[v12 / 8];
v12 += 8LL;
}
while ( v12 < ((v5 - 1LL) & 0xFFFFFFFFFFFFFFF8LL) );
}
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(result + 80) = *(_DWORD *)a2;
*(_DWORD *)(v11 + v5 - 4) = *(_DWORD *)((char *)a2 + v5 - 4);
}
else if ( v5 )
{
*(_BYTE *)(result + 80) = *(_BYTE *)a2;
if ( (v5 & 2) != 0 )
*(_WORD *)(v11 + v5 - 2) = *(_WORD *)((char *)a2 + v5 - 2);
}
*(_BYTE *)(result + v5 + 80) = 0;
*a1 = result;
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = a1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 *a1, unsigned __int64 *a2, int a3)
{
int v5; // edi
unsigned __int64 result; // rax
unsigned __int64 v7; // rcx
unsigned __int64 v8; // rax
char *v9; // r8
unsigned __int64 v10; // rdx
unsigned __int64 v11; // rsi
unsigned __int64 v12; // rdx

v5 = 63;
if ( a3 <= 63 )
v5 = a3;
result = (unsigned __int64)(a1 + 1);
if ( (unsigned __int64)v5 >= 8 )
{
v7 = (unsigned __int64)(a1 + 2) & 0xFFFFFFFFFFFFFFF8LL;
a1[1] = *a2;
*(unsigned __int64 *)((char *)a1 + v5) = *(unsigned __int64 *)((char *)a2 + v5 - 8);
v8 = result - v7;
v9 = (char *)a2 - v8;
result = (v5 + v8) & 0xFFFFFFFFFFFFFFF8LL;
if ( result >= 8 )
{
result &= 0xFFFFFFFFFFFFFFF8LL;
v10 = 0LL;
do
{
*(_QWORD *)(v7 + v10) = *(_QWORD *)&v9[v10];
v10 += 8LL;
}
while ( v10 < result );
*((_BYTE *)a1 + v5 + 8) = 0;
if ( *a1 )
return result;
goto LABEL_14;
}
}
else if ( (v5 & 4) != 0 )
{
*((_DWORD *)a1 + 2) = *(_DWORD *)a2;
*(_DWORD *)(result + v5 - 4) = *(_DWORD *)((char *)a2 + v5 - 4);
}
else if ( v5 )
{
*((_BYTE *)a1 + 8) = *(_BYTE *)a2;
if ( (v5 & 2) != 0 )
*(_WORD *)(result + v5 - 2) = *(_WORD *)((char *)a2 + v5 - 2);
}
*((_BYTE *)a1 + v5 + 8) = 0;
if ( *a1 )
return result;
LABEL_14:
result = (unsigned __int64)malloc(v5 + 81);
*(_QWORD *)(result + 16) = 0x6D656C45746F6F72LL;
v11 = result + 80;
*(_DWORD *)(result + 24) = 7630437;
if ( (unsigned __int64)v5 >= 8 )
{
*(_QWORD *)(v11 + v5 - 8) = *(unsigned __int64 *)((char *)a2 + v5 - 8);
if ( (unsigned __int64)(v5 - 1LL) >= 8 )
{
v12 = 0LL;
do
{
*(_QWORD *)(v11 + v12) = a2[v12 / 8];
v12 += 8LL;
}
while ( v12 < ((v5 - 1LL) & 0xFFFFFFFFFFFFFFF8LL) );
}
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(result + 80) = *(_DWORD *)a2;
*(_DWORD *)(v11 + v5 - 4) = *(_DWORD *)((char *)a2 + v5 - 4);
}
else if ( v5 )
{
*(_BYTE *)(result + 80) = *(_BYTE *)a2;
if ( (v5 & 2) != 0 )
*(_WORD *)(v11 + v5 - 2) = *(_WORD *)((char *)a2 + v5 - 2);
}
*(_BYTE *)(result + v5 + 80) = 0;
*a1 = result;
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
static void
NameValueParserStartElt(void * d, const char * name, int l)
{
    struct NameValueParserData * data = (struct NameValueParserData *)d;
    if(l>63)
        l = 63;
    memcpy(data->curelt, name, l);
    data->curelt[l] = '\0';
    if(!data->head.lh_first)
    {
        struct NameValue * nv;
        nv = malloc(sizeof(struct NameValue)+l+1);
        strcpy(nv->name, "rootElement");
        memcpy(nv->value, name, l);
        nv->value[l] = '\0';
        do { if (((nv)->entries.le_next = (&(data->head))->lh_first) != ((void *)0)) (&(data->head))->lh_first->entries.le_prev = &(nv)->entries.le_next; (&(data->head))->lh_first = (nv); (nv)->entries.le_prev = &(&(data->head))->lh_first; } while ( 0);
    }
}

canonical_original_code:
static void NameValueParserStartElt(void *d, char *name, int l)
{
    struct NameValueParserData *data = (struct NameValueParserData *)d;
    if(l>63)
        l = 63;
    memcpy(data->curelt, name, l);
    data->curelt[l] = '\0';
    if(!data->head.lh_first)
    {
        struct NameValue *nv;
        nv = malloc(sizeof(struct NameValue)+l+1);
        strcpy(nv->name, "rootElement");
        memcpy(nv->value, name, l);
        nv->value[l] = '\0';
        do { if (((nv)->entries.le_next = (&(data->head))->lh_first) != ((void *)0)) (&(data->head))->lh_first->entries.le_prev = &(nv)->entries.le_next; (&(data->head))->lh_first = (nv); (nv)->entries.le_prev = &(&(data->head))->lh_first; } while ( 0);
    }
}

variable_types:
name
char *

variable_types: struct NameValue { struct { struct NameValue *le_next; struct NameValue **le_prev; } entries; char name[64]; char value[]; } *


ParseNameValue

decompiled_code:
__int64 __fastcall ParseNameValue(__int64 a1, int a2, _QWORD *a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-58h] BYREF
int v5; // [rsp+18h] [rbp-40h]
_QWORD *v6; // [rsp+20h] [rbp-38h]
unsigned __int64 (__fastcall *v7)(unsigned __int64 *, unsigned __int64 *, int); // [rsp+28h] [rbp-30h]
__int64 v8; // [rsp+30h] [rbp-28h]
__int64 (__fastcall *v9)(char *, _DWORD *, int); // [rsp+38h] [rbp-20h]
__int64 v10; // [rsp+40h] [rbp-18h]

*a3 = 0LL;
v4[0] = a1;
v5 = a2;
v6 = a3;
v7 = NameValueParserStartElt;
v8 = 0LL;
v9 = NameValueParserGetData;
v10 = 0LL;
return parsexml(v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, _QWORD *a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-58h] BYREF
int v5; // [rsp+18h] [rbp-40h]
_QWORD *v6; // [rsp+20h] [rbp-38h]
unsigned __int64 (__fastcall *v7)(unsigned __int64 *, unsigned __int64 *, int); // [rsp+28h] [rbp-30h]
__int64 v8; // [rsp+30h] [rbp-28h]
__int64 (__fastcall *v9)(char *, _DWORD *, int); // [rsp+38h] [rbp-20h]
__int64 v10; // [rsp+40h] [rbp-18h]

*a3 = 0LL;
v4[0] = a1;
v5 = a2;
v6 = a3;
v7 = NameValueParserStartElt;
v8 = 0LL;
v9 = NameValueParserGetData;
v10 = 0LL;
return parsexml(v4);
}

original_code:
void
ParseNameValue(const char * buffer, int bufsize,
                    struct NameValueParserData * data)
{
    struct xmlparser parser;
    do { (&(data->head))->lh_first = ((void *)0); } while ( 0);
    parser.xmlstart = buffer;
    parser.xmlsize = bufsize;
    parser.data = data;
    parser.starteltfunc = NameValueParserStartElt;
    parser.endeltfunc = 0;
    parser.datafunc = NameValueParserGetData;
    parser.attfunc = 0;
    parsexml(&parser);
}

canonical_original_code:
void ParseNameValue(char *buffer, int bufsize, struct NameValueParserData *data)
{
    struct xmlparser parser;
    do { (&(data->head))->lh_first = ((void *)0); } while ( 0);
    parser.xmlstart = buffer;
    parser.xmlsize = bufsize;
    parser.data = data;
    parser.starteltfunc = NameValueParserStartElt;
    parser.endeltfunc = 0;
    parser.datafunc = NameValueParserGetData;
    parser.attfunc = 0;
    parsexml(&parser);
}

variable_types:
buffer
char *

variable_types: bufsize int

variable_types: struct xmlparser { char *xmlstart; char *xmlend; char *xml; int xmlsize; void *data; void (*starteltfunc)(void *, char *, int); void (*endeltfunc)(void *, char *, int); void (*datafunc)(void *, char *, int); void (*attfunc)(void *, char *, int, char *, int); }

user_defined_types: struct NameValue { struct { struct NameValue *le_next; struct NameValue **le_prev; } entries; char name[64]; char value[]; }


decompiled_code:
int close_server()
{
return close(*(int *)&rc.sa_family);
}

canonical_decompiled_code:
int func1()
{
return close(*(int *)&rc.sa_family);
}

original_code:
void close_server(void)
{
 close(rc.server_socket);
}

canonical_original_code:
void close_server()
{
 close(rc.server_socket);
}


decompiled_code:
__int64 build_server()
{
__int16 v0; // di
int v1; // edx
int v2; // er8
__int64 result; // rax

v0 = runtime_vars;
*(_OWORD *)&rc.sa_data[10] = 0LL;
*(_WORD *)&rc.sa_data[12] = _bswap_16(v0);
*(_WORD *)&rc.sa_data[10] = 2;
*(_DWORD *)&rc.sa_family = socket(2, 1, v1);
if ( bind(*(int *)&rc.sa_family, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 12), 0x10u) < 0 )
{
log_err(1LL, 0LL, "tcptunnel.c", 94LL, "Failed to bind to socket for tcp tunnel. EXITING.\n");
result = 1LL;
}
else
{
v2 = listen(*(int *)&rc.sa_family, 1);
result = 0LL;
if ( v2 < 0 )
{
log_err(1LL, 0LL, "tcptunnel.c", 100LL, "Failed to listen on socket for tcp tunnel. EXITING.\n");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int16 v0; // di
int v1; // edx
int v2; // er8
__int64 result; // rax

v0 = runtime_vars;
*(_OWORD *)&rc.sa_data[10] = 0LL;
*(_WORD *)&rc.sa_data[12] = func0(v0);
*(_WORD *)&rc.sa_data[10] = 2;
*(_DWORD *)&rc.sa_family = socket(2, 1, v1);
if ( bind(*(int *)&rc.sa_family, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 12), 0x10u) < 0 )
{
log_err(1LL, 0LL, "tcptunnel.c", 94LL, "Failed to bind to socket for tcp tunnel. EXITING.\n");
result = 1LL;
}
else
{
v2 = listen(*(int *)&rc.sa_family, 1);
result = 0LL;
if ( v2 < 0 )
{
log_err(1LL, 0LL, "tcptunnel.c", 100LL, "Failed to listen on socket for tcp tunnel. EXITING.\n");
result = 1LL;
}
}
return result;
}

original_code:
int build_server(void)
{
 memset(&rc.server_addr, 0, sizeof(rc.server_addr));
 rc.server_addr.sin_port = htons(runtime_vars.port);
 rc.server_addr.sin_family = 2;
 rc.server_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 rc.server_socket = socket(2, SOCK_STREAM, 0);
 if (rc.server_socket < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 86, "Failed to open socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 if (bind(rc.server_socket, (struct sockaddr *) &rc.server_addr, sizeof(rc.server_addr)) < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 94, "Failed to bind to socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 if (listen(rc.server_socket, 1) < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 100, "Failed to listen on socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 return 0;
}

canonical_original_code:
int build_server()
{
 memset(&rc.server_addr, 0, sizeof(rc.server_addr));
 rc.server_addr.sin_port = htons(runtime_vars.port);
 rc.server_addr.sin_family = 2;
 rc.server_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 rc.server_socket = socket(2, SOCK_STREAM, 0);
 if (rc.server_socket < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 86, "Failed to open socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 if (bind(rc.server_socket, (struct sockaddr *) &rc.server_addr, sizeof(rc.server_addr)) < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 94, "Failed to bind to socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 if (listen(rc.server_socket, 1) < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 100, "Failed to listen on socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 wait_for_clients()
{
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
*(_DWORD *)&rc.sa_data[2] = accept(
*(int *)&rc.sa_family,
(struct sockaddr *)(unsigned int)((_DWORD)&rc + 28),
addr_len);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
*(_DWORD *)&rc.sa_data[2] = accept(
*(int *)&rc.sa_family,
(struct sockaddr *)(unsigned int)((_DWORD)&rc + 28),
addr_len);
return 0LL;
}

original_code:
int wait_for_clients(void)
{
 int client_addr_size = sizeof(struct sockaddr_in);
 rc.client_socket = accept(rc.server_socket, (struct sockaddr *) &rc.client_addr, (socklen_t *) &client_addr_size);
 if (rc.client_socket < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 114, "Failed to wait for connections on socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 return 0;
}

canonical_original_code:
int wait_for_clients()
{
 int client_addr_size = sizeof(struct sockaddr_in);
 rc.client_socket = accept(rc.server_socket, (struct sockaddr *) &rc.client_addr, (unsigned int *) &client_addr_size);
 if (rc.client_socket < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 114, "Failed to wait for connections on socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 build_tunnel()
{
struct hostent *v0; // rax
__int16 v1; // di
__int16 v2; // ax
__int64 v3; // rdx
size_t v4; // r8
int v5; // eax
int v6; // er8
__int64 result; // rax

v0 = gethostbyname(*((const char **)&runtime_vars + 1));
*((_QWORD *)&rc + 8) = v0;
if ( v0 )
{
v1 = *((_WORD *)&runtime_vars + 2);
*(struct sockaddr *)((char *)&rc + 44) = 0LL;
*((_WORD *)&rc + 22) = 2;
v2 = _bswap_16(v1);
v4 = *(int *)(v3 + 20);
*((_WORD *)&rc + 23) = v2;
memcpy((void *)(unsigned int)((_DWORD)&rc + 48), **(const void ***)(v3 + 24), v4);
v5 = socket(2, 1, 0);
*(_DWORD *)&rc.sa_data[6] = v5;
v6 = connect(v5, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 44), 0x10u);
result = 0LL;
if ( v6 < 0 )
{
log_err(1LL, 0LL, "tcptunnel.c", 148LL, "Failed to connect to remote host for tcp tunnel. EXITING.\n");
result = 1LL;
}
}
else
{
log_err(1LL, 0LL, "tcptunnel.c", 128LL, "Failed to resolve hostname for tcp tunnel. EXITING.\n");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
struct hostent *v0; // rax
__int16 v1; // di
__int16 v2; // ax
__int64 v3; // rdx
size_t v4; // r8
int v5; // eax
int v6; // er8
__int64 result; // rax

v0 = gethostbyname(*((const char **)&runtime_vars + 1));
*((_QWORD *)&rc + 8) = v0;
if ( v0 )
{
v1 = *((_WORD *)&runtime_vars + 2);
*(struct sockaddr *)((char *)&rc + 44) = 0LL;
*((_WORD *)&rc + 22) = 2;
v2 = func0(v1);
v4 = *(int *)(v3 + 20);
*((_WORD *)&rc + 23) = v2;
memcpy((void *)(unsigned int)((_DWORD)&rc + 48), **(const void ***)(v3 + 24), v4);
v5 = socket(2, 1, 0);
*(_DWORD *)&rc.sa_data[6] = v5;
v6 = connect(v5, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 44), 0x10u);
result = 0LL;
if ( v6 < 0 )
{
log_err(1LL, 0LL, "tcptunnel.c", 148LL, "Failed to connect to remote host for tcp tunnel. EXITING.\n");
result = 1LL;
}
}
else
{
log_err(1LL, 0LL, "tcptunnel.c", 128LL, "Failed to resolve hostname for tcp tunnel. EXITING.\n");
result = 1LL;
}
return result;
}

original_code:
int build_tunnel(void)
{
 rc.remote_host = gethostbyname(runtime_vars.rhost);
 if (rc.remote_host == ((void *)0))
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 128, "Failed to resolve hostname for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 memset(&rc.remote_addr, 0, sizeof(rc.remote_addr));
 rc.remote_addr.sin_family = 2;
 rc.remote_addr.sin_port = htons(runtime_vars.rport);
 memcpy(&rc.remote_addr.sin_addr.s_addr, rc.remote_host->h_addr_list[0], rc.remote_host->h_length);
 rc.remote_socket = socket(2, SOCK_STREAM, 0);
 if (rc.remote_socket < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 142, "Failed to open socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 if (connect(rc.remote_socket, (struct sockaddr *) &rc.remote_addr, sizeof(rc.remote_addr)) < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 148, "Failed to connect to remote host for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 return 0;
}

canonical_original_code:
int build_tunnel()
{
 rc.remote_host = gethostbyname(runtime_vars.rhost);
 if (rc.remote_host == ((void *)0))
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 128, "Failed to resolve hostname for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 memset(&rc.remote_addr, 0, sizeof(rc.remote_addr));
 rc.remote_addr.sin_family = 2;
 rc.remote_addr.sin_port = htons(runtime_vars.rport);
 memcpy(&rc.remote_addr.sin_addr.s_addr, rc.remote_host->h_addr_list[0], rc.remote_host->h_length);
 rc.remote_socket = socket(2, SOCK_STREAM, 0);
 if (rc.remote_socket < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 142, "Failed to open socket for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 if (connect(rc.remote_socket, (struct sockaddr *) &rc.remote_addr, sizeof(rc.remote_addr)) < 0)
 {
  { log_err(1, L_GENERAL, "tcptunnel.c", 148, "Failed to connect to remote host for tcp tunnel. EXITING.\n"); };
  return 1;
 }
 return 0;
}


fd

decompiled_code:
__int64 fd()
{
unsigned int v0; // eax

v0 = *(_DWORD *)&rc.sa_data[2];
if ( *(_DWORD *)&rc.sa_data[6] >= v0 )
v0 = *(_DWORD *)&rc.sa_data[6];
return v0 + 1;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // eax

v0 = *(_DWORD *)&rc.sa_data[2];
if ( *(_DWORD *)&rc.sa_data[6] >= v0 )
v0 = *(_DWORD *)&rc.sa_data[6];
return v0 + 1;
}

original_code:
int fd(void)
{
 unsigned int fd = rc.client_socket;
 if (fd < rc.remote_socket)
 {
  fd = rc.remote_socket;
 }
 return fd + 1;
}

canonical_original_code:
int fd()
{
 unsigned int fd = rc.client_socket;
 if (fd < rc.remote_socket)
 {
  fd = rc.remote_socket;
 }
 return fd + 1;
}

variable_types:
fd
unsigned int


decompiled_code:
__int64 use_tunnel()
{
unsigned int v0; // edi
unsigned int v1; // ecx
int v2; // eax
fd_set *v3; // rdx
fd_set *v4; // rcx
struct timeval *v5; // r8
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // er13
int v10; // eax
int v11; // edi
const char *v12; // r8
__int64 v13; // rcx
fd_set v14; // [rsp+0h] [rbp-10A8h] BYREF
char buf[4096]; // [rsp+80h] [rbp-1028h] BYREF
__int64 v16; // [rsp+1080h] [rbp-28h] BYREF

while ( 1 )
{
if ( quitting )
return 0;
memset(&v14, 0, sizeof(v14));
v1 = *(_DWORD *)&rc.sa_data[6];
v14.fds_bits[*(_DWORD *)&rc.sa_data[2] >> 6] |= 1LL << *(_DWORD *)&rc.sa_data[2];
v14.fds_bits[v1 >> 6] |= 1LL << v1;
memset(buf, 0, sizeof(buf));
v2 = fd(&v16, &v14, 0LL, 0LL, 0LL);
if ( select(v2, &v14, v3, v4, v5) < 0 )
{
v8 = 0;
log_err(1LL, 0LL, "tcptunnel.c", 170LL, "Failed to use selected tcp tunnel. EXITING.\n");
return v8;
}
v6 = *(_DWORD *)&rc.sa_data[2];
if ( (v14.fds_bits[v6 >> 6] & (1LL << v6)) == 0 )
goto LABEL_2;
v7 = recv(v6, buf, 0x1000uLL, 0);
v8 = v7;
if ( v7 < 0 )
{
v12 = "Failed to receive on client socket for tcp tunnel. EXITING.\n";
v13 = 179LL;
LABEL_16:
log_err(1LL, 0LL, "tcptunnel.c", v13, v12);
v8 = 1;
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v8;
}
if ( !v7 )
break;
send(*(_DWORD *)&rc.sa_data[6], buf, v7, 0);
LABEL_2:
v0 = *(_DWORD *)&rc.sa_data[6];
if ( (v14.fds_bits[v0 >> 6] & (1LL << v0)) != 0 )
{
v10 = recv(v0, buf, 0x1000uLL, 0);
v8 = v10;
if ( v10 < 0 )
{
v12 = "Failed to receive on remote socket for tcp tunnel. EXITING.\n";
v13 = 204LL;
goto LABEL_16;
}
v11 = *(_DWORD *)&rc.sa_data[2];
if ( !v10 )
{
close(v11);
close(*(_DWORD *)&rc.sa_data[6]);
return v8;
}
send(v11, buf, v10, 0);
}
}
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v8;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // edi
unsigned int v1; // ecx
int v2; // eax
fd_set *v3; // rdx
fd_set *v4; // rcx
struct timeval *v5; // r8
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // er13
int v10; // eax
int v11; // edi
const char *v12; // r8
__int64 v13; // rcx
fd_set v14; // [rsp+0h] [rbp-10A8h] BYREF
char buf[4096]; // [rsp+80h] [rbp-1028h] BYREF
__int64 v16; // [rsp+1080h] [rbp-28h] BYREF

while ( 1 )
{
if ( quitting )
return 0;
memset(&v14, 0, sizeof(v14));
v1 = *(_DWORD *)&rc.sa_data[6];
v14.fds_bits[*(_DWORD *)&rc.sa_data[2] >> 6] |= 1LL << *(_DWORD *)&rc.sa_data[2];
v14.fds_bits[v1 >> 6] |= 1LL << v1;
memset(buf, 0, sizeof(buf));
v2 = func5(&v16, &v14, 0LL, 0LL, 0LL);
if ( select(v2, &v14, v3, v4, v5) < 0 )
{
v8 = 0;
log_err(1LL, 0LL, "tcptunnel.c", 170LL, "Failed to use selected tcp tunnel. EXITING.\n");
return v8;
}
v6 = *(_DWORD *)&rc.sa_data[2];
if ( (v14.fds_bits[v6 >> 6] & (1LL << v6)) == 0 )
goto LABEL_2;
v7 = recv(v6, buf, 0x1000uLL, 0);
v8 = v7;
if ( v7 < 0 )
{
v12 = "Failed to receive on client socket for tcp tunnel. EXITING.\n";
v13 = 179LL;
LABEL_16:
log_err(1LL, 0LL, "tcptunnel.c", v13, v12);
v8 = 1;
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v8;
}
if ( !v7 )
break;
send(*(_DWORD *)&rc.sa_data[6], buf, v7, 0);
LABEL_2:
v0 = *(_DWORD *)&rc.sa_data[6];
if ( (v14.fds_bits[v0 >> 6] & (1LL << v0)) != 0 )
{
v10 = recv(v0, buf, 0x1000uLL, 0);
v8 = v10;
if ( v10 < 0 )
{
v12 = "Failed to receive on remote socket for tcp tunnel. EXITING.\n";
v13 = 204LL;
goto LABEL_16;
}
v11 = *(_DWORD *)&rc.sa_data[2];
if ( !v10 )
{
close(v11);
close(*(_DWORD *)&rc.sa_data[6]);
return v8;
}
send(v11, buf, v10, 0);
}
}
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v8;
}

original_code:
int use_tunnel(void)
{
 fd_set io;
 char buffer[4096];
 while(!quitting)
 {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&io)->fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&io)->fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&io)->fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))));
  memset(buffer, 0, 4096);
  if (select(fd(), &io, ((void *)0), ((void *)0), ((void *)0)) < 0 )
  {
   { log_err(1, L_GENERAL, "tcptunnel.c", 170, "Failed to use selected tcp tunnel. EXITING.\n"); };
   break;
  }
  if (((((&io)->fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.client_socket, buffer, 4096, 0);
   if (count < 0)
   {
    { log_err(1, L_GENERAL, "tcptunnel.c", 179, "Failed to receive on client socket for tcp tunnel. EXITING.\n"); };
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.remote_socket, buffer, count, 0);
  }
  if (((((&io)->fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.remote_socket, buffer, 4096, 0);
   if (count < 0)
   {
    { log_err(1, L_GENERAL, "tcptunnel.c", 204, "Failed to receive on remote socket for tcp tunnel. EXITING.\n"); };
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.client_socket, buffer, count, 0);
  }
 }
 return 0;
}

canonical_original_code:
int use_tunnel()
{
 struct fd_set io;
 char buffer[4096];
 while(!quitting)
 {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&io)->fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&io)->fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&io)->fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))));
  memset(buffer, 0, 4096);
  if (select(fd(), &io, ((void *)0), ((void *)0), ((void *)0)) < 0 )
  {
   { log_err(1, L_GENERAL, "tcptunnel.c", 170, "Failed to use selected tcp tunnel. EXITING.\n"); };
   break;
  }
  if (((((&io)->fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.client_socket, buffer, 4096, 0);
   if (count < 0)
   {
    { log_err(1, L_GENERAL, "tcptunnel.c", 179, "Failed to receive on client socket for tcp tunnel. EXITING.\n"); };
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.remote_socket, buffer, count, 0);
  }
  if (((((&io)->fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.remote_socket, buffer, 4096, 0);
   if (count < 0)
   {
    { log_err(1, L_GENERAL, "tcptunnel.c", 204, "Failed to receive on remote socket for tcp tunnel. EXITING.\n"); };
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.client_socket, buffer, count, 0);
  }
 }
 return 0;
}

variable_types:
io
struct fd_set { long fds_bits[-1]; }

variable_types:
buffer
char [4096]

variable_types: count int


decompiled_code:
char *get_current_timestamp()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(date_str_0, 0xFFFuLL, "%a %d %H:%M:%S", v0);
return date_str_0;
}

canonical_decompiled_code:
char *func7()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(date_str_0, 0xFFFuLL, "%a %d %H:%M:%S", v0);
return date_str_0;
}

original_code:
char *get_current_timestamp(void)
{
 static char date_str[4096];
 time_t date;
 time(&date);
 strftime(date_str, 4096 - 1, "%a %d %H:%M:%S", localtime(&date));
 return date_str;
}

canonical_original_code:
char *get_current_timestamp()
{
 static char date_str[4096];
 long date;
 time(&date);
 strftime(date_str, 4096 - 1, "%a %d %H:%M:%S", localtime(&date));
 return date_str;
}

variable_types: date long


original_code:
unsigned long long
monotonic_us(void)
{
 struct timespec ts;
 syscall(228, 1, &ts);
 return ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000;
}

canonical_original_code:
unsigned long long monotonic_us()
{
 struct timespec ts;
 syscall(228, 1, &ts);
 return ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000;
}

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

return_type: unsigned long long


decompiled_code:
__int64 __fastcall read_random_bytes(void *buf, size_t nbytes)
{
int v3; // eax
unsigned int v4; // eax
char *v5; // rbp
__pid_t i; // er12
char *v7; // rbx
__int64 result; // rax
unsigned int v9; // edi
int v10; // ebp

v3 = open64("/dev/urandom", 0);
if ( v3 >= 0 )
{
v10 = v3;
if ( read(v3, buf, nbytes) )
close(v10);
}
v4 = monotonic_us();
v5 = (char *)buf + nbytes;
srand(v4);
for ( i = getpid(); ; i = 0 )
{
v7 = (char *)buf;
do
{
result = (unsigned int)(rand() >> 5);
*v7++ ^= result;
}
while ( v5 != v7 );
if ( !i )
break;
v9 = i;
srand(v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf, size_t nbytes)
{
int v3; // eax
unsigned int v4; // eax
char *v5; // rbp
__pid_t i; // er12
char *v7; // rbx
__int64 result; // rax
unsigned int v9; // edi
int v10; // ebp

v3 = open64("/dev/urandom", 0);
if ( v3 >= 0 )
{
v10 = v3;
if ( read(v3, buf, nbytes) )
close(v10);
}
v4 = func0();
v5 = (char *)buf + nbytes;
srand(v4);
for ( i = getpid(); ; i = 0 )
{
v7 = (char *)buf;
do
{
result = (unsigned int)(rand() >> 5);
*v7++ ^= result;
}
while ( v5 != v7 );
if ( !i )
break;
v9 = i;
srand(v9);
}
return result;
}

original_code:
static void
read_random_bytes(unsigned char *buf, size_t size)
{
 int i;
 pid_t pid;
 i = open("/dev/urandom", 00);
 if(i >= 0)
 {
  if(read(i, buf, size))
  {
   close(i);
  }
 }
 srand(monotonic_us());
 pid = getpid();
 while(1)
 {
  for(i = 0; i < size; i++)
   buf[i] ^= rand() >> 5;
  if(pid == 0)
   break;
  srand(pid);
  pid = 0;
 }
}

canonical_original_code:
static void read_random_bytes(unsigned char *buf, unsigned long size)
{
 int i;
 int pid;
 i = open("/dev/urandom", 00);
 if(i >= 0)
 {
  if(read(i, buf, size))
  {
   close(i);
  }
 }
 srand(monotonic_us());
 pid = getpid();
 while(1)
 {
  for(i = 0; i < size; i++)
   buf[i] ^= rand() >> 5;
  if(pid == 0)
   break;
  srand(pid);
  pid = 0;
 }
}

variable_types:
buf
unsigned char *

variable_types:
size
unsigned long

variable_types: i int

variable_types: pid int


decompiled_code:
__int64 init_clockseq()
{
__int64 result; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

read_random_bytes(buf, 4uLL);
clock_seq_initialized = 1;
result = buf[0] & 0x3FFF;
clock_seq = buf[0] & 0x3FFF;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

func1(buf, 4uLL);
clock_seq_initialized = 1;
result = buf[0] & 0x3FFF;
clock_seq = buf[0] & 0x3FFF;
return result;
}

original_code:
void
init_clockseq(void)
{
 unsigned char buf[4];
 read_random_bytes(buf, 4);
 memcpy(&clock_seq, &buf, sizeof(clock_seq));
 clock_seq &= clock_seq_max;
 clock_seq_initialized = 1;
}

canonical_original_code:
void init_clockseq()
{
 unsigned char buf[4];
 read_random_bytes(buf, 4);
 memcpy(&clock_seq, &buf, sizeof(clock_seq));
 clock_seq &= clock_seq_max;
 clock_seq_initialized = 1;
}

variable_types:
buf
unsigned char [4]


decompiled_code:
__int64 __fastcall generate_uuid(__int64 a1)
{
void *v1; // rbx
_BOOL4 v2; // eax
int v3; // er12
unsigned __int64 v4; // rbx
int v5; // eax
__int64 result; // rax
int v7; // [rsp+Ah] [rbp-2Eh] BYREF
__int16 v8; // [rsp+Eh] [rbp-2Ah]
__int64 v9; // [rsp+10h] [rbp-28h] BYREF
__int64 v10; // [rsp+18h] [rbp-20h]

v1 = (void *)(a1 + 10);
v7 = 0;
v8 = 0;
if ( (unsigned int)getsyshwaddr(&v7, 6LL) )
{
log_err(4LL, 2LL, "uuid.c", 146LL, "Could not find MAC. Use bootid's nodeID.\n");
if ( (unsigned int)read_bootid_node((__int64)v1, 6LL) )
{
log_err(4LL, 2LL, "uuid.c", 149LL, "bootid node not successfully read.\n");
read_random_bytes(v1, 6uLL);
}
}
else
{
*(_DWORD *)(a1 + 10) = v7;
*(_WORD *)(a1 + 14) = v8;
}
v2 = last_node_2 != *(_DWORD *)(a1 + 10) || word_540 != *(_WORD *)(a1 + 14);
v3 = clock_seq_initialized;
if ( !v2 )
{
syscall(228LL, 0LL, &v9);
v4 = (10000000 * v9 + v10 / 100 + 122192928000000000LL) & 0xFFFFFFFFFFFFFFFLL;
if ( v3 )
{
if ( last_time_all_0 < v4 )
{
LOWORD(v5) = clock_seq;
clock_seq_started_1 = clock_seq;
goto LABEL_9;
}
goto LABEL_7;
}
LABEL_10:
init_clockseq();
LOWORD(v5) = clock_seq;
clock_seq_started_1 = clock_seq;
goto LABEL_9;
}
last_node_2 = *(_DWORD *)(a1 + 10);
word_540 = *(_WORD *)(a1 + 14);
syscall(228LL, 0LL, &v9);
v4 = (10000000 * v9 + v10 / 100 + 122192928000000000LL) & 0xFFFFFFFFFFFFFFFLL;
if ( !v3 )
goto LABEL_10;
LABEL_7:
v5 = ((_WORD)clock_seq + 1) & 0x3FFF;
clock_seq = v5;
if ( v5 == clock_seq_started_1 )
{
v5 = ((_WORD)v5 - 1) & 0x3FFF;
clock_seq = v5;
}
LABEL_9:
*(_BYTE *)(a1 + 9) = v5;
*(_DWORD *)a1 = _byteswap_ulong(v4);
last_time_all_0 = v4;
*(_BYTE *)(a1 + 5) = BYTE4(v4);
*(_BYTE *)(a1 + 8) = BYTE1(v5) & 0x3F | 0x80;
result = 0LL;
*(_BYTE *)(a1 + 4) = BYTE5(v4);
*(_BYTE *)(a1 + 6) = HIBYTE(v4) | 0x10;
*(_BYTE *)(a1 + 7) = BYTE6(v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
void *v1; // rbx
_BOOL4 v2; // eax
int v3; // er12
unsigned __int64 v4; // rbx
int v5; // eax
__int64 result; // rax
int v7; // [rsp+Ah] [rbp-2Eh] BYREF
__int16 v8; // [rsp+Eh] [rbp-2Ah]
__int64 v9; // [rsp+10h] [rbp-28h] BYREF
__int64 v10; // [rsp+18h] [rbp-20h]

v1 = (void *)(a1 + 10);
v7 = 0;
v8 = 0;
if ( (unsigned int)getsyshwaddr(&v7, 6LL) )
{
log_err(4LL, 2LL, "uuid.c", 146LL, "Could not find MAC. Use bootid's nodeID.\n");
if ( (unsigned int)func2((__int64)v1, 6LL) )
{
log_err(4LL, 2LL, "uuid.c", 149LL, "bootid node not successfully read.\n");
func1(v1, 6uLL);
}
}
else
{
*(_DWORD *)(a1 + 10) = v7;
*(_WORD *)(a1 + 14) = v8;
}
v2 = last_node_2 != *(_DWORD *)(a1 + 10) || word_540 != *(_WORD *)(a1 + 14);
v3 = clock_seq_initialized;
if ( !v2 )
{
syscall(228LL, 0LL, &v9);
v4 = (10000000 * v9 + v10 / 100 + 122192928000000000LL) & 0xFFFFFFFFFFFFFFFLL;
if ( v3 )
{
if ( last_time_all_0 < v4 )
{
LOWORD(v5) = clock_seq;
clock_seq_started_1 = clock_seq;
goto LABEL_9;
}
goto LABEL_7;
}
LABEL_10:
func3();
LOWORD(v5) = clock_seq;
clock_seq_started_1 = clock_seq;
goto LABEL_9;
}
last_node_2 = *(_DWORD *)(a1 + 10);
word_540 = *(_WORD *)(a1 + 14);
syscall(228LL, 0LL, &v9);
v4 = (10000000 * v9 + v10 / 100 + 122192928000000000LL) & 0xFFFFFFFFFFFFFFFLL;
if ( !v3 )
goto LABEL_10;
LABEL_7:
v5 = ((_WORD)clock_seq + 1) & 0x3FFF;
clock_seq = v5;
if ( v5 == clock_seq_started_1 )
{
v5 = ((_WORD)v5 - 1) & 0x3FFF;
clock_seq = v5;
}
LABEL_9:
*(_BYTE *)(a1 + 9) = v5;
*(_DWORD *)a1 = _byteswap_ulong(v4);
last_time_all_0 = v4;
*(_BYTE *)(a1 + 5) = BYTE4(v4);
*(_BYTE *)(a1 + 8) = BYTE1(v5) & 0x3F | 0x80;
result = 0LL;
*(_BYTE *)(a1 + 4) = BYTE5(v4);
*(_BYTE *)(a1 + 6) = HIBYTE(v4) | 0x10;
*(_BYTE *)(a1 + 7) = BYTE6(v4);
return result;
}

original_code:
int
generate_uuid(unsigned char uuid_out[16])
{
 static u_int64_t last_time_all;
 static unsigned int clock_seq_started;
 static char last_node[6] = { 0, 0, 0, 0, 0, 0 };
 struct timespec ts;
 u_int64_t time_all;
 int inc_clock_seq = 0;
 unsigned char mac[6];
 int mac_error;
 memset(&mac, '\0', sizeof(mac));
 mac_error = getsyshwaddr((char *)mac, sizeof(mac));
 if(!mac_error)
 {
  memcpy(&uuid_out[10], mac, 6);
 }
 else
 {
  { log_err(4, L_HTTP, "uuid.c", 146, "Could not find MAC.  Use bootid's nodeID.\n"); };
  if( read_bootid_node(&uuid_out[10], 6) != 0)
  {
   { log_err(4, L_HTTP, "uuid.c", 149, "bootid node not successfully read.\n"); };
   read_random_bytes(&uuid_out[10], 6);
  }
 }
 if(memcmp(last_node, uuid_out+10, 6) != 0)
 {
  inc_clock_seq = 1;
  memcpy(last_node, uuid_out+10, 6);
 }
 syscall(228, 0, &ts);
 time_all = ((u_int64_t)ts.tv_sec) * (1000000000L / 100);
 time_all += ts.tv_nsec / 100;
 time_all += 12219292800000ULL * (1000000L / 100);
 time_all &= 0x0fffffffffffffffULL;
 if(!clock_seq_initialized)
 {
  init_clockseq();
  clock_seq_started = clock_seq;
 }
 else
 {
  if(inc_clock_seq || time_all <= last_time_all)
  {
   clock_seq = (clock_seq + 1) & clock_seq_max;
   if(clock_seq == clock_seq_started)
   {
    clock_seq = (clock_seq - 1) & clock_seq_max;
   }
  }
  else
   clock_seq_started = clock_seq;
 }
 last_time_all = time_all;
 uuid_out[3] = (u_int8_t)time_all;
 uuid_out[2] = (u_int8_t)(time_all >> 8);
 uuid_out[1] = (u_int8_t)(time_all >> 16);
 uuid_out[0] = (u_int8_t)(time_all >> 24);
 uuid_out[5] = (u_int8_t)(time_all >> 32);
 uuid_out[4] = (u_int8_t)(time_all >> 40);
 uuid_out[7] = (u_int8_t)(time_all >> 48);
 uuid_out[6] = (u_int8_t)(time_all >> 56);
 uuid_out[8] = clock_seq >> 8;
 uuid_out[9] = clock_seq & 0xff;
 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x10;
 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;
 return 0;
}

canonical_original_code:
int generate_uuid(unsigned char uuid_out[16])
{
 static unsigned int last_time_all;
 static unsigned int clock_seq_started;
 static char last_node[6] = { 0, 0, 0, 0, 0, 0 };
 struct timespec ts;
 unsigned int time_all;
 int inc_clock_seq = 0;
 unsigned char mac[6];
 int mac_error;
 memset(&mac, '\0', sizeof(mac));
 mac_error = getsyshwaddr((char *)mac, sizeof(mac));
 if(!mac_error)
 {
  memcpy(&uuid_out[10], mac, 6);
 }
 else
 {
  { log_err(4, L_HTTP, "uuid.c", 146, "Could not find MAC.  Use bootid's nodeID.\n"); };
  if( read_bootid_node(&uuid_out[10], 6) != 0)
  {
   { log_err(4, L_HTTP, "uuid.c", 149, "bootid node not successfully read.\n"); };
   read_random_bytes(&uuid_out[10], 6);
  }
 }
 if(memcmp(last_node, uuid_out+10, 6) != 0)
 {
  inc_clock_seq = 1;
  memcpy(last_node, uuid_out+10, 6);
 }
 syscall(228, 0, &ts);
 time_all = ((unsigned int)ts.tv_sec) * (1000000000L / 100);
 time_all += ts.tv_nsec / 100;
 time_all += 12219292800000ULL * (1000000L / 100);
 time_all &= 0x0fffffffffffffffULL;
 if(!clock_seq_initialized)
 {
  init_clockseq();
  clock_seq_started = clock_seq;
 }
 else
 {
  if(inc_clock_seq || time_all <= last_time_all)
  {
   clock_seq = (clock_seq + 1) & clock_seq_max;
   if(clock_seq == clock_seq_started)
   {
    clock_seq = (clock_seq - 1) & clock_seq_max;
   }
  }
  else
   clock_seq_started = clock_seq;
 }
 last_time_all = time_all;
 uuid_out[3] = (unsigned int)time_all;
 uuid_out[2] = (u_int8_t)(time_all >> 8);
 uuid_out[1] = (u_int8_t)(time_all >> 16);
 uuid_out[0] = (u_int8_t)(time_all >> 24);
 uuid_out[5] = (u_int8_t)(time_all >> 32);
 uuid_out[4] = (u_int8_t)(time_all >> 40);
 uuid_out[7] = (u_int8_t)(time_all >> 48);
 uuid_out[6] = (u_int8_t)(time_all >> 56);
 uuid_out[8] = clock_seq >> 8;
 uuid_out[9] = clock_seq & 0xff;
 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x10;
 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;
 return 0;
}

variable_types:
mac
unsigned char [6]

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


decompiled_code:
__int64 __fastcall get_uuid_string(char *s)
{
unsigned int v1; // er12
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

if ( (unsigned int)generate_uuid((__int64)v3) )
return (unsigned int)-1;
v1 = 0;
sprintf(
s,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(unsigned __int8)v3[0],
(unsigned __int8)v3[1],
(unsigned __int8)v3[2],
(unsigned __int8)v3[3],
(unsigned __int8)v3[4],
(unsigned __int8)v3[5],
(unsigned __int8)v3[6],
(unsigned __int8)v3[7],
(unsigned __int8)v3[8],
(unsigned __int8)v3[9],
(unsigned __int8)v3[10],
(unsigned __int8)v3[11],
(unsigned __int8)v3[12],
(unsigned __int8)v3[13],
(unsigned __int8)v3[14],
(unsigned __int8)v3[15]);
s[36] = 0;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s)
{
unsigned int v1; // er12
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

if ( (unsigned int)func4((__int64)v3) )
return (unsigned int)-1;
v1 = 0;
sprintf(
s,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(unsigned __int8)v3[0],
(unsigned __int8)v3[1],
(unsigned __int8)v3[2],
(unsigned __int8)v3[3],
(unsigned __int8)v3[4],
(unsigned __int8)v3[5],
(unsigned __int8)v3[6],
(unsigned __int8)v3[7],
(unsigned __int8)v3[8],
(unsigned __int8)v3[9],
(unsigned __int8)v3[10],
(unsigned __int8)v3[11],
(unsigned __int8)v3[12],
(unsigned __int8)v3[13],
(unsigned __int8)v3[14],
(unsigned __int8)v3[15]);
s[36] = 0;
return v1;
}

variable_types:
buf
char *

variable_types:
uuid
unsigned char [16]