main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
const char *v4; // r15
int v5; // eax
char *v6; // r15
size_t v7; // rax
void *v8; // rsp
__int64 v9; // rax
char *v10; // r13
size_t v11; // rax
void *v12; // rsp
int v13; // er14
int v14; // er12
char *v15; // rax
unsigned int v16; // eax
char *v17; // r15
char *v18; // r13
const char **v19; // r14
__int64 i; // rbx
char *v21; // r14
__int64 v22; // rbx
unsigned int v23; // er12
unsigned int v24; // er13
int v25; // er14
void *v26; // r14
int v27; // ebx
int result; // eax
__int64 v29; // [rsp+0h] [rbp-2C0h] BYREF
size_t v30; // [rsp+8h] [rbp-2B8h]
void *v31; // [rsp+10h] [rbp-2B0h]
int v32; // [rsp+1Ch] [rbp-2A4h]
int v33; // [rsp+20h] [rbp-2A0h]
int v34; // [rsp+24h] [rbp-29Ch]
unsigned int v35; // [rsp+28h] [rbp-298h]
unsigned int v36; // [rsp+2Ch] [rbp-294h]
char *nptr; // [rsp+30h] [rbp-290h]
__int128 v38; // [rsp+38h] [rbp-288h]
__int64 v39; // [rsp+48h] [rbp-278h]
char s[64]; // [rsp+50h] [rbp-270h] BYREF
char buf[560]; // [rsp+90h] [rbp-230h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
const char *v4; // r15
int v5; // eax
char *v6; // r15
size_t v7; // rax
void *v8; // rsp
__int64 v9; // rax
char *v10; // r13
size_t v11; // rax
void *v12; // rsp
int v13; // er14
int v14; // er12
char *v15; // rax
unsigned int v16; // eax
char *v17; // r15
char *v18; // r13
const char **v19; // r14
__int64 i; // rbx
char *v21; // r14
__int64 v22; // rbx
unsigned int v23; // er12
unsigned int v24; // er13
int v25; // er14
void *v26; // r14
int v27; // ebx
int result; // eax
__int64 v29; // [rsp+0h] [rbp-2C0h] BYREF
size_t v30; // [rsp+8h] [rbp-2B8h]
void *v31; // [rsp+10h] [rbp-2B0h]
int v32; // [rsp+1Ch] [rbp-2A4h]
int v33; // [rsp+20h] [rbp-2A0h]
int v34; // [rsp+24h] [rbp-29Ch]
unsigned int v35; // [rsp+28h] [rbp-298h]
unsigned int v36; // [rsp+2Ch] [rbp-294h]
char *nptr; // [rsp+30h] [rbp-290h]
__int128 v38; // [rsp+38h] [rbp-288h]
__int64 v39; // [rsp+48h] [rbp-278h]
char s[64]; // [rsp+50h] [rbp-270h] BYREF
char buf[560]; // [rsp+90h] [rbp-230h] BYREF

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

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

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]

return_type: int


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; // r14
unsigned int i; // er13
unsigned int *v7; // rbp
int v8; // er12
int v9; // eax
const char *v10; // rdx
int v11; // eax
const char *v12; // rdx
unsigned int *v13; // rbx
int v14; // ebp
int v15; // er12
const char *v16; // rbx
const char *v17; // r15
unsigned int v19; // [rsp+Ch] [rbp-203Ch] BYREF
int v20[1024]; // [rsp+10h] [rbp-2038h] BYREF
int v21[1038]; // [rsp+1010h] [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 )
{
v7 = v2;
v8 = query_int_list(*v2, "Part/File", v21, 1024LL);
mfs_dir_free(v7);
if ( v8 > 0 )
{
v9 = crypto_check((unsigned int)v21[v8 - 1]);
v10 = "enabled";
if ( !v9 )
v10 = "disabled";
fprintf(stdout, "TyStream encryption is currently %s.\n", v10);
}
}
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 )
{
v13 = (unsigned int *)(v5 + 16LL * i);
v14 = query_int_list(*v13, "Part/File", v21, 1024LL);
LODWORD(v4) = query_int_list(*v13, "Part/CommercialSkipOffset", v20, 1024LL);
v15 = v4;
if ( v14 > 0 )
{
v16 = (const char *)query_string(*v13, "Showing/Program/Title");
v17 = "No ";
if ( v15 && v20[v15 - 1] )
v17 = "Yes ";
v11 = crypto_check((unsigned int)v21[v14 - 1]);
v12 = "Yes ";
if ( !v11 )
v12 = "No ";
LODWORD(v4) = fprintf(stdout, "%s%s%s\n", v12, v17, v16);
}
}
}
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; // r14
unsigned int i; // er13
unsigned int *v7; // rbp
int v8; // er12
int v9; // eax
const char *v10; // rdx
int v11; // eax
const char *v12; // rdx
unsigned int *v13; // rbx
int v14; // ebp
int v15; // er12
const char *v16; // rbx
const char *v17; // r15
unsigned int v19; // [rsp+Ch] [rbp-203Ch] BYREF
int v20[1024]; // [rsp+10h] [rbp-2038h] BYREF
int v21[1038]; // [rsp+1010h] [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 )
{
v7 = v2;
v8 = query_int_list(*v2, "Part/File", v21, 1024LL);
mfs_dir_free(v7);
if ( v8 > 0 )
{
v9 = func1((unsigned int)v21[v8 - 1]);
v10 = "enabled";
if ( !v9 )
v10 = "disabled";
fprintf(stdout, "TyStream encryption is currently %s.\n", v10);
}
}
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 )
{
v13 = (unsigned int *)(v5 + 16LL * i);
v14 = query_int_list(*v13, "Part/File", v21, 1024LL);
LODWORD(v4) = query_int_list(*v13, "Part/CommercialSkipOffset", v20, 1024LL);
v15 = v4;
if ( v14 > 0 )
{
v16 = (const char *)query_string(*v13, "Showing/Program/Title");
v17 = "No ";
if ( v15 && v20[v15 - 1] )
v17 = "Yes ";
v11 = func1((unsigned int)v21[v14 - 1]);
v12 = "Yes ";
if ( !v11 )
v12 = "No ";
LODWORD(v4) = fprintf(stdout, "%s%s%s\n", v12, v17, v16);
}
}
}
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

