decompiled_code:
_BOOL8 __fastcall sglib_hashed_ht_entry_t_delete_if_member(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int16 v4; // ax

v4 = ht_entry_hash_function((__int64)a2);
return sglib_ht_entry_t_delete_if_member((_QWORD **)(a1 + 8LL * (v4 & 0x1FF)), a2, a3);
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int16 v4; // ax

v4 = func0((__int64)a2);
return func6((_QWORD **)(a1 + 8LL * (v4 & 0x1FF)), a2, a3);
}

original_code: int sglib_hashed_ht_entry_t_delete_if_member(ht_entry_t *table[512], ht_entry_t *elem, ht_entry_t **memb) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_delete_if_member(&(table)[i], elem, memb)); }

canonical_original_code: int sglib_hashed_ht_entry_t_delete_if_member(struct ht_entry_s *table[512], struct ht_entry_s *elem, struct ht_entry_s **memb) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_delete_if_member(&(table)[i], elem, memb)); }

variable_types:
memb
struct ht_entry_s **


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_is_member(__int64 a1, __int64 a2)
{
__int16 v2; // ax

v2 = ht_entry_hash_function(a2);
return sglib_ht_entry_t_is_member(*(_QWORD *)(a1 + 8LL * (v2 & 0x1FF)), a2);
}

original_code: int sglib_hashed_ht_entry_t_is_member(ht_entry_t *table[512], ht_entry_t *elem) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_is_member((table)[i], elem)); }

canonical_original_code: int sglib_hashed_ht_entry_t_is_member(struct ht_entry_s *table[512], struct ht_entry_s *elem) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_is_member((table)[i], elem)); }

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *[512]

variable_types:
elem
struct ht_entry_s *

variable_types:
i
unsigned int

return_type: int


decompiled_code:
// attributes: thunk
__int64 __fastcall sglib_hashed_ht_entry_t_it_current(__int64 a1)
{
return sglib_ht_entry_t_it_current(a1);
}

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

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_current(struct sglib_hashed_ht_entry_t_iterator *it) { return(sglib_ht_entry_t_it_current(&it->containerIt)); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_current(struct sglib_hashed_ht_entry_t_iterator *it) { return(sglib_ht_entry_t_it_current(&it->containerIt)); }

variable_types: struct sglib_hashed_ht_entry_t_iterator { struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } containerIt; struct ht_entry_s **table; int currentIndex; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } *

return_type: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *

user_defined_types: struct sglib_hashed_ht_entry_t_iterator { struct sglib_ht_entry_t_iterator containerIt; struct ht_entry_s **table; int currentIndex; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_it_next(__int64 a1)
{
__int64 v1; // rbp
int v2; // eax
__int64 v3; // rax

v1 = sglib_ht_entry_t_it_next((_QWORD *)a1);
if ( !v1 )
{
while ( 1 )
{
v2 = *(_DWORD *)(a1 + 40) + 1;
*(_DWORD *)(a1 + 40) = v2;
if ( v2 > 511 )
break;
v3 = sglib_ht_entry_t_it_init_on_equal(
(_QWORD *)a1,
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * v2),
*(_QWORD *)(a1 + 48),
*(_QWORD *)(a1 + 56));
if ( v3 )
return v3;
}
}
return v1;
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_next(struct sglib_hashed_ht_entry_t_iterator *it) { ht_entry_t *e; e = sglib_ht_entry_t_it_next(&it->containerIt); while (e==((void *)0) && (++(it->currentIndex))<(512)) { e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, it->table[it->currentIndex], it->subcomparator, it->equalto); } return(e); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_next(struct sglib_hashed_ht_entry_t_iterator *it) { struct ht_entry_s *e; e = sglib_ht_entry_t_it_next(&it->containerIt); while (e==((void *)0) && (++(it->currentIndex))<(512)) { e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, it->table[it->currentIndex], it->subcomparator, it->equalto); } return(e); }

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *

user_defined_types: struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_it_init_on_equal(__int64 a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

*(_QWORD *)(a1 + 32) = a2;
*(_DWORD *)(a1 + 40) = 0;
*(_QWORD *)(a1 + 48) = a3;
*(_QWORD *)(a1 + 56) = a4;
result = sglib_ht_entry_t_it_init_on_equal((_QWORD *)a1, *a2, a3, a4);
if ( !result )
result = sglib_hashed_ht_entry_t_it_next(a1);
return result;
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_init_on_equal(struct sglib_hashed_ht_entry_t_iterator *it, ht_entry_t *table[512], int (*subcomparator)(ht_entry_t *, ht_entry_t *), ht_entry_t *equalto) { ht_entry_t *e; it->table = table; it->currentIndex = 0; it->subcomparator = subcomparator; it->equalto = equalto; e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, table[it->currentIndex], it->subcomparator, it->equalto); if (e==((void *)0)) e = sglib_hashed_ht_entry_t_it_next(it); return(e); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_init_on_equal(struct sglib_hashed_ht_entry_t_iterator *it, struct ht_entry_s *table[512], int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *), struct ht_entry_s *equalto) { struct ht_entry_s *e; it->table = table; it->currentIndex = 0; it->subcomparator = subcomparator; it->equalto = equalto; e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, table[it->currentIndex], it->subcomparator, it->equalto); if (e==((void *)0)) e = sglib_hashed_ht_entry_t_it_next(it); return(e); }

variable_types:
table
struct ht_entry_s *[512]

variable_types: int (*)(struct ht_entry_s *, struct ht_entry_s *)

variable_types:
equalto
struct ht_entry_s *

user_defined_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; }


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_it_init(__int64 a1, __int64 *a2)
{
return sglib_hashed_ht_entry_t_it_init_on_equal(a1, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 *a2)
{
return func21(a1, a2, 0LL, 0LL);
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_init(struct sglib_hashed_ht_entry_t_iterator *it, ht_entry_t *table[512]) { return(sglib_hashed_ht_entry_t_it_init_on_equal(it, table, ((void *)0), ((void *)0))); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_init(struct sglib_hashed_ht_entry_t_iterator *it, struct ht_entry_s *table[512]) { return(sglib_hashed_ht_entry_t_it_init_on_equal(it, table, ((void *)0), ((void *)0))); }


decompiled_code:
__int64 __fastcall delete_ht(__int64 *a1)
{
__int64 result; // rax
void *i; // rdi
_BYTE v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = sglib_hashed_ht_entry_t_it_init((__int64)v3, a1);
for ( i = (void *)result; result; i = (void *)result )
{
free(i);
result = sglib_hashed_ht_entry_t_it_next((__int64)v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 *a1)
{
__int64 result; // rax
void *i; // rdi
_BYTE v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = func22((__int64)v3, a1);
for ( i = (void *)result; result; i = (void *)result )
{
free(i);
result = func20((__int64)v3);
}
return result;
}

original_code:
void delete_ht (ht_entry_t **ht) {
    ht_entry_t *i;
    struct sglib_hashed_ht_entry_t_iterator it;
    for (i = sglib_hashed_ht_entry_t_it_init(&it, ht); i != ((void *)0);
         i = sglib_hashed_ht_entry_t_it_next(&it)) {
        free(i);
    }
}

canonical_original_code:
void delete_ht(struct ht_entry_s **ht) {
    struct ht_entry_s *i;
    struct sglib_hashed_ht_entry_t_iterator it;
    for (i = sglib_hashed_ht_entry_t_it_init(&it, ht); i != ((void *)0);
         i = sglib_hashed_ht_entry_t_it_next(&it)) {
        free(i);
    }
}

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } **

variable_types: struct sglib_hashed_ht_entry_t_iterator { struct sglib_ht_entry_t_iterator { struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } containerIt; struct ht_entry_s **table; int currentIndex; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }

return_type: void


decompiled_code:
int __fastcall parse_options(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "t:f:");
if ( result == -1 )
break;
if ( result == 102 )
{
*((_DWORD *)&env + 2) = 0;
}
else
{
if ( result != 116 )
{
fprintf(stderr, "Usage: %s [-t trace file] [-f trace format]\n", *argv);
exit(1);
}
env = optarg;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "t:f:");
if ( result == -1 )
break;
if ( result == 102 )
{
*((_DWORD *)&env + 2) = 0;
}
else
{
if ( result != 116 )
{
fprintf(stderr, "Usage: %s [-t trace file] [-f trace format]\n", *argv);
exit(1);
}
env = optarg;
}
}
return result;
}

original_code:
void parse_options (int argc, const char *argv[]) {
  int opt;
  while ((opt = getopt(argc, argv, "t:f:")) != -1) {
    switch (opt) {
      case 't':
        env.file_name = optarg;
        break;
      case 'f':
        env.trace_format = SEAGATE;
        break;
      default:
        fprintf (stderr, "Usage: %s [-t trace file] [-f trace format]\n",
                 argv[0]);
        exit(1);
    }
  }
}

canonical_original_code:
void parse_options(int argc, char *argv[]) {
  int opt;
  while ((opt = getopt(argc, argv, "t:f:")) != -1) {
    switch (opt) {
      case 't':
        env.file_name = optarg;
        break;
      case 'f':
        env.trace_format = SEAGATE;
        break;
      default:
        fprintf (stderr, "Usage: %s [-t trace file] [-f trace format]\n",
                 argv[0]);
        exit(1);
    }
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int


repo: parzio/crypto-secure-communication

original_code:
void MAJ5_init(MAJ5 *maj5){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 maj5->reg[0] = temp;
 LFSR_init(&maj5->reg[0] , MAJ5_reg1 , MAJ5_poly1 , MAJ5_degree[0]);
 maj5->reg[1] = temp;
 LFSR_init(&maj5->reg[1] , MAJ5_reg2 , MAJ5_poly2 , MAJ5_degree[1]);
 maj5->reg[2] = temp;
 LFSR_init(&maj5->reg[2] , MAJ5_reg3 , MAJ5_poly3 , MAJ5_degree[2]);
 maj5->reg[3] = temp;
 LFSR_init(&maj5->reg[3] , MAJ5_reg4 , MAJ5_poly4 , MAJ5_degree[3]);
 maj5->reg[4] = temp;
 LFSR_init(&maj5->reg[4] , MAJ5_reg5 , MAJ5_poly5 , MAJ5_degree[4]);
}

canonical_original_code:
void MAJ5_init(struct MAJ5 *maj5){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 maj5->reg[0] = temp;
 LFSR_init(&maj5->reg[0] , MAJ5_reg1 , MAJ5_poly1 , MAJ5_degree[0]);
 maj5->reg[1] = temp;
 LFSR_init(&maj5->reg[1] , MAJ5_reg2 , MAJ5_poly2 , MAJ5_degree[1]);
 maj5->reg[2] = temp;
 LFSR_init(&maj5->reg[2] , MAJ5_reg3 , MAJ5_poly3 , MAJ5_degree[2]);
 maj5->reg[3] = temp;
 LFSR_init(&maj5->reg[3] , MAJ5_reg4 , MAJ5_poly4 , MAJ5_degree[3]);
 maj5->reg[4] = temp;
 LFSR_init(&maj5->reg[4] , MAJ5_reg5 , MAJ5_poly5 , MAJ5_degree[4]);
}

variable_types: struct MAJ5 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } *


decompiled_code:
__int64 __fastcall MAJ5_delete(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = LFSR_delete(v1);
v1 += 24LL;
}
while ( v1 != a1 + 120 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = LFSR_delete(v1);
v1 += 24LL;
}
while ( v1 != a1 + 120 );
return result;
}

original_code:
void MAJ5_delete(MAJ5 *maj5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&maj5->reg[i]);
}

canonical_original_code:
void MAJ5_delete(struct MAJ5 *maj5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&maj5->reg[i]);
}

variable_types: i int

user_defined_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; }


