decompiled_code:
__int64 compresse_tst()
{
compresse_test(3u, (__int64)&t1_4, 2, (__int64)&ok1_3);
return compresse_test(9u, (__int64)&t2_2, 7, (__int64)&ok2_1);
}

original_code:
void compresse_tst()
{
  static float t1[] = { 0, 0, 5 } ;
  static int ok1[] = { 2, 5 } ;
  static float t2[] = { -0.4, -0.9, 0, 0.4, 0.9, 2 , 0,0,0 } ;
  static int ok2[] = { 1,-1, 2,1, 0,2, 3 } ;
  compresse_test(( sizeof(t1) / sizeof(t1[0]) ), t1, ( sizeof(ok1) / sizeof(ok1[0]) ), ok1) ;
  compresse_test(( sizeof(t2) / sizeof(t2[0]) ), t2, ( sizeof(ok2) / sizeof(ok2[0]) ), ok2) ;
  return ;
}

canonical_original_code:
void compresse_tst()
{
  static float t1[] = { 0, 0, 5 };
  static int ok1[] = { 2, 5 };
  static float t2[] = { -0.4, -0.9, 0, 0.4, 0.9, 2 , 0,0,0 };
  static int ok2[] = { 1,-1, 2,1, 0,2, 3 };
  compresse_test(( sizeof(t1) / sizeof(t1[0]) ), t1, ( sizeof(ok1) / sizeof(ok1[0]) ), ok1) ;
  compresse_test(( sizeof(t2) / sizeof(t2[0]) ), t2, ( sizeof(ok2) / sizeof(ok2[0]) ), ok2) ;
  return ;
}


repo: sgerin/DCT

decompiled_code:
__int64 allocation_matrice_carree_float()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
float** allocation_matrice_carree_float(int nbe)
{
return 0 ;
}

canonical_original_code:
float **allocation_matrice_carree_float(int nbe)
{
return 0 ;
}

variable_types: nbe int

return_type: float **


decompiled_code:
void liberation_matrice_carree_float()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void liberation_matrice_carree_float(float **table, int nbe)
{
}

variable_types:
table
float **

return_type: void


original_code:
void produit_matrices_carrees_float(int nbe, float **a, float **b, float **resultat)
 {
  int j, i, k ;
  float s ;
  for(j=0; j<nbe; j++)
    for(i=0; i<nbe; i++)
      {
 s = 0 ;
 for(k=0;k<nbe;k++)
   s += a[j][k]*b[k][i] ;
 resultat[j][i] = s ;
      }
 }

canonical_original_code:
void produit_matrices_carrees_float(int nbe, float **a, float **b, float **resultat)
 {
  int j; int i; int k;
  float s;
  for(j=0; j<nbe; j++)
    for(i=0; i<nbe; i++)
      {
 s = 0 ;
 for(k=0;k<nbe;k++)
   s += a[j][k]*b[k][i] ;
 resultat[j][i] = s ;
      }
 }

variable_types:
a
float **

variable_types:
b
float **

variable_types:
resultat
float **

variable_types: j int

variable_types: i int

variable_types: k int

variable_types: s float


original_code:
void produit_matrice_carree_vecteur(int nbe, float **m, const float *v, float *resultat)
 {
  int j, i ;
  float s ;
  for(j=0; j<nbe; j++)
    {
      s = 0 ;
      for(i=0;i<nbe;i++)
 s += m[j][i] * v[i] ;
      resultat[j] = s ;
    }
 }

canonical_original_code:
void produit_matrice_carree_vecteur(int nbe, float **m, float *v, float *resultat)
 {
  int j; int i;
  float s;
  for(j=0; j<nbe; j++)
    {
      s = 0 ;
      for(i=0;i<nbe;i++)
 s += m[j][i] * v[i] ;
      resultat[j] = s ;
    }
 }

variable_types:
m
float **

variable_types:
v
float *

variable_types:
resultat
float *


original_code:
void transposition_matrice_carree(int nbe, float **a, float **a_t)
 {
  int i, j ;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      a_t[j][i] = a[i][j] ;
 }

canonical_original_code:
void transposition_matrice_carree(int nbe, float **a, float **a_t)
 {
  int i; int j;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      a_t[j][i] = a[i][j] ;
 }


simple

decompiled_code:
__int64 __fastcall simple(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return a1;
}

original_code:
static int simple(int n)
{
  return(n) ;
}

variable_types: n int

return_type: int


aleatoire

decompiled_code:
__int64 __fastcall aleatoire(unsigned int a1)
{
srand(a1);
return (unsigned int)(rand() % 50);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
srand(a1);
return (unsigned int)(rand() % 50);
}

original_code:
static int aleatoire(int n)
{
  srand(n) ;
  return( rand() % 50 ) ;
}


