main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
void *v4; // r13
void *v5; // r12
const char *v7; // rsi
int v8; // eax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
__pid_t v13; // eax
int v14; // eax
const char *v16; // r15
size_t v17; // r14
const char *v18; // r15
size_t v19; // r14
struct option v20; // [rsp+0h] [rbp-D8h] BYREF
const char *v21; // [rsp+20h] [rbp-B8h]
int v22; // [rsp+28h] [rbp-B0h]
__int64 v23; // [rsp+30h] [rbp-A8h]
int v24; // [rsp+38h] [rbp-A0h]
const char *v25; // [rsp+40h] [rbp-98h]
int v26; // [rsp+48h] [rbp-90h]
__int64 v27; // [rsp+50h] [rbp-88h]
int v28; // [rsp+58h] [rbp-80h]
const char *v29; // [rsp+60h] [rbp-78h]
int v30; // [rsp+68h] [rbp-70h]
__int64 v31; // [rsp+70h] [rbp-68h]
int v32; // [rsp+78h] [rbp-60h]
__int64 v33; // [rsp+80h] [rbp-58h]
int v34; // [rsp+88h] [rbp-50h]
__int64 v35; // [rsp+90h] [rbp-48h]
int v36; // [rsp+98h] [rbp-40h]

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v20.name = "conffile";
v20.has_arg = 1;
v20.flag = 0LL;
v20.val = 99;
v21 = "foreground";
v22 = 0;
v23 = 0LL;
v24 = 102;
v25 = "help";
v26 = 0;
v27 = 0LL;
v28 = 104;
v29 = "logfile";
v30 = 1;
v31 = 0LL;
v32 = 108;
v33 = 0LL;
v34 = 0;
v35 = 0LL;
v36 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v7 = (const char *)argv;
v8 = getopt_long(argc, (char *const *)argv, "c:fhl:", &v20, 0LL);
if ( v8 != 102 )
break;
v3 = 1;
}
if ( v8 <= 102 )
break;
if ( v8 != 108 )
LABEL_55:
usage(*argv);
v4 = strdup(optarg);
}
if ( v8 == -1 )
break;
if ( v8 != 99 )
goto LABEL_55;
v5 = strdup(optarg);
}
if ( v3 )
{
log_fp = stdout;
if ( !v4 )
{
LABEL_7:
if ( !v5 )
{
v16 = *argv;
v17 = strlen(*argv) + 6;
v5 = malloc(v17);
memset(v5, 0, v17);
v7 = "%s.conf";
sprintf((char *)v5, "%s.conf", v16);
}
if ( (unsigned int)parse_config_file((const char *)v5) )
{
v3 = 1;
fwrite("ERROR: parsing config file failed.\n", 1uLL, 0x23uLL, log_fp);
}
else if ( (unsigned int)set_defaults(
v5,
v7,
v9,
v10,
v11,
v12,
v20.name,
v20.has_arg,
v20.flag,
v20.val,
v21,
v22,
v23,
v24,
v25,
v26,
v27,
v28,
v29,
v30) )
{
v3 = 1;
fwrite("ERROR: unable to set defaults.\n", 1uLL, 0x1FuLL, log_fp);
}
else if ( (unsigned int)check_valid_config() )
{
v3 = 1;
fwrite("ERROR: bad config file.\n", 1uLL, 0x18uLL, log_fp);
}
else if ( (unsigned int)logger_init((const char *)levels) )
{
v3 = 1;
fwrite("ERROR: unable initialize logger.\n", 1uLL, 0x21uLL, log_fp);
}
else if ( (unsigned int)http_init() )
{
v3 = 1;
logger(1u, "ERROR: http_init failed.\n");
}
else
{
v3 = sql_init();
if ( v3 )
{
v3 = 1;
logger(1u, "ERROR: sql_init failed.\n");
}
else
{
while ( !terminate )
;
}
}
sql_fin();
http_fin();
fflush(log_fp);
if ( log_fp != stdout )
{
v14 = fileno(log_fp);
fsync(v14);
fclose(log_fp);
}
if ( v4 )
free(v4);
free(v5);
if ( host )
free(host);
if ( name )
free(name);
if ( passwd )
free(passwd);
if ( user )
free(user);
if ( ptr )
free(ptr);
if ( port )
free(port);
return v3;
}
LABEL_28:
v7 = "a";
log_fp = fopen((const char *)v4, "a");
if ( !log_fp )
{
v3 = 1;
printf("ERROR: Unable to open log file: %s\n", (const char *)v4);
return v3;
}
goto LABEL_7;
}
v13 = fork();
if ( v13 < 0 )
{
v3 = 1;
puts("Unable to background as daemon process.");
return v3;
}
if ( !v13 )
{
umask(0);
if ( setsid() == -1 )
{
v3 = 1;
puts("Unable to create new session for child process.");
return v3;
}
fclose(stdin);
fclose(stdout);
fclose(stderr);
signal(17, (__sighandler_t)((char *)strip_comments + 1));
signal(13, (__sighandler_t)((char *)strip_comments + 1));
signal(1, signal_handler);
signal(2, signal_handler);
signal(3, signal_handler);
signal(15, signal_handler);
if ( !v4 )
{
v18 = *argv;
v19 = strlen(*argv) + 5;
v4 = malloc(v19);
memset(v4, 0, v19);
sprintf((char *)v4, "%s.log", v18);
}
log_fp = stdout;
goto LABEL_28;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
void *v4; // r13
void *v5; // r12
const char *v7; // rsi
int v8; // eax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
__pid_t v13; // eax
int v14; // eax
const char *v16; // r15
size_t v17; // r14
const char *v18; // r15
size_t v19; // r14
struct option v20; // [rsp+0h] [rbp-D8h] BYREF
const char *v21; // [rsp+20h] [rbp-B8h]
int v22; // [rsp+28h] [rbp-B0h]
__int64 v23; // [rsp+30h] [rbp-A8h]
int v24; // [rsp+38h] [rbp-A0h]
const char *v25; // [rsp+40h] [rbp-98h]
int v26; // [rsp+48h] [rbp-90h]
__int64 v27; // [rsp+50h] [rbp-88h]
int v28; // [rsp+58h] [rbp-80h]
const char *v29; // [rsp+60h] [rbp-78h]
int v30; // [rsp+68h] [rbp-70h]
__int64 v31; // [rsp+70h] [rbp-68h]
int v32; // [rsp+78h] [rbp-60h]
__int64 v33; // [rsp+80h] [rbp-58h]
int v34; // [rsp+88h] [rbp-50h]
__int64 v35; // [rsp+90h] [rbp-48h]
int v36; // [rsp+98h] [rbp-40h]

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v20.name = "conffile";
v20.has_arg = 1;
v20.flag = 0LL;
v20.val = 99;
v21 = "foreground";
v22 = 0;
v23 = 0LL;
v24 = 102;
v25 = "help";
v26 = 0;
v27 = 0LL;
v28 = 104;
v29 = "logfile";
v30 = 1;
v31 = 0LL;
v32 = 108;
v33 = 0LL;
v34 = 0;
v35 = 0LL;
v36 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v7 = (const char *)argv;
v8 = getopt_long(argc, (char *const *)argv, "c:fhl:", &v20, 0LL);
if ( v8 != 102 )
break;
v3 = 1;
}
if ( v8 <= 102 )
break;
if ( v8 != 108 )
LABEL_55:
func2(*argv);
v4 = strdup(optarg);
}
if ( v8 == -1 )
break;
if ( v8 != 99 )
goto LABEL_55;
v5 = strdup(optarg);
}
if ( v3 )
{
log_fp = stdout;
if ( !v4 )
{
LABEL_7:
if ( !v5 )
{
v16 = *argv;
v17 = strlen(*argv) + 6;
v5 = malloc(v17);
memset(v5, 0, v17);
v7 = "%s.conf";
sprintf((char *)v5, "%s.conf", v16);
}
if ( (unsigned int)func4((const char *)v5) )
{
v3 = 1;
fwrite("ERROR: parsing config file failed.\n", 1uLL, 0x23uLL, log_fp);
}
else if ( (unsigned int)func0(
v5,
v7,
v9,
v10,
v11,
v12,
v20.name,
v20.has_arg,
v20.flag,
v20.val,
v21,
v22,
v23,
v24,
v25,
v26,
v27,
v28,
v29,
v30) )
{
v3 = 1;
fwrite("ERROR: unable to set defaults.\n", 1uLL, 0x1FuLL, log_fp);
}
else if ( (unsigned int)func1() )
{
v3 = 1;
fwrite("ERROR: bad config file.\n", 1uLL, 0x18uLL, log_fp);
}
else if ( (unsigned int)func5((const char *)levels) )
{
v3 = 1;
fwrite("ERROR: unable initialize logger.\n", 1uLL, 0x21uLL, log_fp);
}
else if ( (unsigned int)http_init() )
{
v3 = 1;
func6(1u, "ERROR: http_init failed.\n");
}
else
{
v3 = sql_init();
if ( v3 )
{
v3 = 1;
func6(1u, "ERROR: sql_init failed.\n");
}
else
{
while ( !terminate )
;
}
}
sql_fin();
http_fin();
fflush(log_fp);
if ( log_fp != stdout )
{
v14 = fileno(log_fp);
fsync(v14);
fclose(log_fp);
}
if ( v4 )
free(v4);
free(v5);
if ( host )
free(host);
if ( name )
free(name);
if ( passwd )
free(passwd);
if ( user )
free(user);
if ( ptr )
free(ptr);
if ( port )
free(port);
return v3;
}
LABEL_28:
v7 = "a";
log_fp = fopen((const char *)v4, "a");
if ( !log_fp )
{
v3 = 1;
printf("ERROR: Unable to open log file: %s\n", (const char *)v4);
return v3;
}
goto LABEL_7;
}
v13 = fork();
if ( v13 < 0 )
{
v3 = 1;
puts("Unable to background as daemon process.");
return v3;
}
if ( !v13 )
{
umask(0);
if ( setsid() == -1 )
{
v3 = 1;
puts("Unable to create new session for child process.");
return v3;
}
fclose(stdin);
fclose(stdout);
fclose(stderr);
signal(17, (__sighandler_t)((char *)strip_comments + 1));
signal(13, (__sighandler_t)((char *)strip_comments + 1));
signal(1, signal_handler);
signal(2, signal_handler);
signal(3, signal_handler);
signal(15, signal_handler);
if ( !v4 )
{
v18 = *argv;
v19 = strlen(*argv) + 5;
v4 = malloc(v19);
memset(v4, 0, v19);
sprintf((char *)v4, "%s.log", v18);
}
log_fp = stdout;
goto LABEL_28;
}
return v3;
}

