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


repo: johnkerl/ctools

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 *

return_type: int


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; // r15
unsigned int v7; // er12
const char *v8; // rbp
const char *v9; // r13
_BYTE v11[492]; // [rsp+0h] [rbp-268h] BYREF
unsigned int v12; // [rsp+1ECh] [rbp-7Ch] BYREF
char v13[40]; // [rsp+1F0h] [rbp-78h] BYREF
int v14; // [rsp+218h] [rbp-50h] BYREF
int v15; // [rsp+21Ch] [rbp-4Ch] BYREF
__int64 v16; // [rsp+220h] [rbp-48h] BYREF
int v17[15]; // [rsp+22Ch] [rbp-3Ch] BYREF

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

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; // r15
unsigned int v7; // er12
const char *v8; // rbp
const char *v9; // r13
_BYTE v11[492]; // [rsp+0h] [rbp-268h] BYREF
unsigned int v12; // [rsp+1ECh] [rbp-7Ch] BYREF
char v13[40]; // [rsp+1F0h] [rbp-78h] BYREF
int v14; // [rsp+218h] [rbp-50h] BYREF
int v15; // [rsp+21Ch] [rbp-4Ch] BYREF
__int64 v16; // [rsp+220h] [rbp-48h] BYREF
int v17[15]; // [rsp+22Ch] [rbp-3Ch] BYREF

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

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

