decompiled_code:
void *__fastcall process_queue(int a1, unsigned int a2)
{
int v2; // er14
size_t v3; // rdx
void *v4; // rsp
void *result; // rax
_DWORD *v6; // rbx
_DWORD v7[3]; // [rsp-Eh] [rbp-28h] BYREF

if ( a1 )
{
v2 = nq;
v3 = 4LL * nq;
v4 = alloca(v3 + 8);
result = memcpy(v7, fsid_queue, v3);
nq = 0;
if ( v2 > 0 )
{
v6 = v7;
do
result = (void *)dumpobj((unsigned int)*v6++, a2, 1LL, &unk_AB7A);
while ( v6 != &v7[v2] );
}
}
else
{
nq = 0;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(int a1, unsigned int a2)
{
int v2; // er14
size_t v3; // rdx
void *v4; // rsp
void *result; // rax
_DWORD *v6; // rbx
_DWORD v7[3]; // [rsp-Eh] [rbp-28h] BYREF

if ( a1 )
{
v2 = nq;
v3 = 4LL * nq;
v4 = alloca(v3 + 8);
result = memcpy(v7, fsid_queue, v3);
nq = 0;
if ( v2 > 0 )
{
v6 = v7;
do
result = (void *)func7((unsigned int)*v6++, a2, 1LL, &unk_AB7A);
while ( v6 != &v7[v2] );
}
}
else
{
nq = 0;
}
return result;
}

original_code:
static void process_queue(int recurse, int fileobj)
{
 if (recurse) {
  int i;
  int n = nq;
  int *q = __builtin_alloca (n*sizeof(int));
  ((void) sizeof ((q) ? 1 : 0), __extension__ ({ if (q) ; else __assert_fail ("q", "mfs_dumpobj.c", 38, __extension__ __PRETTY_FUNCTION__); }));
  memcpy( q, fsid_queue, n*sizeof(int) );
  nq = 0;
  for(i=0; i<n; i++)
   dumpobj( q[i], fileobj, 1, "" );
 } else
  nq = 0;
}

variable_types: recurse int

variable_types: fileobj int

variable_types: n int

variable_types:
q
int *


dumpobj

decompiled_code:
unsigned int __fastcall dumpobj(unsigned int a1, unsigned int a2, int a3, const char *a4)
{
unsigned int result; // eax
unsigned int v7; // er14
unsigned int i; // ebx
unsigned int v9; // er15
size_t v10; // r13
const char **v11; // r14
void *v12; // rsp
int v13; // eax
int v14; // ecx
__int64 v15; // rdx
char *v16; // rax
char *v17; // rdx
__int64 v18; // rcx
void *v19; // rsp
_BYTE v20[15]; // [rsp-Eh] [rbp-20060h] BYREF
char v21[8]; // [rsp+20002h] [rbp-50h] BYREF
__int64 v22; // [rsp+2000Ah] [rbp-48h]
unsigned int v23[13]; // [rsp+2001Eh] [rbp-34h] BYREF

result = seen_before(a1);
if ( !result )
{
if ( (unsigned int)mfs_valid_fsid(a1) )
{
result = mfs_fsid_type(a1);
if ( result == 4 )
{
if ( a3 )
{
v22 = mfs_dir(a1, v23);
if ( v23[0] )
{
v9 = 0;
do
{
v10 = strlen(a4);
v11 = (const char **)(v22 + 16LL * v9);
v12 = alloca(16 * ((v10 + strlen(v11[1]) + 25) / 0x10));
strcpy(v21, a4);
strcat(v21, v11[1]);
v13 = strlen(v21);
v14 = v13;
if ( v13 > 0 )
{
v15 = v13;
v16 = &v21[v13 - 1];
v17 = &v21[v15 - 2 - (unsigned int)(v14 - 1)];
do
{
if ( *v16 != 32 )
break;
*v16-- = 0;
}
while ( v16 != v17 );
}
*(_WORD *)&v21[strlen(v21)] = 47;
dumpobj(*(unsigned int *)v11, a2, 1LL, v21);
++v9;
}
while ( v23[0] > v9 );
}
result = v22;
if ( v22 )
result = mfs_dir_free(v22);
}
}
else if ( result == 8 )
{
v18 = mfs_fsid_size(a1);
v19 = alloca(16 * (((unsigned __int64)(unsigned int)v18 + 23) >> 4));
mfs_fsid_pread(a1, v21, 0LL, v18);
last = 0;
parse_object(a1, v21, dump_callback);
puts("}");
result = (unsigned int)process_queue(a3, a2);
}
else if ( result == 1 && a2 )
{
printf("tyFile %d {\n", a1);
v7 = mfs_fsid_size(a1);
if ( v7 )
{
for ( i = 0; i < v7; i += 0x20000 )
{
mfs_fsid_pread(a1, v20, i, 0x20000LL);
hexdump((__int64)v20, i, 0x20000u);
}
}
result = putchar(125);
}
}
else
{
result = fprintf(stderr, "Skipping invalid fsid: %d\n", a1);
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func7(unsigned int a1, unsigned int a2, int a3, const char *a4)
{
unsigned int result; // eax
unsigned int v7; // er14
unsigned int i; // ebx
unsigned int v9; // er15
size_t v10; // r13
const char **v11; // r14
void *v12; // rsp
int v13; // eax
int v14; // ecx
__int64 v15; // rdx
char *v16; // rax
char *v17; // rdx
__int64 v18; // rcx
void *v19; // rsp
_BYTE v20[15]; // [rsp-Eh] [rbp-20060h] BYREF
char v21[8]; // [rsp+20002h] [rbp-50h] BYREF
__int64 v22; // [rsp+2000Ah] [rbp-48h]
unsigned int v23[13]; // [rsp+2001Eh] [rbp-34h] BYREF

result = func4(a1);
if ( !result )
{
if ( (unsigned int)mfs_valid_fsid(a1) )
{
result = mfs_fsid_type(a1);
if ( result == 4 )
{
if ( a3 )
{
v22 = mfs_dir(a1, v23);
if ( v23[0] )
{
v9 = 0;
do
{
v10 = strlen(a4);
v11 = (const char **)(v22 + 16LL * v9);
v12 = alloca(16 * ((v10 + strlen(v11[1]) + 25) / 0x10));
strcpy(v21, a4);
strcat(v21, v11[1]);
v13 = strlen(v21);
v14 = v13;
if ( v13 > 0 )
{
v15 = v13;
v16 = &v21[v13 - 1];
v17 = &v21[v15 - 2 - (unsigned int)(v14 - 1)];
do
{
if ( *v16 != 32 )
break;
*v16-- = 0;
}
while ( v16 != v17 );
}
*(_WORD *)&v21[strlen(v21)] = 47;
func7(*(unsigned int *)v11, a2, 1LL, v21);
++v9;
}
while ( v23[0] > v9 );
}
result = v22;
if ( v22 )
result = mfs_dir_free(v22);
}
}
else if ( result == 8 )
{
v18 = mfs_fsid_size(a1);
v19 = alloca(16 * (((unsigned __int64)(unsigned int)v18 + 23) >> 4));
mfs_fsid_pread(a1, v21, 0LL, v18);
last = 0;
parse_object(a1, v21, dump_callback);
puts("}");
result = (unsigned int)func6(a3, a2);
}
else if ( result == 1 && a2 )
{
printf("tyFile %d {\n", a1);
v7 = mfs_fsid_size(a1);
if ( v7 )
{
for ( i = 0; i < v7; i += 0x20000 )
{
mfs_fsid_pread(a1, v20, i, 0x20000LL);
func5((__int64)v20, i, 0x20000u);
}
}
result = putchar(125);
}
}
else
{
result = fprintf(stderr, "Skipping invalid fsid: %d\n", a1);
}
}
return result;
}

original_code:
static void dumpobj(int fsid, int fileobj, int recurse, const char *path)
{
 void *buf;
 u32 size;
 int type;
 if (seen_before(fsid)) return;
 if (! mfs_valid_fsid(fsid)) {
   fprintf( stderr, "Skipping invalid fsid: %d\n", fsid );
   return;
 }
 type = mfs_fsid_type(fsid);
 switch (type) {
 case 4:
  if (recurse) {
   u32 count, i;
   struct mfs_dirent *dir = mfs_dir(fsid,&count);
   for(i=0; i<count; i++) {
    int len;
    char *newpath = __builtin_alloca (strlen(path) + strlen(dir[i].name) + 2);
    ((void) sizeof ((newpath) ? 1 : 0), __extension__ ({ if (newpath) ; else __assert_fail ("newpath", "mfs_dumpobj.c", 222, __extension__ __PRETTY_FUNCTION__); }));
    strcpy( newpath, path );
    strcat( newpath, dir[i].name );
    len = strlen(newpath);
    while (len>0 && newpath[len-1]== ' ')
     newpath[--len]=0;
    strcat( newpath, "/" );
    dumpobj( dir[i].fsid, fileobj, 1, newpath );
   }
   if (dir) mfs_dir_free(dir);
  }
  break;
 case 2:
  break;
 case 1:
  if (fileobj) {
   u32 off = 0;
   const u32 bsize = 128*1024;
   printf( "tyFile %d {\n", fsid );
   size = mfs_fsid_size(fsid);
   buf = __builtin_alloca (bsize);
   if (buf) {
    for(off=0; off<size; off+= bsize) {
     int l = size-off;
     if (l > bsize) l = bsize;
     mfs_fsid_pread(fsid, buf, off, bsize);
     hexdump( buf, off, bsize );
    }
   } else {
    fprintf( stderr, "memory allocation failed allocating %d bytes for fsid: %d\n", size, fsid );
   }
   printf("}");
  }
  break;
 case 8:
  size = mfs_fsid_size(fsid);
  buf = __builtin_alloca (size);
  mfs_fsid_pread(fsid, buf, 0, size);
  last = 0;
  parse_object(fsid, buf, dump_callback);
  printf("}\n");
  process_queue(recurse, fileobj);
 }
}

canonical_original_code:
static void dumpobj(int fsid, int fileobj, int recurse, char *path)
{
 void *buf;
 unsigned int size;
 int type;
 if (seen_before(fsid)) return;
 if (! mfs_valid_fsid(fsid)) {
   fprintf( stderr, "Skipping invalid fsid: %d\n", fsid );
   return;
 }
 type = mfs_fsid_type(fsid);
 switch (type) {
 case 4:
  if (recurse) {
   unsigned int count; unsigned int i;
   struct mfs_dirent *dir = mfs_dir(fsid,&count);
   for(i=0; i<count; i++) {
    int len;
    char *newpath = __builtin_alloca (strlen(path) + strlen(dir[i].name) + 2);
    ((void) sizeof ((newpath) ? 1 : 0), __extension__ ({ if (newpath) ; else __assert_fail ("newpath", "mfs_dumpobj.c", 222, __extension__ __PRETTY_FUNCTION__); }));
    strcpy( newpath, path );
    strcat( newpath, dir[i].name );
    len = strlen(newpath);
    while (len>0 && newpath[len-1]== ' ')
     newpath[--len]=0;
    strcat( newpath, "/" );
    dumpobj( dir[i].fsid, fileobj, 1, newpath );
   }
   if (dir) mfs_dir_free(dir);
  }
  break;
 case 2:
  break;
 case 1:
  if (fileobj) {
   unsigned int off = 0;
   unsigned int bsize = 128*1024;
   printf( "tyFile %d {\n", fsid );
   size = mfs_fsid_size(fsid);
   buf = __builtin_alloca (bsize);
   if (buf) {
    for(off=0; off<size; off+= bsize) {
     int l = size-off;
     if (l > bsize) l = bsize;
     mfs_fsid_pread(fsid, buf, off, bsize);
     hexdump( buf, off, bsize );
    }
   } else {
    fprintf( stderr, "memory allocation failed allocating %d bytes for fsid: %d\n", size, fsid );
   }
   printf("}");
  }
  break;
 case 8:
  size = mfs_fsid_size(fsid);
  buf = __builtin_alloca (size);
  mfs_fsid_pread(fsid, buf, 0, size);
  last = 0;
  parse_object(fsid, buf, dump_callback);
  printf("}\n");
  process_queue(recurse, fileobj);
 }
}

variable_types: fsid int

variable_types:
path
char *

variable_types:
buf
void *

variable_types:
size
unsigned int

variable_types: type int

variable_types:
count
unsigned int

variable_types:
i
unsigned int

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

variable_types: len int

variable_types:
newpath
char *

variable_types:
off
unsigned int

variable_types:
bsize
unsigned int

variable_types: l int

return_type: void


decompiled_code:
void free_hash()
{
if ( hash_table )
{
free(hash_table);
hash_table = 0LL;
hash_size = 0;
}
}

canonical_decompiled_code:
void func8()
{
if ( hash_table )
{
free(hash_table);
hash_table = 0LL;
hash_size = 0;
}
}

original_code:
static void free_hash() {
 if (hash_table) {
  free(hash_table);
  hash_table = 0;
  hash_size = 0;
 }
}


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"\n"
"usage: mfs_dumpobj [options] <path|fsid>\n"
"\n"
" -h\t\t\t display humnan readable dates, times, and durations\n"
" -f hexdump file objects\n"
" -l\t\t\t convert dates and times to local TZ\n"
" -r recusive\n",
1uLL,
0x10BuLL,
stderr);
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite(
"\n"
"usage: mfs_dumpobj [options] <path|fsid>\n"
"\n"
" -h\t\t\t display humnan readable dates, times, and durations\n"
" -f hexdump file objects\n"
" -l\t\t\t convert dates and times to local TZ\n"
" -r recusive\n",
1uLL,
0x10BuLL,
stderr);
credits();
exit(1);
}

original_code:
static void usage(void)
{
 fprintf( stderr, "\nusage: mfs_dumpobj [options] <path|fsid>\n\n      -h			     display humnan readable dates, times, and durations\n      -f                             hexdump file objects\n      -l			     convert dates and times to local TZ\n      -r                             recusive\n");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf( stderr, "\nusage: mfs_dumpobj [options] <path|fsid>\n\n      -h			     display humnan readable dates, times, and durations\n      -f                             hexdump file objects\n      -l			     convert dates and times to local TZ\n      -r                             recusive\n");
 credits();
 exit(1);
}


decompiled_code:
__int64 __fastcall queue_add(int a1)
{
__int64 result; // rax

LODWORD(result) = nq;
if ( nq > 10239 )
_assert_fail("nq < MAX_QUEUE", "mfs_dumpobj.c", 0x1Cu, "queue_add");
++nq;
result = (int)result;
fsid_queue[(int)result] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax

LODWORD(result) = nq;
if ( nq > 10239 )
_assert_fail("nq < MAX_QUEUE", "mfs_dumpobj.c", 0x1Cu, "queue_add");
++nq;
result = (int)result;
fsid_queue[(int)result] = a1;
return result;
}

original_code:
static void queue_add(int fsid) {
 ((void) sizeof ((nq < 10240) ? 1 : 0), __extension__ ({ if (nq < 10240) ; else __assert_fail ("nq < MAX_QUEUE", "mfs_dumpobj.c", 28, __extension__ __PRETTY_FUNCTION__); }));
 fsid_queue[nq++] = fsid;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // er13
int v5; // eax
const char **v6; // rbx
unsigned int v7; // eax

mfs_init(argc, argv, envp);
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fhlr");
if ( v5 == -1 )
break;
if ( v5 == 108 )
{
timefn = (__int64 (__fastcall *)(_QWORD))&localtime;
}
else if ( v5 > 108 )
{
if ( v5 != 114 )
goto LABEL_11;
v4 = 1;
}
else if ( v5 == 102 )
{
v3 = 1;
}
else
{
if ( v5 != 104 )
LABEL_11:
usage();
option_human = 1;
}
}
v6 = &argv[optind];
if ( argc - optind <= 0 )
usage();
v7 = mfs_resolve(*v6);
dumpobj(v7, v3, v4, *v6);
free_hash();
return 0;
}

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

mfs_init(argc, argv, envp);
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fhlr");
if ( v5 == -1 )
break;
if ( v5 == 108 )
{
timefn = (__int64 (__fastcall *)(_QWORD))&localtime;
}
else if ( v5 > 108 )
{
if ( v5 != 114 )
goto LABEL_11;
v4 = 1;
}
else if ( v5 == 102 )
{
v3 = 1;
}
else
{
if ( v5 != 104 )
LABEL_11:
func0();
option_human = 1;
}
}
v6 = &argv[optind];
if ( argc - optind <= 0 )
func0();
v7 = mfs_resolve(*v6);
func7(v7, v3, v4, *v6);
func8();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 int recurse = 0;
 int fileobj = 0;
 mfs_init();
 while ((c = getopt(argc, argv, "fhlr")) != -1 ){
  switch (c) {
  case 'f':
   fileobj = 1;
   break;
  case 'h':
   option_human = 1;
   break;
  case 'l':
   timefn = localtime;
   break;
  case 'r':
   recurse = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 fsid = mfs_resolve(argv[0]);
 dumpobj(fsid,fileobj,recurse,argv[0]);
 free_hash();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: recurse int

return_type: int


readall

decompiled_code:
ssize_t __fastcall readall(int fd, void *buf, size_t n)
{
size_t v4; // rbx
ssize_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // r14
int v8; // eax
ssize_t v10; // rax

v4 = n;
if ( use_recv )
{
if ( !n )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = recv(fd, buf, v4, 256);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 += v6;
v4 -= v6;
if ( !v4 )
return v5;
}
perror("recv error, falling back to read loop. ");
use_recv = 0;
v7 = v5;
}
else
{
v7 = 0LL;
}
if ( !v4 )
return v7;
do
{
v10 = read(fd, buf, v4);
v5 = v10;
if ( v10 <= 0 )
{
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
return v5;
}
else
{
buf = (char *)buf + v10;
v4 -= v10;
v7 += v10;
}
}
while ( v4 );
return v7;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, void *buf, size_t n)
{
size_t v4; // rbx
ssize_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // r14
int v8; // eax
ssize_t v10; // rax

v4 = n;
if ( use_recv )
{
if ( !n )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = recv(fd, buf, v4, 256);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 += v6;
v4 -= v6;
if ( !v4 )
return v5;
}
perror("recv error, falling back to read loop. ");
use_recv = 0;
v7 = v5;
}
else
{
v7 = 0LL;
}
if ( !v4 )
return v7;
do
{
v10 = read(fd, buf, v4);
v5 = v10;
if ( v10 <= 0 )
{
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
return v5;
}
else
{
buf = (char *)buf + v10;
v4 -= v10;
v7 += v10;
}
}
while ( v4 );
return v7;
}

original_code:
static inline ssize_t readall( int fd, void *buf, size_t count )
{
 unsigned char *p = buf;
 ssize_t rc = 0;
 ssize_t ret = 0;
 if (use_recv) {
  while (count > 0) {
   ret = recv( fd, p, count, MSG_WAITALL );
   if (ret <= 0) {
    perror("recv error, falling back to read loop. ");
    use_recv=0;
    break;
   }
   p += ret;
   count -= ret;
   rc += ret;
  }
 }
 if (!use_recv)
 {
  while (count > 0) {
   ret = read( fd, p, count );
   if (ret <= 0) {
    if ((*__errno_location ()) != 4 && (*__errno_location ()) != 11)
     return ret;
    continue;
   }
   p += ret;
   count -= ret;
   rc += ret;
  }
 }
 return rc;
}

canonical_original_code:
static inline long readall(int fd, void *buf, unsigned long count)
{
 unsigned char *p = buf;
 long rc = 0;
 long ret = 0;
 if (use_recv) {
  while (count > 0) {
   ret = recv( fd, p, count, MSG_WAITALL );
   if (ret <= 0) {
    perror("recv error, falling back to read loop. ");
    use_recv=0;
    break;
   }
   p += ret;
   count -= ret;
   rc += ret;
  }
 }
 if (!use_recv)
 {
  while (count > 0) {
   ret = read( fd, p, count );
   if (ret <= 0) {
    if ((*__errno_location ()) != 4 && (*__errno_location ()) != 11)
     return ret;
    continue;
   }
   p += ret;
   count -= ret;
   rc += ret;
  }
 }
 return rc;
}

variable_types: fd int

variable_types:
count
unsigned long

variable_types:
p
unsigned char *

variable_types: rc long

variable_types: ret long

return_type: long


decompiled_code:
__int64 __fastcall overwrite_stream(unsigned int a1, int a2, unsigned __int64 a3, unsigned __int64 a4, int a5, unsigned int a6, int a7)
{
void *v7; // rsp
unsigned __int64 v8; // rcx
int v9; // er14
unsigned __int64 v10; // r15
unsigned __int64 v11; // r14
unsigned __int64 v12; // r12
unsigned int v13; // er15
int v14; // eax
int v15; // ebx
int v16; // er13
unsigned __int64 v17; // r15
unsigned __int64 v19; // rax
unsigned __int64 v20; // r14
__int16 v21; // bx
int v22; // eax
int v23; // ebx
unsigned int v24; // ebx
unsigned __int64 v25; // rbx
int v26; // eax
int v27; // er12
int v28; // er12
unsigned __int64 v29; // rax
int v30; // ebx
__int64 v31; // [rsp+0h] [rbp-290h] BYREF
__int64 v32; // [rsp+8h] [rbp-288h]
unsigned __int64 v33; // [rsp+10h] [rbp-280h]
int v34; // [rsp+1Ch] [rbp-274h]
unsigned int v35; // [rsp+20h] [rbp-270h]
int fd; // [rsp+24h] [rbp-26Ch]
unsigned __int64 v37; // [rsp+28h] [rbp-268h]
__int64 v38; // [rsp+30h] [rbp-260h]
void *buf; // [rsp+38h] [rbp-258h]
int v40; // [rsp+40h] [rbp-250h]
unsigned int v41; // [rsp+44h] [rbp-24Ch]
unsigned __int64 v42; // [rsp+48h] [rbp-248h]
struct timespec requested_time; // [rsp+50h] [rbp-240h] BYREF
char v44[56]; // [rsp+60h] [rbp-230h] BYREF
unsigned int v45; // [rsp+98h] [rbp-1F8h]
int v46[125]; // [rsp+9Ch] [rbp-1F4h]

fd = a2;
v37 = a3;
v33 = a4;
v40 = a5;
v35 = a6;
v7 = alloca(16 * (((unsigned __int64)(a6 << 9) + 23) >> 4));
buf = &v31;
if ( a5 > 0 )
{
requested_time.tv_sec = a5 / 1000;
v40 = a5 % 1000;
requested_time.tv_nsec = 1000000 * (a5 % 1000);
}
mfs_load_inode(a1, v44);
v8 = mfs_fsid_size(a1);
if ( v8 >= v37 )
{
if ( v33 + v37 <= v8 && v33 )
{
if ( !a7 )
goto LABEL_8;
}
else
{
v33 = v8 - v37;
if ( !a7 )
goto LABEL_7;
}
fprintf(stderr, "importing fsid %d of size %llu starting at offset %llu for %lld bytes\n", a1, v8, v37, v33);
LABEL_7:
v9 = v33;
if ( !v33 )
return (unsigned int)(v33 - v9);
LABEL_8:
v32 = 0LL;
v34 = 0;
v42 = 0LL;
v10 = v33;
while ( v45 > (unsigned int)v32 )
{
v16 = v46[2 * v32 + 1];
if ( v42 + ((__int64)v16 << 9) >= v37 )
{
if ( v16 > 0 )
{
v41 = v46[2 * v32];
v11 = v10;
while ( 1 )
{
if ( v37 <= v42 )
{
v17 = v11;
}
else
{
v21 = v37 - v42;
v22 = ((int)v37 - (int)v42) >> 9;
v42 += (int)v37 - (int)v42;
v16 -= v22;
v41 += v22;
v17 = v11;
v23 = v21 & 0x1FF;
if ( v23 )
{
v12 = 512 - v23;
if ( v12 > v11 )
LODWORD(v12) = v11;
v13 = v41;
mfs_read_sectors(buf, v41, 1LL);
v14 = readall(fd, (char *)buf + v23, (int)v12);
v15 = v14;
if ( v14 <= 0 )
{
fwrite("read failed.\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
if ( (_DWORD)v12 != v14 )
fprintf(stderr, "short read: %d/%d\n", (unsigned int)v14, (unsigned int)v12);
mfs_write_sectors(buf, v13, 1LL);
++v41;
--v16;
v17 = v11 - v15;
v42 += v15;
}
}
v24 = v35;
if ( v16 <= v35 )
v24 = v16;
v25 = (int)(v24 << 9);
if ( v25 > v17 )
LODWORD(v25) = v17;
v26 = readall(fd, buf, (int)v25);
v27 = v26;
if ( v26 < 0 )
{
perror("read failed:");
return 0xFFFFFFFFLL;
}
v38 = v26;
v42 += v26;
v11 = v17 - v26;
mfs_write_partial(buf, v41);
if ( (_DWORD)v25 != v27 )
{
v19 = v11;
v20 = v17;
v10 = v19;
fprintf(stderr, "input stream truncated early: %lld out of %lld bytes received\n", v33 + v38 - v20, v19);
goto LABEL_21;
}
v28 = v27 >> 9;
v16 -= v28;
v41 += v28;
if ( a7 )
{
v29 = 100 * (v33 - v17 + v38) / v33;
v30 = v29;
if ( (_DWORD)v29 == v34 )
{
v34 = 100 * (v33 - v17 + v38) / v33;
}
else
{
fprintf(stderr, "%d%%\r", (unsigned int)v29);
fflush(stderr);
v34 = v30;
}
}
if ( v40 > 0 )
{
nanosleep(&requested_time, 0LL);
}
else if ( !v40 )
{
sched_yield();
}
if ( v16 <= 0 )
break;
if ( !v11 )
{
v10 = 0LL;
goto LABEL_21;
}
}
v10 = v11;
}
}
else
{
v42 += (__int64)v16 << 9;
}
LABEL_21:
++v32;
if ( !v10 )
{
v9 = 0;
return (unsigned int)(v33 - v9);
}
}
v9 = v10;
return (unsigned int)(v33 - v9);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, unsigned __int64 a3, unsigned __int64 a4, int a5, unsigned int a6, int a7)
{
void *v7; // rsp
unsigned __int64 v8; // rcx
int v9; // er14
unsigned __int64 v10; // r15
unsigned __int64 v11; // r14
unsigned __int64 v12; // r12
unsigned int v13; // er15
int v14; // eax
int v15; // ebx
int v16; // er13
unsigned __int64 v17; // r15
unsigned __int64 v19; // rax
unsigned __int64 v20; // r14
__int16 v21; // bx
int v22; // eax
int v23; // ebx
unsigned int v24; // ebx
unsigned __int64 v25; // rbx
int v26; // eax
int v27; // er12
int v28; // er12
unsigned __int64 v29; // rax
int v30; // ebx
__int64 v31; // [rsp+0h] [rbp-290h] BYREF
__int64 v32; // [rsp+8h] [rbp-288h]
unsigned __int64 v33; // [rsp+10h] [rbp-280h]
int v34; // [rsp+1Ch] [rbp-274h]
unsigned int v35; // [rsp+20h] [rbp-270h]
int fd; // [rsp+24h] [rbp-26Ch]
unsigned __int64 v37; // [rsp+28h] [rbp-268h]
__int64 v38; // [rsp+30h] [rbp-260h]
void *buf; // [rsp+38h] [rbp-258h]
int v40; // [rsp+40h] [rbp-250h]
unsigned int v41; // [rsp+44h] [rbp-24Ch]
unsigned __int64 v42; // [rsp+48h] [rbp-248h]
struct timespec requested_time; // [rsp+50h] [rbp-240h] BYREF
char v44[56]; // [rsp+60h] [rbp-230h] BYREF
unsigned int v45; // [rsp+98h] [rbp-1F8h]
int v46[125]; // [rsp+9Ch] [rbp-1F4h]

fd = a2;
v37 = a3;
v33 = a4;
v40 = a5;
v35 = a6;
v7 = alloca(16 * (((unsigned __int64)(a6 << 9) + 23) >> 4));
buf = &v31;
if ( a5 > 0 )
{
requested_time.tv_sec = a5 / 1000;
v40 = a5 % 1000;
requested_time.tv_nsec = 1000000 * (a5 % 1000);
}
mfs_load_inode(a1, v44);
v8 = mfs_fsid_size(a1);
if ( v8 >= v37 )
{
if ( v33 + v37 <= v8 && v33 )
{
if ( !a7 )
goto LABEL_8;
}
else
{
v33 = v8 - v37;
if ( !a7 )
goto LABEL_7;
}
fprintf(stderr, "importing fsid %d of size %llu starting at offset %llu for %lld bytes\n", a1, v8, v37, v33);
LABEL_7:
v9 = v33;
if ( !v33 )
return (unsigned int)(v33 - v9);
LABEL_8:
v32 = 0LL;
v34 = 0;
v42 = 0LL;
v10 = v33;
while ( v45 > (unsigned int)v32 )
{
v16 = v46[2 * v32 + 1];
if ( v42 + ((__int64)v16 << 9) >= v37 )
{
if ( v16 > 0 )
{
v41 = v46[2 * v32];
v11 = v10;
while ( 1 )
{
if ( v37 <= v42 )
{
v17 = v11;
}
else
{
v21 = v37 - v42;
v22 = ((int)v37 - (int)v42) >> 9;
v42 += (int)v37 - (int)v42;
v16 -= v22;
v41 += v22;
v17 = v11;
v23 = v21 & 0x1FF;
if ( v23 )
{
v12 = 512 - v23;
if ( v12 > v11 )
LODWORD(v12) = v11;
v13 = v41;
mfs_read_sectors(buf, v41, 1LL);
v14 = func1(fd, (char *)buf + v23, (int)v12);
v15 = v14;
if ( v14 <= 0 )
{
fwrite("read failed.\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
if ( (_DWORD)v12 != v14 )
fprintf(stderr, "short read: %d/%d\n", (unsigned int)v14, (unsigned int)v12);
mfs_write_sectors(buf, v13, 1LL);
++v41;
--v16;
v17 = v11 - v15;
v42 += v15;
}
}
v24 = v35;
if ( v16 <= v35 )
v24 = v16;
v25 = (int)(v24 << 9);
if ( v25 > v17 )
LODWORD(v25) = v17;
v26 = func1(fd, buf, (int)v25);
v27 = v26;
if ( v26 < 0 )
{
perror("read failed:");
return 0xFFFFFFFFLL;
}
v38 = v26;
v42 += v26;
v11 = v17 - v26;
mfs_write_partial(buf, v41);
if ( (_DWORD)v25 != v27 )
{
v19 = v11;
v20 = v17;
v10 = v19;
fprintf(stderr, "input stream truncated early: %lld out of %lld bytes received\n", v33 + v38 - v20, v19);
goto LABEL_21;
}
v28 = v27 >> 9;
v16 -= v28;
v41 += v28;
if ( a7 )
{
v29 = 100 * (v33 - v17 + v38) / v33;
v30 = v29;
if ( (_DWORD)v29 == v34 )
{
v34 = 100 * (v33 - v17 + v38) / v33;
}
else
{
fprintf(stderr, "%d%%\r", (unsigned int)v29);
fflush(stderr);
v34 = v30;
}
}
if ( v40 > 0 )
{
nanosleep(&requested_time, 0LL);
}
else if ( !v40 )
{
sched_yield();
}
if ( v16 <= 0 )
break;
if ( !v11 )
{
v10 = 0LL;
goto LABEL_21;
}
}
v10 = v11;
}
}
else
{
v42 += (__int64)v16 << 9;
}
LABEL_21:
++v32;
if ( !v10 )
{
v9 = 0;
return (unsigned int)(v33 - v9);
}
}
v9 = v10;
return (unsigned int)(v33 - v9);
}
return 0LL;
}

original_code:
static int overwrite_stream(const u32 fsid, const int fd, u64 start,
       u64 count, int delayms, u32 nbufs, int verbose )
{
        struct mfs_inode inode;
        int run;
        int pct, last_pct=0;
        u64 ofs=0, size;
 u64 total;
 struct timespec delay;
        unsigned char *buf = __builtin_alloca (nbufs*512);
 if (!buf) {
  fprintf( stderr, "Couldn't allocate buffer: %d\n",
    nbufs*512 );
  exit(1);
 }
 if (delayms > 0) {
  delay.tv_sec = delayms/1000;
  delayms %= 1000;
  delay.tv_nsec = delayms*1000000;
 }
        mfs_load_inode(fsid, &inode);
        size = mfs_fsid_size(fsid);
 if (start>size) {
  return 0;
 }
 if (start+count>size || count==0) {
  count = size-start;
 }
 total = count;
 if (verbose) {
  fprintf(stderr,
   "importing fsid %d of size %llu starting at offset %llu for %lld bytes\n",
   fsid, size, start, count);
 }
        for (run=0;count>0 && run<inode.num_runs;run++) {
                int len=inode.u.runs[run].len;
                int sec=inode.u.runs[run].start;
  if (start > ofs+((u64)len<<9)) {
   ofs +=((u64)len<<9);
   continue;
  }
                while (len>0 && count>0) {
   int rlen, blen, ret;
   if (start > ofs) {
    int bofs = start-ofs;
    int sofs = bofs>>9;
    int bmod = bofs&(512 -1);
    ofs += bofs;
    len -= sofs;
    sec += sofs;
    if (bmod) {
     int blen = ((512 -bmod)<(count)?(512 -bmod):(count));
     int ret;
     mfs_read_sectors(buf,sec,1);
     ret = readall(fd, buf+bmod, blen );
     if (ret <= 0) {
      fprintf(stderr,"read failed.\n");
      exit(1);
     } else if (ret != blen) {
      fprintf(stderr,"short read: %d/%d\n",
       ret, blen);
     }
     mfs_write_sectors(buf,sec,1);
     sec++;
     len--;
     count -= ret;
     ofs += ret;
    }
   }
                        rlen = ((nbufs)<(len)?(nbufs):(len));
   blen = ((rlen<<9)<(count)?(rlen<<9):(count));
                        ret = readall(fd,buf,blen);
                        if (ret < 0) {
    perror("read failed:");
    return -1;
   }
                        ofs += ret;
   count -= ret;
   mfs_write_partial(buf, sec, ret);
   if (ret != blen) {
     fprintf( stderr, "input stream truncated early:  %lld out of %lld bytes received\n",
       (total-count), count );
     break;
   }
                        ret >>= 9;
                        len -= ret;
                        sec += ret;
   if (verbose) {
    pct = (100 * (total-count))/total;
    if (pct != last_pct) {
     fprintf(stderr,"%d%%\r", pct);
     fflush(stderr);
     last_pct = pct;
    }
   }
   if (delayms > 0)
    nanosleep( &delay, ((void *)0) );
   else if (delayms == 0)
    sched_yield();
                }
        }
 return total-count;
}

canonical_original_code:
static int overwrite_stream(unsigned int fsid, int fd, unsigned int start, unsigned int count, int delayms, unsigned int nbufs, int verbose)
{
        struct mfs_inode inode;
        int run;
        int pct; int last_pct = 0;
        unsigned int ofs = 0; unsigned int size;
 unsigned int total;
 struct timespec delay;
        unsigned char *buf = __builtin_alloca (nbufs*512);
 if (!buf) {
  fprintf( stderr, "Couldn't allocate buffer: %d\n",
    nbufs*512 );
  exit(1);
 }
 if (delayms > 0) {
  delay.tv_sec = delayms/1000;
  delayms %= 1000;
  delay.tv_nsec = delayms*1000000;
 }
        mfs_load_inode(fsid, &inode);
        size = mfs_fsid_size(fsid);
 if (start>size) {
  return 0;
 }
 if (start+count>size || count==0) {
  count = size-start;
 }
 total = count;
 if (verbose) {
  fprintf(stderr,
   "importing fsid %d of size %llu starting at offset %llu for %lld bytes\n",
   fsid, size, start, count);
 }
        for (run=0;count>0 && run<inode.num_runs;run++) {
                int len = inode.u.runs[run].len;
                int sec = inode.u.runs[run].start;
  if (start > ofs+((unsigned int)len<<9)) {
   ofs +=((unsigned int)len<<9);
   continue;
  }
                while (len>0 && count>0) {
   int rlen; int blen; int ret;
   if (start > ofs) {
    int bofs = start-ofs;
    int sofs = bofs>>9;
    int bmod = bofs&(512 -1);
    ofs += bofs;
    len -= sofs;
    sec += sofs;
    if (bmod) {
     int blen = ((512 -bmod)<(count)?(512 -bmod):(count));
     int ret;
     mfs_read_sectors(buf,sec,1);
     ret = readall(fd, buf+bmod, blen );
     if (ret <= 0) {
      fprintf(stderr,"read failed.\n");
      exit(1);
     } else if (ret != blen) {
      fprintf(stderr,"short read: %d/%d\n",
       ret, blen);
     }
     mfs_write_sectors(buf,sec,1);
     sec++;
     len--;
     count -= ret;
     ofs += ret;
    }
   }
                        rlen = ((nbufs)<(len)?(nbufs):(len));
   blen = ((rlen<<9)<(count)?(rlen<<9):(count));
                        ret = readall(fd,buf,blen);
                        if (ret < 0) {
    perror("read failed:");
    return -1;
   }
                        ofs += ret;
   count -= ret;
   mfs_write_partial(buf, sec, ret);
   if (ret != blen) {
     fprintf( stderr, "input stream truncated early:  %lld out of %lld bytes received\n",
       (total-count), count );
     break;
   }
                        ret >>= 9;
                        len -= ret;
                        sec += ret;
   if (verbose) {
    pct = (100 * (total-count))/total;
    if (pct != last_pct) {
     fprintf(stderr,"%d%%\r", pct);
     fflush(stderr);
     last_pct = pct;
    }
   }
   if (delayms > 0)
    nanosleep( &delay, ((void *)0) );
   else if (delayms == 0)
    sched_yield();
                }
        }
 return total-count;
}

variable_types:
fsid
unsigned int

variable_types:
start
unsigned int

variable_types:
count
unsigned int

variable_types: delayms int

variable_types:
nbufs
unsigned int

variable_types: verbose 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; }

variable_types: run int

variable_types: pct int

variable_types:
ofs
unsigned int

variable_types:
size
unsigned int

variable_types:
total
unsigned int

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

variable_types:
buf
unsigned char *

variable_types: sec int

variable_types: rlen int

variable_types: blen int

variable_types: ret int

variable_types: bofs int

variable_types: sofs int

variable_types: bmod int

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


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"\n"
"usage: %s [options] <path|fsid> [<src>]\n"
"\n"
" options:\n"
" -c <count> number of bytes (defaults to size of fsid)\n"
"\t-n <count>\t number of sectors to use for buffering\n"
"\t-p <priority> Priority 0: ts; 1-99 RT FIFO\n"
" -s <start> start offset, in bytes (defaults to 0)\n"
"\t-r <ms>\t\t rate control (throttle)\n"
" -'ve : no delay (default)\n"
" 0 : sched_yield() between chunks\n"
" +'ve : # of ms to delay between chunks\n"
"\t-v\t\t verbose progress messages on stderr\n"
"\n"
" <src> defaults to stdin if not present on the command line.\n",
(const char *)prog);
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(
stderr,
"\n"
"usage: %s [options] <path|fsid> [<src>]\n"
"\n"
" options:\n"
" -c <count> number of bytes (defaults to size of fsid)\n"
"\t-n <count>\t number of sectors to use for buffering\n"
"\t-p <priority> Priority 0: ts; 1-99 RT FIFO\n"
" -s <start> start offset, in bytes (defaults to 0)\n"
"\t-r <ms>\t\t rate control (throttle)\n"
" -'ve : no delay (default)\n"
" 0 : sched_yield() between chunks\n"
" +'ve : # of ms to delay between chunks\n"
"\t-v\t\t verbose progress messages on stderr\n"
"\n"
" <src> defaults to stdin if not present on the command line.\n",
(const char *)prog);
credits();
exit(1);
}

original_code:
static void usage(void)
{
 fprintf(stderr,"\nusage: %s [options] <path|fsid> [<src>]\n\n   options:\n        -c <count>          number of bytes (defaults to size of fsid)\n	-n <count>	    number of sectors to use for buffering\n	-p <priority>       Priority  0: ts; 1-99 RT FIFO\n        -s <start>          start offset, in bytes (defaults to 0)\n	-r <ms>		    rate control (throttle)\n                              -'ve  : no delay (default)\n                              0     : sched_yield() between chunks\n                              +'ve  : # of ms to delay between chunks\n	-v		    verbose progress messages on stderr\n\n   <src> defaults to stdin if not present on the command line.\n", prog );
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr,"\nusage: %s [options] <path|fsid> [<src>]\n\n   options:\n        -c <count>          number of bytes (defaults to size of fsid)\n	-n <count>	    number of sectors to use for buffering\n	-p <priority>       Priority  0: ts; 1-99 RT FIFO\n        -s <start>          start offset, in bytes (defaults to 0)\n	-r <ms>		    rate control (throttle)\n                              -'ve  : no delay (default)\n                              0     : sched_yield() between chunks\n                              +'ve  : # of ms to delay between chunks\n	-v		    verbose progress messages on stderr\n\n   <src> defaults to stdin if not present on the command line.\n", prog );
 credits();
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // er13
__int64 v5; // r12
int v6; // eax
__int64 v7; // rax
int v8; // ebx
const char **v9; // rbp
unsigned int v10; // er15
bool v11; // zf
int v12; // esi
int result; // eax
__int64 v14; // [rsp+0h] [rbp-48h]
int v15; // [rsp+Ch] [rbp-3Ch]

prog = (void *)*argv;
v15 = 0;
v3 = 256;
v4 = -1;
v5 = 0LL;
v14 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hvs:c:r:n:p:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'c':
v5 = strtoll(optarg, 0LL, 0);
break;
case 'h':
usage();
return result;
case 'n':
v3 = strtoll(optarg, 0LL, 0);
break;
case 'p':
v7 = strtoll(optarg, 0LL, 0);
fixPriority(v7);
break;
case 'r':
v4 = strtoll(optarg, 0LL, 0);
break;
case 's':
v14 = strtoll(optarg, 0LL, 0);
break;
case 'v':
v15 = 1;
break;
default:
usage();
return result;
}
}
v8 = argc - optind;
v9 = &argv[optind];
if ( argc - optind <= 0 )
usage();
mfs_init();
v10 = mfs_resolve(*v9);
if ( !v10 )
{
fprintf(stderr, "Error: The path or fsid %s is invalid\n", v9[1]);
exit(1);
}
if ( v8 <= 1 )
{
v12 = 0;
return (int)overwrite_stream(v10, v12, v14, v5, v4, v3, v15) <= 0;
}
v11 = strcmp(v9[1], "-") == 0;
v12 = !v11;
if ( v11 )
return (int)overwrite_stream(v10, v12, v14, v5, v4, v3, v15) <= 0;
v12 = open64(v9[1], 0);
if ( v12 >= 0 )
return (int)overwrite_stream(v10, v12, v14, v5, v4, v3, v15) <= 0;
perror(v9[1]);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // er13
__int64 v5; // r12
int v6; // eax
__int64 v7; // rax
int v8; // ebx
const char **v9; // rbp
unsigned int v10; // er15
bool v11; // zf
int v12; // esi
int result; // eax
__int64 v14; // [rsp+0h] [rbp-48h]
int v15; // [rsp+Ch] [rbp-3Ch]

prog = (void *)*argv;
v15 = 0;
v3 = 256;
v4 = -1;
v5 = 0LL;
v14 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hvs:c:r:n:p:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'c':
v5 = strtoll(optarg, 0LL, 0);
break;
case 'h':
func0();
return result;
case 'n':
v3 = strtoll(optarg, 0LL, 0);
break;
case 'p':
v7 = strtoll(optarg, 0LL, 0);
fixPriority(v7);
break;
case 'r':
v4 = strtoll(optarg, 0LL, 0);
break;
case 's':
v14 = strtoll(optarg, 0LL, 0);
break;
case 'v':
v15 = 1;
break;
default:
func0();
return result;
}
}
v8 = argc - optind;
v9 = &argv[optind];
if ( argc - optind <= 0 )
func0();
mfs_init();
v10 = mfs_resolve(*v9);
if ( !v10 )
{
fprintf(stderr, "Error: The path or fsid %s is invalid\n", v9[1]);
exit(1);
}
if ( v8 <= 1 )
{
v12 = 0;
return (int)func2(v10, v12, v14, v5, v4, v3, v15) <= 0;
}
v11 = strcmp(v9[1], "-") == 0;
v12 = !v11;
if ( v11 )
return (int)func2(v10, v12, v14, v5, v4, v3, v15) <= 0;
v12 = open64(v9[1], 0);
if ( v12 >= 0 )
return (int)func2(v10, v12, v14, v5, v4, v3, v15) <= 0;
perror(v9[1]);
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 int fsid=0, fd=0;
 int c;
 u64 start=0;
 u64 count=0;
 int delayms = -1;
 u32 nbufs = 256;
 int verbose = 0;
 int ret;
 prog = argv[0];
 while ((c = getopt(argc, argv, "hvs:c:r:n:p:")) != -1 ){
  switch (c) {
  case 'h':
   usage();
   break;
  case 'c':
   count = strtoll(optarg, ((void *)0), 0);
   break;
  case 'p':
   fixPriority(strtoll(optarg, ((void *)0), 0));
   break;
  case 'n':
   nbufs = strtoll(optarg, ((void *)0), 0);
   break;
  case 's':
   start = strtoll(optarg, ((void *)0), 0);
   break;
  case 'r':
   delayms = strtoll(optarg, ((void *)0), 0);
   break;
  case 'v':
   verbose = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 mfs_init();
 fsid = mfs_resolve(argv[0]);
 if (fsid == 0)
 {
  fprintf(stderr, "Error: The path or fsid %s is invalid\n", argv[1]);
  exit(1);
 }
 if ( argc>=2 && strcmp(argv[1],"-")!=0 &&
      (fd = open(argv[1], 00)) < 0) {
  perror(argv[1]);
  return 1;
 }
 ret = overwrite_stream(fsid,fd,start,count,delayms,nbufs,verbose);
 return (ret > 0 ) ? 0 : 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fsid = 0; int fd = 0;
 int c;
 unsigned int start = 0;
 unsigned int count = 0;
 int delayms = -1;
 unsigned int nbufs = 256;
 int verbose = 0;
 int ret;
 prog = argv[0];
 while ((c = getopt(argc, argv, "hvs:c:r:n:p:")) != -1 ){
  switch (c) {
  case 'h':
   usage();
   break;
  case 'c':
   count = strtoll(optarg, ((void *)0), 0);
   break;
  case 'p':
   fixPriority(strtoll(optarg, ((void *)0), 0));
   break;
  case 'n':
   nbufs = strtoll(optarg, ((void *)0), 0);
   break;
  case 's':
   start = strtoll(optarg, ((void *)0), 0);
   break;
  case 'r':
   delayms = strtoll(optarg, ((void *)0), 0);
   break;
  case 'v':
   verbose = 1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 mfs_init();
 fsid = mfs_resolve(argv[0]);
 if (fsid == 0)
 {
  fprintf(stderr, "Error: The path or fsid %s is invalid\n", argv[1]);
  exit(1);
 }
 if ( argc>=2 && strcmp(argv[1],"-")!=0 &&
      (fd = open(argv[1], 00)) < 0) {
  perror(argv[1]);
  return 1;
 }
 ret = overwrite_stream(fsid,fd,start,count,delayms,nbufs,verbose);
 return (ret > 0 ) ? 0 : 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fsid int

variable_types: fd int

variable_types: c int

variable_types:
start
unsigned int

variable_types:
count
unsigned int

variable_types: delayms int

variable_types:
nbufs
unsigned int


getvids

decompiled_code:
void __fastcall getvids(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // r12
__int64 i; // rbp
int *v5; // rbx
int v6; // edx
int v7; // eax
char v8[4]; // [rsp+Ch] [rbp-3Ch] BYREF
char *ptr; // [rsp+10h] [rbp-38h] BYREF
int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v2 = (unsigned int *)query_object(a1, a2, v10);
if ( v2 )
{
v3 = v2;
if ( *v2 )
{
for ( i = 0LL; v10[0] > (int)i; ++i )
{
asprintf(&ptr, "%s/%d/VideoClip", a2, v3[2 * i + 1]);
v5 = (int *)query_object((unsigned int)a1, ptr, v8);
v6 = *v5;
v7 = num_vids++;
vid_fsid[v7] = v6;
free(ptr);
free(v5);
}
free(v3);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // r12
__int64 i; // rbp
int *v5; // rbx
int v6; // edx
int v7; // eax
char v8[4]; // [rsp+Ch] [rbp-3Ch] BYREF
char *ptr; // [rsp+10h] [rbp-38h] BYREF
int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v2 = (unsigned int *)query_object(a1, a2, v10);
if ( v2 )
{
v3 = v2;
if ( *v2 )
{
for ( i = 0LL; v10[0] > (int)i; ++i )
{
asprintf(&ptr, "%s/%d/VideoClip", a2, v3[2 * i + 1]);
v5 = (int *)query_object((unsigned int)a1, ptr, v8);
v6 = *v5;
v7 = num_vids++;
vid_fsid[v7] = v6;
free(ptr);
free(v5);
}
free(v3);
}
}
}

original_code:
static void getvids(int fsid, const char *name)
{
 struct mfs_obj_attr *obj;
 int count, i;
 obj = query_object(fsid, name, &count);
 if (!obj || obj[0].fsid == 0) {
 }
 if (!obj || obj[0].fsid == 0) return;
 for (i=0;i<count;i++) {
  char *path;
  int count2;
  struct mfs_obj_attr *vobj;
  asprintf(&path, "%s/%d/VideoClip", name, obj[i].subobj);
  vobj = query_object(fsid, path, &count2);
  vid_fsid[num_vids++] = vobj->fsid;
  free(path);
  free(vobj);
 }
 free(obj);
}

canonical_original_code:
static void getvids(int fsid, char *name)
{
 struct mfs_obj_attr *obj;
 int count; int i;
 obj = query_object(fsid, name, &count);
 if (!obj || obj[0].fsid == 0) {
 }
 if (!obj || obj[0].fsid == 0) return;
 for (i=0;i<count;i++) {
  char *path;
  int count2;
  struct mfs_obj_attr *vobj;
  asprintf(&path, "%s/%d/VideoClip", name, obj[i].subobj);
  vobj = query_object(fsid, path, &count2);
  vid_fsid[num_vids++] = vobj->fsid;
  free(path);
  free(vobj);
 }
 free(obj);
}

variable_types:
name
char *

variable_types: struct mfs_obj_attr { unsigned int fsid; int subobj; } *

variable_types: count int

variable_types: i int

variable_types:
path
char *


decompiled_code:
int __fastcall dump_video(__int64 a1)
{
unsigned int v1; // ebp
const char *v2; // rax
const char *v3; // rax
__int64 v4; // rbp
unsigned __int64 v5; // rax
int result; // eax
const char *v7; // r12
int v8; // eax
int v9; // ebx

v1 = query_int(a1, "ServerVersion");
v2 = (const char *)query_string((unsigned int)a1, "ServerId");
printf("VideoClip/1/%s/%d {\n", v2, v1);
v3 = (const char *)query_string((unsigned int)a1, "Name");
printf("\tName: {%s}\n", v3);
v4 = (unsigned int)query_int((unsigned int)a1, "File");
v5 = mfs_fsid_size(v4);
printf("\tFile: File of size %d/131072\n", v5 >> 17);
result = puts("}\n");
if ( pull_files )
{
v7 = (const char *)query_string((unsigned int)a1, "Name");
v8 = open64(v7, 577, 420LL);
v9 = v8;
if ( v8 < 0 )
perror(v7);
else
export_file((unsigned int)v4, (unsigned int)v8, 0LL, 0LL, 0xFFFFFFFFLL, 256LL, 0LL);
result = close(v9);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int v1; // ebp
const char *v2; // rax
const char *v3; // rax
__int64 v4; // rbp
unsigned __int64 v5; // rax
int result; // eax
const char *v7; // r12
int v8; // eax
int v9; // ebx

v1 = query_int(a1, "ServerVersion");
v2 = (const char *)query_string((unsigned int)a1, "ServerId");
printf("VideoClip/1/%s/%d {\n", v2, v1);
v3 = (const char *)query_string((unsigned int)a1, "Name");
printf("\tName: {%s}\n", v3);
v4 = (unsigned int)query_int((unsigned int)a1, "File");
v5 = mfs_fsid_size(v4);
printf("\tFile: File of size %d/131072\n", v5 >> 17);
result = puts("}\n");
if ( pull_files )
{
v7 = (const char *)query_string((unsigned int)a1, "Name");
v8 = open64(v7, 577, 420LL);
v9 = v8;
if ( v8 < 0 )
perror(v7);
else
export_file((unsigned int)v4, (unsigned int)v8, 0LL, 0LL, 0xFFFFFFFFLL, 256LL, 0LL);
result = close(v9);
}
return result;
}

original_code:
static void dump_video(int fsid)
{
 int vid;
 printf("VideoClip/1/%s/%d {\n",
        query_string(fsid, "ServerId"),
        query_int(fsid, "ServerVersion"));
 printf("\tName: {%s}\n",
        query_string(fsid, "Name"));
 vid = query_int(fsid, "File");
 printf("\tFile: File of size %d/131072\n",
        (int)(mfs_fsid_size(vid)/131072));
 printf("}\n\n");
 if (pull_files) {
  int fd;
  char *dest = query_string(fsid, "Name");
  if ( (fd = open(dest, 01|0100|01000|0, 0644)) <0)
   perror(dest);
  else
   export_file(vid, fd , 0, 0, -1, 256, 0 );
  close(fd);
 }
}

variable_types: vid int

variable_types:
dest
char *


gethead

decompiled_code:
void __fastcall gethead(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbp
__int64 v4; // rbx
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = (unsigned int *)query_object(a1, a2, v5);
if ( v2 )
{
v3 = v2;
if ( *v2 )
{
printf("\t%s: ", a2);
if ( v5[0] > 0 )
{
v4 = 0LL;
do
printf("LoopSetClip/%d ", v3[2 * v4++ + 1]);
while ( v5[0] > (int)v4 );
}
putchar(10);
free(v3);
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbp
__int64 v4; // rbx
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = (unsigned int *)query_object(a1, a2, v5);
if ( v2 )
{
v3 = v2;
if ( *v2 )
{
printf("\t%s: ", a2);
if ( v5[0] > 0 )
{
v4 = 0LL;
do
printf("LoopSetClip/%d ", v3[2 * v4++ + 1]);
while ( v5[0] > (int)v4 );
}
putchar(10);
free(v3);
}
}
}

original_code:
static void gethead(int fsid, const char *name)
{
 struct mfs_obj_attr *obj;
 int count, i;
 obj = query_object(fsid, name, &count);
 if (!obj || obj[0].fsid == 0) return;
 printf("\t%s: ", name);
 for (i=0;i<count;i++) {
  printf("LoopSetClip/%d ", obj[i].subobj);
 }
 printf("\n");
 free(obj);
}

canonical_original_code:
static void gethead(int fsid, char *name)
{
 struct mfs_obj_attr *obj;
 int count; int i;
 obj = query_object(fsid, name, &count);
 if (!obj || obj[0].fsid == 0) return;
 printf("\t%s: ", name);
 for (i=0;i<count;i++) {
  printf("LoopSetClip/%d ", obj[i].subobj);
 }
 printf("\n");
 free(obj);
}

user_defined_types: struct mfs_obj_attr { unsigned int fsid; int subobj; }


getstate

decompiled_code:
void __fastcall getstate(__int64 a1, const char *a2)
{
unsigned int v2; // er13
unsigned int *v3; // rax
unsigned int *v4; // rbp
__int64 i; // rbx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int *v8; // r12
__int64 v9; // rdi
int v10; // eax
const char *v11; // rax
char v12[4]; // [rsp+Ch] [rbp-4Ch] BYREF
char *ptr; // [rsp+10h] [rbp-48h] BYREF
char *v14; // [rsp+18h] [rbp-40h] BYREF
char *v15; // [rsp+20h] [rbp-38h] BYREF
int v16[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

v2 = a1;
v3 = (unsigned int *)query_object(a1, a2, v16);
if ( v3 )
{
v4 = v3;
if ( *v3 )
{
for ( i = 0LL; v16[0] > (int)i; ++i )
{
asprintf(&ptr, "%s/%d/Entrance", a2, v4[2 * i + 1]);
asprintf(&v14, "%s/%d/Exit", a2, v4[2 * i + 1]);
asprintf(&v15, "%s/%d/VideoClip", a2, v4[2 * i + 1]);
printf("\tSubrecord LoopSetClip/%d {\n", v4[2 * i + 1]);
v6 = query_int(v2, ptr);
printf("\t\tEntrance: %d\n", v6);
v7 = query_int(v2, v14);
printf("\t\tExit: %d\n", v7);
v8 = (unsigned int *)query_object(v2, v15, v12);
v9 = *v8;
v10 = num_vids++;
vid_fsid[v10] = v9;
v11 = (const char *)query_string(v9, "ServerId");
printf("\t\tVideoClip: VideoClip/1/%s\n", v11);
puts("\t}");
free(ptr);
free(v14);
free(v15);
free(v8);
}
putchar(10);
free(v4);
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v2; // er13
unsigned int *v3; // rax
unsigned int *v4; // rbp
__int64 i; // rbx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int *v8; // r12
__int64 v9; // rdi
int v10; // eax
const char *v11; // rax
char v12[4]; // [rsp+Ch] [rbp-4Ch] BYREF
char *ptr; // [rsp+10h] [rbp-48h] BYREF
char *v14; // [rsp+18h] [rbp-40h] BYREF
char *v15; // [rsp+20h] [rbp-38h] BYREF
int v16[11]; // [rsp+2Ch] [rbp-2Ch] BYREF

v2 = a1;
v3 = (unsigned int *)query_object(a1, a2, v16);
if ( v3 )
{
v4 = v3;
if ( *v3 )
{
for ( i = 0LL; v16[0] > (int)i; ++i )
{
asprintf(&ptr, "%s/%d/Entrance", a2, v4[2 * i + 1]);
asprintf(&v14, "%s/%d/Exit", a2, v4[2 * i + 1]);
asprintf(&v15, "%s/%d/VideoClip", a2, v4[2 * i + 1]);
printf("\tSubrecord LoopSetClip/%d {\n", v4[2 * i + 1]);
v6 = query_int(v2, ptr);
printf("\t\tEntrance: %d\n", v6);
v7 = query_int(v2, v14);
printf("\t\tExit: %d\n", v7);
v8 = (unsigned int *)query_object(v2, v15, v12);
v9 = *v8;
v10 = num_vids++;
vid_fsid[v10] = v9;
v11 = (const char *)query_string(v9, "ServerId");
printf("\t\tVideoClip: VideoClip/1/%s\n", v11);
puts("\t}");
free(ptr);
free(v14);
free(v15);
free(v8);
}
putchar(10);
free(v4);
}
}
}

original_code:
static void getstate(int fsid, const char *name)
{
 struct mfs_obj_attr *obj;
 int count, i;
 obj = query_object(fsid, name, &count);
 if (!obj || obj[0].fsid == 0) return;
 for (i=0;i<count;i++) {
  char *path1, *path2, *path3;
  int vid, count2;
  struct mfs_obj_attr *vobj;
  asprintf(&path1, "%s/%d/Entrance", name, obj[i].subobj);
  asprintf(&path2, "%s/%d/Exit", name, obj[i].subobj);
  asprintf(&path3, "%s/%d/VideoClip", name, obj[i].subobj);
  printf("\tSubrecord LoopSetClip/%d {\n",
         obj[i].subobj);
  printf("\t\tEntrance: %d\n", query_int(fsid, path1));
  printf("\t\tExit: %d\n", query_int(fsid, path2));
  vobj = query_object(fsid, path3, &count2);
  vid = vobj->fsid;
  vid_fsid[num_vids++] = vid;
  printf("\t\tVideoClip: VideoClip/1/%s\n",
         query_string(vid, "ServerId"));
  printf("\t}\n");
  free(path1);
  free(path2);
  free(path3);
  free(vobj);
 }
 printf("\n");
 free(obj);
}

canonical_original_code:
static void getstate(int fsid, char *name)
{
 struct mfs_obj_attr *obj;
 int count; int i;
 obj = query_object(fsid, name, &count);
 if (!obj || obj[0].fsid == 0) return;
 for (i=0;i<count;i++) {
  char *path1; char *path2; char *path3;
  int vid; int count2;
  struct mfs_obj_attr *vobj;
  asprintf(&path1, "%s/%d/Entrance", name, obj[i].subobj);
  asprintf(&path2, "%s/%d/Exit", name, obj[i].subobj);
  asprintf(&path3, "%s/%d/VideoClip", name, obj[i].subobj);
  printf("\tSubrecord LoopSetClip/%d {\n",
         obj[i].subobj);
  printf("\t\tEntrance: %d\n", query_int(fsid, path1));
  printf("\t\tExit: %d\n", query_int(fsid, path2));
  vobj = query_object(fsid, path3, &count2);
  vid = vobj->fsid;
  vid_fsid[num_vids++] = vid;
  printf("\t\tVideoClip: VideoClip/1/%s\n",
         query_string(vid, "ServerId"));
  printf("\t}\n");
  free(path1);
  free(path2);
  free(path3);
  free(vobj);
 }
 printf("\n");
 free(obj);
}


getslice

decompiled_code:
int __fastcall getslice(unsigned int a1)
{
__int64 v1; // rbx
unsigned int v2; // ebx
const char *v3; // rax
const char *v4; // rax

if ( (unsigned int)mfs_fsid_type() != 8 )
{
fprintf(stderr, "%d is not an object\n", a1);
exit(1);
}
puts("Guide type=3\n");
getvids(a1, "State");
getvids(a1, "Trans");
if ( num_vids > 0 )
{
v1 = 0LL;
do
{
if ( !(_DWORD)v1 || vid_fsid[v1] != *(_DWORD *)(4 * v1 + 0x57C) )
dump_video((unsigned int)vid_fsid[v1]);
++v1;
}
while ( num_vids > (int)v1 );
}
v2 = query_int(a1, "ServerVersion");
v3 = (const char *)query_string(a1, "ServerId");
printf("LoopSet/1/%s/%d {\n", v3, v2);
v4 = (const char *)query_string(a1, "Name");
printf("\tName: {%s}\n", v4);
gethead(a1, "State");
gethead(a1, "Trans");
getstate(a1, "State");
getstate(a1, "Trans");
return puts("}\n");
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
__int64 v1; // rbx
unsigned int v2; // ebx
const char *v3; // rax
const char *v4; // rax

if ( (unsigned int)mfs_fsid_type() != 8 )
{
fprintf(stderr, "%d is not an object\n", a1);
exit(1);
}
puts("Guide type=3\n");
func1(a1, "State");
func1(a1, "Trans");
if ( num_vids > 0 )
{
v1 = 0LL;
do
{
if ( !(_DWORD)v1 || vid_fsid[v1] != *(_DWORD *)(4 * v1 + 0x57C) )
func2((unsigned int)vid_fsid[v1]);
++v1;
}
while ( num_vids > (int)v1 );
}
v2 = query_int(a1, "ServerVersion");
v3 = (const char *)query_string(a1, "ServerId");
printf("LoopSet/1/%s/%d {\n", v3, v2);
v4 = (const char *)query_string(a1, "Name");
printf("\tName: {%s}\n", v4);
func3(a1, "State");
func3(a1, "Trans");
func4(a1, "State");
func4(a1, "Trans");
return puts("}\n");
}

original_code:
static void getslice(int fsid)
{
 int i;
 if (mfs_fsid_type(fsid) != 8) {
  fprintf(stderr,"%d is not an object\n", fsid);
  exit(1);
 }
 printf("Guide type=3\n\n");
 getvids(fsid, "State");
 getvids(fsid, "Trans");
 for (i=0;i<num_vids;i++) {
  if (i==0 || vid_fsid[i] != vid_fsid[i-1]) {
   dump_video(vid_fsid[i]);
  }
 }
 printf("LoopSet/1/%s/%d {\n",
        query_string(fsid, "ServerId"),
        query_int(fsid, "ServerVersion"));
 printf("\tName: {%s}\n", query_string(fsid, "Name"));
 gethead(fsid, "State");
 gethead(fsid, "Trans");
 getstate(fsid, "State");
 getstate(fsid, "Trans");
 printf("}\n\n");
}


usage

decompiled_code:
void __noreturn usage()
{
puts("\nusage: mfs_getslice [options] <path|fsid>");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("\nusage: mfs_getslice [options] <path|fsid>");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\n"
"usage: mfs_getslice [options] <path|fsid>\n"
);
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\n"
"usage: mfs_getslice [options] <path|fsid>\n"
);
 credits();
 exit(1);
}


main

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

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "f");
if ( v3 == -1 )
break;
if ( v3 != 102 )
usage();
pull_files = 1;
}
v4 = &argv[optind];
if ( argc - optind <= 0 )
usage();
mfs_init();
v5 = mfs_resolve(*v4);
getslice(v5);
return 0;
}

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

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "f");
if ( v3 == -1 )
break;
if ( v3 != 102 )
func0();
pull_files = 1;
}
v4 = &argv[optind];
if ( argc - optind <= 0 )
func0();
mfs_init();
v5 = mfs_resolve(*v4);
func5(v5);
return 0;
}

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


decompiled_code:
__int64 __fastcall mfsd_main(int argc, char **argv)
{
unsigned int v3; // er14
signed int v4; // er13
unsigned int v5; // er12
int v6; // eax
unsigned int v7; // ebp
bool v9; // r15
char *v10; // rsi
uint16_t *v11; // rbx
__int64 v12; // rax
unsigned int v13; // er14
__int64 v14; // rbx
int v15; // er13
unsigned int v16; // esi
uint32_t v17; // er12
uint32_t v18; // eax
uint32_t v19; // eax
unsigned __int8 v20; // al
uint32_t v21; // er12
uint32_t v22; // eax
uint32_t v23; // eax
uint32_t v24; // eax
uint32_t v25; // er12
unsigned int v26; // eax
uint32_t v27; // eax
__int64 i; // r12
uint32_t v29; // er13
uint32_t v30; // eax
signed int v31; // er12
__int64 v32; // r12
uint32_t v33; // er13
uint32_t v34; // eax
__int64 v35; // r12
uint32_t v36; // er13
uint32_t v37; // eax
int v38; // [rsp+0h] [rbp-48h]
unsigned int nmemb; // [rsp+4h] [rbp-44h]
uint16_t *nmemb_4; // [rsp+8h] [rbp-40h]

progname = (__int64)*argv;
v38 = 0;
v3 = -559038737;
v4 = 0;
nmemb = 1;
v5 = -559038737;
while ( 1 )
{
v6 = getopt(argc, argv, "bhc:s:i:f:");
if ( v6 < 0 )
break;
switch ( v6 )
{
case 'b':
v38 = 2;
continue;
case 'c':
nmemb = strtoul(optarg, 0LL, 0);
continue;
case 'f':
if ( v3 != -559038737 )
{
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
usage();
return 1;
}
v4 = strtoul(optarg, 0LL, 0);
break;
case 'h':
v38 = 1;
continue;
case 'i':
if ( v4 )
{
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
usage();
return 2;
}
v3 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v5 = strtoul(optarg, 0LL, 0);
continue;
default:
usage();
return 3;
}
}
v9 = v3 == -559038737 && v4 == 0 && v5 == -559038737;
if ( v9 || optind == argc || optind > argc + 1 )
{
usage();
return 4;
}
v10 = 0LL;
if ( optind + 1 < argc )
v10 = argv[optind + 1];
mfs = mfs_init(argv[optind], v10, 0LL);
v7 = mfs_has_error(mfs);
if ( v7 )
{
mfs_perror(mfs, *argv);
return 1;
}
if ( v4 )
{
v12 = mfs_read_inode_by_fsid(mfs, (unsigned int)v4);
v11 = (uint16_t *)v12;
if ( !v12 )
{
mfs_perror(mfs, "Read fsid");
return 1;
}
}
else
{
v11 = 0LL;
if ( v3 == -559038737 )
goto LABEL_24;
v12 = mfs_read_inode(mfs, v3);
v11 = (uint16_t *)v12;
if ( !v12 )
{
mfs_perror(mfs, "Read inode");
return 1;
}
}
v4 = 8 * htonl(*(_DWORD *)(v12 + 56)) + 60;
LABEL_24:
if ( v5 == -559038737 )
{
if ( v38 != 2 )
{
if ( v38 == 1 || !v11 )
{
if ( !v4 )
return v7;
nmemb_4 = v11;
goto LABEL_42;
}
v17 = htonl(*(_DWORD *)v11);
v18 = htonl(*((_DWORD *)v11 + 4));
printf("Inode: %-13dFSid: %d\n", v18, v17);
v19 = htonl(*((_DWORD *)v11 + 1));
printf("Refcount: %-10dType: ", v19);
v20 = *((_BYTE *)v11 + 40);
if ( v20 == 4 )
{
puts("tyDir");
goto LABEL_61;
}
if ( v20 > 4u )
{
if ( v20 == 8 )
{
puts("tyDb");
goto LABEL_61;
}
}
else
{
if ( v20 == 1 )
{
puts("tyFile");
goto LABEL_61;
}
if ( v20 == 2 )
{
puts("tyStream");
LABEL_61:
v21 = htonl(*((_DWORD *)v11 + 3));
v22 = htonl(*((_DWORD *)v11 + 2));
printf("???: %-15d???: %d\n", v22, v21);
if ( *((_BYTE *)v11 + 40) == 2 )
{
v31 = htonl(*((_DWORD *)v11 + 5));
v32 = (int)htonl(*((_DWORD *)v11 + 6)) * (__int64)v31;
v33 = htonl(*((_DWORD *)v11 + 5));
v34 = htonl(*((_DWORD *)v11 + 6));
printf("Size: %d blocks of %d bytes (%llu)\n", v34, v33, v32);
LODWORD(v32) = htonl(*((_DWORD *)v11 + 8));
v35 = (int)htonl(*((_DWORD *)v11 + 7)) * (__int64)(int)v32;
v36 = htonl(*((_DWORD *)v11 + 7));
v37 = htonl(*((_DWORD *)v11 + 8));
printf("Used: %d blocks of %d bytes (%llu)\n", v37, v36, v35);
}
else
{
v23 = htonl(*((_DWORD *)v11 + 6));
printf("Size: %d bytes\n", v23);
}
v24 = htonl(*((_DWORD *)v11 + 13));
printf("Checksum: %08x Flags(?): %d\n", *((unsigned int *)v11 + 12), v24);
v25 = htonl(*((_DWORD *)v11 + 11));
LOWORD(v26) = htons(v11[21]);
printf("Sigs: %02x %04x %08x (Always 02 beef 91231ebc?)\n", *((unsigned __int8 *)v11 + 41), v26, v25);
if ( htonl(*((_DWORD *)v11 + 14)) )
{
v27 = htonl(*((_DWORD *)v11 + 14));
printf("Data is in %d blocks:\n", v27);
for ( i = 0LL; (int)htonl(*((_DWORD *)v11 + 14)) > (int)i; ++i )
{
v29 = htonl(*(_DWORD *)&v11[4 * i + 32]);
v30 = htonl(*(_DWORD *)&v11[4 * i + 30]);
printf("At %-8x %d sectors\n", v30, v29);
}
}
else
{
puts("Data is in inode block.");
v7 = 0;
}
return v7;
}
}
printf("???");
goto LABEL_61;
}
LABEL_52:
write(1, v11, (unsigned int)v4);
return v7;
}
nmemb_4 = (uint16_t *)calloc(nmemb, 0x200uLL);
if ( !nmemb_4 )
{
fprintf(stderr, "%s: Couldn't allocate %d bytes!\n", (const char *)progname, nmemb << 9);
return 1;
}
if ( v11 )
{
v4 = mfs_read_inode_data_part(mfs, v11, nmemb_4, v5, nmemb);
if ( v4 > 0 )
goto LABEL_40;
LABEL_50:
mfs_perror(mfs, "Read data");
return 1;
}
v4 = mfsvol_read_data(*(_QWORD *)mfs, nmemb_4, v5, nmemb);
if ( v4 <= 0 )
goto LABEL_50;
LABEL_40:
if ( v38 == 2 )
{
v11 = nmemb_4;
goto LABEL_52;
}
v9 = 1;
LABEL_42:
v13 = v5 + ((unsigned int)(v4 - 1) >> 9) + 1;
v14 = (__int64)nmemb_4;
v15 = (_DWORD)nmemb_4 + v4;
do
{
v16 = -559038737;
if ( v9 )
v16 = v5;
hexdump(v14, v16, v15 - v14);
++v5;
v14 += 512LL;
}
while ( v5 != v13 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
unsigned int v3; // er14
signed int v4; // er13
unsigned int v5; // er12
int v6; // eax
unsigned int v7; // ebp
bool v9; // r15
char *v10; // rsi
uint16_t *v11; // rbx
__int64 v12; // rax
unsigned int v13; // er14
__int64 v14; // rbx
int v15; // er13
unsigned int v16; // esi
uint32_t v17; // er12
uint32_t v18; // eax
uint32_t v19; // eax
unsigned __int8 v20; // al
uint32_t v21; // er12
uint32_t v22; // eax
uint32_t v23; // eax
uint32_t v24; // eax
uint32_t v25; // er12
unsigned int v26; // eax
uint32_t v27; // eax
__int64 i; // r12
uint32_t v29; // er13
uint32_t v30; // eax
signed int v31; // er12
__int64 v32; // r12
uint32_t v33; // er13
uint32_t v34; // eax
__int64 v35; // r12
uint32_t v36; // er13
uint32_t v37; // eax
int v38; // [rsp+0h] [rbp-48h]
unsigned int nmemb; // [rsp+4h] [rbp-44h]
uint16_t *nmemb_4; // [rsp+8h] [rbp-40h]

progname = (__int64)*argv;
v38 = 0;
v3 = -559038737;
v4 = 0;
nmemb = 1;
v5 = -559038737;
while ( 1 )
{
v6 = getopt(argc, argv, "bhc:s:i:f:");
if ( v6 < 0 )
break;
switch ( v6 )
{
case 'b':
v38 = 2;
continue;
case 'c':
nmemb = strtoul(optarg, 0LL, 0);
continue;
case 'f':
if ( v3 != -559038737 )
{
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
func0();
return 1;
}
v4 = strtoul(optarg, 0LL, 0);
break;
case 'h':
v38 = 1;
continue;
case 'i':
if ( v4 )
{
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
func0();
return 2;
}
v3 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v5 = strtoul(optarg, 0LL, 0);
continue;
default:
func0();
return 3;
}
}
v9 = v3 == -559038737 && v4 == 0 && v5 == -559038737;
if ( v9 || optind == argc || optind > argc + 1 )
{
func0();
return 4;
}
v10 = 0LL;
if ( optind + 1 < argc )
v10 = argv[optind + 1];
mfs = mfs_init(argv[optind], v10, 0LL);
v7 = mfs_has_error(mfs);
if ( v7 )
{
mfs_perror(mfs, *argv);
return 1;
}
if ( v4 )
{
v12 = mfs_read_inode_by_fsid(mfs, (unsigned int)v4);
v11 = (uint16_t *)v12;
if ( !v12 )
{
mfs_perror(mfs, "Read fsid");
return 1;
}
}
else
{
v11 = 0LL;
if ( v3 == -559038737 )
goto LABEL_24;
v12 = mfs_read_inode(mfs, v3);
v11 = (uint16_t *)v12;
if ( !v12 )
{
mfs_perror(mfs, "Read inode");
return 1;
}
}
v4 = 8 * htonl(*(_DWORD *)(v12 + 56)) + 60;
LABEL_24:
if ( v5 == -559038737 )
{
if ( v38 != 2 )
{
if ( v38 == 1 || !v11 )
{
if ( !v4 )
return v7;
nmemb_4 = v11;
goto LABEL_42;
}
v17 = htonl(*(_DWORD *)v11);
v18 = htonl(*((_DWORD *)v11 + 4));
printf("Inode: %-13dFSid: %d\n", v18, v17);
v19 = htonl(*((_DWORD *)v11 + 1));
printf("Refcount: %-10dType: ", v19);
v20 = *((_BYTE *)v11 + 40);
if ( v20 == 4 )
{
puts("tyDir");
goto LABEL_61;
}
if ( v20 > 4u )
{
if ( v20 == 8 )
{
puts("tyDb");
goto LABEL_61;
}
}
else
{
if ( v20 == 1 )
{
puts("tyFile");
goto LABEL_61;
}
if ( v20 == 2 )
{
puts("tyStream");
LABEL_61:
v21 = htonl(*((_DWORD *)v11 + 3));
v22 = htonl(*((_DWORD *)v11 + 2));
printf("???: %-15d???: %d\n", v22, v21);
if ( *((_BYTE *)v11 + 40) == 2 )
{
v31 = htonl(*((_DWORD *)v11 + 5));
v32 = (int)htonl(*((_DWORD *)v11 + 6)) * (__int64)v31;
v33 = htonl(*((_DWORD *)v11 + 5));
v34 = htonl(*((_DWORD *)v11 + 6));
printf("Size: %d blocks of %d bytes (%llu)\n", v34, v33, v32);
LODWORD(v32) = htonl(*((_DWORD *)v11 + 8));
v35 = (int)htonl(*((_DWORD *)v11 + 7)) * (__int64)(int)v32;
v36 = htonl(*((_DWORD *)v11 + 7));
v37 = htonl(*((_DWORD *)v11 + 8));
printf("Used: %d blocks of %d bytes (%llu)\n", v37, v36, v35);
}
else
{
v23 = htonl(*((_DWORD *)v11 + 6));
printf("Size: %d bytes\n", v23);
}
v24 = htonl(*((_DWORD *)v11 + 13));
printf("Checksum: %08x Flags(?): %d\n", *((unsigned int *)v11 + 12), v24);
v25 = htonl(*((_DWORD *)v11 + 11));
LOWORD(v26) = htons(v11[21]);
printf("Sigs: %02x %04x %08x (Always 02 beef 91231ebc?)\n", *((unsigned __int8 *)v11 + 41), v26, v25);
if ( htonl(*((_DWORD *)v11 + 14)) )
{
v27 = htonl(*((_DWORD *)v11 + 14));
printf("Data is in %d blocks:\n", v27);
for ( i = 0LL; (int)htonl(*((_DWORD *)v11 + 14)) > (int)i; ++i )
{
v29 = htonl(*(_DWORD *)&v11[4 * i + 32]);
v30 = htonl(*(_DWORD *)&v11[4 * i + 30]);
printf("At %-8x %d sectors\n", v30, v29);
}
}
else
{
puts("Data is in inode block.");
v7 = 0;
}
return v7;
}
}
printf("???");
goto LABEL_61;
}
LABEL_52:
write(1, v11, (unsigned int)v4);
return v7;
}
nmemb_4 = (uint16_t *)calloc(nmemb, 0x200uLL);
if ( !nmemb_4 )
{
fprintf(stderr, "%s: Couldn't allocate %d bytes!\n", (const char *)progname, nmemb << 9);
return 1;
}
if ( v11 )
{
v4 = mfs_read_inode_data_part(mfs, v11, nmemb_4, v5, nmemb);
if ( v4 > 0 )
goto LABEL_40;
LABEL_50:
mfs_perror(mfs, "Read data");
return 1;
}
v4 = mfsvol_read_data(*(_QWORD *)mfs, nmemb_4, v5, nmemb);
if ( v4 <= 0 )
goto LABEL_50;
LABEL_40:
if ( v38 == 2 )
{
v11 = nmemb_4;
goto LABEL_52;
}
v9 = 1;
LABEL_42:
v13 = v5 + ((unsigned int)(v4 - 1) >> 9) + 1;
v14 = (__int64)nmemb_4;
v15 = (_DWORD)nmemb_4 + v4;
do
{
v16 = -559038737;
if ( v9 )
v16 = v5;
func1(v14, v16, v15 - v14);
++v5;
v14 += 512LL;
}
while ( v5 != v13 );
return v7;
}

original_code:
int
mfsd_main (int argc, char **argv)
{
 int curarg;
 unsigned char *buf = ((void *)0);
 unsigned int sector = 0xdeadbeef, count = 1;
 unsigned int fsid = 0;
 unsigned int inode = 0xdeadbeef;
 unsigned int bufsize = 0;
 mfs_inode *inode_buf = ((void *)0);
 enum
 { None, Hex, Bin }
 format = None;
 progname = argv[0];
 while ((curarg = getopt (argc, argv, "bhc:s:i:f:")) >= 0)
 {
  switch (curarg)
  {
  case 'b':
   format = Bin;
   break;
  case 'h':
   format = Hex;
   break;
  case 's':
   sector = strtoul (optarg, 0, 0);
   break;
  case 'c':
   count = strtoul (optarg, 0, 0);
   break;
  case 'f':
   if (inode != 0xdeadbeef)
   {
    fprintf (stderr, "Only 1 of -f and -i may be used.\n");
    usage ();
    return 1;
   }
   fsid = strtoul (optarg, 0, 0);
   break;
  case 'i':
   if (fsid)
   {
    fprintf (stderr, "Only 1 of -f and -i may be used.\n");
    usage ();
    return 2;
   }
   inode = strtoul (optarg, 0, 0);
   break;
  default:
   usage ();
   return 3;
  }
 }
 if (sector == 0xdeadbeef && !fsid && inode == 0xdeadbeef || optind == argc || optind >= argc + 2)
 {
  usage ();
  return 4;
 }
 mfs = mfs_init (argv[optind], optind + 1 < argc? argv[optind + 1] : ((void *)0), 00);
 if (mfs_has_error (mfs))
 {
  mfs_perror (mfs, argv[0]);
  return 1;
 }
 if (fsid)
 {
  inode_buf = mfs_read_inode_by_fsid (mfs, fsid);
  if (!inode_buf)
  {
   mfs_perror (mfs, "Read fsid");
   return 1;
  }
  bufsize = sizeof (*inode_buf) + htonl (inode_buf->numblocks) * 8;
  buf = (unsigned char *) inode_buf;
 }
 else if (inode != 0xdeadbeef)
 {
  inode_buf = mfs_read_inode (mfs, inode);
  if (!inode_buf)
  {
   mfs_perror (mfs, "Read inode");
   return 1;
  }
  bufsize = sizeof (*inode_buf) + htonl (inode_buf->numblocks) * 8;
  buf = (unsigned char *) inode_buf;
 }
 if (sector != 0xdeadbeef)
 {
  buf = calloc (count, 512);
  if (!buf)
  {
   fprintf (stderr, "%s: Couldn't allocate %d bytes!\n", progname, count * 512);
   return 1;
  }
  if (inode_buf)
  {
   int nread = mfs_read_inode_data_part (mfs, inode_buf, buf, sector, count);
   if (nread <= 0)
   {
    mfs_perror (mfs, "Read data");
    return 1;
   }
   bufsize = nread;
  }
  else
  {
   int nread = mfsvol_read_data ((mfs)->vols, buf, sector, count);
   if (nread <= 0)
   {
    mfs_perror (mfs, "Read data");
    return 1;
   }
   bufsize = nread;
  }
 }
 if (format == Bin)
 {
  write (1, buf, bufsize);
 }
 else if (format == Hex || !inode_buf || sector != 0xdeadbeef)
 {
  int offset = 0;
  while (offset * 512 < bufsize)
  {
   hexdump (buf + offset * 512, sector == 0xdeadbeef ? sector : offset + sector, bufsize - offset * 512);
   offset++;
  }
 }
 else
 {
  printf ("Inode: %-13dFSid: %d\n", htonl (inode_buf->inode), htonl (inode_buf->fsid));
  printf ("Refcount: %-10dType: ", htonl (inode_buf->refcount));
  switch (inode_buf->type)
  {
  case tyDir:
   printf ("tyDir\n");
   break;
  case tyDb:
   printf ("tyDb\n");
   break;
  case tyStream:
   printf ("tyStream\n");
   break;
  case tyFile:
   printf ("tyFile\n");
   break;
  default:
   printf ("???");
  }
  printf ("???: %-15d???: %d\n", htonl (inode_buf->unk1), htonl (inode_buf->unk2));
  if (inode_buf->type == tyStream)
  {
   printf ("Size: %d blocks of %d bytes (%llu)\n", htonl (inode_buf->size), htonl (inode_buf->unk3), (unsigned long long) htonl (inode_buf->unk3) * (unsigned long long) htonl (inode_buf->size));
   printf ("Used: %d blocks of %d bytes (%llu)\n", htonl (inode_buf->blockused), htonl (inode_buf->blocksize), (unsigned long long) htonl (inode_buf->blockused) * (unsigned long long) htonl (inode_buf->blocksize));
  }
  else
  {
   printf ("Size: %d bytes\n", htonl (inode_buf->size));
  }
  printf ("Checksum: %08x  Flags(?): %d\n", inode_buf->checksum, htonl (inode_buf->inode_flags));
  printf ("Sigs: %02x %04x %08x (Always 02 beef 91231ebc?)\n", inode_buf->unk6, htons (inode_buf->beef), htonl (inode_buf->sig));
  if (htonl (inode_buf->numblocks))
  {
   int loop;
   printf ("Data is in %d blocks:\n", htonl (inode_buf->numblocks));
   for (loop = 0; loop < htonl (inode_buf->numblocks); loop++)
   {
    printf ("At %-8x %d sectors\n", htonl (inode_buf->datablocks[loop].sector), htonl (inode_buf->datablocks[loop].count));
   }
  }
  else
  {
   printf ("Data is in inode block.\n");
  }
 }
 return 0;
}

canonical_original_code:
int mfsd_main(int argc, char **argv)
{
 int curarg;
 unsigned char *buf = ((void *)0);
 unsigned int sector = 0xdeadbeef; unsigned int count = 1;
 unsigned int fsid = 0;
 unsigned int inode = 0xdeadbeef;
 unsigned int bufsize = 0;
 struct mfs_inode_s *inode_buf = ((void *)0);
 enum { None=0, Hex=1, Bin=2 } format = None;
 progname = argv[0];
 while ((curarg = getopt (argc, argv, "bhc:s:i:f:")) >= 0)
 {
  switch (curarg)
  {
  case 'b':
   format = Bin;
   break;
  case 'h':
   format = Hex;
   break;
  case 's':
   sector = strtoul (optarg, 0, 0);
   break;
  case 'c':
   count = strtoul (optarg, 0, 0);
   break;
  case 'f':
   if (inode != 0xdeadbeef)
   {
    fprintf (stderr, "Only 1 of -f and -i may be used.\n");
    usage ();
    return 1;
   }
   fsid = strtoul (optarg, 0, 0);
   break;
  case 'i':
   if (fsid)
   {
    fprintf (stderr, "Only 1 of -f and -i may be used.\n");
    usage ();
    return 2;
   }
   inode = strtoul (optarg, 0, 0);
   break;
  default:
   usage ();
   return 3;
  }
 }
 if (sector == 0xdeadbeef && !fsid && inode == 0xdeadbeef || optind == argc || optind >= argc + 2)
 {
  usage ();
  return 4;
 }
 mfs = mfs_init (argv[optind], optind + 1 < argc? argv[optind + 1] : ((void *)0), 00);
 if (mfs_has_error (mfs))
 {
  mfs_perror (mfs, argv[0]);
  return 1;
 }
 if (fsid)
 {
  inode_buf = mfs_read_inode_by_fsid (mfs, fsid);
  if (!inode_buf)
  {
   mfs_perror (mfs, "Read fsid");
   return 1;
  }
  bufsize = sizeof (*inode_buf) + htonl (inode_buf->numblocks) * 8;
  buf = (unsigned char *) inode_buf;
 }
 else if (inode != 0xdeadbeef)
 {
  inode_buf = mfs_read_inode (mfs, inode);
  if (!inode_buf)
  {
   mfs_perror (mfs, "Read inode");
   return 1;
  }
  bufsize = sizeof (*inode_buf) + htonl (inode_buf->numblocks) * 8;
  buf = (unsigned char *) inode_buf;
 }
 if (sector != 0xdeadbeef)
 {
  buf = calloc (count, 512);
  if (!buf)
  {
   fprintf (stderr, "%s: Couldn't allocate %d bytes!\n", progname, count * 512);
   return 1;
  }
  if (inode_buf)
  {
   int nread = mfs_read_inode_data_part (mfs, inode_buf, buf, sector, count);
   if (nread <= 0)
   {
    mfs_perror (mfs, "Read data");
    return 1;
   }
   bufsize = nread;
  }
  else
  {
   int nread = mfsvol_read_data ((mfs)->vols, buf, sector, count);
   if (nread <= 0)
   {
    mfs_perror (mfs, "Read data");
    return 1;
   }
   bufsize = nread;
  }
 }
 if (format == Bin)
 {
  write (1, buf, bufsize);
 }
 else if (format == Hex || !inode_buf || sector != 0xdeadbeef)
 {
  int offset = 0;
  while (offset * 512 < bufsize)
  {
   hexdump (buf + offset * 512, sector == 0xdeadbeef ? sector : offset + sector, bufsize - offset * 512);
   offset++;
  }
 }
 else
 {
  printf ("Inode: %-13dFSid: %d\n", htonl (inode_buf->inode), htonl (inode_buf->fsid));
  printf ("Refcount: %-10dType: ", htonl (inode_buf->refcount));
  switch (inode_buf->type)
  {
  case tyDir:
   printf ("tyDir\n");
   break;
  case tyDb:
   printf ("tyDb\n");
   break;
  case tyStream:
   printf ("tyStream\n");
   break;
  case tyFile:
   printf ("tyFile\n");
   break;
  default:
   printf ("???");
  }
  printf ("???: %-15d???: %d\n", htonl (inode_buf->unk1), htonl (inode_buf->unk2));
  if (inode_buf->type == tyStream)
  {
   printf ("Size: %d blocks of %d bytes (%llu)\n", htonl (inode_buf->size), htonl (inode_buf->unk3), (unsigned long long) htonl (inode_buf->unk3) * (unsigned long long) htonl (inode_buf->size));
   printf ("Used: %d blocks of %d bytes (%llu)\n", htonl (inode_buf->blockused), htonl (inode_buf->blocksize), (unsigned long long) htonl (inode_buf->blockused) * (unsigned long long) htonl (inode_buf->blocksize));
  }
  else
  {
   printf ("Size: %d bytes\n", htonl (inode_buf->size));
  }
  printf ("Checksum: %08x  Flags(?): %d\n", inode_buf->checksum, htonl (inode_buf->inode_flags));
  printf ("Sigs: %02x %04x %08x (Always 02 beef 91231ebc?)\n", inode_buf->unk6, htons (inode_buf->beef), htonl (inode_buf->sig));
  if (htonl (inode_buf->numblocks))
  {
   int loop;
   printf ("Data is in %d blocks:\n", htonl (inode_buf->numblocks));
   for (loop = 0; loop < htonl (inode_buf->numblocks); loop++)
   {
    printf ("At %-8x %d sectors\n", htonl (inode_buf->datablocks[loop].sector), htonl (inode_buf->datablocks[loop].count));
   }
  }
  else
  {
   printf ("Data is in inode block.\n");
  }
 }
 return 0;
}

variable_types:
argv
char **

variable_types: curarg int

variable_types:
buf
unsigned char *

variable_types:
sector
unsigned int

variable_types:
fsid
unsigned int

variable_types:
inode
unsigned int

variable_types:
bufsize
unsigned int

variable_types: struct mfs_inode_s { unsigned int fsid; unsigned int refcount; unsigned int unk1; unsigned int unk2; unsigned int inode; unsigned int unk3; unsigned int size; unsigned int blocksize; unsigned int blockused; unsigned int lastmodified; enum fsid_type_e { tyNone=0, tyFile=1, tyStream=2, tyDir=4, tyDb=8 } type; unsigned char unk6; unsigned short beef; unsigned int sig; unsigned int checksum; unsigned int inode_flags; unsigned int numblocks; struct { unsigned int sector; unsigned int count; } datablocks[]; } *

variable_types:
format
enum { None=0, Hex=1, Bin=2 }

variable_types: nread int

variable_types: offset int

variable_types: loop int

user_defined_types: struct mfs_inode_s { unsigned int fsid; unsigned int refcount; unsigned int unk1; unsigned int unk2; unsigned int inode; unsigned int unk3; unsigned int size; unsigned int blocksize; unsigned int blockused; unsigned int lastmodified; enum fsid_type_e type; unsigned char unk6; unsigned short beef; unsigned int sig; unsigned int checksum; unsigned int inode_flags; unsigned int numblocks; struct { unsigned int sector; unsigned int count; } datablocks[]; }


usage

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

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

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

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


hexdump

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

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

variable_types:
size
unsigned int

variable_types: ofs int

variable_types:
line
unsigned char [20]

variable_types: myo int


verbose

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

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

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

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

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

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

variable_types:
fmt
char *


usage

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

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

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

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