decompiled_code:
__int64 __fastcall aleatoire2(unsigned int a1)
{
int v1; // eax

srand(a1);
v1 = rand();
return (unsigned int)(int)pow((double)(v1 % 50), 0.1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
int v1; // eax

srand(a1);
v1 = rand();
return (unsigned int)(int)pow((double)(v1 % 50), 0.1);
}

original_code:
static int aleatoire2(int n)
{
  srand(n) ;
  return( pow( rand() % 50, .1 ) ) ;
}


decompiled_code:
__int64 __fastcall trouve_position(unsigned int *a1, int a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rsi
__int64 result; // rax
unsigned int v7; // edx

v5 = *a1;
if ( !(_DWORD)v5 )
return a4;
result = 0LL;
while ( 1 )
{
v7 = a1[2 * result + 1];
if ( v7 == a2 )
break;
if ( v7 == 0x7FFFFFFF )
a4 = result;
if ( ++result == v5 )
return a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, int a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rsi
__int64 result; // rax
unsigned int v7; // edx

v5 = *a1;
if ( !(_DWORD)v5 )
return a4;
result = 0LL;
while ( 1 )
{
v7 = a1[2 * result + 1];
if ( v7 == a2 )
break;
if ( v7 == 0x7FFFFFFF )
a4 = result;
if ( ++result == v5 )
return a4;
}
return result;
}

original_code:
static int trouve_position(const struct shannon_fano *sf, int evenement)
{
 unsigned int i;
 unsigned int escape;
 for(i=0; i<sf->nb_evenements; ++i)
 {
  if(sf->evenements[i].valeur == evenement)
   return i;
  if(sf->evenements[i].valeur == 0x7fffffff)
   escape = i;
 }
 return escape;
}

canonical_original_code:
static int trouve_position(struct shannon_fano *sf, int evenement)
{
 unsigned int i;
 unsigned int escape;
 for(i=0; i<sf->nb_evenements; ++i)
 {
  if(sf->evenements[i].valeur == evenement)
   return i;
  if(sf->evenements[i].valeur == 0x7fffffff)
   escape = i;
 }
 return escape;
}

variable_types: struct shannon_fano { int nb_evenements; struct evenement { int valeur; int nb_occurrences; } evenements[200000]; } *

variable_types: evenement int

variable_types:
i
unsigned int

variable_types:
escape
unsigned int

user_defined_types: struct shannon_fano { int nb_evenements; struct evenement evenements[200000]; }


decompiled_code:
__int64 __fastcall trouve_separation(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // edx
__int64 v6; // r8
__int64 v7; // r8

result = (unsigned int)a3;
if ( a2 <= a3 )
{
v4 = 0;
v5 = 0;
do
{
while ( v5 < v4 )
{
v6 = a2++;
v5 += *(_DWORD *)(a1 + 8 * v6 + 8);
if ( (int)result < a2 )
return result;
}
v7 = (int)result;
result = (unsigned int)(result - 1);
v4 += *(_DWORD *)(a1 + 8 * v7 + 8);
}
while ( (int)result >= a2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // edx
__int64 v6; // r8
__int64 v7; // r8

result = (unsigned int)a3;
if ( a2 <= a3 )
{
v4 = 0;
v5 = 0;
do
{
while ( v5 < v4 )
{
v6 = a2++;
v5 += *(_DWORD *)(a1 + 8 * v6 + 8);
if ( (int)result < a2 )
return result;
}
v7 = (int)result;
result = (unsigned int)(result - 1);
v4 += *(_DWORD *)(a1 + 8 * v7 + 8);
}
while ( (int)result >= a2 );
}
return result;
}

original_code:
static int trouve_separation(const struct shannon_fano *sf
        , int position_min
        , int position_max)
{
 unsigned int sum_inf = 0;
 unsigned int sum_sup = 0;
 while(position_min <= position_max)
 {
  if(sum_inf < sum_sup)
  {
   sum_inf += sf->evenements[position_min].nb_occurrences;
   ++position_min;
  }
  else
  {
   sum_sup += sf->evenements[position_max].nb_occurrences;
   --position_max;
  }
 }
 return position_max;
}

canonical_original_code:
static int trouve_separation(struct shannon_fano *sf, int position_min, int position_max)
{
 unsigned int sum_inf = 0;
 unsigned int sum_sup = 0;
 while(position_min <= position_max)
 {
  if(sum_inf < sum_sup)
  {
   sum_inf += sf->evenements[position_min].nb_occurrences;
   ++position_min;
  }
  else
  {
   sum_sup += sf->evenements[position_max].nb_occurrences;
   --position_max;
  }
 }
 return position_max;
}

user_defined_types: struct evenement { int valeur; int nb_occurrences; }


decompiled_code:
__int64 __fastcall incremente_et_ordonne(__int64 a1, int a2)
{
unsigned int *v2; // r8
__int64 result; // rax
int v4; // ecx
int v5; // edx
__int64 v6; // rcx

v2 = (unsigned int *)(a1 + 8LL * a2);
result = v2[2];
v4 = result + 1;
v2[2] = result + 1;
if ( a2 > 0 )
{
v5 = a2;
result = a2 - 1;
do
{
if ( v4 > *(_DWORD *)(a1 + 8 * result + 8) )
v5 = result;
--result;
}
while ( (_DWORD)result != -1 );
if ( v5 != a2 )
{
v6 = *(_QWORD *)(a1 + 8LL * a2 + 4);
result = *v2;
v2[1] = *(v2 - 1);
*(_QWORD *)(v2 - 1) = v6;
v2[2] = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int *v2; // r8
__int64 result; // rax
int v4; // ecx
int v5; // edx
__int64 v6; // rcx

v2 = (unsigned int *)(a1 + 8LL * a2);
result = v2[2];
v4 = result + 1;
v2[2] = result + 1;
if ( a2 > 0 )
{
v5 = a2;
result = a2 - 1;
do
{
if ( v4 > *(_DWORD *)(a1 + 8 * result + 8) )
v5 = result;
--result;
}
while ( (_DWORD)result != -1 );
if ( v5 != a2 )
{
v6 = *(_QWORD *)(a1 + 8LL * a2 + 4);
result = *v2;
v2[1] = *(v2 - 1);
*(_QWORD *)(v2 - 1) = v6;
v2[2] = result;
}
}
return result;
}

original_code:
static void incremente_et_ordonne(struct shannon_fano *sf, int position)
{
 sf->evenements[position].nb_occurrences++;
 if(position > 0)
 {
  int position_swap = position;
  int i;
  for(i=position-1; i>=0; i--)
  {
   if(sf->evenements[i].nb_occurrences < sf->evenements[position].nb_occurrences)
    position_swap = i;
  }
  if(position_swap != position)
  {
   struct evenement tmp = sf->evenements[position-1];
   sf->evenements[position-1] = sf->evenements[position];
   sf->evenements[position] = tmp;
  }
 }
}

variable_types: position int

variable_types: struct evenement { int valeur; int nb_occurrences; }


decompiled_code:
_DWORD *open_shannon_fano()
{
_DWORD *result; // rax

result = malloc(0x186A04uLL);
if ( !result )
{
fwrite("Plus de memoire\n", 1uLL, 0x10uLL, stderr);
fprintf(stderr, "%s:%d\n", "sf.c", 34LL);
abort();
}
result[2] = 1;
*(_QWORD *)result = 0x7FFFFFFF00000001LL;
return result;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *result; // rax

result = malloc(0x186A04uLL);
if ( !result )
{
fwrite("Plus de memoire\n", 1uLL, 0x10uLL, stderr);
fprintf(stderr, "%s:%d\n", "sf.c", 34LL);
abort();
}
result[2] = 1;
*(_QWORD *)result = 0x7FFFFFFF00000001LL;
return result;
}

original_code:
struct shannon_fano* open_shannon_fano()
{
 struct shannon_fano* sf;
 do if ( (sf = malloc(sizeof(*(sf)) * (1))) == 0 ) { fprintf(stderr, "Plus de memoire\n") ; do { fprintf(stderr,"%s:%d\n","sf.c",34) ; abort() ; } while(0) ; } while(0);
 sf->nb_evenements = 1;
 sf->evenements[0].valeur = 0x7fffffff;
 sf->evenements[0].nb_occurrences = 1;
 return sf;
}

canonical_original_code:
struct shannon_fano *open_shannon_fano()
{
 struct shannon_fano *sf;
 do if ( (sf = malloc(sizeof(*(sf)) * (1))) == 0 ) { fprintf(stderr, "Plus de memoire\n") ; do { fprintf(stderr,"%s:%d\n","sf.c",34) ; abort() ; } while(0) ; } while(0);
 sf->nb_evenements = 1;
 sf->evenements[0].valeur = 0x7fffffff;
 sf->evenements[0].nb_occurrences = 1;
 return sf;
}

return_type: struct shannon_fano { int nb_evenements; struct evenement { int valeur; int nb_occurrences; } evenements[200000]; } *


decompiled_code:
// attributes: thunk
void close_shannon_fano(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func6(void *ptr)
{
free(ptr);
}

original_code:
void close_shannon_fano(struct shannon_fano *sf)
{
 free(sf);
}


decompiled_code:
__int64 __fastcall sf_get_nb_evenements(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
return *a1;
}

original_code:
int sf_get_nb_evenements(struct shannon_fano *sf)
 {
   return sf->nb_evenements ;
 }


decompiled_code:
__int64 nb_bits_utile_tst()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = 0LL;
while ( 1 )
{
result = nb_bits_utile(v0);
if ( (_DWORD)result != n_0[v0] )
break;
if ( ++v0 == 9 )
return result;
}
return eprintf("nb_bits_utile(%d) != %d\n", (unsigned int)v0);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = 0LL;
while ( 1 )
{
result = nb_bits_utile(v0);
if ( (_DWORD)result != n_0[v0] )
break;
if ( ++v0 == 9 )
return result;
}
return eprintf("nb_bits_utile(%d) != %d\n", (unsigned int)v0);
}

original_code:
void nb_bits_utile_tst()
{
  int i ;
  static int n[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4 } ;
  for( i=0; i<( sizeof(n) / sizeof(n[0]) ); i++)
    if ( nb_bits_utile(i) != n[i] )
      {
 eprintf("nb_bits_utile(%d) != %d\n", i, n[i]) ;
 return ;
      }
}

canonical_original_code:
void nb_bits_utile_tst()
{
  int i;
  static int n[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4 };
  for( i=0; i<( sizeof(n) / sizeof(n[0]) ); i++)
    if ( nb_bits_utile(i) != n[i] )
      {
 eprintf("nb_bits_utile(%d) != %d\n", i, n[i]) ;
 return ;
      }
}

variable_types:
n
int []


decompiled_code:
int __fastcall pow2_tst(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v2 = 0;
if ( pow2(0LL) == 1 )
{
do
{
v3 = v2 + 1;
v4 = pow2(v2 + 1);
v5 = pow2(v2++);
if ( v4 != 2 * v5 )
{
LODWORD(v6) = eprintf("pow2(%d) != pow2(%d)*2\n", v3);
return v6;
}
}
while ( v3 != 31 );
v6 = pow2(70LL);
if ( v6 )
{
v7 = pow2(70LL);
LODWORD(v6) = fprintf(
stderr,
"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n : ",
v7);
}
}
else
{
LODWORD(v6) = eprintf("pow2(0) != 1\n", a2);
}
return v6;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v2 = 0;
if ( pow2(0LL) == 1 )
{
do
{
v3 = v2 + 1;
v4 = pow2(v2 + 1);
v5 = pow2(v2++);
if ( v4 != 2 * v5 )
{
LODWORD(v6) = eprintf("pow2(%d) != pow2(%d)*2\n", v3);
return v6;
}
}
while ( v3 != 31 );
v6 = pow2(70LL);
if ( v6 )
{
v7 = pow2(70LL);
LODWORD(v6) = fprintf(
stderr,
"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n : ",
v7);
}
}
else
{
LODWORD(v6) = eprintf("pow2(0) != 1\n", a2);
}
return v6;
}

original_code:
void pow2_tst()
{
  int i ;
  if ( pow2(0) != 1 )
    {
      eprintf("pow2(0) != 1\n") ;
      return ;
    }
  for(i=0;i<31;i++)
    if ( pow2(i+1) != pow2(i)*2 )
      {
 eprintf("pow2(%d) != pow2(%d)*2\n", i+1, i) ;
 return ;
      }
  if ( pow2(70) != 0 )
    fprintf(stderr,"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n                                         : ",pow2(70));
}

canonical_original_code:
void pow2_tst()
{
  int i;
  if ( pow2(0) != 1 )
    {
      eprintf("pow2(0) != 1\n") ;
      return ;
    }
  for(i=0;i<31;i++)
    if ( pow2(i+1) != pow2(i)*2 )
      {
 eprintf("pow2(%d) != pow2(%d)*2\n", i+1, i) ;
 return ;
      }
  if ( pow2(70) != 0 )
    fprintf(stderr,"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n                                         : ",pow2(70));
}


decompiled_code:
__int64 prend_bit_tst()
{
int v0; // er14
int v1; // eax
int v2; // er12
unsigned int v3; // ebx
__int64 v4; // rbp
int v5; // er13
__int64 v6; // rsi
__int64 result; // rax
__int64 v8; // rdi
const char *v9; // rdi

v0 = 1000;
while ( 2 )
{
v1 = rand();
v2 = 0;
v3 = 0;
v4 = v1;
v5 = v1;
do
{
while ( 1 )
{
v6 = v3;
if ( (unsigned int)prend_bit(v4, v3) == 1 )
break;
v6 = v3;
result = prend_bit(v4, v3);
if ( (_DWORD)result )
{
v9 = "Retourne ni Faux, ni Vrai\n";
return eprintf(v9, v6);
}
if ( ++v3 == 64 )
goto LABEL_7;
}
v8 = v3++;
result = pow2(v8);
v2 |= result;
}
while ( v3 != 64 );
LABEL_7:
if ( v2 != v5 )
{
v9 = "Mauvais\n";
return eprintf(v9, v6);
}
if ( --v0 )
continue;
return result;
}
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er14
int v1; // eax
int v2; // er12
unsigned int v3; // ebx
__int64 v4; // rbp
int v5; // er13
__int64 v6; // rsi
__int64 result; // rax
__int64 v8; // rdi
const char *v9; // rdi

v0 = 1000;
while ( 2 )
{
v1 = rand();
v2 = 0;
v3 = 0;
v4 = v1;
v5 = v1;
do
{
while ( 1 )
{
v6 = v3;
if ( (unsigned int)prend_bit(v4, v3) == 1 )
break;
v6 = v3;
result = prend_bit(v4, v3);
if ( (_DWORD)result )
{
v9 = "Retourne ni Faux, ni Vrai\n";
return eprintf(v9, v6);
}
if ( ++v3 == 64 )
goto LABEL_7;
}
v8 = v3++;
result = pow2(v8);
v2 |= result;
}
while ( v3 != 64 );
LABEL_7:
if ( v2 != v5 )
{
v9 = "Mauvais\n";
return eprintf(v9, v6);
}
if ( --v0 )
continue;
return result;
}
}

original_code:
void prend_bit_tst()
{
  int i, j, k, s ;
  for(i=0;i<1000;i++)
    {
      j = rand() ;
      s = 0 ;
      for(k=0;k<8*sizeof(unsigned long);k++)
 if ( prend_bit(j, k) == Vrai )
   s |= pow2(k) ;
 else
   if ( prend_bit(j, k) != Faux )
     {
       eprintf("Retourne ni Faux, ni Vrai\n") ;
       return ;
     }
      if ( s != j )
 {
   eprintf("Mauvais\n") ;
   return ;
 }
    }
}

canonical_original_code:
void prend_bit_tst()
{
  int i; int j; int k; int s;
  for(i=0;i<1000;i++)
    {
      j = rand() ;
      s = 0 ;
      for(k=0;k<8*sizeof(unsigned long);k++)
 if ( prend_bit(j, k) == Vrai )
   s |= pow2(k) ;
 else
   if ( prend_bit(j, k) != Faux )
     {
       eprintf("Retourne ni Faux, ni Vrai\n") ;
       return ;
     }
      if ( s != j )
 {
   eprintf("Mauvais\n") ;
   return ;
 }
    }
}

variable_types: s int


decompiled_code:
__int64 coef_dct_tst()
{
unsigned int v0; // er13
_QWORD *v1; // rbp
double v2; // xmm1_8
__int64 result; // rax
__int64 i; // rbx
double v5; // xmm0_8

v0 = 0;
v1 = (_QWORD *)allocation_matrice_carree_float(5LL);
coef_dct(5LL, v1);
*(_QWORD *)&v2 = (unsigned int)LC0;
result = 0LL;
LABEL_2:
for ( i = 0LL; ; *(_QWORD *)&v2 = (unsigned int)t_1[i + result] )
{
v5 = COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(*v1 + 4 * i) - *(float *)&v2) & LC1);
if ( v5 > 0.0001 )
break;
if ( ++i == 5 )
{
++v0;
++v1;
result += 5LL;
if ( v0 == 5 )
return result * 4;
*(_QWORD *)&v2 = (unsigned int)t_1[result];
goto LABEL_2;
}
}
eprintf("La matrice est mauvaise.\n", v5, v2, 0.0001, COERCE_DOUBLE((unsigned __int64)LC1));
return eprintf("dct[%d][%d] = %g au lieu de %g\n", v0, (unsigned int)i, *(float *)(*v1 + 4 * i), *(float *)&v2);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er13
_QWORD *v1; // rbp
double v2; // xmm1_8
__int64 result; // rax
__int64 i; // rbx
double v5; // xmm0_8

v0 = 0;
v1 = (_QWORD *)allocation_matrice_carree_float(5LL);
coef_dct(5LL, v1);
*(_QWORD *)&v2 = (unsigned int)LC0;
result = 0LL;
LABEL_2:
for ( i = 0LL; ; *(_QWORD *)&v2 = (unsigned int)t_1[i + result] )
{
v5 = COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(*v1 + 4 * i) - *(float *)&v2) & LC1);
if ( v5 > 0.0001 )
break;
if ( ++i == 5 )
{
++v0;
++v1;
result += 5LL;
if ( v0 == 5 )
return result * 4;
*(_QWORD *)&v2 = (unsigned int)t_1[result];
goto LABEL_2;
}
}
eprintf("La matrice est mauvaise.\n", v5, v2, 0.0001, COERCE_DOUBLE((unsigned __int64)LC1));
return eprintf("dct[%d][%d] = %g au lieu de %g\n", v0, (unsigned int)i, *(float *)(*v1 + 4 * i), *(float *)&v2);
}

variable_types:
table
float **

variable_types:
t
float [5][5]


decompiled_code:
void dct_tst()
{
__int64 v0; // rbx
double v1; // xmm1_8
int v2; // eax
float v3; // xmm0_4
__int64 v4; // rbx
double v5; // xmm1_8
double v6; // xmm0_8
float *v7; // rbx
int *v8; // rax
int v9; // ebp
double v10; // xmm0_8
double v11; // xmm1_8
double v12; // xmm0_8
double v13; // [rsp+8h] [rbp-430h]
double v14; // [rsp+8h] [rbp-430h]
double v15; // [rsp+10h] [rbp-428h]
double v16; // [rsp+10h] [rbp-428h]
double v17; // [rsp+10h] [rbp-428h]
double v18; // [rsp+18h] [rbp-420h]
float v19[128]; // [rsp+20h] [rbp-418h] BYREF
float v20[134]; // [rsp+220h] [rbp-218h] BYREF

v0 = 1LL;
v1 = *(double *)&LC5;
v15 = *(double *)&LC6;
v13 = *(double *)&LC7;
while ( 1 )
{
v2 = v0;
v3 = v13 + v15 + v1;
*((float *)&v18 + ++v0) = v3;
if ( v0 == 129 )
break;
v16 = (double)v2;
v13 = cos((double)v2);
v18 = v16;
v15 = cos(0.25 * v16 + 0.1);
v1 = cos(v18 / 7.0 + 2.0);
}
v4 = 0LL;
dct(0LL, 128LL, v19, v20);
for ( *(_QWORD *)&v5 = (unsigned int)LC8; ; *(_QWORD *)&v5 = (unsigned int)dct_ok_0[v4] )
{
v6 = COERCE_FLOAT(COERCE_UNSIGNED_INT(v20[v4] - *(float *)&v5) & LC1);
if ( v6 > 0.0001 )
{
eprintf("La dct est mauvaise.\n", v6, v5, *(double *)&LC2, COERCE_DOUBLE((unsigned __int64)LC1));
eprintf("sortie[%d] = %g au lieu de %g\n", (unsigned int)v4, v20[(int)v4], *(float *)&v5);
return;
}
if ( ++v4 == 128 )
break;
}
v7 = v19;
v8 = (int *)v19;
do
*v8++ = LC15;
while ( v20 != (float *)v8 );
v9 = 0;
dct(1LL, 128LL, v20, v19);
v10 = *(double *)&LC5;
v17 = *(double *)&LC6;
v14 = *(double *)&LC7;
while ( 1 )
{
v11 = v14 + v17 + v10;
*(_QWORD *)&v12 = COERCE_UNSIGNED_INT64(*v7 - v11) & LC16;
if ( v12 > 0.01 )
break;
++v9;
++v7;
if ( v9 == 128 )
return;
v14 = cos((double)v9);
v18 = (double)v9;
v17 = cos(0.25 * v18 + 0.1);
v10 = cos(v18 / 7.0 + 2.0);
}
eprintf("La dct inverse est mauvaise.\n", v12, v11, *(double *)&LC2, COERCE_DOUBLE((unsigned __int64)LC1));
eprintf("sortie[%d] = %g au lieu de %g\n", (unsigned int)v9, v19[v9], v11);
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx
double v1; // xmm1_8
int v2; // eax
float v3; // xmm0_4
__int64 v4; // rbx
double v5; // xmm1_8
double v6; // xmm0_8
float *v7; // rbx
int *v8; // rax
int v9; // ebp
double v10; // xmm0_8
double v11; // xmm1_8
double v12; // xmm0_8
double v13; // [rsp+8h] [rbp-430h]
double v14; // [rsp+8h] [rbp-430h]
double v15; // [rsp+10h] [rbp-428h]
double v16; // [rsp+10h] [rbp-428h]
double v17; // [rsp+10h] [rbp-428h]
double v18; // [rsp+18h] [rbp-420h]
float v19[128]; // [rsp+20h] [rbp-418h] BYREF
float v20[134]; // [rsp+220h] [rbp-218h] BYREF

v0 = 1LL;
v1 = *(double *)&LC5;
v15 = *(double *)&LC6;
v13 = *(double *)&LC7;
while ( 1 )
{
v2 = v0;
v3 = v13 + v15 + v1;
*((float *)&v18 + ++v0) = v3;
if ( v0 == 129 )
break;
v16 = (double)v2;
v13 = cos((double)v2);
v18 = v16;
v15 = cos(0.25 * v16 + 0.1);
v1 = cos(v18 / 7.0 + 2.0);
}
v4 = 0LL;
dct(0LL, 128LL, v19, v20);
for ( *(_QWORD *)&v5 = (unsigned int)LC8; ; *(_QWORD *)&v5 = (unsigned int)dct_ok_0[v4] )
{
v6 = COERCE_FLOAT(COERCE_UNSIGNED_INT(v20[v4] - *(float *)&v5) & LC1);
if ( v6 > 0.0001 )
{
eprintf("La dct est mauvaise.\n", v6, v5, *(double *)&LC2, COERCE_DOUBLE((unsigned __int64)LC1));
eprintf("sortie[%d] = %g au lieu de %g\n", (unsigned int)v4, v20[(int)v4], *(float *)&v5);
return;
}
if ( ++v4 == 128 )
break;
}
v7 = v19;
v8 = (int *)v19;
do
*v8++ = LC15;
while ( v20 != (float *)v8 );
v9 = 0;
dct(1LL, 128LL, v20, v19);
v10 = *(double *)&LC5;
v17 = *(double *)&LC6;
v14 = *(double *)&LC7;
while ( 1 )
{
v11 = v14 + v17 + v10;
*(_QWORD *)&v12 = COERCE_UNSIGNED_INT64(*v7 - v11) & LC16;
if ( v12 > 0.01 )
break;
++v9;
++v7;
if ( v9 == 128 )
return;
v14 = cos((double)v9);
v18 = (double)v9;
v17 = cos(0.25 * v18 + 0.1);
v10 = cos(v18 / 7.0 + 2.0);
}
eprintf("La dct inverse est mauvaise.\n", v12, v11, *(double *)&LC2, COERCE_DOUBLE((unsigned __int64)LC1));
eprintf("sortie[%d] = %g au lieu de %g\n", (unsigned int)v9, v19[v9], v11);
}

variable_types: i int

variable_types:
entree
float [128]

variable_types:
sortie
float [128]


decompiled_code:
__int64 allocation_image()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
struct image* allocation_image(int hauteur, int largeur)
{
return 0 ;
}

canonical_original_code:
struct image *allocation_image(int hauteur, int largeur)
{
return 0 ;
}

variable_types: hauteur int

variable_types: largeur int

return_type: struct image { int largeur; int hauteur; unsigned char **pixels; } *


decompiled_code:
void liberation_image()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void liberation_image(struct image* image)
{
}

canonical_original_code:
void liberation_image(struct image *image)
{
}

variable_types: struct image { int largeur; int hauteur; unsigned char **pixels; } *


original_code:
static void extrait_matrice(int y, int x, int nbe
       , const struct image *entree
       , float **extrait
       )
 {
  int i, j ;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < entree->hauteur && i+x < entree->largeur )
 extrait[j][i] = entree->pixels[j+y][i+x] ;
      else
 extrait[j][i] = 0 ;
 }

canonical_original_code:
static void extrait_matrice(int y, int x, int nbe, struct image *entree, float **extrait)
 {
  int i; int j;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < entree->hauteur && i+x < entree->largeur )
 extrait[j][i] = entree->pixels[j+y][i+x] ;
      else
 extrait[j][i] = 0 ;
 }

