decompiled_code:
signed __int64 __fastcall val2elapstr(int a1, char *a2)
{
int v2; // ebx
char *v3; // rax
char *v5; // rbp
char *v6; // r14
char *v7; // r14

v2 = a1;
if ( a1 > 86400 )
{
v5 = &a2[sprintf(a2, "%dd", (unsigned int)(a1 / 86400))];
v2 = a1 % 86400;
LABEL_8:
v6 = &v5[sprintf(v5, "%dh", (unsigned int)(v2 / 3600))];
v2 %= 3600;
LABEL_9:
v7 = &v6[sprintf(v6, "%dm", (unsigned int)(v2 / 60))];
v2 %= 60;
LABEL_10:
v3 = &v7[sprintf(v7, "%ds", (unsigned int)v2)];
return v3 - a2;
}
if ( a1 > 3600 )
{
v5 = a2;
goto LABEL_8;
}
if ( a1 > 60 )
{
v6 = a2;
goto LABEL_9;
}
if ( a1 )
{
v7 = a2;
goto LABEL_10;
}
v3 = a2;
return v3 - a2;
}

canonical_decompiled_code:
signed __int64 __fastcall func5(int a1, char *a2)
{
int v2; // ebx
char *v3; // rax
char *v5; // rbp
char *v6; // r14
char *v7; // r14

v2 = a1;
if ( a1 > 86400 )
{
v5 = &a2[sprintf(a2, "%dd", (unsigned int)(a1 / 86400))];
v2 = a1 % 86400;
LABEL_8:
v6 = &v5[sprintf(v5, "%dh", (unsigned int)(v2 / 3600))];
v2 %= 3600;
LABEL_9:
v7 = &v6[sprintf(v6, "%dm", (unsigned int)(v2 / 60))];
v2 %= 60;
LABEL_10:
v3 = &v7[sprintf(v7, "%ds", (unsigned int)v2)];
return v3 - a2;
}
if ( a1 > 3600 )
{
v5 = a2;
goto LABEL_8;
}
if ( a1 > 60 )
{
v6 = a2;
goto LABEL_9;
}
if ( a1 )
{
v7 = a2;
goto LABEL_10;
}
v3 = a2;
return v3 - a2;
}

original_code:
int
val2elapstr(int value, char *strvalue)
{
        char *p=strvalue, doshow=0;
        if (value > (24*60*60))
        {
                p+=sprintf(p, "%dd", value/(24*60*60));
                value %= (24*60*60);
  doshow = 1;
        }
        if (value > (60*60) || doshow)
        {
                p+=sprintf(p, "%dh", value/(60*60));
                value %= (60*60);
  doshow = 1;
        }
        if (value > (60) || doshow)
        {
                p+=sprintf(p, "%dm", value/(60));
                value %= (60);
  doshow = 1;
        }
        if (value || doshow)
        {
                p+=sprintf(p, "%ds", value);
  doshow = 1;
        }
        return p-strvalue;
}

canonical_original_code:
int val2elapstr(int value, char *strvalue)
{
        char *p = strvalue; char doshow = 0;
        if (value > (24*60*60))
        {
                p+=sprintf(p, "%dd", value/(24*60*60));
                value %= (24*60*60);
  doshow = 1;
        }
        if (value > (60*60) || doshow)
        {
                p+=sprintf(p, "%dh", value/(60*60));
                value %= (60*60);
  doshow = 1;
        }
        if (value > (60) || doshow)
        {
                p+=sprintf(p, "%dm", value/(60));
                value %= (60);
  doshow = 1;
        }
        if (value || doshow)
        {
                p+=sprintf(p, "%ds", value);
  doshow = 1;
        }
        return p-strvalue;
}

variable_types: value int

variable_types:
p
char *

variable_types: doshow char


repo: samm-git/atop-freebsd

original_code:
char *
val2cpustr(count_t value, char *strvalue)
{
 if (value < (count_t)100000)
 {
  sprintf(strvalue, "%2lld.%02llds", value/1000, value%1000/10);
 }
 else
 {
         value = (value + 500) / 1000;
         if (value < (count_t)6000)
         {
                  sprintf(strvalue, "%2lldm%02llds", value/60, value%60);
  }
  else
  {
   value = (value + 30) / 60;
   if (value < (count_t)6000)
   {
    sprintf(strvalue, "%2lldh%02lldm",
       value/60, value%60);
   }
   else
   {
    value = (value + 30) / 60;
    sprintf(strvalue, "%2lldd%02lldh",
      value/24, value%24);
   }
  }
 }
 return strvalue;
}

canonical_original_code:
char *val2cpustr(long long value, char *strvalue)
{
 if (value < (long long)100000)
 {
  sprintf(strvalue, "%2lld.%02llds", value/1000, value%1000/10);
 }
 else
 {
         value = (value + 500) / 1000;
         if (value < (long long)6000)
         {
                  sprintf(strvalue, "%2lldm%02llds", value/60, value%60);
  }
  else
  {
   value = (value + 30) / 60;
   if (value < (long long)6000)
   {
    sprintf(strvalue, "%2lldh%02lldm",
       value/60, value%60);
   }
   else
   {
    value = (value + 30) / 60;
    sprintf(strvalue, "%2lldd%02lldh",
      value/24, value%24);
   }
  }
 }
 return strvalue;
}

variable_types:
value
long long

variable_types:
strvalue
char *

return_type: char *


original_code:
char *
val2Hzstr(count_t value, char *strvalue)
{
        if (value < 1000)
        {
                sprintf(strvalue, "%4lldMHz", value);
        }
        else
        {
                double fval=value/1000.0;
                char prefix='G';
                if (fval >= 1000.0)
                {
                        prefix='T';
                        fval /= 1000.0;
                }
                sprintf(strvalue, "%4.2f%cHz", fval, prefix);
        }
 return strvalue;
}

canonical_original_code:
char *val2Hzstr(long long value, char *strvalue)
{
        if (value < 1000)
        {
                sprintf(strvalue, "%4lldMHz", value);
        }
        else
        {
                double fval = value/1000.0;
                char prefix = 'G';
                if (fval >= 1000.0)
                {
                        prefix='T';
                        fval /= 1000.0;
                }
                sprintf(strvalue, "%4.2f%cHz", fval, prefix);
        }
 return strvalue;
}

variable_types: fval double

variable_types: prefix char


original_code:
char *
val2memstr(count_t value, char *strvalue, int pformat, int avgval, int nsecs)
{
 char aformat;
 count_t verifyval;
 char *suffix = "";
 int basewidth = 6;
 if (value < 0)
  verifyval = -value * 10;
 else
  verifyval = value;
 if (avgval)
 {
  value /= nsecs;
  verifyval *= 100;
  basewidth -= 2;
  suffix = "/s";
 }
 if (verifyval <= 1024)
  aformat = 0;
 else
  if (verifyval <= 1024*99999L)
   aformat = 1;
  else
   if (verifyval <= 1048576*999L)
    aformat = 2;
   else
    if (verifyval <= 1073741824L*999LL)
     aformat = 3;
    else
     aformat = 4;
 if (aformat <= pformat)
  aformat = pformat;
 switch (aformat)
 {
    case 0:
  sprintf(strvalue, "%*lld%s",
    basewidth, value, suffix);
  break;
    case 1:
  sprintf(strvalue, "%*lldK%s",
    basewidth-1, value/1024, suffix);
  break;
    case 2:
  sprintf(strvalue, "%*.1lfM%s",
   basewidth-1, (double)((double)value/1048576), suffix);
  break;
    case 3:
  sprintf(strvalue, "%*.1lfG%s",
   basewidth-1, (double)((double)value/1073741824L), suffix);
  break;
    case 4:
  sprintf(strvalue, "%*.1lfT%s",
   basewidth-1, (double)((double)value/1099511627776LL), suffix);
  break;
    default:
  sprintf(strvalue, "!TILT!");
 }
 return strvalue;
}

canonical_original_code:
char *val2memstr(long long value, char *strvalue, int pformat, int avgval, int nsecs)
{
 char aformat;
 long long verifyval;
 char *suffix = "";
 int basewidth = 6;
 if (value < 0)
  verifyval = -value * 10;
 else
  verifyval = value;
 if (avgval)
 {
  value /= nsecs;
  verifyval *= 100;
  basewidth -= 2;
  suffix = "/s";
 }
 if (verifyval <= 1024)
  aformat = 0;
 else
  if (verifyval <= 1024*99999L)
   aformat = 1;
  else
   if (verifyval <= 1048576*999L)
    aformat = 2;
   else
    if (verifyval <= 1073741824L*999LL)
     aformat = 3;
    else
     aformat = 4;
 if (aformat <= pformat)
  aformat = pformat;
 switch (aformat)
 {
    case 0:
  sprintf(strvalue, "%*lld%s",
    basewidth, value, suffix);
  break;
    case 1:
  sprintf(strvalue, "%*lldK%s",
    basewidth-1, value/1024, suffix);
  break;
    case 2:
  sprintf(strvalue, "%*.1lfM%s",
   basewidth-1, (double)((double)value/1048576), suffix);
  break;
    case 3:
  sprintf(strvalue, "%*.1lfG%s",
   basewidth-1, (double)((double)value/1073741824L), suffix);
  break;
    case 4:
  sprintf(strvalue, "%*.1lfT%s",
   basewidth-1, (double)((double)value/1099511627776LL), suffix);
  break;
    default:
  sprintf(strvalue, "!TILT!");
 }
 return strvalue;
}

variable_types: pformat int

variable_types: avgval int

variable_types: nsecs int

variable_types: aformat char

variable_types:
verifyval
long long

variable_types:
suffix
char *

variable_types: basewidth int


numeric