decompiled_code:
__int64 __fastcall MAJ5_update(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rbp
int v4; // er13
__int64 v5; // r12
unsigned int v6; // ebp
__int64 v7; // r12

v1 = a1;
v2 = a1;
v3 = 0LL;
v4 = 0;
do
{
v4 += (unsigned __int8)LFSR_getBit(v2, (unsigned int)MAJ5_clock[v3++]) == 0;
v2 += 24LL;
}
while ( v3 != 5 );
if ( v4 <= 2 )
{
v7 = 0LL;
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v1, (unsigned int)MAJ5_clock[v7]) == 1 )
v6 ^= LFSR_update(v1);
else
v6 ^= LFSR_getBit(v1, (unsigned int)(*(_DWORD *)(v1 + 16) - 1));
++v7;
v1 += 24LL;
}
while ( v7 != 5 );
}
else
{
v5 = 0LL;
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v1, (unsigned int)MAJ5_clock[v5]) )
v6 ^= LFSR_getBit(v1, (unsigned int)(*(_DWORD *)(v1 + 16) - 1));
else
v6 ^= LFSR_update(v1);
++v5;
v1 += 24LL;
}
while ( v5 != 5 );
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rbp
int v4; // er13
__int64 v5; // r12
unsigned int v6; // ebp
__int64 v7; // r12

v1 = a1;
v2 = a1;
v3 = 0LL;
v4 = 0;
do
{
v4 += (unsigned __int8)LFSR_getBit(v2, (unsigned int)MAJ5_clock[v3++]) == 0;
v2 += 24LL;
}
while ( v3 != 5 );
if ( v4 <= 2 )
{
v7 = 0LL;
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v1, (unsigned int)MAJ5_clock[v7]) == 1 )
v6 ^= LFSR_update(v1);
else
v6 ^= LFSR_getBit(v1, (unsigned int)(*(_DWORD *)(v1 + 16) - 1));
++v7;
v1 += 24LL;
}
while ( v7 != 5 );
}
else
{
v5 = 0LL;
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v1, (unsigned int)MAJ5_clock[v5]) )
v6 ^= LFSR_getBit(v1, (unsigned int)(*(_DWORD *)(v1 + 16) - 1));
else
v6 ^= LFSR_update(v1);
++v5;
v1 += 24LL;
}
while ( v5 != 5 );
}
return v6;
}

original_code:
bit MAJ5_update(MAJ5 *maj5){
 int count_zero = 0;
 int i;
 bit output = 0;
 bit temp = 0;
 for(i = 0; i < 5; i++)
 {
  temp = LFSR_getBit(&maj5->reg[i] , MAJ5_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 3)
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 0)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 1)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 return output;
}

canonical_original_code:
unsigned int MAJ5_update(struct MAJ5 *maj5){
 int count_zero = 0;
 int i;
 unsigned int output = 0;
 unsigned int temp = 0;
 for(i = 0; i < 5; i++)
 {
  temp = LFSR_getBit(&maj5->reg[i] , MAJ5_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 3)
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 0)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 1)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 return output;
}

variable_types:
output
unsigned int

variable_types:
temp
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall MAJ5_warmUpStream(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = MAJ5_update(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = func2(a1);
}
return result;
}

original_code:
void MAJ5_warmUpStream(MAJ5 *maj5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  MAJ5_update(maj5);
}

canonical_original_code:
void MAJ5_warmUpStream(struct MAJ5 *maj5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  MAJ5_update(maj5);
}

variable_types:
stream
unsigned int


decompiled_code:
void __fastcall MAJ5_getStream(__int64 a1, _BYTE *a2, int a3)
{
_BYTE *v3; // rbx
__int64 v4; // r12

if ( a3 )
{
v3 = a2;
v4 = (__int64)&a2[a3 - 1 + 1];
do
*v3++ = MAJ5_update(a1);
while ( v3 != (_BYTE *)v4 );
}
}

original_code:
void MAJ5_getStream(MAJ5 *maj5, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = MAJ5_update(maj5);
}

canonical_original_code:
void MAJ5_getStream(struct MAJ5 *maj5, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = MAJ5_update(maj5);
}

variable_types:
result
unsigned int *


decompiled_code:
__int64 __fastcall MAJ5_encrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
MAJ5_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a2 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a3 + i) = v7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a2 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a3 + i) = v7;
}
}
return result;
}

original_code:
void MAJ5_encrypt(MAJ5 *maj5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  byte currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

canonical_original_code:
void MAJ5_encrypt(struct MAJ5 *maj5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  unsigned int currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types:
length
unsigned int

variable_types: j int

variable_types:
temp
unsigned int [8]

variable_types:
currentByte
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall MAJ5_decrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
MAJ5_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a3 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a2 + i) = v7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a3 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a2 + i) = v7;
}
}
return result;
}

original_code:
void MAJ5_decrypt(MAJ5 *maj5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  byte currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

canonical_original_code:
void MAJ5_decrypt(struct MAJ5 *maj5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  unsigned int currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}


getChunk

decompiled_code:
__int64 __fastcall getChunk(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(v5 + result) = *(_BYTE *)(a1 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(v5 + result) = *(_BYTE *)(a1 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

original_code:
void getChunk(bit block[24], bit chunk[6], unsigned int index){
 int j, z = 0 , end = (6 * index + 6) , start = index * 6;
 for(j = start; j < end ; j++)
 {
  chunk[z] = block[j];
  z++;
 }
}

canonical_original_code:
void getChunk(unsigned int block[24], unsigned int chunk[6], unsigned int index){
 int j; int z = 0; int end = (6 * index + 6); int start = index * 6;
 for(j = start; j < end ; j++)
 {
  chunk[z] = block[j];
  z++;
 }
}

variable_types:
block
unsigned int [24]

variable_types:
chunk
unsigned int [6]

variable_types:
index
unsigned int

variable_types: z int

variable_types: end int

variable_types: start int


setChunk

decompiled_code:
__int64 __fastcall setChunk(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(a1 + result) = *(_BYTE *)(v5 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(a1 + result) = *(_BYTE *)(v5 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

original_code:
void setChunk(bit block[24], bit chunk[6], unsigned int index){
 int j, z = 0 , end = (6 * index + 6) , start = index * 6;
 for(j = start; j < end ; j++)
 {
  block[j] = chunk[z];
  z++;
 }
}

canonical_original_code:
void setChunk(unsigned int block[24], unsigned int chunk[6], unsigned int index){
 int j; int z = 0; int end = (6 * index + 6); int start = index * 6;
 for(j = start; j < end ; j++)
 {
  block[j] = chunk[z];
  z++;
 }
}


mixingLayer

decompiled_code:
__int64 __fastcall mixingLayer(__int64 a1)
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
mixingLayerMatrixMul(a1, &v4[6 * i], i);
for ( j = 0LL; j != 4; ++j )
result = setChunk(a1, (__int64)&v4[6 * j], j);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
func2(a1, &v4[6 * i], i);
for ( j = 0LL; j != 4; ++j )
result = func3(a1, (__int64)&v4[6 * j], j);
return result;
}

original_code:
void mixingLayer(bit block[24]){
 int i;
 bit chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}

canonical_original_code:
void mixingLayer(unsigned int block[24]){
 int i;
 unsigned int chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}

variable_types: i int


decompiled_code:
__int64 __fastcall inverse_mixingLayer(__int64 a1)
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
inverse_mixingLayerMatrixMul(a1, &v4[6 * i], i);
for ( j = 0LL; j != 4; ++j )
result = setChunk(a1, (__int64)&v4[6 * j], j);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
func1(a1, &v4[6 * i], i);
for ( j = 0LL; j != 4; ++j )
result = func3(a1, (__int64)&v4[6 * j], j);
return result;
}

original_code:
void inverse_mixingLayer(bit block[24]){
 int i;
 bit chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  inverse_mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}

canonical_original_code:
void inverse_mixingLayer(unsigned int block[24]){
 int i;
 unsigned int chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  inverse_mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}


blockInversion

decompiled_code:
__int64 __fastcall blockInversion(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
getChunk(a1, (__int64)v3, i);
inverteArray(v3, 6LL);
result = setChunk(a1, (__int64)v3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
func0(a1, (__int64)v3, i);
inverteArray(v3, 6LL);
result = func3(a1, (__int64)v3, i);
}
return result;
}

original_code:
void blockInversion(bit block[24]){
 int i;
 bit chunk[6];
 for(i = 0; i < 4; i++)
 {
  getChunk(block , chunk , i);
  inverteArray(chunk , 6);
  setChunk(block , chunk , i);
 }
}

canonical_original_code:
void blockInversion(unsigned int block[24]){
 int i;
 unsigned int chunk[6];
 for(i = 0; i < 4; i++)
 {
  getChunk(block , chunk , i);
  inverteArray(chunk , 6);
  setChunk(block , chunk , i);
 }
}


sbox

decompiled_code:
__int64 __fastcall sbox(__int64 a1, int a2)
{
__int64 i; // rax
int v3; // ebp
int v4; // ebp
__int64 result; // rax
int v6; // ebp
int v7; // ebp
char v8[2]; // [rsp+Ah] [rbp-1Eh] BYREF
char v9; // [rsp+Ch] [rbp-1Ch]

for ( i = 0LL; i != 6; ++i )
v8[i] = *(_BYTE *)(a1 + i);
if ( a2 == 2 )
{
v7 = 16;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v7;
}
while ( v7 );
}
else if ( a2 > 2 )
{
v4 = 61;
if ( a2 != 3 )
goto LABEL_22;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v4;
}
while ( v4 );
v9 ^= 1u;
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v3 = 4;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v3;
}
while ( v3 );
goto LABEL_13;
}
LABEL_22:
puts("sbox index error ");
goto LABEL_13;
}
v6 = 61;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v6;
}
while ( v6 );
}
LABEL_13:
for ( result = 0LL; result != 6; ++result )
*(_BYTE *)(a1 + result) = v8[result];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 i; // rax
int v3; // ebp
int v4; // ebp
__int64 result; // rax
int v6; // ebp
int v7; // ebp
char v8[2]; // [rsp+Ah] [rbp-1Eh] BYREF
char v9; // [rsp+Ch] [rbp-1Ch]

for ( i = 0LL; i != 6; ++i )
v8[i] = *(_BYTE *)(a1 + i);
if ( a2 == 2 )
{
v7 = 16;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v7;
}
while ( v7 );
}
else if ( a2 > 2 )
{
v4 = 61;
if ( a2 != 3 )
goto LABEL_22;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v4;
}
while ( v4 );
v9 ^= 1u;
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v3 = 4;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v3;
}
while ( v3 );
goto LABEL_13;
}
LABEL_22:
puts("sbox index error ");
goto LABEL_13;
}
v6 = 61;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v6;
}
while ( v6 );
}
LABEL_13:
for ( result = 0LL; result != 6; ++result )
*(_BYTE *)(a1 + result) = v8[result];
return result;
}

