decompiled_code:
__int64 __fastcall open_socket_out(char *name, __int16 a2)
{
unsigned int v2; // ebx
struct hostent *v3; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int optval; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v12 = 1;
optval = 0xFFFF;
v2 = socket(2, 1, 0);
if ( v2 != -1 )
{
v3 = gethostbyname(name);
if ( v3 )
{
memcpy(&addr.sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)addr.sa_data = _bswap_16(a2);
addr.sa_family = 2;
if ( connect(v2, &addr, 0x10u) )
{
close(v2);
if ( !use_syslog )
goto LABEL_20;
if ( fileno(stderr) == 2 )
{
v7 = _errno_location();
v8 = strerror(*v7);
syslog(3, "failed to connect to %s - %s\n", name, v8);
return (unsigned int)-1;
}
if ( fileno(stderr) != 1 )
{
LABEL_20:
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "failed to connect to %s - %s\n", name, v10);
return (unsigned int)-1;
}
v2 = -1;
if ( use_syslog > 1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(6, "failed to connect to %s - %s\n", name, v6);
}
}
else
{
setsockopt(v2, 1, 8, &optval, 4u);
setsockopt(v2, 6, 1, &v12, 4u);
}
}
else
{
if ( !use_syslog )
goto LABEL_12;
if ( fileno(stderr) == 2 )
{
syslog(3, "unknown host: %s\n", name);
return (unsigned int)-1;
}
if ( fileno(stderr) != 1 )
{
LABEL_12:
fprintf(stderr, "unknown host: %s\n", name);
return (unsigned int)-1;
}
v2 = -1;
if ( use_syslog > 1 )
syslog(6, "unknown host: %s\n", name);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *name, __int16 a2)
{
unsigned int v2; // ebx
struct hostent *v3; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int optval; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v12 = 1;
optval = 0xFFFF;
v2 = socket(2, 1, 0);
if ( v2 != -1 )
{
v3 = gethostbyname(name);
if ( v3 )
{
memcpy(&addr.sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)addr.sa_data = func0(a2);
addr.sa_family = 2;
if ( connect(v2, &addr, 0x10u) )
{
close(v2);
if ( !use_syslog )
goto LABEL_20;
if ( fileno(stderr) == 2 )
{
v7 = _errno_location();
v8 = strerror(*v7);
syslog(3, "failed to connect to %s - %s\n", name, v8);
return (unsigned int)-1;
}
if ( fileno(stderr) != 1 )
{
LABEL_20:
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "failed to connect to %s - %s\n", name, v10);
return (unsigned int)-1;
}
v2 = -1;
if ( use_syslog > 1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(6, "failed to connect to %s - %s\n", name, v6);
}
}
else
{
setsockopt(v2, 1, 8, &optval, 4u);
setsockopt(v2, 6, 1, &v12, 4u);
}
}
else
{
if ( !use_syslog )
goto LABEL_12;
if ( fileno(stderr) == 2 )
{
syslog(3, "unknown host: %s\n", name);
return (unsigned int)-1;
}
if ( fileno(stderr) != 1 )
{
LABEL_12:
fprintf(stderr, "unknown host: %s\n", name);
return (unsigned int)-1;
}
v2 = -1;
if ( use_syslog > 1 )
syslog(6, "unknown host: %s\n", name);
}
}
return v2;
}

original_code:
int open_socket_out(char *host, int port)
{
 int type = SOCK_STREAM;
 struct sockaddr_in sock_out;
 int res;
 struct hostent *hp;
 int nodelay = 1;
 int window = 65535;
 res = socket(2, type, 0);
 if (res == -1) {
  return -1;
 }
 hp = gethostbyname(host);
 if (!hp) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "unknown host: %s\n", host),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"unknown host: %s\n", host),1) : 1) : fprintf((stderr),"unknown host: %s\n", host)) : fprintf((stderr),"unknown host: %s\n", host));
  return -1;
 }
 memcpy(&sock_out.sin_addr, hp->h_addr_list[0], hp->h_length);
 sock_out.sin_port = htons(port);
 sock_out.sin_family = 2;
 if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out))) {
  close(res);
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "failed to connect to %s - %s\n", host, strerror((*__errno_location ()))),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"failed to connect to %s - %s\n", host, strerror((*__errno_location ()))),1) : 1) : fprintf((stderr),"failed to connect to %s - %s\n", host, strerror((*__errno_location ())))) : fprintf((stderr),"failed to connect to %s - %s\n", host, strerror((*__errno_location ()))));
  return -1;
 }
 setsockopt(res, 1, 8, &window, sizeof(int));
 setsockopt(res, IPPROTO_TCP, 1, &nodelay, sizeof(int));
 return res;
}

variable_types:
host
char *

variable_types: port int

variable_types: type int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: res int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: nodelay int

variable_types: window int

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


decompiled_code:
__off64_t __fastcall ll_seek(int a1, __off64_t a2, int a3)
{
__off64_t result; // rax

result = lseek64(a1, a2, a3);
if ( result == -1 )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "llseek failed\n");
goto LABEL_9;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "llseek failed\n");
}
else
{
LABEL_8:
fwrite("llseek failed\n", 1uLL, 0xEuLL, stderr);
}
LABEL_9:
exit(1);
}
return result;
}

canonical_decompiled_code:
__off64_t __fastcall func6(int a1, __off64_t a2, int a3)
{
__off64_t result; // rax

result = lseek64(a1, a2, a3);
if ( result == -1 )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "llseek failed\n");
goto LABEL_9;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "llseek failed\n");
}
else
{
LABEL_8:
fwrite("llseek failed\n", 1uLL, 0xEuLL, stderr);
}
LABEL_9:
exit(1);
}
return result;
}

original_code:
u64 ll_seek(int fd, u64 offset, int whence)
{
 u64 result;
 int ret = 0;
 result = lseek(fd, offset, whence);
 if(ret || (result == (off_t)-1))
 {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "llseek failed\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"llseek failed\n"),1) : 1) : fprintf((stderr),"llseek failed\n")) : fprintf((stderr),"llseek failed\n"));
  exit(1);
 }
 return result;
}

canonical_original_code:
unsigned int ll_seek(int fd, unsigned int offset, int whence)
{
 unsigned int result;
 int ret = 0;
 result = lseek(fd, offset, whence);
 if(ret || (result == (off_t)-1))
 {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "llseek failed\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"llseek failed\n"),1) : 1) : fprintf((stderr),"llseek failed\n")) : fprintf((stderr),"llseek failed\n"));
  exit(1);
 }
 return result;
}

variable_types: fd int

variable_types:
offset
unsigned int

variable_types: whence int

variable_types:
result
unsigned int

variable_types: ret int

return_type: unsigned int


decompiled_code:
ssize_t __fastcall read_sectors(int fd, void *buf, unsigned int a3, int a4)
{
ll_seek(fd, (unsigned __int64)a3 << 9, 0);
return read(fd, buf, (unsigned int)(a4 << 9)) >> 9;
}

canonical_decompiled_code:
ssize_t __fastcall func7(int fd, void *buf, unsigned int a3, int a4)
{
func6(fd, (unsigned __int64)a3 << 9, 0);
return read(fd, buf, (unsigned int)(a4 << 9)) >> 9;
}

original_code:
u32 read_sectors(int fd, void *buf, u32 sector, u32 count)
{
 ll_seek(fd, ((u64)sector)<<9, 0);
 return read(fd, buf, count * 512)>>9;
}

canonical_original_code:
unsigned int read_sectors(int fd, void *buf, unsigned int sector, unsigned int count)
{
 ll_seek(fd, ((unsigned int)sector)<<9, 0);
 return read(fd, buf, count * 512)>>9;
}

variable_types:
buf
void *

variable_types:
sector
unsigned int

variable_types:
count
unsigned int


decompiled_code:
ssize_t __fastcall write_sectors(int fd, void *buf, unsigned int a3, int a4)
{
if ( fs_inconsistent )
{
if ( !use_syslog )
goto LABEL_9;
if ( fileno(stderr) == 2 )
{
syslog(3, "Filesystem is inconsistent, cannot write\n");
goto LABEL_10;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Filesystem is inconsistent, cannot write\n");
}
else
{
LABEL_9:
fwrite("Filesystem is inconsistent, cannot write\n", 1uLL, 0x29uLL, stderr);
}
LABEL_10:
exit(1);
}
ll_seek(fd, (unsigned __int64)a3 << 9, 0);
return write(fd, buf, (unsigned int)(a4 << 9)) >> 9;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, void *buf, unsigned int a3, int a4)
{
if ( fs_inconsistent )
{
if ( !use_syslog )
goto LABEL_9;
if ( fileno(stderr) == 2 )
{
syslog(3, "Filesystem is inconsistent, cannot write\n");
goto LABEL_10;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Filesystem is inconsistent, cannot write\n");
}
else
{
LABEL_9:
fwrite("Filesystem is inconsistent, cannot write\n", 1uLL, 0x29uLL, stderr);
}
LABEL_10:
exit(1);
}
func6(fd, (unsigned __int64)a3 << 9, 0);
return write(fd, buf, (unsigned int)(a4 << 9)) >> 9;
}

original_code:
u32 write_sectors(int fd, void *buf, u32 sector, u32 count)
{
 if(fs_inconsistent)
 {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Filesystem is inconsistent, cannot write\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Filesystem is inconsistent, cannot write\n"),1) : 1) : fprintf((stderr),"Filesystem is inconsistent, cannot write\n")) : fprintf((stderr),"Filesystem is inconsistent, cannot write\n"));
  exit(1);
 }
 {
 ll_seek(fd, ((u64)sector)<<9, 0);
 return write(fd, buf, count * 512)>>9;
 }
}

canonical_original_code:
unsigned int write_sectors(int fd, void *buf, unsigned int sector, unsigned int count)
{
 if(fs_inconsistent)
 {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Filesystem is inconsistent, cannot write\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Filesystem is inconsistent, cannot write\n"),1) : 1) : fprintf((stderr),"Filesystem is inconsistent, cannot write\n")) : fprintf((stderr),"Filesystem is inconsistent, cannot write\n"));
  exit(1);
 }
 {
 ll_seek(fd, ((unsigned int)sector)<<9, 0);
 return write(fd, buf, count * 512)>>9;
 }
}


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

result = fcntl64(a1, 3LL, 0LL);
if ( (_DWORD)result != -1 && (result & 0x800) == 0 )
{
BYTE1(result) |= 8u;
result = fcntl64((unsigned int)a1, 4LL, (unsigned int)result);
}
return result;
}

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

result = fcntl64(a1, 3LL, 0LL);
if ( (_DWORD)result != -1 && (result & 0x800) == 0 )
{
BYTE1(result) |= 8u;
result = fcntl64((unsigned int)a1, 4LL, (unsigned int)result);
}
return result;
}

original_code:
void set_nonblocking(int fd)
{
 int val;
 if((val = fcntl(fd, 3, 0)) == -1)
  return;
 if (!(val & 04000)) {
  val |= 04000;
  fcntl(fd, 4, val);
 }
}

variable_types: val int

return_type: void


