decompiled_code:
__int64 __fastcall list_sectors_for_file(__int64 a1, __int64 *a2, int a3)
{
__int64 v5; // rbx
unsigned int v6; // er13
__int64 v7; // rax
bool v8; // cf
bool v9; // zf
__int64 v10; // rdx
FILE *v12; // rcx
_BYTE v13[56]; // [rsp+0h] [rbp-228h] BYREF
unsigned int v14[124]; // [rsp+38h] [rbp-1F0h]

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 *a2, int a3)
{
__int64 v5; // rbx
unsigned int v6; // er13
__int64 v7; // rax
bool v8; // cf
bool v9; // zf
__int64 v10; // rdx
FILE *v12; // rcx
_BYTE v13[56]; // [rsp+0h] [rbp-228h] BYREF
unsigned int v14[124]; // [rsp+38h] [rbp-1F0h]

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

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


decompiled_code:
char *read_xml()
{
char *v0; // rbp
int v1; // ebx
int v2; // er12
int v3; // eax
char *result; // rax

v0 = (char *)malloc(0x4000uLL);
v1 = read(0, v0, 0x4000uLL);
if ( v1 > 0 )
{
v2 = 0x4000;
do
{
v2 *= 2;
v0 = (char *)realloc(v0, v2 + v1);
v3 = read(0, &v0[v1], v2);
v1 += v3;
}
while ( v3 > 0 );
}
result = v0;
v0[v1] = 0;
return result;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rbp
int v1; // ebx
int v2; // er12
int v3; // eax
char *result; // rax

v0 = (char *)malloc(0x4000uLL);
v1 = read(0, v0, 0x4000uLL);
if ( v1 > 0 )
{
v2 = 0x4000;
do
{
v2 *= 2;
v0 = (char *)realloc(v0, v2 + v1);
v3 = read(0, &v0[v1], v2);
v1 += v3;
}
while ( v3 > 0 );
}
result = v0;
v0[v1] = 0;
return result;
}

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

return_type: char *


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

return_type: 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 *

return_type: void


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 **v3; // rbx
__int64 v4; // r13
int v5; // er14
const char *v6; // rdi
char *v7; // r15
__int64 v8; // rbx
const char *v9; // r14
char *v10; // rax
char *v12; // rax
char *dest; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
char *__fastcall func0(int a1, const char **a2)
{
const char **v3; // rbx
__int64 v4; // r13
int v5; // er14
const char *v6; // rdi
char *v7; // r15
__int64 v8; // rbx
const char *v9; // r14
char *v10; // rax
char *v12; // rax
char *dest; // [rsp+8h] [rbp-40h]

if ( a1 <= 0 )
{
v12 = (char *)malloc(0LL);
dest = v12;
if ( v12 )
*v12 = 0;
}
else
{
v3 = a2;
v4 = (unsigned int)(a1 - 1);
v5 = 0;
do
{
v6 = *v3++;
v5 += strlen(v6) + 1;
}
while ( &a2[v4 + 1] != v3 );
dest = (char *)malloc(v5);
if ( dest )
{
v7 = dest;
v8 = 0LL;
*dest = 0;
do
{
v9 = a2[v8];
strcat(v7, v9);
v10 = &v7[strlen(v9)];
v7 = v10;
if ( (_DWORD)v4 != (_DWORD)v8 )
{
v7 = v10 + 1;
*(_WORD *)v10 = 32;
}
++v8;
}
while ( a1 != v8 );
}
}
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; // ebx
void *v3; // r12

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; // ebx
void *v3; // r12

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


decompiled_code:
int __fastcall unlock_callback(unsigned int a1, __int64 a2, __int64 a3, unsigned int *a4)
{
__int64 v6; // r12
char v7; // al
__int64 v8; // r13
unsigned int v9; // edi
unsigned int v10; // eax
int v11; // eax
int v12; // edx
int v13; // eax
bool v14; // zf
const char *v15; // rsi
__int64 v16; // rax
unsigned __int64 i; // r12
unsigned int v18; // edi
unsigned int v19; // eax
__int64 v20; // rdx
int v21; // er13
__int64 v23; // rdi
const char *v24; // rbx
unsigned int v25; // er14
const char *v26; // rax
int v27; // eax
unsigned int v28; // ecx
int v29; // edx
__int64 v30; // rcx

if ( a3 )
{
v6 = schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
printf("\t%s[%d]=", (const char *)v6, *(unsigned __int8 *)(a3 + 1));
v7 = *(_BYTE *)a3 >> 6;
if ( v7 == 1 )
{
v21 = 0;
if ( *(_WORD *)(a3 + 2) > 4u )
{
do
{
printf("%s ", (const char *)a4 + v21);
v21 += strlen((const char *)a4 + v21) + 1;
}
while ( *(unsigned __int16 *)(a3 + 2) - 4 > v21 );
}
}
else if ( v7 == 2 )
{
for ( i = 0LL; (unsigned __int64)(*(unsigned __int16 *)(a3 + 2) - 4) >> 3 > i; ++i )
{
_bswap_32(a4[2 * i + 1]);
v18 = a4[2 * i];
v19 = _bswap_32(v18);
printf("%d/%d ", v19, v20);
}
}
else
{
v8 = 0LL;
if ( *(_WORD *)(a3 + 2) > 7u )
{
do
{
v9 = a4[v8++];
v10 = _bswap_32(v9);
printf("%d ", v10);
v11 = *(unsigned __int16 *)(a3 + 2);
v12 = v11 - 1;
v13 = v11 - 4;
if ( v13 < 0 )
v13 = v12;
}
while ( v13 >> 2 > (int)v8 );
}
v14 = strcmp((const char *)lasttype_1, "DiskPartition") == 0;
if ( v6 && v14 )
{
if ( *(_BYTE *)v6 == 73 && *(_BYTE *)(v6 + 1) == 100 && !*(_BYTE *)(v6 + 2) )
{
v15 = "TivoClips";
lastid_0 = _bswap_32(*a4);
if ( lastid_0 != 11 )
v15 = "User";
printf(" (%s)", v15);
}
else if ( !strcmp((const char *)v6, "SizeInKb") && (unsigned int)(lastid_0 - 10) <= 1 )
{
v27 = _bswap_32(*a4);
v28 = tivoclipKB;
if ( v29 != 11 )
v28 = userKB;
++hits;
if ( v28 != v27 )
{
*a4 = _bswap_32(v28);
printf("\n**new**\t%s[%d]=%d ", (const char *)v6, *(unsigned __int8 *)(a3 + 1), v30);
}
}
}
}
LODWORD(v16) = putchar(10);
}
else
{
if ( last_2 )
puts("}");
v23 = *(unsigned __int16 *)(a2 + 4);
v24 = "PRIMARY ";
if ( !*(_WORD *)(a2 + 6) )
v24 = (const char *)&unk_91B;
v25 = *(_DWORD *)(a2 + 12);
last_2 = a1;
v26 = (const char *)schema_type(v23);
printf("%s %d/%d %s{\n", v26, a1, v25, v24);
v16 = schema_type(*(unsigned __int16 *)(a2 + 4));
lasttype_1 = v16;
}
return v16;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, __int64 a2, __int64 a3, unsigned int *a4)
{
__int64 v6; // r12
char v7; // al
__int64 v8; // r13
unsigned int v9; // edi
unsigned int v10; // eax
int v11; // eax
int v12; // edx
int v13; // eax
bool v14; // zf
const char *v15; // rsi
__int64 v16; // rax
unsigned __int64 i; // r12
unsigned int v18; // edi
unsigned int v19; // eax
__int64 v20; // rdx
int v21; // er13
__int64 v23; // rdi
const char *v24; // rbx
unsigned int v25; // er14
const char *v26; // rax
int v27; // eax
unsigned int v28; // ecx
int v29; // edx
__int64 v30; // rcx

if ( a3 )
{
v6 = schema_attrib(*(unsigned __int16 *)(a2 + 4), *(unsigned __int8 *)(a3 + 1));
printf("\t%s[%d]=", (const char *)v6, *(unsigned __int8 *)(a3 + 1));
v7 = *(_BYTE *)a3 >> 6;
if ( v7 == 1 )
{
v21 = 0;
if ( *(_WORD *)(a3 + 2) > 4u )
{
do
{
printf("%s ", (const char *)a4 + v21);
v21 += strlen((const char *)a4 + v21) + 1;
}
while ( *(unsigned __int16 *)(a3 + 2) - 4 > v21 );
}
}
else if ( v7 == 2 )
{
for ( i = 0LL; (unsigned __int64)(*(unsigned __int16 *)(a3 + 2) - 4) >> 3 > i; ++i )
{
func3(a4[2 * i + 1]);
v18 = a4[2 * i];
v19 = func3(v18);
printf("%d/%d ", v19, v20);
}
}
else
{
v8 = 0LL;
if ( *(_WORD *)(a3 + 2) > 7u )
{
do
{
v9 = a4[v8++];
v10 = func3(v9);
printf("%d ", v10);
v11 = *(unsigned __int16 *)(a3 + 2);
v12 = v11 - 1;
v13 = v11 - 4;
if ( v13 < 0 )
v13 = v12;
}
while ( v13 >> 2 > (int)v8 );
}
v14 = strcmp((const char *)lasttype_1, "DiskPartition") == 0;
if ( v6 && v14 )
{
if ( *(_BYTE *)v6 == 73 && *(_BYTE *)(v6 + 1) == 100 && !*(_BYTE *)(v6 + 2) )
{
v15 = "TivoClips";
lastid_0 = func3(*a4);
if ( lastid_0 != 11 )
v15 = "User";
printf(" (%s)", v15);
}
else if ( !strcmp((const char *)v6, "SizeInKb") && (unsigned int)(lastid_0 - 10) <= 1 )
{
v27 = func3(*a4);
v28 = tivoclipKB;
if ( v29 != 11 )
v28 = userKB;
++hits;
if ( v28 != v27 )
{
*a4 = func3(v28);
printf("\n**new**\t%s[%d]=%d ", (const char *)v6, *(unsigned __int8 *)(a3 + 1), v30);
}
}
}
}
LODWORD(v16) = putchar(10);
}
else
{
if ( last_2 )
puts("}");
v23 = *(unsigned __int16 *)(a2 + 4);
v24 = "PRIMARY ";
if ( !*(_WORD *)(a2 + 6) )
v24 = (const char *)&unk_91B;
v25 = *(_DWORD *)(a2 + 12);
last_2 = a1;
v26 = (const char *)schema_type(v23);
printf("%s %d/%d %s{\n", v26, a1, v25, v24);
v16 = schema_type(*(unsigned __int16 *)(a2 + 4));
lasttype_1 = v16;
}
return v16;
}

original_code:
static void unlock_callback(int fsid, struct mfs_subobj_header *obj,
       struct mfs_attr_header *attr, void *data)
{
 int i;
 char *p = data;
 static int last;
 struct mfs_obj_attr *objattr;
 static const char *lasttype;
 static int lastid;
 if (!attr) {
  if (last) printf("}\n");
  last = fsid;
  printf("%s %d/%d %s{\n",
         schema_type(obj->obj_type), fsid, obj->id,
         obj->flags?"PRIMARY ":"");
  lasttype=schema_type(obj->obj_type);
  return;
 }
 const char *attrstr=schema_attrib(obj->obj_type,attr->attr);
 if (attr) {
  printf("\t%s[%d]=", attrstr, attr->attr);
 } else {
  printf("\t[%d]=", attr->attr);
 }
        switch (attr->eltype>>6) {
        case 1:
                for (i=0;i<attr->len-4;) {
                        char *s = (char *)&p[i];
                        printf("%s ", s);
                        i += strlen(s)+1;
                }
                break;
        case 0:
        case 3:
  for (i=0;i<(attr->len-4)/4;i++) {
   printf("%d ",(int)ntohl(*(int *)&p[i*4]));
  }
  if (strcmp(lasttype,"DiskPartition")==0) {
   if (attrstr != 0 && strcmp(attrstr,"Id")==0) {
    lastid = ntohl(*(int *)p);
    printf( "  (%s)", lastid==11 ? "TivoClips" : "User" );
   } else if (attrstr != 0 &&
       strcmp(attrstr,"SizeInKb")==0 &&
       (lastid == 10 || lastid == 11)) {
    int oldsize = ntohl(*(int *)p);
    int newsize = (lastid == 11) ? tivoclipKB : userKB;
    hits++;
    if (oldsize != newsize) {
     *(int *)p = htonl(newsize);
     printf("\n**new**\t%s[%d]=%d ",
            attrstr, attr->attr, newsize );
    }
   }
  }
                break;
        case 2:
  objattr = (struct mfs_obj_attr *)p;
                for (i=0;i<(attr->len-4)/sizeof(*objattr);i++) {
                        printf("%d/%d ",
          (int)ntohl(objattr->fsid),
                               (int)ntohl(objattr->subobj));
   objattr++;
                }
                break;
        }
 printf("\n");
}

canonical_original_code:
static void unlock_callback(int fsid, struct mfs_subobj_header *obj, struct mfs_attr_header *attr, void *data)
{
 int i;
 char *p = data;
 static int last;
 struct mfs_obj_attr *objattr;
 static char *lasttype;
 static int lastid;
 if (!attr) {
  if (last) printf("}\n");
  last = fsid;
  printf("%s %d/%d %s{\n",
         schema_type(obj->obj_type), fsid, obj->id,
         obj->flags?"PRIMARY ":"");
  lasttype=schema_type(obj->obj_type);
  return;
 }
 char *attrstr = schema_attrib(obj->obj_type,attr->attr);
 if (attr) {
  printf("\t%s[%d]=", attrstr, attr->attr);
 } else {
  printf("\t[%d]=", attr->attr);
 }
        switch (attr->eltype>>6) {
        case 1:
                for (i=0;i<attr->len-4;) {
                        char *s = (char *)&p[i];
                        printf("%s ", s);
                        i += strlen(s)+1;
                }
                break;
        case 0:
        case 3:
  for (i=0;i<(attr->len-4)/4;i++) {
   printf("%d ",(int)ntohl(*(int *)&p[i*4]));
  }
  if (strcmp(lasttype,"DiskPartition")==0) {
   if (attrstr != 0 && strcmp(attrstr,"Id")==0) {
    lastid = ntohl(*(int *)p);
    printf( "  (%s)", lastid==11 ? "TivoClips" : "User" );
   } else if (attrstr != 0 &&
       strcmp(attrstr,"SizeInKb")==0 &&
       (lastid == 10 || lastid == 11)) {
    int oldsize = ntohl(*(int *)p);
    int newsize = (lastid == 11) ? tivoclipKB : userKB;
    hits++;
    if (oldsize != newsize) {
     *(int *)p = htonl(newsize);
     printf("\n**new**\t%s[%d]=%d ",
            attrstr, attr->attr, newsize );
    }
   }
  }
                break;
        case 2:
  objattr = (struct mfs_obj_attr *)p;
                for (i=0;i<(attr->len-4)/sizeof(*objattr);i++) {
                        printf("%d/%d ",
          (int)ntohl(objattr->fsid),
                               (int)ntohl(objattr->subobj));
   objattr++;
                }
                break;
        }
 printf("\n");
}

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

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

variable_types:
data
void *

variable_types: last int

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

variable_types:
lasttype
char *

variable_types: lastid int

variable_types:
attrstr
char *

variable_types:
s
char *

variable_types: oldsize int

variable_types: newsize int


usage

decompiled_code:
void __noreturn usage()
{
printf(
"\n"
"Usage: %s [-p path] [-c tivoclipsKB] [-u userKB] [-w] [device]\n"
"\n"
" This program unlocks the 80 hour lock on a Toshiba SD-H400 TiVo by modifying\n"
" the Active DiskConfiguration object in the Media File System (MFS).\n"
"\n"
" The device should be a device file such as /dev/hdc. If not present, the\n"
" vplay MFS_DEVLIST environment variable is used.\n"
"\n"
" The default is to modify \"/Config/DiskConfigurations/Active\" and \n"
" set the TiVoClips size to 10000000 and the User size to -1. This reserves \n"
" 10 million K bytes for tivo clips (ads), and expands the user area to fill \n"
" the remaining available space.\n"
"\n"
" Without the -w option, the program is running in test mode: it will show you\n"
" the changes it would make, but it won't write them to disk.\n"
"\n"
"jamie@xmission.com, Oct 2004\n"
"based on mfs_dumpobj by tridge@samba.org, January 2001\n"
"released under the Gnu GPL v2\n",
(const char *)prog);
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
printf(
"\n"
"Usage: %s [-p path] [-c tivoclipsKB] [-u userKB] [-w] [device]\n"
"\n"
" This program unlocks the 80 hour lock on a Toshiba SD-H400 TiVo by modifying\n"
" the Active DiskConfiguration object in the Media File System (MFS).\n"
"\n"
" The device should be a device file such as /dev/hdc. If not present, the\n"
" vplay MFS_DEVLIST environment variable is used.\n"
"\n"
" The default is to modify \"/Config/DiskConfigurations/Active\" and \n"
" set the TiVoClips size to 10000000 and the User size to -1. This reserves \n"
" 10 million K bytes for tivo clips (ads), and expands the user area to fill \n"
" the remaining available space.\n"
"\n"
" Without the -w option, the program is running in test mode: it will show you\n"
" the changes it would make, but it won't write them to disk.\n"
"\n"
"jamie@xmission.com, Oct 2004\n"
"based on mfs_dumpobj by tridge@samba.org, January 2001\n"
"released under the Gnu GPL v2\n",
(const char *)prog);
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf(
  "\nUsage: %s [-p path] [-c tivoclipsKB] [-u userKB] [-w] [device]\n\n  This program unlocks the 80 hour lock on a Toshiba SD-H400 TiVo by modifying\n  the Active DiskConfiguration object in the Media File System (MFS).\n\n  The device should be a device file such as /dev/hdc.  If not present, the\n  vplay MFS_DEVLIST environment variable is used.\n\n  The default is to modify \"/Config/DiskConfigurations/Active\" and \n  set the TiVoClips size to 10000000 and the User size to -1.  This reserves \n  10 million K bytes for tivo clips (ads), and expands the  user area to fill \n  the remaining  available space.\n\n  Without the -w option, the program is running in test mode: it will show you\n  the changes it would make, but it won't write them to disk.\n\njamie@xmission.com, Oct 2004\nbased on mfs_dumpobj by tridge@samba.org, January 2001\nreleased under the Gnu GPL v2\n", prog
  );
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf(
  "\nUsage: %s [-p path] [-c tivoclipsKB] [-u userKB] [-w] [device]\n\n  This program unlocks the 80 hour lock on a Toshiba SD-H400 TiVo by modifying\n  the Active DiskConfiguration object in the Media File System (MFS).\n\n  The device should be a device file such as /dev/hdc.  If not present, the\n  vplay MFS_DEVLIST environment variable is used.\n\n  The default is to modify \"/Config/DiskConfigurations/Active\" and \n  set the TiVoClips size to 10000000 and the User size to -1.  This reserves \n  10 million K bytes for tivo clips (ads), and expands the  user area to fill \n  the remaining  available space.\n\n  Without the -w option, the program is running in test mode: it will show you\n  the changes it would make, but it won't write them to disk.\n\njamie@xmission.com, Oct 2004\nbased on mfs_dumpobj by tridge@samba.org, January 2001\nreleased under the Gnu GPL v2\n", prog
  );
 credits();
 exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // er12
int v5; // eax
char *v6; // r8
unsigned int v7; // edi
const char *v8; // rsi

v3 = "/Config/DiskConfigurations/Active";
v4 = 1;
prog = (__int64)*argv;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "u:c:p:wh");
if ( v5 == -1 )
break;
if ( v5 == 117 )
{
userKB = atoi(optarg);
}
else if ( v5 > 117 )
{
if ( v5 != 119 )
goto LABEL_23;
v4 = 0;
}
else if ( v5 == 99 )
{
tivoclipKB = atoi(optarg);
}
else
{
if ( v5 != 112 )
goto LABEL_23;
v3 = optarg;
}
}
v6 = 0LL;
if ( argc - optind > 0 )
v6 = cat_args(argc - optind, &argv[optind]);
if ( tivoclipKB < 0 && userKB < 0 )
LABEL_23:
usage();
mfs_init_dev(v6);
v7 = mfs_resolve(v3);
if ( !v7 )
{
fprintf(
stderr,
"\n"
" MFS Path \"%s\" does not seem to be valid.\n"
" This disk does not appear to have a capacity lock that we can remove.\n",
v3);
exit(1);
}
unlock_obj(v7, v4);
if ( hits == 2 )
{
v8 = "not ";
if ( !v4 )
v8 = (const char *)&unk_91B;
printf("Success! (%scommitted)\n", v8);
}
else
{
puts("Failure: the DiskConfigurations object didn't match the expected structure");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // er12
int v5; // eax
char *v6; // r8
unsigned int v7; // edi
const char *v8; // rsi

v3 = "/Config/DiskConfigurations/Active";
v4 = 1;
prog = (__int64)*argv;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "u:c:p:wh");
if ( v5 == -1 )
break;
if ( v5 == 117 )
{
userKB = atoi(optarg);
}
else if ( v5 > 117 )
{
if ( v5 != 119 )
goto LABEL_23;
v4 = 0;
}
else if ( v5 == 99 )
{
tivoclipKB = atoi(optarg);
}
else
{
if ( v5 != 112 )
goto LABEL_23;
v3 = optarg;
}
}
v6 = 0LL;
if ( argc - optind > 0 )
v6 = func0(argc - optind, &argv[optind]);
if ( tivoclipKB < 0 && userKB < 0 )
LABEL_23:
func1();
mfs_init_dev(v6);
v7 = mfs_resolve(v3);
if ( !v7 )
{
fprintf(
stderr,
"\n"
" MFS Path \"%s\" does not seem to be valid.\n"
" This disk does not appear to have a capacity lock that we can remove.\n",
v3);
exit(1);
}
func2(v7, v4);
if ( hits == 2 )
{
v8 = "not ";
if ( !v4 )
v8 = (const char *)&unk_91B;
printf("Success! (%scommitted)\n", v8);
}
else
{
puts("Failure: the DiskConfigurations object didn't match the expected structure");
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 prog = argv[0];
 char *path = "/Config/DiskConfigurations/Active";
 int test=1;
 char *dev=0;
 while ((c = getopt(argc, argv, "u:c:p:wh")) != -1 ){
  switch (c) {
  case 'c':
   tivoclipKB = atoi(optarg);
   break;
  case 'h':
   usage();
   break;
  case 'p':
   path = optarg;
   break;
  case 'w':
   test=0;
   break;
  case 'u':
   userKB = atoi(optarg);
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc > 0)
  dev = cat_args( argc, argv );
 if ((tivoclipKB<0 && userKB<0))
  usage();
 mfs_init_dev(dev);
 fsid = mfs_resolve(path);
 if (fsid == 0) {
  fprintf( stderr, "\n  MFS Path \"%s\" does not seem to be valid.\n  This disk does not appear to have a  capacity lock that we can remove.\n", path );
  exit(1);
 }
 unlock_obj(fsid,test);
 if (hits==2) {
  printf( "Success! (%scommitted)\n", test?"not ":"");
 } else
  printf( "Failure: the DiskConfigurations object didn't match the expected structure\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 prog = argv[0];
 char *path = "/Config/DiskConfigurations/Active";
 int test = 1;
 char *dev = 0;
 while ((c = getopt(argc, argv, "u:c:p:wh")) != -1 ){
  switch (c) {
  case 'c':
   tivoclipKB = atoi(optarg);
   break;
  case 'h':
   usage();
   break;
  case 'p':
   path = optarg;
   break;
  case 'w':
   test=0;
   break;
  case 'u':
   userKB = atoi(optarg);
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc > 0)
  dev = cat_args( argc, argv );
 if ((tivoclipKB<0 && userKB<0))
  usage();
 mfs_init_dev(dev);
 fsid = mfs_resolve(path);
 if (fsid == 0) {
  fprintf( stderr, "\n  MFS Path \"%s\" does not seem to be valid.\n  This disk does not appear to have a  capacity lock that we can remove.\n", path );
  exit(1);
 }
 unlock_obj(fsid,test);
 if (hits==2) {
  printf( "Success! (%scommitted)\n", test?"not ":"");
 } else
  printf( "Failure: the DiskConfigurations object didn't match the expected structure\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
path
char *

variable_types:
dev
char *

return_type: int


decompiled_code:
void __fastcall bitmap_set(__int64 *a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edi
unsigned int v5; // er9
__int64 v6; // rdx
char v7; // cl
__int64 v8; // rax

v4 = a2 + a3;
v5 = *((_DWORD *)a1 + 2);
if ( a2 + a3 > v5 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "Invalid bitmap set bits=%d i=%d n=%d\n", *((unsigned int *)a1 + 2), a2, a3);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Invalid bitmap set bits=%d i=%d n=%d\n", *((unsigned int *)a1 + 2), a2, a3);
}
else
{
fprintf(stderr, "Invalid bitmap set bits=%d i=%d n=%d\n", *((unsigned int *)a1 + 2), a2, a3);
}
}
else
{
fprintf(stderr, "Invalid bitmap set bits=%d i=%d n=%d\n", v5, a2, a3);
}
exit(1);
}
if ( a3 )
{
v6 = *a1;
do
{
v7 = 31 - a2;
v8 = a2++ >> 5;
*(_DWORD *)(v6 + 4 * v8) |= 1 << v7;
}
while ( v4 != a2 );
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 *a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edi
unsigned int v5; // er9
__int64 v6; // rdx
char v7; // cl
__int64 v8; // rax

v4 = a2 + a3;
v5 = *((_DWORD *)a1 + 2);
if ( a2 + a3 > v5 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "Invalid bitmap set bits=%d i=%d n=%d\n", *((unsigned int *)a1 + 2), a2, a3);
}
else if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Invalid bitmap set bits=%d i=%d n=%d\n", *((unsigned int *)a1 + 2), a2, a3);
}
else
{
fprintf(stderr, "Invalid bitmap set bits=%d i=%d n=%d\n", *((unsigned int *)a1 + 2), a2, a3);
}
}
else
{
fprintf(stderr, "Invalid bitmap set bits=%d i=%d n=%d\n", v5, a2, a3);
}
exit(1);
}
if ( a3 )
{
v6 = *a1;
do
{
v7 = 31 - a2;
v8 = a2++ >> 5;
*(_DWORD *)(v6 + 4 * v8) |= 1 << v7;
}
while ( v4 != a2 );
}
}