original_code:
void sbox(bit chunk[6] , int index){
 int i;
 bit result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   for( i = 1; i < sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   result[2] ^= 1;
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}

canonical_original_code:
void sbox(unsigned int chunk[6], int index){
 int i;
 unsigned int result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   for( i = 1; i < sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   result[2] ^= 1;
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}

variable_types: index int

variable_types:
result
unsigned int [6]


keySchedule

original_code:
void keySchedule(bit key[24] , bit schedule[16][24]){
 bit word[88][6];
 int i , j , r;
 for(i = 0; i < 4; i++){
  getChunk(key, word[i], i);
  for(j = 0; j < 6; j++)
   word[i + 4][j] = word[i][j];
 }
 for(i = 4; i < 8; i++)
 {
  sbox(word[i], i - 4);
  if(i < 7)
   arraySum(word[i - 3] , word[i] , word[i] , 6);
  else
   arraySum(word[0] , word[i] , word[i] , 6);
 }
 for(j = 9; j <= 88; j++)
 {
  i = j-1;
  if((j % 8) == 1)
   {
   bit buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   rotate(buffer, -1 , 6);
   sbox(buffer , 1);
   arraySum(buffer , word[i - 8], word[i], 6);
   arraySum(word[i], keyScheduleArray , word[i], 6);
   }
  else if((j % 8) == 5)
   {
   bit buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   sbox(buffer , 2);
   arraySum(word[i - 8] , buffer , word[i] , 6);
   }
  else if((j % 4) != 1)
   arraySum(word[i - 8] , word[i - 1] , word[i] , 6);
 }
 for(r = 0; r < 3; r++)
 {
  for(j = 0; j < 5; j++)
  {
   int z = (8 + 20*r) + j;
   int index = (r*5)+j;
   for(i = 0; i < 4; i++)
   {
    setChunk(schedule[index] , word[z] , i);
    z += 5;
   }
  }
 }
 int z = 68;
 for(i = 0; i < 4; i++)
 {
  setChunk(schedule[15] , word[z] , i);
  z += 5;
 }
}

canonical_original_code:
void keySchedule(unsigned int key[24], unsigned int schedule[16][24]){
 unsigned int word[88][6];
 int i; int j; int r;
 for(i = 0; i < 4; i++){
  getChunk(key, word[i], i);
  for(j = 0; j < 6; j++)
   word[i + 4][j] = word[i][j];
 }
 for(i = 4; i < 8; i++)
 {
  sbox(word[i], i - 4);
  if(i < 7)
   arraySum(word[i - 3] , word[i] , word[i] , 6);
  else
   arraySum(word[0] , word[i] , word[i] , 6);
 }
 for(j = 9; j <= 88; j++)
 {
  i = j-1;
  if((j % 8) == 1)
   {
   unsigned int buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   rotate(buffer, -1 , 6);
   sbox(buffer , 1);
   arraySum(buffer , word[i - 8], word[i], 6);
   arraySum(word[i], keyScheduleArray , word[i], 6);
   }
  else if((j % 8) == 5)
   {
   unsigned int buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   sbox(buffer , 2);
   arraySum(word[i - 8] , buffer , word[i] , 6);
   }
  else if((j % 4) != 1)
   arraySum(word[i - 8] , word[i - 1] , word[i] , 6);
 }
 for(r = 0; r < 3; r++)
 {
  for(j = 0; j < 5; j++)
  {
   int z = (8 + 20*r) + j;
   int index = (r*5)+j;
   for(i = 0; i < 4; i++)
   {
    setChunk(schedule[index] , word[z] , i);
    z += 5;
   }
  }
 }
 int z = 68;
 for(i = 0; i < 4; i++)
 {
  setChunk(schedule[15] , word[z] , i);
  z += 5;
 }
}

variable_types:
key
unsigned int [24]

variable_types:
schedule
unsigned int [16][24]

variable_types:
word
unsigned int [88][6]

variable_types: r int

variable_types:
buffer
unsigned int [6]


sboxLayer

decompiled_code:
__int64 __fastcall sboxLayer(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
getChunk(a1, (__int64)v3, i);
sbox((__int64)v3, i);
result = setChunk(a1, (__int64)v3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
func0(a1, (__int64)v3, i);
func7((__int64)v3, i);
result = func3(a1, (__int64)v3, i);
}
return result;
}

original_code:
void sboxLayer(bit block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  bit chunk[6];
  getChunk(block , chunk , i);
  sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}

canonical_original_code:
void sboxLayer(unsigned int block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  unsigned int chunk[6];
  getChunk(block , chunk , i);
  sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}


round

decompiled_code:
__int64 __fastcall round(__int64 a1, __int64 a2)
{
sboxLayer(a1);
mixingLayer(a1);
return arraySum(a1, a2, a1, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
func9(a1);
func4(a1);
return arraySum(a1, a2, a1, 24LL);
}

original_code:
void round(bit block[24], bit key[24]){
 sboxLayer(block);
 mixingLayer(block);
 arraySum(block , key , block , 24);
}

canonical_original_code:
void round(unsigned int block[24], unsigned int key[24]){
 sboxLayer(block);
 mixingLayer(block);
 arraySum(block , key , block , 24);
}


decompiled_code:
__int64 __fastcall bunny24_encrypt(__int64 a1, __int64 a2)
{
_BYTE v3[24]; // [rsp+0h] [rbp-188h] BYREF
char v4[24]; // [rsp+18h] [rbp-170h] BYREF
char v5[24]; // [rsp+30h] [rbp-158h] BYREF
char v6[320]; // [rsp+48h] [rbp-140h] BYREF

keySchedule(a2, (__int64)v3);
arraySum(a1, v3, a1, 24LL);
round(a1, (__int64)v4);
round(a1, (__int64)v5);
return round(a1, (__int64)v6);
}

original_code:
void bunny24_encrypt(bit block[24] , bit key[24]){
 bit keys[16][24];
 keySchedule(key , keys);
 int i;
 arraySum(block , keys[0] , block , 24);
 for(i = 1; i <= 3; i++)
  round(block , keys[i]);
}

canonical_original_code:
void bunny24_encrypt(unsigned int block[24], unsigned int key[24]){
 unsigned int keys[16][24];
 keySchedule(key , keys);
 int i;
 arraySum(block , keys[0] , block , 24);
 for(i = 1; i <= 3; i++)
  round(block , keys[i]);
}

variable_types:
keys
unsigned int [16][24]


decompiled_code:
__int64 __fastcall inverse_sbox(__int64 a1, int a2)
{
__int64 i; // rax
int v3; // ebp
int v4; // ebp
int v5; // ebp
int v6; // ebp
__int64 result; // rax
char v8[2]; // [rsp+Ah] [rbp-1Eh] BYREF
char v9; // [rsp+Ch] [rbp-1Ch]

for ( i = 0LL; i != 6; ++i )
v8[i] = *(_BYTE *)(a1 + i);
if ( a2 == 2 )
{
v6 = 25;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v6;
}
while ( v6 );
}
else if ( a2 > 2 )
{
if ( a2 != 3 )
goto LABEL_20;
v9 ^= 1u;
*(_BYTE *)(a1 + 2) ^= 1u;
v4 = 61;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v4;
}
while ( v4 );
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v3 = 37;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v3;
}
while ( v3 );
goto LABEL_21;
}
LABEL_20:
puts("sbox index error ");
goto LABEL_21;
}
v5 = 61;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v5;
}
while ( v5 );
}
LABEL_21:
for ( result = 0LL; result != 6; ++result )
*(_BYTE *)(a1 + result) = v8[result];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 i; // rax
int v3; // ebp
int v4; // ebp
int v5; // ebp
int v6; // ebp
__int64 result; // rax
char v8[2]; // [rsp+Ah] [rbp-1Eh] BYREF
char v9; // [rsp+Ch] [rbp-1Ch]

for ( i = 0LL; i != 6; ++i )
v8[i] = *(_BYTE *)(a1 + i);
if ( a2 == 2 )
{
v6 = 25;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v6;
}
while ( v6 );
}
else if ( a2 > 2 )
{
if ( a2 != 3 )
goto LABEL_20;
v9 ^= 1u;
*(_BYTE *)(a1 + 2) ^= 1u;
v4 = 61;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v4;
}
while ( v4 );
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v3 = 37;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v3;
}
while ( v3 );
goto LABEL_21;
}
LABEL_20:
puts("sbox index error ");
goto LABEL_21;
}
v5 = 61;
do
{
arrayMul(v8, a1, &primitivePoly, v8, 6LL);
--v5;
}
while ( v5 );
}
LABEL_21:
for ( result = 0LL; result != 6; ++result )
*(_BYTE *)(a1 + result) = v8[result];
return result;
}

original_code:
void inverse_sbox(bit chunk[6] , int index){
 int i;
 bit result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < inverse_sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < inverse_sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < inverse_sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   result[2] ^= 1;
   chunk[2] ^= 1;
   for(i = 1; i < inverse_sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}

canonical_original_code:
void inverse_sbox(unsigned int chunk[6], int index){
 int i;
 unsigned int result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < inverse_sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < inverse_sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < inverse_sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   result[2] ^= 1;
   chunk[2] ^= 1;
   for(i = 1; i < inverse_sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}


decompiled_code:
__int64 __fastcall inverse_sboxLayer(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
getChunk(a1, (__int64)v3, i);
inverse_sbox((__int64)v3, i);
result = setChunk(a1, (__int64)v3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
func0(a1, (__int64)v3, i);
func12((__int64)v3, i);
result = func3(a1, (__int64)v3, i);
}
return result;
}

original_code:
void inverse_sboxLayer(bit block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  bit chunk[6];
  getChunk(block , chunk , i);
  inverse_sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}

canonical_original_code:
void inverse_sboxLayer(unsigned int block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  unsigned int chunk[6];
  getChunk(block , chunk , i);
  inverse_sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}


decompiled_code:
__int64 __fastcall inverse_round(__int64 a1, __int64 a2)
{
arraySum(a1, a2, a1, 24LL);
inverse_mixingLayer(a1);
return inverse_sboxLayer(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
arraySum(a1, a2, a1, 24LL);
func5(a1);
return func13(a1);
}

original_code:
void inverse_round(bit block[24], bit key[24]){
 arraySum(block , key , block , 24);
 inverse_mixingLayer(block);
 inverse_sboxLayer(block);
}

canonical_original_code:
void inverse_round(unsigned int block[24], unsigned int key[24]){
 arraySum(block , key , block , 24);
 inverse_mixingLayer(block);
 inverse_sboxLayer(block);
}


decompiled_code:
__int64 __fastcall bunny24_decrypt(__int64 a1, __int64 a2)
{
_BYTE v3[24]; // [rsp+0h] [rbp-188h] BYREF
char v4[24]; // [rsp+18h] [rbp-170h] BYREF
char v5[24]; // [rsp+30h] [rbp-158h] BYREF
char v6[320]; // [rsp+48h] [rbp-140h] BYREF

keySchedule(a2, (__int64)v3);
inverse_round(a1, (__int64)v6);
inverse_round(a1, (__int64)v5);
inverse_round(a1, (__int64)v4);
return arraySum(a1, v3, a1, 24LL);
}

original_code:
void bunny24_decrypt(bit block[24] , bit key[24]){
 bit keys[16][24];
 keySchedule(key , keys);
 int i;
 for(i = 3; i > 0; i--)
  inverse_round(block , keys[i]);
 arraySum(block , keys[0] , block , 24);
}

canonical_original_code:
void bunny24_decrypt(unsigned int block[24], unsigned int key[24]){
 unsigned int keys[16][24];
 keySchedule(key , keys);
 int i;
 for(i = 3; i > 0; i--)
  inverse_round(block , keys[i]);
 arraySum(block , keys[0] , block , 24);
}


decompiled_code:
__int64 __fastcall bunny24_bruteForce(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 i; // rcx
__int64 result; // rax
_BYTE v5[32]; // [rsp+0h] [rbp-58h] BYREF
char v6[56]; // [rsp+20h] [rbp-38h] BYREF

v2 = 0;
while ( 1 )
{
arrayCopy(a1, v5, 24LL);
for ( i = 0LL; i != 24; ++i )
v6[i] = (v2 & (1 << i)) != 0;
bunny24_encrypt((__int64)v5, (__int64)v6);
result = arrayEqual(v5, a2, 24LL);
if ( !(_DWORD)result )
break;
if ( ++v2 == 0x1000000 )
return result;
}
return printHex(v6, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 i; // rcx
__int64 result; // rax
_BYTE v5[32]; // [rsp+0h] [rbp-58h] BYREF
char v6[56]; // [rsp+20h] [rbp-38h] BYREF

v2 = 0;
while ( 1 )
{
arrayCopy(a1, v5, 24LL);
for ( i = 0LL; i != 24; ++i )
v6[i] = (v2 & (1 << i)) != 0;
func11((__int64)v5, (__int64)v6);
result = arrayEqual(v5, a2, 24LL);
if ( !(_DWORD)result )
break;
if ( ++v2 == 0x1000000 )
return result;
}
return printHex(v6, 24LL);
}

original_code:
void bunny24_bruteForce(bit plain[24] , bit crypt[24]){
 unsigned int i, end = 1024 * 1024 * 16;
 bit test[24];
 bit testp[24];
 for(i = 0; i < end; i++)
 {
  arrayCopy(plain , testp , 24);
  int j;
  for(j = 0; j < 24; j++)
  {
   if(i & (1 << j))
    test[j] = 1;
   else
    test[j] = 0;
  }
  bunny24_encrypt(testp , test);
  if(arrayEqual(testp , crypt , 24) == 0)
  {
   printHex(test , 24);
   return;
  }
 }
}

canonical_original_code:
void bunny24_bruteForce(unsigned int plain[24], unsigned int crypt[24]){
 unsigned int i; unsigned int end = 1024 * 1024 * 16;
 unsigned int test[24];
 unsigned int testp[24];
 for(i = 0; i < end; i++)
 {
  arrayCopy(plain , testp , 24);
  int j;
  for(j = 0; j < 24; j++)
  {
   if(i & (1 << j))
    test[j] = 1;
   else
    test[j] = 0;
  }
  bunny24_encrypt(testp , test);
  if(arrayEqual(testp , crypt , 24) == 0)
  {
   printHex(test , 24);
   return;
  }
 }
}

variable_types:
plain
unsigned int [24]

variable_types:
crypt
unsigned int [24]

variable_types:
i
unsigned int

variable_types:
end
unsigned int

variable_types:
test
unsigned int [24]

variable_types:
testp
unsigned int [24]

variable_types: j int


isZero

original_code:
int isZero(bit * reg , int length){
 int x = 0;
 int j = 0;
 for(x = 0; x < length; x++)
  if(reg[x] == 0)
   j++;
 if(j == length)
  return 0;
 else
  return 1;
}

canonical_original_code:
int isZero(unsigned int *reg, int length){
 int x = 0;
 int j = 0;
 for(x = 0; x < length; x++)
  if(reg[x] == 0)
   j++;
 if(j == length)
  return 0;
 else
  return 1;
}

variable_types:
reg
unsigned int *

variable_types: length int

variable_types: x int


original_code:
void TOY_init(TOY *toy){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 bit TOY_reg1[TOY_degree[0]];
 bit TOY_reg2[TOY_degree[1]];
 bit TOY_reg3[TOY_degree[2]];
 bit TOY_reg4[TOY_degree[3]];
 bit TOY_reg5[TOY_degree[4]];
 initFPRNG();
 int r1 = 0 , r2 = 0, r3 = 0 , r4 = 0, r5 = 0;
 do{
 SPRNG(TOY_reg1 , TOY_degree[0]);
 r1 = isZero(TOY_reg1 , TOY_degree[0]);
 SPRNG(TOY_reg2 , TOY_degree[1]);
 r2 = isZero(TOY_reg2 , TOY_degree[1]);
 SPRNG(TOY_reg3 , TOY_degree[2]);
 r3 = isZero(TOY_reg3 , TOY_degree[2]);
 SPRNG(TOY_reg4 , TOY_degree[3]);
 r4 = isZero(TOY_reg4 , TOY_degree[3]);
 SPRNG(TOY_reg5 , TOY_degree[4]);
 r5 = isZero(TOY_reg5 , TOY_degree[4]);
 }while(r1 == 0 || r2 == 0 || r3 == 0 || r4 == 0 || r5 == 0);
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , TOY_reg1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , TOY_reg2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , TOY_reg3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , TOY_reg4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , TOY_reg5 , TOY_poly5 , TOY_degree[4]);
}

canonical_original_code:
void TOY_init(struct TOY *toy){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 unsigned int TOY_reg1[-1];
 unsigned int TOY_reg2[-1];
 unsigned int TOY_reg3[-1];
 unsigned int TOY_reg4[-1];
 unsigned int TOY_reg5[-1];
 initFPRNG();
 int r1 = 0; int r2 = 0; int r3 = 0; int r4 = 0; int r5 = 0;
 do{
 SPRNG(TOY_reg1 , TOY_degree[0]);
 r1 = isZero(TOY_reg1 , TOY_degree[0]);
 SPRNG(TOY_reg2 , TOY_degree[1]);
 r2 = isZero(TOY_reg2 , TOY_degree[1]);
 SPRNG(TOY_reg3 , TOY_degree[2]);
 r3 = isZero(TOY_reg3 , TOY_degree[2]);
 SPRNG(TOY_reg4 , TOY_degree[3]);
 r4 = isZero(TOY_reg4 , TOY_degree[3]);
 SPRNG(TOY_reg5 , TOY_degree[4]);
 r5 = isZero(TOY_reg5 , TOY_degree[4]);
 }while(r1 == 0 || r2 == 0 || r3 == 0 || r4 == 0 || r5 == 0);
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , TOY_reg1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , TOY_reg2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , TOY_reg3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , TOY_reg4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , TOY_reg5 , TOY_poly5 , TOY_degree[4]);
}

variable_types: struct TOY { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } *


original_code:
void TOY_init_with_reg(TOY * toy , bit r1[2] , bit r2[3] , bit r3[4] , bit r4[7] , bit r5[8]){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , r1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , r2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , r3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , r4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , r5 , TOY_poly5 , TOY_degree[4]);
}

canonical_original_code:
void TOY_init_with_reg(struct TOY *toy, unsigned int r1[2], unsigned int r2[3], unsigned int r3[4], unsigned int r4[7], unsigned int r5[8]){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , r1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , r2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , r3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , r4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , r5 , TOY_poly5 , TOY_degree[4]);
}

