decompiled_code:
__int64 __fastcall ALL5_update(__int64 a1)
{
char *v2; // rbx
char v4; // [rsp+Bh] [rbp-1Dh] BYREF
char v5; // [rsp+Ch] [rbp-1Ch]
char v6; // [rsp+Dh] [rbp-1Bh]
char v7; // [rsp+Eh] [rbp-1Ah]
char v8; // [rsp+Fh] [rbp-19h]
char v9; // [rsp+10h] [rbp-18h] BYREF

v2 = &v4;
do
{
*v2 = LFSR_update(a1);
a1 += 24LL;
++v2;
}
while ( v2 != &v9 );
return (unsigned __int8)(v6 & v7) ^ (unsigned __int8)(v8 & v5) ^ (unsigned __int8)(v6 & v5) ^ (unsigned int)(unsigned __int8)(v4 & v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char *v2; // rbx
char v4; // [rsp+Bh] [rbp-1Dh] BYREF
char v5; // [rsp+Ch] [rbp-1Ch]
char v6; // [rsp+Dh] [rbp-1Bh]
char v7; // [rsp+Eh] [rbp-1Ah]
char v8; // [rsp+Fh] [rbp-19h]
char v9; // [rsp+10h] [rbp-18h] BYREF

v2 = &v4;
do
{
*v2 = LFSR_update(a1);
a1 += 24LL;
++v2;
}
while ( v2 != &v9 );
return (unsigned __int8)(v6 & v7) ^ (unsigned __int8)(v8 & v5) ^ (unsigned __int8)(v6 & v5) ^ (unsigned int)(unsigned __int8)(v4 & v7);
}

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

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

variable_types:
out
unsigned int [5]

variable_types:
result
unsigned int


repo: parzio/crypto-secure-communication

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

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = ALL5_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 ALL5_warmUpStream(ALL5 *all5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  ALL5_update(all5);
}

canonical_original_code:
void ALL5_warmUpStream(struct ALL5 *all5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  ALL5_update(all5);
}

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

variable_types:
stream
unsigned int

variable_types: i int

return_type: void


decompiled_code:
void __fastcall ALL5_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++ = ALL5_update(a1);
while ( v3 != (_BYTE *)v4 );
}
}

original_code:
void ALL5_getStream(ALL5 *all5, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = ALL5_update(all5);
}

canonical_original_code:
void ALL5_getStream(struct ALL5 *all5, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = ALL5_update(all5);
}

variable_types:
result
unsigned int *

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