decompiled_code:
__int64 __fastcall numeric(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

original_code:
int
numeric(char *ns)
{
 register char *s = ns;
 while (*s)
  if (*s < '0' || *s > '9')
   return(0);
  else
   s++;
 return(1);
}

variable_types:
ns
char *

variable_types:
s
char *

return_type: int


getboot

decompiled_code:
__int64 getboot()
{
if ( !boottime_0 )
boottime_0 = getbootlinux(hertz);
return boottime_0;
}

canonical_decompiled_code:
__int64 func10()
{
if ( !boottime_0 )
boottime_0 = getbootlinux(hertz);
return boottime_0;
}

original_code:
unsigned long long
getboot(void)
{
 static unsigned long long boottime;
 unsigned long long getbootlinux(long);
 if (!boottime)
  boottime = getbootlinux(hertz);
 return boottime;
}

canonical_original_code:
unsigned long long getboot()
{
 static unsigned long long boottime;
 unsigned long long getbootlinux(long);
 if (!boottime)
  boottime = getbootlinux(hertz);
 return boottime;
}

variable_types:
boottime
unsigned long long

variable_types:
getbootlinux
unsigned long long (long)

return_type: unsigned long long


ptrverify

decompiled_code:
char *__fastcall ptrverify(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
char *result; // rax
void (*v8)(FILE *, const char *, ...); // rax
_QWORD v9[7]; // [rsp+0h] [rbp-38h] BYREF

result = &a7;
v9[4] = &a7;
if ( !a1 )
{
acctswoff();
netatop_signoff();
v8 = (void (*)(FILE *, const char *, ...))vis[2];
if ( v8 )
v8(0LL, a2);
fprintf(stderr, a2, v9);
exit(13);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
char *result; // rax
void (*v8)(FILE *, const char *, ...); // rax
_QWORD v9[7]; // [rsp+0h] [rbp-38h] BYREF

result = &a7;
v9[4] = &a7;
if ( !a1 )
{
acctswoff();
netatop_signoff();
v8 = (void (*)(FILE *, const char *, ...))vis[2];
if ( v8 )
v8(0LL, a2);
fprintf(stderr, a2, v9);
exit(13);
}
return result;
}

original_code:
void
ptrverify(const void *ptr, const char *errormsg, ...)
{
 va_list args;
        __builtin_va_start(args,errormsg);
 if (!ptr)
 {
  acctswoff();
  netatop_signoff();
  if (vis.show_end)
   (vis.show_end)();
         va_list args;
  fprintf(stderr, errormsg, args);
         __builtin_va_end(args);
  exit(13);
 }
}

canonical_original_code:
void ptrverify(void *ptr, char *errormsg, ...)
{
 __builtin_va_list args;
        __builtin_va_start(args,errormsg);
 if (!ptr)
 {
  acctswoff();
  netatop_signoff();
  if (vis.show_end)
   (vis.show_end)();
         __builtin_va_list args;
  fprintf(stderr, errormsg, args);
         __builtin_va_end(args);
  exit(13);
 }
}

variable_types:
ptr
void *

variable_types:
errormsg
char *

return_type: void


droprootprivs

decompiled_code:
_BOOL8 droprootprivs()
{
__uid_t v0; // eax
int v1; // edx
_BOOL8 result; // rax

v0 = getuid();
v1 = seteuid(v0);
result = 1LL;
if ( v1 == -1 )
result = *_errno_location() == 1;
return result;
}

canonical_decompiled_code:
_BOOL8 func13()
{
__uid_t v0; // eax
int v1; // edx
_BOOL8 result; // rax

v0 = getuid();
v1 = seteuid(v0);
result = 1LL;
if ( v1 == -1 )
result = *_errno_location() == 1;
return result;
}

original_code:
int
droprootprivs(void)
{
 if (seteuid( getuid() ) == -1 && (*__errno_location ()) != 1)
  return 0;
 else
  return 1;
}

canonical_original_code:
int droprootprivs()
{
 if (seteuid( getuid() ) == -1 && (*__errno_location ()) != 1)
  return 0;
 else
  return 1;
}


regainrootprivs

decompiled_code:
int regainrootprivs()
{
return seteuid(0);
}

canonical_decompiled_code:
int func14()
{
return seteuid(0);
}

original_code:
void
regainrootprivs(void)
{
 seteuid(0);
}

canonical_original_code:
void regainrootprivs()
{
 seteuid(0);
}


decompiled_code:
__int64 __fastcall pdb_gettask(int a1, char a2, int a3, __int64 *a4)
{
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rcx

result = phash[(unsigned __int8)a1];
if ( !result )
return 0LL;
while ( 1 )
{
if ( *(_DWORD *)(result + 28) != a1 || *(_BYTE *)(result + 88) != a2 )
{
result = *(_QWORD *)result;
goto LABEL_5;
}
if ( (unsigned int)(*(_DWORD *)(result + 96) + 1 - a3) <= 2 )
break;
result = *(_QWORD *)result;
LABEL_5:
if ( !result )
return result;
}
v6 = *(_QWORD *)(result + 8);
if ( v6 )
{
v7 = *(_QWORD *)(result + 16);
*(_QWORD *)(v6 + 16) = v7;
*(_QWORD *)(v7 + 8) = *(_QWORD *)(result + 8);
}
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*a4 = result;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char a2, int a3, __int64 *a4)
{
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rcx

result = phash[(unsigned __int8)a1];
if ( !result )
return 0LL;
while ( 1 )
{
if ( *(_DWORD *)(result + 28) != a1 || *(_BYTE *)(result + 88) != a2 )
{
result = *(_QWORD *)result;
goto LABEL_5;
}
if ( (unsigned int)(*(_DWORD *)(result + 96) + 1 - a3) <= 2 )
break;
result = *(_QWORD *)result;
LABEL_5:
if ( !result )
return result;
}
v6 = *(_QWORD *)(result + 8);
if ( v6 )
{
v7 = *(_QWORD *)(result + 16);
*(_QWORD *)(v6 + 16) = v7;
*(_QWORD *)(v7 + 8) = *(_QWORD *)(result + 8);
}
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*a4 = result;
return 1LL;
}

original_code:
int
pdb_gettask(int pid, char isproc, time_t btime, struct pinfo **pinfopp)
{
 register struct pinfo *pp;
 pp = phash[pid&(256 -1)];
 while (pp)
 {
  if (pp->tstat.gen.pid == pid &&
      pp->tstat.gen.isproc == isproc )
  {
   int diff = pp->tstat.gen.btime - btime;
   if (diff > 1 || diff < -1)
   {
    pp = pp->phnext;
    continue;
   }
   if (pp->prnext)
   {
    (pp->prnext)->prprev = pp->prprev;
    (pp->prprev)->prnext = pp->prnext;
   }
   pp->prnext = ((void *)0);
   pp->prprev = ((void *)0);
   *pinfopp = pp;
   return(1);
  }
  pp = pp->phnext;
 }
 return(0);
}

canonical_original_code:
int pdb_gettask(int pid, char isproc, long btime, struct pinfo **pinfopp)
{
 register struct pinfo *pp;
 pp = phash[pid&(256 -1)];
 while (pp)
 {
  if (pp->tstat.gen.pid == pid &&
      pp->tstat.gen.isproc == isproc )
  {
   int diff = pp->tstat.gen.btime - btime;
   if (diff > 1 || diff < -1)
   {
    pp = pp->phnext;
    continue;
   }
   if (pp->prnext)
   {
    (pp->prnext)->prprev = pp->prprev;
    (pp->prprev)->prnext = pp->prnext;
   }
   pp->prnext = ((void *)0);
   pp->prprev = ((void *)0);
   *pinfopp = pp;
   return(1);
  }
  pp = pp->phnext;
 }
 return(0);
}

variable_types: pid int

variable_types: isproc char

variable_types: btime long

variable_types: struct pinfo { struct pinfo *phnext; struct pinfo *prnext; struct pinfo *prprev; struct tstat { struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; } gen; struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; } cpu; struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; } dsk; struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; } mem; struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; } net; } tstat; } **

variable_types: diff int

user_defined_types: struct pinfo { struct pinfo *phnext; struct pinfo *prnext; struct pinfo *prprev; struct tstat tstat; }

user_defined_types: struct tstat { struct gen gen; struct cpu cpu; struct dsk dsk; struct mem mem; struct net net; }


decompiled_code:
__int64 __fastcall pdb_addtask(unsigned __int8 a1, __int64 *a2)
{
__int64 result; // rax

result = phash[a1];
*a2 = result;
phash[a1] = (__int64)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, __int64 *a2)
{
__int64 result; // rax

result = phash[a1];
*a2 = result;
phash[a1] = (__int64)a2;
return result;
}

original_code:
void
pdb_addtask(int pid, struct pinfo *pinfop)
{
 register int i = pid&(256 -1);
 pinfop->phnext = phash[i];
 phash[i] = pinfop;
}

variable_types: struct pinfo { struct pinfo *phnext; struct pinfo *prnext; struct pinfo *prprev; struct tstat { struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; } gen; struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; } cpu; struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; } dsk; struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; } mem; struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; } net; } tstat; } *

variable_types: i int


original_code:
int
pdb_deltask(int pid, char isproc)
{
 register struct pinfo *pp, *ppp;
 pp = phash[pid&(256 -1)];
 if (pp->tstat.gen.pid == pid && pp->tstat.gen.isproc == isproc)
 {
  phash[pid&(256 -1)] = pp->phnext;
  if ( pp->prnext )
  {
   (pp->prprev)->prnext = pp->prnext;
   (pp->prnext)->prprev = pp->prprev;
  }
  free(pp);
  return(1);
 }
 ppp = pp;
 pp = pp->phnext;
 while (pp)
 {
  if (pp->tstat.gen.pid == pid && pp->tstat.gen.isproc == isproc)
  {
   ppp->phnext = pp->phnext;
   if ( pp->prnext )
   {
    (pp->prnext)->prprev = pp->prprev;
    (pp->prprev)->prnext = pp->prnext;
   }
   free(pp);
   return(1);
  }
  ppp = pp;
  pp = pp->phnext;
 }
 return(0);
}

canonical_original_code:
int pdb_deltask(int pid, char isproc)
{
 register struct pinfo *pp; register struct pinfo *ppp;
 pp = phash[pid&(256 -1)];
 if (pp->tstat.gen.pid == pid && pp->tstat.gen.isproc == isproc)
 {
  phash[pid&(256 -1)] = pp->phnext;
  if ( pp->prnext )
  {
   (pp->prprev)->prnext = pp->prnext;
   (pp->prnext)->prprev = pp->prprev;
  }
  free(pp);
  return(1);
 }
 ppp = pp;
 pp = pp->phnext;
 while (pp)
 {
  if (pp->tstat.gen.pid == pid && pp->tstat.gen.isproc == isproc)
  {
   ppp->phnext = pp->phnext;
   if ( pp->prnext )
   {
    (pp->prnext)->prprev = pp->prprev;
    (pp->prprev)->prnext = pp->prnext;
   }
   free(pp);
   return(1);
  }
  ppp = pp;
  pp = pp->phnext;
 }
 return(0);
}