variable_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; }


decompiled_code:
int __fastcall TOY_print_intial_state(_QWORD *a1)
{
puts("Reg initial state \n------------------------- ");
printArray(*a1, 2LL);
printArray(a1[3], 3LL);
printArray(a1[6], 4LL);
printArray(a1[9], 7LL);
printArray(a1[12], 8LL);
return puts("------------------------- ");
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1)
{
puts("Reg initial state \n------------------------- ");
printArray(*a1, 2LL);
printArray(a1[3], 3LL);
printArray(a1[6], 4LL);
printArray(a1[9], 7LL);
printArray(a1[12], 8LL);
return puts("------------------------- ");
}

original_code:
void TOY_print_intial_state(TOY * toy){
 printf("Reg initial state \n------------------------- \n");
 LFSR * reg1 , *reg2 , *reg3 , *reg4 , *reg5;
 reg1 = &toy->reg[0];
 reg2 = &toy->reg[1];
 reg3 = &toy->reg[2];
 reg4 = &toy->reg[3];
 reg5 = &toy->reg[4];
 printArray(reg1->reg, TOY_degree[0]);
 printArray(reg2->reg , TOY_degree[1]);
 printArray(reg3->reg , TOY_degree[2]);
 printArray(reg4->reg , TOY_degree[3]);
 printArray(reg5->reg , TOY_degree[4]);
 printf("------------------------- \n");
}

canonical_original_code:
void TOY_print_intial_state(struct TOY *toy){
 printf("Reg initial state \n------------------------- \n");
 struct LFSR *reg1; struct LFSR *reg2; struct LFSR *reg3; struct LFSR *reg4; struct LFSR *reg5;
 reg1 = &toy->reg[0];
 reg2 = &toy->reg[1];
 reg3 = &toy->reg[2];
 reg4 = &toy->reg[3];
 reg5 = &toy->reg[4];
 printArray(reg1->reg, TOY_degree[0]);
 printArray(reg2->reg , TOY_degree[1]);
 printArray(reg3->reg , TOY_degree[2]);
 printArray(reg4->reg , TOY_degree[3]);
 printArray(reg5->reg , TOY_degree[4]);
 printf("------------------------- \n");
}

variable_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } *


decompiled_code:
__int64 __fastcall TOY_delete(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = LFSR_delete(v1);
v1 += 24LL;
}
while ( v1 != a1 + 120 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = LFSR_delete(v1);
v1 += 24LL;
}
while ( v1 != a1 + 120 );
return result;
}

original_code:
void TOY_delete(TOY *toy){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&toy->reg[i]);
}

canonical_original_code:
void TOY_delete(struct TOY *toy){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&toy->reg[i]);
}

variable_types: i int


decompiled_code:
char __fastcall TOY_update(__int64 a1)
{
char *v2; // rbx
char v4[5]; // [rsp+Bh] [rbp-1Dh] BYREF
char v5; // [rsp+10h] [rbp-18h] BYREF

v2 = v4;
do
{
*v2 = LFSR_update(a1);
a1 += 24LL;
++v2;
}
while ( v2 != &v5 );
return v4[4] & (~v4[3] | v4[2] & v4[1] & v4[0]);
}

original_code:
bit TOY_update(TOY *toy){
 bit out[5];
 int i;
 for(i = 0; i < 5; i++)
  out[i] = LFSR_update(&toy->reg[i]);
 bit result = (out[0] & out[1] & out[2] & out[3] & out[4]) ^ (out[3] & out[4]) ^ out[4];
 return result;
}

canonical_original_code:
unsigned int TOY_update(struct TOY *toy){
 unsigned int out[5];
 int i;
 for(i = 0; i < 5; i++)
  out[i] = LFSR_update(&toy->reg[i]);
 unsigned int result = (out[0] & out[1] & out[2] & out[3] & out[4]) ^ (out[3] & out[4]) ^ out[4];
 return result;
}

variable_types:
out
unsigned int [5]

variable_types:
result
unsigned int


decompiled_code:
void __fastcall TOY_getStream(__int64 a1, char *a2, int a3)
{
char *v3; // rbx
__int64 v4; // r12

if ( a3 )
{
v3 = a2;
v4 = (__int64)&a2[a3 - 1 + 1];
do
*v3++ = TOY_update(a1);
while ( v3 != (char *)v4 );
}
}

original_code:
void TOY_getStream(TOY *toy, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = TOY_update(toy);
}

canonical_original_code:
void TOY_getStream(struct TOY *toy, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = TOY_update(toy);
}

variable_types:
result
unsigned int *

variable_types:
stream
unsigned int


canonical_original_code:
void A51_init(struct A51 *a51){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 a51->reg[0] = temp;
 LFSR_init(&a51->reg[0] , A51_reg1 , A51_poly1 , A51_degree[0]);
 a51->reg[1] = temp;
 LFSR_init(&a51->reg[1] , A51_reg2 , A51_poly2 , A51_degree[1]);
 a51->reg[2] = temp;
 LFSR_init(&a51->reg[2] , A51_reg3 , A51_poly3 , A51_degree[2]);
}

variable_types: struct A51 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[3]; } *


decompiled_code:
__int64 __fastcall A51_delete(__int64 a1)
{
((void (*)(void))LFSR_delete)();
LFSR_delete(a1 + 24);
return LFSR_delete(a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
((void (*)(void))LFSR_delete)();
LFSR_delete(a1 + 24);
return LFSR_delete(a1 + 48);
}

original_code:
void A51_delete(A51 *a51){
 int i;
 for(i = 0; i < 3; i++)
  LFSR_delete(&a51->reg[i]);
}

canonical_original_code:
void A51_delete(struct A51 *a51){
 int i;
 for(i = 0; i < 3; i++)
  LFSR_delete(&a51->reg[i]);
}


decompiled_code:
__int64 __fastcall A51_update(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v2; // r13
__int64 v3; // rbp
unsigned int *v4; // r12
int v5; // er14
unsigned int v6; // ebx

v1 = a1;
v2 = (unsigned int *)&A51_clock;
v3 = a1;
v4 = (unsigned int *)&A51_clock;
v5 = 0;
do
{
v5 += (unsigned __int8)LFSR_getBit(v1, *v4++) == 0;
v1 += 24LL;
}
while ( v4 != (unsigned int *)1132 );
if ( v5 <= 1 )
{
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v3, *v2) == 1 )
v6 ^= LFSR_update(v3);
else
v6 ^= LFSR_getBit(v3, (unsigned int)(*(_DWORD *)(v3 + 16) - 1));
++v2;
v3 += 24LL;
}
while ( v2 != (unsigned int *)1132 );
}
else
{
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v3, *v2) )
v6 ^= LFSR_getBit(v3, (unsigned int)(*(_DWORD *)(v3 + 16) - 1));
else
v6 ^= LFSR_update(v3);
++v2;
v3 += 24LL;
}
while ( v2 != (unsigned int *)1132 );
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v2; // r13
__int64 v3; // rbp
unsigned int *v4; // r12
int v5; // er14
unsigned int v6; // ebx

