decompiled_code:
__int64 __fastcall auto_crc(__int64 a1, int a2, unsigned int *a3)
{
unsigned int v4; // ebp
int v5; // eax
char *v6; // r9
_DWORD *v7; // rdx
unsigned int v8; // er12
signed int v9; // er8
__int64 result; // rax

v4 = _bswap_32(*a3);
v5 = _bswap_32(0xDEADF00D);
*v7 = v5;
if ( a2 <= 3 )
goto LABEL_10;
v8 = 4;
while ( v4 != (unsigned int)crc32(v6, v8) )
{
if ( v9 < (int)++v8 )
goto LABEL_10;
}
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
}
else
{
fprintf(stderr, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
}
LABEL_10:
result = _bswap_32(v4);
*a3 = result;
return result;
}
fprintf(stderr, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
result = _bswap_32(v4);
*a3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, unsigned int *a3)
{
unsigned int v4; // ebp
int v5; // eax
char *v6; // r9
_DWORD *v7; // rdx
unsigned int v8; // er12
signed int v9; // er8
__int64 result; // rax

v4 = func0(*a3);
v5 = func0(0xDEADF00D);
*v7 = v5;
if ( a2 <= 3 )
goto LABEL_10;
v8 = 4;
while ( v4 != (unsigned int)func1(v6, v8) )
{
if ( v9 < (int)++v8 )
goto LABEL_10;
}
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
}
else
{
fprintf(stderr, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
}
LABEL_10:
result = func0(v4);
*a3 = result;
return result;
}
fprintf(stderr, "XXXXX auto crc match len=%d 0x%08x\n", v8, v4);
result = func0(v4);
*a3 = result;
return result;
}

original_code:
void auto_crc(void *buf, int max_length, u32 *crc)
{
 u32 crc_saved = ntohl(*crc);
 u32 new;
 int length;
 *crc = htonl(0xdeadf00d);
 for (length=4; length <= max_length; length += 1) {
  new = crc32(buf, length);
  if (new == crc_saved) {
   (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "XXXXX auto crc match len=%d 0x%08x\n", length, new),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"XXXXX auto crc match len=%d 0x%08x\n", length, new),1) : 1) : fprintf((stderr),"XXXXX auto crc match len=%d 0x%08x\n", length, new)) : fprintf((stderr),"XXXXX auto crc match len=%d 0x%08x\n", length, new));
   break;
  }
 }
 *crc = htonl(crc_saved);
}

canonical_original_code:
void auto_crc(void *buf, int max_length, unsigned int *crc)
{
 unsigned int crc_saved = ntohl(*crc);
 unsigned int new;
 int length;
 *crc = htonl(0xdeadf00d);
 for (length=4; length <= max_length; length += 1) {
  new = crc32(buf, length);
  if (new == crc_saved) {
   (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "XXXXX auto crc match len=%d 0x%08x\n", length, new),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"XXXXX auto crc match len=%d 0x%08x\n", length, new),1) : 1) : fprintf((stderr),"XXXXX auto crc match len=%d 0x%08x\n", length, new)) : fprintf((stderr),"XXXXX auto crc match len=%d 0x%08x\n", length, new));
   break;
  }
 }
 *crc = htonl(crc_saved);
}


checksum

decompiled_code:
int __fastcall checksum(char *a1)
{
char *v1; // rax
__int64 v2; // rdx
int v3; // ecx

v1 = a1;
LODWORD(v2) = 0;
do
{
v3 = *v1++;
v2 = (unsigned int)(v3 + v2);
}
while ( v1 != a1 + 512 );
return sprintf(a1 + 148, "%07o", v2);
}

canonical_decompiled_code:
int __fastcall func0(char *a1)
{
char *v1; // rax
__int64 v2; // rdx
int v3; // ecx

v1 = a1;
LODWORD(v2) = 0;
do
{
v3 = *v1++;
v2 = (unsigned int)(v3 + v2);
}
while ( v1 != a1 + 512 );
return sprintf(a1 + 148, "%07o", v2);
}

original_code:
static void checksum(tar_record *rec)
{
 int chksum = 0;
 int i;
 for (i = 0; i < sizeof(tar_record); i++)
  chksum += rec->charptr[i];
 sprintf(rec->header.chksum, "%07o", chksum);
}

canonical_original_code:
static void checksum(union _tar_record *rec)
{
 int chksum = 0;
 int i;
 for (i = 0; i < sizeof(tar_record); i++)
  chksum += rec->charptr[i];
 sprintf(rec->header.chksum, "%07o", chksum);
}

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: chksum int

variable_types: i int

return_type: void

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


decompiled_code:
int __fastcall create_tarheader(char *dest, const char *a2, unsigned int a3)
{
unsigned __int64 v5; // rdi
time_t v6; // rax

v5 = (unsigned __int64)(dest + 8);
*(_QWORD *)(v5 - 8) = 0LL;
*(_QWORD *)(v5 + 496) = 0LL;
memset((void *)(v5 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)dest - (v5 & 0xFFFFFFF8) + 512) >> 3));
strncpy(dest, a2, 0x64uLL);
*(_QWORD *)(dest + 100) = 0x34343630303130LL;
*(_QWORD *)(dest + 108) = 0x30303030303030LL;
*(_QWORD *)(dest + 116) = 0x30303030303030LL;
sprintf(dest + 124, "%011o", a3);
v6 = time(0LL);
sprintf(dest + 136, "%011lo", v6);
sprintf(dest + 148, " ");
dest[156] = 48;
*(_QWORD *)(dest + 257) = 0x20207261747375LL;
strcpy(dest + 265, "tivo");
strcpy(dest + 297, "tivo");
return checksum(dest);
}

canonical_decompiled_code:
int __fastcall func1(char *dest, const char *a2, unsigned int a3)
{
unsigned __int64 v5; // rdi
time_t v6; // rax

v5 = (unsigned __int64)(dest + 8);
*(_QWORD *)(v5 - 8) = 0LL;
*(_QWORD *)(v5 + 496) = 0LL;
memset((void *)(v5 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)dest - (v5 & 0xFFFFFFF8) + 512) >> 3));
strncpy(dest, a2, 0x64uLL);
*(_QWORD *)(dest + 100) = 0x34343630303130LL;
*(_QWORD *)(dest + 108) = 0x30303030303030LL;
*(_QWORD *)(dest + 116) = 0x30303030303030LL;
sprintf(dest + 124, "%011o", a3);
v6 = time(0LL);
sprintf(dest + 136, "%011lo", v6);
sprintf(dest + 148, " ");
dest[156] = 48;
*(_QWORD *)(dest + 257) = 0x20207261747375LL;
strcpy(dest + 265, "tivo");
strcpy(dest + 297, "tivo");
return func0(dest);
}

original_code:
void create_tarheader(tar_record *rec, char *name, int size)
{
 memset(rec, 0, sizeof(tar_record));
 strncpy(rec->header.name, name, sizeof(rec->header.name));
 strcpy(rec->header.mode, "0100644");
 strcpy(rec->header.uid, "0000000");
 strcpy(rec->header.gid, "0000000");
 sprintf(rec->header.size, "%011o", size);
 sprintf(rec->header.mtime, "%011lo", time(((void *)0)));
 sprintf(rec->header.chksum, "        ");
 rec->header.linkflag = '0';
 strcpy(rec->header.magic, "ustar  ");
 strcpy(rec->header.uname, "tivo");
 strcpy(rec->header.gname, "tivo");
 checksum(rec);
}

