usage

decompiled_code:
size_t usage()
{
fprintf(
stderr,
"Usage:\n%s [-i inode] [-f fsid] [-s sector] [-c count] [-h] [-b] /dev/hda [/dev/hdb]\n",
(const char *)progname);
fwrite(" -f\tRead from fsid\n", 1uLL, 0x16uLL, stderr);
fwrite(" -i\tRead from inode\n", 1uLL, 0x17uLL, stderr);
fwrite(" -s\tRead from sector, or from offset into file\n", 1uLL, 0x32uLL, stderr);
fwrite(" -c\tRead count sectors, where applicable\n", 1uLL, 0x2CuLL, stderr);
fwrite(" -h\tDisplay in hex, no matter the format\n", 1uLL, 0x2CuLL, stderr);
return fwrite(" -b\tDisplay in binary, no matter the format\n", 1uLL, 0x2FuLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
fprintf(
stderr,
"Usage:\n%s [-i inode] [-f fsid] [-s sector] [-c count] [-h] [-b] /dev/hda [/dev/hdb]\n",
(const char *)progname);
fwrite(" -f\tRead from fsid\n", 1uLL, 0x16uLL, stderr);
fwrite(" -i\tRead from inode\n", 1uLL, 0x17uLL, stderr);
fwrite(" -s\tRead from sector, or from offset into file\n", 1uLL, 0x32uLL, stderr);
fwrite(" -c\tRead count sectors, where applicable\n", 1uLL, 0x2CuLL, stderr);
fwrite(" -h\tDisplay in hex, no matter the format\n", 1uLL, 0x2CuLL, stderr);
return fwrite(" -b\tDisplay in binary, no matter the format\n", 1uLL, 0x2FuLL, stderr);
}

original_code:
static void
usage ()
{
 fprintf (stderr, "Usage:\n%s [-i inode] [-f fsid] [-s sector] [-c count] [-h] [-b] /dev/hda [/dev/hdb]\n", progname);
 fprintf (stderr, "    -f	Read from fsid\n");
 fprintf (stderr, "    -i	Read from inode\n");
 fprintf (stderr, "    -s	Read from sector, or from offset into file\n");
 fprintf (stderr, "    -c	Read count sectors, where applicable\n");
 fprintf (stderr, "    -h	Display in hex, no matter the format\n");
 fprintf (stderr, "    -b	Display in binary, no matter the format\n");
}

canonical_original_code:
static void usage()
{
 fprintf (stderr, "Usage:\n%s [-i inode] [-f fsid] [-s sector] [-c count] [-h] [-b] /dev/hda [/dev/hdb]\n", progname);
 fprintf (stderr, "    -f	Read from fsid\n");
 fprintf (stderr, "    -i	Read from inode\n");
 fprintf (stderr, "    -s	Read from sector, or from offset into file\n");
 fprintf (stderr, "    -c	Read count sectors, where applicable\n");
 fprintf (stderr, "    -h	Display in hex, no matter the format\n");
 fprintf (stderr, "    -b	Display in binary, no matter the format\n");
}


hexdump

original_code:
static void
hexdump (unsigned char *buf, unsigned int sector, unsigned int size)
{
 int ofs;
 for (ofs = 0; ofs < 512 && size > 0; ofs += 16)
 {
  unsigned char line[20];
  int myo;
  if (sector == 0xdeadbeef)
  {
   printf ("%03x ", ofs);
  }
  else
  {
   printf ("%08x:%03x ", sector, ofs);
  }
  for (myo = 0; myo < 16; myo++)
  {
   if (size--)
   {
    printf ("%02x%c", buf[myo + ofs], myo < 15 && (myo & 3) == 3 ? '-' : ' ');
    line[myo] = (isprint (buf[myo + ofs]) ? buf[myo + ofs] : '.');
   }
   else
   {
    line[myo] = '|';
    line[myo + 1] = '\n';
    line[myo + 2] = 0;
    do
    {
     printf ("  %c", myo < 15 && (myo & 3) == 3 ? '-' : ' ');
    }
    while (++myo < 16);
    printf ("|%s", line);
    return;
   }
  }
  printf ("|");
  line[16] = '|';
  line[17] = '\n';
  line[18] = 0;
  printf ("%s", line);
 }
}

canonical_original_code:
static void hexdump(unsigned char *buf, unsigned int sector, unsigned int size)
{
 int ofs;
 for (ofs = 0; ofs < 512 && size > 0; ofs += 16)
 {
  unsigned char line[20];
  int myo;
  if (sector == 0xdeadbeef)
  {
   printf ("%03x ", ofs);
  }
  else
  {
   printf ("%08x:%03x ", sector, ofs);
  }
  for (myo = 0; myo < 16; myo++)
  {
   if (size--)
   {
    printf ("%02x%c", buf[myo + ofs], myo < 15 && (myo & 3) == 3 ? '-' : ' ');
    line[myo] = (isprint (buf[myo + ofs]) ? buf[myo + ofs] : '.');
   }
   else
   {
    line[myo] = '|';
    line[myo + 1] = '\n';
    line[myo + 2] = 0;
    do
    {
     printf ("  %c", myo < 15 && (myo & 3) == 3 ? '-' : ' ');
    }
    while (++myo < 16);
    printf ("|%s", line);
    return;
   }
  }
  printf ("|");
  line[16] = '|';
  line[17] = '\n';
  line[18] = 0;
  printf ("%s", line);
 }
}

variable_types:
buf
unsigned char *

variable_types:
sector
unsigned int

variable_types:
size
unsigned int

variable_types: ofs int

variable_types:
line
unsigned char [20]

variable_types: myo int

return_type: void


verbose

decompiled_code:
int verbose(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = verb;
if ( verb )
{
va_start(arg, format);
result = vfprintf(stderr, format, arg);
}
return result;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = verb;
if ( verb )
{
va_start(arg, format);
result = vfprintf(stderr, format, arg);
}
return result;
}

original_code:
static void verbose(const char *fmt, ...) {
 va_list ap;
 if (!verb) return;
 __builtin_va_start(ap,fmt);
 vfprintf( stderr, fmt, ap );
 __builtin_va_end(ap);
}

canonical_original_code:
static void verbose(char *fmt, ...) {
 __builtin_va_list ap;
 if (!verb) return;
 __builtin_va_start(ap,fmt);
 vfprintf( stderr, fmt, ap );
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"\n"
"usage: %s [options] [<path|fsid> ...]\n"
"\n"
" options:\n"
"\t-a\t\tOpen output file for appending (requires [-o path])\n"
"\t-c <count> # of bytes to copy (defaults to allocated size of fsid)\n"
"\t-h\t\tDisplay this usage info.\n"
"\t-n <count>\t# of sectors to use for buffering. Defaults to 256\n"
"\t-o <path|address:port>\tWrite output to the specified file or to a\n"
"\t\t\t\tTCP connection to the specified host and port\n"
"\t-p <priority>\tPriority 0: ts; 1-99 RT FIFO\n"
"\t-r <ms>\t\tRate control (throttle)\n"
"\t\t\t\t-'ve : no delay (default)\n"
"\t\t\t\t0 : sched_yield() between chunks\n"
"\t\t\t\t+'ve : # of ms to delay between chunks\n"
" -R <path|fsid> Export the parts of a recording FSID.\n"
"\t-s <start>\tStart offset, in bytes (defaults to 0)\n"
"\t-t\t\ttar/tmf output\n"
"\t-x\t\tInclude showing.xml. With -R, computed internally,\n"
" without -R, read from standard in.\n"
" -X Output only showing.xml (requires -R).\n"
"\t-v\t\tVerbose progress messages on stderr\n"
"\n"
" Output defaults to stdout if not present on the command line.\n",
(const char *)prog);
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(
stderr,
"\n"
"usage: %s [options] [<path|fsid> ...]\n"
"\n"
" options:\n"
"\t-a\t\tOpen output file for appending (requires [-o path])\n"
"\t-c <count> # of bytes to copy (defaults to allocated size of fsid)\n"
"\t-h\t\tDisplay this usage info.\n"
"\t-n <count>\t# of sectors to use for buffering. Defaults to 256\n"
"\t-o <path|address:port>\tWrite output to the specified file or to a\n"
"\t\t\t\tTCP connection to the specified host and port\n"
"\t-p <priority>\tPriority 0: ts; 1-99 RT FIFO\n"
"\t-r <ms>\t\tRate control (throttle)\n"
"\t\t\t\t-'ve : no delay (default)\n"
"\t\t\t\t0 : sched_yield() between chunks\n"
"\t\t\t\t+'ve : # of ms to delay between chunks\n"
" -R <path|fsid> Export the parts of a recording FSID.\n"
"\t-s <start>\tStart offset, in bytes (defaults to 0)\n"
"\t-t\t\ttar/tmf output\n"
"\t-x\t\tInclude showing.xml. With -R, computed internally,\n"
" without -R, read from standard in.\n"
" -X Output only showing.xml (requires -R).\n"
"\t-v\t\tVerbose progress messages on stderr\n"
"\n"
" Output defaults to stdout if not present on the command line.\n",
(const char *)prog);
credits();
exit(1);
}

original_code:
static void usage(void)
{
 fprintf(stderr,"\nusage: %s [options] [<path|fsid> ...]\n\n   options:\n	-a		Open output file for appending (requires [-o path])\n	-c <count>      # of bytes to copy (defaults to allocated size of fsid)\n	-h		Display this usage info.\n	-n <count>	# of sectors to use for buffering.  Defaults to 256\n	-o <path|address:port>	Write output to the specified file or to a\n				TCP connection to the specified host and port\n	-p <priority>	Priority  0: ts; 1-99 RT FIFO\n	-r <ms>		Rate control (throttle)\n				-'ve  : no delay (default)\n				0     : sched_yield() between chunks\n				+'ve  : # of ms to delay between chunks\n        -R <path|fsid>  Export the parts of a recording FSID.\n	-s <start>	Start offset, in bytes (defaults to 0)\n	-t		tar/tmf output\n	-x		Include showing.xml.  With -R, computed internally,\n                          without -R, read from standard in.\n        -X              Output only showing.xml (requires -R).\n	-v		Verbose progress messages on stderr\n\n   Output defaults to stdout if not present on the command line.\n", prog );
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr,"\nusage: %s [options] [<path|fsid> ...]\n\n   options:\n	-a		Open output file for appending (requires [-o path])\n	-c <count>      # of bytes to copy (defaults to allocated size of fsid)\n	-h		Display this usage info.\n	-n <count>	# of sectors to use for buffering.  Defaults to 256\n	-o <path|address:port>	Write output to the specified file or to a\n				TCP connection to the specified host and port\n	-p <priority>	Priority  0: ts; 1-99 RT FIFO\n	-r <ms>		Rate control (throttle)\n				-'ve  : no delay (default)\n				0     : sched_yield() between chunks\n				+'ve  : # of ms to delay between chunks\n        -R <path|fsid>  Export the parts of a recording FSID.\n	-s <start>	Start offset, in bytes (defaults to 0)\n	-t		tar/tmf output\n	-x		Include showing.xml.  With -R, computed internally,\n                          without -R, read from standard in.\n        -X              Output only showing.xml (requires -R).\n	-v		Verbose progress messages on stderr\n\n   Output defaults to stdout if not present on the command line.\n", prog );
 credits();
 exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