decompiled_code:
__int64 __fastcall bitcount32(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

original_code:
int bitcount32(u32 x)
{
 int count;
 for (count=0; x; count++)
  x &= (x-1);
 return count;
}

canonical_original_code:
int bitcount32(unsigned int x)
{
 int count;
 for (count=0; x; count++)
  x &= (x-1);
 return count;
}

variable_types:
x
unsigned int

variable_types: count int

return_type: int


decompiled_code:
int mls_usage()
{
return fprintf(stderr, "Usage:\n%s [/dev/hda [/dev/hdb]] /path", (const char *)progname);
}

canonical_decompiled_code:
int func1()
{
return fprintf(stderr, "Usage:\n%s [/dev/hda [/dev/hdb]] /path", (const char *)progname);
}

original_code:
void
mls_usage ()
{
 fprintf (stderr, "Usage:\n%s [/dev/hda [/dev/hdb]] /path", progname);
}

canonical_original_code:
void mls_usage()
{
 fprintf (stderr, "Usage:\n%s [/dev/hda [/dev/hdb]] /path", progname);
}


decompiled_code:
__int64 __fastcall find_file_by_name(__int64 a1, unsigned int a2, const char *a3)
{
int v4; // ebp
__int64 v5; // rbx

if ( a2 <= 4 )
return 0LL;
v4 = 4;
while ( 1 )
{
v5 = a1 + v4;
if ( !strcmp((const char *)(v5 + 6), a3) )
break;
v4 += *(unsigned __int8 *)(v5 + 4);
if ( v4 >= a2 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, const char *a3)
{
int v4; // ebp
__int64 v5; // rbx

if ( a2 <= 4 )
return 0LL;
v4 = 4;
while ( 1 )
{
v5 = a1 + v4;
if ( !strcmp((const char *)(v5 + 6), a3) )
break;
v4 += *(unsigned __int8 *)(v5 + 4);
if ( v4 >= a2 )
return 0LL;
}
return v5;
}

original_code:
fs_entry *
find_file_by_name (unsigned char *dir, unsigned int dirlen, unsigned char *name)
{
 int offset = 4;
 while (offset < dirlen)
 {
  fs_entry *cur = (fs_entry *) (dir + offset);
  if (!strcmp (cur->name, name))
  {
   return cur;
  }
  offset += cur->entry_length;
 }
 return 0;
}

canonical_original_code:
struct fs_entry_s *find_file_by_name(unsigned char *dir, unsigned int dirlen, unsigned char *name)
{
 int offset = 4;
 while (offset < dirlen)
 {
  struct fs_entry_s *cur = (fs_entry *) (dir + offset);
  if (!strcmp (cur->name, name))
  {
   return cur;
  }
  offset += cur->entry_length;
 }
 return 0;
}

variable_types:
dir
unsigned char *

variable_types:
dirlen
unsigned int

variable_types:
name
unsigned char *

variable_types: offset int

variable_types: struct fs_entry_s { unsigned int fsid; unsigned char entry_length; enum fsid_type_e { tyNone=0, tyFile=1, tyStream=2, tyDir=4, tyDb=8 } type; unsigned char name[]; } *

user_defined_types: struct fs_entry_s { unsigned int fsid; unsigned char entry_length; enum fsid_type_e type; unsigned char name[]; }


decompiled_code:
void __fastcall print_file_details(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rax
unsigned int *v3; // rbp
struct tm *v4; // rax
unsigned __int8 v5; // al
__int64 v6; // r14
__int64 v7; // r13
unsigned int v8; // er12
unsigned int v9; // eax
const char *v10; // r13
unsigned int v11; // er12
unsigned int v12; // eax
unsigned __int8 v13; // al
time_t timer; // [rsp+8h] [rbp-50h] BYREF
char s[72]; // [rsp+10h] [rbp-48h] BYREF

strcpy(s, "xx/xx/xx xx:xx");
s[16] = 0;
v1 = _bswap_32(*(_DWORD *)a1);
v2 = mfs_read_inode_by_fsid(mfs, v1);
v3 = (unsigned int *)v2;
if ( !v2 )
{
v13 = *(_BYTE *)(a1 + 5);
if ( v13 != 4 )
{
if ( v13 > 4u )
{
if ( v13 == 8 )
goto LABEL_10;
}
else
{
if ( v13 == 1 )
{
v10 = "tyFile";
v11 = -1;
goto LABEL_15;
}
if ( v13 == 2 )
goto LABEL_6;
}
goto LABEL_27;
}
LABEL_12:
v10 = "tyDir";
goto LABEL_13;
}
timer = (unsigned int)_bswap_32(*(_DWORD *)(v2 + 36));
v4 = localtime(&timer);
strftime(s, 0x10uLL, "%D %R", v4);
v5 = *(_BYTE *)(a1 + 5);
if ( v5 == 4 )
goto LABEL_12;
if ( v5 > 4u )
{
if ( v5 == 8 )
{
LABEL_10:
v10 = "tyDb";
goto LABEL_13;
}
LABEL_27:
v10 = "ty???";
LABEL_13:
v11 = -1;
if ( !v3 )
{
LABEL_15:
v12 = _bswap_32(*(_DWORD *)a1);
printf(" %-26s%-8s%8d%16s%7d\n", (const char *)(a1 + 6), v10, v12, s, v11);
goto LABEL_16;
}
LABEL_14:
v11 = _bswap_32(v3[6]);
goto LABEL_15;
}
if ( v5 == 1 )
{
v10 = "tyFile";
goto LABEL_14;
}
if ( v5 != 2 )
goto LABEL_27;
LABEL_6:
if ( v3 )
{
v6 = (unsigned int)_bswap_32(v3[8]);
v7 = (unsigned int)_bswap_32(v3[6]);
v8 = _bswap_32(v3[7]);
}
else
{
v7 = 0xFFFFFFFFLL;
v6 = 0xFFFFFFFFLL;
v8 = -1;
}
v9 = _bswap_32(*(_DWORD *)a1);
printf(" %-26s%-8s%8d%16s%7d x %d(%d)\n", (const char *)(a1 + 6), "tyStream", v9, s, v8, v7, v6);
LABEL_16:
if ( v3 )
free(v3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rax
unsigned int *v3; // rbp
struct tm *v4; // rax
unsigned __int8 v5; // al
__int64 v6; // r14
__int64 v7; // r13
unsigned int v8; // er12
unsigned int v9; // eax
const char *v10; // r13
unsigned int v11; // er12
unsigned int v12; // eax
unsigned __int8 v13; // al
time_t timer; // [rsp+8h] [rbp-50h] BYREF
char s[72]; // [rsp+10h] [rbp-48h] BYREF

strcpy(s, "xx/xx/xx xx:xx");
s[16] = 0;
v1 = func0(*(_DWORD *)a1);
v2 = mfs_read_inode_by_fsid(mfs, v1);
v3 = (unsigned int *)v2;
if ( !v2 )
{
v13 = *(_BYTE *)(a1 + 5);
if ( v13 != 4 )
{
if ( v13 > 4u )
{
if ( v13 == 8 )
goto LABEL_10;
}
else
{
if ( v13 == 1 )
{
v10 = "tyFile";
v11 = -1;
goto LABEL_15;
}
if ( v13 == 2 )
goto LABEL_6;
}
goto LABEL_27;
}
LABEL_12:
v10 = "tyDir";
goto LABEL_13;
}
timer = (unsigned int)func0(*(_DWORD *)(v2 + 36));
v4 = localtime(&timer);
strftime(s, 0x10uLL, "%D %R", v4);
v5 = *(_BYTE *)(a1 + 5);
if ( v5 == 4 )
goto LABEL_12;
if ( v5 > 4u )
{
if ( v5 == 8 )
{
LABEL_10:
v10 = "tyDb";
goto LABEL_13;
}
LABEL_27:
v10 = "ty???";
LABEL_13:
v11 = -1;
if ( !v3 )
{
LABEL_15:
v12 = func0(*(_DWORD *)a1);
printf(" %-26s%-8s%8d%16s%7d\n", (const char *)(a1 + 6), v10, v12, s, v11);
goto LABEL_16;
}
LABEL_14:
v11 = func0(v3[6]);
goto LABEL_15;
}
if ( v5 == 1 )
{
v10 = "tyFile";
goto LABEL_14;
}
if ( v5 != 2 )
goto LABEL_27;
LABEL_6:
if ( v3 )
{
v6 = (unsigned int)func0(v3[8]);
v7 = (unsigned int)func0(v3[6]);
v8 = func0(v3[7]);
}
else
{
v7 = 0xFFFFFFFFLL;
v6 = 0xFFFFFFFFLL;
v8 = -1;
}
v9 = func0(*(_DWORD *)a1);
printf(" %-26s%-8s%8d%16s%7d x %d(%d)\n", (const char *)(a1 + 6), "tyStream", v9, s, v8, v7, v6);
LABEL_16:
if ( v3 )
free(v3);
}

original_code:
void
print_file_details (fs_entry * file)
{
 unsigned char *type = "ty???";
 unsigned char date[17] = "xx/xx/xx xx:xx";
 mfs_inode *nfo;
 time_t modtime;
 nfo = mfs_read_inode_by_fsid (mfs, htonl (file->fsid));
 if (nfo)
 {
  modtime = htonl (nfo->lastmodified);
  strftime (date, 16, "%D %R", localtime (&modtime));
 }
 switch (file->type)
 {
 case tyFile:
  type = "tyFile";
  break;
 case tyStream:
  type = "tyStream";
  break;
 case tyDir:
  type = "tyDir";
  break;
 case tyDb:
  type = "tyDb";
  break;
 default:
  type = "ty???";
  break;
 }
 if (file->type == tyStream)
 {
  printf ("    %-26s%-8s%8d%16s%7d x %d(%d)\n", file->name, type, htonl (file->fsid), date, nfo ? htonl (nfo->blocksize) : -1, nfo ? htonl (nfo->size) : -1, nfo ? htonl (nfo->blockused) : -1);
 }
 else
 {
  printf ("    %-26s%-8s%8d%16s%7d\n", file->name, type, htonl (file->fsid), date, nfo ? htonl (nfo->size) : -1);
 }
 if (nfo)
  free (nfo);
}

canonical_original_code:
void print_file_details(struct fs_entry_s *file)
{
 unsigned char *type = "ty???";
 unsigned char date[17] = "xx/xx/xx xx:xx";
 struct mfs_inode_s *nfo;
 long modtime;
 nfo = mfs_read_inode_by_fsid (mfs, htonl (file->fsid));
 if (nfo)
 {
  modtime = htonl (nfo->lastmodified);
  strftime (date, 16, "%D %R", localtime (&modtime));
 }
 switch (file->type)
 {
 case tyFile:
  type = "tyFile";
  break;
 case tyStream:
  type = "tyStream";
  break;
 case tyDir:
  type = "tyDir";
  break;
 case tyDb:
  type = "tyDb";
  break;
 default:
  type = "ty???";
  break;
 }
 if (file->type == tyStream)
 {
  printf ("    %-26s%-8s%8d%16s%7d x %d(%d)\n", file->name, type, htonl (file->fsid), date, nfo ? htonl (nfo->blocksize) : -1, nfo ? htonl (nfo->size) : -1, nfo ? htonl (nfo->blockused) : -1);
 }
 else
 {
  printf ("    %-26s%-8s%8d%16s%7d\n", file->name, type, htonl (file->fsid), date, nfo ? htonl (nfo->size) : -1);
 }
 if (nfo)
  free (nfo);
}

variable_types:
type
unsigned char *

variable_types:
date
unsigned char [17]

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: modtime long

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


decompiled_code:
void __fastcall list_file(char *s)
{
char *v1; // rbx
void *v2; // r14
__int64 v3; // r15
void *v4; // r13
__int64 v5; // rax
unsigned int v6; // eax
int i; // ebp
char *v8; // rax
char *v9; // r12
__int64 v10; // rbx
unsigned int v11; // eax
__int64 v12; // r12
signed int j; // ebp
unsigned int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v14[0] = 0;
if ( !s )
{
v2 = (void *)mfs_read_inode_by_fsid(mfs, 1LL);
if ( v2 )
{
v1 = "/";
goto LABEL_4;
}
LABEL_5:
mfs_perror(mfs, "Read root directory");
exit(1);
}
v1 = s;
v2 = (void *)mfs_read_inode_by_fsid(mfs, 1LL);
if ( !v2 )
goto LABEL_5;
if ( !*s )
{
puts(" Name Type FsId Date Time Size");
puts(" ---- ---- ---- ---- ---- ----");
v4 = 0LL;
LABEL_23:
free(v2);
v10 = mfs_read_inode_by_fsid(mfs, 1LL);
goto LABEL_27;
}
LABEL_4:
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
for ( i = 0; *v1 == 47; ++i )
++v1;
v8 = strchr(v1, 47);
v9 = v8;
if ( v8 )
*v8 = 0;
if ( !*v1 )
break;
if ( v4 )
free(v4);
v5 = mfs_read_inode_data(mfs, v2, v14);
v4 = (void *)v5;
if ( !v5 )
{
mfs_perror(mfs, "Read directory");
exit(1);
}
v3 = find_file_by_name(v5, v14[0], v1);
if ( !v3 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
free(v2);
v6 = _bswap_32(*(_DWORD *)v3);
v2 = (void *)mfs_read_inode_by_fsid(mfs, v6);
if ( !v2 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( !v9 )
{
i = 0;
goto LABEL_36;
}
*v9 = 47;
v1 = v9 + 1;
if ( !v9[1] )
{
i = 1;
LABEL_36:
puts(" Name Type FsId Date Time Size");
puts(" ---- ---- ---- ---- ---- ----");
goto LABEL_37;
}
}
puts(" Name Type FsId Date Time Size");
puts(" ---- ---- ---- ---- ---- ----");
if ( !v3 )
goto LABEL_23;
LABEL_37:
if ( *(_BYTE *)(v3 + 5) != 4 || !i )
{
print_file_details(v3);
return;
}
free(v2);
v11 = _bswap_32(*(_DWORD *)v3);
v10 = mfs_read_inode_by_fsid(mfs, v11);
LABEL_27:
if ( !v10 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( v4 )
free(v4);
v12 = mfs_read_inode_data(mfs, v10, v14);
if ( !v12 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
for ( j = 4; j < v14[0]; j += *(unsigned __int8 *)(v12 + j + 4) )
print_file_details(v12 + j);
}

canonical_decompiled_code:
void __fastcall func4(char *s)
{
char *v1; // rbx
void *v2; // r14
__int64 v3; // r15
void *v4; // r13
__int64 v5; // rax
unsigned int v6; // eax
int i; // ebp
char *v8; // rax
char *v9; // r12
__int64 v10; // rbx
unsigned int v11; // eax
__int64 v12; // r12
signed int j; // ebp
unsigned int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v14[0] = 0;
if ( !s )
{
v2 = (void *)mfs_read_inode_by_fsid(mfs, 1LL);
if ( v2 )
{
v1 = "/";
goto LABEL_4;
}
LABEL_5:
mfs_perror(mfs, "Read root directory");
exit(1);
}
v1 = s;
v2 = (void *)mfs_read_inode_by_fsid(mfs, 1LL);
if ( !v2 )
goto LABEL_5;
if ( !*s )
{
puts(" Name Type FsId Date Time Size");
puts(" ---- ---- ---- ---- ---- ----");
v4 = 0LL;
LABEL_23:
free(v2);
v10 = mfs_read_inode_by_fsid(mfs, 1LL);
goto LABEL_27;
}
LABEL_4:
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
for ( i = 0; *v1 == 47; ++i )
++v1;
v8 = strchr(v1, 47);
v9 = v8;
if ( v8 )
*v8 = 0;
if ( !*v1 )
break;
if ( v4 )
free(v4);
v5 = mfs_read_inode_data(mfs, v2, v14);
v4 = (void *)v5;
if ( !v5 )
{
mfs_perror(mfs, "Read directory");
exit(1);
}
v3 = func2(v5, v14[0], v1);
if ( !v3 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
free(v2);
v6 = func0(*(_DWORD *)v3);
v2 = (void *)mfs_read_inode_by_fsid(mfs, v6);
if ( !v2 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( !v9 )
{
i = 0;
goto LABEL_36;
}
*v9 = 47;
v1 = v9 + 1;
if ( !v9[1] )
{
i = 1;
LABEL_36:
puts(" Name Type FsId Date Time Size");
puts(" ---- ---- ---- ---- ---- ----");
goto LABEL_37;
}
}
puts(" Name Type FsId Date Time Size");
puts(" ---- ---- ---- ---- ---- ----");
if ( !v3 )
goto LABEL_23;
LABEL_37:
if ( *(_BYTE *)(v3 + 5) != 4 || !i )
{
func3(v3);
return;
}
free(v2);
v11 = func0(*(_DWORD *)v3);
v10 = mfs_read_inode_by_fsid(mfs, v11);
LABEL_27:
if ( !v10 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( v4 )
free(v4);
v12 = mfs_read_inode_data(mfs, v10, v14);
if ( !v12 )
{
fwrite("No such file or directory!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
for ( j = 4; j < v14[0]; j += *(unsigned __int8 *)(v12 + j + 4) )
func3(v12 + j);
}

original_code:
void
list_file (unsigned char *name)
{
 mfs_inode *cur_nfo = 0;
 unsigned char *cur_dir = 0;
 unsigned int cur_dir_length = 0;
 fs_entry *cur_file = 0;
 int trailingslash = 0;
 if (!name)
 {
  name = "/";
 }
 cur_nfo = mfs_read_inode_by_fsid (mfs, 1);
 if (!cur_nfo)
 {
  mfs_perror (mfs, "Read root directory");
  exit (1);
 }
 while (*name)
 {
  char *next;
  trailingslash = 0;
  while (*name == '/')
   name++, trailingslash++;
  next = strchr (name, '/');
  if (next)
   *next = 0;
  if (!*name)
  {
   break;
  }
  if (cur_dir)
   free (cur_dir);
  cur_dir = mfs_read_inode_data (mfs, cur_nfo, &cur_dir_length);
  if (!cur_dir)
  {
   mfs_perror (mfs, "Read directory");
   exit (1);
  }
  cur_file = find_file_by_name (cur_dir, cur_dir_length, name);
  if (!cur_file)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  free (cur_nfo);
  cur_nfo = mfs_read_inode_by_fsid (mfs, htonl (cur_file->fsid));
  if (!cur_nfo)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  if (next)
  {
   *next = '/';
   trailingslash = 1;
   name = next + 1;
  }
  else
  {
   trailingslash = 0;
   break;
  }
 }
 printf ("    Name                      Type        FsId      Date  Time   Size\n");
 printf ("    ----                      ----        ----      ----  ----   ----\n");
 if (!cur_file || (cur_file->type == tyDir && trailingslash))
 {
  int offset = 4;
  free (cur_nfo);
  if (cur_file)
  {
   cur_nfo = mfs_read_inode_by_fsid (mfs, htonl (cur_file->fsid));
  }
  else
  {
   cur_nfo = mfs_read_inode_by_fsid (mfs, 1);
  }
  if (!cur_nfo)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  if (cur_dir)
   free (cur_dir);
  cur_dir = mfs_read_inode_data (mfs, cur_nfo, &cur_dir_length);
  if (!cur_dir)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  for (offset = 4; offset < cur_dir_length; offset += cur_file->entry_length)
  {
   cur_file = (fs_entry *) (cur_dir + offset);
   print_file_details (cur_file);
  }
 }
 else
 {
  print_file_details (cur_file);
 }
}

canonical_original_code:
void list_file(unsigned char *name)
{
 struct mfs_inode_s *cur_nfo = 0;
 unsigned char *cur_dir = 0;
 unsigned int cur_dir_length = 0;
 struct fs_entry_s *cur_file = 0;
 int trailingslash = 0;
 if (!name)
 {
  name = "/";
 }
 cur_nfo = mfs_read_inode_by_fsid (mfs, 1);
 if (!cur_nfo)
 {
  mfs_perror (mfs, "Read root directory");
  exit (1);
 }
 while (*name)
 {
  char *next;
  trailingslash = 0;
  while (*name == '/')
   name++, trailingslash++;
  next = strchr (name, '/');
  if (next)
   *next = 0;
  if (!*name)
  {
   break;
  }
  if (cur_dir)
   free (cur_dir);
  cur_dir = mfs_read_inode_data (mfs, cur_nfo, &cur_dir_length);
  if (!cur_dir)
  {
   mfs_perror (mfs, "Read directory");
   exit (1);
  }
  cur_file = find_file_by_name (cur_dir, cur_dir_length, name);
  if (!cur_file)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  free (cur_nfo);
  cur_nfo = mfs_read_inode_by_fsid (mfs, htonl (cur_file->fsid));
  if (!cur_nfo)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  if (next)
  {
   *next = '/';
   trailingslash = 1;
   name = next + 1;
  }
  else
  {
   trailingslash = 0;
   break;
  }
 }
 printf ("    Name                      Type        FsId      Date  Time   Size\n");
 printf ("    ----                      ----        ----      ----  ----   ----\n");
 if (!cur_file || (cur_file->type == tyDir && trailingslash))
 {
  int offset = 4;
  free (cur_nfo);
  if (cur_file)
  {
   cur_nfo = mfs_read_inode_by_fsid (mfs, htonl (cur_file->fsid));
  }
  else
  {
   cur_nfo = mfs_read_inode_by_fsid (mfs, 1);
  }
  if (!cur_nfo)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  if (cur_dir)
   free (cur_dir);
  cur_dir = mfs_read_inode_data (mfs, cur_nfo, &cur_dir_length);
  if (!cur_dir)
  {
   fprintf (stderr, "No such file or directory!\n");
   exit (1);
  }
  for (offset = 4; offset < cur_dir_length; offset += cur_file->entry_length)
  {
   cur_file = (struct fs_entry_s *) (cur_dir + offset);
   print_file_details (cur_file);
  }
 }
 else
 {
  print_file_details (cur_file);
 }
}

variable_types: trailingslash int

variable_types:
next
char *

user_defined_types: enum fsid_type_e { tyNone=0, tyFile=1, tyStream=2, tyDir=4, tyDb=8 }


decompiled_code:
__int64 __fastcall mls_main(int a1, _QWORD *a2)
{
char *v2; // rax
const char *v3; // rbp
char *v4; // r12
__int64 v5; // rdi
unsigned int v6; // ebp
char *v8; // r13

v3 = (const char *)a2[1];
progname = *a2;
if ( a1 <= 2 )
{
v8 = getenv("MFS_HDA");
v2 = getenv("MFS_HDB");
if ( v8 )
{
v4 = (char *)v3;
if ( *v8 )
{
v3 = v8;
}
else
{
v2 = "/dev/hdb";
v3 = "/dev/hda";
}
}
else
{
v4 = (char *)v3;
v2 = "/dev/hdb";
v3 = "/dev/hda";
}
}
else
{
v4 = (char *)a2[2];
if ( a1 > 3 )
{
if ( a1 > 4 )
{
mls_usage();
return 1;
}
v2 = (char *)a2[2];
v4 = (char *)a2[3];
}
}
v5 = mfs_init(v3, v2, 0LL);
mfs = v5;
if ( v5 )
{
v6 = mfs_has_error(v5);
if ( v6 )
{
mfs_perror(mfs, *a2);
v6 = 1;
}
else
{
list_file(v4);
}
}
else
{
fwrite("mfs_init: Failed. Bailing.\n", 1uLL, 0x1CuLL, stderr);
v6 = 1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, _QWORD *a2)
{
char *v2; // rax
const char *v3; // rbp
char *v4; // r12
__int64 v5; // rdi
unsigned int v6; // ebp
char *v8; // r13

v3 = (const char *)a2[1];
progname = *a2;
if ( a1 <= 2 )
{
v8 = getenv("MFS_HDA");
v2 = getenv("MFS_HDB");
if ( v8 )
{
v4 = (char *)v3;
if ( *v8 )
{
v3 = v8;
}
else
{
v2 = "/dev/hdb";
v3 = "/dev/hda";
}
}
else
{
v4 = (char *)v3;
v2 = "/dev/hdb";
v3 = "/dev/hda";
}
}
else
{
v4 = (char *)a2[2];
if ( a1 > 3 )
{
if ( a1 > 4 )
{
func1();
return 1;
}
v2 = (char *)a2[2];
v4 = (char *)a2[3];
}
}
v5 = mfs_init(v3, v2, 0LL);
mfs = v5;
if ( v5 )
{
v6 = mfs_has_error(v5);
if ( v6 )
{
mfs_perror(mfs, *a2);
v6 = 1;
}
else
{
func4(v4);
}
}
else
{
fwrite("mfs_init: Failed. Bailing.\n", 1uLL, 0x1CuLL, stderr);
v6 = 1;
}
return v6;
}

original_code:
int
mls_main (int argc, char **argv)
{
 char *arg = argv[1];
 char *hda, *hdb;
 progname = argv[0];
 if (argc > 2)
 {
  hda = argv[1];
  arg = argv[2];
  if (argc > 3)
  {
   hdb = argv[2];
   arg = argv[3];
   if (argc > 4)
   {
    mls_usage ();
    return 1;
   }
  }
 }
 else
 {
  hda = getenv ("MFS_HDA");
  hdb = getenv ("MFS_HDB");
  if (!hda || !*hda)
  {
   hda = "/dev/hda";
   hdb = "/dev/hdb";
  }
 }
 mfs = mfs_init (hda, hdb, 00);
 if (!mfs)
 {
  fprintf (stderr, "mfs_init: Failed.  Bailing.\n");
  return 1;
 }
 if (mfs_has_error (mfs))
 {
  mfs_perror (mfs, argv[0]);
  return 1;
 }
 list_file (arg);
 return 0;
}

canonical_original_code:
int mls_main(int argc, char **argv)
{
 char *arg = argv[1];
 char *hda; char *hdb;
 progname = argv[0];
 if (argc > 2)
 {
  hda = argv[1];
  arg = argv[2];
  if (argc > 3)
  {
   hdb = argv[2];
   arg = argv[3];
   if (argc > 4)
   {
    mls_usage ();
    return 1;
   }
  }
 }
 else
 {
  hda = getenv ("MFS_HDA");
  hdb = getenv ("MFS_HDB");
  if (!hda || !*hda)
  {
   hda = "/dev/hda";
   hdb = "/dev/hdb";
  }
 }
 mfs = mfs_init (hda, hdb, 00);
 if (!mfs)
 {
  fprintf (stderr, "mfs_init: Failed.  Bailing.\n");
  return 1;
 }
 if (mfs_has_error (mfs))
 {
  mfs_perror (mfs, argv[0]);
  return 1;
 }
 list_file (arg);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
arg
char *

variable_types:
hda
char *

variable_types:
hdb
char *


decompiled_code:
void __fastcall load_object(unsigned int a1)
{
int v1; // ebp

if ( loaded != a1 )
{
if ( ptr )
free(ptr);
loaded = a1;
v1 = mfs_fsid_size(a1);
dword_5C0 = v1;
ptr = malloc(v1);
mfs_fsid_pread(a1, ptr, 0LL, (unsigned int)v1);
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1)
{
int v1; // ebp

if ( loaded != a1 )
{
if ( ptr )
free(ptr);
loaded = a1;
v1 = mfs_fsid_size(a1);
dword_5C0 = v1;
ptr = malloc(v1);
mfs_fsid_pread(a1, ptr, 0LL, (unsigned int)v1);
}
}

original_code:
static void load_object(int fsid)
{
 if (fsid == loaded.fsid) return;
 if (loaded.buf) free(loaded.buf);
 loaded.fsid = fsid;
 loaded.size = mfs_fsid_size(fsid);
 loaded.buf = malloc(loaded.size);
 mfs_fsid_pread(fsid, loaded.buf, 0, loaded.size);
}

variable_types: fsid int


decompiled_code:
__int64 __fastcall query_part(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v8[3]; // [rsp+0h] [rbp-48h] BYREF
int v9; // [rsp+18h] [rbp-30h]
__int16 v10; // [rsp+1Ch] [rbp-2Ch] BYREF
unsigned int v11; // [rsp+1Eh] [rbp-2Ah]
__int16 v12; // [rsp+22h] [rbp-26h]
__int64 *v13; // [rsp+24h] [rbp-24h]
int v14; // [rsp+2Ch] [rbp-1Ch]
char *v15; // [rsp+38h] [rbp-10h]

v15 = &a7;
v9 = a2;
v8[2] = a3;
v8[1] = a4;
v10 = -17599;
v11 = (unsigned int)callback_0;
v12 = -17847;
v13 = v8;
v14 = -1864106167;
v8[0] = 0LL;
if ( (unsigned int)mfs_fsid_type() != 8 )
{
fprintf(stderr, "%d is not an object\n", a1);
exit(1);
}
load_object(a1);
parse_object(a1, ptr, &v10);
return v8[0];
}

original_code:
void *query_part(int fsid, int subobj, const char *name, int *len)
{
 void *ret = ((void *)0);
 void callback(int fsid, struct mfs_subobj_header *obj,
        struct mfs_attr_header *attr, void *data)
  {
   if (!attr) return;
   if (!(obj->flags && subobj == -1) && !(obj->id == subobj)) return;
   if (strcmp(schema_attrib(obj->obj_type, attr->attr), name)) return;
   *len = attr->len;
   ret = data;
  }
 if (mfs_fsid_type(fsid) != 8) {
  fprintf(stderr,"%d is not an object\n", fsid);
  exit(1);
 }
 load_object(fsid);
 parse_object(fsid, loaded.buf, callback);
 return ret;
}

canonical_original_code:
void *query_part(int fsid, int subobj, char *name, int *len)
{
 void *ret = ((void *)0);
 void callback(int fsid, struct mfs_subobj_header *obj,
        struct mfs_attr_header *attr, void *data)
  {
   if (!attr) return;
   if (!(obj->flags && subobj == -1) && !(obj->id == subobj)) return;
   if (strcmp(schema_attrib(obj->obj_type, attr->attr), name)) return;
   *len = attr->len;
   ret = data;
  }
 if (mfs_fsid_type(fsid) != 8) {
  fprintf(stderr,"%d is not an object\n", fsid);
  exit(1);
 }
 load_object(fsid);
 parse_object(fsid, loaded.buf, callback);
 return ret;
}

variable_types: subobj int

variable_types:
name
char *

variable_types:
len
int *

variable_types:
ret
void *

return_type: void *


original_code:
static int query_subobj_path(int fsid, int subobj, const char *path, int *len,
         void *ret[], const int max)
{
 int i=0;
 int idx = 0;
 const char *tok, *end;
 if (max <=0) return 0;
 end = strchr(path,'/');
 tok = (end) ? (__extension__ ({ const char *__old = (path); size_t __len = strnlen (__old, (end-path)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })) : path;
 ret[idx] = query_part(fsid, subobj, tok, &len[idx]);
 if (!ret[idx]) return idx;
 if (end) {
  struct mfs_obj_attr *objattr = ret[idx];
  int count = (len[idx]-4)/sizeof(*objattr);
  for (i=0;i<count;i++) {
   int n;
   fsid = ntohl(objattr->fsid);
   subobj = ntohl(objattr->subobj);
   n = query_subobj_path(
    fsid, subobj, end+1, len+idx,
    ret+idx, max-idx );
   idx += n;
   objattr++;
  }
 } else
  idx++;
 return idx;
}

canonical_original_code:
static int query_subobj_path(int fsid, int subobj, char *path, int *len, void *ret[], int max)
{
 int i = 0;
 int idx = 0;
 char *tok; char *end;
 if (max <=0) return 0;
 end = strchr(path,'/');
 tok = (end) ? (__extension__ ({ char *__old = (path); unsigned long __len = strnlen (__old, (end-path)); char *__new = (char *) __builtin_alloca (__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old, __len); })) : path;
 ret[idx] = query_part(fsid, subobj, tok, &len[idx]);
 if (!ret[idx]) return idx;
 if (end) {
  struct mfs_obj_attr *objattr = ret[idx];
  int count = (len[idx]-4)/sizeof(*objattr);
  for (i=0;i<count;i++) {
   int n;
   fsid = ntohl(objattr->fsid);
   subobj = ntohl(objattr->subobj);
   n = query_subobj_path(
    fsid, subobj, end+1, len+idx,
    ret+idx, max-idx );
   idx += n;
   objattr++;
  }
 } else
  idx++;
 return idx;
}

variable_types:
path
char *

variable_types:
ret
void *[]

variable_types: max int

variable_types: i int

variable_types: idx int

variable_types:
tok
char *

variable_types:
end
char *

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

variable_types: count int

variable_types: n int


decompiled_code:
__int64 __fastcall query_string(unsigned int a1, const char *a2)
{
bool v2; // zf
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v4 = 0LL;
v2 = (unsigned int)query_subobj_path(a1, -1, a2, v5, &v4, 1) == 1;
result = 0LL;
if ( v2 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, const char *a2)
{
bool v2; // zf
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v4 = 0LL;
v2 = (unsigned int)func4(a1, -1, a2, v5, &v4, 1) == 1;
result = 0LL;
if ( v2 )
result = v4;
return result;
}

original_code:
char *query_string(int fsid, char *path)
{
 int len = 0;
 void *p = {0};
 int n = query_subobj_path(fsid, -1, path, &len, &p, 1);
 return (n==1) ? (char *)p : 0;
}

variable_types: len int

variable_types:
p
void *

return_type: char *


decompiled_code:
__int64 __fastcall query_int(unsigned int a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
unsigned int *v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v4 = 0LL;
v2 = query_subobj_path(a1, -1, a2, v5, &v4, 1);
result = 0LL;
if ( v2 == 1 )
result = _bswap_32(*v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
unsigned int *v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
v4 = 0LL;
v2 = func4(a1, -1, a2, v5, &v4, 1);
result = 0LL;
if ( v2 == 1 )
result = func2(*v4);
return result;
}

original_code:
int query_int(int fsid, char *path)
{
 int len = 0;
 void *p = 0;
 int n = query_subobj_path(fsid, -1, path, &len, &p, 1);
 return (n==1) ? ntohl(*((int*)p)) : 0;
}

canonical_original_code:
int query_int(int fsid, char *path)
{
 int len = 0;
 void *p = 0;
 int n = query_subobj_path(fsid, -1, path, &len, &p, 1);
 return (n==1) ? ntohl(*((int *)p)) : 0;
}

variable_types: fsid int


decompiled_code:
__int64 __fastcall query_int_list(unsigned int a1, const char *a2, __int64 a3, int a4)
{
void *v5; // rsp
void *v6; // rsp
int v7; // eax
unsigned int v8; // er15
__int64 v9; // r14
__int64 i; // rbx
__int64 v12; // [rsp+0h] [rbp-30h] BYREF

v5 = alloca(16 * ((4LL * a4 + 23) / 0x10uLL));
v6 = alloca(16 * ((8LL * a4 + 23) / 0x10uLL));
v7 = query_subobj_path(a1, -1, a2, &v12, &v12, a4);
v8 = v7;
if ( v7 > 0 )
{
v9 = (unsigned int)v7;
for ( i = 0LL; i != v9; ++i )
*(_DWORD *)(a3 + 4 * i) = _bswap_32(*(_DWORD *)*(&v12 + i));
}
return v8;
}

original_code:
int query_int_list(int fsid, char *path, int ret[], int max)
{
 int i;
 int *len = __builtin_alloca (max*sizeof(int));
 void **p = __builtin_alloca (max*sizeof(void *));
 int n=query_subobj_path(fsid, -1, path, len, p, max);
 for(i=0; i<n; i++)
  ret[i] = ntohl(*((int*)p[i]));
 return n;
}

canonical_original_code:
int query_int_list(int fsid, char *path, int ret[], int max)
{
 int i;
 int *len = __builtin_alloca (max*sizeof(int));
 void **p = __builtin_alloca (max*sizeof(void *));
 int n = query_subobj_path(fsid, -1, path, len, p, max);
 for(i=0; i<n; i++)
  ret[i] = ntohl(*((int *)p[i]));
 return n;
}

variable_types:
ret
int []

variable_types:
p
void **


decompiled_code:
int query_streams()
{
unsigned int v0; // eax
__int64 v1; // rax
__int64 v2; // r13
unsigned int i; // er12
unsigned int *v4; // rbx
int v5; // ebp
const char *v6; // rax
const char *v7; // rdi
unsigned int *v8; // rbx
char *v9; // rbp
unsigned int v11; // [rsp+Ch] [rbp-102Ch] BYREF
char v12[4136]; // [rsp+10h] [rbp-1028h] BYREF

v0 = mfs_resolve();
v1 = mfs_dir(v0, &v11);
v2 = v1;
if ( v11 )
{
for ( i = 0; i < v11; ++i )
{
v4 = (unsigned int *)(v2 + 16LL * i);
v5 = query_int_list(*v4, "Part/File", (__int64)v12, 1024);
fprintf(stdout, "%d\t", *v4);
v6 = (const char *)query_string(*v4, "Showing/Program/Title");
fprintf(stdout, "%s\t", v6);
v7 = (const char *)query_string(*v4, "Showing/Program/EpisodeTitle");
if ( !v7 )
v7 = &s;
fputs(v7, stdout);
if ( v5 )
{
v8 = (unsigned int *)v12;
v9 = &v12[4 * (v5 - 1) + 4];
do
fprintf(stdout, "\t%d", *v8++);
while ( v8 != (unsigned int *)v9 );
}
LODWORD(v1) = fputc(10, stdout);
}
}
if ( v2 )
LODWORD(v1) = mfs_dir_free(v2);
return v1;
}

canonical_decompiled_code:
int func8()
{
unsigned int v0; // eax
__int64 v1; // rax
__int64 v2; // r13
unsigned int i; // er12
unsigned int *v4; // rbx
int v5; // ebp
const char *v6; // rax
const char *v7; // rdi
unsigned int *v8; // rbx
char *v9; // rbp
unsigned int v11; // [rsp+Ch] [rbp-102Ch] BYREF
char v12[4136]; // [rsp+10h] [rbp-1028h] BYREF

v0 = mfs_resolve();
v1 = mfs_dir(v0, &v11);
v2 = v1;
if ( v11 )
{
for ( i = 0; i < v11; ++i )
{
v4 = (unsigned int *)(v2 + 16LL * i);
v5 = func7(*v4, "Part/File", (__int64)v12, 1024);
fprintf(stdout, "%d\t", *v4);
v6 = (const char *)func5(*v4, "Showing/Program/Title");
fprintf(stdout, "%s\t", v6);
v7 = (const char *)func5(*v4, "Showing/Program/EpisodeTitle");
if ( !v7 )
v7 = &s;
fputs(v7, stdout);
if ( v5 )
{
v8 = (unsigned int *)v12;
v9 = &v12[4 * (v5 - 1) + 4];
do
fprintf(stdout, "\t%d", *v8++);
while ( v8 != (unsigned int *)v9 );
}
LODWORD(v1) = fputc(10, stdout);
}
}
if ( v2 )
LODWORD(v1) = mfs_dir_free(v2);
return v1;
}

original_code:
void query_streams(const char *path)
{
 struct mfs_dirent *dir;
 int parts[1024];
 u32 count, i, j;
 const char *ep;
 dir = mfs_dir(mfs_resolve(path), &count);
 for (i=0;i<count;i++) {
  int n = query_int_list(dir[i].fsid, "Part/File", parts, 1024 );
  fprintf(stdout, "%d\t", dir[i].fsid );
  fprintf(stdout,"%s\t",
         query_string(dir[i].fsid, "Showing/Program/Title"));
  ep = query_string(dir[i].fsid, "Showing/Program/EpisodeTitle");
  fprintf(stdout, "%s", ep?ep:"" );
  for(j=0;j<n; j++)
   fprintf(stdout, "\t%d", parts[j] );
  fprintf(stdout,"\n");
 }
 if (dir) mfs_dir_free(dir);
}

canonical_original_code:
void query_streams(char *path)
{
 struct mfs_dirent *dir;
 int parts[1024];
 unsigned int count; unsigned int i; unsigned int j;
 char *ep;
 dir = mfs_dir(mfs_resolve(path), &count);
 for (i=0;i<count;i++) {
  int n = query_int_list(dir[i].fsid, "Part/File", parts, 1024 );
  fprintf(stdout, "%d\t", dir[i].fsid );
  fprintf(stdout,"%s\t",
         query_string(dir[i].fsid, "Showing/Program/Title"));
  ep = query_string(dir[i].fsid, "Showing/Program/EpisodeTitle");
  fprintf(stdout, "%s", ep?ep:"" );
  for(j=0;j<n; j++)
   fprintf(stdout, "\t%d", parts[j] );
  fprintf(stdout,"\n");
 }
 if (dir) mfs_dir_free(dir);
}

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

variable_types:
parts
int [1024]

variable_types:
count
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
ep
char *


decompiled_code:
void __fastcall partition_parse(__int64 a1)
{
unsigned int j; // ebx
unsigned __int16 v2; // ax
int v3; // eax
int v4; // ebp
__int64 v5; // r12
int v6; // er13
int v7; // [rsp+8h] [rbp-240h]
unsigned int i; // [rsp+Ch] [rbp-23Ch]
__int16 v9[2]; // [rsp+10h] [rbp-238h] BYREF
unsigned int v10; // [rsp+14h] [rbp-234h]
unsigned int v11; // [rsp+18h] [rbp-230h]
unsigned int v12; // [rsp+1Ch] [rbp-22Ch]
char v13[520]; // [rsp+40h] [rbp-208h] BYREF

read_sectors(a1, v9, 1LL, 1LL);
for ( i = 0; (unsigned int)num_devs() > i; ++i )
{
v7 = dev_start_sector(i);
read_sectors((unsigned int)a1, v9, (unsigned int)(v7 + 1), 1LL);
v6 = _bswap_32(v10);
if ( v6 > 0 )
{
for ( j = 0; j != v6; ++j )
{
read_sectors((unsigned int)a1, v9, j + v7 + 1, 1LL);
v2 = _bswap_16(v9[0]);
if ( v2 != 20557 )
{
if ( use_syslog )
{
if ( use_syslog > 1 )
syslog(6, "wrong magic %x in partition %d\n", v2, j);
}
else
{
printf("wrong magic %x in partition %d\n", v2, j);
}
exit(1);
}
if ( !strcmp(v13, "MFS") )
{
v3 = _bswap_32(v11);
v4 = num_partitions;
v5 = num_partitions;
pmaps[2 * num_partitions] = v7 + v3;
pmaps[2 * v5 + 1] = _bswap_32(v12);
num_partitions = v4 + 1;
}
}
}
}
if ( !use_syslog )
goto LABEL_21;
if ( fileno(stderr) == 2 )
{
syslog(3, "Found %d MFS partitions\n", (unsigned int)num_partitions);
goto LABEL_22;
}
if ( fileno(stderr) != 1 )
{
LABEL_21:
fprintf(stderr, "Found %d MFS partitions\n", (unsigned int)num_partitions);
goto LABEL_22;
}
if ( use_syslog > 1 )
syslog(6, "Found %d MFS partitions\n", (unsigned int)num_partitions);
LABEL_22:
use_ptable = 1;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
unsigned int j; // ebx
unsigned __int16 v2; // ax
int v3; // eax
int v4; // ebp
__int64 v5; // r12
int v6; // er13
int v7; // [rsp+8h] [rbp-240h]
unsigned int i; // [rsp+Ch] [rbp-23Ch]
__int16 v9[2]; // [rsp+10h] [rbp-238h] BYREF
unsigned int v10; // [rsp+14h] [rbp-234h]
unsigned int v11; // [rsp+18h] [rbp-230h]
unsigned int v12; // [rsp+1Ch] [rbp-22Ch]
char v13[520]; // [rsp+40h] [rbp-208h] BYREF

read_sectors(a1, v9, 1LL, 1LL);
for ( i = 0; (unsigned int)num_devs() > i; ++i )
{
v7 = dev_start_sector(i);
read_sectors((unsigned int)a1, v9, (unsigned int)(v7 + 1), 1LL);
v6 = func1(v10);
if ( v6 > 0 )
{
for ( j = 0; j != v6; ++j )
{
read_sectors((unsigned int)a1, v9, j + v7 + 1, 1LL);
v2 = func0(v9[0]);
if ( v2 != 20557 )
{
if ( use_syslog )
{
if ( use_syslog > 1 )
syslog(6, "wrong magic %x in partition %d\n", v2, j);
}
else
{
printf("wrong magic %x in partition %d\n", v2, j);
}
exit(1);
}
if ( !strcmp(v13, "MFS") )
{
v3 = func1(v11);
v4 = num_partitions;
v5 = num_partitions;
pmaps[2 * num_partitions] = v7 + v3;
pmaps[2 * v5 + 1] = func1(v12);
num_partitions = v4 + 1;
}
}
}
}
if ( !use_syslog )
goto LABEL_21;
if ( fileno(stderr) == 2 )
{
syslog(3, "Found %d MFS partitions\n", (unsigned int)num_partitions);
goto LABEL_22;
}
if ( fileno(stderr) != 1 )
{
LABEL_21:
fprintf(stderr, "Found %d MFS partitions\n", (unsigned int)num_partitions);
goto LABEL_22;
}
if ( use_syslog > 1 )
syslog(6, "Found %d MFS partitions\n", (unsigned int)num_partitions);
LABEL_22:
use_ptable = 1;
}

original_code:
void partition_parse(int fd)
{
 char buf[512];
 struct tivo_partition *tp;
 int i, count, dev_no;
 tp = (struct tivo_partition *)buf;
 read_sectors(fd, tp, 1, 1);
 count = ntohl(tp->map_count);
 for (dev_no = 0; dev_no < num_devs(); ++dev_no) {
  u32 offset = dev_start_sector(dev_no);
  read_sectors(fd, tp, offset+1, 1);
  count = ntohl(tp->map_count);
  for (i=0;i<count;i++) {
   read_sectors(fd, tp, offset+i+1, 1);
   if (ntohs(tp->signature) != 0x504d) {
    (use_syslog ? (use_syslog>=2 ? (syslog(6,"wrong magic %x in partition %d\n", ntohs(tp->signature), i),1) : 1) : printf("wrong magic %x in partition %d\n", ntohs(tp->signature), i));
    exit(1);
   }
   if (strcmp(tp->type, "MFS") == 0) {
    pmaps[num_partitions].start =
        ntohl(tp->start_block)+offset;
    pmaps[num_partitions].length =
        ntohl(tp->block_count);
    num_partitions++;
   }
  }
 }
 (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Found %d MFS partitions\n", num_partitions),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Found %d MFS partitions\n", num_partitions),1) : 1) : fprintf((stderr),"Found %d MFS partitions\n", num_partitions)) : fprintf((stderr),"Found %d MFS partitions\n", num_partitions));
 use_ptable = 1;
}

canonical_original_code:
void partition_parse(int fd)
{
 char buf[512];
 struct tivo_partition *tp;
 int i; int count; int dev_no;
 tp = (struct tivo_partition *)buf;
 read_sectors(fd, tp, 1, 1);
 count = ntohl(tp->map_count);
 for (dev_no = 0; dev_no < num_devs(); ++dev_no) {
  unsigned int offset = dev_start_sector(dev_no);
  read_sectors(fd, tp, offset+1, 1);
  count = ntohl(tp->map_count);
  for (i=0;i<count;i++) {
   read_sectors(fd, tp, offset+i+1, 1);
   if (ntohs(tp->signature) != 0x504d) {
    (use_syslog ? (use_syslog>=2 ? (syslog(6,"wrong magic %x in partition %d\n", ntohs(tp->signature), i),1) : 1) : printf("wrong magic %x in partition %d\n", ntohs(tp->signature), i));
    exit(1);
   }
   if (strcmp(tp->type, "MFS") == 0) {
    pmaps[num_partitions].start =
        ntohl(tp->start_block)+offset;
    pmaps[num_partitions].length =
        ntohl(tp->block_count);
    num_partitions++;
   }
  }
 }
 (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Found %d MFS partitions\n", num_partitions),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Found %d MFS partitions\n", num_partitions),1) : 1) : fprintf((stderr),"Found %d MFS partitions\n", num_partitions)) : fprintf((stderr),"Found %d MFS partitions\n", num_partitions));
 use_ptable = 1;
}

variable_types: fd int

variable_types:
buf
char [512]

variable_types: struct tivo_partition { unsigned short signature; unsigned short res1; unsigned int map_count; unsigned int start_block; unsigned int block_count; char name[32]; char type[32]; unsigned int data_start; unsigned int data_count; unsigned int status; unsigned int boot_start; unsigned int boot_size; unsigned int boot_load; unsigned int boot_load2; unsigned int boot_entry; unsigned int boot_entry2; unsigned int boot_cksum; char processor[16]; } *

variable_types: i int

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall partition_remap(unsigned int a1)
{
unsigned int v1; // ebx
unsigned int v2; // eax
__int64 v3; // rdx
int v4; // ecx
int v5; // edi

v1 = a1;
if ( use_ptable )
{
if ( num_partitions <= 0 )
{
v5 = 0;
LABEL_9:
if ( num_partitions != v5 )
return v1;
if ( !use_syslog )
goto LABEL_17;
if ( fileno(stderr) == 2 )
{
syslog(3, "Failed to partition map sector %d\n", v1);
goto LABEL_18;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Failed to partition map sector %d\n", v1);
}
else
{
LABEL_17:
fprintf(stderr, "Failed to partition map sector %d\n", v1);
}
LABEL_18:
exit(1);
}
v2 = pmaps[1];
v3 = 1LL;
v4 = 0;
if ( a1 >= v2 )
{
while ( 1 )
{
v4 += v2 & 0xFFFFFC00;
v5 = v3;
if ( v3 == num_partitions )
goto LABEL_9;
v2 = pmaps[2 * v3++ + 1];
if ( v2 + v4 > v1 )
goto LABEL_6;
}
}
v4 = 0;
v5 = 0;
LABEL_6:
v1 += pmaps[2 * v5] - v4;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int v1; // ebx
unsigned int v2; // eax
__int64 v3; // rdx
int v4; // ecx
int v5; // edi

v1 = a1;
if ( use_ptable )
{
if ( num_partitions <= 0 )
{
v5 = 0;
LABEL_9:
if ( num_partitions != v5 )
return v1;
if ( !use_syslog )
goto LABEL_17;
if ( fileno(stderr) == 2 )
{
syslog(3, "Failed to partition map sector %d\n", v1);
goto LABEL_18;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Failed to partition map sector %d\n", v1);
}
else
{
LABEL_17:
fprintf(stderr, "Failed to partition map sector %d\n", v1);
}
LABEL_18:
exit(1);
}
v2 = pmaps[1];
v3 = 1LL;
v4 = 0;
if ( a1 >= v2 )
{
while ( 1 )
{
v4 += v2 & 0xFFFFFC00;
v5 = v3;
if ( v3 == num_partitions )
goto LABEL_9;
v2 = pmaps[2 * v3++ + 1];
if ( v2 + v4 > v1 )
goto LABEL_6;
}
}
v4 = 0;
v5 = 0;
LABEL_6:
v1 += pmaps[2 * v5] - v4;
}
return v1;
}

original_code:
u32 partition_remap(u32 sec)
{
 int i;
 u32 start=0;
 if (!use_ptable) return sec;
 for (i=0; i<num_partitions; i++) {
  if (sec < start + pmaps[i].length) {
   return pmaps[i].start + (sec - start);
  }
  start += (pmaps[i].length & ~(1024 -1));
 }
 if (i == num_partitions) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Failed to partition map sector %d\n", sec),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Failed to partition map sector %d\n", sec),1) : 1) : fprintf((stderr),"Failed to partition map sector %d\n", sec)) : fprintf((stderr),"Failed to partition map sector %d\n", sec));
  exit(1);
 }
 return sec;
}

canonical_original_code:
unsigned int partition_remap(unsigned int sec)
{
 int i;
 unsigned int start = 0;
 if (!use_ptable) return sec;
 for (i=0; i<num_partitions; i++) {
  if (sec < start + pmaps[i].length) {
   return pmaps[i].start + (sec - start);
  }
  start += (pmaps[i].length & ~(1024 -1));
 }
 if (i == num_partitions) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Failed to partition map sector %d\n", sec),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Failed to partition map sector %d\n", sec),1) : 1) : fprintf((stderr),"Failed to partition map sector %d\n", sec)) : fprintf((stderr),"Failed to partition map sector %d\n", sec));
  exit(1);
 }
 return sec;
}