variable_types: y int

variable_types: x int

variable_types: nbe int

variable_types:
extrait
float **

variable_types: j int

user_defined_types: struct image { int largeur; int hauteur; unsigned char **pixels; }


original_code:
static void insert_matrice(int y, int x, int nbe
      , float **extrait
      , struct image *sortie
      )
 {
  int i, j ;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < sortie->hauteur && i+x < sortie->largeur )
 {
   if ( extrait[j][i] < 0 )
     sortie->pixels[j+y][i+x] = 0 ;
   else
     {
       if ( extrait[j][i] > 255 )
  sortie->pixels[j+y][i+x] = 255 ;
       else
  sortie->pixels[j+y][i+x] = rint(extrait[j][i]) ;
     }
 }
 }

canonical_original_code:
static void insert_matrice(int y, int x, int nbe, float **extrait, struct image *sortie)
 {
  int i; int j;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < sortie->hauteur && i+x < sortie->largeur )
 {
   if ( extrait[j][i] < 0 )
     sortie->pixels[j+y][i+x] = 0 ;
   else
     {
       if ( extrait[j][i] > 255 )
  sortie->pixels[j+y][i+x] = 255 ;
       else
  sortie->pixels[j+y][i+x] = rint(extrait[j][i]) ;
     }
 }
 }


decompiled_code:
void dct_image()
{
;
}

original_code:
void dct_image(int inverse, int nbe, float **image)
{
}

variable_types: inverse int

variable_types:
image
float **


quantification

decompiled_code:
void quantification()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void quantification(int nbe, int qualite, float **extrait, int inverse)
{
}

variable_types: qualite int


zigzag

decompiled_code:
void zigzag()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void zigzag(int nbe, int *y, int *x)
{
}

variable_types:
y
int *

variable_types:
x
int *


decompiled_code:
__int64 allocation_image_tst()
{
__int64 v0; // rcx
__int64 i; // rax
__int64 v2; // rcx
__int64 result; // rax
_BYTE *v4; // rdx

v0 = allocation_image(1LL, 1000LL);
for ( i = 0LL; i != 1000; ++i )
*(_BYTE *)(**(_QWORD **)(v0 + 8) + i) = 99;
v2 = allocation_image(1000LL, 1LL);
for ( result = 0LL; result != 8000; result += 8LL )
{
v4 = *(_BYTE **)(*(_QWORD *)(v2 + 8) + result);
*v4 = 99;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rcx
__int64 i; // rax
__int64 v2; // rcx
__int64 result; // rax
_BYTE *v4; // rdx

v0 = allocation_image(1LL, 1000LL);
for ( i = 0LL; i != 1000; ++i )
*(_BYTE *)(**(_QWORD **)(v0 + 8) + i) = 99;
v2 = allocation_image(1000LL, 1LL);
for ( result = 0LL; result != 8000; result += 8LL )
{
v4 = *(_BYTE **)(*(_QWORD *)(v2 + 8) + result);
*v4 = 99;
}
return result;
}

original_code:
void allocation_image_tst()
{
  struct image *image ;
  int i ;
  image = allocation_image(1, 1000) ;
  for(i=0; i<1000; i++)
    image->pixels[0][i] = 99 ;
  image = allocation_image(1000, 1) ;
  for(i=0; i<1000; i++)
    image->pixels[i][0] = 99 ;
}

canonical_original_code:
void allocation_image_tst()
{
  struct image *image;
  int i;
  image = allocation_image(1, 1000) ;
  for(i=0; i<1000; i++)
    image->pixels[0][i] = 99 ;
  image = allocation_image(1000, 1) ;
  for(i=0; i<1000; i++)
    image->pixels[i][0] = 99 ;
}


decompiled_code:
__int64 lecture_image_tst()
{
FILE *v0; // rax
unsigned int *v1; // rax
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // r10
__int64 v5; // r9
__int64 v6; // rsi
__int64 i; // rcx
__int64 result; // rax

v0 = fopen("DONNEES/bat710.pgm", "r");
v1 = (unsigned int *)lecture_image(v0);
v2 = v1[1];
if ( (_DWORD)v2 != 135 )
return eprintf("Mauvaise hauteur : %d au lieu de 135\n", v2);
v3 = *v1;
if ( (_DWORD)v3 != 254 )
return eprintf("Mauvaise largeur : %d au lieu de 254\n", v3);
v4 = *((_QWORD *)v1 + 1);
v5 = 0LL;
LODWORD(v6) = 0;
do
{
for ( i = 1LL; i != 255; ++i )
{
result = (unsigned int)((int)(v5 * *(unsigned __int8 *)(*(_QWORD *)(v4 + 8 * v5) + i - 1)) / (int)i);
v6 = (unsigned int)(result + v6);
}
++v5;
}
while ( v5 != 135 );
if ( (_DWORD)v6 != 5709193 )
result = eprintf("Mauvais pixels : Checksum = %d\n", v6);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
FILE *v0; // rax
unsigned int *v1; // rax
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // r10
__int64 v5; // r9
__int64 v6; // rsi
__int64 i; // rcx
__int64 result; // rax

v0 = fopen("DONNEES/bat710.pgm", "r");
v1 = (unsigned int *)lecture_image(v0);
v2 = v1[1];
if ( (_DWORD)v2 != 135 )
return eprintf("Mauvaise hauteur : %d au lieu de 135\n", v2);
v3 = *v1;
if ( (_DWORD)v3 != 254 )
return eprintf("Mauvaise largeur : %d au lieu de 254\n", v3);
v4 = *((_QWORD *)v1 + 1);
v5 = 0LL;
LODWORD(v6) = 0;
do
{
for ( i = 1LL; i != 255; ++i )
{
result = (unsigned int)((int)(v5 * *(unsigned __int8 *)(*(_QWORD *)(v4 + 8 * v5) + i - 1)) / (int)i);
v6 = (unsigned int)(result + v6);
}
++v5;
}
while ( v5 != 135 );
if ( (_DWORD)v6 != 5709193 )
result = eprintf("Mauvais pixels : Checksum = %d\n", v6);
return result;
}

original_code:
void lecture_image_tst()
{
  struct image *image ;
  int j, i ;
  int s ;
  image = lecture_image(fopen("DONNEES/bat710.pgm","r")) ;
  if ( image->hauteur != 135 )
    {
      eprintf("Mauvaise hauteur : %d au lieu de 135\n", image->hauteur) ;
      return ;
    }
  if ( image->largeur != 254 )
    {
      eprintf("Mauvaise largeur : %d au lieu de 254\n", image->largeur) ;
      return ;
    }
  s = 0 ;
  for(j=0; j<image->hauteur; j++)
    for(i=0; i<image->largeur; i++)
      s += (j*image->pixels[j][i])/(i+1) ;
  if ( s != 5709193 )
    eprintf("Mauvais pixels : Checksum = %d\n", s) ;
}

canonical_original_code:
void lecture_image_tst()
{
  struct image *image;
  int j; int i;
  int s;
  image = lecture_image(fopen("DONNEES/bat710.pgm","r")) ;
  if ( image->hauteur != 135 )
    {
      eprintf("Mauvaise hauteur : %d au lieu de 135\n", image->hauteur) ;
      return ;
    }
  if ( image->largeur != 254 )
    {
      eprintf("Mauvaise largeur : %d au lieu de 254\n", image->largeur) ;
      return ;
    }
  s = 0 ;
  for(j=0; j<image->hauteur; j++)
    for(i=0; i<image->largeur; i++)
      s += (j*image->pixels[j][i])/(i+1) ;
  if ( s != 5709193 )
    eprintf("Mauvais pixels : Checksum = %d\n", s) ;
}

variable_types: s int


decompiled_code:
__int64 psycho_tst()
{
int v0; // xmm0_4
__int64 result; // rax
int v2[98]; // [rsp+0h] [rbp-188h] BYREF

qmemcpy(v2, &t_1, 0x174uLL);
psycho(93LL, v2, COERCE_DOUBLE((unsigned __int64)LC1));
v0 = LC0;
for ( result = 0LL; *(float *)&v0 == *(float *)&v2[result]; v0 = t_ok_0[result] )
{
if ( ++result == 93 )
return result * 4;
}
return eprintf("Voir le source du test\n");
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // xmm0_4
__int64 result; // rax
int v2[98]; // [rsp+0h] [rbp-188h] BYREF

qmemcpy(v2, &t_1, 0x174uLL);
psycho(93LL, v2, COERCE_DOUBLE((unsigned __int64)LC1));
v0 = LC0;
for ( result = 0LL; *(float *)&v0 == *(float *)&v2[result]; v0 = t_ok_0[result] )
{
if ( ++result == 93 )
return result * 4;
}
return eprintf("Voir le source du test\n");
}

variable_types:
t
float []

variable_types:
tt
float [-1]

variable_types: i int


psycho

decompiled_code:
void psycho()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void psycho(int nbe, float *dct, float c)
{
}

variable_types:
dct
float *

variable_types: c float


eprintf

decompiled_code:
int eprintf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( premiere )
{
premiere = 0;
fwrite("\n\n************** ERREUR ! ***************\n\n", 1uLL, 0x2BuLL, stderr);
}
va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( premiere )
{
premiere = 0;
fwrite("\n\n************** ERREUR ! ***************\n\n", 1uLL, 0x2BuLL, stderr);
}
va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
int eprintf(const char *format, ...)
{
    va_list ap;
    int i ;
    if ( premiere )
      {
 premiere = 0 ;
 fprintf(stderr, "\n\n************** ERREUR ! ***************\n\n") ;
      }
    __builtin_va_start(ap,format);
    i = vfprintf(stderr, format, ap );
    __builtin_va_end(ap);
    return(i) ;
}

canonical_original_code:
int eprintf(char *format, ...)
{
    __builtin_va_list ap;
    int i;
    if ( premiere )
      {
 premiere = 0 ;
 fprintf(stderr, "\n\n************** ERREUR ! ***************\n\n") ;
      }
    __builtin_va_start(ap,format);
    i = vfprintf(stderr, format, ap );
    __builtin_va_end(ap);
    return(i) ;
}

variable_types:
format
char *


decompiled_code:
_BOOL8 eprintf_utilisee()
{
return premiere == 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return premiere == 0;
}

original_code:
int eprintf_utilisee()
{
  return(premiere==0) ;
}


htonHeader

decompiled_code:
__int16 __fastcall htonHeader(__int16 a1, __int16 *a2)
{
__int16 v2; // edx^2
__int16 result; // ax

*a2 = _bswap_16(a1);
result = _bswap_16(v2);
a2[1] = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func2(__int16 a1, __int16 *a2)
{
__int16 v2; // edx^2
__int16 result; // ax

*a2 = func0(a1);
result = func0(v2);
a2[1] = result;
return result;
}

original_code:
void htonHeader(pkt_header head, char* buffer) {
    uint16_t type, len;
    type = htons(head.type);
    memcpy(buffer+0,&type,2);
    len = htons(head.length);
    memcpy(buffer+2,&len,2);
}

canonical_original_code:
void htonHeader(struct pkt_header head, char *buffer) {
    unsigned short type; unsigned short len;
    type = htons(head.type);
    memcpy(buffer+0,&type,2);
    len = htons(head.length);
    memcpy(buffer+2,&len,2);
}

variable_types: struct pkt_header { unsigned short type; unsigned short length; }

variable_types:
buffer
char *

variable_types:
type
unsigned short

variable_types:
len
unsigned short


htonProxyInfo

decompiled_code:
__int64 __fastcall htonProxyInfo(unsigned int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx
__int64 result; // rax

*(_DWORD *)a2 = _bswap_32(*a1);
*(_WORD *)(a2 + 4) = _bswap_16(*(_WORD *)(v2 + 4));
*(_DWORD *)(a2 + 6) = *(_DWORD *)(v3 + 6);
result = *(unsigned __int16 *)(v3 + 10);
*(_WORD *)(a2 + 10) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx
__int64 result; // rax

*(_DWORD *)a2 = func1(*a1);
*(_WORD *)(a2 + 4) = func0(*(_WORD *)(v2 + 4));
*(_DWORD *)(a2 + 6) = *(_DWORD *)(v3 + 6);
result = *(unsigned __int16 *)(v3 + 10);
*(_WORD *)(a2 + 10) = result;
return result;
}

original_code:
void htonProxyInfo(proxy_info* proxy, char* buffer) {
    uint32_t ip = htonl(proxy->ip);
    memcpy(buffer,&ip,4);
    uint16_t portno = htons(proxy->portno);
    memcpy(buffer+4,&portno,2);
    memcpy(buffer+6,&proxy->macaddr,6);
}

canonical_original_code:
void htonProxyInfo(struct proxy_info *proxy, char *buffer) {
    unsigned int ip = htonl(proxy->ip);
    memcpy(buffer,&ip,4);
    unsigned short portno = htons(proxy->portno);
    memcpy(buffer+4,&portno,2);
    memcpy(buffer+6,&proxy->macaddr,6);
}

variable_types: struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } *

variable_types:
ip
unsigned int

variable_types:
portno
unsigned short


htonLinkstate

decompiled_code:
__int64 __fastcall htonLinkstate(_DWORD *a1, __int16 *a2)
{
__int64 v3; // rcx
__int64 v4; // rsi
__int64 v5; // rcx
__int64 result; // rax
__int64 v7; // rcx
__int64 v8; // rbx
__int64 v9; // rbp
__int64 v10; // rsi

htonHeader(*a1, a2);
v4 = (__int64)(a2 + 3);
*(_WORD *)(v4 - 2) = _bswap_16(*(_WORD *)(v3 + 4));
result = htonProxyInfo((unsigned int *)(v5 + 8), v4);
v8 = *(_QWORD *)(v7 + 24);
if ( v8 )
{
v9 = (__int64)(a2 + 9);
do
{
htonProxyInfo((unsigned int *)v8, v9);
v10 = v9 + 12;
v9 += 36LL;
htonProxyInfo((unsigned int *)(v8 + 12), v10);
*(_DWORD *)(v9 - 12) = _bswap_32(*(_DWORD *)(v8 + 24));
result = htonll(*(_QWORD *)(v8 + 32));
*(_QWORD *)(v9 - 8) = result;
v8 = *(_QWORD *)(v8 + 40);
}
while ( v8 );
}
return result;
}

original_code:
void htonLinkstate(linkstate_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    uint16_t numNeighbors;
    numNeighbors = htons(pkt->numNeighbors);
    memcpy(buffer+4,&numNeighbors,2);
    htonProxyInfo(&pkt->source,buffer+6);
    linkstate_node* list = pkt->list;
    int i = 0;
    while (list != ((void *)0)) {
        htonProxyInfo(&list->local,buffer+18+36*i);
        htonProxyInfo(&list->remote,buffer+30+36*i);
        uint32_t linkweight;
        linkweight = htonl(list->linkweight);
        memcpy(buffer+42+36*i,&linkweight,4);
        uint64_t ID;
        ID = htonll(list->ID);
        memcpy(buffer+46+36*i,&ID,8);
        list = list->next;
        i++;
    }
}

canonical_original_code:
void htonLinkstate(struct linkstate_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    unsigned short numNeighbors;
    numNeighbors = htons(pkt->numNeighbors);
    memcpy(buffer+4,&numNeighbors,2);
    htonProxyInfo(&pkt->source,buffer+6);
    struct linkstate_node *list = pkt->list;
    int i = 0;
    while (list != ((void *)0)) {
        htonProxyInfo(&list->local,buffer+18+36*i);
        htonProxyInfo(&list->remote,buffer+30+36*i);
        unsigned int linkweight;
        linkweight = htonl(list->linkweight);
        memcpy(buffer+42+36*i,&linkweight,4);
        unsigned long ID;
        ID = htonll(list->ID);
        memcpy(buffer+46+36*i,&ID,8);
        list = list->next;
        i++;
    }
}

variable_types: struct linkstate_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; unsigned short numNeighbors; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } source; struct linkstate_node { struct proxy_info local; struct proxy_info remote; unsigned int linkweight; unsigned long ID; struct linkstate_node *next; } *list; } *