const char *v4; // r14
void *v5; // r13
const char *v7; // rax
const char **v8; // rsi
int v9; // eax
int v10; // er8
int v11; // er12
__int64 v12; // rax
char *v13; // r14
size_t v14; // rax
void *v15; // rsp
char *v16; // r13
size_t v17; // rax
void *v18; // rsp
char *v19; // rax
__int64 v20; // rcx
int v21; // er8
const char *v22; // r15
unsigned int v23; // eax
__int64 v24; // rdx
__int64 v25; // rcx
int v26; // er8
_DWORD *v27; // r14
const char **v28; // r13
__int64 i; // rbx
int v30; // eax
__int64 v31; // rax
unsigned int v32; // er14
__int64 v33; // rbx
__int64 v34; // r13
unsigned int v35; // er12
void *v36; // rax
unsigned int v37; // eax
unsigned int v38; // er14
__int64 v39; // rax
__int64 v41; // [rsp+0h] [rbp-2B0h] BYREF
int v42; // [rsp+8h] [rbp-2A8h]
int v43; // [rsp+Ch] [rbp-2A4h]
void *ptr; // [rsp+10h] [rbp-2A0h]
int v45; // [rsp+18h] [rbp-298h]
int v46; // [rsp+1Ch] [rbp-294h]
__int64 v47; // [rsp+20h] [rbp-290h]
unsigned int v48; // [rsp+28h] [rbp-288h]
unsigned int v49; // [rsp+2Ch] [rbp-284h]
__int64 v50; // [rsp+30h] [rbp-280h]
__int64 v51; // [rsp+38h] [rbp-278h]
char s[64]; // [rsp+40h] [rbp-270h] BYREF
char buf[560]; // [rsp+80h] [rbp-230h] BYREF

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v7 = *argv;
LODWORD(v51) = 0;
v45 = 0;
prog = (void *)v7;
v46 = 0;
v48 = 256;
v49 = -1;
v47 = 0LL;
v50 = 0LL;
while ( 2 )
{
v8 = argv;
v9 = getopt(argc, (char *const *)argv, "ac:hn:o:p:r:R:s:txXv");
if ( v9 != -1 )
{
switch ( v9 )
{
case 'R':
v16 = optarg;
v17 = strlen(optarg);
v18 = alloca(v17 + 9);
v5 = memcpy(&v41, v16, v17 + 1);
continue;
case 'X':
LODWORD(v51) = 1;
continue;
case 'a':
v3 = 1;
continue;
case 'c':
v47 = strtoll(optarg, 0LL, 0);
continue;
case 'n':
v48 = strtoll(optarg, 0LL, 0);
continue;
case 'o':
v13 = optarg;
v14 = strlen(optarg);
v15 = alloca(v14 + 9);
v4 = (const char *)memcpy(&v41, v13, v14 + 1);
continue;
case 'p':
v12 = strtoll(optarg, 0LL, 0);
fixPriority(v12);
continue;
case 'r':
v49 = strtoll(optarg, 0LL, 0);
continue;
case 's':
v50 = strtoll(optarg, 0LL, 0);
continue;
case 't':
v46 = 1;
continue;
case 'v':
verb = 1;
continue;
case 'x':
v45 = 1;
continue;
default:
goto LABEL_8;
}
}
break;
}
v10 = optind;
v11 = argc - optind;
if ( argc - optind <= 0 && !v5 || (_DWORD)v51 && !v5 || v11 && v5 || v47 | v50 && (v11 > 1 || v5) )
LABEL_8:
usage();
if ( v4 )
{
LODWORD(ptr) = optind;
v19 = strchr(v4, 58);
v21 = (int)ptr;
if ( v19 )
{
*v19 = 0;
v22 = v19 + 1;
LODWORD(ptr) = v21;
verbose("opening socket to %s on %s\n", v4, v19 + 1);
fflush(stderr);
v23 = atoi(v22);
v8 = (const char **)(unsigned int)open_socket_out(v4, v23);
v3 = (unsigned int)v8;
verbose("socket opened %d\n", v8);
fflush(stderr);
v10 = (int)ptr;
}
else
{
v8 = (const char **)((v3 == 0 ? 512 : 1024) | 0x41u);
v30 = open64(v4, (int)v8, 420LL, v20, (unsigned int)ptr);
v10 = (int)ptr;
v3 = v30;
}
if ( v3 == -1 )
{
if ( *_errno_location() )
perror(v4);
goto LABEL_66;
}
}
else if ( v3 )
{
v8 = (const char **)(usage + 1);
LODWORD(ptr) = optind;
fwrite("WARNING: -a makes no sense without -o\n", 1uLL, 0x26uLL, stderr);
v10 = (int)ptr;
}
else
{
v3 = 1;
}
LODWORD(ptr) = v10;
mfs_init();
v43 = v51 | v45;
v26 = (int)ptr;
if ( !((unsigned int)v51 | v45) )
{
if ( v5 )
{
v42 = (int)ptr;
generate_xml(v5);
v31 = get_parts();
v26 = v42;
ptr = 0LL;
v27 = (_DWORD *)v31;
if ( v31 )
goto LABEL_45;
}
ptr = 0LL;
goto LABEL_33;
}
verbose("getting showing.xml contents\n", v8, v24, v25, (unsigned int)ptr);
v43 = (int)ptr;
if ( v5 )
v36 = (void *)generate_xml(v5);
else
v36 = (void *)read_xml();
ptr = v36;
v42 = v43;
if ( v36 )
{
v37 = strlen((const char *)ptr);
v26 = v42;
v43 = v37;
v38 = v37;
if ( v37 )
{
if ( v46 )
{
create_tarheader(buf, "showing.xml", v37);
write(v3, buf, 0x200uLL);
write(v3, ptr, (int)v38);
free(ptr);
write_tar_padding(v3, v38);
v26 = v42;
}
if ( v5 )
{
v42 = v26;
v39 = get_parts();
v26 = v42;
v27 = (_DWORD *)v39;
if ( v39 )
{
LABEL_38:
if ( (_DWORD)v51 )
{
if ( v46 )
goto LABEL_40;
write(v3, ptr, v43);
goto LABEL_54;
}
LABEL_45:
v51 = (__int64)v27;
v32 = v48;
v33 = 0LL;
v34 = v47;
while ( 1 )
{
v35 = *(_DWORD *)(v51 + 4 * v33);
if ( v35 == -1 )
break;
if ( v46 )
{
snprintf(s, 0x40uLL, "part%02d.ty", (unsigned int)v33);
v47 = mfs_fsid_size(v35);
create_tarheader(buf, s, (unsigned int)v47);
write(v3, buf, 0x200uLL);
export_file(v35, v3, v50, v34, v49, v32, (unsigned int)verb, buf);
write_tar_padding(v3, (unsigned int)v47);
}
else
{
export_file(v35, v3, v50, v34, v49, v32, (unsigned int)verb, v51);
}
++v33;
}
if ( v46 )
{
memset(buf, 0, 0x200uLL);
write(v3, buf, 0x200uLL);
LABEL_40:
close(v3);
exit(0);
}
if ( !v45 )
goto LABEL_40;
write(
v3,
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"################################################################################",
0x200uLL);
write(v3, ptr, v43);
write(
v3,
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"################################################################################",
0x200uLL);
LABEL_54:
free(ptr);
goto LABEL_40;
}
}
LABEL_33:
v42 = v26;
v27 = malloc(4LL * (v11 + 1));
if ( !v27 )
_assert_fail("parts", "mfs_uberexport.c", 0xD9u, "main");
v28 = &argv[v42];
for ( i = 0LL; v11 > (int)i; ++i )
v27[i] = mfs_resolve(v28[i]);
v27[v11] = -1;
goto LABEL_38;
}
}
fprintf(stderr, "%s Error getting showing.xml\n", (const char *)prog);
LABEL_66:
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
const char *v4; // r14
void *v5; // r13
const char *v7; // rax
const char **v8; // rsi
int v9; // eax
int v10; // er8
int v11; // er12
__int64 v12; // rax
char *v13; // r14
size_t v14; // rax
void *v15; // rsp
char *v16; // r13
size_t v17; // rax
void *v18; // rsp
char *v19; // rax
__int64 v20; // rcx
int v21; // er8
const char *v22; // r15
unsigned int v23; // eax
__int64 v24; // rdx
__int64 v25; // rcx
int v26; // er8
_DWORD *v27; // r14
const char **v28; // r13
__int64 i; // rbx
int v30; // eax
__int64 v31; // rax
unsigned int v32; // er14
__int64 v33; // rbx
__int64 v34; // r13
unsigned int v35; // er12
void *v36; // rax
unsigned int v37; // eax
unsigned int v38; // er14
__int64 v39; // rax
__int64 v41; // [rsp+0h] [rbp-2B0h] BYREF
int v42; // [rsp+8h] [rbp-2A8h]
int v43; // [rsp+Ch] [rbp-2A4h]
void *ptr; // [rsp+10h] [rbp-2A0h]
int v45; // [rsp+18h] [rbp-298h]
int v46; // [rsp+1Ch] [rbp-294h]
__int64 v47; // [rsp+20h] [rbp-290h]
unsigned int v48; // [rsp+28h] [rbp-288h]
unsigned int v49; // [rsp+2Ch] [rbp-284h]
__int64 v50; // [rsp+30h] [rbp-280h]
__int64 v51; // [rsp+38h] [rbp-278h]
char s[64]; // [rsp+40h] [rbp-270h] BYREF
char buf[560]; // [rsp+80h] [rbp-230h] BYREF

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v7 = *argv;
LODWORD(v51) = 0;
v45 = 0;
prog = (void *)v7;
v46 = 0;
v48 = 256;
v49 = -1;
v47 = 0LL;
v50 = 0LL;
while ( 2 )
{
v8 = argv;
v9 = getopt(argc, (char *const *)argv, "ac:hn:o:p:r:R:s:txXv");
if ( v9 != -1 )
{
switch ( v9 )
{
case 'R':
v16 = optarg;
v17 = strlen(optarg);
v18 = alloca(v17 + 9);
v5 = memcpy(&v41, v16, v17 + 1);
continue;
case 'X':
LODWORD(v51) = 1;
continue;
case 'a':
v3 = 1;
continue;
case 'c':
v47 = strtoll(optarg, 0LL, 0);
continue;
case 'n':
v48 = strtoll(optarg, 0LL, 0);
continue;
case 'o':
v13 = optarg;
v14 = strlen(optarg);
v15 = alloca(v14 + 9);
v4 = (const char *)memcpy(&v41, v13, v14 + 1);
continue;
case 'p':
v12 = strtoll(optarg, 0LL, 0);
fixPriority(v12);
continue;
case 'r':
v49 = strtoll(optarg, 0LL, 0);
continue;
case 's':
v50 = strtoll(optarg, 0LL, 0);
continue;
case 't':
v46 = 1;
continue;
case 'v':
verb = 1;
continue;
case 'x':
v45 = 1;
continue;
default:
goto LABEL_8;
}
}
break;
}
v10 = optind;
v11 = argc - optind;
if ( argc - optind <= 0 && !v5 || (_DWORD)v51 && !v5 || v11 && v5 || v47 | v50 && (v11 > 1 || v5) )
LABEL_8:
func0();
if ( v4 )
{
LODWORD(ptr) = optind;
v19 = strchr(v4, 58);
v21 = (int)ptr;
if ( v19 )
{
*v19 = 0;
v22 = v19 + 1;
LODWORD(ptr) = v21;
func1("opening socket to %s on %s\n", v4, v19 + 1);
fflush(stderr);
v23 = atoi(v22);
v8 = (const char **)(unsigned int)open_socket_out(v4, v23);
v3 = (unsigned int)v8;
func1("socket opened %d\n", v8);
fflush(stderr);
v10 = (int)ptr;
}
else
{
v8 = (const char **)((v3 == 0 ? 512 : 1024) | 0x41u);
v30 = open64(v4, (int)v8, 420LL, v20, (unsigned int)ptr);
v10 = (int)ptr;
v3 = v30;
}
if ( v3 == -1 )
{
if ( *_errno_location() )
perror(v4);
goto LABEL_66;
}
}
else if ( v3 )
{
v8 = (const char **)(usage + 1);
LODWORD(ptr) = optind;
fwrite("WARNING: -a makes no sense without -o\n", 1uLL, 0x26uLL, stderr);
v10 = (int)ptr;
}
else
{
v3 = 1;
}
LODWORD(ptr) = v10;
mfs_init();
v43 = v51 | v45;
v26 = (int)ptr;
if ( !((unsigned int)v51 | v45) )
{
if ( v5 )
{
v42 = (int)ptr;
generate_xml(v5);
v31 = get_parts();
v26 = v42;
ptr = 0LL;
v27 = (_DWORD *)v31;
if ( v31 )
goto LABEL_45;
}
ptr = 0LL;
goto LABEL_33;
}
func1("getting showing.xml contents\n", v8, v24, v25, (unsigned int)ptr);
v43 = (int)ptr;
if ( v5 )
v36 = (void *)generate_xml(v5);
else
v36 = (void *)read_xml();
ptr = v36;
v42 = v43;
if ( v36 )
{
v37 = strlen((const char *)ptr);
v26 = v42;
v43 = v37;
v38 = v37;
if ( v37 )
{
if ( v46 )
{
create_tarheader(buf, "showing.xml", v37);
write(v3, buf, 0x200uLL);
write(v3, ptr, (int)v38);
free(ptr);
write_tar_padding(v3, v38);
v26 = v42;
}
if ( v5 )
{
v42 = v26;
v39 = get_parts();
v26 = v42;
v27 = (_DWORD *)v39;
if ( v39 )
{
LABEL_38:
if ( (_DWORD)v51 )
{
if ( v46 )
goto LABEL_40;
write(v3, ptr, v43);
goto LABEL_54;
}
LABEL_45:
v51 = (__int64)v27;
v32 = v48;
v33 = 0LL;
v34 = v47;
while ( 1 )
{
v35 = *(_DWORD *)(v51 + 4 * v33);
if ( v35 == -1 )
break;
if ( v46 )
{
snprintf(s, 0x40uLL, "part%02d.ty", (unsigned int)v33);
v47 = mfs_fsid_size(v35);
create_tarheader(buf, s, (unsigned int)v47);
write(v3, buf, 0x200uLL);
export_file(v35, v3, v50, v34, v49, v32, (unsigned int)verb, buf);
write_tar_padding(v3, (unsigned int)v47);
}
else
{
export_file(v35, v3, v50, v34, v49, v32, (unsigned int)verb, v51);
}
++v33;
}
if ( v46 )
{
memset(buf, 0, 0x200uLL);
write(v3, buf, 0x200uLL);
LABEL_40:
close(v3);
exit(0);
}
if ( !v45 )
goto LABEL_40;
write(
v3,
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"################################################################################",
0x200uLL);
write(v3, ptr, v43);
write(
v3,
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"############################################################################################################"
"################################################################################",
0x200uLL);
LABEL_54:
free(ptr);
goto LABEL_40;
}
}
LABEL_33:
v42 = v26;
v27 = malloc(4LL * (v11 + 1));
if ( !v27 )
_assert_fail("parts", "mfs_uberexport.c", 0xD9u, "main");
v28 = &argv[v42];
for ( i = 0LL; v11 > (int)i; ++i )
v27[i] = mfs_resolve(v28[i]);
v27[v11] = -1;
goto LABEL_38;
}
}
fprintf(stderr, "%s Error getting showing.xml\n", (const char *)prog);
LABEL_66:
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
 int fd = 1;
 int fsid;
 int c;
 u64 start=0;
 u64 count=0;
 int rate = -1;
 u32 nbufs = 256;
 int append = 0;
 int tar=0;
 int xml = 0;
 int xmlonly = 0;
 char *output = 0;
 int *parts = 0;
 char *showPath = 0;
 char *xml_buf=0;
 int xml_len=0;
 tar_record tar_header;
 int i;
 prog = argv[0];
 while ((c = getopt(argc, argv, "ac:hn:o:p:r:R:s:txXv")) != -1 ){
  switch (c) {
  case 'a':
   append=1;
   break;
  case 'c':
   count = strtoll(optarg, ((void *)0), 0);
   break;
  case 'h':
   usage();
   break;
  case 'n':
   nbufs = strtoll(optarg, ((void *)0), 0);
   break;
  case 'o':
   output = (__extension__ ({ const char *__old = (optarg); size_t __len = strlen (__old) + 1; char *__new = (char *) __builtin_alloca (__len); (char *) memcpy (__new, __old, __len); }));
   break;
  case 'p':
   fixPriority(strtoll(optarg, ((void *)0), 0));
   break;
  case 'r':
   rate = strtoll(optarg, ((void *)0), 0);
   break;
  case 'R':
   showPath = (__extension__ ({ const char *__old = (optarg); size_t __len = strlen (__old) + 1; char *__new = (char *) __builtin_alloca (__len); (char *) memcpy (__new, __old, __len); }));
   break;
  case 's':
   start = strtoll(optarg, ((void *)0), 0);
   break;
  case 't':
   tar = 1;
   break;
  case 'x':
   xml = 1;
   break;
  case 'X':
   xmlonly = 1;
   break;
  case 'v':
   verb = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (!showPath && argc <1) {
  usage();
  fprintf( stderr, "%s Command line error: The command line must include a path or fsid.\n",
    prog );
  exit(1);
 }
 if ( xmlonly && !showPath ) {
  usage();
  fprintf( stderr, "%s Command line error: The -X option only makes sense when combined with -R\n",
    prog );
  exit(1);
 }
 if (showPath && argc!=0) {
  usage();
  fprintf( stderr, "%s Command line error: The -R option only makes sense with a single path/fsid\n",
    prog );
  exit(1);
 }
 if ( (start!=0 || count!=0) && (showPath || argc>1) ) {
  usage();
  fprintf( stderr, "%s Command line error: The -s and -c option are only supported with a single path/fsid\n",
    prog );
  exit(1);
 }
        if (output) {
                char *portstr;
                portstr = strchr(output, ':');
                if (!portstr) {
                        int open_flags = 01|0100|0;
                        open_flags |= append ? 02000 : 01000;
                        fd = open(output, open_flags, 0644);
                } else {
                        *portstr = 0;
                        ++portstr;
                        verbose("opening socket to %s on %s\n", output, portstr); fflush(stderr);
                        fd = open_socket_out(output, atoi(portstr));
                        verbose("socket opened %d\n", fd); fflush(stderr);
                }
                if (fd == -1) {
                        if ((*__errno_location ()))
                                perror(output);
                        exit(1);
                }
        } else {
                if (append)
                        fprintf(stderr, "WARNING: -a makes no sense without -o\n");
        }
 mfs_init();
 if (xml || xmlonly) {
  verbose("getting showing.xml contents\n");
  xml_buf = showPath ? generate_xml(showPath) : read_xml();
  xml_len = xml_buf ? strlen(xml_buf) : 0;
  if (xml_len == 0) {
   fprintf( stderr, "%s Error getting showing.xml\n", prog );
   exit(1);
  }
  if (tar) {
   create_tarheader(&tar_header, "showing.xml", xml_len);
   write(fd, &tar_header, sizeof(tar_header));
   write(fd,xml_buf,xml_len);
   free(xml_buf);
   write_tar_padding(fd, xml_len);
  }
 }
 if (showPath) {
  if (xml_buf == 0) generate_xml(showPath);
  parts = get_parts();
 }
 if (parts == 0) {
  parts = (int *) malloc( (argc+1)*sizeof(int) );
  ((void) sizeof ((parts) ? 1 : 0), __extension__ ({ if (parts) ; else __assert_fail ("parts", "mfs_uberexport.c", 217, __extension__ __PRETTY_FUNCTION__); }));
  for(i=0; i<argc; i++)
   parts[i] = mfs_resolve(argv[i]);
  parts[argc] = -1;
 }
 if (!xmlonly) {
  for( i = 0; parts[i] != -1; i++)
  {
   char buffer[64];
   u64 size = 0;
   fsid = parts[i];
   if (tar) {
    snprintf(buffer, sizeof(buffer),"part%02d.ty", i);
    size = mfs_fsid_size(fsid);
    create_tarheader(&tar_header, buffer, size);
    write(fd, &tar_header, sizeof(tar_header));
   }
   export_file(fsid,fd, start, count, rate, nbufs, verb);
   if (tar)
    write_tar_padding(fd, size);
  }
  if (tar) {
   memset(&tar_header, 0, sizeof(tar_header));
   write(fd, &tar_header, sizeof(tar_header));
  }
 }
 if (!tar && (xml || xmlonly)) {
  const char *typlusdelim = "################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################";
  const size_t l = strlen(typlusdelim);
  if (!xmlonly)
   write(fd,typlusdelim,l);
  write(fd,xml_buf,xml_len);
  if (!xmlonly)
   write(fd,typlusdelim,l);
  free(xml_buf);
 }
 close(fd);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd = 1;
 int fsid;
 int c;
 unsigned int start = 0;
 unsigned int count = 0;
 int rate = -1;
 unsigned int nbufs = 256;
 int append = 0;
 int tar = 0;
 int xml = 0;
 int xmlonly = 0;
 char *output = 0;
 int *parts = 0;
 char *showPath = 0;
 char *xml_buf = 0;
 int xml_len = 0;
 union _tar_record tar_header;
 int i;
 prog = argv[0];
 while ((c = getopt(argc, argv, "ac:hn:o:p:r:R:s:txXv")) != -1 ){
  switch (c) {
  case 'a':
   append=1;
   break;
  case 'c':
   count = strtoll(optarg, ((void *)0), 0);
   break;
  case 'h':
   usage();
   break;
  case 'n':
   nbufs = strtoll(optarg, ((void *)0), 0);
   break;
  case 'o':
   output = (__extension__ ({ char *__old = (optarg); unsigned long __len = strlen (__old) + 1; char *__new = (char *) __builtin_alloca (__len); (char *) memcpy (__new, __old, __len); }));
   break;
  case 'p':
   fixPriority(strtoll(optarg, ((void *)0), 0));
   break;
  case 'r':
   rate = strtoll(optarg, ((void *)0), 0);
   break;
  case 'R':
   showPath = (__extension__ ({ char *__old = (optarg); unsigned long __len = strlen (__old) + 1; char *__new = (char *) __builtin_alloca (__len); (char *) memcpy (__new, __old, __len); }));
   break;
  case 's':
   start = strtoll(optarg, ((void *)0), 0);
   break;
  case 't':
   tar = 1;
   break;
  case 'x':
   xml = 1;
   break;
  case 'X':
   xmlonly = 1;
   break;
  case 'v':
   verb = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (!showPath && argc <1) {
  usage();
  fprintf( stderr, "%s Command line error: The command line must include a path or fsid.\n",
    prog );
  exit(1);
 }
 if ( xmlonly && !showPath ) {
  usage();
  fprintf( stderr, "%s Command line error: The -X option only makes sense when combined with -R\n",
    prog );
  exit(1);
 }
 if (showPath && argc!=0) {
  usage();
  fprintf( stderr, "%s Command line error: The -R option only makes sense with a single path/fsid\n",
    prog );
  exit(1);
 }
 if ( (start!=0 || count!=0) && (showPath || argc>1) ) {
  usage();
  fprintf( stderr, "%s Command line error: The -s and -c option are only supported with a single path/fsid\n",
    prog );
  exit(1);
 }
        if (output) {
                char *portstr;
                portstr = strchr(output, ':');
                if (!portstr) {
                        int open_flags = 01|0100|0;
                        open_flags |= append ? 02000 : 01000;
                        fd = open(output, open_flags, 0644);
                } else {
                        *portstr = 0;
                        ++portstr;
                        verbose("opening socket to %s on %s\n", output, portstr); fflush(stderr);
                        fd = open_socket_out(output, atoi(portstr));
                        verbose("socket opened %d\n", fd); fflush(stderr);
                }
                if (fd == -1) {
                        if ((*__errno_location ()))
                                perror(output);
                        exit(1);
                }
        } else {
                if (append)
                        fprintf(stderr, "WARNING: -a makes no sense without -o\n");
        }
 mfs_init();
 if (xml || xmlonly) {
  verbose("getting showing.xml contents\n");
  xml_buf = showPath ? generate_xml(showPath) : read_xml();
  xml_len = xml_buf ? strlen(xml_buf) : 0;
  if (xml_len == 0) {
   fprintf( stderr, "%s Error getting showing.xml\n", prog );
   exit(1);
  }
  if (tar) {
   create_tarheader(&tar_header, "showing.xml", xml_len);
   write(fd, &tar_header, sizeof(tar_header));
   write(fd,xml_buf,xml_len);
   free(xml_buf);
   write_tar_padding(fd, xml_len);
  }
 }
 if (showPath) {
  if (xml_buf == 0) generate_xml(showPath);
  parts = get_parts();
 }
 if (parts == 0) {
  parts = (int *) malloc( (argc+1)*sizeof(int) );
  ((void) sizeof ((parts) ? 1 : 0), __extension__ ({ if (parts) ; else __assert_fail ("parts", "mfs_uberexport.c", 217, __extension__ __PRETTY_FUNCTION__); }));
  for(i=0; i<argc; i++)
   parts[i] = mfs_resolve(argv[i]);
  parts[argc] = -1;
 }
 if (!xmlonly) {
  for( i = 0; parts[i] != -1; i++)
  {
   char buffer[64];
   unsigned int size = 0;
   fsid = parts[i];
   if (tar) {
    snprintf(buffer, sizeof(buffer),"part%02d.ty", i);
    size = mfs_fsid_size(fsid);
    create_tarheader(&tar_header, buffer, size);
    write(fd, &tar_header, sizeof(tar_header));
   }
   export_file(fsid,fd, start, count, rate, nbufs, verb);
   if (tar)
    write_tar_padding(fd, size);
  }
  if (tar) {
   memset(&tar_header, 0, sizeof(tar_header));
   write(fd, &tar_header, sizeof(tar_header));
  }
 }
 if (!tar && (xml || xmlonly)) {
  char *typlusdelim = "################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################";
  unsigned long l = strlen(typlusdelim);
  if (!xmlonly)
   write(fd,typlusdelim,l);
  write(fd,xml_buf,xml_len);
  if (!xmlonly)
   write(fd,typlusdelim,l);
  free(xml_buf);
 }
 close(fd);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int

variable_types: fsid int

variable_types: c int

variable_types:
start
unsigned int

variable_types:
count
unsigned int

variable_types: rate int

variable_types:
nbufs
unsigned int

variable_types: append int

variable_types: tar int

variable_types: xml int

variable_types: xmlonly int

variable_types:
output
char *

variable_types:
parts
int *

variable_types:
showPath
char *

variable_types: union _tar_record { char charptr[512]; struct header { char name[100]; char mode[8]; char uid[8]; char gid[8]; char size[12]; char mtime[12]; char chksum[8]; char linkflag; char linkname[100]; char magic[8]; char uname[32]; char gname[32]; char devmajor[8]; char devminor[8]; } header; }

variable_types: i int

variable_types:
portstr
char *

variable_types:
buffer
char [64]

variable_types:
typlusdelim
char *

variable_types:
l
unsigned long

return_type: int

user_defined_types: union _tar_record { char charptr[512]; struct header header; }


decompiled_code:
int __fastcall crypto_check(__int64 a1)
{
char s1[12]; // [rsp+Ch] [rbp-Ch] BYREF

mfs_fsid_pread(a1, s1, 0LL, 4LL);
return memcmp(s1, &expected_0, 4uLL);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char s1[12]; // [rsp+Ch] [rbp-Ch] BYREF

mfs_fsid_pread(a1, s1, 0LL, 4LL);
return memcmp(s1, &expected_0, 4uLL);
}

original_code:
static int
crypto_check( int fsid )
{
 static const unsigned char expected[] = { 0xf5, 0x46, 0x7a, 0xbd };
 unsigned char buf[4];
 mfs_fsid_pread( fsid, buf, 0, sizeof(buf) );
 return memcmp(buf,expected,sizeof(expected));
}

canonical_original_code:
static int crypto_check(int fsid)
{
 static unsigned char expected[] = { 0xf5, 0x46, 0x7a, 0xbd };
 unsigned char buf[4];
 mfs_fsid_pread( fsid, buf, 0, sizeof(buf) );
 return memcmp(buf,expected,sizeof(expected));
}

variable_types: fsid int

variable_types:
expected
unsigned char []

variable_types:
buf
unsigned char [4]


ciphercheck

decompiled_code:
int __fastcall ciphercheck(__int64 a1)
{
unsigned int v1; // eax
unsigned int *v2; // rax
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // r13
unsigned int i; // er12
unsigned int *v7; // rbx
int v8; // ebp
const char *v9; // r15
__int64 v10; // rbx
int v11; // eax
const char *v12; // rdx
unsigned int *v13; // r12
int v14; // ebx
int v15; // eax
const char *v16; // rdx
int v18; // [rsp+Ch] [rbp-204Ch]
unsigned int v19; // [rsp+1Ch] [rbp-203Ch] BYREF
int v20[1024]; // [rsp+20h] [rbp-2038h] BYREF
int v21[1038]; // [rsp+1020h] [rbp-1038h] BYREF

fwrite("CipherCheck - based on CipherCheck.tcl by AlphaWolf_HK\n\n", 1uLL, 0x38uLL, stdout);
v1 = mfs_resolve("/Recording/LiveCache");
v2 = (unsigned int *)mfs_dir(v1, &v19);
if ( v19 )
{
v13 = v2;
v14 = query_int_list(*v2, "Part/File", v20, 1024LL);
mfs_dir_free(v13);
if ( v14 > 0 )
{
v15 = crypto_check((unsigned int)v20[v14 - 1]);
v16 = "enabled";
if ( !v15 )
v16 = "disabled";
fprintf(stdout, "TyStream encryption is currently %s.\n", v16);
}
}
fwrite(
"\nHere is the status of your current recordings:\n\nEncrypted CSO Set Stream Name\n--------- ------- -----------\n",
1uLL,
0x6DuLL,
stdout);
v3 = mfs_resolve(a1);
v4 = mfs_dir(v3, &v19);
v5 = v4;
if ( v19 )
{
for ( i = 0; i < v19; ++i )
{
while ( 1 )
{
v7 = (unsigned int *)(v5 + 16LL * i);
v8 = query_int_list(*v7, "Part/File", v20, 1024LL);
LODWORD(v4) = query_int_list(*v7, "Part/CommercialSkipOffset", v21, 1024LL);
v18 = v4;
if ( v8 > 0 )
break;
if ( v19 <= ++i )
goto LABEL_12;
}
v9 = "No ";
v10 = query_string(*v7, "Showing/Program/Title");
if ( v18 && v21[v18 - 1] )
v9 = "Yes ";
v11 = crypto_check((unsigned int)v20[v8 - 1]);
v12 = "Yes ";
if ( !v11 )
v12 = "No ";
LODWORD(v4) = fprintf(stdout, "%s%s%s\n", v12, v9, v10);
}
}
LABEL_12:
if ( v5 )
LODWORD(v4) = mfs_dir_free(v5);
return v4;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int v1; // eax
unsigned int *v2; // rax
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // r13
unsigned int i; // er12
unsigned int *v7; // rbx
int v8; // ebp
const char *v9; // r15
__int64 v10; // rbx
int v11; // eax
const char *v12; // rdx
unsigned int *v13; // r12
int v14; // ebx
int v15; // eax
const char *v16; // rdx
int v18; // [rsp+Ch] [rbp-204Ch]
unsigned int v19; // [rsp+1Ch] [rbp-203Ch] BYREF
int v20[1024]; // [rsp+20h] [rbp-2038h] BYREF
int v21[1038]; // [rsp+1020h] [rbp-1038h] BYREF

fwrite("CipherCheck - based on CipherCheck.tcl by AlphaWolf_HK\n\n", 1uLL, 0x38uLL, stdout);
v1 = mfs_resolve("/Recording/LiveCache");
v2 = (unsigned int *)mfs_dir(v1, &v19);
if ( v19 )
{
v13 = v2;
v14 = query_int_list(*v2, "Part/File", v20, 1024LL);
mfs_dir_free(v13);
if ( v14 > 0 )
{
v15 = func1((unsigned int)v20[v14 - 1]);
v16 = "enabled";
if ( !v15 )
v16 = "disabled";
fprintf(stdout, "TyStream encryption is currently %s.\n", v16);
}
}
fwrite(
"\nHere is the status of your current recordings:\n\nEncrypted CSO Set Stream Name\n--------- ------- -----------\n",
1uLL,
0x6DuLL,
stdout);
v3 = mfs_resolve(a1);
v4 = mfs_dir(v3, &v19);
v5 = v4;
if ( v19 )
{
for ( i = 0; i < v19; ++i )
{
while ( 1 )
{
v7 = (unsigned int *)(v5 + 16LL * i);
v8 = query_int_list(*v7, "Part/File", v20, 1024LL);
LODWORD(v4) = query_int_list(*v7, "Part/CommercialSkipOffset", v21, 1024LL);
v18 = v4;
if ( v8 > 0 )
break;
if ( v19 <= ++i )
goto LABEL_12;
}
v9 = "No ";
v10 = query_string(*v7, "Showing/Program/Title");
if ( v18 && v21[v18 - 1] )
v9 = "Yes ";
v11 = func1((unsigned int)v20[v8 - 1]);
v12 = "Yes ";
if ( !v11 )
v12 = "No ";
LODWORD(v4) = fprintf(stdout, "%s%s%s\n", v12, v9, v10);
}
}
LABEL_12:
if ( v5 )
LODWORD(v4) = mfs_dir_free(v5);
return v4;
}

original_code:
static void
ciphercheck(const char *path)
{
 struct mfs_dirent *dir;
 int parts[1024];
 int cso[1024];
 u32 count, i;
 int np,nc;
 fprintf( stdout, "CipherCheck - based on CipherCheck.tcl by AlphaWolf_HK\n\n" );
 dir = mfs_dir(mfs_resolve("/Recording/LiveCache"), &count);
 if (count > 0) {
  np = query_int_list(dir[0].fsid, "Part/File", parts, 1024 );
  if (dir) mfs_dir_free(dir);
  if (np > 0)
   fprintf( stdout, "TyStream encryption is currently %s.\n",
     crypto_check(parts[np-1])? "enabled" : "disabled");
 }
 fprintf( stdout, "\nHere is the status of your current recordings:\n\nEncrypted CSO Set Stream Name\n--------- ------- -----------\n");
 dir = mfs_dir(mfs_resolve(path), &count);
 for (i=0;i<count;i++) {
  np = query_int_list(dir[i].fsid, "Part/File", parts, 1024 );
  nc = query_int_list(dir[i].fsid, "Part/CommercialSkipOffset", cso, 1024 );
  if (np > 0) {
   fprintf(stdout,"%s%s%s\n",
    (crypto_check(parts[np-1]) ? "Yes       " : "No        "),
    (nc==0 || cso[nc-1]==0 ? "No      " : "Yes     "),
    query_string(dir[i].fsid, "Showing/Program/Title"));
  }
 }
 if (dir) mfs_dir_free(dir);
}

canonical_original_code:
static void ciphercheck(char *path)
{
 struct mfs_dirent *dir;
 int parts[1024];
 int cso[1024];
 unsigned int count; unsigned int i;
 int np; int nc;
 fprintf( stdout, "CipherCheck - based on CipherCheck.tcl by AlphaWolf_HK\n\n" );
 dir = mfs_dir(mfs_resolve("/Recording/LiveCache"), &count);
 if (count > 0) {
  np = query_int_list(dir[0].fsid, "Part/File", parts, 1024 );
  if (dir) mfs_dir_free(dir);
  if (np > 0)
   fprintf( stdout, "TyStream encryption is currently %s.\n",
     crypto_check(parts[np-1])? "enabled" : "disabled");
 }
 fprintf( stdout, "\nHere is the status of your current recordings:\n\nEncrypted CSO Set Stream Name\n--------- ------- -----------\n");
 dir = mfs_dir(mfs_resolve(path), &count);
 for (i=0;i<count;i++) {
  np = query_int_list(dir[i].fsid, "Part/File", parts, 1024 );
  nc = query_int_list(dir[i].fsid, "Part/CommercialSkipOffset", cso, 1024 );
  if (np > 0) {
   fprintf(stdout,"%s%s%s\n",
    (crypto_check(parts[np-1]) ? "Yes       " : "No        "),
    (nc==0 || cso[nc-1]==0 ? "No      " : "Yes     "),
    query_string(dir[i].fsid, "Showing/Program/Title"));
  }
 }
 if (dir) mfs_dir_free(dir);
}

variable_types:
path
char *

variable_types: struct mfs_dirent { unsigned int fsid; unsigned char type; char *name; } *

variable_types:
parts
int [1024]

variable_types:
cso
int [1024]

variable_types:
count
unsigned int

variable_types:
i
unsigned int

variable_types: np int

variable_types: nc int


usage

decompiled_code:
void __noreturn usage()
{
puts("\nusage: ciphercheck\n");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("\nusage: ciphercheck\n");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\nusage: ciphercheck\n\n");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\nusage: ciphercheck\n\n");
 credits();
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rdi
__int64 v5; // rax

if ( getopt(argc, (char *const *)argv, &shortopts) != -1 )
usage();
mfs_init();
if ( (unsigned int)mfs_resolve("/Recording/NowShowingByClassic") )
{
v5 = 0LL;
LABEL_7:
v3 = paths_1[v5];
goto LABEL_5;
}
if ( (unsigned int)mfs_resolve("/Recording/NowShowing") )
{
v5 = 1LL;
goto LABEL_7;
}
v3 = 0LL;
if ( (unsigned int)mfs_resolve("/Recording/Complete") )
{
v5 = 2LL;
goto LABEL_7;
}
LABEL_5:
ciphercheck((__int64)v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rdi
__int64 v5; // rax

if ( getopt(argc, (char *const *)argv, &shortopts) != -1 )
func0();
mfs_init();
if ( (unsigned int)mfs_resolve("/Recording/NowShowingByClassic") )
{
v5 = 0LL;
LABEL_7:
v3 = paths_1[v5];
goto LABEL_5;
}
if ( (unsigned int)mfs_resolve("/Recording/NowShowing") )
{
v5 = 1LL;
goto LABEL_7;
}
v3 = 0LL;
if ( (unsigned int)mfs_resolve("/Recording/Complete") )
{
v5 = 2LL;
goto LABEL_7;
}
LABEL_5:
func2((__int64)v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 const char *path = ((void *)0);
 int c,i;
 static const char *paths[] = {
   "/Recording/NowShowingByClassic",
   "/Recording/NowShowing",
   "/Recording/Complete",
 };
 static const int count = sizeof(paths)/sizeof(paths[0]);
 while ((c = getopt(argc, argv, "")) != -1 ){
  switch (c) {
  default:
   usage();
  }
 }
 mfs_init();
 for(i=0; i<count; i++)
   if (mfs_resolve(paths[i]) != 0) {
     path = paths[i];
     break;
   }
 ciphercheck(path);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *path = ((void *)0);
 int c; int i;
 static char *paths[] = {
   "/Recording/NowShowingByClassic",
   "/Recording/NowShowing",
   "/Recording/Complete",
 };
 static int count = sizeof(paths)/sizeof(paths[0]);
 while ((c = getopt(argc, argv, "")) != -1 ){
  switch (c) {
  default:
   usage();
  }
 }
 mfs_init();
 for(i=0; i<count; i++)
   if (mfs_resolve(paths[i]) != 0) {
     path = paths[i];
     break;
   }
 ciphercheck(path);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
paths
char *[]

variable_types: count int


decompiled_code:
__int64 queue_new()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static queue queue_new() {
 queue rv;
 rv.nq = rv.nalloc = 0;
 rv.queue = 0;
 return rv;
}

canonical_original_code:
static struct queue_t queue_new() {
 struct queue_t rv;
 rv.nq = rv.nalloc = 0;
 rv.queue = 0;
 return rv;
}

variable_types: struct queue_t { int nq; int nalloc; int *queue; }


decompiled_code:
__int64 hash_table_new()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
static hash_table hash_table_new() {
 hash_table rv;
 rv.hash_table = 0;
 rv.hash_size = 0;
 return rv;
}

canonical_original_code:
static struct hash_table_t hash_table_new() {
 struct hash_table_t rv;
 rv.hash_table = 0;
 rv.hash_size = 0;
 return rv;
}

variable_types: struct hash_table_t { int *hash_table; unsigned int hash_size; }


decompiled_code:
__int64 __fastcall hash_table_search(__int64 *a1, unsigned int a2)
{
unsigned int v4; // er12
signed int v5; // eax
__int64 v6; // rsi
signed int v7; // edi
unsigned int v8; // eax
signed int v9; // edx
unsigned int *v10; // rcx
unsigned int v12; // eax
size_t v13; // r13
void *v14; // rax

if ( *a1 )
{
v4 = *((_DWORD *)a1 + 2);
}
else
{
v12 = inode_count();
*((_DWORD *)a1 + 2) = v12;
v4 = v12;
v13 = 4LL * v12;
v14 = malloc(v13);
*a1 = (__int64)v14;
if ( !v14 )
_assert_fail("h->hash_table", "mfs_info.c", 0x55u, "hash_table_search");
if ( v4 )
memset(v14, 255, v13);
}
v5 = fsid_hash(a2, v4);
v6 = *a1;
v7 = v5;
v8 = *(_DWORD *)(*a1 + 4LL * v5);
v9 = v7;
while ( 1 )
{
if ( a2 == v8 )
return 1LL;
if ( v8 == -1 )
{
v10 = (unsigned int *)(v6 + 4LL * v9);
LABEL_9:
*v10 = a2;
return 0LL;
}
v9 = (unsigned int)(v9 + 1) % *((_DWORD *)a1 + 2);
v10 = (unsigned int *)(v6 + 4LL * v9);
v8 = *v10;
if ( v7 == v9 )
break;
if ( v8 == -1 )
goto LABEL_9;
}
if ( v8 == -1 )
goto LABEL_9;
fwrite("hash table full!?\n", 1uLL, 0x12uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, unsigned int a2)
{
unsigned int v4; // er12
signed int v5; // eax
__int64 v6; // rsi
signed int v7; // edi
unsigned int v8; // eax
signed int v9; // edx
unsigned int *v10; // rcx
unsigned int v12; // eax
size_t v13; // r13
void *v14; // rax

if ( *a1 )
{
v4 = *((_DWORD *)a1 + 2);
}
else
{
v12 = inode_count();
*((_DWORD *)a1 + 2) = v12;
v4 = v12;
v13 = 4LL * v12;
v14 = malloc(v13);
*a1 = (__int64)v14;
if ( !v14 )
_assert_fail("h->hash_table", "mfs_info.c", 0x55u, "hash_table_search");
if ( v4 )
memset(v14, 255, v13);
}
v5 = fsid_hash(a2, v4);
v6 = *a1;
v7 = v5;
v8 = *(_DWORD *)(*a1 + 4LL * v5);
v9 = v7;
while ( 1 )
{
if ( a2 == v8 )
return 1LL;
if ( v8 == -1 )
{
v10 = (unsigned int *)(v6 + 4LL * v9);
LABEL_9:
*v10 = a2;
return 0LL;
}
v9 = (unsigned int)(v9 + 1) % *((_DWORD *)a1 + 2);
v10 = (unsigned int *)(v6 + 4LL * v9);
v8 = *v10;
if ( v7 == v9 )
break;
if ( v8 == -1 )
goto LABEL_9;
}
if ( v8 == -1 )
goto LABEL_9;
fwrite("hash table full!?\n", 1uLL, 0x12uLL, stderr);
return 0LL;
}

original_code:
static int hash_table_search(hash_table *h, int fsid) {
 int i, hash, first;
 if (! h->hash_table) {
  h->hash_size = inode_count();
  h->hash_table = malloc( h->hash_size * sizeof(int) );
  ((void) sizeof ((h->hash_table) ? 1 : 0), __extension__ ({ if (h->hash_table) ; else __assert_fail ("h->hash_table", "mfs_info.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  for(i=0; i<h->hash_size; i++)
   h->hash_table[i] = -1;
 }
 first = hash = fsid_hash( fsid, h->hash_size );
 do {
  if(h->hash_table[hash] == fsid) return 1;
  if (h->hash_table[hash] != -1)
   hash = (hash+1)%h->hash_size;
 } while (hash != first && h->hash_table[hash] != -1);
 if (h->hash_table[hash] != -1)
  fprintf( stderr, "hash table full!?\n" );
 else
  h->hash_table[hash] = fsid;
 return 0;
}

canonical_original_code:
static int hash_table_search(struct hash_table_t *h, int fsid) {
 int i; int hash; int first;
 if (! h->hash_table) {
  h->hash_size = inode_count();
  h->hash_table = malloc( h->hash_size * sizeof(int) );
  ((void) sizeof ((h->hash_table) ? 1 : 0), __extension__ ({ if (h->hash_table) ; else __assert_fail ("h->hash_table", "mfs_info.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  for(i=0; i<h->hash_size; i++)
   h->hash_table[i] = -1;
 }
 first = hash = fsid_hash( fsid, h->hash_size );
 do {
  if(h->hash_table[hash] == fsid) return 1;
  if (h->hash_table[hash] != -1)
   hash = (hash+1)%h->hash_size;
 } while (hash != first && h->hash_table[hash] != -1);
 if (h->hash_table[hash] != -1)
  fprintf( stderr, "hash table full!?\n" );
 else
  h->hash_table[hash] = fsid;
 return 0;
}

variable_types: struct hash_table_t { int *hash_table; unsigned int hash_size; } *

variable_types: fsid int

variable_types: i int

variable_types: hash int

variable_types: first int


decompiled_code:
__int64 __fastcall queue_copy(const void **a1)
{
__int64 v1; // rbx
void *v2; // rax

v1 = *(int *)a1;
v2 = malloc(4 * v1);
memcpy(v2, a1[1], 4 * v1);
return (v1 << 32) | (unsigned int)v1;
}

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

v1 = *(int *)a1;
v2 = malloc(4 * v1);
memcpy(v2, a1[1], 4 * v1);
return (v1 << 32) | (unsigned int)v1;
}

original_code:
static queue queue_copy(queue *q) {
 queue rv;
 rv.nq = rv.nalloc = q->nq;
 rv.queue = malloc( q->nq*sizeof(int) );
 memcpy( rv.queue, q->queue, q->nq*sizeof(int) );
 return rv;
}

canonical_original_code:
static struct queue_t queue_copy(struct queue_t *q) {
 struct queue_t rv;
 rv.nq = rv.nalloc = q->nq;
 rv.queue = malloc( q->nq*sizeof(int) );
 memcpy( rv.queue, q->queue, q->nq*sizeof(int) );
 return rv;
}

variable_types:
q
struct queue_t *

return_type: struct queue_t { int nq; int nalloc; int *queue; }


decompiled_code:
void __fastcall queue_free(__int64 a1)
{
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = 0LL;
}

original_code:
static void queue_free(queue *q) {
 free(q->queue);
 q->nalloc = q->nq = 0;
}

canonical_original_code:
static void queue_free(struct queue_t *q) {
 free(q->queue);
 q->nalloc = q->nq = 0;
}

variable_types: struct queue_t { int nq; int nalloc; int *queue; } *


decompiled_code:
void __fastcall hash_table_free(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}
}

original_code:
static void hash_table_free(hash_table *h) {
 if (h->hash_table) {
  free(h->hash_table);
  h->hash_table = 0;
  h->hash_size = 0;
 }
}

canonical_original_code:
static void hash_table_free(struct hash_table_t *h) {
 if (h->hash_table) {
  free(h->hash_table);
  h->hash_table = 0;
  h->hash_size = 0;
 }
}

user_defined_types: struct hash_table_t { int *hash_table; unsigned int hash_size; }


decompiled_code:
int __fastcall stream_scan1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
const void *v7; // rdx
__int64 v8; // rax
__int64 v9; // rdx
unsigned int v10; // eax
__int64 v11; // r8
__int64 v12; // r9
const void *v14[2]; // [rsp+0h] [rbp-68h] BYREF
__int64 v15[2]; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v16; // [rsp+20h] [rbp-48h] BYREF
unsigned int v17; // [rsp+30h] [rbp-38h]
__int16 v18; // [rsp+34h] [rbp-34h] BYREF
int v19; // [rsp+36h] [rbp-32h]
__int16 v20; // [rsp+3Ah] [rbp-2Eh]
unsigned __int64 *v21; // [rsp+3Ch] [rbp-2Ch]
int v22; // [rsp+44h] [rbp-24h]
char *v23; // [rsp+50h] [rbp-18h]

v18 = -17599;
v23 = &a7;
v19 = (int)sfn_0;
v21 = &v16;
v20 = -17847;
v22 = -1864106167;
v17 = 0;
v16 = 0LL;
fprintf(stderr, "traversing %s... ", "/Resource");
LOBYTE(v14[0]) = queue_new("/Resource");
v14[1] = v7;
v8 = hash_table_new();
v15[1] = v9;
v15[0] = v8;
v10 = mfs_resolve();
traverse(v14, v15, v10, (void (__fastcall *)(_QWORD))&v18, v11, v12, (char)v14[0]);
queue_free((__int64)v14);
hash_table_free((__int64)v15);
fputc(10, stderr);
fprintf(stderr, "max stream fsid under /Resource: %d\n", v17);
return fprintf(stderr, "max stream size under /Resource: %uMB\n", v16 >> 20);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
const void *v7; // rdx
__int64 v8; // rax
__int64 v9; // rdx
unsigned int v10; // eax
__int64 v11; // r8
__int64 v12; // r9
const void *v14[2]; // [rsp+0h] [rbp-68h] BYREF
__int64 v15[2]; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v16; // [rsp+20h] [rbp-48h] BYREF
unsigned int v17; // [rsp+30h] [rbp-38h]
__int16 v18; // [rsp+34h] [rbp-34h] BYREF
int v19; // [rsp+36h] [rbp-32h]
__int16 v20; // [rsp+3Ah] [rbp-2Eh]
unsigned __int64 *v21; // [rsp+3Ch] [rbp-2Ch]
int v22; // [rsp+44h] [rbp-24h]
char *v23; // [rsp+50h] [rbp-18h]

v18 = -17599;
v23 = &a7;
v19 = (int)sfn_0;
v21 = &v16;
v20 = -17847;
v22 = -1864106167;
v17 = 0;
v16 = 0LL;
fprintf(stderr, "traversing %s... ", "/Resource");
LOBYTE(v14[0]) = func0("/Resource");
v14[1] = v7;
v8 = func1();
v15[1] = v9;
v15[0] = v8;
v10 = mfs_resolve();
func11(v14, v15, v10, (void (__fastcall *)(_QWORD))&v18, v11, v12, (char)v14[0]);
func10((__int64)v14);
func12((__int64)v15);
fputc(10, stderr);
fprintf(stderr, "max stream fsid under /Resource: %d\n", v17);
return fprintf(stderr, "max stream size under /Resource: %uMB\n", v16 >> 20);
}

original_code:
static void stream_scan1()
{
 const char *path = "/Resource";
 int mx_fsid = 0;
 u64 mx_sz = 0;
 u64 size;
 queue q;
 hash_table h;
 void sfn(int fsid) {
  struct mfs_inode inode;
  mfs_load_inode( fsid, &inode );
  if (fsid > mx_fsid) mx_fsid = fsid;
  size = inode.size;
  if (inode.units == 0x20000)
   size <<= 17;
  if (size > mx_sz) mx_sz = size;
  fprintf( stderr, ".");
 }
 fprintf( stderr, "traversing %s... ", path );
 q = queue_new();
 h = hash_table_new();
 traverse(&q, &h, mfs_resolve(path), sfn );
 queue_free(&q);
 hash_table_free(&h);
 fprintf( stderr, "\n" );
 fprintf( stderr, "max stream fsid under /Resource: %d\n", mx_fsid );
 fprintf( stderr, "max stream size under /Resource: %uMB\n", (unsigned int)(mx_sz/(1024*1024)));
}

canonical_original_code:
static void stream_scan1()
{
 char *path = "/Resource";
 int mx_fsid = 0;
 unsigned int mx_sz = 0;
 unsigned int size;
 struct queue_t q;
 struct hash_table_t h;
 void sfn(int fsid) {
  struct mfs_inode inode;
  mfs_load_inode( fsid, &inode );
  if (fsid > mx_fsid) mx_fsid = fsid;
  size = inode.size;
  if (inode.units == 0x20000)
   size <<= 17;
  if (size > mx_sz) mx_sz = size;
  fprintf( stderr, ".");
 }
 fprintf( stderr, "traversing %s... ", path );
 q = queue_new();
 h = hash_table_new();
 traverse(&q, &h, mfs_resolve(path), sfn );
 queue_free(&q);
 hash_table_free(&h);
 fprintf( stderr, "\n" );
 fprintf( stderr, "max stream fsid under /Resource: %d\n", mx_fsid );
 fprintf( stderr, "max stream size under /Resource: %uMB\n", (unsigned int)(mx_sz/(1024*1024)));
}

variable_types:
path
char *

variable_types:
size
unsigned int

variable_types: struct mfs_inode { unsigned int id; unsigned int typexx; unsigned int fill1[3]; unsigned int units; unsigned int size; unsigned int used_units; unsigned int used_size; unsigned int fill2; unsigned char type; unsigned char fill3; unsigned short fill4; unsigned int fill5; unsigned int crc; unsigned int flags; unsigned int num_runs; union { struct mfs_run { unsigned int start; unsigned int len; } runs[56]; char data[452]; } u; }

user_defined_types: struct queue_t { int nq; int nalloc; int *queue; }

user_defined_types: struct mfs_inode { unsigned int id; unsigned int typexx; unsigned int fill1[3]; unsigned int units; unsigned int size; unsigned int used_units; unsigned int used_size; unsigned int fill2; unsigned char type; unsigned char fill3; unsigned short fill4; unsigned int fill5; unsigned int crc; unsigned int flags; unsigned int num_runs; union { struct mfs_run runs[56]; char data[452]; } u; }


decompiled_code:
int __fastcall stream_scan2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rdx
unsigned int v10; // eax
__int64 v11; // r8
__int64 v12; // r9
__int64 v13; // rax
__int64 v14; // rdx
const char *v15; // rdx
__int64 v16; // rdx
const void *v17; // rax
__int64 v18; // rdx
unsigned int v19; // eax
__int64 v20; // r8
__int64 v21; // r9
__int64 v22; // rbx
unsigned __int64 v23; // r12
unsigned int v24; // er13
unsigned int v25; // ebp
unsigned __int64 v26; // rax
const void *v28; // [rsp+0h] [rbp-288h] BYREF
__int64 v29; // [rsp+8h] [rbp-280h]
__int64 v30; // [rsp+10h] [rbp-278h] BYREF
__int64 v31; // [rsp+18h] [rbp-270h]
__int64 v32; // [rsp+20h] [rbp-268h] BYREF
__int64 v33; // [rsp+28h] [rbp-260h]
__int16 v34; // [rsp+30h] [rbp-258h] BYREF
int v35; // [rsp+32h] [rbp-256h]
__int16 v36; // [rsp+36h] [rbp-252h]
__int64 *v37; // [rsp+38h] [rbp-250h]
int v38; // [rsp+40h] [rbp-248h]
char *v39; // [rsp+50h] [rbp-238h]
char v40[20]; // [rsp+60h] [rbp-228h] BYREF
int v41; // [rsp+74h] [rbp-214h]
unsigned int v42; // [rsp+78h] [rbp-210h]

v36 = -17847;
v39 = &a7;
v34 = -17599;
v35 = (int)check_inode_fn_2;
v37 = &v30;
v38 = -1864106167;
fprintf(stderr, "traversing %s... ", "/Recording");
LOBYTE(v28) = queue_new("/Recording");
v29 = v7;
v8 = ((__int64 (*)(void))hash_table_new)();
v33 = v9;
v32 = v8;
v10 = mfs_resolve();
traverse(&v28, &v32, v10, 0LL, v11, v12, (char)v28);
queue_free((__int64)&v28);
fputc(10, stderr);
fwrite("scanning inodes... ", 1uLL, 0x13uLL, stderr);
v13 = queue_new(&v34);
v31 = v14;
v30 = v13;
mfs_all_inodes();
fputc(10, stderr);
hash_table_free((__int64)&v32);
v32 = hash_table_new(&v32, "traversing %s... ", v15);
v33 = v16;
fprintf(stderr, "traversing %s... ", "/Recording");
v17 = (const void *)queue_new("/Recording");
v29 = v18;
v28 = v17;
v19 = mfs_resolve();
traverse(&v28, &v32, v19, 0LL, v20, v21, (char)v28);
queue_free((__int64)&v28);
fputc(10, stderr);
if ( (int)v30 <= 0 )
{
v23 = 0LL;
v24 = 0;
}
else
{
v22 = 0LL;
v23 = 0LL;
v24 = 0;
do
{
v25 = *(_DWORD *)(v31 + 4 * v22);
if ( !(unsigned int)hash_table_search(&v32, v25) )
{
fprintf(stderr, "%d ", v25);
mfs_load_inode(v25, v40);
v26 = v42;
if ( (int)v24 < (int)v25 )
v24 = v25;
if ( v41 == 0x20000 )
v26 = (unsigned __int64)v42 << 17;
if ( v23 < v26 )
v23 = v26;
}
++v22;
}
while ( (int)v30 > (int)v22 );
}
fputc(10, stderr);
queue_free((__int64)&v30);
hash_table_free((__int64)&v32);
fprintf(stderr, "max stream fsid excluding /Recordings: %d\n", v24);
return fprintf(stderr, "max stream size excluding /Recordings: %uMB\n", v23 >> 20);
}

original_code:
static void stream_scan2()
{
 const char *path = "/Recording";
 int i, mx_fsid = 0;
 u64 mx_sz = 0;
 u64 size;
 queue q, q1;
 hash_table h;
 void check_inode_fn(struct mfs_inode *inode) {
  if (inode->type != 2) return;
  if (hash_table_search(&h,inode->id)) return;
  fprintf( stderr, ".");
  queue_add(&q, inode->id);
 }
 fprintf( stderr, "traversing %s... ", path );
 q1 = queue_new();
 h = hash_table_new();
 traverse(&q1, &h, mfs_resolve(path),0);
 queue_free(&q1);
 fprintf( stderr, "\n" );
 fprintf( stderr, "scanning inodes... ");
 q = queue_new();
 mfs_all_inodes( check_inode_fn );
 fprintf( stderr, "\n" );
 hash_table_free(&h);
 h = hash_table_new();
 fprintf( stderr, "traversing %s... ", path );
 q1 = queue_new();
 traverse(&q1, &h, mfs_resolve(path),0);
 queue_free(&q1);
 fprintf( stderr, "\n" );
 for(i=0; i<q.nq; i++) {
  int fsid = q.queue[i];
  struct mfs_inode inode;
  if (hash_table_search( &h, fsid)) continue;
  fprintf( stderr, "%d ", fsid );
  mfs_load_inode( fsid, &inode );
  if (fsid > mx_fsid) mx_fsid = fsid;
  size = inode.size;
  if (inode.units == 0x20000)
   size <<= 17;
  if (size > mx_sz) mx_sz = size;
 }
 fprintf( stderr, "\n");
 queue_free(&q);
 hash_table_free(&h);
 fprintf( stderr, "max stream fsid excluding /Recordings: %d\n", mx_fsid );
 fprintf( stderr, "max stream size excluding /Recordings: %uMB\n", (unsigned int)(mx_sz/(1024*1024)));
}

canonical_original_code:
static void stream_scan2()
{
 char *path = "/Recording";
 int i; int mx_fsid = 0;
 unsigned int mx_sz = 0;
 unsigned int size;
 struct queue_t q; struct queue_t q1;
 struct hash_table_t h;
 void check_inode_fn(struct mfs_inode *inode) {
  if (inode->type != 2) return;
  if (hash_table_search(&h,inode->id)) return;
  fprintf( stderr, ".");
  queue_add(&q, inode->id);
 }
 fprintf( stderr, "traversing %s... ", path );
 q1 = queue_new();
 h = hash_table_new();
 traverse(&q1, &h, mfs_resolve(path),0);
 queue_free(&q1);
 fprintf( stderr, "\n" );
 fprintf( stderr, "scanning inodes... ");
 q = queue_new();
 mfs_all_inodes( check_inode_fn );
 fprintf( stderr, "\n" );
 hash_table_free(&h);
 h = hash_table_new();
 fprintf( stderr, "traversing %s... ", path );
 q1 = queue_new();
 traverse(&q1, &h, mfs_resolve(path),0);
 queue_free(&q1);
 fprintf( stderr, "\n" );
 for(i=0; i<q.nq; i++) {
  int fsid = q.queue[i];
  struct mfs_inode inode;
  if (hash_table_search( &h, fsid)) continue;
  fprintf( stderr, "%d ", fsid );
  mfs_load_inode( fsid, &inode );
  if (fsid > mx_fsid) mx_fsid = fsid;
  size = inode.size;
  if (inode.units == 0x20000)
   size <<= 17;
  if (size > mx_sz) mx_sz = size;
 }
 fprintf( stderr, "\n");
 queue_free(&q);
 hash_table_free(&h);
 fprintf( stderr, "max stream fsid excluding /Recordings: %d\n", mx_fsid );
 fprintf( stderr, "max stream size excluding /Recordings: %uMB\n", (unsigned int)(mx_sz/(1024*1024)));
}

user_defined_types: struct mfs_run { unsigned int start; unsigned int len; }


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"\n"
"usage: %s [options] [<path|fsid>]\n"
"\n"
" options:\n"
"\t-f\t\tFix the superblock crc, if it is incorrect.\n"
"\t-h\t\tDisplay this usage info.\n"
" -s|s1 Scan for max tyStream fsid referenced in /Resource\n"
" -s2 Scan for max tyStream fsid NOT referenced in /Recording\n"
" -s3 Run both the s1 and s2 scans.\n",
(const char *)&unk_91E);
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
fprintf(
stderr,
"\n"
"usage: %s [options] [<path|fsid>]\n"
"\n"
" options:\n"
"\t-f\t\tFix the superblock crc, if it is incorrect.\n"
"\t-h\t\tDisplay this usage info.\n"
" -s|s1 Scan for max tyStream fsid referenced in /Resource\n"
" -s2 Scan for max tyStream fsid NOT referenced in /Recording\n"
" -s3 Run both the s1 and s2 scans.\n",
(const char *)&unk_91E);
credits();
exit(1);
}

original_code:
static void usage(void)
{
 fprintf(stderr,"\nusage: %s [options] [<path|fsid>]\n\n   options:\n	-f		Fix the superblock crc, if it is incorrect.\n	-h		Display this usage info.\n        -s|s1           Scan for max tyStream fsid referenced in /Resource\n        -s2             Scan for max tyStream fsid NOT referenced in /Recording\n        -s3             Run both the s1 and s2 scans.\n", prog );
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr,"\nusage: %s [options] [<path|fsid>]\n\n   options:\n	-f		Fix the superblock crc, if it is incorrect.\n	-h		Display this usage info.\n        -s|s1           Scan for max tyStream fsid referenced in /Resource\n        -s2             Scan for max tyStream fsid NOT referenced in /Recording\n        -s3             Run both the s1 and s2 scans.\n", prog );
 credits();
 exit(1);
}


decompiled_code:
__int64 __fastcall queue_add(int *a1, int a2)
{
__int64 result; // rax
void *v5; // rdi
int v6; // eax
size_t v7; // rsi
_DWORD *v8; // rax
_DWORD *v9; // rdi

result = *a1;
v5 = (void *)*((_QWORD *)a1 + 1);
if ( (_DWORD)result == a1[1] )
{
if ( (int)result <= 0 )
{
v7 = 409600LL;
v6 = 102400;
}
else
{
v6 = 2 * result;
v7 = 4LL * v6;
}
a1[1] = v6;
v8 = realloc(v5, v7);
*((_QWORD *)a1 + 1) = v8;
v9 = v8;
result = *a1;
*a1 = result + 1;
v9[result] = a2;
}
else
{
*a1 = result + 1;
*((_DWORD *)v5 + result) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, int a2)
{
__int64 result; // rax
void *v5; // rdi
int v6; // eax
size_t v7; // rsi
_DWORD *v8; // rax
_DWORD *v9; // rdi

result = *a1;
v5 = (void *)*((_QWORD *)a1 + 1);
if ( (_DWORD)result == a1[1] )
{
if ( (int)result <= 0 )
{
v7 = 409600LL;
v6 = 102400;
}
else
{
v6 = 2 * result;
v7 = 4LL * v6;
}
a1[1] = v6;
v8 = realloc(v5, v7);
*((_QWORD *)a1 + 1) = v8;
v9 = v8;
result = *a1;
*a1 = result + 1;
v9[result] = a2;
}
else
{
*a1 = result + 1;
*((_DWORD *)v5 + result) = a2;
}
return result;
}

original_code:
static void queue_add(queue *q, int fsid) {
 if (q->nq == q->nalloc) {
  q->nalloc = (q->nalloc <= 0) ? 102400 : q->nalloc*2;
  q->queue = realloc( q->queue, q->nalloc*sizeof(int) );
 }
 q->queue[q->nq++] = fsid;
}

canonical_original_code:
static void queue_add(struct queue_t *q, int fsid) {
 if (q->nq == q->nalloc) {
  q->nalloc = (q->nalloc <= 0) ? 102400 : q->nalloc*2;
  q->queue = realloc( q->queue, q->nalloc*sizeof(int) );
 }
 q->queue[q->nq++] = fsid;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
unsigned int v4; // ebp
int v5; // eax
__int64 v6; // r14
int v7; // ebx
unsigned int v8; // eax
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
char v18; // [rsp+0h] [rbp-28h]

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hfs::");
if ( v5 == -1 )
break;
if ( v5 == 104 )
usage();
if ( v5 == 115 )
{
v3 = 1;
if ( optarg )
v3 = atoi(optarg);
}
else if ( v5 == 102 )
{
v4 = 1;
}
}
v6 = optind;
v7 = argc - optind;
mfs_init_fix(v4);
mfs_info();
if ( v7 > 0 )
{
putchar(10);
v8 = mfs_resolve(argv[v6]);
mfs_fsid_info(v8);
}
if ( (v3 & 1) != 0 )
{
putchar(10);
stream_scan1(10LL, (__int64)argv, v10, v11, v12, v13, v18);
}
if ( (v3 & 2) != 0 )
{
putchar(10);
stream_scan2(10LL, (__int64)argv, v14, v15, v16, v17, v18);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
unsigned int v4; // ebp
int v5; // eax
__int64 v6; // r14
int v7; // ebx
unsigned int v8; // eax
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
char v18; // [rsp+0h] [rbp-28h]

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hfs::");
if ( v5 == -1 )
break;
if ( v5 == 104 )
func2();
if ( v5 == 115 )
{
v3 = 1;
if ( optarg )
v3 = atoi(optarg);
}
else if ( v5 == 102 )
{
v4 = 1;
}
}
v6 = optind;
v7 = argc - optind;
mfs_init_fix(v4);
mfs_info();
if ( v7 > 0 )
{
putchar(10);
v8 = mfs_resolve(argv[v6]);
mfs_fsid_info(v8);
}
if ( (v3 & 1) != 0 )
{
putchar(10);
func13(10LL, (__int64)argv, v10, v11, v12, v13, v18);
}
if ( (v3 & 2) != 0 )
{
putchar(10);
func14(10LL, (__int64)argv, v14, v15, v16, v17, v18);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int c;
 int fix=0;
 int scan = 0;
 while ((c = getopt(argc, argv, "hfs::")) != -1 ){
  switch (c) {
  case 'h':
   usage();
   break;
  case 'f':
   fix = 1;
   break;
  case 's':
   if (optarg != 0)
    scan = atoi(optarg);
   else
    scan = 1;
   break;
  }
 }
 argc -= optind;
 argv += optind;
 mfs_init_fix(fix);
 mfs_info();
 if (argc > 0) {
  printf("\n");
  mfs_fsid_info(mfs_resolve(argv[0]));
 }
 if (scan & 1) {
  printf("\n");
  stream_scan1();
 }
 if (scan & 2) {
  printf("\n");
  stream_scan2();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int c;
 int fix = 0;
 int scan = 0;
 while ((c = getopt(argc, argv, "hfs::")) != -1 ){
  switch (c) {
  case 'h':
   usage();
   break;
  case 'f':
   fix = 1;
   break;
  case 's':
   if (optarg != 0)
    scan = atoi(optarg);
   else
    scan = 1;
   break;
  }
 }
 argc -= optind;
 argv += optind;
 mfs_init_fix(fix);
 mfs_info();
 if (argc > 0) {
  printf("\n");
  mfs_fsid_info(mfs_resolve(argv[0]));
 }
 if (scan & 1) {
  printf("\n");
  stream_scan1();
 }
 if (scan & 2) {
  printf("\n");
  stream_scan2();
 }
 return 0;
}

variable_types: argc int

variable_types: fix int

variable_types: scan int


tzoffset

decompiled_code:
__int64 __fastcall tzoffset(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
unsigned int v7; // er12
int v9; // er12
__int64 v10; // rax
void *v11; // rsp
struct tm *v12; // rax
int v13; // edx
int v14; // ecx
int v15; // esi
bool v16; // dl
int v17; // edi
int v18; // eax
int v19; // er12
__int64 v20; // [rsp+0h] [rbp-50h] BYREF
time_t timer; // [rsp+8h] [rbp-48h] BYREF
__int64 v22; // [rsp+10h] [rbp-40h] BYREF
int v23; // [rsp+18h] [rbp-38h]
__int16 v24; // [rsp+1Ch] [rbp-34h] BYREF
unsigned int v25; // [rsp+1Eh] [rbp-32h]
__int16 v26; // [rsp+22h] [rbp-2Eh]
__int64 *v27; // [rsp+24h] [rbp-2Ch]
int v28; // [rsp+2Ch] [rbp-24h]
char *v29; // [rsp+38h] [rbp-18h]

v7 = tzoff_3;
v29 = &a7;
v24 = -17599;
v25 = (unsigned int)callback_0;
v26 = -17847;
v27 = &v22;
v28 = -1864106167;
v22 = 0LL;
v23 = 0;
if ( tzoff_3 != 0x7FFFFFFF )
return v7;
v9 = mfs_resolve("/State/LocationConfig");
if ( v9 > 0 || (v9 = mfs_resolve("/Setup"), v9 > 0) )
{
v10 = mfs_fsid_size((unsigned int)v9);
v11 = alloca(16 * (((unsigned __int64)(unsigned int)v10 + 23) >> 4));
mfs_fsid_pread((unsigned int)v9, &v20, 0LL, v10);
parse_object((unsigned int)v9, &v20, &v24);
}
v7 = tzoff_3;
if ( tzoff_3 == 0x7FFFFFFF )
{
v19 = v23;
if ( (unsigned int)(v23 - 1) <= 0x18 )
v19 = tzlist_1[v23];
v7 = 3600 * v19;
tzoff_3 = v7;
}
if ( (_DWORD)v22 != 2 && ((_DWORD)v22 != 0x7FFFFFFF || HIDWORD(v22) != 2 && HIDWORD(v22) != 0x7FFFFFFF) )
return v7;
timer = time(0LL);
v12 = gmtime(&timer);
v13 = v12->tm_mon;
if ( (unsigned int)(v13 - 4) <= 4 )
goto LABEL_19;
v14 = v12->tm_mday;
v15 = v13 + 1;
v16 = v13 == 3;
if ( v14 > 7 && v16 )
goto LABEL_19;
v17 = v12->tm_wday;
v18 = v12->tm_hour;
if ( v14 > 7 || !v16 )
{
if ( v14 <= 24 )
{
if ( v15 != 10 )
return v7;
goto LABEL_19;
}
if ( v15 == 10 )
{
if ( !v17 )
{
if ( v18 > 1 )
return v7;
goto LABEL_19;
}
if ( v14 - 24 - v17 <= 0 )
goto LABEL_19;
}
return v7;
}
if ( v17 )
{
if ( v14 - v17 > 0 )
goto LABEL_19;
return v7;
}
if ( v18 <= 1 )
return v7;
LABEL_19:
tzoff_3 = v7 + 3600;
return v7 + 3600;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
unsigned int v7; // er12
int v9; // er12
__int64 v10; // rax
void *v11; // rsp
struct tm *v12; // rax
int v13; // edx
int v14; // ecx
int v15; // esi
bool v16; // dl
int v17; // edi
int v18; // eax
int v19; // er12
__int64 v20; // [rsp+0h] [rbp-50h] BYREF
time_t timer; // [rsp+8h] [rbp-48h] BYREF
__int64 v22; // [rsp+10h] [rbp-40h] BYREF
int v23; // [rsp+18h] [rbp-38h]
__int16 v24; // [rsp+1Ch] [rbp-34h] BYREF
unsigned int v25; // [rsp+1Eh] [rbp-32h]
__int16 v26; // [rsp+22h] [rbp-2Eh]
__int64 *v27; // [rsp+24h] [rbp-2Ch]
int v28; // [rsp+2Ch] [rbp-24h]
char *v29; // [rsp+38h] [rbp-18h]

v7 = tzoff_3;
v29 = &a7;
v24 = -17599;
v25 = (unsigned int)callback_0;
v26 = -17847;
v27 = &v22;
v28 = -1864106167;
v22 = 0LL;
v23 = 0;
if ( tzoff_3 != 0x7FFFFFFF )
return v7;
v9 = mfs_resolve("/State/LocationConfig");
if ( v9 > 0 || (v9 = mfs_resolve("/Setup"), v9 > 0) )
{
v10 = mfs_fsid_size((unsigned int)v9);
v11 = alloca(16 * (((unsigned __int64)(unsigned int)v10 + 23) >> 4));
mfs_fsid_pread((unsigned int)v9, &v20, 0LL, v10);
parse_object((unsigned int)v9, &v20, &v24);
}
v7 = tzoff_3;
if ( tzoff_3 == 0x7FFFFFFF )
{
v19 = v23;
if ( (unsigned int)(v23 - 1) <= 0x18 )
v19 = tzlist_1[v23];
v7 = 3600 * v19;
tzoff_3 = v7;
}
if ( (_DWORD)v22 != 2 && ((_DWORD)v22 != 0x7FFFFFFF || HIDWORD(v22) != 2 && HIDWORD(v22) != 0x7FFFFFFF) )
return v7;
timer = time(0LL);
v12 = gmtime(&timer);
v13 = v12->tm_mon;
if ( (unsigned int)(v13 - 4) <= 4 )
goto LABEL_19;
v14 = v12->tm_mday;
v15 = v13 + 1;
v16 = v13 == 3;
if ( v14 > 7 && v16 )
goto LABEL_19;
v17 = v12->tm_wday;
v18 = v12->tm_hour;
if ( v14 > 7 || !v16 )
{
if ( v14 <= 24 )
{
if ( v15 != 10 )
return v7;
goto LABEL_19;
}
if ( v15 == 10 )
{
if ( !v17 )
{
if ( v18 > 1 )
return v7;
goto LABEL_19;
}
if ( v14 - 24 - v17 <= 0 )
goto LABEL_19;
}
return v7;
}
if ( v17 )
{
if ( v14 - v17 > 0 )
goto LABEL_19;
return v7;
}
if ( v18 <= 1 )
return v7;
LABEL_19:
tzoff_3 = v7 + 3600;
return v7 + 3600;
}

original_code:
int tzoffset()
{
 static int tzoff = 0x7fffffff;
 int tzOld = 0;
 int dstOld = 0;
 int useDst = 0;
 int fsid;
 void callback(int fsid, struct mfs_subobj_header *obj,
        struct mfs_attr_header *attr, void *data)
 {
  if(obj && attr) {
   if (obj->obj_type == 136) {
    if (attr->attr == 19)
     tzoff = ntohl(*(int *)data);
    else if (attr->attr == 17)
     tzOld = ntohl(*(int *)data);
    else if (attr->attr == 18)
     dstOld = ntohl(*(int *)data);
    else if (attr->attr == 21)
     useDst = ntohl(*(int *)data);
   } else if (obj->obj_type == 43) {
    if (attr->attr == 18)
     tzOld = ntohl(*(int *)data);
    else if (attr->attr == 19)
     dstOld = ntohl(*(int *)data);
   }
  }
 }
 if (tzoff != 0x7fffffff) return tzoff;
 fsid = mfs_resolve( "/State/LocationConfig" );
 if (fsid > 0) {
  u32 size = mfs_fsid_size(fsid);
  char *buf=__builtin_alloca (size);
  mfs_fsid_pread(fsid, buf, 0, size );
  parse_object(fsid, buf, callback);
 } else {
   fsid = mfs_resolve( "/Setup" );
   if (fsid > 0) {
    u32 size = mfs_fsid_size(fsid);
    char *buf=__builtin_alloca (size);
    mfs_fsid_pread(fsid, buf, 0, size );
    parse_object(fsid, buf, callback);
   }
 }
 if (tzoff == 0x7fffffff) {
  int tz = tzOld;
  static short tzlist[] = {-5,-6,-7,-8,-9,-10,0,1,2,3,4,5,6,7,8,9,10,11,12,-1,-2,-3,-4,-11,-12};
  static size_t l = sizeof(tzlist)/sizeof(tzlist[0]);
  if (tzOld>0 && tzOld <= l)
   tz = tzlist[tzOld];
  tzoff = tz*60*60;
 }
 if (useDst == 2 || (useDst==0x7fffffff &&
       (dstOld==2 || dstOld==0x7fffffff))) {
  time_t secs = time(0);
  struct tm *tm = gmtime(&secs);
  int month=tm->tm_mon+1,
   dom=tm->tm_mday,
   dow=tm->tm_wday,
   hour=tm->tm_hour;
  if ((month > 4 && month < 10) ||
      (month == 4 && dom > 7) ||
      (month == 4 && dom <= 7 && dow == 0 && hour >= 2) ||
      (month == 4 && dom <= 7 && dow != 0 && (dom-dow > 0)) ||
      (month == 10 && dom < 25) ||
      (month == 10 && dom >= 25 && dow == 0 && hour < 2) ||
      (month == 10 && dom >= 25 && dow != 0 && (dom-24-dow < 1) ))
   tzoff += 60*60;
 }
 return tzoff;
}

canonical_original_code:
int tzoffset()
{
 static int tzoff = 0x7fffffff;
 int tzOld = 0;
 int dstOld = 0;
 int useDst = 0;
 int fsid;
 void callback(int fsid, struct mfs_subobj_header *obj,
        struct mfs_attr_header *attr, void *data)
 {
  if(obj && attr) {
   if (obj->obj_type == 136) {
    if (attr->attr == 19)
     tzoff = ntohl(*(int *)data);
    else if (attr->attr == 17)
     tzOld = ntohl(*(int *)data);
    else if (attr->attr == 18)
     dstOld = ntohl(*(int *)data);
    else if (attr->attr == 21)
     useDst = ntohl(*(int *)data);
   } else if (obj->obj_type == 43) {
    if (attr->attr == 18)
     tzOld = ntohl(*(int *)data);
    else if (attr->attr == 19)
     dstOld = ntohl(*(int *)data);
   }
  }
 }
 if (tzoff != 0x7fffffff) return tzoff;
 fsid = mfs_resolve( "/State/LocationConfig" );
 if (fsid > 0) {
  unsigned int size = mfs_fsid_size(fsid);
  char *buf = __builtin_alloca (size);
  mfs_fsid_pread(fsid, buf, 0, size );
  parse_object(fsid, buf, callback);
 } else {
   fsid = mfs_resolve( "/Setup" );
   if (fsid > 0) {
    unsigned int size = mfs_fsid_size(fsid);
    char *buf = __builtin_alloca (size);
    mfs_fsid_pread(fsid, buf, 0, size );
    parse_object(fsid, buf, callback);
   }
 }
 if (tzoff == 0x7fffffff) {
  int tz = tzOld;
  static short tzlist[] = {-5,-6,-7,-8,-9,-10,0,1,2,3,4,5,6,7,8,9,10,11,12,-1,-2,-3,-4,-11,-12};
  static unsigned long l = sizeof(tzlist)/sizeof(tzlist[0]);
  if (tzOld>0 && tzOld <= l)
   tz = tzlist[tzOld];
  tzoff = tz*60*60;
 }
 if (useDst == 2 || (useDst==0x7fffffff &&
       (dstOld==2 || dstOld==0x7fffffff))) {
  long secs = time(0);
  struct tm *tm = gmtime(&secs);
  int month = tm->tm_mon+1; int dom = tm->tm_mday; int dow = tm->tm_wday; int hour = tm->tm_hour;
  if ((month > 4 && month < 10) ||
      (month == 4 && dom > 7) ||
      (month == 4 && dom <= 7 && dow == 0 && hour >= 2) ||
      (month == 4 && dom <= 7 && dow != 0 && (dom-dow > 0)) ||
      (month == 10 && dom < 25) ||
      (month == 10 && dom >= 25 && dow == 0 && hour < 2) ||
      (month == 10 && dom >= 25 && dow != 0 && (dom-24-dow < 1) ))
   tzoff += 60*60;
 }
 return tzoff;
}

variable_types: tzoff int

variable_types: tzOld int

variable_types: dstOld int

variable_types: useDst int

variable_types:
buf
char *

variable_types: tz int

variable_types:
tzlist
short []

variable_types:
l
unsigned long

variable_types: secs long

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

variable_types: month int

variable_types: dom int

variable_types: dow int

variable_types: hour int


decompiled_code:
char *__fastcall find_function(char *s2)
{
char *v2; // r13
const char **v3; // rbx
const char *v4; // rdi
int v5; // ebp

v2 = funcs;
while ( !v2 )
{
LABEL_7:
if ( *s2 != 109 || s2[1] != 102 || s2[2] != 115 )
return 0LL;
s2 += 3;
}
v3 = (const char **)(unsigned int)((_DWORD)&funcs + 24);
v4 = v2;
v5 = 0;
while ( strcasecmp(v4, s2) )
{
v4 = *v3;
v3 += 3;
++v5;
if ( !v4 )
goto LABEL_7;
}
return (&funcs)[3 * v5 + 1];
}

canonical_decompiled_code:
char *__fastcall func0(char *s2)
{
char *v2; // r13
const char **v3; // rbx
const char *v4; // rdi
int v5; // ebp

v2 = funcs;
while ( !v2 )
{
LABEL_7:
if ( *s2 != 109 || s2[1] != 102 || s2[2] != 115 )
return 0LL;
s2 += 3;
}
v3 = (const char **)(unsigned int)((_DWORD)&funcs + 24);
v4 = v2;
v5 = 0;
while ( strcasecmp(v4, s2) )
{
v4 = *v3;
v3 += 3;
++v5;
if ( !v4 )
goto LABEL_7;
}
return (&funcs)[3 * v5 + 1];
}

original_code:
mainfunc
find_function (char *name)
{
 int loop;
 for (loop = 0; funcs[loop].name; loop++)
  if (!strcasecmp (funcs[loop].name, name))
   return funcs[loop].main;
 if (!strncmp (name, "mfs", 3))
  return find_function (name + 3);
 return 0;
}

canonical_original_code:
int (*find_function(char *name))(int, char **)
{
 int loop;
 for (loop = 0; funcs[loop].name; loop++)
  if (!strcasecmp (funcs[loop].name, name))
   return funcs[loop].main;
 if (!strncmp (name, "mfs", 3))
  return find_function (name + 3);
 return 0;
}

variable_types:
name
char *

variable_types: loop int

return_type: int (*)(int, char **)


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rax
char *v5; // rax
char *v7; // rax
const char *v8; // rdx
const char **v9; // rbx
const char *v10; // rcx

v3 = (char *)*argv;
v4 = strrchr(*argv, 47);
if ( v4 )
v3 = v4 + 1;
v5 = find_function(v3);
if ( v5 )
return ((__int64 (__fastcall *)(_QWORD, const char **))v5)((unsigned int)argc, argv);
if ( argc > 1 )
{
v7 = find_function((char *)argv[1]);
if ( v7 )
return ((__int64 (__fastcall *)(_QWORD, const char **))v7)((unsigned int)(argc - 1), argv + 1);
}
fprintf(stderr, "%s %s\n", "MFSTools", "snapshot050221");
fprintf(stderr, "Usage: %s <function> <args> or <function> <args>\n", *argv);
fwrite("Available functions:\n", 1uLL, 0x15uLL, stderr);
v8 = funcs;
if ( funcs )
{
v9 = (const char **)(unsigned int)((_DWORD)&funcs + 16);
do
{
v10 = *v9;
v9 += 3;
fprintf(stderr, " %-10s%s\n", v8, v10);
v8 = *(v9 - 2);
}
while ( v8 );
}
fprintf(stderr, "For help on a particular function: %s <function> -h\n", *argv);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rax
char *v5; // rax
char *v7; // rax
const char *v8; // rdx
const char **v9; // rbx
const char *v10; // rcx

v3 = (char *)*argv;
v4 = strrchr(*argv, 47);
if ( v4 )
v3 = v4 + 1;
v5 = func0(v3);
if ( v5 )
return ((__int64 (__fastcall *)(_QWORD, const char **))v5)((unsigned int)argc, argv);
if ( argc > 1 )
{
v7 = func0((char *)argv[1]);
if ( v7 )
return ((__int64 (__fastcall *)(_QWORD, const char **))v7)((unsigned int)(argc - 1), argv + 1);
}
fprintf(stderr, "%s %s\n", "MFSTools", "snapshot050221");
fprintf(stderr, "Usage: %s <function> <args> or <function> <args>\n", *argv);
fwrite("Available functions:\n", 1uLL, 0x15uLL, stderr);
v8 = funcs;
if ( funcs )
{
v9 = (const char **)(unsigned int)((_DWORD)&funcs + 16);
do
{
v10 = *v9;
v9 += 3;
fprintf(stderr, " %-10s%s\n", v8, v10);
v8 = *(v9 - 2);
}
while ( v8 );
}
fprintf(stderr, "For help on a particular function: %s <function> -h\n", *argv);
return 1;
}

original_code:
int
main (int argc, char **argv)
{
 mainfunc toolmain;
 char *tmp;
 int loop;
 tmp = strrchr(argv[0], '/');
 tmp = tmp? tmp + 1: argv[0];
 if ((toolmain = find_function (tmp)))
 {
  return toolmain (argc, argv);
 }
 if (argc > 1 && (toolmain = find_function (argv[1])))
 {
  return toolmain (argc - 1, argv + 1);
 }
 fprintf (stderr, "%s %s\n", "MFSTools", "snapshot050221");
 fprintf (stderr, "Usage: %s <function> <args> or <function> <args>\n", argv[0]);
 fprintf (stderr, "Available functions:\n");
 for (loop = 0; funcs[loop].name; loop++)
  fprintf (stderr, "  %-10s%s\n", funcs[loop].name, funcs[loop].desc);
 fprintf (stderr, "For help on a particular function: %s <function> -h\n", argv[0]);
 return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int (*toolmain)(int, char **);
 char *tmp;
 int loop;
 tmp = strrchr(argv[0], '/');
 tmp = tmp? tmp + 1: argv[0];
 if ((toolmain = find_function (tmp)))
 {
  return toolmain (argc, argv);
 }
 if (argc > 1 && (toolmain = find_function (argv[1])))
 {
  return toolmain (argc - 1, argv + 1);
 }
 fprintf (stderr, "%s %s\n", "MFSTools", "snapshot050221");
 fprintf (stderr, "Usage: %s <function> <args> or <function> <args>\n", argv[0]);
 fprintf (stderr, "Available functions:\n");
 for (loop = 0; funcs[loop].name; loop++)
  fprintf (stderr, "  %-10s%s\n", funcs[loop].name, funcs[loop].desc);
 fprintf (stderr, "For help on a particular function: %s <function> -h\n", argv[0]);
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
toolmain
int (*)(int, char **)

variable_types:
tmp
char *


decompiled_code:
void __fastcall setup_syslog(int a1)
{
if ( !use_syslog )
openlog(0LL, 1, 8);
use_syslog = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( !use_syslog )
openlog(0LL, 1, 8);
use_syslog = a1;
}

original_code:
void setup_syslog (int level)
{
  if (!use_syslog)
    openlog(((void *)0), 0x01, (1<<3));
  use_syslog= level;
  return;
}

canonical_original_code:
void setup_syslog(int level)
{
  if (!use_syslog)
    openlog(((void *)0), 0x01, (1<<3));
  use_syslog= level;
  return;
}

variable_types: level int


decompiled_code:
__int64 __fastcall parse_object(unsigned int a1, __int64 a2, void (__fastcall *a3)(_QWORD, unsigned __int16 *, _QWORD, _QWORD))
{
unsigned int v4; // ebx
unsigned __int16 *v5; // rbp

byte_swap(a2, &unk_177);
if ( *(_DWORD *)(a2 + 4) > 8u )
{
v4 = 8;
do
{
v5 = (unsigned __int16 *)(a2 + v4);
byte_swap(v5, "s6 i1");
a3(a1, v5, 0LL, 0LL);
parse_subobj_isra_0((__int64)(v5 + 8), *v5 - 16, a1, (__int64)v5);
v4 += *v5;
byte_swap(v5, "s6 i1");
}
while ( *(_DWORD *)(a2 + 4) > v4 );
}
return byte_swap(a2, &unk_177);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, void (__fastcall *a3)(_QWORD, unsigned __int16 *, _QWORD, _QWORD))
{
unsigned int v4; // ebx
unsigned __int16 *v5; // rbp

byte_swap(a2, &unk_177);
if ( *(_DWORD *)(a2 + 4) > 8u )
{
v4 = 8;
do
{
v5 = (unsigned __int16 *)(a2 + v4);
byte_swap(v5, "s6 i1");
a3(a1, v5, 0LL, 0LL);
func2((__int64)(v5 + 8), *v5 - 16, a1, (__int64)v5);
v4 += *v5;
byte_swap(v5, "s6 i1");
}
while ( *(_DWORD *)(a2 + 4) > v4 );
}
return byte_swap(a2, &unk_177);
}

original_code:
void parse_object(int fsid, void *buf, object_fn fn)
{
 char *p;
 u32 ofs;
 struct mfs_obj_header *obj = buf;
 int i=0;
 byte_swap(obj, "i2");
 p = buf;
 ofs = sizeof(*obj);
 while (ofs < obj->size) {
  struct mfs_subobj_header *subobj = buf+ofs;
  byte_swap(subobj, "s6 i1");
  fn(fsid, subobj, ((void *)0), ((void *)0));
  parse_subobj(buf+ofs+sizeof(*subobj),
        subobj->obj_type,
        subobj->len-sizeof(*subobj), fsid, subobj, fn);
  ofs += subobj->len;
  i++;
  byte_swap(subobj, "s6 i1");
 }
 byte_swap(obj, "i2");
}

canonical_original_code:
void parse_object(int fsid, void *buf, void (*fn)(int fsid, struct mfs_subobj_header *obj, struct mfs_attr_header *attr, void *data))
{
 char *p;
 unsigned int ofs;
 struct mfs_obj_header *obj = buf;
 int i = 0;
 byte_swap(obj, "i2");
 p = buf;
 ofs = sizeof(*obj);
 while (ofs < obj->size) {
  struct mfs_subobj_header *subobj = buf+ofs;
  byte_swap(subobj, "s6 i1");
  fn(fsid, subobj, ((void *)0), ((void *)0));
  parse_subobj(buf+ofs+sizeof(*subobj),
        subobj->obj_type,
        subobj->len-sizeof(*subobj), fsid, subobj, fn);
  ofs += subobj->len;
  i++;
  byte_swap(subobj, "s6 i1");
 }
 byte_swap(obj, "i2");
}

variable_types: fsid int

variable_types:
buf
void *

variable_types: void (*)(int fsid, struct mfs_subobj_header { unsigned short len; unsigned short len1; unsigned short obj_type; unsigned short flags; unsigned short fill[2]; unsigned int id; } *obj, struct mfs_attr_header { unsigned char eltype; unsigned char attr; unsigned short len; } *attr, void *data)

variable_types:
p
char *

variable_types:
ofs
unsigned int

variable_types: struct mfs_obj_header { unsigned int fill1; unsigned int size; } *

variable_types: i int


decompiled_code:
const char *__fastcall object_typestr(unsigned int a1)
{
const char *result; // rax

result = "UNKNOWN";
if ( a1 <= 3 )
result = CSWTCH_5[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1)
{
const char *result; // rax

result = "UNKNOWN";
if ( a1 <= 3 )
result = CSWTCH_5[a1];
return result;
}

original_code:
char *object_typestr(int objtype)
{
 switch (objtype) {
 case 0: return "int";
 case 1: return "string";
 case 2: return "object";
 case 3: return "file";
 }
 return "UNKNOWN";
}

variable_types: objtype int

return_type: char *


decompiled_code:
__int64 __fastcall lock_byte(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-38h] BYREF
__int64 v4; // [rsp+8h] [rbp-30h]
__int64 v5; // [rsp+10h] [rbp-28h]
__pid_t v6; // [rsp+18h] [rbp-20h]

v3 = 1;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 7LL, &v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
{
LABEL_3:
fprintf(stderr, "ERROR: Failed to get lock at %d\n", a2);
goto LABEL_4;
}
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to get lock at %d\n", a2);
}
else
{
if ( fileno(stderr) != 1 )
goto LABEL_3;
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to get lock at %d\n", a2);
}
LABEL_4:
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-38h] BYREF
__int64 v4; // [rsp+8h] [rbp-30h]
__int64 v5; // [rsp+10h] [rbp-28h]
__pid_t v6; // [rsp+18h] [rbp-20h]

v3 = 1;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 7LL, &v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
{
LABEL_3:
fprintf(stderr, "ERROR: Failed to get lock at %d\n", a2);
goto LABEL_4;
}
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to get lock at %d\n", a2);
}
else
{
if ( fileno(stderr) != 1 )
goto LABEL_3;
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to get lock at %d\n", a2);
}
LABEL_4:
exit(0);
}
return result;
}

original_code:
static void lock_byte(int fd, int b)
{
 struct flock lock;
 lock.l_type = 1;
 lock.l_whence = 0;
 lock.l_start = b;
 lock.l_len = 1;
 lock.l_pid = getpid();
 if (fcntl(fd,7,&lock) != 0) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "ERROR: Failed to get lock at %d\n", b),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"ERROR: Failed to get lock at %d\n", b),1) : 1) : fprintf((stderr),"ERROR: Failed to get lock at %d\n", b)) : fprintf((stderr),"ERROR: Failed to get lock at %d\n", b));
  exit(0);
 }
}