variable_types:
sec
unsigned int

variable_types:
start
unsigned int


decompiled_code:
__int64 partition_total_size()
{
unsigned int v0; // ecx
__int64 v1; // rax

v0 = 0;
if ( use_ptable )
{
if ( num_partitions <= 0 )
{
v0 = 0;
}
else
{
v1 = 0LL;
do
v0 += pmaps[2 * v1++ + 1] & 0xFFFFFC00;
while ( v1 != num_partitions );
}
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ecx
__int64 v1; // rax

v0 = 0;
if ( use_ptable )
{
if ( num_partitions <= 0 )
{
v0 = 0;
}
else
{
v1 = 0LL;
do
v0 += pmaps[2 * v1++ + 1] & 0xFFFFFC00;
while ( v1 != num_partitions );
}
}
return v0;
}

original_code:
u32 partition_total_size(void)
{
 u32 total=0;
 int i;
 if (!use_ptable) return 0;
 for (i=0; i<num_partitions; i++) {
  total += (pmaps[i].length & ~(1024 -1));
 }
 return total;
}

canonical_original_code:
unsigned int partition_total_size()
{
 unsigned int total = 0;
 int i;
 if (!use_ptable) return 0;
 for (i=0; i<num_partitions; i++) {
  total += (pmaps[i].length & ~(1024 -1));
 }
 return total;
}

variable_types:
total
unsigned int


decompiled_code:
void clear_use_ptable()
{
use_ptable = 0;
}

canonical_decompiled_code:
void func5()
{
use_ptable = 0;
}


writeall

decompiled_code:
ssize_t __fastcall writeall(int fd, void *buf, size_t n)
{
size_t v4; // rbp
int v5; // er14
int v6; // eax
ssize_t v8; // rax
ssize_t v9; // rbx

if ( n )
{
v4 = n;
v5 = 0;
while ( 1 )
{
v8 = write(fd, buf, v4);
v9 = v8;
if ( v8 < 0 )
{
v6 = *_errno_location();
if ( v6 != 4 && v6 != 11 )
return v9;
}
else
{
buf = (char *)buf + v8;
v4 -= v8;
v5 += v8;
}
if ( !v4 )
return v5;
}
}
return 0;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd, void *buf, size_t n)
{
size_t v4; // rbp
int v5; // er14
int v6; // eax
ssize_t v8; // rax
ssize_t v9; // rbx

if ( n )
{
v4 = n;
v5 = 0;
while ( 1 )
{
v8 = write(fd, buf, v4);
v9 = v8;
if ( v8 < 0 )
{
v6 = *_errno_location();
if ( v6 != 4 && v6 != 11 )
return v9;
}
else
{
buf = (char *)buf + v8;
v4 -= v8;
v5 += v8;
}
if ( !v4 )
return v5;
}
}
return 0;
}

original_code:
static inline ssize_t writeall( int fd, void *buf, size_t count )
{
 unsigned char *p = buf;
 int rc = 0;
 ssize_t ret = 0;
 while (count > 0) {
   ret = write( 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 writeall(int fd, void *buf, unsigned long count)
{
 unsigned char *p = buf;
 int rc = 0;
 long ret = 0;
 while (count > 0) {
   ret = write( 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:
buf
void *

variable_types:
count
unsigned long

variable_types:
p
unsigned char *

variable_types: rc int

variable_types: ret long

return_type: long


decompiled_code:
__int64 __fastcall export_file(unsigned int a1, int a2, unsigned __int64 a3, size_t a4, int a5, int a6, int a7)
{
size_t v7; // rbx
void *v8; // rsp
unsigned __int64 v9; // r12
size_t v10; // r15
unsigned __int64 v11; // r14
size_t v12; // rbx
void *v13; // r14
int v14; // eax
unsigned int v15; // edx
int *v17; // rax
char *v18; // rax
size_t v19; // r13
int v20; // eax
unsigned int v21; // er12
int v22; // ebx
size_t v23; // r13
int *v24; // rax
char *v25; // rax
__int16 v26; // r12
int v27; // eax
int v28; // er12
int v29; // er12
size_t v30; // r12
int v31; // eax
__int64 v32; // rdx
int v33; // eax
size_t v34; // rax
unsigned int v35; // er12
__int64 v36; // [rsp+0h] [rbp-280h] BYREF
__int64 v37; // [rsp+8h] [rbp-278h]
unsigned int v38; // [rsp+14h] [rbp-26Ch]
size_t n; // [rsp+18h] [rbp-268h]
int v40; // [rsp+20h] [rbp-260h]
int fd; // [rsp+24h] [rbp-25Ch]
unsigned __int64 v42; // [rsp+28h] [rbp-258h]
void *buf; // [rsp+30h] [rbp-250h]
int v44; // [rsp+38h] [rbp-248h]
unsigned int v45; // [rsp+3Ch] [rbp-244h]
struct timespec requested_time; // [rsp+40h] [rbp-240h] BYREF
char v47[56]; // [rsp+50h] [rbp-230h] BYREF
unsigned int v48; // [rsp+88h] [rbp-1F8h]
int v49[125]; // [rsp+8Ch] [rbp-1F4h]

fd = a2;
v42 = a3;
n = a4;
v44 = a5;
if ( !a6 )
a6 = 256;
v40 = a6;
v7 = a6 << 9;
v8 = alloca(v7 + 16);
buf = &v36;
if ( a5 > 0 )
{
requested_time.tv_sec = a5 / 1000;
v44 = a5 % 1000;
requested_time.tv_nsec = 1000000 * (a5 % 1000);
}
mfs_load_inode(a1, v47);
v9 = mfs_fsid_size(a1);
if ( v9 < v42 )
return (unsigned int)-1;
if ( n + v42 > v9 || !n )
n = v9 - v42;
if ( a7 )
{
if ( !use_syslog )
goto LABEL_16;
if ( fileno(stderr) == 2 )
{
syslog(3, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", a1, v9, v42, n);
goto LABEL_17;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", a1, v9, v42, n);
}
else
{
LABEL_16:
fprintf(stderr, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", a1, v9, v42, n);
}
}
LABEL_17:
mfs_readahead(1LL);
if ( v48 )
{
LODWORD(v10) = n;
if ( n )
{
v10 = n;
v37 = 0LL;
v38 = 0;
v11 = 0LL;
do
{
v22 = v49[2 * v37 + 1];
if ( v11 + ((__int64)v22 << 9) >= v42 )
{
if ( v22 > 0 )
{
v45 = v49[2 * v37];
do
{
if ( v42 <= v11 )
{
v23 = v10;
}
else
{
v26 = v42 - v11;
v27 = ((int)v42 - (int)v11) >> 9;
v11 += (int)v42 - (int)v11;
v22 -= v27;
v45 += v27;
v23 = v10;
v28 = v26 & 0x1FF;
if ( v28 )
{
v19 = 512 - v28;
if ( v19 > v10 )
LODWORD(v19) = v10;
mfs_read_sectors(buf, v45, 1LL);
v36 = (int)v19;
v20 = writeall(fd, (char *)buf + v28, (int)v19);
v21 = v20;
if ( v20 <= 0 )
{
if ( use_syslog )
goto LABEL_32;
LABEL_46:
perror("write failed:");
return (unsigned int)-1;
}
if ( (_DWORD)v19 != v20 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "short write: %d/%d\n", v21, (unsigned int)v19);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "short write: %d/%d\n", v21, (unsigned int)v19);
}
else
{
fprintf(stderr, "short write: %d/%d\n", v21, (unsigned int)v19);
}
}
else
{
fprintf(stderr, "short write: %d/%d\n", (unsigned int)v20, (unsigned int)v19);
}
}
++v45;
--v22;
v23 = v10 - (int)v21;
v11 += v36;
}
}
v29 = v40;
if ( v22 <= v40 )
v29 = v22;
v30 = v29 << 9;
if ( v30 > v23 )
LODWORD(v30) = v23;
mfs_read_partial(buf, v45, (int)v30);
v31 = writeall(fd, buf, (int)v30);
if ( v31 < 0 || (_DWORD)v30 != v31 )
{
if ( use_syslog )
{
v24 = _errno_location();
v25 = strerror(*v24);
syslog(3, "%s: %s", "write failed:", v25);
}
else
{
perror("write failed:");
}
return (unsigned int)-1;
}
v32 = v31;
v11 += v31;
v10 = v23 - v31;
v33 = v31 >> 9;
v22 -= v33;
v45 += v33;
if ( a7 )
{
v34 = 100 * (n - v23 + v32) / n;
v35 = v34;
if ( (_DWORD)v34 != v38 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "%d%%\r", v35);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "%d%%\r", v35);
}
else
{
fprintf(stderr, "%d%%\r", v35);
}
}
else
{
fprintf(stderr, "%d%%\r", (unsigned int)v34);
}
fflush(stderr);
v38 = v35;
}
}
if ( v44 > 0 )
{
nanosleep(&requested_time, 0LL);
}
else if ( !v44 )
{
sched_yield();
}
}
while ( v22 > 0 && v10 );
}
}
else
{
v11 += (__int64)v22 << 9;
}
if ( !v10 )
break;
++v37;
}
while ( v48 > (unsigned int)v37 );
}
return (unsigned int)(n - v10);
}
if ( v7 < n )
{
if ( !use_syslog )
goto LABEL_27;
if ( fileno(stderr) == 2 )
{
syslog(3, "inode data too big for buffer!? Output truncated.\n");
n = v7;
goto LABEL_28;
}
if ( fileno(stderr) != 1 )
{
LABEL_27:
fwrite("inode data too big for buffer!? Output truncated.\n", 1uLL, 0x33uLL, stderr);
n = v7;
goto LABEL_28;
}
n = v7;
if ( use_syslog > 1 )
{
syslog(6, "inode data too big for buffer!? Output truncated.\n");
n = v7;
}
}
LABEL_28:
v12 = n;
v13 = buf;
mfs_fsid_pread(a1, buf, v42, (unsigned int)n);
v14 = writeall(fd, v13, v12);
if ( v14 < 0 || (v15 = v12, v14 != v12) )
{
if ( !use_syslog )
goto LABEL_46;
LABEL_32:
v17 = _errno_location();
v18 = strerror(*v17);
syslog(3, "%s: %s", "write failed:", v18);
v15 = -1;
}
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, unsigned __int64 a3, size_t a4, int a5, int a6, int a7)
{
size_t v7; // rbx
void *v8; // rsp
unsigned __int64 v9; // r12
size_t v10; // r15
unsigned __int64 v11; // r14
size_t v12; // rbx
void *v13; // r14
int v14; // eax
unsigned int v15; // edx
int *v17; // rax
char *v18; // rax
size_t v19; // r13
int v20; // eax
unsigned int v21; // er12
int v22; // ebx
size_t v23; // r13
int *v24; // rax
char *v25; // rax
__int16 v26; // r12
int v27; // eax
int v28; // er12
int v29; // er12
size_t v30; // r12
int v31; // eax
__int64 v32; // rdx
int v33; // eax
size_t v34; // rax
unsigned int v35; // er12
__int64 v36; // [rsp+0h] [rbp-280h] BYREF
__int64 v37; // [rsp+8h] [rbp-278h]
unsigned int v38; // [rsp+14h] [rbp-26Ch]
size_t n; // [rsp+18h] [rbp-268h]
int v40; // [rsp+20h] [rbp-260h]
int fd; // [rsp+24h] [rbp-25Ch]
unsigned __int64 v42; // [rsp+28h] [rbp-258h]
void *buf; // [rsp+30h] [rbp-250h]
int v44; // [rsp+38h] [rbp-248h]
unsigned int v45; // [rsp+3Ch] [rbp-244h]
struct timespec requested_time; // [rsp+40h] [rbp-240h] BYREF
char v47[56]; // [rsp+50h] [rbp-230h] BYREF
unsigned int v48; // [rsp+88h] [rbp-1F8h]
int v49[125]; // [rsp+8Ch] [rbp-1F4h]

fd = a2;
v42 = a3;
n = a4;
v44 = a5;
if ( !a6 )
a6 = 256;
v40 = a6;
v7 = a6 << 9;
v8 = alloca(v7 + 16);
buf = &v36;
if ( a5 > 0 )
{
requested_time.tv_sec = a5 / 1000;
v44 = a5 % 1000;
requested_time.tv_nsec = 1000000 * (a5 % 1000);
}
mfs_load_inode(a1, v47);
v9 = mfs_fsid_size(a1);
if ( v9 < v42 )
return (unsigned int)-1;
if ( n + v42 > v9 || !n )
n = v9 - v42;
if ( a7 )
{
if ( !use_syslog )
goto LABEL_16;
if ( fileno(stderr) == 2 )
{
syslog(3, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", a1, v9, v42, n);
goto LABEL_17;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", a1, v9, v42, n);
}
else
{
LABEL_16:
fprintf(stderr, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", a1, v9, v42, n);
}
}
LABEL_17:
mfs_readahead(1LL);
if ( v48 )
{
LODWORD(v10) = n;
if ( n )
{
v10 = n;
v37 = 0LL;
v38 = 0;
v11 = 0LL;
do
{
v22 = v49[2 * v37 + 1];
if ( v11 + ((__int64)v22 << 9) >= v42 )
{
if ( v22 > 0 )
{
v45 = v49[2 * v37];
do
{
if ( v42 <= v11 )
{
v23 = v10;
}
else
{
v26 = v42 - v11;
v27 = ((int)v42 - (int)v11) >> 9;
v11 += (int)v42 - (int)v11;
v22 -= v27;
v45 += v27;
v23 = v10;
v28 = v26 & 0x1FF;
if ( v28 )
{
v19 = 512 - v28;
if ( v19 > v10 )
LODWORD(v19) = v10;
mfs_read_sectors(buf, v45, 1LL);
v36 = (int)v19;
v20 = func0(fd, (char *)buf + v28, (int)v19);
v21 = v20;
if ( v20 <= 0 )
{
if ( use_syslog )
goto LABEL_32;
LABEL_46:
perror("write failed:");
return (unsigned int)-1;
}
if ( (_DWORD)v19 != v20 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "short write: %d/%d\n", v21, (unsigned int)v19);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "short write: %d/%d\n", v21, (unsigned int)v19);
}
else
{
fprintf(stderr, "short write: %d/%d\n", v21, (unsigned int)v19);
}
}
else
{
fprintf(stderr, "short write: %d/%d\n", (unsigned int)v20, (unsigned int)v19);
}
}
++v45;
--v22;
v23 = v10 - (int)v21;
v11 += v36;
}
}
v29 = v40;
if ( v22 <= v40 )
v29 = v22;
v30 = v29 << 9;
if ( v30 > v23 )
LODWORD(v30) = v23;
mfs_read_partial(buf, v45, (int)v30);
v31 = func0(fd, buf, (int)v30);
if ( v31 < 0 || (_DWORD)v30 != v31 )
{
if ( use_syslog )
{
v24 = _errno_location();
v25 = strerror(*v24);
syslog(3, "%s: %s", "write failed:", v25);
}
else
{
perror("write failed:");
}
return (unsigned int)-1;
}
v32 = v31;
v11 += v31;
v10 = v23 - v31;
v33 = v31 >> 9;
v22 -= v33;
v45 += v33;
if ( a7 )
{
v34 = 100 * (n - v23 + v32) / n;
v35 = v34;
if ( (_DWORD)v34 != v38 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "%d%%\r", v35);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "%d%%\r", v35);
}
else
{
fprintf(stderr, "%d%%\r", v35);
}
}
else
{
fprintf(stderr, "%d%%\r", (unsigned int)v34);
}
fflush(stderr);
v38 = v35;
}
}
if ( v44 > 0 )
{
nanosleep(&requested_time, 0LL);
}
else if ( !v44 )
{
sched_yield();
}
}
while ( v22 > 0 && v10 );
}
}
else
{
v11 += (__int64)v22 << 9;
}
if ( !v10 )
break;
++v37;
}
while ( v48 > (unsigned int)v37 );
}
return (unsigned int)(n - v10);
}
if ( v7 < n )
{
if ( !use_syslog )
goto LABEL_27;
if ( fileno(stderr) == 2 )
{
syslog(3, "inode data too big for buffer!? Output truncated.\n");
n = v7;
goto LABEL_28;
}
if ( fileno(stderr) != 1 )
{
LABEL_27:
fwrite("inode data too big for buffer!? Output truncated.\n", 1uLL, 0x33uLL, stderr);
n = v7;
goto LABEL_28;
}
n = v7;
if ( use_syslog > 1 )
{
syslog(6, "inode data too big for buffer!? Output truncated.\n");
n = v7;
}
}
LABEL_28:
v12 = n;
v13 = buf;
mfs_fsid_pread(a1, buf, v42, (unsigned int)n);
v14 = func0(fd, v13, v12);
if ( v14 < 0 || (v15 = v12, v14 != v12) )
{
if ( !use_syslog )
goto LABEL_46;
LABEL_32:
v17 = _errno_location();
v18 = strerror(*v17);
syslog(3, "%s: %s", "write failed:", v18);
v15 = -1;
}
return v15;
}