canonical_original_code:
void create_tarheader(union _tar_record *rec, char *name, int size)
{
 memset(rec, 0, sizeof(tar_record));
 strncpy(rec->header.name, name, sizeof(rec->header.name));
 strcpy(rec->header.mode, "0100644");
 strcpy(rec->header.uid, "0000000");
 strcpy(rec->header.gid, "0000000");
 sprintf(rec->header.size, "%011o", size);
 sprintf(rec->header.mtime, "%011lo", time(((void *)0)));
 sprintf(rec->header.chksum, "        ");
 rec->header.linkflag = '0';
 strcpy(rec->header.magic, "ustar  ");
 strcpy(rec->header.uname, "tivo");
 strcpy(rec->header.gname, "tivo");
 checksum(rec);
}

variable_types:
name
char *

variable_types: size int

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


decompiled_code:
void __fastcall write_tar_padding(int fd, int a2)
{
void *v2; // rax
void *v3; // r12

if ( (a2 & 0x1FF) != 0 )
{
v2 = calloc(0x200uLL, 1uLL);
v3 = v2;
if ( !v2 )
{
perror("calloc failed\n");
exit(1);
}
write(
fd,
v2,
(int)(((unsigned int)(a2 >> 31) >> 23) - ((((unsigned int)(a2 >> 31) >> 23) + (_WORD)a2) & 0x1FF) + 512));
free(v3);
}
}

canonical_decompiled_code:
void __fastcall func2(int fd, int a2)
{
void *v2; // rax
void *v3; // r12

if ( (a2 & 0x1FF) != 0 )
{
v2 = calloc(0x200uLL, 1uLL);
v3 = v2;
if ( !v2 )
{
perror("calloc failed\n");
exit(1);
}
write(
fd,
v2,
(int)(((unsigned int)(a2 >> 31) >> 23) - ((((unsigned int)(a2 >> 31) >> 23) + (_WORD)a2) & 0x1FF) + 512));
free(v3);
}
}

original_code:
void write_tar_padding(int output_fd, int size)
{
    char *zilch;
    int slack;
    if (size % 512) {
        zilch = calloc(512, 1);
        if (zilch == ((void *)0)) {
            perror("calloc failed\n");
            exit(1);
        }
        slack = 512 - (size % 512);
        write(output_fd, zilch, slack);
        free(zilch);
        zilch = ((void *)0);
    }
}

variable_types:
zilch
char *

variable_types: slack int