variable_types: fd int

variable_types: b int

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
__int64 __fastcall unlock_byte(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-38h] BYREF
__int64 v4; // [rsp+8h] [rbp-30h]
__int64 v5; // [rsp+10h] [rbp-28h]
__pid_t v6; // [rsp+18h] [rbp-20h]

v3 = 1;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 2LL, &v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
{
LABEL_3:
fprintf(stderr, "ERROR: Failed to unlock at %d\n", a2);
goto LABEL_4;
}
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to unlock at %d\n", a2);
}
else
{
if ( fileno(stderr) != 1 )
goto LABEL_3;
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to unlock at %d\n", a2);
}
LABEL_4:
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-38h] BYREF
__int64 v4; // [rsp+8h] [rbp-30h]
__int64 v5; // [rsp+10h] [rbp-28h]
__pid_t v6; // [rsp+18h] [rbp-20h]

v3 = 1;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 2LL, &v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
{
LABEL_3:
fprintf(stderr, "ERROR: Failed to unlock at %d\n", a2);
goto LABEL_4;
}
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to unlock at %d\n", a2);
}
else
{
if ( fileno(stderr) != 1 )
goto LABEL_3;
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to unlock at %d\n", a2);
}
LABEL_4:
exit(0);
}
return result;
}

original_code:
static void unlock_byte(int fd, int b)
{
 struct flock lock;
 lock.l_type = 1;
 lock.l_whence = 0;
 lock.l_start = b;
 lock.l_len = 1;
 lock.l_pid = getpid();
 if (fcntl(fd,2,&lock) != 0) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "ERROR: Failed to unlock at %d\n", b),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"ERROR: Failed to unlock at %d\n", b),1) : 1) : fprintf((stderr),"ERROR: Failed to unlock at %d\n", b)) : fprintf((stderr),"ERROR: Failed to unlock at %d\n", b));
  exit(0);
 }
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