original_code:
int export_file(const u32 fsid, const int fd, u64 start,
   u64 count, int delayms, u32 nbufs, int verbose )
{
        struct mfs_inode inode;
        int run, ret, rlen, blen;
        int pct, last_pct=0;
        u64 ofs=0, size;
 u64 total;
 struct timespec delay;
 int nb = (nbufs>0) ? nbufs : 256;
        unsigned char *buf = __builtin_alloca (nb*512);
 if (!buf) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Couldn't allocate buffer: %d\n", nb*512),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Couldn't allocate buffer: %d\n", nb*512),1) : 1) : fprintf((stderr),"Couldn't allocate buffer: %d\n", nb*512)) : fprintf((stderr),"Couldn't allocate buffer: %d\n", nb*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 -1;
 }
 if (start+count>size || count==0) {
  count = size-start;
 }
 total = count;
 if (verbose)
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count),1) : 1) : fprintf((stderr),"exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count)) : fprintf((stderr),"exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count));
 mfs_readahead(1);
 if(inode.num_runs == 0) {
  if (count > nb*512) {
   (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "inode data too big for buffer!?  Output truncated.\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"inode data too big for buffer!?  Output truncated.\n"),1) : 1) : fprintf((stderr),"inode data too big for buffer!?  Output truncated.\n")) : fprintf((stderr),"inode data too big for buffer!?  Output truncated.\n"));
   count = nb*512;
  }
  mfs_fsid_pread( fsid, buf, start, count );
  ret = writeall(fd,buf,count);
  if (ret < 0 || ret != count) {
   (use_syslog ? (syslog(3,"%s: %s",("write failed:"),strerror((*__errno_location ()))),1) : perror("write failed:"));
   return -1;
  }
  return 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) {
   if (start > ofs) {
    int bofs = start-ofs;
    int sofs = bofs>>9;
    int bmod = bofs&(512 -1);
    ofs += bofs;
    len -= sofs;
    sec += sofs;
    if (bmod) {
     blen = ((512 -bmod)<(count)?(512 -bmod):(count));
     mfs_read_sectors(buf,sec,1);
     ret = writeall( fd, buf+bmod, blen);
     if (ret <= 0) {
      (use_syslog ? (syslog(3,"%s: %s",("write failed:"),strerror((*__errno_location ()))),1) : perror("write failed:"));
      return -1;
     } else if (ret != blen) {
      (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "short write: %d/%d\n", ret, blen),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"short write: %d/%d\n", ret, blen),1) : 1) : fprintf((stderr),"short write: %d/%d\n", ret, blen)) : fprintf((stderr),"short write: %d/%d\n", ret, blen));
     }
     sec++;
     len--;
     count -= ret;
     ofs += blen;
    }
   }
                        rlen = ((nb)<(len)?(nb):(len));
   blen = ((rlen<<9)<(count)?(rlen<<9):(count));
   mfs_read_partial(buf, sec, blen);
                        ret = writeall(fd,buf,blen);
                        if (ret < 0 || ret != blen) {
    (use_syslog ? (syslog(3,"%s: %s",("write failed:"),strerror((*__errno_location ()))),1) : perror("write failed:"));
    return -1;
   }
   ofs += ret;
   count -= ret;
                        ret >>= 9;
                        len -= ret;
                        sec += ret;
   if (verbose) {
    pct = (100 * (total-count))/total;
    if (pct != last_pct) {
     (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "%d%%\r", pct),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"%d%%\r", pct),1) : 1) : fprintf((stderr),"%d%%\r", 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:
int export_file(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 ret; int rlen; int blen;
        int pct; int last_pct = 0;
        unsigned int ofs = 0; unsigned int size;
 unsigned int total;
 struct timespec delay;
 int nb = (nbufs>0) ? nbufs : 256;
        unsigned char *buf = __builtin_alloca (nb*512);
 if (!buf) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Couldn't allocate buffer: %d\n", nb*512),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Couldn't allocate buffer: %d\n", nb*512),1) : 1) : fprintf((stderr),"Couldn't allocate buffer: %d\n", nb*512)) : fprintf((stderr),"Couldn't allocate buffer: %d\n", nb*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 -1;
 }
 if (start+count>size || count==0) {
  count = size-start;
 }
 total = count;
 if (verbose)
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count),1) : 1) : fprintf((stderr),"exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count)) : fprintf((stderr),"exporting fsid %d of size %lld starting at offset %lld for %lld bytes\n", fsid, size, start, count));
 mfs_readahead(1);
 if(inode.num_runs == 0) {
  if (count > nb*512) {
   (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "inode data too big for buffer!?  Output truncated.\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"inode data too big for buffer!?  Output truncated.\n"),1) : 1) : fprintf((stderr),"inode data too big for buffer!?  Output truncated.\n")) : fprintf((stderr),"inode data too big for buffer!?  Output truncated.\n"));
   count = nb*512;
  }
  mfs_fsid_pread( fsid, buf, start, count );
  ret = writeall(fd,buf,count);
  if (ret < 0 || ret != count) {
   (use_syslog ? (syslog(3,"%s: %s",("write failed:"),strerror((*__errno_location ()))),1) : perror("write failed:"));
   return -1;
  }
  return 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) {
   if (start > ofs) {
    int bofs = start-ofs;
    int sofs = bofs>>9;
    int bmod = bofs&(512 -1);
    ofs += bofs;
    len -= sofs;
    sec += sofs;
    if (bmod) {
     blen = ((512 -bmod)<(count)?(512 -bmod):(count));
     mfs_read_sectors(buf,sec,1);
     ret = writeall( fd, buf+bmod, blen);
     if (ret <= 0) {
      (use_syslog ? (syslog(3,"%s: %s",("write failed:"),strerror((*__errno_location ()))),1) : perror("write failed:"));
      return -1;
     } else if (ret != blen) {
      (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "short write: %d/%d\n", ret, blen),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"short write: %d/%d\n", ret, blen),1) : 1) : fprintf((stderr),"short write: %d/%d\n", ret, blen)) : fprintf((stderr),"short write: %d/%d\n", ret, blen));
     }
     sec++;
     len--;
     count -= ret;
     ofs += blen;
    }
   }
                        rlen = ((nb)<(len)?(nb):(len));
   blen = ((rlen<<9)<(count)?(rlen<<9):(count));
   mfs_read_partial(buf, sec, blen);
                        ret = writeall(fd,buf,blen);
                        if (ret < 0 || ret != blen) {
    (use_syslog ? (syslog(3,"%s: %s",("write failed:"),strerror((*__errno_location ()))),1) : perror("write failed:"));
    return -1;
   }
   ofs += ret;
   count -= ret;
                        ret >>= 9;
                        len -= ret;
                        sec += ret;
   if (verbose) {
    pct = (100 * (total-count))/total;
    if (pct != last_pct) {
     (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "%d%%\r", pct),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"%d%%\r", pct),1) : 1) : fprintf((stderr),"%d%%\r", 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:
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: ret int

variable_types: rlen int

variable_types: blen int

variable_types: pct int

variable_types:
ofs
unsigned int

variable_types:
size
unsigned int

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

variable_types: nb int

variable_types:
buf
unsigned char *

variable_types: len int

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


decompiled_code:
__int64 __fastcall list_sectors_for_file(__int64 a1, _QWORD *a2, int a3)
{
__int64 v5; // rdx
__int64 v6; // rbx
__int64 v7; // rcx
bool v8; // al
__int64 v10; // rdx
_BYTE v11[56]; // [rsp+0h] [rbp-218h] BYREF
unsigned int v12[120]; // [rsp+38h] [rbp-1E0h]

mfs_load_inode(a1, v11);
mfs_fsid_size((unsigned int)a1);
if ( v12[0] )
{
v6 = 1LL;
v7 = 0LL;
if ( a3 > 0 )
{
do
{
*a2 = mfs_list_sectors(*(unsigned int *)&v11[8 * v6 + 52], v12[2 * v6], v5, v7);
a2[1] = v5;
v7 = (unsigned int)v6;
LOBYTE(v5) = v12[0] > (unsigned int)v6;
v8 = a3 > (int)v6++;
a2 += 2;
}
while ( (v8 & (unsigned __int8)v5) != 0 );
}
}
else
{
if ( !use_syslog )
goto LABEL_11;
if ( fileno(stderr) == 2 )
{
syslog(3, "LISTSECTORS was asked to list a short inode! Not supported.");
LODWORD(v7) = -1;
return (unsigned int)v7;
}
if ( fileno(stderr) != 1 )
{
LABEL_11:
fwrite("LISTSECTORS was asked to list a short inode! Not supported.", 1uLL, 0x3BuLL, stderr);
LODWORD(v7) = -1;
return (unsigned int)v7;
}
LODWORD(v7) = -1;
if ( use_syslog > 1 )
{
syslog(6, "LISTSECTORS was asked to list a short inode! Not supported.", v10, 0xFFFFFFFFLL);
LODWORD(v7) = -1;
}
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, int a3)
{
__int64 v5; // rdx
__int64 v6; // rbx
__int64 v7; // rcx
bool v8; // al
__int64 v10; // rdx
_BYTE v11[56]; // [rsp+0h] [rbp-218h] BYREF
unsigned int v12[120]; // [rsp+38h] [rbp-1E0h]

mfs_load_inode(a1, v11);
mfs_fsid_size((unsigned int)a1);
if ( v12[0] )
{
v6 = 1LL;
v7 = 0LL;
if ( a3 > 0 )
{
do
{
*a2 = mfs_list_sectors(*(unsigned int *)&v11[8 * v6 + 52], v12[2 * v6], v5, v7);
a2[1] = v5;
v7 = (unsigned int)v6;
LOBYTE(v5) = v12[0] > (unsigned int)v6;
v8 = a3 > (int)v6++;
a2 += 2;
}
while ( (v8 & (unsigned __int8)v5) != 0 );
}
}
else
{
if ( !use_syslog )
goto LABEL_11;
if ( fileno(stderr) == 2 )
{
syslog(3, "LISTSECTORS was asked to list a short inode! Not supported.");
LODWORD(v7) = -1;
return (unsigned int)v7;
}
if ( fileno(stderr) != 1 )
{
LABEL_11:
fwrite("LISTSECTORS was asked to list a short inode! Not supported.", 1uLL, 0x3BuLL, stderr);
LODWORD(v7) = -1;
return (unsigned int)v7;
}
LODWORD(v7) = -1;
if ( use_syslog > 1 )
{
syslog(6, "LISTSECTORS was asked to list a short inode! Not supported.", v10, 0xFFFFFFFFLL);
LODWORD(v7) = -1;
}
}
return (unsigned int)v7;
}

original_code:
int list_sectors_for_file(const u32 fsid, run_desc runs[], int maxruns )
{
 struct mfs_inode inode;
 int run;
 u64 size;
 mfs_load_inode(fsid, &inode);
 size = mfs_fsid_size(fsid);
 if ( inode.num_runs == 0 )
 {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "LISTSECTORS was asked to list a short inode! Not supported."),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"LISTSECTORS was asked to list a short inode! Not supported."),1) : 1) : fprintf((stderr),"LISTSECTORS was asked to list a short inode! Not supported.")) : fprintf((stderr),"LISTSECTORS was asked to list a short inode! Not supported."));
  return -1;
 }
 for ( run=0; run<inode.num_runs && run<maxruns; run++ )
 {
   runs[run] = mfs_list_sectors( inode.u.runs[run].start, inode.u.runs[run].len );
 }
 return run;
}

