decompiled_code:
char *__fastcall bencode_dct(__int64 a1)
{
char *v1; // rbx
char *v2; // r12
size_t v3; // rbp
size_t v4; // rax
char *v5; // rax
char *v6; // rbp
size_t v7; // r13
__int64 v8; // r12
int v9; // er14
char *v10; // rax
size_t v11; // rax
char *v12; // rax
size_t v14; // [rsp+8h] [rbp-40h]

v1 = *(char **)(a1 + 8);
if ( v1 )
{
v1 = bencode_str(*(char **)a1);
if ( v1 )
{
v2 = benc_encode(*(_QWORD *)(a1 + 8));
if ( v2 )
{
v3 = strlen(v1);
v4 = strlen(v2);
v5 = (char *)malloc(v3 + v4 + 1);
v6 = v5;
if ( v5 )
{
sprintf(v5, "%s%s", v1, v2);
free(v1);
free(v2);
v7 = strlen(v6) + 1;
v8 = a1 + 16;
if ( *(_QWORD *)(a1 + 24) )
{
v9 = 1;
while ( 1 )
{
v1 = bencode_str(*(char **)v8);
if ( !v1 )
break;
v2 = benc_encode(*(_QWORD *)(v8 + 8));
if ( !v2 )
{
free(v1);
free(v6);
return 0LL;
}
v14 = strlen(v1);
v7 += v14 + strlen(v2);
v10 = (char *)realloc(v6, v7);
v6 = v10;
if ( !v10 )
goto LABEL_16;
strcat(v10, v1);
strcat(v6, v2);
free(v1);
free(v2);
v8 = a1 + 16LL * (unsigned int)++v9;
if ( !*(_QWORD *)(v8 + 8) )
goto LABEL_11;
}
}
else
{
LABEL_11:
v11 = strlen(v6);
v12 = (char *)malloc(v11 + 3);
v1 = v12;
if ( v12 )
sprintf(v12, "d%se", v6);
}
free(v6);
}
else
{
LABEL_16:
free(v2);
free(v1);
v1 = 0LL;
}
}
else
{
free(v1);
v1 = 0LL;
}
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
char *v1; // rbx
char *v2; // r12
size_t v3; // rbp
size_t v4; // rax
char *v5; // rax
char *v6; // rbp
size_t v7; // r13
__int64 v8; // r12
int v9; // er14
char *v10; // rax
size_t v11; // rax
char *v12; // rax
size_t v14; // [rsp+8h] [rbp-40h]

v1 = *(char **)(a1 + 8);
if ( v1 )
{
v1 = func3(*(char **)a1);
if ( v1 )
{
v2 = func5(*(_QWORD *)(a1 + 8));
if ( v2 )
{
v3 = strlen(v1);
v4 = strlen(v2);
v5 = (char *)malloc(v3 + v4 + 1);
v6 = v5;
if ( v5 )
{
sprintf(v5, "%s%s", v1, v2);
free(v1);
free(v2);
v7 = strlen(v6) + 1;
v8 = a1 + 16;
if ( *(_QWORD *)(a1 + 24) )
{
v9 = 1;
while ( 1 )
{
v1 = func3(*(char **)v8);
if ( !v1 )
break;
v2 = func5(*(_QWORD *)(v8 + 8));
if ( !v2 )
{
free(v1);
free(v6);
return 0LL;
}
v14 = strlen(v1);
v7 += v14 + strlen(v2);
v10 = (char *)realloc(v6, v7);
v6 = v10;
if ( !v10 )
goto LABEL_16;
strcat(v10, v1);
strcat(v6, v2);
free(v1);
free(v2);
v8 = a1 + 16LL * (unsigned int)++v9;
if ( !*(_QWORD *)(v8 + 8) )
goto LABEL_11;
}
}
else
{
LABEL_11:
v11 = strlen(v6);
v12 = (char *)malloc(v11 + 3);
v1 = v12;
if ( v12 )
sprintf(v12, "d%se", v6);
}
free(v6);
}
else
{
LABEL_16:
free(v2);
free(v1);
v1 = 0LL;
}
}
else
{
free(v1);
v1 = 0LL;
}
}
}
return v1;
}

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 *


repo: krosswindz/tmst

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

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

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

v0 = (void **)malloc(0x20uLL);
v1 = v0;
if ( !v0 )
return 0LL;
v0[3] = 0LL;
*v0 = strdup("failure reason");
v2 = new_benc_data(3);
if ( v2 )
{
v3 = strdup("Missing passkey, re-download torrent from forum.");
v2[1] = v3;
if ( v3 )
{
v1[1] = v2;
v4 = new_benc_data(0);
v5 = v4;
if ( v4 )
{
v4[1] = v1;
v2 = func5((__int64)v4);
func0(v5);
}
else
{
func0(v1[1]);
free(*v1);
free(v1);
v2 = 0LL;
}
}
else
{
free(v2);
free(*v1);
free(v1);
v2 = 0LL;
}
}
else
{
free(*v1);
free(v1);
}
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;
}

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:
str
char *

return_type: char *

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:
_QWORD *bad_request()
{
void **v0; // rax
void **v1; // rbp
_QWORD *v2; // rbx
char *v3; // r12
_QWORD *v4; // rax
_QWORD *v5; // r12

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

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

v0 = (void **)malloc(0x20uLL);
v1 = v0;
if ( !v0 )
return 0LL;
v0[3] = 0LL;
*v0 = strdup("failure reason");
v2 = new_benc_data(3);
if ( v2 )
{
v3 = strdup("Bad request, unsupported request from client.");
v2[1] = v3;
if ( v3 )
{
v1[1] = v2;
v4 = new_benc_data(0);
v5 = v4;
if ( v4 )
{
v4[1] = v1;
v2 = func5((__int64)v4);
func0(v5);
}
else
{
func0(v1[1]);
free(*v1);
free(v1);
v2 = 0LL;
}
}
else
{
free(v2);
free(*v1);
free(v1);
v2 = 0LL;
}
}
else
{
free(*v1);
free(v1);
}
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;
}

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

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


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

return_type: void


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(1u, "%s_%d, %s: ERROR: faild to connect to database, error: %s\n", "sql.c", 35LL, "sql_init", v2);
result = 0xFFFFFFFFLL;
}
}
else
{
logger(1u, "%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(1u, "%s_%d, %s: ERROR: faild to connect to database, error: %s\n", "sql.c", 35LL, "sql_init", v2);
result = 0xFFFFFFFFLL;
}
}
else
{
func0(1u, "%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; // ebx
int v6; // ebp
int v8[8]; // [rsp+8h] [rbp-20h] BYREF

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

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

v4 = open(a1, 0);
if ( v4 < 0 )
{
v6 = *__errno_location();
perror(0LL);
}
else
{
v5 = v4;
v8[0] = a2;
v8[1] = a3;
v6 = ioctl(v4, 0x40046664uLL, v8);
if ( v6 < 0 )
{
v6 = *__errno_location();
perror(0LL);
}
if ( v5 > 0 )
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; // ebx
int v3; // ebp

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 > 0 )
close(v2);
}
return (unsigned int)v3;
}

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

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 > 0 )
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; // ebx
int v3; // ebp

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 > 0 )
close(v2);
}
return (unsigned int)v3;
}

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

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 > 0 )
close(v2);
}
return (unsigned int)v3;
}