variable_types:
numNeighbors
unsigned short

variable_types: struct linkstate_node { struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; struct proxy_info remote; unsigned int linkweight; unsigned long ID; struct linkstate_node *next; } *

variable_types:
linkweight
unsigned int

variable_types:
ID
unsigned long

user_defined_types: struct linkstate_pkt { struct pkt_header head; unsigned short numNeighbors; struct proxy_info source; struct linkstate_node *list; }


htonData

decompiled_code:
const void *__fastcall htonData(_DWORD *a1, __int64 a2)
{
__int64 v2; // r8
void *v3; // rdi
__int64 v4; // rcx
__int64 v5; // rcx
const void *result; // rax

htonHeader(*a1, (__int16 *)a2);
v3 = (void *)((a2 + 12) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)(a2 + 4) = *(_QWORD *)(v2 + 8);
v5 = v4 - (_QWORD)v3;
result = (const void *)(v2 + 8 - v5);
*(_QWORD *)(a2 + 2044) = *(_QWORD *)(v2 + 2048);
qmemcpy(v3, result, 8LL * ((unsigned int)(v5 + 2048) >> 3));
return result;
}

canonical_decompiled_code:
const void *__fastcall func6(_DWORD *a1, __int64 a2)
{
__int64 v2; // r8
void *v3; // rdi
__int64 v4; // rcx
__int64 v5; // rcx
const void *result; // rax

func2(*a1, (__int16 *)a2);
v3 = (void *)((a2 + 12) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)(a2 + 4) = *(_QWORD *)(v2 + 8);
v5 = v4 - (_QWORD)v3;
result = (const void *)(v2 + 8 - v5);
*(_QWORD *)(a2 + 2044) = *(_QWORD *)(v2 + 2048);
qmemcpy(v3, result, 8LL * ((unsigned int)(v5 + 2048) >> 3));
return result;
}

original_code:
void htonData(data_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    memcpy(buffer+4,&pkt->data,2048);
}

canonical_original_code:
void htonData(struct data_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    memcpy(buffer+4,&pkt->data,2048);
}

variable_types: struct data_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; void *data; } *

user_defined_types: struct data_pkt { struct pkt_header head; void *data; }


htonLeave