user_defined_types: struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; }

user_defined_types: struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; }

user_defined_types: struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; }

user_defined_types: struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; }

user_defined_types: struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; }


original_code:
int
pdb_makeresidue(void)
{
 register struct pinfo *pp, *pr;
 register int i;
 pr = &presidue;
 pr->prnext = pr;
 pr->prprev = pr;
 for (i=0; i < 256; i++)
 {
  if (!phash[i])
   continue;
  pp = phash[i];
  while (pp)
  {
   pp->prnext = pr->prnext;
   pr->prnext = pp;
    pp->prprev = (pp->prnext)->prprev;
   (pp->prnext)->prprev = pp;
   pp = pp->phnext;
  }
 }
 return(1);
}

canonical_original_code:
int pdb_makeresidue()
{
 register struct pinfo *pp; register struct pinfo *pr;
 register int i;
 pr = &presidue;
 pr->prnext = pr;
 pr->prprev = pr;
 for (i=0; i < 256; i++)
 {
  if (!phash[i])
   continue;
  pp = phash[i];
  while (pp)
  {
   pp->prnext = pr->prnext;
   pr->prnext = pp;
    pp->prprev = (pp->prnext)->prprev;
   (pp->prnext)->prprev = pp;
   pp = pp->phnext;
  }
 }
 return(1);
}


decompiled_code:
__int64 pdb_cleanresidue()
{
__int64 v0; // rbx
int v1; // edi
char v2; // si

v0 = qword_2A8;
while ( (_UNKNOWN *)v0 != &presidue )
{
v1 = *(_DWORD *)(v0 + 28);
v2 = *(_BYTE *)(v0 + 88);
v0 = *(_QWORD *)(v0 + 8);
pdb_deltask(v1, v2);
}
return 1LL;
}

original_code:
int
pdb_cleanresidue(void)
{
 register struct pinfo *pr;
 register int pid;
        char isproc;
 pr = presidue.prnext;
 while (pr != &presidue)
 {
  pid = pr->tstat.gen.pid;
  isproc = pr->tstat.gen.isproc;
  pr = pr->prnext;
  pdb_deltask(pid, isproc);
 }
 return(1);
}

canonical_original_code:
int pdb_cleanresidue()
{
 register struct pinfo *pr;
 register int pid;
        char isproc;
 pr = presidue.prnext;
 while (pr != &presidue)
 {
  pid = pr->tstat.gen.pid;
  isproc = pr->tstat.gen.isproc;
  pr = pr->prnext;
  pdb_deltask(pid, isproc);
 }
 return(1);
}


decompiled_code:
__int64 __fastcall pdb_srchresidue(__int64 a1, __int64 *a2)
{
__int64 v2; // rbx
int v3; // ebp
__int64 v4; // r13
__int64 result; // rax
__int64 v6; // rax

v2 = qword_2A8;
if ( (_UNKNOWN *)qword_2A8 == &presidue )
return 0LL;
v3 = *(_DWORD *)(a1 + 12);
v4 = 0LL;
do
{
if ( *(_DWORD *)(v2 + 36) == v3
&& *(_DWORD *)(v2 + 52) == *(_DWORD *)(a1 + 28)
&& !strcmp((const char *)(v2 + 72), (const char *)(a1 + 48)) )
{
v6 = *(_QWORD *)(v2 + 96) - *(_QWORD *)(a1 + 72);
if ( !v6 )
{
*a2 = v2;
return 1LL;
}
if ( !(v4 | (v6 + 1) & 0xFFFFFFFFFFFFFFFDLL) )
v4 = v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
while ( (_UNKNOWN *)v2 != &presidue );
result = 0LL;
if ( v4 )
{
*a2 = v4;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 *a2)
{
__int64 v2; // rbx
int v3; // ebp
__int64 v4; // r13
__int64 result; // rax
__int64 v6; // rax

v2 = qword_2A8;
if ( (_UNKNOWN *)qword_2A8 == &presidue )
return 0LL;
v3 = *(_DWORD *)(a1 + 12);
v4 = 0LL;
do
{
if ( *(_DWORD *)(v2 + 36) == v3
&& *(_DWORD *)(v2 + 52) == *(_DWORD *)(a1 + 28)
&& !strcmp((const char *)(v2 + 72), (const char *)(a1 + 48)) )
{
v6 = *(_QWORD *)(v2 + 96) - *(_QWORD *)(a1 + 72);
if ( !v6 )
{
*a2 = v2;
return 1LL;
}
if ( !(v4 | (v6 + 1) & 0xFFFFFFFFFFFFFFFDLL) )
v4 = v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
while ( (_UNKNOWN *)v2 != &presidue );
result = 0LL;
if ( v4 )
{
*a2 = v4;
result = 1LL;
}
return result;
}

original_code:
int
pdb_srchresidue(struct tstat *tstatp, struct pinfo **pinfopp)
{
 register struct pinfo *pr, *prmin=((void *)0);
 register long btimediff;
 pr = presidue.prnext;
 while (pr != &presidue)
 {
  if ( pr->tstat.gen.ruid == tstatp->gen.ruid &&
   pr->tstat.gen.rgid == tstatp->gen.rgid &&
   strcmp(pr->tstat.gen.name, tstatp->gen.name) == 0 )
  {
   btimediff = pr->tstat.gen.btime - tstatp->gen.btime;
   if (btimediff == 0)
   {
    *pinfopp = pr;
    return(1);
   }
   if ((btimediff== -1 || btimediff== 1) && prmin== ((void *)0))
    prmin = pr;
  }
  pr = pr->prnext;
 }
 if (prmin)
 {
  *pinfopp = prmin;
  return(1);
 }
 return(0);
}

canonical_original_code:
int pdb_srchresidue(struct tstat *tstatp, struct pinfo **pinfopp)
{
 register struct pinfo *pr; register struct pinfo *prmin = ((void *)0);
 register long btimediff;
 pr = presidue.prnext;
 while (pr != &presidue)
 {
  if ( pr->tstat.gen.ruid == tstatp->gen.ruid &&
   pr->tstat.gen.rgid == tstatp->gen.rgid &&
   strcmp(pr->tstat.gen.name, tstatp->gen.name) == 0 )
  {
   btimediff = pr->tstat.gen.btime - tstatp->gen.btime;
   if (btimediff == 0)
   {
    *pinfopp = pr;
    return(1);
   }
   if ((btimediff== -1 || btimediff== 1) && prmin== ((void *)0))
    prmin = pr;
  }
  pr = pr->prnext;
 }
 if (prmin)
 {
  *pinfopp = prmin;
  return(1);
 }
 return(0);
}

variable_types: struct tstat { struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; } gen; struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; } cpu; struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; } dsk; struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; } mem; struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; } net; } *

variable_types: struct pinfo { struct pinfo *phnext; struct pinfo *prnext; struct pinfo *prprev; struct tstat tstat; } **

variable_types: btimediff long


getstrvers

decompiled_code:
char *getstrvers()
{
snprintf(vers_0, 0x100uLL, "Version: %s - %s <gerlof.langeveld@atoptool.nl>", atopversion, atopdate);
return vers_0;
}

canonical_decompiled_code:
char *func0()
{
snprintf(vers_0, 0x100uLL, "Version: %s - %s <gerlof.langeveld@atoptool.nl>", atopversion, atopdate);
return vers_0;
}

original_code:
char *
getstrvers(void)
{
 static char vers[256];
 snprintf(vers, sizeof vers,
  "Version: %s - %s     <gerlof.langeveld@atoptool.nl>",
  atopversion, atopdate);
 return vers;
}

canonical_original_code:
char *getstrvers()
{
 static char vers[256];
 snprintf(vers, sizeof vers,
  "Version: %s - %s     <gerlof.langeveld@atoptool.nl>",
  atopversion, atopdate);
 return vers;
}

variable_types:
vers
char [256]


getnumvers

decompiled_code:
__int16 getnumvers()
{
__int16 v1; // [rsp+8h] [rbp-10h] BYREF
__int16 v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(atopversion, "%u.%u", &v2, &v1);
return v1 + (v2 << 8);
}

canonical_decompiled_code:
__int16 func1()
{
__int16 v1; // [rsp+8h] [rbp-10h] BYREF
__int16 v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(atopversion, "%u.%u", &v2, &v1);
return v1 + (v2 << 8);
}

original_code:
unsigned short
getnumvers(void)
{
 int vers1, vers2;
 sscanf(atopversion, "%u.%u", &vers1, &vers2);
 return (unsigned short) ((vers1 << 8) + vers2);
}

canonical_original_code:
unsigned short getnumvers()
{
 int vers1; int vers2;
 sscanf(atopversion, "%u.%u", &vers1, &vers2);
 return (unsigned short) ((vers1 << 8) + vers2);
}

return_type: unsigned short


getifprop

decompiled_code:
__int64 __fastcall getifprop(char *s1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // r13

if ( ifprops[0] )
{
v1 = 0LL;
while ( 1 )
{
v2 = 32 * v1;
if ( !strcmp(s1, &ifprops[32 * v1]) )
break;
++v1;
if ( !byte_280[v2] )
goto LABEL_5;
}
v4 = 2LL * (int)v1;
*(__m128i *)s1 = _mm_load_si128((const __m128i *)&ifprops[v4 * 16]);
*((__m128i *)s1 + 1) = _mm_load_si128((const __m128i *)&xmmword_270[v4]);
result = 1LL;
}
else
{
LABEL_5:
*((_QWORD *)s1 + 2) = 0LL;
s1[24] = 0;
result = 0LL;
}
return result;
}

original_code:
int
getifprop(struct ifprop *ifp)
{
 register int i;
 for (i=0; ifprops[i].name[0]; i++)
 {
  if (strcmp(ifp->name, ifprops[i].name) == 0)
  {
   *ifp = ifprops[i];
   return 1;
  }
 }
 ifp->speed = 0;
 ifp->fullduplex = 0;
 return 0;
}