dump

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

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 > 0 )
close(v2);
}
return (unsigned int)v3;
}

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

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 > 0 )
close(v2);
}
return (unsigned int)v3;
}


reset

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

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 > 0 )
close(v2);
}
return (unsigned int)v3;
}

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

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 > 0 )
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
int v4; // er12
int v5; // er14
int v6; // eax
int result; // eax

v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "a:t:p:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'p':
v4 = strtol(optarg, 0LL, 10);
break;
case 't':
if ( !strcmp(optarg, "all") )
{
v5 = 1;
}
else if ( !strcmp(optarg, "time") )
{
v5 = 3;
}
else
{
if ( strcmp(optarg, "number") )
{
usage();
exit(1);
}
v5 = 2;
}
break;
case 'a':
if ( !strcmp(optarg, "version") )
{
v3 = 1;
}
else if ( !strcmp(optarg, "unversion") )
{
v3 = 2;
}
else if ( !strcmp(optarg, "prune") )
{
v3 = 3;
}
else if ( !strcmp(optarg, "dump") )
{
v3 = 4;
}
else
{
if ( strcmp(optarg, "reset") )
{
usage();
exit(1);
}
v3 = 5;
}
break;
default:
usage();
exit(1);
}
}
switch ( v3 )
{
case 1:
result = version(argv[_bss_start], v5, v4);
break;
case 2:
result = unversion(argv[_bss_start]);
break;
case 3:
result = prune(argv[_bss_start]);
break;
case 4:
result = dump(argv[_bss_start]);
break;
case 5:
result = reset(argv[_bss_start]);
break;
default:
result = -22;
break;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // er14
int v6; // eax
int result; // eax

v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "a:t:p:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'p':
v4 = strtol(optarg, 0LL, 10);
break;
case 't':
if ( !strcmp(optarg, "all") )
{
v5 = 1;
}
else if ( !strcmp(optarg, "time") )
{
v5 = 3;
}
else
{
if ( strcmp(optarg, "number") )
{
func7();
exit(1);
}
v5 = 2;
}
break;
case 'a':
if ( !strcmp(optarg, "version") )
{
v3 = 1;
}
else if ( !strcmp(optarg, "unversion") )
{
v3 = 2;
}
else if ( !strcmp(optarg, "prune") )
{
v3 = 3;
}
else if ( !strcmp(optarg, "dump") )
{
v3 = 4;
}
else
{
if ( strcmp(optarg, "reset") )
{
func7();
exit(1);
}
v3 = 5;
}
break;
default:
func7();
exit(1);
}
}
switch ( v3 )
{
case 1:
result = func8(argv[_bss_start], v5, v4);
break;
case 2:
result = func9(argv[_bss_start]);
break;
case 3:
result = func10(argv[_bss_start]);
break;
case 4:
result = func11(argv[_bss_start]);
break;
case 5:
result = func12(argv[_bss_start]);
break;
default:
result = -22;
break;
}
return result;
}

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; // ebp
__int64 result; // rax
int v5; // eax
int v6; // ebx
int v7[1034]; // [rsp+0h] [rbp-1028h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax
int v5; // eax
int v6; // ebx
int v7[1034]; // [rsp+0h] [rbp-1028h] BYREF

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

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)
{
int v3; // eax
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)
{
int v3; // eax
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; // er12
int result; // eax
int i; // ebx
int *v6; // rdi
int v7; // ebp
int v8[1034]; // [rsp+0h] [rbp-1028h] BYREF

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

canonical_decompiled_code:
int __fastcall func7(const char *a1, int a2)
{
int v2; // eax
int v3; // er12
int result; // eax
int i; // ebx
int *v6; // rdi
int v7; // ebp
int v8[1034]; // [rsp+0h] [rbp-1028h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror(0LL);
result = *__errno_location();
}
else
{
v3 = v2;
memset(v8, 0, 0x1008uLL);
v8[1] = a2;
while ( 1 )
{
v7 = ioctl(v3, 0xC0046666uLL, v8);
if ( v7 > 0 )
{
for ( i = 0; i < v7; i += 64 )
{
v6 = &v8[i / 4u + 2];
if ( *v6 )
puts((const char *)v6 + 4);
}
}
if ( v7 <= 4095 )
break;
v8[0] += 4096;
memset(&v8[2], 0, 0x1000uLL);
}
v8[0] += 4096;
memset(&v8[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)
{
int v3; // eax
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)
{
int v3; // eax
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 v2; // ebp
int v5; // esi
int v6; // eax
int v7; // ebx
struct stat v8; // [rsp+0h] [rbp-10C8h] BYREF
int v9[1038]; // [rsp+90h] [rbp-1038h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(char *file, int a2)
{
int v2; // ebp
int v5; // esi
int v6; // eax
int v7; // ebx
struct stat v8; // [rsp+0h] [rbp-10C8h] BYREF
int v9[1038]; // [rsp+90h] [rbp-1038h] BYREF

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

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 v3; // eax
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 = jrollback((char *)argv[1], v3);
}
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 v3; // eax
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((char *)argv[1], v3);
}
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; // rbx
size_t v2; // rbp
const char *v3; // r12
size_t v4; // rax
int result; // eax

v0 = getuid();
v1 = getpwuid(v0)->pw_dir;
homedir = v1;
v2 = strlen(v1);
v3 = DIR_PATH;
v4 = strlen(DIR_PATH);
settingsdir = (__int64)calloc(1uLL, v2 + v4 + 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; // rbx
size_t v2; // rbp
const char *v3; // r12
size_t v4; // rax
int result; // eax

v0 = getuid();
v1 = getpwuid(v0)->pw_dir;
homedir = v1;
v2 = strlen(v1);
v3 = DIR_PATH;
v4 = strlen(DIR_PATH);
settingsdir = (__int64)calloc(1uLL, v2 + v4 + 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()
{
if ( !settingsdir )
init_filehandler();
return settingsdir;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !settingsdir )
func0();
return settingsdir;
}

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

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


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"
    );
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
int v4; // ebx
__int64 v6; // rbx
int v7; // eax
unsigned __int64 v8; // r13
int *v9; // rax
const char *v10; // rax
int v11; // ebp
size_t v12; // rbx
int v13; // eax
int v14; // er14
int v15; // er12
int v16; // [rsp+Ch] [rbp-8Ch]
unsigned __int64 v17; // [rsp+10h] [rbp-88h]
size_t size; // [rsp+18h] [rbp-80h]
size_t sizea; // [rsp+18h] [rbp-80h]
const char *v20; // [rsp+20h] [rbp-78h]
const char *v21; // [rsp+28h] [rbp-70h]
const char *v22; // [rsp+30h] [rbp-68h]
const char *v23; // [rsp+38h] [rbp-60h]
char *buf; // [rsp+40h] [rbp-58h]
int v25; // [rsp+48h] [rbp-50h]
size_t nbytes; // [rsp+50h] [rbp-48h]
const char *v27; // [rsp+58h] [rbp-40h]

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
int v4; // ebx
__int64 v6; // rbx
int v7; // eax
unsigned __int64 v8; // r13
int *v9; // rax
const char *v10; // rax
int v11; // ebp
size_t v12; // rbx
int v13; // eax
int v14; // er14
int v15; // er12
int v16; // [rsp+Ch] [rbp-8Ch]
unsigned __int64 v17; // [rsp+10h] [rbp-88h]
size_t size; // [rsp+18h] [rbp-80h]
size_t sizea; // [rsp+18h] [rbp-80h]
const char *v20; // [rsp+20h] [rbp-78h]
const char *v21; // [rsp+28h] [rbp-70h]
const char *v22; // [rsp+30h] [rbp-68h]
const char *v23; // [rsp+38h] [rbp-60h]
char *buf; // [rsp+40h] [rbp-58h]
int v25; // [rsp+48h] [rbp-50h]
size_t nbytes; // [rsp+50h] [rbp-48h]
const char *v27; // [rsp+58h] [rbp-40h]

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

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 *


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


decompiled_code:
void __fastcall free_hwa_info(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

v1 = (void **)ptr;
if ( ptr )
{
do
{
free(v1[4]);
v2 = v1;
v1 = (void **)v1[5];
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

v1 = (void **)ptr;
if ( ptr )
{
do
{
free(v1[4]);
v2 = v1;
v1 = (void **)v1[5];
free(v2);
}
while ( v1 );
}
}

original_code:
void
free_hwa_info(struct hwa_info *hwahead)
{
 struct hwa_info *hwa, *hwanext;
 for (hwa = hwahead; hwa != ((void *)0); hwa = hwanext) {
  free(hwa->ip_addr);
  hwanext = hwa->hwa_next;
  free(hwa);
 }
}

canonical_original_code:
void free_hwa_info(struct hwa_info *hwahead)
{
 struct hwa_info *hwa; struct hwa_info *hwanext;
 for (hwa = hwahead; hwa != ((void *)0); hwa = hwanext) {
  free(hwa->ip_addr);
  hwanext = hwa->hwa_next;
  free(hwa);
 }
}

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


decompiled_code:
__int64 Get_hw_addrs()
{
__int64 v0; // rbx

v0 = get_hw_addrs();
if ( !v0 )
perror("get_hw_addrs error");
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx

v0 = func0();
if ( !v0 )
perror("get_hw_addrs error");
return v0;
}

original_code:
struct hwa_info *
Get_hw_addrs()
{
 struct hwa_info *hwa;
 if ( (hwa = get_hw_addrs()) == ((void *)0))
  perror("get_hw_addrs error");
 return(hwa);
}

canonical_original_code:
struct hwa_info *Get_hw_addrs()
{
 struct hwa_info *hwa;
 if ( (hwa = get_hw_addrs()) == ((void *)0))
  perror("get_hw_addrs error");
 return(hwa);
}

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


decompiled_code:
__int64 __fastcall msg_send(int fd, void *src, int a3, const char *a4, int a5)
{
_DWORD *v7; // rbx
unsigned int v8; // er12
size_t v9; // rax
size_t v10; // rax
struct sockaddr v13; // [rsp+10h] [rbp-128h] BYREF
int v14; // [rsp+78h] [rbp-C0h]
__int16 v15; // [rsp+7Ch] [rbp-BCh]
struct sockaddr addr; // [rsp+80h] [rbp-B8h] BYREF
int v17; // [rsp+E8h] [rbp-50h]
__int16 v18; // [rsp+ECh] [rbp-4Ch]
socklen_t len[15]; // [rsp+FCh] [rbp-3Ch] BYREF

v7 = malloc(0x80CuLL);
memset(&addr, 0, 0x68uLL);
v17 = 0;
v18 = 0;
memset(&v13.sa_data[6], 0, 0x60uLL);
v14 = 0;
v15 = 0;
memset(v7, 0, 0x808uLL);
v7[514] = 0;
v13.sa_family = 1;
strcpy(v13.sa_data, "my_odr_path");
len[0] = 110;
if ( getsockname(fd, &addr, len) )
{
perror("On getsockname for unix socket ");
v8 = -1;
}
else
{
v8 = 0;
*v7 = fd;
v7[257] = a3;
v7[514] = a5;
v9 = strlen(a4);
memcpy(v7 + 258, a4, v9);
v10 = strlen((const char *)src);
memcpy(v7 + 1, src, v10);
if ( sendto(fd, v7, 0x80CuLL, 0, &v13, 0x6Eu) == -1 )
{
puts("sendto() error");
free(v7);
v8 = -1;
}
else
{
free(v7);
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *src, int a3, const char *a4, int a5)
{
_DWORD *v7; // rbx
unsigned int v8; // er12
size_t v9; // rax
size_t v10; // rax
struct sockaddr v13; // [rsp+10h] [rbp-128h] BYREF
int v14; // [rsp+78h] [rbp-C0h]
__int16 v15; // [rsp+7Ch] [rbp-BCh]
struct sockaddr addr; // [rsp+80h] [rbp-B8h] BYREF
int v17; // [rsp+E8h] [rbp-50h]
__int16 v18; // [rsp+ECh] [rbp-4Ch]
socklen_t len[15]; // [rsp+FCh] [rbp-3Ch] BYREF

v7 = malloc(0x80CuLL);
memset(&addr, 0, 0x68uLL);
v17 = 0;
v18 = 0;
memset(&v13.sa_data[6], 0, 0x60uLL);
v14 = 0;
v15 = 0;
memset(v7, 0, 0x808uLL);
v7[514] = 0;
v13.sa_family = 1;
strcpy(v13.sa_data, "my_odr_path");
len[0] = 110;
if ( getsockname(fd, &addr, len) )
{
perror("On getsockname for unix socket ");
v8 = -1;
}
else
{
v8 = 0;
*v7 = fd;
v7[257] = a3;
v7[514] = a5;
v9 = strlen(a4);
memcpy(v7 + 258, a4, v9);
v10 = strlen((const char *)src);
memcpy(v7 + 1, src, v10);
if ( sendto(fd, v7, 0x80CuLL, 0, &v13, 0x6Eu) == -1 )
{
puts("sendto() error");
free(v7);
v8 = -1;
}
else
{
free(v7);
}
}
return v8;
}

original_code:
int msg_send(int socket_fd, char* canonical_ip, int dest_port, char* message, int flag)
{
 socklen_t length;
 struct sockaddr_un cli_verify;
 struct sockaddr_un odr_addr;
 msg_send_serialized_data *data_to_send;
 data_to_send = malloc(sizeof(msg_send_serialized_data));
 memset(&cli_verify, 0, sizeof(struct sockaddr_un));
 memset(&odr_addr, 0, sizeof(struct sockaddr_un));
 memset(data_to_send, 0, sizeof(msg_send_serialized_data));
 odr_addr.sun_family = 1;
 strcpy(odr_addr.sun_path, "my_odr_path");
 length = sizeof(cli_verify);
 if (0 != getsockname(socket_fd, (struct sockaddr *) &cli_verify, &length))
 {
  perror("On getsockname for unix socket ");
  return -1;
 }
 data_to_send->socket_fd = socket_fd;
 data_to_send->dest_port = dest_port;
 data_to_send->flag = flag;
 memcpy(data_to_send->message, message, strlen(message));
 memcpy(data_to_send->canonical_ip, canonical_ip, strlen(canonical_ip));
 if(sendto(socket_fd, (void*)data_to_send, sizeof(msg_send_serialized_data), 0, (struct sockaddr*)&odr_addr, sizeof(struct sockaddr_un)) == -1)
 {
  printf("sendto() error\n");
  free(data_to_send);
  return -1;
 }
 free(data_to_send);
 return 0;
}

canonical_original_code:
int msg_send(int socket_fd, char *canonical_ip, int dest_port, char *message, int flag)
{
 unsigned int length;
 struct sockaddr_un cli_verify;
 struct sockaddr_un odr_addr;
 struct msg_send_serialized_data *data_to_send;
 data_to_send = malloc(sizeof(msg_send_serialized_data));
 memset(&cli_verify, 0, sizeof(struct sockaddr_un));
 memset(&odr_addr, 0, sizeof(struct sockaddr_un));
 memset(data_to_send, 0, sizeof(msg_send_serialized_data));
 odr_addr.sun_family = 1;
 strcpy(odr_addr.sun_path, "my_odr_path");
 length = sizeof(cli_verify);
 if (0 != getsockname(socket_fd, (struct sockaddr *) &cli_verify, &length))
 {
  perror("On getsockname for unix socket ");
  return -1;
 }
 data_to_send->socket_fd = socket_fd;
 data_to_send->dest_port = dest_port;
 data_to_send->flag = flag;
 memcpy(data_to_send->message, message, strlen(message));
 memcpy(data_to_send->canonical_ip, canonical_ip, strlen(canonical_ip));
 if(sendto(socket_fd, (void *)data_to_send, sizeof(msg_send_serialized_data), 0, (struct sockaddr *)&odr_addr, sizeof(struct sockaddr_un)) == -1)
 {
  printf("sendto() error\n");
  free(data_to_send);
  return -1;
 }
 free(data_to_send);
 return 0;
}

variable_types:
message
char *

variable_types: flag int

variable_types:
length
unsigned int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: struct msg_send_serialized_data { int socket_fd; char canonical_ip[1024]; int dest_port; char message[1024]; int flag; } *

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


decompiled_code:
__int64 __fastcall msg_recv(int fd, char *dest, _DWORD *a3, __int64 a4)
{
char *v5; // rbx
__int64 v6; // r15
unsigned int v7; // ebp
struct timeval timeout; // [rsp+10h] [rbp-148h] BYREF
fd_set readfds; // [rsp+20h] [rbp-138h] BYREF
socklen_t addr_len; // [rsp+ACh] [rbp-ACh] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-A8h] BYREF

timeout.tv_sec = 30LL;
timeout.tv_usec = 0LL;
v5 = (char *)malloc(0x80CuLL);
addr_len = 110;
memset(v5, 0, 0x808uLL);
*((_DWORD *)v5 + 514) = 0;
memset(&readfds, 0, sizeof(readfds));
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
{
printf("select() error");
v7 = -1;
}
else if ( (readfds.fds_bits[fd / 64] & v6) != 0 )
{
v7 = recvfrom(fd, v5, 0x80CuLL, 0, &addr, &addr_len);
if ( v7 == -1 )
{
puts("recvfrom() error in msg_recv");
exit(-1);
}
*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 1016) = 0LL;
memset(
(void *)((a4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 1024) >> 3));
*(_QWORD *)dest = 0LL;
*((_QWORD *)dest + 127) = 0LL;
memset(
(void *)((unsigned __int64)(dest + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)dest - (((_DWORD)dest + 8) & 0xFFFFFFF8) + 1024) >> 3));
strcpy((char *)a4, v5 + 1032);
*a3 = *((_DWORD *)v5 + 257);
strcpy(dest, v5 + 4);
}
else
{
v7 = -2;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, char *dest, _DWORD *a3, __int64 a4)
{
char *v5; // rbx
__int64 v6; // r15
unsigned int v7; // ebp
struct timeval timeout; // [rsp+10h] [rbp-148h] BYREF
fd_set readfds; // [rsp+20h] [rbp-138h] BYREF
socklen_t addr_len; // [rsp+ACh] [rbp-ACh] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-A8h] BYREF

timeout.tv_sec = 30LL;
timeout.tv_usec = 0LL;
v5 = (char *)malloc(0x80CuLL);
addr_len = 110;
memset(v5, 0, 0x808uLL);
*((_DWORD *)v5 + 514) = 0;
memset(&readfds, 0, sizeof(readfds));
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
{
printf("select() error");
v7 = -1;
}
else if ( (readfds.fds_bits[fd / 64] & v6) != 0 )
{
v7 = recvfrom(fd, v5, 0x80CuLL, 0, &addr, &addr_len);
if ( v7 == -1 )
{
puts("recvfrom() error in msg_recv");
exit(-1);
}
*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 1016) = 0LL;
memset(
(void *)((a4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 1024) >> 3));
*(_QWORD *)dest = 0LL;
*((_QWORD *)dest + 127) = 0LL;
memset(
(void *)((unsigned __int64)(dest + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)dest - (((_DWORD)dest + 8) & 0xFFFFFFF8) + 1024) >> 3));
strcpy((char *)a4, v5 + 1032);
*a3 = *((_DWORD *)v5 + 257);
strcpy(dest, v5 + 4);
}
else
{
v7 = -2;
}
return v7;
}

original_code:
int msg_recv(int socket_fd, char* canonical_ip, int* src_port, char* message)
{
 struct sockaddr_un client_socket_address;
 int client_address_length;
 msg_send_serialized_data *client_recvd_data;
 int length;
 fd_set setallfd;
 struct timeval tv;
 int n;
 tv.tv_sec = 30;
 tv.tv_usec = 0;
 client_recvd_data = (void*)malloc(sizeof(msg_send_serialized_data));
 length = 0;
 client_address_length = sizeof(client_socket_address);
 memset(client_recvd_data, 0, sizeof(msg_send_serialized_data));
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&setallfd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
 n = select(socket_fd + 1, &setallfd, ((void *)0), ((void *)0), &tv);
 if (n < 0)
 {
  printf("select() error");
  return -1;
 }
 if (((((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  length = recvfrom(socket_fd, (void*)client_recvd_data, sizeof(msg_send_serialized_data), 0,
     (struct sockaddr*)&client_socket_address, &client_address_length);
  if (length == -1)
  {
   printf("recvfrom() error in msg_recv\n");
   exit(-1);
  }
 }
 else
 {
  return -2;
 }
 memset(message, 0, 1024);
 memset(canonical_ip, 0, 1024);
 strcpy(message, client_recvd_data->message);
 *src_port = client_recvd_data->dest_port;
 strcpy(canonical_ip, client_recvd_data->canonical_ip);
 return length;
}

canonical_original_code:
int msg_recv(int socket_fd, char *canonical_ip, int *src_port, char *message)
{
 struct sockaddr_un client_socket_address;
 int client_address_length;
 struct msg_send_serialized_data *client_recvd_data;
 int length;
 struct fd_set setallfd;
 struct timeval tv;
 int n;
 tv.tv_sec = 30;
 tv.tv_usec = 0;
 client_recvd_data = (void *)malloc(sizeof(msg_send_serialized_data));
 length = 0;
 client_address_length = sizeof(client_socket_address);
 memset(client_recvd_data, 0, sizeof(msg_send_serialized_data));
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&setallfd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
 n = select(socket_fd + 1, &setallfd, ((void *)0), ((void *)0), &tv);
 if (n < 0)
 {
  printf("select() error");
  return -1;
 }
 if (((((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  length = recvfrom(socket_fd, (void *)client_recvd_data, sizeof(msg_send_serialized_data), 0,
     (struct sockaddr *)&client_socket_address, &client_address_length);
  if (length == -1)
  {
   printf("recvfrom() error in msg_recv\n");
   exit(-1);
  }
 }
 else
 {
  return -2;
 }
 memset(message, 0, 1024);
 memset(canonical_ip, 0, 1024);
 strcpy(message, client_recvd_data->message);
 *src_port = client_recvd_data->dest_port;
 strcpy(canonical_ip, client_recvd_data->canonical_ip);
 return length;
}

variable_types: length int

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

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

variable_types: n int

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

user_defined_types: struct msg_send_serialized_data { int socket_fd; char canonical_ip[1024]; int dest_port; char message[1024]; int flag; }


repo: kubo/ocidump

original_code:
int ocidump_oranumber_to_str(const OCINumber *on, char *buf, int buflen)
{
    signed char exponent;
    signed char mantissa[21];
    int datalen = on->OCINumberPart[0];
    int len = 0;
    int idx;
    int n;
    if (datalen == 0) {
        return -1;
    }
    if (datalen == 1) {
        if (on->OCINumberPart[1] == 0x80) {
            do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
        if (on->OCINumberPart[1] == 0) {
            do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 2;
        }
        return -1;
    }
    if (datalen == 2) {
        if (on->OCINumberPart[1] == 255 && on->OCINumberPart[2] == 101) {
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
    }
    if (datalen > 21) {
        return -1;
    }
    if (on->OCINumberPart[1] >= 128) {
        exponent = on->OCINumberPart[1] - 193;
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = on->OCINumberPart[idx + 2] - 1;
        }
        mantissa[idx] = -1;
    } else {
        exponent = 62 - on->OCINumberPart[1];
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = 101 - on->OCINumberPart[idx + 2];
        }
        mantissa[idx] = -1;
        do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
    }
    idx = 0;
    if (exponent-- >= 0) {
        n = mantissa[idx++];
        if (n / 10 != 0) {
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        }
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        while (exponent-- >= 0) {
            n = mantissa[idx++];
            if (n < 0) {
                do {
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                } while (exponent-- >= 0);
                do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
                return len;
            }
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        }
        if (mantissa[idx] < 0) {
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return len;
        }
    } else {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    do { if (len < buflen) { buf[len++] = ('.'); } else { return -2; } } while(0);
    while (++exponent < -1) {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    while ((n = mantissa[idx++]) >= 0) {
        do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
    }
    if (buf[len - 1] == '0') {
        len--;
    }
    do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
    return len;
}

canonical_original_code:
int ocidump_oranumber_to_str(struct OCINumber *on, char *buf, int buflen)
{
    char exponent;
    char mantissa[21];
    int datalen = on->OCINumberPart[0];
    int len = 0;
    int idx;
    int n;
    if (datalen == 0) {
        return -1;
    }
    if (datalen == 1) {
        if (on->OCINumberPart[1] == 0x80) {
            do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
        if (on->OCINumberPart[1] == 0) {
            do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 2;
        }
        return -1;
    }
    if (datalen == 2) {
        if (on->OCINumberPart[1] == 255 && on->OCINumberPart[2] == 101) {
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
    }
    if (datalen > 21) {
        return -1;
    }
    if (on->OCINumberPart[1] >= 128) {
        exponent = on->OCINumberPart[1] - 193;
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = on->OCINumberPart[idx + 2] - 1;
        }
        mantissa[idx] = -1;
    } else {
        exponent = 62 - on->OCINumberPart[1];
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = 101 - on->OCINumberPart[idx + 2];
        }
        mantissa[idx] = -1;
        do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
    }
    idx = 0;
    if (exponent-- >= 0) {
        n = mantissa[idx++];
        if (n / 10 != 0) {
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        }
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        while (exponent-- >= 0) {
            n = mantissa[idx++];
            if (n < 0) {
                do {
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                } while (exponent-- >= 0);
                do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
                return len;
            }
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        }
        if (mantissa[idx] < 0) {
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return len;
        }
    } else {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    do { if (len < buflen) { buf[len++] = ('.'); } else { return -2; } } while(0);
    while (++exponent < -1) {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    while ((n = mantissa[idx++]) >= 0) {
        do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
    }
    if (buf[len - 1] == '0') {
        len--;
    }
    do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
    return len;
}

variable_types: struct OCINumber { unsigned char OCINumberPart[22]; } *

variable_types:
buf
char *

variable_types: buflen int

variable_types: exponent char

variable_types:
mantissa
char [21]

variable_types: datalen int

variable_types: len int

variable_types: idx int


decompiled_code:
__int64 __fastcall ocidump_oranumber_dump(unsigned __int8 *a1, char *a2)
{
int v2; // ebx
int v3; // ebp
int v4; // er14
__int64 v5; // rbx
__int64 result; // rax

v2 = *a1;
v3 = sprintf(a2, "Typ=2 Len=%u: ", *a1);
v4 = 21;
if ( v2 <= 21 )
v4 = v2;
if ( v2 > 0 )
{
v5 = 1LL;
do
v3 += sprintf(&a2[v3], "%u,", a1[v5++]);
while ( v4 >= (int)v5 );
}
result = (unsigned int)(v3 - 1);
a2[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, char *a2)
{
int v2; // ebx
int v3; // ebp
int v4; // er14
__int64 v5; // rbx
__int64 result; // rax

v2 = *a1;
v3 = sprintf(a2, "Typ=2 Len=%u: ", *a1);
v4 = 21;
if ( v2 <= 21 )
v4 = v2;
if ( v2 > 0 )
{
v5 = 1LL;
do
v3 += sprintf(&a2[v3], "%u,", a1[v5++]);
while ( v4 >= (int)v5 );
}
result = (unsigned int)(v3 - 1);
a2[(int)result] = 0;
return result;
}

original_code:
int ocidump_oranumber_dump(const OCINumber *on, char *buf)
{
    int idx;
    int len = on->OCINumberPart[0];
    int offset;
    offset = sprintf(buf, "Typ=2 Len=%u: ", len);
    if (len > 21) {
        len = 21;
    }
    for (idx = 1; idx <= len; idx++) {
        offset += sprintf(buf + offset, "%u,", (ub4)on->OCINumberPart[idx]);
    }
    buf[--offset] = '\0';
    return offset;
}

canonical_original_code:
int ocidump_oranumber_dump(struct OCINumber *on, char *buf)
{
    int idx;
    int len = on->OCINumberPart[0];
    int offset;
    offset = sprintf(buf, "Typ=2 Len=%u: ", len);
    if (len > 21) {
        len = 21;
    }
    for (idx = 1; idx <= len; idx++) {
        offset += sprintf(buf + offset, "%u,", (unsigned int)on->OCINumberPart[idx]);
    }
    buf[--offset] = '\0';
    return offset;
}

variable_types: offset int

user_defined_types: struct OCINumber { unsigned char OCINumberPart[22]; }


original_code:
static void delete_entry(ht_entry_t *entry)
{
    ht_entry_t **entry_p;
    entry_p = &hash_table[((size_t)entry->addr) % hash_table_size];
    while (*entry_p != ((void *)0)) {
        if (*entry_p == entry) {
            *entry_p = entry->next;
            break;
        }
        entry_p = &(*entry_p)->next;
    }
    if (entry->parent != ((void *)0)) {
        if (entry->parent->children == entry) {
            if (entry->next_sibling == entry) {
                entry->parent->children = ((void *)0);
            } else {
              entry->parent->children = entry->next_sibling;
            }
        }
    }
    entry->next_sibling->prev_sibling = entry->prev_sibling;
    entry->prev_sibling->next_sibling = entry->next_sibling;
    while (entry->children) {
        delete_entry(entry->children);
    }
    free(entry);
}

canonical_original_code:
static void delete_entry(struct ht_entry *entry)
{
    struct ht_entry **entry_p;
    entry_p = &hash_table[((unsigned long)entry->addr) % hash_table_size];
    while (*entry_p != ((void *)0)) {
        if (*entry_p == entry) {
            *entry_p = entry->next;
            break;
        }
        entry_p = &(*entry_p)->next;
    }
    if (entry->parent != ((void *)0)) {
        if (entry->parent->children == entry) {
            if (entry->next_sibling == entry) {
                entry->parent->children = ((void *)0);
            } else {
              entry->parent->children = entry->next_sibling;
            }
        }
    }
    entry->next_sibling->prev_sibling = entry->prev_sibling;
    entry->prev_sibling->next_sibling = entry->next_sibling;
    while (entry->children) {
        delete_entry(entry->children);
    }
    free(entry);
}

variable_types: struct ht_entry { struct ht_entry *next; void *addr; struct ht_entry *parent; struct ht_entry *children; struct ht_entry *prev_sibling; struct ht_entry *next_sibling; struct ocihandle { unsigned int type; unsigned int id; } handle; } **

user_defined_types: struct ht_entry { struct ht_entry *next; void *addr; struct ht_entry *parent; struct ht_entry *children; struct ht_entry *prev_sibling; struct ht_entry *next_sibling; struct ocihandle handle; }