canonical_original_code:
int list_sectors_for_file(unsigned int fsid, struct run_desc_t runs[], int maxruns)
{
 struct mfs_inode inode;
 int run;
 unsigned int size;
 mfs_load_inode(fsid, &inode);
 size = mfs_fsid_size(fsid);
 if ( inode.num_runs == 0 )
 {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "LISTSECTORS was asked to list a short inode! Not supported."),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"LISTSECTORS was asked to list a short inode! Not supported."),1) : 1) : fprintf((stderr),"LISTSECTORS was asked to list a short inode! Not supported.")) : fprintf((stderr),"LISTSECTORS was asked to list a short inode! Not supported."));
  return -1;
 }
 for ( run=0; run<inode.num_runs && run<maxruns; run++ )
 {
   runs[run] = mfs_list_sectors( inode.u.runs[run].start, inode.u.runs[run].len );
 }
 return run;
}

variable_types:
fsid
unsigned int

variable_types: struct run_desc_t { unsigned int drive; unsigned int partition; unsigned int start; unsigned int count; } []

variable_types: maxruns int

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


original_code:
char *read_xml()
{
 char *buf;
 int n, p;
 int nalloc = 16*1024;
 buf = malloc(nalloc);
 n = read(0, buf, nalloc);
 p = n;
 while (n > 0)
 {
  nalloc *= 2;
  buf = realloc(buf, p + nalloc);
  n = read(0, &buf[p], nalloc);
  p += n;
 }
 buf[p] = 0;
 return buf;
}