v1 = a1;
v2 = (unsigned int *)&A51_clock;
v3 = a1;
v4 = (unsigned int *)&A51_clock;
v5 = 0;
do
{
v5 += (unsigned __int8)LFSR_getBit(v1, *v4++) == 0;
v1 += 24LL;
}
while ( v4 != (unsigned int *)1132 );
if ( v5 <= 1 )
{
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v3, *v2) == 1 )
v6 ^= LFSR_update(v3);
else
v6 ^= LFSR_getBit(v3, (unsigned int)(*(_DWORD *)(v3 + 16) - 1));
++v2;
v3 += 24LL;
}
while ( v2 != (unsigned int *)1132 );
}
else
{
v6 = 0;
do
{
if ( (unsigned __int8)LFSR_getBit(v3, *v2) )
v6 ^= LFSR_getBit(v3, (unsigned int)(*(_DWORD *)(v3 + 16) - 1));
else
v6 ^= LFSR_update(v3);
++v2;
v3 += 24LL;
}
while ( v2 != (unsigned int *)1132 );
}
return v6;
}

original_code:
bit A51_update(A51 *a51){
 int count_zero = 0;
 int i;
 bit output = 0;
 bit temp = 0;
 for(i = 0; i < 3; i++)
 {
  temp = LFSR_getBit(&a51->reg[i] , A51_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 2)
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 0)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 1)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 return output;
}

canonical_original_code:
unsigned int A51_update(struct A51 *a51){
 int count_zero = 0;
 int i;
 unsigned int output = 0;
 unsigned int temp = 0;
 for(i = 0; i < 3; i++)
 {
  temp = LFSR_getBit(&a51->reg[i] , A51_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 2)
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 0)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 1)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 return output;
}

variable_types:
output
unsigned int

variable_types:
temp
unsigned int


decompiled_code:
__int64 __fastcall A51_warmUpStream(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = A51_update(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = func2(a1);
}
return result;
}

original_code:
void A51_warmUpStream(A51 *a51, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  A51_update(a51);
}

canonical_original_code:
void A51_warmUpStream(struct A51 *a51, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  A51_update(a51);
}


original_code:
void A51_getStream(A51 *a51, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = A51_update(a51);
}

canonical_original_code:
void A51_getStream(struct A51 *a51, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = A51_update(a51);
}


decompiled_code:
__int64 __fastcall A51_encrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
A51_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a2 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a3 + i) = v7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a2 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a3 + i) = v7;
}
}
return result;
}

original_code:
void A51_encrypt(A51 *a51, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  A51_getStream(a51 , temp , 8);
  byte currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

canonical_original_code:
void A51_encrypt(struct A51 *a51, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  A51_getStream(a51 , temp , 8);
  unsigned int currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types:
length
unsigned int

variable_types:
temp
unsigned int [8]

variable_types:
currentByte
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall A51_decrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
A51_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a3 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a2 + i) = v7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
char v7; // dl
__int64 j; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a3 + i);
for ( j = 0LL; j != 8; ++j )
{
result = (unsigned __int8)v10[j] << j;
v7 ^= result;
}
*(_BYTE *)(a2 + i) = v7;
}
}
return result;
}