variable_types: struct ifprop { char name[16]; long speed; char fullduplex; } *


test

repo: samphippen/lsquare

decompiled_code:
__int64 test()
{
void **v0; // rbp
int v1; // ebx
unsigned int v2; // er12
__int64 v3; // rbx
_QWORD *v4; // rbx
__int64 result; // rax

v0 = (void **)malloc(0x20uLL);
init_latin_square("abcd", v0);
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 9u, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0xAu, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0xBu, "test");
if ( !(unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 1", "test.c", 0xCu, "test");
*(_BYTE *)v0[1] = 97;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0xFu, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0x10u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x11u, "test");
if ( !(unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 1", "test.c", 0x12u, "test");
*((_BYTE *)v0[1] + 1) = 97;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x15u, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0x16u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x17u, "test");
if ( (unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 0", "test.c", 0x18u, "test");
*((_BYTE *)v0[1] + 1) = 98;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x1Bu, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0x1Cu, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x1Du, "test");
if ( !(unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 1", "test.c", 0x1Eu, "test");
v1 = *(_DWORD *)v0;
if ( *(_DWORD *)v0 )
{
v2 = 0;
do
{
v3 = (__int64)v0[1] + v2 * v1;
*(_DWORD *)v3 = *(_DWORD *)v0[3];
if ( !(unsigned __int8)row_is_filled(v2, v0) )
_assert_fail("row_is_filled(i, my_square) == 1", "test.c", 0x24u, "test");
if ( !(unsigned __int8)row_is_valid(v2, v0) )
_assert_fail("row_is_valid(i, my_square) == 1", "test.c", 0x25u, "test");
*(_BYTE *)(v3 + 3) = 46;
if ( (unsigned __int8)row_is_filled(v2, v0) )
_assert_fail("row_is_filled(i, my_square) == 0", "test.c", 0x28u, "test");
if ( !(unsigned __int8)row_is_valid(v2, v0) )
_assert_fail("row_is_valid(i, my_square) == 1", "test.c", 0x29u, "test");
*(_BYTE *)(v3 + 3) = 100;
*(_BYTE *)v3 = 46;
if ( (unsigned __int8)row_is_filled(v2, v0) )
_assert_fail("row_is_filled(i, my_square) == 0", "test.c", 0x2Du, "test");
if ( !(unsigned __int8)row_is_valid(v2, v0) )
_assert_fail("row_is_valid(i, my_square) == 1", "test.c", 0x2Eu, "test");
++v2;
v1 = *(_DWORD *)v0;
}
while ( *(_DWORD *)v0 > v2 );
}
free(v0[1]);
init_latin_square(v0[3], v0);
*(_BYTE *)v0[1] = 97;
*((_BYTE *)v0[1] + 4) = 98;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x37u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x38u, "test");
*((_BYTE *)v0[1] + 8) = 99;
*((_BYTE *)v0[1] + 12) = 100;
if ( !(unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 1", "test.c", 0x3Cu, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x3Du, "test");
*(_BYTE *)v0[1] = 46;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x40u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x41u, "test");
*(_BYTE *)v0[1] = 97;
*((_BYTE *)v0[1] + 4) = 97;
*((_BYTE *)v0[1] + 8) = 97;
*((_BYTE *)v0[1] + 12) = 97;
if ( !(unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 1", "test.c", 0x47u, "test");
if ( (unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 0", "test.c", 0x48u, "test");
v4 = malloc(0x20uLL);
init_latin_square("ab", v4);
v4[1] = "abba";
if ( !(unsigned __int8)square_complete(v4) )
_assert_fail("square_complete(my_square_2)", "test.c", 0x4Du, "test");
init_latin_square("abcd", v4);
solve_latin_square(v4, 0LL);
result = square_complete(v4);
if ( !(_BYTE)result )
_assert_fail("square_complete(my_square_2)", "test.c", 0x51u, "test");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
void **v0; // rbp
int v1; // ebx
unsigned int v2; // er12
__int64 v3; // rbx
_QWORD *v4; // rbx
__int64 result; // rax

v0 = (void **)malloc(0x20uLL);
init_latin_square("abcd", v0);
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 9u, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0xAu, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0xBu, "test");
if ( !(unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 1", "test.c", 0xCu, "test");
*(_BYTE *)v0[1] = 97;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0xFu, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0x10u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x11u, "test");
if ( !(unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 1", "test.c", 0x12u, "test");
*((_BYTE *)v0[1] + 1) = 97;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x15u, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0x16u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x17u, "test");
if ( (unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 0", "test.c", 0x18u, "test");
*((_BYTE *)v0[1] + 1) = 98;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x1Bu, "test");
if ( (unsigned __int8)row_is_filled(0LL, v0) )
_assert_fail("row_is_filled(0, my_square) == 0", "test.c", 0x1Cu, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x1Du, "test");
if ( !(unsigned __int8)row_is_valid(0LL, v0) )
_assert_fail("row_is_valid(0, my_square) == 1", "test.c", 0x1Eu, "test");
v1 = *(_DWORD *)v0;
if ( *(_DWORD *)v0 )
{
v2 = 0;
do
{
v3 = (__int64)v0[1] + v2 * v1;
*(_DWORD *)v3 = *(_DWORD *)v0[3];
if ( !(unsigned __int8)row_is_filled(v2, v0) )
_assert_fail("row_is_filled(i, my_square) == 1", "test.c", 0x24u, "test");
if ( !(unsigned __int8)row_is_valid(v2, v0) )
_assert_fail("row_is_valid(i, my_square) == 1", "test.c", 0x25u, "test");
*(_BYTE *)(v3 + 3) = 46;
if ( (unsigned __int8)row_is_filled(v2, v0) )
_assert_fail("row_is_filled(i, my_square) == 0", "test.c", 0x28u, "test");
if ( !(unsigned __int8)row_is_valid(v2, v0) )
_assert_fail("row_is_valid(i, my_square) == 1", "test.c", 0x29u, "test");
*(_BYTE *)(v3 + 3) = 100;
*(_BYTE *)v3 = 46;
if ( (unsigned __int8)row_is_filled(v2, v0) )
_assert_fail("row_is_filled(i, my_square) == 0", "test.c", 0x2Du, "test");
if ( !(unsigned __int8)row_is_valid(v2, v0) )
_assert_fail("row_is_valid(i, my_square) == 1", "test.c", 0x2Eu, "test");
++v2;
v1 = *(_DWORD *)v0;
}
while ( *(_DWORD *)v0 > v2 );
}
free(v0[1]);
init_latin_square(v0[3], v0);
*(_BYTE *)v0[1] = 97;
*((_BYTE *)v0[1] + 4) = 98;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x37u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x38u, "test");
*((_BYTE *)v0[1] + 8) = 99;
*((_BYTE *)v0[1] + 12) = 100;
if ( !(unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 1", "test.c", 0x3Cu, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x3Du, "test");
*(_BYTE *)v0[1] = 46;
if ( (unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 0", "test.c", 0x40u, "test");
if ( !(unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 1", "test.c", 0x41u, "test");
*(_BYTE *)v0[1] = 97;
*((_BYTE *)v0[1] + 4) = 97;
*((_BYTE *)v0[1] + 8) = 97;
*((_BYTE *)v0[1] + 12) = 97;
if ( !(unsigned __int8)col_is_filled(0LL, v0) )
_assert_fail("col_is_filled(0, my_square) == 1", "test.c", 0x47u, "test");
if ( (unsigned __int8)col_is_valid(0LL, v0) )
_assert_fail("col_is_valid(0, my_square) == 0", "test.c", 0x48u, "test");
v4 = malloc(0x20uLL);
init_latin_square("ab", v4);
v4[1] = "abba";
if ( !(unsigned __int8)square_complete(v4) )
_assert_fail("square_complete(my_square_2)", "test.c", 0x4Du, "test");
init_latin_square("abcd", v4);
solve_latin_square(v4, 0LL);
result = square_complete(v4);
if ( !(_BYTE)result )
_assert_fail("square_complete(my_square_2)", "test.c", 0x51u, "test");
return result;
}

original_code:
void test() {
    latin_square* my_square = malloc(sizeof(latin_square));
    init_latin_square("abcd", my_square);
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 9, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 11, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 1) ; else __assert_fail ("row_is_valid(0, my_square) == 1", "test.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[0] = 'a';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 16, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 1) ; else __assert_fail ("row_is_valid(0, my_square) == 1", "test.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[1] = 'a';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 21, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 0) ; else __assert_fail ("row_is_valid(0, my_square) == 0", "test.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[1] = 'b';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 27, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 1) ; else __assert_fail ("row_is_valid(0, my_square) == 1", "test.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    int i;
    for (i = 0; i < my_square->width; i++) {
        char* row_ptr = my_square->grid + i * my_square->width;
        memcpy(row_ptr, my_square->alphabet, 4);
        ((void) sizeof ((row_is_filled(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_filled(i, my_square) == 1) ; else __assert_fail ("row_is_filled(i, my_square) == 1", "test.c", 36, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((row_is_valid(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(i, my_square) == 1) ; else __assert_fail ("row_is_valid(i, my_square) == 1", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
        row_ptr[3] = '.';
        ((void) sizeof ((row_is_filled(i, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(i, my_square) == 0) ; else __assert_fail ("row_is_filled(i, my_square) == 0", "test.c", 40, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((row_is_valid(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(i, my_square) == 1) ; else __assert_fail ("row_is_valid(i, my_square) == 1", "test.c", 41, __extension__ __PRETTY_FUNCTION__); }));
        row_ptr[3] = 'd';
        row_ptr[0] = '.';
        ((void) sizeof ((row_is_filled(i, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(i, my_square) == 0) ; else __assert_fail ("row_is_filled(i, my_square) == 0", "test.c", 45, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((row_is_valid(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(i, my_square) == 1) ; else __assert_fail ("row_is_valid(i, my_square) == 1", "test.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    }
    free(my_square->grid);
    init_latin_square(my_square->alphabet, my_square);
    my_square->grid[0] = 'a';
    my_square->grid[4] = 'b';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 55, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[8] = 'c';
    my_square->grid[12] = 'd';
    ((void) sizeof ((col_is_filled(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 1) ; else __assert_fail ("col_is_filled(0, my_square) == 1", "test.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[0] = '.';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[0] = 'a';
    my_square->grid[4] = 'a';
    my_square->grid[8] = 'a';
    my_square->grid[12] = 'a';
    ((void) sizeof ((col_is_filled(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 1) ; else __assert_fail ("col_is_filled(0, my_square) == 1", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 0) ; else __assert_fail ("col_is_valid(0, my_square) == 0", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    latin_square* my_square_2 = malloc(sizeof(latin_square));
    init_latin_square("ab", my_square_2);
    my_square_2->grid = "abba";
    ((void) sizeof ((square_complete(my_square_2)) ? 1 : 0), __extension__ ({ if (square_complete(my_square_2)) ; else __assert_fail ("square_complete(my_square_2)", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    init_latin_square("abcd", my_square_2);
    solve_latin_square(my_square_2, 0);
    ((void) sizeof ((square_complete(my_square_2)) ? 1 : 0), __extension__ ({ if (square_complete(my_square_2)) ; else __assert_fail ("square_complete(my_square_2)", "test.c", 81, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void test() {
    struct _latin_square *my_square = malloc(sizeof(latin_square));
    init_latin_square("abcd", my_square);
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 9, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 11, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 1) ; else __assert_fail ("row_is_valid(0, my_square) == 1", "test.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[0] = 'a';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 16, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 1) ; else __assert_fail ("row_is_valid(0, my_square) == 1", "test.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[1] = 'a';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 21, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 0) ; else __assert_fail ("row_is_valid(0, my_square) == 0", "test.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[1] = 'b';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 27, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(0, my_square) == 0) ; else __assert_fail ("row_is_filled(0, my_square) == 0", "test.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(0, my_square) == 1) ; else __assert_fail ("row_is_valid(0, my_square) == 1", "test.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    int i;
    for (i = 0; i < my_square->width; i++) {
        char *row_ptr = my_square->grid + i * my_square->width;
        memcpy(row_ptr, my_square->alphabet, 4);
        ((void) sizeof ((row_is_filled(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_filled(i, my_square) == 1) ; else __assert_fail ("row_is_filled(i, my_square) == 1", "test.c", 36, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((row_is_valid(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(i, my_square) == 1) ; else __assert_fail ("row_is_valid(i, my_square) == 1", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
        row_ptr[3] = '.';
        ((void) sizeof ((row_is_filled(i, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(i, my_square) == 0) ; else __assert_fail ("row_is_filled(i, my_square) == 0", "test.c", 40, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((row_is_valid(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(i, my_square) == 1) ; else __assert_fail ("row_is_valid(i, my_square) == 1", "test.c", 41, __extension__ __PRETTY_FUNCTION__); }));
        row_ptr[3] = 'd';
        row_ptr[0] = '.';
        ((void) sizeof ((row_is_filled(i, my_square) == 0) ? 1 : 0), __extension__ ({ if (row_is_filled(i, my_square) == 0) ; else __assert_fail ("row_is_filled(i, my_square) == 0", "test.c", 45, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((row_is_valid(i, my_square) == 1) ? 1 : 0), __extension__ ({ if (row_is_valid(i, my_square) == 1) ; else __assert_fail ("row_is_valid(i, my_square) == 1", "test.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    }
    free(my_square->grid);
    init_latin_square(my_square->alphabet, my_square);
    my_square->grid[0] = 'a';
    my_square->grid[4] = 'b';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 55, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[8] = 'c';
    my_square->grid[12] = 'd';
    ((void) sizeof ((col_is_filled(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 1) ; else __assert_fail ("col_is_filled(0, my_square) == 1", "test.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[0] = '.';
    ((void) sizeof ((col_is_filled(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 0) ; else __assert_fail ("col_is_filled(0, my_square) == 0", "test.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 1) ; else __assert_fail ("col_is_valid(0, my_square) == 1", "test.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    my_square->grid[0] = 'a';
    my_square->grid[4] = 'a';
    my_square->grid[8] = 'a';
    my_square->grid[12] = 'a';
    ((void) sizeof ((col_is_filled(0, my_square) == 1) ? 1 : 0), __extension__ ({ if (col_is_filled(0, my_square) == 1) ; else __assert_fail ("col_is_filled(0, my_square) == 1", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((col_is_valid(0, my_square) == 0) ? 1 : 0), __extension__ ({ if (col_is_valid(0, my_square) == 0) ; else __assert_fail ("col_is_valid(0, my_square) == 0", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    struct _latin_square *my_square_2 = malloc(sizeof(latin_square));
    init_latin_square("ab", my_square_2);
    my_square_2->grid = "abba";
    ((void) sizeof ((square_complete(my_square_2)) ? 1 : 0), __extension__ ({ if (square_complete(my_square_2)) ; else __assert_fail ("square_complete(my_square_2)", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    init_latin_square("abcd", my_square_2);
    solve_latin_square(my_square_2, 0);
    ((void) sizeof ((square_complete(my_square_2)) ? 1 : 0), __extension__ ({ if (square_complete(my_square_2)) ; else __assert_fail ("square_complete(my_square_2)", "test.c", 81, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct _latin_square { unsigned int width; char *grid; char *orig_grid; char *alphabet; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
return 0;
}

original_code:
int main() {
    test();
    return 0;
}

canonical_original_code:
int main() {
    test();
    return 0;
}


decompiled_code:
__int64 __fastcall randomize_char(__int64 a1, int a2, int a3)
{
__int64 v5; // r13
char v6; // si
__int64 result; // rax

v5 = *(_QWORD *)(a1 + 24);
v6 = *(_BYTE *)(v5 + (unsigned int)rand() % *(_DWORD *)a1);
result = (unsigned int)(a3 * *(_DWORD *)a1 + a2);
*(_BYTE *)(*(_QWORD *)(a1 + 8) + result) = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
__int64 v5; // r13
char v6; // si
__int64 result; // rax

v5 = *(_QWORD *)(a1 + 24);
v6 = *(_BYTE *)(v5 + (unsigned int)rand() % *(_DWORD *)a1);
result = (unsigned int)(a3 * *(_DWORD *)a1 + a2);
*(_BYTE *)(*(_QWORD *)(a1 + 8) + result) = v6;
return result;
}

original_code:
static void randomize_char(latin_square* square, unsigned x, unsigned y) {
    square->grid[y * square->width + x] = square->alphabet[rand() % square->width];
}

canonical_original_code:
static void randomize_char(struct _latin_square *square, unsigned int x, unsigned int y) {
    square->grid[y * square->width + x] = square->alphabet[rand() % square->width];
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

user_defined_types: struct _latin_square { unsigned int width; char *grid; char *orig_grid; char *alphabet; }


strip

decompiled_code:
size_t __fastcall strip(char *s)
{
unsigned int i; // ebp
size_t result; // rax
char v3; // al

for ( i = 0; ; ++i )
{
result = strlen(s);
if ( i >= result )
break;
v3 = s[i];
if ( v3 == 10 || v3 == 32 )
strcpy(&s[i], &s[i + 1]);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(char *s)
{
unsigned int i; // ebp
size_t result; // rax
char v3; // al

for ( i = 0; ; ++i )
{
result = strlen(s);
if ( i >= result )
break;
v3 = s[i];
if ( v3 == 10 || v3 == 32 )
strcpy(&s[i], &s[i + 1]);
}
return result;
}

original_code:
void strip(char* string) {
    unsigned i = 0;
    for (i = 0; i < strlen(string); i++) {
        if (string[i] == '\n' || string[i] == ' ') {
            strcpy(string + i, string + i + 1);
        }
    }
}

canonical_original_code:
void strip(char *string) {
    unsigned int i = 0;
    for (i = 0; i < strlen(string); i++) {
        if (string[i] == '\n' || string[i] == ' ') {
            strcpy(string + i, string + i + 1);
        }
    }
}

variable_types:
string
char *

variable_types:
i
unsigned int


decompiled_code:
void *__fastcall init_latin_square(const char *a1, __int64 a2)
{
unsigned int v2; // eax
size_t v3; // rbx
void *v4; // r14
void *v5; // r13
void *result; // rax

v2 = strlen(a1);
*(_DWORD *)a2 = v2;
v3 = v2 * (unsigned __int64)v2;
v4 = malloc(v3);
*(_QWORD *)(a2 + 8) = v4;
v5 = malloc(v3);
*(_QWORD *)(a2 + 16) = v5;
memset(v4, 46, (unsigned int)v3);
result = memset(v5, 46, (unsigned int)v3);
*(_QWORD *)(a2 + 24) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func11(const char *a1, __int64 a2)
{
unsigned int v2; // eax
size_t v3; // rbx
void *v4; // r14
void *v5; // r13
void *result; // rax

v2 = strlen(a1);
*(_DWORD *)a2 = v2;
v3 = v2 * (unsigned __int64)v2;
v4 = malloc(v3);
*(_QWORD *)(a2 + 8) = v4;
v5 = malloc(v3);
*(_QWORD *)(a2 + 16) = v5;
memset(v4, 46, (unsigned int)v3);
result = memset(v5, 46, (unsigned int)v3);
*(_QWORD *)(a2 + 24) = a1;
return result;
}

original_code:
void init_latin_square(char* alphabet, latin_square* square) {
    square->width = strlen(alphabet);
    square->grid = malloc(sizeof(char) * square->width * square->width);
    square->orig_grid = malloc(sizeof(char) * square->width * square->width);
    memset(square->grid, placeholder_char, square->width * square->width);
    memset(square->orig_grid, placeholder_char, square->width * square->width);
    square->alphabet = alphabet;
}

canonical_original_code:
void init_latin_square(char *alphabet, struct _latin_square *square) {
    square->width = strlen(alphabet);
    square->grid = malloc(sizeof(char) * square->width * square->width);
    square->orig_grid = malloc(sizeof(char) * square->width * square->width);
    memset(square->grid, placeholder_char, square->width * square->width);
    memset(square->orig_grid, placeholder_char, square->width * square->width);
    square->alphabet = alphabet;
}

variable_types:
alphabet
char *


decompiled_code:
void *__fastcall take_string_descriptor(void *src, __int64 a2)
{
memcpy(*(void **)(a2 + 8), src, (unsigned int)(*(_DWORD *)a2 * *(_DWORD *)a2));
return memcpy(*(void **)(a2 + 16), src, (unsigned int)(*(_DWORD *)a2 * *(_DWORD *)a2));
}

canonical_decompiled_code:
void *__fastcall func12(void *src, __int64 a2)
{
memcpy(*(void **)(a2 + 8), src, (unsigned int)(*(_DWORD *)a2 * *(_DWORD *)a2));
return memcpy(*(void **)(a2 + 16), src, (unsigned int)(*(_DWORD *)a2 * *(_DWORD *)a2));
}

original_code:
void take_string_descriptor(char* string, latin_square* square) {
    int i;
    memcpy(square->grid, string, square->width * square->width);
    memcpy(square->orig_grid, string, square->width * square->width);
}

canonical_original_code:
void take_string_descriptor(char *string, struct _latin_square *square) {
    int i;
    memcpy(square->grid, string, square->width * square->width);
    memcpy(square->orig_grid, string, square->width * square->width);
}


decompiled_code:
__int64 __fastcall row_is_filled(int a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdi
_BYTE *v4; // rax
__int64 v5; // rdx

v2 = *(_QWORD *)(a2 + 8);
v3 = (unsigned int)(*(_DWORD *)a2 * a1);
if ( !*(_DWORD *)a2 )
return 1LL;
v4 = (_BYTE *)(v2 + v3);
v5 = (unsigned int)(*(_DWORD *)a2 - 1) + v2 + v3 + 1;
while ( *v4 != 46 )
{
if ( ++v4 == (_BYTE *)v5 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdi
_BYTE *v4; // rax
__int64 v5; // rdx

v2 = *(_QWORD *)(a2 + 8);
v3 = (unsigned int)(*(_DWORD *)a2 * a1);
if ( !*(_DWORD *)a2 )
return 1LL;
v4 = (_BYTE *)(v2 + v3);
v5 = (unsigned int)(*(_DWORD *)a2 - 1) + v2 + v3 + 1;
while ( *v4 != 46 )
{
if ( ++v4 == (_BYTE *)v5 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool row_is_filled(unsigned row, latin_square* square) {
    char* row_ptr = square->grid + row * square->width;
    int i;
    for (i = 0; i < square->width; i++) {
        if (row_ptr[i] == placeholder_char) return 0;
    }
    return 1;
}

canonical_original_code:
_Bool row_is_filled(unsigned int row, struct _latin_square *square) {
    char *row_ptr = square->grid + row * square->width;
    int i;
    for (i = 0; i < square->width; i++) {
        if (row_ptr[i] == placeholder_char) return 0;
    }
    return 1;
}

variable_types:
row
unsigned int


decompiled_code:
__int64 __fastcall col_is_filled(unsigned int a1, int *a2)
{
int v3; // esi
unsigned int v4; // edx
int v5; // ecx

v3 = *a2;
if ( !v3 )
return 1LL;
v4 = 0;
v5 = 0;
while ( *(_BYTE *)(*((_QWORD *)a2 + 1) + v4 + a1) != 46 )
{
++v5;
v4 += v3;
if ( v3 == v5 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, int *a2)
{
int v3; // esi
unsigned int v4; // edx
int v5; // ecx

v3 = *a2;
if ( !v3 )
return 1LL;
v4 = 0;
v5 = 0;
while ( *(_BYTE *)(*((_QWORD *)a2 + 1) + v4 + a1) != 46 )
{
++v5;
v4 += v3;
if ( v3 == v5 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool col_is_filled(unsigned col, latin_square* square) {
    int i;
    for (i = 0; i < square->width; i++) {
        char* row_ptr = square->grid + i * square->width;
        if (row_ptr[col] == placeholder_char) return 0;
    }
    return 1;
}

canonical_original_code:
_Bool col_is_filled(unsigned int col, struct _latin_square *square) {
    int i;
    for (i = 0; i < square->width; i++) {
        char *row_ptr = square->grid + i * square->width;
        if (row_ptr[col] == placeholder_char) return 0;
    }
    return 1;
}

variable_types:
col
unsigned int


original_code:
_Bool row_is_valid(unsigned row, latin_square* square) {
    char* row_ptr = square->grid + row * square->width;
    unsigned c_count1, c_count2;
    char c_char1, c_char2;
    for (c_count1 = 0; c_count1 < square->width; c_count1++) {
        c_char1 = row_ptr[c_count1];
        if (c_char1 != placeholder_char) {
            for (c_count2 = 0; c_count2 < square->width; c_count2++) {
                c_char2 = row_ptr[c_count2];
                if (c_char2 != placeholder_char && c_count1 != c_count2 && c_char1 == c_char2) {
                    return 0;
                }
            }
        }
    }
    return 1;
}

canonical_original_code:
_Bool row_is_valid(unsigned int row, struct _latin_square *square) {
    char *row_ptr = square->grid + row * square->width;
    unsigned int c_count1; unsigned int c_count2;
    char c_char1; char c_char2;
    for (c_count1 = 0; c_count1 < square->width; c_count1++) {
        c_char1 = row_ptr[c_count1];
        if (c_char1 != placeholder_char) {
            for (c_count2 = 0; c_count2 < square->width; c_count2++) {
                c_char2 = row_ptr[c_count2];
                if (c_char2 != placeholder_char && c_count1 != c_count2 && c_char1 == c_char2) {
                    return 0;
                }
            }
        }
    }
    return 1;
}


decompiled_code:
__int64 __fastcall col_is_valid(int a1, int *a2)
{
int v2; // er15
int v3; // ebp
int v4; // ebx
char v5; // al
char v7; // r13

v2 = *a2;
if ( !*a2 )
return 1LL;
v3 = 0;
while ( 1 )
{
v7 = get_char_at((__int64)a2, a1, v3);
if ( v7 != 46 )
break;
LABEL_7:
if ( ++v3 == v2 )
return 1LL;
}
v4 = 0;
while ( 1 )
{
v5 = get_char_at((__int64)a2, a1, v4);
if ( v3 != v4 && v5 != 46 && v7 == v5 )
return 0LL;
if ( ++v4 == v2 )
goto LABEL_7;
}
}

original_code:
_Bool col_is_valid(unsigned col, latin_square* square) {
    unsigned r_count1, r_count2;
    char r_char1, r_char2;
    for (r_count1 = 0; r_count1 < square->width; r_count1++) {
        r_char1 = get_char_at(square, col, r_count1);
        if (r_char1 != placeholder_char) {
            for (r_count2 = 0; r_count2 < square->width; r_count2++) {
                r_char2 = get_char_at(square, col, r_count2);
                if (r_char2 != placeholder_char && r_count1 != r_count2 && r_char1 == r_char2) return 0;
            }
        }
    }
    return 1;
}

canonical_original_code:
_Bool col_is_valid(unsigned int col, struct _latin_square *square) {
    unsigned int r_count1; unsigned int r_count2;
    char r_char1; char r_char2;
    for (r_count1 = 0; r_count1 < square->width; r_count1++) {
        r_char1 = get_char_at(square, col, r_count1);
        if (r_char1 != placeholder_char) {
            for (r_count2 = 0; r_count2 < square->width; r_count2++) {
                r_char2 = get_char_at(square, col, r_count2);
                if (r_char2 != placeholder_char && r_count1 != r_count2 && r_char1 == r_char2) return 0;
            }
        }
    }
    return 1;
}


decompiled_code:
int __fastcall print_latin_square(int *a1)
{
int v1; // er14
unsigned int v2; // er13
int v3; // er12
__int64 v4; // rdx
char *v5; // rbx
__int64 v6; // rbp
int result; // eax

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0;
do
{
v4 = *((_QWORD *)a1 + 1);
v5 = (char *)(v4 + v2);
v6 = v2 + v4 + (unsigned int)(v1 - 1) + 1;
do
{
putchar(*v5);
putchar(32);
++v5;
}
while ( v5 != (char *)v6 );
result = putchar(10);
++v3;
v2 += v1;
}
while ( v1 != v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(int *a1)
{
int v1; // er14
unsigned int v2; // er13
int v3; // er12
__int64 v4; // rdx
char *v5; // rbx
__int64 v6; // rbp
int result; // eax

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0;
do
{
v4 = *((_QWORD *)a1 + 1);
v5 = (char *)(v4 + v2);
v6 = v2 + v4 + (unsigned int)(v1 - 1) + 1;
do
{
putchar(*v5);
putchar(32);
++v5;
}
while ( v5 != (char *)v6 );
result = putchar(10);
++v3;
v2 += v1;
}
while ( v1 != v3 );
}
return result;
}

original_code:
void print_latin_square(latin_square* square) {
    unsigned i = 0;
    unsigned j = 0;
    unsigned width = square->width;
    for (j = 0; j < width; j++) {
        char* row = square->grid + (j * width);
        for (i = 0; i < width; i++) {
            putchar(row[i]);
            putchar(' ');
        }
        putchar('\n');
    }
}

canonical_original_code:
void print_latin_square(struct _latin_square *square) {
    unsigned int i = 0;
    unsigned int j = 0;
    unsigned int width = square->width;
    for (j = 0; j < width; j++) {
        char *row = square->grid + (j * width);
        for (i = 0; i < width; i++) {
            putchar(row[i]);
            putchar(' ');
        }
        putchar('\n');
    }
}

variable_types:
j
unsigned int

variable_types:
width
unsigned int

variable_types:
row
char *


decompiled_code:
__int64 __fastcall square_complete(int *a1)
{
int v1; // er13
unsigned int v2; // ebx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0;
do
{
result = col_is_filled(v2, a1);
if ( !(_BYTE)result )
break;
result = row_is_filled(v2, (__int64)a1);
if ( !(_BYTE)result )
break;
result = row_is_valid(v2, a1);
if ( !(_BYTE)result )
break;
result = col_is_valid(v2, a1);
if ( !(_BYTE)result )
break;
++v2;
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int *a1)
{
int v1; // er13
unsigned int v2; // ebx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0;
do
{
result = func14(v2, a1);
if ( !(_BYTE)result )
break;
result = func13(v2, (__int64)a1);
if ( !(_BYTE)result )
break;
result = func15(v2, a1);
if ( !(_BYTE)result )
break;
result = func16(v2, a1);
if ( !(_BYTE)result )
break;
++v2;
}
while ( v2 != v1 );
return result;
}

original_code:
_Bool square_complete(latin_square* square) {
    int i;
    for (i = 0; i < square->width; i++) {
        if (!(col_is_filled(i, square) &&
              row_is_filled(i, square) &&
              row_is_valid(i, square) &&
              col_is_valid(i, square))) return 0;
    }
    return 1;
}

canonical_original_code:
_Bool square_complete(struct _latin_square *square) {
    int i;
    for (i = 0; i < square->width; i++) {
        if (!(col_is_filled(i, square) &&
              row_is_filled(i, square) &&
              row_is_valid(i, square) &&
              col_is_valid(i, square))) return 0;
    }
    return 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall solve_latin_square(__int64 a1, char a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v4; // er15
int v5; // er14
__int64 v6; // rbx
__int64 v7; // r13
unsigned int v8; // ebx
__int64 result; // rax
int v10; // [rsp+8h] [rbp-40h]

v2 = clock();
srand(v2);
LABEL_2:
v3 = 0;
v4 = 0;
v10 = 0;
v5 = 0;
while ( 1 )
{
result = square_complete((int *)a1);
if ( (_BYTE)result )
return result;
if ( a2 )
{
putchar(13);
randomize_char(a1, v10, v5);
if ( *(_DWORD *)a1 )
{
v6 = 0LL;
v7 = (unsigned int)(v5 * *(_DWORD *)a1) + *(_QWORD *)(a1 + 8);
do
{
putchar(*(char *)(v7 + v6));
putchar(32);
++v6;
}
while ( *(_DWORD *)a1 > (unsigned int)v6 );
}
fflush(_bss_start);
}
else
{
randomize_char(a1, v10, v5);
}
++v3;
if ( (unsigned __int8)row_is_valid(v5, (int *)a1) && (unsigned __int8)col_is_valid(v10, (int *)a1) )
{
++v10;
v8 = 0;
if ( *(_DWORD *)a1 == v10 )
{
++v5;
if ( a2 )
{
putchar(10);
fflush(_bss_start);
}
v3 = 0;
v8 = 0;
v10 = 0;
goto LABEL_10;
}
}
else
{
v8 = v4 + 1;
if ( v4 > 0x7F )
{
reset_row(v5, (unsigned int *)a1);
v10 = 0;
}
}
if ( v3 > 0x1000000 )
{
puts("resetting grid!");
puts("------------------------------------------------");
memcpy(*(void **)(a1 + 8), *(const void **)(a1 + 16), (unsigned int)(*(_DWORD *)a1 * *(_DWORD *)a1));
goto LABEL_2;
}
LABEL_10:
v4 = v8;
}
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, char a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v4; // er15
int v5; // er14
__int64 v6; // rbx
__int64 v7; // r13
unsigned int v8; // ebx
__int64 result; // rax
int v10; // [rsp+8h] [rbp-40h]

v2 = clock();
srand(v2);
LABEL_2:
v3 = 0;
v4 = 0;
v10 = 0;
v5 = 0;
while ( 1 )
{
result = func18((int *)a1);
if ( (_BYTE)result )
return result;
if ( a2 )
{
putchar(13);
func9(a1, v10, v5);
if ( *(_DWORD *)a1 )
{
v6 = 0LL;
v7 = (unsigned int)(v5 * *(_DWORD *)a1) + *(_QWORD *)(a1 + 8);
do
{
putchar(*(char *)(v7 + v6));
putchar(32);
++v6;
}
while ( *(_DWORD *)a1 > (unsigned int)v6 );
}
fflush(_bss_start);
}
else
{
func9(a1, v10, v5);
}
++v3;
if ( (unsigned __int8)func15(v5, (int *)a1) && (unsigned __int8)func16(v10, (int *)a1) )
{
++v10;
v8 = 0;
if ( *(_DWORD *)a1 == v10 )
{
++v5;
if ( a2 )
{
putchar(10);
fflush(_bss_start);
}
v3 = 0;
v8 = 0;
v10 = 0;
goto LABEL_10;
}
}
else
{
v8 = v4 + 1;
if ( v4 > 0x7F )
{
func8(v5, (unsigned int *)a1);
v10 = 0;
}
}
if ( v3 > 0x1000000 )
{
puts("resetting grid!");
puts("------------------------------------------------");
memcpy(*(void **)(a1 + 8), *(const void **)(a1 + 16), (unsigned int)(*(_DWORD *)a1 * *(_DWORD *)a1));
goto LABEL_2;
}
LABEL_10:
v4 = v8;
}
}

original_code:
void solve_latin_square(latin_square* square, _Bool verbose) {
    unsigned working_row = 0;
    unsigned charpos = 0;
    unsigned tries = 0;
    unsigned row_tries = 0;
    unsigned seekback = 1;
    int i;
    srand(clock());
    while (!square_complete(square)) {
        if (verbose) {
            putchar('\r');
        }
        randomize_char(square, charpos, working_row);
        if (verbose) {
            char* row_ptr = square->grid + working_row * square->width;
            for (i = 0; i < square->width; i++) {
                putchar(row_ptr[i]);
                putchar(' ');
            }
            fflush(stdout);
        }
        row_tries++;
        if (row_is_valid(working_row, square) && col_is_valid(charpos, square)) {
           tries = 0;
           if (++charpos == square->width) {
               charpos = 0;
               working_row += 1;
               seekback = 1;
               row_tries = 0;
               if (verbose) {
                   putchar('\n');
                   fflush(stdout);
               }
           }
        } else if (tries++ >= 128) {
                reset_row(working_row, square);
                charpos = 0;
        }
        if (row_tries > (1 << 24)) {
            printf("resetting grid!\n");
            printf("------------------------------------------------\n");
            working_row = 0;
            charpos = 0;
            tries = 0;
            row_tries = 0;
            memcpy(square->grid, square->orig_grid, square->width * square->width);
        }
    }
}

canonical_original_code:
void solve_latin_square(struct _latin_square *square, _Bool verbose) {
    unsigned int working_row = 0;
    unsigned int charpos = 0;
    unsigned int tries = 0;
    unsigned int row_tries = 0;
    unsigned int seekback = 1;
    int i;
    srand(clock());
    while (!square_complete(square)) {
        if (verbose) {
            putchar('\r');
        }
        randomize_char(square, charpos, working_row);
        if (verbose) {
            char *row_ptr = square->grid + working_row * square->width;
            for (i = 0; i < square->width; i++) {
                putchar(row_ptr[i]);
                putchar(' ');
            }
            fflush(stdout);
        }
        row_tries++;
        if (row_is_valid(working_row, square) && col_is_valid(charpos, square)) {
           tries = 0;
           if (++charpos == square->width) {
               charpos = 0;
               working_row += 1;
               seekback = 1;
               row_tries = 0;
               if (verbose) {
                   putchar('\n');
                   fflush(stdout);
               }
           }
        } else if (tries++ >= 128) {
                reset_row(working_row, square);
                charpos = 0;
        }
        if (row_tries > (1 << 24)) {
            printf("resetting grid!\n");
            printf("------------------------------------------------\n");
            working_row = 0;
            charpos = 0;
            tries = 0;
            row_tries = 0;
            memcpy(square->grid, square->orig_grid, square->width * square->width);
        }
    }
}

variable_types:
charpos
unsigned int

variable_types:
tries
unsigned int

variable_types:
seekback
unsigned int


printtime

repo: sampost/libsort

decompiled_code:
int __fastcall printtime(_QWORD *a1, _QWORD *a2)
{
unsigned __int64 v2; // rcx

v2 = 1000000LL * *a2 + a2[1] - a1[1] - 1000000LL * *a1;
return printf("%llu s, %06llu us\n", v2 / 0xF4240, v2 % 0xF4240);
}

original_code:
void printtime(struct timeval * start, struct timeval * end)
{
    unsigned long long diff_us;
    diff_us =
        (((unsigned long long)end->tv_sec)*1000000 + end->tv_usec) -
        (((unsigned long long)start->tv_sec)*1000000 + start->tv_usec);
    printf("%llu s, %06llu us\n", diff_us/1000000, diff_us%1000000);
}

canonical_original_code:
void printtime(struct timeval *start, struct timeval *end)
{
    unsigned long long diff_us;
    diff_us =
        (((unsigned long long)end->tv_sec)*1000000 + end->tv_usec) -
        (((unsigned long long)start->tv_sec)*1000000 + start->tv_usec);
    printf("%llu s, %06llu us\n", diff_us/1000000, diff_us%1000000);
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types:
end
struct timeval *


decompiled_code:
__int64 __fastcall verify_sort(__int64 a1, int a2, __int16 a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // rsi
__int64 v9; // rcx
__int64 v10; // r8

if ( a2 <= 1 )
return 0LL;
v4 = (unsigned int)(a2 - 2) + 2LL;
v5 = 1LL;
do
{
v8 = (unsigned int)(v5 - 1);
if ( a3 )
{
v9 = *(unsigned int *)(a1 + 4 * v5 - 4);
v10 = *(unsigned int *)(a1 + 4 * v5);
if ( (int)v9 > (int)v10 )
printf("Failure! n[%d] > n[%d] (%d, %d)\n", v8, (unsigned int)v5, v9, v10);
}
else
{
v6 = *(unsigned int *)(a1 + 4 * v5 - 4);
v7 = *(unsigned int *)(a1 + 4 * v5);
if ( (int)v6 < (int)v7 )
printf("Failure! n[%d] < n[%d] (%d, %d)\n", v8, (unsigned int)v5, v6, v7);
}
++v5;
}
while ( v5 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int16 a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // rsi
__int64 v9; // rcx
__int64 v10; // r8

if ( a2 <= 1 )
return 0LL;
v4 = (unsigned int)(a2 - 2) + 2LL;
v5 = 1LL;
do
{
v8 = (unsigned int)(v5 - 1);
if ( a3 )
{
v9 = *(unsigned int *)(a1 + 4 * v5 - 4);
v10 = *(unsigned int *)(a1 + 4 * v5);
if ( (int)v9 > (int)v10 )
printf("Failure! n[%d] > n[%d] (%d, %d)\n", v8, (unsigned int)v5, v9, v10);
}
else
{
v6 = *(unsigned int *)(a1 + 4 * v5 - 4);
v7 = *(unsigned int *)(a1 + 4 * v5);
if ( (int)v6 < (int)v7 )
printf("Failure! n[%d] < n[%d] (%d, %d)\n", v8, (unsigned int)v5, v6, v7);
}
++v5;
}
while ( v5 != v4 );
return 0LL;
}

original_code:
int verify_sort(int * numbers, int len, short asc)
{
    int i;
    for(i = 0; i < len-1; i++)
    {
        if(asc && (numbers[i] > numbers[i+1]))
           printf("Failure! n[%d] > n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
        if(!asc && (numbers[i] < numbers[i+1]))
           printf("Failure! n[%d] < n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
    }
}

canonical_original_code:
int verify_sort(int *numbers, int len, short asc)
{
    int i;
    for(i = 0; i < len-1; i++)
    {
        if(asc && (numbers[i] > numbers[i+1]))
           printf("Failure! n[%d] > n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
        if(!asc && (numbers[i] < numbers[i+1]))
           printf("Failure! n[%d] < n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
    }
}

variable_types:
numbers
int *

variable_types: len int

variable_types: asc short


decompiled_code:
int __fastcall do_int_sort(__int64 a1, int a2, const char *a3, __int64 (__fastcall **a4)(_QWORD, _QWORD, _QWORD, _QWORD), void *a5)
{
const char *v9; // rdx
struct timeval v11; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v9 = "asc";
if ( a5 != &int_compare_asc )
v9 = "desc";
printf("Sorting %s, int %s: ", a3, v9);
fflush(stdout);
if ( a4 == &bubblesort )
{
gettimeofday(&tv, 0LL);
bubblesort(a1, a2, 4LL, a5);
gettimeofday(&v11, 0LL);
}
else if ( a4 == &mergesort )
{
gettimeofday(&tv, 0LL);
mergesort(a1, a2, 4LL, a5);
gettimeofday(&v11, 0LL);
}
else if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc )
{
gettimeofday(&tv, 0LL);
mergesort_onemalloc(a1, a2, 4LL, a5, 0LL);
gettimeofday(&v11, 0LL);
}
else if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort )
{
gettimeofday(&tv, 0LL);
quicksort(a1, 0LL, a2 - 1, 4LL, a5);
gettimeofday(&v11, 0LL);
}
else if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc )
{
gettimeofday(&tv, 0LL);
quicksort_onemalloc(a1, 0LL, a2 - 1, 4LL, a5, 0LL);
gettimeofday(&v11, 0LL);
}
return printtime(&tv, &v11);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, const char *a3, __int64 (__fastcall **a4)(_QWORD, _QWORD, _QWORD, _QWORD), void *a5)
{
const char *v9; // rdx
struct timeval v11; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v9 = "asc";
if ( a5 != &int_compare_asc )
v9 = "desc";
printf("Sorting %s, int %s: ", a3, v9);
fflush(stdout);
if ( a4 == &bubblesort )
{
gettimeofday(&tv, 0LL);
bubblesort(a1, a2, 4LL, a5);
gettimeofday(&v11, 0LL);
}
else if ( a4 == &mergesort )
{
gettimeofday(&tv, 0LL);
mergesort(a1, a2, 4LL, a5);
gettimeofday(&v11, 0LL);
}
else if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc )
{
gettimeofday(&tv, 0LL);
mergesort_onemalloc(a1, a2, 4LL, a5, 0LL);
gettimeofday(&v11, 0LL);
}
else if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort )
{
gettimeofday(&tv, 0LL);
quicksort(a1, 0LL, a2 - 1, 4LL, a5);
gettimeofday(&v11, 0LL);
}
else if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc )
{
gettimeofday(&tv, 0LL);
quicksort_onemalloc(a1, 0LL, a2 - 1, 4LL, a5, 0LL);
gettimeofday(&v11, 0LL);
}
return func0(&tv, &v11);
}

original_code:
int do_int_sort(int * numbers, int len, char * name, void * func,
                compare_func comp)
{
    struct timeval start, end;
    printf("Sorting %s, int %s: ", name,
           (comp == &int_compare_asc? "asc" : "desc"));
    fflush(stdout);
    if(func == &bubblesort)
    {
        gettimeofday(&start, ((void *)0));
        bubblesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort)
    {
        gettimeofday(&start, ((void *)0));
        mergesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        mergesort_onemalloc(numbers, len, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort)
    {
        gettimeofday(&start, ((void *)0));
        quicksort(numbers, 0, len-1, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        quicksort_onemalloc(numbers, 0, len-1, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    printtime(&start, &end);
}

canonical_original_code:
int do_int_sort(int *numbers, int len, char *name, void *func, int (*comp)(void *first, void *second))
{
    struct timeval start; struct timeval end;
    printf("Sorting %s, int %s: ", name,
           (comp == &int_compare_asc? "asc" : "desc"));
    fflush(stdout);
    if(func == &bubblesort)
    {
        gettimeofday(&start, ((void *)0));
        bubblesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort)
    {
        gettimeofday(&start, ((void *)0));
        mergesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        mergesort_onemalloc(numbers, len, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort)
    {
        gettimeofday(&start, ((void *)0));
        quicksort(numbers, 0, len-1, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        quicksort_onemalloc(numbers, 0, len-1, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    printtime(&start, &end);
}

variable_types:
name
char *

variable_types:
func
void *

variable_types:
comp
int (*)(void *first, void *second)

variable_types: struct timeval { long tv_sec; long tv_usec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // r14
int v5; // er12
void *v6; // rax
void *v7; // rbp
int *v8; // rbx
__int64 v9; // r13
unsigned int v11; // eax

if ( argc == 3 )
{
v4 = argv[2];
printf("Limiting algorithm to %s\n", v4);
v11 = time(0LL);
srand(v11);
goto LABEL_4;
}
v3 = time(0LL);
srand(v3);
if ( argc > 1 )
{
v4 = 0LL;
LABEL_4:
v5 = atoi(argv[1]);
goto LABEL_5;
}
v5 = rand() % 100000;
v4 = 0LL;
LABEL_5:
printf("Generating array of %d random int's\n", (unsigned int)v5);
v6 = malloc(4LL * v5);
v7 = v6;
if ( v6 )
{
if ( v5 > 0 )
{
v8 = (int *)v6;
v9 = (__int64)v6 + 4 * (unsigned int)(v5 - 1) + 4;
do
*v8++ = rand();
while ( v8 != (int *)v9 );
}
if ( v4 )
{
if ( !strcmp(v4, "bubble") )
{
do_int_sort((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "merge") )
{
do_int_sort((__int64)v7, v5, "mergesort", &mergesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, "mergesort", &mergesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "mone") )
{
do_int_sort(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "quick") )
{
do_int_sort(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( strcmp(v4, "qone") )
goto LABEL_20;
}
else
{
do_int_sort((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
do_int_sort((__int64)v7, v5, "mergesort", &mergesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, "mergesort", &mergesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
do_int_sort(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
do_int_sort(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
do_int_sort(
(__int64)v7,
v5,
"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
LABEL_20:
free(v7);
return 0;
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // r14
int v5; // er12
void *v6; // rax
void *v7; // rbp
int *v8; // rbx
__int64 v9; // r13
unsigned int v11; // eax

if ( argc == 3 )
{
v4 = argv[2];
printf("Limiting algorithm to %s\n", v4);
v11 = time(0LL);
srand(v11);
goto LABEL_4;
}
v3 = time(0LL);
srand(v3);
if ( argc > 1 )
{
v4 = 0LL;
LABEL_4:
v5 = atoi(argv[1]);
goto LABEL_5;
}
v5 = rand() % 100000;
v4 = 0LL;
LABEL_5:
printf("Generating array of %d random int's\n", (unsigned int)v5);
v6 = malloc(4LL * v5);
v7 = v6;
if ( v6 )
{
if ( v5 > 0 )
{
v8 = (int *)v6;
v9 = (__int64)v6 + 4 * (unsigned int)(v5 - 1) + 4;
do
*v8++ = rand();
while ( v8 != (int *)v9 );
}
if ( v4 )
{
if ( !strcmp(v4, "bubble") )
{
func2((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "merge") )
{
func2((__int64)v7, v5, "mergesort", &mergesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, "mergesort", &mergesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "mone") )
{
func2(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "quick") )
{
func2(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( strcmp(v4, "qone") )
goto LABEL_20;
}
else
{
func2((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, "bubblesort", &bubblesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
func2((__int64)v7, v5, "mergesort", &mergesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, "mergesort", &mergesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
func2(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
func1((__int64)v7, v5, 0);
func2(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
func1((__int64)v7, v5, 0);
}
func2(
(__int64)v7,
v5,
"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_desc);
func1((__int64)v7, v5, 0);
LABEL_20:
free(v7);
return 0;
}
return 1;
}

original_code:
int main(int argc, char ** argv)
{
    int * numbers;
    int len, i;
    char * algo = ((void *)0);
    if(argc == 3)
    {
        algo = argv[2];
        printf("Limiting algorithm to %s\n", algo);
    }
    srand(time(((void *)0)));
    if(argc >= 2)
        len = atoi(argv[1]);
    else
    {
        len = rand() % 100000;
    }
    printf("Generating array of %d random int's\n", len);
    numbers = malloc(sizeof(int) * len);
    if(!numbers)
        return 1;
    for(i = 0; i < len; i++)
        numbers[i] = rand();
    if(algo == ((void *)0) || strcmp(algo, "bubble") == 0)
    {
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "merge") == 0)
    {
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "mone") == 0)
    {
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "quick") == 0)
    {
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "qone") == 0)
    {
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    free(numbers);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int *numbers;
    int len; int i;
    char *algo = ((void *)0);
    if(argc == 3)
    {
        algo = argv[2];
        printf("Limiting algorithm to %s\n", algo);
    }
    srand(time(((void *)0)));
    if(argc >= 2)
        len = atoi(argv[1]);
    else
    {
        len = rand() % 100000;
    }
    printf("Generating array of %d random int's\n", len);
    numbers = malloc(sizeof(int) * len);
    if(!numbers)
        return 1;
    for(i = 0; i < len; i++)
        numbers[i] = rand();
    if(algo == ((void *)0) || strcmp(algo, "bubble") == 0)
    {
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "merge") == 0)
    {
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "mone") == 0)
    {
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "quick") == 0)
    {
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "qone") == 0)
    {
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    free(numbers);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
algo
char *