wordtolist

decompiled_code:
__int64 __fastcall wordtolist(_BYTE *a1, unsigned int a2, char a3)
{
__int64 result; // rax

if ( a3 == 108 )
return wordinsert(list, a1, a2, 108LL);
switch ( *a1 )
{
case 'A':
case 'a':
result = wordinsert(lista, a1, a2, (unsigned int)a3);
break;
case 'B':
case 'b':
result = wordinsert(listb, a1, a2, (unsigned int)a3);
break;
case 'C':
case 'c':
result = wordinsert(listc, a1, a2, (unsigned int)a3);
break;
case 'D':
case 'd':
result = wordinsert(listd, a1, a2, (unsigned int)a3);
break;
case 'E':
case 'e':
result = wordinsert(liste, a1, a2, (unsigned int)a3);
break;
case 'F':
case 'f':
result = wordinsert(listf, a1, a2, (unsigned int)a3);
break;
case 'G':
case 'g':
result = wordinsert(listg, a1, a2, (unsigned int)a3);
break;
case 'H':
case 'h':
result = wordinsert(listh, a1, a2, (unsigned int)a3);
break;
case 'I':
case 'i':
result = wordinsert(listi, a1, a2, (unsigned int)a3);
break;
case 'J':
case 'j':
result = wordinsert(listj, a1, a2, (unsigned int)a3);
break;
case 'K':
case 'k':
result = wordinsert(listk, a1, a2, (unsigned int)a3);
break;
case 'L':
case 'l':
result = wordinsert(listl, a1, a2, (unsigned int)a3);
break;
case 'M':
case 'm':
result = wordinsert(listm, a1, a2, (unsigned int)a3);
break;
case 'N':
case 'n':
result = wordinsert(listn, a1, a2, (unsigned int)a3);
break;
case 'O':
case 'o':
result = wordinsert(listo, a1, a2, (unsigned int)a3);
break;
case 'P':
case 'p':
result = wordinsert(listp, a1, a2, (unsigned int)a3);
break;
case 'Q':
case 'q':
result = wordinsert(listq, a1, a2, (unsigned int)a3);
break;
case 'R':
case 'r':
result = wordinsert(listr, a1, a2, (unsigned int)a3);
break;
case 'S':
case 's':
result = wordinsert(lists, a1, a2, (unsigned int)a3);
break;
case 'T':
case 't':
result = wordinsert(listt, a1, a2, (unsigned int)a3);
break;
case 'U':
case 'u':
result = wordinsert(listu, a1, a2, (unsigned int)a3);
break;
case 'V':
case 'v':
result = wordinsert(listv, a1, a2, (unsigned int)a3);
break;
case 'W':
case 'w':
result = wordinsert(listw, a1, a2, (unsigned int)a3);
break;
case 'X':
case 'x':
result = wordinsert(listx, a1, a2, (unsigned int)a3);
break;
case 'Y':
case 'y':
result = wordinsert(listy, a1, a2, (unsigned int)a3);
break;
case 'Z':
case 'z':
result = wordinsert(listz, a1, a2, (unsigned int)a3);
break;
default:
result = wordinsert(list, a1, a2, (unsigned int)a3);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned int a2, char a3)
{
__int64 result; // rax

if ( a3 == 108 )
return wordinsert(list, a1, a2, 108LL);
switch ( *a1 )
{
case 'A':
case 'a':
result = wordinsert(lista, a1, a2, (unsigned int)a3);
break;
case 'B':
case 'b':
result = wordinsert(listb, a1, a2, (unsigned int)a3);
break;
case 'C':
case 'c':
result = wordinsert(listc, a1, a2, (unsigned int)a3);
break;
case 'D':
case 'd':
result = wordinsert(listd, a1, a2, (unsigned int)a3);
break;
case 'E':
case 'e':
result = wordinsert(liste, a1, a2, (unsigned int)a3);
break;
case 'F':
case 'f':
result = wordinsert(listf, a1, a2, (unsigned int)a3);
break;
case 'G':
case 'g':
result = wordinsert(listg, a1, a2, (unsigned int)a3);
break;
case 'H':
case 'h':
result = wordinsert(listh, a1, a2, (unsigned int)a3);
break;
case 'I':
case 'i':
result = wordinsert(listi, a1, a2, (unsigned int)a3);
break;
case 'J':
case 'j':
result = wordinsert(listj, a1, a2, (unsigned int)a3);
break;
case 'K':
case 'k':
result = wordinsert(listk, a1, a2, (unsigned int)a3);
break;
case 'L':
case 'l':
result = wordinsert(listl, a1, a2, (unsigned int)a3);
break;
case 'M':
case 'm':
result = wordinsert(listm, a1, a2, (unsigned int)a3);
break;
case 'N':
case 'n':
result = wordinsert(listn, a1, a2, (unsigned int)a3);
break;
case 'O':
case 'o':
result = wordinsert(listo, a1, a2, (unsigned int)a3);
break;
case 'P':
case 'p':
result = wordinsert(listp, a1, a2, (unsigned int)a3);
break;
case 'Q':
case 'q':
result = wordinsert(listq, a1, a2, (unsigned int)a3);
break;
case 'R':
case 'r':
result = wordinsert(listr, a1, a2, (unsigned int)a3);
break;
case 'S':
case 's':
result = wordinsert(lists, a1, a2, (unsigned int)a3);
break;
case 'T':
case 't':
result = wordinsert(listt, a1, a2, (unsigned int)a3);
break;
case 'U':
case 'u':
result = wordinsert(listu, a1, a2, (unsigned int)a3);
break;
case 'V':
case 'v':
result = wordinsert(listv, a1, a2, (unsigned int)a3);
break;
case 'W':
case 'w':
result = wordinsert(listw, a1, a2, (unsigned int)a3);
break;
case 'X':
case 'x':
result = wordinsert(listx, a1, a2, (unsigned int)a3);
break;
case 'Y':
case 'y':
result = wordinsert(listy, a1, a2, (unsigned int)a3);
break;
case 'Z':
case 'z':
result = wordinsert(listz, a1, a2, (unsigned int)a3);
break;
default:
result = wordinsert(list, a1, a2, (unsigned int)a3);
break;
}
return result;
}

original_code:
void wordtolist(char *ss, int islistempty,char cnt)
{
 if(cnt == 'l')
 {
  wordinsert(list,ss,islistempty,cnt);
 }
 else
 {
  char firstch = ss[0];
  switch(firstch)
  {
   case 'a':
   case 'A': wordinsert(lista,ss,islistempty,cnt);break;
   case 'b':
   case 'B': wordinsert(listb,ss,islistempty,cnt);break;
   case 'c':
   case 'C': wordinsert(listc,ss,islistempty,cnt);break;
   case 'd':
   case 'D': wordinsert(listd,ss,islistempty,cnt);break;
   case 'e':
   case 'E': wordinsert(liste,ss,islistempty,cnt);break;
   case 'f':
   case 'F': wordinsert(listf,ss,islistempty,cnt);break;
   case 'g':
   case 'G': wordinsert(listg,ss,islistempty,cnt);break;
   case 'h':
   case 'H': wordinsert(listh,ss,islistempty,cnt);break;
   case 'i':
   case 'I': wordinsert(listi,ss,islistempty,cnt);break;
   case 'j':
   case 'J': wordinsert(listj,ss,islistempty,cnt);break;
   case 'k':
   case 'K': wordinsert(listk,ss,islistempty,cnt);break;
   case 'l':
   case 'L': wordinsert(listl,ss,islistempty,cnt);break;
   case 'm':
   case 'M': wordinsert(listm,ss,islistempty,cnt);break;
   case 'n':
   case 'N': wordinsert(listn,ss,islistempty,cnt);break;
   case 'o':
   case 'O': wordinsert(listo,ss,islistempty,cnt);break;
   case 'p':
   case 'P': wordinsert(listp,ss,islistempty,cnt);break;
   case 'q':
   case 'Q': wordinsert(listq,ss,islistempty,cnt);break;
   case 'r':
   case 'R': wordinsert(listr,ss,islistempty,cnt);break;
   case 's':
   case 'S': wordinsert(lists,ss,islistempty,cnt);break;
   case 't':
   case 'T': wordinsert(listt,ss,islistempty,cnt);break;
   case 'u':
   case 'U': wordinsert(listu,ss,islistempty,cnt);break;
   case 'v':
   case 'V': wordinsert(listv,ss,islistempty,cnt);break;
   case 'w':
   case 'W': wordinsert(listw,ss,islistempty,cnt);break;
   case 'x':
   case 'X': wordinsert(listx,ss,islistempty,cnt);break;
   case 'y':
   case 'Y': wordinsert(listy,ss,islistempty,cnt);break;
   case 'z':
   case 'Z': wordinsert(listz,ss,islistempty,cnt);break;
   default :wordinsert(list,ss,islistempty,cnt);break;
  }
 }
}

canonical_original_code:
void wordtolist(char *ss, int islistempty, char cnt)
{
 if(cnt == 'l')
 {
  wordinsert(list,ss,islistempty,cnt);
 }
 else
 {
  char firstch = ss[0];
  switch(firstch)
  {
   case 'a':
   case 'A': wordinsert(lista,ss,islistempty,cnt);break;
   case 'b':
   case 'B': wordinsert(listb,ss,islistempty,cnt);break;
   case 'c':
   case 'C': wordinsert(listc,ss,islistempty,cnt);break;
   case 'd':
   case 'D': wordinsert(listd,ss,islistempty,cnt);break;
   case 'e':
   case 'E': wordinsert(liste,ss,islistempty,cnt);break;
   case 'f':
   case 'F': wordinsert(listf,ss,islistempty,cnt);break;
   case 'g':
   case 'G': wordinsert(listg,ss,islistempty,cnt);break;
   case 'h':
   case 'H': wordinsert(listh,ss,islistempty,cnt);break;
   case 'i':
   case 'I': wordinsert(listi,ss,islistempty,cnt);break;
   case 'j':
   case 'J': wordinsert(listj,ss,islistempty,cnt);break;
   case 'k':
   case 'K': wordinsert(listk,ss,islistempty,cnt);break;
   case 'l':
   case 'L': wordinsert(listl,ss,islistempty,cnt);break;
   case 'm':
   case 'M': wordinsert(listm,ss,islistempty,cnt);break;
   case 'n':
   case 'N': wordinsert(listn,ss,islistempty,cnt);break;
   case 'o':
   case 'O': wordinsert(listo,ss,islistempty,cnt);break;
   case 'p':
   case 'P': wordinsert(listp,ss,islistempty,cnt);break;
   case 'q':
   case 'Q': wordinsert(listq,ss,islistempty,cnt);break;
   case 'r':
   case 'R': wordinsert(listr,ss,islistempty,cnt);break;
   case 's':
   case 'S': wordinsert(lists,ss,islistempty,cnt);break;
   case 't':
   case 'T': wordinsert(listt,ss,islistempty,cnt);break;
   case 'u':
   case 'U': wordinsert(listu,ss,islistempty,cnt);break;
   case 'v':
   case 'V': wordinsert(listv,ss,islistempty,cnt);break;
   case 'w':
   case 'W': wordinsert(listw,ss,islistempty,cnt);break;
   case 'x':
   case 'X': wordinsert(listx,ss,islistempty,cnt);break;
   case 'y':
   case 'Y': wordinsert(listy,ss,islistempty,cnt);break;
   case 'z':
   case 'Z': wordinsert(listz,ss,islistempty,cnt);break;
   default :wordinsert(list,ss,islistempty,cnt);break;
  }
 }
}

variable_types:
ss
char *

variable_types: islistempty int

variable_types: cnt char

variable_types: firstch char


decompiled_code:
int __fastcall cmp_list_word(__int64 a1, const char *a2)
{
return strcmp(*(const char **)(a1 + 8), a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2)
{
return strcmp(*(const char **)(a1 + 8), a2);
}

original_code:
int cmp_list_word(const void *a, const void *b)
{
 STWD *p1 = (STWD *)a;
 char *p2 = (char *)b;
 return strcmp((const char *)p1->word, p2);
}

canonical_original_code:
int cmp_list_word(void *a, void *b)
{
 struct STWD *p1 = (STWD *)a;
 char *p2 = (char *)b;
 return strcmp((char *)p1->word, p2);
}

variable_types:
a
void *

variable_types:
b
void *

return_type: int


getwordstdin

decompiled_code:
size_t __fastcall getwordstdin(int a1, char a2)
{
unsigned int v2; // er13
int v3; // ebx
size_t result; // rax
char v5; // [rsp+Fh] [rbp-129h] BYREF
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v2 = 1;
v3 = 0;
while ( (unsigned int)_isoc99_scanf(&unk_128, &v5) != -1 )
{
if ( (unsigned __int8)(v5 - 48) <= 9u || (unsigned __int8)(v5 - 97) <= 0x19u )
{
if ( a1 != 1 )
goto LABEL_3;
if ( (unsigned __int8)(v5 - 65) <= 0x19u )
goto LABEL_16;
s[v3++] = v5;
}
else if ( (unsigned __int8)(v5 - 65) <= 0x19u )
{
if ( a1 == 1 )
LABEL_16:
s[v3++] = v5 + 32;
else
LABEL_3:
s[v3++] = v5;
}
else
{
s[v3] = 0;
if ( (int)strlen(s) > 0 )
{
wordinsert(list, s, v2, (unsigned int)a2);
v2 = 0;
}
s[0] = 0;
v3 = 0;
}
}
s[v3] = 0;
result = strlen(s);
if ( (int)result > 0 )
result = wordinsert(list, s, v2, (unsigned int)a2);
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(int a1, char a2)
{
unsigned int v2; // er13
int v3; // ebx
size_t result; // rax
char v5; // [rsp+Fh] [rbp-129h] BYREF
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v2 = 1;
v3 = 0;
while ( (unsigned int)_isoc99_scanf(&unk_128, &v5) != -1 )
{
if ( (unsigned __int8)(v5 - 48) <= 9u || (unsigned __int8)(v5 - 97) <= 0x19u )
{
if ( a1 != 1 )
goto LABEL_3;
if ( (unsigned __int8)(v5 - 65) <= 0x19u )
goto LABEL_16;
s[v3++] = v5;
}
else if ( (unsigned __int8)(v5 - 65) <= 0x19u )
{
if ( a1 == 1 )
LABEL_16:
s[v3++] = v5 + 32;
else
LABEL_3:
s[v3++] = v5;
}
else
{
s[v3] = 0;
if ( (int)strlen(s) > 0 )
{
wordinsert(list, s, v2, (unsigned int)a2);
v2 = 0;
}
s[0] = 0;
v3 = 0;
}
}
s[v3] = 0;
result = strlen(s);
if ( (int)result > 0 )
result = wordinsert(list, s, v2, (unsigned int)a2);
return result;
}

original_code:
void getwordstdin(int uptolower,char cnt)
{
 char ss[256];
 char c;
 int i =0;
 int len = 0;
 int islistempty=1;
 while(scanf("%c",&c) != (-1))
 {
  if((c >= '0' && c<='9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
  {
   if(uptolower == 1)
   {
    if(c >= 'A' && c <= 'Z')
    {
     ss[i++] = c + 32;
    }
    else
    {
     ss[i++] = c;
    }
   }
   else
   {
    ss[i++] = c;
   }
  }
  else
  {
   ss[i++] = '\0';
   len = strlen(ss);
   if(len >0)
   {
    wordinsert(list,ss, islistempty,cnt);
    islistempty = 0;
   }
   i = 0;
   ss[i] = '\0';
  }
 }
 ss[i++] = '\0';
 len = strlen(ss);
 if(len >0)
  {
  wordinsert(list,ss,islistempty,cnt);
  islistempty = 0;
  }
}

canonical_original_code:
void getwordstdin(int uptolower, char cnt)
{
 char ss[256];
 char c;
 int i = 0;
 int len = 0;
 int islistempty = 1;
 while(scanf("%c",&c) != (-1))
 {
  if((c >= '0' && c<='9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
  {
   if(uptolower == 1)
   {
    if(c >= 'A' && c <= 'Z')
    {
     ss[i++] = c + 32;
    }
    else
    {
     ss[i++] = c;
    }
   }
   else
   {
    ss[i++] = c;
   }
  }
  else
  {
   ss[i++] = '\0';
   len = strlen(ss);
   if(len >0)
   {
    wordinsert(list,ss, islistempty,cnt);
    islistempty = 0;
   }
   i = 0;
   ss[i] = '\0';
  }
 }
 ss[i++] = '\0';
 len = strlen(ss);
 if(len >0)
  {
  wordinsert(list,ss,islistempty,cnt);
  islistempty = 0;
  }
}

variable_types: uptolower int

variable_types:
ss
char [256]

variable_types: c char

variable_types: i int

variable_types: len int

return_type: void


decompiled_code:
void __fastcall diag_similarity_transform(__int64 a1, unsigned int a2)
{
double *v2; // r14
__int64 i; // rbx
__int64 v4; // rbp
double *v5; // rbx

v2 = (double *)calloc((int)a2, 8uLL);
diag(v2, a1, a2);
if ( (int)a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = a1;
cblas_dscal(a2, i * 8 + a1, a2, v2[i]);
}
v5 = v2;
do
{
cblas_dscal(a2, v4, 1LL, *v5++);
v4 += 8LL * (int)a2;
}
while ( v5 != &v2[a2] );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, unsigned int a2)
{
double *v2; // r14
__int64 i; // rbx
__int64 v4; // rbp
double *v5; // rbx

v2 = (double *)calloc((int)a2, 8uLL);
func1(v2, a1, a2);
if ( (int)a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = a1;
cblas_dscal(a2, i * 8 + a1, a2, v2[i]);
}
v5 = v2;
do
{
cblas_dscal(a2, v4, 1LL, *v5++);
v4 += 8LL * (int)a2;
}
while ( v5 != &v2[a2] );
}
free(v2);
}

original_code:
static void diag_similarity_transform(double *w, int n_patch)
{
    double *d = (double *)calloc(n_patch, sizeof(double));
    int i;
    diag(d, w, n_patch);
    for (i = 0; i < n_patch; i++)
        cblas_dscal(n_patch, d[i], &w[i], n_patch);
    for (i = 0; i < n_patch; i++)
        cblas_dscal(n_patch, d[i], &w[i * n_patch], 1);
    free(d);
}

variable_types:
w
double *

variable_types:
d
double *


original_code:
static void compute_l(double *w, int n_patch)
{
    int N = n_patch * n_patch;
    int i;
    for (i = 0; i < N; i++)
        w[i] = ((i % (n_patch + 1) == 0) ? 1.0 : 0.0) - w[i];
}

variable_types: N int


diag

original_code:
static void diag(double *d, const double *w, int n_patch)
{
    int i, j;
    double sum;
    for (j = 0; j < n_patch; j++){
        sum = 0;
        for (i = 0; i < n_patch; i++)
            sum += w[i + j * n_patch];
        d[j] = 1 / sqrt(sum);
    }
}

canonical_original_code:
static void diag(double *d, double *w, int n_patch)
{
    int i; int j;
    double sum;
    for (j = 0; j < n_patch; j++){
        sum = 0;
        for (i = 0; i < n_patch; i++)
            sum += w[i + j * n_patch];
        d[j] = 1 / sqrt(sum);
    }
}

variable_types: j int

variable_types: sum double


laplacian

decompiled_code:
void __fastcall laplacian(__int64 a1, unsigned int a2)
{
diag_similarity_transform(a1, a2);
compute_l(a1, a2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned int a2)
{
func2(a1, a2);
func0(a1, a2);
}

original_code:
void laplacian(double *w, int n_patch)
{
    diag_similarity_transform(w, n_patch);
    compute_l(w, n_patch);
}


pairweight

decompiled_code:
__int64 __fastcall pairweight(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5, int a6, int *a7)
{
return diff_reduce(a1, a3, a4, a5[1] * *a5, a6, *a7, a7[1], a2);
}

original_code:
void pairweight(double *w, int n_patch, double *feat, double *pos,
                int feat_dim[2], int pos_dim, int par[2], int option)
{
    diff_reduce(w, feat, pos, feat_dim[0] * feat_dim[1], pos_dim,
        par[0], par[1], n_patch);
}

variable_types:
feat
double *

variable_types:
pos
double *

variable_types:
par
int [2]

variable_types: option int


arggetc

repo: hcpa/rpi-usbcam

variable_types: struct arg_t { char *s; char *sep; char opts; char quote; } *


argopts

original_code:
int argopts(arg_t *arg, char *src, char *sep, int opts)
{
 memset(arg, 0, sizeof(arg_t));
 arg->s = src;
 arg->sep = sep;
 arg->opts = opts;
 return(0);
}

canonical_original_code:
int argopts(struct arg_t *arg, char *src, char *sep, int opts)
{
 memset(arg, 0, sizeof(arg_t));
 arg->s = src;
 arg->sep = sep;
 arg->opts = opts;
 return(0);
}

variable_types:
src
char *

variable_types:
sep
char *

variable_types: opts int

user_defined_types: struct arg_t { char *s; char *sep; char opts; char quote; }


argncpy

original_code:
int argncpy(char *dst, size_t n, char *src, char *sep, int arg, int opt)
{
 arg_t s;
 char *d;
 size_t l;
 int r;
 argopts(&s, src, sep, opt);
 d = dst;
 *d = '\0';
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(0);
   d = dst;
   *d = '\0';
   l = 0;
   continue;
  }
  if(n > l)
  {
   *(d++) = r;
   *d = '\0';
   l++;
  }
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(0);
 return(-1);
}

canonical_original_code:
int argncpy(char *dst, unsigned long n, char *src, char *sep, int arg, int opt)
{
 struct arg_t s;
 char *d;
 unsigned long l;
 int r;
 argopts(&s, src, sep, opt);
 d = dst;
 *d = '\0';
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(0);
   d = dst;
   *d = '\0';
   l = 0;
   continue;
  }
  if(n > l)
  {
   *(d++) = r;
   *d = '\0';
   l++;
  }
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(0);
 return(-1);
}

variable_types:
dst
char *

variable_types:
n
unsigned long

variable_types: arg int

variable_types: opt int

variable_types: struct arg_t { char *s; char *sep; char opts; char quote; }

variable_types:
d
char *

variable_types:
l
unsigned long

variable_types: r int


arglen

decompiled_code:
__int64 __fastcall arglen(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax
char *v8[9]; // [rsp+0h] [rbp-48h] BYREF

argopts((__int64)v8, a1, a2, a4);
v6 = 0LL;
while ( 1 )
{
result = arggetc(v8);
if ( (_DWORD)result == -1 )
break;
if ( (_DWORD)result == -2 )
{
if ( (((unsigned __int8)(a4 >> 3) ^ 1) & 1) != 0 && !v6 )
{
v6 = 0LL;
}
else
{
if ( !a3 )
return (unsigned int)v6;
--a3;
v6 = 0LL;
}
}
else
{
++v6;
}
}
if ( !a3 && ((a4 & 8) != 0 || v6) )
result = (unsigned int)v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax
char *v8[9]; // [rsp+0h] [rbp-48h] BYREF

func1((__int64)v8, a1, a2, a4);
v6 = 0LL;
while ( 1 )
{
result = func0(v8);
if ( (_DWORD)result == -1 )
break;
if ( (_DWORD)result == -2 )
{
if ( (((unsigned __int8)(a4 >> 3) ^ 1) & 1) != 0 && !v6 )
{
v6 = 0LL;
}
else
{
if ( !a3 )
return (unsigned int)v6;
--a3;
v6 = 0LL;
}
}
else
{
++v6;
}
}
if ( !a3 && ((a4 & 8) != 0 || v6) )
result = (unsigned int)v6;
return result;
}

original_code:
int arglen(char *src, char *sep, int arg, int opt)
{
 arg_t s;
 size_t l;
 int r;
 argopts(&s, src, sep, opt);
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(l);
   l = 0;
   continue;
  }
  l++;
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(l);
 return(-1);
}

canonical_original_code:
int arglen(char *src, char *sep, int arg, int opt)
{
 struct arg_t s;
 unsigned long l;
 int r;
 argopts(&s, src, sep, opt);
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(l);
   l = 0;
   continue;
  }
  l++;
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(l);
 return(-1);
}


argcount

decompiled_code:
__int64 __fastcall argcount(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int i; // ebx

for ( i = 0; (int)arglen(a1, a2, i, a3) >= 0; ++i )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int i; // ebx

for ( i = 0; (int)func3(a1, a2, i, a3) >= 0; ++i )
;
return i;
}

original_code:
int argcount(char *src, char *sep, int opt)
{
 int count = 0;
 while(arglen(src, sep, count, opt) >= 0)
  count++;
 return(count);
}

variable_types: count int


argtol

decompiled_code:
__int64 __fastcall argtol(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, int a5)
{
char *v6; // rax
char *v7; // rbx
int *v8; // rbp
__int64 v9; // rax
bool v10; // zf
__int64 v11; // rbp

v6 = argdup(a1, a2, a3, a4);
if ( !v6 )
return -1LL;
v7 = v6;
v8 = _errno_location();
*v8 = 0;
v9 = strtol(v7, 0LL, a5);
v10 = *v8 == 0;
v11 = -1LL;
if ( v10 )
v11 = v9;
free(v7);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, int a5)
{
char *v6; // rax
char *v7; // rbx
int *v8; // rbp
__int64 v9; // rax
bool v10; // zf
__int64 v11; // rbp

v6 = argdup(a1, a2, a3, a4);
if ( !v6 )
return -1LL;
v7 = v6;
v8 = _errno_location();
*v8 = 0;
v9 = strtol(v7, 0LL, a5);
v10 = *v8 == 0;
v11 = -1LL;
if ( v10 )
v11 = v9;
free(v7);
return v11;
}

original_code:
long argtol(char *src, char *sep, int arg, int opt, int base)
{
 char *str;
 long val;
 str = argdup(src, sep, arg, opt);
 if(!str) return(-1);
 (*__errno_location ()) = 0;
 val = strtol(str, ((void *)0), base);
 if((*__errno_location ())) val = -1;
 free(str);
 return(val);
}

variable_types: base int

variable_types:
str
char *

variable_types: val long

return_type: long


decompiled_code:
__int64 __fastcall parse_font(char *src, void **a2, int *a3)
{
size_t v5; // r12
char *v6; // rax
char *v7; // r13
int v8; // eax
char *v9; // rdi

if ( a3 == 0LL || a2 == 0LL || !src )
return 0xFFFFFFFFLL;
v5 = strlen(src);
v6 = strrchr(src, 58);
v7 = v6;
if ( v6 )
{
v8 = atoi(v6 + 1);
if ( v8 > 0 )
{
*a3 = v8;
v5 = v7 - src;
}
}
if ( *a2 )
free(*a2);
v9 = (char *)calloc(v5 + 1, 1uLL);
*a2 = v9;
if ( !v9 )
return 0xFFFFFFFFLL;
strncpy(v9, src, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src, void **a2, int *a3)
{
size_t v5; // r12
char *v6; // rax
char *v7; // r13
int v8; // eax
char *v9; // rdi

if ( a3 == 0LL || a2 == 0LL || !src )
return 0xFFFFFFFFLL;
v5 = strlen(src);
v6 = strrchr(src, 58);
v7 = v6;
if ( v6 )
{
v8 = atoi(v6 + 1);
if ( v8 > 0 )
{
*a3 = v8;
v5 = v7 - src;
}
}
if ( *a2 )
free(*a2);
v9 = (char *)calloc(v5 + 1, 1uLL);
*a2 = v9;
if ( !v9 )
return 0xFFFFFFFFLL;
strncpy(v9, src, v5);
return 0LL;
}

original_code:
int parse_font(char *src, char **font, int *fontsize)
{
 char *p;
 size_t l;
 if(!src || !font || !fontsize) return(-1);
 l = strlen(src);
 if((p = strrchr(src, ':')))
 {
  int i = atoi(p + 1);
  if(i > 0)
  {
   *fontsize = i;
   l = p - src;
  }
 }
 if(*font) free(*font);
 *font = (char *) calloc(l + 1, 1);
 if(!*font) return(-1);
 strncpy(*font, src, l);
 return(0);
}

canonical_original_code:
int parse_font(char *src, char **font, int *fontsize)
{
 char *p;
 unsigned long l;
 if(!src || !font || !fontsize) return(-1);
 l = strlen(src);
 if((p = strrchr(src, ':')))
 {
  int i = atoi(p + 1);
  if(i > 0)
  {
   *fontsize = i;
   l = p - src;
  }
 }
 if(*font) free(*font);
 *font = (char *) calloc(l + 1, 1);
 if(!*font) return(-1);
 strncpy(*font, src, l);
 return(0);
}

variable_types:
font
char **

variable_types:
fontsize
int *

variable_types:
p
char *

variable_types: i int


strtrim

decompiled_code:
const char *__fastcall strtrim(const char *a1, const char *a2)
{
char *v2; // r12
const char *v3; // rbx
char i; // r13
size_t v5; // rbp

v2 = (char *)a1;
v3 = &a1[strspn(a1, a2)];
for ( i = *v3; *v3; i = *v3 )
{
v5 = strspn(v3, a2);
if ( v5 == strlen(v3) )
break;
++v3;
*v2++ = i;
}
*v2 = 0;
return v3;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1, const char *a2)
{
char *v2; // r12
const char *v3; // rbx
char i; // r13
size_t v5; // rbp

v2 = (char *)a1;
v3 = &a1[strspn(a1, a2)];
for ( i = *v3; *v3; i = *v3 )
{
v5 = strspn(v3, a2);
if ( v5 == strlen(v3) )
break;
++v3;
*v2++ = i;
}
*v2 = 0;
return v3;
}

original_code:
char *strtrim(char *str, char *ws)
{
 char *s = str;
 str += strspn(str, ws);
 while(*str != '\0' && strspn(str, ws) != strlen(str))
  *(s++) = *(str++);
 *s = '\0';
 return(str);
}

variable_types:
ws
char *

variable_types:
s
char *

return_type: char *


dpixGetMax

decompiled_code:
__int64 __fastcall dpixGetMax(__int64 a1, double *a2, unsigned __int64 a3, unsigned __int64 a4)
{
int v6; // er11
int v7; // er10
__int64 v8; // rdx
__int64 v9; // rcx
double v10; // xmm1_8
int v11; // edi
int v12; // er8
int i; // er9
__int64 result; // rax
__int64 v15; // rax

if ( (unsigned __int64)a2 | a4 | a3 )
{
if ( a2 )
*a2 = 0.0;
if ( a3 )
*(_DWORD *)a3 = 0;
if ( a4 )
*(_DWORD *)a4 = 0;
if ( a1 )
{
v6 = *(_DWORD *)a1;
v7 = *(_DWORD *)(a1 + 4);
v8 = *(_QWORD *)(a1 + 8);
if ( v7 <= 0 )
{
v10 = *(double *)&LC0;
v11 = 0;
v12 = 0;
}
else
{
v9 = (unsigned int)(v6 - 1);
v10 = *(double *)&LC0;
v11 = 0;
v12 = 0;
for ( i = 0; i != v7; ++i )
{
v15 = 0LL;
if ( v6 > 0 )
{
while ( 1 )
{
if ( *(double *)(v8 + 8 * v15) > v10 )
{
v10 = *(double *)(v8 + 8 * v15);
v11 = i;
v12 = v15;
}
if ( v15 == v9 )
break;
++v15;
}
v8 += 8 * v9 + 8;
}
}
}
if ( a2 )
*a2 = v10;
if ( a3 )
*(_DWORD *)a3 = v12;
result = 0LL;
if ( a4 )
*(_DWORD *)a4 = v11;
}
else
{
log_msg("fft.c", "dpixGetMax", 40LL, 1LL, "dpix not defined");
result = 0xFFFFFFFFLL;
}
}
else
{
log_msg("fft.c", "dpixGetMax", 32LL, 1LL, "nothing to do");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double *a2, unsigned __int64 a3, unsigned __int64 a4)
{
int v6; // er11
int v7; // er10
__int64 v8; // rdx
__int64 v9; // rcx
double v10; // xmm1_8
int v11; // edi
int v12; // er8
int i; // er9
__int64 result; // rax
__int64 v15; // rax

if ( (unsigned __int64)a2 | a4 | a3 )
{
if ( a2 )
*a2 = 0.0;
if ( a3 )
*(_DWORD *)a3 = 0;
if ( a4 )
*(_DWORD *)a4 = 0;
if ( a1 )
{
v6 = *(_DWORD *)a1;
v7 = *(_DWORD *)(a1 + 4);
v8 = *(_QWORD *)(a1 + 8);
if ( v7 <= 0 )
{
v10 = *(double *)&LC0;
v11 = 0;
v12 = 0;
}
else
{
v9 = (unsigned int)(v6 - 1);
v10 = *(double *)&LC0;
v11 = 0;
v12 = 0;
for ( i = 0; i != v7; ++i )
{
v15 = 0LL;
if ( v6 > 0 )
{
while ( 1 )
{
if ( *(double *)(v8 + 8 * v15) > v10 )
{
v10 = *(double *)(v8 + 8 * v15);
v11 = i;
v12 = v15;
}
if ( v15 == v9 )
break;
++v15;
}
v8 += 8 * v9 + 8;
}
}
}
if ( a2 )
*a2 = v10;
if ( a3 )
*(_DWORD *)a3 = v12;
result = 0LL;
if ( a4 )
*(_DWORD *)a4 = v11;
}
else
{
log_msg("fft.c", "dpixGetMax", 40LL, 1LL, "dpix not defined");
result = 0xFFFFFFFFLL;
}
}
else
{
log_msg("fft.c", "dpixGetMax", 32LL, 1LL, "nothing to do");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int32_t
dpixGetMax(hc_dpix_t *dpix,
           double *pmaxval,
           int32_t *pxmaxloc,
           int32_t *pymaxloc)
{
 int32_t i, j, w, h, xmaxloc, ymaxloc;
 double *data;
 double maxval;
    if (!pmaxval && !pxmaxloc && !pymaxloc)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 32, (1), "nothing to do");
  return(-1);
 }
    if (pmaxval) *pmaxval = 0.0;
    if (pxmaxloc) *pxmaxloc = 0;
    if (pymaxloc) *pymaxloc = 0;
    if (!dpix)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 40, (1), "dpix not defined");
  return(-1);
 }
    maxval = -1.0e40;
    xmaxloc = 0;
    ymaxloc = 0;
    w = dpix->width;
 h = dpix->height;
    data = dpix->data;
    for (i = 0; i < h; i++)
 {
        for (j = 0; j < w; j++)
  {
            if( (*data) > maxval )
   {
                maxval = (*data);
                xmaxloc = j;
                ymaxloc = i;
            }
   data++;
        }
    }
    if (pmaxval) *pmaxval = maxval;
    if (pxmaxloc) *pxmaxloc = xmaxloc;
    if (pymaxloc) *pymaxloc = ymaxloc;
    return 0;
}

canonical_original_code:
int dpixGetMax(struct hc_dpix_t *dpix, double *pmaxval, int *pxmaxloc, int *pymaxloc)
{
 int i; int j; int w; int h; int xmaxloc; int ymaxloc;
 double *data;
 double maxval;
    if (!pmaxval && !pxmaxloc && !pymaxloc)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 32, (1), "nothing to do");
  return(-1);
 }
    if (pmaxval) *pmaxval = 0.0;
    if (pxmaxloc) *pxmaxloc = 0;
    if (pymaxloc) *pymaxloc = 0;
    if (!dpix)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 40, (1), "dpix not defined");
  return(-1);
 }
    maxval = -1.0e40;
    xmaxloc = 0;
    ymaxloc = 0;
    w = dpix->width;
 h = dpix->height;
    data = dpix->data;
    for (i = 0; i < h; i++)
 {
        for (j = 0; j < w; j++)
  {
            if( (*data) > maxval )
   {
                maxval = (*data);
                xmaxloc = j;
                ymaxloc = i;
            }
   data++;
        }
    }
    if (pmaxval) *pmaxval = maxval;
    if (pxmaxloc) *pxmaxloc = xmaxloc;
    if (pymaxloc) *pymaxloc = ymaxloc;
    return 0;
}

