decompiled_code:
// attributes: thunk
__int64 __fastcall binv_decrypt_block(__int64 a1, __int64 a2, int *a3)
{
return binv_encrypt_block(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int *a3)
{
return func0(a1, a2, a3);
}

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


repo: johnkerl/ctools

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

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

return_type: int


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)
{
}

return_type: void

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


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

variable_types: bl int


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

variable_types: kl int


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

return_type: char *


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


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 _AES_key_schedule_t { unsigned char rk[-1][4][-1]; } *


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

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

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

func1(*a3, a1, v6);
AES_encrypt_block(v6, v7, (unsigned int)a3[1], (unsigned int)*a3);
func2(*a3, v7, a2);
return 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(char *a1, __int64 a2, int *a3)
{
unsigned int v4; // er8
_BYTE v6[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

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

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

func1(*a3, a1, v6);
AES_decrypt_block(v6, v7, (unsigned int)a3[1], (unsigned int)*a3);
func2(*a3, v7, a2);
return 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);
}

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 AES_make_key(__int64 a1, unsigned int *a2)
{
int v2; // er12
void *v4; // rax
void *v5; // r13
unsigned int v6; // edx
__int64 v7; // rax
int v8; // edx
char v9; // cl
char v10; // si
__int64 v12; // [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;
v4 = malloc(0x1E0uLL);
v5 = v4;
if ( !v4 )
return 4294967294LL;
v6 = a2[35];
*((_QWORD *)a2 + 18) = v4;
if ( v6 )
{
memcpy(dest, a2 + 19, v2);
}
else
{
fill_region_from_string(dest, (unsigned int)v2, a1);
v2 = a2[1];
}
v7 = 0LL;
if ( v2 > 0 )
{
do
{
v8 = v7;
v9 = v7;
v10 = dest[v7++];
dest[8 * (v9 & 3) - 32 + (v8 >> 2)] = v10;
}
while ( v7 != v2 );
}
if ( a2[39] )
{
hex_dump_region("AES key material", dest, (unsigned int)v2, 16LL);
v2 = a2[1];
}
AES_key_schedule(&v12, (unsigned int)v2, *a2, v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int *a2)
{
int v2; // er12
void *v4; // rax
void *v5; // r13
unsigned int v6; // edx
__int64 v7; // rax
int v8; // edx
char v9; // cl
char v10; // si
__int64 v12; // [rsp+0h] [rbp-88h] BYREF
char dest[104]; // [rsp+20h] [rbp-68h] BYREF

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


decompiled_code:
__int64 __fastcall twiddle_encrypt_block(__int64 a1, __int64 a2, __int64 a3)
{
char v3; // r8
__int64 i; // rax

v3 = **(_BYTE **)(a3 + 144);
for ( i = 0LL; *(_DWORD *)a3 > (int)i; ++i )
*(_BYTE *)(a2 + i) = v3 ^ *(_BYTE *)(a1 + i);
return 1LL;
}

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


decompiled_code:
// attributes: thunk
__int64 __fastcall twiddle_decrypt_block(__int64 a1, __int64 a2, __int64 a3)
{
return twiddle_encrypt_block(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return func0(a1, a2, a3);
}

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; // er12

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

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

v2 = (unsigned int *)malloc(4uLL);
if ( !v2 )
return (unsigned int)-2;
*v2 = 0;
v3 = v2;
*(_QWORD *)(a2 + 144) = v2;
v4 = _isoc99_sscanf(a1, "%x", v2);
if ( v4 != 1 )
{
if ( *(_DWORD *)(a2 + 156) )
fwrite("Twiddle: key mat extraction failed.\n", 1uLL, 0x24uLL, stderr);
return (unsigned int)-1;
}
if ( !*(_DWORD *)(a2 + 156) )
return v4;
fprintf(stderr, "Twiddle: key mat \"%s\" -> 0x%02x\n", a1, *v3);
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)
{
__int64 v3; // rbp
char *v4; // rbx
char *v5; // rbp
const unsigned __int16 **v6; // r13
int v7; // edi

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

canonical_decompiled_code:
size_t __fastcall func7(const char *a1, char *a2, int a3)
{
__int64 v3; // rbp
char *v4; // rbx
char *v5; // rbp
const unsigned __int16 **v6; // r13
int v7; // edi

v3 = a3;
v4 = a2;
fprintf(stderr, "%8s @ 0x%08llx: <<", a1, a2);
if ( (int)v3 > 0 )
{
v5 = &a2[v3];
v6 = _ctype_b_loc();
do
{
v7 = *v4;
if ( ((*v6)[*v4] & 0x4000) == 0 )
v7 = 46;
++v4;
fputc(v7, stderr);
}
while ( v4 != v5 );
}
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(char *a1, int a2, unsigned int *a3, int a4)
{
unsigned int v5; // eax
char *v6; // rcx
char v7; // dl

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

canonical_decompiled_code:
void __fastcall func8(char *a1, int a2, unsigned int *a3, int a4)
{
unsigned int v5; // eax
char *v6; // rcx
char v7; // dl

switch ( a4 )
{
case 2:
v5 = *a3;
if ( a2 )
{
v6 = &a1[a2];
do
{
v7 = *a1++;
v5 = eth_CRC_table[(unsigned __int8)(v5 ^ v7)] ^ (v5 >> 8);
}
while ( a1 != v6 );
}
*a3 = v5;
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)
{
int v4; // er12
unsigned int *v5; // rbx
unsigned int *v6; // r13
unsigned int *v7; // rax
__int64 v8; // rbx
const unsigned __int16 **v9; // r14
int v10; // edi

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

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

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


decompiled_code:
void __fastcall RC6_bytes_to_block(int a1, unsigned __int8 *a2, _QWORD *a3)
{
__int64 v5; // r8
_QWORD *v6; // r9

if ( a1 > 0 )
{
do
{
RC6_bytes_to_word(*a2, a2[1], a2[2], a2[3], a3);
a3 = (_QWORD *)(v5 + 8);
}
while ( v6 != a3 );
}
}

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)
{
unsigned __int64 result; // rax
_BYTE *v6; // r10

if ( a1 > 0 )
{
do
{
result = RC6_word_to_bytes(*a2, a3, a3 + 1, a3 + 2, a3 + 3);
a3 += 4;
}
while ( a3 != v6 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(int a1, unsigned __int64 *a2, _BYTE *a3)
{
unsigned __int64 result; // rax
_BYTE *v6; // r10

if ( a1 > 0 )
{
do
{
result = func5(*a2, a3, a3 + 1, a3 + 2, a3 + 3);
a3 += 4;
}
while ( a3 != v6 );
}
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 >> (32 - (unsigned __int8)v3)) | (a1 << 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 >> (32 - (unsigned __int8)v3)) | (a1 << 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 << (32 - (unsigned __int8)v3)) | (a1 >> 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 << (32 - (unsigned __int8)v3)) | (a1 >> 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_decrypt_file(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
size_t v4; // r15
__m128i *v5; // rbp
_DWORD *v6; // r12
unsigned int v7; // er15
int v9; // eax
int v10; // ebx
int v11; // eax
unsigned int v12; // er14
int v13; // ebx
unsigned int v14; // edx
unsigned int v15; // er14
unsigned int v16; // eax
size_t v17; // rdx
FILE *v18; // rcx
const char *v19; // rdi
__int64 v21; // [rsp+14h] [rbp-64h]
unsigned int v22; // [rsp+1Ch] [rbp-5Ch]
__int128 v23[5]; // [rsp+20h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
size_t v4; // r15
__m128i *v5; // rbp
_DWORD *v6; // r12
unsigned int v7; // er15
int v9; // eax
int v10; // ebx
int v11; // eax
unsigned int v12; // er14
int v13; // ebx
unsigned int v14; // edx
unsigned int v15; // er14
unsigned int v16; // eax
size_t v17; // rdx
FILE *v18; // rcx
const char *v19; // rdi
__int64 v21; // [rsp+14h] [rbp-64h]
unsigned int v22; // [rsp+1Ch] [rbp-5Ch]
__int128 v23[5]; // [rsp+20h] [rbp-58h] BYREF

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

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

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:
__int64 __fastcall my_AES_encrypt_file(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
int v5; // eax
unsigned int v6; // er14
_OWORD *v7; // rbp
__m128i *v8; // r12
FILE *v9; // rcx
int v10; // eax
__int64 result; // rax
int v12; // [rsp+14h] [rbp-74h]
__int64 v14; // [rsp+24h] [rbp-64h]
int v15; // [rsp+2Ch] [rbp-5Ch]
__m128i v16; // [rsp+30h] [rbp-58h] BYREF
__m128i v17[4]; // [rsp+40h] [rbp-48h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3, unsigned int a4)
{
int v5; // eax
unsigned int v6; // er14
_OWORD *v7; // rbp
__m128i *v8; // r12
FILE *v9; // rcx
int v10; // eax
__int64 result; // rax
int v12; // [rsp+14h] [rbp-74h]
__int64 v14; // [rsp+24h] [rbp-64h]
int v15; // [rsp+2Ch] [rbp-5Ch]
__m128i v16; // [rsp+30h] [rbp-58h] BYREF
__m128i v17[4]; // [rsp+40h] [rbp-48h] BYREF

v5 = round_up(a4, 32LL);
v6 = v5 + 64;
v12 = v5;
v7 = (_OWORD *)my_malloc((unsigned int)(v5 + 64));
v8 = (__m128i *)my_malloc(v6);
memset(v7, 112, (int)v6);
memset(v8, 99, (int)v6);
fprintf(stderr, "%s:\n", a2);
fprintf(stderr, " Reading ... ");
fflush(stderr);
read_file_to_region(a2, a4, v7 + 2);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
LODWORD(v14) = -1595885089;
HIDWORD(v14) = (int)a4 % 32;
v15 = get_ethernet_CRC(v7 + 2, a4);
*v7 = 0LL;
v7[1] = 0LL;
*(_QWORD *)v7 = v14;
*((_DWORD *)v7 + 2) = v15;
func3(&v16, a1);
*v8 = _mm_loadu_si128(&v16);
v9 = stderr;
v8[1] = _mm_loadu_si128(v17);
fwrite(" Encrypting ... ", 1uLL, 0x11uLL, v9);
fflush(stderr);
v10 = AES_encrypt(2LL, 256LL, a1, &v16, v7, (unsigned int)(8 * v12 + 256), &v8[2]);
if ( v10 < 0 )
{
fprintf(stderr, "\nAES_encrypt() failure: code %d.\n", (unsigned int)v10);
free(v7);
free(v8);
result = 0LL;
}
else
{
fwrite(" done.\n", 1uLL, 8uLL, stderr);
fwrite(" Writing ... ", 1uLL, 0xEuLL, stderr);
fflush(stderr);
write_region_to_file(v8, v6, a3);
fwrite(" done.\n", 1uLL, 8uLL, stderr);
free(v7);
free(v8);
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;
}

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


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s {+key} {file name(s) ...\n", a1);
fprintf(stderr, "Or: %s {-key} {file name(s) ...\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Usage: %s {+key} {file name(s) ...\n", a1);
fprintf(stderr, "Or: %s {-key} {file name(s) ...\n", a1);
exit(1);
}

original_code:
static void usage(char *argv0)
{
 fprintf(stderr, "Usage: %s {+key} {file name(s) ...\n", argv0);
 fprintf(stderr, "Or:    %s {-key} {file name(s) ...\n", argv0);
 exit(1);
}


original_code:
static int parse_command_line(
 int argc,
 char ** argv,
 char ** pkey_text,
 int * pforward,
 int * pargind,
 int * poutcat)
{
 char * dirkey;
 *pargind = 2;
 *poutcat = 0;
 if (argc >= 2) {
  if (strcmp(argv[1], "cat") == 0) {
   *poutcat = 1;
   *pargind = 3;
  }
 }
 if ((argc - *pargind) < 1)
  return 0;
 dirkey = argv[*pargind - 1];
 *pkey_text = &dirkey[1];
 if (dirkey[0] == '+')
  *pforward = 1;
 else if (dirkey[0] == '-')
  *pforward = 0;
 else
  return 0;
 return 1;
}

canonical_original_code:
static int parse_command_line(int argc, char **argv, char **pkey_text, int *pforward, int *pargind, int *poutcat)
{
 char *dirkey;
 *pargind = 2;
 *poutcat = 0;
 if (argc >= 2) {
  if (strcmp(argv[1], "cat") == 0) {
   *poutcat = 1;
   *pargind = 3;
  }
 }
 if ((argc - *pargind) < 1)
  return 0;
 dirkey = argv[*pargind - 1];
 *pkey_text = &dirkey[1];
 if (dirkey[0] == '+')
  *pforward = 1;
 else if (dirkey[0] == '-')
  *pforward = 0;
 else
  return 0;
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
pforward
int *

variable_types:
pargind
int *

variable_types:
poutcat
int *

variable_types:
dirkey
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // er14
const char **v5; // rbx
const char **v6; // r13
const char *v7; // rbp
const char *v8; // r15
int v10; // [rsp+8h] [rbp-260h] BYREF
int v11; // [rsp+Ch] [rbp-25Ch] BYREF
int v12; // [rsp+10h] [rbp-258h] BYREF
unsigned int v13; // [rsp+14h] [rbp-254h] BYREF
__int64 v14; // [rsp+18h] [rbp-250h] BYREF
char v15[32]; // [rsp+20h] [rbp-248h] BYREF
char v16[552]; // [rsp+40h] [rbp-228h] BYREF

if ( !(unsigned int)parse_command_line(argc, (__int64)argv, &v14, &v10, &v11, &v12) )
usage(*argv);
fill_region_from_string(v15, 32LL, v14);
v3 = AES_make_key(v16, 256LL, 256LL, v15);
if ( v3 != 1 )
{
fprintf(stderr, "AES_make_key() failure: code %d.\n", v3);
exit(1);
}
if ( argc > v11 )
{
v4 = 0;
v5 = &argv[v11];
v6 = &(&argv[v11])[(unsigned __int64)(unsigned int)(argc + ~v11) + 1];
while ( 1 )
{
while ( 1 )
{
v7 = *v5;
v8 = "-";
if ( !v12 )
v8 = *v5;
if ( !(unsigned int)get_file_size(*v5, &v13) )
{
v4 = 1;
fprintf(stderr, "Couldn't open file \"%s\".\n", v7);
goto LABEL_7;
}
if ( !v10 )
break;
if ( !(unsigned int)my_AES_encrypt_file((__int64)v16, v7, (__int64)v8, v13) )
goto LABEL_6;
LABEL_7:
if ( ++v5 == v6 )
goto LABEL_14;
}
if ( !(unsigned int)my_AES_decrypt_file((__int64)v16, v7, (__int64)v8, v13) )
{
LABEL_6:
v4 = 1;
goto LABEL_7;
}
if ( ++v5 == v6 )
goto LABEL_14;
}
}
v4 = 0;
LABEL_14:
fprintf(stderr, "Exit status %d.\n", v4);
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // er14
const char **v5; // rbx
const char **v6; // r13
const char *v7; // rbp
const char *v8; // r15
int v10; // [rsp+8h] [rbp-260h] BYREF
int v11; // [rsp+Ch] [rbp-25Ch] BYREF
int v12; // [rsp+10h] [rbp-258h] BYREF
unsigned int v13; // [rsp+14h] [rbp-254h] BYREF
__int64 v14; // [rsp+18h] [rbp-250h] BYREF
char v15[32]; // [rsp+20h] [rbp-248h] BYREF
char v16[552]; // [rsp+40h] [rbp-228h] BYREF

if ( !(unsigned int)func1(argc, (__int64)argv, &v14, &v10, &v11, &v12) )
func0(*argv);
fill_region_from_string(v15, 32LL, v14);
v3 = AES_make_key(v16, 256LL, 256LL, v15);
if ( v3 != 1 )
{
fprintf(stderr, "AES_make_key() failure: code %d.\n", v3);
exit(1);
}
if ( argc > v11 )
{
v4 = 0;
v5 = &argv[v11];
v6 = &(&argv[v11])[(unsigned __int64)(unsigned int)(argc + ~v11) + 1];
while ( 1 )
{
while ( 1 )
{
v7 = *v5;
v8 = "-";
if ( !v12 )
v8 = *v5;
if ( !(unsigned int)get_file_size(*v5, &v13) )
{
v4 = 1;
fprintf(stderr, "Couldn't open file \"%s\".\n", v7);
goto LABEL_7;
}
if ( !v10 )
break;
if ( !(unsigned int)func4((__int64)v16, v7, (__int64)v8, v13) )
goto LABEL_6;
LABEL_7:
if ( ++v5 == v6 )
goto LABEL_14;
}
if ( !(unsigned int)func2((__int64)v16, v7, (__int64)v8, v13) )
{
LABEL_6:
v4 = 1;
goto LABEL_7;
}
if ( ++v5 == v6 )
goto LABEL_14;
}
}
v4 = 0;
LABEL_14:
fprintf(stderr, "Exit status %d.\n", v4);
return v4;
}

original_code:
int main(int argc, char **argv)
{
 int forward;
 char * input_file_name;
 char * output_file_name;
 char * key_text;
 int argind;
 int outcat;
 char key_material[32];
 int argi;
 int file_size_success;
 int file_size;
 key_instance AES_key_instance;
 int make_key_rc;
 int rv = 0;
 if (!parse_command_line(argc, argv, &key_text, &forward, &argind,
   &outcat))
  usage(argv[0]);
 fill_region_from_string(key_material, 32, key_text);
 make_key_rc = AES_make_key(&AES_key_instance, 32 * 8,
  32 * 8, key_material);
 if (make_key_rc != 1) {
  fprintf(stderr, "AES_make_key() failure:  code %d.\n",
   make_key_rc);
  exit(1);
 }
 for (argi = argind; argi < argc; argi++) {
  input_file_name = argv[argi];
  if (outcat)
   output_file_name = "-";
  else
   output_file_name = input_file_name;
  file_size_success = get_file_size(input_file_name, &file_size);
  if (!file_size_success) {
   fprintf(stderr, "Couldn't open file \"%s\".\n",
    input_file_name);
   rv = 1;
   continue;
  }
  if (forward) {
   if (!my_AES_encrypt_file(&AES_key_instance,
    input_file_name, output_file_name, file_size))
    rv = 1;
  }
  else {
   if (!my_AES_decrypt_file(&AES_key_instance,
    input_file_name, output_file_name, file_size))
    rv = 1;
  }
 }
 fprintf(stderr, "Exit status %d.\n", rv);
 return rv;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int forward;
 char *input_file_name;
 char *output_file_name;
 char *key_text;
 int argind;
 int outcat;
 char key_material[32];
 int argi;
 int file_size_success;
 int file_size;
 struct _key_instance AES_key_instance;
 int make_key_rc;
 int rv = 0;
 if (!parse_command_line(argc, argv, &key_text, &forward, &argind,
   &outcat))
  usage(argv[0]);
 fill_region_from_string(key_material, 32, key_text);
 make_key_rc = AES_make_key(&AES_key_instance, 32 * 8,
  32 * 8, key_material);
 if (make_key_rc != 1) {
  fprintf(stderr, "AES_make_key() failure:  code %d.\n",
   make_key_rc);
  exit(1);
 }
 for (argi = argind; argi < argc; argi++) {
  input_file_name = argv[argi];
  if (outcat)
   output_file_name = "-";
  else
   output_file_name = input_file_name;
  file_size_success = get_file_size(input_file_name, &file_size);
  if (!file_size_success) {
   fprintf(stderr, "Couldn't open file \"%s\".\n",
    input_file_name);
   rv = 1;
   continue;
  }
  if (forward) {
   if (!my_AES_encrypt_file(&AES_key_instance,
    input_file_name, output_file_name, file_size))
    rv = 1;
  }
  else {
   if (!my_AES_decrypt_file(&AES_key_instance,
    input_file_name, output_file_name, file_size))
    rv = 1;
  }
 }
 fprintf(stderr, "Exit status %d.\n", rv);
 return rv;
}

variable_types: forward int

variable_types: argind int

variable_types: outcat int

variable_types: argi int

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

variable_types: rv int


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

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

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

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

variable_types: code int


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

result = 1LL;
if ( a1 != 16 )
result = 4294967285LL;
return result;
}

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

result = 1LL;
if ( a1 != 16 )
result = 4294967285LL;
return result;
}

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

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

variable_types: bl int


decompiled_code:
__int64 __fastcall RC6_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 RC6_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

canonical_original_code:
static int RC6_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 RC6_make_key(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
void *v3; // rax
void *v4; // r12
unsigned int v5; // edx
_BYTE v7[64]; // [rsp+0h] [rbp-A8h] BYREF
char v8[104]; // [rsp+40h] [rbp-68h] BYREF

v2 = a2[1];
if ( !(unsigned int)valid_key_length(v2) )
return 4294967292LL;
v3 = malloc(0x160uLL);
v4 = v3;
if ( !v3 )
return 4294967294LL;
v5 = a2[35];
*((_QWORD *)a2 + 18) = v3;
if ( v5 )
{
memcpy(v7, a2 + 19, (int)v2);
}
else
{
fill_region_from_string(v7, v2, a1);
v2 = a2[1];
}
RC6_bytes_to_block(v2, v7, v8);
if ( a2[39] )
hex_dump_region("RC6 key material", v7, a2[1], 16LL);
RC6_key_schedule(v8, a2[1], *a2, v4);
return 1LL;
}

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

v2 = a2[1];
if ( !(unsigned int)func0(v2) )
return 4294967292LL;
v3 = malloc(0x160uLL);
v4 = v3;
if ( !v3 )
return 4294967294LL;
v5 = a2[35];
*((_QWORD *)a2 + 18) = v3;
if ( v5 )
{
memcpy(v7, a2 + 19, (int)v2);
}
else
{
fill_region_from_string(v7, v2, a1);
v2 = a2[1];
}
RC6_bytes_to_block(v2, v7, v8);
if ( a2[39] )
hex_dump_region("RC6 key material", v7, a2[1], 16LL);
RC6_key_schedule(v8, a2[1], *a2, v4);
return 1LL;
}

original_code:
int RC6_make_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 char full_key_material[64];
 RC6_key_schedule_t * pks;
 u32 key_mat_block[8];
 if (!valid_key_length(pciphinst->kl))
  return -4;
 pks = (RC6_key_schedule_t *)malloc(sizeof(RC6_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);
 }
 RC6_bytes_to_block(pciphinst->kl, full_key_material, key_mat_block);
 if (pciphinst->alg_debug) {
  hex_dump_region("RC6 key material",
   full_key_material,
   pciphinst->kl,16);
 }
 RC6_key_schedule(key_mat_block, pciphinst->kl,
  pciphinst->bl, pks->L);
 return 1;
}

canonical_original_code:
int RC6_make_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 char full_key_material[64];
 struct _RC6_key_schedule_t *pks;
 unsigned long key_mat_block[8];
 if (!valid_key_length(pciphinst->kl))
  return -4;
 pks = (struct _RC6_key_schedule_t *)malloc(sizeof(RC6_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);
 }
 RC6_bytes_to_block(pciphinst->kl, full_key_material, key_mat_block);
 if (pciphinst->alg_debug) {
  hex_dump_region("RC6 key material",
   full_key_material,
   pciphinst->kl,16);
 }
 RC6_key_schedule(key_mat_block, pciphinst->kl,
  pciphinst->bl, pks->L);
 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 _RC6_key_schedule_t { unsigned long L[-1]; } *


decompiled_code:
void __fastcall RC6_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 RC6_free_key(
 char * key_material,
 block_cipher_instance_t * pciphinst)
{
 RC6_key_schedule_t * pkey =
  (RC6_key_schedule_t *)pciphinst->pkey_schedule;
 free(pkey);
}

canonical_original_code:
void RC6_free_key(char *key_material, struct _block_cipher_instance_t *pciphinst)
{
 struct _RC6_key_schedule_t *pkey = (RC6_key_schedule_t *)pciphinst->pkey_schedule;
 free(pkey);
}

user_defined_types: struct _RC6_key_schedule_t { unsigned long L[-1]; }


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

v4 = *((_QWORD *)a3 + 18);
RC6_bytes_to_block(*a3, a1, v6);
LODWORD(v4) = RC6_encrypt_block(v6, v7, a3[1], v4);
RC6_block_to_bytes(*a3, v7, a2);
return (unsigned int)v4;
}

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

v4 = *((_QWORD *)a3 + 18);
RC6_bytes_to_block(*a3, a1, v6);
LODWORD(v4) = RC6_encrypt_block(v6, v7, a3[1], v4);
RC6_block_to_bytes(*a3, v7, a2);
return (unsigned int)v4;
}

original_code:
int RC6_encrypt_bytes(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 u32 block_in [4];
 u32 block_out[4];
 RC6_key_schedule_t * pkey =
  (RC6_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 RC6_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = RC6_encrypt_block(block_in, block_out,
  pciphinst->kl, pkey->L);
 RC6_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

canonical_original_code:
int RC6_encrypt_bytes(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 unsigned long block_in[4];
 unsigned long block_out[4];
 struct _RC6_key_schedule_t *pkey = (RC6_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 RC6_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = RC6_encrypt_block(block_in, block_out,
  pciphinst->kl, pkey->L);
 RC6_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}


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

v4 = *((_QWORD *)a3 + 18);
RC6_bytes_to_block(*a3, a1, v6);
LODWORD(v4) = RC6_decrypt_block(v6, v7, a3[1], v4);
RC6_block_to_bytes(*a3, v7, a2);
return (unsigned int)v4;
}

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

v4 = *((_QWORD *)a3 + 18);
RC6_bytes_to_block(*a3, a1, v6);
LODWORD(v4) = RC6_decrypt_block(v6, v7, a3[1], v4);
RC6_block_to_bytes(*a3, v7, a2);
return (unsigned int)v4;
}

original_code:
int RC6_decrypt_bytes(
 char * bytes_in,
 char * bytes_out,
 block_cipher_instance_t * pciphinst)
{
 u32 block_in [4];
 u32 block_out[4];
 RC6_key_schedule_t * pkey =
  (RC6_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 RC6_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = RC6_decrypt_block(block_in, block_out,
  pciphinst->kl, pkey->L);
 RC6_block_to_bytes(pciphinst->bl, block_out, bytes_out);
 return rv;
}

canonical_original_code:
int RC6_decrypt_bytes(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst)
{
 unsigned long block_in[4];
 unsigned long block_out[4];
 struct _RC6_key_schedule_t *pkey = (RC6_key_schedule_t *)pciphinst->pkey_schedule;
 int rv;
 RC6_bytes_to_block(pciphinst->bl, bytes_in, block_in);
 rv = RC6_decrypt_block(block_in, block_out,
  pciphinst->kl, pkey->L);
 RC6_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 null_encrypt_block(__int64 a1, __int64 a2, int *a3)
{
__int64 v3; // rax

if ( *a3 > 0 )
{
v3 = 0LL;
do
{
*(_BYTE *)(a2 + v3) = *(_BYTE *)(a1 + v3);
++v3;
}
while ( *a3 > (int)v3 );
}
return 1LL;
}

original_code:
static int null_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 null_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;
}

variable_types: i int


decompiled_code:
// attributes: thunk
__int64 __fastcall null_decrypt_block(__int64 a1, __int64 a2, int *a3)
{
return null_encrypt_block(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int *a3)
{
return func0(a1, a2, a3);
}

original_code:
static int null_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 null_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 null_make_key()
{
return 1LL;
}

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

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

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


decompiled_code:
void null_free_key()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


decompiled_code:
__int64 __fastcall null_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 null_check_bl(
 int bl)
{
 switch (bl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -11;
 }
}

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


decompiled_code:
__int64 __fastcall null_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 null_check_kl(
 int kl)
{
 switch (kl) {
 case 16:
 case 24:
 case 32:
  return 1;
 default:
  return -12;
 }
}

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


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

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

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

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


decompiled_code:
__int64 spin_check()
{
__int64 result; // rax

if ( (unsigned int)(fast_1 + 1) > 0x190 )
{
++slow_0;
result = 1LL;
fast_1 = 0;
}
else
{
++fast_1;
result = 0LL;
}
return result;
}

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

if ( (unsigned int)(fast_1 + 1) > 0x190 )
{
++slow_0;
result = 1LL;
fast_1 = 0;
}
else
{
++fast_1;
result = 0LL;
}
return result;
}

original_code:
static int spin_check(void)
{
 static int32u fast = 0;
 static int32u slow = 0;
 if (++fast > 400) {
  fast = 0;
  slow++;
  return 1;
 }
 else {
  return 0;
 }
}

canonical_original_code:
static int spin_check()
{
 static unsigned int fast = 0;
 static unsigned int slow = 0;
 if (++fast > 400) {
  fast = 0;
  slow++;
  return 1;
 }
 else {
  return 0;
 }
}

variable_types:
fast
unsigned int

variable_types:
slow
unsigned int


decompiled_code:
int spin_last()
{
printf("\r \r");
return fflush(stdout);
}

canonical_decompiled_code:
int func2()
{
printf("\r \r");
return fflush(stdout);
}

original_code:
static void spin_last(void)
{
 printf("\r                     \r");
 fflush(stdout);
}

canonical_original_code:
static void spin_last()
{
 printf("\r                     \r");
 fflush(stdout);
}


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [algorithm] {files ...}\n", a1);
fwrite("Algorithm is one of -ip, -eth, -crca, -murmur, -floppy, or -md5.\n", 1uLL, 0x41uLL, stderr);
fwrite("If omitted, defaults to -eth.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "Usage: %s [algorithm] {files ...}\n", a1);
fwrite("Algorithm is one of -ip, -eth, -crca, -murmur, -floppy, or -md5.\n", 1uLL, 0x41uLL, stderr);
fwrite("If omitted, defaults to -eth.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
static void usage(char *argv0)
{
 fprintf(stderr, "Usage: %s [algorithm] {files ...}\n", argv0);
 fprintf(stderr,
  "Algorithm is one of -ip, -eth, -crca, -murmur, -floppy, or -md5.\n");
 fprintf(stderr,
  "If omitted, defaults to -eth.\n");
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // ebp
int v5; // er14
const char **v6; // r13
int v7; // er15
const char *v8; // r8
char *v9; // rdi
char *s1; // [rsp+8h] [rbp-40h]

if ( argc <= 1 )
{
v5 = 0;
v7 = 2;
LABEL_28:
do_one_argument("-", v7, v5);
return 0;
}
v3 = argv + 1;
v4 = 0;
v5 = 0;
v6 = &argv[(unsigned int)(argc - 2) + 2];
v7 = 2;
do
{
while ( 1 )
{
v8 = *v3;
if ( !strcmp(*v3, "--help") )
LABEL_22:
usage(*argv);
if ( *v8 != 45 || !v8[1] )
break;
if ( v8[1] == 105 && v8[2] == 112 && !v8[3] )
{
v7 = 1;
}
else if ( !strcmp(v8 + 1, "eth") )
{
v7 = 2;
}
else if ( !strcmp(v8 + 1, "crca") )
{
v7 = 3;
}
else if ( !strcmp(v8 + 1, "murmur") )
{
v7 = 4;
}
else if ( !strcmp(v8 + 1, "floppy") )
{
v7 = 5;
}
else if ( !strcmp(v8 + 1, "md5") )
{
v7 = 6;
}
else
{
s1 = (char *)(v8 + 1);
if ( !strcmp(v8 + 1, "nop") )
{
v7 = 7;
}
else if ( !strcmp(s1, "spin") )
{
v5 = 1;
}
else
{
v5 = strcmp(s1, "nospin");
if ( v5 )
goto LABEL_22;
}
}
if ( ++v3 == v6 )
goto LABEL_12;
}
v9 = (char *)*v3++;
do_one_argument(v9, v7, v5);
++v4;
}
while ( v3 != v6 );
LABEL_12:
if ( !v4 )
goto LABEL_28;
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // ebp
int v5; // er14
const char **v6; // r13
int v7; // er15
const char *v8; // r8
char *v9; // rdi
char *s1; // [rsp+8h] [rbp-40h]

if ( argc <= 1 )
{
v5 = 0;
v7 = 2;
LABEL_28:
func3("-", v7, v5);
return 0;
}
v3 = argv + 1;
v4 = 0;
v5 = 0;
v6 = &argv[(unsigned int)(argc - 2) + 2];
v7 = 2;
do
{
while ( 1 )
{
v8 = *v3;
if ( !strcmp(*v3, "--help") )
LABEL_22:
func1(*argv);
if ( *v8 != 45 || !v8[1] )
break;
if ( v8[1] == 105 && v8[2] == 112 && !v8[3] )
{
v7 = 1;
}
else if ( !strcmp(v8 + 1, "eth") )
{
v7 = 2;
}
else if ( !strcmp(v8 + 1, "crca") )
{
v7 = 3;
}
else if ( !strcmp(v8 + 1, "murmur") )
{
v7 = 4;
}
else if ( !strcmp(v8 + 1, "floppy") )
{
v7 = 5;
}
else if ( !strcmp(v8 + 1, "md5") )
{
v7 = 6;
}
else
{
s1 = (char *)(v8 + 1);
if ( !strcmp(v8 + 1, "nop") )
{
v7 = 7;
}
else if ( !strcmp(s1, "spin") )
{
v5 = 1;
}
else
{
v5 = strcmp(s1, "nospin");
if ( v5 )
goto LABEL_22;
}
}
if ( ++v3 == v6 )
goto LABEL_12;
}
v9 = (char *)*v3++;
func3(v9, v7, v5);
++v4;
}
while ( v3 != v6 );
LABEL_12:
if ( !v4 )
goto LABEL_28;
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int argi;
 int style = 2;
 int do_spin = 0;
 int got_files = 0;
 for (argi = 1; argi < argc; argi++) {
  if (strcmp(argv[argi], "--help") == 0)
   usage(argv[0]);
  if ((argv[argi][0] == '-') && argv[argi][1]) {
   if (strcmp(&argv[argi][1], "ip") == 0)
    style = 1;
   else if (strcmp(&argv[argi][1], "eth") == 0)
    style = 2;
   else if (strcmp(&argv[argi][1], "crca") == 0)
    style = 3;
   else if (strcmp(&argv[argi][1], "murmur") == 0)
    style = 4;
   else if (strcmp(&argv[argi][1], "floppy") == 0)
    style = 5;
   else if (strcmp(&argv[argi][1], "md5") == 0)
    style = 6;
   else if (strcmp(&argv[argi][1], "nop") == 0)
    style = 7;
   else if (strcmp(&argv[argi][1], "spin") == 0)
    do_spin = 1;
   else if (strcmp(&argv[argi][1], "nospin") == 0)
    do_spin = 0;
   else
    usage(argv[0]);
   continue;
  }
  got_files++;
  do_one_argument(argv[argi], style, do_spin);
 }
 if (!got_files)
  do_one_argument("-", style, do_spin);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: style int


decompiled_code:
_BOOL8 __fastcall is_a_directory(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
int is_a_directory(
 char * file_name)
{
 struct stat stat_buf;
 if (stat(file_name, &stat_buf) != 0)
  return 0;
 if (((((stat_buf.st_mode & 0170000)) & 0170000) == (0040000)))
  return 1;
 return 0;
}

canonical_original_code:
int is_a_directory(char *file_name)
{
 struct stat stat_buf;
 if (stat(file_name, &stat_buf) != 0)
  return 0;
 if (((((stat_buf.st_mode & 0170000)) & 0170000) == (0040000)))
  return 1;
 return 0;
}

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

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


decompiled_code:
__int64 __fastcall get_file_size(const char *a1, _DWORD *a2)
{
int v2; // er8
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat(a1, &v4);
result = 0LL;
if ( !v2 )
{
*a2 = v4.st_size;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _DWORD *a2)
{
int v2; // er8
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat(a1, &v4);
result = 0LL;
if ( !v2 )
{
*a2 = v4.st_size;
result = 1LL;
}
return result;
}

original_code:
int get_file_size(
 char * file_name,
 int * pfile_size)
{
 struct stat stat_buf;
 if (stat(file_name, &stat_buf) != 0)
  return 0;
 *pfile_size = stat_buf.st_size;
 return 1;
}

canonical_original_code:
int get_file_size(char *file_name, int *pfile_size)
{
 struct stat stat_buf;
 if (stat(file_name, &stat_buf) != 0)
  return 0;
 *pfile_size = stat_buf.st_size;
 return 1;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
void accum_murmur_hash_32(
 int8u * buf,
 int32u len,
 int32u * pcsum,
 int32u op)
{
 const int32u const_m = 0x5bd1e995;
 const int const_r = 24;
 const int32u const_seed = 0xdeadbeef;
 int32u csum;
 switch (op) {
 case 0:
  *pcsum = const_seed ^ len;
  break;
 case 1:
  csum = *pcsum;
  while (len >= 4) {
   unsigned int k = *(unsigned int *)buf;
   k *= const_m;
   k ^= k >> const_r;
   k *= const_m;
   csum *= const_m;
   csum ^= k;
   buf += 4;
   len -= 4;
  }
  switch(len) {
  case 3: csum ^= buf[2] << 16;
     case 2: csum ^= buf[1] << 8;
     case 1: csum ^= buf[0]; csum *= const_m;
     }
  *pcsum = csum;
  break;
 case 2:
  csum = *pcsum;
  *pcsum ^= *pcsum >> 13;
  *pcsum *= const_m;
  *pcsum ^= *pcsum >> 15;
  *pcsum = csum;
  break;
 }
}

canonical_original_code:
void accum_murmur_hash_32(unsigned char *buf, unsigned int len, unsigned int *pcsum, unsigned int op)
{
 unsigned int const_m = 0x5bd1e995;
 int const_r = 24;
 unsigned int const_seed = 0xdeadbeef;
 unsigned int csum;
 switch (op) {
 case 0:
  *pcsum = const_seed ^ len;
  break;
 case 1:
  csum = *pcsum;
  while (len >= 4) {
   unsigned int k = *(unsigned int *)buf;
   k *= const_m;
   k ^= k >> const_r;
   k *= const_m;
   csum *= const_m;
   csum ^= k;
   buf += 4;
   len -= 4;
  }
  switch(len) {
  case 3: csum ^= buf[2] << 16;
     case 2: csum ^= buf[1] << 8;
     case 1: csum ^= buf[0]; csum *= const_m;
     }
  *pcsum = csum;
  break;
 case 2:
  csum = *pcsum;
  *pcsum ^= *pcsum >> 13;
  *pcsum *= const_m;
  *pcsum ^= *pcsum >> 15;
  *pcsum = csum;
  break;
 }
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int

variable_types:
pcsum
unsigned int *

variable_types:
op
unsigned int

variable_types:
csum
unsigned int

variable_types:
k
unsigned int


original_code:
static void set_defaults(
 opts_t * popts)
{
 memset(popts, 0, sizeof(*popts));
 popts->key_text = 0;
 popts->operation = 0;
 popts->first_file_argi = 1;
 block_cipher_select_default(&popts->pcipher, &popts->ciphinst);
 popts->ciphinst.do_cbc = 1;
 memset(popts->ciphinst.user_IV, 0, sizeof(popts->ciphinst.user_IV));
 popts->ciphinst.have_user_IV = 0;
 popts->app_debug = 0;
 popts->ciphinst.alg_debug = 0;
 popts->do_crc = 1;
 popts->do_spin = 1;
}

canonical_original_code:
static void set_defaults(struct _opts_t *popts)
{
 memset(popts, 0, sizeof(*popts));
 popts->key_text = 0;
 popts->operation = 0;
 popts->first_file_argi = 1;
 block_cipher_select_default(&popts->pcipher, &popts->ciphinst);
 popts->ciphinst.do_cbc = 1;
 memset(popts->ciphinst.user_IV, 0, sizeof(popts->ciphinst.user_IV));
 popts->ciphinst.have_user_IV = 0;
 popts->app_debug = 0;
 popts->ciphinst.alg_debug = 0;
 popts->do_crc = 1;
 popts->do_spin = 1;
}

variable_types: struct _opts_t { struct _block_cipher_t { char *cipher_name; int default_bl; int default_kl; int (*pencryptor)(char *bytes_in, char *bytes_out, 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; } *pciphinst); int (*pdecryptor)(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst); int (*pkey_maker)(char *key_material, struct _block_cipher_instance_t *pciphinst); void (*pkey_freer)(char *key_material, struct _block_cipher_instance_t *pciphinst); int (*pbl_checker)(int bl); int (*pkl_checker)(int kl); char *(*perror_explainer)(int error_code); } *pcipher; struct _block_cipher_instance_t ciphinst; char *key_text; int operation; int first_file_argi; int app_debug; int do_crc; int do_spin; } *

user_defined_types: struct _opts_t { struct _block_cipher_t *pcipher; struct _block_cipher_instance_t ciphinst; char *key_text; int operation; int first_file_argi; int app_debug; int do_crc; int do_spin; }

user_defined_types: struct _block_cipher_t { char *cipher_name; int default_bl; int default_kl; int (*pencryptor)(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst); int (*pdecryptor)(char *bytes_in, char *bytes_out, struct _block_cipher_instance_t *pciphinst); int (*pkey_maker)(char *key_material, struct _block_cipher_instance_t *pciphinst); void (*pkey_freer)(char *key_material, struct _block_cipher_instance_t *pciphinst); int (*pbl_checker)(int bl); int (*pkl_checker)(int kl); char *(*perror_explainer)(int error_code); }


decompiled_code:
__int64 __fastcall get_arg_int(const char **a1, int a2, int a3, __int64 a4, const char *a5)
{
const char **v5; // r12
__int64 result; // rax

if ( a2 + 1 >= a3 )
{
fprintf(stderr, "%s: Missing argument to %s.\n", *a1, a1[a2]);
result = 0LL;
}
else
{
v5 = &a1[a2 + 1];
result = _isoc99_sscanf(*v5, "%d", a4);
if ( (_DWORD)result != 1 )
{
fprintf(stderr, "%s: Couldn't scan \"%s\" as %s.\n", *a1, *v5, a5);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, int a2, int a3, __int64 a4, const char *a5)
{
const char **v5; // r12
__int64 result; // rax

if ( a2 + 1 >= a3 )
{
fprintf(stderr, "%s: Missing argument to %s.\n", *a1, a1[a2]);
result = 0LL;
}
else
{
v5 = &a1[a2 + 1];
result = _isoc99_sscanf(*v5, "%d", a4);
if ( (_DWORD)result != 1 )
{
fprintf(stderr, "%s: Couldn't scan \"%s\" as %s.\n", *a1, *v5, a5);
result = 0LL;
}
}
return result;
}

original_code:
static int get_arg_int(
 char ** argv,
 int argi,
 int argc,
 int * pval,
 char * desc)
{
 if (argc <= argi + 1) {
  fprintf(stderr, "%s:  Missing argument to %s.\n",
   argv[0], argv[argi]);
  return 0;
 }
 if (sscanf(argv[argi+1], "%d", pval) != 1) {
  fprintf(stderr, "%s: Couldn't scan \"%s\" as %s.\n",
   argv[0], argv[argi+1], desc);
  return 0;
 }
 return 1;
}

canonical_original_code:
static int get_arg_int(char **argv, int argi, int argc, int *pval, char *desc)
{
 if (argc <= argi + 1) {
  fprintf(stderr, "%s:  Missing argument to %s.\n",
   argv[0], argv[argi]);
  return 0;
 }
 if (sscanf(argv[argi+1], "%d", pval) != 1) {
  fprintf(stderr, "%s: Couldn't scan \"%s\" as %s.\n",
   argv[0], argv[argi+1], desc);
  return 0;
 }
 return 1;
}

variable_types: argi int

variable_types:
pval
int *

variable_types:
desc
char *