canonical_original_code:
char *read_xml()
{
 char *buf;
 int n; int p;
 int nalloc = 16*1024;
 buf = malloc(nalloc);
 n = read(0, buf, nalloc);
 p = n;
 while (n > 0)
 {
  nalloc *= 2;
  buf = realloc(buf, p + nalloc);
  n = read(0, &buf[p], nalloc);
  p += n;
 }
 buf[p] = 0;
 return buf;
}

variable_types:
buf
char *

variable_types: n int

variable_types: p int

variable_types: nalloc int


decompiled_code:
__int64 __fastcall get_percent(unsigned int a1, unsigned int a2)
{
if ( a2 <= 0x346DC )
return 10000 * a1 / a2;
if ( a2 > 0x147AE14 )
return a1 / (a2 / 0x2710);
return 100 * a1 / (a2 / 0x64);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
if ( a2 <= 0x346DC )
return 10000 * a1 / a2;
if ( a2 > 0x147AE14 )
return a1 / (a2 / 0x2710);
return 100 * a1 / (a2 / 0x64);
}

original_code:
static unsigned int
get_percent (unsigned int current, unsigned int max)
{
 unsigned int prcnt;
 if (max <= 0x7fffffff / 10000)
 {
  prcnt = current * 10000 / max;
 }
 else if (max <= 0x7fffffff / 100)
 {
  prcnt = current * 100 / (max / 100);
 }
 else
 {
  prcnt = current / (max / 10000);
 }
 return prcnt;
}

