decompiled_code:
void use_dummy()
{
p_gettext = (__int64)dummy_gettext;
p_dgettext = (__int64)dummy_dgettext;
p_dcgettext = (__int64)dummy_dcgettext;
p_ngettext = (__int64)dummy_ngettext;
p_dngettext = (__int64)dummy_dngettext;
p_dcngettext = (__int64)dummy_dcngettext;
p_textdomain = (__int64)dummy_textdomain;
p_bindtextdomain = (__int64)dummy_bindtextdomain;
p_bind_textdomain_codeset = (__int64)dummy_bind_textdomain_codeset;
}

canonical_decompiled_code:
void func8()
{
p_gettext = (__int64)dummy_gettext;
p_dgettext = (__int64)dummy_dgettext;
p_dcgettext = (__int64)dummy_dcgettext;
p_ngettext = (__int64)dummy_ngettext;
p_dngettext = (__int64)dummy_dngettext;
p_dcngettext = (__int64)dummy_dcngettext;
p_textdomain = (__int64)dummy_textdomain;
p_bindtextdomain = (__int64)dummy_bindtextdomain;
p_bind_textdomain_codeset = (__int64)dummy_bind_textdomain_codeset;
}

original_code:
static void
use_dummy (void)
{
  p_gettext = dummy_gettext;
  p_dgettext = dummy_dgettext;
  p_dcgettext = dummy_dcgettext;
  p_ngettext = dummy_ngettext;
  p_dngettext = dummy_dngettext;
  p_dcngettext = dummy_dcngettext;
  p_textdomain = dummy_textdomain;
  p_bindtextdomain = dummy_bindtextdomain;
  p_bind_textdomain_codeset = dummy_bind_textdomain_codeset;
}

canonical_original_code:
static void use_dummy()
{
  p_gettext = dummy_gettext;
  p_dgettext = dummy_dgettext;
  p_dcgettext = dummy_dcgettext;
  p_ngettext = dummy_ngettext;
  p_dngettext = dummy_dngettext;
  p_dcngettext = dummy_dcngettext;
  p_textdomain = dummy_textdomain;
  p_bindtextdomain = dummy_bindtextdomain;
  p_bind_textdomain_codeset = dummy_bind_textdomain_codeset;
}