usage

decompiled_code:
void __noreturn usage()
{
puts("vserver_mfs [options]");
puts("Version: 1.3-20050428");
puts("options:");
puts(" -l Send messages to syslog");
puts(" -L Send all messages to syslog");
puts(" -i inetd mode. Use this in inetd.conf.");
puts(" -h help");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("vserver_mfs [options]");
puts("Version: 1.3-20050428");
puts("options:");
puts(" -l Send messages to syslog");
puts(" -L Send all messages to syslog");
puts(" -i inetd mode. Use this in inetd.conf.");
puts(" -h help");
credits();
exit(1);
}

original_code:
void usage(void)
{
 printf("vserver_mfs [options]\n");
 printf("Version: 1.3-20050428\n");
 printf("options:\n");
 printf("    -l  Send messages to syslog\n");
 printf("    -L  Send all messages to syslog\n");
 printf("    -i  inetd mode. Use this in inetd.conf.\n");
 printf("    -h  help\n");
 credits();
 exit(1);
}

canonical_original_code:
void usage()
{
 printf("vserver_mfs [options]\n");
 printf("Version: 1.3-20050428\n");
 printf("options:\n");
 printf("    -l  Send messages to syslog\n");
 printf("    -L  Send all messages to syslog\n");
 printf("    -i  inetd mode. Use this in inetd.conf.\n");
 printf("    -h  help\n");
 credits();
 exit(1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int v5; // er12
int v6; // eax
int v7; // ebp
int v8; // ebp
struct sockaddr *v9; // rsi
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
char v14; // [rsp+0h] [rbp-38h]
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "lLih?");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'i':
v3 = 1;
break;
case 'l':
setup_syslog(1LL);
break;
case 'L':
setup_syslog(2LL);
break;
default:
goto LABEL_6;
}
}
if ( optind != argc )
LABEL_6:
usage();
if ( v3 )
{
v6 = open64("/dev/null", 577, 420LL);
v7 = v6;
if ( v6 == -1 )
exit(2);
dup2(v6, 1);
close(v7);
dup2(1, 2);
v8 = dup(0);
close(0);
v9 = (struct sockaddr *)((char *)_bswap_32 + 1);
signal(17, (__sighandler_t)((char *)_bswap_32 + 1));
mfs_init();
if ( use_syslog )
{
v9 = (struct sockaddr *)"starting vserver\n";
syslog(6, "starting vserver\n");
}
else
{
puts("starting vserver");
}
}
else
{
v5 = open_socket_in_constprop_0();
if ( listen(v5, 5) == -1 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "listen failed\n");
goto LABEL_18;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "listen failed\n");
LABEL_18:
exit(1);
}
}
fwrite("listen failed\n", 1uLL, 0xEuLL, stderr);
goto LABEL_18;
}
signal(17, (__sighandler_t)((char *)_bswap_32 + 1));
mfs_init();
if ( use_syslog )
syslog(6, "waiting for connections on port %d\n", 8074LL);
else
printf("waiting for connections on port %d\n", 8074LL);
while ( 1 )
{
do
{
v9 = &addr;
addr_len = 16;
v8 = accept(v5, &addr, &addr_len);
}
while ( v8 == -1 );
if ( !fork() )
break;
close(v8);
}
close(v5);
}
vserver_isra_0(v8, (char)v9, v10, v11, v12, v13, v14);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int v5; // er12
int v6; // eax
int v7; // ebp
int v8; // ebp
struct sockaddr *v9; // rsi
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
char v14; // [rsp+0h] [rbp-38h]
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "lLih?");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'i':
v3 = 1;
break;
case 'l':
setup_syslog(1LL);
break;
case 'L':
setup_syslog(2LL);
break;
default:
goto LABEL_6;
}
}
if ( optind != argc )
LABEL_6:
func7();
if ( v3 )
{
v6 = open64("/dev/null", 577, 420LL);
v7 = v6;
if ( v6 == -1 )
exit(2);
dup2(v6, 1);
close(v7);
dup2(1, 2);
v8 = dup(0);
close(0);
v9 = (struct sockaddr *)((char *)_bswap_32 + 1);
signal(17, (__sighandler_t)((char *)_bswap_32 + 1));
mfs_init();
if ( use_syslog )
{
v9 = (struct sockaddr *)"starting vserver\n";
syslog(6, "starting vserver\n");
}
else
{
puts("starting vserver");
}
}
else
{
v5 = func6();
if ( listen(v5, 5) == -1 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "listen failed\n");
goto LABEL_18;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "listen failed\n");
LABEL_18:
exit(1);
}
}
fwrite("listen failed\n", 1uLL, 0xEuLL, stderr);
goto LABEL_18;
}
signal(17, (__sighandler_t)((char *)_bswap_32 + 1));
mfs_init();
if ( use_syslog )
syslog(6, "waiting for connections on port %d\n", 8074LL);
else
printf("waiting for connections on port %d\n", 8074LL);
while ( 1 )
{
do
{
v9 = &addr;
addr_len = 16;
v8 = accept(v5, &addr, &addr_len);
}
while ( v8 == -1 );
if ( !fork() )
break;
close(v8);
}
close(v5);
}
func5(v8, (char)v9, v10, v11, v12, v13, v14);
}