canonical_original_code:
static unsigned int get_percent(unsigned int current, unsigned int max)
{
 unsigned int prcnt;
 if (max <= 0x7fffffff / 10000)
 {
  prcnt = current * 10000 / max;
 }
 else if (max <= 0x7fffffff / 100)
 {
  prcnt = current * 100 / (max / 100);
 }
 else
 {
  prcnt = current / (max / 10000);
 }
 return prcnt;
}

variable_types:
current
unsigned int

variable_types:
max
unsigned int

variable_types:
prcnt
unsigned int


decompiled_code:
size_t __fastcall restore_usage(const char *a1)
{
fprintf(stderr, "Usage: %s [options] Adrive [Bdrive]\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h Display this help message\n", 1uLL, 0x25uLL, stderr);
fwrite(" -i file Input from file, - for stdin\n", 1uLL, 0x28uLL, stderr);
fwrite(" -p Optimize partition layout\n", 1uLL, 0x25uLL, stderr);
fwrite(" -x Expand the backup to fill the drive(s)\n", 1uLL, 0x32uLL, stderr);
fwrite(" -r scale Expand the backup with block size scale\n", 1uLL, 0x33uLL, stderr);
fwrite(" -q Do not display progress\n", 1uLL, 0x23uLL, stderr);
fwrite(" -qq Do not display anything but error messages\n", 1uLL, 0x36uLL, stderr);
fwrite(" -v size Recreate /var as size megabytes (Only if not in backup)\n", 1uLL, 0x43uLL, stderr);
fwrite(" -s size Recreate swap as size megabytes\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -l Leave at least 2 partitions free\n", 1uLL, 0x2CuLL, stderr);
fwrite(" -b Force no byte swapping on restore\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -B Force byte swapping on restore\n", 1uLL, 0x2AuLL, stderr);
return fwrite(" -z Zero out partitions not backed up\n", 1uLL, 0x2DuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func4(const char *a1)
{
fprintf(stderr, "Usage: %s [options] Adrive [Bdrive]\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h Display this help message\n", 1uLL, 0x25uLL, stderr);
fwrite(" -i file Input from file, - for stdin\n", 1uLL, 0x28uLL, stderr);
fwrite(" -p Optimize partition layout\n", 1uLL, 0x25uLL, stderr);
fwrite(" -x Expand the backup to fill the drive(s)\n", 1uLL, 0x32uLL, stderr);
fwrite(" -r scale Expand the backup with block size scale\n", 1uLL, 0x33uLL, stderr);
fwrite(" -q Do not display progress\n", 1uLL, 0x23uLL, stderr);
fwrite(" -qq Do not display anything but error messages\n", 1uLL, 0x36uLL, stderr);
fwrite(" -v size Recreate /var as size megabytes (Only if not in backup)\n", 1uLL, 0x43uLL, stderr);
fwrite(" -s size Recreate swap as size megabytes\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -l Leave at least 2 partitions free\n", 1uLL, 0x2CuLL, stderr);
fwrite(" -b Force no byte swapping on restore\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -B Force byte swapping on restore\n", 1uLL, 0x2AuLL, stderr);
return fwrite(" -z Zero out partitions not backed up\n", 1uLL, 0x2DuLL, stderr);
}

original_code:
void
restore_usage (char *progname)
{
 fprintf (stderr, "Usage: %s [options] Adrive [Bdrive]\n", progname);
 fprintf (stderr, "Options:\n");
 fprintf (stderr, " -h        Display this help message\n");
 fprintf (stderr, " -i file   Input from file, - for stdin\n");
 fprintf (stderr, " -p        Optimize partition layout\n");
 fprintf (stderr, " -x        Expand the backup to fill the drive(s)\n");
 fprintf (stderr, " -r scale  Expand the backup with block size scale\n");
 fprintf (stderr, " -q        Do not display progress\n");
 fprintf (stderr, " -qq       Do not display anything but error messages\n");
 fprintf (stderr, " -v size   Recreate /var as size megabytes (Only if not in backup)\n");
 fprintf (stderr, " -s size   Recreate swap as size megabytes\n");
 fprintf (stderr, " -l        Leave at least 2 partitions free\n");
 fprintf (stderr, " -b        Force no byte swapping on restore\n");
 fprintf (stderr, " -B        Force byte swapping on restore\n");
 fprintf (stderr, " -z        Zero out partitions not backed up\n");
}

canonical_original_code:
void restore_usage(char *progname)
{
 fprintf (stderr, "Usage: %s [options] Adrive [Bdrive]\n", progname);
 fprintf (stderr, "Options:\n");
 fprintf (stderr, " -h        Display this help message\n");
 fprintf (stderr, " -i file   Input from file, - for stdin\n");
 fprintf (stderr, " -p        Optimize partition layout\n");
 fprintf (stderr, " -x        Expand the backup to fill the drive(s)\n");
 fprintf (stderr, " -r scale  Expand the backup with block size scale\n");
 fprintf (stderr, " -q        Do not display progress\n");
 fprintf (stderr, " -qq       Do not display anything but error messages\n");
 fprintf (stderr, " -v size   Recreate /var as size megabytes (Only if not in backup)\n");
 fprintf (stderr, " -s size   Recreate swap as size megabytes\n");
 fprintf (stderr, " -l        Leave at least 2 partitions free\n");
 fprintf (stderr, " -b        Force no byte swapping on restore\n");
 fprintf (stderr, " -B        Force byte swapping on restore\n");
 fprintf (stderr, " -z        Zero out partitions not backed up\n");
}

variable_types:
progname
char *


decompiled_code:
size_t __fastcall backup_usage(const char *a1)
{
fprintf(stderr, "Usage: %s [options] Adrive [Bdrive]\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h Display this help message\n", 1uLL, 0x25uLL, stderr);
fwrite(" -o file Output to file, - for stdout\n", 1uLL, 0x28uLL, stderr);
fwrite(" -1 .. -9 Compress backup, quick (-1) through best (-9)\n", 1uLL, 0x39uLL, stderr);
fwrite(" -v Do not include /var in backup\n", 1uLL, 0x29uLL, stderr);
fwrite(" -s Shrink MFS in backup\n", 1uLL, 0x20uLL, stderr);
fwrite(" -q Do not display progress\n", 1uLL, 0x23uLL, stderr);
fwrite(" -qq Do not display anything but error messages\n", 1uLL, 0x36uLL, stderr);
fwrite(" -f max Backup only fsids below max\n", 1uLL, 0x27uLL, stderr);
fwrite(" -l max Backup only streams less than max megabytes\n", 1uLL, 0x37uLL, stderr);
fwrite(" -t Use total length of stream instead of used length\n", 1uLL, 0x3DuLL, stderr);
fwrite(" -T Backup total length of stream instead of used length\n", 1uLL, 0x40uLL, stderr);
return fwrite(" -a Backup all streams\n", 1uLL, 0x1EuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func5(const char *a1)
{
fprintf(stderr, "Usage: %s [options] Adrive [Bdrive]\n", a1);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h Display this help message\n", 1uLL, 0x25uLL, stderr);
fwrite(" -o file Output to file, - for stdout\n", 1uLL, 0x28uLL, stderr);
fwrite(" -1 .. -9 Compress backup, quick (-1) through best (-9)\n", 1uLL, 0x39uLL, stderr);
fwrite(" -v Do not include /var in backup\n", 1uLL, 0x29uLL, stderr);
fwrite(" -s Shrink MFS in backup\n", 1uLL, 0x20uLL, stderr);
fwrite(" -q Do not display progress\n", 1uLL, 0x23uLL, stderr);
fwrite(" -qq Do not display anything but error messages\n", 1uLL, 0x36uLL, stderr);
fwrite(" -f max Backup only fsids below max\n", 1uLL, 0x27uLL, stderr);
fwrite(" -l max Backup only streams less than max megabytes\n", 1uLL, 0x37uLL, stderr);
fwrite(" -t Use total length of stream instead of used length\n", 1uLL, 0x3DuLL, stderr);
fwrite(" -T Backup total length of stream instead of used length\n", 1uLL, 0x40uLL, stderr);
return fwrite(" -a Backup all streams\n", 1uLL, 0x1EuLL, stderr);
}

original_code:
void
backup_usage (char *progname)
{
 fprintf (stderr, "Usage: %s [options] Adrive [Bdrive]\n", progname);
 fprintf (stderr, "Options:\n");
 fprintf (stderr, " -h        Display this help message\n");
 fprintf (stderr, " -o file   Output to file, - for stdout\n");
 fprintf (stderr, " -1 .. -9  Compress backup, quick (-1) through best (-9)\n");
 fprintf (stderr, " -v        Do not include /var in backup\n");
 fprintf (stderr, " -s        Shrink MFS in backup\n");
 fprintf (stderr, " -q        Do not display progress\n");
 fprintf (stderr, " -qq       Do not display anything but error messages\n");
 fprintf (stderr, " -f max    Backup only fsids below max\n");
 fprintf (stderr, " -l max    Backup only streams less than max megabytes\n");
 fprintf (stderr, " -t        Use total length of stream instead of used length\n");
 fprintf (stderr, " -T        Backup total length of stream instead of used length\n");
 fprintf (stderr, " -a        Backup all streams\n");
}

canonical_original_code:
void backup_usage(char *progname)
{
 fprintf (stderr, "Usage: %s [options] Adrive [Bdrive]\n", progname);
 fprintf (stderr, "Options:\n");
 fprintf (stderr, " -h        Display this help message\n");
 fprintf (stderr, " -o file   Output to file, - for stdout\n");
 fprintf (stderr, " -1 .. -9  Compress backup, quick (-1) through best (-9)\n");
 fprintf (stderr, " -v        Do not include /var in backup\n");
 fprintf (stderr, " -s        Shrink MFS in backup\n");
 fprintf (stderr, " -q        Do not display progress\n");
 fprintf (stderr, " -qq       Do not display anything but error messages\n");
 fprintf (stderr, " -f max    Backup only fsids below max\n");
 fprintf (stderr, " -l max    Backup only streams less than max megabytes\n");
 fprintf (stderr, " -t        Use total length of stream instead of used length\n");
 fprintf (stderr, " -T        Backup total length of stream instead of used length\n");
 fprintf (stderr, " -a        Backup all streams\n");
}


decompiled_code:
char *__fastcall cat_args(int a1, const char **a2)
{
const char **v2; // rbx
int v3; // ebp
char *v4; // rbp
__int64 v5; // rbx
char *v6; // rax
const char *v8; // r12
char *v9; // rax
char *dest; // [rsp+8h] [rbp-40h]

if ( a1 <= 0 )
{
v6 = (char *)malloc(0LL);
dest = v6;
if ( v6 )
*v6 = 0;
}
else
{
v2 = a2;
v3 = 0;
do
v3 += strlen(*v2++) + 1;
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
dest = (char *)malloc(v3);
if ( dest )
{
*dest = 0;
v4 = dest;
v5 = 0LL;
do
{
v8 = a2[v5];
strcat(v4, v8);
v9 = &v4[strlen(v8)];
v4 = v9;
if ( a1 - 1 != (_DWORD)v5 )
{
v4 = v9 + 1;
*v9 = 32;
v9[1] = 0;
}
++v5;
}
while ( a1 > (int)v5 );
}
}
return dest;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, const char **a2)
{
const char **v2; // rbx
int v3; // ebp
char *v4; // rbp
__int64 v5; // rbx
char *v6; // rax
const char *v8; // r12
char *v9; // rax
char *dest; // [rsp+8h] [rbp-40h]

if ( a1 <= 0 )
{
v6 = (char *)malloc(0LL);
dest = v6;
if ( v6 )
*v6 = 0;
}
else
{
v2 = a2;
v3 = 0;
do
v3 += strlen(*v2++) + 1;
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
dest = (char *)malloc(v3);
if ( dest )
{
*dest = 0;
v4 = dest;
v5 = 0LL;
do
{
v8 = a2[v5];
strcat(v4, v8);
v9 = &v4[strlen(v8)];
v4 = v9;
if ( a1 - 1 != (_DWORD)v5 )
{
v4 = v9 + 1;
*v9 = 32;
v9[1] = 0;
}
++v5;
}
while ( a1 > (int)v5 );
}
}
return dest;
}

original_code:
static char *cat_args( int argc, char *argv[]) {
 int i;
 int tlen=0;
 char *res, *p;
 for(i=0; i<argc; i++)
  tlen += strlen(argv[i]) + 1;
 p = res = malloc(tlen);
 if (!res) return res;
 res[0] = 0;
 for(i=0; i<argc; i++) {
  strcat( p, argv[i] );
  p += strlen(argv[i]);
  if (i != argc-1) {
    *p++ = ' ';
    *p = 0;
  }
 }
 return res;
}

canonical_original_code:
static char *cat_args(int argc, char *argv[]) {
 int i;
 int tlen = 0;
 char *res; char *p;
 for(i=0; i<argc; i++)
  tlen += strlen(argv[i]) + 1;
 p = res = malloc(tlen);
 if (!res) return res;
 res[0] = 0;
 for(i=0; i<argc; i++) {
  strcat( p, argv[i] );
  p += strlen(argv[i]);
  if (i != argc-1) {
    *p++ = ' ';
    *p = 0;
  }
 }
 return res;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: tlen int

variable_types:
res
char *

variable_types:
p
char *


decompiled_code:
int __fastcall unlock_obj(unsigned int a1, int a2)
{
unsigned int v2; // er12
void *v3; // rbp

if ( (unsigned int)mfs_fsid_type() != 8 )
{
fprintf(stderr, "%d is not an object\n", a1);
exit(1);
}
v2 = mfs_fsid_size(a1);
v3 = malloc(v2);
mfs_fsid_pread(a1, v3, 0LL, v2);
parse_object(a1, v3, unlock_callback);
if ( hits == 2 && !a2 )
mfs_fsid_pwrite(a1, v3, 0LL, v2);
free(v3);
return puts("}");
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, int a2)
{
unsigned int v2; // er12
void *v3; // rbp

if ( (unsigned int)mfs_fsid_type() != 8 )
{
fprintf(stderr, "%d is not an object\n", a1);
exit(1);
}
v2 = mfs_fsid_size(a1);
v3 = malloc(v2);
mfs_fsid_pread(a1, v3, 0LL, v2);
parse_object(a1, v3, unlock_callback);
if ( hits == 2 && !a2 )
mfs_fsid_pwrite(a1, v3, 0LL, v2);
free(v3);
return puts("}");
}

original_code:
static void unlock_obj(int fsid, int test)
{
 void *buf;
 u32 size;
 if (mfs_fsid_type(fsid) != 8) {
  fprintf(stderr,"%d is not an object\n", fsid);
  exit(1);
 }
 size = mfs_fsid_size(fsid);
 buf = malloc(size);
 mfs_fsid_pread(fsid, buf, 0, size);
 parse_object(fsid, buf, unlock_callback);
 if (hits == 2 && !test) {
  mfs_fsid_pwrite(fsid, buf, 0, size);
 }
 free(buf);
 printf("}\n");
}

canonical_original_code:
static void unlock_obj(int fsid, int test)
{
 void *buf;
 unsigned int size;
 if (mfs_fsid_type(fsid) != 8) {
  fprintf(stderr,"%d is not an object\n", fsid);
  exit(1);
 }
 size = mfs_fsid_size(fsid);
 buf = malloc(size);
 mfs_fsid_pread(fsid, buf, 0, size);
 parse_object(fsid, buf, unlock_callback);
 if (hits == 2 && !test) {
  mfs_fsid_pwrite(fsid, buf, 0, size);
 }
 free(buf);
 printf("}\n");
}

variable_types: fsid int

variable_types: test int

variable_types:
buf
void *

variable_types:
size
unsigned int