decompiled_code:
int __fastcall dump_callback(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er13
const char *v7; // rax
unsigned __int16 v8; // cx
char v9; // al
__int64 v10; // r14
unsigned int v11; // edi
unsigned int v12; // eax
time_t v13; // r13
int v14; // eax
int v15; // edx
int v16; // eax
unsigned __int64 v18; // r12
unsigned int v19; // er13
unsigned int v20; // edi
unsigned int v21; // eax
__int64 v23; // rdi
const char *v24; // rbx
unsigned int v25; // er14
const char *v26; // rax
__int64 v27; // r13
unsigned int v28; // edi
int v29; // eax
int v30; // eax
int v31; // edx
int v32; // eax
int v33; // er13
const char *v34; // rax
_DWORD *v35; // rax
const char *v36; // rax
unsigned int *v37; // rax
const char *v38; // rax
struct tm *v39; // rax
time_t timer[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a3 )
{
if ( schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1)) )
{
v6 = *(unsigned __int8 *)(a3 + 1);
v7 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
printf("\t%s[%d]=", v7, v6);
v8 = *(_WORD *)(a3 + 2);
v9 = *(_BYTE *)a3 >> 6;
if ( v9 != 2 )
goto LABEL_4;
}
else
{
printf("\t[%d]=", *(unsigned __int8 *)(a3 + 1));
v8 = *(_WORD *)(a3 + 2);
v9 = *(_BYTE *)a3 >> 6;
if ( v9 != 2 )
{
LABEL_4:
if ( v9 == 3 )
{
v27 = 0LL;
if ( v8 <= 7u )
goto LABEL_36;
do
{
v28 = *(_DWORD *)(a4 + 4 * v27++);
v29 = _bswap_32(v28);
queue_add(v29);
v30 = *(unsigned __int16 *)(a3 + 2);
v31 = v30 - 1;
v8 = *(_WORD *)(a3 + 2);
v32 = v30 - 4;
if ( v32 < 0 )
v32 = v31;
}
while ( v32 >> 2 > (int)v27 );
}
else if ( v9 == 1 )
{
v33 = 0;
if ( v8 > 4u )
{
do
{
printf("%s ", (const char *)(a4 + v33));
v33 += strlen((const char *)(a4 + v33)) + 1;
}
while ( *(unsigned __int16 *)(a3 + 2) - 4 > v33 );
}
return putchar(10);
}
if ( v8 > 7u )
{
v10 = 0LL;
do
{
v11 = *(_DWORD *)(a4 + 4 * v10++);
v12 = _bswap_32(v11);
v13 = (int)v12;
printf("%d ", v12);
v14 = *(unsigned __int16 *)(a3 + 2);
v15 = v14 - 1;
v16 = v14 - 4;
if ( v16 < 0 )
v16 = v15;
}
while ( v16 >> 2 > (int)v10 );
goto LABEL_11;
}
LABEL_36:
v13 = 0LL;
LABEL_11:
if ( option_human )
{
v34 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
if ( strstr(v34, "Date") )
{
timer[0] = 86400 * (int)v13;
v35 = (_DWORD *)timefn(timer);
printf(
" (%.3s %.3s%3d %d)",
&wday_name_3[3 * v35[6]],
&mon_name_4[3 * v35[4]],
(unsigned int)v35[3],
(unsigned int)(v35[5] + 1900));
}
v36 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
if ( strstr(v36, "Time") )
{
timer[0] = (int)v13;
v37 = (unsigned int *)timefn(timer);
printf(" (%.2d:%.2d:%.2d)", v37[2], v37[1], *v37);
}
v38 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
if ( strstr(v38, "Duration") )
{
timer[0] = v13;
v39 = gmtime(timer);
printf(
" (%.2d:%.2d:%.2d)",
(unsigned int)v39->tm_hour,
(unsigned int)v39->tm_min,
(unsigned int)v39->tm_sec);
}
}
return putchar(10);
}
}
v18 = 0LL;
if ( (unsigned __int64)(v8 - 4) >> 3 )
{
do
{
v19 = _bswap_32(*(_DWORD *)(a4 + 8 * v18));
queue_add(v19);
v20 = *(_DWORD *)(a4 + 8 * v18++ + 4);
v21 = _bswap_32(v20);
printf("%d/%d ", v19, v21);
}
while ( (unsigned __int64)(*(unsigned __int16 *)(a3 + 2) - 4) >> 3 > v18 );
}
return putchar(10);
}
if ( last )
puts("}");
v23 = *(unsigned __int16 *)(a2 + 4);
v24 = "PRIMARY ";
if ( !*(_WORD *)(a2 + 6) )
v24 = (const char *)&unk_AADA;
v25 = *(_DWORD *)(a2 + 12);
last = a1;
v26 = (const char *)schema_type(v23);
return printf("%s %d/%d %s{\n", v26, a1, v25, v24);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er13
const char *v7; // rax
unsigned __int16 v8; // cx
char v9; // al
__int64 v10; // r14
unsigned int v11; // edi
unsigned int v12; // eax
time_t v13; // r13
int v14; // eax
int v15; // edx
int v16; // eax
unsigned __int64 v18; // r12
unsigned int v19; // er13
unsigned int v20; // edi
unsigned int v21; // eax
__int64 v23; // rdi
const char *v24; // rbx
unsigned int v25; // er14
const char *v26; // rax
__int64 v27; // r13
unsigned int v28; // edi
int v29; // eax
int v30; // eax
int v31; // edx
int v32; // eax
int v33; // er13
const char *v34; // rax
_DWORD *v35; // rax
const char *v36; // rax
unsigned int *v37; // rax
const char *v38; // rax
struct tm *v39; // rax
time_t timer[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a3 )
{
if ( schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1)) )
{
v6 = *(unsigned __int8 *)(a3 + 1);
v7 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
printf("\t%s[%d]=", v7, v6);
v8 = *(_WORD *)(a3 + 2);
v9 = *(_BYTE *)a3 >> 6;
if ( v9 != 2 )
goto LABEL_4;
}
else
{
printf("\t[%d]=", *(unsigned __int8 *)(a3 + 1));
v8 = *(_WORD *)(a3 + 2);
v9 = *(_BYTE *)a3 >> 6;
if ( v9 != 2 )
{
LABEL_4:
if ( v9 == 3 )
{
v27 = 0LL;
if ( v8 <= 7u )
goto LABEL_36;
do
{
v28 = *(_DWORD *)(a4 + 4 * v27++);
v29 = func2(v28);
func1(v29);
v30 = *(unsigned __int16 *)(a3 + 2);
v31 = v30 - 1;
v8 = *(_WORD *)(a3 + 2);
v32 = v30 - 4;
if ( v32 < 0 )
v32 = v31;
}
while ( v32 >> 2 > (int)v27 );
}
else if ( v9 == 1 )
{
v33 = 0;
if ( v8 > 4u )
{
do
{
printf("%s ", (const char *)(a4 + v33));
v33 += strlen((const char *)(a4 + v33)) + 1;
}
while ( *(unsigned __int16 *)(a3 + 2) - 4 > v33 );
}
return putchar(10);
}
if ( v8 > 7u )
{
v10 = 0LL;
do
{
v11 = *(_DWORD *)(a4 + 4 * v10++);
v12 = func2(v11);
v13 = (int)v12;
printf("%d ", v12);
v14 = *(unsigned __int16 *)(a3 + 2);
v15 = v14 - 1;
v16 = v14 - 4;
if ( v16 < 0 )
v16 = v15;
}
while ( v16 >> 2 > (int)v10 );
goto LABEL_11;
}
LABEL_36:
v13 = 0LL;
LABEL_11:
if ( option_human )
{
v34 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
if ( strstr(v34, "Date") )
{
timer[0] = 86400 * (int)v13;
v35 = (_DWORD *)timefn(timer);
printf(
" (%.3s %.3s%3d %d)",
&wday_name_3[3 * v35[6]],
&mon_name_4[3 * v35[4]],
(unsigned int)v35[3],
(unsigned int)(v35[5] + 1900));
}
v36 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
if ( strstr(v36, "Time") )
{
timer[0] = (int)v13;
v37 = (unsigned int *)timefn(timer);
printf(" (%.2d:%.2d:%.2d)", v37[2], v37[1], *v37);
}
v38 = (const char *)schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
if ( strstr(v38, "Duration") )
{
timer[0] = v13;
v39 = gmtime(timer);
printf(
" (%.2d:%.2d:%.2d)",
(unsigned int)v39->tm_hour,
(unsigned int)v39->tm_min,
(unsigned int)v39->tm_sec);
}
}
return putchar(10);
}
}
v18 = 0LL;
if ( (unsigned __int64)(v8 - 4) >> 3 )
{
do
{
v19 = func2(*(_DWORD *)(a4 + 8 * v18));
func1(v19);
v20 = *(_DWORD *)(a4 + 8 * v18++ + 4);
v21 = func2(v20);
printf("%d/%d ", v19, v21);
}
while ( (unsigned __int64)(*(unsigned __int16 *)(a3 + 2) - 4) >> 3 > v18 );
}
return putchar(10);
}
if ( last )
puts("}");
v23 = *(unsigned __int16 *)(a2 + 4);
v24 = "PRIMARY ";
if ( !*(_WORD *)(a2 + 6) )
v24 = (const char *)&unk_AADA;
v25 = *(_DWORD *)(a2 + 12);
last = a1;
v26 = (const char *)schema_type(v23);
return printf("%s %d/%d %s{\n", v26, a1, v25, v24);
}

original_code:
static void dump_callback(int fsid, struct mfs_subobj_header *obj,
     struct mfs_attr_header *attr, void *data)
{
 int i;
 char *p = data;
 struct mfs_obj_attr *objattr;
 int intvalue = 0;
 struct tm *timeptr;
 time_t date_time;
 static char wday_name[7][3] = {
  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 };
 static char mon_name[12][3] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 if (!attr) {
  if (last) printf("}\n");
  last = fsid;
  printf("%s %d/%d %s{\n",
         schema_type(obj->obj_type), fsid, obj->id,
         obj->flags?"PRIMARY ":"");
  return;
 }
 if (schema_attrib(obj->obj_type,attr->attr)) {
  printf("\t%s[%d]=",
         schema_attrib(obj->obj_type,attr->attr), attr->attr);
 } else {
  printf("\t[%d]=", attr->attr);
 }
 switch (attr->eltype>>6) {
 case 1:
  for (i=0;i<attr->len-4;) {
   char *s = (char *)&p[i];
   printf("%s ", s);
   i += strlen(s)+1;
  }
  break;
 case 3:
  for (i=0;i<(attr->len-4)/4;i++)
   queue_add(ntohl(*(int *)&p[i*4]));
 case 0:
  for (i=0;i<(attr->len-4)/4;i++) {
   intvalue = ntohl(*(int *)&p[i*4]);
   printf("%d ", intvalue);
  }
  if (option_human) {
   if (strstr(schema_attrib(obj->obj_type,attr->attr), "Date")) {
    date_time = (time_t)(intvalue*86400 + tzoff);
    timeptr = timefn(&date_time);
    printf(" (%.3s %.3s%3d %d)",
           wday_name[timeptr->tm_wday],
           mon_name[timeptr->tm_mon],
           timeptr->tm_mday,
           1900 + timeptr->tm_year);
   }
   if (strstr(schema_attrib(obj->obj_type,attr->attr), "Time")) {
    date_time = (time_t)(intvalue + tzoff);
    timeptr = timefn(&date_time);
    printf(" (%.2d:%.2d:%.2d)",
           timeptr->tm_hour,
           timeptr->tm_min,
           timeptr->tm_sec);
   }
   if (strstr(schema_attrib(obj->obj_type,attr->attr), "Duration")) {
    date_time = (time_t)(intvalue);
    timeptr = gmtime(&date_time);
    printf(" (%.2d:%.2d:%.2d)",
           timeptr->tm_hour,
           timeptr->tm_min,
           timeptr->tm_sec);
   }
  }
  break;
 case 2:
  objattr = (struct mfs_obj_attr *)p;
  for (i=0;i<(attr->len-4)/sizeof(*objattr);i++) {
   int fsid = ntohl(objattr->fsid);
   queue_add(fsid);
   printf("%d/%d ",
          fsid,
          (int) ntohl(objattr->subobj));
   objattr++;
  }
  break;
 }
 printf("\n");
}