return_type: char *


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)
{
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(0x160uLL);
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);
RC6_bytes_to_block(a2[1], dest, v6);
if ( a2[39] )
hex_dump_region("RC6 key material", dest, a2[1], 16LL);
RC6_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(0x160uLL);
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);
RC6_bytes_to_block(a2[1], dest, v6);
if ( a2[39] )
hex_dump_region("RC6 key material", dest, a2[1], 16LL);
RC6_key_schedule(v6, 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);
}

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

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; // rbp
_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, v7);
LODWORD(v4) = RC6_encrypt_block(v7, v6, a3[1], v4);
RC6_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[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = *((_QWORD *)a3 + 18);
RC6_bytes_to_block(*a3, a1, v7);
LODWORD(v4) = RC6_encrypt_block(v7, v6, a3[1], v4);
RC6_block_to_bytes(*a3, v6, 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; // rbp
_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, v7);
LODWORD(v4) = RC6_decrypt_block(v7, v6, a3[1], v4);
RC6_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[32]; // [rsp+0h] [rbp-58h] BYREF
char v7[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = *((_QWORD *)a3 + 18);
RC6_bytes_to_block(*a3, a1, v7);
LODWORD(v4) = RC6_decrypt_block(v7, v6, a3[1], v4);
RC6_block_to_bytes(*a3, v6, 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:
__int64 __fastcall null_decrypt_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_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 )
{
fast_1 = 0;
++slow_0;
result = 1LL;
}
else
{
++fast_1;
result = 0LL;
}
return result;
}

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

if ( (unsigned int)(fast_1 + 1) > 0x190 )
{
fast_1 = 0;
++slow_0;
result = 1LL;
}
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; // rbp
int v4; // er12
int v5; // er15
int v6; // er14
const char *v7; // rbx
const char *v8; // rbx

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // er12
int v5; // er15
int v6; // er14
const char *v7; // rbx
const char *v8; // rbx

if ( argc <= 1 )
{
v5 = 0;
v6 = 2;
LABEL_30:
func3("-", v6, v5);
return 0;
}
v3 = argv + 1;
v4 = 0;
v5 = 0;
v6 = 2;
do
{
v7 = *v3;
if ( !strcmp(*v3, "--help") )
func1(*argv);
if ( *v7 == 45 && v7[1] )
{
v8 = v7 + 1;
if ( !strcmp(v8, "ip") )
{
v6 = 1;
}
else if ( !strcmp(v8, "eth") )
{
v6 = 2;
}
else if ( !strcmp(v8, "crca") )
{
v6 = 3;
}
else if ( !strcmp(v8, "murmur") )
{
v6 = 4;
}
else if ( !strcmp(v8, "floppy") )
{
v6 = 5;
}
else if ( !strcmp(v8, "md5") )
{
v6 = 6;
}
else if ( !strcmp(v8, "nop") )
{
v6 = 7;
}
else if ( !strcmp(v8, "spin") )
{
v5 = 1;
}
else
{
v5 = strcmp(v8, "nospin");
if ( v5 )
func1(*argv);
}
}
else
{
++v4;
func3((char *)*v3, v6, v5);
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
if ( !v4 )
goto LABEL_30;
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; // edx
_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 func1(const char *a1)
{
int v1; // edx
_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; // edx
__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 func2(const char *a1, _DWORD *a2)
{
int v2; // edx
__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 **v6; // r12
__int64 result; // rax

if ( a2 + 1 >= a3 )
{
fprintf(stderr, "%s: Missing argument to %s.\n", *a1, a1[a2]);
result = 0LL;
}
else
{
v6 = &a1[a2 + 1];
result = _isoc99_sscanf(*v6, "%d", a4);
if ( (_DWORD)result != 1 )
{
fprintf(stderr, "%s: Couldn't scan \"%s\" as %s.\n", *a1, *v6, 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 **v6; // r12
__int64 result; // rax

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


decompiled_code:
__int64 __fastcall parse_command_line(int a1, const char **a2, _DWORD *a3)
{
unsigned int v4; // er15
int v5; // ebx
__int64 v6; // rdx
const char *v7; // rbp
const char **v8; // rbp
unsigned int v9; // edx
const char **v10; // rbp
const char *v11; // rbx
const char *v12; // rdx
char v13; // al
const char *v15; // [rsp+0h] [rbp-58h]
unsigned int v16; // [rsp+8h] [rbp-50h]
int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v17[0] = -1;
if ( a1 <= 1 )
{
a3[45] = 2;
v4 = -1;
v15 = 0LL;
v16 = 0;
v5 = 1;
LABEL_68:
v9 = *(_DWORD *)(*(_QWORD *)a3 + 8LL);
goto LABEL_35;
}
v4 = -1;
v15 = 0LL;
v16 = 0;
v5 = 1;
while ( 1 )
{
v6 = v5;
v7 = a2[v6];
if ( !strcmp(v7, "-kl") )
{
if ( !(unsigned int)get_arg_int(a2, v5, a1, (__int64)v17, "block length") )
return 0;
++v5;
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-bkl") )
{
if ( !(unsigned int)get_arg_int(a2, v5, a1, (__int64)v17, "block & key length") )
return 0;
v4 = v17[0];
++v5;
goto LABEL_5;
}
if ( strcmp(a2[v5], "-nocbc") )
break;
a3[40] = 0;
LABEL_5:
if ( a1 <= ++v5 )
goto LABEL_34;
}
if ( !strcmp(a2[v5], "-ecb") )
{
a3[40] = 0;
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-c") )
{
++v5;
v8 = &a2[v6 + 1];
if ( !(unsigned int)block_cipher_select(*v8, a3, a3 + 2) )
{
fprintf(stderr, "Couldn't find cipher \"%s\".\n", *v8);
return 0;
}
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-iv") )
{
a3[20] = 1;
++v5;
v15 = a2[v6 + 1];
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-app") )
{
++a3[46];
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-alg") )
{
++a3[41];
goto LABEL_5;
}
if ( !strcmp(v7, "-list") )
{
block_cipher_list();
exit(0);
}
if ( !strcmp(v7, "-nospin") )
{
a3[48] = 0;
goto LABEL_5;
}
if ( !strcmp(v7, "-crc") )
{
a3[47] = 1;
goto LABEL_5;
}
if ( !strcmp(v7, "-nocrc") )
{
a3[47] = 0;
goto LABEL_5;
}
if ( !strcmp(v7, "-dump") )
{
v16 = 1;
goto LABEL_5;
}
if ( !strcmp(v7, "--help") )
return 0;
LABEL_34:
a3[45] = v5 + 1;
v9 = v17[0];
if ( v17[0] == -1 )
goto LABEL_68;
LABEL_35:
a3[2] = v9;
if ( v4 == -1 )
v4 = *(_DWORD *)(*(_QWORD *)a3 + 12LL);
a3[3] = v4;
if ( v4 - 1 > 0x3F )
{
fprintf(stderr, "%s: Key length %d out of range for application.\n", *a2, v4);
v16 = 0;
}
else if ( v9 - 1 > 0x3F )
{
fprintf(stderr, "%s: Block length %d out of range for application.\n", *a2, v9);
v16 = 0;
}
else
{
if ( a3[20] && !(unsigned int)bc_read_block_from_file(v15, a3 + 4) )
exit(1);
if ( v16 )
{
fprintf(stderr, "Cipher: %s\n", **(const char ***)a3);
fprintf(stderr, "Block length: %d\n", (unsigned int)a3[2]);
fprintf(stderr, "Key length: %d\n", (unsigned int)a3[3]);
v12 = "yes";
if ( !a3[40] )
v12 = "no";
fprintf(stderr, "CBC: %s\n", v12);
exit(0);
}
if ( a1 <= v5 )
{
fprintf(stderr, "%s: Missing verb (check, +key or -key).\n", *a2);
}
else
{
v10 = &a2[v5];
v11 = *v10;
if ( !strcmp(*v10, "check") )
{
a3[44] = 3;
goto LABEL_44;
}
*((_QWORD *)a3 + 21) = v11 + 1;
v13 = **v10;
if ( v13 == 43 )
{
a3[44] = 1;
LABEL_59:
if ( v11[1] == 64 )
{
if ( !(unsigned int)bc_read_block_from_file(v11 + 2, a3 + 21) )
exit(1);
a3[37] = 1;
}
LABEL_44:
if ( a3[46] || (v16 = 1, a3[41]) )
{
a3[48] = 0;
v16 = 1;
}
}
else if ( v13 == 45 )
{
a3[44] = 2;
goto LABEL_59;
}
}
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char **a2, _DWORD *a3)
{
unsigned int v4; // er15
int v5; // ebx
__int64 v6; // rdx
const char *v7; // rbp
const char **v8; // rbp
unsigned int v9; // edx
const char **v10; // rbp
const char *v11; // rbx
const char *v12; // rdx
char v13; // al
const char *v15; // [rsp+0h] [rbp-58h]
unsigned int v16; // [rsp+8h] [rbp-50h]
int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v17[0] = -1;
if ( a1 <= 1 )
{
a3[45] = 2;
v4 = -1;
v15 = 0LL;
v16 = 0;
v5 = 1;
LABEL_68:
v9 = *(_DWORD *)(*(_QWORD *)a3 + 8LL);
goto LABEL_35;
}
v4 = -1;
v15 = 0LL;
v16 = 0;
v5 = 1;
while ( 1 )
{
v6 = v5;
v7 = a2[v6];
if ( !strcmp(v7, "-kl") )
{
if ( !(unsigned int)func1(a2, v5, a1, (__int64)v17, "block length") )
return 0;
++v5;
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-bkl") )
{
if ( !(unsigned int)func1(a2, v5, a1, (__int64)v17, "block & key length") )
return 0;
v4 = v17[0];
++v5;
goto LABEL_5;
}
if ( strcmp(a2[v5], "-nocbc") )
break;
a3[40] = 0;
LABEL_5:
if ( a1 <= ++v5 )
goto LABEL_34;
}
if ( !strcmp(a2[v5], "-ecb") )
{
a3[40] = 0;
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-c") )
{
++v5;
v8 = &a2[v6 + 1];
if ( !(unsigned int)block_cipher_select(*v8, a3, a3 + 2) )
{
fprintf(stderr, "Couldn't find cipher \"%s\".\n", *v8);
return 0;
}
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-iv") )
{
a3[20] = 1;
++v5;
v15 = a2[v6 + 1];
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-app") )
{
++a3[46];
goto LABEL_5;
}
if ( !strcmp(a2[v5], "-alg") )
{
++a3[41];
goto LABEL_5;
}
if ( !strcmp(v7, "-list") )
{
block_cipher_list();
exit(0);
}
if ( !strcmp(v7, "-nospin") )
{
a3[48] = 0;
goto LABEL_5;
}
if ( !strcmp(v7, "-crc") )
{
a3[47] = 1;
goto LABEL_5;
}
if ( !strcmp(v7, "-nocrc") )
{
a3[47] = 0;
goto LABEL_5;
}
if ( !strcmp(v7, "-dump") )
{
v16 = 1;
goto LABEL_5;
}
if ( !strcmp(v7, "--help") )
return 0;
LABEL_34:
a3[45] = v5 + 1;
v9 = v17[0];
if ( v17[0] == -1 )
goto LABEL_68;
LABEL_35:
a3[2] = v9;
if ( v4 == -1 )
v4 = *(_DWORD *)(*(_QWORD *)a3 + 12LL);
a3[3] = v4;
if ( v4 - 1 > 0x3F )
{
fprintf(stderr, "%s: Key length %d out of range for application.\n", *a2, v4);
v16 = 0;
}
else if ( v9 - 1 > 0x3F )
{
fprintf(stderr, "%s: Block length %d out of range for application.\n", *a2, v9);
v16 = 0;
}
else
{
if ( a3[20] && !(unsigned int)bc_read_block_from_file(v15, a3 + 4) )
exit(1);
if ( v16 )
{
fprintf(stderr, "Cipher: %s\n", **(const char ***)a3);
fprintf(stderr, "Block length: %d\n", (unsigned int)a3[2]);
fprintf(stderr, "Key length: %d\n", (unsigned int)a3[3]);
v12 = "yes";
if ( !a3[40] )
v12 = "no";
fprintf(stderr, "CBC: %s\n", v12);
exit(0);
}
if ( a1 <= v5 )
{
fprintf(stderr, "%s: Missing verb (check, +key or -key).\n", *a2);
}
else
{
v10 = &a2[v5];
v11 = *v10;
if ( !strcmp(*v10, "check") )
{
a3[44] = 3;
goto LABEL_44;
}
*((_QWORD *)a3 + 21) = v11 + 1;
v13 = **v10;
if ( v13 == 43 )
{
a3[44] = 1;
LABEL_59:
if ( v11[1] == 64 )
{
if ( !(unsigned int)bc_read_block_from_file(v11 + 2, a3 + 21) )
exit(1);
a3[37] = 1;
}
LABEL_44:
if ( a3[46] || (v16 = 1, a3[41]) )
{
a3[48] = 0;
v16 = 1;
}
}
else if ( v13 == 45 )
{
a3[44] = 2;
goto LABEL_59;
}
}
}
return v16;
}

original_code:
static int parse_command_line(
 int argc,
 char ** argv,
 opts_t * popts)
{
 int argi;
 int bl = -1;
 int kl = -1;
 int dump = 0;
 char * IV_file_name = 0;
 for (argi = 1; argi < argc; argi++) {
  if (strcmp(argv[argi], "-kl") == 0) {
   if (!get_arg_int(argv, argi, argc, &bl,
     "block length"))
    return 0;
   argi++;
  }
  else if (strcmp(argv[argi], "-kl") == 0) {
   if (!get_arg_int(argv, argi, argc, &kl,
     "key length"))
    return 0;
   argi++;
  }
  else if (strcmp(argv[argi], "-bkl") == 0) {
   if (!get_arg_int(argv, argi, argc, &bl,
     "block & key length"))
    return 0;
   kl = bl;
   argi++;
  }
  else if (strcmp(argv[argi], "-nocbc") == 0) {
   popts->ciphinst.do_cbc = 0;
  }
  else if (strcmp(argv[argi], "-ecb") == 0) {
   popts->ciphinst.do_cbc = 0;
  }
  else if (strcmp(argv[argi], "-c") == 0) {
   argi++;
   if (!block_cipher_select(argv[argi],
    &popts->pcipher, &popts->ciphinst))
   {
    fprintf(stderr,
     "Couldn't find cipher \"%s\".\n",
     argv[argi]);
    return 0;
   }
  }
  else if (strcmp(argv[argi], "-iv") == 0) {
   popts->ciphinst.have_user_IV = 1;
   argi++;
   IV_file_name = argv[argi];
  }
  else if (strcmp(argv[argi], "-app") == 0) {
   popts->app_debug++;
  }
  else if (strcmp(argv[argi], "-alg") == 0) {
   popts->ciphinst.alg_debug++;
  }
  else if (strcmp(argv[argi], "-list") == 0) {
   block_cipher_list();
   exit(0);
  }
  else if (strcmp(argv[argi], "-nospin") == 0) {
   popts->do_spin = 0;
  }
  else if (strcmp(argv[argi], "-crc") == 0) {
   popts->do_crc = 1;
  }
  else if (strcmp(argv[argi], "-nocrc") == 0) {
   popts->do_crc = 0;
  }
  else if (strcmp(argv[argi], "-dump") == 0) {
   dump = 1;
  }
  else if (strcmp(argv[argi], "--help") == 0) {
   return 0;
  }
  else {
   break;
  }
 }
 popts->first_file_argi = argi + 1;
 if (bl == -1)
  popts->ciphinst.bl =
   popts->pcipher->default_bl;
 else
  popts->ciphinst.bl = bl;
 if (kl == -1)
  popts->ciphinst.kl =
   popts->pcipher->default_kl;
 else
  popts->ciphinst.kl = kl;
 if ((popts->ciphinst.kl < 1) || (popts->ciphinst.kl > 64)) {
  fprintf(stderr,
   "%s:  Key length %d out of range for application.\n",
   argv[0], popts->ciphinst.kl);
  return 0;
 }
 if ((popts->ciphinst.bl < 1) || (popts->ciphinst.bl > 64)) {
  fprintf(stderr,
   "%s:  Block length %d out of range for application.\n",
   argv[0], popts->ciphinst.bl);
  return 0;
 }
 if ((popts->ciphinst.kl < 1) || (popts->ciphinst.kl > 64)) {
  fprintf(stderr,
   "%s:  Key length %d out of range for application.\n",
   argv[0], popts->ciphinst.kl);
  return 0;
 }
 if ((popts->ciphinst.bl < 1) || (popts->ciphinst.bl > 64)) {
  fprintf(stderr,
   "%s:  Block length %d out of range for application.\n",
   argv[0], popts->ciphinst.bl);
  return 0;
 }
 if (popts->ciphinst.have_user_IV) {
  if (!bc_read_block_from_file(IV_file_name,
  popts->ciphinst.user_IV,
  popts->ciphinst.bl))
  {
   exit(1);
  }
 }
 if (dump) {
  fprintf(stderr, "Cipher:       %s\n",
   popts->pcipher->cipher_name);
  fprintf(stderr, "Block length: %d\n",
   popts->ciphinst.bl);
  fprintf(stderr, "Key   length: %d\n",
   popts->ciphinst.kl);
  fprintf(stderr, "CBC:          %s\n",
   popts->ciphinst.do_cbc ? "yes" : "no");
  exit(0);
 }
 if (argi >= argc) {
  fprintf(stderr,
   "%s:  Missing verb (check, +key or -key).\n",
   argv[0]);
  return 0;
 }
 if (strcmp(argv[argi], "check") == 0) {
  popts->operation = 3;
 }
 else {
  popts->key_text = &argv[argi][1];
  if (argv[argi][0] == '+')
   popts->operation = 1;
  else if (argv[argi][0] == '-')
   popts->operation = 2;
  else
   return 0;
  if (popts->key_text[0] == '@') {
   if (!bc_read_block_from_file(&popts->key_text[1],
   popts->ciphinst.user_key_mat,
   popts->ciphinst.kl))
    exit(1);
   popts->ciphinst.have_user_key_mat = 1;
  }
 }
 if (popts->app_debug || popts->ciphinst.alg_debug)
  popts->do_spin = 0;
 return 1;
}

canonical_original_code:
static int parse_command_line(int argc, char **argv, struct _opts_t *popts)
{
 int argi;
 int bl = -1;
 int kl = -1;
 int dump = 0;
 char *IV_file_name = 0;
 for (argi = 1; argi < argc; argi++) {
  if (strcmp(argv[argi], "-kl") == 0) {
   if (!get_arg_int(argv, argi, argc, &bl,
     "block length"))
    return 0;
   argi++;
  }
  else if (strcmp(argv[argi], "-kl") == 0) {
   if (!get_arg_int(argv, argi, argc, &kl,
     "key length"))
    return 0;
   argi++;
  }
  else if (strcmp(argv[argi], "-bkl") == 0) {
   if (!get_arg_int(argv, argi, argc, &bl,
     "block & key length"))
    return 0;
   kl = bl;
   argi++;
  }
  else if (strcmp(argv[argi], "-nocbc") == 0) {
   popts->ciphinst.do_cbc = 0;
  }
  else if (strcmp(argv[argi], "-ecb") == 0) {
   popts->ciphinst.do_cbc = 0;
  }
  else if (strcmp(argv[argi], "-c") == 0) {
   argi++;
   if (!block_cipher_select(argv[argi],
    &popts->pcipher, &popts->ciphinst))
   {
    fprintf(stderr,
     "Couldn't find cipher \"%s\".\n",
     argv[argi]);
    return 0;
   }
  }
  else if (strcmp(argv[argi], "-iv") == 0) {
   popts->ciphinst.have_user_IV = 1;
   argi++;
   IV_file_name = argv[argi];
  }
  else if (strcmp(argv[argi], "-app") == 0) {
   popts->app_debug++;
  }
  else if (strcmp(argv[argi], "-alg") == 0) {
   popts->ciphinst.alg_debug++;
  }
  else if (strcmp(argv[argi], "-list") == 0) {
   block_cipher_list();
   exit(0);
  }
  else if (strcmp(argv[argi], "-nospin") == 0) {
   popts->do_spin = 0;
  }
  else if (strcmp(argv[argi], "-crc") == 0) {
   popts->do_crc = 1;
  }
  else if (strcmp(argv[argi], "-nocrc") == 0) {
   popts->do_crc = 0;
  }
  else if (strcmp(argv[argi], "-dump") == 0) {
   dump = 1;
  }
  else if (strcmp(argv[argi], "--help") == 0) {
   return 0;
  }
  else {
   break;
  }
 }
 popts->first_file_argi = argi + 1;
 if (bl == -1)
  popts->ciphinst.bl =
   popts->pcipher->default_bl;
 else
  popts->ciphinst.bl = bl;
 if (kl == -1)
  popts->ciphinst.kl =
   popts->pcipher->default_kl;
 else
  popts->ciphinst.kl = kl;
 if ((popts->ciphinst.kl < 1) || (popts->ciphinst.kl > 64)) {
  fprintf(stderr,
   "%s:  Key length %d out of range for application.\n",
   argv[0], popts->ciphinst.kl);
  return 0;
 }
 if ((popts->ciphinst.bl < 1) || (popts->ciphinst.bl > 64)) {
  fprintf(stderr,
   "%s:  Block length %d out of range for application.\n",
   argv[0], popts->ciphinst.bl);
  return 0;
 }
 if ((popts->ciphinst.kl < 1) || (popts->ciphinst.kl > 64)) {
  fprintf(stderr,
   "%s:  Key length %d out of range for application.\n",
   argv[0], popts->ciphinst.kl);
  return 0;
 }
 if ((popts->ciphinst.bl < 1) || (popts->ciphinst.bl > 64)) {
  fprintf(stderr,
   "%s:  Block length %d out of range for application.\n",
   argv[0], popts->ciphinst.bl);
  return 0;
 }
 if (popts->ciphinst.have_user_IV) {
  if (!bc_read_block_from_file(IV_file_name,
  popts->ciphinst.user_IV,
  popts->ciphinst.bl))
  {
   exit(1);
  }
 }
 if (dump) {
  fprintf(stderr, "Cipher:       %s\n",
   popts->pcipher->cipher_name);
  fprintf(stderr, "Block length: %d\n",
   popts->ciphinst.bl);
  fprintf(stderr, "Key   length: %d\n",
   popts->ciphinst.kl);
  fprintf(stderr, "CBC:          %s\n",
   popts->ciphinst.do_cbc ? "yes" : "no");
  exit(0);
 }
 if (argi >= argc) {
  fprintf(stderr,
   "%s:  Missing verb (check, +key or -key).\n",
   argv[0]);
  return 0;
 }
 if (strcmp(argv[argi], "check") == 0) {
  popts->operation = 3;
 }
 else {
  popts->key_text = &argv[argi][1];
  if (argv[argi][0] == '+')
   popts->operation = 1;
  else if (argv[argi][0] == '-')
   popts->operation = 2;
  else
   return 0;
  if (popts->key_text[0] == '@') {
   if (!bc_read_block_from_file(&popts->key_text[1],
   popts->ciphinst.user_key_mat,
   popts->ciphinst.kl))
    exit(1);
   popts->ciphinst.have_user_key_mat = 1;
  }
 }
 if (popts->app_debug || popts->ciphinst.alg_debug)
  popts->do_spin = 0;
 return 1;
}

variable_types: bl int

variable_types: kl int

variable_types: dump int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, " Usage: %s [options] {verb} {file name(s) ... }\n", a1);
fwrite(" Options:\n", 1uLL, 0xBuLL, stderr);
fwrite(" -kl {n}: Key length in bytes.\n", 1uLL, 0x25uLL, stderr);
fwrite(" -bl {n}: Block length in bytes.\n", 1uLL, 0x25uLL, stderr);
fwrite(" Verb:\n", 1uLL, 8uLL, stderr);
fwrite(" +{key text} for encrypt\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -{key text} for decrypt\n", 1uLL, 0x1CuLL, stderr);
fwrite(" check to see if file was encrypted with this program\n", 1uLL, 0x3FuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(stderr, " Usage: %s [options] {verb} {file name(s) ... }\n", a1);
fwrite(" Options:\n", 1uLL, 0xBuLL, stderr);
fwrite(" -kl {n}: Key length in bytes.\n", 1uLL, 0x25uLL, stderr);
fwrite(" -bl {n}: Block length in bytes.\n", 1uLL, 0x25uLL, stderr);
fwrite(" Verb:\n", 1uLL, 8uLL, stderr);
fwrite(" +{key text} for encrypt\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -{key text} for decrypt\n", 1uLL, 0x1CuLL, stderr);
fwrite(" check to see if file was encrypted with this program\n", 1uLL, 0x3FuLL, stderr);
exit(1);
}

original_code:
static void usage(char *argv0)
{
 fprintf(stderr,
  "  Usage: %s [options] {verb} {file name(s) ... }\n",
  argv0);
 fprintf(stderr, "  Options:\n");
 fprintf(stderr, "    -kl {n}:  Key   length in bytes.\n");
 fprintf(stderr, "    -bl {n}:  Block length in bytes.\n");
 fprintf(stderr, "  Verb:\n");
 fprintf(stderr, "    +{key text} for encrypt\n");
 fprintf(stderr, "    -{key text} for decrypt\n");
 fprintf(stderr,
 "    check       to see if file was encrypted with this program\n");
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // rbx
const char **v5; // r12
unsigned int v7; // eax
const char *v8; // rax
__int64 v9; // [rsp+0h] [rbp-F8h] BYREF
char v10[160]; // [rsp+8h] [rbp-F0h] BYREF
__int64 v11; // [rsp+A8h] [rbp-50h]
int v12; // [rsp+B0h] [rbp-48h]
int v13; // [rsp+B4h] [rbp-44h]

set_defaults((__int64)&v9);
if ( !(unsigned int)parse_command_line(argc, argv, &v9) )
usage(*argv);
if ( (unsigned int)(v12 - 1) <= 1 )
{
v7 = (*(__int64 (__fastcall **)(__int64, char *))(v9 + 32))(v11, v10);
if ( v7 != 1 )
{
v8 = (const char *)(*(__int64 (__fastcall **)(_QWORD))(v9 + 64))(v7);
fprintf(stderr, "%s: %s while scheduling key.\n", *(const char **)v9, v8);
exit(1);
}
}
v3 = 0;
if ( v13 == argc )
v3 = bc_handle_fp_pair(stdin, stdout, "stdin", "stdout", &v9) == 0;
if ( argc > v13 )
{
v4 = &argv[v13];
v5 = &(&argv[v13])[(unsigned __int64)(unsigned int)(argc + ~v13) + 1];
do
v3 += bc_handle_file_name(*v4++, &v9) == 0;
while ( v4 != v5 );
}
(*(void (__fastcall **)(__int64, char *))(v9 + 40))(v11, v10);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // rbx
const char **v5; // r12
unsigned int v7; // eax
const char *v8; // rax
__int64 v9; // [rsp+0h] [rbp-F8h] BYREF
char v10[160]; // [rsp+8h] [rbp-F0h] BYREF
__int64 v11; // [rsp+A8h] [rbp-50h]
int v12; // [rsp+B0h] [rbp-48h]
int v13; // [rsp+B4h] [rbp-44h]

func0((__int64)&v9);
if ( !(unsigned int)func2(argc, argv, &v9) )
func3(*argv);
if ( (unsigned int)(v12 - 1) <= 1 )
{
v7 = (*(__int64 (__fastcall **)(__int64, char *))(v9 + 32))(v11, v10);
if ( v7 != 1 )
{
v8 = (const char *)(*(__int64 (__fastcall **)(_QWORD))(v9 + 64))(v7);
fprintf(stderr, "%s: %s while scheduling key.\n", *(const char **)v9, v8);
exit(1);
}
}
v3 = 0;
if ( v13 == argc )
v3 = bc_handle_fp_pair(stdin, stdout, "stdin", "stdout", &v9) == 0;
if ( argc > v13 )
{
v4 = &argv[v13];
v5 = &(&argv[v13])[(unsigned __int64)(unsigned int)(argc + ~v13) + 1];
do
v3 += bc_handle_file_name(*v4++, &v9) == 0;
while ( v4 != v5 );
}
(*(void (__fastcall **)(__int64, char *))(v9 + 40))(v11, v10);
return v3;
}

original_code:
int main(int argc, char **argv)
{
 opts_t opts;
 int argi;
 int rv = 0;
 int make_key_rc;
 set_defaults(&opts);
 if (!parse_command_line(argc, argv, &opts))
  usage(argv[0]);
 if (opts.operation == 1 || opts.operation == 2) {
  make_key_rc = opts.pcipher->pkey_maker(opts.key_text,
  &opts.ciphinst);
  if (make_key_rc != 1) {
   fprintf(stderr, "%s:  %s while scheduling key.\n",
    opts.pcipher->cipher_name,
    opts.pcipher->perror_explainer(make_key_rc));
   exit(1);
  }
 }
 if (opts.first_file_argi == argc) {
  if (!bc_handle_fp_pair(stdin, stdout, "stdin", "stdout", &opts))
   rv++;
 }
 for (argi = opts.first_file_argi; argi < argc; argi++) {
  if (!bc_handle_file_name(argv[argi], &opts))
   rv++;
 }
 opts.pcipher->pkey_freer(opts.key_text, &opts.ciphinst);
 return rv;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct _opts_t opts;
 int argi;
 int rv = 0;
 int make_key_rc;
 set_defaults(&opts);
 if (!parse_command_line(argc, argv, &opts))
  usage(argv[0]);
 if (opts.operation == 1 || opts.operation == 2) {
  make_key_rc = opts.pcipher->pkey_maker(opts.key_text,
  &opts.ciphinst);
  if (make_key_rc != 1) {
   fprintf(stderr, "%s:  %s while scheduling key.\n",
    opts.pcipher->cipher_name,
    opts.pcipher->perror_explainer(make_key_rc));
   exit(1);
  }
 }
 if (opts.first_file_argi == argc) {
  if (!bc_handle_fp_pair(stdin, stdout, "stdin", "stdout", &opts))
   rv++;
 }
 for (argi = opts.first_file_argi; argi < argc; argi++) {
  if (!bc_handle_file_name(argv[argi], &opts))
   rv++;
 }
 opts.pcipher->pkey_freer(opts.key_text, &opts.ciphinst);
 return rv;
}

variable_types: argc int

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

variable_types: rv int


decompiled_code:
__int64 __fastcall block_cipher_select(char *s1, const char ***a2)
{
__int64 v2; // rbx
unsigned int v3; // er14
const char **v4; // rbp

if ( num_block_ciphers <= 0 )
return 0;
v2 = 0LL;
v3 = 0;
do
{
v4 = (const char **)*(&pblock_ciphers + v2);
if ( !strcasecmp(s1, *v4) )
{
*a2 = v4;
v3 = 1;
}
++v2;
}
while ( num_block_ciphers > (int)v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, const char ***a2)
{
__int64 v2; // rbx
unsigned int v3; // er14
const char **v4; // rbp

if ( num_block_ciphers <= 0 )
return 0;
v2 = 0LL;
v3 = 0;
do
{
v4 = (const char **)*(&pblock_ciphers + v2);
if ( !strcasecmp(s1, *v4) )
{
*a2 = v4;
v3 = 1;
}
++v2;
}
while ( num_block_ciphers > (int)v2 );
return v3;
}

original_code:
int block_cipher_select(
 char * cipher_name,
 block_cipher_t ** ppcipher,
 block_cipher_instance_t * pciphinst)
{
 int i;
 int got = 0;
 for (i = 0; i < num_block_ciphers; i++) {
  if (strcasecmp(
   cipher_name, pblock_ciphers[i]->cipher_name) == 0)
  {
   *ppcipher = pblock_ciphers[i];
   got = 1;
  }
 }
 return got;
}

canonical_original_code:
int block_cipher_select(char *cipher_name, struct _block_cipher_t **ppcipher, struct _block_cipher_instance_t *pciphinst)
{
 int i;
 int got = 0;
 for (i = 0; i < num_block_ciphers; i++) {
  if (strcasecmp(
   cipher_name, pblock_ciphers[i]->cipher_name) == 0)
  {
   *ppcipher = pblock_ciphers[i];
   got = 1;
  }
 }
 return got;
}

variable_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 { 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); } **

variable_types:
pciphinst
struct _block_cipher_instance_t *

variable_types: i int

variable_types: got int


decompiled_code:
int block_cipher_list()
{
__int64 v0; // rbx

fwrite("Available ciphers:\n", 1uLL, 0x13uLL, stderr);
if ( num_block_ciphers > 0 )
{
v0 = 0LL;
do
fprintf(stderr, " %s\n", *(const char **)*(&pblock_ciphers + v0++));
while ( num_block_ciphers > (int)v0 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx

fwrite("Available ciphers:\n", 1uLL, 0x13uLL, stderr);
if ( num_block_ciphers > 0 )
{
v0 = 0LL;
do
fprintf(stderr, " %s\n", *(const char **)*(&pblock_ciphers + v0++));
while ( num_block_ciphers > (int)v0 );
}
return fputc(10, stderr);
}

original_code:
void block_cipher_list(void)
{
 int i;
 fprintf(stderr, "Available ciphers:\n");
 for (i = 0; i < num_block_ciphers; i++) {
  fprintf(stderr, "  %s\n", pblock_ciphers[i]->cipher_name);
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void block_cipher_list()
{
 int i;
 fprintf(stderr, "Available ciphers:\n");
 for (i = 0; i < num_block_ciphers; i++) {
  fprintf(stderr, "  %s\n", pblock_ciphers[i]->cipher_name);
 }
 fprintf(stderr, "\n");
}


original_code:
static void block_to_stream(
 int block_length_in_bits,
 word8 block[4][(256/32)],
 BYTE * output)
{
 int j;
 int n = block_length_in_bits >> 5;
 int j2;
 for (j = 0; j < n; j++) {
  j2 = j << 2;
  output[j2 ] = (BYTE) block[0][j];
  output[j2+1] = (BYTE) block[1][j];
  output[j2+2] = (BYTE) block[2][j];
  output[j2+3] = (BYTE) block[3][j];
 }
}

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

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

variable_types:
output
unsigned char *

variable_types: j int

variable_types: n int


decompiled_code:
__int64 __fastcall AES_encrypt(int a1, int a2, int *a3, _BYTE *a4, _BYTE *a5, int a6, _BYTE *a7)
{
int v11; // er15
__int64 v12; // rax
int j; // er14
int i; // er14
int v16; // [rsp+Ch] [rbp-6Ch]
int v18; // [rsp+10h] [rbp-68h]
int v19; // [rsp+18h] [rbp-60h]
char v20[88]; // [rsp+20h] [rbp-58h] BYREF

v16 = a2 >> 3;
if ( !a3 )
return 4294967294LL;
if ( !(unsigned int)valid_key_length(*a3) )
return 4294967294LL;
if ( (unsigned int)(a1 - 1) > 1 )
return 4294967292LL;
if ( (unsigned int)valid_block_length(a2) )
{
v11 = a6 / a2;
if ( a1 == 1 )
{
if ( v11 > 0 )
{
for ( i = 0; i != v11; ++i )
{
stream_to_block(a2, a5, v20, 0);
AES_encrypt_block(v20, (unsigned int)*a3, (unsigned int)a2, a3 + 1);
block_to_stream(a2, v20, a7);
a5 += v16;
a7 += v16;
}
}
return (unsigned int)(v11 * a2);
}
stream_to_block(a2, a4, v20, 0);
if ( v11 <= 9 )
{
fputc(10, stderr);
if ( v11 <= 0 )
{
LABEL_23:
fputc(10, stderr);
return (unsigned int)(v11 * a2);
}
v19 = 1;
}
else
{
if ( v11 <= 1000 )
v12 = (1717986919LL * v11) >> 34;
else
v12 = (1717986919LL * v11) >> 35;
v19 = v12 - (v11 >> 31);
fputc(10, stderr);
}
v18 = 100;
for ( j = 0; j < v11; ++j )
{
if ( !(j % v19) || v11 == j + 1 )
{
fprintf(stderr, "\r %3d%%", (unsigned int)(v18 / v11));
fflush(stdout);
}
stream_to_block(a2, a5, v20, 1);
AES_encrypt_block(v20, (unsigned int)*a3, (unsigned int)a2, a3 + 1);
block_to_stream(a2, v20, a7);
a5 += v16;
a7 += v16;
v18 += 100;
}
goto LABEL_23;
}
return 4294967291LL;
}

original_code:
int AES_encrypt(
 int mode,
 int block_length_in_bits,
 key_instance * key,
 BYTE * IV,
 BYTE * input,
 int input_length_in_bits,
 BYTE * output)
{
 int i, num_blocks;
 word8 block[4][(256/32)];
 int progress_interval;
 int bl5 = block_length_in_bits >> 5;
 int bl3 = block_length_in_bits >> 3;
 if (key == ((void *)0))
  return -2;
 if (!valid_key_length(key->key_length_in_bits))
  return -2;
 if (mode != 1 && mode != 2)
  return -4;
 if (!valid_block_length(block_length_in_bits))
  return -5;
 num_blocks = input_length_in_bits/block_length_in_bits;
 switch (mode) {
 case 1:
  for (i = 0; i < num_blocks; i++) {
   stream_to_block(block_length_in_bits, input, block, 0);
   AES_encrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   block_to_stream(block_length_in_bits, block, output);
   input += bl3;
   output += bl3;
  }
  break;
 case 2:
  stream_to_block(block_length_in_bits, IV, block, 0);
  if (num_blocks < 10)
   progress_interval = 1;
  else if (num_blocks > 1000)
   progress_interval = num_blocks / 20;
  else
   progress_interval = num_blocks / 10;
  fprintf(stderr, "\n");
  for (i = 0; i < num_blocks; i++) {
   if (((i % progress_interval) == 0) || (i+1 == num_blocks)) {
    fprintf(stderr, "\r    %3d%%",
     (100 * (i+1)) / num_blocks);
    fflush(stdout);
   }
   stream_to_block(block_length_in_bits, input, block, 1);
   AES_encrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   block_to_stream(block_length_in_bits, block, output);
   input += bl3;
   output += bl3;
  }
  fprintf(stderr, "\n");
  break;
 default:
  return -4;
 }
 return num_blocks * block_length_in_bits;
}

canonical_original_code:
int AES_encrypt(int mode, int block_length_in_bits, struct _key_instance *key, unsigned char *IV, unsigned char *input, int input_length_in_bits, unsigned char *output)
{
 int i; int num_blocks;
 unsigned char block[4][-1];
 int progress_interval;
 int bl5 = block_length_in_bits >> 5;
 int bl3 = block_length_in_bits >> 3;
 if (key == ((void *)0))
  return -2;
 if (!valid_key_length(key->key_length_in_bits))
  return -2;
 if (mode != 1 && mode != 2)
  return -4;
 if (!valid_block_length(block_length_in_bits))
  return -5;
 num_blocks = input_length_in_bits/block_length_in_bits;
 switch (mode) {
 case 1:
  for (i = 0; i < num_blocks; i++) {
   stream_to_block(block_length_in_bits, input, block, 0);
   AES_encrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   block_to_stream(block_length_in_bits, block, output);
   input += bl3;
   output += bl3;
  }
  break;
 case 2:
  stream_to_block(block_length_in_bits, IV, block, 0);
  if (num_blocks < 10)
   progress_interval = 1;
  else if (num_blocks > 1000)
   progress_interval = num_blocks / 20;
  else
   progress_interval = num_blocks / 10;
  fprintf(stderr, "\n");
  for (i = 0; i < num_blocks; i++) {
   if (((i % progress_interval) == 0) || (i+1 == num_blocks)) {
    fprintf(stderr, "\r    %3d%%",
     (100 * (i+1)) / num_blocks);
    fflush(stdout);
   }
   stream_to_block(block_length_in_bits, input, block, 1);
   AES_encrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   block_to_stream(block_length_in_bits, block, output);
   input += bl3;
   output += bl3;
  }
  fprintf(stderr, "\n");
  break;
 default:
  return -4;
 }
 return num_blocks * block_length_in_bits;
}

variable_types: mode int

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

variable_types:
IV
unsigned char *

variable_types:
input
unsigned char *


original_code:
int AES_decrypt(
 int mode,
 int block_length_in_bits,
 key_instance * key,
 BYTE * IV,
 BYTE * input,
 int input_length_in_bits,
 BYTE * output)
{
 int i, j, num_blocks;
 word8 block[4][(256/32)];
 int progress_interval;
 int bl5 = block_length_in_bits >> 5;
 int bl3 = block_length_in_bits >> 3;
 if (key == ((void *)0))
  return -2;
 if (!valid_key_length(key->key_length_in_bits))
  return -2;
 if (mode != 1 && mode != 2)
  return -4;
 if (!valid_block_length(block_length_in_bits))
  return -5;
 num_blocks = input_length_in_bits/block_length_in_bits;
 switch (mode) {
 case 1:
  for (i = 0; i < num_blocks; i++) {
   stream_to_block(block_length_in_bits, input, block, 0);
   AES_decrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   block_to_stream(block_length_in_bits, block, output);
   input += bl3;
   output += bl3;
  }
  break;
 case 2:
  if (num_blocks < 10)
   progress_interval = 1;
  else if (num_blocks > 1000)
   progress_interval = num_blocks / 20;
  else
   progress_interval = num_blocks / 10;
  stream_to_block(block_length_in_bits, input, block, 0);
  AES_decrypt_block(block, key->key_length_in_bits,
   block_length_in_bits, key->key_sched);
  input += bl3;
  for (j = 0; j < bl5; j++) {
   int idx = j << 2;
   output[idx ] = (BYTE) (block[0][j] ^ IV[ idx]);
   output[idx+1] = (BYTE) (block[1][j] ^ IV[1+idx]);
   output[idx+2] = (BYTE) (block[2][j] ^ IV[2+idx]);
   output[idx+3] = (BYTE) (block[3][j] ^ IV[3+idx]);
  }
  output += bl3;
  fprintf(stderr, "\n");
  for (i = 1; i < num_blocks; i++) {
   if (((i % progress_interval) == 0) || (i+1 == num_blocks)) {
    fprintf(stderr, "\r    %3d%%", (100 * (i+1)) / num_blocks);
    fflush(stdout);
   }
   stream_to_block(block_length_in_bits, input, block, 0);
   AES_decrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   for (j = 0; j < bl5; j++) {
    int idxo = j << 2;
    int idxi = idxo - bl3;
    output[idxo+0] = (BYTE) (block[0][j] ^ input[idxi+0]);
    output[idxo+1] = (BYTE) (block[1][j] ^ input[idxi+1]);
    output[idxo+2] = (BYTE) (block[2][j] ^ input[idxi+2]);
    output[idxo+3] = (BYTE) (block[3][j] ^ input[idxi+3]);
   }
   input += bl3;
   output += bl3;
  }
  fprintf(stderr, "\n");
  break;
 default: return -4;
 }
 return num_blocks * block_length_in_bits;
}

canonical_original_code:
int AES_decrypt(int mode, int block_length_in_bits, struct _key_instance *key, unsigned char *IV, unsigned char *input, int input_length_in_bits, unsigned char *output)
{
 int i; int j; int num_blocks;
 unsigned char block[4][-1];
 int progress_interval;
 int bl5 = block_length_in_bits >> 5;
 int bl3 = block_length_in_bits >> 3;
 if (key == ((void *)0))
  return -2;
 if (!valid_key_length(key->key_length_in_bits))
  return -2;
 if (mode != 1 && mode != 2)
  return -4;
 if (!valid_block_length(block_length_in_bits))
  return -5;
 num_blocks = input_length_in_bits/block_length_in_bits;
 switch (mode) {
 case 1:
  for (i = 0; i < num_blocks; i++) {
   stream_to_block(block_length_in_bits, input, block, 0);
   AES_decrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   block_to_stream(block_length_in_bits, block, output);
   input += bl3;
   output += bl3;
  }
  break;
 case 2:
  if (num_blocks < 10)
   progress_interval = 1;
  else if (num_blocks > 1000)
   progress_interval = num_blocks / 20;
  else
   progress_interval = num_blocks / 10;
  stream_to_block(block_length_in_bits, input, block, 0);
  AES_decrypt_block(block, key->key_length_in_bits,
   block_length_in_bits, key->key_sched);
  input += bl3;
  for (j = 0; j < bl5; j++) {
   int idx = j << 2;
   output[idx ] = (BYTE) (block[0][j] ^ IV[ idx]);
   output[idx+1] = (BYTE) (block[1][j] ^ IV[1+idx]);
   output[idx+2] = (BYTE) (block[2][j] ^ IV[2+idx]);
   output[idx+3] = (BYTE) (block[3][j] ^ IV[3+idx]);
  }
  output += bl3;
  fprintf(stderr, "\n");
  for (i = 1; i < num_blocks; i++) {
   if (((i % progress_interval) == 0) || (i+1 == num_blocks)) {
    fprintf(stderr, "\r    %3d%%", (100 * (i+1)) / num_blocks);
    fflush(stdout);
   }
   stream_to_block(block_length_in_bits, input, block, 0);
   AES_decrypt_block(block, key->key_length_in_bits,
    block_length_in_bits, key->key_sched);
   for (j = 0; j < bl5; j++) {
    int idxo = j << 2;
    int idxi = idxo - bl3;
    output[idxo+0] = (BYTE) (block[0][j] ^ input[idxi+0]);
    output[idxo+1] = (BYTE) (block[1][j] ^ input[idxi+1]);
    output[idxo+2] = (BYTE) (block[2][j] ^ input[idxi+2]);
    output[idxo+3] = (BYTE) (block[3][j] ^ input[idxi+3]);
   }
   input += bl3;
   output += bl3;
  }
  fprintf(stderr, "\n");
  break;
 default: return -4;
 }
 return num_blocks * block_length_in_bits;
}

variable_types: idx int

variable_types: idxo int

variable_types: idxi int

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


decompiled_code:
__int64 __fastcall valid_key_length(int a1)
{
return (a1 == 256) | (unsigned __int8)((a1 & 0xFFFFFFBF) == 128);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (a1 == 256) | (unsigned __int8)((a1 & 0xFFFFFFBF) == 128);
}

original_code:
static int valid_key_length(
 int key_length_in_bits)
{
 if (key_length_in_bits == 128)
  return 1;
 else if (key_length_in_bits == 192)
  return 1;
 else if (key_length_in_bits == 256)
  return 1;
 else
  return 0;
}

canonical_original_code:
static int valid_key_length(int key_length_in_bits)
{
 if (key_length_in_bits == 128)
  return 1;
 else if (key_length_in_bits == 192)
  return 1;
 else if (key_length_in_bits == 256)
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall AES_make_key(int *a1, int a2, unsigned int a3, __int64 a4)
{
__int64 v6; // rax
_BYTE v8[72]; // [rsp-20h] [rbp-48h] BYREF

if ( !a1 )
return 4294967293LL;
if ( !(unsigned int)valid_key_length(a2) )
return 4294967294LL;
*a1 = a2;
if ( !a4 )
return 4294967294LL;
if ( a2 >> 3 > 0 )
{
v6 = 0LL;
do
{
v8[8 * (v6 & 3) + ((int)v6 >> 2)] = *(_BYTE *)(a4 + v6);
++v6;
}
while ( v6 != a2 >> 3 );
}
AES_key_schedule(v8, (unsigned int)a2, a3, a1 + 1);
return 1LL;
}

original_code:
int AES_make_key(
 key_instance * key,
 int key_length_in_bits,
 int block_length_in_bits,
 char * key_material)
{
 word8 k[4][(256/32)];
 int i, j;
 if (key == ((void *)0))
  return -3;
 if (valid_key_length(key_length_in_bits))
  key->key_length_in_bits = key_length_in_bits;
 else
  return -2;
 if (key_material == ((void *)0))
  return -2;
 for (i = 0; i < key->key_length_in_bits >> 3; i++)
  k[i & 3][i >> 2] = (word8) key_material[i];
 AES_key_schedule(k, key->key_length_in_bits,
  block_length_in_bits, key->key_sched);
 return 1;
}

canonical_original_code:
int AES_make_key(struct _key_instance *key, int key_length_in_bits, int block_length_in_bits, char *key_material)
{
 unsigned char k[4][-1];
 int i; int j;
 if (key == ((void *)0))
  return -3;
 if (valid_key_length(key_length_in_bits))
  key->key_length_in_bits = key_length_in_bits;
 else
  return -2;
 if (key_material == ((void *)0))
  return -2;
 for (i = 0; i < key->key_length_in_bits >> 3; i++)
  k[i & 3][i >> 2] = (unsigned char) key_material[i];
 AES_key_schedule(k, key->key_length_in_bits,
  block_length_in_bits, key->key_sched);
 return 1;
}

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


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 func2(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


decompiled_code:
__int64 __fastcall get_ethernet_CRC(_BYTE *a1, int a2)
{
_BYTE *v2; // rcx
unsigned int v3; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = -1;
do
v3 = crctable[2 * (unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( a1 != v2 );
}
else
{
v3 = -1;
}
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, int a2)
{
_BYTE *v2; // rcx
unsigned int v3; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = -1;
do
v3 = crctable[2 * (unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( a1 != v2 );
}
else
{
v3 = -1;
}
return ~v3;
}

original_code:
unsigned get_ethernet_CRC(
 void * pfile_contents,
 int file_size)
{
 unsigned char * p;
 int len;
 unsigned crc;
 p = (unsigned char *)pfile_contents;
 len = file_size;
 crc = 0xffffffff;
 while (len--)
  crc = crctable[(crc ^ *p++) & 0xff] ^ (crc >> 8);
 return crc ^ 0xffffffff;
}

canonical_original_code:
unsigned int get_ethernet_CRC(void *pfile_contents, int file_size)
{
 unsigned char *p;
 int len;
 unsigned int crc;
 p = (unsigned char *)pfile_contents;
 len = file_size;
 crc = 0xffffffff;
 while (len--)
  crc = crctable[(crc ^ *p++) & 0xff] ^ (crc >> 8);
 return crc ^ 0xffffffff;
}

variable_types:
p
unsigned char *

variable_types: len int

variable_types:
crc
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall accum_CRCA(_BYTE *a1, unsigned int a2, unsigned int *a3, int a4)
{
unsigned int v4; // eax
_BYTE *v5; // rcx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
_BYTE *v13; // rsi

switch ( a4 )
{
case 1:
v4 = *a3;
if ( a2 > 7 )
{
v5 = &a1[8 * ((a2 - 8) >> 3) + 8];
do
{
v6 = CRCA_table[(unsigned __int8)(*a1 ^ v4)] ^ (v4 >> 8);
v7 = CRCA_table[(unsigned __int8)(a1[1] ^ v6)] ^ (v6 >> 8);
v8 = CRCA_table[(unsigned __int8)(a1[2] ^ v7)] ^ (v7 >> 8);
v9 = CRCA_table[(unsigned __int8)(a1[3] ^ v8)] ^ (v8 >> 8);
v10 = CRCA_table[(unsigned __int8)(a1[4] ^ v9)] ^ (v9 >> 8);
v11 = CRCA_table[(unsigned __int8)(a1[5] ^ v10)] ^ (v10 >> 8);
v12 = CRCA_table[(unsigned __int8)(a1[6] ^ v11)] ^ (v11 >> 8);
a1 += 8;
v4 = CRCA_table[(unsigned __int8)(*(a1 - 1) ^ v12)] ^ (v12 >> 8);
}
while ( a1 != v5 );
a2 &= 7u;
}
if ( a2 )
{
v13 = &a1[a2];
do
v4 = CRCA_table[(unsigned __int8)(*a1++ ^ v4)] ^ (v4 >> 8);
while ( v13 != a1 );
}
*a3 = v4;
break;
case 2:
*a3 = ~*a3;
break;
case 0:
*a3 = -1;
break;
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1, unsigned int a2, unsigned int *a3, int a4)
{
unsigned int v4; // eax
_BYTE *v5; // rcx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
_BYTE *v13; // rsi

switch ( a4 )
{
case 1:
v4 = *a3;
if ( a2 > 7 )
{
v5 = &a1[8 * ((a2 - 8) >> 3) + 8];
do
{
v6 = CRCA_table[(unsigned __int8)(*a1 ^ v4)] ^ (v4 >> 8);
v7 = CRCA_table[(unsigned __int8)(a1[1] ^ v6)] ^ (v6 >> 8);
v8 = CRCA_table[(unsigned __int8)(a1[2] ^ v7)] ^ (v7 >> 8);
v9 = CRCA_table[(unsigned __int8)(a1[3] ^ v8)] ^ (v8 >> 8);
v10 = CRCA_table[(unsigned __int8)(a1[4] ^ v9)] ^ (v9 >> 8);
v11 = CRCA_table[(unsigned __int8)(a1[5] ^ v10)] ^ (v10 >> 8);
v12 = CRCA_table[(unsigned __int8)(a1[6] ^ v11)] ^ (v11 >> 8);
a1 += 8;
v4 = CRCA_table[(unsigned __int8)(*(a1 - 1) ^ v12)] ^ (v12 >> 8);
}
while ( a1 != v5 );
a2 &= 7u;
}
if ( a2 )
{
v13 = &a1[a2];
do
v4 = CRCA_table[(unsigned __int8)(*a1++ ^ v4)] ^ (v4 >> 8);
while ( v13 != a1 );
}
*a3 = v4;
break;
case 2:
*a3 = ~*a3;
break;
case 0:
*a3 = -1;
break;
}
}

original_code:
void accum_CRCA(
 int8u * buf,
 int32u len,
 int32u * pcsum,
 int32u op)
{
 int32u csum;
 switch (op) {
 case 0:
  *pcsum = 0xffffffff;
  break;
 case 1:
  csum = *pcsum;
  while (len >= 8) {
   csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;;; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;;;;
   len -= 8;
  }
  if (len) {
   do {
    csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;
   } while (--len);
  }
  while (len--)
   csum = CRCA_table[(csum ^ *buf++) & 0xff] ^ (csum >> 8);
  *pcsum = csum;
  break;
 case 2:
  *pcsum ^= 0xffffffff;
  break;
 }
}

canonical_original_code:
void accum_CRCA(unsigned char *buf, unsigned int len, unsigned int *pcsum, unsigned int op)
{
 unsigned int csum;
 switch (op) {
 case 0:
  *pcsum = 0xffffffff;
  break;
 case 1:
  csum = *pcsum;
  while (len >= 8) {
   csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;;; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);; csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;;;;
   len -= 8;
  }
  if (len) {
   do {
    csum = CRCA_table[((int)csum ^ (*buf++)) & 0xff] ^ (csum >> 8);;
   } while (--len);
  }
  while (len--)
   csum = CRCA_table[(csum ^ *buf++) & 0xff] ^ (csum >> 8);
  *pcsum = csum;
  break;
 case 2:
  *pcsum ^= 0xffffffff;
  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


original_code:
int ulong_from_binary_string(
 char input[],
 unsigned long * poutput)
{
 unsigned long u = 0;
 char * p;
 for (p = input; *p; p++) {
  if (*p == '_')
   continue;
  else if (*p == '1') {
   u <<= 1;
   u++;
  }
  else if (*p == '0') {
   u <<= 1;
  }
  else {
   return 0;
  }
 }
 *poutput = u;
 return 1;
}

canonical_original_code:
int ulong_from_binary_string(char input[], unsigned long *poutput)
{
 unsigned long u = 0;
 char *p;
 for (p = input; *p; p++) {
  if (*p == '_')
   continue;
  else if (*p == '1') {
   u <<= 1;
   u++;
  }
  else if (*p == '0') {
   u <<= 1;
  }
  else {
   return 0;
  }
 }
 *poutput = u;
 return 1;
}

variable_types:
input
char []

variable_types:
poutput
unsigned long *

variable_types:
u
unsigned long

variable_types:
p
char *


decompiled_code:
__int64 __fastcall accum_floppy_CRC(_BYTE *a1, unsigned int a2, _BYTE *a3, _BYTE *a4, int a5)
{
__int64 result; // rax
_BYTE *v6; // r8
__int64 v7; // rax

result = a2;
if ( a5 )
{
if ( a5 == 1 )
{
v6 = &a1[a2];
if ( a2 )
{
do
{
v7 = (unsigned __int8)(*a3 ^ *a1++);
*a3 = *a4 ^ floppy_CRC_table_1[v7];
result = (unsigned __int8)floppy_CRC_table_2[v7];
*a4 = result;
}
while ( v6 != a1 );
}
}
}
else
{
*a3 = -107;
*a4 = -30;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned int a2, _BYTE *a3, _BYTE *a4, int a5)
{
__int64 result; // rax
_BYTE *v6; // r8
__int64 v7; // rax

result = a2;
if ( a5 )
{
if ( a5 == 1 )
{
v6 = &a1[a2];
if ( a2 )
{
do
{
v7 = (unsigned __int8)(*a3 ^ *a1++);
*a3 = *a4 ^ floppy_CRC_table_1[v7];
result = (unsigned __int8)floppy_CRC_table_2[v7];
*a4 = result;
}
while ( v6 != a1 );
}
}
}
else
{
*a3 = -107;
*a4 = -30;
}
return result;
}

original_code:
void accum_floppy_CRC(
 int8u * buf,
 int32u len,
 int8u * pcsumh,
 int8u * pcsuml,
 int32u op)
{
 int32u i;
 int8u c;
 switch (op) {
 case 0:
  *pcsumh = 0x95;
  *pcsuml = 0xe2;
  break;
 case 1:
  for (i = 0; i < len; i++) {
   c = (*buf++) ^ *pcsumh;
   *pcsumh = floppy_CRC_table_1[c] ^ *pcsuml;
   *pcsuml = floppy_CRC_table_2[c];
  }
  break;
 case 2:
  break;
 }
}

canonical_original_code:
void accum_floppy_CRC(unsigned char *buf, unsigned int len, unsigned char *pcsumh, unsigned char *pcsuml, unsigned int op)
{
 unsigned int i;
 unsigned char c;
 switch (op) {
 case 0:
  *pcsumh = 0x95;
  *pcsuml = 0xe2;
  break;
 case 1:
  for (i = 0; i < len; i++) {
   c = (*buf++) ^ *pcsumh;
   *pcsumh = floppy_CRC_table_1[c] ^ *pcsuml;
   *pcsuml = floppy_CRC_table_2[c];
  }
  break;
 case 2:
  break;
 }
}

variable_types:
pcsumh
unsigned char *

variable_types:
pcsuml
unsigned char *

variable_types:
i
unsigned int

variable_types:
c
unsigned char


decompiled_code:
void *__fastcall malloc_or_die(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* malloc_or_die(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 *malloc_or_die(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 *


decompiled_code:
void *__fastcall int_malloc_or_die(int a1)
{
return malloc_or_die(4 * a1);
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
return func0(4 * a1);
}

original_code:
int* int_malloc_or_die(int num_ints)
{
 return (int*)malloc_or_die(num_ints * sizeof(int));
}

canonical_original_code:
int *int_malloc_or_die(int num_ints)
{
 return (int *)malloc_or_die(num_ints * sizeof(int));
}

return_type: int *


decompiled_code:
void *__fastcall char_malloc_or_die(unsigned int a1)
{
return malloc_or_die(a1);
}

canonical_decompiled_code:
void *__fastcall func2(unsigned int a1)
{
return func0(a1);
}

original_code:
char* char_malloc_or_die(int num_chars)
{
 return (char*)malloc_or_die(num_chars * sizeof(char));
}

canonical_original_code:
char *char_malloc_or_die(int num_chars)
{
 return (char *)malloc_or_die(num_chars * sizeof(char));
}


decompiled_code:
void *__fastcall double_malloc_or_die(int a1)
{
return malloc_or_die(8 * a1);
}

canonical_decompiled_code:
void *__fastcall func3(int a1)
{
return func0(8 * a1);
}

original_code:
double* double_malloc_or_die(int num_doubles)
{
 return (double*)malloc_or_die(num_doubles * sizeof(double));
}

canonical_original_code:
double *double_malloc_or_die(int num_doubles)
{
 return (double *)malloc_or_die(num_doubles * sizeof(double));
}

return_type: double *


ipow

decompiled_code:
__int64 __fastcall ipow(int a1, int a2)
{
int v2; // eax
unsigned int v3; // edx

if ( a2 <= 0 )
return 1;
v2 = 0;
v3 = 1;
do
{
v3 *= a1;
++v2;
}
while ( a2 != v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
int v2; // eax
unsigned int v3; // edx

if ( a2 <= 0 )
return 1;
v2 = 0;
v3 = 1;
do
{
v3 *= a1;
++v2;
}
while ( a2 != v2 );
return v3;
}

original_code:
int ipow(int x, int n)
{
 int xn = 1;
 int i;
 for (i = 0; i < n; i++)
  xn *= x;
 return xn;
}

variable_types: x int

variable_types: n int

variable_types: xn int

variable_types: i int


decompiled_code:
int check_stop()
{
int result; // eax
const char *v1; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat("./__stop__", &v2);
if ( !result )
{
v1 = (const char *)get_sys_time_string();
printf("Exiting due to __stop__ file. Time: %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
const char *v1; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat("./__stop__", &v2);
if ( !result )
{
v1 = (const char *)get_sys_time_string();
printf("Exiting due to __stop__ file. Time: %s", v1);
exit(1);
}
return result;
}

original_code:
void check_stop(void)
{
 struct stat statbuf;
 if (stat("./__stop__", &statbuf) == 0) {
  printf("Exiting due to __stop__ file.  Time:  %s",
   get_sys_time_string());
  exit(1);
 }
}

canonical_original_code:
void check_stop()
{
 struct stat statbuf;
 if (stat("./__stop__", &statbuf) == 0) {
  printf("Exiting due to __stop__ file.  Time:  %s",
   get_sys_time_string());
  exit(1);
 }
}

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


decompiled_code:
void __fastcall vector_accumulate(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(double *)(a1 + 8 * i) = *(double *)(a1 + 8 * i) + *(double *)(a2 + 8 * i);
}
}

original_code:
void vector_accumulate(double * sum, double * v, int length)
{
 int i;
 for (i = 0; i < length; i++)
  sum[i] += v[i];
}

canonical_original_code:
void vector_accumulate(double *sum, double *v, int length)
{
 int i;
 for (i = 0; i < length; i++)
  sum[i] += v[i];
}

variable_types:
sum
double *

variable_types:
v
double *

variable_types: length int


decompiled_code:
void __fastcall vector_iaccumulate(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(double *)(a1 + 8 * i) = (double)*(int *)(a2 + 4 * i) + *(double *)(a1 + 8 * i);
}
}

original_code:
void vector_iaccumulate(double * sum, int * v, int length)
{
 int i;
 for (i = 0; i < length; i++)
  sum[i] += (double)v[i];
}

canonical_original_code:
void vector_iaccumulate(double *sum, int *v, int length)
{
 int i;
 for (i = 0; i < length; i++)
  sum[i] += (double)v[i];
}

variable_types:
v
int *


decompiled_code:
void __fastcall vector_scale(__int64 a1, __int64 a2, int a3, double a4)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(double *)(a1 + 8 * i) = a4 * *(double *)(a2 + 8 * i);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, int a3, double a4)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(double *)(a1 + 8 * i) = a4 * *(double *)(a2 + 8 * i);
}
}

original_code:
void vector_scale(double* v, double* u, double a, int length)
{
 int i;
 for (i = 0; i < length; i++)
  v[i] = a * u[i];
}

canonical_original_code:
void vector_scale(double *v, double *u, double a, int length)
{
 int i;
 for (i = 0; i < length; i++)
  v[i] = a * u[i];
}

variable_types:
u
double *

variable_types: a double


decompiled_code:
int __fastcall vector_row_printf(double *a1, int a2, const char *a3)
{
__int64 v4; // rbx

if ( a2 > 0 )
{
v4 = 1LL;
printf(a3, *a1);
while ( v4 != a2 )
{
if ( (int)v4 > 0 )
putchar(32);
printf(a3, a1[v4++]);
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(double *a1, int a2, const char *a3)
{
__int64 v4; // rbx

if ( a2 > 0 )
{
v4 = 1LL;
printf(a3, *a1);
while ( v4 != a2 )
{
if ( (int)v4 > 0 )
putchar(32);
printf(a3, a1[v4++]);
}
}
return putchar(10);
}

original_code:
void vector_row_printf(double* v, int length, char* format)
{
 int i;
 for (i = 0; i < length; i++) {
  if (i > 0)
   printf(" ");
  printf(format, v[i]);
 }
 printf("\n");
}

canonical_original_code:
void vector_row_printf(double *v, int length, char *format)
{
 int i;
 for (i = 0; i < length; i++) {
  if (i > 0)
   printf(" ");
  printf(format, v[i]);
 }
 printf("\n");
}

variable_types:
format
char *


decompiled_code:
int __fastcall vector_col_printf(double *a1, int a2, const char *a3)
{
double *v4; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = a1;
do
{
printf(a3, *v4);
result = putchar(10);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(double *a1, int a2, const char *a3)
{
double *v4; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = a1;
do
{
printf(a3, *v4);
result = putchar(10);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

original_code:
void vector_col_printf (double* v, int length, char* format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v[i]);
  printf("\n");
 }
}

canonical_original_code:
void vector_col_printf(double *v, int length, char *format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v[i]);
  printf("\n");
 }
}


decompiled_code:
int __fastcall vector_col2_printf(__int64 a1, __int64 a2, int a3, const char *a4)
{
__int64 v5; // r12
__int64 i; // rbx
int result; // eax

if ( a3 > 0 )
{
v5 = (unsigned int)a3;
for ( i = 0LL; i != v5; ++i )
{
printf(a4, *(double *)(a1 + 8 * i));
putchar(32);
printf(a4, *(double *)(a2 + 8 * i));
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2, int a3, const char *a4)
{
__int64 v5; // r12
__int64 i; // rbx
int result; // eax

if ( a3 > 0 )
{
v5 = (unsigned int)a3;
for ( i = 0LL; i != v5; ++i )
{
printf(a4, *(double *)(a1 + 8 * i));
putchar(32);
printf(a4, *(double *)(a2 + 8 * i));
result = putchar(10);
}
}
return result;
}

original_code:
void vector_col2_printf(double* v1, double* v2, int length, char* format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf("\n");
 }
}

canonical_original_code:
void vector_col2_printf(double *v1, double *v2, int length, char *format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf("\n");
 }
}


decompiled_code:
int __fastcall vector_col3_printf(__int64 a1, __int64 a2, __int64 a3, int a4, const char *a5)
{
__int64 v7; // r12
__int64 i; // rbx
int result; // eax

if ( a4 > 0 )
{
v7 = (unsigned int)a4;
for ( i = 0LL; i != v7; ++i )
{
printf(a5, *(double *)(a1 + 8 * i));
putchar(32);
printf(a5, *(double *)(a2 + 8 * i));
putchar(32);
printf(a5, *(double *)(a3 + 8 * i));
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2, __int64 a3, int a4, const char *a5)
{
__int64 v7; // r12
__int64 i; // rbx
int result; // eax

if ( a4 > 0 )
{
v7 = (unsigned int)a4;
for ( i = 0LL; i != v7; ++i )
{
printf(a5, *(double *)(a1 + 8 * i));
putchar(32);
printf(a5, *(double *)(a2 + 8 * i));
putchar(32);
printf(a5, *(double *)(a3 + 8 * i));
result = putchar(10);
}
}
return result;
}

original_code:
void vector_col3_printf(double* v1, double* v2, double* v3, int length,
 char* format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf("\n");
 }
}

canonical_original_code:
void vector_col3_printf(double *v1, double *v2, double *v3, int length, char *format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf("\n");
 }
}


decompiled_code:
int __fastcall vector_col4_printf(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, const char *a6)
{
__int64 i; // rbx
int result; // eax
__int64 v11; // [rsp+0h] [rbp-40h]

if ( a5 > 0 )
{
v11 = (unsigned int)a5;
for ( i = 0LL; i != v11; ++i )
{
printf(a6, *(double *)(a1 + 8 * i));
putchar(32);
printf(a6, *(double *)(a2 + 8 * i));
putchar(32);
printf(a6, *(double *)(a3 + 8 * i));
putchar(32);
printf(a6, *(double *)(a4 + 8 * i));
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, const char *a6)
{
__int64 i; // rbx
int result; // eax
__int64 v11; // [rsp+0h] [rbp-40h]

if ( a5 > 0 )
{
v11 = (unsigned int)a5;
for ( i = 0LL; i != v11; ++i )
{
printf(a6, *(double *)(a1 + 8 * i));
putchar(32);
printf(a6, *(double *)(a2 + 8 * i));
putchar(32);
printf(a6, *(double *)(a3 + 8 * i));
putchar(32);
printf(a6, *(double *)(a4 + 8 * i));
result = putchar(10);
}
}
return result;
}

original_code:
void vector_col4_printf(double* v1, double* v2, double* v3, double* v4,
 int length, char* format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf(" ");
  printf(format, v4[i]);
  printf("\n");
 }
}

canonical_original_code:
void vector_col4_printf(double *v1, double *v2, double *v3, double *v4, int length, char *format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf(" ");
  printf(format, v4[i]);
  printf("\n");
 }
}


decompiled_code:
int __fastcall vector_col5_printf(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6, char *format)
{
__int64 i; // rbx
int result; // eax
__int64 v12; // [rsp+8h] [rbp-40h]

if ( a6 > 0 )
{
v12 = (unsigned int)a6;
for ( i = 0LL; i != v12; ++i )
{
printf(format, *(double *)(a1 + 8 * i));
putchar(32);
printf(format, *(double *)(a2 + 8 * i));
putchar(32);
printf(format, *(double *)(a3 + 8 * i));
putchar(32);
printf(format, *(double *)(a4 + 8 * i));
putchar(32);
printf(format, *(double *)(a5 + 8 * i));
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6, char *format)
{
__int64 i; // rbx
int result; // eax
__int64 v12; // [rsp+8h] [rbp-40h]

if ( a6 > 0 )
{
v12 = (unsigned int)a6;
for ( i = 0LL; i != v12; ++i )
{
printf(format, *(double *)(a1 + 8 * i));
putchar(32);
printf(format, *(double *)(a2 + 8 * i));
putchar(32);
printf(format, *(double *)(a3 + 8 * i));
putchar(32);
printf(format, *(double *)(a4 + 8 * i));
putchar(32);
printf(format, *(double *)(a5 + 8 * i));
result = putchar(10);
}
}
return result;
}

original_code:
void vector_col5_printf(double* v1, double* v2, double* v3, double* v4, double* v5,
 int length, char* format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf(" ");
  printf(format, v4[i]);
  printf(" ");
  printf(format, v5[i]);
  printf("\n");
 }
}

canonical_original_code:
void vector_col5_printf(double *v1, double *v2, double *v3, double *v4, double *v5, int length, char *format)
{
 int i;
 for (i = 0; i < length; i++) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf(" ");
  printf(format, v4[i]);
  printf(" ");
  printf(format, v5[i]);
  printf("\n");
 }
}


decompiled_code:
int __fastcall vector_col5_printf_decimated(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6, char *format)
{
__int64 v10; // rbx
int v11; // er12
int result; // eax
int v13; // [rsp+0h] [rbp-58h]

if ( a6 <= 2000 )
{
if ( a6 <= 0 )
return result;
v13 = 1;
}
else
{
v13 = a6 / 2000;
}
v10 = 0LL;
v11 = 0;
do
{
printf(format, *(double *)(a1 + v10));
putchar(32);
printf(format, *(double *)(a2 + v10));
putchar(32);
printf(format, *(double *)(a3 + v10));
putchar(32);
printf(format, *(double *)(a4 + v10));
putchar(32);
printf(format, *(double *)(a5 + v10));
result = putchar(10);
v11 += v13;
v10 += 8LL * v13;
}
while ( a6 > v11 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6, char *format)
{
__int64 v10; // rbx
int v11; // er12
int result; // eax
int v13; // [rsp+0h] [rbp-58h]

if ( a6 <= 2000 )
{
if ( a6 <= 0 )
return result;
v13 = 1;
}
else
{
v13 = a6 / 2000;
}
v10 = 0LL;
v11 = 0;
do
{
printf(format, *(double *)(a1 + v10));
putchar(32);
printf(format, *(double *)(a2 + v10));
putchar(32);
printf(format, *(double *)(a3 + v10));
putchar(32);
printf(format, *(double *)(a4 + v10));
putchar(32);
printf(format, *(double *)(a5 + v10));
result = putchar(10);
v11 += v13;
v10 += 8LL * v13;
}
while ( a6 > v11 );
return result;
}

original_code:
void vector_col5_printf_decimated(
 double* v1, double* v2, double* v3, double* v4, double* v5,
 int length, char* format)
{
 int stride = 1;
 int i;
 const int maxlen = 2000;
 if (length > maxlen)
  stride = length / maxlen;
 for (i = 0; i < length; i += stride) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf(" ");
  printf(format, v4[i]);
  printf(" ");
  printf(format, v5[i]);
  printf("\n");
 }
}

canonical_original_code:
void vector_col5_printf_decimated(double *v1, double *v2, double *v3, double *v4, double *v5, int length, char *format)
{
 int stride = 1;
 int i;
 int maxlen = 2000;
 if (length > maxlen)
  stride = length / maxlen;
 for (i = 0; i < length; i += stride) {
  printf(format, v1[i]);
  printf(" ");
  printf(format, v2[i]);
  printf(" ");
  printf(format, v3[i]);
  printf(" ");
  printf(format, v4[i]);
  printf(" ");
  printf(format, v5[i]);
  printf("\n");
 }
}

variable_types: stride int

variable_types: maxlen int