return_type: void


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

canonical_name: main

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

if ( getopt(argc, (char *const *)argv, &shortopts) != -1 )
usage();
mfs_init();
if ( (unsigned int)mfs_resolve("/Recording/NowShowingByClassic") )
{
v3 = "/Recording/NowShowingByClassic";
}
else if ( (unsigned int)mfs_resolve("/Recording/NowShowing") )
{
v3 = "/Recording/NowShowing";
}
else
{
v3 = "/Recording/Complete";
if ( !(unsigned int)mfs_resolve("/Recording/Complete") )
v3 = 0LL;
}
ciphercheck((__int64)v3);
return 0;
}

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

if ( getopt(argc, (char *const *)argv, &shortopts) != -1 )
func0();
mfs_init();
if ( (unsigned int)mfs_resolve("/Recording/NowShowingByClassic") )
{
v3 = "/Recording/NowShowingByClassic";
}
else if ( (unsigned int)mfs_resolve("/Recording/NowShowing") )
{
v3 = "/Recording/NowShowing";
}
else
{
v3 = "/Recording/Complete";
if ( !(unsigned int)mfs_resolve("/Recording/Complete") )
v3 = 0LL;
}
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)
{
signed int v3; // eax
signed int v4; // esi
__int64 v5; // rcx
unsigned int v6; // er12
void *v7; // rax
__int64 v8; // rax
unsigned int *v9; // rdx
int v10; // edx
signed int v11; // edx

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, unsigned int a2)
{
signed int v3; // eax
signed int v4; // esi
__int64 v5; // rcx
unsigned int v6; // er12
void *v7; // rax
__int64 v8; // rax
unsigned int *v9; // rdx
int v10; // edx
signed int v11; // edx

if ( !*a1 )
{
v6 = inode_count();
*((_DWORD *)a1 + 2) = v6;
v7 = malloc(4LL * v6);
*a1 = (__int64)v7;
if ( !v7 )
_assert_fail("h->hash_table", "mfs_info.c", 0x55u, "hash_table_search");
v8 = 0LL;
if ( v6 )
{
do
*(_DWORD *)(*a1 + 4 * v8++) = -1;
while ( *((_DWORD *)a1 + 2) > (unsigned int)v8 );
}
}
v3 = fsid_hash(a2, *((unsigned int *)a1 + 2));
v4 = v3;
v5 = *a1;
while ( 1 )
{
v10 = *(_DWORD *)(v5 + 4LL * v3);
if ( v10 == a2 )
return 1LL;
if ( v10 == -1 )
break;
v11 = (unsigned int)(v3 + 1) % *((_DWORD *)a1 + 2);
v3 = v11;
if ( v4 == v11 )
goto LABEL_17;
v9 = (unsigned int *)(v5 + 4LL * v11);
if ( *v9 == -1 )
goto LABEL_15;
}
if ( v3 != v4 )
{
v9 = (unsigned int *)(v5 + 4LL * v3);
LABEL_15:
*v9 = a2;
return 0LL;
}
LABEL_17:
v9 = (unsigned int *)(v5 + 4LL * v4);
if ( *v9 == -1 )
goto LABEL_15;
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; // rbp

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

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

v1 = *(unsigned int *)a1;
v2 = malloc(4LL * (int)v1);
memcpy(v2, a1[1], 4LL * (int)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; }


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; // rdx
unsigned int v9; // eax
__int64 v10; // r8
__int64 v11; // r9
unsigned __int64 v13; // [rsp+0h] [rbp-68h] BYREF
unsigned int v14; // [rsp+10h] [rbp-58h]
__int16 v15; // [rsp+14h] [rbp-54h] BYREF
int v16; // [rsp+16h] [rbp-52h]
__int16 v17; // [rsp+1Ah] [rbp-4Eh]
unsigned __int64 *v18; // [rsp+1Ch] [rbp-4Ch]
int v19; // [rsp+24h] [rbp-44h]
char *v20; // [rsp+30h] [rbp-38h]
__int64 v21[2]; // [rsp+40h] [rbp-28h] BYREF
const void *v22[3]; // [rsp+50h] [rbp-18h] BYREF

v20 = &a7;
v15 = -17599;
v16 = (int)sfn_0;
v17 = -17847;
v18 = &v13;
v19 = -1864106167;
v14 = 0;
v13 = 0LL;
fprintf(stderr, "traversing %s... ", "/Resource");
v22[0] = (const void *)queue_new();
v22[1] = v7;
v21[0] = hash_table_new();
v21[1] = v8;
v9 = mfs_resolve("/Resource");
traverse(v22, v21, v9, (void (__fastcall *)(_QWORD))&v15, v10, v11, v13);
queue_free((__int64)v22);
hash_table_free((__int64)v21);
fputc(10, stderr);
fprintf(stderr, "max stream fsid under /Resource: %d\n", v14);
return fprintf(stderr, "max stream size under /Resource: %uMB\n", v13 >> 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; // rdx
unsigned int v9; // eax
__int64 v10; // r8
__int64 v11; // r9
unsigned __int64 v13; // [rsp+0h] [rbp-68h] BYREF
unsigned int v14; // [rsp+10h] [rbp-58h]
__int16 v15; // [rsp+14h] [rbp-54h] BYREF
int v16; // [rsp+16h] [rbp-52h]
__int16 v17; // [rsp+1Ah] [rbp-4Eh]
unsigned __int64 *v18; // [rsp+1Ch] [rbp-4Ch]
int v19; // [rsp+24h] [rbp-44h]
char *v20; // [rsp+30h] [rbp-38h]
__int64 v21[2]; // [rsp+40h] [rbp-28h] BYREF
const void *v22[3]; // [rsp+50h] [rbp-18h] BYREF

v20 = &a7;
v15 = -17599;
v16 = (int)sfn_0;
v17 = -17847;
v18 = &v13;
v19 = -1864106167;
v14 = 0;
v13 = 0LL;
fprintf(stderr, "traversing %s... ", "/Resource");
v22[0] = (const void *)func0();
v22[1] = v7;
v21[0] = func1();
v21[1] = v8;
v9 = mfs_resolve("/Resource");
func11(v22, v21, v9, (void (__fastcall *)(_QWORD))&v15, v10, v11, v13);
func10((__int64)v22);
func12((__int64)v21);
fputc(10, stderr);
fprintf(stderr, "max stream fsid under /Resource: %d\n", v14);
return fprintf(stderr, "max stream size under /Resource: %uMB\n", v13 >> 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; // rdx
unsigned int v9; // eax
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // rdx
__int64 v13; // rdx
__int64 v14; // rdx
unsigned int v15; // eax
__int64 v16; // r8
__int64 v17; // r9
__int64 v18; // rbx
unsigned __int64 v19; // r12
unsigned int v20; // er13
unsigned int v21; // ebp
unsigned __int64 v22; // rax
__int64 v24; // [rsp+0h] [rbp-288h] BYREF
__int64 v25; // [rsp+8h] [rbp-280h]
__int64 v26; // [rsp+10h] [rbp-278h] BYREF
__int64 v27; // [rsp+18h] [rbp-270h]
__int16 v28; // [rsp+20h] [rbp-268h] BYREF
int v29; // [rsp+22h] [rbp-266h]
__int16 v30; // [rsp+26h] [rbp-262h]
__int64 *v31; // [rsp+28h] [rbp-260h]
int v32; // [rsp+30h] [rbp-258h]
char *v33; // [rsp+40h] [rbp-248h]
char v34[20]; // [rsp+50h] [rbp-238h] BYREF
int v35; // [rsp+64h] [rbp-224h]
unsigned int v36; // [rsp+68h] [rbp-220h]
__int64 v37; // [rsp+250h] [rbp-38h] BYREF
__int64 v38; // [rsp+258h] [rbp-30h]

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

v3 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)a1 == v3 )
{
v6 = 2 * v3;
if ( v3 <= 0 )
v6 = 102400;
*(_DWORD *)(a1 + 4) = v6;
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), 4LL * v6);
}
v4 = *(_QWORD *)(a1 + 8);
LODWORD(result) = (*(_DWORD *)a1)++;
result = (int)result;
*(_DWORD *)(v4 + 4LL * (int)result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v3; // eax
__int64 v4; // rdx
__int64 result; // rax
int v6; // esi

v3 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)a1 == v3 )
{
v6 = 2 * v3;
if ( v3 <= 0 )
v6 = 102400;
*(_DWORD *)(a1 + 4) = v6;
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), 4LL * v6);
}
v4 = *(_QWORD *)(a1 + 8);
LODWORD(result) = (*(_DWORD *)a1)++;
result = (int)result;
*(_DWORD *)(v4 + 4LL * (int)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; // r14
unsigned int v4; // ebx
int v5; // eax
int v6; // er12
int v7; // ebp
unsigned int v9; // 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);
v9 = mfs_resolve(argv[v6]);
mfs_fsid_info(v9);
}
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; // r14
unsigned int v4; // ebx
int v5; // eax
int v6; // er12
int v7; // ebp
unsigned int v9; // 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);
v9 = mfs_resolve(argv[v6]);
mfs_fsid_info(v9);
}
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

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(const char *a1)
{
const char *v2; // rdi
bool v3; // cf
bool v4; // zf
__int64 v5; // rbx
int v6; // ebp
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char *result; // rax

v2 = funcs;
v3 = 0;
v4 = funcs == 0LL;
if ( funcs )
{
v5 = (unsigned int)((_DWORD)&funcs + 24);
v6 = 0;
while ( strcasecmp(v2, a1) )
{
++v6;
v5 += 24LL;
v2 = *(const char **)(v5 - 24);
v3 = 0;
v4 = v2 == 0LL;
if ( !v2 )
goto LABEL_5;
}
result = (&funcs)[3 * v6 + 1];
}
else
{
LABEL_5:
v7 = (const char *)&unk_261;
v8 = 3LL;
v9 = a1;
do
{
if ( !v8 )
break;
v3 = *v9 < (unsigned int)*v7;
v4 = *v9++ == *v7++;
--v8;
}
while ( v4 );
result = 0LL;
if ( (!v3 && !v4) == v3 )
result = (char *)find_function(a1 + 3, v9);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
const char *v2; // rdi
bool v3; // cf
bool v4; // zf
__int64 v5; // rbx
int v6; // ebp
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi
char *result; // rax

v2 = funcs;
v3 = 0;
v4 = funcs == 0LL;
if ( funcs )
{
v5 = (unsigned int)((_DWORD)&funcs + 24);
v6 = 0;
while ( strcasecmp(v2, a1) )
{
++v6;
v5 += 24LL;
v2 = *(const char **)(v5 - 24);
v3 = 0;
v4 = v2 == 0LL;
if ( !v2 )
goto LABEL_5;
}
result = (&funcs)[3 * v6 + 1];
}
else
{
LABEL_5:
v7 = (const char *)&unk_261;
v8 = 3LL;
v9 = a1;
do
{
if ( !v8 )
break;
v3 = *v9 < (unsigned int)*v7;
v4 = *v9++ == *v7++;
--v8;
}
while ( v4 );
result = 0LL;
if ( (!v3 && !v4) == v3 )
result = (char *)func0(a1 + 3, v9);
}
return result;
}

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)
{
const char *v3; // rbx
char *v4; // rax
char *v5; // rax
char *v7; // rax
const char *v8; // rdx
const char **v9; // rbx

v3 = *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(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
{
fprintf(stderr, " %-10s%s\n", v8, *v9);
v9 += 3;
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)
{
const char *v3; // rbx
char *v4; // rax
char *v5; // rax
char *v7; // rax
const char *v8; // rdx
const char **v9; // rbx

v3 = *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(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
{
fprintf(stderr, " %-10s%s\n", v8, *v9);
v9 += 3;
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, __int64, __int64, __int64))
{
unsigned int v4; // ebp
unsigned __int16 *v5; // rbx

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

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(int a1)
{
const char *result; // rax

if ( a1 == 2 )
return "object";
if ( a1 > 2 )
{
result = "UNKNOWN";
if ( a1 == 3 )
result = "file";
}
else
{
result = "int";
if ( a1 )
{
result = "UNKNOWN";
if ( a1 == 1 )
result = "string";
}
}
return result;
}

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

if ( a1 == 2 )
return "object";
if ( a1 > 2 )
{
result = "UNKNOWN";
if ( a1 == 3 )
result = "file";
}
else
{
result = "int";
if ( a1 )
{
result = "UNKNOWN";
if ( a1 == 1 )
result = "string";
}
}
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
__int16 v3[4]; // [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[0] = 1;
v3[1] = 0;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 7LL, v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to get lock at %d\n", a2);
goto LABEL_9;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to get lock at %d\n", a2);
}
else
{
LABEL_8:
fprintf(stderr, "ERROR: Failed to get lock at %d\n", a2);
}
LABEL_9:
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int16 v3[4]; // [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[0] = 1;
v3[1] = 0;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 7LL, v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to get lock at %d\n", a2);
goto LABEL_9;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to get lock at %d\n", a2);
}
else
{
LABEL_8:
fprintf(stderr, "ERROR: Failed to get lock at %d\n", a2);
}
LABEL_9:
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
__int16 v3[4]; // [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[0] = 1;
v3[1] = 0;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 2LL, v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to unlock at %d\n", a2);
goto LABEL_9;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to unlock at %d\n", a2);
}
else
{
LABEL_8:
fprintf(stderr, "ERROR: Failed to unlock at %d\n", a2);
}
LABEL_9:
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int16 v3[4]; // [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[0] = 1;
v3[1] = 0;
v4 = (int)a2;
v5 = 1LL;
v6 = getpid();
result = fcntl64(a1, 2LL, v3);
if ( (_DWORD)result )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "ERROR: Failed to unlock at %d\n", a2);
goto LABEL_9;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "ERROR: Failed to unlock at %d\n", a2);
}
else
{
LABEL_8:
fprintf(stderr, "ERROR: Failed to unlock at %d\n", a2);
}
LABEL_9:
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; // er13
int v4; // eax
int v5; // eax
int v6; // ebx
int v7; // ebx
const char *v8; // rsi
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
int v13; // ebp
int v14; // ebx
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
char v19; // [rsp+0h] [rbp-48h]
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "lLih?");
if ( v4 == -1 )
break;
if ( v4 == 105 )
{
v3 = 1;
}
else if ( v4 == 108 )
{
setup_syslog(1LL);
}
else
{
if ( v4 != 76 )
usage();
setup_syslog(2LL);
}
}
if ( optind != argc )
usage();
if ( v3 )
{
v5 = open64("/dev/null", 577, 420LL);
v6 = v5;
if ( v5 != -1 )
{
dup2(v5, 1);
close(v6);
dup2(1, 2);
v7 = dup(0);
close(0);
v8 = (char *)_bswap_16 + 1;
signal(17, (__sighandler_t)((char *)_bswap_16 + 1));
mfs_init();
if ( use_syslog )
{
v8 = "starting vserver\n";
syslog(6, "starting vserver\n");
}
else
{
puts("starting vserver");
}
vserver(v7, (char)v8, v9, v10, v11, v12, v19);
}
exit(2);
}
v13 = open_socket_in(1, 8074, 0);
if ( listen(v13, 5) != -1 )
{
signal(17, (__sighandler_t)((char *)_bswap_16 + 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
{
addr_len = 16;
v14 = accept(v13, &addr, &addr_len);
}
while ( v14 == -1 );
if ( !fork() )
break;
close(v14);
}
close(v13);
vserver(v14, (char)&addr, v15, v16, v17, v18, v19);
}
if ( !use_syslog )
goto LABEL_26;
if ( fileno(stderr) == 2 )
{
syslog(3, "listen failed\n");
goto LABEL_27;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "listen failed\n");
}
else
{
LABEL_26:
fwrite("listen failed\n", 1uLL, 0xEuLL, stderr);
}
LABEL_27:
exit(1);
}

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

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "lLih?");
if ( v4 == -1 )
break;
if ( v4 == 105 )
{
v3 = 1;
}
else if ( v4 == 108 )
{
setup_syslog(1LL);
}
else
{
if ( v4 != 76 )
func7();
setup_syslog(2LL);
}
}
if ( optind != argc )
func7();
if ( v3 )
{
v5 = open64("/dev/null", 577, 420LL);
v6 = v5;
if ( v5 != -1 )
{
dup2(v5, 1);
close(v6);
dup2(1, 2);
v7 = dup(0);
close(0);
v8 = (char *)_bswap_16 + 1;
signal(17, (__sighandler_t)((char *)_bswap_16 + 1));
mfs_init();
if ( use_syslog )
{
v8 = "starting vserver\n";
syslog(6, "starting vserver\n");
}
else
{
puts("starting vserver");
}
func6(v7, (char)v8, v9, v10, v11, v12, v19);
}
exit(2);
}
v13 = func1(1, 8074, 0);
if ( listen(v13, 5) != -1 )
{
signal(17, (__sighandler_t)((char *)_bswap_16 + 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
{
addr_len = 16;
v14 = accept(v13, &addr, &addr_len);
}
while ( v14 == -1 );
if ( !fork() )
break;
close(v14);
}
close(v13);
func6(v14, (char)&addr, v15, v16, v17, v18, v19);
}
if ( !use_syslog )
goto LABEL_26;
if ( fileno(stderr) == 2 )
{
syslog(3, "listen failed\n");
goto LABEL_27;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "listen failed\n");
}
else
{
LABEL_26:
fwrite("listen failed\n", 1uLL, 0xEuLL, stderr);
}
LABEL_27:
exit(1);
}

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