original_code:
int main(int argc, char *argv[])
{
 int sock;
 int c, inetd = 0;
 while ((c = getopt(argc, argv, "lLih?")) != -1)
 {
  switch (c)
  {
   case 'l': setup_syslog(1); break;
   case 'L': setup_syslog(2); break;
   case 'i': inetd=1; break;
   default: usage(); exit(1);
  }
 }
 argc -= optind; argv += optind;
 if (argc != 0)
 {
  usage();
 }
 if (inetd) {
  int logfd;
  logfd= open("/dev/null", 01|0100|01000, 0644);
  if (logfd==-1) exit(2);
  dup2(logfd,1);
  close(logfd);
  dup2(1,2);
  sock = dup(0);
  close(0);
  signal(17, ((__sighandler_t) 1));
  mfs_init();
  (use_syslog ? (syslog(6,"starting vserver\n"),1) : (use_syslog ? (use_syslog>=2 ? (syslog(6,"starting vserver\n"),1) : 1) : printf("starting vserver\n")));
  vserver(sock);
  return 0;
 }
 sock = open_socket_in(SOCK_STREAM, 8074, ((in_addr_t) 0x00000000));
 if (listen(sock, 5) == -1) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "listen failed\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"listen failed\n"),1) : 1) : fprintf((stderr),"listen failed\n")) : fprintf((stderr),"listen failed\n"));
  exit(1);
 }
 signal(17, ((__sighandler_t) 1));
 mfs_init();
 (use_syslog ? (syslog(6,"waiting for connections on port %d\n", 8074),1) : (use_syslog ? (use_syslog>=2 ? (syslog(6,"waiting for connections on port %d\n", 8074),1) : 1) : printf("waiting for connections on port %d\n", 8074)));
 while (1) {
  struct sockaddr addr;
  int in_addrlen = sizeof(addr);
  int fd;
  fd = accept(sock,&addr,&in_addrlen);
  if (fd != -1) {
   if (fork() == 0) {
    close(sock);
    vserver(fd);
   }
   close(fd);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int sock;
 int c; int inetd = 0;
 while ((c = getopt(argc, argv, "lLih?")) != -1)
 {
  switch (c)
  {
   case 'l': setup_syslog(1); break;
   case 'L': setup_syslog(2); break;
   case 'i': inetd=1; break;
   default: usage(); exit(1);
  }
 }
 argc -= optind; argv += optind;
 if (argc != 0)
 {
  usage();
 }
 if (inetd) {
  int logfd;
  logfd= open("/dev/null", 01|0100|01000, 0644);
  if (logfd==-1) exit(2);
  dup2(logfd,1);
  close(logfd);
  dup2(1,2);
  sock = dup(0);
  close(0);
  signal(17, ((void (*)(int)) 1));
  mfs_init();
  (use_syslog ? (syslog(6,"starting vserver\n"),1) : (use_syslog ? (use_syslog>=2 ? (syslog(6,"starting vserver\n"),1) : 1) : printf("starting vserver\n")));
  vserver(sock);
  return 0;
 }
 sock = open_socket_in(SOCK_STREAM, 8074, ((unsigned int) 0x00000000));
 if (listen(sock, 5) == -1) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "listen failed\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"listen failed\n"),1) : 1) : fprintf((stderr),"listen failed\n")) : fprintf((stderr),"listen failed\n"));
  exit(1);
 }
 signal(17, ((void (*)(int)) 1));
 mfs_init();
 (use_syslog ? (syslog(6,"waiting for connections on port %d\n", 8074),1) : (use_syslog ? (use_syslog>=2 ? (syslog(6,"waiting for connections on port %d\n", 8074),1) : 1) : printf("waiting for connections on port %d\n", 8074)));
 while (1) {
  struct sockaddr addr;
  int in_addrlen = sizeof(addr);
  int fd;
  fd = accept(sock,&addr,&in_addrlen);
  if (fd != -1) {
   if (fork() == 0) {
    close(sock);
    vserver(fd);
   }
   close(fd);
  }
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: sock int

variable_types: c int

variable_types: inetd int

variable_types: logfd int

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