variable_types: struct hc_dpix_t { unsigned int width; unsigned int height; double *data; } *

variable_types:
pmaxval
double *

variable_types:
pxmaxloc
int *

variable_types:
pymaxloc
int *

variable_types: j int

variable_types: w int

variable_types: h int

variable_types: xmaxloc int

variable_types: ymaxloc int

variable_types:
data
double *

variable_types: maxval double


dpixNormalize

decompiled_code:
__int64 __fastcall dpixNormalize(__int64 a1)
{
double v1; // xmm1_8
double *v2; // rax
unsigned int v3; // ecx
__int64 result; // rax
unsigned int i; // edx

if ( a1 )
{
v1 = (double)(*(_DWORD *)a1 * *(_DWORD *)(a1 + 4));
v2 = *(double **)(a1 + 8);
v3 = 0;
if ( *(_DWORD *)(a1 + 4) )
{
do
{
for ( i = 0; *(_DWORD *)a1 > i; ++i )
{
*v2 = *v2 / v1;
++v2;
}
++v3;
}
while ( *(_DWORD *)(a1 + 4) > v3 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
log_msg("fft.c", "dpixNormalize", 104LL, 1LL, "dpixs not defined");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
double v1; // xmm1_8
double *v2; // rax
unsigned int v3; // ecx
__int64 result; // rax
unsigned int i; // edx

if ( a1 )
{
v1 = (double)(*(_DWORD *)a1 * *(_DWORD *)(a1 + 4));
v2 = *(double **)(a1 + 8);
v3 = 0;
if ( *(_DWORD *)(a1 + 4) )
{
do
{
for ( i = 0; *(_DWORD *)a1 > i; ++i )
{
*v2 = *v2 / v1;
++v2;
}
++v3;
}
while ( *(_DWORD *)(a1 + 4) > v3 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
log_msg("fft.c", "dpixNormalize", 104LL, 1LL, "dpixs not defined");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int32_t
dpixNormalize(hc_dpix_t *dpixs)
{
 int32_t i, j;
 double *data, n;
    if (!dpixs)
 {
  log_msg("fft.c", (char *) __FUNCTION__, 104, (1), "dpixs not defined");
  return(-1);
 }
 n = dpixs->width * dpixs->height;
 data = dpixs->data;
 for (i = 0; i < dpixs->height; i++)
  for (j = 0; j < dpixs->width; j++)
  {
   *data = (*data)/n;
   data++;
  }
 return 0;
}

canonical_original_code:
int dpixNormalize(struct hc_dpix_t *dpixs)
{
 int i; int j;
 double *data; double n;
    if (!dpixs)
 {
  log_msg("fft.c", (char *) __FUNCTION__, 104, (1), "dpixs not defined");
  return(-1);
 }
 n = dpixs->width * dpixs->height;
 data = dpixs->data;
 for (i = 0; i < dpixs->height; i++)
  for (j = 0; j < dpixs->width; j++)
  {
   *data = (*data)/n;
   data++;
  }
 return 0;
}

variable_types: n double

user_defined_types: struct hc_dpix_t { unsigned int width; unsigned int height; double *data; }


decompiled_code:
void __fastcall log_set_fd(int a1)
{
fd_log = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
fd_log = a1;
}

original_code:
void log_set_fd(int fd)
{
 fd_log = fd;
}

variable_types: fd int


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

if ( fd_log != 2 && !use_syslog )
{
result = close(fd_log);
fd_log = 2;
}
return result;
}

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

if ( fd_log != 2 && !use_syslog )
{
result = close(fd_log);
fd_log = 2;
}
return result;
}

original_code:
void log_close()
{
 if(fd_log == 2 || use_syslog) return;
 close(fd_log);
 fd_log = 2;
}


decompiled_code:
void __fastcall log_verbose(char a1)
{
verbose = a1;
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
verbose = a1;
}

original_code:
void log_verbose(char v)
{
 verbose = v;
}

variable_types: v char


decompiled_code:
void __fastcall log_quiet(char a1)
{
quiet = a1;
}

canonical_decompiled_code:
void __fastcall func3(char a1)
{
quiet = a1;
}

original_code:
void log_quiet(char v)
{
 quiet = v;
}

canonical_original_code:
void log_quiet(char v)
{
 quiet = v;
}


decompiled_code:
void __fastcall log_syslog(char a1)
{
use_syslog = a1;
if ( a1 )
openlog("test", 3, 8);
else
closelog();
}

canonical_decompiled_code:
void __fastcall func4(char a1)
{
use_syslog = a1;
if ( a1 )
openlog("test", 3, 8);
else
closelog();
}

original_code:
void log_syslog(char v)
{
 use_syslog = v;
 if(use_syslog) openlog("test", 0x01 | 0x02, (1<<3));
 else closelog();
}


decompiled_code:
char *__fastcall vmake_message(char *format, const __m128i *a2)
{
char *v2; // rbp
int v3; // ebx
char *v4; // rax
int v5; // eax
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h]

v2 = (char *)malloc(0x64uLL);
if ( v2 )
{
v3 = 100;
while ( 1 )
{
arg = _mm_loadu_si128(a2);
v8 = a2[1].m128i_i64[0];
v5 = vsnprintf(v2, v3, format, &arg);
if ( v5 >= 0 && v3 > v5 )
break;
v3 *= 2;
if ( v5 >= 0 )
v3 = v5 + 1;
v4 = (char *)realloc(v2, v3);
if ( !v4 )
{
free(v2);
return 0LL;
}
v2 = v4;
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *format, const __m128i *a2)
{
char *v2; // rbp
int v3; // ebx
char *v4; // rax
int v5; // eax
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h]

v2 = (char *)malloc(0x64uLL);
if ( v2 )
{
v3 = 100;
while ( 1 )
{
arg = _mm_loadu_si128(a2);
v8 = a2[1].m128i_i64[0];
v5 = vsnprintf(v2, v3, format, &arg);
if ( v5 >= 0 && v3 > v5 )
break;
v3 *= 2;
if ( v5 >= 0 )
v3 = v5 + 1;
v4 = (char *)realloc(v2, v3);
if ( !v4 )
{
free(v2);
return 0LL;
}
v2 = v4;
}
}
return v2;
}

original_code:
char *vmake_message(const char *fmt, va_list ap)
{
 int n, size = 100;
 char *p;
 p = (char *) malloc(size);
 if(!p) return(((void *)0));
 while(1)
 {
  char *np;
  va_list apc;
  __builtin_va_copy(apc,ap);
  n = vsnprintf(p, size, fmt, apc);
  if(n > -1 && n < size) return(p);
  if(n > -1) size = n + 1;
  else size *= 2;
  np = (char *) realloc(p, size);
  if(!np)
  {
   free(p);
   return(((void *)0));
  }
  p = np;
 }
 free(p);
        return(((void *)0));
}

canonical_original_code:
char *vmake_message(char *fmt, __builtin_va_list ap)
{
 int n; int size = 100;
 char *p;
 p = (char *) malloc(size);
 if(!p) return(((void *)0));
 while(1)
 {
  char *np;
  __builtin_va_list apc;
  __builtin_va_copy(apc,ap);
  n = vsnprintf(p, size, fmt, apc);
  if(n > -1 && n < size) return(p);
  if(n > -1) size = n + 1;
  else size *= 2;
  np = (char *) realloc(p, size);
  if(!np)
  {
   free(p);
   return(((void *)0));
  }
  p = np;
 }
 free(p);
        return(((void *)0));
}

variable_types:
fmt
char *

variable_types: n int

variable_types: size int

variable_types:
p
char *

variable_types:
np
char *


decompiled_code:
char *make_message(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return vmake_message(a1, (const __m128i *)va);
}

canonical_decompiled_code:
char *func6(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func5(a1, (const __m128i *)va);
}

original_code:
char *make_message(const char *fmt, ... )
{
 va_list ap;
 char *msg;
 __builtin_va_start(ap,fmt);
 msg = vmake_message(fmt, ap);
 __builtin_va_end(ap);
 return(msg);
}

canonical_original_code:
char *make_message(char *fmt, ...)
{
 __builtin_va_list ap;
 char *msg;
 __builtin_va_start(ap,fmt);
 msg = vmake_message(fmt, ap);
 __builtin_va_end(ap);
 return(msg);
}

variable_types:
msg
char *


decompiled_code:
void log_msg(__int64 a1, const char *a2, unsigned int a3, char a4, char *a5, ...)
{
char *v7; // rax
char *v8; // r13
char *v9; // rbp
int v10; // edi
char *v11; // rax
__int64 v12; // rdx
size_t v13; // rax
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

if ( fd_log == -1 )
return;
switch ( a4 )
{
case 0:
if ( quiet )
return;
goto LABEL_4;
case 4:
if ( quiet )
return;
goto LABEL_4;
case 5:
if ( !verbose )
return;
goto LABEL_4;
case 2:
if ( quiet )
return;
goto LABEL_4;
}
if ( a4 != 3 )
{
LABEL_4:
va_start(va, a5);
v7 = vmake_message(a5, (const __m128i *)va);
v8 = v7;
if ( !v7 )
return;
v9 = make_message("%s\n", v7);
goto LABEL_6;
}
if ( !verbose )
return;
va_start(va, a5);
v11 = vmake_message(a5, (const __m128i *)va);
v8 = v11;
if ( !v11 )
return;
v9 = make_message("%s,%i: %s\n", a2, a3, v11);
LABEL_6:
if ( !v9 )
{
free(v8);
return;
}
if ( fd_log == 2 )
{
if ( use_syslog )
{
LABEL_9:
v10 = 4;
if ( a4 != 2 )
{
v10 = 7;
if ( a4 != 3 )
v10 = 3 * (a4 != 1) + 3;
}
syslog(v10, "%s", v9);
goto LABEL_13;
}
v12 = 31LL;
if ( a4 != 1 )
{
v12 = 1LL;
if ( a4 != 4 )
{
v12 = 36LL;
if ( a4 != 3 )
v12 = 0LL;
}
}
fprintf(stderr, "\x1B[%im", v12);
}
if ( use_syslog )
goto LABEL_9;
v13 = strlen(v9);
write(fd_log, v9, v13);
LABEL_13:
if ( fd_log == 2 && !use_syslog )
fprintf(stderr, "\x1B[%im", 0LL);
free(v8);
free(v9);
}

canonical_decompiled_code:
void func7(__int64 a1, const char *a2, unsigned int a3, char a4, char *a5, ...)
{
char *v7; // rax
char *v8; // r13
char *v9; // rbp
int v10; // edi
char *v11; // rax
__int64 v12; // rdx
size_t v13; // rax
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

if ( fd_log == -1 )
return;
switch ( a4 )
{
case 0:
if ( quiet )
return;
goto LABEL_4;
case 4:
if ( quiet )
return;
goto LABEL_4;
case 5:
if ( !verbose )
return;
goto LABEL_4;
case 2:
if ( quiet )
return;
goto LABEL_4;
}
if ( a4 != 3 )
{
LABEL_4:
va_start(va, a5);
v7 = func5(a5, (const __m128i *)va);
v8 = v7;
if ( !v7 )
return;
v9 = func6("%s\n", v7);
goto LABEL_6;
}
if ( !verbose )
return;
va_start(va, a5);
v11 = func5(a5, (const __m128i *)va);
v8 = v11;
if ( !v11 )
return;
v9 = func6("%s,%i: %s\n", a2, a3, v11);
LABEL_6:
if ( !v9 )
{
free(v8);
return;
}
if ( fd_log == 2 )
{
if ( use_syslog )
{
LABEL_9:
v10 = 4;
if ( a4 != 2 )
{
v10 = 7;
if ( a4 != 3 )
v10 = 3 * (a4 != 1) + 3;
}
syslog(v10, "%s", v9);
goto LABEL_13;
}
v12 = 31LL;
if ( a4 != 1 )
{
v12 = 1LL;
if ( a4 != 4 )
{
v12 = 36LL;
if ( a4 != 3 )
v12 = 0LL;
}
}
fprintf(stderr, "\x1B[%im", v12);
}
if ( use_syslog )
goto LABEL_9;
v13 = strlen(v9);
write(fd_log, v9, v13);
LABEL_13:
if ( fd_log == 2 && !use_syslog )
fprintf(stderr, "\x1B[%im", 0LL);
free(v8);
free(v9);
}

original_code:
void log_msg(char *file, char *function, int line, char l, char *s, ... )
{
 va_list ap;
 char *msg, *o;
 if(fd_log == -1) return;
 if(l == (0) && quiet) return;
 if(l == (4) && quiet) return;
 if(l == (5) && !verbose) return;
 if(l == (2) && quiet) return;
 if(l == (3) && !verbose) return;
 __builtin_va_start(ap,s);
 msg = vmake_message(s, ap);
 __builtin_va_end(ap);
 if(!msg) return;
 o = ((void *)0);
 if(l == (3)) o = make_message("%s,%i: %s\n", function, line, msg);
 else o = make_message("%s\n", msg);
 if(!o)
 {
  free(msg);
  return;
 }
 if(fd_log == 2 && !use_syslog)
 {
  int colour = -1;
  if(l == (1)) colour = (31);
  else if(l == (4)) colour = (1);
  else if(l == (3)) colour = (36);
  else colour = (0);
  if(!use_syslog) fprintf(stderr, "\033[%im", colour);
 }
 if(!use_syslog) write(fd_log, o, strlen(o));
 else
 {
  int p = 6;
  switch(l)
  {
  case (1): p = 3; break;
  case (2): p = 4; break;
  case (3): p = 7; break;
  }
  syslog(p, "%s", o);
 }
 if(fd_log == 2 && !use_syslog) fprintf(stderr, "\033[%im", (0));
 free(msg);
 free(o);
}

canonical_original_code:
void log_msg(char *file, char *function, int line, char l, char *s, ...)
{
 __builtin_va_list ap;
 char *msg; char *o;
 if(fd_log == -1) return;
 if(l == (0) && quiet) return;
 if(l == (4) && quiet) return;
 if(l == (5) && !verbose) return;
 if(l == (2) && quiet) return;
 if(l == (3) && !verbose) return;
 __builtin_va_start(ap,s);
 msg = vmake_message(s, ap);
 __builtin_va_end(ap);
 if(!msg) return;
 o = ((void *)0);
 if(l == (3)) o = make_message("%s,%i: %s\n", function, line, msg);
 else o = make_message("%s\n", msg);
 if(!o)
 {
  free(msg);
  return;
 }
 if(fd_log == 2 && !use_syslog)
 {
  int colour = -1;
  if(l == (1)) colour = (31);
  else if(l == (4)) colour = (1);
  else if(l == (3)) colour = (36);
  else colour = (0);
  if(!use_syslog) fprintf(stderr, "\033[%im", colour);
 }
 if(!use_syslog) write(fd_log, o, strlen(o));
 else
 {
  int p = 6;
  switch(l)
  {
  case (1): p = 3; break;
  case (2): p = 4; break;
  case (3): p = 7; break;
  }
  syslog(p, "%s", o);
 }
 if(fd_log == 2 && !use_syslog) fprintf(stderr, "\033[%im", (0));
 free(msg);
 free(o);
}

variable_types:
file
char *

variable_types:
function
char *

variable_types: line int

variable_types: l char

variable_types:
s
char *

variable_types:
o
char *

variable_types: colour int

variable_types: p int


decompiled_code:
__int64 __fastcall log_open(const char *a1)
{
unsigned int v1; // ebp
int v3; // eax
int *v4; // rax
char *v5; // rax

if ( !a1 )
return 0;
v1 = 0;
if ( !use_syslog )
{
v3 = open(a1, 1053761, 384LL);
v1 = v3;
if ( v3 == -1 )
{
log_msg((__int64)"log.c", "log_open", 0x3Au, 1, "Error opening log file '%s'...", a1);
v4 = _errno_location();
v5 = strerror(*v4);
log_msg((__int64)"log.c", "log_open", 0x3Bu, 1, "open: %s", v5);
}
else
{
fd_log = v3;
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
unsigned int v1; // ebp
int v3; // eax
int *v4; // rax
char *v5; // rax

if ( !a1 )
return 0;
v1 = 0;
if ( !use_syslog )
{
v3 = open(a1, 1053761, 384LL);
v1 = v3;
if ( v3 == -1 )
{
func7((__int64)"log.c", "log_open", 0x3Au, 1, "Error opening log file '%s'...", a1);
v4 = _errno_location();
v5 = strerror(*v4);
func7((__int64)"log.c", "log_open", 0x3Bu, 1, "open: %s", v5);
}
else
{
fd_log = v3;
v1 = 0;
}
}
return v1;
}

original_code:
int log_open(char *f)
{
 int fd;
 if(!f || use_syslog) return(0);
 fd = open(f, 0100 | 01 | 02000 | 04010000,
           0400 | 0200);
 if(fd == -1)
 {
  log_msg("log.c", (char *) __FUNCTION__, 58, (1), "Error opening log file '%s'...", f);
  log_msg("log.c", (char *) __FUNCTION__, 59, (1), "open: %s", strerror((*__errno_location ())));
  return(-1);
 }
 fd_log = fd;
 return(0);
}

variable_types:
f
char *


hcButterworthHiPassFilter

decompiled_code:
__int64 __fastcall hcButterworthHiPassFilter(__int128 a1, double a2)
{
_DWORD *v2; // rbx
__int64 v3; // rbp

v2 = hcCreateButterworthHiPassFilter(*(_DWORD *)a1, *(_DWORD *)(a1 + 4), a2, (double)SDWORD2(a1));
double_save(*((_QWORD *)v2 + 1), (unsigned int)*v2, (unsigned int)v2[1], "filter.jpg");
*((_QWORD *)&a1 + 1) = v2;
v3 = hcApplyFilter(a1);
free(*((void **)v2 + 1));
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int128 a1, double a2)
{
_DWORD *v2; // rbx
__int64 v3; // rbp

v2 = hcCreateButterworthHiPassFilter(*(_DWORD *)a1, *(_DWORD *)(a1 + 4), a2, (double)SDWORD2(a1));
double_save(*((_QWORD *)v2 + 1), (unsigned int)*v2, (unsigned int)v2[1], "filter.jpg");
*((_QWORD *)&a1 + 1) = v2;
v3 = func0(a1);
free(*((void **)v2 + 1));
free(v2);
return v3;
}

original_code:
hc_dpix_t *hcButterworthHiPassFilter( hc_dpix_t *src, double radius, uint32_t order)
{
 hc_dpix_t *filter;
 hc_dpix_t *result;
 filter = hcCreateButterworthHiPassFilter( src->width, src->height, radius, order);
 double_save(filter->data, filter->width, filter->height, "filter.jpg");
 result = hcApplyFilter( src, filter );
 free(filter->data);
 free(filter);
 return result;
}

canonical_original_code:
struct hc_dpix_t *hcButterworthHiPassFilter(struct hc_dpix_t *src, double radius, unsigned int order)
{
 struct hc_dpix_t *filter;
 struct hc_dpix_t *result;
 filter = hcCreateButterworthHiPassFilter( src->width, src->height, radius, order);
 double_save(filter->data, filter->width, filter->height, "filter.jpg");
 result = hcApplyFilter( src, filter );
 free(filter->data);
 free(filter);
 return result;
}

variable_types:
src
struct hc_dpix_t *

variable_types: radius double

variable_types:
order
unsigned int

variable_types: struct hc_dpix_t { unsigned int width; unsigned int height; double *data; } *


main

canonical_name: main

repo: hdevalence/binary-power

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+20h] [rbp-10h]
unsigned int v5; // [rsp+24h] [rbp-Ch]
unsigned int v6; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v6 = atoi(argv[1]);
v5 = atoi(argv[2]);
v4 = atoi(argv[3]);
for ( i = 0; i <= 99999999; ++i )
binary_exp_c(v6, v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+20h] [rbp-10h]
unsigned int v5; // [rsp+24h] [rbp-Ch]
unsigned int v6; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v6 = atoi(argv[1]);
v5 = atoi(argv[2]);
v4 = atoi(argv[3]);
for ( i = 0; i <= 99999999; ++i )
func7(v6, v5, v4);
return 0;
}

original_code:
int __attribute__((optimize("O0"))) main(int argc, char** argv)
{
 uint32_t x = atoi(argv[1]);
 uint32_t a = atoi(argv[2]);
 uint32_t p = atoi(argv[3]);
 uint32_t y;
 for(int i = 0; i < 100000000; ++i) {
  y = binary_exp_c(x,a,p);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned int x = atoi(argv[1]);
 unsigned int a = atoi(argv[2]);
 unsigned int p = atoi(argv[3]);
 unsigned int y;
 for(int i = 0; i < 100000000; ++i) {
  y = binary_exp_c(x,a,p);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
x
unsigned int

variable_types:
a
unsigned int

variable_types:
p
unsigned int

variable_types:
y
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall binary_exp_c(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8

if ( a2 <= 1 )
{
v3 = 1;
}
else
{
v3 = 1;
do
{
if ( (a2 & 1) != 0 )
v3 = a1 * v3 % a3;
a1 = a1 * a1 % a3;
a2 >>= 1;
}
while ( a2 > 1 );
}
return a1 * v3 % a3;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8

if ( a2 <= 1 )
{
v3 = 1;
}
else
{
v3 = 1;
do
{
if ( (a2 & 1) != 0 )
v3 = a1 * v3 % a3;
a1 = a1 * a1 % a3;
a2 >>= 1;
}
while ( a2 > 1 );
}
return a1 * v3 % a3;
}

original_code:
uint32_t binary_exp_c(uint32_t x, uint32_t a, uint32_t p)
{
 uint32_t r = 1;
 uint32_t y = x;
 while (a>1) {
  if (a & 1)
   r = ((r*y) % p);
  y = ((y*y) % p);
  a >>= 1;
 }
 return ((r*y) % p);
}

canonical_original_code:
unsigned int binary_exp_c(unsigned int x, unsigned int a, unsigned int p)
{
 unsigned int r = 1;
 unsigned int y = x;
 while (a>1) {
  if (a & 1)
   r = ((r*y) % p);
  y = ((y*y) % p);
  a >>= 1;
 }
 return ((r*y) % p);
}

variable_types:
r
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall montgomery_ladder(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned int v4; // eax
signed int v5; // ecx

v3 = a1 * a1 % a3;
_BitScanReverse(&v4, a2);
v5 = 30 - (v4 ^ 0x1F);
if ( v5 >= 0 )
{
do
{
if ( (a2 & (1 << v5)) != 0 )
{
a1 = v3 * a1 % a3;
v3 = v3 * v3 % a3;
}
else
{
v3 = a1 * v3 % a3;
a1 = a1 * a1 % a3;
}
--v5;
}
while ( v5 != -1 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned int v4; // eax
signed int v5; // ecx

v3 = a1 * a1 % a3;
_BitScanReverse(&v4, a2);
v5 = 30 - (v4 ^ 0x1F);
if ( v5 >= 0 )
{
do
{
if ( (a2 & (1 << v5)) != 0 )
{
a1 = v3 * a1 % a3;
v3 = v3 * v3 % a3;
}
else
{
v3 = a1 * v3 % a3;
a1 = a1 * a1 % a3;
}
--v5;
}
while ( v5 != -1 );
}
return a1;
}

canonical_original_code:
unsigned int montgomery_ladder(unsigned int x, unsigned int a, unsigned int p)
{
 unsigned int x1 = x;
 unsigned int x2 = ((x*x) % p);
 int k = 31-__builtin_clz(a);
 for(int i = k-1; i >= 0; --i) {
  if( a & (1 << i)) {
   x1 = ((x1*x2) % p);
   x2 = ((x2*x2) % p);
  } else {
   x2 = ((x1*x2) % p);
   x1 = ((x1*x1) % p);
  }
 }
 return x1;
}

variable_types: k int


repo: hdevalence/wordgen

decompiled_code:
__int64 __fastcall parse_data(__int64 a1, const char *a2, __int64 a3)
{
const char *v3; // rbx
const char *v4; // r13
unsigned __int8 v5; // r12
__int64 v6; // rbp
int v7; // ecx
__int64 result; // rax
bool v9; // dl
unsigned __int64 v10; // rax

v3 = a2;
v4 = &a2[a3];
memset(ngram_buf_0, 0, sizeof(ngram_buf_0));
do
{
v5 = *v3;
v6 = 1LL;
v7 = 0;
if ( *v3 == 9 )
{
LABEL_6:
ngram_buf_0[v7] = 0;
do
++v3;
while ( *v3 != 9 );
v10 = strtoull(v3, 0LL, 10);
result = wtrie_add_entry(a1, ngram_buf_0, v10);
}
else
{
while ( 1 )
{
result = wtrie_valid_char(v5);
if ( !(_BYTE)result )
break;
*(_BYTE *)(v6 + 575) = v5;
v7 = v6;
v5 = *++v3;
v9 = (int)v6++ <= 510;
if ( *v3 == 9 || !v9 )
goto LABEL_6;
}
}
if ( v4 > v3 )
{
while ( *v3 != 10 )
{
if ( v4 == ++v3 )
{
v3 = v4;
break;
}
}
}
++v3;
}
while ( v4 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int64 a3)
{
const char *v3; // rbx
const char *v4; // r13
unsigned __int8 v5; // r12
__int64 v6; // rbp
int v7; // ecx
__int64 result; // rax
bool v9; // dl
unsigned __int64 v10; // rax

v3 = a2;
v4 = &a2[a3];
memset(ngram_buf_0, 0, sizeof(ngram_buf_0));
do
{
v5 = *v3;
v6 = 1LL;
v7 = 0;
if ( *v3 == 9 )
{
LABEL_6:
ngram_buf_0[v7] = 0;
do
++v3;
while ( *v3 != 9 );
v10 = strtoull(v3, 0LL, 10);
result = wtrie_add_entry(a1, ngram_buf_0, v10);
}
else
{
while ( 1 )
{
result = wtrie_valid_char(v5);
if ( !(_BYTE)result )
break;
*(_BYTE *)(v6 + 575) = v5;
v7 = v6;
v5 = *++v3;
v9 = (int)v6++ <= 510;
if ( *v3 == 9 || !v9 )
goto LABEL_6;
}
}
if ( v4 > v3 )
{
while ( *v3 != 10 )
{
if ( v4 == ++v3 )
{
v3 = v4;
break;
}
}
}
++v3;
}
while ( v4 != v3 );
return result;
}

original_code:
void parse_data(wtrie_t *root, const char *data, size_t len) {
    const char *end = data + len;
    static char ngram_buf[511 +1];
    memset(ngram_buf, 0, 511 +1);
    _Bool eof;
    while (!eof) {
        int count = 0;
        while (*data != '\t' && count < 511) {
            if (!wtrie_valid_char(*data))
                goto nextline;
            ngram_buf[count] = *data;
            ++count;
            ++data;
        }
        ngram_buf[count] = 0;
        do
            ++data;
        while (*data != '\t');
        uint64_t freq = strtoull(data,((void *)0),10);
        wtrie_add_entry(root,ngram_buf,freq);
        nextline:
        while (data < end && *data != '\n')
            data++;
        eof = (++data == end);
    }
}

canonical_original_code:
void parse_data(struct wtrie_t *root, char *data, unsigned long len) {
    char *end = data + len;
    static char ngram_buf[-1];
    memset(ngram_buf, 0, 511 +1);
    _Bool eof;
    while (!eof) {
        int count = 0;
        while (*data != '\t' && count < 511) {
            if (!wtrie_valid_char(*data))
                goto nextline;
            ngram_buf[count] = *data;
            ++count;
            ++data;
        }
        ngram_buf[count] = 0;
        do
            ++data;
        while (*data != '\t');
        unsigned long freq = strtoull(data,((void *)0),10);
        wtrie_add_entry(root,ngram_buf,freq);
        nextline:
        while (data < end && *data != '\n')
            data++;
        eof = (++data == end);
    }
}

variable_types: struct wtrie_t { union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } child_arr; unsigned long self_freq; unsigned long children_freq; } *

variable_types:
data
char *

variable_types:
len
unsigned long

variable_types:
end
char *

variable_types: count int

variable_types:
freq
unsigned long

user_defined_types: struct wtrie_t { union tagptr_t child_arr; unsigned long self_freq; unsigned long children_freq; }


decompiled_code:
int __fastcall add_to_trie(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // ebx
char *v4; // rax
char *v5; // rbx
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(a2, 0);
if ( v2 < 0 )
{
fprintf(stderr, "Cannot open file %s", a2);
exit(1);
}
v3 = v2;
if ( fstat(v2, &v7) < 0 )
{
fprintf(stderr, "Cannot stat file %s", a2);
exit(1);
}
v4 = (char *)mmap(0LL, v7.st_size, 1, 2, v3, 0LL);
v5 = v4;
if ( v4 == (char *)-1LL )
{
fprintf(stderr, "Cannot mmap file %s", a2);
exit(1);
}
madvise(v4, v7.st_size, 2);
parse_data(a1, v5, v7.st_size);
return munmap(v5, v7.st_size);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // ebx
char *v4; // rax
char *v5; // rbx
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(a2, 0);
if ( v2 < 0 )
{
fprintf(stderr, "Cannot open file %s", a2);
exit(1);
}
v3 = v2;
if ( fstat(v2, &v7) < 0 )
{
fprintf(stderr, "Cannot stat file %s", a2);
exit(1);
}
v4 = (char *)mmap(0LL, v7.st_size, 1, 2, v3, 0LL);
v5 = v4;
if ( v4 == (char *)-1LL )
{
fprintf(stderr, "Cannot mmap file %s", a2);
exit(1);
}
madvise(v4, v7.st_size, 2);
func0(a1, v5, v7.st_size);
return munmap(v5, v7.st_size);
}

original_code:
void add_to_trie(wtrie_t *root, char *filepath) {
    int fd = open(filepath, 00);
    if (fd < 0) {
        fprintf(stderr, "Cannot open file %s", filepath);
        exit(1);
    }
    struct stat statbuf;
    if (fstat(fd, &statbuf) < 0) {
        fprintf(stderr, "Cannot stat file %s", filepath);
        exit(1);
    }
    char *data = mmap(((void *)0), statbuf.st_size, 0x1, 0x02, fd, 0);
    if (data == ((void *) -1)) {
        fprintf(stderr, "Cannot mmap file %s", filepath);
        exit(1);
    }
    madvise(data, statbuf.st_size, 2);
    parse_data(root, data, statbuf.st_size);
    munmap(data, statbuf.st_size);
}

canonical_original_code:
void add_to_trie(struct wtrie_t *root, char *filepath) {
    int fd = open(filepath, 00);
    if (fd < 0) {
        fprintf(stderr, "Cannot open file %s", filepath);
        exit(1);
    }
    struct stat statbuf;
    if (fstat(fd, &statbuf) < 0) {
        fprintf(stderr, "Cannot stat file %s", filepath);
        exit(1);
    }
    char *data = mmap(((void *)0), statbuf.st_size, 0x1, 0x02, fd, 0);
    if (data == ((void *) -1)) {
        fprintf(stderr, "Cannot mmap file %s", filepath);
        exit(1);
    }
    madvise(data, statbuf.st_size, 2);
    parse_data(root, data, statbuf.st_size);
    munmap(data, statbuf.st_size);
}

variable_types:
filepath
char *

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


decompiled_code:
__int64 __fastcall build_trie(const char *a1)
{
__int64 v1; // rbx

v1 = wtrie_alloc();
add_to_trie(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v1; // rbx

v1 = wtrie_alloc();
func1(v1, a1);
return v1;
}

original_code:
wtrie_t* build_trie(char *filepath) {
    wtrie_t* root = wtrie_alloc();
    add_to_trie(root,filepath);
    return root;
}

canonical_original_code:
struct wtrie_t *build_trie(char *filepath) {
    struct wtrie_t *root = wtrie_alloc();
    add_to_trie(root,filepath);
    return root;
}

return_type: struct wtrie_t { union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } child_arr; unsigned long self_freq; unsigned long children_freq; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rsi
__int64 v4; // rdx
void *v5; // rsi
__int64 v6; // rdx
void *v7; // rsi
__int64 v8; // rdx
void *v9; // rsi
__int64 v10; // rdx
void *v11; // rsi
__int64 v12; // rdx
__int64 v13; // rbx
__int64 v14; // rdx
__int64 v15; // rdx
void *v17; // [rsp+0h] [rbp-18h] BYREF
__int64 v18[2]; // [rsp+8h] [rbp-10h] BYREF

v18[0] = 0LL;
tagarray_pprint(0LL, argv, envp);
v17 = malloc(0x10uLL);
set_tag(&v17, 101LL);
v3 = v17;
tagarray_insert(v18, v17);
tagarray_pprint(v18[0], v3, v4);
v17 = malloc(0x10uLL);
set_tag(&v17, 98LL);
v5 = v17;
tagarray_insert(v18, v17);
tagarray_pprint(v18[0], v5, v6);
v17 = malloc(0x10uLL);
set_tag(&v17, 99LL);
v7 = v17;
tagarray_insert(v18, v17);
tagarray_pprint(v18[0], v7, v8);
v17 = malloc(0x10uLL);
set_tag(&v17, 97LL);
v9 = v17;
tagarray_insert(v18, v17);
tagarray_pprint(v18[0], v9, v10);
v17 = malloc(0x10uLL);
set_tag(&v17, 100LL);
v11 = v17;
tagarray_insert(v18, v17);
tagarray_pprint(v18[0], v11, v12);
tagarray_sort(v18[0]);
v13 = tagarray_search(v18[0], 100LL);
tagarray_pprint(v18[0], 100LL, v14);
tagarray_pprint(v13, 100LL, v15);
return 0;
}

original_code:
int main() {
    tagptr_t arr;
    arr.ptr = ((void *)0);
    tagarray_pprint(arr);
    tagptr_t tmp;
    tmp.ptr = malloc(16);
    set_tag(&tmp,'e');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'b');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'c');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'a');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'d');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tagarray_sort(arr);
    tagptr_t val = tagarray_search(arr, 'd');
    tagarray_pprint(arr);
    tagarray_pprint(val);
    return 0;
}

canonical_original_code:
int main() {
    union tagptr_t arr;
    arr.ptr = ((void *)0);
    tagarray_pprint(arr);
    union tagptr_t tmp;
    tmp.ptr = malloc(16);
    set_tag(&tmp,'e');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'b');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'c');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'a');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tmp.ptr = malloc(16);
    set_tag(&tmp,'d');
    tagarray_insert(&arr,tmp);
    tagarray_pprint(arr);
    tagarray_sort(arr);
    union tagptr_t val = tagarray_search(arr, 'd');
    tagarray_pprint(arr);
    tagarray_pprint(val);
    return 0;
}

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


decompiled_code:
__int64 __fastcall tagarray_at(__int64 a1, int a2)
{
return *(_QWORD *)(mask_ptr() + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return *(_QWORD *)(mask_ptr() + 8LL * a2);
}

original_code:
inline tagptr_t tagarray_at(tagptr_t arr, int i) {
    return ((tagptr_t*)mask_ptr(arr))[i];
}

canonical_original_code:
inline union tagptr_t tagarray_at(union tagptr_t arr, int i) {
    return ((union tagptr_t *)mask_ptr(arr))[i];
}

variable_types:
arr
union tagptr_t

return_type: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


decompiled_code:
__int64 __fastcall tagarray_set(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = mask_ptr();
*(_QWORD *)(result + 8LL * a2) = a3;
return result;
}

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

result = mask_ptr();
*(_QWORD *)(result + 8LL * a2) = a3;
return result;
}

original_code:
inline void tagarray_set(tagptr_t arr, int i, tagptr_t obj) {
    ((tagptr_t*)mask_ptr(arr))[i] = obj;
}

canonical_original_code:
inline void tagarray_set(union tagptr_t arr, int i, union tagptr_t obj) {
    ((union tagptr_t *)mask_ptr(arr))[i] = obj;
}

variable_types:
obj
union tagptr_t


decompiled_code:
unsigned __int64 __fastcall tagarray_size(unsigned __int64 a1)
{
return HIBYTE(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return HIBYTE(a1);
}

original_code:
inline uint8_t tagarray_size(tagptr_t arr) {
    return arr.bytes[7];
}

canonical_original_code:
inline unsigned char tagarray_size(union tagptr_t arr) {
    return arr.bytes[7];
}

return_type: unsigned char


decompiled_code:
unsigned __int64 __fastcall tagarray_reserved(unsigned __int64 a1)
{
return HIWORD(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 a1)
{
return HIWORD(a1);
}

original_code:
inline uint8_t tagarray_reserved(tagptr_t arr) {
    return arr.bytes[6];
}

canonical_original_code:
inline unsigned char tagarray_reserved(union tagptr_t arr) {
    return arr.bytes[6];
}


decompiled_code:
unsigned __int64 __fastcall tagarray_free(unsigned __int64 a1)
{
unsigned __int64 result; // rax
unsigned __int8 v2; // bl
__int64 v3; // rbp
__int64 v4; // rax

result = tagarray_reserved(a1);
if ( (_BYTE)result )
{
v2 = result;
v3 = mask_ptr(a1);
v4 = mempool(8LL * v2);
result = mempool_free(v4, v3);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 a1)
{
unsigned __int64 result; // rax
unsigned __int8 v2; // bl
__int64 v3; // rbp
__int64 v4; // rax

result = func3(a1);
if ( (_BYTE)result )
{
v2 = result;
v3 = mask_ptr(a1);
v4 = mempool(8LL * v2);
result = mempool_free(v4, v3);
}
return result;
}

original_code:
void tagarray_free(tagptr_t arr)
{
    uint8_t reserved = tagarray_reserved(arr);
    if (reserved) {
        tagptr_t *raw_arr = (tagptr_t*)mask_ptr(arr);
        mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
    }
}

canonical_original_code:
void tagarray_free(union tagptr_t arr)
{
    unsigned char reserved = tagarray_reserved(arr);
    if (reserved) {
        union tagptr_t *raw_arr = (tagptr_t*)mask_ptr(arr);
        mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
    }
}

variable_types:
reserved
unsigned char

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } *


decompiled_code:
__int64 __fastcall tagarray_push_back(__int64 a1, __int64 a2)
{
char v2; // bp
unsigned __int8 v3; // r12
char *v4; // r14
int v5; // er15
__int64 v6; // rax
_QWORD *v7; // r13
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rax

v2 = *(_BYTE *)(a1 + 7);
v3 = *(_BYTE *)(a1 + 6);
if ( v2 == v3 )
{
v4 = (char *)mask_ptr(*(_QWORD *)a1);
v5 = 2 * v3;
if ( v3 <= 0x40u )
{
if ( !v5 )
v5 = 1;
}
else
{
if ( v2 < 0 )
_assert_fail("size < TAGARRAY_MAXLEN", "tagarray.c", 0x23u, "tagarray_push_back");
v5 = 128;
}
v6 = mempool(8LL * v5);
v7 = (_QWORD *)mempool_alloc(v6);
v8 = 8LL * v3;
if ( (unsigned int)v8 >= 8 )
{
*v7 = *(_QWORD *)v4;
v7[(unsigned __int64)v8 / 8 - 1] = *(_QWORD *)&v4[v8 - 8];
qmemcpy(
(void *)((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4 - ((char *)v7 - ((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v8 + (_DWORD)v7 - (((_DWORD)v7 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (_DWORD)v8 )
{
*(_BYTE *)v7 = *v4;
}
if ( v3 )
{
v10 = mempool(8LL * v3);
mempool_free(v10, v4);
}
*(_QWORD *)a1 = v7;
*(_BYTE *)(a1 + 7) = v2;
*(_BYTE *)(a1 + 6) = v5;
}
result = tagarray_set(*(_QWORD *)a1, (unsigned __int8)v2, a2);
*(_BYTE *)(a1 + 7) = v2 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
char v2; // bp
unsigned __int8 v3; // r12
char *v4; // r14
int v5; // er15
__int64 v6; // rax
_QWORD *v7; // r13
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rax

v2 = *(_BYTE *)(a1 + 7);
v3 = *(_BYTE *)(a1 + 6);
if ( v2 == v3 )
{
v4 = (char *)mask_ptr(*(_QWORD *)a1);
v5 = 2 * v3;
if ( v3 <= 0x40u )
{
if ( !v5 )
v5 = 1;
}
else
{
if ( v2 < 0 )
_assert_fail("size < TAGARRAY_MAXLEN", "tagarray.c", 0x23u, "tagarray_push_back");
v5 = 128;
}
v6 = mempool(8LL * v5);
v7 = (_QWORD *)mempool_alloc(v6);
v8 = 8LL * v3;
if ( (unsigned int)v8 >= 8 )
{
*v7 = *(_QWORD *)v4;
v7[(unsigned __int64)v8 / 8 - 1] = *(_QWORD *)&v4[v8 - 8];
qmemcpy(
(void *)((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4 - ((char *)v7 - ((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v8 + (_DWORD)v7 - (((_DWORD)v7 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (_DWORD)v8 )
{
*(_BYTE *)v7 = *v4;
}
if ( v3 )
{
v10 = mempool(8LL * v3);
mempool_free(v10, v4);
}
*(_QWORD *)a1 = v7;
*(_BYTE *)(a1 + 7) = v2;
*(_BYTE *)(a1 + 6) = v5;
}
result = func1(*(_QWORD *)a1, (unsigned __int8)v2, a2);
*(_BYTE *)(a1 + 7) = v2 + 1;
return result;
}

original_code:
void tagarray_push_back(tagptr_t* arr, tagptr_t p) {
    uint8_t size = arr->bytes[7];
    uint8_t reserved = arr->bytes[6];
    if (size == reserved) {
        tagptr_t* raw_arr = (tagptr_t*)mask_ptr(*arr);
        int new_res = 2*reserved;
        if (new_res > 128) {
            new_res = 128;
            ((size < 128) ? (void) (0) : __assert_fail ("size < TAGARRAY_MAXLEN", "tagarray.c", 35, __extension__ __PRETTY_FUNCTION__));
        }
        if (new_res == 0)
            new_res = 1;
        tagptr_t* new_arr = mempool_alloc(mempool(sizeof(tagptr_t)*new_res));
        memcpy(new_arr, raw_arr, sizeof(tagptr_t)*reserved);
        if (reserved)
            mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
        arr->ptr = new_arr;
        arr->bytes[7] = size;
        arr->bytes[6] = new_res;
    }
    tagarray_set(*arr,size,p);
    ++size;
    arr->bytes[7] = size;
}

canonical_original_code:
void tagarray_push_back(union tagptr_t *arr, union tagptr_t p) {
    unsigned char size = arr->bytes[7];
    unsigned char reserved = arr->bytes[6];
    if (size == reserved) {
        union tagptr_t *raw_arr = (tagptr_t*)mask_ptr(*arr);
        int new_res = 2*reserved;
        if (new_res > 128) {
            new_res = 128;
            ((size < 128) ? (void) (0) : __assert_fail ("size < TAGARRAY_MAXLEN", "tagarray.c", 35, __extension__ __PRETTY_FUNCTION__));
        }
        if (new_res == 0)
            new_res = 1;
        union tagptr_t *new_arr = mempool_alloc(mempool(sizeof(tagptr_t)*new_res));
        memcpy(new_arr, raw_arr, sizeof(tagptr_t)*reserved);
        if (reserved)
            mempool_free(mempool(sizeof(tagptr_t)*reserved), raw_arr);
        arr->ptr = new_arr;
        arr->bytes[7] = size;
        arr->bytes[6] = new_res;
    }
    tagarray_set(*arr,size,p);
    ++size;
    arr->bytes[7] = size;
}

variable_types:
p
union tagptr_t

variable_types:
size
unsigned char


decompiled_code:
unsigned __int64 __fastcall tagarray_insert(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 result; // rax
int v3; // ebx
int v4; // er14
__int64 v5; // rbp
unsigned __int16 v6; // r12

tagarray_push_back((__int64)a1, a2);
result = tagarray_size(*a1);
if ( (unsigned __int8)result > 1u )
{
v3 = (unsigned __int8)result - 1;
while ( 1 )
{
v4 = v3--;
v5 = tagarray_at(*a1, v3);
v6 = get_tag(v5);
if ( v6 <= (unsigned __int16)get_tag(a2) )
break;
tagarray_set(*a1, v4, v5);
if ( !v3 )
goto LABEL_7;
}
v3 = v4;
LABEL_7:
result = tagarray_set(*a1, v3, a2);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 result; // rax
int v3; // ebx
int v4; // er14
__int64 v5; // rbp
unsigned __int16 v6; // r12

func5((__int64)a1, a2);
result = func2(*a1);
if ( (unsigned __int8)result > 1u )
{
v3 = (unsigned __int8)result - 1;
while ( 1 )
{
v4 = v3--;
v5 = func0(*a1, v3);
v6 = get_tag(v5);
if ( v6 <= (unsigned __int16)get_tag(a2) )
break;
func1(*a1, v4, v5);
if ( !v3 )
goto LABEL_7;
}
v3 = v4;
LABEL_7:
result = func1(*a1, v3, a2);
}
return result;
}

original_code:
void tagarray_insert(tagptr_t* arr, tagptr_t p) {
    tagarray_push_back(arr,p);
    if (tagarray_size(*arr) <= 1)
        return;
    int i = tagarray_size(*arr) - 1;
    while (i > 0) {
        tagptr_t q = tagarray_at(*arr,i-1);
        if( get_tag(q) > get_tag(p) ) {
            tagarray_set(*arr,i,q);
            --i;
        } else break;
    }
    tagarray_set(*arr,i,p);
}

canonical_original_code:
void tagarray_insert(union tagptr_t *arr, union tagptr_t p) {
    tagarray_push_back(arr,p);
    if (tagarray_size(*arr) <= 1)
        return;
    int i = tagarray_size(*arr) - 1;
    while (i > 0) {
        union tagptr_t q = tagarray_at(*arr,i-1);
        if( get_tag(q) > get_tag(p) ) {
            tagarray_set(*arr,i,q);
            --i;
        } else break;
    }
    tagarray_set(*arr,i,p);
}

variable_types: i int


decompiled_code:
__int64 __fastcall tagarray_swap(__int64 a1, int a2, int a3)
{
__int64 v4; // r13
__int64 v5; // rax

v4 = tagarray_at(a1, a2);
v5 = tagarray_at(a1, a3);
tagarray_set(a1, a2, v5);
return tagarray_set(a1, a3, v4);
}

original_code:
void tagarray_swap(tagptr_t arr, int i, int j) {
    tagptr_t tmp = tagarray_at(arr, i);
    tagarray_set(arr, i, tagarray_at(arr, j));
    tagarray_set(arr, j, tmp);
}

canonical_original_code:
void tagarray_swap(union tagptr_t arr, int i, int j) {
    union tagptr_t tmp = tagarray_at(arr, i);
    tagarray_set(arr, i, tagarray_at(arr, j));
    tagarray_set(arr, j, tmp);
}

variable_types: j int


decompiled_code:
__int64 __fastcall tagarray_partition(__int64 a1, int a2, int a3, int a4)
{
unsigned int v4; // er12
__int64 v7; // rax
unsigned __int16 v8; // r14
int v9; // ebx
__int64 v10; // rax

v4 = a2;
v7 = tagarray_at(a1, a4);
v8 = get_tag(v7);
tagarray_swap(a1, a4, a3);
if ( a3 >= a2 )
{
v9 = a2;
do
{
v10 = tagarray_at(a1, v9);
if ( (unsigned __int16)get_tag(v10) < v8 )
tagarray_swap(a1, v9, v4++);
++v9;
}
while ( a3 >= v9 );
}
tagarray_swap(a1, v4, a3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3, int a4)
{
unsigned int v4; // er12
__int64 v7; // rax
unsigned __int16 v8; // r14
int v9; // ebx
__int64 v10; // rax

v4 = a2;
v7 = func0(a1, a4);
v8 = get_tag(v7);
func7(a1, a4, a3);
if ( a3 >= a2 )
{
v9 = a2;
do
{
v10 = func0(a1, v9);
if ( (unsigned __int16)get_tag(v10) < v8 )
func7(a1, v9, v4++);
++v9;
}
while ( a3 >= v9 );
}
func7(a1, v4, a3);
return v4;
}

original_code:
int tagarray_partition(tagptr_t arr, int l, int r, int p) {
    uint16_t pivot_tag = get_tag(tagarray_at(arr, p));
    tagarray_swap(arr, p, r);
    int store_idx = l;
    for (int i = l; i <= r; ++i) {
        if (pivot_tag > get_tag(tagarray_at(arr, i))) {
            tagarray_swap(arr,i,store_idx);
            store_idx++;
        }
    }
    tagarray_swap(arr,store_idx,r);
    return store_idx;
}

canonical_original_code:
int tagarray_partition(union tagptr_t arr, int l, int r, int p) {
    unsigned short pivot_tag = get_tag(tagarray_at(arr, p));
    tagarray_swap(arr, p, r);
    int store_idx = l;
    for (int i = l; i <= r; ++i) {
        if (pivot_tag > get_tag(tagarray_at(arr, i))) {
            tagarray_swap(arr,i,store_idx);
            store_idx++;
        }
    }
    tagarray_swap(arr,store_idx,r);
    return store_idx;
}

variable_types: l int

variable_types: r int

variable_types: p int


decompiled_code:
void __fastcall tagarray_qsort(__int64 a1, int a2, int a3)
{
int v4; // ebp

if ( a2 < a3 )
{
v4 = tagarray_partition(a1, a2, a3, (a2 + a3) / 2);
tagarray_qsort(a1, (unsigned int)a2, (unsigned int)(v4 - 1));
tagarray_qsort(a1, (unsigned int)(v4 + 1), (unsigned int)a3);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // ebp

if ( a2 < a3 )
{
v4 = func8(a1, a2, a3, (a2 + a3) / 2);
func9(a1, (unsigned int)a2, (unsigned int)(v4 - 1));
func9(a1, (unsigned int)(v4 + 1), (unsigned int)a3);
}
}

original_code:
void tagarray_qsort(tagptr_t arr, int l, int r) {
    if (l < r) {
        int p = (l+r)/2;
        int newp = tagarray_partition(arr,l,r,p);
        tagarray_qsort(arr,l,newp-1);
        tagarray_qsort(arr,newp+1,r);
    }
}

canonical_original_code:
void tagarray_qsort(union tagptr_t arr, int l, int r) {
    if (l < r) {
        int p = (l+r)/2;
        int newp = tagarray_partition(arr,l,r,p);
        tagarray_qsort(arr,l,newp-1);
        tagarray_qsort(arr,newp+1,r);
    }
}

variable_types: newp int


decompiled_code:
void __fastcall tagarray_sort(unsigned __int64 a1)
{
tagarray_qsort(a1, 0, HIBYTE(a1) - 1);
}

canonical_decompiled_code:
void __fastcall func10(unsigned __int64 a1)
{
func9(a1, 0, HIBYTE(a1) - 1);
}

original_code:
void tagarray_sort(tagptr_t arr) {
    int size = arr.bytes[7];
    tagarray_qsort(arr,0,size-1);
}

canonical_original_code:
void tagarray_sort(union tagptr_t arr) {
    int size = arr.bytes[7];
    tagarray_qsort(arr,0,size-1);
}

variable_types: size int


decompiled_code:
__int64 __fastcall tagarray_search(unsigned __int64 a1, unsigned __int16 a2)
{
unsigned __int8 v2; // al
int v3; // ebp
int v4; // er12
int v5; // ebx
__int64 v6; // rax
unsigned __int16 v7; // ax

v2 = tagarray_size(a1);
v3 = v2;
if ( v2 )
{
v4 = 0;
do
{
v5 = (v4 + v3) / 2;
v6 = tagarray_at(a1, v5);
v7 = get_tag(v6);
if ( v7 >= a2 )
{
if ( v7 <= a2 )
return tagarray_at(a1, v5);
v3 = (v4 + v3) / 2;
}
else
{
v4 = v5 + 1;
}
}
while ( v4 < v3 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int64 a1, unsigned __int16 a2)
{
unsigned __int8 v2; // al
int v3; // ebp
int v4; // er12
int v5; // ebx
__int64 v6; // rax
unsigned __int16 v7; // ax

v2 = func2(a1);
v3 = v2;
if ( v2 )
{
v4 = 0;
do
{
v5 = (v4 + v3) / 2;
v6 = func0(a1, v5);
v7 = get_tag(v6);
if ( v7 >= a2 )
{
if ( v7 <= a2 )
return func0(a1, v5);
v3 = (v4 + v3) / 2;
}
else
{
v4 = v5 + 1;
}
}
while ( v4 < v3 );
}
return 0LL;
}

original_code:
tagptr_t tagarray_search(tagptr_t arr, uint16_t search_tag) {
    int l = 0;
    int r = tagarray_size(arr);
    while (l < r) {
        int mid = (l+r)/2;
        uint16_t mid_tag = get_tag(tagarray_at(arr,mid));
        if (mid_tag < search_tag) {
            l = mid + 1;
        } else if (mid_tag > search_tag) {
            r = mid;
        } else {
            return tagarray_at(arr,mid);
        }
    }
    tagptr_t not_found = { .ptr = ((void *)0) };
    return not_found;
}

canonical_original_code:
union tagptr_t tagarray_search(union tagptr_t arr, unsigned short search_tag) {
    int l = 0;
    int r = tagarray_size(arr);
    while (l < r) {
        int mid = (l+r)/2;
        unsigned short mid_tag = get_tag(tagarray_at(arr,mid));
        if (mid_tag < search_tag) {
            l = mid + 1;
        } else if (mid_tag > search_tag) {
            r = mid;
        } else {
            return tagarray_at(arr,mid);
        }
    }
    union tagptr_t not_found = { .ptr = ((void *)0) };
    return not_found;
}

variable_types: mid int


decompiled_code:
int __fastcall tagarray_pprint(unsigned __int64 a1)
{
int result; // eax
unsigned int v2; // ebp
__int64 v3; // rbx
unsigned __int16 v4; // ax
__int64 v5; // rax

printf("PPRINT 0x%016llX\n", a1);
printf(" SIZE %d\n", HIBYTE(a1));
result = printf(" RSVD %d\n", BYTE6(a1));
if ( (int)HIBYTE(a1) > 0 )
{
v2 = 0;
do
{
v3 = tagarray_at(a1, v2);
printf("\t%d\t0x%016llX\n", v2, v3);
v4 = get_tag(v3);
printf("\t\tTAG\t%d : %c\n", v4, (unsigned int)(char)v4);
v5 = mask_ptr(v3);
result = printf("\t\tVAL\t0x%016llX\n", v5);
++v2;
}
while ( HIBYTE(a1) != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int64 a1)
{
int result; // eax
unsigned int v2; // ebp
__int64 v3; // rbx
unsigned __int16 v4; // ax
__int64 v5; // rax

printf("PPRINT 0x%016llX\n", a1);
printf(" SIZE %d\n", HIBYTE(a1));
result = printf(" RSVD %d\n", BYTE6(a1));
if ( (int)HIBYTE(a1) > 0 )
{
v2 = 0;
do
{
v3 = func0(a1, v2);
printf("\t%d\t0x%016llX\n", v2, v3);
v4 = get_tag(v3);
printf("\t\tTAG\t%d : %c\n", v4, (unsigned int)(char)v4);
v5 = mask_ptr(v3);
result = printf("\t\tVAL\t0x%016llX\n", v5);
++v2;
}
while ( HIBYTE(a1) != v2 );
}
return result;
}

original_code:
void tagarray_pprint(tagptr_t arr) {
    int size = arr.bytes[7];
    int reserved = arr.bytes[6];
    printf("PPRINT 0x%016llX\n", (unsigned long long) arr.ptr);
    printf("  SIZE %d\n", size);
    printf("  RSVD %d\n", reserved);
    for(int i = 0; i < size; ++i) {
        tagptr_t p = tagarray_at(arr,i);
        printf("\t%d\t0x%016llX\n", i, (unsigned long long) p.ptr);
        printf("\t\tTAG\t%d : %c\n", get_tag(p), (char)get_tag(p));
        printf("\t\tVAL\t0x%016llX\n", (unsigned long long) mask_ptr(p));
    }
}

canonical_original_code:
void tagarray_pprint(union tagptr_t arr) {
    int size = arr.bytes[7];
    int reserved = arr.bytes[6];
    printf("PPRINT 0x%016llX\n", (unsigned long long) arr.ptr);
    printf("  SIZE %d\n", size);
    printf("  RSVD %d\n", reserved);
    for(int i = 0; i < size; ++i) {
        union tagptr_t p = tagarray_at(arr,i);
        printf("\t%d\t0x%016llX\n", i, (unsigned long long) p.ptr);
        printf("\t\tTAG\t%d : %c\n", get_tag(p), (char)get_tag(p));
        printf("\t\tVAL\t0x%016llX\n", (unsigned long long) mask_ptr(p));
    }
}

variable_types: reserved int


decompiled_code:
void __fastcall free_mempool(void **a1)
{
if ( *a1 )
free_mempool();
free(a1[1]);
free(a1[4]);
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
if ( *a1 )
func1();
free(a1[1]);
free(a1[4]);
free(a1);
}

original_code:
void free_mempool(mempool_t *pool)
{
    if (pool->next) {
        free_mempool(pool->next);
    }
    free(pool->mem_start);
    free(pool->free_spots);
    free(pool);
}

canonical_original_code:
void free_mempool(struct mempool_t *pool)
{
    if (pool->next) {
        free_mempool(pool->next);
    }
    free(pool->mem_start);
    free(pool->free_spots);
    free(pool);
}

variable_types: struct mempool_t { struct mempool_t *next; char *mem_start; char *mem_end; char *alloc_ptr; char **free_spots; unsigned long alloc_size; unsigned long pool_size; unsigned long free_spots_size; unsigned long free_spots_res; } *


decompiled_code:
void mempool_free_globals()
{
void ***v0; // rbx

v0 = (void ***)global_pools;
do
{
if ( *v0 )
{
free_mempool(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != (void ***)"mempool_create" );
}

canonical_decompiled_code:
void func2()
{
void ***v0; // rbx

v0 = (void ***)global_pools;
do
{
if ( *v0 )
{
func1(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != (void ***)"mempool_create" );
}

original_code:
void mempool_free_globals()
{
    for (int i = 0; i < 129; ++i) {
        if (!global_pools[i])
            continue;
        free_mempool(global_pools[i]);
        global_pools[i] = ((void *)0);
    }
}


decompiled_code:
__int64 __fastcall mempool_alloc(_QWORD *a1)
{
__int64 v1; // rdx
__int64 result; // rax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rcx

v1 = a1[7];
if ( v1 )
{
result = *(_QWORD *)(a1[4] + 8 * v1 - 8);
a1[7] = v1 - 1;
}
else
{
result = a1[3];
v3 = a1[2];
if ( result == v3 )
{
if ( !*a1 )
*a1 = create_mempool(a1[5], a1[6]);
result = mempool_alloc(*a1);
}
else
{
v4 = a1[5] + result;
if ( v3 < v4 )
_assert_fail("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 0x4Eu, "mempool_alloc");
a1[3] = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rdx
__int64 result; // rax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rcx

v1 = a1[7];
if ( v1 )
{
result = *(_QWORD *)(a1[4] + 8 * v1 - 8);
a1[7] = v1 - 1;
}
else
{
result = a1[3];
v3 = a1[2];
if ( result == v3 )
{
if ( !*a1 )
*a1 = create_mempool(a1[5], a1[6]);
result = func3(*a1);
}
else
{
v4 = a1[5] + result;
if ( v3 < v4 )
_assert_fail("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 0x4Eu, "mempool_alloc");
a1[3] = v4;
}
}
return result;
}

original_code:
void *mempool_alloc(mempool_t *pool)
{
    if (pool->free_spots_size > 0) {
        void *alloc = pool->free_spots[pool->free_spots_size -1];
        pool->free_spots_size--;
        return alloc;
    } else if (pool->alloc_ptr != pool->mem_end) {
        ((pool->alloc_ptr + pool->alloc_size <= pool->mem_end) ? (void) (0) : __assert_fail ("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 78, __extension__ __PRETTY_FUNCTION__));
        void *alloc = pool->alloc_ptr;
        pool->alloc_ptr += pool->alloc_size;
        return alloc;
    } else if (!pool->next) {
        pool->next = create_mempool(pool->alloc_size, pool->pool_size);
    }
    return mempool_alloc(pool->next);
}

canonical_original_code:
void *mempool_alloc(struct mempool_t *pool)
{
    if (pool->free_spots_size > 0) {
        void *alloc = pool->free_spots[pool->free_spots_size -1];
        pool->free_spots_size--;
        return alloc;
    } else if (pool->alloc_ptr != pool->mem_end) {
        ((pool->alloc_ptr + pool->alloc_size <= pool->mem_end) ? (void) (0) : __assert_fail ("pool->alloc_ptr + pool->alloc_size <= pool->mem_end", "mempool.c", 78, __extension__ __PRETTY_FUNCTION__));
        void *alloc = pool->alloc_ptr;
        pool->alloc_ptr += pool->alloc_size;
        return alloc;
    } else if (!pool->next) {
        pool->next = create_mempool(pool->alloc_size, pool->pool_size);
    }
    return mempool_alloc(pool->next);
}

variable_types:
alloc
void *

return_type: void *

user_defined_types: struct mempool_t { struct mempool_t *next; char *mem_start; char *mem_end; char *alloc_ptr; char **free_spots; unsigned long alloc_size; unsigned long pool_size; unsigned long free_spots_size; unsigned long free_spots_res; }


decompiled_code:
__int64 __fastcall mempool_free(__int64 *a1, unsigned __int64 a2)
{
__int64 v4; // rsi
__int64 result; // rax
void *v6; // rax
__int64 v7; // rdi

if ( a1[1] <= a2 && a1[2] >= a2 )
{
v4 = a1[8];
if ( a1[7] != v4 )
{
LABEL_4:
result = a1[4];
*(_QWORD *)(result + 8 * a1[7]++) = a2;
return result;
}
v6 = realloc((void *)a1[4], 16 * v4);
if ( v6 )
{
a1[4] = (__int64)v6;
a1[8] *= 2LL;
goto LABEL_4;
}
err_oom("mempool_free");
}
v7 = *a1;
if ( !*a1 )
{
fwrite("tried to mempool_free a pointer not in the memory pool!\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
return mempool_free(v7, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, unsigned __int64 a2)
{
__int64 v4; // rsi
__int64 result; // rax
void *v6; // rax
__int64 v7; // rdi

if ( a1[1] <= a2 && a1[2] >= a2 )
{
v4 = a1[8];
if ( a1[7] != v4 )
{
LABEL_4:
result = a1[4];
*(_QWORD *)(result + 8 * a1[7]++) = a2;
return result;
}
v6 = realloc((void *)a1[4], 16 * v4);
if ( v6 )
{
a1[4] = (__int64)v6;
a1[8] *= 2LL;
goto LABEL_4;
}
err_oom("mempool_free");
}
v7 = *a1;
if ( !*a1 )
{
fwrite("tried to mempool_free a pointer not in the memory pool!\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
return func4(v7, a2);
}

original_code:
void mempool_free(mempool_t *pool, void *ptr) {
    if (pool->mem_start <= (char*)ptr && (char*)ptr <= pool->mem_end) {
        if (pool->free_spots_size == pool->free_spots_res) {
            size_t new_size = 2*sizeof(char*)*pool->free_spots_res;
            char **new_arr = realloc(pool->free_spots, new_size);
            if (!new_arr)
                err_oom("mempool_free");
            pool->free_spots = new_arr;
            pool->free_spots_res *= 2;
        }
        pool->free_spots[pool->free_spots_size] = ptr;
        pool->free_spots_size++;
        return;
    } else if (pool->next) {
        mempool_free(pool->next, ptr);
        return;
    } else {
        fprintf(stderr, "tried to mempool_free a pointer not in the memory pool!\n");
        exit(1);
    }
}

canonical_original_code:
void mempool_free(struct mempool_t *pool, void *ptr) {
    if (pool->mem_start <= (char *)ptr && (char *)ptr <= pool->mem_end) {
        if (pool->free_spots_size == pool->free_spots_res) {
            unsigned long new_size = 2*sizeof(char*)*pool->free_spots_res;
            char **new_arr = realloc(pool->free_spots, new_size);
            if (!new_arr)
                err_oom("mempool_free");
            pool->free_spots = new_arr;
            pool->free_spots_res *= 2;
        }
        pool->free_spots[pool->free_spots_size] = ptr;
        pool->free_spots_size++;
        return;
    } else if (pool->next) {
        mempool_free(pool->next, ptr);
        return;
    } else {
        fprintf(stderr, "tried to mempool_free a pointer not in the memory pool!\n");
        exit(1);
    }
}

variable_types:
ptr
void *


decompiled_code:
void __fastcall __noreturn err_oom(const char *a1)
{
fprintf(stderr, "Out of memory: malloc failed in\t%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Out of memory: malloc failed in\t%s\n", a1);
exit(1);
}

original_code:
inline void err_oom(char *msg)
{
    fprintf(stderr,"Out of memory: malloc failed in\t%s\n", msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall in_string(char a1, _BYTE *a2)
{
__int64 result; // rax

if ( !a2 )
return 1LL;
LOBYTE(result) = *a2;
if ( !*a2 )
return 0LL;
while ( a1 != (_BYTE)result )
{
result = (unsigned __int8)*++a2;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

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

if ( !a2 )
return 1LL;
LOBYTE(result) = *a2;
if ( !*a2 )
return 0LL;
while ( a1 != (_BYTE)result )
{
result = (unsigned __int8)*++a2;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

original_code:
inline _Bool in_string(char c, char *allowed_chars) {
    if (!allowed_chars) {
        return 1;
    } else {
        while (*allowed_chars != 0) {
            if (*allowed_chars == c)
                return 1;
            ++allowed_chars;
        }
        return 0;
    }
}

variable_types: c char


sum

decompiled_code:
double __fastcall sum(int a1, double *a2)
{
double *v2; // rax
double result; // xmm0_8

if ( a1 <= 0 )
return 0.0;
v2 = a2;
result = 0.0;
do
result = result + *v2++;
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
return result;
}

canonical_decompiled_code:
double __fastcall func2(int a1, double *a2)
{
double *v2; // rax
double result; // xmm0_8

if ( a1 <= 0 )
return 0.0;
v2 = a2;
result = 0.0;
do
result = result + *v2++;
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
return result;
}

original_code:
inline double sum(int count, double *restrict arr) {
    double s = 0;
    for (int i = 0; i < count; ++i)
        s += arr[i];
    return s;
}

canonical_original_code:
inline double sum(int count, double *arr) {
    double s = 0;
    for (int i = 0; i < count; ++i)
        s += arr[i];
    return s;
}

variable_types: count int

variable_types:
arr
double *

variable_types: s double

return_type: double


decompiled_code:
__int64 __fastcall base128_count(unsigned __int64 a1)
{
_BitScanReverse64(&a1, a1);
return (unsigned int)(7 * ((int)(63 - (a1 ^ 0x3F)) / 7) != 63 - ((unsigned int)a1 ^ 0x3F))
+ (int)(63 - (a1 ^ 0x3F)) / 7;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1)
{
_BitScanReverse64(&a1, a1);
return (unsigned int)(7 * ((int)(63 - (a1 ^ 0x3F)) / 7) != 63 - ((unsigned int)a1 ^ 0x3F))
+ (int)(63 - (a1 ^ 0x3F)) / 7;
}

original_code:
inline int base128_count(uint64_t val) {
    int lg = 63 - __builtin_clzl(val);
    int q = lg / 7;
    if (7*q == lg)
        return q;
    else
        return q+1;
}

canonical_original_code:
inline int base128_count(unsigned long val) {
    int lg = 63 - __builtin_clzl(val);
    int q = lg / 7;
    if (7*q == lg)
        return q;
    else
        return q+1;
}

variable_types:
val
unsigned long

variable_types: lg int

variable_types: q int


decompiled_code:
__int64 __fastcall base128_digit(unsigned __int64 a1, char a2)
{
return (a1 >> (7 * a2)) & 0x7F;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, char a2)
{
return (a1 >> (7 * a2)) & 0x7F;
}

original_code:
inline uint8_t base128_digit(uint64_t val, int i) {
    return ((val >> 7*i) & 127);
}

canonical_original_code:
inline unsigned char base128_digit(unsigned long val, int i) {
    return ((val >> 7*i) & 127);
}

variable_types: i int


seedrand

decompiled_code:
void seedrand()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_usec) * LODWORD(v0.tv_sec));
srand48(v0.tv_sec * v0.tv_usec);
}

canonical_decompiled_code:
void func5()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_usec) * LODWORD(v0.tv_sec));
srand48(v0.tv_sec * v0.tv_usec);
}

original_code:
void seedrand() {
    struct timeval t;
    gettimeofday(&t, ((void *)0));
    srand(t.tv_usec * t.tv_sec);
    srand48(t.tv_usec * t.tv_sec);
}

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


decompiled_code:
__int64 __fastcall random_sample(int a1, __int64 a2, double a3)
{
double v3; // xmm1_8
__int64 v4; // rax
double v5; // xmm0_8
unsigned int v6; // edx

v3 = a3 * drand48();
if ( a1 <= 0 )
return (unsigned int)(a1 - 1);
v4 = 0LL;
v5 = 0.0;
while ( 1 )
{
v6 = v4;
v5 = v5 + *(double *)(a2 + 8 * v4);
if ( v5 > v3 )
break;
if ( ++v4 == a1 )
return (unsigned int)(a1 - 1);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, __int64 a2, double a3)
{
double v3; // xmm1_8
__int64 v4; // rax
double v5; // xmm0_8
unsigned int v6; // edx

v3 = a3 * drand48();
if ( a1 <= 0 )
return (unsigned int)(a1 - 1);
v4 = 0LL;
v5 = 0.0;
while ( 1 )
{
v6 = v4;
v5 = v5 + *(double *)(a2 + 8 * v4);
if ( v5 > v3 )
break;
if ( ++v4 == a1 )
return (unsigned int)(a1 - 1);
}
return v6;
}

original_code:
int random_sample(int arraylen, double arraysum, double *array) {
    double sampled = arraysum*drand48();
    double cumsum = 0;
    for (int i = 0; i < arraylen; ++i) {
        cumsum += array[i];
        if (sampled < cumsum)
            return i;
    }
    return arraylen-1;
}

variable_types: arraylen int

variable_types: arraysum double

variable_types:
array
double *

variable_types: sampled double

variable_types: cumsum double


decompiled_code:
__int64 __fastcall mask_ptr(__int64 a1)
{
return a1 & 0xFFFFFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 & 0xFFFFFFFFFFFFLL;
}

original_code:
inline void * mask_ptr(tagptr_t p) {
    return (void*)(((uint64_t)p.ptr) & 0x0000ffffffffffffULL);
}

canonical_original_code:
inline void *mask_ptr(union tagptr_t p) {
    return (void *)(((unsigned long)p.ptr) & 0x0000ffffffffffffULL);
}

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; }


decompiled_code:
void __fastcall set_tag(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 6) = a2;
}

original_code:
inline void set_tag(tagptr_t *p, uint16_t tag) {
    p->tags[3] = tag;
}

canonical_original_code:
inline void set_tag(union tagptr_t *p, unsigned short tag) {
    p->tags[3] = tag;
}

variable_types: union tagptr_t { void *ptr; unsigned short tags[4]; unsigned char bytes[8]; } *

variable_types:
tag
unsigned short


decompiled_code:
unsigned __int64 __fastcall get_tag(unsigned __int64 a1)
{
return HIWORD(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return HIWORD(a1);
}

original_code:
inline uint16_t get_tag(tagptr_t p) {
    return p.tags[3];
}

canonical_original_code:
inline unsigned short get_tag(union tagptr_t p) {
    return p.tags[3];
}

return_type: unsigned short


repo: hdznrrd/noiseplug

decompiled_code:
__int64 next_note()
{
char v0; // al
unsigned int v1; // ecx

v0 = idx_1 + 1;
v1 = (unsigned __int8)melody[(unsigned __int8)idx_1];
if ( idx_1 == 23 )
v0 = 0;
idx_1 = v0;
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
char v0; // al
unsigned int v1; // ecx

v0 = idx_1 + 1;
v1 = (unsigned __int8)melody[(unsigned __int8)idx_1];
if ( idx_1 == 23 )
v0 = 0;
idx_1 = v0;
return v1;
}

original_code:
static inline uint8_t next_note()
{
 static uint8_t idx=0;
 const uint8_t v = melody[idx++];
 if(idx == (sizeof((melody))/sizeof(*(melody))))
  idx = 0;
 return v;
}

canonical_original_code:
static inline unsigned char next_note()
{
 static unsigned char idx = 0;
 unsigned char v = melody[idx++];
 if(idx == (sizeof((melody))/sizeof(*(melody))))
  idx = 0;
 return v;
}

variable_types:
idx
unsigned char

variable_types:
v
unsigned char


decompiled_code:
__int64 __fastcall get_sin(char a1)
{
return sin[a1 & 0xF];
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return sin[a1 & 0xF];
}

original_code:
static inline uint8_t get_sin(const uint8_t idx)
{
 return sin[idx%(sizeof((sin))/sizeof(*(sin)))];
}

canonical_original_code:
static inline unsigned char get_sin(unsigned char idx)
{
 return sin[idx%(sizeof((sin))/sizeof(*(sin)))];
}


decompiled_code:
__int64 next_rnd()
{
rnd_0 = (2 * rnd_0) | (((int)(unsigned __int16)rnd_0 >> 10) ^ ((int)(unsigned __int16)rnd_0 >> 13)) & 3;
return get_sin(rnd_0);
}

original_code:
static inline uint8_t next_rnd()
{
 static unsigned short rnd = 13373;
 const uint8_t f1 = (rnd&(3<<13))>>13;
 const uint8_t f2 = (rnd&(3<<10))>>10;
 rnd <<=1;
 rnd |= f1^f2;
 return get_sin(rnd);
}

canonical_original_code:
static inline unsigned char next_rnd()
{
 static unsigned short rnd = 13373;
 unsigned char f1 = (rnd&(3<<13))>>13;
 unsigned char f2 = (rnd&(3<<10))>>10;
 rnd <<=1;
 rnd |= f1^f2;
 return get_sin(rnd);
}

variable_types:
rnd
unsigned short