canonical_original_code:
static void dump_callback(int fsid, struct mfs_subobj_header *obj, struct mfs_attr_header *attr, void *data)
{
 int i;
 char *p = data;
 struct mfs_obj_attr *objattr;
 int intvalue = 0;
 struct tm *timeptr;
 long date_time;
 static char wday_name[7][3] = {
  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 };
 static char mon_name[12][3] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 if (!attr) {
  if (last) printf("}\n");
  last = fsid;
  printf("%s %d/%d %s{\n",
         schema_type(obj->obj_type), fsid, obj->id,
         obj->flags?"PRIMARY ":"");
  return;
 }
 if (schema_attrib(obj->obj_type,attr->attr)) {
  printf("\t%s[%d]=",
         schema_attrib(obj->obj_type,attr->attr), attr->attr);
 } else {
  printf("\t[%d]=", attr->attr);
 }
 switch (attr->eltype>>6) {
 case 1:
  for (i=0;i<attr->len-4;) {
   char *s = (char *)&p[i];
   printf("%s ", s);
   i += strlen(s)+1;
  }
  break;
 case 3:
  for (i=0;i<(attr->len-4)/4;i++)
   queue_add(ntohl(*(int *)&p[i*4]));
 case 0:
  for (i=0;i<(attr->len-4)/4;i++) {
   intvalue = ntohl(*(int *)&p[i*4]);
   printf("%d ", intvalue);
  }
  if (option_human) {
   if (strstr(schema_attrib(obj->obj_type,attr->attr), "Date")) {
    date_time = (time_t)(intvalue*86400 + tzoff);
    timeptr = timefn(&date_time);
    printf(" (%.3s %.3s%3d %d)",
           wday_name[timeptr->tm_wday],
           mon_name[timeptr->tm_mon],
           timeptr->tm_mday,
           1900 + timeptr->tm_year);
   }
   if (strstr(schema_attrib(obj->obj_type,attr->attr), "Time")) {
    date_time = (time_t)(intvalue + tzoff);
    timeptr = timefn(&date_time);
    printf(" (%.2d:%.2d:%.2d)",
           timeptr->tm_hour,
           timeptr->tm_min,
           timeptr->tm_sec);
   }
   if (strstr(schema_attrib(obj->obj_type,attr->attr), "Duration")) {
    date_time = (time_t)(intvalue);
    timeptr = gmtime(&date_time);
    printf(" (%.2d:%.2d:%.2d)",
           timeptr->tm_hour,
           timeptr->tm_min,
           timeptr->tm_sec);
   }
  }
  break;
 case 2:
  objattr = (struct mfs_obj_attr *)p;
  for (i=0;i<(attr->len-4)/sizeof(*objattr);i++) {
   int fsid = ntohl(objattr->fsid);
   queue_add(fsid);
   printf("%d/%d ",
          fsid,
          (int) ntohl(objattr->subobj));
   objattr++;
  }
  break;
 }
 printf("\n");
}

variable_types: fsid int

variable_types: struct mfs_subobj_header { unsigned short len; unsigned short len1; unsigned short obj_type; unsigned short flags; unsigned short fill[2]; unsigned int id; } *

variable_types: struct mfs_attr_header { unsigned char eltype; unsigned char attr; unsigned short len; } *

variable_types:
data
void *

variable_types:
p
char *

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

variable_types: intvalue int

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


decompiled_code:
__int64 __fastcall seen_before(unsigned int a1)
{
unsigned int v1; // ebp
signed int v2; // er8
unsigned int v3; // eax
unsigned int v4; // edx
unsigned int *v5; // rcx
size_t v7; // r12

v1 = hash_size;
if ( !hash_table )
{
hash_size = inode_count();
v1 = hash_size;
v7 = 4LL * (unsigned int)hash_size;
hash_table = malloc(v7);
if ( !hash_table )
_assert_fail("hash_table", "mfs_dumpobj.c", 0x9Du, "seen_before");
if ( v1 )
memset(hash_table, 255, v7);
}
v2 = fsid_hash(a1, v1);
v3 = *((_DWORD *)hash_table + v2);
v4 = v2;
while ( 1 )
{
if ( a1 == v3 )
return 1LL;
if ( v3 == -1 )
{
v5 = (unsigned int *)((char *)hash_table + 4 * (int)v4);
LABEL_8:
*v5 = a1;
return 0LL;
}
v4 = (v4 + 1) % hash_size;
v5 = (unsigned int *)((char *)hash_table + 4 * (int)v4);
v3 = *v5;
if ( v2 == v4 )
break;
if ( v3 == -1 )
goto LABEL_8;
}
if ( v3 == -1 )
goto LABEL_8;
fwrite("hash table full!?\n", 1uLL, 0x12uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned int v1; // ebp
signed int v2; // er8
unsigned int v3; // eax
unsigned int v4; // edx
unsigned int *v5; // rcx
size_t v7; // r12

v1 = hash_size;
if ( !hash_table )
{
hash_size = inode_count();
v1 = hash_size;
v7 = 4LL * (unsigned int)hash_size;
hash_table = malloc(v7);
if ( !hash_table )
_assert_fail("hash_table", "mfs_dumpobj.c", 0x9Du, "seen_before");
if ( v1 )
memset(hash_table, 255, v7);
}
v2 = fsid_hash(a1, v1);
v3 = *((_DWORD *)hash_table + v2);
v4 = v2;
while ( 1 )
{
if ( a1 == v3 )
return 1LL;
if ( v3 == -1 )
{
v5 = (unsigned int *)((char *)hash_table + 4 * (int)v4);
LABEL_8:
*v5 = a1;
return 0LL;
}
v4 = (v4 + 1) % hash_size;
v5 = (unsigned int *)((char *)hash_table + 4 * (int)v4);
v3 = *v5;
if ( v2 == v4 )
break;
if ( v3 == -1 )
goto LABEL_8;
}
if ( v3 == -1 )
goto LABEL_8;
fwrite("hash table full!?\n", 1uLL, 0x12uLL, stderr);
return 0LL;
}

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

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

variable_types: hash int

variable_types: first int

return_type: int


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

canonical_decompiled_code:
void func5()
{
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;
 }
}


dumpobj