original_code:
int
main (int argc, char *argv[])
{
 int c = 0;
 char *conffile = ((void *)0);
 int fg = 0;
 char *logfile = ((void *)0);
 struct option opts[] = {
  {.name = "conffile", .has_arg = 1, .flag = ((void *)0), .val = 'c'},
  {.name = "foreground", .has_arg = 0, .flag = ((void *)0), .val = 'f'},
  {.name = "help", .has_arg = 0, .flag = ((void *)0), .val = 'h'},
  {.name = "logfile", .has_arg = 1, .flag = ((void *)0), .val = 'l'},
  {.name = ((void *)0), .has_arg = 0, .flag = ((void *)0), .val = 0}
 };
 pid_t pid;
 int retval = 0;
 while (c != (-1)) {
  c = getopt_long (argc, argv, "c:fhl:", opts, ((void *)0));
  switch (c) {
   case (-1):
    break;
   case 'c':
    conffile = strdup (optarg);
    break;
   case 'f':
    fg = 1;
    break;
   case 'l':
    logfile = strdup (optarg);
    break;
   case '?':
   case 'h':
   default:
    usage (argv[0]);
  }
 }
 if (fg == 0) {
  pid = fork ();
  if (pid < 0) {
   printf ("Unable to background as daemon process.\n");
   return 1;
  }
  if (pid > 0)
   return 0;
  umask (0);
  if (setsid () == (pid_t) -1) {
   printf ("Unable to create new session for child "
     "process.\n");
   return 1;
  }
  fclose (stdin);
  fclose (stdout);
  fclose (stderr);
  signal (17, ((__sighandler_t) 1));
  signal (13, ((__sighandler_t) 1));
  signal (1, signal_handler);
  signal (2, signal_handler);
  signal (3, signal_handler);
  signal (15, signal_handler);
  if (logfile == ((void *)0)) {
   logfile = (char *) malloc (sizeof (char)
     * (strlen (argv[0]) + 5));
   memset (logfile, 0, sizeof (char)
     * (strlen (argv[0]) + 5));
   sprintf (logfile, "%s.log", argv[0]);
  }
 }
 log_fp = stdout;
 if (logfile != ((void *)0)) {
  log_fp = fopen (logfile, "a");
  if (log_fp == ((void *)0)) {
   printf ("ERROR: Unable to open log file: %s\n",
     logfile);
   return 1;
  }
 }
 if (conffile == ((void *)0)) {
  conffile = (char *) malloc (sizeof (char)
    * (strlen (argv[0]) + 6));
  memset (conffile, 0, sizeof (char) * (strlen (argv[0]) + 6));
  sprintf (conffile, "%s.conf", argv[0]);
 }
 if (parse_config_file (conffile) != 0) {
  fprintf (log_fp, "ERROR: parsing config file failed.\n");
  retval = 1;
  goto cleanup;
 }
 if (set_defaults () != 0) {
  fprintf (log_fp, "ERROR: unable to set defaults.\n");
  retval = 1;
  goto cleanup;
 }
 if (check_valid_config () != 0) {
  fprintf (log_fp, "ERROR: bad config file.\n");
  retval = 1;
  goto cleanup;
 }
 if (logger_init (levels) != 0) {
  fprintf (log_fp, "ERROR: unable initialize logger.\n");
  retval = 1;
  goto cleanup;
 }
 if (http_init () != 0) {
  logger (LOG_ERR, "ERROR: http_init failed.\n");
  retval = 1;
  goto cleanup;
 }
 if (sql_init () != 0) {
  logger (LOG_ERR, "ERROR: sql_init failed.\n");
  retval = 1;
  goto cleanup;
 }
 while (terminate == 0);
cleanup:
 sql_fin ();
 http_fin ();
 fflush (log_fp);
 if (log_fp != stdout) {
  fsync (fileno (log_fp));
  fclose (log_fp);
 }
 if (logfile != ((void *)0))
  free (logfile);
 if (conffile != ((void *)0))
  free (conffile);
 if (host != ((void *)0))
  free (host);
 if (name != ((void *)0))
  free (name);
 if (passwd != ((void *)0))
  free (passwd);
 if (user != ((void *)0))
  free (user);
 if (ip != ((void *)0))
  free (ip);
 if (port != ((void *)0))
  free (port);
 return retval;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int c = 0;
 char *conffile = ((void *)0);
 int fg = 0;
 char *logfile = ((void *)0);
 struct option opts[] = {
  {.name = "conffile", .has_arg = 1, .flag = ((void *)0), .val = 'c'},
  {.name = "foreground", .has_arg = 0, .flag = ((void *)0), .val = 'f'},
  {.name = "help", .has_arg = 0, .flag = ((void *)0), .val = 'h'},
  {.name = "logfile", .has_arg = 1, .flag = ((void *)0), .val = 'l'},
  {.name = ((void *)0), .has_arg = 0, .flag = ((void *)0), .val = 0}
 };
 int pid;
 int retval = 0;
 while (c != (-1)) {
  c = getopt_long (argc, argv, "c:fhl:", opts, ((void *)0));
  switch (c) {
   case (-1):
    break;
   case 'c':
    conffile = strdup (optarg);
    break;
   case 'f':
    fg = 1;
    break;
   case 'l':
    logfile = strdup (optarg);
    break;
   case '?':
   case 'h':
   default:
    usage (argv[0]);
  }
 }
 if (fg == 0) {
  pid = fork ();
  if (pid < 0) {
   printf ("Unable to background as daemon process.\n");
   return 1;
  }
  if (pid > 0)
   return 0;
  umask (0);
  if (setsid () == (pid_t) -1) {
   printf ("Unable to create new session for child "
     "process.\n");
   return 1;
  }
  fclose (stdin);
  fclose (stdout);
  fclose (stderr);
  signal (17, ((void (*)(int)) 1));
  signal (13, ((void (*)(int)) 1));
  signal (1, signal_handler);
  signal (2, signal_handler);
  signal (3, signal_handler);
  signal (15, signal_handler);
  if (logfile == ((void *)0)) {
   logfile = (char *) malloc (sizeof (char)
     * (strlen (argv[0]) + 5));
   memset (logfile, 0, sizeof (char)
     * (strlen (argv[0]) + 5));
   sprintf (logfile, "%s.log", argv[0]);
  }
 }
 log_fp = stdout;
 if (logfile != ((void *)0)) {
  log_fp = fopen (logfile, "a");
  if (log_fp == ((void *)0)) {
   printf ("ERROR: Unable to open log file: %s\n",
     logfile);
   return 1;
  }
 }
 if (conffile == ((void *)0)) {
  conffile = (char *) malloc (sizeof (char)
    * (strlen (argv[0]) + 6));
  memset (conffile, 0, sizeof (char) * (strlen (argv[0]) + 6));
  sprintf (conffile, "%s.conf", argv[0]);
 }
 if (parse_config_file (conffile) != 0) {
  fprintf (log_fp, "ERROR: parsing config file failed.\n");
  retval = 1;
  goto cleanup;
 }
 if (set_defaults () != 0) {
  fprintf (log_fp, "ERROR: unable to set defaults.\n");
  retval = 1;
  goto cleanup;
 }
 if (check_valid_config () != 0) {
  fprintf (log_fp, "ERROR: bad config file.\n");
  retval = 1;
  goto cleanup;
 }
 if (logger_init (levels) != 0) {
  fprintf (log_fp, "ERROR: unable initialize logger.\n");
  retval = 1;
  goto cleanup;
 }
 if (http_init () != 0) {
  logger (LOG_ERR, "ERROR: http_init failed.\n");
  retval = 1;
  goto cleanup;
 }
 if (sql_init () != 0) {
  logger (LOG_ERR, "ERROR: sql_init failed.\n");
  retval = 1;
  goto cleanup;
 }
 while (terminate == 0);
cleanup:
 sql_fin ();
 http_fin ();
 fflush (log_fp);
 if (log_fp != stdout) {
  fsync (fileno (log_fp));
  fclose (log_fp);
 }
 if (logfile != ((void *)0))
  free (logfile);
 if (conffile != ((void *)0))
  free (conffile);
 if (host != ((void *)0))
  free (host);
 if (name != ((void *)0))
  free (name);
 if (passwd != ((void *)0))
  free (passwd);
 if (user != ((void *)0))
  free (user);
 if (ip != ((void *)0))
  free (ip);
 if (port != ((void *)0))
  free (port);
 return retval;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
conffile
char *

variable_types: fg int

variable_types:
logfile
char *

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

variable_types: pid int

variable_types: retval int


repo: krosswindz/tmst

decompiled_code:
void __fastcall free_benc_data(_QWORD *a1)
{
__int64 v2; // rbx
_QWORD *v3; // r8
__int64 v4; // rbx
char *v5; // rax
char *v6; // rdi
__int64 v7; // r12
__int64 v8; // rdi

if ( a1 )
{
LODWORD(v2) = *(_DWORD *)a1;
if ( *(_DWORD *)a1 != 2 )
{
if ( (_DWORD)v2 == 3 )
{
v6 = (char *)a1[1];
if ( !v6 )
goto LABEL_16;
}
else
{
if ( (_DWORD)v2 )
goto LABEL_16;
v5 = (char *)a1[1];
if ( !v5 )
goto LABEL_16;
v6 = (char *)a1[1];
if ( *((_QWORD *)v5 + 1) )
{
v7 = 0LL;
do
{
free(*(void **)v5);
v8 = *(_QWORD *)(a1[1] + v7 + 8);
v2 = (unsigned int)(v2 + 1);
v7 = 16 * v2;
free_benc_data(v8);
v6 = (char *)a1[1];
v5 = &v6[16 * v2];
}
while ( *((_QWORD *)v5 + 1) );
}
}
free(v6);
LABEL_16:
free(a1);
return;
}
v3 = (_QWORD *)a1[1];
if ( !v3 )
goto LABEL_16;
if ( *v3 )
{
LODWORD(v4) = 0;
do
{
((void (*)(void))free_benc_data)();
v3 = (_QWORD *)a1[1];
v4 = (unsigned int)(v4 + 1);
}
while ( v3[v4] );
}
free(v3);
free(a1);
}
}

original_code:
static inline void
free_benc_data (benc_data_t *bd)
{
 uint32_t i;
 if (bd == ((void *)0))
  return;
 switch (bd->type) {
  case BENC_TYPE_DCT:
   if (bd->data.d == ((void *)0))
    break;
   for (i = 0; bd->data.d[i].val; i++) {
    free (bd->data.d[i].key);
    free_benc_data (bd->data.d[i].val);
   }
   free (bd->data.d);
   break;
  case BENC_TYPE_INT:
   break;
  case BENC_TYPE_LST:
   if (bd->data.l == ((void *)0))
    break;
   for (i = 0; bd->data.l[i]; i++)
    free_benc_data (bd->data.l[i]);
   free (bd->data.l);
   break;
  case BENC_TYPE_STR:
   if (bd->data.s)
    free (bd->data.s);
   break;
  default:
   break;
 }
 free (bd);
 return;
}

canonical_original_code:
static inline void free_benc_data(struct __benc_data_type *bd)
{
 unsigned int i;
 if (bd == ((void *)0))
  return;
 switch (bd->type) {
  case BENC_TYPE_DCT:
   if (bd->data.d == ((void *)0))
    break;
   for (i = 0; bd->data.d[i].val; i++) {
    free (bd->data.d[i].key);
    free_benc_data (bd->data.d[i].val);
   }
   free (bd->data.d);
   break;
  case BENC_TYPE_INT:
   break;
  case BENC_TYPE_LST:
   if (bd->data.l == ((void *)0))
    break;
   for (i = 0; bd->data.l[i]; i++)
    free_benc_data (bd->data.l[i]);
   free (bd->data.l);
   break;
  case BENC_TYPE_STR:
   if (bd->data.s)
    free (bd->data.s);
   break;
  default:
   break;
 }
 free (bd);
 return;
}

variable_types: struct __benc_data_type { enum BENC_TYPE { BENC_TYPE_DCT=0, BENC_TYPE_INT=1, BENC_TYPE_LST=2, BENC_TYPE_STR=3 } type; union { struct __benc_dict_type { char *key; struct __benc_data_type *val; } *d; long i; struct __benc_data_type **l; char *s; } data; } *

variable_types:
i
unsigned int

return_type: void

user_defined_types: struct __benc_data_type { enum BENC_TYPE type; union { struct __benc_dict_type *d; long i; struct __benc_data_type **l; char *s; } data; }


decompiled_code:
char *__fastcall bencode_str(char *s)
{
__int64 v1; // rax
const char *v2; // rax
char *v3; // r12
size_t v4; // r14
size_t v5; // rax
char *v6; // rax
char *v7; // r14

v1 = strlen(s);
v2 = (const char *)lltostr_constprop_0(v1);
if ( !v2 )
return 0LL;
v3 = (char *)v2;
v4 = strlen(v2);
v5 = strlen(s);
v6 = (char *)malloc(v4 + v5 + 2);
v7 = v6;
if ( v6 )
sprintf(v6, "%s:%s", v3, s);
else
free(v3);
return v7;
}

canonical_decompiled_code:
char *__fastcall func3(char *s)
{
__int64 v1; // rax
const char *v2; // rax
char *v3; // r12
size_t v4; // r14
size_t v5; // rax
char *v6; // rax
char *v7; // r14

v1 = strlen(s);
v2 = (const char *)func2(v1);
if ( !v2 )
return 0LL;
v3 = (char *)v2;
v4 = strlen(v2);
v5 = strlen(s);
v6 = (char *)malloc(v4 + v5 + 2);
v7 = v6;
if ( v6 )
sprintf(v6, "%s:%s", v3, s);
else
free(v3);
return v7;
}

original_code:
static inline char *
bencode_str (char *s)
{
 char *len = ((void *)0), *str = ((void *)0);
 len = lltostr ((int64_t) strlen (s), BASE_DEC);
 if (len == ((void *)0))
  return ((void *)0);
 str = (char *) malloc (sizeof (char) * (strlen (len) + strlen (s) + 2));
 if (str == ((void *)0)) {
  free (len);
  return ((void *)0);
 }
 sprintf (str, "%s:%s", len, s);
 return str;
}

canonical_original_code:
static inline char *bencode_str(char *s)
{
 char *len = ((void *)0); char *str = ((void *)0);
 len = lltostr ((long) strlen (s), BASE_DEC);
 if (len == ((void *)0))
  return ((void *)0);
 str = (char *) malloc (sizeof (char) * (strlen (len) + strlen (s) + 2));
 if (str == ((void *)0)) {
  free (len);
  return ((void *)0);
 }
 sprintf (str, "%s:%s", len, s);
 return str;
}

variable_types:
s
char *

variable_types:
len
char *

variable_types:
str
char *

return_type: char *


decompiled_code:
char *__fastcall bencode_int(__int64 a1)
{
const char *v1; // rax
char *v2; // r12
size_t v3; // rax
char *v4; // rax
char *v5; // r13

v1 = (const char *)lltostr_constprop_0(a1);
if ( !v1 )
return 0LL;
v2 = (char *)v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 3);
v5 = v4;
if ( v4 )
sprintf(v4, "i%se", v2);
else
free(v2);
return v5;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
const char *v1; // rax
char *v2; // r12
size_t v3; // rax
char *v4; // rax
char *v5; // r13

v1 = (const char *)func2(a1);
if ( !v1 )
return 0LL;
v2 = (char *)v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 3);
v5 = v4;
if ( v4 )
sprintf(v4, "i%se", v2);
else
free(v2);
return v5;
}

original_code:
static inline char *
bencode_int (int64_t i)
{
 char *str = ((void *)0), *tmp = ((void *)0);
 tmp = lltostr (i, BASE_DEC);
 if (tmp == ((void *)0))
  return ((void *)0);
 str = (char *) malloc (sizeof (char) * (strlen (tmp) + 3));
 if (str == ((void *)0)) {
  free (tmp);
  return ((void *)0);
 }
 sprintf (str, "i%se", tmp);
 return str;
}

canonical_original_code:
static inline char *bencode_int(long i)
{
 char *str = ((void *)0); char *tmp = ((void *)0);
 tmp = lltostr (i, BASE_DEC);
 if (tmp == ((void *)0))
  return ((void *)0);
 str = (char *) malloc (sizeof (char) * (strlen (tmp) + 3));
 if (str == ((void *)0)) {
  free (tmp);
  return ((void *)0);
 }
 sprintf (str, "i%se", tmp);
 return str;
}

variable_types: i long

variable_types:
tmp
char *