decompiled_code:
__int64 __fastcall ALL5_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 )
{
ALL5_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 ALL5_encrypt(ALL5 *all5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  ALL5_getStream(all5 , 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 ALL5_encrypt(struct ALL5 *all5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  ALL5_getStream(all5 , 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 ALL5_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 )
{
ALL5_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 ALL5_decrypt(ALL5 *all5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  ALL5_getStream(all5 , 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 ALL5_decrypt(struct ALL5 *all5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  ALL5_getStream(all5 , temp , 8);
  unsigned int currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}


decompiled_code:
__int64 __fastcall open_fifo(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) < 0 )
{
perror("mkfifo()");
exit(1);
}
return open_channel(path);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *path)
{
unlink(path);
if ( mkfifo(path, 0x180u) < 0 )
{
perror("mkfifo()");
exit(1);
}
return func10(path);
}

original_code:
int open_fifo(const char * pathname)
{
 unlink(pathname);
 if( mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  exit(1);
 }
 return (open_channel(pathname));
}

canonical_original_code:
int open_fifo(char *pathname)
{
 unlink(pathname);
 if( mkfifo(pathname,0600) < 0 ) {
  perror("mkfifo()");
  exit(1);
 }
 return (open_channel(pathname));
}

variable_types:
pathname
char *

return_type: int


decompiled_code:
__int64 __fastcall wait_connection(int a1)
{
__int64 result; // rax
char *s2; // [rsp+8h] [rbp-10h]

if ( read_msg(a1) == 6 )
result = (unsigned int)-(strncasecmp("Hello!", s2, 6uLL) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 result; // rax
char *s2; // [rsp+8h] [rbp-10h]

if ( func12(a1) == 6 )
result = (unsigned int)-(strncasecmp("Hello!", s2, 6uLL) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int wait_connection(int channel_fd)
{
 ssize_t msg_size;
 u_int8_t * buff;
 if( ((msg_size = read_msg(channel_fd,&buff)) < 0) ||
  (msg_size != strlen("Hello!") ||
  strncasecmp((const char *)"Hello!",(const char *)buff,msg_size)) ) {
  return (-1);
 }
 return (0);
}

canonical_original_code:
int wait_connection(int channel_fd)
{
 long msg_size;
 unsigned int *buff;
 if( ((msg_size = read_msg(channel_fd,&buff)) < 0) ||
  (msg_size != strlen("Hello!") ||
  strncasecmp((char *)"Hello!",(char *)buff,msg_size)) ) {
  return (-1);
 }
 return (0);
}

variable_types:
buff
unsigned int *


decompiled_code:
void __fastcall print_buff(__int64 a1, unsigned __int64 a2)
{
int v3; // ebp
int v4; // ebp
const unsigned __int16 **v5; // r14
unsigned __int8 v6; // di
unsigned __int64 v7; // rbx
int v8; // ebx
unsigned __int64 v9; // r14
int v10; // [rsp+Ch] [rbp-3Ch]

v10 = 0;
if ( a2 )
{
while ( 1 )
{
v7 = v10;
v9 = v10;
v4 = 0;
if ( a2 > v10 )
{
do
{
fprintf(_bss_start, "%02X ", *(unsigned __int8 *)(a1 + v9));
++v4;
++v9;
}
while ( v4 <= 15 && a2 > v9 );
if ( v4 > 15 )
break;
}
do
{
fwrite("-- ", 1uLL, 3uLL, _bss_start);
++v4;
}
while ( v4 <= 15 );
fwrite(" *** ", 1uLL, 5uLL, _bss_start);
if ( a2 > v10 )
goto LABEL_8;
v3 = 0;
LABEL_14:
v8 = v3;
do
{
fputc(46, _bss_start);
++v8;
}
while ( v8 <= 15 );
v3 = 16;
LABEL_17:
v10 += v3;
fputc(10, _bss_start);
if ( v10 >= a2 )
return;
}
fwrite(" *** ", 1uLL, 5uLL, _bss_start);
LABEL_8:
v5 = __ctype_b_loc();
v3 = 0;
do
{
v6 = *(_BYTE *)(a1 + v7);
if ( ((*v5)[v6] & 0x4000) == 0 )
v6 = 46;
fputc(v6, _bss_start);
++v3;
++v7;
}
while ( v3 <= 15 && a2 > v7 );
if ( v3 > 15 )
goto LABEL_17;
goto LABEL_14;
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, unsigned __int64 a2)
{
int v3; // ebp
int v4; // ebp
const unsigned __int16 **v5; // r14
unsigned __int8 v6; // di
unsigned __int64 v7; // rbx
int v8; // ebx
unsigned __int64 v9; // r14
int v10; // [rsp+Ch] [rbp-3Ch]

v10 = 0;
if ( a2 )
{
while ( 1 )
{
v7 = v10;
v9 = v10;
v4 = 0;
if ( a2 > v10 )
{
do
{
fprintf(_bss_start, "%02X ", *(unsigned __int8 *)(a1 + v9));
++v4;
++v9;
}
while ( v4 <= 15 && a2 > v9 );
if ( v4 > 15 )
break;
}
do
{
fwrite("-- ", 1uLL, 3uLL, _bss_start);
++v4;
}
while ( v4 <= 15 );
fwrite(" *** ", 1uLL, 5uLL, _bss_start);
if ( a2 > v10 )
goto LABEL_8;
v3 = 0;
LABEL_14:
v8 = v3;
do
{
fputc(46, _bss_start);
++v8;
}
while ( v8 <= 15 );
v3 = 16;
LABEL_17:
v10 += v3;
fputc(10, _bss_start);
if ( v10 >= a2 )
return;
}
fwrite(" *** ", 1uLL, 5uLL, _bss_start);
LABEL_8:
v5 = __ctype_b_loc();
v3 = 0;
do
{
v6 = *(_BYTE *)(a1 + v7);
if ( ((*v5)[v6] & 0x4000) == 0 )
v6 = 46;
fputc(v6, _bss_start);
++v3;
++v7;
}
while ( v3 <= 15 && a2 > v7 );
if ( v3 > 15 )
goto LABEL_17;
goto LABEL_14;
}
}

original_code:
void print_buff(u_int8_t * buff, size_t buff_size)
{
 int i = 0, j;
 while( i < buff_size ) {
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%02X ",buff[i+j]);
   j++;
  }
  while( j < 16 ) {
   fprintf(stderr,"-- ");
   j++;
  }
  fprintf(stderr," *** ");
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%c",((*__ctype_b_loc ())[(int) ((buff[i+j]))] & (unsigned short int) _ISprint) ? buff[i+j] : '.');
   j++;
  }
  while( j < 16 ) {
   fputc('.',stderr);
   j++;
  }
      i += j;
  fputc('\n',stderr);
 }
}

canonical_original_code:
void print_buff(unsigned int *buff, unsigned long buff_size)
{
 int i = 0; int j;
 while( i < buff_size ) {
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%02X ",buff[i+j]);
   j++;
  }
  while( j < 16 ) {
   fprintf(stderr,"-- ");
   j++;
  }
  fprintf(stderr," *** ");
  j = 0;
  while( ((j + i) < buff_size) && (j < 16) ) {
   fprintf(stderr,"%c",((*__ctype_b_loc ())[(int) ((buff[i+j]))] & (unsigned short) _ISprint) ? buff[i+j] : '.');
   j++;
  }
  while( j < 16 ) {
   fputc('.',stderr);
   j++;
  }
      i += j;
  fputc('\n',stderr);
 }
}


decompiled_code:
int __fastcall open_channel(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

original_code:
int open_channel(const char * pathname)
{
 int fd;
 if( (fd = open(pathname,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

canonical_original_code:
int open_channel(char *pathname)
{
 int fd;
 if( (fd = open(pathname,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

variable_types: fd int


decompiled_code:
int __fastcall close_channel(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
return close(a1);
}

original_code:
void close_channel(int channel_fd)
{
 close(channel_fd);
}


decompiled_code:
ssize_t __fastcall read_msg(int fd, __int64 *a2)
{
ssize_t v2; // rbx
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( read(fd, buf, 2uLL) < 0 )
{
perror("read()");
exit(1);
}
fwrite("Reading size:\n", 1uLL, 0xEuLL, _bss_start);
print_buff((__int64)buf, 2uLL);
if ( buf[0] > 0x7FFu )
{
fwrite("Message too large\n", 1uLL, 0x12uLL, _bss_start);
v2 = -1LL;
}
else
{
v2 = read(fd, &msg_buff_0, (unsigned __int16)buf[0]);
if ( v2 < 0 )
{
perror("read()");
exit(1);
}
*a2 = (__int64)&msg_buff_0;
fwrite("Reading message:\n", 1uLL, 0x11uLL, _bss_start);
print_buff(*a2, (unsigned __int16)buf[0]);
}
return v2;
}

canonical_decompiled_code:
ssize_t __fastcall func12(int fd, __int64 *a2)
{
ssize_t v2; // rbx
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( read(fd, buf, 2uLL) < 0 )
{
perror("read()");
exit(1);
}
fwrite("Reading size:\n", 1uLL, 0xEuLL, _bss_start);
func9((__int64)buf, 2uLL);
if ( buf[0] > 0x7FFu )
{
fwrite("Message too large\n", 1uLL, 0x12uLL, _bss_start);
v2 = -1LL;
}
else
{
v2 = read(fd, &msg_buff_0, (unsigned __int16)buf[0]);
if ( v2 < 0 )
{
perror("read()");
exit(1);
}
*a2 = (__int64)&msg_buff_0;
fwrite("Reading message:\n", 1uLL, 0x11uLL, _bss_start);
func9(*a2, (unsigned __int16)buf[0]);
}
return v2;
}

original_code:
ssize_t read_msg(int channel_fd, u_int8_t ** msg)
{
 ssize_t read_len;
 u_int16_t msg_size;
 static u_int8_t msg_buff[2048];
 if( read(channel_fd,(void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 fprintf(stderr,"Reading size:\n");
 print_buff((u_int8_t *)(&msg_size),sizeof(msg_size));
 if( msg_size >= 2048 ) {
  fprintf(stderr,"Message too large\n");
  return (-1);
 }
 if( (read_len = read(channel_fd,(void *)msg_buff,msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 (*msg) = msg_buff;
 fprintf(stderr,"Reading message:\n");
 print_buff((u_int8_t *)(*msg),msg_size);
 return (read_len);
}

canonical_original_code:
long read_msg(int channel_fd, unsigned int **msg)
{
 long read_len;
 unsigned int msg_size;
 static unsigned int msg_buff[2048];
 if( read(channel_fd,(void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 fprintf(stderr,"Reading size:\n");
 print_buff((unsigned int *)(&msg_size),sizeof(msg_size));
 if( msg_size >= 2048 ) {
  fprintf(stderr,"Message too large\n");
  return (-1);
 }
 if( (read_len = read(channel_fd,(void *)msg_buff,msg_size)) < 0 ) {
  perror("read()");
  exit(1);
 }
 (*msg) = msg_buff;
 fprintf(stderr,"Reading message:\n");
 print_buff((unsigned int *)(*msg),msg_size);
 return (read_len);
}

variable_types:
msg
unsigned int **

return_type: long


decompiled_code:
__int64 __fastcall write_msg(int fd, void *buf, __int16 a3)
{
__int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) < 0 )
{
perror("write()");
exit(1);
}
fwrite("Writing size:\n", 1uLL, 0xEuLL, _bss_start);
print_buff((__int64)bufa, 2uLL);
if ( write(fd, buf, (unsigned __int16)bufa[0]) < 0 )
{
perror("write()");
exit(1);
}
fwrite("Writing message:\n", 1uLL, 0x11uLL, _bss_start);
print_buff((__int64)buf, (unsigned __int16)bufa[0]);
return (unsigned __int16)bufa[0];
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd, void *buf, __int16 a3)
{
__int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) < 0 )
{
perror("write()");
exit(1);
}
fwrite("Writing size:\n", 1uLL, 0xEuLL, _bss_start);
func9((__int64)bufa, 2uLL);
if ( write(fd, buf, (unsigned __int16)bufa[0]) < 0 )
{
perror("write()");
exit(1);
}
fwrite("Writing message:\n", 1uLL, 0x11uLL, _bss_start);
func9((__int64)buf, (unsigned __int16)bufa[0]);
return (unsigned __int16)bufa[0];
}

original_code:
ssize_t write_msg(int channel_fd, const u_int8_t * msg, u_int16_t msg_size)
{
 if( write(channel_fd,(const void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing size:\n");
 print_buff((u_int8_t *)&msg_size,sizeof(msg_size));
 if( write(channel_fd,(const void *)msg,msg_size) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing message:\n");
 print_buff((u_int8_t *)msg,msg_size);
 return (msg_size);
}

canonical_original_code:
long write_msg(int channel_fd, unsigned int *msg, unsigned int msg_size)
{
 if( write(channel_fd,(void *)&msg_size,sizeof(msg_size)) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing size:\n");
 print_buff((unsigned int *)&msg_size,sizeof(msg_size));
 if( write(channel_fd,(void *)msg,msg_size) < 0 ) {
  perror("write()");
  exit(1);
 }
 fprintf(stderr,"Writing message:\n");
 print_buff((unsigned int *)msg,msg_size);
 return (msg_size);
}

variable_types:
msg
unsigned int *


decompiled_code:
__int64 __fastcall write_OK(int a1)
{
return write_msg(a1, "OK", 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return func13(a1, "OK", 2);
}

original_code:
int write_OK(int channel_fd)
{
 return (write_msg(channel_fd,(const u_int8_t *)"OK",strlen("OK")));
}

canonical_original_code:
int write_OK(int channel_fd)
{
 return (write_msg(channel_fd,(unsigned int *)"OK",strlen("OK")));
}


decompiled_code:
__int64 __fastcall write_BYE(int a1)
{
return write_msg(a1, "Bye", 3);
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return func13(a1, "Bye", 3);
}

original_code:
int write_BYE(int channel_fd)
{
 return (write_msg(channel_fd,(const u_int8_t *)"Bye",strlen("Bye")));
}

canonical_original_code:
int write_BYE(int channel_fd)
{
 return (write_msg(channel_fd,(unsigned int *)"Bye",strlen("Bye")));
}


decompiled_code:
__int64 __fastcall read_string(int a1, const char *a2)
{
ssize_t v2; // rbp
size_t v3; // rax
__int64 result; // rax
void *s1; // [rsp+8h] [rbp-20h] BYREF

v2 = read_msg(a1, (__int64 *)&s1);
v3 = strlen(a2);
if ( v3 == v2 )
result = (unsigned int)-(memcmp(s1, a2, v3) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, const char *a2)
{
ssize_t v2; // rbp
size_t v3; // rax
__int64 result; // rax
void *s1; // [rsp+8h] [rbp-20h] BYREF

v2 = func12(a1, (__int64 *)&s1);
v3 = strlen(a2);
if ( v3 == v2 )
result = (unsigned int)-(memcmp(s1, a2, v3) != 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int read_string(int channel_fd, const char * str)
{
 size_t read_len;
 u_int8_t * msg;
  read_len = read_msg(channel_fd,&msg);
 if( (read_len != strlen(str) ) ||
      memcmp(msg,str,strlen(str)) )
  return (-1);
 return (0);
}

canonical_original_code:
int read_string(int channel_fd, char *str)
{
 unsigned long read_len;
 unsigned int *msg;
  read_len = read_msg(channel_fd,&msg);
 if( (read_len != strlen(str) ) ||
      memcmp(msg,str,strlen(str)) )
  return (-1);
 return (0);
}

variable_types:
str
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
__int64 v5; // [rsp+8h] [rbp-20h]

if ( !argv[1] || !argv[2] || !argv[3] )
{
fwrite("server [server->client fifo] [client->server fifo] [password file]\n", 1uLL, 0x43uLL, _bss_start);
exit(1);
}
while ( 1 )
{
fwrite("Opening server->client fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v3 = open_fifo((char *)argv[1]);
fwrite("Opening client->server fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v4 = open_fifo((char *)argv[2]);
fwrite("Waiting connection...\n", 1uLL, 0x16uLL, _bss_start);
if ( (int)wait_connection(v4) < 0 )
{
fwrite("Communication error...\n", 1uLL, 0x17uLL, _bss_start);
}
else
{
write_OK(v3);
read_msg(v4);
fprintf(_bss_start, "%c\n", *(unsigned __int8 *)(v5 + 2));
}
fwrite("Closing connection...\n", 1uLL, 0x16uLL, _bss_start);
write_BYE(v3);
close_channel(v3);
close_channel(v4);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
__int64 v5; // [rsp+8h] [rbp-20h]

if ( !argv[1] || !argv[2] || !argv[3] )
{
fwrite("server [server->client fifo] [client->server fifo] [password file]\n", 1uLL, 0x43uLL, _bss_start);
exit(1);
}
while ( 1 )
{
fwrite("Opening server->client fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v3 = func7((char *)argv[1]);
fwrite("Opening client->server fifo...\n", 1uLL, 0x1FuLL, _bss_start);
v4 = func7((char *)argv[2]);
fwrite("Waiting connection...\n", 1uLL, 0x16uLL, _bss_start);
if ( (int)func8(v4) < 0 )
{
fwrite("Communication error...\n", 1uLL, 0x17uLL, _bss_start);
}
else
{
func14(v3);
func12(v4);
fprintf(_bss_start, "%c\n", *(unsigned __int8 *)(v5 + 2));
}
fwrite("Closing connection...\n", 1uLL, 0x16uLL, _bss_start);
func15(v3);
func11(v3);
func11(v4);
}
}

original_code:
int main(int argc, char ** argv)
{
 int sc_fifo_fd, cs_fifo_fd;
 u_int8_t * buff;
 if( !argv[1] || !argv[2] || !argv[3] ) {
  fprintf(stderr,"server [server->client fifo] [client->server fifo] [password file]\n");
  exit(1);
 }
main_loop:
  fprintf(stderr,"Opening server->client fifo...\n");
  sc_fifo_fd = open_fifo(argv[1]);
  fprintf(stderr,"Opening client->server fifo...\n");
  cs_fifo_fd = open_fifo(argv[2]);
  fprintf(stderr,"Waiting connection...\n");
  if( wait_connection(cs_fifo_fd) < 0 ) {
   fprintf(stderr,"Communication error...\n");
   goto next1;
  }
  write_OK(sc_fifo_fd);
  read_msg(cs_fifo_fd,&buff);
  fprintf(stderr,"%c\n",buff[2]);
next1:
  fprintf(stderr,"Closing connection...\n");
  write_BYE(sc_fifo_fd);
  close_channel(sc_fifo_fd);
  close_channel(cs_fifo_fd);
    goto main_loop ;
next2:
 fprintf(stderr,"Closing connection...\n");
 if( read_string(cs_fifo_fd,"Bye") < 0 ) {
  fprintf(stderr,"Communication error\n");
  goto next2;
 }
 close_channel(sc_fifo_fd);
 close_channel(cs_fifo_fd);
goto main_loop ;
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int sc_fifo_fd; int cs_fifo_fd;
 unsigned int *buff;
 if( !argv[1] || !argv[2] || !argv[3] ) {
  fprintf(stderr,"server [server->client fifo] [client->server fifo] [password file]\n");
  exit(1);
 }
main_loop:
  fprintf(stderr,"Opening server->client fifo...\n");
  sc_fifo_fd = open_fifo(argv[1]);
  fprintf(stderr,"Opening client->server fifo...\n");
  cs_fifo_fd = open_fifo(argv[2]);
  fprintf(stderr,"Waiting connection...\n");
  if( wait_connection(cs_fifo_fd) < 0 ) {
   fprintf(stderr,"Communication error...\n");
   goto next1;
  }
  write_OK(sc_fifo_fd);
  read_msg(cs_fifo_fd,&buff);
  fprintf(stderr,"%c\n",buff[2]);
next1:
  fprintf(stderr,"Closing connection...\n");
  write_BYE(sc_fifo_fd);
  close_channel(sc_fifo_fd);
  close_channel(cs_fifo_fd);
    goto main_loop ;
next2:
 fprintf(stderr,"Closing connection...\n");
 if( read_string(cs_fifo_fd,"Bye") < 0 ) {
  fprintf(stderr,"Communication error\n");
  goto next2;
 }
 close_channel(sc_fifo_fd);
 close_channel(cs_fifo_fd);
goto main_loop ;
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **


openChannel

decompiled_code:
int __fastcall openChannel(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
{
perror("open()");
exit(1);
}
return result;
}

original_code:
int openChannel(const char * path){
 int fd;
 if( (fd = open(path,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

canonical_original_code:
int openChannel(char *path){
 int fd;
 if( (fd = open(path,02)) < 0 ) {
  perror("open()");
  exit(1);
 }
 return (fd);
}

variable_types:
path
char *


closeChannel

decompiled_code:
int __fastcall closeChannel(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
return close(a1);
}

original_code:
void closeChannel(int channel_fd){
 close(channel_fd);
}


readFromPipe

decompiled_code:
__int64 __fastcall readFromPipe(int fd, void *dest)
{
int v2; // eax
unsigned int v3; // ebx
_BYTE v5[2062]; // [rsp+0h] [rbp-828h] BYREF
unsigned __int16 buf[13]; // [rsp+80Eh] [rbp-1Ah] BYREF

if ( read(fd, buf, 2uLL) < 0 )
{
perror("readSize()");
v3 = -1;
}
else if ( buf[0] > 0x7FFu )
{
perror("Message too large\n");
v3 = -1;
}
else
{
v2 = read(fd, v5, buf[0]);
v3 = v2;
if ( v2 < 0 )
{
perror("readMsg()");
v3 = -1;
}
else
{
memcpy(dest, v5, v2);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *dest)
{
int v2; // eax
unsigned int v3; // ebx
_BYTE v5[2062]; // [rsp+0h] [rbp-828h] BYREF
unsigned __int16 buf[13]; // [rsp+80Eh] [rbp-1Ah] BYREF

if ( read(fd, buf, 2uLL) < 0 )
{
perror("readSize()");
v3 = -1;
}
else if ( buf[0] > 0x7FFu )
{
perror("Message too large\n");
v3 = -1;
}
else
{
v2 = read(fd, v5, buf[0]);
v3 = v2;
if ( v2 < 0 )
{
perror("readMsg()");
v3 = -1;
}
else
{
memcpy(dest, v5, v2);
}
}
return v3;
}

original_code:
int readFromPipe(const int in , byte *msg){
 int read_len;
 u_int16_t msg_size;
 if(read(in ,(void *)&msg_size , sizeof(msg_size)) < 0 ) {
  perror("readSize()");
  return -1;
 }
 if( msg_size >= 2048 ) {
  perror("Message too large\n");
  return -1;
 }
 char buffer[2048];
 read_len = read(in , (void *)buffer , msg_size);
 if( read_len < 0 ) {
  perror("readMsg()");
  return -1;
 }
 memcpy(msg, buffer , read_len);
 return read_len;
}

canonical_original_code:
int readFromPipe(int in, unsigned int *msg){
 int read_len;
 unsigned int msg_size;
 if(read(in ,(void *)&msg_size , sizeof(msg_size)) < 0 ) {
  perror("readSize()");
  return -1;
 }
 if( msg_size >= 2048 ) {
  perror("Message too large\n");
  return -1;
 }
 char buffer[2048];
 read_len = read(in , (void *)buffer , msg_size);
 if( read_len < 0 ) {
  perror("readMsg()");
  return -1;
 }
 memcpy(msg, buffer , read_len);
 return read_len;
}

variable_types: in int

variable_types:
buffer
char [2048]


writeInPipe

decompiled_code:
__int64 __fastcall writeInPipe(int fd, void *buf, unsigned __int16 a3)
{
unsigned __int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) >= 0 )
return (unsigned __int16)write(fd, buf, bufa[0]);
perror("writeSize()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf, unsigned __int16 a3)
{
unsigned __int16 bufa[14]; // [rsp+Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
if ( write(fd, bufa, 2uLL) >= 0 )
return (unsigned __int16)write(fd, buf, bufa[0]);
perror("writeSize()");
return 0xFFFFFFFFLL;
}

original_code:
int writeInPipe(const int out , const byte *msg , u_int16_t size){
 if(write(out , (const void *)&size , sizeof(size)) < 0 ) {
  perror("writeSize()");
  return -1;
 }
 u_int16_t written = write(out ,(const void *)msg, size);
 if( written < 0 ) {
  perror("writeMsg()");
  return -1;
 }
 return written;
}

canonical_original_code:
int writeInPipe(int out, unsigned int *msg, unsigned int size){
 if(write(out , (void *)&size , sizeof(size)) < 0 ) {
  perror("writeSize()");
  return -1;
 }
 unsigned int written = write(out ,(const void *)msg, size);
 if( written < 0 ) {
  perror("writeMsg()");
  return -1;
 }
 return written;
}

variable_types: out int

variable_types:
size
unsigned int

variable_types:
written
unsigned int


cipherInit

decompiled_code:
void *__fastcall cipherInit(__int64 a1, const void *a2, int a3, const void *a4, int a5, int a6)
{
size_t v8; // rbp
void *v9; // r14
void *v10; // r13
void *result; // rax

*(_DWORD *)(a1 + 260) = a3;
*(_DWORD *)(a1 + 256) = a5;
v8 = a3;
v9 = malloc(a3);
*(_QWORD *)(a1 + 240) = v9;
v10 = malloc(a5);
*(_QWORD *)(a1 + 248) = v10;
memcpy(v9, a2, v8);
result = memcpy(v10, a4, a5);
if ( a6 == 3 )
{
MAJ5_init(a1 + 120);
MAJ5_keyLoading(a1 + 120, a2, a4);
result = (void *)MAJ5_warmUpStream(a1 + 120, 100LL);
}
else if ( a6 == 2 )
{
ALL5_init(a1);
ALL5_keyLoading(a1, a2, a4);
result = (void *)ALL5_warmUpStream(a1, 100LL);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, const void *a2, int a3, const void *a4, int a5, int a6)
{
size_t v8; // rbp
void *v9; // r14
void *v10; // r13
void *result; // rax

*(_DWORD *)(a1 + 260) = a3;
*(_DWORD *)(a1 + 256) = a5;
v8 = a3;
v9 = malloc(a3);
*(_QWORD *)(a1 + 240) = v9;
v10 = malloc(a5);
*(_QWORD *)(a1 + 248) = v10;
memcpy(v9, a2, v8);
result = memcpy(v10, a4, a5);
if ( a6 == 3 )
{
MAJ5_init(a1 + 120);
MAJ5_keyLoading(a1 + 120, a2, a4);
result = (void *)MAJ5_warmUpStream(a1 + 120, 100LL);
}
else if ( a6 == 2 )
{
ALL5_init(a1);
ALL5_keyLoading(a1, a2, a4);
result = (void *)ALL5_warmUpStream(a1, 100LL);
}
return result;
}

original_code:
void cipherInit(cipher_struct * cipher , const bit * key , const int keyLength , const bit * initVector , const int vectorLength, const EncType encType){
 cipher->keyLength = keyLength;
 cipher->vectorLength = vectorLength;
 cipher->key = malloc(keyLength * sizeof(bit));
 cipher->vector = malloc(vectorLength * sizeof(bit));
 memcpy(cipher->key , key , sizeof(bit) * keyLength);
 memcpy(cipher->vector , initVector , sizeof(bit) * vectorLength);
 if(encType == Cipher_MAJ5)
 {
  MAJ5_init(&cipher->maj5);
  MAJ5_keyLoading(&cipher->maj5 , key , initVector);
  MAJ5_warmUpStream(&cipher->maj5 , 100);
  return;
 }
 if(encType == Cipher_ALL5)
 {
  ALL5_init(&cipher->all5);
  ALL5_keyLoading(&cipher->all5 , key , initVector);
  ALL5_warmUpStream(&cipher->all5 , 100);
  return;
 }
}

canonical_original_code:
void cipherInit(struct cc_ss *cipher, unsigned int *key, int keyLength, unsigned int *initVector, int vectorLength, enum EncType encType){
 cipher->keyLength = keyLength;
 cipher->vectorLength = vectorLength;
 cipher->key = malloc(keyLength * sizeof(bit));
 cipher->vector = malloc(vectorLength * sizeof(bit));
 memcpy(cipher->key , key , sizeof(bit) * keyLength);
 memcpy(cipher->vector , initVector , sizeof(bit) * vectorLength);
 if(encType == Cipher_MAJ5)
 {
  MAJ5_init(&cipher->maj5);
  MAJ5_keyLoading(&cipher->maj5 , key , initVector);
  MAJ5_warmUpStream(&cipher->maj5 , 100);
  return;
 }
 if(encType == Cipher_ALL5)
 {
  ALL5_init(&cipher->all5);
  ALL5_keyLoading(&cipher->all5 , key , initVector);
  ALL5_warmUpStream(&cipher->all5 , 100);
  return;
 }
}

variable_types: struct cc_ss { struct ALL5 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } all5; struct MAJ5 { struct LFSR reg[5]; } maj5; unsigned int *key; unsigned int *vector; unsigned int vectorLength; unsigned int keyLength; } *

variable_types:
key
unsigned int *

variable_types: keyLength int

variable_types:
initVector
unsigned int *

variable_types: vectorLength int

variable_types: enum EncType { Cipher_Bunny24=1, Cipher_MAJ5=3, Cipher_ALL5=2, hash_spongeBunny=4, RSA64=5, RSA512=6, PLAIN=7 }

user_defined_types: struct cc_ss { struct ALL5 all5; struct MAJ5 maj5; unsigned int *key; unsigned int *vector; unsigned int vectorLength; unsigned int keyLength; }


cipherDelete

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

if ( a2 == 3 )
{
MAJ5_delete(a1 + 120);
}
else if ( a2 == 2 )
{
ALL5_delete();
}
v3 = *(void **)(a1 + 240);
if ( v3 )
free(v3);
v4 = *(void **)(a1 + 248);
if ( v4 )
free(v4);
}

original_code:
void cipherDelete(cipher_struct * cipher, const EncType encType){
 if(encType == Cipher_MAJ5)
  MAJ5_delete(&cipher->maj5);
 if(encType == Cipher_ALL5)
  ALL5_delete(&cipher->all5);
 if(cipher->key != ((void *)0))
  free(cipher->key);
 if(cipher->vector != ((void *)0))
  free(cipher->vector);
}

canonical_original_code:
void cipherDelete(struct cc_ss *cipher, enum EncType encType){
 if(encType == Cipher_MAJ5)
  MAJ5_delete(&cipher->maj5);
 if(encType == Cipher_ALL5)
  ALL5_delete(&cipher->all5);
 if(cipher->key != ((void *)0))
  free(cipher->key);
 if(cipher->vector != ((void *)0))
  free(cipher->vector);
}

user_defined_types: enum EncType { Cipher_Bunny24=1, Cipher_MAJ5=3, Cipher_ALL5=2, hash_spongeBunny=4, RSA64=5, RSA512=6, PLAIN=7 }


initStreamChiper

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

*(_DWORD *)(a1 + 312) = a2;
switch ( a2 )
{
case 1:
ALL5_init(a1 + 72);
ALL5_keyLoading(a1 + 72, a3, a4);
result = ALL5_warmUpStream(a1 + 72, 100LL);
break;
case 2:
A51_init();
A51_keyLoading(a1, a3, a4);
result = A51_warmUpStream(a1, 100LL);
break;
case 0:
MAJ5_init(a1 + 192);
MAJ5_keyLoading(a1 + 192, a3, a4);
result = MAJ5_warmUpStream(a1 + 192, 100LL);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

*(_DWORD *)(a1 + 312) = a2;
switch ( a2 )
{
case 1:
ALL5_init(a1 + 72);
ALL5_keyLoading(a1 + 72, a3, a4);
result = ALL5_warmUpStream(a1 + 72, 100LL);
break;
case 2:
A51_init();
A51_keyLoading(a1, a3, a4);
result = A51_warmUpStream(a1, 100LL);
break;
case 0:
MAJ5_init(a1 + 192);
MAJ5_keyLoading(a1 + 192, a3, a4);
result = MAJ5_warmUpStream(a1 + 192, 100LL);
break;
}
return result;
}

original_code:
void initStreamChiper(streamChiper *chiper , streamChiperSuite type , bit *key , bit *initVector){
 chiper->type = type;
 switch(type){
  case Stream_A51 : {
   A51_init(&chiper->a51);
   A51_keyLoading(&chiper->a51 , key , initVector);
   A51_warmUpStream(&chiper->a51 , 100);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_init(&chiper->maj5);
   MAJ5_keyLoading(&chiper->maj5 , key , initVector);
   MAJ5_warmUpStream(&chiper->maj5 , 100);
   break;
  }
  case Stream_ALL5 : {
   ALL5_init(&chiper->all5);
   ALL5_keyLoading(&chiper->all5 , key , initVector);
   ALL5_warmUpStream(&chiper->all5 , 100);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void initStreamChiper(struct streamChiper *chiper, enum streamChiperSuite type, unsigned int *key, unsigned int *initVector){
 chiper->type = type;
 switch(type){
  case Stream_A51 : {
   A51_init(&chiper->a51);
   A51_keyLoading(&chiper->a51 , key , initVector);
   A51_warmUpStream(&chiper->a51 , 100);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_init(&chiper->maj5);
   MAJ5_keyLoading(&chiper->maj5 , key , initVector);
   MAJ5_warmUpStream(&chiper->maj5 , 100);
   break;
  }
  case Stream_ALL5 : {
   ALL5_init(&chiper->all5);
   ALL5_keyLoading(&chiper->all5 , key , initVector);
   ALL5_warmUpStream(&chiper->all5 , 100);
   break;
  }
  default : break;
 }
}

variable_types: struct streamChiper { struct A51 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[3]; } a51; struct ALL5 { struct LFSR reg[5]; } all5; struct MAJ5 { struct LFSR reg[5]; } maj5; enum streamChiperSuite { Stream_MAJ5=0, Stream_ALL5=1, Stream_A51=2 } type; } *

user_defined_types: struct streamChiper { struct A51 a51; struct ALL5 all5; struct MAJ5 maj5; enum streamChiperSuite type; }


deleteStreamChiper

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

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_delete(a1 + 72);
case 2:
return A51_delete();
case 0:
result = MAJ5_delete(a1 + 192);
break;
}
return result;
}

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

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_delete(a1 + 72);
case 2:
return A51_delete();
case 0:
result = MAJ5_delete(a1 + 192);
break;
}
return result;
}

original_code:
void deleteStreamChiper(streamChiper *chiper){
 switch(chiper->type){
  case Stream_A51 : {
   A51_delete(&chiper->a51);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_delete(&chiper->maj5);
   break;
  }
  case Stream_ALL5 : {
   ALL5_delete(&chiper->all5);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void deleteStreamChiper(struct streamChiper *chiper){
 switch(chiper->type){
  case Stream_A51 : {
   A51_delete(&chiper->a51);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_delete(&chiper->maj5);
   break;
  }
  case Stream_ALL5 : {
   ALL5_delete(&chiper->all5);
   break;
  }
  default : break;
 }
}

user_defined_types: enum streamChiperSuite { Stream_MAJ5=0, Stream_ALL5=1, Stream_A51=2 }


encrypt

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

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_encrypt(a1 + 72);
case 2:
return A51_encrypt();
case 0:
result = MAJ5_encrypt(a1 + 192);
break;
}
return result;
}

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

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_encrypt(a1 + 72);
case 2:
return A51_encrypt();
case 0:
result = MAJ5_encrypt(a1 + 192);
break;
}
return result;
}

original_code:
void encrypt(streamChiper *chiper , byte *plaintext, byte *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_encrypt(&chiper->a51, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_encrypt(&chiper->maj5, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_encrypt(&chiper->all5, plaintext, chipertext, (unsigned) length);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void encrypt(struct streamChiper *chiper, unsigned int *plaintext, unsigned int *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_encrypt(&chiper->a51, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_encrypt(&chiper->maj5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_encrypt(&chiper->all5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  default : break;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types: length int


decrypt

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

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_decrypt(a1 + 72);
case 2:
return A51_decrypt();
case 0:
result = MAJ5_decrypt(a1 + 192);
break;
}
return result;
}

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

result = *(unsigned int *)(a1 + 312);
switch ( (_DWORD)result )
{
case 1:
return ALL5_decrypt(a1 + 72);
case 2:
return A51_decrypt();
case 0:
result = MAJ5_decrypt(a1 + 192);
break;
}
return result;
}

original_code:
void decrypt(streamChiper *chiper , byte *plaintext, byte *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_decrypt(&chiper->a51, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_decrypt(&chiper->maj5, plaintext, chipertext, (unsigned) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_decrypt(&chiper->all5, plaintext, chipertext, (unsigned) length);
   break;
  }
  default : break;
 }
}

canonical_original_code:
void decrypt(struct streamChiper *chiper, unsigned int *plaintext, unsigned int *chipertext, int length){
 switch(chiper->type){
  case Stream_A51 : {
   A51_decrypt(&chiper->a51, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_MAJ5 : {
   MAJ5_decrypt(&chiper->maj5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  case Stream_ALL5 : {
   ALL5_decrypt(&chiper->all5, plaintext, chipertext, (unsigned int) length);
   break;
  }
  default : break;
 }
}


decompiled_code:
void __fastcall LFSR_delete(__int64 a1)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)a1;
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)a1;
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
}

original_code:
void LFSR_delete(LFSR *lfsr){
 if(lfsr->reg != ((void *)0))
  free(lfsr->reg);
 if(lfsr->poly != ((void *)0))
  free(lfsr->poly);
}

canonical_original_code:
void LFSR_delete(struct LFSR *lfsr){
 if(lfsr->reg != ((void *)0))
  free(lfsr->reg);
 if(lfsr->poly != ((void *)0))
  free(lfsr->poly);
}

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


decompiled_code:
int __fastcall LFSR_print(__int64 a1)
{
__int64 v2; // rbx

if ( !*(_QWORD *)a1 || !*(_QWORD *)(a1 + 8) || !*(_DWORD *)(a1 + 16) )
return printf("reg empty!!!");
printf("LFSR reg : ");
if ( *(_DWORD *)(a1 + 16) )
{
v2 = 0LL;
do
printf("%d ", *(unsigned __int8 *)(*(_QWORD *)a1 + v2++));
while ( *(_DWORD *)(a1 + 16) > (unsigned int)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v2; // rbx

if ( !*(_QWORD *)a1 || !*(_QWORD *)(a1 + 8) || !*(_DWORD *)(a1 + 16) )
return printf("reg empty!!!");
printf("LFSR reg : ");
if ( *(_DWORD *)(a1 + 16) )
{
v2 = 0LL;
do
printf("%d ", *(unsigned __int8 *)(*(_QWORD *)a1 + v2++));
while ( *(_DWORD *)(a1 + 16) > (unsigned int)v2 );
}
return putchar(10);
}

original_code:
void LFSR_print(LFSR *lfsr){
 if(lfsr->reg == ((void *)0) || lfsr->poly == ((void *)0) || lfsr->degree == 0)
 {
  printf("reg empty!!!");
  return;
 }
 int i = 0;
 printf("LFSR reg : ");
 for(i = 0 ; i < lfsr->degree ; i++)
  printf("%d " , lfsr->reg[i]);
 printf("\n");
}

canonical_original_code:
void LFSR_print(struct LFSR *lfsr){
 if(lfsr->reg == ((void *)0) || lfsr->poly == ((void *)0) || lfsr->degree == 0)
 {
  printf("reg empty!!!");
  return;
 }
 int i = 0;
 printf("LFSR reg : ");
 for(i = 0 ; i < lfsr->degree ; i++)
  printf("%d " , lfsr->reg[i]);
 printf("\n");
}

variable_types: i int


decompiled_code:
__int64 __fastcall LFSR_getBit(_DWORD *a1, unsigned int a2)
{
if ( a1[4] > a2 )
return *(unsigned __int8 *)(*(_QWORD *)a1 + a2);
perror("index of out range");
return **(unsigned __int8 **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, unsigned int a2)
{
if ( a1[4] > a2 )
return *(unsigned __int8 *)(*(_QWORD *)a1 + a2);
perror("index of out range");
return **(unsigned __int8 **)a1;
}

original_code:
bit LFSR_getBit(LFSR *lfsr, unsigned int position){
  if(position < 0 || position >= lfsr->degree)
  {
   perror("index of out range");
   return lfsr->reg[0];
  }
  return lfsr->reg[position];
}

canonical_original_code:
unsigned int LFSR_getBit(struct LFSR *lfsr, unsigned int position){
  if(position < 0 || position >= lfsr->degree)
  {
   perror("index of out range");
   return lfsr->reg[0];
  }
  return lfsr->reg[position];
}

variable_types:
position
unsigned int

return_type: unsigned int


original_code:
bit LFSR_update(LFSR *lfsr){
 unsigned int i;
 bit xored = 0;
 bit output = lfsr->reg[lfsr->degree - 1];
 for(i = 1; i < (lfsr->degree + 1); i++)
 {
  if(lfsr->poly[i] == 1)
   xored ^= lfsr->reg[i - 1];
 }
 rotate(lfsr->reg , -1 , lfsr->degree);
 lfsr->reg[0] = xored;
 return output;
}

canonical_original_code:
unsigned int LFSR_update(struct LFSR *lfsr){
 unsigned int i;
 unsigned int xored = 0;
 unsigned int output = lfsr->reg[lfsr->degree - 1];
 for(i = 1; i < (lfsr->degree + 1); i++)
 {
  if(lfsr->poly[i] == 1)
   xored ^= lfsr->reg[i - 1];
 }
 rotate(lfsr->reg , -1 , lfsr->degree);
 lfsr->reg[0] = xored;
 return output;
}

variable_types:
i
unsigned int

variable_types:
xored
unsigned int

variable_types:
output
unsigned int


decompiled_code:
void __fastcall LFSR_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++ = LFSR_update(a1);
while ( v3 != (_BYTE *)v4 );
}
}

original_code:
void LFSR_getStream(LFSR *lfsr , bit *result, unsigned int stream){
 int i;
 for(i=0; i < stream; i++)
  result[i] = LFSR_update(lfsr);
}

canonical_original_code:
void LFSR_getStream(struct LFSR *lfsr, unsigned int *result, unsigned int stream){
 int i;
 for(i=0; i < stream; i++)
  result[i] = LFSR_update(lfsr);
}

variable_types:
result
unsigned int *

variable_types:
stream
unsigned int


printArray

decompiled_code:
int __fastcall printArray(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx

if ( a2 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx

if ( a2 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

original_code:
void printArray(bit *array, unsigned int x){
 int i;
 for(i=0; i < x; i++)
  printf("%d " , array[i]);
 printf("\n");
}

canonical_original_code:
void printArray(unsigned int *array, unsigned int x){
 int i;
 for(i=0; i < x; i++)
  printf("%d " , array[i]);
 printf("\n");
}

variable_types:
array
unsigned int *

variable_types:
x
unsigned int


arraySum

original_code:
void arraySum(bit *pA , bit *pB , bit *result, unsigned int degree){
 int i;
 for(i = 0; i < degree; i++)
  result[i] = pA[i] ^ pB[i];
}

canonical_original_code:
void arraySum(unsigned int *pA, unsigned int *pB, unsigned int *result, unsigned int degree){
 int i;
 for(i = 0; i < degree; i++)
  result[i] = pA[i] ^ pB[i];
}

variable_types:
pA
unsigned int *

variable_types:
pB
unsigned int *

variable_types:
degree
unsigned int


arrayMul

decompiled_code:
signed __int64 __fastcall arrayMul(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
int v6; // er13
signed __int64 result; // rax
void *v8; // rsp
signed __int64 i; // rdx
int v10; // edi
_BYTE *v11; // rdx
_BYTE v12[32]; // [rsp+0h] [rbp-20h] BYREF

v6 = 2 * a5;
result = 16 * (((unsigned __int64)(unsigned int)(2 * a5) + 15) >> 4);
v8 = alloca(result);
if ( 2 * a5 )
{
result = (signed __int64)v12;
do
*(_BYTE *)result++ = 0;
while ( (_BYTE *)result != &v12[v6] );
}
if ( a5 )
{
for ( i = 0LL; i != a5; ++i )
{
if ( *(_BYTE *)(a2 + i) == 1 )
{
result = i;
do
{
v12[result] ^= *(_BYTE *)(a1 - i + result);
++result;
}
while ( result != i + (unsigned int)a5 );
}
}
v10 = v6 - 1;
if ( v6 - 1 < (unsigned int)a5 )
goto LABEL_19;
}
else
{
v10 = -1;
}
v11 = &v12[v10 - (__int64)a5];
do
{
if ( v11[a5] == 1 && a5 >= 0 )
{
result = a5;
do
{
v11[result] ^= *(_BYTE *)(a3 + result);
--result;
}
while ( (int)result >= 0 );
}
--v10;
--v11;
}
while ( a5 <= (unsigned int)v10 );
if ( a5 )
{
LABEL_19:
result = 0LL;
do
{
*(_BYTE *)(a4 + result) = v12[result];
++result;
}
while ( a5 > (unsigned int)result );
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
int v6; // er13
signed __int64 result; // rax
void *v8; // rsp
signed __int64 i; // rdx
int v10; // edi
_BYTE *v11; // rdx
_BYTE v12[32]; // [rsp+0h] [rbp-20h] BYREF

v6 = 2 * a5;
result = 16 * (((unsigned __int64)(unsigned int)(2 * a5) + 15) >> 4);
v8 = alloca(result);
if ( 2 * a5 )
{
result = (signed __int64)v12;
do
*(_BYTE *)result++ = 0;
while ( (_BYTE *)result != &v12[v6] );
}
if ( a5 )
{
for ( i = 0LL; i != a5; ++i )
{
if ( *(_BYTE *)(a2 + i) == 1 )
{
result = i;
do
{
v12[result] ^= *(_BYTE *)(a1 - i + result);
++result;
}
while ( result != i + (unsigned int)a5 );
}
}
v10 = v6 - 1;
if ( v6 - 1 < (unsigned int)a5 )
goto LABEL_19;
}
else
{
v10 = -1;
}
v11 = &v12[v10 - (__int64)a5];
do
{
if ( v11[a5] == 1 && a5 >= 0 )
{
result = a5;
do
{
v11[result] ^= *(_BYTE *)(a3 + result);
--result;
}
while ( (int)result >= 0 );
}
--v10;
--v11;
}
while ( a5 <= (unsigned int)v10 );
if ( a5 )
{
LABEL_19:
result = 0LL;
do
{
*(_BYTE *)(a4 + result) = v12[result];
++result;
}
while ( a5 > (unsigned int)result );
}
return result;
}

original_code:
void arrayMul(bit *pA , bit *pB , bit *field, bit *result, unsigned int degree){
 bit temp[degree * 2];
 int i;
 for(i = 0; i < degree * 2; i++)
  temp[i] = 0;
 for(i = 0; i < degree; i++)
 {
  if(pB[i] == 1)
  {
   int j;
   int z = i;
   for(j=0; j < degree; j++)
   {
    temp[z] ^= pA[j];
    z++;
   }
  }
 }
 for(i = (degree * 2) - 1; i >= degree; i--)
 {
  if(temp[i] == 1)
  {
   int j = i;
   int z;
   for(z = degree; z >= 0; z--){
    temp[j] ^= field[z];
    j--;
   }
  }
 }
 for(i = 0; i < degree; i++)
  result[i] = temp[i];
}

canonical_original_code:
void arrayMul(unsigned int *pA, unsigned int *pB, unsigned int *field, unsigned int *result, unsigned int degree){
 unsigned int temp[-1];
 int i;
 for(i = 0; i < degree * 2; i++)
  temp[i] = 0;
 for(i = 0; i < degree; i++)
 {
  if(pB[i] == 1)
  {
   int j;
   int z = i;
   for(j=0; j < degree; j++)
   {
    temp[z] ^= pA[j];
    z++;
   }
  }
 }
 for(i = (degree * 2) - 1; i >= degree; i--)
 {
  if(temp[i] == 1)
  {
   int j = i;
   int z;
   for(z = degree; z >= 0; z--){
    temp[j] ^= field[z];
    j--;
   }
  }
 }
 for(i = 0; i < degree; i++)
  result[i] = temp[i];
}

variable_types:
field
unsigned int *

variable_types:
temp
unsigned int [-1]

variable_types: j int

variable_types: z int


arrayToByte

decompiled_code:
__int64 __fastcall arrayToByte(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // r8
__int64 i; // rdx

if ( a3 > 0 )
{
v4 = (unsigned int)a3;
for ( i = 0LL; i != v4; ++i )
*(_BYTE *)(a2 + (int)i / 8) |= *(_BYTE *)(a1 + i);
}
return (unsigned int)(a3 / 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // r8
__int64 i; // rdx

if ( a3 > 0 )
{
v4 = (unsigned int)a3;
for ( i = 0LL; i != v4; ++i )
*(_BYTE *)(a2 + (int)i / 8) |= *(_BYTE *)(a1 + i);
}
return (unsigned int)(a3 / 8);
}

original_code:
int arrayToByte(bit *bits, bit *bytes, int length){
 int i;
 for(i = 0; i < length; i++)
 {
  int j = i / 8;
  bytes[j] |= bits[i];
 }
 return length/8;
}

canonical_original_code:
int arrayToByte(unsigned int *bits, unsigned int *bytes, int length){
 int i;
 for(i = 0; i < length; i++)
 {
  int j = i / 8;
  bytes[j] |= bits[i];
 }
 return length/8;
}

variable_types:
bits
unsigned int *

variable_types:
bytes
unsigned int *

variable_types: length int


rotate

decompiled_code:
__int64 __fastcall rotate(__int64 a1, int a2, unsigned int a3)
{
void *v3; // rsp
__int64 result; // rax
signed int v5; // er9
char *v6; // r9
signed int v7; // esi
signed int v8; // er9
char *v9; // rsi
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

v3 = alloca(16 * (((unsigned __int64)a3 + 15) >> 4));
if ( a2 < 0 )
{
result = (unsigned int)(a2 >> 31);
v7 = abs32(a2);
v8 = a3 - v7;
if ( a3 - v7 >= a3 )
{
v7 = 0;
}
else
{
result = v8;
do
{
*((_BYTE *)&savedregs + result - v8) = *(_BYTE *)(a1 + result);
++result;
}
while ( a3 > (unsigned int)result );
}
if ( v8 )
{
result = 0LL;
v9 = (char *)&savedregs + v7;
do
{
v9[result] = *(_BYTE *)(a1 + result);
++result;
}
while ( v8 != result );
}
LABEL_7:
if ( !a3 )
return result;
goto LABEL_8;
}
result = a2;
if ( a3 <= a2 )
{
if ( a2 <= 0 )
goto LABEL_7;
v5 = 0;
goto LABEL_5;
}
do
{
*((_BYTE *)&savedregs + result - a2) = *(_BYTE *)(a1 + result);
++result;
}
while ( a3 > (unsigned int)result );
v5 = a3 - a2;
if ( a2 > 0 )
{
LABEL_5:
result = 0LL;
v6 = (char *)&savedregs + v5;
do
{
v6[result] = *(_BYTE *)(a1 + result);
++result;
}
while ( a2 > (int)result );
goto LABEL_7;
}
LABEL_8:
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = *((_BYTE *)&savedregs + result);
++result;
}
while ( a3 > (unsigned int)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, unsigned int a3)
{
void *v3; // rsp
__int64 result; // rax
signed int v5; // er9
char *v6; // r9
signed int v7; // esi
signed int v8; // er9
char *v9; // rsi
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

v3 = alloca(16 * (((unsigned __int64)a3 + 15) >> 4));
if ( a2 < 0 )
{
result = (unsigned int)(a2 >> 31);
v7 = abs32(a2);
v8 = a3 - v7;
if ( a3 - v7 >= a3 )
{
v7 = 0;
}
else
{
result = v8;
do
{
*((_BYTE *)&savedregs + result - v8) = *(_BYTE *)(a1 + result);
++result;
}
while ( a3 > (unsigned int)result );
}
if ( v8 )
{
result = 0LL;
v9 = (char *)&savedregs + v7;
do
{
v9[result] = *(_BYTE *)(a1 + result);
++result;
}
while ( v8 != result );
}
LABEL_7:
if ( !a3 )
return result;
goto LABEL_8;
}
result = a2;
if ( a3 <= a2 )
{
if ( a2 <= 0 )
goto LABEL_7;
v5 = 0;
goto LABEL_5;
}
do
{
*((_BYTE *)&savedregs + result - a2) = *(_BYTE *)(a1 + result);
++result;
}
while ( a3 > (unsigned int)result );
v5 = a3 - a2;
if ( a2 > 0 )
{
LABEL_5:
result = 0LL;
v6 = (char *)&savedregs + v5;
do
{
v6[result] = *(_BYTE *)(a1 + result);
++result;
}
while ( a2 > (int)result );
goto LABEL_7;
}
LABEL_8:
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = *((_BYTE *)&savedregs + result);
++result;
}
while ( a3 > (unsigned int)result );
return result;
}

original_code:
void rotate(bit * array, int shift , unsigned int degree){
 bit buffer[degree];
 int i;
 if(shift < 0)
 {
  int j = 0;
  for(i = (degree - abs(shift)) ; i < degree; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0; i < (degree - abs(shift)) ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 else
 {
  int j = 0;
  for(i = shift ; i < degree ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0 ; i < shift ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 for(i=0; i < degree; i++)
  array[i] = buffer[i];
}

canonical_original_code:
void rotate(unsigned int *array, int shift, unsigned int degree){
 unsigned int buffer[-1];
 int i;
 if(shift < 0)
 {
  int j = 0;
  for(i = (degree - abs(shift)) ; i < degree; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0; i < (degree - abs(shift)) ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 else
 {
  int j = 0;
  for(i = shift ; i < degree ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
  for(i = 0 ; i < shift ; i++)
  {
   buffer[j] = array[i];
   j++;
  }
 }
 for(i=0; i < degree; i++)
  array[i] = buffer[i];
}

variable_types: shift int

variable_types:
buffer
unsigned int [-1]

variable_types: i int


inverteArray

decompiled_code:
__int64 __fastcall inverteArray(_BYTE *a1, unsigned int a2)
{
void *v2; // rsp
__int64 v3; // r9
_BYTE *v4; // rax
__int64 result; // rax
__int64 v6; // rcx
__int64 savedregs; // [rsp+0h] [rbp+0h]

v2 = alloca(16 * (((unsigned __int64)a2 + 15) >> 4));
v3 = a2 - 1;
v4 = a1;
do
{
*((_BYTE *)&savedregs + (unsigned int)((_DWORD)a1 + v3 - (_DWORD)v4)) = *v4;
++v4;
}
while ( v4 != &a1[v3 + 1] );
result = 0LL;
do
{
a1[result] = *((_BYTE *)&savedregs + result);
v6 = result++;
}
while ( v6 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, unsigned int a2)
{
void *v2; // rsp
__int64 v3; // r9
_BYTE *v4; // rax
__int64 result; // rax
__int64 v6; // rcx
__int64 savedregs; // [rsp+0h] [rbp+0h]

v2 = alloca(16 * (((unsigned __int64)a2 + 15) >> 4));
v3 = a2 - 1;
v4 = a1;
do
{
*((_BYTE *)&savedregs + (unsigned int)((_DWORD)a1 + v3 - (_DWORD)v4)) = *v4;
++v4;
}
while ( v4 != &a1[v3 + 1] );
result = 0LL;
do
{
a1[result] = *((_BYTE *)&savedregs + result);
v6 = result++;
}
while ( v6 != v3 );
return result;
}

original_code:
void inverteArray(bit *array, unsigned int length){
 int i;
 bit buffer[length];
 length --;
 for(i = 0; i <= length; i++)
  buffer[length - i] = array[i];
 for(i = 0; i <= length; i++)
  array[i] = buffer[i];
}

canonical_original_code:
void inverteArray(unsigned int *array, unsigned int length){
 int i;
 unsigned int buffer[-1];
 length --;
 for(i = 0; i <= length; i++)
  buffer[length - i] = array[i];
 for(i = 0; i <= length; i++)
  array[i] = buffer[i];
}

variable_types:
length
unsigned int


corrHexToBinary

decompiled_code:
__int64 __fastcall corrHexToBinary(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
__int64 v5; // rbx
_BYTE *v6; // rbp
int v7; // ecx
_BYTE *v8; // rdx
char v9; // dl

v2 = strlen(a2);
v3 = 4 * v2 - 1;
result = (unsigned int)(v2 - 1);
if ( (int)result >= 0 )
{
v5 = (int)result;
v6 = (_BYTE *)(v3 + a1);
do
{
v9 = a2[v5];
switch ( v9 )
{
case '0':
LOBYTE(v7) = 0;
break;
case '1':
LOBYTE(v7) = 1;
break;
case '2':
LOBYTE(v7) = 2;
break;
case '3':
LOBYTE(v7) = 3;
break;
case '4':
LOBYTE(v7) = 4;
break;
case '5':
LOBYTE(v7) = 5;
break;
case '6':
LOBYTE(v7) = 6;
break;
case '7':
LOBYTE(v7) = 7;
break;
case '8':
LOBYTE(v7) = 8;
break;
case '9':
LOBYTE(v7) = 9;
break;
case 'A':
LOBYTE(v7) = 10;
break;
case 'B':
LOBYTE(v7) = 11;
break;
case 'C':
LOBYTE(v7) = 12;
break;
case 'D':
LOBYTE(v7) = 13;
break;
case 'E':
LOBYTE(v7) = 14;
break;
case 'F':
LOBYTE(v7) = 15;
break;
case 'a':
LOBYTE(v7) = 10;
break;
case 'b':
LOBYTE(v7) = 11;
break;
case 'c':
LOBYTE(v7) = 12;
break;
case 'd':
LOBYTE(v7) = 13;
break;
case 'e':
LOBYTE(v7) = 14;
break;
case 'f':
LOBYTE(v7) = 15;
break;
default:
printf("error hex for char %c \n\n", (unsigned int)v9);
LOBYTE(v7) = 0;
break;
}
v8 = v6;
LODWORD(result) = 0;
v7 = (unsigned __int8)v7;
do
{
if ( _bittest(&v7, result) )
*v8 = 1;
else
*v8 = 0;
result = (unsigned int)(result + 1);
--v8;
}
while ( (_DWORD)result != 4 );
--v5;
v6 -= 4;
}
while ( (int)v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
__int64 v5; // rbx
_BYTE *v6; // rbp
int v7; // ecx
_BYTE *v8; // rdx
char v9; // dl

v2 = strlen(a2);
v3 = 4 * v2 - 1;
result = (unsigned int)(v2 - 1);
if ( (int)result >= 0 )
{
v5 = (int)result;
v6 = (_BYTE *)(v3 + a1);
do
{
v9 = a2[v5];
switch ( v9 )
{
case '0':
LOBYTE(v7) = 0;
break;
case '1':
LOBYTE(v7) = 1;
break;
case '2':
LOBYTE(v7) = 2;
break;
case '3':
LOBYTE(v7) = 3;
break;
case '4':
LOBYTE(v7) = 4;
break;
case '5':
LOBYTE(v7) = 5;
break;
case '6':
LOBYTE(v7) = 6;
break;
case '7':
LOBYTE(v7) = 7;
break;
case '8':
LOBYTE(v7) = 8;
break;
case '9':
LOBYTE(v7) = 9;
break;
case 'A':
LOBYTE(v7) = 10;
break;
case 'B':
LOBYTE(v7) = 11;
break;
case 'C':
LOBYTE(v7) = 12;
break;
case 'D':
LOBYTE(v7) = 13;
break;
case 'E':
LOBYTE(v7) = 14;
break;
case 'F':
LOBYTE(v7) = 15;
break;
case 'a':
LOBYTE(v7) = 10;
break;
case 'b':
LOBYTE(v7) = 11;
break;
case 'c':
LOBYTE(v7) = 12;
break;
case 'd':
LOBYTE(v7) = 13;
break;
case 'e':
LOBYTE(v7) = 14;
break;
case 'f':
LOBYTE(v7) = 15;
break;
default:
printf("error hex for char %c \n\n", (unsigned int)v9);
LOBYTE(v7) = 0;
break;
}
v8 = v6;
LODWORD(result) = 0;
v7 = (unsigned __int8)v7;
do
{
if ( _bittest(&v7, result) )
*v8 = 1;
else
*v8 = 0;
result = (unsigned int)(result + 1);
--v8;
}
while ( (_DWORD)result != 4 );
--v5;
v6 -= 4;
}
while ( (int)v5 >= 0 );
}
return result;
}

original_code:
void corrHexToBinary(bit * array , char * hex){
 int i, j , index = strlen(hex) * 4 - 1;
 for(i = strlen(hex) - 1; i >= 0; i--)
 {
  u_int8_t num = 0;
  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 : printf("error hex for char %c \n\n" , hex[i]); break;
   }
  for(j = 0; j < 4; j++)
  {
   if(num & (1 << j))
    array[index] = 1;
   else
    array[index] = 0;
   index--;
  }
 }
}

canonical_original_code:
void corrHexToBinary(unsigned int *array, char *hex){
 int i; int j; int index = strlen(hex) * 4 - 1;
 for(i = strlen(hex) - 1; i >= 0; i--)
 {
  unsigned int num = 0;
  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 : printf("error hex for char %c \n\n" , hex[i]); break;
   }
  for(j = 0; j < 4; j++)
  {
   if(num & (1 << j))
    array[index] = 1;
   else
    array[index] = 0;
   index--;
  }
 }
}

variable_types:
hex
char *

variable_types: index int

variable_types:
num
unsigned int


hexToBinary

decompiled_code:
__int64 __fastcall hexToBinary(_BYTE *a1, const char *a2)
{
__int64 result; // rax
__int64 v4; // rbx
int v5; // ecx
_BYTE *v6; // rdx
char v7; // dl

result = (unsigned int)strlen(a2) - 1;
if ( (int)result >= 0 )
{
v4 = (int)result;
do
{
v7 = a2[v4];
switch ( v7 )
{
case '0':
LOBYTE(v5) = 0;
break;
case '1':
LOBYTE(v5) = 1;
break;
case '2':
LOBYTE(v5) = 2;
break;
case '3':
LOBYTE(v5) = 3;
break;
case '4':
LOBYTE(v5) = 4;
break;
case '5':
LOBYTE(v5) = 5;
break;
case '6':
LOBYTE(v5) = 6;
break;
case '7':
LOBYTE(v5) = 7;
break;
case '8':
LOBYTE(v5) = 8;
break;
case '9':
LOBYTE(v5) = 9;
break;
case 'A':
LOBYTE(v5) = 10;
break;
case 'B':
LOBYTE(v5) = 11;
break;
case 'C':
LOBYTE(v5) = 12;
break;
case 'D':
LOBYTE(v5) = 13;
break;
case 'E':
LOBYTE(v5) = 14;
break;
case 'F':
LOBYTE(v5) = 15;
break;
case 'a':
LOBYTE(v5) = 10;
break;
case 'b':
LOBYTE(v5) = 11;
break;
case 'c':
LOBYTE(v5) = 12;
break;
case 'd':
LOBYTE(v5) = 13;
break;
case 'e':
LOBYTE(v5) = 14;
break;
case 'f':
LOBYTE(v5) = 15;
break;
default:
printf("error hex for char %c \n\n", (unsigned int)v7);
LOBYTE(v5) = 0;
break;
}
v6 = a1;
LODWORD(result) = 0;
v5 = (unsigned __int8)v5;
do
{
if ( _bittest(&v5, result) )
*v6 = 1;
else
*v6 = 0;
result = (unsigned int)(result + 1);
++v6;
}
while ( (_DWORD)result != 4 );
--v4;
a1 += 4;
}
while ( (int)v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1, const char *a2)
{
__int64 result; // rax
__int64 v4; // rbx
int v5; // ecx
_BYTE *v6; // rdx
char v7; // dl

result = (unsigned int)strlen(a2) - 1;
if ( (int)result >= 0 )
{
v4 = (int)result;
do
{
v7 = a2[v4];
switch ( v7 )
{
case '0':
LOBYTE(v5) = 0;
break;
case '1':
LOBYTE(v5) = 1;
break;
case '2':
LOBYTE(v5) = 2;
break;
case '3':
LOBYTE(v5) = 3;
break;
case '4':
LOBYTE(v5) = 4;
break;
case '5':
LOBYTE(v5) = 5;
break;
case '6':
LOBYTE(v5) = 6;
break;
case '7':
LOBYTE(v5) = 7;
break;
case '8':
LOBYTE(v5) = 8;
break;
case '9':
LOBYTE(v5) = 9;
break;
case 'A':
LOBYTE(v5) = 10;
break;
case 'B':
LOBYTE(v5) = 11;
break;
case 'C':
LOBYTE(v5) = 12;
break;
case 'D':
LOBYTE(v5) = 13;
break;
case 'E':
LOBYTE(v5) = 14;
break;
case 'F':
LOBYTE(v5) = 15;
break;
case 'a':
LOBYTE(v5) = 10;
break;
case 'b':
LOBYTE(v5) = 11;
break;
case 'c':
LOBYTE(v5) = 12;
break;
case 'd':
LOBYTE(v5) = 13;
break;
case 'e':
LOBYTE(v5) = 14;
break;
case 'f':
LOBYTE(v5) = 15;
break;
default:
printf("error hex for char %c \n\n", (unsigned int)v7);
LOBYTE(v5) = 0;
break;
}
v6 = a1;
LODWORD(result) = 0;
v5 = (unsigned __int8)v5;
do
{
if ( _bittest(&v5, result) )
*v6 = 1;
else
*v6 = 0;
result = (unsigned int)(result + 1);
++v6;
}
while ( (_DWORD)result != 4 );
--v4;
a1 += 4;
}
while ( (int)v4 >= 0 );
}
return result;
}

original_code:
void hexToBinary(bit * array, char * hex){
 int i, j , index = 0;
 for(i = strlen(hex) - 1; i >= 0; i--)
 {
  u_int8_t num = 0;
  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 : printf("error hex for char %c \n\n" , hex[i]); break;
   }
  for(j = 0; j < 4; j++)
  {
   if(num & (1 << j))
    array[index] = 1;
   else
    array[index] = 0;
   index++;
  }
 }
}

canonical_original_code:
void hexToBinary(unsigned int *array, char *hex){
 int i; int j; int index = 0;
 for(i = strlen(hex) - 1; i >= 0; i--)
 {
  unsigned int num = 0;
  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 : printf("error hex for char %c \n\n" , hex[i]); break;
   }
  for(j = 0; j < 4; j++)
  {
   if(num & (1 << j))
    array[index] = 1;
   else
    array[index] = 0;
   index++;
  }
 }
}

variable_types:
array
unsigned int *


printHex

decompiled_code:
int __fastcall printHex(__int64 a1, unsigned int a2)
{
char v2; // r14
int v5; // ebx
void *v6; // rsp
_BYTE *v7; // rax
_BYTE *v8; // rsi
int v9; // edx
__int64 i; // rcx
__int64 v11; // rbx
_BYTE v13[48]; // [rsp+0h] [rbp-30h] BYREF

v5 = (a2 >> 2) + ((a2 & 3) != 0);
v6 = alloca((v5 + 15) & 0xFFFFFFF0);
v7 = memset(v13, 0, v5);
if ( v5 > 0 )
{
v8 = v7;
v9 = 0;
do
{
for ( i = 0LL; i != 4; ++i )
{
if ( a2 > v9 + (int)i )
*v8 |= *(unsigned __int8 *)(a1 + i) << i;
}
++v8;
a1 += 4LL;
v9 += 4;
}
while ( v9 != 4 * v5 );
v11 = v5 - 1;
do
{
switch ( v13[v11] )
{
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 0xA:
v2 = 65;
break;
case 0xB:
v2 = 66;
break;
case 0xC:
v2 = 67;
break;
case 0xD:
v2 = 68;
break;
case 0xE:
v2 = 69;
break;
case 0xF:
v2 = 70;
break;
default:
break;
}
putchar(v2);
--v11;
}
while ( (int)v11 >= 0 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, unsigned int a2)
{
char v2; // r14
int v5; // ebx
void *v6; // rsp
_BYTE *v7; // rax
_BYTE *v8; // rsi
int v9; // edx
__int64 i; // rcx
__int64 v11; // rbx
_BYTE v13[48]; // [rsp+0h] [rbp-30h] BYREF

v5 = (a2 >> 2) + ((a2 & 3) != 0);
v6 = alloca((v5 + 15) & 0xFFFFFFF0);
v7 = memset(v13, 0, v5);
if ( v5 > 0 )
{
v8 = v7;
v9 = 0;
do
{
for ( i = 0LL; i != 4; ++i )
{
if ( a2 > v9 + (int)i )
*v8 |= *(unsigned __int8 *)(a1 + i) << i;
}
++v8;
a1 += 4LL;
v9 += 4;
}
while ( v9 != 4 * v5 );
v11 = v5 - 1;
do
{
switch ( v13[v11] )
{
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 0xA:
v2 = 65;
break;
case 0xB:
v2 = 66;
break;
case 0xC:
v2 = 67;
break;
case 0xD:
v2 = 68;
break;
case 0xE:
v2 = 69;
break;
case 0xF:
v2 = 70;
break;
default:
break;
}
putchar(v2);
--v11;
}
while ( (int)v11 >= 0 );
}
return putchar(10);
}

original_code:
void printHex(bit * array, unsigned int length){
 int i,j;
 int num_of_hex = length / 4 + ((length % 4 != 0) ? 1 : 0);
 unsigned char buffer[num_of_hex];
 memset(buffer , 0 , num_of_hex * sizeof(char));
 for(i = 0; i < num_of_hex; i++)
 {
  for(j = 0; j < 4; j++)
  {
   int index = (i * 4) + j;
   if(index < length)
    buffer[i] |= (array[index] << j);
  }
 }
 char x;
 for(i = num_of_hex - 1; i >= 0 ; i--)
 {
  switch(buffer[i]){
   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;
   }
  printf("%c" , x);
 }
 printf("\n");
}

canonical_original_code:
void printHex(unsigned int *array, unsigned int length){
 int i; int j;
 int num_of_hex = length / 4 + ((length % 4 != 0) ? 1 : 0);
 unsigned char buffer[-1];
 memset(buffer , 0 , num_of_hex * sizeof(char));
 for(i = 0; i < num_of_hex; i++)
 {
  for(j = 0; j < 4; j++)
  {
   int index = (i * 4) + j;
   if(index < length)
    buffer[i] |= (array[index] << j);
  }
 }
 char x;
 for(i = num_of_hex - 1; i >= 0 ; i--)
 {
  switch(buffer[i]){
   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;
   }
  printf("%c" , x);
 }
 printf("\n");
}

variable_types:
buffer
unsigned char [-1]

variable_types: x char


arrayCopy

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

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

original_code:
void arrayCopy(bit * a , bit * b , int length){
 int i;
 for(i = 0; i < length; i++)
  b[i] = a[i];
}

canonical_original_code:
void arrayCopy(unsigned int *a, unsigned int *b, int length){
 int i;
 for(i = 0; i < length; i++)
  b[i] = a[i];
}

variable_types:
a
unsigned int *

variable_types:
b
unsigned int *


arrayEqual

decompiled_code:
__int64 __fastcall arrayEqual(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int arrayEqual(bit *a1 , bit *a2 , unsigned int length){
 int i;
 for(i = 0; i < length; i++)
  if(a1[i] != a2[i])
   return -1;
 return 0;
}

canonical_original_code:
int arrayEqual(unsigned int *a1, unsigned int *a2, unsigned int length){
 int i;
 for(i = 0; i < length; i++)
  if(a1[i] != a2[i])
   return -1;
 return 0;
}


initFPRNG

decompiled_code:
void initFPRNG()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void initFPRNG(){
 srand(time(((void *)0)));
}


FPRNG

decompiled_code:
__int64 __fastcall FPRNG(__int64 a1, int a2)
{
void *v2; // rsp
void *v3; // rsp
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax
char v7[128]; // [rsp+0h] [rbp-1F0h] BYREF
char v8[128]; // [rsp+80h] [rbp-170h] BYREF
char v9[32]; // [rsp+100h] [rbp-F0h] BYREF
char v10[32]; // [rsp+120h] [rbp-D0h] BYREF
char v11[64]; // [rsp+140h] [rbp-B0h] BYREF
char v12[112]; // [rsp+180h] [rbp-70h] BYREF

v2 = alloca(a2);
v3 = alloca(a2);
for ( i = 0LL; i != 64; ++i )
{
v12[i] = -(char)rand();
v11[i] = rand() / 0x3FFFFFFF;
}
for ( j = 0LL; j != 22; ++j )
{
v10[j] = -(char)rand();
v9[j] = rand() / 0x3FFFFFFF;
}
MAJ5_init(v8);
MAJ5_keyLoading(v8, v12, v10);
MAJ5_warmUpStream(v8, 100LL);
MAJ5_getStream(v8, v7, (unsigned int)a2);
MAJ5_delete(v8);
ALL5_init(v7);
ALL5_keyLoading(v7, v11, v9);
ALL5_warmUpStream(v7, 100LL);
ALL5_getStream(v7, v7, (unsigned int)a2);
result = ALL5_delete(v7);
if ( a2 > 0 )
{
for ( result = 0LL; result != a2; *(_BYTE *)(a1 + result++) = 0 )
;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
void *v2; // rsp
void *v3; // rsp
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax
char v7[128]; // [rsp+0h] [rbp-1F0h] BYREF
char v8[128]; // [rsp+80h] [rbp-170h] BYREF
char v9[32]; // [rsp+100h] [rbp-F0h] BYREF
char v10[32]; // [rsp+120h] [rbp-D0h] BYREF
char v11[64]; // [rsp+140h] [rbp-B0h] BYREF
char v12[112]; // [rsp+180h] [rbp-70h] BYREF

v2 = alloca(a2);
v3 = alloca(a2);
for ( i = 0LL; i != 64; ++i )
{
v12[i] = -(char)rand();
v11[i] = rand() / 0x3FFFFFFF;
}
for ( j = 0LL; j != 22; ++j )
{
v10[j] = -(char)rand();
v9[j] = rand() / 0x3FFFFFFF;
}
MAJ5_init(v8);
MAJ5_keyLoading(v8, v12, v10);
MAJ5_warmUpStream(v8, 100LL);
MAJ5_getStream(v8, v7, (unsigned int)a2);
MAJ5_delete(v8);
ALL5_init(v7);
ALL5_keyLoading(v7, v11, v9);
ALL5_warmUpStream(v7, 100LL);
ALL5_getStream(v7, v7, (unsigned int)a2);
result = ALL5_delete(v7);
if ( a2 > 0 )
{
for ( result = 0LL; result != a2; *(_BYTE *)(a1 + result++) = 0 )
;
}
return result;
}

original_code:
void FPRNG(bit * result , int length){
 bit seed1[64] , seed2[64];
 bit init1[22] , init2[22];
 bit maj_buffer[length];
 bit all_buffer[length];
 int i;
 for(i = 0; i < 64; i++){
  seed1[i] = (int) rand() / (int) (2147483647/2);
  seed2[i] = (int) rand() / (int) (2147483647/2);
 }
 for(i = 0; i < 22; i++){
  init1[i] = (int) rand() / (int) (2147483647/2);
  init2[i] = (int) rand() / (int) (2147483647/2);
 }
 MAJ5 maj5;
 MAJ5_init(&maj5);
 MAJ5_keyLoading(&maj5 , seed1 , init1);
 MAJ5_warmUpStream(&maj5 , 100);
 MAJ5_getStream(&maj5, maj_buffer, (unsigned) length);
 MAJ5_delete(&maj5);
 ALL5 all5;
 ALL5_init(&all5);
 ALL5_keyLoading(&all5 , seed2 , init2);
 ALL5_warmUpStream(&all5 , 100);
 ALL5_getStream(&all5, all_buffer , (unsigned) length);
 ALL5_delete(&all5);
 for(i = 0; i < length; i++)
  result[i] = maj_buffer[i] ^ all_buffer[i];
}

canonical_original_code:
void FPRNG(unsigned int *result, int length){
 unsigned int seed1[64]; unsigned int seed2[64];
 unsigned int init1[22]; unsigned int init2[22];
 unsigned int maj_buffer[-1];
 unsigned int all_buffer[-1];
 int i;
 for(i = 0; i < 64; i++){
  seed1[i] = (int) rand() / (int) (2147483647/2);
  seed2[i] = (int) rand() / (int) (2147483647/2);
 }
 for(i = 0; i < 22; i++){
  init1[i] = (int) rand() / (int) (2147483647/2);
  init2[i] = (int) rand() / (int) (2147483647/2);
 }
 struct MAJ5 maj5;
 MAJ5_init(&maj5);
 MAJ5_keyLoading(&maj5 , seed1 , init1);
 MAJ5_warmUpStream(&maj5 , 100);
 MAJ5_getStream(&maj5, maj_buffer, (unsigned int) length);
 MAJ5_delete(&maj5);
 struct ALL5 all5;
 ALL5_init(&all5);
 ALL5_keyLoading(&all5 , seed2 , init2);
 ALL5_warmUpStream(&all5 , 100);
 ALL5_getStream(&all5, all_buffer , (unsigned int) length);
 ALL5_delete(&all5);
 for(i = 0; i < length; i++)
  result[i] = maj_buffer[i] ^ all_buffer[i];
}

variable_types:
result
unsigned int *

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

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


SPRNG

original_code:
void SPRNG(bit * result , int length){
 int cicle = length + (24 - (length % 24));
 bit fseed[cicle * 2];
 bit resul[cicle];
 FPRNG(fseed , cicle * 2);
 int i , end = cicle/24 , p = 0;
 bit key[24] , block[24];
 for(i = 0; i < end; i++)
 {
  int ks = i * 48;
  int ke = ks + 24;
  int bs = ke;
  int be = bs + 24;
  int z = 0 , j;
  for(j = ks; j < ke; j++)
  {
   key[z] = fseed[j];
   z++;
  }
  z = 0;
  for(j = bs; j < be; j++)
  {
   block[z] = fseed[j];
   z++;
  }
  bunny24_encrypt(block , key);
  int rs = i * 24;
  int re = rs + 24;
  z = 0;
  for(j = rs; j < re; j++)
  {
   resul[j] = block[z];
   z++;
  }
 }
 for(i = 0; i < length; i++)
  result[i] = resul[i];
}

canonical_original_code:
void SPRNG(unsigned int *result, int length){
 int cicle = length + (24 - (length % 24));
 unsigned int fseed[-1];
 unsigned int resul[-1];
 FPRNG(fseed , cicle * 2);
 int i; int end = cicle/24; int p = 0;
 unsigned int key[24]; unsigned int block[24];
 for(i = 0; i < end; i++)
 {
  int ks = i * 48;
  int ke = ks + 24;
  int bs = ke;
  int be = bs + 24;
  int z = 0; int j;
  for(j = ks; j < ke; j++)
  {
   key[z] = fseed[j];
   z++;
  }
  z = 0;
  for(j = bs; j < be; j++)
  {
   block[z] = fseed[j];
   z++;
  }
  bunny24_encrypt(block , key);
  int rs = i * 24;
  int re = rs + 24;
  z = 0;
  for(j = rs; j < re; j++)
  {
   resul[j] = block[z];
   z++;
  }
 }
 for(i = 0; i < length; i++)
  result[i] = resul[i];
}

variable_types: cicle int

variable_types:
fseed
unsigned int [-1]

variable_types:
resul
unsigned int [-1]

variable_types: end int

variable_types: p int

variable_types:
key
unsigned int [24]

variable_types:
block
unsigned int [24]

variable_types: ks int

variable_types: ke int

variable_types: bs int

variable_types: be int

variable_types: z int

variable_types: j int

variable_types: rs int

variable_types: re int


spongeBunnyComputeHash

original_code:
void spongeBunnyComputeHash(byte * message , byte hash[160 / 8], int length){
 int i,j;
 memset(hash, 0, 160 / 8 * sizeof(byte));
 int bitLength = length * 8;
 bit bit_message[bitLength];
 for(i = 0; i < bitLength; i++)
  bit_message[i] = (message[i / 8] & (1 << i % 8)) ? 1 : 0;
 bit output[160];
 memset(output, 0, 160 * sizeof(bit));
 int rounds = bitLength/20;
 if(bitLength % 20 != 0)
  rounds++;
 bit input[rounds][20];
 for(i = 0; i < rounds-1; i++)
 {
  for(j = 0; j < 20; j++)
   input[i][j] = bit_message[i*20 +j];
 }
 if((bitLength % 20) == 0 )
 {
  for(j = 0; j < 20; j++)
   input[rounds-1][j] = bit_message[i*20 +j];
 }
 else
 {
  for(j = 0; j < bitLength % 20; j++)
   input[rounds-1][j] = bit_message[(rounds-1)*20 +j];
  for(j = bitLength % 20; j < 20; j++)
   input[rounds-1][j] = 0;
 }
 bit state[24];
 memset(&state, 0, 24 * sizeof(bit));
 for(i = 0;i < rounds; i++)
 {
  for(j = 0; j < 20; j++)
   state[j] ^= input[i][j];
  bunny24_encrypt(state, SPONGE_KEY);
 }
 int roundsSqueeze = 160/20;
 for(i = 0; i < roundsSqueeze; i++)
 {
  for(j = 0; j < 20; j++ )
   output[i*20 + j] = state[j];
  bunny24_encrypt(state, SPONGE_KEY);
 }
  for(i = 0; i < 160; i++)
   hash[i/8] |= (output[i] << (i % 8));
}

canonical_original_code:
void spongeBunnyComputeHash(unsigned int *message, unsigned int hash[-1], int length){
 int i; int j;
 memset(hash, 0, 160 / 8 * sizeof(byte));
 int bitLength = length * 8;
 unsigned int bit_message[-1];
 for(i = 0; i < bitLength; i++)
  bit_message[i] = (message[i / 8] & (1 << i % 8)) ? 1 : 0;
 unsigned int output[160];
 memset(output, 0, 160 * sizeof(bit));
 int rounds = bitLength/20;
 if(bitLength % 20 != 0)
  rounds++;
 unsigned int input[-1][20];
 for(i = 0; i < rounds-1; i++)
 {
  for(j = 0; j < 20; j++)
   input[i][j] = bit_message[i*20 +j];
 }
 if((bitLength % 20) == 0 )
 {
  for(j = 0; j < 20; j++)
   input[rounds-1][j] = bit_message[i*20 +j];
 }
 else
 {
  for(j = 0; j < bitLength % 20; j++)
   input[rounds-1][j] = bit_message[(rounds-1)*20 +j];
  for(j = bitLength % 20; j < 20; j++)
   input[rounds-1][j] = 0;
 }
 unsigned int state[24];
 memset(&state, 0, 24 * sizeof(bit));
 for(i = 0;i < rounds; i++)
 {
  for(j = 0; j < 20; j++)
   state[j] ^= input[i][j];
  bunny24_encrypt(state, SPONGE_KEY);
 }
 int roundsSqueeze = 160/20;
 for(i = 0; i < roundsSqueeze; i++)
 {
  for(j = 0; j < 20; j++ )
   output[i*20 + j] = state[j];
  bunny24_encrypt(state, SPONGE_KEY);
 }
  for(i = 0; i < 160; i++)
   hash[i/8] |= (output[i] << (i % 8));
}

variable_types:
message
unsigned int *

variable_types:
hash
unsigned int [-1]

variable_types: length int

variable_types: i int

variable_types: bitLength int

variable_types:
output
unsigned int [160]

variable_types: rounds int

variable_types:
input
unsigned int [-1][20]

variable_types:
state
unsigned int [24]

variable_types: roundsSqueeze int


original_code:
unsigned long long str2ll(const char *s)
{
 char *str = (char *)s;
 unsigned long long ret = 0;
 long long qen = 1, queue = 10;
 char *end = str + strlen(str) - 1;
 if( *str=='0' && (*(str+1) == 'x' || *(str+1)=='X'))
  str+=2;
 while(end >= str)
 {
  if(*end >= '0' && *end <= '9')
   ret += (*end-'0')*qen;
  else if( *end >= 'a' && *end <= 'f')
   ret += (*end-'a'+10)*qen;
  else if(*end>='A'&&*end<='F')
   ret += (*end-'A'+10)*qen;
  else
   return ret;
  end--;
  qen *= queue;
 }
 return ret;
}

canonical_original_code:
unsigned long long str2ll(char *s)
{
 char *str = (char *)s;
 unsigned long long ret = 0;
 long long qen = 1; long long queue = 10;
 char *end = str + strlen(str) - 1;
 if( *str=='0' && (*(str+1) == 'x' || *(str+1)=='X'))
  str+=2;
 while(end >= str)
 {
  if(*end >= '0' && *end <= '9')
   ret += (*end-'0')*qen;
  else if( *end >= 'a' && *end <= 'f')
   ret += (*end-'a'+10)*qen;
  else if(*end>='A'&&*end<='F')
   ret += (*end-'A'+10)*qen;
  else
   return ret;
  end--;
  qen *= queue;
 }
 return ret;
}

variable_types:
s
char *

variable_types:
str
char *

variable_types:
ret
unsigned long long

variable_types:
qen
long long

variable_types:
queue
long long

variable_types:
end
char *

return_type: unsigned long long


decompiled_code:
void *__fastcall bitmap_creat(unsigned __int64 a1)
{
void *result; // rax

if ( bm )
{
if ( qword_208 >= a1 )
goto LABEL_5;
free(bm);
}
printf("%s:need memory size %dM\n", "bitmap_creat", a1 >> 23);
bm = malloc(a1 >> 3);
if ( !bm )
{
printf("%s:cannot malloc %llu memory\n", "bitmap_creat", a1 >> 3);
exit(0);
}
LABEL_5:
result = memset(bm, 0, a1 >> 3);
qword_208 = a1;
return result;
}

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

if ( bm )
{
if ( qword_208 >= a1 )
goto LABEL_5;
free(bm);
}
printf("%s:need memory size %dM\n", "bitmap_creat", a1 >> 23);
bm = malloc(a1 >> 3);
if ( !bm )
{
printf("%s:cannot malloc %llu memory\n", "bitmap_creat", a1 >> 3);
exit(0);
}
LABEL_5:
result = memset(bm, 0, a1 >> 3);
qword_208 = a1;
return result;
}

original_code:
void bitmap_creat(unsigned long long max_length)
{
 if( !bm.data || (max_length > bm.len) )
 {
  if(bm.data)
   free(bm.data);
  printf("%s:need memory size %dM\n", __FUNCTION__, (int)(max_length>>23));
  bm.data = (unsigned char *)malloc(max_length>>3);
  if(bm.data == ((void *)0))
  {
   printf("%s:cannot malloc %llu memory\n", __FUNCTION__, max_length>>3);
   exit(0);
  }
  bm.len = max_length;
 }
 if( bm.data && (max_length <= bm.len) )
 {
  memset(bm.data, 0, max_length>>3);
  bm.len = max_length;
 }
}


decompiled_code:
__int64 __fastcall bitmap_set(unsigned __int64 a1)
{
__int64 result; // rax
unsigned int v2; // ecx
_BYTE *v3; // rdi
int v4; // esi

result = 0LL;
if ( qword_208 >= a1 )
{
v2 = a1 & 7;
v3 = (char *)bm + (a1 >> 3);
v4 = (unsigned __int8)*v3;
if ( !_bittest(&v4, v2) )
{
*v3 |= 1 << v2;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
__int64 result; // rax
unsigned int v2; // ecx
_BYTE *v3; // rdi
int v4; // esi

result = 0LL;
if ( qword_208 >= a1 )
{
v2 = a1 & 7;
v3 = (char *)bm + (a1 >> 3);
v4 = (unsigned __int8)*v3;
if ( !_bittest(&v4, v2) )
{
*v3 |= 1 << v2;
result = 1LL;
}
}
return result;
}

original_code:
int bitmap_set(unsigned long long offs)
{
 unsigned long long pos = offs/8;
 int bits = offs%8;
 unsigned char *data = (unsigned char *)(bm.data + pos);
 if(offs > bm.len)
  return 0;
 if( *data & (1<<bits))
  return 0;
 *data |= 1<<bits;
 return 1;
}

variable_types:
offs
unsigned long long

variable_types:
pos
unsigned long long

variable_types: bits int

variable_types:
data
unsigned char *


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

result = ((int)*((unsigned __int8 *)bm + (a1 >> 3)) >> (a1 & 7)) & 1;
if ( a2 )
*a2 = result;
return result;
}

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

result = ((int)*((unsigned __int8 *)bm + (a1 >> 3)) >> (a1 & 7)) & 1;
if ( a2 )
*a2 = result;
return result;
}

original_code:
int bitmap_get(unsigned long long offs, int *isIn)
{
 unsigned long long pos = offs/8;
 int bits = offs%8;
 unsigned char *data = (unsigned char *)(bm.data + pos);
 int ret = *data & 1<<bits?1:0;
 if(isIn)
  *isIn = ret;
 return ret;
}

variable_types:
isIn
int *

variable_types: ret int


decompiled_code:
__int64 __fastcall bitmap_setstr(__int64 a1)
{
__int64 v1; // rax

v1 = str2ll(a1 + 1);
return bitmap_set(v1);
}

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

v1 = func0(a1 + 1);
return func2(v1);
}

original_code:
int bitmap_setstr(char *str)
{
 char *_s = str+1;
 unsigned long long tmp = str2ll(_s);
 return bitmap_set(tmp);
}

variable_types:
tmp
unsigned long long


decompiled_code:
__int64 __fastcall bitmap_getstr(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = str2ll(a1 + 1);
return bitmap_get(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = func0(a1 + 1);
return func3(v2, a2);
}

original_code:
int bitmap_getstr(char *str, int *isIn)
{
 char *_s = str+1;
 unsigned long long tmp = str2ll(_s);
 return bitmap_get(tmp, isIn);
}


decompiled_code:
void bitmap_destroy()
{
if ( bm )
{
free(bm);
bm = 0LL;
qword_208 = 0LL;
}
}

canonical_decompiled_code:
void func6()
{
if ( bm )
{
free(bm);
bm = 0LL;
qword_208 = 0LL;
}
}

original_code:
void bitmap_destroy()
{
 if(bm.data)
 {
  free(bm.data);
  bm.data = 0;
  bm.len = 0;
 }
}


repo: passedaway/mem

original_code:
static inline void memnode_free(mem_node_t *mnode)
{
 mnode->seal = 0x5AA5A55A;
 mnode->type = 1;
}

canonical_original_code:
static inline void memnode_free(struct mem_node_s *mnode)
{
 mnode->seal = 0x5AA5A55A;
 mnode->type = 1;
}

variable_types: struct mem_node_s { union { struct queue_s { struct queue_s *prev; struct queue_s *next; } dirty_queue; struct queue_s free_queue; }; unsigned int seal; int size; int type; char *file_name; char *func_name; int line_num; void *data; } *

user_defined_types: struct mem_node_s { union { struct queue_s dirty_queue; struct queue_s free_queue; }; unsigned int seal; int size; int type; char *file_name; char *func_name; int line_num; void *data; }


decompiled_code:
__int64 __fastcall outof_free_queue(__int64 a1, _QWORD *a2)
{
_QWORD *v3; // rdx

if ( *(_QWORD **)(a1 + 24) != a2 )
goto LABEL_2;
v3 = (_QWORD *)a2[1];
if ( v3 != a2 )
{
*(_QWORD *)(a1 + 24) = v3;
LABEL_2:
queue_out(a2);
return 0LL;
}
*(_QWORD *)(a1 + 24) = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
_QWORD *v3; // rdx

if ( *(_QWORD **)(a1 + 24) != a2 )
goto LABEL_2;
v3 = (_QWORD *)a2[1];
if ( v3 != a2 )
{
*(_QWORD *)(a1 + 24) = v3;
LABEL_2:
queue_out(a2);
return 0LL;
}
*(_QWORD *)(a1 + 24) = 0LL;
return 1LL;
}

original_code:
static inline int outof_free_queue(mem_mgr_t *mgr, mem_node_t *outq)
{
 if( outq == mgr->head_free )
 {
  if( mgr->head_free->free_queue.next == (queue_t*)mgr->head_free )
  {
   mgr->head_free = ((void *)0);
   return 1;
  }
  else
   mgr->head_free = (mem_node_t*)outq->free_queue.next;
 }
 queue_out(&outq->free_queue);
 return 0;
}

canonical_original_code:
static inline int outof_free_queue(struct mem_mgr_s *mgr, struct mem_node_s *outq)
{
 if( outq == mgr->head_free )
 {
  if( mgr->head_free->free_queue.next == (struct queue_s *)mgr->head_free )
  {
   mgr->head_free = ((void *)0);
   return 1;
  }
  else
   mgr->head_free = (struct mem_node_s *)outq->free_queue.next;
 }
 queue_out(&outq->free_queue);
 return 0;
}

variable_types: struct mem_mgr_s { int total_size; int free_size; int alocate_size; struct mem_node_s { union { struct queue_s { struct queue_s *prev; struct queue_s *next; } dirty_queue; struct queue_s free_queue; }; unsigned int seal; int size; int type; char *file_name; char *func_name; int line_num; void *data; } *head_dirty; } *

variable_types:
outq
struct mem_node_s *

user_defined_types: struct mem_mgr_s { int total_size; int free_size; int alocate_size; struct mem_node_s *head_dirty; }


original_code:
static inline mem_node_t *memnode_alloc(void *ptr, int size)
{
 mem_node_t *mnode = (mem_node_t*)ptr;
 memset(ptr, 0, sizeof(mem_node_t));
 mnode->type = 0;
 mnode->size = size;
 (mnode)->data = (unsigned char *)(mnode) + (int)&(((mem_node_t*)0)->data) + 4;
 mnode->seal = 0x5AA5A55A;
 return mnode;
}

canonical_original_code:
static inline struct mem_node_s *memnode_alloc(void *ptr, int size)
{
 struct mem_node_s *mnode = (mem_node_t*)ptr;
 memset(ptr, 0, sizeof(mem_node_t));
 mnode->type = 0;
 mnode->size = size;
 (mnode)->data = (unsigned char *)(mnode) + (int)&(((struct mem_node_s *)0)->data) + 4;
 mnode->seal = 0x5AA5A55A;
 return mnode;
}

variable_types:
ptr
void *

variable_types: size int

return_type: struct mem_node_s { union { struct queue_s { struct queue_s *prev; struct queue_s *next; } dirty_queue; struct queue_s free_queue; }; unsigned int seal; int size; int type; char *file_name; char *func_name; int line_num; void *data; } *


original_code:
mem_mgr_t *mem_init(void *ptr, int size)
{
 mem_mgr_t *mgr = ((void *)0);
 if( ptr == ((void *)0) || (size <= (sizeof(mem_mgr_t) + 512)) )
  return ((void *)0);
 mgr = (mem_mgr_t *)ptr;
 mgr->total_size = ((size+3) & (~0x3));
 mgr->free_size = ((size+3) & (~0x3)) - sizeof(mem_mgr_t) - 1 * sizeof(mem_node_t);
 mgr->alocate_size = 0;
 mgr->head_dirty = ((void *)0);
 mgr->head_free = ((void *)0);
 mgr->head_free = memnode_alloc((unsigned char *)ptr + sizeof(mem_mgr_t), mgr->free_size);
 mgr->head_free->type = 1;
 queue_init(&mgr->head_free->free_queue);
 g_mgr = mgr;
 return (mgr->head_free)?mgr:((void *)0);
}

canonical_original_code:
struct mem_mgr_s *mem_init(void *ptr, int size)
{
 struct mem_mgr_s *mgr = ((void *)0);
 if( ptr == ((void *)0) || (size <= (sizeof(mem_mgr_t) + 512)) )
  return ((void *)0);
 mgr = (struct mem_mgr_s *)ptr;
 mgr->total_size = ((size+3) & (~0x3));
 mgr->free_size = ((size+3) & (~0x3)) - sizeof(mem_mgr_t) - 1 * sizeof(mem_node_t);
 mgr->alocate_size = 0;
 mgr->head_dirty = ((void *)0);
 mgr->head_free = ((void *)0);
 mgr->head_free = memnode_alloc((unsigned char *)ptr + sizeof(mem_mgr_t), mgr->free_size);
 mgr->head_free->type = 1;
 queue_init(&mgr->head_free->free_queue);
 g_mgr = mgr;
 return (mgr->head_free)?mgr:((void *)0);
}

return_type: struct mem_mgr_s { int total_size; int free_size; int alocate_size; struct mem_node_s { union { struct queue_s { struct queue_s *prev; struct queue_s *next; } dirty_queue; struct queue_s free_queue; }; unsigned int seal; int size; int type; char *file_name; char *func_name; int line_num; void *data; } *head_dirty; } *


decompiled_code:
__int64 __fastcall mem_deinit(_QWORD *a1)
{
_QWORD *v1; // r12
__int64 v2; // rbp
__int64 v3; // rbx

v1 = a1;
if ( !a1 )
{
v1 = (_QWORD *)g_mgr;
if ( !g_mgr )
return 0xFFFFFFFFLL;
}
g_mgr = 0LL;
v2 = v1[2];
if ( v2 )
{
v3 = v1[2];
do
{
printf(
"MEM_LEAK AT:[%s][%s][%d] size=%d (0x%x) ptr=%p\n",
*(const char **)(v3 + 32),
*(const char **)(v3 + 40),
*(unsigned int *)(v3 + 48),
*(unsigned int *)(v3 + 20),
*(unsigned int *)(v3 + 20),
*(const void **)(v3 + 56));
v3 = *(_QWORD *)(v3 + 8);
}
while ( v2 != v3 );
}
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
return 0LL;
}

original_code:
int mem_deinit(mem_mgr_t *mgr)
{
 if( mgr == ((void *)0) )
  mgr = g_mgr;
 if( mgr == ((void *)0) )
  return -1;
 g_mgr = ((void *)0);
 if( mgr->head_dirty != ((void *)0) )
 {
  queue_t *head, *q;
  mem_node_t *tmp;
  head = &mgr->head_dirty->dirty_queue;
  q = head;
  do{
   tmp = (mem_node_t*)q;
   printf("MEM_LEAK AT:[%s][%s][%d] size=%d (0x%x) ptr=%p\n",
     tmp->file_name, tmp->func_name, tmp->line_num,
     tmp->size, tmp->size, tmp->data );
   q = q->next;
  }while( q != head );
 }
 memset(mgr, 0, sizeof(mem_mgr_t));
 return 0;
}

canonical_original_code:
int mem_deinit(struct mem_mgr_s *mgr)
{
 if( mgr == ((void *)0) )
  mgr = g_mgr;
 if( mgr == ((void *)0) )
  return -1;
 g_mgr = ((void *)0);
 if( mgr->head_dirty != ((void *)0) )
 {
  struct queue_s *head; struct queue_s *q;
  struct mem_node_s *tmp;
  head = &mgr->head_dirty->dirty_queue;
  q = head;
  do{
   tmp = (struct mem_node_s *)q;
   printf("MEM_LEAK AT:[%s][%s][%d] size=%d (0x%x) ptr=%p\n",
     tmp->file_name, tmp->func_name, tmp->line_num,
     tmp->size, tmp->size, tmp->data );
   q = q->next;
  }while( q != head );
 }
 memset(mgr, 0, sizeof(mem_mgr_t));
 return 0;
}

variable_types: struct queue_s { struct queue_s *prev; struct queue_s *next; } *


original_code:
void *mem_malloc(const char *file_name, const char *func_name, const int line_num, mem_mgr_t *mgr, int size)
{
 queue_t *q, *head;
 mem_node_t *mnode, *newnode;
 unsigned char *ptr;
 if( mgr == ((void *)0) )
  mgr = g_mgr;
 if( (size <= 0) || (mgr == ((void *)0)) )
  return ((void *)0);
 if ( mgr->free_size < size )
  return ((void *)0);
 size = ((size+3) & (~0x3));
 if( mgr->head_free )
  head = &mgr->head_free->free_queue;
 else
  return ((void *)0);
 q = head;
 while( q->next != head )
 {
  if( ((mem_node_t*)q)->size < size + sizeof(mem_node_t) )
   q = q->next;
  else
   break;
 }
 {
  mnode = (mem_node_t*)q;
  if( mnode->size < size + sizeof(mem_node_t))
  {
   return ((void *)0);
  }
 }
 ptr = (unsigned char*)mnode->data + mnode->size - size - sizeof(mem_node_t);
 newnode = memnode_alloc(ptr, size);
 newnode->type = 2;
 newnode->seal = 0x55AAAA55;
 newnode->file_name = file_name;
 newnode->func_name = func_name;
 newnode->line_num = line_num;
 mnode->size -= (size + sizeof(mem_node_t));
 if( mnode->size <= 0 )
 {
  if( mnode == mgr->head_free )
  {
   mgr->head_free = ((void *)0);
  }else{
   queue_out((queue_t*)mnode);
   memnode_free(mnode);
  }
 }
 if( mgr->head_dirty == ((void *)0) )
 {
  mgr->head_dirty = newnode;
  queue_init(&newnode->dirty_queue);
 }else
  queue_in(&mgr->head_dirty->dirty_queue, &newnode->dirty_queue);
 mgr->alocate_size += size;
 mgr->free_size -= (size+sizeof(mem_node_t));
 return newnode->data;
}

canonical_original_code:
void *mem_malloc(char *file_name, char *func_name, int line_num, struct mem_mgr_s *mgr, int size)
{
 struct queue_s *q; struct queue_s *head;
 struct mem_node_s *mnode; struct mem_node_s *newnode;
 unsigned char *ptr;
 if( mgr == ((void *)0) )
  mgr = g_mgr;
 if( (size <= 0) || (mgr == ((void *)0)) )
  return ((void *)0);
 if ( mgr->free_size < size )
  return ((void *)0);
 size = ((size+3) & (~0x3));
 if( mgr->head_free )
  head = &mgr->head_free->free_queue;
 else
  return ((void *)0);
 q = head;
 while( q->next != head )
 {
  if( ((struct mem_node_s *)q)->size < size + sizeof(mem_node_t) )
   q = q->next;
  else
   break;
 }
 {
  mnode = (struct mem_node_s *)q;
  if( mnode->size < size + sizeof(mem_node_t))
  {
   return ((void *)0);
  }
 }
 ptr = (unsigned char *)mnode->data + mnode->size - size - sizeof(mem_node_t);
 newnode = memnode_alloc(ptr, size);
 newnode->type = 2;
 newnode->seal = 0x55AAAA55;
 newnode->file_name = file_name;
 newnode->func_name = func_name;
 newnode->line_num = line_num;
 mnode->size -= (size + sizeof(mem_node_t));
 if( mnode->size <= 0 )
 {
  if( mnode == mgr->head_free )
  {
   mgr->head_free = ((void *)0);
  }else{
   queue_out((struct queue_s *)mnode);
   memnode_free(mnode);
  }
 }
 if( mgr->head_dirty == ((void *)0) )
 {
  mgr->head_dirty = newnode;
  queue_init(&newnode->dirty_queue);
 }else
  queue_in(&mgr->head_dirty->dirty_queue, &newnode->dirty_queue);
 mgr->alocate_size += size;
 mgr->free_size -= (size+sizeof(mem_node_t));
 return newnode->data;
}

variable_types:
ptr
unsigned char *

return_type: void *

user_defined_types: struct queue_s { struct queue_s *prev; struct queue_s *next; }


original_code:
void mem_print(mem_mgr_t *mgr)
{
 queue_t *q, *head;
 mem_node_t *tmp;
 if( mgr == ((void *)0) )
  return;
 printf("\n******************************************\n");
 printf("**************** mgr info ****************\n");
 printf("*\ttotal size = %d ( 0x%x )\n*\t"
   "free size = %d ( 0x%x )\n*\t"
   "alocate size = %d ( 0x%x )\n*\t"
   "ptr = %p\n",
   mgr->total_size, mgr->total_size,
   mgr->free_size, mgr->free_size,
   mgr->alocate_size, mgr->alocate_size,
   mgr);
 printf("**************** allocate ****************\n");
 {
  if( mgr->head_dirty != ((void *)0) )
  {
   head = &mgr->head_dirty->dirty_queue;
   q = head;
   do{
    tmp = (mem_node_t*)q;
    printf("*[%s][%s][%d] size=%d (0x%x) ptr=%p  start=%p end=%p\n",
      tmp->file_name, tmp->func_name, tmp->line_num, tmp->size,
      tmp->size, tmp->data ,
      tmp, (unsigned char *)tmp->data + tmp->size);
    q = q->next;
   }while( q != head );
  }else
  {
   printf("*\tNone\n");
  }
 }
 printf("****************   free   ****************\n");
 {
  if ( mgr->head_free != ((void *)0) )
  {
   head = &mgr->head_free->dirty_queue;
   q = head;
   do{
    tmp = (mem_node_t*)q;
    printf("*\tsize=%d (0x%x) ptr=%p start=%p end=%p\n",
      tmp->size, tmp->size, tmp->data,
      tmp, (unsigned char *)tmp->data + tmp->size);
    q = q->next;
   }while( q != head );
  }else{
   printf("*\tNone\n");
  }
 }
 printf("******************************************\n\n");
}

canonical_original_code:
void mem_print(struct mem_mgr_s *mgr)
{
 struct queue_s *q; struct queue_s *head;
 struct mem_node_s *tmp;
 if( mgr == ((void *)0) )
  return;
 printf("\n******************************************\n");
 printf("**************** mgr info ****************\n");
 printf("*\ttotal size = %d ( 0x%x )\n*\t"
   "free size = %d ( 0x%x )\n*\t"
   "alocate size = %d ( 0x%x )\n*\t"
   "ptr = %p\n",
   mgr->total_size, mgr->total_size,
   mgr->free_size, mgr->free_size,
   mgr->alocate_size, mgr->alocate_size,
   mgr);
 printf("**************** allocate ****************\n");
 {
  if( mgr->head_dirty != ((void *)0) )
  {
   head = &mgr->head_dirty->dirty_queue;
   q = head;
   do{
    tmp = (struct mem_node_s *)q;
    printf("*[%s][%s][%d] size=%d (0x%x) ptr=%p  start=%p end=%p\n",
      tmp->file_name, tmp->func_name, tmp->line_num, tmp->size,
      tmp->size, tmp->data ,
      tmp, (unsigned char *)tmp->data + tmp->size);
    q = q->next;
   }while( q != head );
  }else
  {
   printf("*\tNone\n");
  }
 }
 printf("****************   free   ****************\n");
 {
  if ( mgr->head_free != ((void *)0) )
  {
   head = &mgr->head_free->dirty_queue;
   q = head;
   do{
    tmp = (struct mem_node_s *)q;
    printf("*\tsize=%d (0x%x) ptr=%p start=%p end=%p\n",
      tmp->size, tmp->size, tmp->data,
      tmp, (unsigned char *)tmp->data + tmp->size);
    q = q->next;
   }while( q != head );
  }else{
   printf("*\tNone\n");
  }
 }
 printf("******************************************\n\n");
}