decompiled_code:
int __fastcall dumpobj(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
__int64 v7; // rax
unsigned int v8; // ebx
unsigned int v9; // er14
int v10; // esi
__int64 v11; // rax
void *v12; // rsp
size_t v13; // r14
const char **v14; // r13
void *v15; // rsp
signed __int64 v16; // rax
size_t v17; // rsi
__int64 v18; // rdx
__int64 v19; // rsi
char *v20; // rax
char *v21; // rdx
_BYTE v23[15]; // [rsp-Eh] [rbp-20060h] BYREF
__int64 i; // [rsp+20002h] [rbp-50h] BYREF
unsigned int v25; // [rsp+2000Eh] [rbp-44h]
unsigned int v26[13]; // [rsp+2001Eh] [rbp-34h] BYREF

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

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
__int64 v7; // rax
unsigned int v8; // ebx
unsigned int v9; // er14
int v10; // esi
__int64 v11; // rax
void *v12; // rsp
size_t v13; // r14
const char **v14; // r13
void *v15; // rsp
signed __int64 v16; // rax
size_t v17; // rsi
__int64 v18; // rdx
__int64 v19; // rsi
char *v20; // rax
char *v21; // rdx
_BYTE v23[15]; // [rsp-Eh] [rbp-20060h] BYREF
__int64 i; // [rsp+20002h] [rbp-50h] BYREF
unsigned int v25; // [rsp+2000Eh] [rbp-44h]
unsigned int v26[13]; // [rsp+2001Eh] [rbp-34h] BYREF

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

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: fileobj int

variable_types: recurse 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


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

if ( a1 )
return sub_8A0();
nq = 0;
return result;
}

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

if ( a1 )
return sub_8A0();
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: i int

variable_types: n int

variable_types:
q
int *


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

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

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

result = nq;
if ( nq > 10239 )
_assert_fail("nq < MAX_QUEUE", "mfs_dumpobj.c", 0x1Cu, "queue_add");
fsid_queue[nq] = a1;
nq = result + 1;
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;
}

variable_types: fsid int


main

canonical_name: main

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

v3 = 0;
v4 = 0;
mfs_init(argc, argv, envp);
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_14;
v4 = 1;
}
else if ( v5 == 102 )
{
v3 = 1;
}
else
{
if ( v5 != 104 )
goto LABEL_14;
option_human = 1;
}
}
v6 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_14:
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; // er13
unsigned int v4; // er12
int v5; // eax
const char **v6; // rbp
unsigned int v7; // eax

v3 = 0;
v4 = 0;
mfs_init(argc, argv, envp);
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_14;
v4 = 1;
}
else if ( v5 == 102 )
{
v3 = 1;
}
else
{
if ( v5 != 104 )
goto LABEL_14;
option_human = 1;
}
}
v6 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_14:
func0();
v7 = mfs_resolve(*v6);
func7(v7, v3, v4, *v6);
func5();
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

variable_types: fileobj int


readall

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

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

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