decompiled_code:
__int64 __fastcall htonLeave(_DWORD *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rcx
__int64 result; // rax

htonHeader(*a1, (__int16 *)a2);
htonProxyInfo((unsigned int *)(v2 + 4), a2 + 4);
result = htonll(*(_QWORD *)(v3 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rcx
__int64 result; // rax

func2(*a1, (__int16 *)a2);
func3((unsigned int *)(v2 + 4), a2 + 4);
result = htonll(*(_QWORD *)(v3 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

original_code:
void htonLeave(leave_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    uint64_t ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

canonical_original_code:
void htonLeave(struct leave_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    unsigned long ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

variable_types: struct leave_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *

user_defined_types: struct leave_pkt { struct pkt_header head; struct proxy_info local; unsigned long ID; }


ntohLeave

decompiled_code:
char *__fastcall ntohLeave(__int64 a1)
{
char *v1; // r12
_WORD *v2; // r13
__int64 v3; // rax
__int64 v4; // rdi
void *v5; // rbp

v1 = (char *)malloc(0x18uLL);
v2 = ntohHeader((__int16 *)a1);
*(_DWORD *)v1 = *(_DWORD *)v2;
v3 = ntohProxyInfo(a1 + 4);
v4 = *(_QWORD *)(a1 + 16);
v5 = (void *)v3;
*(_QWORD *)(v1 + 4) = *(_QWORD *)v3;
*((_DWORD *)v1 + 3) = *(_DWORD *)(v3 + 8);
*((_QWORD *)v1 + 2) = htonll(v4);
free(v2);
free(v5);
return v1;
}

original_code:
leave_pkt* ntohLeave(char *buffer) {
    leave_pkt* pkt = malloc(sizeof(leave_pkt));
    pkt_header* head = ntohHeader(buffer);
    pkt->head = *head;
    proxy_info* local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    uint64_t ID;
    ID = htonll(*(uint64_t*)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

canonical_original_code:
struct leave_pkt *ntohLeave(char *buffer) {
    struct leave_pkt *pkt = malloc(sizeof(leave_pkt));
    struct pkt_header *head = ntohHeader(buffer);
    pkt->head = *head;
    struct proxy_info *local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    unsigned long ID;
    ID = htonll(*(unsigned long *)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

variable_types: struct pkt_header { unsigned short type; unsigned short length; } *

return_type: struct leave_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *


htonQuit

decompiled_code:
__int64 __fastcall htonQuit(_DWORD *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rcx
__int64 result; // rax

htonHeader(*a1, (__int16 *)a2);
htonProxyInfo((unsigned int *)(v2 + 4), a2 + 4);
result = htonll(*(_QWORD *)(v3 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rcx
__int64 result; // rax

func2(*a1, (__int16 *)a2);
func3((unsigned int *)(v2 + 4), a2 + 4);
result = htonll(*(_QWORD *)(v3 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

original_code:
void htonQuit(quit_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    uint64_t ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

canonical_original_code:
void htonQuit(struct quit_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    unsigned long ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

variable_types: struct quit_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *

user_defined_types: struct quit_pkt { struct pkt_header head; struct proxy_info local; unsigned long ID; }


ntohQuit

decompiled_code:
char *__fastcall ntohQuit(__int64 a1)
{
char *v1; // r12
_WORD *v2; // r13
__int64 v3; // rax
__int64 v4; // rdi
void *v5; // rbp

v1 = (char *)malloc(0x18uLL);
v2 = ntohHeader((__int16 *)a1);
*(_DWORD *)v1 = *(_DWORD *)v2;
v3 = ntohProxyInfo(a1 + 4);
v4 = *(_QWORD *)(a1 + 16);
v5 = (void *)v3;
*(_QWORD *)(v1 + 4) = *(_QWORD *)v3;
*((_DWORD *)v1 + 3) = *(_DWORD *)(v3 + 8);
*((_QWORD *)v1 + 2) = htonll(v4);
free(v2);
free(v5);
return v1;
}

original_code:
quit_pkt* ntohQuit(char *buffer) {
    quit_pkt* pkt = malloc(sizeof(quit_pkt));
    pkt_header* head = ntohHeader(buffer);
    pkt->head = *head;
    proxy_info* local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    uint64_t ID;
    ID = htonll(*(uint64_t*)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

canonical_original_code:
struct quit_pkt *ntohQuit(char *buffer) {
    struct quit_pkt *pkt = malloc(sizeof(quit_pkt));
    struct pkt_header *head = ntohHeader(buffer);
    pkt->head = *head;
    struct proxy_info *local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    unsigned long ID;
    ID = htonll(*(unsigned long *)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

return_type: struct quit_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *


gettimeid

decompiled_code:
__time_t gettimeid()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
unsigned long gettimeid(void) {
    struct timeval tim;
    gettimeofday(&tim, ((void *)0));
    return (tim.tv_sec) * 1000 + (tim.tv_usec)/1000;
}

canonical_original_code:
unsigned long gettimeid() {
    struct timeval tim;
    gettimeofday(&tim, ((void *)0));
    return (tim.tv_sec) * 1000 + (tim.tv_usec)/1000;
}

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

return_type: unsigned long


htonll

decompiled_code:
unsigned __int64 __fastcall htonll(unsigned __int64 a1)
{
if ( !typ_0 )
{
typ_0 = 1;
return _byteswap_uint64(a1);
}
if ( typ_0 != 2 )
return _byteswap_uint64(a1);
return a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
if ( !typ_0 )
{
typ_0 = 1;
return _byteswap_uint64(a1);
}
if ( typ_0 != 2 )
return _byteswap_uint64(a1);
return a1;
}

original_code:
unsigned long long htonll(unsigned long long src) {
  static int typ = 0;
  unsigned char c;
  union {
    unsigned long long ull;
    unsigned char c[8];
  } x;
  if (typ == 0) {
    x.ull = 0x01;
    typ = (x.c[7] == 0x01ULL) ? 2 : 1;
  }
  if (typ == 2)
    return src;
  x.ull = src;
  c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c;
  c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c;
  c = x.c[2]; x.c[2] = x.c[5]; x.c[5] = c;
  c = x.c[3]; x.c[3] = x.c[4]; x.c[4] = c;
  return x.ull;
}

variable_types:
src
unsigned long long

variable_types: typ int

variable_types:
c
unsigned char

return_type: unsigned long long


decompiled_code:
__int64 __fastcall comp_mac_addrs(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2) )
{
if ( ++v2 == 6 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2) )
{
if ( ++v2 == 6 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int comp_mac_addrs(uint8_t* mac1, uint8_t* mac2) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != mac2[i]) {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int comp_mac_addrs(unsigned char *mac1, unsigned char *mac2) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != mac2[i]) {
            return -1;
        }
    }
    return 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall comp_mac_zero(_BYTE *a1)
{
_BYTE *v1; // rax

v1 = a1 + 6;
while ( !*a1 )
{
if ( ++a1 == v1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
_BYTE *v1; // rax

v1 = a1 + 6;
while ( !*a1 )
{
if ( ++a1 == v1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int comp_mac_zero(uint8_t* mac1) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != 0) {
            return 0;
        }
    }
    return -1;
}

canonical_original_code:
int comp_mac_zero(unsigned char *mac1) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != 0) {
            return 0;
        }
    }
    return -1;
}


decompiled_code:
__int64 __fastcall ref_init(int a1, unsigned __int8 a2, int a3, unsigned __int8 *a4)
{
int v4; // er9
unsigned __int8 *v5; // rsi
int v6; // edi
int v7; // eax
int v8; // edx
int v9; // er8
__int64 result; // rax
int v11; // edx

v4 = a2;
ref_a = a1;
ref_r = a2;
ref_c = a3;
if ( a2 <= 3u )
{
result = 0LL;
}
else
{
v5 = a4;
v6 = 0;
do
{
v7 = v5[1];
v8 = *v5;
v9 = v6;
v6 += 4;
v5 += 4;
ref_state[v9 >> 2] = (v7 << 8) + (*(v5 - 2) << 16) + v8 + (*(v5 - 1) << 24);
}
while ( v6 != ((v4 - 4) & 0xFFFFFFFC) + 4 );
result = 4 * ((unsigned int)(v4 - 4) >> 2) + 4;
}
if ( (int)result < v4 )
ref_state[(int)result >> 2] = a4[(int)result];
if ( (int)result + 1 < v4 )
ref_state[(int)result >> 2] += a4[(int)result + 1] << 8;
v11 = result + 2;
if ( (int)result + 2 < v4 )
{
result = (int)result >> 2;
ref_state[result] += a4[v11] << 16;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned __int8 a2, int a3, unsigned __int8 *a4)
{
int v4; // er9
unsigned __int8 *v5; // rsi
int v6; // edi
int v7; // eax
int v8; // edx
int v9; // er8
__int64 result; // rax
int v11; // edx

v4 = a2;
ref_a = a1;
ref_r = a2;
ref_c = a3;
if ( a2 <= 3u )
{
result = 0LL;
}
else
{
v5 = a4;
v6 = 0;
do
{
v7 = v5[1];
v8 = *v5;
v9 = v6;
v6 += 4;
v5 += 4;
ref_state[v9 >> 2] = (v7 << 8) + (*(v5 - 2) << 16) + v8 + (*(v5 - 1) << 24);
}
while ( v6 != ((v4 - 4) & 0xFFFFFFFC) + 4 );
result = 4 * ((unsigned int)(v4 - 4) >> 2) + 4;
}
if ( (int)result < v4 )
ref_state[(int)result >> 2] = a4[(int)result];
if ( (int)result + 1 < v4 )
ref_state[(int)result >> 2] += a4[(int)result + 1] << 8;
v11 = result + 2;
if ( (int)result + 2 < v4 )
{
result = (int)result >> 2;
ref_state[result] += a4[v11] << 16;
}
return result;
}

original_code:
static void ref_init(uint32_t a, uint8_t r, uint32_t c, uint8_t const *seed)
{
    int i;
    ref_a = a;
    ref_r = r;
    ref_c = c;
    for (i = 0; i + 3 < r; i += 4)
        ref_state[i >> 2] = seed[i] + ((uint32_t)seed[i + 1] << 8) + ((uint32_t)seed[i + 2] << 16) + ((uint32_t)seed[i + 3] << 24);
    if (i < r) ref_state[i >> 2] = seed[i];
    if (i + 1 < r) ref_state[i >> 2] += (uint32_t)seed[i + 1] << 8;
    if (i + 2 < r) ref_state[i >> 2] += (uint32_t)seed[i + 2] << 16;
}

canonical_original_code:
static void ref_init(unsigned int a, unsigned char r, unsigned int c, unsigned char *seed)
{
    int i;
    ref_a = a;
    ref_r = r;
    ref_c = c;
    for (i = 0; i + 3 < r; i += 4)
        ref_state[i >> 2] = seed[i] + ((unsigned int)seed[i + 1] << 8) + ((unsigned int)seed[i + 2] << 16) + ((unsigned int)seed[i + 3] << 24);
    if (i < r) ref_state[i >> 2] = seed[i];
    if (i + 1 < r) ref_state[i >> 2] += (unsigned int)seed[i + 1] << 8;
    if (i + 2 < r) ref_state[i >> 2] += (unsigned int)seed[i + 2] << 16;
}

variable_types:
a
unsigned int

variable_types:
r
unsigned char

variable_types:
c
unsigned int

variable_types:
seed
unsigned char *


original_code:
static void dut_memrand(uint8_t *dst, int length, uint16_t (*genfn)(void))
{
    int i;
    uint8_t *p = dst;
    for (i = 0; i < length; i += 2)
    {
        uint16_t x = genfn();
        *p++ = x & 0xff;
        *p++ = x >> 8;
    }
}

canonical_original_code:
static void dut_memrand(unsigned char *dst, int length, unsigned short (*genfn)())
{
    int i;
    unsigned char *p = dst;
    for (i = 0; i < length; i += 2)
    {
        unsigned short x = genfn();
        *p++ = x & 0xff;
        *p++ = x >> 8;
    }
}

variable_types:
dst
unsigned char *

variable_types: length int

variable_types:
genfn
unsigned short (*)()

variable_types:
p
unsigned char *

variable_types:
x
unsigned short


decompiled_code:
__int64 __fastcall ref_memtest(unsigned __int8 *a1, int a2, __int64 a3)
{
int v3; // ecx
__int64 result; // rax
unsigned __int64 v5; // r13
int v6; // esi
int v7; // er14
__int64 v8; // r10
int v9; // ebp
int v10; // edx
unsigned int v11; // er9
char v12; // dl
__int64 v13; // rbx
unsigned __int64 v14; // r12
__int64 v15; // r8
int v16; // ecx
unsigned int v17; // [rsp+Ch] [rbp-4Ch]
unsigned int v19; // [rsp+14h] [rbp-44h]

v3 = a2;
result = (unsigned int)ref_a;
v5 = (unsigned int)ref_c;
v6 = (unsigned __int8)ref_r;
v19 = ref_a;
if ( v3 > 0 )
{
v7 = 0;
v8 = (unsigned int)ref_a;
v17 = 8 * (unsigned __int8)ref_r;
while ( 1 )
{
result = v17;
v9 = 0;
if ( v6 )
break;
LABEL_14:
v7 += v6;
if ( a2 <= v7 )
goto LABEL_15;
}
while ( 1 )
{
v11 = *a1;
v13 = v9 >> 2;
v14 = (unsigned int)v5 + v8 * (unsigned int)ref_state[v13];
v12 = result;
v15 = (unsigned int)(v5 + v8 * ref_state[v13]);
if ( (int)result > 31 )
{
v10 = a1[1];
a1 += 4;
v11 += (v10 << 8) + (*(a1 - 2) << 16) + (*(a1 - 1) << 24);
v12 = 32;
}
else
{
v15 = (unsigned int)v14 & ~(-1 << result);
if ( (int)result <= 8 )
{
++a1;
if ( v11 != (_DWORD)v15 )
{
LABEL_11:
fprintf(stderr, "0x%llx: 0x%08x != 0x%08x\n", a3 + v9 + (__int64)v7, v11, v15);
fprintf(
stderr,
"t=0x%010llx=(a=0x%04x * s[%d]=0x%08x + c=0x%04x)\n",
v14,
v19,
(unsigned int)v9,
(unsigned int)ref_state[v13],
v5);
exit(1);
}
goto LABEL_7;
}
v11 += a1[1] << 8;
if ( (int)result <= 16 )
{
a1 += 2;
}
else
{
v16 = a1[2];
a1 += 3;
v11 += v16 << 16;
}
}
if ( v11 != (_DWORD)v15 )
goto LABEL_11;
LABEL_7:
v9 += 4;
ref_state[v13] = v11;
result = (unsigned int)(result - 32);
v5 = v14 >> v12;
if ( v6 <= v9 )
goto LABEL_14;
}
}
LABEL_15:
ref_c = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, int a2, __int64 a3)
{
int v3; // ecx
__int64 result; // rax
unsigned __int64 v5; // r13
int v6; // esi
int v7; // er14
__int64 v8; // r10
int v9; // ebp
int v10; // edx
unsigned int v11; // er9
char v12; // dl
__int64 v13; // rbx
unsigned __int64 v14; // r12
__int64 v15; // r8
int v16; // ecx
unsigned int v17; // [rsp+Ch] [rbp-4Ch]
unsigned int v19; // [rsp+14h] [rbp-44h]

v3 = a2;
result = (unsigned int)ref_a;
v5 = (unsigned int)ref_c;
v6 = (unsigned __int8)ref_r;
v19 = ref_a;
if ( v3 > 0 )
{
v7 = 0;
v8 = (unsigned int)ref_a;
v17 = 8 * (unsigned __int8)ref_r;
while ( 1 )
{
result = v17;
v9 = 0;
if ( v6 )
break;
LABEL_14:
v7 += v6;
if ( a2 <= v7 )
goto LABEL_15;
}
while ( 1 )
{
v11 = *a1;
v13 = v9 >> 2;
v14 = (unsigned int)v5 + v8 * (unsigned int)ref_state[v13];
v12 = result;
v15 = (unsigned int)(v5 + v8 * ref_state[v13]);
if ( (int)result > 31 )
{
v10 = a1[1];
a1 += 4;
v11 += (v10 << 8) + (*(a1 - 2) << 16) + (*(a1 - 1) << 24);
v12 = 32;
}
else
{
v15 = (unsigned int)v14 & ~(-1 << result);
if ( (int)result <= 8 )
{
++a1;
if ( v11 != (_DWORD)v15 )
{
LABEL_11:
fprintf(stderr, "0x%llx: 0x%08x != 0x%08x\n", a3 + v9 + (__int64)v7, v11, v15);
fprintf(
stderr,
"t=0x%010llx=(a=0x%04x * s[%d]=0x%08x + c=0x%04x)\n",
v14,
v19,
(unsigned int)v9,
(unsigned int)ref_state[v13],
v5);
exit(1);
}
goto LABEL_7;
}
v11 += a1[1] << 8;
if ( (int)result <= 16 )
{
a1 += 2;
}
else
{
v16 = a1[2];
a1 += 3;
v11 += v16 << 16;
}
}
if ( v11 != (_DWORD)v15 )
goto LABEL_11;
LABEL_7:
v9 += 4;
ref_state[v13] = v11;
result = (unsigned int)(result - 32);
v5 = v14 >> v12;
if ( v6 <= v9 )
goto LABEL_14;
}
}
LABEL_15:
ref_c = v5;
return result;
}

original_code:
static void ref_memtest(uint8_t const *src, int length, uint64_t count)
{
    unsigned int a = ref_a;
    unsigned int c = ref_c;
    int r = ref_r;
    int i, j;
    for (i = 0; i < length; i += r)
    {
        for (j = 0; j < r; j += 4)
        {
            uint32_t dut;
            uint32_t x = ref_state[j >> 2];
            uint64_t t;
            int bits;
            t = (uint64_t)x * a + c;
            bits = (r - j) * 8;
            if (bits >= 32)
            {
                bits = 32;
                x = (uint32_t)t;
                dut = src[0] + ((uint32_t)src[1] << 8) + ((uint32_t)src[2] << 16) + ((uint32_t)src[3] << 24);
                src += 4;
            }
            else
            {
                x = (uint32_t)t & ~(0xffffffff << bits);
                dut = *src++;
                if (bits > 8) dut += (uint32_t)*src++ << 8;
                if (bits > 16) dut += (uint32_t)*src++ << 16;
            }
            if (dut != x)
            {
                fprintf(stderr, "0x%llx: 0x%08x != 0x%08x\n", count + i+j, dut, x);
                fprintf(stderr, "t=0x%010llx=(a=0x%04x * s[%d]=0x%08x + c=0x%04x)\n", t, a, j, ref_state[j >> 2], c);
                exit(1);
            }
            c = (uint32_t)(t >> bits);
            ref_state[j >> 2] = x;
        }
    }
    ref_c = c;
}

canonical_original_code:
static void ref_memtest(unsigned char *src, int length, unsigned long count)
{
    unsigned int a = ref_a;
    unsigned int c = ref_c;
    int r = ref_r;
    int i; int j;
    for (i = 0; i < length; i += r)
    {
        for (j = 0; j < r; j += 4)
        {
            unsigned int dut;
            unsigned int x = ref_state[j >> 2];
            unsigned long t;
            int bits;
            t = (unsigned long)x * a + c;
            bits = (r - j) * 8;
            if (bits >= 32)
            {
                bits = 32;
                x = (unsigned int)t;
                dut = src[0] + ((unsigned int)src[1] << 8) + ((unsigned int)src[2] << 16) + ((unsigned int)src[3] << 24);
                src += 4;
            }
            else
            {
                x = (unsigned int)t & ~(0xffffffff << bits);
                dut = *src++;
                if (bits > 8) dut += (unsigned int)*src++ << 8;
                if (bits > 16) dut += (unsigned int)*src++ << 16;
            }
            if (dut != x)
            {
                fprintf(stderr, "0x%llx: 0x%08x != 0x%08x\n", count + i+j, dut, x);
                fprintf(stderr, "t=0x%010llx=(a=0x%04x * s[%d]=0x%08x + c=0x%04x)\n", t, a, j, ref_state[j >> 2], c);
                exit(1);
            }
            c = (unsigned int)(t >> bits);
            ref_state[j >> 2] = x;
        }
    }
    ref_c = c;
}

variable_types:
src
unsigned char *

variable_types:
count
unsigned long

variable_types: r int

variable_types: j int

variable_types:
dut
unsigned int

variable_types:
x
unsigned int

variable_types:
t
unsigned long

variable_types: bits int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // eax
char *v5; // r15
unsigned __int64 v7; // rax
char *v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // rax
unsigned int v12; // ebx
__int128 *v13; // r15
__int64 v14; // rdx
const char *v15; // rdi
unsigned __int64 v16; // r10
unsigned __int64 v17; // r8
__int64 v18; // [rsp+0h] [rbp-90h]
char *v19; // [rsp+8h] [rbp-88h]
void *v20; // [rsp+8h] [rbp-88h]
unsigned int v21; // [rsp+14h] [rbp-7Ch]
char *v22; // [rsp+18h] [rbp-78h]
int v23; // [rsp+20h] [rbp-70h]
unsigned __int8 v24; // [rsp+25h] [rbp-6Bh]
unsigned __int16 v25; // [rsp+26h] [rbp-6Ah]
int v26; // [rsp+34h] [rbp-5Ch] BYREF
__int128 v27[5]; // [rsp+38h] [rbp-58h] BYREF

LOBYTE(v3) = 0;
v18 = 0LL;
v19 = 0LL;
v23 = 0;
v22 = 0LL;
v24 = 0;
v25 = 1;
v21 = 0;
v27[0] = 0LL;
v27[1] = 0LL;
LABEL_2:
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "e:W:w:n:u:a:r:s:c:gth");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'W':
v19 = (char *)&multiplier_table;
v18 = strtol(optarg, 0LL, 0);
continue;
case 'a':
v21 = strtoul(optarg, 0LL, 0);
continue;
case 'c':
v25 = strtoul(optarg, 0LL, 0);
continue;
case 'e':
v7 = strtol(optarg, 0LL, 0);
if ( v7 > 5 )
{
fprintf(stderr, "Only %d known example functions.\n", 6LL);
exit(1);
}
v22 = (char *)&examples + 40 * v7;
v21 = *((_DWORD *)v22 + 4);
v24 = v22[20];
continue;
case 'g':
v23 = 0;
continue;
case 'h':
usage();
return 0;
case 'n':
v19 = (char *)&multiplier_table + 1056;
v18 = strtol(optarg, 0LL, 0);
continue;
case 'r':
v24 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v5 = optarg;
if ( !strncasecmp(optarg, "0x", 2uLL) )
v5 += 2;
v3 = 0LL;
break;
case 't':
v23 = 1;
continue;
case 'u':
v19 = (char *)&multiplier_table + 1584;
v18 = strtol(optarg, 0LL, 0);
continue;
case 'w':
v19 = (char *)&multiplier_table + 528;
v18 = strtol(optarg, 0LL, 0);
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
usage();
exit(1);
}
while ( (unsigned int)_isoc99_sscanf(v5, "%02x", &v26) == 1 )
{
v5 += 2;
*((_BYTE *)v27 + v3++) = v26;
if ( v3 == 32 )
goto LABEL_2;
}
memset((char *)v27 + (int)v3, 0, (unsigned int)(32 - v3));
}
if ( (unsigned __int8)(v24 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v21 )
{
if ( !v19 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
v8 = &v19[16 * v24];
v9 = *(unsigned int *)v8;
if ( v18 < 0 )
v18 += (int)v9;
if ( (unsigned int)v9 <= (unsigned int)v18 )
{
if ( (int)v9 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v24);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v9, v24);
LABEL_51:
exit(1);
}
v21 = *(_DWORD *)(*((_QWORD *)v8 + 1) + 4 * v18);
}
if ( v22 )
{
(*(void (__fastcall **)(__int128 *, _QWORD))v22)(v27, (unsigned __int8)v3);
v10 = *((_QWORD *)v22 + 3);
v11 = 0LL;
do
{
*((_BYTE *)v27 + v11) = *(_BYTE *)(v10 + v11);
++v11;
}
while ( v24 > (int)v11 );
v20 = (void *)*((_QWORD *)v22 + 1);
v12 = **((unsigned __int16 **)v22 + 4);
}
else
{
v12 = v25;
rand8_init((unsigned __int16)v21, v24, v25, v27);
if ( (unsigned __int16)(v21 >> 8) )
{
v20 = &rand16_9bit;
if ( (unsigned __int16)(v21 >> 8) != 1 )
{
v20 = &rand16_16bit;
if ( !BYTE1(v21) )
{
rand8_init((unsigned __int16)((v21 >> 8) | (unsigned __int8)v21), v24, v25, v27);
v20 = &rand16_8z8bit;
}
}
}
else
{
v20 = &rand16_8bit;
}
}
v13 = v27;
fprintf(stderr, "b=256 a=0x%04x r=%d c=0x%04x s=0x", v21, v24, v12);
do
{
v14 = *(unsigned __int8 *)v13;
v13 = (__int128 *)((char *)v13 + 1);
fprintf(stderr, "%02x", v14);
}
while ( v13 != (__int128 *)((char *)v27 + v24) );
fputc(10, stderr);
if ( (unsigned __int16)v21 + 255 * (unsigned int)(unsigned __int8)v21 - 1 > 0xFFFF )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
goto LABEL_51;
}
v15 = argv[optind];
if ( v23 == 1 )
{
v16 = 0x40000000LL;
if ( v15 )
v16 = strtoull(v15, 0LL, 0);
test_loop(v16, v20, v21, v24, v12, v27);
}
else
{
v17 = -1LL;
if ( v15 )
v17 = strtoull(v15, 0LL, 0);
generate_loop(v17, v20);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // eax
char *v5; // r15
unsigned __int64 v7; // rax
char *v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // rax
unsigned int v12; // ebx
__int128 *v13; // r15
__int64 v14; // rdx
const char *v15; // rdi
unsigned __int64 v16; // r10
unsigned __int64 v17; // r8
__int64 v18; // [rsp+0h] [rbp-90h]
char *v19; // [rsp+8h] [rbp-88h]
void *v20; // [rsp+8h] [rbp-88h]
unsigned int v21; // [rsp+14h] [rbp-7Ch]
char *v22; // [rsp+18h] [rbp-78h]
int v23; // [rsp+20h] [rbp-70h]
unsigned __int8 v24; // [rsp+25h] [rbp-6Bh]
unsigned __int16 v25; // [rsp+26h] [rbp-6Ah]
int v26; // [rsp+34h] [rbp-5Ch] BYREF
__int128 v27[5]; // [rsp+38h] [rbp-58h] BYREF

LOBYTE(v3) = 0;
v18 = 0LL;
v19 = 0LL;
v23 = 0;
v22 = 0LL;
v24 = 0;
v25 = 1;
v21 = 0;
v27[0] = 0LL;
v27[1] = 0LL;
LABEL_2:
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "e:W:w:n:u:a:r:s:c:gth");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'W':
v19 = (char *)&multiplier_table;
v18 = strtol(optarg, 0LL, 0);
continue;
case 'a':
v21 = strtoul(optarg, 0LL, 0);
continue;
case 'c':
v25 = strtoul(optarg, 0LL, 0);
continue;
case 'e':
v7 = strtol(optarg, 0LL, 0);
if ( v7 > 5 )
{
fprintf(stderr, "Only %d known example functions.\n", 6LL);
exit(1);
}
v22 = (char *)&examples + 40 * v7;
v21 = *((_DWORD *)v22 + 4);
v24 = v22[20];
continue;
case 'g':
v23 = 0;
continue;
case 'h':
func3();
return 0;
case 'n':
v19 = (char *)&multiplier_table + 1056;
v18 = strtol(optarg, 0LL, 0);
continue;
case 'r':
v24 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v5 = optarg;
if ( !strncasecmp(optarg, "0x", 2uLL) )
v5 += 2;
v3 = 0LL;
break;
case 't':
v23 = 1;
continue;
case 'u':
v19 = (char *)&multiplier_table + 1584;
v18 = strtol(optarg, 0LL, 0);
continue;
case 'w':
v19 = (char *)&multiplier_table + 528;
v18 = strtol(optarg, 0LL, 0);
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
func3();
exit(1);
}
while ( (unsigned int)_isoc99_sscanf(v5, "%02x", &v26) == 1 )
{
v5 += 2;
*((_BYTE *)v27 + v3++) = v26;
if ( v3 == 32 )
goto LABEL_2;
}
memset((char *)v27 + (int)v3, 0, (unsigned int)(32 - v3));
}
if ( (unsigned __int8)(v24 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v21 )
{
if ( !v19 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
v8 = &v19[16 * v24];
v9 = *(unsigned int *)v8;
if ( v18 < 0 )
v18 += (int)v9;
if ( (unsigned int)v9 <= (unsigned int)v18 )
{
if ( (int)v9 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v24);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v9, v24);
LABEL_51:
exit(1);
}
v21 = *(_DWORD *)(*((_QWORD *)v8 + 1) + 4 * v18);
}
if ( v22 )
{
(*(void (__fastcall **)(__int128 *, _QWORD))v22)(v27, (unsigned __int8)v3);
v10 = *((_QWORD *)v22 + 3);
v11 = 0LL;
do
{
*((_BYTE *)v27 + v11) = *(_BYTE *)(v10 + v11);
++v11;
}
while ( v24 > (int)v11 );
v20 = (void *)*((_QWORD *)v22 + 1);
v12 = **((unsigned __int16 **)v22 + 4);
}
else
{
v12 = v25;
rand8_init((unsigned __int16)v21, v24, v25, v27);
if ( (unsigned __int16)(v21 >> 8) )
{
v20 = &rand16_9bit;
if ( (unsigned __int16)(v21 >> 8) != 1 )
{
v20 = &rand16_16bit;
if ( !BYTE1(v21) )
{
rand8_init((unsigned __int16)((v21 >> 8) | (unsigned __int8)v21), v24, v25, v27);
v20 = &rand16_8z8bit;
}
}
}
else
{
v20 = &rand16_8bit;
}
}
v13 = v27;
fprintf(stderr, "b=256 a=0x%04x r=%d c=0x%04x s=0x", v21, v24, v12);
do
{
v14 = *(unsigned __int8 *)v13;
v13 = (__int128 *)((char *)v13 + 1);
fprintf(stderr, "%02x", v14);
}
while ( v13 != (__int128 *)((char *)v27 + v24) );
fputc(10, stderr);
if ( (unsigned __int16)v21 + 255 * (unsigned int)(unsigned __int8)v21 - 1 > 0xFFFF )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
goto LABEL_51;
}
v15 = argv[optind];
if ( v23 == 1 )
{
v16 = 0x40000000LL;
if ( v15 )
v16 = strtoull(v15, 0LL, 0);
test_loop(v16, v20, v21, v24, v12, v27);
}
else
{
v17 = -1LL;
if ( v15 )
v17 = strtoull(v15, 0LL, 0);
generate_loop(v17, v20);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    uint16_t a = 0;
    uint8_t r = 0;
    int quick = 0;
    tabptr_t const *table = ((void *)0);
    long tab_index = 0;
    uint8_t a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned short a = 0;
    unsigned char r = 0;
    int quick = 0;
    struct tabptr_t *table = ((void *)0);
    long tab_index = 0;
    unsigned char a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned int)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
unsigned short

variable_types: quick int

variable_types: struct tabptr_t { int len; unsigned int *tab; } *

variable_types: optc int


hash

original_code:
static uint8_t hash(uint8_t *out, uint8_t olen, uint8_t const *in, uint8_t ilen)
{
    uint8_t i, l;
    uint8_t *end = out + olen;
    uint16_t seed = 0x5555;
    l = ilen + olen;
    for (i = 0; i < l; i++)
    {
        seed += i;
        if (i < ilen) seed += *in++;
        if (i > olen) seed += *out << 8;
        seed = (seed ^ (seed >> 11)) * 0xe9;
        *out++ = seed >> 8;
        if (out >= end)
            out -= olen;
    }
    return seed & 0xff;
}

canonical_original_code:
static unsigned char hash(unsigned char *out, unsigned char olen, unsigned char *in, unsigned char ilen)
{
    unsigned char i; unsigned char l;
    unsigned char *end = out + olen;
    unsigned short seed = 0x5555;
    l = ilen + olen;
    for (i = 0; i < l; i++)
    {
        seed += i;
        if (i < ilen) seed += *in++;
        if (i > olen) seed += *out << 8;
        seed = (seed ^ (seed >> 11)) * 0xe9;
        *out++ = seed >> 8;
        if (out >= end)
            out -= olen;
    }
    return seed & 0xff;
}

variable_types:
out
unsigned char *

variable_types:
olen
unsigned char

variable_types:
in
unsigned char *

variable_types:
ilen
unsigned char

variable_types:
i
unsigned char

variable_types:
l
unsigned char

variable_types:
end
unsigned char *

variable_types:
seed
unsigned short

return_type: unsigned char


decompiled_code:
__int16 __fastcall basicrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = hash(&rand_state, 8u, a1, a2);
byte_6A2 = 0;
HIBYTE(result) = 85;
word_6A0 = result;
return result;
}

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

LOBYTE(result) = func0(&rand_state, 8u, a1, a2);
byte_6A2 = 0;
HIBYTE(result) = 85;
word_6A0 = result;
return result;
}

original_code:
void basicrand_seed(void const *s, uint8_t l)
{
    rand_state.c = 0x5500 | hash(rand_state.x, sizeof(rand_state.x), s, l);
    rand_state.i = 0;
}

canonical_original_code:
void basicrand_seed(void *s, unsigned char l)
{
    rand_state.c = 0x5500 | hash(rand_state.x, sizeof(rand_state.x), s, l);
    rand_state.i = 0;
}

variable_types:
s
void *


basicrand

decompiled_code:
__int64 basicrand()
{
__int64 v0; // r9
int v1; // er8
int v2; // edx
int v3; // edi
unsigned __int16 v4; // cx
int v5; // eax
int v6; // eax
__int16 v7; // r10
__int64 result; // rax

v0 = (unsigned __int8)byte_6A2;
v1 = (unsigned __int8)byte_6A2 + 1;
v2 = (unsigned __int8)rand_state[(unsigned __int8)byte_6A2];
v3 = (unsigned __int8)rand_state[v1];
byte_6A2 = (byte_6A2 + 2) & 6;
v4 = word_6A0 + 23 * v2;
rand_state[v0] = v4;
v5 = 23 * v3 + 220 * v2;
HIWORD(v2) = (unsigned int)(23 * v2) >> 16;
LOWORD(v2) = HIBYTE(v4);
v6 = v2 + v5;
rand_state[(unsigned __int8)v1] = v6;
v7 = BYTE1(v6);
result = (unsigned __int8)v4 | (unsigned int)(v6 << 8);
word_6A0 = v7 + 220 * v3;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r9
int v1; // er8
int v2; // edx
int v3; // edi
unsigned __int16 v4; // cx
int v5; // eax
int v6; // eax
__int16 v7; // r10
__int64 result; // rax

v0 = (unsigned __int8)byte_6A2;
v1 = (unsigned __int8)byte_6A2 + 1;
v2 = (unsigned __int8)rand_state[(unsigned __int8)byte_6A2];
v3 = (unsigned __int8)rand_state[v1];
byte_6A2 = (byte_6A2 + 2) & 6;
v4 = word_6A0 + 23 * v2;
rand_state[v0] = v4;
v5 = 23 * v3 + 220 * v2;
HIWORD(v2) = (unsigned int)(23 * v2) >> 16;
LOWORD(v2) = HIBYTE(v4);
v6 = v2 + v5;
rand_state[(unsigned __int8)v1] = v6;
v7 = BYTE1(v6);
result = (unsigned __int8)v4 | (unsigned int)(v6 << 8);
word_6A0 = v7 + 220 * v3;
return result;
}

original_code:
uint16_t basicrand(void)
{
    uint8_t x, y;
    uint16_t c;
    uint8_t i;
    c = rand_state.c;
    i = rand_state.i;
    x = rand_state.x[i + 0];
    y = rand_state.x[i + 1];
    do { uint16_t t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(x))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xdc17 >> 8)) * (uint8_t)(x))); x = t & 0xff; } while (0);
    do { uint16_t t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(y))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xdc17 >> 8)) * (uint8_t)(y))); y = t & 0xff; } while (0);
    rand_state.x[i++] = x;
    rand_state.x[i++] = y;
    i &= 6;
    rand_state.c = c;
    rand_state.i = i;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short basicrand()
{
    unsigned char x; unsigned char y;
    unsigned short c;
    unsigned char i;
    c = rand_state.c;
    i = rand_state.i;
    x = rand_state.x[i + 0];
    y = rand_state.x[i + 1];
    do { unsigned short t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(x))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xdc17 >> 8)) * (unsigned char)(x))); x = t & 0xff; } while (0);
    do { unsigned short t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(y))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xdc17 >> 8)) * (unsigned char)(y))); y = t & 0xff; } while (0);
    rand_state.x[i++] = x;
    rand_state.x[i++] = y;
    i &= 6;
    rand_state.c = c;
    rand_state.i = i;
    return (y << 8) | x;
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types:
c
unsigned short