original_code:
void A51_decrypt(A51 *a51, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  A51_getStream(a51 , temp , 8);
  byte currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

canonical_original_code:
void A51_decrypt(struct A51 *a51, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  A51_getStream(a51 , temp , 8);
  unsigned int currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

variable_types: j int


getCipherLength

decompiled_code:
__int64 __fastcall getCipherLength(signed int a1)
{
unsigned int v1; // edx

v1 = a1;
if ( a1 != 24 * (a1 / 24) )
v1 = 8 * (3 * (a1 / 24) + 3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(signed int a1)
{
unsigned int v1; // edx

v1 = a1;
if ( a1 != 24 * (a1 / 24) )
v1 = 8 * (3 * (a1 / 24) + 3);
return v1;
}

original_code:
int getCipherLength(int length){
 if(length % 24 == 0)
  return length;
 return (length / 24 + 1) * 24;
}

variable_types: length int


messageToBlocks

decompiled_code:
__int64 __fastcall messageToBlocks(__int64 a1, __int64 a2, signed int a3)
{
__int64 v5; // r8
__int64 i; // rdx
signed int v7; // ebp
__int64 result; // rax
int v9; // esi

if ( a3 )
{
v5 = (unsigned int)a3;
for ( i = 0LL; i != v5; ++i )
*(_BYTE *)(a2 + 24LL * ((int)i / 24) + (int)i % 24) = *(_BYTE *)(a1 + i);
}
v7 = a3;
result = getCipherLength(a3);
v9 = result;
if ( a3 < (int)result )
{
do
{
result = v7 % 24;
*(_BYTE *)(a2 + 24LL * (v7 / 24) + result) = 0;
++v7;
}
while ( v9 != v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, signed int a3)
{
__int64 v5; // r8
__int64 i; // rdx
signed int v7; // ebp
__int64 result; // rax
int v9; // esi

if ( a3 )
{
v5 = (unsigned int)a3;
for ( i = 0LL; i != v5; ++i )
*(_BYTE *)(a2 + 24LL * ((int)i / 24) + (int)i % 24) = *(_BYTE *)(a1 + i);
}
v7 = a3;
result = func0(a3);
v9 = result;
if ( a3 < (int)result )
{
do
{
result = v7 % 24;
*(_BYTE *)(a2 + 24LL * (v7 / 24) + result) = 0;
++v7;
}
while ( v9 != v7 );
}
return result;
}

original_code:
void messageToBlocks(bit * message , bit blocks[][24] , unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = message[i];
 }
 int end = getCipherLength(length);
 for(i = length; i < end; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = 0;
 }
}

canonical_original_code:
void messageToBlocks(unsigned int *message, unsigned int blocks[][24], unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = message[i];
 }
 int end = getCipherLength(length);
 for(i = length; i < end; i++)
 {
  j = i / 24;
  blocks[j][i % 24] = 0;
 }
}

variable_types:
message
unsigned int *

variable_types:
blocks
unsigned int [][24]

variable_types: end int


blocksToMessage

decompiled_code:
__int64 __fastcall blocksToMessage(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // r9
__int64 i; // rdx
__int64 result; // rax

if ( a3 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
result = *(unsigned __int8 *)(a2 + 24LL * ((int)i / 24) + (int)i % 24);
*(_BYTE *)(a1 + i) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // r9
__int64 i; // rdx
__int64 result; // rax

if ( a3 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
result = *(unsigned __int8 *)(a2 + 24LL * ((int)i / 24) + (int)i % 24);
*(_BYTE *)(a1 + i) = result;
}
}
return result;
}

original_code:
void blocksToMessage(bit * message , bit blocks[][24] , unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  message[i] = blocks[j][i % 24];
 }
}

canonical_original_code:
void blocksToMessage(unsigned int *message, unsigned int blocks[][24], unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  j = i / 24;
  message[i] = blocks[j][i % 24];
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall bunny24CBC_decrypt(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned int v7; // ebx
void *v8; // rsp
signed int v9; // eax
__int64 *v10; // r12
int i; // ebx
__int64 v13; // [rsp+0h] [rbp-40h] BYREF
__int64 v14; // [rsp+8h] [rbp-38h]

v14 = a1;
v13 = a3;
v7 = a5 / 0x18;
v8 = alloca(16 * ((unsigned __int64)(24LL * (int)(a5 / 0x18 + 1) + 15) >> 4));
v9 = getCipherLength(a5);
messageToBlocks(a2, (__int64)&v13, v9);
v10 = &v13 + 3 * (int)v7;
for ( i = v7 - 1; ; --i )
{
bunny24_decrypt(v10, a4);
if ( i + 1 <= 0 )
break;
arraySum(&v13 + 3 * i, v10, v10, 24LL);
LABEL_3:
v10 -= 3;
}
if ( i >= 0 )
goto LABEL_3;
arraySum(&v13, v13, &v13, 24LL);
return blocksToMessage(v14, (__int64)&v13, a5);
}

original_code:
void bunny24CBC_decrypt(bit * message , bit * ciphertext, bit initVector[24] , bit key[24] , unsigned int length){
 int num = length / 24 + 1 , i;
 bit blocks[num][24];
 messageToBlocks(ciphertext , blocks , getCipherLength(length));
 for(i = num - 1; i >= 0; i--)
 {
  bunny24_decrypt(blocks[i] , key);
  if(i > 0)
   arraySum(blocks[i - 1] , blocks[i] , blocks[i] , 24);
 }
 arraySum(blocks[0] , initVector , blocks[0] , 24);
 blocksToMessage(message , blocks , length);
}

canonical_original_code:
void bunny24CBC_decrypt(unsigned int *message, unsigned int *ciphertext, unsigned int initVector[24], unsigned int key[24], unsigned int length){
 int num = length / 24 + 1; int i;
 unsigned int blocks[-1][24];
 messageToBlocks(ciphertext , blocks , getCipherLength(length));
 for(i = num - 1; i >= 0; i--)
 {
  bunny24_decrypt(blocks[i] , key);
  if(i > 0)
   arraySum(blocks[i - 1] , blocks[i] , blocks[i] , 24);
 }
 arraySum(blocks[0] , initVector , blocks[0] , 24);
 blocksToMessage(message , blocks , length);
}

variable_types:
ciphertext
unsigned int *

variable_types:
initVector
unsigned int [24]

variable_types:
key
unsigned int [24]

variable_types: num int

variable_types:
blocks
unsigned int [-1][24]


newEmptyBitArray

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

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

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

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

original_code:
bitArray * newEmptyBitArray(){
  bitArray * bA = malloc(sizeof(bitArray));
  bA->length = 0;
  bA->array = ((void *)0);
  return bA;
}

canonical_original_code:
struct array_of_bit *newEmptyBitArray(){
  struct array_of_bit *bA = malloc(sizeof(bitArray));
  bA->length = 0;
  bA->array = ((void *)0);
  return bA;
}

variable_types: struct array_of_bit { unsigned int *array; int length; } *


resizeBitArray

decompiled_code:
void *__fastcall resizeBitArray(__int64 a1, int a2)
{
void *v3; // rdi
void *v4; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
*(_DWORD *)(a1 + 8) = a2;
v4 = malloc(a2);
*(_QWORD *)a1 = v4;
return memset(v4, 0, a2);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, int a2)
{
void *v3; // rdi
void *v4; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
*(_DWORD *)(a1 + 8) = a2;
v4 = malloc(a2);
*(_QWORD *)a1 = v4;
return memset(v4, 0, a2);
}

original_code:
void resizeBitArray(bitArray * bA , const int l){
  if(bA->array != ((void *)0))
   free(bA->array);
  bA->length = l;
  bA->array = malloc(sizeof(bit) * l);
  memset(bA->array , 0 , sizeof(bit) * l);
}

canonical_original_code:
void resizeBitArray(struct array_of_bit *bA, int l){
  if(bA->array != ((void *)0))
   free(bA->array);
  bA->length = l;
  bA->array = malloc(sizeof(bit) * l);
  memset(bA->array , 0 , sizeof(bit) * l);
}

variable_types: l int

user_defined_types: struct array_of_bit { unsigned int *array; int length; }


deleteBitArray

decompiled_code:
void __fastcall deleteBitArray(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
free(ptr);
}

original_code:
void deleteBitArray(bitArray * bA){
  if(bA != ((void *)0))
   if(bA->array != ((void *)0))
    free(bA->array);
   free(bA);
}

canonical_original_code:
void deleteBitArray(struct array_of_bit *bA){
  if(bA != ((void *)0))
   if(bA->array != ((void *)0))
    free(bA->array);
   free(bA);
}


copyBitArray

decompiled_code:
void *__fastcall copyBitArray(__int64 a1, __int64 a2)
{
void *v3; // rdi
int v4; // edi
void *v5; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
v4 = *(_DWORD *)(a2 + 8);
*(_DWORD *)(a1 + 8) = v4;
v5 = malloc(v4);
*(_QWORD *)a1 = v5;
return memcpy(v5, *(const void **)a2, *(int *)(a2 + 8));
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2)
{
void *v3; // rdi
int v4; // edi
void *v5; // rax

v3 = *(void **)a1;
if ( v3 )
free(v3);
v4 = *(_DWORD *)(a2 + 8);
*(_DWORD *)(a1 + 8) = v4;
v5 = malloc(v4);
*(_QWORD *)a1 = v5;
return memcpy(v5, *(const void **)a2, *(int *)(a2 + 8));
}

original_code:
void copyBitArray(bitArray * r , const bitArray * s){
 if(r->array != ((void *)0))
  free(r->array);
 r->length = s->length;
 r->array = malloc(sizeof(bit) * s->length);
 memcpy(r->array , s->array , sizeof(bit) * s->length);
}

canonical_original_code:
void copyBitArray(struct array_of_bit *r, struct array_of_bit *s){
 if(r->array != ((void *)0))
  free(r->array);
 r->length = s->length;
 r->array = malloc(sizeof(bit) * s->length);
 memcpy(r->array , s->array , sizeof(bit) * s->length);
}

variable_types:
s
struct array_of_bit *


decompiled_code:
__int64 __fastcall bitArray2Hex(__int64 a1, char *a2)
{
char v2; // bl
int v3; // edx
__int64 result; // rax
int v7; // er8
__int64 v8; // r10
int v9; // esi
int v10; // edi
char v11; // cl

v3 = *(_DWORD *)(a1 + 8);
result = (unsigned int)(v3 / 4);
if ( v3 > 3 )
{
v7 = 4 * result;
v8 = 4 * (int)result - 4;
do
{
result = v8;
v9 = 0;
v10 = 0;
do
{
v11 = v9++;
v10 |= *(unsigned __int8 *)(*(_QWORD *)a1 + result++) << v11;
}
while ( v7 > (int)result );
switch ( v10 )
{
case 0:
v2 = 48;
break;
case 1:
v2 = 49;
break;
case 2:
v2 = 50;
break;
case 3:
v2 = 51;
break;
case 4:
v2 = 52;
break;
case 5:
v2 = 53;
break;
case 6:
v2 = 54;
break;
case 7:
v2 = 55;
break;
case 8:
v2 = 56;
break;
case 9:
v2 = 57;
break;
case 10:
v2 = 65;
break;
case 11:
v2 = 66;
break;
case 12:
v2 = 67;
break;
case 13:
v2 = 68;
break;
case 14:
v2 = 69;
break;
case 15:
v2 = 70;
break;
default:
break;
}
*a2++ = v2;
v8 -= 4LL;
v7 -= 4;
}
while ( v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
char v2; // bl
int v3; // edx
__int64 result; // rax
int v7; // er8
__int64 v8; // r10
int v9; // esi
int v10; // edi
char v11; // cl

v3 = *(_DWORD *)(a1 + 8);
result = (unsigned int)(v3 / 4);
if ( v3 > 3 )
{
v7 = 4 * result;
v8 = 4 * (int)result - 4;
do
{
result = v8;
v9 = 0;
v10 = 0;
do
{
v11 = v9++;
v10 |= *(unsigned __int8 *)(*(_QWORD *)a1 + result++) << v11;
}
while ( v7 > (int)result );
switch ( v10 )
{
case 0:
v2 = 48;
break;
case 1:
v2 = 49;
break;
case 2:
v2 = 50;
break;
case 3:
v2 = 51;
break;
case 4:
v2 = 52;
break;
case 5:
v2 = 53;
break;
case 6:
v2 = 54;
break;
case 7:
v2 = 55;
break;
case 8:
v2 = 56;
break;
case 9:
v2 = 57;
break;
case 10:
v2 = 65;
break;
case 11:
v2 = 66;
break;
case 12:
v2 = 67;
break;
case 13:
v2 = 68;
break;
case 14:
v2 = 69;
break;
case 15:
v2 = 70;
break;
default:
break;
}
*a2++ = v2;
v8 -= 4LL;
v7 -= 4;
}
while ( v7 );
}
return result;
}

original_code:
void bitArray2Hex(const bitArray *a , char * hex){
 int num_of_char = a->length / 4;
 int i , j;
 char x;
 for(i = num_of_char - 1; i >= 0; i--)
 {
  int num = 0;
  int e = i * 4 + 4;
  int z = 0;
  for(j = (i * 4); j < e; j++)
   num |= (a->array[j] << z++);
  switch(num){
   case 0 : x = '0'; break;
   case 1 : x = '1'; break;
   case 2 : x = '2'; break;
   case 3 : x = '3'; break;
   case 4 : x = '4'; break;
   case 5 : x = '5'; break;
   case 6 : x = '6'; break;
   case 7 : x = '7'; break;
   case 8 : x = '8'; break;
   case 9 : x = '9'; break;
   case 10 : x = 'A'; break;
   case 11 : x = 'B'; break;
   case 12 : x = 'C'; break;
   case 13 : x = 'D'; break;
   case 14 : x = 'E'; break;
   case 15 : x = 'F'; break;
   default : break;
   }
   hex[num_of_char - 1 - i] = x;
 }
}

canonical_original_code:
void bitArray2Hex(struct array_of_bit *a, char *hex){
 int num_of_char = a->length / 4;
 int i; int j;
 char x;
 for(i = num_of_char - 1; i >= 0; i--)
 {
  int num = 0;
  int e = i * 4 + 4;
  int z = 0;
  for(j = (i * 4); j < e; j++)
   num |= (a->array[j] << z++);
  switch(num){
   case 0 : x = '0'; break;
   case 1 : x = '1'; break;
   case 2 : x = '2'; break;
   case 3 : x = '3'; break;
   case 4 : x = '4'; break;
   case 5 : x = '5'; break;
   case 6 : x = '6'; break;
   case 7 : x = '7'; break;
   case 8 : x = '8'; break;
   case 9 : x = '9'; break;
   case 10 : x = 'A'; break;
   case 11 : x = 'B'; break;
   case 12 : x = 'C'; break;
   case 13 : x = 'D'; break;
   case 14 : x = 'E'; break;
   case 15 : x = 'F'; break;
   default : break;
   }
   hex[num_of_char - 1 - i] = x;
 }
}

variable_types:
hex
char *

variable_types: x char

variable_types: e int

variable_types: z int


decompiled_code:
void *__fastcall bitArray2Binary(__int64 a1, void *a2)
{
return memcpy(a2, *(const void **)a1, *(int *)(a1 + 8));
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, void *a2)
{
return memcpy(a2, *(const void **)a1, *(int *)(a1 + 8));
}

original_code:
void bitArray2Binary(const bitArray *a, bit dest[]){
 memcpy(dest , a->array , sizeof(bit) * a->length);
}

canonical_original_code:
void bitArray2Binary(struct array_of_bit *a, unsigned int dest[]){
 memcpy(dest , a->array , sizeof(bit) * a->length);
}

variable_types:
dest
unsigned int []


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

result = (unsigned __int8 *)memset(a2, 0, *(_DWORD *)(a1 + 8) / 8);
if ( *(int *)(a1 + 8) > 0 )
{
result = 0LL;
do
{
*((_BYTE *)a2 + (int)result / 8) |= result[*(_QWORD *)a1] << ((int)result % 8);
++result;
}
while ( *(_DWORD *)(a1 + 8) > (int)result );
}
return result;
}

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

result = (unsigned __int8 *)memset(a2, 0, *(_DWORD *)(a1 + 8) / 8);
if ( *(int *)(a1 + 8) > 0 )
{
result = 0LL;
do
{
*((_BYTE *)a2 + (int)result / 8) |= result[*(_QWORD *)a1] << ((int)result % 8);
++result;
}
while ( *(_DWORD *)(a1 + 8) > (int)result );
}
return result;
}

original_code:
void bitArray2Byte(const bitArray *a, byte dest[]){
 int i;
 memset(dest , 0 , sizeof(byte) * (a->length / 8));
 for(i = 0; i < a->length; i++)
  dest[i/8] |= (a->array[i] << (i % 8));
}

canonical_original_code:
void bitArray2Byte(struct array_of_bit *a, unsigned int dest[]){
 int i;
 memset(dest , 0 , sizeof(byte) * (a->length / 8));
 for(i = 0; i < a->length; i++)
  dest[i/8] |= (a->array[i] << (i % 8));
}


decompiled_code:
void *__fastcall binary2BitArray(void **a1, const void *a2, int a3)
{
resizeBitArray((__int64)a1, a3);
return memcpy(*a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func7(void **a1, const void *a2, int a3)
{
func1((__int64)a1, a3);
return memcpy(*a1, a2, a3);
}

original_code:
void binary2BitArray(bitArray *r, const bit x[], const int length){
 resizeBitArray(r , length);
 memcpy(r->array , x , sizeof(bit) * length);
}

canonical_original_code:
void binary2BitArray(struct array_of_bit *r, unsigned int x[], int length){
 resizeBitArray(r , length);
 memcpy(r->array , x , sizeof(bit) * length);
}

variable_types:
x
unsigned int []

variable_types: length int


decompiled_code:
char *__fastcall byte2BitArray(_QWORD *a1, __int64 a2, int a3)
{
int v3; // er12
char *result; // rax

v3 = 8 * a3;
result = (char *)resizeBitArray((__int64)a1, 8 * a3);
if ( v3 > 0 )
{
result = 0LL;
do
{
result[*a1] = ((int)*(unsigned __int8 *)(a2 + (int)result / 8) >> ((int)result % 8)) & 1;
++result;
}
while ( result != (char *)(unsigned int)v3 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(_QWORD *a1, __int64 a2, int a3)
{
int v3; // er12
char *result; // rax

v3 = 8 * a3;
result = (char *)func1((__int64)a1, 8 * a3);
if ( v3 > 0 )
{
result = 0LL;
do
{
result[*a1] = ((int)*(unsigned __int8 *)(a2 + (int)result / 8) >> ((int)result % 8)) & 1;
++result;
}
while ( result != (char *)(unsigned int)v3 );
}
return result;
}

original_code:
void byte2BitArray(bitArray *r, const byte x[], const int length){
 int l = length * 8;
 resizeBitArray(r , l);
 int i;
 for(i = 0; i < l; i++)
  r->array[i] = (x[i/8] & (1 << i % 8)) ? 1 : 0;
}

canonical_original_code:
void byte2BitArray(struct array_of_bit *r, unsigned int x[], int length){
 int l = length * 8;
 resizeBitArray(r , l);
 int i;
 for(i = 0; i < l; i++)
  r->array[i] = (x[i/8] & (1 << i % 8)) ? 1 : 0;
}


decompiled_code:
char *__fastcall hex2BitArray(_QWORD *a1, const char *a2)
{
unsigned __int8 v2; // bp
int v4; // er12
char *result; // rax
const char *v6; // rdi
char *v7; // rsi
int i; // ecx

v4 = strlen(a2);
result = (char *)resizeBitArray((__int64)a1, 4 * v4);
if ( v4 - 1 >= 0 )
{
v6 = &a2[v4 - 1];
v7 = 0LL;
do
{
switch ( *v6 )
{
case '0':
v2 = 0;
break;
case '1':
v2 = 1;
break;
case '2':
v2 = 2;
break;
case '3':
v2 = 3;
break;
case '4':
v2 = 4;
break;
case '5':
v2 = 5;
break;
case '6':
v2 = 6;
break;
case '7':
v2 = 7;
break;
case '8':
v2 = 8;
break;
case '9':
v2 = 9;
break;
case 'A':
v2 = 10;
break;
case 'B':
v2 = 11;
break;
case 'C':
v2 = 12;
break;
case 'D':
v2 = 13;
break;
case 'E':
v2 = 14;
break;
case 'F':
v2 = 15;
break;
case 'a':
v2 = 10;
break;
case 'b':
v2 = 11;
break;
case 'c':
v2 = 12;
break;
case 'd':
v2 = 13;
break;
case 'e':
v2 = 14;
break;
case 'f':
v2 = 15;
break;
default:
break;
}
result = v7;
for ( i = 0; i != 4; ++i )
(result++)[*a1] = ((int)v2 >> i) & 1;
--v6;
v7 += 4;
}
while ( v7 != (char *)(4LL * (unsigned int)(v4 - 1) + 4) );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(_QWORD *a1, const char *a2)
{
unsigned __int8 v2; // bp
int v4; // er12
char *result; // rax
const char *v6; // rdi
char *v7; // rsi
int i; // ecx

v4 = strlen(a2);
result = (char *)func1((__int64)a1, 4 * v4);
if ( v4 - 1 >= 0 )
{
v6 = &a2[v4 - 1];
v7 = 0LL;
do
{
switch ( *v6 )
{
case '0':
v2 = 0;
break;
case '1':
v2 = 1;
break;
case '2':
v2 = 2;
break;
case '3':
v2 = 3;
break;
case '4':
v2 = 4;
break;
case '5':
v2 = 5;
break;
case '6':
v2 = 6;
break;
case '7':
v2 = 7;
break;
case '8':
v2 = 8;
break;
case '9':
v2 = 9;
break;
case 'A':
v2 = 10;
break;
case 'B':
v2 = 11;
break;
case 'C':
v2 = 12;
break;
case 'D':
v2 = 13;
break;
case 'E':
v2 = 14;
break;
case 'F':
v2 = 15;
break;
case 'a':
v2 = 10;
break;
case 'b':
v2 = 11;
break;
case 'c':
v2 = 12;
break;
case 'd':
v2 = 13;
break;
case 'e':
v2 = 14;
break;
case 'f':
v2 = 15;
break;
default:
break;
}
result = v7;
for ( i = 0; i != 4; ++i )
(result++)[*a1] = ((int)v2 >> i) & 1;
--v6;
v7 += 4;
}
while ( v7 != (char *)(4LL * (unsigned int)(v4 - 1) + 4) );
}
return result;
}

original_code:
void hex2BitArray(bitArray *r, const char * hex){
 int len = strlen(hex);
 int l = len * 4 , i , j = 0 , z = 0;
 resizeBitArray(r , l);
 for(i = len-1; i >= 0; i--)
 {
  byte num;
  switch(hex[i]){
   case '0' : num = 0; break;
   case '1' : num = 1; break;
   case '2' : num = 2; break;
   case '3' : num = 3; break;
   case '4' : num = 4; break;
   case '5' : num = 5; break;
   case '6' : num = 6; break;
   case '7' : num = 7; break;
   case '8' : num = 8; break;
   case '9' : num = 9; break;
   case 'A' : num = 10; break;
   case 'B' : num = 11; break;
   case 'C' : num = 12; break;
   case 'D' : num = 13; break;
   case 'E' : num = 14; break;
   case 'F' : num = 15; break;
   case 'a' : num = 10; break;
   case 'b' : num = 11; break;
   case 'c' : num = 12; break;
   case 'd' : num = 13; break;
   case 'e' : num = 14; break;
   case 'f' : num = 15; break;
   default : break;
   }
   for(j = 0 ; j < 4; j++)
   r->array[z++] = (num & (1 << j)) ? 1 : 0;
 }
}

canonical_original_code:
void hex2BitArray(struct array_of_bit *r, char *hex){
 int len = strlen(hex);
 int l = len * 4; int i; int j = 0; int z = 0;
 resizeBitArray(r , l);
 for(i = len-1; i >= 0; i--)
 {
  unsigned int num;
  switch(hex[i]){
   case '0' : num = 0; break;
   case '1' : num = 1; break;
   case '2' : num = 2; break;
   case '3' : num = 3; break;
   case '4' : num = 4; break;
   case '5' : num = 5; break;
   case '6' : num = 6; break;
   case '7' : num = 7; break;
   case '8' : num = 8; break;
   case '9' : num = 9; break;
   case 'A' : num = 10; break;
   case 'B' : num = 11; break;
   case 'C' : num = 12; break;
   case 'D' : num = 13; break;
   case 'E' : num = 14; break;
   case 'F' : num = 15; break;
   case 'a' : num = 10; break;
   case 'b' : num = 11; break;
   case 'c' : num = 12; break;
   case 'd' : num = 13; break;
   case 'e' : num = 14; break;
   case 'f' : num = 15; break;
   default : break;
   }
   for(j = 0 ; j < 4; j++)
   r->array[z++] = (num & (1 << j)) ? 1 : 0;
 }
}

variable_types: len int

variable_types: j int

variable_types:
num
unsigned int


printBinaryBitArray

decompiled_code:
int __fastcall printBinaryBitArray(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbx

putchar(123);
v1 = *(unsigned int *)(a1 + 8);
if ( (int)v1 > 0 )
{
v2 = 0LL;
do
{
printf(" %d", *(unsigned __int8 *)(*(_QWORD *)a1 + v2));
v1 = *(unsigned int *)(a1 + 8);
++v2;
}
while ( (int)v1 > (int)v2 );
}
return printf(" } : %d \n", v1);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbx

putchar(123);
v1 = *(unsigned int *)(a1 + 8);
if ( (int)v1 > 0 )
{
v2 = 0LL;
do
{
printf(" %d", *(unsigned __int8 *)(*(_QWORD *)a1 + v2));
v1 = *(unsigned int *)(a1 + 8);
++v2;
}
while ( (int)v1 > (int)v2 );
}
return printf(" } : %d \n", v1);
}

original_code:
void printBinaryBitArray(const bitArray *bA){
 int i;
 printf("{");
 for(i = 0; i < bA->length; i++)
  printf(" %d", bA->array[i]);
 printf(" } : %d \n", bA->length);
}

canonical_original_code:
void printBinaryBitArray(struct array_of_bit *bA){
 int i;
 printf("{");
 for(i = 0; i < bA->length; i++)
  printf(" %d", bA->array[i]);
 printf(" } : %d \n", bA->length);
}

variable_types: i int


printHexBitArray

decompiled_code:
int __fastcall printHexBitArray(__int64 a1)
{
int v1; // ebx
int v2; // er12
void *v3; // rsp
__int64 v4; // rbx
char v6[48]; // [rsp+0h] [rbp-30h] BYREF

v1 = *(_DWORD *)(a1 + 8);
if ( (v1 & 3) != 0 )
return puts("The array needs to be a multiple of 4 (Beta)\n");
v2 = v1 / 4;
v3 = alloca(v1 / 4);
bitArray2Hex(a1, v6);
printf("{ ");
if ( v1 > 3 )
{
v4 = 0LL;
do
putchar(v6[v4++]);
while ( v2 > (int)v4 );
}
return printf(" } : %d \n", *(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int v1; // ebx
int v2; // er12
void *v3; // rsp
__int64 v4; // rbx
char v6[48]; // [rsp+0h] [rbp-30h] BYREF

v1 = *(_DWORD *)(a1 + 8);
if ( (v1 & 3) != 0 )
return puts("The array needs to be a multiple of 4 (Beta)\n");
v2 = v1 / 4;
v3 = alloca(v1 / 4);
func4(a1, v6);
printf("{ ");
if ( v1 > 3 )
{
v4 = 0LL;
do
putchar(v6[v4++]);
while ( v2 > (int)v4 );
}
return printf(" } : %d \n", *(unsigned int *)(a1 + 8));
}

original_code:
void printHexBitArray(const bitArray *bA){
 if(bA->length % 4 != 0)
 {
  printf("The array needs to be a multiple of 4 (Beta)\n\n");
  return;
 }
 int l = bA->length / 4;
 char str[l];
 bitArray2Hex(bA , str);
 int i;
 printf("{ ");
 for(i = 0; i < l; i++)
  printf("%c" , str[i]);
 printf(" } : %d \n", bA->length);
}

canonical_original_code:
void printHexBitArray(struct array_of_bit *bA){
 if(bA->length % 4 != 0)
 {
  printf("The array needs to be a multiple of 4 (Beta)\n\n");
  return;
 }
 int l = bA->length / 4;
 char str[-1];
 bitArray2Hex(bA , str);
 int i;
 printf("{ ");
 for(i = 0; i < l; i++)
  printf("%c" , str[i]);
 printf(" } : %d \n", bA->length);
}

variable_types:
str
char [-1]


getGradeBitArray

decompiled_code:
__int64 __fastcall getGradeBitArray(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rax
unsigned int v4; // esi
bool v5; // cl
bool v6; // dl

v2 = *a1;
v3 = *((_DWORD *)a1 + 2) - 1;
do
{
v4 = v3;
v5 = *(_BYTE *)(v2 + v3) != 1;
v6 = (int)v3-- > 0;
}
while ( v6 && v5 );
return v4;
}

original_code:
int getGradeBitArray(const bitArray *a){
 int i = a->length;
 do{
  i --;
 }while(a->array[i] != 1 && i > 0);
 return i;
}

canonical_original_code:
int getGradeBitArray(struct array_of_bit *a){
 int i = a->length;
 do{
  i --;
 }while(a->array[i] != 1 && i > 0);
 return i;
}


cmpBitArray

decompiled_code:
__int64 __fastcall cmpBitArray(__int64 *a1, __int64 *a2)
{
int v2; // ebx
int v3; // eax
unsigned int v4; // edx
int v5; // ebx
__int64 v6; // rax
unsigned __int8 v7; // dl
unsigned __int8 v8; // cl

v2 = getGradeBitArray(a1);
v3 = getGradeBitArray(a2);
v4 = 1;
if ( v2 <= v3 )
{
v4 = -1;
if ( v2 >= v3 )
{
v5 = v2 - 1;
if ( v5 < 0 )
{
v4 = 0;
}
else
{
v6 = v5;
while ( 1 )
{
v7 = *(_BYTE *)(*a1 + v6);
v8 = *(_BYTE *)(*a2 + v6);
if ( v7 != v8 )
break;
if ( (int)--v6 < 0 )
return 0;
}
v4 = v8 < v7 ? 1 : -1;
}
}
}
return v4;
}

original_code:
int cmpBitArray(const bitArray *a , const bitArray *b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 if(aG > bG)
  return 1;
 if(aG < bG)
  return -1;
 int i;
 for(i = aG - 1; i >= 0; i--)
  if(a->array[i] != b->array[i])
   return (a->array[i] > b->array[i]) ? 1 : -1;
 return 0;
}

canonical_original_code:
int cmpBitArray(struct array_of_bit *a, struct array_of_bit *b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 if(aG > bG)
  return 1;
 if(aG < bG)
  return -1;
 int i;
 for(i = aG - 1; i >= 0; i--)
  if(a->array[i] != b->array[i])
   return (a->array[i] > b->array[i]) ? 1 : -1;
 return 0;
}

variable_types:
b
struct array_of_bit *

variable_types: aG int

variable_types: bG int


sumBitArray

original_code:
void sumBitArray(bitArray *r , const bitArray * a , const bitArray * b){
  int l = (a->length > b->length) ? a->length : b->length;
  bitArray * tmp = newBitArray(l);
  if(a->length > b->length)
   memcpy(tmp->array , a->array , sizeof(bit) * l);
  else
   memcpy(tmp->array , b->array , sizeof(bit) * l);
  int i , e = (a->length < b->length) ? a->length : b->length;
  for(i = 0; i < e; i++)
   tmp->array[i] = a->array[i] ^ b->array[i];
  copyBitArray(r , tmp);
  deleteBitArray(tmp);
}

canonical_original_code:
void sumBitArray(struct array_of_bit *r, struct array_of_bit *a, struct array_of_bit *b){
  int l = (a->length > b->length) ? a->length : b->length;
  struct array_of_bit *tmp = newBitArray(l);
  if(a->length > b->length)
   memcpy(tmp->array , a->array , sizeof(bit) * l);
  else
   memcpy(tmp->array , b->array , sizeof(bit) * l);
  int i; int e = (a->length < b->length) ? a->length : b->length;
  for(i = 0; i < e; i++)
   tmp->array[i] = a->array[i] ^ b->array[i];
  copyBitArray(r , tmp);
  deleteBitArray(tmp);
}

variable_types: struct array_of_bit { unsigned int *array; int length; } *

variable_types:
a
struct array_of_bit *

variable_types: l int


shiftBitArray

decompiled_code:
void *__fastcall shiftBitArray(__int64 a1, int a2)
{
int v2; // ebx
void *v3; // rsp
void *v4; // r14
void *result; // rax
signed int v6; // er13
signed int v7; // er13
_BYTE v8[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = *(_DWORD *)(a1 + 8);
v3 = alloca(v2);
v4 = *(void **)a1;
result = memcpy(v8, *(const void **)a1, v2);
if ( a2 > 0 )
{
v6 = abs32(a2 % v2);
memcpy(v4, &v8[v2 - v6], v6);
result = memcpy((void *)(*(_QWORD *)a1 + v6), v8, *(_DWORD *)(a1 + 8) - v6);
}
else if ( a2 < 0 )
{
v7 = abs32(a2 % v2);
memcpy(v4, &v8[v7], v2 - v7);
result = memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - v7), v8, v7);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func15(__int64 a1, int a2)
{
int v2; // ebx
void *v3; // rsp
void *v4; // r14
void *result; // rax
signed int v6; // er13
signed int v7; // er13
_BYTE v8[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = *(_DWORD *)(a1 + 8);
v3 = alloca(v2);
v4 = *(void **)a1;
result = memcpy(v8, *(const void **)a1, v2);
if ( a2 > 0 )
{
v6 = abs32(a2 % v2);
memcpy(v4, &v8[v2 - v6], v6);
result = memcpy((void *)(*(_QWORD *)a1 + v6), v8, *(_DWORD *)(a1 + 8) - v6);
}
else if ( a2 < 0 )
{
v7 = abs32(a2 % v2);
memcpy(v4, &v8[v7], v2 - v7);
result = memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - v7), v8, v7);
}
return result;
}

original_code:
void shiftBitArray(bitArray * a , const int shift){
  bit tmp[a->length];
  memcpy(tmp , a->array, sizeof(bit) * a->length);
  if(shift > 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * (a->length - len)) , sizeof(bit) * len);
   memcpy(a->array + (sizeof(bit) * len) , tmp , sizeof(bit) * (a->length - len));
  }
  else if(shift < 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * len) , sizeof(bit) * (a->length - len));
   memcpy(a->array + (sizeof(bit) * (a->length - len)) , tmp , sizeof(bit) * len);
  }
}

canonical_original_code:
void shiftBitArray(struct array_of_bit *a, int shift){
  unsigned int tmp[-1];
  memcpy(tmp , a->array, sizeof(bit) * a->length);
  if(shift > 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * (a->length - len)) , sizeof(bit) * len);
   memcpy(a->array + (sizeof(bit) * len) , tmp , sizeof(bit) * (a->length - len));
  }
  else if(shift < 0){
   int len = abs(shift % a->length);
   memcpy(a->array , tmp + (sizeof(bit) * len) , sizeof(bit) * (a->length - len));
   memcpy(a->array + (sizeof(bit) * (a->length - len)) , tmp , sizeof(bit) * len);
  }
}

variable_types: shift int

variable_types:
tmp
unsigned int [-1]


mulBitArray

decompiled_code:
void __fastcall mulBitArray(__int64 a1, __int64 *a2, __int64 *a3)
{
int v4; // er15
int v5; // er13
_DWORD *v6; // rbx
__int64 v7; // rcx
__int64 v8; // rax

v4 = getGradeBitArray(a2);
v5 = getGradeBitArray(a3);
v6 = newBitArray(v4 + v5 + 1);
if ( v4 >= 0 )
{
v7 = 0LL;
do
{
if ( *(_BYTE *)(*a2 + v7) == 1 && v5 >= 0 )
{
v8 = 0LL;
do
{
*(_BYTE *)(*(_QWORD *)v6 + v7 + v8) ^= *(_BYTE *)(*a3 + v8);
++v8;
}
while ( v5 + 1 != v8 );
}
++v7;
}
while ( v7 != v4 + 1 );
}
copyBitArray(a1, (__int64)v6);
deleteBitArray(v6);
}

original_code:
void mulBitArray(bitArray *r , const bitArray * a , const bitArray * b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 int l = aG + bG + 1;
 bitArray * tmp = newBitArray(l);
 int i;
 for(i = 0; i <= aG; i++)
 {
  if(a->array[i] == 1)
  {
   int j , c = i;
   for(j = 0; j <= bG; j++)
    tmp->array[c++] ^= b->array[j];
  }
 }
 copyBitArray(r , tmp);
 deleteBitArray(tmp);
}

canonical_original_code:
void mulBitArray(struct array_of_bit *r, struct array_of_bit *a, struct array_of_bit *b){
 int aG = getGradeBitArray(a);
 int bG = getGradeBitArray(b);
 int l = aG + bG + 1;
 struct array_of_bit *tmp = newBitArray(l);
 int i;
 for(i = 0; i <= aG; i++)
 {
  if(a->array[i] == 1)
  {
   int j; int c = i;
   for(j = 0; j <= bG; j++)
    tmp->array[c++] ^= b->array[j];
  }
 }
 copyBitArray(r , tmp);
 deleteBitArray(tmp);
}

variable_types: c int


openFifo

decompiled_code:
__int64 __fastcall openFifo(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) >= 0 )
return openChannel(path);
perror("mkfifo()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) >= 0 )
return openChannel(path);
perror("mkfifo()");
return 0xFFFFFFFFLL;
}

original_code:
int openFifo(const char * pathname){
 unlink(pathname);
 if(mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  return -1;
 }
 return (openChannel(pathname));
}

canonical_original_code:
int openFifo(char *pathname){
 unlink(pathname);
 if(mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  return -1;
 }
 return (openChannel(pathname));
}

variable_types:
pathname
char *


communication

decompiled_code:
__int64 communication()
{
FILE *v0; // rbp
__int64 result; // rax
unsigned int v2; // ebx
int v3; // eax
int v4; // ebx
unsigned __int64 v5; // rcx
bool v6; // zf
char v7[2048]; // [rsp+0h] [rbp-1028h] BYREF
char s[2088]; // [rsp+800h] [rbp-828h] BYREF

v0 = fopen("server_folder/clientMSG.txt", "w+");
if ( v0 )
{
while ( 1 )
{
v3 = readFromPipe((unsigned int)inputChannel, s);
v4 = v3;
if ( v3 == -1 )
{
fclose(v0);
return 5LL;
}
printMsg("Client to server ---> ", s, (unsigned __int16)v3);
v5 = 4LL;
if ( (unsigned __int64)v4 <= 4 )
v5 = v4;
v6 = memcmp(s, "Bye", v5) == 0;
if ( v4 == 3 && v6 )
{
fclose(v0);
return 4LL;
}
fputs(s, v0);
strcpy(v7, "ACK MSG : ");
strncat(v7, s, v4);
v2 = (unsigned __int16)(v4 + 10);
if ( (int)writeInPipe((unsigned int)outputChannel, v7, v2) < 0 )
break;
printMsg("Server to client ---> ", v7, v2);
fputc(10, stderr);
}
fwrite("\n **** communication write error **** \n\n", 1uLL, 0x28uLL, stderr);
fclose(v0);
result = 5LL;
}
else
{
perror("Server txt file ");
result = 5LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
FILE *v0; // rbp
__int64 result; // rax
unsigned int v2; // ebx
int v3; // eax
int v4; // ebx
unsigned __int64 v5; // rcx
bool v6; // zf
char v7[2048]; // [rsp+0h] [rbp-1028h] BYREF
char s[2088]; // [rsp+800h] [rbp-828h] BYREF

v0 = fopen("server_folder/clientMSG.txt", "w+");
if ( v0 )
{
while ( 1 )
{
v3 = readFromPipe((unsigned int)inputChannel, s);
v4 = v3;
if ( v3 == -1 )
{
fclose(v0);
return 5LL;
}
printMsg("Client to server ---> ", s, (unsigned __int16)v3);
v5 = 4LL;
if ( (unsigned __int64)v4 <= 4 )
v5 = v4;
v6 = memcmp(s, "Bye", v5) == 0;
if ( v4 == 3 && v6 )
{
fclose(v0);
return 4LL;
}
fputs(s, v0);
strcpy(v7, "ACK MSG : ");
strncat(v7, s, v4);
v2 = (unsigned __int16)(v4 + 10);
if ( (int)writeInPipe((unsigned int)outputChannel, v7, v2) < 0 )
break;
printMsg("Server to client ---> ", v7, v2);
fputc(10, stderr);
}
fwrite("\n **** communication write error **** \n\n", 1uLL, 0x28uLL, stderr);
fclose(v0);
result = 5LL;
}
else
{
perror("Server txt file ");
result = 5LL;
}
return result;
}

original_code:
serverState communication(){
 char msg[2048];
 int length = 0;
 do{
 encType = cipherSpec.symmetric_cipher;
 fprintf(stderr , "\n< Client message , communication > \n");
 length = receive_and_decrypt(msg);
 if(strncmp(msg , "Bye" , length) == 0 && length == strlen("Bye")){
  fprintf(stderr , "%s" , "Bye");
  encType = PLAIN;
  return CLOSING;
 }
 encType = PLAIN;
 fprintf(stderr , "\n< Server response , communication >\n" );
 encrypt_and_send(msg , length);
 printMsg("" , msg ,(u_int16_t) length);
 }while(1);
}

canonical_original_code:
enum serverState communication(){
 char msg[2048];
 int length = 0;
 do{
 encType = cipherSpec.symmetric_cipher;
 fprintf(stderr , "\n< Client message , communication > \n");
 length = receive_and_decrypt(msg);
 if(strncmp(msg , "Bye" , length) == 0 && length == strlen("Bye")){
  fprintf(stderr , "%s" , "Bye");
  encType = PLAIN;
  return CLOSING;
 }
 encType = PLAIN;
 fprintf(stderr , "\n< Server response , communication >\n" );
 encrypt_and_send(msg , length);
 printMsg("" , msg ,(unsigned int) length);
 }while(1);
}

variable_types:
msg
char [2048]

return_type: enum serverState { WAITING=0, HANDSHAKE=1, AUTHENTICATED=2, COMMUNICATION=3, CLOSING=4, ERROR=5 }


authentication

decompiled_code:
__int64 authentication()
{
return 2LL;
}

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

canonical_original_code:
enum serverState authentication(){
 return AUTHENTICATED;
}

user_defined_types: enum serverState { WAITING=0, HANDSHAKE=1, AUTHENTICATED=2, COMMUNICATION=3, CLOSING=4, ERROR=5 }


keyExchange

decompiled_code:
__int64 keyExchange()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 3LL;
}

canonical_original_code:
enum serverState keyExchange(){
 return COMMUNICATION;
}


original_code:
void ALL5_init(ALL5 *all5){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 all5->reg[0] = temp;
 LFSR_init(&all5->reg[0] , ALL5_reg1 , ALL5_poly1 , ALL5_degree[0]);
 all5->reg[1] = temp;
 LFSR_init(&all5->reg[1] , ALL5_reg2 , ALL5_poly2 , ALL5_degree[1]);
 all5->reg[2] = temp;
 LFSR_init(&all5->reg[2] , ALL5_reg3 , ALL5_poly3 , ALL5_degree[2]);
 all5->reg[3] = temp;
 LFSR_init(&all5->reg[3] , ALL5_reg4 , ALL5_poly4 , ALL5_degree[3]);
 all5->reg[4] = temp;
 LFSR_init(&all5->reg[4] , ALL5_reg5 , ALL5_poly5 , ALL5_degree[4]);
}

canonical_original_code:
void ALL5_init(struct ALL5 *all5){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 all5->reg[0] = temp;
 LFSR_init(&all5->reg[0] , ALL5_reg1 , ALL5_poly1 , ALL5_degree[0]);
 all5->reg[1] = temp;
 LFSR_init(&all5->reg[1] , ALL5_reg2 , ALL5_poly2 , ALL5_degree[1]);
 all5->reg[2] = temp;
 LFSR_init(&all5->reg[2] , ALL5_reg3 , ALL5_poly3 , ALL5_degree[2]);
 all5->reg[3] = temp;
 LFSR_init(&all5->reg[3] , ALL5_reg4 , ALL5_poly4 , ALL5_degree[3]);
 all5->reg[4] = temp;
 LFSR_init(&all5->reg[4] , ALL5_reg5 , ALL5_poly5 , ALL5_degree[4]);
}

variable_types: struct ALL5 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } *


decompiled_code:
__int64 __fastcall ALL5_delete(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = LFSR_delete(v1);
v1 += 24LL;
}
while ( v1 != a1 + 120 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = LFSR_delete(v1);
v1 += 24LL;
}
while ( v1 != a1 + 120 );
return result;
}

original_code:
void ALL5_delete(ALL5 *all5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&all5->reg[i]);
}

canonical_original_code:
void ALL5_delete(struct ALL5 *all5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&all5->reg[i]);
}