decompiled_code:
char *__fastcall benc_encode(__int64 a1)
{
unsigned int v1; // eax
char *result; // rax

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 2 )
return (char *)bencode_lst(*(_QWORD *)(a1 + 8));
if ( v1 > 2 )
{
if ( v1 == 3 )
return bencode_str(*(char **)(a1 + 8));
return 0LL;
}
if ( v1 )
result = bencode_int(*(_QWORD *)(a1 + 8));
else
result = (char *)bencode_dct(*(_QWORD *)(a1 + 8));
return result;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
unsigned int v1; // eax
char *result; // rax

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 2 )
return (char *)func7(*(_QWORD *)(a1 + 8));
if ( v1 > 2 )
{
if ( v1 == 3 )
return func3(*(char **)(a1 + 8));
return 0LL;
}
if ( v1 )
result = func4(*(_QWORD *)(a1 + 8));
else
result = (char *)func6(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
static inline char *
benc_encode (benc_data_t *bd)
{
 char *benc_str = ((void *)0);
 if (bd == ((void *)0))
  return ((void *)0);
 switch (bd->type) {
  case BENC_TYPE_DCT:
   benc_str = bencode_dct (bd->data.d);
   break;
  case BENC_TYPE_INT:
   benc_str = bencode_int (bd->data.i);
   break;
  case BENC_TYPE_LST:
   benc_str = bencode_lst (bd->data.l);
   break;
  case BENC_TYPE_STR:
   benc_str = bencode_str (bd->data.s);
   break;
  default:
   return ((void *)0);
 }
 return benc_str;
}

canonical_original_code:
static inline char *benc_encode(struct __benc_data_type *bd)
{
 char *benc_str = ((void *)0);
 if (bd == ((void *)0))
  return ((void *)0);
 switch (bd->type) {
  case BENC_TYPE_DCT:
   benc_str = bencode_dct (bd->data.d);
   break;
  case BENC_TYPE_INT:
   benc_str = bencode_int (bd->data.i);
   break;
  case BENC_TYPE_LST:
   benc_str = bencode_lst (bd->data.l);
   break;
  case BENC_TYPE_STR:
   benc_str = bencode_str (bd->data.s);
   break;
  default:
   return ((void *)0);
 }
 return benc_str;
}

user_defined_types: enum BENC_TYPE { BENC_TYPE_DCT=0, BENC_TYPE_INT=1, BENC_TYPE_LST=2, BENC_TYPE_STR=3 }

user_defined_types: struct __benc_dict_type { char *key; struct __benc_data_type *val; }


decompiled_code:
char *__fastcall bencode_dct(__int64 a1)
{
char *v1; // r13
char *v2; // rdi
char *v3; // rbp
size_t v4; // rbx
size_t v5; // rax
char *v6; // rax
char *v7; // r12
size_t v8; // rax
size_t v9; // r14
__int64 v10; // rbx
unsigned int v11; // er15
char *v12; // r13
size_t v13; // rbx
const char *v14; // rax
size_t v15; // rax
char *v16; // rax
char *v18; // rax
char *v19; // rdi

if ( !*(_QWORD *)(a1 + 8) )
return 0LL;
v1 = bencode_str(*(char **)a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = benc_encode(*(_QWORD *)(a1 + 8));
if ( v3 )
{
v4 = strlen(v1);
v5 = strlen(v3);
v6 = (char *)malloc(v4 + v5 + 1);
v7 = v6;
if ( !v6 )
{
v19 = v3;
v3 = 0LL;
free(v19);
free(v1);
return v3;
}
sprintf(v6, "%s%s", v1, v3);
free(v1);
free(v3);
v8 = strlen(v7);
v9 = v8 + 1;
v10 = a1 + 16;
if ( *(_QWORD *)(a1 + 24) )
{
v11 = 1;
while ( 1 )
{
v3 = bencode_str(*(char **)v10);
if ( !v3 )
break;
v12 = benc_encode(*(_QWORD *)(v10 + 8));
if ( !v12 )
{
free(v3);
v3 = 0LL;
free(v7);
return v3;
}
v13 = strlen(v3);
v9 += strlen(v12) + v13;
v14 = (const char *)realloc(v7, v9);
v7 = (char *)v14;
if ( !v14 )
{
free(v12);
free(v3);
return 0LL;
}
v15 = strlen(v14);
++v11;
v16 = stpcpy(&v7[v15], v3);
strcpy(v16, v12);
free(v3);
free(v12);
v10 = a1 + 16LL * v11;
if ( !*(_QWORD *)(v10 + 8) )
{
v8 = strlen(v7);
goto LABEL_17;
}
}
}
else
{
LABEL_17:
v18 = (char *)malloc(v8 + 3);
v3 = v18;
if ( v18 )
sprintf(v18, "d%se", v7);
}
v2 = v7;
}
free(v2);
return v3;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
char *v1; // r13
char *v2; // rdi
char *v3; // rbp
size_t v4; // rbx
size_t v5; // rax
char *v6; // rax
char *v7; // r12
size_t v8; // rax
size_t v9; // r14
__int64 v10; // rbx
unsigned int v11; // er15
char *v12; // r13
size_t v13; // rbx
const char *v14; // rax
size_t v15; // rax
char *v16; // rax
char *v18; // rax
char *v19; // rdi

if ( !*(_QWORD *)(a1 + 8) )
return 0LL;
v1 = func3(*(char **)a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = func5(*(_QWORD *)(a1 + 8));
if ( v3 )
{
v4 = strlen(v1);
v5 = strlen(v3);
v6 = (char *)malloc(v4 + v5 + 1);
v7 = v6;
if ( !v6 )
{
v19 = v3;
v3 = 0LL;
free(v19);
free(v1);
return v3;
}
sprintf(v6, "%s%s", v1, v3);
free(v1);
free(v3);
v8 = strlen(v7);
v9 = v8 + 1;
v10 = a1 + 16;
if ( *(_QWORD *)(a1 + 24) )
{
v11 = 1;
while ( 1 )
{
v3 = func3(*(char **)v10);
if ( !v3 )
break;
v12 = func5(*(_QWORD *)(v10 + 8));
if ( !v12 )
{
free(v3);
v3 = 0LL;
free(v7);
return v3;
}
v13 = strlen(v3);
v9 += strlen(v12) + v13;
v14 = (const char *)realloc(v7, v9);
v7 = (char *)v14;
if ( !v14 )
{
free(v12);
free(v3);
return 0LL;
}
v15 = strlen(v14);
++v11;
v16 = stpcpy(&v7[v15], v3);
strcpy(v16, v12);
free(v3);
free(v12);
v10 = a1 + 16LL * v11;
if ( !*(_QWORD *)(v10 + 8) )
{
v8 = strlen(v7);
goto LABEL_17;
}
}
}
else
{
LABEL_17:
v18 = (char *)malloc(v8 + 3);
v3 = v18;
if ( v18 )
sprintf(v18, "d%se", v7);
}
v2 = v7;
}
free(v2);
return v3;
}

original_code:
static inline char *
bencode_dct (benc_dict_t *dict)
{
 char *key = ((void *)0), *str = ((void *)0), *val = ((void *)0);
 uint32_t i;
 size_t len = 0;
 if (dict[0].val == ((void *)0))
  return ((void *)0);
 key = bencode_str (dict[0].key);
 if (key == ((void *)0))
  return ((void *)0);
 val = benc_encode (dict[0].val);
 if (val == ((void *)0)) {
  free (key);
  return ((void *)0);
 }
 len = strlen (key) + strlen (val) + 1;
 str = (char *) malloc (sizeof (char) * len);
 if (str == ((void *)0)) {
  free (val);
  free (key);
  return ((void *)0);
 }
 sprintf (str, "%s%s", key, val);
 free (key);
 free (val);
 key = val = ((void *)0);
 len = strlen (str) + 1;
 for (i = 1; dict[i].val; i++) {
  key = bencode_str (dict[i].key);
  if (key == ((void *)0)) {
   free (str);
   return ((void *)0);
  }
  val = benc_encode (dict[i].val);
  if (val == ((void *)0)) {
   free (key);
   free (str);
   return ((void *)0);
  }
  len += strlen (key) + strlen (val);
  str = (char *) realloc (str, sizeof (char) * len);
  if (str == ((void *)0)) {
   free (val);
   free (key);
   return ((void *)0);
  }
  strcat (str, key);
  strcat (str, val);
  free (key);
  free (val);
  key = val = ((void *)0);
 }
 val = str;
 len = strlen (str) + 3;
 str = (char *) malloc (sizeof (char) * len);
 if (str == ((void *)0)) {
  free (val);
  return ((void *)0);
 }
 sprintf (str, "d%se", val);
 free (val);
 return str;
}

canonical_original_code:
static inline char *bencode_dct(struct __benc_dict_type *dict)
{
 char *key = ((void *)0); char *str = ((void *)0); char *val = ((void *)0);
 unsigned int i;
 unsigned long len = 0;
 if (dict[0].val == ((void *)0))
  return ((void *)0);
 key = bencode_str (dict[0].key);
 if (key == ((void *)0))
  return ((void *)0);
 val = benc_encode (dict[0].val);
 if (val == ((void *)0)) {
  free (key);
  return ((void *)0);
 }
 len = strlen (key) + strlen (val) + 1;
 str = (char *) malloc (sizeof (char) * len);
 if (str == ((void *)0)) {
  free (val);
  free (key);
  return ((void *)0);
 }
 sprintf (str, "%s%s", key, val);
 free (key);
 free (val);
 key = val = ((void *)0);
 len = strlen (str) + 1;
 for (i = 1; dict[i].val; i++) {
  key = bencode_str (dict[i].key);
  if (key == ((void *)0)) {
   free (str);
   return ((void *)0);
  }
  val = benc_encode (dict[i].val);
  if (val == ((void *)0)) {
   free (key);
   free (str);
   return ((void *)0);
  }
  len += strlen (key) + strlen (val);
  str = (char *) realloc (str, sizeof (char) * len);
  if (str == ((void *)0)) {
   free (val);
   free (key);
   return ((void *)0);
  }
  strcat (str, key);
  strcat (str, val);
  free (key);
  free (val);
  key = val = ((void *)0);
 }
 val = str;
 len = strlen (str) + 3;
 str = (char *) malloc (sizeof (char) * len);
 if (str == ((void *)0)) {
  free (val);
  return ((void *)0);
 }
 sprintf (str, "d%se", val);
 free (val);
 return str;
}

variable_types: struct __benc_dict_type { char *key; struct __benc_data_type { enum BENC_TYPE { BENC_TYPE_DCT=0, BENC_TYPE_INT=1, BENC_TYPE_LST=2, BENC_TYPE_STR=3 } type; union { struct __benc_dict_type *d; long i; struct __benc_data_type **l; char *s; } data; } *val; } *

variable_types:
key
char *

variable_types:
val
char *

variable_types:
len
unsigned long


decompiled_code:
char *__fastcall bencode_lst(__int64 *a1)
{
__int64 v2; // rdi
char *v3; // rax
char *v4; // r12
size_t v5; // rax
__int64 v6; // rdi
size_t v7; // rbx
int v8; // er13
char *v9; // rax
char *v10; // rax
char *v11; // rbp
char *v13; // rax

v2 = *a1;
if ( !v2 )
return 0LL;
v3 = benc_encode(v2);
v4 = v3;
if ( !v3 )
return 0LL;
v5 = strlen(v3);
v6 = a1[1];
v7 = v5 + 1;
if ( v6 )
{
v8 = 1;
while ( 1 )
{
v10 = benc_encode(v6);
v11 = v10;
if ( !v10 )
break;
v7 += strlen(v10);
v9 = (char *)realloc(v4, v7);
v4 = v9;
if ( !v9 )
{
v5 = strlen(0LL);
goto LABEL_10;
}
strcat(v9, v11);
free(v11);
v6 = a1[++v8];
if ( !v6 )
{
v5 = strlen(v4);
goto LABEL_10;
}
}
}
else
{
LABEL_10:
v13 = (char *)malloc(v5 + 3);
v11 = v13;
if ( v13 )
sprintf(v13, "l%se", v4);
}
free(v4);
return v11;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 *a1)
{
__int64 v2; // rdi
char *v3; // rax
char *v4; // r12
size_t v5; // rax
__int64 v6; // rdi
size_t v7; // rbx
int v8; // er13
char *v9; // rax
char *v10; // rax
char *v11; // rbp
char *v13; // rax

v2 = *a1;
if ( !v2 )
return 0LL;
v3 = func5(v2);
v4 = v3;
if ( !v3 )
return 0LL;
v5 = strlen(v3);
v6 = a1[1];
v7 = v5 + 1;
if ( v6 )
{
v8 = 1;
while ( 1 )
{
v10 = func5(v6);
v11 = v10;
if ( !v10 )
break;
v7 += strlen(v10);
v9 = (char *)realloc(v4, v7);
v4 = v9;
if ( !v9 )
{
v5 = strlen(0LL);
goto LABEL_10;
}
strcat(v9, v11);
free(v11);
v6 = a1[++v8];
if ( !v6 )
{
v5 = strlen(v4);
goto LABEL_10;
}
}
}
else
{
LABEL_10:
v13 = (char *)malloc(v5 + 3);
v11 = v13;
if ( v13 )
sprintf(v13, "l%se", v4);
}
free(v4);
return v11;
}

original_code:
static inline char *
bencode_lst (benc_data_t **list)
{
 uint32_t i = 0;
 size_t len = 0;
 char *str = ((void *)0), *tmp = ((void *)0);
 if (list[0] == ((void *)0))
  return ((void *)0);
 tmp = benc_encode (list[0]);
 if (tmp == ((void *)0))
  return ((void *)0);
 str = tmp;
 tmp = ((void *)0);
 len = strlen (str) + 1;
 for (i = 1; list[i]; i++) {
  tmp = benc_encode (list[i]);
  if (tmp == ((void *)0)) {
   free (str);
   return ((void *)0);
  }
  len += strlen (tmp);
  str = (char *) realloc (str, sizeof (char) * len);
  if (str == ((void *)0))
   break;
  strcat (str, tmp);
  free (tmp);
  tmp = ((void *)0);
 }
 tmp = str;
 len = strlen (str) + 3;
 str = (char *) malloc (sizeof (char) * len);
 if (str == ((void *)0)) {
  free (tmp);
  return ((void *)0);
 }
 sprintf (str, "l%se", tmp);
 free (tmp);
 return str;
}

canonical_original_code:
static inline char *bencode_lst(struct __benc_data_type **list)
{
 unsigned int i = 0;
 unsigned long len = 0;
 char *str = ((void *)0); char *tmp = ((void *)0);
 if (list[0] == ((void *)0))
  return ((void *)0);
 tmp = benc_encode (list[0]);
 if (tmp == ((void *)0))
  return ((void *)0);
 str = tmp;
 tmp = ((void *)0);
 len = strlen (str) + 1;
 for (i = 1; list[i]; i++) {
  tmp = benc_encode (list[i]);
  if (tmp == ((void *)0)) {
   free (str);
   return ((void *)0);
  }
  len += strlen (tmp);
  str = (char *) realloc (str, sizeof (char) * len);
  if (str == ((void *)0))
   break;
  strcat (str, tmp);
  free (tmp);
  tmp = ((void *)0);
 }
 tmp = str;
 len = strlen (str) + 3;
 str = (char *) malloc (sizeof (char) * len);
 if (str == ((void *)0)) {
  free (tmp);
  return ((void *)0);
 }
 sprintf (str, "l%se", tmp);
 free (tmp);
 return str;
}

variable_types: struct __benc_data_type { enum BENC_TYPE { BENC_TYPE_DCT=0, BENC_TYPE_INT=1, BENC_TYPE_LST=2, BENC_TYPE_STR=3 } type; union { struct __benc_dict_type { char *key; struct __benc_data_type *val; } *d; long i; struct __benc_data_type **l; char *s; } data; } **


decompiled_code:
_QWORD *missing_pass_key()
{
void **v0; // rax
void **v1; // rbp
_QWORD *v2; // r12
char *v3; // rax
_DWORD *v4; // rax
_QWORD *v5; // r13

v0 = (void **)malloc(0x20uLL);
if ( !v0 )
return 0LL;
v0[3] = 0LL;
v1 = v0;
*v0 = strdup("failure reason");
v2 = new_benc_data(3);
if ( !v2 )
{
free(*v1);
free(v1);
return v2;
}
v3 = strdup("Missing passkey, re-download torrent from forum.");
v2[1] = v3;
if ( !v3 )
{
free(v2);
goto LABEL_9;
}
v1[1] = v2;
v4 = new_benc_data(0);
v5 = v4;
if ( !v4 )
{
free_benc_data(v1[1]);
LABEL_9:
v2 = 0LL;
free(*v1);
free(v1);
return v2;
}
*((_QWORD *)v4 + 1) = v1;
v2 = benc_encode((__int64)v4);
free_benc_data(v5);
return v2;
}

canonical_decompiled_code:
_QWORD *func8()
{
void **v0; // rax
void **v1; // rbp
_QWORD *v2; // r12
char *v3; // rax
_DWORD *v4; // rax
_QWORD *v5; // r13

v0 = (void **)malloc(0x20uLL);
if ( !v0 )
return 0LL;
v0[3] = 0LL;
v1 = v0;
*v0 = strdup("failure reason");
v2 = new_benc_data(3);
if ( !v2 )
{
free(*v1);
free(v1);
return v2;
}
v3 = strdup("Missing passkey, re-download torrent from forum.");
v2[1] = v3;
if ( !v3 )
{
free(v2);
goto LABEL_9;
}
v1[1] = v2;
v4 = new_benc_data(0);
v5 = v4;
if ( !v4 )
{
func0(v1[1]);
LABEL_9:
v2 = 0LL;
free(*v1);
free(v1);
return v2;
}
*((_QWORD *)v4 + 1) = v1;
v2 = func5((__int64)v4);
func0(v5);
return v2;
}

original_code:
static inline char *
missing_pass_key (void)
{
 benc_data_t *bd = ((void *)0);
 benc_dict_t *dict = ((void *)0);
 char *str = ((void *)0);
 dict = (benc_dict_t *) malloc (sizeof (benc_dict_t) * 2);
 if (dict == ((void *)0))
  return ((void *)0);
 dict[1].val = ((void *)0);
 dict[0].key = strdup ("failure reason");
 bd = new_benc_data (BENC_TYPE_STR);
 if (bd == ((void *)0)) {
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.s = strdup ("Missing passkey, re-download torrent from "
   "forum.");
 if (bd->data.s == ((void *)0)) {
  free (bd);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 dict[0].val = bd;
 bd = new_benc_data (BENC_TYPE_DCT);
 if (bd == ((void *)0)) {
  free_benc_data (dict[0].val);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.d = dict;
 str = benc_encode (bd);
 free_benc_data (bd);
 return str;
}

canonical_original_code:
static inline char *missing_pass_key()
{
 struct __benc_data_type *bd = ((void *)0);
 struct __benc_dict_type *dict = ((void *)0);
 char *str = ((void *)0);
 dict = (struct __benc_dict_type *) malloc (sizeof (benc_dict_t) * 2);
 if (dict == ((void *)0))
  return ((void *)0);
 dict[1].val = ((void *)0);
 dict[0].key = strdup ("failure reason");
 bd = new_benc_data (BENC_TYPE_STR);
 if (bd == ((void *)0)) {
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.s = strdup ("Missing passkey, re-download torrent from "
   "forum.");
 if (bd->data.s == ((void *)0)) {
  free (bd);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 dict[0].val = bd;
 bd = new_benc_data (BENC_TYPE_DCT);
 if (bd == ((void *)0)) {
  free_benc_data (dict[0].val);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.d = dict;
 str = benc_encode (bd);
 free_benc_data (bd);
 return str;
}


decompiled_code:
_QWORD *bad_request()
{
void **v0; // rax
void **v1; // rbp
_QWORD *v2; // r12
char *v3; // rax
_DWORD *v4; // rax
_QWORD *v5; // r13

v0 = (void **)malloc(0x20uLL);
if ( !v0 )
return 0LL;
v0[3] = 0LL;
v1 = v0;
*v0 = strdup("failure reason");
v2 = new_benc_data(3);
if ( !v2 )
{
free(*v1);
free(v1);
return v2;
}
v3 = strdup("Bad request, unsupported request from client.");
v2[1] = v3;
if ( !v3 )
{
free(v2);
goto LABEL_9;
}
v1[1] = v2;
v4 = new_benc_data(0);
v5 = v4;
if ( !v4 )
{
free_benc_data(v1[1]);
LABEL_9:
v2 = 0LL;
free(*v1);
free(v1);
return v2;
}
*((_QWORD *)v4 + 1) = v1;
v2 = benc_encode((__int64)v4);
free_benc_data(v5);
return v2;
}

canonical_decompiled_code:
_QWORD *func9()
{
void **v0; // rax
void **v1; // rbp
_QWORD *v2; // r12
char *v3; // rax
_DWORD *v4; // rax
_QWORD *v5; // r13

v0 = (void **)malloc(0x20uLL);
if ( !v0 )
return 0LL;
v0[3] = 0LL;
v1 = v0;
*v0 = strdup("failure reason");
v2 = new_benc_data(3);
if ( !v2 )
{
free(*v1);
free(v1);
return v2;
}
v3 = strdup("Bad request, unsupported request from client.");
v2[1] = v3;
if ( !v3 )
{
free(v2);
goto LABEL_9;
}
v1[1] = v2;
v4 = new_benc_data(0);
v5 = v4;
if ( !v4 )
{
func0(v1[1]);
LABEL_9:
v2 = 0LL;
free(*v1);
free(v1);
return v2;
}
*((_QWORD *)v4 + 1) = v1;
v2 = func5((__int64)v4);
func0(v5);
return v2;
}

original_code:
static inline char *
bad_request (void)
{
 benc_data_t *bd = ((void *)0);
 benc_dict_t *dict = ((void *)0);
 char *str = ((void *)0);
 dict = (benc_dict_t *) malloc (sizeof (benc_dict_t) * 2);
 if (dict == ((void *)0))
  return ((void *)0);
 dict[1].val = ((void *)0);
 dict[0].key = strdup ("failure reason");
 bd = new_benc_data (BENC_TYPE_STR);
 if (bd == ((void *)0)) {
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.s = strdup ("Bad request, unsupported request from client.");
 if (bd->data.s == ((void *)0)) {
  free (bd);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 dict[0].val = bd;
 bd = new_benc_data (BENC_TYPE_DCT);
 if (bd == ((void *)0)) {
  free_benc_data (dict[0].val);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.d = dict;
 str = benc_encode (bd);
 free_benc_data (bd);
 return str;
}

canonical_original_code:
static inline char *bad_request()
{
 struct __benc_data_type *bd = ((void *)0);
 struct __benc_dict_type *dict = ((void *)0);
 char *str = ((void *)0);
 dict = (struct __benc_dict_type *) malloc (sizeof (benc_dict_t) * 2);
 if (dict == ((void *)0))
  return ((void *)0);
 dict[1].val = ((void *)0);
 dict[0].key = strdup ("failure reason");
 bd = new_benc_data (BENC_TYPE_STR);
 if (bd == ((void *)0)) {
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.s = strdup ("Bad request, unsupported request from client.");
 if (bd->data.s == ((void *)0)) {
  free (bd);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 dict[0].val = bd;
 bd = new_benc_data (BENC_TYPE_DCT);
 if (bd == ((void *)0)) {
  free_benc_data (dict[0].val);
  free (dict[0].key);
  free (dict);
  return ((void *)0);
 }
 bd->data.d = dict;
 str = benc_encode (bd);
 free_benc_data (bd);
 return str;
}


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

if ( sql_conn )
result = mysql_close();
sql_conn = 0LL;
return result;
}

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

if ( sql_conn )
result = mysql_close();
sql_conn = 0LL;
return result;
}

original_code:
void
sql_fin (void)
{
 if (sql_conn != ((void *)0))
  mysql_close (sql_conn);
 sql_conn = ((void *)0);
 return;
}

canonical_original_code:
void sql_fin()
{
 if (sql_conn != ((void *)0))
  mysql_close (sql_conn);
 sql_conn = ((void *)0);
 return;
}


decompiled_code:
__int64 sql_init()
{
__int64 v0; // rax
__int64 result; // rax
const char *v2; // rax

v0 = mysql_init(0LL);
sql_conn = v0;
if ( v0 )
{
if ( mysql_real_connect(v0, host, user, passwd, name, 0LL, 0LL, 0LL) )
{
result = 0LL;
}
else
{
v2 = (const char *)mysql_error(sql_conn);
logger_constprop_0(
1LL,
"%s_%d, %s: ERROR: faild to connect to database, error: %s\n",
"sql.c",
35LL,
"sql_init",
v2);
result = 0xFFFFFFFFLL;
}
}
else
{
logger_constprop_0(1LL, "%s_%d, %s: ERROR: out-of-memory.\n", "sql.c", 29LL, "sql_init");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 result; // rax
const char *v2; // rax

v0 = mysql_init(0LL);
sql_conn = v0;
if ( v0 )
{
if ( mysql_real_connect(v0, host, user, passwd, name, 0LL, 0LL, 0LL) )
{
result = 0LL;
}
else
{
v2 = (const char *)mysql_error(sql_conn);
func0(
1LL,
"%s_%d, %s: ERROR: faild to connect to database, error: %s\n",
"sql.c",
35LL,
"sql_init",
v2);
result = 0xFFFFFFFFLL;
}
}
else
{
func0(1LL, "%s_%d, %s: ERROR: out-of-memory.\n", "sql.c", 29LL, "sql_init");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
sql_init (void)
{
 sql_conn = mysql_init (((void *)0));
 if (sql_conn == ((void *)0)) {
  do { logger (LOG_ERR, "%s_%d, %s: " "ERROR: out-of-memory.\n", "sql.c", 29, __FUNCTION__); } while (0);;
  return -1;
 }
 if (mysql_real_connect (sql_conn, host, user, passwd, name, 0, ((void *)0), 0)
   == ((void *)0)) {
  do { logger (LOG_ERR, "%s_%d, %s: " "ERROR: faild to connect to database, error: " "%s\n", "sql.c", 35, __FUNCTION__, mysql_error (sql_conn)); } while (0);;
  return -1;
 }
 return 0;
}

canonical_original_code:
int sql_init()
{
 sql_conn = mysql_init (((void *)0));
 if (sql_conn == ((void *)0)) {
  do { logger (LOG_ERR, "%s_%d, %s: " "ERROR: out-of-memory.\n", "sql.c", 29, __FUNCTION__); } while (0);;
  return -1;
 }
 if (mysql_real_connect (sql_conn, host, user, passwd, name, 0, ((void *)0), 0)
   == ((void *)0)) {
  do { logger (LOG_ERR, "%s_%d, %s: " "ERROR: faild to connect to database, error: " "%s\n", "sql.c", 35, __FUNCTION__, mysql_error (sql_conn)); } while (0);;
  return -1;
 }
 return 0;
}

return_type: int


usage

repo: kruhft/woc

decompiled_code:
size_t usage()
{
fwrite("usage: woc [words...] -- [files or directories...]\n", 1uLL, 0x33uLL, stderr);
return fwrite("count the number of occurances of words in files or files in directories\n", 1uLL, 0x49uLL, stderr);
}

canonical_decompiled_code:
size_t func8()
{
fwrite("usage: woc [words...] -- [files or directories...]\n", 1uLL, 0x33uLL, stderr);
return fwrite("count the number of occurances of words in files or files in directories\n", 1uLL, 0x49uLL, stderr);
}

original_code:
void usage(void) {
  fprintf(stderr, "usage: woc [words...] -- [files or directories...]\n");
  fprintf(stderr, "count the number of occurances of words in files or files in directories\n");
}

canonical_original_code:
void usage() {
  fprintf(stderr, "usage: woc [words...] -- [files or directories...]\n");
  fprintf(stderr, "count the number of occurances of words in files or files in directories\n");
}


decompiled_code:
int usage()
{
return puts(
"Usage: jagadm -a ACTION [-t TYPE] [-p PARAM] FILE/DIR\n"
"ACTION can be\n"
"version - Version the FILE/DIR\n"
"unversion - Unversion the FILE/DIR\n"
"prune\t\t- Remove the older versions that are not needed\n"
"dump\t\t- Dump statistics\n"
"reset\t\t- Reset statistics\n"
"TYPE can be\n"
"all\t\t- Keep all older versions\n"
"time\t\t- Keep versions within last few seconds\n"
"number\t\t- Keep last few versions\n"
"PARAM can be\n"
"number of seconds (when TYPE is time) or\n"
"number of versions (when TYPE is number)");
}

canonical_decompiled_code:
int func7()
{
return puts(
"Usage: jagadm -a ACTION [-t TYPE] [-p PARAM] FILE/DIR\n"
"ACTION can be\n"
"version - Version the FILE/DIR\n"
"unversion - Unversion the FILE/DIR\n"
"prune\t\t- Remove the older versions that are not needed\n"
"dump\t\t- Dump statistics\n"
"reset\t\t- Reset statistics\n"
"TYPE can be\n"
"all\t\t- Keep all older versions\n"
"time\t\t- Keep versions within last few seconds\n"
"number\t\t- Keep last few versions\n"
"PARAM can be\n"
"number of seconds (when TYPE is time) or\n"
"number of versions (when TYPE is number)");
}

original_code:
static void usage(void)
{
 printf("Usage: jagadm -a ACTION [-t TYPE] [-p PARAM] FILE/DIR\n"
  "ACTION can be\n"
  "version        - Version the FILE/DIR\n"
  "unversion      - Unversion the FILE/DIR\n"
  "prune		- Remove the older versions that are not needed\n"
  "dump		- Dump statistics\n"
  "reset		- Reset statistics\n"
  "TYPE can be\n"
  "all		- Keep all older versions\n"
  "time		- Keep versions within last few seconds\n"
  "number		- Keep last few versions\n"
  "PARAM can be\n"
  "number of seconds (when TYPE is time) or\n"
  "number of versions (when TYPE is number)\n"
  );
}

canonical_original_code:
static void usage()
{
 printf("Usage: jagadm -a ACTION [-t TYPE] [-p PARAM] FILE/DIR\n"
  "ACTION can be\n"
  "version        - Version the FILE/DIR\n"
  "unversion      - Unversion the FILE/DIR\n"
  "prune		- Remove the older versions that are not needed\n"
  "dump		- Dump statistics\n"
  "reset		- Reset statistics\n"
  "TYPE can be\n"
  "all		- Keep all older versions\n"
  "time		- Keep versions within last few seconds\n"
  "number		- Keep last few versions\n"
  "PARAM can be\n"
  "number of seconds (when TYPE is time) or\n"
  "number of versions (when TYPE is number)\n"
  );
}


version

decompiled_code:
__int64 __fastcall version(const char *a1, int a2, int a3)
{
int v4; // eax
int v5; // ebp
int v6; // er12
int v8[8]; // [rsp+8h] [rbp-20h] BYREF

v4 = open(a1, 0);
if ( v4 < 0 )
{
v6 = *__errno_location();
perror(0LL);
}
else
{
v5 = v4;
v8[1] = a3;
v8[0] = a2;
v6 = ioctl(v4, 0x40046664uLL, v8);
if ( v6 < 0 )
{
v6 = *__errno_location();
perror(0LL);
}
if ( v5 )
close(v5);
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, int a2, int a3)
{
int v4; // eax
int v5; // ebp
int v6; // er12
int v8[8]; // [rsp+8h] [rbp-20h] BYREF

v4 = open(a1, 0);
if ( v4 < 0 )
{
v6 = *__errno_location();
perror(0LL);
}
else
{
v5 = v4;
v8[1] = a3;
v8[0] = a2;
v6 = ioctl(v4, 0x40046664uLL, v8);
if ( v6 < 0 )
{
v6 = *__errno_location();
perror(0LL);
}
if ( v5 )
close(v5);
}
return (unsigned int)v6;
}

original_code:
static int version(const char *filename, int type, int param)
{
 int fd = -1, ret = -22;
 struct version_info info;
 if ((fd = open(filename, 00)) < 0) {
  ret = (*__errno_location ());
  perror(((void *)0));
  goto err;
 }
 info.type = type;
 info.param = param;
 if ((ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((100)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &info)) < 0) {
  ret = (*__errno_location ());
  perror(((void *)0));
  goto err;
 }
err:
 if (fd > 0)
  close(fd);
 return ret;
}

canonical_original_code:
static int version(char *filename, int type, int param)
{
 int fd = -1; int ret = -22;
 struct version_info info;
 if ((fd = open(filename, 00)) < 0) {
  ret = (*__errno_location ());
  perror(((void *)0));
  goto err;
 }
 info.type = type;
 info.param = param;
 if ((ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((100)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &info)) < 0) {
  ret = (*__errno_location ());
  perror(((void *)0));
  goto err;
 }
err:
 if (fd > 0)
  close(fd);
 return ret;
}

variable_types:
filename
char *

variable_types: type int

variable_types: param int

variable_types: fd int

variable_types: ret int

variable_types: struct version_info { int type; int param; }


unversion

decompiled_code:
__int64 __fastcall unversion(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x6665uLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x6665uLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}

original_code:
static int unversion(const char *filename)
{
 int fd = -1, ret = -22;
 if ((fd = open(filename, 00)) < 0) {
  ret = (*__errno_location ());
  perror(((void *)0));
  goto err;
 }
 if ((ret = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((101)) << 0) | ((0) << ((0 +8)+8))), ((void *)0))) < 0) {
  ret = (*__errno_location ());
  perror(((void *)0));
  goto err;
 }
err:
 if (fd > 0)
  close(fd);
 return ret;
}


prune

decompiled_code:
__int64 __fastcall prune(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x6667uLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x6667uLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}


dump

decompiled_code:
__int64 __fastcall dump(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x666AuLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x666AuLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}


reset

decompiled_code:
__int64 __fastcall reset(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x6669uLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
else
{
v2 = v1;
v3 = ioctl(v1, 0x6669uLL, 0LL);
if ( v3 < 0 )
{
v3 = *__errno_location();
perror(0LL);
}
if ( v2 )
close(v2);
}
return (unsigned int)v3;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
unsigned int v4; // er14
unsigned int v5; // er12
const char **v8; // rsi
const char *v9; // rdi
int v10; // eax
char *v11; // rdx
__int64 v12; // rcx
bool v13; // al
bool v14; // cf
bool v15; // zf
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi

v4 = 0;
v5 = 0;
while ( 1 )
{
v8 = argv;
v9 = (const char *)(unsigned int)argc;
v10 = getopt(argc, (char *const *)argv, "a:t:p:");
if ( v10 == -1 )
break;
switch ( v10 )
{
case 'p':
v5 = strtol(optarg, 0LL, 10);
break;
case 't':
v11 = optarg;
if ( !strcmp(optarg, "all") )
{
v4 = 1;
}
else
{
v13 = strcmp(optarg, "time") != 0;
v14 = 0;
v15 = !v13;
if ( v13 )
{
v9 = "number";
v12 = 7LL;
v8 = (const char **)optarg;
do
{
if ( !v12 )
break;
v14 = *(_BYTE *)v8 < *v9;
v15 = *(_BYTE *)v8 == *v9;
v8 = (const char **)((char *)v8 + 1);
++v9;
--v12;
}
while ( v15 );
if ( (!v14 && !v15) != v14 )
goto LABEL_13;
v4 = 2;
}
else
{
v4 = 3;
}
}
break;
case 'a':
v11 = optarg;
if ( !strcmp(optarg, "version") )
{
v3 = 1;
}
else if ( !strcmp(optarg, "unversion") )
{
v3 = 2;
}
else if ( !strcmp(optarg, "prune") )
{
v3 = 3;
}
else
{
v16 = strcmp(optarg, "dump") != 0;
v17 = 0;
v18 = !v16;
if ( v16 )
{
v9 = "reset";
v12 = 6LL;
v8 = (const char **)optarg;
do
{
if ( !v12 )
break;
v17 = *(_BYTE *)v8 < *v9;
v18 = *(_BYTE *)v8 == *v9;
v8 = (const char **)((char *)v8 + 1);
++v9;
--v12;
}
while ( v18 );
if ( (!v17 && !v18) != v17 )
{
LABEL_13:
usage(v9, v8, v11, v12);
exit(1);
}
v3 = 5;
}
else
{
v3 = 4;
}
}
break;
default:
goto LABEL_13;
}
}
v19 = argv[_bss_start];
switch ( v3 )
{
case 4:
return dump(v19);
case 5:
return reset(v19);
case 2:
return unversion(v19);
case 3:
return prune(v19);
}
return version(v19, v4, v5);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
unsigned int v4; // er14
unsigned int v5; // er12
const char **v8; // rsi
const char *v9; // rdi
int v10; // eax
char *v11; // rdx
__int64 v12; // rcx
bool v13; // al
bool v14; // cf
bool v15; // zf
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi

v4 = 0;
v5 = 0;
while ( 1 )
{
v8 = argv;
v9 = (const char *)(unsigned int)argc;
v10 = getopt(argc, (char *const *)argv, "a:t:p:");
if ( v10 == -1 )
break;
switch ( v10 )
{
case 'p':
v5 = strtol(optarg, 0LL, 10);
break;
case 't':
v11 = optarg;
if ( !strcmp(optarg, "all") )
{
v4 = 1;
}
else
{
v13 = strcmp(optarg, "time") != 0;
v14 = 0;
v15 = !v13;
if ( v13 )
{
v9 = "number";
v12 = 7LL;
v8 = (const char **)optarg;
do
{
if ( !v12 )
break;
v14 = *(_BYTE *)v8 < *v9;
v15 = *(_BYTE *)v8 == *v9;
v8 = (const char **)((char *)v8 + 1);
++v9;
--v12;
}
while ( v15 );
if ( (!v14 && !v15) != v14 )
goto LABEL_13;
v4 = 2;
}
else
{
v4 = 3;
}
}
break;
case 'a':
v11 = optarg;
if ( !strcmp(optarg, "version") )
{
v3 = 1;
}
else if ( !strcmp(optarg, "unversion") )
{
v3 = 2;
}
else if ( !strcmp(optarg, "prune") )
{
v3 = 3;
}
else
{
v16 = strcmp(optarg, "dump") != 0;
v17 = 0;
v18 = !v16;
if ( v16 )
{
v9 = "reset";
v12 = 6LL;
v8 = (const char **)optarg;
do
{
if ( !v12 )
break;
v17 = *(_BYTE *)v8 < *v9;
v18 = *(_BYTE *)v8 == *v9;
v8 = (const char **)((char *)v8 + 1);
++v9;
--v12;
}
while ( v18 );
if ( (!v17 && !v18) != v17 )
{
LABEL_13:
func7(v9, v8, v11, v12);
exit(1);
}
v3 = 5;
}
else
{
v3 = 4;
}
}
break;
default:
goto LABEL_13;
}
}
v19 = argv[_bss_start];
switch ( v3 )
{
case 4:
return func11(v19);
case 5:
return func12(v19);
case 2:
return func9(v19);
case 3:
return func10(v19);
}
return func8(v19, v4, v5);
}

original_code:
int main(int argc, char **argv)
{
 int opt, action, ret = -22;
 int type = 0, param = 0;
 while ((opt = getopt(argc, argv, "a:t:p:")) != -1) {
  switch (opt) {
  case 'a':
   if (strcmp(optarg, "version") == 0) {
    action = 1;
   } else if (strcmp(optarg, "unversion") == 0) {
    action = 2;
   } else if (strcmp(optarg, "prune") == 0) {
    action = 3;
   } else if (strcmp(optarg, "dump") == 0) {
    action = 4;
   } else if (strcmp(optarg, "reset") == 0) {
    action = 5;
   } else {
    usage();
    exit(1);
   }
   break;
  case 't':
   if (strcmp(optarg, "all") == 0) {
    type = 1;
   } else if (strcmp(optarg, "time") == 0) {
    type = 3;
   } else if (strcmp(optarg, "number") == 0) {
    type = 2;
   } else {
    usage();
    exit(1);
   }
   break;
  case 'p':
   param = strtol(optarg, ((void *)0), 10);
   break;
  default:
   usage();
   exit(1);
  }
 }
 switch (action) {
 case 1:
  ret = version(argv[optind], type, param);
  break;
 case 2:
  ret = unversion(argv[optind]);
  break;
 case 3:
  ret = prune(argv[optind]);
  break;
 case 4:
  ret = dump(argv[optind]);
  break;
 case 5:
  ret = reset(argv[optind]);
  break;
 }
 return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int opt; int action; int ret = -22;
 int type = 0; int param = 0;
 while ((opt = getopt(argc, argv, "a:t:p:")) != -1) {
  switch (opt) {
  case 'a':
   if (strcmp(optarg, "version") == 0) {
    action = 1;
   } else if (strcmp(optarg, "unversion") == 0) {
    action = 2;
   } else if (strcmp(optarg, "prune") == 0) {
    action = 3;
   } else if (strcmp(optarg, "dump") == 0) {
    action = 4;
   } else if (strcmp(optarg, "reset") == 0) {
    action = 5;
   } else {
    usage();
    exit(1);
   }
   break;
  case 't':
   if (strcmp(optarg, "all") == 0) {
    type = 1;
   } else if (strcmp(optarg, "time") == 0) {
    type = 3;
   } else if (strcmp(optarg, "number") == 0) {
    type = 2;
   } else {
    usage();
    exit(1);
   }
   break;
  case 'p':
   param = strtol(optarg, ((void *)0), 10);
   break;
  default:
   usage();
   exit(1);
  }
 }
 switch (action) {
 case 1:
  ret = version(argv[optind], type, param);
  break;
 case 2:
  ret = unversion(argv[optind]);
  break;
 case 3:
  ret = prune(argv[optind]);
  break;
 case 4:
  ret = dump(argv[optind]);
  break;
 case 5:
  ret = reset(argv[optind]);
  break;
 }
 return ret;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: action int


jcat

decompiled_code:
__int64 __fastcall jcat(const char *a1, int a2)
{
int v2; // eax
int v3; // er12
int v4; // eax
int v5; // ebx
int v7[1038]; // [rsp+0h] [rbp-1038h] BYREF

v2 = open(a1, 0);
if ( v2 >= 0 )
{
v3 = v2;
memset(v7, 0, 0x1008uLL);
v7[1] = a2;
while ( 1 )
{
v4 = ioctl(v3, 0xC0046666uLL, v7);
v5 = v4;
if ( v4 < 0 )
break;
*((_BYTE *)&v7[2] + v4) = 0;
printf("%s", (const char *)&v7[2]);
memset(&v7[2], 0, 0x1000uLL);
v7[0] += 4096;
if ( v5 <= 4095 )
{
close(v3);
return 0LL;
}
}
}
perror(0LL);
return (unsigned int)*__errno_location();
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
int v2; // eax
int v3; // er12
int v4; // eax
int v5; // ebx
int v7[1038]; // [rsp+0h] [rbp-1038h] BYREF

v2 = open(a1, 0);
if ( v2 >= 0 )
{
v3 = v2;
memset(v7, 0, 0x1008uLL);
v7[1] = a2;
while ( 1 )
{
v4 = ioctl(v3, 0xC0046666uLL, v7);
v5 = v4;
if ( v4 < 0 )
break;
*((_BYTE *)&v7[2] + v4) = 0;
printf("%s", (const char *)&v7[2]);
memset(&v7[2], 0, 0x1000uLL);
v7[0] += 4096;
if ( v5 <= 4095 )
{
close(v3);
return 0LL;
}
}
}
perror(0LL);
return (unsigned int)*__errno_location();
}

original_code:
static int jcat(const char *filename, time_t at)
{
 int fd, done = 0, nbytes;
 struct version_buffer ver_buf;
 if ((fd = open(filename, 00)) < 0) {
  perror(((void *)0));
  return (*__errno_location ());
 }
 memset(&ver_buf, 0, sizeof(ver_buf));
 ver_buf.at = at;
 while (!done) {
  if ((nbytes = ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((102)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf)) < 0) {
   perror(((void *)0));
   return (*__errno_location ());
  }
  ver_buf.data[nbytes] = 0;
  printf("%s", ver_buf.data);
  if (nbytes < 4096)
   done = 1;
  ver_buf.offset += 4096;
  memset(ver_buf.data, 0, 4096);
 }
 close(fd);
 return 0;
}

canonical_original_code:
static int jcat(char *filename, long at)
{
 int fd; int done = 0; int nbytes;
 struct version_buffer ver_buf;
 if ((fd = open(filename, 00)) < 0) {
  perror(((void *)0));
  return (*__errno_location ());
 }
 memset(&ver_buf, 0, sizeof(ver_buf));
 ver_buf.at = at;
 while (!done) {
  if ((nbytes = ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((102)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf)) < 0) {
   perror(((void *)0));
   return (*__errno_location ());
  }
  ver_buf.data[nbytes] = 0;
  printf("%s", ver_buf.data);
  if (nbytes < 4096)
   done = 1;
  ver_buf.offset += 4096;
  memset(ver_buf.data, 0, 4096);
 }
 close(fd);
 return 0;
}

variable_types: at long

variable_types: done int

variable_types: nbytes int

variable_types: struct version_buffer { int offset; int at; char data[4096]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rax
int result; // eax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

if ( argc == 3 )
{
strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &v5);
v3 = mktime(&v5);
result = jcat(argv[1], v3);
}
else
{
puts("Usage: jcat FILE TIME\nFILE - filename\nTIME - time in the format DD-MM-YYYY:HH:MM:SS");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rax
int result; // eax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

if ( argc == 3 )
{
strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &v5);
v3 = mktime(&v5);
result = func7(argv[1], v3);
}
else
{
puts("Usage: jcat FILE TIME\nFILE - filename\nTIME - time in the format DD-MM-YYYY:HH:MM:SS");
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 struct tm tm_arg;
 time_t time_arg;
 if (argc != 3) {
  printf("Usage: jcat FILE TIME\n"
   "FILE - filename\n"
   "TIME - time in the format DD-MM-YYYY:HH:MM:SS\n");
  return -1;
 }
 strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &tm_arg);
 time_arg = mktime(&tm_arg);
 return jcat(argv[1], time_arg);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct tm tm_arg;
 long time_arg;
 if (argc != 3) {
  printf("Usage: jcat FILE TIME\n"
   "FILE - filename\n"
   "TIME - time in the format DD-MM-YYYY:HH:MM:SS\n");
  return -1;
 }
 strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &tm_arg);
 time_arg = mktime(&tm_arg);
 return jcat(argv[1], time_arg);
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


original_code:
int fill_super_block(struct super_block *sb, int disk_size)
{
 int max_inodes, max_blks, metadata_size;
 int data_bmap_size, inode_bmap_size, inode_tbl_size;
 max_inodes = disk_size / 8192;
 max_blks = disk_size / 4096;
 data_bmap_size = (((max_blks / 8) + 4096 - 1) / 4096 * 4096);
 inode_bmap_size = (((max_inodes / 8) + 4096 - 1) / 4096 * 4096);
 inode_tbl_size = (((max_inodes * 128) + 4096 - 1) / 4096 * 4096);
 printf("disk size = %d\n", disk_size);
 printf("max_blocks = %d, data_bmap_size = %d\n",
  max_blks, data_bmap_size);
 printf("max_inodes = %d, inode_bmap_size = %d, inode_tbl_size = %d\n",
  max_inodes, inode_bmap_size, inode_tbl_size);
 strcpy(sb->name, "jaguarfs");
 sb->sb_start = 0;
 sb->sb_size = 4096;
 printf("super block: start = %d, size = %d\n", sb->sb_start, sb->sb_size);
 sb->data_bmap_start = sb->sb_start + sb->sb_size;
 sb->data_bmap_size = data_bmap_size;
 printf("data bitmap: start = %d, size = %d\n", sb->data_bmap_start, sb->data_bmap_size);
 sb->inode_bmap_start = sb->data_bmap_start + sb->data_bmap_size;
 sb->inode_bmap_size = inode_bmap_size;
 printf("inode bitmap: start = %d, size = %d\n", sb->inode_bmap_start, sb->inode_bmap_size);
 sb->inode_tbl_start = sb->inode_bmap_start + sb->inode_bmap_size;
 sb->inode_tbl_size = inode_tbl_size;
 printf("inode table: start = %d, size = %d\n", sb->inode_tbl_start, sb->inode_tbl_size);
 sb->data_start = sb->inode_tbl_start + sb->inode_tbl_size;
 printf("data: start = %d\n", sb->data_start);
 metadata_size = 4096 + data_bmap_size + inode_bmap_size + inode_tbl_size;
 sb->n_blocks = max_blks;
 sb->n_blocks_free = max_blks - (metadata_size / 4096);
 sb->next_free_block = metadata_size / 4096;
 printf("blocks: total = %d, free = %d, next = %d\n", sb->n_blocks, sb->n_blocks_free, sb->next_free_block);
 sb->n_inodes = max_inodes;
 sb->n_inodes_free = max_inodes - 2;
 sb->next_free_inode = 2;
 printf("inodes: total = %d, free = %d, next = %d\n", sb->n_inodes, sb->n_inodes_free, sb->next_free_inode);
 return 0;
}

canonical_original_code:
int fill_super_block(struct super_block *sb, int disk_size)
{
 int max_inodes; int max_blks; int metadata_size;
 int data_bmap_size; int inode_bmap_size; int inode_tbl_size;
 max_inodes = disk_size / 8192;
 max_blks = disk_size / 4096;
 data_bmap_size = (((max_blks / 8) + 4096 - 1) / 4096 * 4096);
 inode_bmap_size = (((max_inodes / 8) + 4096 - 1) / 4096 * 4096);
 inode_tbl_size = (((max_inodes * 128) + 4096 - 1) / 4096 * 4096);
 printf("disk size = %d\n", disk_size);
 printf("max_blocks = %d, data_bmap_size = %d\n",
  max_blks, data_bmap_size);
 printf("max_inodes = %d, inode_bmap_size = %d, inode_tbl_size = %d\n",
  max_inodes, inode_bmap_size, inode_tbl_size);
 strcpy(sb->name, "jaguarfs");
 sb->sb_start = 0;
 sb->sb_size = 4096;
 printf("super block: start = %d, size = %d\n", sb->sb_start, sb->sb_size);
 sb->data_bmap_start = sb->sb_start + sb->sb_size;
 sb->data_bmap_size = data_bmap_size;
 printf("data bitmap: start = %d, size = %d\n", sb->data_bmap_start, sb->data_bmap_size);
 sb->inode_bmap_start = sb->data_bmap_start + sb->data_bmap_size;
 sb->inode_bmap_size = inode_bmap_size;
 printf("inode bitmap: start = %d, size = %d\n", sb->inode_bmap_start, sb->inode_bmap_size);
 sb->inode_tbl_start = sb->inode_bmap_start + sb->inode_bmap_size;
 sb->inode_tbl_size = inode_tbl_size;
 printf("inode table: start = %d, size = %d\n", sb->inode_tbl_start, sb->inode_tbl_size);
 sb->data_start = sb->inode_tbl_start + sb->inode_tbl_size;
 printf("data: start = %d\n", sb->data_start);
 metadata_size = 4096 + data_bmap_size + inode_bmap_size + inode_tbl_size;
 sb->n_blocks = max_blks;
 sb->n_blocks_free = max_blks - (metadata_size / 4096);
 sb->next_free_block = metadata_size / 4096;
 printf("blocks: total = %d, free = %d, next = %d\n", sb->n_blocks, sb->n_blocks_free, sb->next_free_block);
 sb->n_inodes = max_inodes;
 sb->n_inodes_free = max_inodes - 2;
 sb->next_free_inode = 2;
 printf("inodes: total = %d, free = %d, next = %d\n", sb->n_inodes, sb->n_inodes_free, sb->next_free_inode);
 return 0;
}

variable_types: struct super_block { char name[16]; int sb_start; int sb_size; int data_bmap_start; int data_bmap_size; int inode_bmap_start; int inode_bmap_size; int inode_tbl_start; int inode_tbl_size; int data_start; int n_blocks; int n_blocks_free; int n_inodes; int n_inodes_free; int next_free_block; int next_free_inode; } *


decompiled_code:
__int64 __fastcall set_bit(__int64 a1, int a2)
{
__int64 result; // rax

result = a2 / 8;
*(_BYTE *)(a1 + result) |= 128 >> (a2 % 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 result; // rax

result = a2 / 8;
*(_BYTE *)(a1 + result) |= 128 >> (a2 % 8);
return result;
}

original_code:
void set_bit(unsigned char *buf, int pos)
{
 int index, offset;
 unsigned char mask;
 index = pos / 8;
 offset = pos % 8;
 mask = 0x80 >> offset;
 buf[index] |= mask;
}

canonical_original_code:
void set_bit(unsigned char *buf, int pos)
{
 int index; int offset;
 unsigned char mask;
 index = pos / 8;
 offset = pos % 8;
 mask = 0x80 >> offset;
 buf[index] |= mask;
}

variable_types:
buf
unsigned char *

variable_types: pos int

variable_types: index int

variable_types: offset int

variable_types:
mask
unsigned char


jls

decompiled_code:
int __fastcall jls(const char *a1, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // er14
int i; // er13
int *v6; // rdi
int v7; // eax
int result; // eax
int v9[1042]; // [rsp+0h] [rbp-1048h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror(0LL);
result = *__errno_location();
}
else
{
v3 = v2;
memset(v9, 0, 0x1008uLL);
v9[1] = a2;
while ( 1 )
{
v4 = ioctl(v3, 0xC0046666uLL, v9);
if ( v4 <= 0 )
break;
for ( i = 0; i < v4; i += 64 )
{
while ( 1 )
{
v6 = &v9[i / 4u + 2];
if ( *v6 )
break;
i += 64;
if ( v4 <= i )
goto LABEL_8;
}
puts((const char *)v6 + 4);
}
LABEL_8:
v7 = v9[0] + 4096;
if ( v4 <= 4095 )
goto LABEL_11;
v9[0] += 4096;
memset(&v9[2], 0, 0x1000uLL);
}
v7 = v9[0] + 4096;
LABEL_11:
v9[0] = v7;
memset(&v9[2], 0, 0x1000uLL);
result = close(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // er14
int i; // er13
int *v6; // rdi
int v7; // eax
int result; // eax
int v9[1042]; // [rsp+0h] [rbp-1048h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror(0LL);
result = *__errno_location();
}
else
{
v3 = v2;
memset(v9, 0, 0x1008uLL);
v9[1] = a2;
while ( 1 )
{
v4 = ioctl(v3, 0xC0046666uLL, v9);
if ( v4 <= 0 )
break;
for ( i = 0; i < v4; i += 64 )
{
while ( 1 )
{
v6 = &v9[i / 4u + 2];
if ( *v6 )
break;
i += 64;
if ( v4 <= i )
goto LABEL_8;
}
puts((const char *)v6 + 4);
}
LABEL_8:
v7 = v9[0] + 4096;
if ( v4 <= 4095 )
goto LABEL_11;
v9[0] += 4096;
memset(&v9[2], 0, 0x1000uLL);
}
v7 = v9[0] + 4096;
LABEL_11:
v9[0] = v7;
memset(&v9[2], 0, 0x1000uLL);
result = close(v3);
}
return result;
}

original_code:
static int jls(const char *dirname, time_t at)
{
 int fd, done = 0, nbytes, i;
 struct version_buffer ver_buf;
 struct jaguar_dentry *dentry;
 if ((fd = open(dirname, 00)) < 0) {
  perror(((void *)0));
  return (*__errno_location ());
 }
 memset(&ver_buf, 0, sizeof(ver_buf));
 ver_buf.at = at;
 while (!done) {
  if ((nbytes = ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((102)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf)) < 0) {
  }
  for (i = 0; i < nbytes; i += sizeof(*dentry)) {
   dentry = (struct jaguar_dentry *) (ver_buf.data + i);
   if (dentry->inum != 0)
    printf("%s\n", dentry->name);
  }
  if (nbytes < 4096)
   done = 1;
  ver_buf.offset += 4096;
  memset(ver_buf.data, 0, 4096);
 }
 close(fd);
}

canonical_original_code:
static int jls(char *dirname, long at)
{
 int fd; int done = 0; int nbytes; int i;
 struct version_buffer ver_buf;
 struct jaguar_dentry *dentry;
 if ((fd = open(dirname, 00)) < 0) {
  perror(((void *)0));
  return (*__errno_location ());
 }
 memset(&ver_buf, 0, sizeof(ver_buf));
 ver_buf.at = at;
 while (!done) {
  if ((nbytes = ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((102)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf)) < 0) {
  }
  for (i = 0; i < nbytes; i += sizeof(*dentry)) {
   dentry = (struct jaguar_dentry *) (ver_buf.data + i);
   if (dentry->inum != 0)
    printf("%s\n", dentry->name);
  }
  if (nbytes < 4096)
   done = 1;
  ver_buf.offset += 4096;
  memset(ver_buf.data, 0, 4096);
 }
 close(fd);
}

variable_types:
dirname
char *

variable_types: fd int

variable_types: i int

variable_types: struct jaguar_dentry { unsigned int inum; char name[60]; } *

user_defined_types: struct version_buffer { int offset; int at; char data[4096]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rax
int result; // eax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

if ( argc == 3 )
{
strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &v5);
v3 = mktime(&v5);
result = jls(argv[1], v3);
}
else
{
puts("Usage: jls DIR TIME\nDIR - dirname\nTIME - time in the format DD-MM-YYYY:HH:MM:SS");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rax
int result; // eax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

if ( argc == 3 )
{
strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &v5);
v3 = mktime(&v5);
result = func7(argv[1], v3);
}
else
{
puts("Usage: jls DIR TIME\nDIR - dirname\nTIME - time in the format DD-MM-YYYY:HH:MM:SS");
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 struct tm tm_arg;
 time_t time_arg;
 if (argc != 3) {
  printf("Usage: jls DIR TIME\n"
   "DIR - dirname\n"
   "TIME - time in the format DD-MM-YYYY:HH:MM:SS\n");
  return -1;
 }
 strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &tm_arg);
 time_arg = mktime(&tm_arg);
 return jls(argv[1], time_arg);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct tm tm_arg;
 long time_arg;
 if (argc != 3) {
  printf("Usage: jls DIR TIME\n"
   "DIR - dirname\n"
   "TIME - time in the format DD-MM-YYYY:HH:MM:SS\n");
  return -1;
 }
 strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &tm_arg);
 time_arg = mktime(&tm_arg);
 return jls(argv[1], time_arg);
}

variable_types: argc int

variable_types:
argv
char **

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


jrollback

decompiled_code:
__int64 __fastcall jrollback(char *file, int a2)
{
int v3; // esi
int v4; // ebp
int v5; // eax
int v6; // er15
__int64 result; // rax
struct stat v8; // [rsp+10h] [rbp-10D8h] BYREF
int v9[1042]; // [rsp+A0h] [rbp-1048h] BYREF

if ( (int)stat(file, &v8) < 0 )
{
perror("stat");
result = (unsigned int)*__errno_location();
}
else
{
v3 = 0;
if ( (v8.st_mode & 0xF000) != 0x4000 )
v3 = 513;
v4 = open(file, v3);
if ( v4 < 0 )
{
perror("open");
result = (unsigned int)*__errno_location();
}
else
{
memset(v9, 0, 0x1008uLL);
v9[1] = a2;
while ( 1 )
{
v5 = ioctl(v4, 0xC0046666uLL, v9);
v6 = v5;
if ( v5 < 0 )
break;
*((_BYTE *)&v9[2] + v5) = 0;
if ( (v8.st_mode & 0xF000) == 0x4000 )
{
v9[1] = v5;
if ( ioctl(v4, 0x40046668uLL, v9) < 0 )
{
puts("error restoring");
v9[1] = a2;
goto LABEL_10;
}
v9[1] = a2;
if ( v6 <= 4095 )
goto LABEL_10;
}
else
{
if ( (int)write(v4, &v9[2], (unsigned int)v5) < 0 )
{
puts("error restoring");
LABEL_10:
v9[0] += 4096;
memset(&v9[2], 0, 0x1000uLL);
close(v4);
return 0LL;
}
if ( v6 <= 4095 )
goto LABEL_10;
}
v9[0] += 4096;
memset(&v9[2], 0, 0x1000uLL);
}
perror(0LL);
result = (unsigned int)*__errno_location();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *file, int a2)
{
int v3; // esi
int v4; // ebp
int v5; // eax
int v6; // er15
__int64 result; // rax
struct stat v8; // [rsp+10h] [rbp-10D8h] BYREF
int v9[1042]; // [rsp+A0h] [rbp-1048h] BYREF

if ( (int)func10(file, &v8) < 0 )
{
perror("stat");
result = (unsigned int)*__errno_location();
}
else
{
v3 = 0;
if ( (v8.st_mode & 0xF000) != 0x4000 )
v3 = 513;
v4 = open(file, v3);
if ( v4 < 0 )
{
perror("open");
result = (unsigned int)*__errno_location();
}
else
{
memset(v9, 0, 0x1008uLL);
v9[1] = a2;
while ( 1 )
{
v5 = ioctl(v4, 0xC0046666uLL, v9);
v6 = v5;
if ( v5 < 0 )
break;
*((_BYTE *)&v9[2] + v5) = 0;
if ( (v8.st_mode & 0xF000) == 0x4000 )
{
v9[1] = v5;
if ( ioctl(v4, 0x40046668uLL, v9) < 0 )
{
puts("error restoring");
v9[1] = a2;
goto LABEL_10;
}
v9[1] = a2;
if ( v6 <= 4095 )
goto LABEL_10;
}
else
{
if ( (int)write(v4, &v9[2], (unsigned int)v5) < 0 )
{
puts("error restoring");
LABEL_10:
v9[0] += 4096;
memset(&v9[2], 0, 0x1000uLL);
close(v4);
return 0LL;
}
if ( v6 <= 4095 )
goto LABEL_10;
}
v9[0] += 4096;
memset(&v9[2], 0, 0x1000uLL);
}
perror(0LL);
result = (unsigned int)*__errno_location();
}
}
return result;
}

original_code:
static int jrollback(const char *filename, time_t at)
{
 int fd, done = 0, nbytes;
 struct version_buffer ver_buf;
 struct stat info;
 if (stat(filename, &info) < 0) {
  perror("stat");
  return (*__errno_location ());
 }
 if (((((info.st_mode)) & 0170000) == (0040000))) {
  if ((fd = open(filename, 00)) < 0) {
   perror("open");
   return (*__errno_location ());
  }
 } else {
  if ((fd = open(filename, 01|01000)) < 0) {
   perror("open");
   return (*__errno_location ());
  }
 }
 memset(&ver_buf, 0, sizeof(ver_buf));
 ver_buf.at = at;
 while (!done) {
  if ((nbytes = ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((102)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf)) < 0) {
   perror(((void *)0));
   return (*__errno_location ());
  }
  ver_buf.data[nbytes] = 0;
  if (((((info.st_mode)) & 0170000) == (0040000))) {
   ver_buf.at = nbytes;
   if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((104)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf) < 0) {
    printf("error restoring\n");
    done = 1;
   }
   ver_buf.at = at;
  } else {
   if (write(fd, ver_buf.data, nbytes) < 0) {
    printf("error restoring\n");
    done = 1;
   }
  }
  if (nbytes < 4096)
   done = 1;
  ver_buf.offset += 4096;
  memset(ver_buf.data, 0, 4096);
 }
 close(fd);
 return 0;
}

canonical_original_code:
static int jrollback(char *filename, long at)
{
 int fd; int done = 0; int nbytes;
 struct version_buffer ver_buf;
 struct stat info;
 if (stat(filename, &info) < 0) {
  perror("stat");
  return (*__errno_location ());
 }
 if (((((info.st_mode)) & 0170000) == (0040000))) {
  if ((fd = open(filename, 00)) < 0) {
   perror("open");
   return (*__errno_location ());
  }
 } else {
  if ((fd = open(filename, 01|01000)) < 0) {
   perror("open");
   return (*__errno_location ());
  }
 }
 memset(&ver_buf, 0, sizeof(ver_buf));
 ver_buf.at = at;
 while (!done) {
  if ((nbytes = ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((102)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf)) < 0) {
   perror(((void *)0));
   return (*__errno_location ());
  }
  ver_buf.data[nbytes] = 0;
  if (((((info.st_mode)) & 0170000) == (0040000))) {
   ver_buf.at = nbytes;
   if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) | (((104)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ver_buf) < 0) {
    printf("error restoring\n");
    done = 1;
   }
   ver_buf.at = at;
  } else {
   if (write(fd, ver_buf.data, nbytes) < 0) {
    printf("error restoring\n");
    done = 1;
   }
  }
  if (nbytes < 4096)
   done = 1;
  ver_buf.offset += 4096;
  memset(ver_buf.data, 0, 4096);
 }
 close(fd);
 return 0;
}

variable_types:
filename
char *

variable_types: at long

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
struct tm v4; // [rsp+0h] [rbp-48h] BYREF

if ( argc == 3 )
{
strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &v4);
mktime(&v4);
result = jrollback((char *)argv[1]);
}
else
{
puts(
"Usage: jrollback FILE/DIR TIME\n"
"FILE/DIR - file name or directory name\n"
"TIME - time in the format DD-MM-YYYY:HH:MM:SS");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
struct tm v4; // [rsp+0h] [rbp-48h] BYREF

if ( argc == 3 )
{
strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &v4);
mktime(&v4);
result = func7((char *)argv[1]);
}
else
{
puts(
"Usage: jrollback FILE/DIR TIME\n"
"FILE/DIR - file name or directory name\n"
"TIME - time in the format DD-MM-YYYY:HH:MM:SS");
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 struct tm tm_arg;
 time_t time_arg;
 if (argc != 3) {
  printf("Usage: jrollback FILE/DIR TIME\n"
   "FILE/DIR - file name or directory name\n"
   "TIME - time in the format DD-MM-YYYY:HH:MM:SS\n");
  return -1;
 }
 strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &tm_arg);
 time_arg = mktime(&tm_arg);
 return jrollback(argv[1], time_arg);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct tm tm_arg;
 long time_arg;
 if (argc != 3) {
  printf("Usage: jrollback FILE/DIR TIME\n"
   "FILE/DIR - file name or directory name\n"
   "TIME - time in the format DD-MM-YYYY:HH:MM:SS\n");
  return -1;
 }
 strptime(argv[2], "%d-%m-%Y:%H:%M:%S", &tm_arg);
 time_arg = mktime(&tm_arg);
 return jrollback(argv[1], time_arg);
}


decompiled_code:
int init_filehandler()
{
__uid_t v0; // eax
char *v1; // r12
size_t v2; // rax
const char *v3; // r13
size_t v4; // rbx
size_t v5; // rax
int result; // eax

v0 = getuid();
v1 = getpwuid(v0)->pw_dir;
homedir = v1;
v2 = strlen(v1);
v3 = DIR_PATH;
v4 = v2;
v5 = strlen(DIR_PATH);
settingsdir = (__int64)calloc(1uLL, v4 + v5 + 1);
result = sprintf((char *)settingsdir, "%s%s", v1, v3);
if ( !homedir )
{
fwrite("Could not aquire homedir directory", 1uLL, 0x22uLL, stderr);
exit(2);
}
return result;
}

canonical_decompiled_code:
int func0()
{
__uid_t v0; // eax
char *v1; // r12
size_t v2; // rax
const char *v3; // r13
size_t v4; // rbx
size_t v5; // rax
int result; // eax

v0 = getuid();
v1 = getpwuid(v0)->pw_dir;
homedir = v1;
v2 = strlen(v1);
v3 = DIR_PATH;
v4 = v2;
v5 = strlen(DIR_PATH);
settingsdir = (__int64)calloc(1uLL, v4 + v5 + 1);
result = sprintf((char *)settingsdir, "%s%s", v1, v3);
if ( !homedir )
{
fwrite("Could not aquire homedir directory", 1uLL, 0x22uLL, stderr);
exit(2);
}
return result;
}

original_code:
void init_filehandler()
{
 uid_t userid = getuid();
 struct passwd * userpasswd = getpwuid(userid);
 homedir = userpasswd->pw_dir;
 settingsdir = (char *) calloc(1,(strlen(homedir)+strlen(DIR_PATH))+sizeof(char));
 sprintf(settingsdir,"%s%s",homedir,DIR_PATH);
 if(!(homedir))
 {
  fprintf(stderr,"Could not aquire homedir directory");
  exit(2);
 }
}

canonical_original_code:
void init_filehandler()
{
 unsigned int userid = getuid();
 struct passwd *userpasswd = getpwuid(userid);
 homedir = userpasswd->pw_dir;
 settingsdir = (char *) calloc(1,(strlen(homedir)+strlen(DIR_PATH))+sizeof(char));
 sprintf(settingsdir,"%s%s",homedir,DIR_PATH);
 if(!(homedir))
 {
  fprintf(stderr,"Could not aquire homedir directory");
  exit(2);
 }
}

variable_types:
userid
unsigned int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


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

result = settingsdir;
if ( !settingsdir )
{
init_filehandler();
result = settingsdir;
}
return result;
}

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

result = settingsdir;
if ( !settingsdir )
{
func0();
result = settingsdir;
}
return result;
}

original_code:
char * get_settingsdir()
{
 if(!settingsdir)
  init_filehandler();
 return settingsdir;
}

canonical_original_code:
char *get_settingsdir()
{
 if(!settingsdir)
  init_filehandler();
 return settingsdir;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r15
const char *v4; // rbp
int v5; // er14
int v7; // eax
int *v8; // rax
const char *v9; // rax
int v10; // eax
int v11; // er12
int v12; // ebx
unsigned __int64 v13; // r14
__int64 v14; // rsi
int v15; // [rsp+Ch] [rbp-8Ch]
unsigned __int64 size; // [rsp+10h] [rbp-88h]
__int64 i; // [rsp+18h] [rbp-80h]
const char *v18; // [rsp+20h] [rbp-78h]
const char *v19; // [rsp+28h] [rbp-70h]
const char *v20; // [rsp+30h] [rbp-68h]
const char *v21; // [rsp+38h] [rbp-60h]
char *buf; // [rsp+40h] [rbp-58h]
int v23; // [rsp+48h] [rbp-50h]
const char *v24; // [rsp+58h] [rbp-40h]

v3 = 8LL;
v4 = "'\\x%02X'";
opterr = 0;
v21 = "size_t";
v19 = "";
v20 = "_len";
v18 = "out";
v15 = 0;
size = 4096LL;
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "hl:n:s:q:pf:t:b:");
if ( v5 == -1 )
{
buf = (char *)malloc(size);
if ( buf )
{
v9 = "";
if ( *v19 )
v9 = " ";
v24 = v9;
printf("%s%schar %s[] = {\n ", v19, v9, v18);
for ( i = 0LL; ; i += (unsigned int)(v23 - 1) + 1LL )
{
v10 = read(0, buf, size);
v11 = v10;
if ( v10 < 0 )
{
perror("read");
return 127;
}
if ( !v10 )
break;
v23 = v10;
v12 = 0;
v13 = i;
do
{
if ( v13 )
{
if ( v13 % v3 )
printf(", ");
else
printf(",\n ");
}
v14 = (unsigned __int8)buf[v13 - i];
++v12;
++v13;
printf(v4, v14);
}
while ( v11 > v12 );
}
puts("\n};");
if ( v15 )
{
printf("%s%s%s %s%s = %zu;\n", v19, v24, v21, v18, v20, i);
v15 = 0;
}
}
else
{
fwrite("error: failed to allocate input buffer\n", 1uLL, 0x27uLL, stderr);
v15 = 116;
}
}
else
{
switch ( v5 )
{
case '?':
fprintf(stderr, "error: unknown or poorly-used option -%c, use -h for help\n", (unsigned int)optopt);
v15 = 105;
break;
case 'b':
size = strtoul(_bss_start, 0LL, 10);
v8 = __errno_location();
if ( *v8 != 34 && *v8 != 22 && size < 0x80000000 )
continue;
fwrite("error: -b takes a reasonably-bounded integer in decimal >= 1\n", 1uLL, 0x3DuLL, stderr);
v15 = v5;
break;
case 'f':
v4 = _bss_start;
continue;
case 'h':
help();
v15 = 0;
break;
case 'l':
v3 = strtol(_bss_start, 0LL, 10);
v7 = *__errno_location();
if ( v7 != 22 && v7 != 34 && v3 - 1 <= 0x7FFFFFFE )
continue;
fwrite("error: -l takes a reasonably-bounded integer in decimal >= 1\n", 1uLL, 0x3DuLL, stderr);
v15 = 71;
break;
case 'n':
v18 = _bss_start;
continue;
case 'p':
v15 = 1;
continue;
case 'q':
v19 = _bss_start;
continue;
case 's':
v20 = _bss_start;
continue;
case 't':
v21 = _bss_start;
continue;
default:
fwrite("error: option parser internal failure\n", 1uLL, 0x26uLL, stderr);
v15 = 109;
break;
}
}
break;
}
return v15;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r15
const char *v4; // rbp
int v5; // er14
int v7; // eax
int *v8; // rax
const char *v9; // rax
int v10; // eax
int v11; // er12
int v12; // ebx
unsigned __int64 v13; // r14
__int64 v14; // rsi
int v15; // [rsp+Ch] [rbp-8Ch]
unsigned __int64 size; // [rsp+10h] [rbp-88h]
__int64 i; // [rsp+18h] [rbp-80h]
const char *v18; // [rsp+20h] [rbp-78h]
const char *v19; // [rsp+28h] [rbp-70h]
const char *v20; // [rsp+30h] [rbp-68h]
const char *v21; // [rsp+38h] [rbp-60h]
char *buf; // [rsp+40h] [rbp-58h]
int v23; // [rsp+48h] [rbp-50h]
const char *v24; // [rsp+58h] [rbp-40h]

v3 = 8LL;
v4 = "'\\x%02X'";
opterr = 0;
v21 = "size_t";
v19 = "";
v20 = "_len";
v18 = "out";
v15 = 0;
size = 4096LL;
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "hl:n:s:q:pf:t:b:");
if ( v5 == -1 )
{
buf = (char *)malloc(size);
if ( buf )
{
v9 = "";
if ( *v19 )
v9 = " ";
v24 = v9;
printf("%s%schar %s[] = {\n ", v19, v9, v18);
for ( i = 0LL; ; i += (unsigned int)(v23 - 1) + 1LL )
{
v10 = read(0, buf, size);
v11 = v10;
if ( v10 < 0 )
{
perror("read");
return 127;
}
if ( !v10 )
break;
v23 = v10;
v12 = 0;
v13 = i;
do
{
if ( v13 )
{
if ( v13 % v3 )
printf(", ");
else
printf(",\n ");
}
v14 = (unsigned __int8)buf[v13 - i];
++v12;
++v13;
printf(v4, v14);
}
while ( v11 > v12 );
}
puts("\n};");
if ( v15 )
{
printf("%s%s%s %s%s = %zu;\n", v19, v24, v21, v18, v20, i);
v15 = 0;
}
}
else
{
fwrite("error: failed to allocate input buffer\n", 1uLL, 0x27uLL, stderr);
v15 = 116;
}
}
else
{
switch ( v5 )
{
case '?':
fprintf(stderr, "error: unknown or poorly-used option -%c, use -h for help\n", (unsigned int)optopt);
v15 = 105;
break;
case 'b':
size = strtoul(_bss_start, 0LL, 10);
v8 = __errno_location();
if ( *v8 != 34 && *v8 != 22 && size < 0x80000000 )
continue;
fwrite("error: -b takes a reasonably-bounded integer in decimal >= 1\n", 1uLL, 0x3DuLL, stderr);
v15 = v5;
break;
case 'f':
v4 = _bss_start;
continue;
case 'h':
func7();
v15 = 0;
break;
case 'l':
v3 = strtol(_bss_start, 0LL, 10);
v7 = *__errno_location();
if ( v7 != 22 && v7 != 34 && v3 - 1 <= 0x7FFFFFFE )
continue;
fwrite("error: -l takes a reasonably-bounded integer in decimal >= 1\n", 1uLL, 0x3DuLL, stderr);
v15 = 71;
break;
case 'n':
v18 = _bss_start;
continue;
case 'p':
v15 = 1;
continue;
case 'q':
v19 = _bss_start;
continue;
case 's':
v20 = _bss_start;
continue;
case 't':
v21 = _bss_start;
continue;
default:
fwrite("error: option parser internal failure\n", 1uLL, 0x26uLL, stderr);
v15 = 109;
break;
}
}
break;
}
return v15;
}

original_code:
int
main(const int argc, char **argv)
{
  long line_len, buf_len;
  int print_len;
  const char *nam, *len_sfx, *quals, *char_fmt, *len_typ, *quals_spc;
  size_t tc;
  int i, r;
  char *buf;
  line_len = 8;
  nam = "out";
  len_sfx = "_len";
  quals = "";
  print_len = 0;
  char_fmt = "'\\x%02X'";
  len_typ = "size_t";
  buf_len = 4096;
  opterr = 0;
  while (-1 != (r = getopt(argc, argv, "hl:n:s:q:pf:t:b:"))) {
    switch(r) {
      case 'h':
        help();
        return 0;
        break;
      case 'l':
        line_len = strtol(optarg, ((void *)0), 10);
        if (22 == (*__errno_location ()) || 34 == (*__errno_location ()) || 1 > line_len ||
            0x7fffffff < line_len) {
          fprintf(stderr,
            "error: -l takes a reasonably-bounded integer in decimal >= 1\n");
          return 71;
        }
        break;
      case 'n':
        nam = optarg;
        break;
      case 's':
        len_sfx = optarg;
        break;
      case 'q':
        quals = optarg;
        break;
      case 'p':
        print_len = 1;
        break;
      case 'f':
        char_fmt = optarg;
        break;
      case 't':
        len_typ = optarg;
        break;
      case 'b':
        buf_len = strtoul(optarg, ((void *)0), 10);
        if (22 == (*__errno_location ()) || 34 == (*__errno_location ()) || 0 > buf_len ||
            0x7fffffff < buf_len) {
          fprintf(stderr,
            "error: -b takes a reasonably-bounded integer in decimal >= 1\n");
          return 98;
        }
        break;
      case '?':
        fprintf(stderr,
          "error: unknown or poorly-used option -%c, use -h for help\n",
          optopt);
        return 105;
        break;
      default:
        fprintf(stderr, "error: option parser internal failure\n");
        return 109;
    }
  }
  buf = (char *)malloc(buf_len * sizeof(char));
  if (((void *)0) == buf) {
    fprintf(stderr, "error: failed to allocate input buffer\n");
    return 116;
  }
  quals_spc = 0 < strlen(quals) ? " " : "";
  printf("%s%schar %s[] = {\n  ", quals, quals_spc, nam);
  for (tc = 0;;) {
    r = read(0, buf, buf_len);
    if (0 > r) {
      perror("read");
      return 127;
    }
    if (0 == r)
      break;
    for (i = 0; i < r; i++, tc++) {
      if (0 < tc) {
        if (tc % line_len == 0)
          printf(",\n  ");
        else
          printf(", ");
      }
      printf(char_fmt, 0xff & buf[i]);
    }
  }
  printf("\n};\n");
  if (print_len)
    printf("%s%s%s %s%s = %zu;\n", quals, quals_spc, len_typ, nam, len_sfx,
      tc);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  long line_len; long buf_len;
  int print_len;
  char *nam; char *len_sfx; char *quals; char *char_fmt; char *len_typ; char *quals_spc;
  unsigned long tc;
  int i; int r;
  char *buf;
  line_len = 8;
  nam = "out";
  len_sfx = "_len";
  quals = "";
  print_len = 0;
  char_fmt = "'\\x%02X'";
  len_typ = "size_t";
  buf_len = 4096;
  opterr = 0;
  while (-1 != (r = getopt(argc, argv, "hl:n:s:q:pf:t:b:"))) {
    switch(r) {
      case 'h':
        help();
        return 0;
        break;
      case 'l':
        line_len = strtol(optarg, ((void *)0), 10);
        if (22 == (*__errno_location ()) || 34 == (*__errno_location ()) || 1 > line_len ||
            0x7fffffff < line_len) {
          fprintf(stderr,
            "error: -l takes a reasonably-bounded integer in decimal >= 1\n");
          return 71;
        }
        break;
      case 'n':
        nam = optarg;
        break;
      case 's':
        len_sfx = optarg;
        break;
      case 'q':
        quals = optarg;
        break;
      case 'p':
        print_len = 1;
        break;
      case 'f':
        char_fmt = optarg;
        break;
      case 't':
        len_typ = optarg;
        break;
      case 'b':
        buf_len = strtoul(optarg, ((void *)0), 10);
        if (22 == (*__errno_location ()) || 34 == (*__errno_location ()) || 0 > buf_len ||
            0x7fffffff < buf_len) {
          fprintf(stderr,
            "error: -b takes a reasonably-bounded integer in decimal >= 1\n");
          return 98;
        }
        break;
      case '?':
        fprintf(stderr,
          "error: unknown or poorly-used option -%c, use -h for help\n",
          optopt);
        return 105;
        break;
      default:
        fprintf(stderr, "error: option parser internal failure\n");
        return 109;
    }
  }
  buf = (char *)malloc(buf_len * sizeof(char));
  if (((void *)0) == buf) {
    fprintf(stderr, "error: failed to allocate input buffer\n");
    return 116;
  }
  quals_spc = 0 < strlen(quals) ? " " : "";
  printf("%s%schar %s[] = {\n  ", quals, quals_spc, nam);
  for (tc = 0;;) {
    r = read(0, buf, buf_len);
    if (0 > r) {
      perror("read");
      return 127;
    }
    if (0 == r)
      break;
    for (i = 0; i < r; i++, tc++) {
      if (0 < tc) {
        if (tc % line_len == 0)
          printf(",\n  ");
        else
          printf(", ");
      }
      printf(char_fmt, 0xff & buf[i]);
    }
  }
  printf("\n};\n");
  if (print_len)
    printf("%s%s%s %s%s = %zu;\n", quals, quals_spc, len_typ, nam, len_sfx,
      tc);
  return 0;
}

variable_types:
nam
char *

variable_types:
quals
char *

variable_types:
tc
unsigned long

variable_types: r int

variable_types:
buf
char *


help

decompiled_code:
int help()
{
return puts(
"usage: b2c [options]\n"
"\n"
"-h show this help\n"
"-l <line length> line length\n"
"-n <name> array name and length prefix\n"
"-s <suffix> length suffix (default: \"len\")\n"
"-q <qualifiers> array and length qualifiers\n"
"-p print length\n"
"-f <character format> printf format for each character\n"
"-t <length type> length type (default: size_t)\n"
"-b <buffer length> input buffer length");
}

canonical_decompiled_code:
int func7()
{
return puts(
"usage: b2c [options]\n"
"\n"
"-h show this help\n"
"-l <line length> line length\n"
"-n <name> array name and length prefix\n"
"-s <suffix> length suffix (default: \"len\")\n"
"-q <qualifiers> array and length qualifiers\n"
"-p print length\n"
"-f <character format> printf format for each character\n"
"-t <length type> length type (default: size_t)\n"
"-b <buffer length> input buffer length");
}

original_code:
static void
help(void) {
  printf(
    "usage: b2c [options]\n"
    "\n"
    "-h                     show this help\n"
    "-l <line length>       line length\n"
    "-n <name>              array name and length prefix\n"
    "-s <suffix>            length suffix (default: \"len\")\n"
    "-q <qualifiers>        array and length qualifiers\n"
    "-p                     print length\n"
    "-f <character format>  printf format for each character\n"
    "-t <length type>       length type (default: size_t)\n"
    "-b <buffer length>     input buffer length\n"
    );
}

canonical_original_code:
static void help() {
  printf(
    "usage: b2c [options]\n"
    "\n"
    "-h                     show this help\n"
    "-l <line length>       line length\n"
    "-n <name>              array name and length prefix\n"
    "-s <suffix>            length suffix (default: \"len\")\n"
    "-q <qualifiers>        array and length qualifiers\n"
    "-p                     print length\n"
    "-f <character format>  printf format for each character\n"
    "-t <length type>       length type (default: size_t)\n"
    "-b <buffer length>     input buffer length\n"
    );
}


CriticalError

repo: ksheedlo/kmdata

decompiled_code:
int __fastcall CriticalError(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void CriticalError(char *str){
    fprintf(stderr, "%s\n", str);
}

variable_types:
str
char *


original_code:
struct hwa_info *
get_hw_addrs()
{
 struct hwa_info *hwa, *hwahead, **hwapnext;
 int sockfd, len, lastlen, alias;
 char *ptr, *buf, lastname[16], *cptr;
 struct ifconf ifc;
 struct ifreq *ifr, ifrcopy;
 struct sockaddr *sinptr;
 sockfd = socket(2, SOCK_DGRAM, 0);
 lastlen = 0;
 len = 100 * sizeof(struct ifreq);
 for ( ; ; ) {
  buf = (char*) malloc(len);
  ifc.ifc_len = len;
  ifc.ifc_ifcu.ifcu_buf = buf;
  if (ioctl(sockfd, 0x8912, &ifc) < 0) {
   if ((*__errno_location ()) != 22 || lastlen != 0)
    perror("ioctl error");
  } else {
   if (ifc.ifc_len == lastlen)
    break;
   lastlen = ifc.ifc_len;
  }
  len += 10 * sizeof(struct ifreq);
  free(buf);
 }
 hwahead = ((void *)0);
 hwapnext = &hwahead;
 lastname[0] = 0;
 for (ptr = buf; ptr < buf + ifc.ifc_len; ) {
  ifr = (struct ifreq *) ptr;
  len = sizeof(struct sockaddr);
  ptr += sizeof(ifr->ifr_ifrn.ifrn_name) + len;
  alias = 0;
  hwa = (struct hwa_info *) calloc(1, sizeof(struct hwa_info));
  memcpy(hwa->if_name, ifr->ifr_ifrn.ifrn_name, 16);
  hwa->if_name[16 -1] = '\0';
  if ( (cptr = (char *) strchr(ifr->ifr_ifrn.ifrn_name, ':')) != ((void *)0))
   *cptr = 0;
  if (strncmp(lastname, ifr->ifr_ifrn.ifrn_name, 16) == 0) {
   alias = 1;
  }
  memcpy(lastname, ifr->ifr_ifrn.ifrn_name, 16);
  ifrcopy = *ifr;
  *hwapnext = hwa;
  hwapnext = &hwa->hwa_next;
  hwa->ip_alias = alias;
                sinptr = &ifr->ifr_ifru.ifru_addr;
  hwa->ip_addr = (struct sockaddr *) calloc(1, sizeof(struct sockaddr));
         memcpy(hwa->ip_addr, sinptr, sizeof(struct sockaddr));
  ioctl(sockfd, 0x8927, &ifrcopy);
  memcpy(hwa->if_haddr, ifrcopy.ifr_ifru.ifru_hwaddr.sa_data, 6);
  ioctl(sockfd, 0x8933, &ifrcopy);
  memcpy(&hwa->if_index, &ifrcopy.ifr_ifru.ifru_ivalue, sizeof(int));
 }
 free(buf);
 return(hwahead);
}

canonical_original_code:
struct hwa_info *get_hw_addrs()
{
 struct hwa_info *hwa; struct hwa_info *hwahead; struct hwa_info **hwapnext;
 int sockfd; int len; int lastlen; int alias;
 char *ptr; char *buf; char lastname[16]; char *cptr;
 struct ifconf ifc;
 struct ifreq *ifr; struct ifreq ifrcopy;
 struct sockaddr *sinptr;
 sockfd = socket(2, SOCK_DGRAM, 0);
 lastlen = 0;
 len = 100 * sizeof(struct ifreq);
 for ( ; ; ) {
  buf = (char *) malloc(len);
  ifc.ifc_len = len;
  ifc.ifc_ifcu.ifcu_buf = buf;
  if (ioctl(sockfd, 0x8912, &ifc) < 0) {
   if ((*__errno_location ()) != 22 || lastlen != 0)
    perror("ioctl error");
  } else {
   if (ifc.ifc_len == lastlen)
    break;
   lastlen = ifc.ifc_len;
  }
  len += 10 * sizeof(struct ifreq);
  free(buf);
 }
 hwahead = ((void *)0);
 hwapnext = &hwahead;
 lastname[0] = 0;
 for (ptr = buf; ptr < buf + ifc.ifc_len; ) {
  ifr = (struct ifreq *) ptr;
  len = sizeof(struct sockaddr);
  ptr += sizeof(ifr->ifr_ifrn.ifrn_name) + len;
  alias = 0;
  hwa = (struct hwa_info *) calloc(1, sizeof(struct hwa_info));
  memcpy(hwa->if_name, ifr->ifr_ifrn.ifrn_name, 16);
  hwa->if_name[16 -1] = '\0';
  if ( (cptr = (char *) strchr(ifr->ifr_ifrn.ifrn_name, ':')) != ((void *)0))
   *cptr = 0;
  if (strncmp(lastname, ifr->ifr_ifrn.ifrn_name, 16) == 0) {
   alias = 1;
  }
  memcpy(lastname, ifr->ifr_ifrn.ifrn_name, 16);
  ifrcopy = *ifr;
  *hwapnext = hwa;
  hwapnext = &hwa->hwa_next;
  hwa->ip_alias = alias;
                sinptr = &ifr->ifr_ifru.ifru_addr;
  hwa->ip_addr = (struct sockaddr *) calloc(1, sizeof(struct sockaddr));
         memcpy(hwa->ip_addr, sinptr, sizeof(struct sockaddr));
  ioctl(sockfd, 0x8927, &ifrcopy);
  memcpy(hwa->if_haddr, ifrcopy.ifr_ifru.ifru_hwaddr.sa_data, 6);
  ioctl(sockfd, 0x8933, &ifrcopy);
  memcpy(&hwa->if_index, &ifrcopy.ifr_ifru.ifru_ivalue, sizeof(int));
 }
 free(buf);
 return(hwahead);
}

variable_types: struct hwa_info { char if_name[16]; char if_haddr[6]; int if_index; short ip_alias; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ip_addr; struct hwa_info *hwa_next; } **

variable_types: sockfd int

variable_types: len int

variable_types: lastlen int

variable_types: alias int

variable_types:
ptr
char *

variable_types:
lastname
char [16]

variable_types:
cptr
char *

variable_types: struct ifconf { int ifc_len; union { char *ifcu_buf; 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; } *ifcu_req; } ifc_ifcu; }

user_defined_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }

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 hwa_info { char if_name[16]; char if_haddr[6]; int if_index; short ip_alias; struct sockaddr *ip_addr; struct hwa_info *hwa_next; }