variable_types:
t
unsigned short

return_type: unsigned short


decompiled_code:
__int16 __fastcall newrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = hash(&byte_68F, 3u, a1, a2);
byte_68E = 0;
HIBYTE(result) = 85;
newrand_state = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = func0(&byte_68F, 3u, a1, a2);
byte_68E = 0;
HIBYTE(result) = 85;
newrand_state = result;
return result;
}

original_code:
void newrand_seed(void const *s, uint8_t l)
{
    newrand_state.c0 = 0x5500 | hash(newrand_state.x, sizeof(newrand_state.x), s, l);
    newrand_state.c1 = 0;
}

canonical_original_code:
void newrand_seed(void *s, unsigned char l)
{
    newrand_state.c0 = 0x5500 | hash(newrand_state.x, sizeof(newrand_state.x), s, l);
    newrand_state.c1 = 0;
}


newrand

decompiled_code:
__int64 newrand()
{
int v0; // esi
int v1; // edx
unsigned __int16 v2; // cx
int v3; // eax
unsigned int v4; // edx

v0 = (unsigned __int8)byte_690;
v1 = (unsigned __int8)byte_690 << 6;
v2 = 200 * (unsigned __int8)byte_690;
byte_690 = -56 * byte_68F + newrand_state;
v3 = (unsigned __int8)(-56 * byte_68F + newrand_state);
v4 = ((unsigned int)(((16580608 * (unsigned __int8)byte_68F) | (unsigned __int16)(200 * (unsigned __int8)byte_68F))
+ ((unsigned __int16)newrand_state | ((unsigned __int8)byte_68E << 16))) >> 8)
+ (v2 | ((v0 + 4 * (v1 - v0)) << 16));
newrand_state = v4 >> 8;
byte_68E = HIBYTE(v4);
LOBYTE(v2) = byte_691;
byte_691 = v4;
byte_68F = v2;
return (v4 << 8) | v3;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // esi
int v1; // edx
unsigned __int16 v2; // cx
int v3; // eax
unsigned int v4; // edx

v0 = (unsigned __int8)byte_690;
v1 = (unsigned __int8)byte_690 << 6;
v2 = 200 * (unsigned __int8)byte_690;
byte_690 = -56 * byte_68F + newrand_state;
v3 = (unsigned __int8)(-56 * byte_68F + newrand_state);
v4 = ((unsigned int)(((16580608 * (unsigned __int8)byte_68F) | (unsigned __int16)(200 * (unsigned __int8)byte_68F))
+ ((unsigned __int16)newrand_state | ((unsigned __int8)byte_68E << 16))) >> 8)
+ (v2 | ((v0 + 4 * (v1 - v0)) << 16));
newrand_state = v4 >> 8;
byte_68E = HIBYTE(v4);
LOBYTE(v2) = byte_691;
byte_691 = v4;
byte_68F = v2;
return (v4 << 8) | v3;
}