v4 = n;
if ( !use_recv )
{
v5 = 0LL;
if ( n )
goto LABEL_3;
return 0LL;
}
v8 = 0LL;
if ( !n )
return v8;
while ( 1 )
{
v11 = recv(fd, buf, v4, 256);
if ( v11 <= 0 )
break;
buf = (char *)buf + v11;
v8 += v11;
v4 -= v11;
if ( !v4 )
return v8;
}
v5 = v8;
perror("recv error, falling back to read loop. ");
use_recv = 0;
do
{
LABEL_3:
while ( 1 )
{
v6 = read(fd, buf, v4);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 += v6;
v4 -= v6;
if ( !v4 )
return v5;
}
v10 = *_errno_location();
}
while ( v10 == 4 || v10 == 11 );
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:
buf
void *

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, size_t a4, int a5, unsigned int a6, int a7)
{
void *v7; // rsp
unsigned __int64 v8; // rcx
unsigned __int64 v9; // r13
__int64 v10; // r12
unsigned __int64 v11; // rax
unsigned int v13; // er14
size_t v14; // rcx
int v15; // esi
unsigned int v16; // ebx
size_t v17; // rbx
ssize_t v18; // rax
int v19; // ebx
unsigned __int64 v20; // rax
int v21; // ebx
size_t v22; // rbx
ssize_t v23; // rax
__int64 v24; // r8
__int64 v25; // rsi
_BYTE v26[8]; // [rsp+0h] [rbp-290h] BYREF
size_t v27; // [rsp+8h] [rbp-288h]
__int64 v28; // [rsp+10h] [rbp-280h]
int v29; // [rsp+18h] [rbp-278h]
int v30; // [rsp+1Ch] [rbp-274h]
unsigned int v31; // [rsp+20h] [rbp-270h]
int fd; // [rsp+24h] [rbp-26Ch]
unsigned __int64 v33; // [rsp+28h] [rbp-268h]
ssize_t v34; // [rsp+30h] [rbp-260h]
size_t v35; // [rsp+38h] [rbp-258h]
__int64 v36; // [rsp+40h] [rbp-250h]
size_t n; // [rsp+48h] [rbp-248h]
struct timespec requested_time; // [rsp+50h] [rbp-240h] BYREF
char v39[56]; // [rsp+60h] [rbp-230h] BYREF
unsigned int v40; // [rsp+98h] [rbp-1F8h]
int v41[125]; // [rsp+9Ch] [rbp-1F4h]

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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, unsigned __int64 a3, size_t a4, int a5, unsigned int a6, int a7)
{
void *v7; // rsp
unsigned __int64 v8; // rcx
unsigned __int64 v9; // r13
__int64 v10; // r12
unsigned __int64 v11; // rax
unsigned int v13; // er14
size_t v14; // rcx
int v15; // esi
unsigned int v16; // ebx
size_t v17; // rbx
ssize_t v18; // rax
int v19; // ebx
unsigned __int64 v20; // rax
int v21; // ebx
size_t v22; // rbx
ssize_t v23; // rax
__int64 v24; // r8
__int64 v25; // rsi
_BYTE v26[8]; // [rsp+0h] [rbp-290h] BYREF
size_t v27; // [rsp+8h] [rbp-288h]
__int64 v28; // [rsp+10h] [rbp-280h]
int v29; // [rsp+18h] [rbp-278h]
int v30; // [rsp+1Ch] [rbp-274h]
unsigned int v31; // [rsp+20h] [rbp-270h]
int fd; // [rsp+24h] [rbp-26Ch]
unsigned __int64 v33; // [rsp+28h] [rbp-268h]
ssize_t v34; // [rsp+30h] [rbp-260h]
size_t v35; // [rsp+38h] [rbp-258h]
__int64 v36; // [rsp+40h] [rbp-250h]
size_t n; // [rsp+48h] [rbp-248h]
struct timespec requested_time; // [rsp+50h] [rbp-240h] BYREF
char v39[56]; // [rsp+60h] [rbp-230h] BYREF
unsigned int v40; // [rsp+98h] [rbp-1F8h]
int v41[125]; // [rsp+9Ch] [rbp-1F4h]

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

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: len int

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; // er15
int v4; // er14
__int64 v5; // r13
__int64 v6; // r12
int v7; // eax
__int64 v8; // rax
int v9; // ebx
const char **v10; // rbp
unsigned int v11; // er10
const char *v12; // rdi
int v13; // esi
int v15; // eax
int v16; // [rsp+8h] [rbp-40h]
unsigned int v17; // [rsp+Ch] [rbp-3Ch]

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
int v4; // er14
__int64 v5; // r13
__int64 v6; // r12
int v7; // eax
__int64 v8; // rax
int v9; // ebx
const char **v10; // rbp
unsigned int v11; // er10
const char *v12; // rdi
int v13; // esi
int v15; // eax
int v16; // [rsp+8h] [rbp-40h]
unsigned int v17; // [rsp+Ch] [rbp-3Ch]

v3 = 256;
v4 = -1;
v5 = 0LL;
v6 = 0LL;
v16 = 0;
prog = (void *)*argv;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "hvs:c:r:n:p:");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'c':
v5 = strtoll(optarg, 0LL, 0);
continue;
case 'n':
v3 = strtoll(optarg, 0LL, 0);
continue;
case 'p':
v8 = strtoll(optarg, 0LL, 0);
fixPriority(v8);
continue;
case 'r':
v4 = strtoll(optarg, 0LL, 0);
continue;
case 's':
v6 = strtoll(optarg, 0LL, 0);
continue;
case 'v':
v16 = 1;
continue;
default:
goto LABEL_19;
}
}
break;
}
v9 = argc - optind;
v10 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_19:
func0();
mfs_init();
v11 = mfs_resolve(*v10);
if ( !v11 )
{
fprintf(stderr, "Error: The path or fsid %s is invalid\n", v10[1]);
exit(1);
}
if ( v9 == 1 )
{
v13 = 0;
return (int)func2(v11, v13, v6, v5, v4, v3, v16) <= 0;
}
v12 = v10[1];
if ( *v12 == 45 )
{
v13 = *((unsigned __int8 *)v12 + 1);
if ( !v12[1] )
return (int)func2(v11, v13, v6, v5, v4, v3, v16) <= 0;
}
v17 = v11;
v15 = open64(v12, 0);
v11 = v17;
v13 = v15;
if ( v15 >= 0 )
return (int)func2(v11, v13, v6, v5, v4, v3, v16) <= 0;
perror(v10[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

variable_types: verbose int


getvids

decompiled_code:
void __fastcall getvids(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int *v3; // rax
unsigned int *v4; // r14
__int64 v5; // r13
__int64 v6; // rcx
int *v7; // rax
char *v8; // rdi
int *v9; // rbp
int v10; // ecx
int v11; // [rsp+0h] [rbp-38h] BYREF
char v12[4]; // [rsp+4h] [rbp-34h] BYREF
char *ptr; // [rsp+8h] [rbp-30h] BYREF

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

canonical_decompiled_code:
void __fastcall func1(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int *v3; // rax
unsigned int *v4; // r14
__int64 v5; // r13
__int64 v6; // rcx
int *v7; // rax
char *v8; // rdi
int *v9; // rbp
int v10; // ecx
int v11; // [rsp+0h] [rbp-38h] BYREF
char v12[4]; // [rsp+4h] [rbp-34h] BYREF
char *ptr; // [rsp+8h] [rbp-30h] BYREF

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

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; // er12
const char *v2; // rax
const char *v3; // rax
__int64 v4; // r12
unsigned __int64 v5; // rax
int result; // eax
const char *v7; // r13
int v8; // eax
int v9; // ebp

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; // er12
const char *v2; // rax
const char *v3; // rax
__int64 v4; // r12
unsigned __int64 v5; // rax
int result; // eax
const char *v7; // r13
int v8; // eax
int v9; // ebp

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
__int64 v5; // rsi
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = (unsigned int *)query_object(a1, a2, v6);
if ( v2 )
{
v3 = v2;
if ( *v2 )
{
printf("\t%s: ", a2);
if ( v6[0] > 0 )
{
v4 = 0LL;
do
{
v5 = v3[2 * v4++ + 1];
printf("LoopSetClip/%d ", v5);
}
while ( v6[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
__int64 v5; // rsi
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = (unsigned int *)query_object(a1, a2, v6);
if ( v2 )
{
v3 = v2;
if ( *v2 )
{
printf("\t%s: ", a2);
if ( v6[0] > 0 )
{
v4 = 0LL;
do
{
v5 = v3[2 * v4++ + 1];
printf("LoopSetClip/%d ", v5);
}
while ( v6[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 v3; // er13
unsigned int *v4; // rax
unsigned int *v5; // rbp
__int64 v6; // rbx
__int64 v7; // rsi
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int *v10; // rax
__int64 v11; // rdi
void *v12; // r12
int v13; // edx
const char *v14; // rax
int v15; // [rsp+0h] [rbp-48h] BYREF
char v16[4]; // [rsp+4h] [rbp-44h] BYREF
char *ptr; // [rsp+8h] [rbp-40h] BYREF
char *v18; // [rsp+10h] [rbp-38h] BYREF
char *v19; // [rsp+18h] [rbp-30h] BYREF

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

canonical_decompiled_code:
void __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v3; // er13
unsigned int *v4; // rax
unsigned int *v5; // rbp
__int64 v6; // rbx
__int64 v7; // rsi
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int *v10; // rax
__int64 v11; // rdi
void *v12; // r12
int v13; // edx
const char *v14; // rax
int v15; // [rsp+0h] [rbp-48h] BYREF
char v16[4]; // [rsp+4h] [rbp-44h] BYREF
char *ptr; // [rsp+8h] [rbp-40h] BYREF
char *v18; // [rsp+10h] [rbp-38h] BYREF
char *v19; // [rsp+18h] [rbp-30h] BYREF

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

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; // er12
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);
}
v1 = 0LL;
puts("Guide type=3\n");
getvids(a1, "State");
getvids(a1, "Trans");
if ( num_vids > 0 )
{
do
{
if ( !v1 || *(_DWORD *)(4 * v1 + 0x4FC) != vid_fsid[v1] )
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; // er12
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);
}
v1 = 0LL;
puts("Guide type=3\n");
func1(a1, "State");
func1(a1, "Trans");
if ( num_vids > 0 )
{
do
{
if ( !v1 || *(_DWORD *)(4 * v1 + 0x4FC) != vid_fsid[v1] )
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 )
goto LABEL_7;
pull_files = 1;
}
v4 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_7:
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 )
goto LABEL_7;
pull_files = 1;
}
v4 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_7:
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;
}

variable_types: argc int


decompiled_code:
__int64 __fastcall mfsd_main(int argc, char **argv)
{
unsigned int v2; // er15
unsigned int v3; // er14
unsigned int v4; // er13
uint32_t v5; // er12
int v7; // eax
unsigned int v8; // ebp
char *v10; // rsi
__int64 v11; // rbx
unsigned __int8 *v12; // r13
int v13; // ebx
unsigned int v14; // er15
unsigned int v15; // esi
int v16; // edx
unsigned __int8 *v17; // rdi
unsigned __int8 *v18; // rax
int v19; // eax
__int64 v20; // r9
int v21; // eax
uint32_t v22; // er12
uint32_t v23; // eax
uint32_t v24; // eax
unsigned __int8 v25; // al
uint32_t v26; // er12
uint32_t v27; // eax
uint32_t v28; // eax
uint32_t v29; // eax
uint32_t v30; // er12
unsigned int v31; // eax
__int64 v32; // r12
uint32_t v33; // eax
uint32_t v34; // eax
uint32_t v35; // edi
uint32_t v36; // er13
uint32_t v37; // eax
__int64 v38; // r12
__int64 v39; // r12
uint32_t v40; // er13
uint32_t v41; // eax
__int64 v42; // r12
__int64 v43; // r12
uint32_t v44; // er13
uint32_t v45; // eax
int v46; // [rsp+4h] [rbp-44h]
__int64 v47; // [rsp+8h] [rbp-40h]
__int64 v48; // [rsp+8h] [rbp-40h]

v2 = 1;
v3 = -559038737;
v4 = -559038737;
v5 = 0;
v46 = 0;
progname = (__int64)*argv;
while ( 1 )
{
v7 = getopt(argc, argv, "bhc:s:i:f:");
if ( v7 < 0 )
break;
switch ( v7 )
{
case 'b':
v46 = 2;
continue;
case 'c':
v2 = strtoul(optarg, 0LL, 0);
continue;
case 'f':
if ( v4 != -559038737 )
{
v8 = 1;
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
usage();
return v8;
}
v5 = strtoul(optarg, 0LL, 0);
continue;
case 'h':
v46 = 1;
continue;
case 'i':
if ( v5 )
{
v8 = 2;
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
usage();
return v8;
}
v4 = strtoul(optarg, 0LL, 0);
break;
case 's':
v3 = strtoul(optarg, 0LL, 0);
continue;
default:
v8 = 3;
usage();
return v8;
}
}
if ( v5 == 0 && v3 == -559038737 && v4 == -559038737 || optind == argc || optind > argc + 1 )
{
v8 = 4;
usage();
return v8;
}
v10 = 0LL;
if ( optind + 1 < argc )
v10 = argv[optind + 1];
mfs = mfs_init(argv[optind], v10, 0LL);
v8 = mfs_has_error(mfs);
if ( v8 )
{
v8 = 1;
mfs_perror(mfs, *argv);
return v8;
}
if ( v5 )
{
v11 = mfs_read_inode_by_fsid(mfs, v5);
if ( !v11 )
{
v8 = 1;
mfs_perror(mfs, "Read fsid");
return v8;
}
}
else
{
v11 = 0LL;
if ( v4 == -559038737 )
goto LABEL_23;
v11 = mfs_read_inode(mfs, v4);
if ( !v11 )
{
v8 = 1;
mfs_perror(mfs, "Read inode");
return v8;
}
}
v5 = 8 * htonl(*(_DWORD *)(v11 + 56)) + 60;
LABEL_23:
if ( v3 == -559038737 )
{
if ( v46 != 2 )
{
if ( !v11 || (v46 & 1) != 0 )
{
v12 = (unsigned __int8 *)v11;
if ( !v5 )
return v8;
goto LABEL_28;
}
v22 = htonl(*(_DWORD *)v11);
v23 = htonl(*(_DWORD *)(v11 + 16));
printf("Inode: %-13dFSid: %d\n", v23, v22);
v24 = htonl(*(_DWORD *)(v11 + 4));
printf("Refcount: %-10dType: ", v24);
v25 = *(_BYTE *)(v11 + 40);
if ( v25 == 4 )
{
puts("tyDir");
goto LABEL_54;
}
if ( v25 > 4u )
{
if ( v25 == 8 )
{
puts("tyDb");
goto LABEL_54;
}
}
else
{
if ( v25 == 1 )
{
puts("tyFile");
goto LABEL_54;
}
if ( v25 == 2 )
{
puts("tyStream");
LABEL_54:
v26 = htonl(*(_DWORD *)(v11 + 12));
v27 = htonl(*(_DWORD *)(v11 + 8));
printf("???: %-15d???: %d\n", v27, v26);
if ( *(_BYTE *)(v11 + 40) == 2 )
{
v38 = (int)htonl(*(_DWORD *)(v11 + 20));
v39 = (int)htonl(*(_DWORD *)(v11 + 24)) * v38;
v40 = htonl(*(_DWORD *)(v11 + 20));
v41 = htonl(*(_DWORD *)(v11 + 24));
printf("Size: %d blocks of %d bytes (%llu)\n", v41, v40, v39);
v42 = (int)htonl(*(_DWORD *)(v11 + 32));
v43 = (int)htonl(*(_DWORD *)(v11 + 28)) * v42;
v44 = htonl(*(_DWORD *)(v11 + 28));
v45 = htonl(*(_DWORD *)(v11 + 32));
printf("Used: %d blocks of %d bytes (%llu)\n", v45, v44, v43);
}
else
{
v28 = htonl(*(_DWORD *)(v11 + 24));
printf("Size: %d bytes\n", v28);
}
v29 = htonl(*(_DWORD *)(v11 + 52));
printf("Checksum: %08x Flags(?): %d\n", *(unsigned int *)(v11 + 48), v29);
v30 = htonl(*(_DWORD *)(v11 + 44));
LOWORD(v31) = htons(*(_WORD *)(v11 + 42));
printf("Sigs: %02x %04x %08x (Always 02 beef 91231ebc?)\n", *(unsigned __int8 *)(v11 + 41), v31, v30);
if ( htonl(*(_DWORD *)(v11 + 56)) )
{
v32 = 0LL;
v33 = htonl(*(_DWORD *)(v11 + 56));
printf("Data is in %d blocks:\n", v33);
while ( (int)htonl(*(_DWORD *)(v11 + 56)) > (int)v32 )
{
v34 = htonl(*(_DWORD *)(v11 + 8 * v32 + 64));
v35 = *(_DWORD *)(v11 + 8 * v32++ + 60);
v36 = v34;
v37 = htonl(v35);
printf("At %-8x %d sectors\n", v37, v36);
}
}
else
{
v8 = 0;
puts("Data is in inode block.");
}
return v8;
}
}
printf("???");
goto LABEL_54;
}
LABEL_39:
write(1, (const void *)v11, v5);
return v8;
}
v18 = (unsigned __int8 *)calloc(v2, 0x200uLL);
v12 = v18;
if ( !v18 )
{
v8 = 1;
fprintf(stderr, "%s: Couldn't allocate %d bytes!\n", (const char *)progname, v2 << 9);
return v8;
}
if ( v11 )
{
v47 = (__int64)v18;
v19 = mfs_read_inode_data_part(mfs, v11, v18, v3, v2);
v20 = v47;
v5 = v19;
if ( v19 > 0 )
goto LABEL_37;
LABEL_48:
v8 = 1;
mfs_perror(mfs, "Read data");
return v8;
}
v48 = (__int64)v18;
v21 = mfsvol_read_data(*(_QWORD *)mfs, v18, v3, v2);
v20 = v48;
v5 = v21;
if ( v21 <= 0 )
goto LABEL_48;
LABEL_37:
if ( v46 == 2 )
{
v11 = v20;
goto LABEL_39;
}
LABEL_28:
v13 = v5;
v14 = v3;
do
{
v15 = -559038737;
v16 = v13;
v17 = v12;
if ( v3 != -559038737 )
v15 = v14;
v13 -= 512;
++v14;
v12 += 512;
hexdump(v17, v15, v16);
}
while ( v5 - v13 < v5 );
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
unsigned int v2; // er15
unsigned int v3; // er14
unsigned int v4; // er13
uint32_t v5; // er12
int v7; // eax
unsigned int v8; // ebp
char *v10; // rsi
__int64 v11; // rbx
unsigned __int8 *v12; // r13
int v13; // ebx
unsigned int v14; // er15
unsigned int v15; // esi
int v16; // edx
unsigned __int8 *v17; // rdi
unsigned __int8 *v18; // rax
int v19; // eax
__int64 v20; // r9
int v21; // eax
uint32_t v22; // er12
uint32_t v23; // eax
uint32_t v24; // eax
unsigned __int8 v25; // al
uint32_t v26; // er12
uint32_t v27; // eax
uint32_t v28; // eax
uint32_t v29; // eax
uint32_t v30; // er12
unsigned int v31; // eax
__int64 v32; // r12
uint32_t v33; // eax
uint32_t v34; // eax
uint32_t v35; // edi
uint32_t v36; // er13
uint32_t v37; // eax
__int64 v38; // r12
__int64 v39; // r12
uint32_t v40; // er13
uint32_t v41; // eax
__int64 v42; // r12
__int64 v43; // r12
uint32_t v44; // er13
uint32_t v45; // eax
int v46; // [rsp+4h] [rbp-44h]
__int64 v47; // [rsp+8h] [rbp-40h]
__int64 v48; // [rsp+8h] [rbp-40h]

v2 = 1;
v3 = -559038737;
v4 = -559038737;
v5 = 0;
v46 = 0;
progname = (__int64)*argv;
while ( 1 )
{
v7 = getopt(argc, argv, "bhc:s:i:f:");
if ( v7 < 0 )
break;
switch ( v7 )
{
case 'b':
v46 = 2;
continue;
case 'c':
v2 = strtoul(optarg, 0LL, 0);
continue;
case 'f':
if ( v4 != -559038737 )
{
v8 = 1;
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
func0();
return v8;
}
v5 = strtoul(optarg, 0LL, 0);
continue;
case 'h':
v46 = 1;
continue;
case 'i':
if ( v5 )
{
v8 = 2;
fwrite("Only 1 of -f and -i may be used.\n", 1uLL, 0x21uLL, stderr);
func0();
return v8;
}
v4 = strtoul(optarg, 0LL, 0);
break;
case 's':
v3 = strtoul(optarg, 0LL, 0);
continue;
default:
v8 = 3;
func0();
return v8;
}
}
if ( v5 == 0 && v3 == -559038737 && v4 == -559038737 || optind == argc || optind > argc + 1 )
{
v8 = 4;
func0();
return v8;
}
v10 = 0LL;
if ( optind + 1 < argc )
v10 = argv[optind + 1];
mfs = mfs_init(argv[optind], v10, 0LL);
v8 = mfs_has_error(mfs);
if ( v8 )
{
v8 = 1;
mfs_perror(mfs, *argv);
return v8;
}
if ( v5 )
{
v11 = mfs_read_inode_by_fsid(mfs, v5);
if ( !v11 )
{
v8 = 1;
mfs_perror(mfs, "Read fsid");
return v8;
}
}
else
{
v11 = 0LL;
if ( v4 == -559038737 )
goto LABEL_23;
v11 = mfs_read_inode(mfs, v4);
if ( !v11 )
{
v8 = 1;
mfs_perror(mfs, "Read inode");
return v8;
}
}
v5 = 8 * htonl(*(_DWORD *)(v11 + 56)) + 60;
LABEL_23:
if ( v3 == -559038737 )
{
if ( v46 != 2 )
{
if ( !v11 || (v46 & 1) != 0 )
{
v12 = (unsigned __int8 *)v11;
if ( !v5 )
return v8;
goto LABEL_28;
}
v22 = htonl(*(_DWORD *)v11);
v23 = htonl(*(_DWORD *)(v11 + 16));
printf("Inode: %-13dFSid: %d\n", v23, v22);
v24 = htonl(*(_DWORD *)(v11 + 4));
printf("Refcount: %-10dType: ", v24);
v25 = *(_BYTE *)(v11 + 40);
if ( v25 == 4 )
{
puts("tyDir");
goto LABEL_54;
}
if ( v25 > 4u )
{
if ( v25 == 8 )
{
puts("tyDb");
goto LABEL_54;
}
}
else
{
if ( v25 == 1 )
{
puts("tyFile");
goto LABEL_54;
}
if ( v25 == 2 )
{
puts("tyStream");
LABEL_54:
v26 = htonl(*(_DWORD *)(v11 + 12));
v27 = htonl(*(_DWORD *)(v11 + 8));
printf("???: %-15d???: %d\n", v27, v26);
if ( *(_BYTE *)(v11 + 40) == 2 )
{
v38 = (int)htonl(*(_DWORD *)(v11 + 20));
v39 = (int)htonl(*(_DWORD *)(v11 + 24)) * v38;
v40 = htonl(*(_DWORD *)(v11 + 20));
v41 = htonl(*(_DWORD *)(v11 + 24));
printf("Size: %d blocks of %d bytes (%llu)\n", v41, v40, v39);
v42 = (int)htonl(*(_DWORD *)(v11 + 32));
v43 = (int)htonl(*(_DWORD *)(v11 + 28)) * v42;
v44 = htonl(*(_DWORD *)(v11 + 28));
v45 = htonl(*(_DWORD *)(v11 + 32));
printf("Used: %d blocks of %d bytes (%llu)\n", v45, v44, v43);
}
else
{
v28 = htonl(*(_DWORD *)(v11 + 24));
printf("Size: %d bytes\n", v28);
}
v29 = htonl(*(_DWORD *)(v11 + 52));
printf("Checksum: %08x Flags(?): %d\n", *(unsigned int *)(v11 + 48), v29);
v30 = htonl(*(_DWORD *)(v11 + 44));
LOWORD(v31) = htons(*(_WORD *)(v11 + 42));
printf("Sigs: %02x %04x %08x (Always 02 beef 91231ebc?)\n", *(unsigned __int8 *)(v11 + 41), v31, v30);
if ( htonl(*(_DWORD *)(v11 + 56)) )
{
v32 = 0LL;
v33 = htonl(*(_DWORD *)(v11 + 56));
printf("Data is in %d blocks:\n", v33);
while ( (int)htonl(*(_DWORD *)(v11 + 56)) > (int)v32 )
{
v34 = htonl(*(_DWORD *)(v11 + 8 * v32 + 64));
v35 = *(_DWORD *)(v11 + 8 * v32++ + 60);
v36 = v34;
v37 = htonl(v35);
printf("At %-8x %d sectors\n", v37, v36);
}
}
else
{
v8 = 0;
puts("Data is in inode block.");
}
return v8;
}
}
printf("???");
goto LABEL_54;
}
LABEL_39:
write(1, (const void *)v11, v5);
return v8;
}
v18 = (unsigned __int8 *)calloc(v2, 0x200uLL);
v12 = v18;
if ( !v18 )
{
v8 = 1;
fprintf(stderr, "%s: Couldn't allocate %d bytes!\n", (const char *)progname, v2 << 9);
return v8;
}
if ( v11 )
{
v47 = (__int64)v18;
v19 = mfs_read_inode_data_part(mfs, v11, v18, v3, v2);
v20 = v47;
v5 = v19;
if ( v19 > 0 )
goto LABEL_37;
LABEL_48:
v8 = 1;
mfs_perror(mfs, "Read data");
return v8;
}
v48 = (__int64)v18;
v21 = mfsvol_read_data(*(_QWORD *)mfs, v18, v3, v2);
v20 = v48;
v5 = v21;
if ( v21 <= 0 )
goto LABEL_48;
LABEL_37:
if ( v46 == 2 )
{
v11 = v20;
goto LABEL_39;
}
LABEL_28:
v13 = v5;
v14 = v3;
do
{
v15 = -559038737;
v16 = v13;
v17 = v12;
if ( v3 != -559038737 )
v15 = v14;
v13 -= 512;
++v14;
v12 += 512;
func1(v17, v15, v16);
}
while ( v5 - v13 < v5 );
return v8;
}

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