decompiled_code:
ssize_t __fastcall dump_raw(unsigned int a1, unsigned int a2)
{
unsigned int v3; // ebp
ssize_t result; // rax
const void *v5; // r13
unsigned int v6; // ebx

v3 = a2;
result = (ssize_t)malloc(0x20000uLL);
if ( a2 )
{
v5 = (const void *)result;
do
{
v6 = 256;
if ( v3 <= 0x100 )
v6 = v3;
mfs_read_sectors(v5, a1, v6);
result = write(1, v5, (int)(v6 << 9));
a1 += v6;
v3 -= v6;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(unsigned int a1, unsigned int a2)
{
unsigned int v3; // ebp
ssize_t result; // rax
const void *v5; // r13
unsigned int v6; // ebx

v3 = a2;
result = (ssize_t)malloc(0x20000uLL);
if ( a2 )
{
v5 = (const void *)result;
do
{
v6 = 256;
if ( v3 <= 0x100 )
v6 = v3;
mfs_read_sectors(v5, a1, v6);
result = write(1, v5, (int)(v6 << 9));
a1 += v6;
v3 -= v6;
}
while ( v3 );
}
return result;
}

original_code:
static void dump_raw(u32 start, u32 count)
{
 int chunk = 256;
 void *buf = malloc(chunk*512);
 while (count) {
  int n = ((count)<(chunk)?(count):(chunk));
  mfs_read_sectors(buf, start, n);
  write(1, buf, n*512);
  start += n;
  count -= n;
 }
}

canonical_original_code:
static void dump_raw(unsigned int start, unsigned int count)
{
 int chunk = 256;
 void *buf = malloc(chunk*512);
 while (count) {
  int n = ((count)<(chunk)?(count):(chunk));
  mfs_read_sectors(buf, start, n);
  write(1, buf, n*512);
  start += n;
  count -= n;
 }
}

variable_types:
start
unsigned int

variable_types:
count
unsigned int

variable_types: chunk int

variable_types: n int


usage

decompiled_code:
void __noreturn usage()
{
puts("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n -R raw data");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n -R raw data");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n        -R            raw data\n");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n        -R            raw data\n");
 credits();
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // er12
int v4; // eax
const char **v5; // rbp
unsigned int v6; // er13
unsigned int v7; // ebx
void *v9; // rbp

for ( i = 0; ; i = 1 )
{
v4 = getopt(argc, (char *const *)argv, "R");
if ( v4 == -1 )
break;
if ( v4 != 82 )
usage();
}
v5 = &argv[optind];
if ( argc - optind <= 1 )
usage();
v6 = strtol(*v5, 0LL, 0);
v7 = strtol(v5[1], 0LL, 0);
mfs_init();
if ( i )
{
dump_raw(v6, v7);
}
else
{
v9 = malloc(v7 << 9);
mfs_read_sectors(v9, v6, v7);
dump_sectors(v9, v7);
free(v9);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // er12
int v4; // eax
const char **v5; // rbp
unsigned int v6; // er13
unsigned int v7; // ebx
void *v9; // rbp

for ( i = 0; ; i = 1 )
{
v4 = getopt(argc, (char *const *)argv, "R");
if ( v4 == -1 )
break;
if ( v4 != 82 )
func0();
}
v5 = &argv[optind];
if ( argc - optind <= 1 )
func0();
v6 = strtol(*v5, 0LL, 0);
v7 = strtol(v5[1], 0LL, 0);
mfs_init();
if ( i )
{
func1(v6, v7);
}
else
{
v9 = malloc(v7 << 9);
mfs_read_sectors(v9, v6, v7);
dump_sectors(v9, v7);
free(v9);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 u32 start;
 u32 count;
 int c;
 int raw=0;
 while ((c = getopt(argc, argv, "R")) != -1 ){
  switch (c) {
  case 'R':
   raw=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 2) {
  usage();
 }
 start = strtol(argv[0], ((void *)0), 0);
 count = strtol(argv[1], ((void *)0), 0);
 mfs_init();
 if (raw) {
  dump_raw(start, count);
 } else {
  void *buf = malloc(count*512);
  mfs_read_sectors(buf, start, count);
  dump_sectors(buf, count);
  free(buf);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned int start;
 unsigned int count;
 int c;
 int raw = 0;
 while ((c = getopt(argc, argv, "R")) != -1 ){
  switch (c) {
  case 'R':
   raw=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 2) {
  usage();
 }
 start = strtol(argv[0], ((void *)0), 0);
 count = strtol(argv[1], ((void *)0), 0);
 mfs_init();
 if (raw) {
  dump_raw(start, count);
 } else {
  void *buf = malloc(count*512);
  mfs_read_sectors(buf, start, count);
  dump_sectors(buf, count);
  free(buf);
 }
 return 0;
}

variable_types: argc int

variable_types: raw int

variable_types:
buf
void *


credits

decompiled_code:
size_t credits()
{
return fwrite(
"\n"
"Released under the Gnu GPL v2\n"
"Original mfs_* package by tridge at samba.org, January 2001\n"
"Modifications by:\n"
"\tadh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n"
"\tDaniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n"
" and possibly others...\n"
"\n"
"\tA support thread is in the forums at dealdatabase.com\n",
1uLL,
0x13CuLL,
stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"\n"
"Released under the Gnu GPL v2\n"
"Original mfs_* package by tridge at samba.org, January 2001\n"
"Modifications by:\n"
"\tadh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n"
"\tDaniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n"
" and possibly others...\n"
"\n"
"\tA support thread is in the forums at dealdatabase.com\n",
1uLL,
0x13CuLL,
stderr);
}

original_code:
void credits(void)
{
 fprintf(stderr, "\nReleased under the Gnu GPL v2\nOriginal mfs_* package by tridge at samba.org, January 2001\nModifications by:\n	adh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n	Daniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n        and possibly others...\n\n	A support thread is in the forums at dealdatabase.com\n");
}

canonical_original_code:
void credits()
{
 fprintf(stderr, "\nReleased under the Gnu GPL v2\nOriginal mfs_* package by tridge at samba.org, January 2001\nModifications by:\n	adh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n	Daniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n        and possibly others...\n\n	A support thread is in the forums at dealdatabase.com\n");
}


decompiled_code:
int __fastcall dir_list(__int64 a1, int a2)
{
__int64 v2; // r12
int result; // eax
unsigned int v4; // ebp
const char *v5; // r14
const char *v6; // rax
unsigned int *v7; // rbx
const char *v8; // r15
__int64 v9; // r14
const char *v10; // rax
unsigned int v11; // ebp
const char **v12; // rbx
unsigned int v13[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = mfs_dir(a1, v13);
printf("dir: fsid=%d count=%d\n", (unsigned int)a1, v13[0]);
if ( long_list )
result = puts(" fsid type size name\n -----------------------------------");
else
result = puts(" fsid type name\n -----------------------------------");
v4 = 0;
if ( v13[0] )
{
do
{
v7 = (unsigned int *)(v2 + 16LL * v4);
if ( long_list )
{
v8 = (const char *)*((_QWORD *)v7 + 1);
v9 = mfs_fsid_size(*v7);
v10 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %10lld %s\n", *v7, v10, v9, v8);
}
else
{
v5 = (const char *)*((_QWORD *)v7 + 1);
v6 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %s\n", *v7, v6, v5);
}
++v4;
result = v13[0];
}
while ( v13[0] > v4 );
if ( a2 && v13[0] )
{
v11 = 0;
do
{
v12 = (const char **)(v2 + 16LL * v11);
if ( *((_BYTE *)v12 + 4) == 4 )
{
printf("\n%s[%d]:\n", v12[1], *(unsigned int *)v12);
result = dir_list(*(unsigned int *)v12, 1LL);
}
++v11;
}
while ( v13[0] > v11 );
}
}
if ( v2 )
result = mfs_dir_free(v2);
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // r12
int result; // eax
unsigned int v4; // ebp
const char *v5; // r14
const char *v6; // rax
unsigned int *v7; // rbx
const char *v8; // r15
__int64 v9; // r14
const char *v10; // rax
unsigned int v11; // ebp
const char **v12; // rbx
unsigned int v13[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = mfs_dir(a1, v13);
printf("dir: fsid=%d count=%d\n", (unsigned int)a1, v13[0]);
if ( long_list )
result = puts(" fsid type size name\n -----------------------------------");
else
result = puts(" fsid type name\n -----------------------------------");
v4 = 0;
if ( v13[0] )
{
do
{
v7 = (unsigned int *)(v2 + 16LL * v4);
if ( long_list )
{
v8 = (const char *)*((_QWORD *)v7 + 1);
v9 = mfs_fsid_size(*v7);
v10 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %10lld %s\n", *v7, v10, v9, v8);
}
else
{
v5 = (const char *)*((_QWORD *)v7 + 1);
v6 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %s\n", *v7, v6, v5);
}
++v4;
result = v13[0];
}
while ( v13[0] > v4 );
if ( a2 && v13[0] )
{
v11 = 0;
do
{
v12 = (const char **)(v2 + 16LL * v11);
if ( *((_BYTE *)v12 + 4) == 4 )
{
printf("\n%s[%d]:\n", v12[1], *(unsigned int *)v12);
result = func1(*(unsigned int *)v12, 1LL);
}
++v11;
}
while ( v13[0] > v11 );
}
}
if ( v2 )
result = mfs_dir_free(v2);
return result;
}

original_code:
static void dir_list(int fsid, int recurse)
{
 struct mfs_dirent *dir;
 u32 count, i;
 dir = mfs_dir(fsid, &count);
 printf("dir: fsid=%d count=%d\n", fsid, count);
 if (long_list) {
  printf("      fsid   type           size     name\n      -----------------------------------\n");
 } else {
  printf("      fsid   type     name\n      -----------------------------------\n");
 }
 for (i=0;i<count;i++) {
  if (long_list) {
   printf("   %7d   %-8s %10lld     %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          mfs_fsid_size(dir[i].fsid),
          dir[i].name);
  } else {
   printf("   %7d   %-8s %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          dir[i].name);
  }
 }
 if (recurse) {
  for (i=0;i<count;i++) {
   if (dir[i].type == 4) {
    printf("\n%s[%d]:\n",
           dir[i].name, dir[i].fsid);
    dir_list(dir[i].fsid, 1);
   }
  }
 }
 if (dir) mfs_dir_free(dir);
}

canonical_original_code:
static void dir_list(int fsid, int recurse)
{
 struct mfs_dirent *dir;
 unsigned int count; unsigned int i;
 dir = mfs_dir(fsid, &count);
 printf("dir: fsid=%d count=%d\n", fsid, count);
 if (long_list) {
  printf("      fsid   type           size     name\n      -----------------------------------\n");
 } else {
  printf("      fsid   type     name\n      -----------------------------------\n");
 }
 for (i=0;i<count;i++) {
  if (long_list) {
   printf("   %7d   %-8s %10lld     %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          mfs_fsid_size(dir[i].fsid),
          dir[i].name);
  } else {
   printf("   %7d   %-8s %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          dir[i].name);
  }
 }
 if (recurse) {
  for (i=0;i<count;i++) {
   if (dir[i].type == 4) {
    printf("\n%s[%d]:\n",
           dir[i].name, dir[i].fsid);
    dir_list(dir[i].fsid, 1);
   }
  }
 }
 if (dir) mfs_dir_free(dir);
}

variable_types: fsid int

variable_types: recurse int

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

variable_types:
i
unsigned int


usage

decompiled_code:
void __noreturn usage()
{
puts(
"\n"
"usage: mfs_ls [options] <path|fsid>\n"
"\n"
" -R recurse\n"
" -l long list (with size)");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts(
"\n"
"usage: mfs_ls [options] <path|fsid>\n"
"\n"
" -R recurse\n"
" -l long list (with size)");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\nusage: mfs_ls [options] <path|fsid>\n\n      -R                             recurse\n      -l                             long list (with size)\n");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\nusage: mfs_ls [options] <path|fsid>\n\n      -R                             recurse\n      -l                             long list (with size)\n");
 credits();
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // rbp
unsigned int v6; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "Rl");
if ( v4 == -1 )
break;
if ( v4 == 82 )
{
v3 = 1;
}
else
{
if ( v4 != 108 )
usage();
long_list = 1;
}
}
v5 = &argv[optind];
if ( argc - optind <= 0 )
usage();
mfs_init();
v6 = mfs_resolve(*v5);
dir_list(v6, v3);
return 0;
}

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

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "Rl");
if ( v4 == -1 )
break;
if ( v4 == 82 )
{
v3 = 1;
}
else
{
if ( v4 != 108 )
func0();
long_list = 1;
}
}
v5 = &argv[optind];
if ( argc - optind <= 0 )
func0();
mfs_init();
v6 = mfs_resolve(*v5);
func1(v6, v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 int recurse=0;
 while ((c = getopt(argc, argv, "Rl")) != -1 ){
  switch (c) {
  case 'R':
   recurse=1;
   break;
  case 'l':
   long_list=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 mfs_init();
 fsid = mfs_resolve(argv[0]);
 dir_list(fsid, recurse);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 int recurse = 0;
 while ((c = getopt(argc, argv, "Rl")) != -1 ){
  switch (c) {
  case 'R':
   recurse=1;
   break;
  case 'l':
   long_list=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 mfs_init();
 fsid = mfs_resolve(argv[0]);
 dir_list(fsid, recurse);
 return 0;
}

variable_types:
argv
char *[]