original_code:
uint16_t newrand(void)
{
    uint8_t x, y, z;
    uint32_t c;
    c = newrand_state.c0 | ((uint32_t)newrand_state.c1 << 16);
    x = newrand_state.x[0];
    y = newrand_state.x[1];
    z = newrand_state.x[2];
    do { uint32_t t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(x))); t |= (uint32_t)((uint16_t)((uint8_t)((0xfd00c8ul >> 16)) * (uint8_t)(x))) << 16; t += c; c = t >> 8; x = t & 0xff; } while (0);
    do { uint32_t t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(y))); t |= (uint32_t)((uint16_t)((uint8_t)((0xfd00c8ul >> 16)) * (uint8_t)(y))) << 16; t += c; c = t >> 8; y = t & 0xff; } while (0);
    newrand_state.c0 = (uint16_t)c;
    newrand_state.c1 = (uint8_t)(c >> 16);
    newrand_state.x[0] = z;
    newrand_state.x[1] = x;
    newrand_state.x[2] = y;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short newrand()
{
    unsigned char x; unsigned char y; unsigned char z;
    unsigned int c;
    c = newrand_state.c0 | ((unsigned int)newrand_state.c1 << 16);
    x = newrand_state.x[0];
    y = newrand_state.x[1];
    z = newrand_state.x[2];
    do { unsigned int t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(x))); t |= (unsigned int)((unsigned short)((unsigned char)((0xfd00c8ul >> 16)) * (unsigned char)(x))) << 16; t += c; c = t >> 8; x = t & 0xff; } while (0);
    do { unsigned int t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(y))); t |= (unsigned int)((unsigned short)((unsigned char)((0xfd00c8ul >> 16)) * (unsigned char)(y))) << 16; t += c; c = t >> 8; y = t & 0xff; } while (0);
    newrand_state.c0 = (unsigned short)c;
    newrand_state.c1 = (unsigned char)(c >> 16);
    newrand_state.x[0] = z;
    newrand_state.x[1] = x;
    newrand_state.x[2] = y;
    return (y << 8) | x;
}

variable_types:
z
unsigned char

variable_types:
c
unsigned int

variable_types:
t
unsigned int


decompiled_code:
__int16 __fastcall tinyrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = hash(&tinyrand_state, 2u, a1, a2);
HIBYTE(result) = 85;
word_68A = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func5(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = func0(&tinyrand_state, 2u, a1, a2);
HIBYTE(result) = 85;
word_68A = result;
return result;
}

original_code:
void tinyrand_seed(void const *s, uint8_t l)
{
    tinyrand_state.c = 0x5500 | hash(tinyrand_state.x, sizeof(tinyrand_state.x), s, l);
}

canonical_original_code:
void tinyrand_seed(void *s, unsigned char l)
{
    tinyrand_state.c = 0x5500 | hash(tinyrand_state.x, sizeof(tinyrand_state.x), s, l);
}


tinyrand

decompiled_code:
__int64 tinyrand()
{
int v0; // esi
unsigned __int16 v1; // cx
int v2; // eax
int v3; // edx
int v4; // eax
int v5; // eax
__int16 v6; // di
__int64 result; // rax

v0 = (unsigned __int8)tinyrand_state;
v1 = word_68A + 7 * (unsigned __int8)tinyrand_state;
v2 = 205 * (unsigned __int8)tinyrand_state;
HIWORD(v3) = (7 * (unsigned int)(unsigned __int8)tinyrand_state) >> 16;
tinyrand_state = word_68A + 7 * tinyrand_state;
v4 = v0 + v2;
LOWORD(v0) = (unsigned __int8)byte_689;
LOWORD(v3) = HIBYTE(v1);
v5 = v3 + v4 + 8 * (unsigned __int8)byte_689 - (unsigned __int8)byte_689;
LOWORD(v3) = 41 * (unsigned __int8)byte_689;
byte_689 = v5;
v6 = BYTE1(v5);
result = (unsigned __int8)v1 | (unsigned int)(v5 << 8);
word_68A = v6 + v0 + 5 * v3;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // esi
unsigned __int16 v1; // cx
int v2; // eax
int v3; // edx
int v4; // eax
int v5; // eax
__int16 v6; // di
__int64 result; // rax

v0 = (unsigned __int8)tinyrand_state;
v1 = word_68A + 7 * (unsigned __int8)tinyrand_state;
v2 = 205 * (unsigned __int8)tinyrand_state;
HIWORD(v3) = (7 * (unsigned int)(unsigned __int8)tinyrand_state) >> 16;
tinyrand_state = word_68A + 7 * tinyrand_state;
v4 = v0 + v2;
LOWORD(v0) = (unsigned __int8)byte_689;
LOWORD(v3) = HIBYTE(v1);
v5 = v3 + v4 + 8 * (unsigned __int8)byte_689 - (unsigned __int8)byte_689;
LOWORD(v3) = 41 * (unsigned __int8)byte_689;
byte_689 = v5;
v6 = BYTE1(v5);
result = (unsigned __int8)v1 | (unsigned int)(v5 << 8);
word_68A = v6 + v0 + 5 * v3;
return result;
}

original_code:
uint16_t tinyrand(void)
{
    uint8_t x, y;
    uint16_t c;
    c = tinyrand_state.c;
    x = tinyrand_state.x[0];
    y = tinyrand_state.x[1];
    do { uint16_t t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(x))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xce07 >> 8)) * (uint8_t)(x))); x = t & 0xff; } while (0);
    do { uint16_t t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(y))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xce07 >> 8)) * (uint8_t)(y))); y = t & 0xff; } while (0);
    tinyrand_state.c = c;
    tinyrand_state.x[0] = x;
    tinyrand_state.x[1] = y;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short tinyrand()
{
    unsigned char x; unsigned char y;
    unsigned short c;
    c = tinyrand_state.c;
    x = tinyrand_state.x[0];
    y = tinyrand_state.x[1];
    do { unsigned short t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(x))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xce07 >> 8)) * (unsigned char)(x))); x = t & 0xff; } while (0);
    do { unsigned short t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(y))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xce07 >> 8)) * (unsigned char)(y))); y = t & 0xff; } while (0);
    tinyrand_state.c = c;
    tinyrand_state.x[0] = x;
    tinyrand_state.x[1] = y;
    return (y << 8) | x;
}


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

result = (unsigned __int8)hash(fastrand_state, 6u, a1, a2) | 0x80u;
word_686 = (unsigned __int8)result;
return result;
}

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

result = (unsigned __int8)func0(fastrand_state, 6u, a1, a2) | 0x80u;
word_686 = (unsigned __int8)result;
return result;
}

original_code:
void fastrand_seed(void const *s, uint8_t l)
{
    fastrand_state.c = 0x0080 | hash(fastrand_state.x, sizeof(fastrand_state.x), s, l);
}

canonical_original_code:
void fastrand_seed(void *s, unsigned char l)
{
    fastrand_state.c = 0x0080 | hash(fastrand_state.x, sizeof(fastrand_state.x), s, l);
}


fastrand

decompiled_code:
__int64 fastrand()
{
int v0; // edx
__int64 v1; // r8
int v2; // er9
unsigned __int8 v3; // si
__int64 v4; // rdi
int v5; // edx
int v6; // ecx
int v7; // eax
int v8; // eax
__int16 v9; // di
__int16 v10; // cx
bool v11; // zf
__int16 v12; // si
__int64 result; // rax

v0 = (unsigned __int16)word_686;
LOWORD(v0) = word_686 & 0x1FF;
v1 = HIBYTE(word_686) & 6;
v2 = (unsigned __int8)fastrand_state[v1];
v3 = (HIBYTE(word_686) & 6) + 2;
v4 = ((HIBYTE(word_686) & 6) + 1) & 0xF;
v5 = 59 * v2 + v0;
v6 = (unsigned __int8)fastrand_state[v4];
fastrand_state[v1] = v5;
v7 = v2 + 60 * v6;
HIWORD(v2) = HIWORD(v5);
LOWORD(v2) = BYTE1(v5);
v8 = v2 + v7 - v6;
fastrand_state[v4] = v8;
v9 = v3 << 8;
v10 = BYTE1(v8) + v6;
v11 = v3 == 6;
v12 = 0;
if ( !v11 )
v12 = v9;
result = (unsigned __int8)v5 | (unsigned int)(v8 << 8);
word_686 = v12 | v10;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // edx
__int64 v1; // r8
int v2; // er9
unsigned __int8 v3; // si
__int64 v4; // rdi
int v5; // edx
int v6; // ecx
int v7; // eax
int v8; // eax
__int16 v9; // di
__int16 v10; // cx
bool v11; // zf
__int16 v12; // si
__int64 result; // rax

v0 = (unsigned __int16)word_686;
LOWORD(v0) = word_686 & 0x1FF;
v1 = HIBYTE(word_686) & 6;
v2 = (unsigned __int8)fastrand_state[v1];
v3 = (HIBYTE(word_686) & 6) + 2;
v4 = ((HIBYTE(word_686) & 6) + 1) & 0xF;
v5 = 59 * v2 + v0;
v6 = (unsigned __int8)fastrand_state[v4];
fastrand_state[v1] = v5;
v7 = v2 + 60 * v6;
HIWORD(v2) = HIWORD(v5);
LOWORD(v2) = BYTE1(v5);
v8 = v2 + v7 - v6;
fastrand_state[v4] = v8;
v9 = v3 << 8;
v10 = BYTE1(v8) + v6;
v11 = v3 == 6;
v12 = 0;
if ( !v11 )
v12 = v9;
result = (unsigned __int8)v5 | (unsigned int)(v8 << 8);
word_686 = v12 | v10;
return result;
}