decompiled_code:
_BOOL8 __fastcall use_intl_dll(void *handle)
{
_BOOL4 v1; // edx

p_gettext = (__int64)dlsym(handle, "gettext");
v1 = 0;
if ( p_gettext )
{
p_dgettext = (__int64)dlsym(handle, "dgettext");
v1 = 0;
if ( p_dgettext )
{
p_dcgettext = (__int64)dlsym(handle, "dcgettext");
v1 = 0;
if ( p_dcgettext )
{
p_ngettext = (__int64)dlsym(handle, "ngettext");
v1 = 0;
if ( p_ngettext )
{
p_dngettext = (__int64)dlsym(handle, "dngettext");
v1 = 0;
if ( p_dngettext )
{
p_dcngettext = (__int64)dlsym(handle, "dcngettext");
v1 = 0;
if ( p_dcngettext )
{
p_textdomain = (__int64)dlsym(handle, "textdomain");
v1 = 0;
if ( p_textdomain )
{
p_bindtextdomain = (__int64)dlsym(handle, "bindtextdomain");
v1 = 0;
if ( p_bindtextdomain )
{
p_bind_textdomain_codeset = (__int64)dlsym(handle, "bind_textdomain_codeset");
v1 = p_bind_textdomain_codeset != 0;
}
}
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(void *handle)
{
_BOOL4 v1; // edx

p_gettext = (__int64)dlsym(handle, "gettext");
v1 = 0;
if ( p_gettext )
{
p_dgettext = (__int64)dlsym(handle, "dgettext");
v1 = 0;
if ( p_dgettext )
{
p_dcgettext = (__int64)dlsym(handle, "dcgettext");
v1 = 0;
if ( p_dcgettext )
{
p_ngettext = (__int64)dlsym(handle, "ngettext");
v1 = 0;
if ( p_ngettext )
{
p_dngettext = (__int64)dlsym(handle, "dngettext");
v1 = 0;
if ( p_dngettext )
{
p_dcngettext = (__int64)dlsym(handle, "dcngettext");
v1 = 0;
if ( p_dcngettext )
{
p_textdomain = (__int64)dlsym(handle, "textdomain");
v1 = 0;
if ( p_textdomain )
{
p_bindtextdomain = (__int64)dlsym(handle, "bindtextdomain");
v1 = 0;
if ( p_bindtextdomain )
{
p_bind_textdomain_codeset = (__int64)dlsym(handle, "bind_textdomain_codeset");
v1 = p_bind_textdomain_codeset != 0;
}
}
}
}
}
}
}
}
return v1;
}

original_code:
static int
use_intl_dll (HMODULE dll)
{
  p_gettext = (void *) dlsym (dll, "gettext"); if (p_gettext == ((void *)0)) return 0;
  p_dgettext = (void *) dlsym (dll, "dgettext"); if (p_dgettext == ((void *)0)) return 0;
  p_dcgettext = (void *) dlsym (dll, "dcgettext"); if (p_dcgettext == ((void *)0)) return 0;
  p_ngettext = (void *) dlsym (dll, "ngettext"); if (p_ngettext == ((void *)0)) return 0;
  p_dngettext = (void *) dlsym (dll, "dngettext"); if (p_dngettext == ((void *)0)) return 0;
  p_dcngettext = (void *) dlsym (dll, "dcngettext"); if (p_dcngettext == ((void *)0)) return 0;
  p_textdomain = (void *) dlsym (dll, "textdomain"); if (p_textdomain == ((void *)0)) return 0;
  p_bindtextdomain = (void *) dlsym (dll, "bindtextdomain"); if (p_bindtextdomain == ((void *)0)) return 0;
  p_bind_textdomain_codeset = (void *) dlsym (dll, "bind_textdomain_codeset"); if (p_bind_textdomain_codeset == ((void *)0)) return 0;
    return 1;
}

canonical_original_code:
static int use_intl_dll(void *dll)
{
  p_gettext = (void *) dlsym (dll, "gettext"); if (p_gettext == ((void *)0)) return 0;
  p_dgettext = (void *) dlsym (dll, "dgettext"); if (p_dgettext == ((void *)0)) return 0;
  p_dcgettext = (void *) dlsym (dll, "dcgettext"); if (p_dcgettext == ((void *)0)) return 0;
  p_ngettext = (void *) dlsym (dll, "ngettext"); if (p_ngettext == ((void *)0)) return 0;
  p_dngettext = (void *) dlsym (dll, "dngettext"); if (p_dngettext == ((void *)0)) return 0;
  p_dcngettext = (void *) dlsym (dll, "dcngettext"); if (p_dcngettext == ((void *)0)) return 0;
  p_textdomain = (void *) dlsym (dll, "textdomain"); if (p_textdomain == ((void *)0)) return 0;
  p_bindtextdomain = (void *) dlsym (dll, "bindtextdomain"); if (p_bindtextdomain == ((void *)0)) return 0;
  p_bind_textdomain_codeset = (void *) dlsym (dll, "bind_textdomain_codeset"); if (p_bind_textdomain_codeset == ((void *)0)) return 0;
    return 1;
}

variable_types:
dll
void *

return_type: int


setup

decompiled_code:
void setup()
{
void *v0; // rdi

if ( !beenhere_0 )
{
v0 = dlopen("libintl.so", 1);
if ( !v0 || !use_intl_dll(v0) )
use_dummy();
beenhere_0 = 1;
}
}

canonical_decompiled_code:
void func10()
{
void *v0; // rdi

if ( !beenhere_0 )
{
v0 = dlopen("libintl.so", 1);
if ( !v0 || !func9(v0) )
func8();
beenhere_0 = 1;
}
}

original_code:
static void
setup (void)
{
  static int beenhere = 0;
  if (!beenhere)
    {
      HMODULE intl_dll = dlopen ("libintl.so", 0x00001);
      if (intl_dll != ((void *)0) &&
   use_intl_dll (intl_dll))
 ;
      else
 use_dummy ();
      beenhere = 1;
    }
}

canonical_original_code:
static void setup()
{
  static int beenhere = 0;
  if (!beenhere)
    {
      void *intl_dll = dlopen ("libintl.so", 0x00001);
      if (intl_dll != ((void *)0) &&
   use_intl_dll (intl_dll))
 ;
      else
 use_dummy ();
      beenhere = 1;
    }
}

variable_types: beenhere int

return_type: void


decompiled_code:
char *__fastcall dummy_textdomain(char *s)
{
char *result; // rax

if ( s )
{
free(current_domain);
result = strdup(s);
current_domain = result;
}
else
{
result = (char *)current_domain;
if ( !current_domain )
{
result = strdup("messages");
current_domain = result;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char *s)
{
char *result; // rax

if ( s )
{
free(current_domain);
result = strdup(s);
current_domain = result;
}
else
{
result = (char *)current_domain;
if ( !current_domain )
{
result = strdup("messages");
current_domain = result;
}
}
return result;
}

original_code: static char * dummy_textdomain (const char *domainname) { return (char *) ((domainname ? (free (current_domain), current_domain = strdup (domainname)) : (current_domain ? current_domain : (current_domain = strdup ("messages"))))); }

canonical_original_code: static char *dummy_textdomain(char *domainname) { return (char *) ((domainname ? (free (current_domain), current_domain = strdup (domainname)) : (current_domain ? current_domain : (current_domain = strdup ("messages"))))); }

variable_types:
domainname
char *

return_type: char *


gettext

decompiled_code:
__int64 __fastcall gettext(__int64 a1)
{
setup();
return p_gettext(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
func10();
return p_gettext(a1);
}

original_code: char * gettext (const char *msgid) { setup (); return p_gettext (msgid); }

canonical_original_code: char *gettext(char *msgid) { setup (); return p_gettext (msgid); }

variable_types:
msgid
char *


dgettext

decompiled_code:
__int64 __fastcall dgettext(__int64 a1, __int64 a2)
{
setup();
return p_dgettext(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
func10();
return p_dgettext(a1, a2);
}

original_code: char * dgettext (const char *domainname, const char *msgid) { setup (); return p_dgettext (domainname, msgid); }

canonical_original_code: char *dgettext(char *domainname, char *msgid) { setup (); return p_dgettext (domainname, msgid); }


dcgettext

decompiled_code:
__int64 __fastcall dcgettext(__int64 a1, __int64 a2, unsigned int a3)
{
setup();
return p_dcgettext(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, unsigned int a3)
{
func10();
return p_dcgettext(a1, a2, a3);
}

original_code: char * dcgettext (const char *domainname, const char *msgid, int category) { setup (); return p_dcgettext (domainname, msgid, category); }

canonical_original_code: char *dcgettext(char *domainname, char *msgid, int category) { setup (); return p_dcgettext (domainname, msgid, category); }

variable_types: category int


ngettext

decompiled_code:
__int64 __fastcall ngettext(__int64 a1, __int64 a2, __int64 a3)
{
setup();
return p_ngettext(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
func10();
return p_ngettext(a1, a2, a3);
}

original_code: char * ngettext (const char *msgid1, const char *msgid2, unsigned long int n) { setup (); return p_ngettext (msgid1, msgid2, n); }

canonical_original_code: char *ngettext(char *msgid1, char *msgid2, unsigned long n) { setup (); return p_ngettext (msgid1, msgid2, n); }

variable_types:
n
unsigned long


dngettext

decompiled_code:
__int64 __fastcall dngettext(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
setup();
return p_dngettext(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
func10();
return p_dngettext(a1, a2, a3, a4);
}

original_code: char * dngettext (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) { setup (); return p_dngettext (domainname, msgid1, msgid2, n); }

canonical_original_code: char *dngettext(char *domainname, char *msgid1, char *msgid2, unsigned long n) { setup (); return p_dngettext (domainname, msgid1, msgid2, n); }


dcngettext

decompiled_code:
__int64 __fastcall dcngettext(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
setup();
return p_dcngettext(a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
func10();
return p_dcngettext(a1, a2, a3, a4, a5);
}

original_code: char * dcngettext (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) { setup (); return p_dcngettext (domainname, msgid1, msgid2, n, category); }

canonical_original_code: char *dcngettext(char *domainname, char *msgid1, char *msgid2, unsigned long n, int category) { setup (); return p_dcngettext (domainname, msgid1, msgid2, n, category); }


textdomain

decompiled_code:
__int64 __fastcall textdomain(__int64 a1)
{
setup();
return p_textdomain(a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
func10();
return p_textdomain(a1);
}

original_code: char * textdomain (const char *domainname) { setup (); return p_textdomain (domainname); }

canonical_original_code: char *textdomain(char *domainname) { setup (); return p_textdomain (domainname); }


bindtextdomain

decompiled_code:
__int64 __fastcall bindtextdomain(__int64 a1, __int64 a2)
{
setup();
return p_bindtextdomain(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2)
{
func10();
return p_bindtextdomain(a1, a2);
}

original_code: char * bindtextdomain (const char *domainname, const char *dirname) { setup (); return p_bindtextdomain (domainname, dirname); }

canonical_original_code: char *bindtextdomain(char *domainname, char *dirname) { setup (); return p_bindtextdomain (domainname, dirname); }

variable_types:
dirname
char *


decompiled_code:
__int64 __fastcall bind_textdomain_codeset(__int64 a1, __int64 a2)
{
setup();
return p_bind_textdomain_codeset(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2)
{
func10();
return p_bind_textdomain_codeset(a1, a2);
}

original_code: char * bind_textdomain_codeset (const char *domainname, const char *codeset) { setup (); return p_bind_textdomain_codeset (domainname, codeset); }

canonical_original_code: char *bind_textdomain_codeset(char *domainname, char *codeset) { setup (); return p_bind_textdomain_codeset (domainname, codeset); }

variable_types:
codeset
char *


repo: johnjlee/opticalflow

original_code:
void draw_needle(struct image *im, int Ax, int Ay, int Bx, int By)
{
   int dX = abs(Bx-Ax);
   int dY = abs(By-Ay);
   int Xincr, Yincr;
   if (Ax > Bx) { Xincr=-1; } else { Xincr=1; }
   if (Ay > By) { Yincr=-1; } else { Yincr=1; }
   if (dX >= dY)
   {
      int dPr = dY<<1;
      int dPru = dPr - (dX<<1);
      int P = dPr - dX;
      for (; dX>=0; dX--)
      {
         if(Ax <= im->xres && Ay <= im->yres &&
            Ax >= 0 && Ay >= 0)
         {
            im->s[Ax][Ay] = 0;
         }
         if (P > 0)
         {
            Ax+=Xincr;
            Ay+=Yincr;
            P+=dPru;
         }
         else
         {
            Ax+=Xincr;
            P+=dPr;
         }
      }
   }
   else
   {
      int dPr = dX<<1;
      int dPru = dPr - (dY<<1);
      int P = dPr - dY;
      for (; dY>=0; dY--)
      {
         if(Ax <= im->xres && Ay <= im->yres &&
            Ax >= 0 && Ay >= 0)
         {
            im->s[Ax][Ay] = 0;
         }
         if (P > 0)
         {
            Ax+=Xincr;
            Ay+=Yincr;
            P+=dPru;
         }
         else
         {
            Ay+=Yincr;
            P+=dPr;
         }
      }
   }
}

canonical_original_code:
void draw_needle(struct image *im, int Ax, int Ay, int Bx, int By)
{
   int dX = abs(Bx-Ax);
   int dY = abs(By-Ay);
   int Xincr; int Yincr;
   if (Ax > Bx) { Xincr=-1; } else { Xincr=1; }
   if (Ay > By) { Yincr=-1; } else { Yincr=1; }
   if (dX >= dY)
   {
      int dPr = dY<<1;
      int dPru = dPr - (dX<<1);
      int P = dPr - dX;
      for (; dX>=0; dX--)
      {
         if(Ax <= im->xres && Ay <= im->yres &&
            Ax >= 0 && Ay >= 0)
         {
            im->s[Ax][Ay] = 0;
         }
         if (P > 0)
         {
            Ax+=Xincr;
            Ay+=Yincr;
            P+=dPru;
         }
         else
         {
            Ax+=Xincr;
            P+=dPr;
         }
      }
   }
   else
   {
      int dPr = dX<<1;
      int dPru = dPr - (dY<<1);
      int P = dPr - dY;
      for (; dY>=0; dY--)
      {
         if(Ax <= im->xres && Ay <= im->yres &&
            Ax >= 0 && Ay >= 0)
         {
            im->s[Ax][Ay] = 0;
         }
         if (P > 0)
         {
            Ax+=Xincr;
            Ay+=Yincr;
            P+=dPru;
         }
         else
         {
            Ay+=Yincr;
            P+=dPr;
         }
      }
   }
}

variable_types:
im
struct image { int **s; int xres; } *

variable_types: Ax int

variable_types: Ay int

variable_types: Bx int

variable_types: By int

variable_types: dX int

variable_types: dY int

variable_types: Xincr int

variable_types: Yincr int

variable_types: dPr int

variable_types: dPru int

variable_types: P int


decompiled_code:
__int64 __fastcall render_needles(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // esi
int v6; // er9
int v7; // ecx
int v8; // edi
__int64 result; // rax
int v10; // er13
__int64 v11; // rbx
__int64 v12; // rbp
float *v13; // rax
__int64 v14; // [rsp+0h] [rbp-78h]
__int64 v15; // [rsp+18h] [rbp-60h]
__int64 v16; // [rsp+20h] [rbp-58h]
int v17; // [rsp+28h] [rbp-50h]
int v18; // [rsp+2Ch] [rbp-4Ch]
__int64 v19; // [rsp+30h] [rbp-48h]
int v20; // [rsp+38h] [rbp-40h]
int v21; // [rsp+3Ch] [rbp-3Ch]

if ( !a1 )
_assert_fail("small != NULL", "needles.c", 8u, "render_needles");
if ( !a2 )
_assert_fail("big != NULL", "needles.c", 9u, "render_needles");
if ( !a3 )
_assert_fail("uv != NULL", "needles.c", 0xAu, "render_needles");
v5 = *(_DWORD *)(a1 + 8);
v6 = *(_DWORD *)(a3 + 8);
if ( v5 != v6 )
_assert_fail("small->xres == uv->xres", "needles.c", 0xBu, "render_needles");
v7 = *(_DWORD *)(a1 + 12);
if ( v7 != *(_DWORD *)(a3 + 12) )
_assert_fail("small->yres == uv->yres", "needles.c", 0xCu, "render_needles");
if ( *(_DWORD *)(a2 + 8) % v5 )
_assert_fail("(big->xres % small->xres) == 0", "needles.c", 0xDu, "render_needles");
v8 = *(_DWORD *)(a2 + 12);
if ( v8 % v7 )
_assert_fail("(big->yres % small->yres) == 0", "needles.c", 0xEu, "render_needles");
v20 = *(_DWORD *)(a2 + 8) / v5;
result = (unsigned int)(v8 / v7);
v17 = v8 / v7;
if ( v6 > 1 )
{
v21 = (int)result / 2;
v18 = v20 / 2;
v15 = 4LL * (int)result;
v19 = 4LL * ((int)result / 2);
v16 = 0LL;
do
{
if ( *(int *)(a3 + 12) > 1 )
{
v14 = 8LL * v18 + 8;
v10 = v21;
v11 = v19;
v12 = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a2 + 8LL * v18) + v11) = 0;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a2 + 8LL * v18) + v11 + 4) = 0;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a2 + v14) + v11) = 0;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)a2 + v14) + v11 + 4) = 0;
v13 = (float *)(*(_QWORD *)(*(_QWORD *)a3 + 8 * v16) + 12 * v12);
draw_needle(a2, v18, v10, (int)(float)((float)v18 + *v13), (int)(float)((float)v10 + v13[1]));
++v12;
v11 += v15;
v10 += v17;
}
while ( *(_DWORD *)(a3 + 12) - 1 > (int)v12 );
}
++v16;
v18 += v20;
result = (unsigned int)(*(_DWORD *)(a3 + 8) - 1);
}
while ( (int)result > (int)v16 );
}
return result;
}

original_code:
void render_needles(struct image *small, struct image *big,
                    struct vector_field *uv)
{
   ((void) sizeof ((small != ((void *)0)) ? 1 : 0), __extension__ ({ if (small != ((void *)0)) ; else __assert_fail ("small != NULL", "needles.c", 8, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((big != ((void *)0)) ? 1 : 0), __extension__ ({ if (big != ((void *)0)) ; else __assert_fail ("big != NULL", "needles.c", 9, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((uv != ((void *)0)) ? 1 : 0), __extension__ ({ if (uv != ((void *)0)) ; else __assert_fail ("uv != NULL", "needles.c", 10, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->xres == uv->xres) ? 1 : 0), __extension__ ({ if (small->xres == uv->xres) ; else __assert_fail ("small->xres == uv->xres", "needles.c", 11, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->yres == uv->yres) ? 1 : 0), __extension__ ({ if (small->yres == uv->yres) ; else __assert_fail ("small->yres == uv->yres", "needles.c", 12, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->xres % small->xres) == 0) ? 1 : 0), __extension__ ({ if ((big->xres % small->xres) == 0) ; else __assert_fail ("(big->xres % small->xres) == 0", "needles.c", 13, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->yres % small->yres) == 0) ? 1 : 0), __extension__ ({ if ((big->yres % small->yres) == 0) ; else __assert_fail ("(big->yres % small->yres) == 0", "needles.c", 14, __extension__ __PRETTY_FUNCTION__); }));
   int i,j;
   int xwidth = big->xres / small->xres;
   int ywidth = big->yres / small->yres;
   for(i=0; i < uv->xres - 1; i++)
   {
      for(j=0; j < uv->yres - 1; j++)
      {
         int centerx = i*xwidth + (xwidth/2);
         int centery = j*ywidth + (ywidth/2);
         big->s[centerx][centery] = 0;
         big->s[centerx][centery+1] = 0;
         big->s[centerx+1][centery] = 0;
         big->s[centerx+1][centery+1] = 0;
         draw_needle(big, centerx, centery, centerx + uv->s[i][j].x,
                     centery + uv->s[i][j].y);
      }
   }
}

canonical_original_code:
void render_needles(struct image *small, struct image *big, struct vector_field *uv)
{
   ((void) sizeof ((small != ((void *)0)) ? 1 : 0), __extension__ ({ if (small != ((void *)0)) ; else __assert_fail ("small != NULL", "needles.c", 8, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((big != ((void *)0)) ? 1 : 0), __extension__ ({ if (big != ((void *)0)) ; else __assert_fail ("big != NULL", "needles.c", 9, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((uv != ((void *)0)) ? 1 : 0), __extension__ ({ if (uv != ((void *)0)) ; else __assert_fail ("uv != NULL", "needles.c", 10, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->xres == uv->xres) ? 1 : 0), __extension__ ({ if (small->xres == uv->xres) ; else __assert_fail ("small->xres == uv->xres", "needles.c", 11, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->yres == uv->yres) ? 1 : 0), __extension__ ({ if (small->yres == uv->yres) ; else __assert_fail ("small->yres == uv->yres", "needles.c", 12, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->xres % small->xres) == 0) ? 1 : 0), __extension__ ({ if ((big->xres % small->xres) == 0) ; else __assert_fail ("(big->xres % small->xres) == 0", "needles.c", 13, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->yres % small->yres) == 0) ? 1 : 0), __extension__ ({ if ((big->yres % small->yres) == 0) ; else __assert_fail ("(big->yres % small->yres) == 0", "needles.c", 14, __extension__ __PRETTY_FUNCTION__); }));
   int i; int j;
   int xwidth = big->xres / small->xres;
   int ywidth = big->yres / small->yres;
   for(i=0; i < uv->xres - 1; i++)
   {
      for(j=0; j < uv->yres - 1; j++)
      {
         int centerx = i*xwidth + (xwidth/2);
         int centery = j*ywidth + (ywidth/2);
         big->s[centerx][centery] = 0;
         big->s[centerx][centery+1] = 0;
         big->s[centerx+1][centery] = 0;
         big->s[centerx+1][centery+1] = 0;
         draw_needle(big, centerx, centery, centerx + uv->s[i][j].x,
                     centery + uv->s[i][j].y);
      }
   }
}

variable_types:
small
struct image { int **s; int xres; } *

variable_types:
big
struct image *

variable_types: struct vector_field { struct vec3 { float x; } **s; int xres; } *

variable_types: i int

variable_types: j int

variable_types: xwidth int

variable_types: ywidth int

variable_types: centerx int

variable_types: centery int

user_defined_types: struct vector_field { struct vec3 **s; int xres; }


variable_types:
uavg
float *

variable_types:
vavg
float *


original_code:
void render_foe(struct image *small, struct image *big,
                    struct vector_field *uv)
{
   ((void) sizeof ((small != ((void *)0)) ? 1 : 0), __extension__ ({ if (small != ((void *)0)) ; else __assert_fail ("small != NULL", "foe.c", 8, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((big != ((void *)0)) ? 1 : 0), __extension__ ({ if (big != ((void *)0)) ; else __assert_fail ("big != NULL", "foe.c", 9, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((uv != ((void *)0)) ? 1 : 0), __extension__ ({ if (uv != ((void *)0)) ; else __assert_fail ("uv != NULL", "foe.c", 10, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->xres == uv->xres) ? 1 : 0), __extension__ ({ if (small->xres == uv->xres) ; else __assert_fail ("small->xres == uv->xres", "foe.c", 11, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->yres == uv->yres) ? 1 : 0), __extension__ ({ if (small->yres == uv->yres) ; else __assert_fail ("small->yres == uv->yres", "foe.c", 12, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->xres % small->xres) == 0) ? 1 : 0), __extension__ ({ if ((big->xres % small->xres) == 0) ; else __assert_fail ("(big->xres % small->xres) == 0", "foe.c", 13, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->yres % small->yres) == 0) ? 1 : 0), __extension__ ({ if ((big->yres % small->yres) == 0) ; else __assert_fail ("(big->yres % small->yres) == 0", "foe.c", 14, __extension__ __PRETTY_FUNCTION__); }));
   int i,j;
   int xwidth = big->xres / small->xres;
   int ywidth = big->yres / small->yres;
   int besti=0, bestj=0;
   float minval = (uv->s[0][0].x)*(uv->s[0][0].x) +
      (uv->s[0][0].y)*(uv->s[0][0].y);
   for(i=3; i < uv->xres - 3; i++)
   {
      for(j=3; j < uv->yres - 3; j++)
      {
         float val = (uv->s[i][j].x)*(uv->s[i][j].x) +
            (uv->s[i][j].y)*(uv->s[i][j].y);
         if(val < minval)
         {
            minval = val;
            besti = i;
            bestj = j;
         }
      }
   }
   int centerx = besti*xwidth + (xwidth/2);
   int centery = bestj*ywidth + (ywidth/2);
   for(i=centerx-2; i <= centerx+2; i++)
   {
      for(j=centery-2; j <= centery+2; j++)
      {
         big->s[i][j] = 255;
      }
   }
}

canonical_original_code:
void render_foe(struct image *small, struct image *big, struct vector_field *uv)
{
   ((void) sizeof ((small != ((void *)0)) ? 1 : 0), __extension__ ({ if (small != ((void *)0)) ; else __assert_fail ("small != NULL", "foe.c", 8, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((big != ((void *)0)) ? 1 : 0), __extension__ ({ if (big != ((void *)0)) ; else __assert_fail ("big != NULL", "foe.c", 9, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((uv != ((void *)0)) ? 1 : 0), __extension__ ({ if (uv != ((void *)0)) ; else __assert_fail ("uv != NULL", "foe.c", 10, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->xres == uv->xres) ? 1 : 0), __extension__ ({ if (small->xres == uv->xres) ; else __assert_fail ("small->xres == uv->xres", "foe.c", 11, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((small->yres == uv->yres) ? 1 : 0), __extension__ ({ if (small->yres == uv->yres) ; else __assert_fail ("small->yres == uv->yres", "foe.c", 12, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->xres % small->xres) == 0) ? 1 : 0), __extension__ ({ if ((big->xres % small->xres) == 0) ; else __assert_fail ("(big->xres % small->xres) == 0", "foe.c", 13, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof (((big->yres % small->yres) == 0) ? 1 : 0), __extension__ ({ if ((big->yres % small->yres) == 0) ; else __assert_fail ("(big->yres % small->yres) == 0", "foe.c", 14, __extension__ __PRETTY_FUNCTION__); }));
   int i; int j;
   int xwidth = big->xres / small->xres;
   int ywidth = big->yres / small->yres;
   int besti = 0; int bestj = 0;
   float minval = (uv->s[0][0].x)*(uv->s[0][0].x) +
      (uv->s[0][0].y)*(uv->s[0][0].y);
   for(i=3; i < uv->xres - 3; i++)
   {
      for(j=3; j < uv->yres - 3; j++)
      {
         float val = (uv->s[i][j].x)*(uv->s[i][j].x) +
            (uv->s[i][j].y)*(uv->s[i][j].y);
         if(val < minval)
         {
            minval = val;
            besti = i;
            bestj = j;
         }
      }
   }
   int centerx = besti*xwidth + (xwidth/2);
   int centery = bestj*ywidth + (ywidth/2);
   for(i=centerx-2; i <= centerx+2; i++)
   {
      for(j=centery-2; j <= centery+2; j++)
      {
         big->s[i][j] = 255;
      }
   }
}

variable_types: besti int

variable_types: bestj int

variable_types: minval float

variable_types: val float


decompiled_code:
void __fastcall free_vector_field(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_vector_field(struct vector_field *s)
{
   int i;
   for(i=0; i < s->xres; i++)
   {
      free(s->s[i]);
   }
   free(s->s);
   free(s);
}


decompiled_code:
void __fastcall free_image(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_image(struct image *s)
{
   int i;
   for(i=0; i < s->xres; i++)
   {
      free(s->s[i]);
   }
   free(s->s);
   free(s);
}

variable_types:
s
struct image { int **s; int xres; } *


usage

repo: johnkerl/bridge-walk-count

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s {constraints name} {N} [options]\n", a1);
fprintf(stderr, "Or: %s {constraints name} {Nmin-Nmax} [options]\n", a1);
list_constraints_names(stderr);
fwrite("Options: \"stdout\" or \"stderr\" to print individual walks.\n", 1uLL, 0x39uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Usage: %s {constraints name} {N} [options]\n", a1);
fprintf(stderr, "Or: %s {constraints name} {Nmin-Nmax} [options]\n", a1);
list_constraints_names(stderr);
fwrite("Options: \"stdout\" or \"stderr\" to print individual walks.\n", 1uLL, 0x39uLL, stderr);
exit(1);
}

original_code:
static void usage(char* argv0)
{
 fprintf(stderr, "Usage: %s {constraints name} {N} [options]\n", argv0);
 fprintf(stderr, "Or:    %s {constraints name} {Nmin-Nmax} [options]\n",
  argv0);
 list_constraints_names(stderr);
 fprintf(stderr, "Options: \"stdout\" or \"stderr\" to print individual walks.\n");
 exit(1);
}

canonical_original_code:
static void usage(char *argv0)
{
 fprintf(stderr, "Usage: %s {constraints name} {N} [options]\n", argv0);
 fprintf(stderr, "Or:    %s {constraints name} {Nmin-Nmax} [options]\n",
  argv0);
 list_constraints_names(stderr);
 fprintf(stderr, "Options: \"stdout\" or \"stderr\" to print individual walks.\n");
 exit(1);
}


repo: johnkerl/ctools

decompiled_code:
const char *AESF_explain_error()
{
return "not there yet";
}

canonical_decompiled_code:
const char *func1()
{
return "not there yet";
}

original_code:
static char * AESF_explain_error(
 int code)
{
 return "not there yet";
}

canonical_original_code:
static char *AESF_explain_error(int code)
{
 return "not there yet";
}

variable_types: code int


decompiled_code:
__int64 __fastcall AESF_check_bl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

original_code:
static int AESF_check_bl(
 int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

canonical_original_code:
static int AESF_check_bl(int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

variable_types: bl int


decompiled_code:
__int64 __fastcall AESF_check_kl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

original_code:
static int AESF_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

canonical_original_code:
static int AESF_check_kl(int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

variable_types: kl int


decompiled_code:
__int64 __fastcall AESF_make_key(__int64 a1, unsigned int *a2)
{
int v2; // er12
void *v3; // rax
void *v4; // rbp
_BYTE v6[64]; // [rsp+0h] [rbp-A8h] BYREF
char dest[104]; // [rsp+40h] [rbp-68h] BYREF

v2 = a2[1];
if ( !(unsigned int)valid_key_length(v2) )
return 4294967292LL;
v3 = malloc(0x3C0uLL);
v4 = v3;
if ( !v3 )
return 4294967294LL;
*((_QWORD *)a2 + 18) = v3;
if ( a2[35] )
memcpy(dest, a2 + 19, v2);
else
fill_region_from_string(dest, (unsigned int)v2, a1);
AESF_bytes_to_block(a2[1], dest, v6);
if ( a2[39] )
hex_dump_region("AESF key material", dest, a2[1], 16LL);
AESF_key_schedule(v6, a2[1], *a2, v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int *a2)
{
int v2; // er12
void *v3; // rax
void *v4; // rbp
_BYTE v6[64]; // [rsp+0h] [rbp-A8h] BYREF
char dest[104]; // [rsp+40h] [rbp-68h] BYREF

v2 = a2[1];
if ( !(unsigned int)func0(v2) )
return 4294967292LL;
v3 = malloc(0x3C0uLL);
v4 = v3;
if ( !v3 )
return 4294967294LL;
*((_QWORD *)a2 + 18) = v3;
if ( a2[35] )
memcpy(dest, a2 + 19, v2);
else
fill_region_from_string(dest, (unsigned int)v2, a1);
AESF_bytes_to_block(a2[1], dest, v6);
if ( a2[39] )
hex_dump_region("AESF key material", dest, a2[1], 16LL);
AESF_key_schedule(v6, a2[1], *a2, v4);
return 1LL;
}

original_code:
int AESF_make_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 char full_key_material[64];
 AESF_key_schedule_t * pks;
 u32 key_mat_block[(256/32)];
 if (!valid_key_length(pciphinst->kl))
  return -4;
 pks = (AESF_key_schedule_t *)malloc(sizeof(AESF_key_schedule_t));
 if (pks == 0)
  return -2;
 pciphinst->pkey_schedule = pks;
 if (pciphinst->have_user_key_mat) {
  memcpy(full_key_material, pciphinst->user_key_mat,
   pciphinst->kl);
 }
 else {
  fill_region_from_string(full_key_material,
   pciphinst->kl, key_material);
 }
 AESF_bytes_to_block(pciphinst->kl, full_key_material, key_mat_block);
 if (pciphinst->alg_debug) {
  hex_dump_region("AESF key material",
   full_key_material,
   pciphinst->kl,16);
 }
 AESF_key_schedule(key_mat_block, pciphinst->kl,
  pciphinst->bl, pks->rk);
 return 1;
}

canonical_original_code:
int AESF_make_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 char full_key_material[64];
 struct _AESF_key_schedule_t *pks;
 unsigned long key_mat_block[-1];
 if (!valid_key_length(pciphinst->kl))
  return -4;
 pks = (struct _AESF_key_schedule_t *)malloc(sizeof(AESF_key_schedule_t));
 if (pks == 0)
  return -2;
 pciphinst->pkey_schedule = pks;
 if (pciphinst->have_user_key_mat) {
  memcpy(full_key_material, pciphinst->user_key_mat,
   pciphinst->kl);
 }
 else {
  fill_region_from_string(full_key_material,
   pciphinst->kl, key_material);
 }
 AESF_bytes_to_block(pciphinst->kl, full_key_material, key_mat_block);
 if (pciphinst->alg_debug) {
  hex_dump_region("AESF key material",
   full_key_material,
   pciphinst->kl,16);
 }
 AESF_key_schedule(key_mat_block, pciphinst->kl,
  pciphinst->bl, pks->rk);
 return 1;
}

variable_types: struct _block_cipher_instance_t { int bl; int kl; char user_IV[64]; int have_user_IV; char user_key_mat[64]; int have_user_key_mat; void *pkey_schedule; int do_cbc; int alg_debug; } *

variable_types: struct _AESF_key_schedule_t { unsigned long rk[-1][-1]; } *


decompiled_code:
void __fastcall AESF_free_key(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

original_code:
void AESF_free_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 AESF_key_schedule_t * pkey =
  (AESF_key_schedule_t *)pciphinst->pkey_schedule;
 free(pkey);
}

canonical_original_code:
void AESF_free_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 struct _AESF_key_schedule_t *pkey = (AESF_key_schedule_t *)pciphinst->pkey_schedule;
 free(pkey);
}

user_defined_types: struct _block_cipher_instance_t { int bl; int kl; char user_IV[64]; int have_user_IV; char user_key_mat[64]; int have_user_key_mat; void *pkey_schedule; int do_cbc; int alg_debug; }

user_defined_types: struct _AESF_key_schedule_t { unsigned long rk[-1][-1]; }


decompiled_code:
__int64 __fastcall AESF_encrypt_bytes(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[64]; // [rsp+0h] [rbp-98h] BYREF
char v7[88]; // [rsp+40h] [rbp-58h] BYREF

v4 = *((_QWORD *)a3 + 18);
AESF_bytes_to_block(*a3, a1, v7);
LODWORD(v4) = AESF_encrypt_block(v7, v6, a3[1], *a3, v4);
AESF_block_to_bytes(*a3, v6, a2);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[64]; // [rsp+0h] [rbp-98h] BYREF
char v7[88]; // [rsp+40h] [rbp-58h] BYREF

v4 = *((_QWORD *)a3 + 18);
AESF_bytes_to_block(*a3, a1, v7);
LODWORD(v4) = AESF_encrypt_block(v7, v6, a3[1], *a3, v4);
AESF_block_to_bytes(*a3, v6, a2);
return (unsigned int)v4;
}

original_code:
int AESF_encrypt_bytes(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 u32 block_in [(256/32)];
 u32 block_out[(256/32)];
 AESF_key_schedule_t * pkey =
  (AESF_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 AESF_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AESF_encrypt_block(block_in, block_out,
  pciphinst->kl, pciphinst->bl, pkey->rk);
 AESF_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

canonical_original_code:
int AESF_encrypt_bytes(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 unsigned long block_in[-1];
 unsigned long block_out[-1];
 struct _AESF_key_schedule_t *pkey = (AESF_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 AESF_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AESF_encrypt_block(block_in, block_out,
  pciphinst->kl, pciphinst->bl, pkey->rk);
 AESF_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

variable_types: rv int


decompiled_code:
__int64 __fastcall AESF_decrypt_bytes(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[64]; // [rsp+0h] [rbp-98h] BYREF
char v7[88]; // [rsp+40h] [rbp-58h] BYREF

v4 = *((_QWORD *)a3 + 18);
AESF_bytes_to_block(*a3, a1, v7);
LODWORD(v4) = AESF_decrypt_block(v7, v6, a3[1], *a3, v4);
AESF_block_to_bytes(*a3, v6, a2);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[64]; // [rsp+0h] [rbp-98h] BYREF
char v7[88]; // [rsp+40h] [rbp-58h] BYREF

v4 = *((_QWORD *)a3 + 18);
AESF_bytes_to_block(*a3, a1, v7);
LODWORD(v4) = AESF_decrypt_block(v7, v6, a3[1], *a3, v4);
AESF_block_to_bytes(*a3, v6, a2);
return (unsigned int)v4;
}

original_code:
int AESF_decrypt_bytes(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 u32 block_in [(256/32)];
 u32 block_out[(256/32)];
 AESF_key_schedule_t * pkey =
  (AESF_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 AESF_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AESF_decrypt_block(block_in, block_out,
  pciphinst->kl, pciphinst->bl, pkey->rk);
 AESF_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

canonical_original_code:
int AESF_decrypt_bytes(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 unsigned long block_in[-1];
 unsigned long block_out[-1];
 struct _AESF_key_schedule_t *pkey = (AESF_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 AESF_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AESF_decrypt_block(block_in, block_out,
  pciphinst->kl, pciphinst->bl, pkey->rk);
 AESF_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}


decompiled_code:
__int64 __fastcall valid_key_length(int a1)
{
return (a1 == 32) | (unsigned __int8)((a1 & 0xFFFFFFF7) == 16);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (a1 == 32) | (unsigned __int8)((a1 & 0xFFFFFFF7) == 16);
}

original_code:
static int valid_key_length(
 int kl)
{
 if (kl == 16)
  return 1;
 else if (kl == 24)
  return 1;
 else if (kl == 32)
  return 1;
 else
  return 0;
}

canonical_original_code:
static int valid_key_length(int kl)
{
 if (kl == 16)
  return 1;
 else if (kl == 24)
  return 1;
 else if (kl == 32)
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall sfei_check_bl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

original_code:
static int sfei_check_bl(
 int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

canonical_original_code:
static int sfei_check_bl(int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}


decompiled_code:
__int64 __fastcall sfei_check_kl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

original_code:
static int sfei_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

canonical_original_code:
static int sfei_check_kl(int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}


decompiled_code:
const char *sfei_explain_error()
{
return "SFEI does not yet feel the need to explain itself";
}

canonical_decompiled_code:
const char *func3()
{
return "SFEI does not yet feel the need to explain itself";
}

original_code:
static char * sfei_explain_error(
 int error_code)
{
 return "SFEI does not yet feel the need to explain itself";
}

canonical_original_code:
static char *sfei_explain_error(int error_code)
{
 return "SFEI does not yet feel the need to explain itself";
}


decompiled_code:
void __fastcall sfei_free_key(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

original_code:
static void sfei_free_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 char * ks = (char *)pciphinst->pkey_schedule;
 free(ks);
}

canonical_original_code:
static void sfei_free_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 char *ks = (char *)pciphinst->pkey_schedule;
 free(ks);
}

variable_types:
ks
char *


decompiled_code:
__int64 __fastcall sfei_make_key(char *s, __int64 a2)
{
void *v2; // rax
void *v3; // rbx
size_t v4; // rax
__int64 result; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 4294967294LL;
v3 = v2;
*(_QWORD *)(a2 + 144) = v2;
v4 = strlen(s);
fill_region_from_other(v3, 16LL, s, v4);
result = 1LL;
if ( *(_DWORD *)(a2 + 156) )
{
hex_dump_region("SFEI KS", v3, 16LL, 4LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, __int64 a2)
{
void *v2; // rax
void *v3; // rbx
size_t v4; // rax
__int64 result; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 4294967294LL;
v3 = v2;
*(_QWORD *)(a2 + 144) = v2;
v4 = strlen(s);
fill_region_from_other(v3, 16LL, s, v4);
result = 1LL;
if ( *(_DWORD *)(a2 + 156) )
{
hex_dump_region("SFEI KS", v3, 16LL, 4LL);
result = 1LL;
}
return result;
}

original_code:
static int sfei_make_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 char * ks;
 int rv = 1;
 int len;
 ks = (char *)malloc(sizeof(char) * 4 * 4);
 if (ks == 0)
  return -2;
 pciphinst->pkey_schedule = (void *)ks;
 len = strlen(key_material);
 fill_region_from_other(ks, 4 * 4, key_material, len);
 if (pciphinst->alg_debug)
  hex_dump_region("SFEI KS", ks, 4 * 4, 4);
 return rv;
}

canonical_original_code:
static int sfei_make_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 char *ks;
 int rv = 1;
 int len;
 ks = (char *)malloc(sizeof(char) * 4 * 4);
 if (ks == 0)
  return -2;
 pciphinst->pkey_schedule = (void *)ks;
 len = strlen(key_material);
 fill_region_from_other(ks, 4 * 4, key_material, len);
 if (pciphinst->alg_debug)
  hex_dump_region("SFEI KS", ks, 4 * 4, 4);
 return rv;
}

variable_types: len int


original_code:
static int sfei_decrypt_block(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 char * ks = (char *)pciphinst->pkey_schedule;
 char * rk = &ks[(4 - 1) * 4];
 int r;
 int i;
 if (pciphinst->alg_debug)
  dump("blin", bytes_in, (4 * 2));
 for (i = 0; i < (4 * 2); i++)
  bytes_out[i] = bytes_in[i];
 for (r = 0; r < 4; r++) {
  char * L = &bytes_out[0];
  char * R = &bytes_out[4];
  char Lt[4];
  char Rt[4];
  char fXK[4];
  f(fXK, L, rk);
  for (i = 0; i < 4; i++) {
   Lt[i] = R[i] ^ fXK[i];
   Rt[i] = L[i];
  }
  for (i = 0; i < 4; i++) {
   L[i] = Lt[i];
   R[i] = Rt[i];
  }
  if (pciphinst->alg_debug)
   dump3("rnd", "rk", "fXK",
    bytes_out, rk, fXK, (4 * 2), 4, 4);
  rk -= 4;
 }
 if (pciphinst->alg_debug)
  fprintf(stderr, "\n");
 return 1;
}

canonical_original_code:
static int sfei_decrypt_block(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 char *ks = (char *)pciphinst->pkey_schedule;
 char *rk = &ks[(4 - 1) * 4];
 int r;
 int i;
 if (pciphinst->alg_debug)
  dump("blin", bytes_in, (4 * 2));
 for (i = 0; i < (4 * 2); i++)
  bytes_out[i] = bytes_in[i];
 for (r = 0; r < 4; r++) {
  char *L = &bytes_out[0];
  char *R = &bytes_out[4];
  char Lt[4];
  char Rt[4];
  char fXK[4];
  f(fXK, L, rk);
  for (i = 0; i < 4; i++) {
   Lt[i] = R[i] ^ fXK[i];
   Rt[i] = L[i];
  }
  for (i = 0; i < 4; i++) {
   L[i] = Lt[i];
   R[i] = Rt[i];
  }
  if (pciphinst->alg_debug)
   dump3("rnd", "rk", "fXK",
    bytes_out, rk, fXK, (4 * 2), 4, 4);
  rk -= 4;
 }
 if (pciphinst->alg_debug)
  fprintf(stderr, "\n");
 return 1;
}

variable_types:
rk
char *

variable_types: r int

variable_types: i int

variable_types:
L
char *

variable_types:
R
char *

variable_types:
Lt
char [4]

variable_types:
Rt
char [4]

variable_types:
fXK
char [4]


original_code:
static int sfei_encrypt_block(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 char * ks = (char *)pciphinst->pkey_schedule;
 char * rk = &ks[0];
 int r;
 int i;
 if (pciphinst->alg_debug)
  dump("blin", bytes_in, (4 * 2));
 for (i = 0; i < (4 * 2); i++)
  bytes_out[i] = bytes_in[i];
 for (r = 0; r < 4; r++) {
  char * L = &bytes_out[0];
  char * R = &bytes_out[4];
  char Lt[4];
  char Rt[4];
  char fXK[4];
  f(fXK, R, rk);
  for (i = 0; i < 4; i++) {
   Lt[i] = R[i];
   Rt[i] = L[i] ^ fXK[i];
  }
  for (i = 0; i < 4; i++) {
   L[i] = Lt[i];
   R[i] = Rt[i];
  }
  if (pciphinst->alg_debug)
   dump3("rnd", "rk", "fXK",
    bytes_out, rk, fXK, (4 * 2), 4, 4);
  rk += 4;
 }
 if (pciphinst->alg_debug)
  fprintf(stderr, "\n");
 return 1;
}

canonical_original_code:
static int sfei_encrypt_block(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 char *ks = (char *)pciphinst->pkey_schedule;
 char *rk = &ks[0];
 int r;
 int i;
 if (pciphinst->alg_debug)
  dump("blin", bytes_in, (4 * 2));
 for (i = 0; i < (4 * 2); i++)
  bytes_out[i] = bytes_in[i];
 for (r = 0; r < 4; r++) {
  char *L = &bytes_out[0];
  char *R = &bytes_out[4];
  char Lt[4];
  char Rt[4];
  char fXK[4];
  f(fXK, R, rk);
  for (i = 0; i < 4; i++) {
   Lt[i] = R[i];
   Rt[i] = L[i] ^ fXK[i];
  }
  for (i = 0; i < 4; i++) {
   L[i] = Lt[i];
   R[i] = Rt[i];
  }
  if (pciphinst->alg_debug)
   dump3("rnd", "rk", "fXK",
    bytes_out, rk, fXK, (4 * 2), 4, 4);
  rk += 4;
 }
 if (pciphinst->alg_debug)
  fprintf(stderr, "\n");
 return 1;
}


original_code:
static int binv_encrypt_block(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = ~*bytes_in++;
 return 1;
}

canonical_original_code:
static int binv_encrypt_block(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = ~*bytes_in++;
 return 1;
}


original_code:
static int binv_decrypt_block(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = ~*bytes_in++;
 return 1;
}

canonical_original_code:
static int binv_decrypt_block(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = ~*bytes_in++;
 return 1;
}


decompiled_code:
__int64 binv_make_key()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
static int binv_make_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 return 1;
}

canonical_original_code:
static int binv_make_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 return 1;
}


decompiled_code:
void binv_free_key()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
static void binv_free_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
}

canonical_original_code:
static void binv_free_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
}


decompiled_code:
__int64 __fastcall binv_check_bl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

original_code:
static int binv_check_bl(
 int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

canonical_original_code:
static int binv_check_bl(int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}


decompiled_code:
__int64 __fastcall binv_check_kl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

original_code:
static int binv_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

canonical_original_code:
static int binv_check_kl(int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}


decompiled_code:
const char *binv_explain_error()
{
return "BINV cipher has nothing to explain.";
}

canonical_decompiled_code:
const char *func6()
{
return "BINV cipher has nothing to explain.";
}

original_code:
static char * binv_explain_error(
 int error_code)
{
 return "BINV cipher has nothing to explain.";
}

canonical_original_code:
static char *binv_explain_error(int error_code)
{
 return "BINV cipher has nothing to explain.";
}


original_code:
static void bytes_to_block(
 int bl,
 char * input,
 u8 block[4][(256/32)])
{
 int j;
 int n = bl >> 2;
 int j2;
 for (j = 0; j < n; j++) {
  j2 = j << 2;
  block[0][j] = 0xff & input[j2];
  block[1][j] = 0xff & input[j2+1];
  block[2][j] = 0xff & input[j2+2];
  block[3][j] = 0xff & input[j2+3];
 }
}

canonical_original_code:
static void bytes_to_block(int bl, char *input, unsigned char block[4][-1])
{
 int j;
 int n = bl >> 2;
 int j2;
 for (j = 0; j < n; j++) {
  j2 = j << 2;
  block[0][j] = 0xff & input[j2];
  block[1][j] = 0xff & input[j2+1];
  block[2][j] = 0xff & input[j2+2];
  block[3][j] = 0xff & input[j2+3];
 }
}

variable_types:
input
char *

variable_types:
block
unsigned char [4][-1]

variable_types: j int

variable_types: n int


original_code:
static void block_to_bytes(
 int bl,
 u8 block[4][(256/32)],
 char * output)
{
 int j;
 int n = bl >> 2;
 int j2;
 for (j = 0; j < n; j++) {
  j2 = j << 2;
  output[j2 ] = (char) block[0][j];
  output[j2+1] = (char) block[1][j];
  output[j2+2] = (char) block[2][j];
  output[j2+3] = (char) block[3][j];
 }
}

canonical_original_code:
static void block_to_bytes(int bl, unsigned char block[4][-1], char *output)
{
 int j;
 int n = bl >> 2;
 int j2;
 for (j = 0; j < n; j++) {
  j2 = j << 2;
  output[j2 ] = (char) block[0][j];
  output[j2+1] = (char) block[1][j];
  output[j2+2] = (char) block[2][j];
  output[j2+3] = (char) block[3][j];
 }
}

variable_types: bl int

variable_types:
output
char *


decompiled_code:
const char *AES_explain_error()
{
return "not there yet";
}

canonical_decompiled_code:
const char *func3()
{
return "not there yet";
}

original_code:
static char * AES_explain_error(
 int code)
{
 return "not there yet";
}

canonical_original_code:
static char *AES_explain_error(int code)
{
 return "not there yet";
}

variable_types: code int


decompiled_code:
__int64 __fastcall AES_check_bl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

original_code:
static int AES_check_bl(
 int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

canonical_original_code:
static int AES_check_bl(int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}


decompiled_code:
__int64 __fastcall AES_check_kl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

original_code:
static int AES_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

canonical_original_code:
static int AES_check_kl(int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

variable_types: kl int


decompiled_code:
void __fastcall AES_free_key(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

original_code:
void AES_free_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 AES_key_schedule_t * pkey =
  (AES_key_schedule_t *)pciphinst->pkey_schedule;
 free(pkey);
}

canonical_original_code:
void AES_free_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 struct _AES_key_schedule_t *pkey = (AES_key_schedule_t *)pciphinst->pkey_schedule;
 free(pkey);
}

variable_types: struct _block_cipher_instance_t { int bl; int kl; char user_IV[64]; int have_user_IV; char user_key_mat[64]; int have_user_key_mat; void *pkey_schedule; int do_cbc; int alg_debug; } *

variable_types: struct _AES_key_schedule_t { unsigned char rk[-1][4][-1]; } *


decompiled_code:
__int64 __fastcall AES_encrypt_bytes(_BYTE *a1, _BYTE *a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = *((_QWORD *)a3 + 18);
bytes_to_block(*a3, a1, v7);
LODWORD(v4) = AES_encrypt_block(v7, v6, a3[1], *a3, v4);
block_to_bytes(*a3, v6, a2);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, _BYTE *a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = *((_QWORD *)a3 + 18);
func1(*a3, a1, v7);
LODWORD(v4) = AES_encrypt_block(v7, v6, a3[1], *a3, v4);
func2(*a3, v6, a2);
return (unsigned int)v4;
}

original_code:
int AES_encrypt_bytes(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 u8 block_in [4][(256/32)];
 u8 block_out[4][(256/32)];
 AES_key_schedule_t * pkey =
  (AES_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AES_encrypt_block(block_in, block_out,
  pciphinst->kl,
  pciphinst->bl, pkey->rk);
 block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

canonical_original_code:
int AES_encrypt_bytes(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 unsigned char block_in[4][-1];
 unsigned char block_out[4][-1];
 struct _AES_key_schedule_t *pkey = (AES_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AES_encrypt_block(block_in, block_out,
  pciphinst->kl,
  pciphinst->bl, pkey->rk);
 block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

variable_types: rv int

user_defined_types: struct _AES_key_schedule_t { unsigned char rk[-1][4][-1]; }


decompiled_code:
__int64 __fastcall AES_decrypt_bytes(_BYTE *a1, _BYTE *a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = *((_QWORD *)a3 + 18);
bytes_to_block(*a3, a1, v7);
LODWORD(v4) = AES_decrypt_block(v7, v6, a3[1], *a3, v4);
block_to_bytes(*a3, v6, a2);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, _BYTE *a2, unsigned int *a3)
{
__int64 v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = *((_QWORD *)a3 + 18);
func1(*a3, a1, v7);
LODWORD(v4) = AES_decrypt_block(v7, v6, a3[1], *a3, v4);
func2(*a3, v6, a2);
return (unsigned int)v4;
}

original_code:
int AES_decrypt_bytes(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 u8 block_in [4][(256/32)];
 u8 block_out[4][(256/32)];
 AES_key_schedule_t * pkey =
  (AES_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AES_decrypt_block(block_in, block_out,
  pciphinst->kl,
  pciphinst->bl, pkey->rk);
 block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

canonical_original_code:
int AES_decrypt_bytes(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 unsigned char block_in[4][-1];
 unsigned char block_out[4][-1];
 struct _AES_key_schedule_t *pkey = (AES_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = AES_decrypt_block(block_in, block_out,
  pciphinst->kl,
  pciphinst->bl, pkey->rk);
 block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}


decompiled_code:
__int64 __fastcall valid_key_length(int a1)
{
return (a1 == 32) | (unsigned __int8)((a1 & 0xFFFFFFF7) == 16);
}

original_code:
static int valid_key_length(
 int kl)
{
 if (kl == 16)
  return 1;
 else if (kl == 24)
  return 1;
 else if (kl == 32)
  return 1;
 else
  return 0;
}

canonical_original_code:
static int valid_key_length(int kl)
{
 if (kl == 16)
  return 1;
 else if (kl == 24)
  return 1;
 else if (kl == 32)
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall AES_make_key(__int64 a1, unsigned int *a2)
{
int v2; // er12
void *v3; // rax
void *v4; // rbp
int v5; // er8
__int64 v6; // rax
__int64 v8; // [rsp+0h] [rbp-88h] BYREF
char dest[104]; // [rsp+20h] [rbp-68h] BYREF

v2 = a2[1];
if ( !(unsigned int)valid_key_length(v2) )
return 4294967292LL;
v3 = malloc(0x1E0uLL);
v4 = v3;
if ( !v3 )
return 4294967294LL;
*((_QWORD *)a2 + 18) = v3;
if ( a2[35] )
memcpy(dest, a2 + 19, v2);
else
fill_region_from_string(dest, (unsigned int)v2, a1);
v5 = a2[1];
v6 = 0LL;
if ( v5 > 0 )
{
do
{
dest[8 * (v6 & 3) - 32 + ((int)v6 >> 2)] = dest[v6];
++v6;
}
while ( v6 != v5 );
}
if ( a2[39] )
hex_dump_region("AES key material", dest, (unsigned int)v5, 16LL);
AES_key_schedule(&v8, a2[1], *a2, v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int *a2)
{
int v2; // er12
void *v3; // rax
void *v4; // rbp
int v5; // er8
__int64 v6; // rax
__int64 v8; // [rsp+0h] [rbp-88h] BYREF
char dest[104]; // [rsp+20h] [rbp-68h] BYREF

v2 = a2[1];
if ( !(unsigned int)func0(v2) )
return 4294967292LL;
v3 = malloc(0x1E0uLL);
v4 = v3;
if ( !v3 )
return 4294967294LL;
*((_QWORD *)a2 + 18) = v3;
if ( a2[35] )
memcpy(dest, a2 + 19, v2);
else
fill_region_from_string(dest, (unsigned int)v2, a1);
v5 = a2[1];
v6 = 0LL;
if ( v5 > 0 )
{
do
{
dest[8 * (v6 & 3) - 32 + ((int)v6 >> 2)] = dest[v6];
++v6;
}
while ( v6 != v5 );
}
if ( a2[39] )
hex_dump_region("AES key material", dest, (unsigned int)v5, 16LL);
AES_key_schedule(&v8, a2[1], *a2, v4);
return 1LL;
}

original_code:
int AES_make_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 char full_key_material[64];
 AES_key_schedule_t * pks;
 u8 key_mat_block[4][(256/32)];
 int i;
 if (!valid_key_length(pciphinst->kl))
  return -4;
 pks = (AES_key_schedule_t *)malloc(sizeof(AES_key_schedule_t));
 if (pks == 0)
  return -2;
 pciphinst->pkey_schedule = pks;
 if (pciphinst->have_user_key_mat) {
  memcpy(full_key_material, pciphinst->user_key_mat,
   pciphinst->kl);
 }
 else {
  fill_region_from_string(full_key_material,
   pciphinst->kl, key_material);
 }
 for (i = 0; i < pciphinst->kl; i++)
  key_mat_block[i & 3][i >> 2] = (u8) full_key_material[i];
 if (pciphinst->alg_debug) {
  hex_dump_region("AES key material",
   full_key_material,
   pciphinst->kl,16);
 }
 AES_key_schedule(key_mat_block, pciphinst->kl,
  pciphinst->bl, pks->rk);
 return 1;
}

canonical_original_code:
int AES_make_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 char full_key_material[64];
 struct _AES_key_schedule_t *pks;
 unsigned char key_mat_block[4][-1];
 int i;
 if (!valid_key_length(pciphinst->kl))
  return -4;
 pks = (struct _AES_key_schedule_t *)malloc(sizeof(AES_key_schedule_t));
 if (pks == 0)
  return -2;
 pciphinst->pkey_schedule = pks;
 if (pciphinst->have_user_key_mat) {
  memcpy(full_key_material, pciphinst->user_key_mat,
   pciphinst->kl);
 }
 else {
  fill_region_from_string(full_key_material,
   pciphinst->kl, key_material);
 }
 for (i = 0; i < pciphinst->kl; i++)
  key_mat_block[i & 3][i >> 2] = (unsigned char) full_key_material[i];
 if (pciphinst->alg_debug) {
  hex_dump_region("AES key material",
   full_key_material,
   pciphinst->kl,16);
 }
 AES_key_schedule(key_mat_block, pciphinst->kl,
  pciphinst->bl, pks->rk);
 return 1;
}

variable_types: i int


original_code:
static int twiddle_encrypt_block(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 int single_xor = *(int *)pciphinst->pkey_schedule;
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = *bytes_in++ ^ single_xor;
 return 1;
}

canonical_original_code:
static int twiddle_encrypt_block(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 int single_xor = *(int *)pciphinst->pkey_schedule;
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = *bytes_in++ ^ single_xor;
 return 1;
}


original_code:
static int twiddle_decrypt_block(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 int single_xor = *(int *)pciphinst->pkey_schedule;
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = *bytes_in++ ^ single_xor;
 return 1;
}

canonical_original_code:
static int twiddle_decrypt_block(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 int single_xor = *(int *)pciphinst->pkey_schedule;
 int i;
 for (i = 0; i < pciphinst->bl; i++)
  *bytes_out++ = *bytes_in++ ^ single_xor;
 return 1;
}


decompiled_code:
__int64 __fastcall twiddle_check_bl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967285LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -11 : 1;
return result;
}

original_code:
static int twiddle_check_bl(
 int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

canonical_original_code:
static int twiddle_check_bl(int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}


decompiled_code:
__int64 __fastcall twiddle_check_kl(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0x20 )
result = 4294967284LL;
else
result = ((1LL << a1) & 0x101010000LL) == 0 ? -12 : 1;
return result;
}

original_code:
static int twiddle_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

canonical_original_code:
static int twiddle_check_kl(int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}


decompiled_code:
const char *twiddle_explain_error()
{
return "Twiddle does not yet feel the need to explain itself";
}

canonical_decompiled_code:
const char *func4()
{
return "Twiddle does not yet feel the need to explain itself";
}

original_code:
static char * twiddle_explain_error(
 int error_code)
{
 return "Twiddle does not yet feel the need to explain itself";
}

canonical_original_code:
static char *twiddle_explain_error(int error_code)
{
 return "Twiddle does not yet feel the need to explain itself";
}


decompiled_code:
void __fastcall twiddle_free_key(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2)
{
free(*(void **)(a2 + 144));
}

original_code:
static void twiddle_free_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 int * pxor = (int *)pciphinst->pkey_schedule;
 free(pxor);
}

canonical_original_code:
static void twiddle_free_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 int *pxor = (int *)pciphinst->pkey_schedule;
 free(pxor);
}

variable_types:
pxor
int *


decompiled_code:
__int64 __fastcall twiddle_make_key(const char *a1, __int64 a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbx
unsigned int v4; // ebp

v2 = (unsigned int *)malloc(4uLL);
if ( !v2 )
return (unsigned int)-2;
v3 = v2;
*v2 = 0;
*(_QWORD *)(a2 + 144) = v2;
v4 = _isoc99_sscanf(a1, "%x", v2);
if ( v4 == 1 )
{
if ( *(_DWORD *)(a2 + 156) )
fprintf(stderr, "Twiddle: key mat \"%s\" -> 0x%02x\n", a1, *v3);
}
else
{
if ( *(_DWORD *)(a2 + 156) )
fwrite("Twiddle: key mat extraction failed.\n", 1uLL, 0x24uLL, stderr);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbx
unsigned int v4; // ebp

v2 = (unsigned int *)malloc(4uLL);
if ( !v2 )
return (unsigned int)-2;
v3 = v2;
*v2 = 0;
*(_QWORD *)(a2 + 144) = v2;
v4 = _isoc99_sscanf(a1, "%x", v2);
if ( v4 == 1 )
{
if ( *(_DWORD *)(a2 + 156) )
fprintf(stderr, "Twiddle: key mat \"%s\" -> 0x%02x\n", a1, *v3);
}
else
{
if ( *(_DWORD *)(a2 + 156) )
fwrite("Twiddle: key mat extraction failed.\n", 1uLL, 0x24uLL, stderr);
v4 = -1;
}
return v4;
}

original_code:
static int twiddle_make_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 int * pxor;
 int rv;
 pxor = (int *)malloc(sizeof(int));
 if (pxor == 0)
  return -2;
 *pxor = 0;
 pciphinst->pkey_schedule = (void *)pxor;
 if (sscanf(key_material, "%x", pxor) != 1)
  rv = -1;
 else
  rv = 1;
 if (pciphinst->alg_debug) {
  if (rv == 1)
   fprintf(stderr, "Twiddle: key mat \"%s\" -> 0x%02x\n",
    key_material, *pxor);
  else
   fprintf(stderr, "Twiddle: key mat extraction failed.\n");
 }
 return rv;
}

canonical_original_code:
static int twiddle_make_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 int *pxor;
 int rv;
 pxor = (int *)malloc(sizeof(int));
 if (pxor == 0)
  return -2;
 *pxor = 0;
 pciphinst->pkey_schedule = (void *)pxor;
 if (sscanf(key_material, "%x", pxor) != 1)
  rv = -1;
 else
  rv = 1;
 if (pciphinst->alg_debug) {
  if (rv == 1)
   fprintf(stderr, "Twiddle: key mat \"%s\" -> 0x%02x\n",
    key_material, *pxor);
  else
   fprintf(stderr, "Twiddle: key mat extraction failed.\n");
 }
 return rv;
}


decompiled_code:
void *__fastcall my_malloc(unsigned int a1)
{
void *result; // rax

result = malloc((int)a1);
if ( !result )
{
fprintf(stderr, "malloc(%d) failed.\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(unsigned int a1)
{
void *result; // rax

result = malloc((int)a1);
if ( !result )
{
fprintf(stderr, "malloc(%d) failed.\n", a1);
exit(1);
}
return result;
}

original_code:
void * my_malloc(
 int num_bytes)
{
 void * rv;
 rv = malloc(num_bytes);
 if (rv == 0) {
  fprintf(stderr, "malloc(%d) failed.\n", num_bytes);
  exit(1);
 }
 return rv;
}

canonical_original_code:
void *my_malloc(int num_bytes)
{
 void *rv;
 rv = malloc(num_bytes);
 if (rv == 0) {
  fprintf(stderr, "malloc(%d) failed.\n", num_bytes);
  exit(1);
 }
 return rv;
}

variable_types:
rv
void *

return_type: void *


decompiled_code:
__int64 __fastcall round_up(int a1, int a2)
{
return (unsigned int)(a2 * ((a2 + a1 - 1) / a2));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return (unsigned int)(a2 * ((a2 + a1 - 1) / a2));
}

original_code:
int round_up(
 int x,
 int n)
{
 return ((x + n - 1) / n) * n;
}

canonical_original_code:
int round_up(int x, int n)
{
 return ((x + n - 1) / n) * n;
}

variable_types: x int


original_code:
void XOR_blocks(
 char * dst,
 char * src1,
 char * src2,
 int num_bytes)
{
 while (num_bytes-- > 0) {
  *dst++ = *src1++ ^ *src2++;
 }
}

canonical_original_code:
void XOR_blocks(char *dst, char *src1, char *src2, int num_bytes)
{
 while (num_bytes-- > 0) {
  *dst++ = *src1++ ^ *src2++;
 }
}

variable_types:
dst
char *


decompiled_code:
size_t __fastcall dump_block(const char *a1, char *a2, int a3)
{
char *v4; // rbx
const unsigned __int16 **v5; // r12
char v6; // di

v4 = a2;
fprintf(stderr, "%8s @ 0x%08llx: <<", a1, a2);
if ( a3 > 0 )
{
v5 = _ctype_b_loc();
do
{
v6 = *v4;
if ( ((*v5)[*v4] & 0x4000) == 0 )
v6 = 46;
fputc(v6, stderr);
++v4;
}
while ( v4 != &a2[a3] );
}
return fwrite(">>\n", 1uLL, 3uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func7(const char *a1, char *a2, int a3)
{
char *v4; // rbx
const unsigned __int16 **v5; // r12
char v6; // di

v4 = a2;
fprintf(stderr, "%8s @ 0x%08llx: <<", a1, a2);
if ( a3 > 0 )
{
v5 = _ctype_b_loc();
do
{
v6 = *v4;
if ( ((*v5)[*v4] & 0x4000) == 0 )
v6 = 46;
fputc(v6, stderr);
++v4;
}
while ( v4 != &a2[a3] );
}
return fwrite(">>\n", 1uLL, 3uLL, stderr);
}

original_code:
void dump_block(
 char * desc,
 char * block,
 int num_bytes)
{
 int i;
 fprintf(stderr, "%8s @ 0x%08llx: <<", desc, (unsigned long long)block);
 for (i = 0; i < num_bytes; i++) {
  fprintf(stderr, "%c",
   (((*__ctype_b_loc ())[(int) (((unsigned)block[i]))] & (unsigned short int) _ISprint) ? block[i] : '.'));
 }
 fprintf(stderr, ">>\n");
}

canonical_original_code:
void dump_block(char *desc, char *block, int num_bytes)
{
 int i;
 fprintf(stderr, "%8s @ 0x%08llx: <<", desc, (unsigned long long)block);
 for (i = 0; i < num_bytes; i++) {
  fprintf(stderr, "%c",
   (((*__ctype_b_loc ())[(int) (((unsigned int)block[i]))] & (unsigned short) _ISprint) ? block[i] : '.'));
 }
 fprintf(stderr, ">>\n");
}

variable_types:
desc
char *

variable_types:
block
char *


decompiled_code:
void __fastcall accum_eth_CRC(_BYTE *a1, int a2, unsigned int *a3, int a4)
{
unsigned int v4; // eax
__int64 v5; // rcx

switch ( a4 )
{
case 2:
v4 = *a3;
if ( a2 )
{
v5 = (__int64)&a1[a2 - 1 + 1];
do
v4 = eth_CRC_table[(unsigned __int8)(*a1++ ^ v4)] ^ (v4 >> 8);
while ( a1 != (_BYTE *)v5 );
}
*a3 = v4;
break;
case 3:
*a3 = ~*a3;
break;
case 1:
*a3 = -1;
break;
}
}

canonical_decompiled_code:
void __fastcall func8(_BYTE *a1, int a2, unsigned int *a3, int a4)
{
unsigned int v4; // eax
__int64 v5; // rcx

switch ( a4 )
{
case 2:
v4 = *a3;
if ( a2 )
{
v5 = (__int64)&a1[a2 - 1 + 1];
do
v4 = eth_CRC_table[(unsigned __int8)(*a1++ ^ v4)] ^ (v4 >> 8);
while ( a1 != (_BYTE *)v5 );
}
*a3 = v4;
break;
case 3:
*a3 = ~*a3;
break;
case 1:
*a3 = -1;
break;
}
}

original_code:
void accum_eth_CRC(
 char * buf,
 unsigned len,
 unsigned * pcsum,
 unsigned op)
{
 unsigned csum;
 switch (op) {
 case 1:
  *pcsum = 0;
  *pcsum = 0xffffffff;
  break;
 case 2:
  csum = *pcsum;
  while (len--)
   csum = eth_CRC_table[(csum ^ *buf++) & 0xff] ^ (csum >> 8);
  *pcsum = csum;
  break;
 case 3:
  *pcsum ^= 0xffffffff;
  break;
 }
}

canonical_original_code:
void accum_eth_CRC(char *buf, unsigned int len, unsigned int *pcsum, unsigned int op)
{
 unsigned int csum;
 switch (op) {
 case 1:
  *pcsum = 0;
  *pcsum = 0xffffffff;
  break;
 case 2:
  csum = *pcsum;
  while (len--)
   csum = eth_CRC_table[(csum ^ *buf++) & 0xff] ^ (csum >> 8);
  *pcsum = csum;
  break;
 case 3:
  *pcsum ^= 0xffffffff;
  break;
 }
}

variable_types:
buf
char *

variable_types:
len
unsigned int

variable_types:
pcsum
unsigned int *

variable_types:
op
unsigned int

variable_types:
csum
unsigned int


decompiled_code:
int __fastcall RC6_print_block(const char *a1, unsigned int *a2, int a3)
{
unsigned int *v4; // rbx
unsigned int *v5; // rax
int v6; // ebp
const unsigned __int16 **v7; // r13
__int64 v8; // rbx
unsigned __int8 v9; // di

fprintf(stderr, "%-6s: ", a1);
if ( a3 <= 0 )
{
fwrite(" ", 1uLL, 2uLL, stderr);
}
else
{
v4 = a2;
do
{
fprintf(stderr, "%08x ", *v4);
v5 = v4;
v4 += 2;
}
while ( v5 != &a2[2 * (a3 - 1)] );
fwrite(" ", 1uLL, 2uLL, stderr);
v6 = 4 * a3;
v7 = _ctype_b_loc();
v8 = 0LL;
do
{
v9 = *((_BYTE *)a2 + v8);
if ( ((*v7)[v9] & 0x4000) == 0 )
v9 = 46;
fputc(v9, stderr);
++v8;
}
while ( v6 > (int)v8 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, unsigned int *a2, int a3)
{
unsigned int *v4; // rbx
unsigned int *v5; // rax
int v6; // ebp
const unsigned __int16 **v7; // r13
__int64 v8; // rbx
unsigned __int8 v9; // di

fprintf(stderr, "%-6s: ", a1);
if ( a3 <= 0 )
{
fwrite(" ", 1uLL, 2uLL, stderr);
}
else
{
v4 = a2;
do
{
fprintf(stderr, "%08x ", *v4);
v5 = v4;
v4 += 2;
}
while ( v5 != &a2[2 * (a3 - 1)] );
fwrite(" ", 1uLL, 2uLL, stderr);
v6 = 4 * a3;
v7 = _ctype_b_loc();
v8 = 0LL;
do
{
v9 = *((_BYTE *)a2 + v8);
if ( ((*v7)[v9] & 0x4000) == 0 )
v9 = 46;
fputc(v9, stderr);
++v8;
}
while ( v6 > (int)v8 );
}
return fputc(10, stderr);
}

original_code:
void RC6_print_block(
 char * msg,
 u32 * a,
 int BW)
{
 int i;
 u8 * pa = (u8 *)&a[0];
 fprintf(stderr, "%-6s: ", msg);
 for (i = 0; i < BW; i++)
  fprintf(stderr, "%08x ", (unsigned)a[i]);
 fprintf(stderr, "  ");
 for (i = 0; i < BW * 4; i++) {
  fprintf(stderr, "%c", ((*__ctype_b_loc ())[(int) ((pa[i]))] & (unsigned short int) _ISprint) ? pa[i] : '.');
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void RC6_print_block(char *msg, unsigned long *a, int BW)
{
 int i;
 unsigned char *pa = (u8 *)&a[0];
 fprintf(stderr, "%-6s: ", msg);
 for (i = 0; i < BW; i++)
  fprintf(stderr, "%08x ", (unsigned int)a[i]);
 fprintf(stderr, "  ");
 for (i = 0; i < BW * 4; i++) {
  fprintf(stderr, "%c", ((*__ctype_b_loc ())[(int) ((pa[i]))] & (unsigned short) _ISprint) ? pa[i] : '.');
 }
 fprintf(stderr, "\n");
}

variable_types:
msg
char *

variable_types:
a
unsigned long *

variable_types: BW int

variable_types:
pa
unsigned char *


decompiled_code:
int __fastcall RC6_print_2(const char *a1, __int64 a2, __int64 a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a2;
v4[1] = a3;
return RC6_print_block(a1, (unsigned int *)v4, 2);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, __int64 a2, __int64 a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a2;
v4[1] = a3;
return func0(a1, (unsigned int *)v4, 2);
}

original_code:
void RC6_print_2(
 char * msg,
 u32 S1,
 u32 S2)
{
 u32 array[2];
 array[0] = S1;
 array[1] = S2;
 RC6_print_block(msg, array, 2);
}

canonical_original_code:
void RC6_print_2(char *msg, unsigned long S1, unsigned long S2)
{
 unsigned long array[2];
 array[0] = S1;
 array[1] = S2;
 RC6_print_block(msg, array, 2);
}

variable_types:
array
unsigned long [2]


decompiled_code:
int __fastcall RC6_print_4(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v6[5]; // [rsp+0h] [rbp-28h] BYREF

v6[0] = a2;
v6[1] = a3;
v6[2] = a4;
v6[3] = a5;
return RC6_print_block(a1, (unsigned int *)v6, 4);
}

original_code:
void RC6_print_4(
 char * msg,
 u32 A,
 u32 B,
 u32 C,
 u32 D)
{
 u32 array[4];
 array[0] = A;
 array[1] = B;
 array[2] = C;
 array[3] = D;
 RC6_print_block(msg, array, 4);
}

canonical_original_code:
void RC6_print_4(char *msg, unsigned long A, unsigned long B, unsigned long C, unsigned long D)
{
 unsigned long array[4];
 array[0] = A;
 array[1] = B;
 array[2] = C;
 array[3] = D;
 RC6_print_block(msg, array, 4);
}

variable_types:
A
unsigned long

variable_types:
B
unsigned long

variable_types:
C
unsigned long

variable_types:
D
unsigned long

variable_types:
array
unsigned long [4]


original_code:
void RC6_bytes_to_block(
 int num_bytes,
 char * input,
 u32 block[4])
{
 int bi;
 int wi;
 for (bi = 0, wi = 0; bi < num_bytes; bi+=4, wi++) {
  RC6_bytes_to_word(
   input[bi],
   input[bi+1],
   input[bi+2],
   input[bi+3],
   &block[wi]);
 }
}

canonical_original_code:
void RC6_bytes_to_block(int num_bytes, char *input, unsigned long block[4])
{
 int bi;
 int wi;
 for (bi = 0, wi = 0; bi < num_bytes; bi+=4, wi++) {
  RC6_bytes_to_word(
   input[bi],
   input[bi+1],
   input[bi+2],
   input[bi+3],
   &block[wi]);
 }
}

variable_types:
input
char *

variable_types:
block
unsigned long [4]

variable_types: bi int

variable_types: wi int


decompiled_code:
unsigned __int64 __fastcall RC6_block_to_bytes(int a1, unsigned __int64 *a2, _BYTE *a3)
{
_BYTE *v4; // rbx
__int64 v5; // r12
unsigned __int64 result; // rax

if ( a1 > 0 )
{
v4 = a3;
v5 = (__int64)&a3[4 * ((unsigned int)(a1 - 1) >> 2) + 4];
do
{
result = RC6_word_to_bytes(*a2++, v4, v4 + 1, v4 + 2, v4 + 3);
v4 += 4;
}
while ( v4 != (_BYTE *)v5 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(int a1, unsigned __int64 *a2, _BYTE *a3)
{
_BYTE *v4; // rbx
__int64 v5; // r12
unsigned __int64 result; // rax

if ( a1 > 0 )
{
v4 = a3;
v5 = (__int64)&a3[4 * ((unsigned int)(a1 - 1) >> 2) + 4];
do
{
result = func5(*a2++, v4, v4 + 1, v4 + 2, v4 + 3);
v4 += 4;
}
while ( v4 != (_BYTE *)v5 );
}
return result;
}

original_code:
void RC6_block_to_bytes(
 int num_bytes,
 u32 block[4],
 char * output)
{
 int bi;
 int wi;
 for (bi = 0, wi = 0; bi < num_bytes; bi+=4, wi++) {
  RC6_word_to_bytes(
   block[wi],
   &output[bi],
   &output[bi+1],
   &output[bi+2],
   &output[bi+3]);
 }
}

canonical_original_code:
void RC6_block_to_bytes(int num_bytes, unsigned long block[4], char *output)
{
 int bi;
 int wi;
 for (bi = 0, wi = 0; bi < num_bytes; bi+=4, wi++) {
  RC6_word_to_bytes(
   block[wi],
   &output[bi],
   &output[bi+1],
   &output[bi+2],
   &output[bi+3]);
 }
}

variable_types:
output
char *


rotl

decompiled_code:
unsigned __int64 __fastcall rotl(unsigned __int64 a1, char a2)
{
unsigned __int64 result; // rax
int v3; // esi

result = a1;
v3 = a2 & 0x1F;
if ( v3 )
result = (a1 << v3) | (a1 >> (32 - (unsigned __int8)v3));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned __int64 a1, char a2)
{
unsigned __int64 result; // rax
int v3; // esi

result = a1;
v3 = a2 & 0x1F;
if ( v3 )
result = (a1 << v3) | (a1 >> (32 - (unsigned __int8)v3));
return result;
}

original_code:
u32 rotl(u32 in, u32 shamt)
{
 shamt &= 31;
 if (shamt == 0)
  return in;
 return (in << shamt) | (in >> (32 - shamt));
}

canonical_original_code:
unsigned long rotl(unsigned long in, unsigned long shamt)
{
 shamt &= 31;
 if (shamt == 0)
  return in;
 return (in << shamt) | (in >> (32 - shamt));
}

variable_types:
in
unsigned long

variable_types:
shamt
unsigned long

return_type: unsigned long


rotr

decompiled_code:
unsigned __int64 __fastcall rotr(unsigned __int64 a1, char a2)
{
unsigned __int64 result; // rax
int v3; // esi

result = a1;
v3 = a2 & 0x1F;
if ( v3 )
result = (a1 >> v3) | (a1 << (32 - (unsigned __int8)v3));
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 a1, char a2)
{
unsigned __int64 result; // rax
int v3; // esi

result = a1;
v3 = a2 & 0x1F;
if ( v3 )
result = (a1 >> v3) | (a1 << (32 - (unsigned __int8)v3));
return result;
}

original_code:
u32 rotr(u32 in, u32 shamt)
{
 shamt &= 31;
 if (shamt == 0)
  return in;
 return (in >> shamt) | (in << (32 - shamt));
}

canonical_original_code:
unsigned long rotr(unsigned long in, unsigned long shamt)
{
 shamt &= 31;
 if (shamt == 0)
  return in;
 return (in >> shamt) | (in << (32 - shamt));
}


canonical_original_code:
int RC6_key_schedule(unsigned long L[8], int kl, int bl, unsigned long S[-1])
{
 unsigned long i; unsigned long j; unsigned long A; unsigned long B; unsigned long v; unsigned long s;
 int c = kl >> 2;
 int maxw = 2 * 20 + 4;
 S[0] = 0xb7e15163;
 for (i = 1; i < maxw; i++)
  S[i] = S[i-1] + 0x9e3779b9;
 A = B = i = j = 0;
 if (maxw > c)
  v = maxw;
 else
  v = c;
 v *= 3;
 for (s = 1; s <= v; s++) {
  A = S[i] = rotl((S[i] + A + B), 3);
  B = L[j] = rotl((L[j] + A + B), (A + B));
  i = (i + 1) % maxw;
  j = (j + 1) % c;
 }
 return 1;
}

variable_types:
L
unsigned long [8]

variable_types: kl int

variable_types: bl int

variable_types:
S
unsigned long [-1]

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
v
unsigned long

variable_types:
s
unsigned long

variable_types: c int

variable_types: maxw int


canonical_original_code:
int RC6_encrypt_block(unsigned long a[4], unsigned long b[4], int kl, unsigned long S[-1])
{
 int i;
 unsigned long A; unsigned long B; unsigned long C; unsigned long D; unsigned long u; unsigned long t; unsigned long sv;
 A = a[0];
 B = a[1];
 C = a[2];
 D = a[3];
 ;
 B = B + S[0];
 D = D + S[1];
 ;
 ;
 for (i = 1; i <= 20; i++) {
  t = rotl(B * ((B << 1) + 1), 5);
  u = rotl(D * ((D << 1) + 1), 5);
  A = rotl((A ^ t), u) + S[i << 1];
  C = rotl((C ^ u), t) + S[(i << 1) + 1];
  sv = A;
  A = B;
  B = C;
  C = D;
  D = sv;
  ;
  ;
 }
 A = A + S[ 2 * 20 + 2];
 C = C + S[ 2 * 20 + 3];
 ;
 ;
 ;
 b[0] = A;
 b[1] = B;
 b[2] = C;
 b[3] = D;
 return 1;
}

variable_types:
a
unsigned long [4]

variable_types:
b
unsigned long [4]

variable_types: i int

variable_types:
A
unsigned long

variable_types:
B
unsigned long

variable_types:
C
unsigned long

variable_types:
D
unsigned long

variable_types:
u
unsigned long

variable_types:
t
unsigned long

variable_types:
sv
unsigned long


canonical_original_code:
int RC6_decrypt_block(unsigned long a[4], unsigned long b[4], int kl, unsigned long S[-1])
{
 int i;
 unsigned long A; unsigned long B; unsigned long C; unsigned long D; unsigned long u; unsigned long t; unsigned long sv;
 A = a[0];
 B = a[1];
 C = a[2];
 D = a[3];
 ;
 C = C - S[2 * 20 + 3];
 A = A - S[2 * 20 + 2];
 ;
 ;
 for (i = 20; i >= 1; i--) {
  sv = D;
  D = C;
  C = B;
  B = A;
  A = sv;
  u = rotl(D * ((D << 1) + 1), 5);
  t = rotl(B * ((B << 1) + 1), 5);
  C = rotr((C - S[(i<<1)+1]), t) ^ u;
  A = rotr((A - S[(i<<1) ]), u) ^ t;
  ;
  ;
 }
 ;
 D = D - S[1];
 B = B - S[0];
 ;
 ;
 b[0] = A;
 b[1] = B;
 b[2] = C;
 b[3] = D;
 return 1;
}

variable_types: kl int

variable_types:
S
unsigned long [-1]


decompiled_code:
__int64 __fastcall my_AES_encrypt_file(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
_QWORD *v5; // rbx
__m128i *v6; // rbp
int v7; // eax
__int64 result; // rax
int v9; // [rsp+Ch] [rbp-7Ch]
__m128i v11; // [rsp+20h] [rbp-68h] BYREF
__m128i v12; // [rsp+30h] [rbp-58h] BYREF
__int64 v13; // [rsp+44h] [rbp-44h]
int v14; // [rsp+4Ch] [rbp-3Ch]

v9 = round_up(a4, 32LL);
v5 = (_QWORD *)my_malloc((unsigned int)(v9 + 64));
v6 = (__m128i *)my_malloc((unsigned int)(v9 + 64));
memset(v5, 112, v9 + 64);
memset(v6, 99, v9 + 64);
fprintf(stderr, "%s:\n", a2);
fprintf(stderr, " Reading ... ");
fflush(stderr);
read_file_to_region(a2, a4, v5 + 4);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
LODWORD(v13) = -1595885089;
HIDWORD(v13) = (int)a4 % 32;
v14 = get_ethernet_CRC(v5 + 4, a4);
*v5 = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
*v5 = v13;
*((_DWORD *)v5 + 2) = v14;
make_IV(&v11, 0x20u, a1);
*v6 = _mm_loadu_si128(&v11);
v6[1] = _mm_loadu_si128(&v12);
fwrite(" Encrypting ... ", 1uLL, 0x11uLL, stderr);
fflush(stderr);
v7 = AES_encrypt(2LL, 256LL, a1, &v11, v5, (unsigned int)(8 * v9 + 256), &v6[2]);
if ( v7 < 0 )
{
fprintf(stderr, "\nAES_encrypt() failure: code %d.\n", (unsigned int)v7);
free(v5);
free(v6);
result = 0LL;
}
else
{
fwrite(" done.\n", 1uLL, 8uLL, stderr);
fwrite(" Writing ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
write_region_to_file(v6, (unsigned int)(v9 + 64), a3);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
free(v5);
free(v6);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
_QWORD *v5; // rbx
__m128i *v6; // rbp
int v7; // eax
__int64 result; // rax
int v9; // [rsp+Ch] [rbp-7Ch]
__m128i v11; // [rsp+20h] [rbp-68h] BYREF
__m128i v12; // [rsp+30h] [rbp-58h] BYREF
__int64 v13; // [rsp+44h] [rbp-44h]
int v14; // [rsp+4Ch] [rbp-3Ch]

v9 = round_up(a4, 32LL);
v5 = (_QWORD *)my_malloc((unsigned int)(v9 + 64));
v6 = (__m128i *)my_malloc((unsigned int)(v9 + 64));
memset(v5, 112, v9 + 64);
memset(v6, 99, v9 + 64);
fprintf(stderr, "%s:\n", a2);
fprintf(stderr, " Reading ... ");
fflush(stderr);
read_file_to_region(a2, a4, v5 + 4);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
LODWORD(v13) = -1595885089;
HIDWORD(v13) = (int)a4 % 32;
v14 = get_ethernet_CRC(v5 + 4, a4);
*v5 = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
*v5 = v13;
*((_DWORD *)v5 + 2) = v14;
func2(&v11, 0x20u, a1);
*v6 = _mm_loadu_si128(&v11);
v6[1] = _mm_loadu_si128(&v12);
fwrite(" Encrypting ... ", 1uLL, 0x11uLL, stderr);
fflush(stderr);
v7 = AES_encrypt(2LL, 256LL, a1, &v11, v5, (unsigned int)(8 * v9 + 256), &v6[2]);
if ( v7 < 0 )
{
fprintf(stderr, "\nAES_encrypt() failure: code %d.\n", (unsigned int)v7);
free(v5);
free(v6);
result = 0LL;
}
else
{
fwrite(" done.\n", 1uLL, 8uLL, stderr);
fwrite(" Writing ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
write_region_to_file(v6, (unsigned int)(v9 + 64), a3);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
free(v5);
free(v6);
result = 1LL;
}
return result;
}

original_code:
static int my_AES_encrypt_file(
 key_instance * pkey_instance,
 char * input_file_name,
 char * output_file_name,
 int plaintext_file_size)
{
 int augmented_plaintext_file_size = 0;
 int ciphertext_file_size = 0;
 header_t header;
 char * input_buffer;
 char * output_buffer;
 char * pinblock0;
 char * pinblock1;
 char * poutblock0;
 char * poutblock1;
 int encrypt_rc;
 BYTE IV[32];
 augmented_plaintext_file_size = round_up(plaintext_file_size,
  32);
 augmented_plaintext_file_size += 32;
 ciphertext_file_size = augmented_plaintext_file_size +
  32;
 input_buffer = my_malloc(ciphertext_file_size);
 output_buffer = my_malloc(ciphertext_file_size);
 memset(input_buffer, 'p', ciphertext_file_size);
 memset(output_buffer, 'c', ciphertext_file_size);
 pinblock0 = &input_buffer [0];
 pinblock1 = &input_buffer [32];
 poutblock0 = &output_buffer[0];
 poutblock1 = &output_buffer[32];
 fprintf(stderr, "%s:\n", input_file_name);
 fprintf(stderr, "  Reading ... ", input_file_name); fflush(stderr);
 read_file_to_region(input_file_name, plaintext_file_size, pinblock1);
 fprintf(stderr, "  done.\n");
 header.magic_number = 0xa0e0b9df;
 header.bytes_in_last_plaintext_block =
  plaintext_file_size % 32;
 header.CRC = get_ethernet_CRC(pinblock1, plaintext_file_size);
 memset(pinblock0, 0, 32);
 memcpy(pinblock0, &header, sizeof(header));
 make_IV(IV, 32, pkey_instance);
 memcpy(poutblock0, IV, 32);
 fprintf(stderr, "  Encrypting ... "); fflush(stderr);
 encrypt_rc = AES_encrypt(2, 32 * 8,
  pkey_instance, IV, pinblock0,
  augmented_plaintext_file_size * 8, poutblock1);
 if (encrypt_rc < 0) {
  fprintf(stderr, "\nAES_encrypt() failure:  code %d.\n",
   encrypt_rc);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 fprintf(stderr, "  done.\n");
 fprintf(stderr, "  Writing ... "); fflush(stderr);
 write_region_to_file(output_buffer, ciphertext_file_size,
  output_file_name);
 fprintf(stderr, "  done.\n");
 free(input_buffer);
 free(output_buffer);
 return 1;
}

canonical_original_code:
static int my_AES_encrypt_file(struct _key_instance *pkey_instance, char *input_file_name, char *output_file_name, int plaintext_file_size)
{
 int augmented_plaintext_file_size = 0;
 int ciphertext_file_size = 0;
 struct _header_t header;
 char *input_buffer;
 char *output_buffer;
 char *pinblock0;
 char *pinblock1;
 char *poutblock0;
 char *poutblock1;
 int encrypt_rc;
 unsigned char IV[32];
 augmented_plaintext_file_size = round_up(plaintext_file_size,
  32);
 augmented_plaintext_file_size += 32;
 ciphertext_file_size = augmented_plaintext_file_size +
  32;
 input_buffer = my_malloc(ciphertext_file_size);
 output_buffer = my_malloc(ciphertext_file_size);
 memset(input_buffer, 'p', ciphertext_file_size);
 memset(output_buffer, 'c', ciphertext_file_size);
 pinblock0 = &input_buffer [0];
 pinblock1 = &input_buffer [32];
 poutblock0 = &output_buffer[0];
 poutblock1 = &output_buffer[32];
 fprintf(stderr, "%s:\n", input_file_name);
 fprintf(stderr, "  Reading ... ", input_file_name); fflush(stderr);
 read_file_to_region(input_file_name, plaintext_file_size, pinblock1);
 fprintf(stderr, "  done.\n");
 header.magic_number = 0xa0e0b9df;
 header.bytes_in_last_plaintext_block =
  plaintext_file_size % 32;
 header.CRC = get_ethernet_CRC(pinblock1, plaintext_file_size);
 memset(pinblock0, 0, 32);
 memcpy(pinblock0, &header, sizeof(header));
 make_IV(IV, 32, pkey_instance);
 memcpy(poutblock0, IV, 32);
 fprintf(stderr, "  Encrypting ... "); fflush(stderr);
 encrypt_rc = AES_encrypt(2, 32 * 8,
  pkey_instance, IV, pinblock0,
  augmented_plaintext_file_size * 8, poutblock1);
 if (encrypt_rc < 0) {
  fprintf(stderr, "\nAES_encrypt() failure:  code %d.\n",
   encrypt_rc);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 fprintf(stderr, "  done.\n");
 fprintf(stderr, "  Writing ... "); fflush(stderr);
 write_region_to_file(output_buffer, ciphertext_file_size,
  output_file_name);
 fprintf(stderr, "  done.\n");
 free(input_buffer);
 free(output_buffer);
 return 1;
}

variable_types: struct _key_instance { int key_length_in_bits; unsigned char key_sched[-1][4][-1]; } *

variable_types: struct _header_t { int magic_number; int bytes_in_last_plaintext_block; unsigned int CRC; }

variable_types:
IV
unsigned char [32]


decompiled_code:
_BOOL8 __fastcall my_AES_decrypt_file(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
__m128i *v7; // rbp
__int64 *v8; // r13
bool v9; // zf
_BOOL4 v10; // er12
int v11; // eax
unsigned int v12; // edx
unsigned int v13; // ebx
unsigned int v14; // eax
__int128 v17[2]; // [rsp+10h] [rbp-68h] BYREF
__int64 v18; // [rsp+34h] [rbp-44h]
unsigned int v19; // [rsp+3Ch] [rbp-3Ch]

v7 = (__m128i *)my_malloc(a4);
v8 = (__int64 *)my_malloc(a4);
memset(v7, 67, (int)a4);
memset(v8, 80, (int)a4);
fprintf(stderr, "%s:\n", a2);
fwrite(" Reading ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
read_file_to_region(a2, a4, v7);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
v9 = memcmp("AES", v7, 3uLL) == 0;
v10 = !v9;
if ( v9 )
{
v17[0] = (__int128)_mm_loadu_si128(v7);
v17[1] = (__int128)_mm_loadu_si128(v7 + 1);
fwrite(" Decrypting ... ", 1uLL, 0x11uLL, stderr);
fflush(stderr);
v11 = AES_decrypt(2LL, 256LL, a1, v17, &v7[2], 8 * a4 - 256, v8);
if ( v11 < 0 )
{
fprintf(stderr, "\nAES_decrypt() failure: code %d.\n", (unsigned int)v11);
free(v7);
free(v8);
}
else
{
fwrite(" done.\n", 1uLL, 8uLL, stderr);
v18 = *v8;
v19 = *((_DWORD *)v8 + 2);
if ( (_DWORD)v18 == -1595885089 )
{
if ( HIDWORD(v18) > 0x1F )
{
fprintf(stderr, "Header damaged in file \"%s\".\n", a2);
free(v7);
free(v8);
}
else
{
v12 = a4 - 64;
v13 = HIDWORD(v18) + a4 - 64 - 32;
if ( !HIDWORD(v18) )
v13 = v12;
v14 = get_ethernet_CRC(v8 + 4, v13);
if ( v19 == v14 )
{
fwrite(" Writing ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
write_region_to_file(v8 + 4, v13, a3);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
free(v7);
free(v8);
v10 = 1;
}
else
{
fprintf(stderr, "Checksum error on file \"%s\". Expected 0x%08x; got 0x%08x.\n", a2, v19, v14);
fwrite("Leaving file as it was.\n", 1uLL, 0x18uLL, stderr);
free(v7);
free(v8);
}
}
}
else
{
fwrite("Key appears to be incorrect.\n", 1uLL, 0x1DuLL, stderr);
free(v7);
free(v8);
}
}
}
else
{
fprintf(stderr, "File \"%s\" appears not to have been encrypted with this program.\n", a2);
free(v7);
free(v8);
v10 = 0;
}
return v10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
__m128i *v7; // rbp
__int64 *v8; // r13
bool v9; // zf
_BOOL4 v10; // er12
int v11; // eax
unsigned int v12; // edx
unsigned int v13; // ebx
unsigned int v14; // eax
__int128 v17[2]; // [rsp+10h] [rbp-68h] BYREF
__int64 v18; // [rsp+34h] [rbp-44h]
unsigned int v19; // [rsp+3Ch] [rbp-3Ch]

v7 = (__m128i *)my_malloc(a4);
v8 = (__int64 *)my_malloc(a4);
memset(v7, 67, (int)a4);
memset(v8, 80, (int)a4);
fprintf(stderr, "%s:\n", a2);
fwrite(" Reading ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
read_file_to_region(a2, a4, v7);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
v9 = memcmp("AES", v7, 3uLL) == 0;
v10 = !v9;
if ( v9 )
{
v17[0] = (__int128)_mm_loadu_si128(v7);
v17[1] = (__int128)_mm_loadu_si128(v7 + 1);
fwrite(" Decrypting ... ", 1uLL, 0x11uLL, stderr);
fflush(stderr);
v11 = AES_decrypt(2LL, 256LL, a1, v17, &v7[2], 8 * a4 - 256, v8);
if ( v11 < 0 )
{
fprintf(stderr, "\nAES_decrypt() failure: code %d.\n", (unsigned int)v11);
free(v7);
free(v8);
}
else
{
fwrite(" done.\n", 1uLL, 8uLL, stderr);
v18 = *v8;
v19 = *((_DWORD *)v8 + 2);
if ( (_DWORD)v18 == -1595885089 )
{
if ( HIDWORD(v18) > 0x1F )
{
fprintf(stderr, "Header damaged in file \"%s\".\n", a2);
free(v7);
free(v8);
}
else
{
v12 = a4 - 64;
v13 = HIDWORD(v18) + a4 - 64 - 32;
if ( !HIDWORD(v18) )
v13 = v12;
v14 = get_ethernet_CRC(v8 + 4, v13);
if ( v19 == v14 )
{
fwrite(" Writing ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
write_region_to_file(v8 + 4, v13, a3);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
free(v7);
free(v8);
v10 = 1;
}
else
{
fprintf(stderr, "Checksum error on file \"%s\". Expected 0x%08x; got 0x%08x.\n", a2, v19, v14);
fwrite("Leaving file as it was.\n", 1uLL, 0x18uLL, stderr);
free(v7);
free(v8);
}
}
}
else
{
fwrite("Key appears to be incorrect.\n", 1uLL, 0x1DuLL, stderr);
free(v7);
free(v8);
}
}
}
else
{
fprintf(stderr, "File \"%s\" appears not to have been encrypted with this program.\n", a2);
free(v7);
free(v8);
v10 = 0;
}
return v10;
}

original_code:
static int my_AES_decrypt_file(
 key_instance * pkey_instance,
 char * input_file_name,
 char * output_file_name,
 int ciphertext_file_size)
{
 int plaintext_file_size = 0;
 header_t header;
 unsigned new_CRC;
 char * input_buffer;
 char * output_buffer;
 char * pinblock0;
 char * pinblock1;
 char * poutblock0;
 char * poutblock1;
 int decrypt_rc;
 BYTE IV[32];
 input_buffer = my_malloc(ciphertext_file_size);
 output_buffer = my_malloc(ciphertext_file_size);
 memset(input_buffer, 'C', ciphertext_file_size);
 memset(output_buffer, 'P', ciphertext_file_size);
 pinblock0 = &input_buffer [0];
 pinblock1 = &input_buffer [32];
 poutblock0 = &output_buffer[0];
 poutblock1 = &output_buffer[32];
 fprintf(stderr, "%s:\n", input_file_name);
 fprintf(stderr, "  Reading ... "); fflush(stderr);
 read_file_to_region(input_file_name, ciphertext_file_size,
  input_buffer);
 fprintf(stderr, "  done.\n");
 if (strncmp("AES", input_buffer, strlen("AES")) != 0) {
  fprintf(stderr,
"File \"%s\" appears not to have been encrypted with this program.\n",
   input_file_name);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 memcpy(IV, pinblock0, 32);
 fprintf(stderr, "  Decrypting ... "); fflush(stderr);
 decrypt_rc = AES_decrypt(2, 32 * 8,
  pkey_instance, IV, pinblock1,
  (ciphertext_file_size - 32) * 8, poutblock0);
 if (decrypt_rc < 0) {
  fprintf(stderr, "\nAES_decrypt() failure:  code %d.\n",
   decrypt_rc);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 fprintf(stderr, "  done.\n");
 memcpy(&header, poutblock0, sizeof(header));
 if (header.magic_number != 0xa0e0b9df) {
  fprintf(stderr, "Key appears to be incorrect.\n");
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 if ((header.bytes_in_last_plaintext_block < 0)
 || (header.bytes_in_last_plaintext_block >= 32)) {
  fprintf(stderr, "Header damaged in file \"%s\".\n",
   input_file_name);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 plaintext_file_size = ciphertext_file_size - 2 * 32;
 if (header.bytes_in_last_plaintext_block != 0)
  plaintext_file_size -=
   (32 - header.bytes_in_last_plaintext_block);
 new_CRC = get_ethernet_CRC(poutblock1, plaintext_file_size);
 if (new_CRC != header.CRC) {
  fprintf(stderr,
 "Checksum error on file \"%s\".  Expected 0x%08x; got 0x%08x.\n",
   input_file_name, header.CRC, new_CRC);
  fprintf(stderr, "Leaving file as it was.\n");
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 fprintf(stderr, "  Writing ... "); fflush(stderr);
 write_region_to_file(poutblock1, plaintext_file_size, output_file_name);
 fprintf(stderr, "  done.\n");
 free(input_buffer);
 free(output_buffer);
 return 1;
}

canonical_original_code:
static int my_AES_decrypt_file(struct _key_instance *pkey_instance, char *input_file_name, char *output_file_name, int ciphertext_file_size)
{
 int plaintext_file_size = 0;
 struct _header_t header;
 unsigned int new_CRC;
 char *input_buffer;
 char *output_buffer;
 char *pinblock0;
 char *pinblock1;
 char *poutblock0;
 char *poutblock1;
 int decrypt_rc;
 unsigned char IV[32];
 input_buffer = my_malloc(ciphertext_file_size);
 output_buffer = my_malloc(ciphertext_file_size);
 memset(input_buffer, 'C', ciphertext_file_size);
 memset(output_buffer, 'P', ciphertext_file_size);
 pinblock0 = &input_buffer [0];
 pinblock1 = &input_buffer [32];
 poutblock0 = &output_buffer[0];
 poutblock1 = &output_buffer[32];
 fprintf(stderr, "%s:\n", input_file_name);
 fprintf(stderr, "  Reading ... "); fflush(stderr);
 read_file_to_region(input_file_name, ciphertext_file_size,
  input_buffer);
 fprintf(stderr, "  done.\n");
 if (strncmp("AES", input_buffer, strlen("AES")) != 0) {
  fprintf(stderr,
"File \"%s\" appears not to have been encrypted with this program.\n",
   input_file_name);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 memcpy(IV, pinblock0, 32);
 fprintf(stderr, "  Decrypting ... "); fflush(stderr);
 decrypt_rc = AES_decrypt(2, 32 * 8,
  pkey_instance, IV, pinblock1,
  (ciphertext_file_size - 32) * 8, poutblock0);
 if (decrypt_rc < 0) {
  fprintf(stderr, "\nAES_decrypt() failure:  code %d.\n",
   decrypt_rc);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 fprintf(stderr, "  done.\n");
 memcpy(&header, poutblock0, sizeof(header));
 if (header.magic_number != 0xa0e0b9df) {
  fprintf(stderr, "Key appears to be incorrect.\n");
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 if ((header.bytes_in_last_plaintext_block < 0)
 || (header.bytes_in_last_plaintext_block >= 32)) {
  fprintf(stderr, "Header damaged in file \"%s\".\n",
   input_file_name);
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 plaintext_file_size = ciphertext_file_size - 2 * 32;
 if (header.bytes_in_last_plaintext_block != 0)
  plaintext_file_size -=
   (32 - header.bytes_in_last_plaintext_block);
 new_CRC = get_ethernet_CRC(poutblock1, plaintext_file_size);
 if (new_CRC != header.CRC) {
  fprintf(stderr,
 "Checksum error on file \"%s\".  Expected 0x%08x; got 0x%08x.\n",
   input_file_name, header.CRC, new_CRC);
  fprintf(stderr, "Leaving file as it was.\n");
  free(input_buffer);
  free(output_buffer);
  return 0;
 }
 fprintf(stderr, "  Writing ... "); fflush(stderr);
 write_region_to_file(poutblock1, plaintext_file_size, output_file_name);
 fprintf(stderr, "  done.\n");
 free(input_buffer);
 free(output_buffer);
 return 1;
}

user_defined_types: struct _header_t { int magic_number; int bytes_in_last_plaintext_block; unsigned int CRC; }

user_defined_types: struct _key_instance { int key_length_in_bits; unsigned char key_sched[-1][4][-1]; }