original_code:
void bitmap_set(struct bitmap *bm, unsigned i, unsigned n)
{
 if (i+n > bm->n) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n),1) : 1) : fprintf((stderr),"Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n)) : fprintf((stderr),"Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n));
  exit(1);
 }
 while (n--) {
  bm->b[i/32] |= (1<<((31-i)%32));
  i++;
 }
}

canonical_original_code:
void bitmap_set(struct bitmap *bm, unsigned int i, unsigned int n)
{
 if (i+n > bm->n) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n),1) : 1) : fprintf((stderr),"Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n)) : fprintf((stderr),"Invalid bitmap set bits=%d i=%d n=%d\n", bm->n, i, n));
  exit(1);
 }
 while (n--) {
  bm->b[i/32] |= (1<<((31-i)%32));
  i++;
 }
}

variable_types: struct bitmap { unsigned int *b; int n; } *

variable_types:
i
unsigned int

variable_types:
n
unsigned int


decompiled_code:
_BOOL8 __fastcall bitmap_query(_QWORD *a1, unsigned int a2)
{
return (*(_DWORD *)(*a1 + 4LL * (a2 >> 5)) & (1 << ~(_BYTE)a2)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1, unsigned int a2)
{
return (*(_DWORD *)(*a1 + 4LL * (a2 >> 5)) & (1 << ~(_BYTE)a2)) != 0;
}

original_code:
int bitmap_query(struct bitmap *bm, unsigned i)
{
 if (bm->b[i/32] & (1<<((31-i)%32))) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int bitmap_query(struct bitmap *bm, unsigned int i)
{
 if (bm->b[i/32] & (1<<((31-i)%32))) {
  return 1;
 }
 return 0;
}

user_defined_types: struct bitmap { unsigned int *b; int n; }


decompiled_code:
void __fastcall process_key(int a1)
{
int v1; // eax
int v2; // eax

switch ( a1 )
{
case 'q':
kill(peer_pid, 15);
exit(0);
case 's':
v2 = *(_DWORD *)(shmem + 4) + 100;
if ( v2 >= *(_DWORD *)shmem )
v2 = *(_DWORD *)shmem - 1;
*(_DWORD *)(shmem + 4) = v2;
break;
case 'b':
v1 = *(_DWORD *)(shmem + 4) - 100;
if ( v1 <= 0 )
v1 = 1;
*(_DWORD *)(shmem + 4) = v1;
break;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
int v1; // eax
int v2; // eax

switch ( a1 )
{
case 'q':
kill(peer_pid, 15);
exit(0);
case 's':
v2 = *(_DWORD *)(shmem + 4) + 100;
if ( v2 >= *(_DWORD *)shmem )
v2 = *(_DWORD *)shmem - 1;
*(_DWORD *)(shmem + 4) = v2;
break;
case 'b':
v1 = *(_DWORD *)(shmem + 4) - 100;
if ( v1 <= 0 )
v1 = 1;
*(_DWORD *)(shmem + 4) = v1;
break;
}
}

original_code:
static void process_key(int c)
{
 switch (c) {
 case 'q':
  kill(peer_pid, 15);
  exit(0);
  break;
 case 's':
  shmem->blk += 100;
  if (shmem->blk >= shmem->size) shmem->blk = shmem->size-1;
  break;
 case 'b':
  shmem->blk -= 100;
  if (shmem->blk < 1) shmem->blk = 1;
  break;
 }
}


decompiled_code:
int curses_start()
{
int result; // eax

if ( use_ncurses )
{
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
result = nodelay(stdscr, 1);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

if ( use_ncurses )
{
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
result = nodelay(stdscr, 1);
}
return result;
}

original_code:
static void curses_start(void)
{
 if (use_ncurses) {
  initscr(); cbreak(); noecho();
  nonl();
  intrflush(stdscr, 0);
  keypad(stdscr, 1);
  nodelay(stdscr, 1);
 }
}

canonical_original_code:
static void curses_start()
{
 if (use_ncurses) {
  initscr(); cbreak(); noecho();
  nonl();
  intrflush(stdscr, 0);
  keypad(stdscr, 1);
  nodelay(stdscr, 1);
 }
}


decompiled_code:
int curses_paint()
{
if ( !use_ncurses )
return printf("Block %d of %d\r", *(unsigned int *)(shmem + 4), *(unsigned int *)shmem);
wclear(stdscr);
mvprintw(0, 0, "Block %d of %d\n", *(unsigned int *)(shmem + 4), *(unsigned int *)shmem);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func4()
{
if ( !use_ncurses )
return printf("Block %d of %d\r", *(unsigned int *)(shmem + 4), *(unsigned int *)shmem);
wclear(stdscr);
mvprintw(0, 0, "Block %d of %d\n", *(unsigned int *)(shmem + 4), *(unsigned int *)shmem);
return wrefresh(stdscr);
}

original_code:
static void curses_paint(void)
{
 if (use_ncurses) {
  wclear(stdscr);
  mvprintw(0, 0, "Block %d of %d\n", shmem->blk, shmem->size);
  wrefresh(stdscr);
 } else {
  printf("Block %d of %d\r", shmem->blk, shmem->size);
 }
}

canonical_original_code:
static void curses_paint()
{
 if (use_ncurses) {
  wclear(stdscr);
  mvprintw(0, 0, "Block %d of %d\n", shmem->blk, shmem->size);
  wrefresh(stdscr);
 } else {
  printf("Block %d of %d\r", shmem->blk, shmem->size);
 }
}


decompiled_code:
__int64 __fastcall vplayer_fetch(char *s, int a2)
{
unsigned int v3; // er15
__int64 v4; // rax
__int64 v5; // rbx
_DWORD *v6; // rdx
unsigned __int64 v7; // rax
signed int v8; // ebx
__int64 result; // rax
void *v10; // rsi
__int64 v11; // rax
int v12; // edx
int v13; // ecx
int v14; // edi
unsigned int v15; // eax
unsigned int v16; // [rsp+Ch] [rbp-3Ch]

if ( *(int *)(shmem + 8) <= 0 )
*(_DWORD *)(shmem + 8) = 1;
if ( a2 )
{
v15 = open64(s, 0);
v3 = v15;
if ( v15 == -1 )
{
perror(s);
exit(1);
}
v5 = ll_seek(v15, 0LL, 2LL);
ll_seek(v3, (int)(*(_DWORD *)(shmem + 8) << 17), 0LL);
v16 = 0;
}
else
{
v3 = 0;
mfs_init();
mfs_readahead(1LL);
v4 = strtol(s, 0LL, 0);
v16 = v4;
v5 = mfs_fsid_size(v4);
}
v6 = (_DWORD *)shmem;
v7 = v5;
v8 = 0;
*(_DWORD *)shmem = v7 >> 17;
LODWORD(v7) = v6[2];
v6[6] = 1;
v6[1] = v7;
curses_start();
for ( result = shmem; *(_DWORD *)(shmem + 4) < *(_DWORD *)shmem; result = shmem )
{
if ( *(_DWORD *)(result + 4LL * v8 + 52) != -1 )
{
do
{
usleep(0x3E8u);
result = shmem;
}
while ( *(_DWORD *)(shmem + 4 * (v8 + 12LL) + 4) != -1 );
}
v10 = (void *)(result + ((__int64)v8 << 17) + 76);
if ( a2 )
read(v3, v10, 0x20000uLL);
else
mfs_fsid_pread(v16, v10, (__int64)(int)(*(_DWORD *)(result + 4) << 8) << 9, 0x20000LL);
v11 = shmem;
v12 = *(_DWORD *)(shmem + 4);
v13 = *(_DWORD *)(shmem + 24);
*(_DWORD *)(shmem + 4LL * v8 + 52) = v12;
*(_DWORD *)(v11 + 4LL * v8 + 28) = v13;
*(_DWORD *)(v11 + 4) = v12 + 1;
*(_DWORD *)(v11 + 24) = v13 & 0xFFFFFFFE;
v8 = (v8 + 1) % 6u;
if ( use_ncurses )
{
v14 = wgetch(stdscr);
if ( v14 != -1 )
process_key(v14);
}
curses_paint();
}
*(_DWORD *)(result + 4LL * v8 + 52) = -2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, int a2)
{
unsigned int v3; // er15
__int64 v4; // rax
__int64 v5; // rbx
_DWORD *v6; // rdx
unsigned __int64 v7; // rax
signed int v8; // ebx
__int64 result; // rax
void *v10; // rsi
__int64 v11; // rax
int v12; // edx
int v13; // ecx
int v14; // edi
unsigned int v15; // eax
unsigned int v16; // [rsp+Ch] [rbp-3Ch]

if ( *(int *)(shmem + 8) <= 0 )
*(_DWORD *)(shmem + 8) = 1;
if ( a2 )
{
v15 = open64(s, 0);
v3 = v15;
if ( v15 == -1 )
{
perror(s);
exit(1);
}
v5 = ll_seek(v15, 0LL, 2LL);
ll_seek(v3, (int)(*(_DWORD *)(shmem + 8) << 17), 0LL);
v16 = 0;
}
else
{
v3 = 0;
mfs_init();
mfs_readahead(1LL);
v4 = strtol(s, 0LL, 0);
v16 = v4;
v5 = mfs_fsid_size(v4);
}
v6 = (_DWORD *)shmem;
v7 = v5;
v8 = 0;
*(_DWORD *)shmem = v7 >> 17;
LODWORD(v7) = v6[2];
v6[6] = 1;
v6[1] = v7;
func3();
for ( result = shmem; *(_DWORD *)(shmem + 4) < *(_DWORD *)shmem; result = shmem )
{
if ( *(_DWORD *)(result + 4LL * v8 + 52) != -1 )
{
do
{
usleep(0x3E8u);
result = shmem;
}
while ( *(_DWORD *)(shmem + 4 * (v8 + 12LL) + 4) != -1 );
}
v10 = (void *)(result + ((__int64)v8 << 17) + 76);
if ( a2 )
read(v3, v10, 0x20000uLL);
else
mfs_fsid_pread(v16, v10, (__int64)(int)(*(_DWORD *)(result + 4) << 8) << 9, 0x20000LL);
v11 = shmem;
v12 = *(_DWORD *)(shmem + 4);
v13 = *(_DWORD *)(shmem + 24);
*(_DWORD *)(shmem + 4LL * v8 + 52) = v12;
*(_DWORD *)(v11 + 4LL * v8 + 28) = v13;
*(_DWORD *)(v11 + 4) = v12 + 1;
*(_DWORD *)(v11 + 24) = v13 & 0xFFFFFFFE;
v8 = (v8 + 1) % 6u;
if ( use_ncurses )
{
v14 = wgetch(stdscr);
if ( v14 != -1 )
func1(v14);
}
func4();
}
*(_DWORD *)(result + 4LL * v8 + 52) = -2;
return result;
}

original_code:
static void vplayer_fetch(char *fname, int raw)
{
 int next = 0;
 int fsid=0, fd=0;
 u64 size;
 if (shmem->start < 1) shmem->start = 1;
 if (!raw) {
  mfs_init();
  mfs_readahead(1);
  fsid = strtol(fname, ((void *)0), 0);
  size = mfs_fsid_size(fsid);
 } else {
  fd = open(fname, 00|0);
  if (fd == -1) {
   perror(fname);
   exit(1);
  }
  size = ll_seek(fd, 0, 2);
  ll_seek(fd, shmem->start*(256*512), 0);
 }
 shmem->size = (size >> 9) / 256;
 shmem->blk = shmem->start;
 shmem->current_flags = 1;
 curses_start();
 while (shmem->blk < shmem->size) {
  int c;
  while (shmem->blknum[next] != -1) usleep(1000);
  if (raw) {
   read(fd, shmem->data[next], (256*512));
  } else {
   mfs_fsid_pread(fsid, shmem->data[next],
           ((u64)(shmem->blk*256))<<9, (256*512));
  }
  shmem->flags[next] = shmem->current_flags;
  shmem->blknum[next] = shmem->blk;
  shmem->current_flags &= ~1;
  shmem->blk++;
  next = (next+1) % 6;
  if (use_ncurses && (c = wgetch(stdscr)) != (-1)) {
   process_key(c);
  }
  curses_paint();
 }
 shmem->blknum[next] = -2;
}

canonical_original_code:
static void vplayer_fetch(char *fname, int raw)
{
 int next = 0;
 int fsid = 0; int fd = 0;
 unsigned int size;
 if (shmem->start < 1) shmem->start = 1;
 if (!raw) {
  mfs_init();
  mfs_readahead(1);
  fsid = strtol(fname, ((void *)0), 0);
  size = mfs_fsid_size(fsid);
 } else {
  fd = open(fname, 00|0);
  if (fd == -1) {
   perror(fname);
   exit(1);
  }
  size = ll_seek(fd, 0, 2);
  ll_seek(fd, shmem->start*(256*512), 0);
 }
 shmem->size = (size >> 9) / 256;
 shmem->blk = shmem->start;
 shmem->current_flags = 1;
 curses_start();
 while (shmem->blk < shmem->size) {
  int c;
  while (shmem->blknum[next] != -1) usleep(1000);
  if (raw) {
   read(fd, shmem->data[next], (256*512));
  } else {
   mfs_fsid_pread(fsid, shmem->data[next],
           ((u64)(shmem->blk*256))<<9, (256*512));
  }
  shmem->flags[next] = shmem->current_flags;
  shmem->blknum[next] = shmem->blk;
  shmem->current_flags &= ~1;
  shmem->blk++;
  next = (next+1) % 6;
  if (use_ncurses && (c = wgetch(stdscr)) != (-1)) {
   process_key(c);
  }
  curses_paint();
 }
 shmem->blknum[next] = -2;
}

variable_types:
fname
char *

variable_types: raw int

variable_types: next int

variable_types: fsid int

variable_types: fd int

variable_types:
size
unsigned int


original_code:
void push_buffer(struct buffer *buffer, char *buf, int size)
{
 int n;
 fd_set fds;
 void push(struct buffer *obuffer) {
  int n = obuffer->count - obuffer->delay;
  if (shmem->bufsize - obuffer->read_ptr < n) {
   n = shmem->bufsize - obuffer->read_ptr;
  }
  n = write(obuffer->fd,
     &obuffer->buf[obuffer->read_ptr], n);
  if (n > 0) {
   obuffer->read_ptr += n;
   obuffer->count -= n;
   if (obuffer->read_ptr == shmem->bufsize) {
    obuffer->read_ptr = 0;
   }
  }
 }
 while (size) {
  if (buffer->count < shmem->bufsize) {
   n = size;
   if (buffer->write_ptr + n > shmem->bufsize)
    n = shmem->bufsize - buffer->write_ptr;
   if (buffer->count + n > shmem->bufsize)
    n = shmem->bufsize - buffer->count;
   memcpy(&buffer->buf[buffer->write_ptr], buf, n);
   buffer->write_ptr += n;
   buffer->count += n;
   buf += n;
   size -= n;
   if (buffer->write_ptr == shmem->bufsize) {
    buffer->write_ptr = 0;
   }
  }
  if (size == 0) break;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
  if (abuffer.count > abuffer.delay) ((void) (((&fds)->fds_bits)[((abuffer.fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((abuffer.fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (vbuffer.count > vbuffer.delay) ((void) (((&fds)->fds_bits)[((vbuffer.fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((vbuffer.fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (select(((abuffer.fd)>(vbuffer.fd)?(abuffer.fd):(vbuffer.fd))+1,
      ((void *)0), &fds, ((void *)0), ((void *)0)) <= 0) {
   continue;
  }
  if (((((&fds)->fds_bits)[((abuffer.fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((abuffer.fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   push(&abuffer);
  }
  if (((((&fds)->fds_bits)[((vbuffer.fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((vbuffer.fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   push(&vbuffer);
  }
 }
}

canonical_original_code:
void push_buffer(struct buffer *buffer, char *buf, int size)
{
 int n;
 struct fd_set fds;
 void push(struct buffer *obuffer) {
  int n = obuffer->count - obuffer->delay;
  if (shmem->bufsize - obuffer->read_ptr < n) {
   n = shmem->bufsize - obuffer->read_ptr;
  }
  n = write(obuffer->fd,
     &obuffer->buf[obuffer->read_ptr], n);
  if (n > 0) {
   obuffer->read_ptr += n;
   obuffer->count -= n;
   if (obuffer->read_ptr == shmem->bufsize) {
    obuffer->read_ptr = 0;
   }
  }
 }
 while (size) {
  if (buffer->count < shmem->bufsize) {
   n = size;
   if (buffer->write_ptr + n > shmem->bufsize)
    n = shmem->bufsize - buffer->write_ptr;
   if (buffer->count + n > shmem->bufsize)
    n = shmem->bufsize - buffer->count;
   memcpy(&buffer->buf[buffer->write_ptr], buf, n);
   buffer->write_ptr += n;
   buffer->count += n;
   buf += n;
   size -= n;
   if (buffer->write_ptr == shmem->bufsize) {
    buffer->write_ptr = 0;
   }
  }
  if (size == 0) break;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
  if (abuffer.count > abuffer.delay) ((void) (((&fds)->fds_bits)[((abuffer.fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((abuffer.fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (vbuffer.count > vbuffer.delay) ((void) (((&fds)->fds_bits)[((vbuffer.fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((vbuffer.fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (select(((abuffer.fd)>(vbuffer.fd)?(abuffer.fd):(vbuffer.fd))+1,
      ((void *)0), &fds, ((void *)0), ((void *)0)) <= 0) {
   continue;
  }
  if (((((&fds)->fds_bits)[((abuffer.fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((abuffer.fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   push(&abuffer);
  }
  if (((((&fds)->fds_bits)[((vbuffer.fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((vbuffer.fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   push(&vbuffer);
  }
 }
}

variable_types: struct buffer { char *buf; int write_ptr; int read_ptr; int count; int fd; int delay; } *

variable_types:
buf
char *

variable_types: size int

variable_types: n int

variable_types:
fds
struct fd_set { long fds_bits[-1]; }


decompiled_code:
__int64 vplayer_play()
{
__int64 v0; // rbp
unsigned int v1; // ebx
__int64 result; // rax
__int64 v3; // r13
int v4; // edx
unsigned int v5; // ebx

v0 = 0LL;
v1 = 0;
for ( result = shmem; ; result = shmem )
{
v3 = v0 + 12;
v4 = *(_DWORD *)(result + 4 * (v0 + 12) + 4);
if ( v4 != -1 )
break;
LABEL_5:
usleep(0x3E8u);
}
while ( v4 != -2 )
{
v5 = v1 + 1;
parse_chunk_constprop_0((_BYTE *)(result + (v0 << 17) + 76));
result = shmem;
*(_DWORD *)(shmem + 4 * v3 + 4) = -1;
v0 = v5 % 6;
v3 = v0 + 12;
v1 = v5 % 6;
v4 = *(_DWORD *)(result + 4 * (v0 + 12) + 4);
if ( v4 == -1 )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbp
unsigned int v1; // ebx
__int64 result; // rax
__int64 v3; // r13
int v4; // edx
unsigned int v5; // ebx

v0 = 0LL;
v1 = 0;
for ( result = shmem; ; result = shmem )
{
v3 = v0 + 12;
v4 = *(_DWORD *)(result + 4 * (v0 + 12) + 4);
if ( v4 != -1 )
break;
LABEL_5:
usleep(0x3E8u);
}
while ( v4 != -2 )
{
v5 = v1 + 1;
func8((_BYTE *)(result + (v0 << 17) + 76));
result = shmem;
*(_DWORD *)(shmem + 4 * v3 + 4) = -1;
v0 = v5 % 6;
v3 = v0 + 12;
v1 = v5 % 6;
v4 = *(_DWORD *)(result + 4 * (v0 + 12) + 4);
if ( v4 == -1 )
goto LABEL_5;
}
return result;
}

original_code:
static void vplayer_play(void)
{
 int next = 0;
 while (1) {
  while (shmem->blknum[next] == -1) usleep(1000);
  if (shmem->blknum[next] == -2) break;
  parse_chunk(shmem->data[next], shmem->flags[next]);
  shmem->blknum[next] = -1;
  next = (next+1) % 6;
 }
}

canonical_original_code:
static void vplayer_play()
{
 int next = 0;
 while (1) {
  while (shmem->blknum[next] == -1) usleep(1000);
  if (shmem->blknum[next] == -2) break;
  parse_chunk(shmem->data[next], shmem->flags[next]);
  shmem->blknum[next] = -1;
  next = (next+1) % 6;
 }
}


usage

decompiled_code:
void __noreturn usage()
{
printf(
"\n"
" vplayer [options] <fsid>\n"
"OR vplayer -l\n"
"\n"
"options:\n"
" -d <delay> delay video\n"
" -l list fsid of recorded streams\n"
" -a <prog> set audio program (default %s)\n"
" -v <prog> set video program (default %s)\n"
" -s <start> set starting block\n",
"mpg123 -q - 2> /dev/null",
"mpeg2dec -o xshm > /dev/null 2>&1");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
printf(
"\n"
" vplayer [options] <fsid>\n"
"OR vplayer -l\n"
"\n"
"options:\n"
" -d <delay> delay video\n"
" -l list fsid of recorded streams\n"
" -a <prog> set audio program (default %s)\n"
" -v <prog> set video program (default %s)\n"
" -s <start> set starting block\n",
"mpg123 -q - 2> /dev/null",
"mpeg2dec -o xshm > /dev/null 2>&1");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\n   vplayer [options] <fsid>\nOR vplayer -l\n\noptions:\n         -d <delay>                delay video\n         -l                        list fsid of recorded streams\n         -a <prog>                 set audio program (default %s)\n         -v <prog>                 set video program (default %s)\n         -s <start>                set starting block\n", "mpg123 -q - 2> /dev/null", "mpeg2dec -o xshm > /dev/null 2>&1");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\n   vplayer [options] <fsid>\nOR vplayer -l\n\noptions:\n         -d <delay>                delay video\n         -l                        list fsid of recorded streams\n         -a <prog>                 set audio program (default %s)\n         -v <prog>                 set video program (default %s)\n         -s <start>                set starting block\n", "mpg123 -q - 2> /dev/null", "mpeg2dec -o xshm > /dev/null 2>&1");
 credits();
 exit(1);
}


decompiled_code:
__int64 __fastcall get_attribute(__int64 a1, __int64 a2, const char *a3, int a4)
{
unsigned __int64 v4; // r13
const char *v5; // r8
_DWORD *v6; // r9
const char *v7; // r14
_DWORD *v8; // rbx
unsigned __int16 v9; // ax
const char *v10; // rdi
unsigned int v11; // er8
unsigned __int64 v12; // rcx
bool v13; // al
unsigned __int64 v15; // r15
unsigned __int16 v16; // ax
int v17; // er12
const char *v18; // r8
unsigned __int8 v19; // al
const char *v20; // rbp
unsigned __int8 v21; // al
unsigned __int64 v22; // r13
__int64 v23; // rdx
int v24; // eax
__int64 v25; // rdx
__int64 v26; // rdx
unsigned __int64 v27; // rsi
int v28; // eax
__int64 v29; // rdx
int v30; // eax
__int64 v31; // rdx
int v32; // eax
__int64 v33; // r12
size_t v34; // rax
char *v35; // rax
unsigned __int64 v36; // [rsp+0h] [rbp-58h]
unsigned __int64 v38; // [rsp+10h] [rbp-48h]

v4 = a1 + 8;
v38 = a1 + (unsigned int)_bswap_32(*(_DWORD *)(a1 + 4));
if ( v38 <= a1 + 8 )
return 0;
v7 = v5;
v8 = v6;
LABEL_3:
v9 = _bswap_16(*(_WORD *)(v4 + 4));
v10 = (const char *)schema_type(v9);
if ( !v10 )
v10 = &s1;
strcmp(v10, a3);
v36 = v4 + (unsigned __int16)_bswap_16(*(_WORD *)v4);
if ( v11 )
{
v13 = v38 > v36;
goto LABEL_11;
}
if ( a4 != -1 && (unsigned int)_bswap_32(*(_DWORD *)(v4 + 12)) != a4 )
goto LABEL_8;
v15 = v4 + 16;
if ( v4 + 16 >= v36 )
{
v12 = v36;
LABEL_8:
if ( v38 > v12 )
goto LABEL_9;
}
else
{
while ( 1 )
{
v16 = _bswap_16(*(_WORD *)(v4 + 4));
schema_attrib(v16, *(unsigned __int8 *)(v15 + 1));
v17 = (unsigned __int16)_bswap_16(*(_WORD *)(v15 + 2));
if ( !strcmp(v18, v7) )
break;
v15 += (int)((v17 + 3) & 0xFFFFFFFC);
if ( v15 >= v36 )
{
v36 = v4 + (unsigned __int16)_bswap_16(*(_WORD *)v4);
v13 = v38 > v36;
LABEL_11:
if ( !v13 )
return 0;
LABEL_9:
v4 = v36;
goto LABEL_3;
}
}
v19 = *(_BYTE *)v15;
v20 = (const char *)(v15 + 4);
v8[1] = 0;
v21 = v19 >> 6;
v22 = v15 + (unsigned __int16)v17;
*v8 = v21;
if ( v21 == 1 )
{
v33 = 1LL;
if ( (unsigned __int64)v20 < v22 )
{
while ( 1 )
{
v34 = strlen(v20);
v35 = (char *)malloc(v34 + 1);
v8[1] = v33;
*(_QWORD *)&v8[2 * v33] = strcpy(v35, v20);
v20 += strlen(v20) + 1;
if ( (unsigned __int64)v20 >= v22 )
break;
if ( ++v33 == 129 )
_assert_fail("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 0x42u, "get_attribute");
}
}
return 1;
}
if ( v21 != 2 )
{
if ( (unsigned __int64)v20 < v22 )
{
v23 = 1LL;
while ( 1 )
{
v24 = _bswap_32(*(_DWORD *)(v15 + 4 * v23));
v8[1] = v25;
v8[v25 + 1] = v24;
if ( (((unsigned __int64)(unsigned __int16)v17 - 5) >> 2) + 1 == v25 )
break;
v23 = v25 + 1;
if ( v23 == 129 )
_assert_fail("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 0x4Cu, "get_attribute");
}
}
return 1;
}
if ( (unsigned __int64)v20 >= v22 )
return 1;
v26 = 1LL;
v27 = (((unsigned __int64)(unsigned __int16)v17 - 5) >> 3) + 1;
while ( 1 )
{
v28 = _bswap_32(*(_DWORD *)(v15 + 8 * v26 - 4));
v8[2 * v29] = v28;
v30 = _bswap_32(*(_DWORD *)(v15 + 8 * v29));
v8[2 * v31 + 1] = v30;
v32 = v31;
if ( v27 == v31 )
break;
v26 = v31 + 1;
if ( v26 == 129 )
{
v8[1] = v32;
_assert_fail("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 0x55u, "get_attribute");
}
}
v8[1] = v27;
v11 = 1;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, const char *a3, int a4)
{
unsigned __int64 v4; // r13
const char *v5; // r8
_DWORD *v6; // r9
const char *v7; // r14
_DWORD *v8; // rbx
unsigned __int16 v9; // ax
const char *v10; // rdi
unsigned int v11; // er8
unsigned __int64 v12; // rcx
bool v13; // al
unsigned __int64 v15; // r15
unsigned __int16 v16; // ax
int v17; // er12
const char *v18; // r8
unsigned __int8 v19; // al
const char *v20; // rbp
unsigned __int8 v21; // al
unsigned __int64 v22; // r13
__int64 v23; // rdx
int v24; // eax
__int64 v25; // rdx
__int64 v26; // rdx
unsigned __int64 v27; // rsi
int v28; // eax
__int64 v29; // rdx
int v30; // eax
__int64 v31; // rdx
int v32; // eax
__int64 v33; // r12
size_t v34; // rax
char *v35; // rax
unsigned __int64 v36; // [rsp+0h] [rbp-58h]
unsigned __int64 v38; // [rsp+10h] [rbp-48h]

v4 = a1 + 8;
v38 = a1 + (unsigned int)func0(*(_DWORD *)(a1 + 4));
if ( v38 <= a1 + 8 )
return 0;
v7 = v5;
v8 = v6;
LABEL_3:
v9 = func1(*(_WORD *)(v4 + 4));
v10 = (const char *)schema_type(v9);
if ( !v10 )
v10 = &s1;
strcmp(v10, a3);
v36 = v4 + (unsigned __int16)func1(*(_WORD *)v4);
if ( v11 )
{
v13 = v38 > v36;
goto LABEL_11;
}
if ( a4 != -1 && (unsigned int)func0(*(_DWORD *)(v4 + 12)) != a4 )
goto LABEL_8;
v15 = v4 + 16;
if ( v4 + 16 >= v36 )
{
v12 = v36;
LABEL_8:
if ( v38 > v12 )
goto LABEL_9;
}
else
{
while ( 1 )
{
v16 = func1(*(_WORD *)(v4 + 4));
schema_attrib(v16, *(unsigned __int8 *)(v15 + 1));
v17 = (unsigned __int16)func1(*(_WORD *)(v15 + 2));
if ( !strcmp(v18, v7) )
break;
v15 += (int)((v17 + 3) & 0xFFFFFFFC);
if ( v15 >= v36 )
{
v36 = v4 + (unsigned __int16)func1(*(_WORD *)v4);
v13 = v38 > v36;
LABEL_11:
if ( !v13 )
return 0;
LABEL_9:
v4 = v36;
goto LABEL_3;
}
}
v19 = *(_BYTE *)v15;
v20 = (const char *)(v15 + 4);
v8[1] = 0;
v21 = v19 >> 6;
v22 = v15 + (unsigned __int16)v17;
*v8 = v21;
if ( v21 == 1 )
{
v33 = 1LL;
if ( (unsigned __int64)v20 < v22 )
{
while ( 1 )
{
v34 = strlen(v20);
v35 = (char *)malloc(v34 + 1);
v8[1] = v33;
*(_QWORD *)&v8[2 * v33] = strcpy(v35, v20);
v20 += strlen(v20) + 1;
if ( (unsigned __int64)v20 >= v22 )
break;
if ( ++v33 == 129 )
_assert_fail("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 0x42u, "get_attribute");
}
}
return 1;
}
if ( v21 != 2 )
{
if ( (unsigned __int64)v20 < v22 )
{
v23 = 1LL;
while ( 1 )
{
v24 = func0(*(_DWORD *)(v15 + 4 * v23));
v8[1] = v25;
v8[v25 + 1] = v24;
if ( (((unsigned __int64)(unsigned __int16)v17 - 5) >> 2) + 1 == v25 )
break;
v23 = v25 + 1;
if ( v23 == 129 )
_assert_fail("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 0x4Cu, "get_attribute");
}
}
return 1;
}
if ( (unsigned __int64)v20 >= v22 )
return 1;
v26 = 1LL;
v27 = (((unsigned __int64)(unsigned __int16)v17 - 5) >> 3) + 1;
while ( 1 )
{
v28 = func0(*(_DWORD *)(v15 + 8 * v26 - 4));
v8[2 * v29] = v28;
v30 = func0(*(_DWORD *)(v15 + 8 * v29));
v8[2 * v31 + 1] = v30;
v32 = v31;
if ( v27 == v31 )
break;
v26 = v31 + 1;
if ( v26 == 129 )
{
v8[1] = v32;
_assert_fail("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 0x55u, "get_attribute");
}
}
v8[1] = v27;
v11 = 1;
}
return v11;
}

original_code:
int
get_attribute( void *buf, unsigned size, const char *target_subobj_name,
        unsigned target_subobj_id, const char *target_attr_name,
        mfs_attribute_t *attribute)
{
 struct mfs_obj_header *obj;
 struct mfs_subobj_header *subobj;
 struct mfs_attr_header *attr;
 struct mfs_obj_attr *objattr;
 unsigned char *p, *q, *pend, *qend, *r, *rend;
 const char *subobj_name, *attr_name;
 unsigned *pint;
 int found;
 int len, alen;
 found = 0;
 obj = (struct mfs_obj_header *) buf;
 pend = (char *) buf + ntohl(obj->size);
 for(p = (char *) buf + sizeof(struct mfs_obj_header); p < pend && ! found; p += ntohs(subobj->len)) {
  subobj = (struct mfs_subobj_header *) p;
  subobj_name = schema_type(ntohs(subobj->obj_type));
  if (!subobj_name)
   subobj_name = "";
  if (strcmp(subobj_name, target_subobj_name) != 0) {
   continue;
  }
  if (target_subobj_id != 0xffffffff && ntohl(subobj->id) != target_subobj_id) {
   continue;
  }
  qend = p + ntohs(subobj->len);
  for(q = p + sizeof(struct mfs_subobj_header); q < qend && ! found; q += alen) {
   attr = (struct mfs_attr_header *) q;
   attr_name = schema_attrib(ntohs(subobj->obj_type), attr->attr);
   alen = len = ntohs(attr->len);
   alen = (alen + 3) & ~3;
   if (strcmp(attr_name, target_attr_name) != 0) {
    continue;
   }
   found = 1;
   r = q + sizeof(struct mfs_attr_header);
   rend = r + len;
   attribute->type = attr->eltype >> 6;
   attribute->n = 0;
   switch (attribute->type) {
   case 1:
    while (r < rend-4) {
     ((void) sizeof ((attribute->n < 128) ? 1 : 0), __extension__ ({ if (attribute->n < 128) ; else __assert_fail ("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 66, __extension__ __PRETTY_FUNCTION__); }));
     attribute->u.string[attribute->n++] =
      strcpy(malloc(strlen(r) + 1), r);
     r += strlen(r) + 1;
    }
    break;
   case 0:
   case 3:
    while (r < rend-4) {
     ((void) sizeof ((attribute->n < 128) ? 1 : 0), __extension__ ({ if (attribute->n < 128) ; else __assert_fail ("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 76, __extension__ __PRETTY_FUNCTION__); }));
     pint = (int *) r;
     attribute->u.integer[attribute->n++] = ntohl(*pint);
     r += sizeof(unsigned);
    }
    break;
   case 2:
    while (r < rend-4) {
     ((void) sizeof ((attribute->n < 128) ? 1 : 0), __extension__ ({ if (attribute->n < 128) ; else __assert_fail ("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 85, __extension__ __PRETTY_FUNCTION__); }));
     objattr = (struct mfs_obj_attr *) r;
     attribute->u.object[attribute->n].fsid = ntohl(objattr->fsid);
     attribute->u.object[attribute->n].subobj = ntohl(objattr->subobj);
     attribute->n++;
     r += sizeof(struct mfs_obj_attr);
    }
    break;
   }
  }
 }
 return found;
}

canonical_original_code:
int get_attribute(void *buf, unsigned int size, char *target_subobj_name, unsigned int target_subobj_id, char *target_attr_name, struct attribute_struct *attribute)
{
 struct mfs_obj_header *obj;
 struct mfs_subobj_header *subobj;
 struct mfs_attr_header *attr;
 struct mfs_obj_attr *objattr;
 unsigned char *p; unsigned char *q; unsigned char *pend; unsigned char *qend; unsigned char *r; unsigned char *rend;
 char *subobj_name; char *attr_name;
 unsigned int *pint;
 int found;
 int len; int alen;
 found = 0;
 obj = (struct mfs_obj_header *) buf;
 pend = (char *) buf + ntohl(obj->size);
 for(p = (char *) buf + sizeof(struct mfs_obj_header); p < pend && ! found; p += ntohs(subobj->len)) {
  subobj = (struct mfs_subobj_header *) p;
  subobj_name = schema_type(ntohs(subobj->obj_type));
  if (!subobj_name)
   subobj_name = "";
  if (strcmp(subobj_name, target_subobj_name) != 0) {
   continue;
  }
  if (target_subobj_id != 0xffffffff && ntohl(subobj->id) != target_subobj_id) {
   continue;
  }
  qend = p + ntohs(subobj->len);
  for(q = p + sizeof(struct mfs_subobj_header); q < qend && ! found; q += alen) {
   attr = (struct mfs_attr_header *) q;
   attr_name = schema_attrib(ntohs(subobj->obj_type), attr->attr);
   alen = len = ntohs(attr->len);
   alen = (alen + 3) & ~3;
   if (strcmp(attr_name, target_attr_name) != 0) {
    continue;
   }
   found = 1;
   r = q + sizeof(struct mfs_attr_header);
   rend = r + len;
   attribute->type = attr->eltype >> 6;
   attribute->n = 0;
   switch (attribute->type) {
   case 1:
    while (r < rend-4) {
     ((void) sizeof ((attribute->n < 128) ? 1 : 0), __extension__ ({ if (attribute->n < 128) ; else __assert_fail ("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 66, __extension__ __PRETTY_FUNCTION__); }));
     attribute->u.string[attribute->n++] =
      strcpy(malloc(strlen(r) + 1), r);
     r += strlen(r) + 1;
    }
    break;
   case 0:
   case 3:
    while (r < rend-4) {
     ((void) sizeof ((attribute->n < 128) ? 1 : 0), __extension__ ({ if (attribute->n < 128) ; else __assert_fail ("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 76, __extension__ __PRETTY_FUNCTION__); }));
     pint = (int *) r;
     attribute->u.integer[attribute->n++] = ntohl(*pint);
     r += sizeof(unsigned int);
    }
    break;
   case 2:
    while (r < rend-4) {
     ((void) sizeof ((attribute->n < 128) ? 1 : 0), __extension__ ({ if (attribute->n < 128) ; else __assert_fail ("attribute->n < MFS_MAX_ARRAY_LEN", "attribute.c", 85, __extension__ __PRETTY_FUNCTION__); }));
     objattr = (struct mfs_obj_attr *) r;
     attribute->u.object[attribute->n].fsid = ntohl(objattr->fsid);
     attribute->u.object[attribute->n].subobj = ntohl(objattr->subobj);
     attribute->n++;
     r += sizeof(struct mfs_obj_attr);
    }
    break;
   }
  }
 }
 return found;
}

variable_types:
buf
void *

variable_types: struct attribute_struct { int type; int n; union { char *string[128]; int integer[128]; struct mfs_obj_attr { unsigned int fsid; int subobj; } object[128]; } u; } *

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

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

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

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

variable_types:
p
unsigned char *

variable_types:
q
unsigned char *

variable_types:
pend
unsigned char *

variable_types:
qend
unsigned char *

variable_types:
r
unsigned char *

variable_types:
rend
unsigned char *

variable_types:
pint
unsigned int *

variable_types: found int

variable_types: len int

variable_types: alen int

user_defined_types: struct attribute_struct { int type; int n; union { char *string[128]; int integer[128]; struct mfs_obj_attr object[128]; } u; }


decompiled_code:
__int64 __fastcall get_attribute_fsid(unsigned int a1, const char *a2, int a3)
{
unsigned int v3; // ebx
void *v4; // r13
unsigned int v5; // er12

if ( (unsigned int)mfs_fsid_type() != 8 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "%d is not an object\n", a1);
goto LABEL_8;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "%d is not an object\n", a1);
LABEL_8:
exit(1);
}
}
fprintf(stderr, "%d is not an object\n", a1);
goto LABEL_8;
}
v3 = mfs_fsid_size(a1);
v4 = malloc(v3);
mfs_fsid_pread(a1, v4, 0LL, v3);
v5 = get_attribute((__int64)v4, v3, a2, a3);
free(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, const char *a2, int a3)
{
unsigned int v3; // ebx
void *v4; // r13
unsigned int v5; // er12

if ( (unsigned int)mfs_fsid_type() != 8 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "%d is not an object\n", a1);
goto LABEL_8;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "%d is not an object\n", a1);
LABEL_8:
exit(1);
}
}
fprintf(stderr, "%d is not an object\n", a1);
goto LABEL_8;
}
v3 = mfs_fsid_size(a1);
v4 = malloc(v3);
mfs_fsid_pread(a1, v4, 0LL, v3);
v5 = func2((__int64)v4, v3, a2, a3);
free(v4);
return v5;
}

original_code:
int
get_attribute_fsid( int fsid, const char *target_subobj_name,
      unsigned target_subobj_id,
      const char *target_attr_name,
      mfs_attribute_t *attribute)
{
  void *buf;
  unsigned size;
  int found;
  if (mfs_fsid_type(fsid) != 8) {
    (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "%d is not an object\n", fsid),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"%d is not an object\n", fsid),1) : 1) : fprintf((stderr),"%d is not an object\n", fsid)) : 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);
  found = get_attribute( buf, size, target_subobj_name, target_subobj_id, target_attr_name, attribute );
  free(buf);
  return found;
}

canonical_original_code:
int get_attribute_fsid(int fsid, char *target_subobj_name, unsigned int target_subobj_id, char *target_attr_name, struct attribute_struct *attribute)
{
  void *buf;
  unsigned int size;
  int found;
  if (mfs_fsid_type(fsid) != 8) {
    (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "%d is not an object\n", fsid),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"%d is not an object\n", fsid),1) : 1) : fprintf((stderr),"%d is not an object\n", fsid)) : 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);
  found = get_attribute( buf, size, target_subobj_name, target_subobj_id, target_attr_name, attribute );
  free(buf);
  return found;
}

variable_types: fsid int

variable_types:
size
unsigned int

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


original_code:
void
attr_release(mfs_attribute_t *attr)
{
 if (attr->type == 1) {
  int i;
  for (i = 0; i < attr->n; ++i)
   free(attr->u.string[i]);
 }
}

canonical_original_code:
void attr_release(struct attribute_struct *attr)
{
 if (attr->type == 1) {
  int i;
  for (i = 0; i < attr->n; ++i)
   free(attr->u.string[i]);
 }
}

variable_types: struct attribute_struct { int type; int n; union { char *string[128]; int integer[128]; struct mfs_obj_attr { unsigned int fsid; int subobj; } object[128]; } u; } *

variable_types: i int


decompiled_code:
char *get_tivo_version()
{
unsigned int v0; // eax
char *v2; // r12
int v3; // [rsp+0h] [rbp-418h] BYREF
char *s; // [rsp+8h] [rbp-410h]

v0 = mfs_resolve("/SwSystem/ACTIVE");
if ( !v0 || !(unsigned int)get_attribute_fsid(v0, "SwSystem", -1) || v3 != 1 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "Can't find TiVo version!\n");
return strdup("UNKNOWN");
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Can't find TiVo version!\n");
return strdup("UNKNOWN");
}
}
fwrite("Can't find TiVo version!\n", 1uLL, 0x19uLL, stderr);
return strdup("UNKNOWN");
}
v2 = strdup(s);
attr_release(&v3);
return v2;
}

canonical_decompiled_code:
char *func5()
{
unsigned int v0; // eax
char *v2; // r12
int v3; // [rsp+0h] [rbp-418h] BYREF
char *s; // [rsp+8h] [rbp-410h]

v0 = mfs_resolve("/SwSystem/ACTIVE");
if ( !v0 || !(unsigned int)func3(v0, "SwSystem", -1) || v3 != 1 )
{
if ( use_syslog )
{
if ( fileno(stderr) == 2 )
{
syslog(3, "Can't find TiVo version!\n");
return strdup("UNKNOWN");
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "Can't find TiVo version!\n");
return strdup("UNKNOWN");
}
}
fwrite("Can't find TiVo version!\n", 1uLL, 0x19uLL, stderr);
return strdup("UNKNOWN");
}
v2 = strdup(s);
func4(&v3);
return v2;
}

original_code:
char *
get_tivo_version()
{
 int fsid = mfs_resolve("/SwSystem/ACTIVE");
 mfs_attribute_t attr;
 char *retval = 0;
 if (!fsid ||
     !get_attribute_fsid(fsid, "SwSystem", 0xffffffff, "Name", &attr) ||
     attr.type != 1) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Can't find TiVo version!\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Can't find TiVo version!\n"),1) : 1) : fprintf((stderr),"Can't find TiVo version!\n")) : fprintf((stderr),"Can't find TiVo version!\n"));
  return strdup("UNKNOWN");
 }
 retval = strdup(attr.u.string[0]);
 attr_release(&attr);
 return retval;
}

canonical_original_code:
char *get_tivo_version()
{
 int fsid = mfs_resolve("/SwSystem/ACTIVE");
 struct attribute_struct attr;
 char *retval = 0;
 if (!fsid ||
     !get_attribute_fsid(fsid, "SwSystem", 0xffffffff, "Name", &attr) ||
     attr.type != 1) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "Can't find TiVo version!\n"),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"Can't find TiVo version!\n"),1) : 1) : fprintf((stderr),"Can't find TiVo version!\n")) : fprintf((stderr),"Can't find TiVo version!\n"));
  return strdup("UNKNOWN");
 }
 retval = strdup(attr.u.string[0]);
 attr_release(&attr);
 return retval;
}

variable_types: struct attribute_struct { int type; int n; union { char *string[128]; int integer[128]; struct mfs_obj_attr { unsigned int fsid; int subobj; } object[128]; } u; }

variable_types:
retval
char *


decompiled_code:
__int64 xml_printf(char *format, ...)
{
__int64 result; // rax
int v3; // ebx
__int64 v4; // rdi
int v5; // eax
int v6; // edx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
result = (__int64)xml_buf;
if ( xml_buf )
{
v3 = xml_alloc_size;
v4 = xml_len;
goto LABEL_3;
}
xml_len = 0;
xml_alloc_size = 0x4000;
result = (__int64)malloc(0x4000uLL);
xml_buf = (void *)result;
if ( result )
{
v4 = 0LL;
v3 = 0x4000;
LABEL_3:
while ( 1 )
{
v5 = vsnprintf((char *)(result + v4), v3 - (int)v4, format, arg);
if ( v5 >= 0 )
break;
xml_alloc_size *= 2;
v3 = xml_alloc_size;
result = (__int64)realloc(xml_buf, xml_alloc_size);
xml_buf = (void *)result;
if ( !result || v3 > 0xFFFFF )
return result;
v4 = xml_len;
}
v6 = xml_alloc_size;
result = (unsigned int)(xml_len + v5);
if ( (int)result < xml_alloc_size )
{
xml_len = result;
}
else
{
xml_alloc_size *= 2;
result = (__int64)realloc(xml_buf, 2 * v6);
xml_buf = (void *)result;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0(char *format, ...)
{
__int64 result; // rax
int v3; // ebx
__int64 v4; // rdi
int v5; // eax
int v6; // edx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
result = (__int64)xml_buf;
if ( xml_buf )
{
v3 = xml_alloc_size;
v4 = xml_len;
goto LABEL_3;
}
xml_len = 0;
xml_alloc_size = 0x4000;
result = (__int64)malloc(0x4000uLL);
xml_buf = (void *)result;
if ( result )
{
v4 = 0LL;
v3 = 0x4000;
LABEL_3:
while ( 1 )
{
v5 = vsnprintf((char *)(result + v4), v3 - (int)v4, format, arg);
if ( v5 >= 0 )
break;
xml_alloc_size *= 2;
v3 = xml_alloc_size;
result = (__int64)realloc(xml_buf, xml_alloc_size);
xml_buf = (void *)result;
if ( !result || v3 > 0xFFFFF )
return result;
v4 = xml_len;
}
v6 = xml_alloc_size;
result = (unsigned int)(xml_len + v5);
if ( (int)result < xml_alloc_size )
{
xml_len = result;
}
else
{
xml_alloc_size *= 2;
result = (__int64)realloc(xml_buf, 2 * v6);
xml_buf = (void *)result;
}
}
return result;
}

original_code:
static void xml_printf(const char *fmt, ...) {
 va_list ap;
 int len;
 __builtin_va_start(ap,fmt);
 if (xml_buf == 0) {
  xml_len = 0;
  xml_alloc_size = 16*1024;
  xml_buf = malloc(xml_alloc_size);
  if (xml_buf == 0) return;
 }
 do {
  len = vsnprintf( xml_buf+xml_len,xml_alloc_size-xml_len, fmt,
     ap );
  if (len < 0 || (xml_len+len)>=xml_alloc_size) {
   xml_alloc_size *= 2;
   xml_buf = realloc( xml_buf, xml_alloc_size );
  } else
   xml_len += len;
 } while (len < 0 && xml_buf != 0 && xml_alloc_size<max_xml_size);
 __builtin_va_end(ap);
}

canonical_original_code:
static void xml_printf(char *fmt, ...) {
 __builtin_va_list ap;
 int len;
 __builtin_va_start(ap,fmt);
 if (xml_buf == 0) {
  xml_len = 0;
  xml_alloc_size = 16*1024;
  xml_buf = malloc(xml_alloc_size);
  if (xml_buf == 0) return;
 }
 do {
  len = vsnprintf( xml_buf+xml_len,xml_alloc_size-xml_len, fmt,
     ap );
  if (len < 0 || (xml_len+len)>=xml_alloc_size) {
   xml_alloc_size *= 2;
   xml_buf = realloc( xml_buf, xml_alloc_size );
  } else
   xml_len += len;
 } while (len < 0 && xml_buf != 0 && xml_alloc_size<max_xml_size);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


decompiled_code:
void __fastcall generate_object_xml(unsigned int a1, unsigned int a2, int a3, __int64 a4, int a5, const char **a6)
{
unsigned int v9; // er13
const char **v10; // r15
int v11; // eax
__int64 v12; // r14
unsigned int v13; // eax
__int64 v14; // r13
unsigned int v15; // er12
const char **v16; // rbp
unsigned int v17; // er15
const char *v18; // r8
unsigned int v19; // eax
__int64 v20; // rax
__int64 v21; // r14
unsigned int v22; // eax
__int64 v23; // r8
__int64 i; // r14
const char *v25; // r8
const char *v26; // rcx
__int64 v27; // [rsp+0h] [rbp-458h]
unsigned int v29; // [rsp+Ch] [rbp-44Ch]
int v30; // [rsp+10h] [rbp-448h] BYREF
int v31; // [rsp+14h] [rbp-444h]
__int64 v32[136]; // [rsp+18h] [rbp-440h]

if ( a5 > 0 )
{
v9 = a3 + 1;
v10 = a6;
v27 = (__int64)&a6[7 * (unsigned int)(a5 - 1) + 7];
while ( !(unsigned int)get_attribute_fsid(a1, a4, a2, *v10, &v30) )
{
if ( *((_DWORD *)v10 + 3) )
{
fprintf(stderr, "Can't get %s:%s\n", a4, *v10);
goto LABEL_18;
}
LABEL_14:
v10 += 7;
if ( v10 == (const char **)v27 )
return;
}
v11 = *((_DWORD *)v10 + 2);
if ( v30 != v11 )
{
fprintf(stderr, "Bad %s:%s\n", a4, *v10);
LABEL_18:
exit(1);
}
if ( v11 == 2 )
{
for ( i = 0LL; v31 > (int)i; ++i )
{
v25 = v10[4];
v26 = v10[3];
if ( *((_DWORD *)v10 + 4) )
{
xml_printf("%*s<SubObject type=\"%s\" id=\"%s\">\n", v9, (const char *)&unk_159B, v26, v25);
generate_object_xml(a1, HIDWORD(v32[i]), v9, v10[3], *((unsigned int *)v10 + 10), v10[6]);
xml_printf("%*s</SubObject>\n", v9, (const char *)&unk_159B);
}
else
{
xml_printf("%*s<Object type=\"%s\" id=\"%s\">\n", v9, (const char *)&unk_159B, v26, v25);
generate_object_xml(LODWORD(v32[i]), HIDWORD(v32[i]), v9, v10[3], *((unsigned int *)v10 + 10), v10[6]);
xml_printf("%*s</Object>\n", v9, (const char *)&unk_159B);
}
}
goto LABEL_13;
}
if ( v11 > 2 )
{
if ( v11 == 3 )
{
xml_printf("%*s<%s>%d</%s>\n", a3 + 2, (const char *)&unk_159B, *v10, LODWORD(v32[0]), *v10);
v20 = parts_len++;
parts[v20] = v32[0];
}
goto LABEL_13;
}
if ( v11 )
{
if ( v11 != 1 )
goto LABEL_13;
v12 = 0LL;
if ( v31 <= 0 )
goto LABEL_13;
v29 = a1;
v13 = v9;
v14 = a4;
v15 = a2;
v16 = v10;
v17 = v13;
do
{
v18 = (const char *)v32[v12++];
xml_printf("%*s<%s>%s</%s>\n", a3 + 2, (const char *)&unk_159B, *v16, v18, *v16);
}
while ( v31 > (int)v12 );
}
else
{
if ( v31 <= 0 )
goto LABEL_13;
v29 = a1;
v21 = 0LL;
v22 = v9;
v14 = a4;
v15 = a2;
v16 = v10;
v17 = v22;
do
{
v23 = *((unsigned int *)v32 + v21++);
xml_printf("%*s<%s>%d</%s>\n", a3 + 2, (const char *)&unk_159B, *v16, v23, *v16);
}
while ( v31 > (int)v21 );
}
v19 = v17;
a1 = v29;
v10 = v16;
a2 = v15;
a4 = v14;
v9 = v19;
LABEL_13:
attr_release(&v30);
goto LABEL_14;
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1, unsigned int a2, int a3, __int64 a4, int a5, const char **a6)
{
unsigned int v9; // er13
const char **v10; // r15
int v11; // eax
__int64 v12; // r14
unsigned int v13; // eax
__int64 v14; // r13
unsigned int v15; // er12
const char **v16; // rbp
unsigned int v17; // er15
const char *v18; // r8
unsigned int v19; // eax
__int64 v20; // rax
__int64 v21; // r14
unsigned int v22; // eax
__int64 v23; // r8
__int64 i; // r14
const char *v25; // r8
const char *v26; // rcx
__int64 v27; // [rsp+0h] [rbp-458h]
unsigned int v29; // [rsp+Ch] [rbp-44Ch]
int v30; // [rsp+10h] [rbp-448h] BYREF
int v31; // [rsp+14h] [rbp-444h]
__int64 v32[136]; // [rsp+18h] [rbp-440h]

if ( a5 > 0 )
{
v9 = a3 + 1;
v10 = a6;
v27 = (__int64)&a6[7 * (unsigned int)(a5 - 1) + 7];
while ( !(unsigned int)get_attribute_fsid(a1, a4, a2, *v10, &v30) )
{
if ( *((_DWORD *)v10 + 3) )
{
fprintf(stderr, "Can't get %s:%s\n", a4, *v10);
goto LABEL_18;
}
LABEL_14:
v10 += 7;
if ( v10 == (const char **)v27 )
return;
}
v11 = *((_DWORD *)v10 + 2);
if ( v30 != v11 )
{
fprintf(stderr, "Bad %s:%s\n", a4, *v10);
LABEL_18:
exit(1);
}
if ( v11 == 2 )
{
for ( i = 0LL; v31 > (int)i; ++i )
{
v25 = v10[4];
v26 = v10[3];
if ( *((_DWORD *)v10 + 4) )
{
func0("%*s<SubObject type=\"%s\" id=\"%s\">\n", v9, (const char *)&unk_159B, v26, v25);
func1(a1, HIDWORD(v32[i]), v9, v10[3], *((unsigned int *)v10 + 10), v10[6]);
func0("%*s</SubObject>\n", v9, (const char *)&unk_159B);
}
else
{
func0("%*s<Object type=\"%s\" id=\"%s\">\n", v9, (const char *)&unk_159B, v26, v25);
func1(LODWORD(v32[i]), HIDWORD(v32[i]), v9, v10[3], *((unsigned int *)v10 + 10), v10[6]);
func0("%*s</Object>\n", v9, (const char *)&unk_159B);
}
}
goto LABEL_13;
}
if ( v11 > 2 )
{
if ( v11 == 3 )
{
func0("%*s<%s>%d</%s>\n", a3 + 2, (const char *)&unk_159B, *v10, LODWORD(v32[0]), *v10);
v20 = parts_len++;
parts[v20] = v32[0];
}
goto LABEL_13;
}
if ( v11 )
{
if ( v11 != 1 )
goto LABEL_13;
v12 = 0LL;
if ( v31 <= 0 )
goto LABEL_13;
v29 = a1;
v13 = v9;
v14 = a4;
v15 = a2;
v16 = v10;
v17 = v13;
do
{
v18 = (const char *)v32[v12++];
func0("%*s<%s>%s</%s>\n", a3 + 2, (const char *)&unk_159B, *v16, v18, *v16);
}
while ( v31 > (int)v12 );
}
else
{
if ( v31 <= 0 )
goto LABEL_13;
v29 = a1;
v21 = 0LL;
v22 = v9;
v14 = a4;
v15 = a2;
v16 = v10;
v17 = v22;
do
{
v23 = *((unsigned int *)v32 + v21++);
func0("%*s<%s>%d</%s>\n", a3 + 2, (const char *)&unk_159B, *v16, v23, *v16);
}
while ( v31 > (int)v21 );
}
v19 = v17;
a1 = v29;
v10 = v16;
a2 = v15;
a4 = v14;
v9 = v19;
LABEL_13:
attr_release(&v30);
goto LABEL_14;
}
}

original_code:
static void
generate_object_xml(int fsid, int subobjid,
      int depth, const char *name,
      int ad_len, const struct TivoObjectAttrDesc *attr_descs)
{
 int i,j=0;
 mfs_attribute_t attr;
 for (i = 0; i < ad_len; ++i) {
  if (get_attribute_fsid(fsid, name, subobjid, attr_descs[i].name,
      &attr)) {
   if (attr.type != attr_descs[i].type) {
    fprintf(stderr, "Bad %s:%s\n", name,
     attr_descs[i].name);
    exit(1);
   }
   switch (attr_descs[i].type) {
   case 0:
    for (j = 0; j < attr.n; ++j) {
     xml_printf("%*s<%s>%d</%s>\n", depth+2, "",
         attr_descs[i].name,
         attr.u.integer[j], attr_descs[i].name);
    }
    break;
   case 3:
    xml_printf("%*s<%s>%d</%s>\n", depth+2, "",
        attr_descs[i].name,
        attr.u.integer[0], attr_descs[i].name);
    parts[parts_len++] = attr.u.integer[0];
    break;
   case 2:
    for (j = 0; j < attr.n; ++j) {
     if (attr_descs[i].is_subobject) {
      xml_printf("%*s<SubObject type=\"%s\" id=\"%s\">\n",
          depth+1, "", attr_descs[i].object_name,
          attr_descs[i].object_xml_id);
      generate_object_xml(fsid, attr.u.object[j].subobj,
            depth+1,
            attr_descs[i].object_name,
            attr_descs[i].object_len,
            attr_descs[i].object_attrs);
      xml_printf("%*s</SubObject>\n", depth+1, "");
     } else {
      xml_printf("%*s<Object type=\"%s\" id=\"%s\">\n",
          depth+1, "", attr_descs[i].object_name,
          attr_descs[i].object_xml_id);
      generate_object_xml(attr.u.object[j].fsid,
            attr.u.object[j].subobj,
            depth+1,
            attr_descs[i].object_name,
            attr_descs[i].object_len,
            attr_descs[i].object_attrs);
      xml_printf("%*s</Object>\n", depth+1, "");
     }
    }
    break;
   case 1:
    for (j = 0; j<attr.n;++j) {
     xml_printf("%*s<%s>%s</%s>\n", depth+2, "",
         attr_descs[i].name,
         attr.u.string[j], attr_descs[i].name);
    }
    break;
   }
   attr_release(&attr);
  } else if (attr_descs[i].mandatory) {
   fprintf(stderr, "Can't get %s:%s\n", name, attr_descs[i].name);
   exit(1);
  }
 }
}

canonical_original_code:
static void generate_object_xml(int fsid, int subobjid, int depth, char *name, int ad_len, struct TivoObjectAttrDesc *attr_descs)
{
 int i; int j = 0;
 struct attribute_struct attr;
 for (i = 0; i < ad_len; ++i) {
  if (get_attribute_fsid(fsid, name, subobjid, attr_descs[i].name,
      &attr)) {
   if (attr.type != attr_descs[i].type) {
    fprintf(stderr, "Bad %s:%s\n", name,
     attr_descs[i].name);
    exit(1);
   }
   switch (attr_descs[i].type) {
   case 0:
    for (j = 0; j < attr.n; ++j) {
     xml_printf("%*s<%s>%d</%s>\n", depth+2, "",
         attr_descs[i].name,
         attr.u.integer[j], attr_descs[i].name);
    }
    break;
   case 3:
    xml_printf("%*s<%s>%d</%s>\n", depth+2, "",
        attr_descs[i].name,
        attr.u.integer[0], attr_descs[i].name);
    parts[parts_len++] = attr.u.integer[0];
    break;
   case 2:
    for (j = 0; j < attr.n; ++j) {
     if (attr_descs[i].is_subobject) {
      xml_printf("%*s<SubObject type=\"%s\" id=\"%s\">\n",
          depth+1, "", attr_descs[i].object_name,
          attr_descs[i].object_xml_id);
      generate_object_xml(fsid, attr.u.object[j].subobj,
            depth+1,
            attr_descs[i].object_name,
            attr_descs[i].object_len,
            attr_descs[i].object_attrs);
      xml_printf("%*s</SubObject>\n", depth+1, "");
     } else {
      xml_printf("%*s<Object type=\"%s\" id=\"%s\">\n",
          depth+1, "", attr_descs[i].object_name,
          attr_descs[i].object_xml_id);
      generate_object_xml(attr.u.object[j].fsid,
            attr.u.object[j].subobj,
            depth+1,
            attr_descs[i].object_name,
            attr_descs[i].object_len,
            attr_descs[i].object_attrs);
      xml_printf("%*s</Object>\n", depth+1, "");
     }
    }
    break;
   case 1:
    for (j = 0; j<attr.n;++j) {
     xml_printf("%*s<%s>%s</%s>\n", depth+2, "",
         attr_descs[i].name,
         attr.u.string[j], attr_descs[i].name);
    }
    break;
   }
   attr_release(&attr);
  } else if (attr_descs[i].mandatory) {
   fprintf(stderr, "Can't get %s:%s\n", name, attr_descs[i].name);
   exit(1);
  }
 }
}

variable_types: subobjid int

variable_types: depth int

variable_types:
name
char *

variable_types: struct TivoObjectAttrDesc { char *name; int type; int mandatory; int is_subobject; char *object_name; char *object_xml_id; int object_len; struct TivoObjectAttrDesc *object_attrs; } *

variable_types: j int


decompiled_code:
void *__fastcall generate_xml(const char *a1)
{
unsigned int v1; // ebp
__int64 v2; // rax
char *v3; // r13
void *result; // rax
unsigned int v5; // eax

v1 = mfs_resolve();
v2 = get_tivo_version();
if ( v1 && (v3 = (char *)v2, (unsigned int)mfs_fsid_type(v1) == 8) )
{
xml_printf("<?xml version=\"1.1\" tivoversion=\"%s\"?>\n", v3);
xml_printf("<Object type=\"Recording\" id=\"_top\">\n");
generate_object_xml(v1, 0xFFFFFFFF, 0, (__int64)"Recording", 15, (const char **)&Recording);
xml_printf("</Object>\n");
if ( v3 )
free(v3);
parts[parts_len] = -1;
result = xml_buf;
}
else
{
v5 = mfs_fsid_type(v1);
fprintf(stderr, "Bad recording id: %s type: %d\n", a1, v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(const char *a1)
{
unsigned int v1; // ebp
__int64 v2; // rax
char *v3; // r13
void *result; // rax
unsigned int v5; // eax

v1 = mfs_resolve();
v2 = get_tivo_version();
if ( v1 && (v3 = (char *)v2, (unsigned int)mfs_fsid_type(v1) == 8) )
{
func0("<?xml version=\"1.1\" tivoversion=\"%s\"?>\n", v3);
func0("<Object type=\"Recording\" id=\"_top\">\n");
func1(v1, 0xFFFFFFFF, 0, (__int64)"Recording", 15, (const char **)&Recording);
func0("</Object>\n");
if ( v3 )
free(v3);
parts[parts_len] = -1;
result = xml_buf;
}
else
{
v5 = mfs_fsid_type(v1);
fprintf(stderr, "Bad recording id: %s type: %d\n", a1, v5);
result = 0LL;
}
return result;
}

original_code:
char *generate_xml(char *path)
{
 int fsid = mfs_resolve(path);
 char *tivo_version = get_tivo_version();
 if (!fsid ||
     mfs_fsid_type(fsid) != 8) {
  fprintf(stderr, "Bad recording id: %s  type: %d\n", path,
   mfs_fsid_type(fsid) );
  return 0;
 }
 xml_printf("<?xml version=\"1.1\" tivoversion=\"%s\"?>\n",
     tivo_version);
 xml_printf("<Object type=\"Recording\" id=\"_top\">\n");
 generate_object_xml(fsid, 0xffffffff, 0, "Recording",
       RecordingLen, Recording);
 xml_printf("</Object>\n");
 if (tivo_version != 0)
  free(tivo_version);
 parts[parts_len] = -1;
 return xml_buf;
}

variable_types:
path
char *


decompiled_code:
int *get_parts()
{
return parts;
}

canonical_decompiled_code:
int *func3()
{
return parts;
}

original_code:
int *get_parts()
{
 return parts;
}

canonical_original_code:
int *get_parts()
{
 return parts;
}

return_type: int *


decompiled_code:
__int64 __fastcall crc32(char *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax
char v4; // dl

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = crc32tab[2 * (unsigned __int8)(result ^ v4)] ^ ((unsigned int)result >> 8);
}
while ( (char *)v2 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax
char v4; // dl

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = crc32tab[2 * (unsigned __int8)(result ^ v4)] ^ ((unsigned int)result >> 8);
}
while ( (char *)v2 != a1 );
return result;
}

original_code:
u32 crc32(const unsigned char *bytes,int length)
{
 int i;
 unsigned ret;
 for (ret=0,i=0;i<length;i++) {
  ret=(crc32tab[((ret) ^ (bytes[i])) & 0xff] ^ ((ret) >> 8));
 }
 return(ret);
}

canonical_original_code:
unsigned int crc32(unsigned char *bytes, int length)
{
 int i;
 unsigned int ret;
 for (ret=0,i=0;i<length;i++) {
  ret=(crc32tab[((ret) ^ (bytes[i])) & 0xff] ^ ((ret) >> 8));
 }
 return(ret);
}

variable_types:
bytes
unsigned char *

variable_types: length int

variable_types:
ret
unsigned int


decompiled_code:
_BOOL8 __fastcall check_crc(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int v4; // ebx
int v5; // eax
_DWORD *v6; // rdx
char *v7; // r8
unsigned int v8; // er12

v4 = _bswap_32(*a3);
v5 = _bswap_32(0xDEADF00D);
*v6 = v5;
v8 = crc32(v7, a2);
if ( v4 != v8 )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
goto LABEL_7;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
else
{
LABEL_8:
fprintf(stderr, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
}
LABEL_7:
*a3 = _bswap_32(v4);
return v4 == v8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int v4; // ebx
int v5; // eax
_DWORD *v6; // rdx
char *v7; // r8
unsigned int v8; // er12

v4 = func0(*a3);
v5 = func0(0xDEADF00D);
*v6 = v5;
v8 = func1(v7, a2);
if ( v4 != v8 )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
goto LABEL_7;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
else
{
LABEL_8:
fprintf(stderr, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
}
LABEL_7:
*a3 = func0(v4);
return v4 == v8;
}

original_code:
int check_crc(void *buf, int length, u32 *crc)
{
 u32 crc_saved = ntohl(*crc);
 u32 new;
 *crc = htonl(0xdeadf00d);
 new = crc32(buf, length);
 if (new != crc_saved) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : 1) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new)) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new));
 }
 *crc = htonl(crc_saved);
 return new == crc_saved ? 1 : 0;
}

canonical_original_code:
int check_crc(void *buf, int length, unsigned int *crc)
{
 unsigned int crc_saved = ntohl(*crc);
 unsigned int new;
 *crc = htonl(0xdeadf00d);
 new = crc32(buf, length);
 if (new != crc_saved) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : 1) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new)) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new));
 }
 *crc = htonl(crc_saved);
 return new == crc_saved ? 1 : 0;
}

variable_types:
buf
void *

variable_types:
crc
unsigned int *

variable_types:
new
unsigned int


decompiled_code:
_BOOL8 __fastcall replace_crc(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int v4; // er12
int v5; // eax
_DWORD *v6; // rdx
char *v7; // r8
unsigned int v8; // ebx

v4 = _bswap_32(*a3);
v5 = _bswap_32(0xDEADF00D);
*v6 = v5;
v8 = crc32(v7, a2);
if ( v4 != v8 )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
goto LABEL_7;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
else
{
LABEL_8:
fprintf(stderr, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
}
LABEL_7:
*a3 = _bswap_32(v8);
return v4 == v8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, unsigned int a2, unsigned int *a3)
{
unsigned int v4; // er12
int v5; // eax
_DWORD *v6; // rdx
char *v7; // r8
unsigned int v8; // ebx

v4 = func0(*a3);
v5 = func0(0xDEADF00D);
*v6 = v5;
v8 = func1(v7, a2);
if ( v4 != v8 )
{
if ( !use_syslog )
goto LABEL_8;
if ( fileno(stderr) == 2 )
{
syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
goto LABEL_7;
}
if ( fileno(stderr) == 1 )
{
if ( use_syslog > 1 )
syslog(6, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
else
{
LABEL_8:
fprintf(stderr, "crc mismatch len=%d 0x%08x 0x%08x\n", a2, v4, v8);
}
}
LABEL_7:
*a3 = func0(v8);
return v4 == v8;
}

original_code:
int replace_crc(void *buf, int length, u32 *crc)
{
 u32 crc_saved = ntohl(*crc);
 u32 new;
 *crc = htonl(0xdeadf00d);
 new = crc32(buf, length);
 if (new != crc_saved) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : 1) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new)) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new));
 }
 *crc = htonl(new);
 return new == crc_saved ? 1 : 0;
}

canonical_original_code:
int replace_crc(void *buf, int length, unsigned int *crc)
{
 unsigned int crc_saved = ntohl(*crc);
 unsigned int new;
 *crc = htonl(0xdeadf00d);
 new = crc32(buf, length);
 if (new != crc_saved) {
  (use_syslog ? (fileno(stderr)==2 ? (syslog(3, "crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : fileno(stderr)==1 ? (use_syslog>=2 ? (syslog(6,"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new),1) : 1) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new)) : fprintf((stderr),"crc mismatch len=%d 0x%08x 0x%08x\n", length, crc_saved, new));
 }
 *crc = htonl(new);
 return new == crc_saved ? 1 : 0;
}