original_code:
uint16_t fastrand(void)
{
    uint8_t x, y;
    uint16_t c;
    uint8_t i;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    do { uint16_t t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(x))) + c; c = t >> 8; if (0x013b & 0x100) c += x; x = t & 0xff; } while (0);
    do { uint16_t t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(y))) + c; c = t >> 8; if (0x013b & 0x100) c += y; y = t & 0xff; } while (0);
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((uint16_t)i << 8);
    return (y << 8) | x;
}

canonical_original_code:
unsigned short fastrand()
{
    unsigned char x; unsigned char y;
    unsigned short c;
    unsigned char i;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    do { unsigned short t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(x))) + c; c = t >> 8; if (0x013b & 0x100) c += x; x = t & 0xff; } while (0);
    do { unsigned short t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(y))) + c; c = t >> 8; if (0x013b & 0x100) c += y; y = t & 0xff; } while (0);
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((unsigned short)i << 8);
    return (y << 8) | x;
}


decompiled_code:
__int64 __fastcall shiftrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
return fastrand_seed(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1, unsigned __int8 a2)
{
return func7(a1, a2);
}

original_code:
void shiftrand_seed(void const *s, uint8_t l)
{
    fastrand_seed(s, l);
}

canonical_original_code:
void shiftrand_seed(void *s, unsigned char l)
{
    fastrand_seed(s, l);
}


shiftrand

decompiled_code:
__int64 shiftrand()
{
int v0; // eax
__int64 v1; // rdi
int v2; // er10
unsigned __int8 v3; // si
__int64 v4; // r8
int v5; // er9
unsigned __int16 v6; // dx
int v7; // ecx
__int16 v8; // di
int v9; // eax
__int16 v10; // cx
bool v11; // zf
__int16 v12; // si
__int64 result; // rax

v0 = (unsigned __int16)word_686;
LOWORD(v0) = word_686 & 0x1FF;
v1 = HIBYTE(word_686) & 6;
v2 = (unsigned __int8)fastrand_state[v1];
v3 = (HIBYTE(word_686) & 6) + 2;
v4 = ((HIBYTE(word_686) & 6) + 1) & 0xF;
v5 = (unsigned __int8)fastrand_state[v4];
HIWORD(v7) = (unsigned int)(63 * v2 + v0 - 4 * v2) >> 16;
v6 = 63 * v2 + (word_686 & 0x1FF) - 4 * v2;
fastrand_state[v1] = 63 * v2 + word_686 - 4 * v2;
LOWORD(v7) = HIBYTE(v6);
v8 = v3 << 8;
v9 = v7 + v2 + 63 * v5 - 4 * v5;
fastrand_state[v4] = v9;
v10 = v5 + BYTE1(v9);
v11 = v3 == 6;
v12 = 0;
if ( !v11 )
v12 = v8;
result = (unsigned __int8)v6 | (unsigned int)(v9 << 8);
word_686 = v12 | v10;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
__int64 v1; // rdi
int v2; // er10
unsigned __int8 v3; // si
__int64 v4; // r8
int v5; // er9
unsigned __int16 v6; // dx
int v7; // ecx
__int16 v8; // di
int v9; // eax
__int16 v10; // cx
bool v11; // zf
__int16 v12; // si
__int64 result; // rax

v0 = (unsigned __int16)word_686;
LOWORD(v0) = word_686 & 0x1FF;
v1 = HIBYTE(word_686) & 6;
v2 = (unsigned __int8)fastrand_state[v1];
v3 = (HIBYTE(word_686) & 6) + 2;
v4 = ((HIBYTE(word_686) & 6) + 1) & 0xF;
v5 = (unsigned __int8)fastrand_state[v4];
HIWORD(v7) = (unsigned int)(63 * v2 + v0 - 4 * v2) >> 16;
v6 = 63 * v2 + (word_686 & 0x1FF) - 4 * v2;
fastrand_state[v1] = 63 * v2 + word_686 - 4 * v2;
LOWORD(v7) = HIBYTE(v6);
v8 = v3 << 8;
v9 = v7 + v2 + 63 * v5 - 4 * v5;
fastrand_state[v4] = v9;
v10 = v5 + BYTE1(v9);
v11 = v3 == 6;
v12 = 0;
if ( !v11 )
v12 = v8;
result = (unsigned __int8)v6 | (unsigned int)(v9 << 8);
word_686 = v12 | v10;
return result;
}

original_code:
uint16_t shiftrand(void)
{
    uint8_t x, y, i;
    uint16_t c, t;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    t = (x << 6) - x - (x << 2) + c;
    c = (t >> 8) + x;
    x = t & 0xff;
    t = (y << 6) - y - (y << 2) + c;
    c = (t >> 8) + y;
    y = t & 0xff;
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((uint16_t)i << 8);
    return (y << 8) | x;
}

canonical_original_code:
unsigned short shiftrand()
{
    unsigned char x; unsigned char y; unsigned char i;
    unsigned short c; unsigned short t;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    t = (x << 6) - x - (x << 2) + c;
    c = (t >> 8) + x;
    x = t & 0xff;
    t = (y << 6) - y - (y << 2) + c;
    c = (t >> 8) + y;
    y = t & 0xff;
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((unsigned short)i << 8);
    return (y << 8) | x;
}


decompiled_code:
__int64 __fastcall fastrand2_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
char v2; // al
__int64 result; // rax

v2 = hash(&fastrand2_state, 8u, a1, a2);
byte_679 = 85;
byte_678 = v2;
result = 0LL;
word_67A = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1, unsigned __int8 a2)
{
char v2; // al
__int64 result; // rax

v2 = func0(&fastrand2_state, 8u, a1, a2);
byte_679 = 85;
byte_678 = v2;
result = 0LL;
word_67A = 0;
return result;
}

original_code:
void fastrand2_seed(void const *s, uint8_t l)
{
    fastrand2_state.c[0] = hash(fastrand2_state.x, sizeof(fastrand2_state.x), s, l);
    fastrand2_state.c[1] = 0x55;
    fastrand2_state.c[2] = 0;
    fastrand2_state.c[3] = 0;
}

canonical_original_code:
void fastrand2_seed(void *s, unsigned char l)
{
    fastrand2_state.c[0] = hash(fastrand2_state.x, sizeof(fastrand2_state.x), s, l);
    fastrand2_state.c[1] = 0x55;
    fastrand2_state.c[2] = 0;
    fastrand2_state.c[3] = 0;
}


decompiled_code:
__int64 fastrand2()
{
__int64 v0; // r11
__int64 v1; // r10
char v2; // r8
int v3; // ebx
int v4; // ebp
int v5; // edi
__int16 v6; // dx
unsigned __int8 v7; // r9
int v8; // eax
__int16 v9; // si
int v10; // eax
__int16 v11; // cx
int v12; // edi
unsigned __int16 v13; // dx
unsigned __int16 v14; // cx
__int16 v15; // si
unsigned __int16 v16; // cx

v0 = HIBYTE(word_67A) >> 1;
v1 = (unsigned __int8)((HIBYTE(word_67A) >> 1) + 1);
v2 = (2 * (HIBYTE(word_67A) >> 1) + 4) & 0xE;
v3 = (unsigned __int8)fastrand2_state[v0];
v4 = (unsigned __int8)fastrand2_state[v1];
v5 = v3 + (unsigned __int8)byte_678;
v6 = v3 + (HIBYTE(word_67A) & 1);
v7 = v3 + byte_678;
v8 = (unsigned __int8)byte_679;
LOWORD(v5) = BYTE1(v5);
v9 = 13 * v3 + (unsigned __int8)word_67A;
fastrand2_state[v0] = v3 + byte_678;
v10 = v8 + v5;
v11 = (unsigned __int8)v10;
v12 = v4 + v10;
fastrand2_state[v1] = v4 + v10;
LOWORD(v10) = BYTE1(v10) + v9;
v13 = BYTE1(v10) + v6;
v14 = (unsigned __int8)v10 + ((unsigned __int16)((unsigned __int8)v4 + v11) >> 8);
v15 = (unsigned __int8)v13;
v13 >>= 8;
byte_678 = v14;
v16 = 13 * (unsigned __int8)v4 + v15 + HIBYTE(v14);
byte_679 = v16;
v16 >>= 8;
LOBYTE(word_67A) = v16 + v13 + v4;
HIBYTE(word_67A) = v2 | ((unsigned __int16)(v16 + v13 + (unsigned __int8)v4) >> 8);
return (v12 << 8) | (unsigned int)v7;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // r11
__int64 v1; // r10
char v2; // r8
int v3; // ebx
int v4; // ebp
int v5; // edi
__int16 v6; // dx
unsigned __int8 v7; // r9
int v8; // eax
__int16 v9; // si
int v10; // eax
__int16 v11; // cx
int v12; // edi
unsigned __int16 v13; // dx
unsigned __int16 v14; // cx
__int16 v15; // si
unsigned __int16 v16; // cx

v0 = HIBYTE(word_67A) >> 1;
v1 = (unsigned __int8)((HIBYTE(word_67A) >> 1) + 1);
v2 = (2 * (HIBYTE(word_67A) >> 1) + 4) & 0xE;
v3 = (unsigned __int8)fastrand2_state[v0];
v4 = (unsigned __int8)fastrand2_state[v1];
v5 = v3 + (unsigned __int8)byte_678;
v6 = v3 + (HIBYTE(word_67A) & 1);
v7 = v3 + byte_678;
v8 = (unsigned __int8)byte_679;
LOWORD(v5) = BYTE1(v5);
v9 = 13 * v3 + (unsigned __int8)word_67A;
fastrand2_state[v0] = v3 + byte_678;
v10 = v8 + v5;
v11 = (unsigned __int8)v10;
v12 = v4 + v10;
fastrand2_state[v1] = v4 + v10;
LOWORD(v10) = BYTE1(v10) + v9;
v13 = BYTE1(v10) + v6;
v14 = (unsigned __int8)v10 + ((unsigned __int16)((unsigned __int8)v4 + v11) >> 8);
v15 = (unsigned __int8)v13;
v13 >>= 8;
byte_678 = v14;
v16 = 13 * (unsigned __int8)v4 + v15 + HIBYTE(v14);
byte_679 = v16;
v16 >>= 8;
LOBYTE(word_67A) = v16 + v13 + v4;
HIBYTE(word_67A) = v2 | ((unsigned __int16)(v16 + v13 + (unsigned __int8)v4) >> 8);
return (v12 << 8) | (unsigned int)v7;
}

original_code:
uint16_t fastrand2(void)
{
    uint8_t x, y;
    uint8_t i;
    i = (fastrand2_state.c[3] >> 1);
    x = fastrand2_state.x[i + 0];
    y = fastrand2_state.x[i + 1];
    do { uint16_t t = x + fastrand2_state.c[0]; uint8_t out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((uint16_t)((uint8_t)(0x010D0001 >> 16) * (uint8_t)(x))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += x; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; x = out; } while (0);
    do { uint16_t t = y + fastrand2_state.c[0]; uint8_t out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((uint16_t)((uint8_t)(0x010D0001 >> 16) * (uint8_t)(y))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += y; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; y = out; } while (0);
    fastrand2_state.x[i++] = x;
    fastrand2_state.x[i++] = y;
    fastrand2_state.c[3] |= (i & 7) << 1;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short fastrand2()
{
    unsigned char x; unsigned char y;
    unsigned char i;
    i = (fastrand2_state.c[3] >> 1);
    x = fastrand2_state.x[i + 0];
    y = fastrand2_state.x[i + 1];
    do { unsigned short t = x + fastrand2_state.c[0]; unsigned char out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((unsigned short)((unsigned char)(0x010D0001 >> 16) * (unsigned char)(x))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += x; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; x = out; } while (0);
    do { unsigned short t = y + fastrand2_state.c[0]; unsigned char out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((unsigned short)((unsigned char)(0x010D0001 >> 16) * (unsigned char)(y))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += y; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; y = out; } while (0);
    fastrand2_state.x[i++] = x;
    fastrand2_state.x[i++] = y;
    fastrand2_state.c[3] |= (i & 7) << 1;
    return (y << 8) | x;
}

variable_types:
out
unsigned char


original_code:
void rand8_init(uint16_t a, uint8_t r, uint16_t c, uint8_t const *seed)
{
    int i;
    rand8.mul_lo = a & 0xff;
    rand8.mul_hi = a >> 8;
    rand8.r = r;
    for (i = 0; i < r; i++)
        rand8.state[i] = seed[i];
    rand8.c = c;
    rand8.i = 0;
}

canonical_original_code:
void rand8_init(unsigned short a, unsigned char r, unsigned short c, unsigned char *seed)
{
    int i;
    rand8.mul_lo = a & 0xff;
    rand8.mul_hi = a >> 8;
    rand8.r = r;
    for (i = 0; i < r; i++)
        rand8.state[i] = seed[i];
    rand8.c = c;
    rand8.i = 0;
}

variable_types:
a
unsigned short

variable_types:
r
unsigned char

variable_types:
seed
unsigned char *

variable_types: i int