main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned __int16 v4; // bp
unsigned int v5; // er14
struct hostent *v6; // rax
struct hostent *v7; // r12
const char *v8; // rsi
__int64 v9; // rbp
struct in_addr **v10; // rbp
struct in_addr *v11; // rax
struct in_addr **v12; // rbp
char *v13; // rax
unsigned int v14; // eax
socklen_t addr_len; // [rsp+8h] [rbp-1C0h] BYREF
unsigned int arg; // [rsp+Ch] [rbp-1BCh] BYREF
struct sockaddr v17; // [rsp+10h] [rbp-1B8h] BYREF
struct sigaction v18; // [rsp+20h] [rbp-1A8h] BYREF
struct sigaction v19; // [rsp+C0h] [rbp-108h] BYREF
unsigned int v20; // [rsp+160h] [rbp-68h] BYREF
__m128i v21; // [rsp+164h] [rbp-64h]
pthread_t th; // [rsp+180h] [rbp-48h] BYREF
pthread_t newthread; // [rsp+188h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+190h] [rbp-38h] BYREF

memset(&v19.sa_mask, 0, 0x90uLL);
v19.sa_handler = (__sighandler_t)handler;
v19.sa_flags = 4;
if ( sigaction(3, &v19, &v18) < 0 )
{
perror("Sigaction quit fail.\n");
goto LABEL_32;
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
perror("Socket not created.\n");
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, 1);
pthread_mutex_init(&mutex, &Attr);
addr.sa_family = 2;
v4 = _bswap_16(5555);
*(_WORD *)addr.sa_data = v4;
v5 = _bswap_32(0);
*(_DWORD *)&addr.sa_data[2] = v5;
printf("htons : %d\n", v4);
printf("htonl : %d\n", v5);
if ( argc == 2 )
{
v6 = gethostbyname(argv[1]);
v7 = v6;
if ( !v6 )
{
perror("Gethostbyname, NULL returned.\n");
goto LABEL_32;
}
printf("Hostinfo->h_name : %s\n", v6->h_name);
v8 = *v7->h_aliases;
if ( v8 )
{
v9 = 1LL;
do
{
printf("Hostinfo->aliases : %s\n", v8);
v8 = v7->h_aliases[v9++];
}
while ( v8 );
}
printf("Hostinfo->h_addrtype : %d\n", (unsigned int)v7->h_addrtype);
printf("Hostinfo->length : %d\n", (unsigned int)v7->h_length);
putchar(10);
v10 = (struct in_addr **)v7->h_addr_list;
v11 = *v10;
if ( *v10 )
{
v12 = v10 + 1;
do
{
v13 = inet_ntoa((struct in_addr)v11->s_addr);
printf("hostinfo->addr_list : %s \n", v13);
v11 = *v12++;
}
while ( v11 );
}
}
if ( bind(v3, &addr, 0x10u) < 0 )
{
perror("Bind failed.\n");
}
else if ( listen(v3, 2) == -1 )
{
if ( (*(_BYTE *)_errno_location() & 9) != 0 )
perror("socket_fd not valid socket.\n");
else
perror("Listen error.\n");
}
else
{
printf("Socket ID is: %d", v3);
do
{
if ( (pthread_mutex_unlock(&mutex) & 1) != 0 )
puts("Mutex not locked.");
arg = accept(v3, &v17, &addr_len);
v20 = arg;
v21 = _mm_loadu_si128((const __m128i *)&v17);
if ( arg == -1 )
perror("accept error.\n");
printf("client accept address : %d \n", v17.sa_family);
printf("after accept ID is: %d.\n", arg);
pthread_mutex_lock(&mutex);
if ( status )
{
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, reader, &arg);
pthread_create(&th, 0LL, (void *(*)(void *))writer, &v20);
}
if ( (pthread_mutex_unlock(&mutex) & 1) != 0 )
puts("Mutex not locked.");
v14 = getpid();
printf("In parent. pid : %d\n", v14);
pthread_mutex_lock(&mutex);
}
while ( status );
pthread_mutex_unlock(&mutex);
pthread_join(newthread, 0LL);
pthread_join(th, 0LL);
}
LABEL_32:
close(v3);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned __int16 v4; // bp
unsigned int v5; // er14
struct hostent *v6; // rax
struct hostent *v7; // r12
const char *v8; // rsi
__int64 v9; // rbp
struct in_addr **v10; // rbp
struct in_addr *v11; // rax
struct in_addr **v12; // rbp
char *v13; // rax
unsigned int v14; // eax
socklen_t addr_len; // [rsp+8h] [rbp-1C0h] BYREF
unsigned int arg; // [rsp+Ch] [rbp-1BCh] BYREF
struct sockaddr v17; // [rsp+10h] [rbp-1B8h] BYREF
struct sigaction v18; // [rsp+20h] [rbp-1A8h] BYREF
struct sigaction v19; // [rsp+C0h] [rbp-108h] BYREF
unsigned int v20; // [rsp+160h] [rbp-68h] BYREF
__m128i v21; // [rsp+164h] [rbp-64h]
pthread_t th; // [rsp+180h] [rbp-48h] BYREF
pthread_t newthread; // [rsp+188h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+190h] [rbp-38h] BYREF

memset(&v19.sa_mask, 0, 0x90uLL);
v19.sa_handler = (__sighandler_t)handler;
v19.sa_flags = 4;
if ( sigaction(3, &v19, &v18) < 0 )
{
perror("Sigaction quit fail.\n");
goto LABEL_32;
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
perror("Socket not created.\n");
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, 1);
pthread_mutex_init(&mutex, &Attr);
addr.sa_family = 2;
v4 = func2(5555);
*(_WORD *)addr.sa_data = v4;
v5 = func3(0);
*(_DWORD *)&addr.sa_data[2] = v5;
printf("htons : %d\n", v4);
printf("htonl : %d\n", v5);
if ( argc == 2 )
{
v6 = gethostbyname(argv[1]);
v7 = v6;
if ( !v6 )
{
perror("Gethostbyname, NULL returned.\n");
goto LABEL_32;
}
printf("Hostinfo->h_name : %s\n", v6->h_name);
v8 = *v7->h_aliases;
if ( v8 )
{
v9 = 1LL;
do
{
printf("Hostinfo->aliases : %s\n", v8);
v8 = v7->h_aliases[v9++];
}
while ( v8 );
}
printf("Hostinfo->h_addrtype : %d\n", (unsigned int)v7->h_addrtype);
printf("Hostinfo->length : %d\n", (unsigned int)v7->h_length);
putchar(10);
v10 = (struct in_addr **)v7->h_addr_list;
v11 = *v10;
if ( *v10 )
{
v12 = v10 + 1;
do
{
v13 = inet_ntoa((struct in_addr)v11->s_addr);
printf("hostinfo->addr_list : %s \n", v13);
v11 = *v12++;
}
while ( v11 );
}
}
if ( bind(v3, &addr, 0x10u) < 0 )
{
perror("Bind failed.\n");
}
else if ( listen(v3, 2) == -1 )
{
if ( (*(_BYTE *)_errno_location() & 9) != 0 )
perror("socket_fd not valid socket.\n");
else
perror("Listen error.\n");
}
else
{
printf("Socket ID is: %d", v3);
do
{
if ( (pthread_mutex_unlock(&mutex) & 1) != 0 )
puts("Mutex not locked.");
arg = accept(v3, &v17, &addr_len);
v20 = arg;
v21 = _mm_loadu_si128((const __m128i *)&v17);
if ( arg == -1 )
perror("accept error.\n");
printf("client accept address : %d \n", v17.sa_family);
printf("after accept ID is: %d.\n", arg);
pthread_mutex_lock(&mutex);
if ( status )
{
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, reader, &arg);
pthread_create(&th, 0LL, (void *(*)(void *))writer, &v20);
}
if ( (pthread_mutex_unlock(&mutex) & 1) != 0 )
puts("Mutex not locked.");
v14 = getpid();
printf("In parent. pid : %d\n", v14);
pthread_mutex_lock(&mutex);
}
while ( status );
pthread_mutex_unlock(&mutex);
pthread_join(newthread, 0LL);
pthread_join(th, 0LL);
}
LABEL_32:
close(v3);
exit(0);
}

original_code:
int main (int argc, char* const argv[])
{
 int i,ret;
 int socket_fd;
 struct sockaddr_in name;
 struct hostent* hostinfo;
 struct hostent* clientinfo;
 struct in_addr **addr_list;
 struct in_addr addr;
 int client_sent_quit_message = 0;
 pid_t pid1;
 pthread_t tid1,tid2;
 packet data;
 struct sigaction act,old_act;
 memset(&act,'\0',sizeof(act));
 act.__sigaction_handler.sa_sigaction = &handler;
 act.sa_flags = 4;
 if(sigaction(3,&act,(void *)&old_act) < 0)
 {
  perror("Sigaction quit fail.\n");
  goto out;
 }
 socket_fd = socket (2, SOCK_STREAM, 0);
 if(socket_fd == -1)
 {
  perror("Socket not created.\n");
 }
 memset(&name,0,sizeof(name));
 pthread_mutexattr_init(&Attr);
 pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE);
 pthread_mutex_init(&mutex, &Attr);
 name.sin_family = 2;
 name.sin_port = htons(5555);
 name.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 printf("htons : %d\n",htons(5555));
 printf("htonl : %d\n",htonl(((in_addr_t) 0x00000000)));
 if(argc == 2)
 {
  hostinfo = gethostbyname (argv[1]);
  if(!hostinfo)
  {
   perror("Gethostbyname, NULL returned.\n");
   goto out;
  }
  printf("Hostinfo->h_name : %s\n",hostinfo->h_name);
  for(i=0 ; hostinfo->h_aliases[i] != ((void *)0) ; i++)
  printf("Hostinfo->aliases : %s\n",hostinfo->h_aliases[i]);
  printf("Hostinfo->h_addrtype : %d\n",hostinfo->h_addrtype);
  printf("Hostinfo->length : %d\n",hostinfo->h_length);
  printf("\n");
  addr_list = (struct in_addr **)hostinfo->h_addr_list;
  for(i = 0; addr_list[i] != ((void *)0); i++) {
    printf("hostinfo->addr_list : %s \n", inet_ntoa(*addr_list[i]));
  }
 }
 if(bind(socket_fd, (struct sockaddr *)&name, sizeof(name)) < 0)
 {
  perror("Bind failed.\n");
  goto out;
 }
 if(listen(socket_fd,2) == -1)
 {
  if((*__errno_location ()) & 9)
   perror("socket_fd not valid socket.\n");
  else
   perror("Listen error.\n");
  goto out;
 }
 printf("Socket ID is: %d",socket_fd);
 do{
  ret = pthread_mutex_unlock(&mutex);
  if(ret & 1)
  {
   printf("Mutex not locked.\n");
  }
  struct sockaddr client_name;
  socklen_t client_name_len;
  int client_socket_fd;
  client_socket_fd = accept(socket_fd, &client_name, &client_name_len);
  data.socket_fd = client_socket_fd;
  data.client_name = client_name;
  if(client_socket_fd == -1)
  {
   perror("accept error.\n");
  }
  printf("client accept address : %d \n",client_name.sa_family);
  printf("after accept ID is: %d.\n",client_socket_fd);
  pthread_mutex_lock(&mutex);
  if(status)
  {
   pthread_mutex_unlock(&mutex);
   pthread_create(&tid1,((void *)0),&reader,(void *)&client_socket_fd);
   pthread_create(&tid2,((void *)0),&writer,(void *)&data);
  }
  ret = pthread_mutex_unlock(&mutex);
  if(ret & 1)
  {
   printf("Mutex not locked.\n");
  }
  printf("In parent. pid : %d\n",getpid());
  pthread_mutex_lock(&mutex);
 }while (status);
 pthread_mutex_unlock(&mutex);
 pthread_join(tid1,((void *)0));
 pthread_join(tid2,((void *)0));
out:
    close (socket_fd);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i; int ret;
 int socket_fd;
 struct sockaddr_in name;
 struct hostent *hostinfo;
 struct hostent *clientinfo;
 struct in_addr **addr_list;
 struct in_addr addr;
 int client_sent_quit_message = 0;
 int pid1;
 unsigned long tid1; unsigned long tid2;
 struct packet data;
 struct sigaction act; struct sigaction old_act;
 memset(&act,'\0',sizeof(act));
 act.__sigaction_handler.sa_sigaction = &handler;
 act.sa_flags = 4;
 if(sigaction(3,&act,(void *)&old_act) < 0)
 {
  perror("Sigaction quit fail.\n");
  goto out;
 }
 socket_fd = socket (2, SOCK_STREAM, 0);
 if(socket_fd == -1)
 {
  perror("Socket not created.\n");
 }
 memset(&name,0,sizeof(name));
 pthread_mutexattr_init(&Attr);
 pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE);
 pthread_mutex_init(&mutex, &Attr);
 name.sin_family = 2;
 name.sin_port = htons(5555);
 name.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 printf("htons : %d\n",htons(5555));
 printf("htonl : %d\n",htonl(((unsigned int) 0x00000000)));
 if(argc == 2)
 {
  hostinfo = gethostbyname (argv[1]);
  if(!hostinfo)
  {
   perror("Gethostbyname, NULL returned.\n");
   goto out;
  }
  printf("Hostinfo->h_name : %s\n",hostinfo->h_name);
  for(i=0 ; hostinfo->h_aliases[i] != ((void *)0) ; i++)
  printf("Hostinfo->aliases : %s\n",hostinfo->h_aliases[i]);
  printf("Hostinfo->h_addrtype : %d\n",hostinfo->h_addrtype);
  printf("Hostinfo->length : %d\n",hostinfo->h_length);
  printf("\n");
  addr_list = (struct in_addr **)hostinfo->h_addr_list;
  for(i = 0; addr_list[i] != ((void *)0); i++) {
    printf("hostinfo->addr_list : %s \n", inet_ntoa(*addr_list[i]));
  }
 }
 if(bind(socket_fd, (struct sockaddr *)&name, sizeof(name)) < 0)
 {
  perror("Bind failed.\n");
  goto out;
 }
 if(listen(socket_fd,2) == -1)
 {
  if((*__errno_location ()) & 9)
   perror("socket_fd not valid socket.\n");
  else
   perror("Listen error.\n");
  goto out;
 }
 printf("Socket ID is: %d",socket_fd);
 do{
  ret = pthread_mutex_unlock(&mutex);
  if(ret & 1)
  {
   printf("Mutex not locked.\n");
  }
  struct sockaddr client_name;
  unsigned int client_name_len;
  int client_socket_fd;
  client_socket_fd = accept(socket_fd, &client_name, &client_name_len);
  data.socket_fd = client_socket_fd;
  data.client_name = client_name;
  if(client_socket_fd == -1)
  {
   perror("accept error.\n");
  }
  printf("client accept address : %d \n",client_name.sa_family);
  printf("after accept ID is: %d.\n",client_socket_fd);
  pthread_mutex_lock(&mutex);
  if(status)
  {
   pthread_mutex_unlock(&mutex);
   pthread_create(&tid1,((void *)0),&reader,(void *)&client_socket_fd);
   pthread_create(&tid2,((void *)0),&writer,(void *)&data);
  }
  ret = pthread_mutex_unlock(&mutex);
  if(ret & 1)
  {
   printf("Mutex not locked.\n");
  }
  printf("In parent. pid : %d\n",getpid());
  pthread_mutex_lock(&mutex);
 }while (status);
 pthread_mutex_unlock(&mutex);
 pthread_join(tid1,((void *)0));
 pthread_join(tid2,((void *)0));
out:
    close (socket_fd);
 exit(0);
}

variable_types: argc int

variable_types: i int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: struct in_addr { unsigned int s_addr; } **

variable_types:
addr
struct in_addr { unsigned int s_addr; }

variable_types: struct packet { int socket_fd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } client_name; }

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


handler

decompiled_code:
void __fastcall handler(char a1)
{
unsigned int v1; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

stat_loc = 0;
if ( (a1 & 3) != 0 )
{
puts("\b\bSIGQUIT is called.");
}
else if ( (a1 & 2) != 0 )
{
puts("\b\bSIGINT is called.");
}
else if ( (a1 & 0x11) != 0 )
{
while ( 1 )
{
v1 = waitpid(-1, &stat_loc, 1);
if ( v1 == -1 )
{
perror("waitpid");
exit(1);
}
printf("> waitpid : %d\n", v1);
if ( (stat_loc & 0x7F) == 0 )
{
printf("exited, status=%d\n", BYTE1(stat_loc));
goto LABEL_10;
}
if ( !__OFSUB__((stat_loc & 0x7F) + 1, 1) && (stat_loc & 0x7F) != 0 )
break;
if ( (_BYTE)stat_loc == 127 )
{
printf("stopped by signal %d\n", BYTE1(stat_loc));
LABEL_10:
if ( (stat_loc & 0x7F) == 0 || (char)((stat_loc & 0x7F) + 1) > 1 )
goto LABEL_6;
}
else if ( stat_loc == 0xFFFF )
{
puts("continued");
goto LABEL_10;
}
}
printf("killed by signal %d\n", stat_loc & 0x7F);
goto LABEL_10;
}
LABEL_6:
status = 0;
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
unsigned int v1; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

stat_loc = 0;
if ( (a1 & 3) != 0 )
{
puts("\b\bSIGQUIT is called.");
}
else if ( (a1 & 2) != 0 )
{
puts("\b\bSIGINT is called.");
}
else if ( (a1 & 0x11) != 0 )
{
while ( 1 )
{
v1 = waitpid(-1, &stat_loc, 1);
if ( v1 == -1 )
{
perror("waitpid");
exit(1);
}
printf("> waitpid : %d\n", v1);
if ( (stat_loc & 0x7F) == 0 )
{
printf("exited, status=%d\n", BYTE1(stat_loc));
goto LABEL_10;
}
if ( !__OFSUB__((stat_loc & 0x7F) + 1, 1) && (stat_loc & 0x7F) != 0 )
break;
if ( (_BYTE)stat_loc == 127 )
{
printf("stopped by signal %d\n", BYTE1(stat_loc));
LABEL_10:
if ( (stat_loc & 0x7F) == 0 || (char)((stat_loc & 0x7F) + 1) > 1 )
goto LABEL_6;
}
else if ( stat_loc == 0xFFFF )
{
puts("continued");
goto LABEL_10;
}
}
printf("killed by signal %d\n", stat_loc & 0x7F);
goto LABEL_10;
}
LABEL_6:
status = 0;
}

original_code:
static void handler (int sig, siginfo_t *siginfo, void *context)
{
 int stat = 0;
 if(sig & 3)
 {
  printf("\b\bSIGQUIT is called.\n");
 }
 else if(sig & 2)
 {
  printf("\b\bSIGINT is called.\n");
 }
 else if(sig & 17)
 {
 do {
  pid_t pid;
  pid = waitpid(-1, &stat, 1);
  if (pid == -1) {
   perror("waitpid");
   exit(1);
  }
  printf("> waitpid : %d\n",pid);
  if ((((stat) & 0x7f) == 0)) {
   printf("exited, status=%d\n", (((stat) & 0xff00) >> 8));
  } else if ((((signed char) (((stat) & 0x7f) + 1) >> 1) > 0)) {
   printf("killed by signal %d\n", ((stat) & 0x7f));
  } else if ((((stat) & 0xff) == 0x7f)) {
   printf("stopped by signal %d\n", (((stat) & 0xff00) >> 8));
  } else if (((stat) == 0xffff)) {
   printf("continued\n");
  }
    } while (!(((stat) & 0x7f) == 0) && !(((signed char) (((stat) & 0x7f) + 1) >> 1) > 0));
 }
 status = 0;
}

canonical_original_code:
static void handler(int sig, struct siginfo_t *siginfo, void *context)
{
 int stat = 0;
 if(sig & 3)
 {
  printf("\b\bSIGQUIT is called.\n");
 }
 else if(sig & 2)
 {
  printf("\b\bSIGINT is called.\n");
 }
 else if(sig & 17)
 {
 do {
  int pid;
  pid = waitpid(-1, &stat, 1);
  if (pid == -1) {
   perror("waitpid");
   exit(1);
  }
  printf("> waitpid : %d\n",pid);
  if ((((stat) & 0x7f) == 0)) {
   printf("exited, status=%d\n", (((stat) & 0xff00) >> 8));
  } else if ((((char) (((stat) & 0x7f) + 1) >> 1) > 0)) {
   printf("killed by signal %d\n", ((stat) & 0x7f));
  } else if ((((stat) & 0xff) == 0x7f)) {
   printf("stopped by signal %d\n", (((stat) & 0xff00) >> 8));
  } else if (((stat) == 0xffff)) {
   printf("continued\n");
  }
    } while (!(((stat) & 0x7f) == 0) && !(((char) (((stat) & 0x7f) + 1) >> 1) > 0));
 }
 status = 0;
}

variable_types: sig int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
context
void *

variable_types: stat int

variable_types: pid int

return_type: void

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 __fastcall write_text(int fd, void *buf, int a3)
{
int bufa[4]; // [rsp+Ch] [rbp-2Ch] BYREF
int v5[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
v5[0] = strlen((const char *)buf) + 1;
write(fd, bufa, 4uLL);
write(fd, v5, 4uLL);
write(fd, buf, v5[0]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, void *buf, int a3)
{
int bufa[4]; // [rsp+Ch] [rbp-2Ch] BYREF
int v5[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

bufa[0] = a3;
v5[0] = strlen((const char *)buf) + 1;
write(fd, bufa, 4uLL);
write(fd, v5, 4uLL);
write(fd, buf, v5[0]);
return 1LL;
}

original_code:
int write_text (int socket_fd, const char* text,int header)
{
 int length = strlen (text) + 1;
 write (socket_fd, &header, sizeof (header));
 write (socket_fd, &length, sizeof (length));
 write (socket_fd, text, length);
 return 1;
}

canonical_original_code:
int write_text(int socket_fd, char *text, int header)
{
 int length = strlen (text) + 1;
 write (socket_fd, &header, sizeof (header));
 write (socket_fd, &length, sizeof (length));
 write (socket_fd, text, length);
 return 1;
}

variable_types:
text
char *

variable_types: header int

variable_types: length int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4[2]; // [rsp+0h] [rbp-368h] BYREF
char v5[496]; // [rsp+10h] [rbp-358h] BYREF
struct sigaction v6; // [rsp+200h] [rbp-168h] BYREF
struct sigaction v7; // [rsp+2A0h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+340h] [rbp-28h] BYREF

memset(&v7.sa_mask, 0, 0x90uLL);
v7.sa_handler = (__sighandler_t)handler;
v7.sa_flags = 4;
if ( sigaction(3, &v7, &v6) < 0 )
{
perror("Sigaction quit fail.\n");
}
else if ( sigaction(2, &v7, &v6) < 0 )
{
perror("Sigaction int fail.\n");
}
else
{
v3 = socket(2, 1, 0);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(5555);
if ( argc == 2 )
{
if ( !inet_aton(argv[1], (struct in_addr *)&addr.sa_data[2]) )
perror("Address is not valid.\n");
}
else
{
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0xC0A86592);
}
printf("ip : %u\n", *(unsigned int *)&addr.sa_data[2]);
if ( connect(v3, &addr, 0x10u) == -1 )
puts("Connect error.");
v4[0] = 0x206873656E746152LL;
v4[1] = 58LL;
memset(v5, 0, sizeof(v5));
while ( 1 )
{
printf("Socket id : %d : msg : %s \n", v3, (const char *)v4);
if ( (unsigned int)write_text(v3, v4, 4) == -1 )
break;
__isoc99_scanf();
if ( !status )
goto LABEL_16;
}
perror("Write failed.\n");
LABEL_16:
puts("Existing main.");
close(v3);
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4[2]; // [rsp+0h] [rbp-368h] BYREF
char v5[496]; // [rsp+10h] [rbp-358h] BYREF
struct sigaction v6; // [rsp+200h] [rbp-168h] BYREF
struct sigaction v7; // [rsp+2A0h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+340h] [rbp-28h] BYREF

memset(&v7.sa_mask, 0, 0x90uLL);
v7.sa_handler = (__sighandler_t)handler;
v7.sa_flags = 4;
if ( sigaction(3, &v7, &v6) < 0 )
{
perror("Sigaction quit fail.\n");
}
else if ( sigaction(2, &v7, &v6) < 0 )
{
perror("Sigaction int fail.\n");
}
else
{
v3 = socket(2, 1, 0);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func8(5555);
if ( argc == 2 )
{
if ( !inet_aton(argv[1], (struct in_addr *)&addr.sa_data[2]) )
perror("Address is not valid.\n");
}
else
{
*(_DWORD *)&addr.sa_data[2] = func9(0xC0A86592);
}
printf("ip : %u\n", *(unsigned int *)&addr.sa_data[2]);
if ( connect(v3, &addr, 0x10u) == -1 )
puts("Connect error.");
v4[0] = 0x206873656E746152LL;
v4[1] = 58LL;
memset(v5, 0, sizeof(v5));
while ( 1 )
{
printf("Socket id : %d : msg : %s \n", v3, (const char *)v4);
if ( (unsigned int)func10(v3, v4, 4) == -1 )
break;
__isoc99_scanf();
if ( !status )
goto LABEL_16;
}
perror("Write failed.\n");
LABEL_16:
puts("Existing main.");
close(v3);
}
exit(0);
}

variable_types:
argv
char *[]

variable_types: ret int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct packet { int socket_fd; struct sockaddr client_name; }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


repo: coriolis/vminspection

decompiled_code:
void __fastcall void_stack_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void void_stack_free(void_stack* stack)
{
  free(stack->elements);
  free(stack);
}

canonical_original_code:
void void_stack_free(struct _void_stack *stack)
{
  free(stack->elements);
  free(stack);
}

variable_types: struct _void_stack { void **elements; unsigned short max_size; unsigned short top; } *


decompiled_code:
void __fastcall void_stack_free_deep(void *ptr)
{
int v1; // ebx

if ( *((_WORD *)ptr + 5) )
{
v1 = 0;
do
free(*(void **)(*(_QWORD *)ptr + 8LL * (unsigned __int16)v1++));
while ( *((_WORD *)ptr + 5) > (unsigned __int16)v1 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
int v1; // ebx

if ( *((_WORD *)ptr + 5) )
{
v1 = 0;
do
free(*(void **)(*(_QWORD *)ptr + 8LL * (unsigned __int16)v1++));
while ( *((_WORD *)ptr + 5) > (unsigned __int16)v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void void_stack_free_deep(void_stack* stack)
{
  unsigned short i;
  for(i=0; i < stack->top; i++)
    free(stack->elements[i]);
  free(stack->elements);
  free(stack);
}

canonical_original_code:
void void_stack_free_deep(struct _void_stack *stack)
{
  unsigned short i;
  for(i=0; i < stack->top; i++)
    free(stack->elements[i]);
  free(stack->elements);
  free(stack);
}

variable_types:
i
unsigned short

user_defined_types: struct _void_stack { void **elements; unsigned short max_size; unsigned short top; }


decompiled_code:
__int64 __fastcall void_stack_size(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

original_code:
unsigned short void_stack_size(const void_stack* stack)
{
  return stack->top;
}

canonical_original_code:
unsigned short void_stack_size(struct _void_stack *stack)
{
  return stack->top;
}

return_type: unsigned short


original_code:
void* void_stack_pop(void_stack* stack)
{
  void* ret_val = ((void *)0);
  if(stack->top > 0)
  {
    ret_val = stack->elements[--(stack->top)];
    stack->elements[stack->top] = ((void *)0);
  }
  return ret_val;
}

canonical_original_code:
void *void_stack_pop(struct _void_stack *stack)
{
  void *ret_val = ((void *)0);
  if(stack->top > 0)
  {
    ret_val = stack->elements[--(stack->top)];
    stack->elements[stack->top] = ((void *)0);
  }
  return ret_val;
}

return_type: void *


original_code:
_Bool void_stack_push(void_stack* stack, void* e)
{
  if(stack->top < stack->max_size)
  {
    stack->elements[stack->top++] = e;
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
_Bool void_stack_push(struct _void_stack *stack, void *e)
{
  if(stack->top < stack->max_size)
  {
    stack->elements[stack->top++] = e;
    return 1;
  }
  else
    return 0;
}

variable_types:
e
void *


decompiled_code:
__int64 __fastcall void_stack_cur(__int64 a1)
{
unsigned __int16 v1; // ax
__int64 v2; // rdx

v1 = *(_WORD *)(a1 + 10);
v2 = 0LL;
if ( v1 )
v2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v1 - 8);
return v2;
}

original_code:
const void* void_stack_cur(const void_stack* stack)
{
  void* ret_val = ((void *)0);
  if(stack->top > 0)
    ret_val = stack->elements[stack->top-1];
  return ret_val;
}

canonical_original_code:
void *void_stack_cur(struct _void_stack *stack)
{
  void *ret_val = ((void *)0);
  if(stack->top > 0)
    ret_val = stack->elements[stack->top-1];
  return ret_val;
}


decompiled_code:
void __fastcall void_stack_iterator_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(void *a1)
{
free(a1);
}

original_code:
void void_stack_iterator_free(void_stack_iterator* iter)
{
  free(iter);
}

canonical_original_code:
void void_stack_iterator_free(struct _void_stack_iterator *iter)
{
  free(iter);
}

variable_types: struct _void_stack_iterator { struct _void_stack { void **elements; unsigned short max_size; unsigned short top; } *stack; unsigned short cur; } *

user_defined_types: struct _void_stack_iterator { struct _void_stack *stack; unsigned short cur; }


decompiled_code:
__int64 __fastcall void_stack_iterator_next(_WORD *a1)
{
unsigned __int16 v1; // ax
__int64 v2; // rdx
__int64 v3; // rdx

v1 = a1[4];
v2 = 0LL;
if ( v1 < *(_WORD *)(*(_QWORD *)a1 + 10LL) )
{
v3 = **(_QWORD **)a1;
a1[4] = v1 + 1;
v2 = *(_QWORD *)(v3 + 8LL * v1);
}
return v2;
}

original_code:
const void* void_stack_iterator_next(void_stack_iterator* iter)
{
  if(iter->cur < iter->stack->top)
    return iter->stack->elements[iter->cur++];
  else
    return ((void *)0);
}

canonical_original_code:
void *void_stack_iterator_next(struct _void_stack_iterator *iter)
{
  if(iter->cur < iter->stack->top)
    return iter->stack->elements[iter->cur++];
  else
    return ((void *)0);
}


myopen

decompiled_code:
int __fastcall myopen(__int64 a1, int a2)
{
fprintf(stderr, "Opening %s \n", regfilename);
return open(regfilename, a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2)
{
fprintf(stderr, "Opening %s \n", regfilename);
return open(regfilename, a2);
}

original_code:
int myopen(char *fname, int mod)
{
    fprintf(stderr, "Opening %s \n", regfilename);
    return open(regfilename, mod);
}

variable_types:
fname
char *

variable_types: mod int


myread

decompiled_code:
__int64 __fastcall myread(int a1, void *a2, unsigned int a3)
{
int v4; // ebx

v4 = read(a1, a2, (int)a3);
if ( v4 < 0 )
perror("Failed to read ....\n");
fprintf(stderr, "Read %d asked %d \n", (unsigned int)v4, a3);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, void *a2, unsigned int a3)
{
int v4; // ebx

v4 = read(a1, a2, (int)a3);
if ( v4 < 0 )
perror("Failed to read ....\n");
fprintf(stderr, "Read %d asked %d \n", (unsigned int)v4, a3);
return (unsigned int)v4;
}

original_code:
int myread(int fd, char *buf, int size)
{
    int ret =0;
    ret = read(fd, buf, size);
    if(ret <0)
        perror("Failed to read ....\n");
    fprintf(stderr, "Read %d asked %d \n", ret, size);
    return ret;
}

canonical_original_code:
int myread(int fd, char *buf, int size)
{
    int ret = 0;
    ret = read(fd, buf, size);
    if(ret <0)
        perror("Failed to read ....\n");
    fprintf(stderr, "Read %d asked %d \n", ret, size);
    return ret;
}

variable_types: fd int

variable_types:
buf
char *

variable_types: size int


mylseek

decompiled_code:
__int64 __fastcall mylseek(int a1, __off_t a2, unsigned int a3)
{
int v4; // ebx

v4 = lseek(a1, a2, a3);
if ( v4 < 0 )
perror("Failed to read ....\n");
fprintf(stderr, "lseek from %d off %d \n", a3, (unsigned int)a2);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __off_t a2, unsigned int a3)
{
int v4; // ebx

v4 = lseek(a1, a2, a3);
if ( v4 < 0 )
perror("Failed to read ....\n");
fprintf(stderr, "lseek from %d off %d \n", a3, (unsigned int)a2);
return (unsigned int)v4;
}

original_code:
int mylseek(int fd, off_t off, int wh)
{
    int ret =0;
    ret = lseek(fd, off, wh);
    if(ret <0)
        perror("Failed to read ....\n");
    fprintf(stderr, "lseek from %d off %d \n", wh, (int)off);
    return ret;
}

canonical_original_code:
int mylseek(int fd, long off, int wh)
{
    int ret = 0;
    ret = lseek(fd, off, wh);
    if(ret <0)
        perror("Failed to read ....\n");
    fprintf(stderr, "lseek from %d off %d \n", wh, (int)off);
    return ret;
}

variable_types: off long

variable_types: wh int


usage

decompiled_code:
int __fastcall usage(const char **a1)
{
return printf("\n%s <regfile_path> \n", *a1);
}

canonical_decompiled_code:
int __fastcall func10(const char **a1)
{
return printf("\n%s <regfile_path> \n", *a1);
}

original_code:
void usage(char *argv[])
{
    printf("\n%s <regfile_path> \n", argv[0]);
    return;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
{
usage(argv);
}
else
{
regfilename = (char *)argv[1];
osi_get_os_details();
free(0LL);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
{
func10(argv);
}
else
{
regfilename = (char *)argv[1];
osi_get_os_details();
free(0LL);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    char **info = ((void *)0);
    int i=0;
    if(argc < 2)
    {
        usage(argv);
        return 0;
    }
    regfilename = argv[1];
    osi_get_os_details(myopen, myread, mylseek, &info);
    while(info && info[i])
    {
        fprintf(stderr, "\t%s: %s\n", info[i], info[i+1]);
        free(info[i]);
        free(info[i+1]);
        i+=2;
    }
    free(info);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char **info = ((void *)0);
    int i = 0;
    if(argc < 2)
    {
        usage(argv);
        return 0;
    }
    regfilename = argv[1];
    osi_get_os_details(myopen, myread, mylseek, &info);
    while(info && info[i])
    {
        fprintf(stderr, "\t%s: %s\n", info[i], info[i+1]);
        free(info[i]);
        free(info[i+1]);
        i+=2;
    }
    free(info);
    return 0;
}

variable_types: argc int

variable_types:
info
char **

variable_types: i int


decompiled_code:
char *__fastcall get_value(char *s)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rax

v1 = s;
v2 = &s[(int)strlen(s) - 1];
if ( *v2 == 44 )
*v2 = 0;
v3 = strrchr(s, 44);
if ( v3 )
v1 = v3 + 1;
return strdup(v1);
}

canonical_decompiled_code:
char *__fastcall func6(char *s)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rax

v1 = s;
v2 = &s[(int)strlen(s) - 1];
if ( *v2 == 44 )
*v2 = 0;
v3 = strrchr(s, 44);
if ( v3 )
v1 = v3 + 1;
return strdup(v1);
}

original_code:
static char * get_value(char *fullkey)
{
    char *val = ((void *)0);
    char *tmp = ((void *)0);
    int len =0;
    len = strlen(fullkey);
    if(fullkey[len-1] == ',')
        fullkey[len-1] = '\0';
    tmp = strrchr(fullkey, ',');
    if(tmp)
        tmp++;
    else
        tmp = fullkey;
    val = strdup(tmp);
    return val;
}

canonical_original_code:
static char *get_value(char *fullkey)
{
    char *val = ((void *)0);
    char *tmp = ((void *)0);
    int len = 0;
    len = strlen(fullkey);
    if(fullkey[len-1] == ',')
        fullkey[len-1] = '\0';
    tmp = strrchr(fullkey, ',');
    if(tmp)
        tmp++;
    else
        tmp = fullkey;
    val = strdup(tmp);
    return val;
}

variable_types:
fullkey
char *

variable_types:
val
char *

variable_types:
tmp
char *

variable_types: len int

return_type: char *


decompiled_code:
char *__fastcall get_base_key(const char *a1)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rax
char *v4; // rbp
size_t v6; // rax

v1 = strdup(a1);
v2 = strchr(v1, 44);
if ( v2 )
*v2 = 0;
v3 = strrchr(v1, 47);
v4 = v3;
if ( v3 && v1 != v3 )
{
v6 = strlen(v3);
memcpy(v1, v4 + 1, v6 + 1);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rax
char *v4; // rbp
size_t v6; // rax

v1 = strdup(a1);
v2 = strchr(v1, 44);
if ( v2 )
*v2 = 0;
v3 = strrchr(v1, 47);
v4 = v3;
if ( v3 && v1 != v3 )
{
v6 = strlen(v3);
memcpy(v1, v4 + 1, v6 + 1);
}
return v1;
}

original_code:
static char * get_base_key(char *fullkey)
{
    char *key = ((void *)0);
    char *tmp = ((void *)0);
    key = strdup(fullkey);
    tmp=strchr(key, ',');
    if(tmp)
        *tmp = '\0';
    tmp = strrchr(key, '/');
    if(tmp && tmp != key)
        memcpy(key, tmp+1, strlen(tmp)+1);
    return key;
}

canonical_original_code:
static char *get_base_key(char *fullkey)
{
    char *key = ((void *)0);
    char *tmp = ((void *)0);
    key = strdup(fullkey);
    tmp=strchr(key, ',');
    if(tmp)
        *tmp = '\0';
    tmp = strrchr(key, '/');
    if(tmp && tmp != key)
        memcpy(key, tmp+1, strlen(tmp)+1);
    return key;
}

variable_types:
key
char *


decompiled_code:
__int64 __fastcall osi_get_os_info(_QWORD *a1)
{
const char **v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // r13
char **v4; // rbp
char *v5; // r12
char *v6; // rax

v1 = (const char **)rll_get_value_strings();
v2 = calloc(0x100uLL, 8uLL);
v3 = v2;
if ( v1 )
{
v4 = (char **)v2;
while ( *v1 )
{
v5 = get_base_key(*v1);
v6 = get_value((char *)*v1);
*v4 = v5;
v4[1] = v6;
++v1;
v4 += 2;
}
}
*a1 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
const char **v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // r13
char **v4; // rbp
char *v5; // r12
char *v6; // rax

v1 = (const char **)rll_get_value_strings();
v2 = calloc(0x100uLL, 8uLL);
v3 = v2;
if ( v1 )
{
v4 = (char **)v2;
while ( *v1 )
{
v5 = func7(*v1);
v6 = func6((char *)*v1);
*v4 = v5;
v4[1] = v6;
++v1;
v4 += 2;
}
}
*a1 = v3;
return 0LL;
}

original_code:
int osi_get_os_info(char ***osinfo)
{
    char **info=((void *)0), **ret=((void *)0);
    char *key = ((void *)0), *value = ((void *)0);
    int i=0;
    info = (char **)rll_get_value_strings(rghandle, win_keys[0].key, win_keys[0].recursive);
    ret = (char **) calloc(256, sizeof(char *));
    while(info && info[i])
    {
        key = get_base_key(info[i]);
        value = get_value(info[i]);
        ret[i*2]=key;
        ret[i*2+1]=value;
        i++;
    }
    *osinfo = ret;
    return 0;
}

canonical_original_code:
int osi_get_os_info(char ***osinfo)
{
    char **info = ((void *)0); char **ret = ((void *)0);
    char *key = ((void *)0); char *value = ((void *)0);
    int i = 0;
    info = (char **)rll_get_value_strings(rghandle, win_keys[0].key, win_keys[0].recursive);
    ret = (char **) calloc(256, sizeof(char *));
    while(info && info[i])
    {
        key = get_base_key(info[i]);
        value = get_value(info[i]);
        ret[i*2]=key;
        ret[i*2+1]=value;
        i++;
    }
    *osinfo = ret;
    return 0;
}

variable_types:
osinfo
char ***

variable_types:
ret
char **

variable_types:
value
char *


decompiled_code:
__int64 __fastcall osi_get_os_details(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v6 = 0LL;
if ( a4 )
{
rghandle = rll_open_file_clbks();
if ( rghandle )
{
osi_get_os_info(&v6);
*a4 = v6;
rll_close();
}
else
{
fwrite("Failed to open registry file \n", 1uLL, 0x1EuLL, stderr);
}
}
else
{
fwrite("Invalid parameters\n", 1uLL, 0x13uLL, stderr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v6 = 0LL;
if ( a4 )
{
rghandle = rll_open_file_clbks();
if ( rghandle )
{
func8(&v6);
*a4 = v6;
rll_close();
}
else
{
fwrite("Failed to open registry file \n", 1uLL, 0x1EuLL, stderr);
}
}
else
{
fwrite("Invalid parameters\n", 1uLL, 0x13uLL, stderr);
}
return 0LL;
}

original_code:
int osi_get_os_details(void *open, void *read, void *lseek, char ***osinfo)
{
    int status =0;
    int i=0;
    char **info = ((void *)0);
    if(!osinfo)
    {
        fprintf(stderr, "Invalid parameters\n");
        return 0;
    }
    rghandle = (void *)rll_open_file_clbks(open, read, lseek);
    if(!rghandle)
    {
        fprintf(stderr, "Failed to open registry file \n");
        return 0;
    }
    osi_get_os_info(&info);
    *osinfo = info;
    rll_close(rghandle);
    return 0;
}

canonical_original_code:
int osi_get_os_details(void *open, void *read, void *lseek, char ***osinfo)
{
    int status = 0;
    int i = 0;
    char **info = ((void *)0);
    if(!osinfo)
    {
        fprintf(stderr, "Invalid parameters\n");
        return 0;
    }
    rghandle = (void *)rll_open_file_clbks(open, read, lseek);
    if(!rghandle)
    {
        fprintf(stderr, "Failed to open registry file \n");
        return 0;
    }
    osi_get_os_info(&info);
    *osinfo = info;
    rll_close(rghandle);
    return 0;
}

variable_types:
open
void *

variable_types:
read
void *

variable_types:
lseek
void *

variable_types: status int


gensquare

repo: coron/htable

decompiled_code:
int gensquare()
{
int v0; // ebp
int i; // ebx
unsigned __int8 v2; // al

printf("byte sq[256]={");
v0 = 1;
for ( i = 0; ; ++i )
{
if ( (i & 7) == 0 )
putchar(10);
v2 = mult((unsigned __int8)i, (unsigned __int8)i);
printf("0x%02x", v2);
if ( i <= 254 )
{
putchar(44);
goto LABEL_4;
}
if ( v0 > 255 )
break;
LABEL_4:
++v0;
}
return puts("};");
}

canonical_decompiled_code:
int func0()
{
int v0; // ebp
int i; // ebx
unsigned __int8 v2; // al

printf("byte sq[256]={");
v0 = 1;
for ( i = 0; ; ++i )
{
if ( (i & 7) == 0 )
putchar(10);
v2 = mult((unsigned __int8)i, (unsigned __int8)i);
printf("0x%02x", v2);
if ( i <= 254 )
{
putchar(44);
goto LABEL_4;
}
if ( v0 > 255 )
break;
LABEL_4:
++v0;
}
return puts("};");
}

canonical_original_code:
void gensquare()
{
  int i;
  unsigned char x = 0;
  printf("byte sq[256]={");
  for(i=0;i<256;i++)
  {
    if((i%8)==0) printf("\n");
    printf("0x%02x",mult(x,x));
    x++;
    if(i<255) printf(",");
  }
  printf("};\n");
}

variable_types:
x
unsigned char


square

decompiled_code:
__int64 __fastcall square(unsigned __int8 a1)
{
return (unsigned __int8)sq[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
return (unsigned __int8)sq[a1];
}

original_code:
byte square(byte x)
{
  return sq[x];
}

canonical_original_code:
unsigned char square(unsigned char x)
{
  return sq[x];
}

return_type: unsigned char


gentaffine

decompiled_code:
int gentaffine()
{
int v0; // ebp
int i; // ebx
unsigned __int8 v2; // al

printf("byte taffine[256]={");
v0 = 1;
for ( i = 0; ; ++i )
{
if ( (i & 7) == 0 )
putchar(10);
v2 = affine((unsigned __int8)i);
printf("0x%02x", v2);
if ( i <= 254 )
{
putchar(44);
goto LABEL_4;
}
if ( v0 > 255 )
break;
LABEL_4:
++v0;
}
return puts("};");
}

canonical_decompiled_code:
int func2()
{
int v0; // ebp
int i; // ebx
unsigned __int8 v2; // al

printf("byte taffine[256]={");
v0 = 1;
for ( i = 0; ; ++i )
{
if ( (i & 7) == 0 )
putchar(10);
v2 = affine((unsigned __int8)i);
printf("0x%02x", v2);
if ( i <= 254 )
{
putchar(44);
goto LABEL_4;
}
if ( v0 > 255 )
break;
LABEL_4:
++v0;
}
return puts("};");
}

original_code:
void gentaffine()
{
  int i;
  byte x=0;
  printf("byte taffine[256]={");
  for(i=0;i<256;i++)
  {
    if((i%8)==0) printf("\n");
    printf("0x%02x",affine(x));
    x++;
    if(i<255) printf(",");
  }
  printf("};\n");
}

canonical_original_code:
void gentaffine()
{
  int i;
  unsigned char x = 0;
  printf("byte taffine[256]={");
  for(i=0;i<256;i++)
  {
    if((i%8)==0) printf("\n");
    printf("0x%02x",affine(x));
    x++;
    if(i<255) printf(",");
  }
  printf("};\n");
}


variable_types: j int

variable_types:
y
unsigned char

variable_types:
t
unsigned char [1024]


multtable

decompiled_code:
char __fastcall multtable(char a1, unsigned __int8 a2)
{
int v2; // ecx
char v3; // di
__int64 v4; // rdx

v2 = (unsigned __int8)(16 * a1);
v3 = a1 & 0xF0;
v4 = (unsigned __int8)(v3 | a2 & 0xF);
BYTE1(v4) = 2;
return tsmult[v2 | (a2 >> 4) | 0x100] ^ tsmult[(unsigned __int8)((a2 >> 4) | v3) | 0x300LL] ^ tsmult[v2 | a2 & 0xF] ^ tsmult[v4];
}

canonical_decompiled_code:
char __fastcall func4(char a1, unsigned __int8 a2)
{
int v2; // ecx
char v3; // di
__int64 v4; // rdx

v2 = (unsigned __int8)(16 * a1);
v3 = a1 & 0xF0;
v4 = (unsigned __int8)(v3 | a2 & 0xF);
BYTE1(v4) = 2;
return tsmult[v2 | (a2 >> 4) | 0x100] ^ tsmult[(unsigned __int8)((a2 >> 4) | v3) | 0x300LL] ^ tsmult[v2 | a2 & 0xF] ^ tsmult[v4];
}


multshare

original_code:
void multshare(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      byte tmp=xorshf96();
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
}

canonical_original_code:
void multshare(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      unsigned char tmp = xorshf96();
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
c
unsigned char *

variable_types: n int

variable_types: i int

variable_types:
tmp
unsigned char


decompiled_code:
__int64 __fastcall subbyte_rp(unsigned __int8 a1)
{
char v1; // al
unsigned __int8 v2; // al
char v3; // al
unsigned __int8 v4; // al
char v5; // bp
unsigned __int8 v6; // al
unsigned __int8 v7; // al
unsigned __int8 v8; // al
unsigned __int8 v9; // al
char v10; // al

v1 = square(a1);
v2 = multtable(v1, a1);
v3 = square(v2);
v4 = multtable(v3, a1);
v5 = square(v4);
v6 = multtable(v5, a1);
v7 = square(v6);
v8 = square(v7);
v9 = square(v8);
v10 = square(v9);
return (unsigned __int8)taffine[(unsigned __int8)multtable(v10, v5)];
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
char v1; // al
unsigned __int8 v2; // al
char v3; // al
unsigned __int8 v4; // al
char v5; // bp
unsigned __int8 v6; // al
unsigned __int8 v7; // al
unsigned __int8 v8; // al
unsigned __int8 v9; // al
char v10; // al

v1 = func1(a1);
v2 = func4(v1, a1);
v3 = func1(v2);
v4 = func4(v3, a1);
v5 = func1(v4);
v6 = func4(v5, a1);
v7 = func1(v6);
v8 = func1(v7);
v9 = func1(v8);
v10 = func1(v9);
return (unsigned __int8)taffine[(unsigned __int8)func4(v10, v5)];
}

original_code:
byte subbyte_rp(byte x)
{
  byte u2=square(x);
  byte u3=multtable(u2,x);
  byte u6=square(u3);
  byte u7=multtable(u6,x);
  byte u14=square(u7);
  byte u15=multtable(u14,x);
  byte u240=square(square(square(square(u15))));
  byte u254=multtable(u240,u14);
  return taffine[u254];
}

canonical_original_code:
unsigned char subbyte_rp(unsigned char x)
{
  unsigned char u2 = square(x);
  unsigned char u3 = multtable(u2,x);
  unsigned char u6 = square(u3);
  unsigned char u7 = multtable(u6,x);
  unsigned char u14 = square(u7);
  unsigned char u15 = multtable(u14,x);
  unsigned char u240 = square(square(square(square(u15))));
  unsigned char u254 = multtable(u240,u14);
  return taffine[u254];
}


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

if ( a2 > 0 )
{
v2 = a1;
do
{
*v2 = square(*v2);
++v2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
}

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

if ( a2 > 0 )
{
v2 = a1;
do
{
*v2 = func1(*v2);
++v2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
}

original_code:
void square_share(byte *a,int n)
{
  int i;
  for(i=0;i<n;i++)
    a[i]=square(a[i]);
}

canonical_original_code:
void square_share(unsigned char *a, int n)
{
  int i;
  for(i=0;i<n;i++)
    a[i]=square(a[i]);
}


decompiled_code:
__int64 __fastcall subbytestate_rp(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = subbyte_rp(*v1);
*v1++ = result;
}
while ( v1 != a1 + 16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 result; // rax

v1 = a1;
do
{
result = func6(*v1);
*v1++ = result;
}
while ( v1 != a1 + 16 );
return result;
}

original_code:
void subbytestate_rp(byte *state)
{
  int i;
  for(i=0;i<16;i++) state[i]=subbyte_rp(state[i]);
}

canonical_original_code:
void subbytestate_rp(unsigned char *state)
{
  int i;
  for(i=0;i<16;i++) state[i]=subbyte_rp(state[i]);
}

variable_types:
state
unsigned char *


decompiled_code:
__int64 __fastcall aes_rp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int j; // ebx
__int64 result; // rax
_BYTE v6[176]; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int8 v7[40]; // [rsp+B0h] [rbp-28h] BYREF

keyexpansion(a3, v6);
for ( i = 0LL; i != 16; ++i )
v7[i] = *(_BYTE *)(a1 + i);
addroundkey(v7, v6, 0LL);
for ( j = 1; j != 10; ++j )
{
subbytestate_rp(v7);
shiftrows(v7);
mixcolumns(v7);
addroundkey(v7, v6, j);
}
subbytestate(v7);
shiftrows(v7);
addroundkey(v7, v6, 10LL);
for ( result = 0LL; result != 16; ++result )
*(_BYTE *)(a2 + result) = v7[result];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int j; // ebx
__int64 result; // rax
_BYTE v6[176]; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int8 v7[40]; // [rsp+B0h] [rbp-28h] BYREF

keyexpansion(a3, v6);
for ( i = 0LL; i != 16; ++i )
v7[i] = *(_BYTE *)(a1 + i);
addroundkey(v7, v6, 0LL);
for ( j = 1; j != 10; ++j )
{
func8(v7);
shiftrows(v7);
mixcolumns(v7);
addroundkey(v7, v6, j);
}
subbytestate(v7);
shiftrows(v7);
addroundkey(v7, v6, 10LL);
for ( result = 0LL; result != 16; ++result )
*(_BYTE *)(a2 + result) = v7[result];
return result;
}

original_code:
void aes_rp(byte in[16],byte out[16],byte key[16])
{
  int i,j;
  int round=0;
  byte state[16];
  byte w[176];
  keyexpansion(key,w);
  for(i=0;i<16;i++)
    state[i]=in[i];
  addroundkey(state,w,0);
  for(round=1;round<10;round++)
  {
    subbytestate_rp(state);
    shiftrows(state);
    mixcolumns(state);
    addroundkey(state,w,round);
  }
  subbytestate(state);
  shiftrows(state);
  addroundkey(state,w,10);
  for(i=0;i<16;i++)
    out[i]=state[i];
}

canonical_original_code:
void aes_rp(unsigned char in[16], unsigned char out[16], unsigned char key[16])
{
  int i; int j;
  int round = 0;
  unsigned char state[16];
  unsigned char w[176];
  keyexpansion(key,w);
  for(i=0;i<16;i++)
    state[i]=in[i];
  addroundkey(state,w,0);
  for(round=1;round<10;round++)
  {
    subbytestate_rp(state);
    shiftrows(state);
    mixcolumns(state);
    addroundkey(state,w,round);
  }
  subbytestate(state);
  shiftrows(state);
  addroundkey(state,w,10);
  for(i=0;i<16;i++)
    out[i]=state[i];
}

variable_types:
in
unsigned char [16]

variable_types:
out
unsigned char [16]

variable_types:
key
unsigned char [16]

variable_types: round int

variable_types:
state
unsigned char [16]

variable_types:
w
unsigned char [176]


decompiled_code:
_BYTE *test_mult_gf16()
{
_BYTE *result; // rax
char v1; // [rsp+Eh] [rbp-Ah] BYREF
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = mult_gf16(0x81u, 0x25u, 0x17u, 0xDu, v2, &v1);
if ( v2[0] != -119 )
_assert_fail("c0==137", "prg.c", 0x1Bu, "test_mult_gf16");
if ( v1 != -56 )
_assert_fail("c1==200", "prg.c", 0x1Cu, "test_mult_gf16");
return result;
}

canonical_decompiled_code:
_BYTE *func0()
{
_BYTE *result; // rax
char v1; // [rsp+Eh] [rbp-Ah] BYREF
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = mult_gf16(0x81u, 0x25u, 0x17u, 0xDu, v2, &v1);
if ( v2[0] != -119 )
_assert_fail("c0==137", "prg.c", 0x1Bu, "test_mult_gf16");
if ( v1 != -56 )
_assert_fail("c1==200", "prg.c", 0x1Cu, "test_mult_gf16");
return result;
}

canonical_original_code:
void test_mult_gf16()
{
  unsigned char c0; unsigned char c1;
  mult_gf16(129,37,23,13,&c0,&c1);
  ((void) sizeof ((c0==137) ? 1 : 0), __extension__ ({ if (c0==137) ; else __assert_fail ("c0==137", "prg.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((c1==200) ? 1 : 0), __extension__ ({ if (c1==200) ; else __assert_fail ("c1==200", "prg.c", 28, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
unsigned __int8 __fastcall eval_poly_gf16(__int64 a1, int a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 *a5, unsigned __int8 *a6)
{
int v6; // esi
__int64 v11; // rbx
unsigned __int8 result; // al
char v13; // [rsp+0h] [rbp-3Ah] BYREF
char v14[57]; // [rsp+1h] [rbp-39h] BYREF

*a5 = 0;
*a6 = 0;
v6 = a2 - 1;
if ( v6 >= 0 )
{
v11 = v6;
do
{
mult_gf16(*a5, *a6, a3, a4, &v13, v14);
*a5 = v13 ^ *(_BYTE *)(a1 + 2 * v11);
result = v14[0] ^ *(_BYTE *)(a1 + 2 * v11 + 1);
*a6 = result;
--v11;
}
while ( (int)v11 >= 0 );
}
return result;
}

canonical_decompiled_code:
unsigned __int8 __fastcall func1(__int64 a1, int a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 *a5, unsigned __int8 *a6)
{
int v6; // esi
__int64 v11; // rbx
unsigned __int8 result; // al
char v13; // [rsp+0h] [rbp-3Ah] BYREF
char v14[57]; // [rsp+1h] [rbp-39h] BYREF

*a5 = 0;
*a6 = 0;
v6 = a2 - 1;
if ( v6 >= 0 )
{
v11 = v6;
do
{
mult_gf16(*a5, *a6, a3, a4, &v13, v14);
*a5 = v13 ^ *(_BYTE *)(a1 + 2 * v11);
result = v14[0] ^ *(_BYTE *)(a1 + 2 * v11 + 1);
*a6 = result;
--v11;
}
while ( (int)v11 >= 0 );
}
return result;
}

canonical_original_code:
void eval_poly_gf16(unsigned char *pol, int d, unsigned char x0, unsigned char x1, unsigned char *r0, unsigned char *r1)
{
  int i;
  *r0=0;*r1=0;
  for(i=d-1;i>=0;i--)
  {
    unsigned char t0; unsigned char t1;
    mult_gf16(*r0,*r1,x0,x1,&t0,&t1);
    *r0=t0 ^ pol[2*i];
    *r1=t1 ^ pol[2*i+1];
  }
}

variable_types:
pol
unsigned char *

variable_types: d int


decompiled_code:
unsigned __int8 test_eval_poly_gf16()
{
unsigned __int8 result; // al
unsigned __int8 v1; // [rsp+8h] [rbp-10h] BYREF
unsigned __int8 v2; // [rsp+9h] [rbp-Fh] BYREF
int v3; // [rsp+Ah] [rbp-Eh] BYREF
__int16 v4; // [rsp+Eh] [rbp-Ah]

v3 = 538064407;
v4 = 7143;
result = eval_poly_gf16((__int64)&v3, 2, 0x43u, 0xCu, &v2, &v1);
if ( v2 != 0xB4 )
_assert_fail("r0==180", "prg.c", 0x33u, "test_eval_poly_gf16");
if ( v1 != 113 )
_assert_fail("r1==113", "prg.c", 0x34u, "test_eval_poly_gf16");
return result;
}

canonical_decompiled_code:
unsigned __int8 func2()
{
unsigned __int8 result; // al
unsigned __int8 v1; // [rsp+8h] [rbp-10h] BYREF
unsigned __int8 v2; // [rsp+9h] [rbp-Fh] BYREF
int v3; // [rsp+Ah] [rbp-Eh] BYREF
__int16 v4; // [rsp+Eh] [rbp-Ah]

v3 = 538064407;
v4 = 7143;
result = func1((__int64)&v3, 2, 0x43u, 0xCu, &v2, &v1);
if ( v2 != 0xB4 )
_assert_fail("r0==180", "prg.c", 0x33u, "test_eval_poly_gf16");
if ( v1 != 113 )
_assert_fail("r1==113", "prg.c", 0x34u, "test_eval_poly_gf16");
return result;
}

canonical_original_code:
void test_eval_poly_gf16()
{
  unsigned char pol[6] = {23,54,18,32,231,27};
  unsigned char x0 = 67; unsigned char x1 = 12;
  unsigned char r0; unsigned char r1;
  eval_poly_gf16(pol,2,x0,x1,&r0,&r1);
  ((void) sizeof ((r0==180) ? 1 : 0), __extension__ ({ if (r0==180) ; else __assert_fail ("r0==180", "prg.c", 51, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((r1==113) ? 1 : 0), __extension__ ({ if (r1==113) ; else __assert_fail ("r1==113", "prg.c", 52, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
pol
unsigned char [6]


decompiled_code:
void *__fastcall init_prg_p(__int64 a1, int a2)
{
void *result; // rax
__int64 v3; // rbx

*(_DWORD *)(a1 + 4) = a2;
result = malloc(2 * a2);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)a1 = 0;
if ( 2 * a2 > 0 )
{
v3 = 0LL;
do
{
result = (void *)xorshf96();
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v3++) = (_BYTE)result;
}
while ( v3 != 2 * a2 );
}
*(_DWORD *)(a1 + 16) = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, int a2)
{
void *result; // rax
__int64 v3; // rbx

*(_DWORD *)(a1 + 4) = a2;
result = malloc(2 * a2);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)a1 = 0;
if ( 2 * a2 > 0 )
{
v3 = 0LL;
do
{
result = (void *)xorshf96();
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v3++) = (_BYTE)result;
}
while ( v3 != 2 * a2 );
}
*(_DWORD *)(a1 + 16) = 0;
return result;
}

original_code:
void init_prg_p(tprg *prg,int d)
{
  prg->dprg=d;
  prg->pol=(byte *) malloc(2*d*sizeof(byte));
  prg->prgcount=0;
  for(int i=0;i<2*d;i++)
    prg->pol[i]=xorshf96();
  prg->prgflag=0;
}

canonical_original_code:
void init_prg_p(struct tprg *prg, int d)
{
  prg->dprg=d;
  prg->pol=(unsigned char *) malloc(2*d*sizeof(byte));
  prg->prgcount=0;
  for(int i = 0;i<2*d;i++)
    prg->pol[i]=xorshf96();
  prg->prgflag=0;
}

variable_types: struct tprg { int prgcount; int dprg; unsigned char *pol; int prgflag; unsigned char r0; } *


decompiled_code:
void *__fastcall init_prg(int a1)
{
return init_prg_p((__int64)&prg, a1);
}

canonical_decompiled_code:
void *__fastcall func4(int a1)
{
return func3((__int64)&prg, a1);
}

original_code:
void init_prg(int d)
{
  init_prg_p(&prg,d);
}


original_code:
byte get_prg_p(tprg *prg)
{
  if (prg->prgflag==1)
  {
    prg->prgflag=0;
    return prg->r1;
  }
  eval_poly_gf16(prg->pol,prg->dprg,prg->prgcount & 255,prg->prgcount >> 8,&prg->r0,&prg->r1);
  prg->prgcount++;
  prg->prgflag=1-prg->prgflag;
  return prg->r0;
}

canonical_original_code:
unsigned char get_prg_p(struct tprg *prg)
{
  if (prg->prgflag==1)
  {
    prg->prgflag=0;
    return prg->r1;
  }
  eval_poly_gf16(prg->pol,prg->dprg,prg->prgcount & 255,prg->prgcount >> 8,&prg->r0,&prg->r1);
  prg->prgcount++;
  prg->prgflag=1-prg->prgflag;
  return prg->r0;
}

user_defined_types: struct tprg { int prgcount; int dprg; unsigned char *pol; int prgflag; unsigned char r0; }


decompiled_code:
__int64 get_prg()
{
return get_prg_p((__int64)&prg);
}

canonical_decompiled_code:
__int64 func6()
{
return func5((__int64)&prg);
}

original_code:
byte get_prg()
{
  return get_prg_p(&prg);
}

canonical_original_code:
unsigned char get_prg()
{
  return get_prg_p(&prg);
}


decompiled_code:
__int64 get_prgcount()
{
return (unsigned int)(2 * prg);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)(2 * prg);
}

original_code:
int get_prgcount()
{
  return prg.prgcount*2;
}


decompiled_code:
void free_prg()
{
free(*((void **)&prg + 1));
}

canonical_decompiled_code:
void func8()
{
free(*((void **)&prg + 1));
}

original_code:
void free_prg()
{
  free(prg.pol);
}

canonical_original_code:
void free_prg()
{
  free(prg.pol);
}


decompiled_code:
int test_prg()
{
int v0; // ebx
unsigned __int8 v1; // al
int result; // eax

init_prg(10);
v0 = 100;
do
{
v1 = get_prg();
result = printf("%d ", v1);
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
int func9()
{
int v0; // ebx
unsigned __int8 v1; // al
int result; // eax

func4(10);
v0 = 100;
do
{
v1 = func6();
result = printf("%d ", v1);
--v0;
}
while ( v0 );
return result;
}

original_code:
void test_prg()
{
  init_prg(10);
  for(int i=0;i<100;i++)
    printf("%d ",get_prg());
}

canonical_original_code:
void test_prg()
{
  init_prg(10);
  for(int i = 0;i<100;i++)
    printf("%d ",get_prg());
}


decompiled_code:
void *__fastcall init_robprg(int a1, int a2)
{
void *result; // rax
__int64 v3; // rbx

result = malloc(24LL * a2);
robprg = result;
if ( a2 > 0 )
{
v3 = 0LL;
do
{
result = init_prg_p((__int64)robprg + v3, a1);
v3 += 24LL;
}
while ( v3 != 24LL * (unsigned int)a2 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(int a1, int a2)
{
void *result; // rax
__int64 v3; // rbx

result = malloc(24LL * a2);
robprg = result;
if ( a2 > 0 )
{
v3 = 0LL;
do
{
result = func3((__int64)robprg + v3, a1);
v3 += 24LL;
}
while ( v3 != 24LL * (unsigned int)a2 );
}
return result;
}

original_code:
void init_robprg(int d,int n)
{
  robprg.vprg=malloc(n*sizeof(tprg));
  for(int i=0;i<n;i++)
    init_prg_p(&robprg.vprg[i],d);
}

canonical_original_code:
void init_robprg(int d, int n)
{
  robprg.vprg=malloc(n*sizeof(tprg));
  for(int i = 0;i<n;i++)
    init_prg_p(&robprg.vprg[i],d);
}


decompiled_code:
__int64 __fastcall get_robprg(int a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

if ( a1 <= 0 )
return 0;
v1 = 0LL;
v2 = 0;
do
{
v2 ^= get_prg_p((__int64)robprg + v1);
v1 += 24LL;
}
while ( v1 != 24LL * (unsigned int)a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp

if ( a1 <= 0 )
return 0;
v1 = 0LL;
v2 = 0;
do
{
v2 ^= func5((__int64)robprg + v1);
v1 += 24LL;
}
while ( v1 != 24LL * (unsigned int)a1 );
return v2;
}

original_code:
byte get_robprg(int n)
{
  byte r=0;
  for(int i=0;i<n;i++)
    r^=get_prg_p(&robprg.vprg[i]);
  return r;
}

canonical_original_code:
unsigned char get_robprg(int n)
{
  unsigned char r = 0;
  for(int i = 0;i<n;i++)
    r^=get_prg_p(&robprg.vprg[i]);
  return r;
}

variable_types:
r
unsigned char


decompiled_code:
__int64 get_robprgcount()
{
return (unsigned int)(2 * *(_DWORD *)robprg);
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned int)(2 * *(_DWORD *)robprg);
}

original_code:
int get_robprgcount()
{
  return robprg.vprg[0].prgcount*2;
}


decompiled_code:
void __fastcall free_robprg(int a1)
{
__int64 v1; // rbx

if ( a1 > 0 )
{
v1 = 0LL;
do
{
free(*(void **)((char *)robprg + v1 + 8));
v1 += 24LL;
}
while ( v1 != 24LL * (unsigned int)a1 );
}
free(robprg);
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
__int64 v1; // rbx

if ( a1 > 0 )
{
v1 = 0LL;
do
{
free(*(void **)((char *)robprg + v1 + 8));
v1 += 24LL;
}
while ( v1 != 24LL * (unsigned int)a1 );
}
free(robprg);
}

original_code:
void free_robprg(int n)
{
  for(int i=0;i<n;i++)
    free(robprg.vprg[i].pol);
  free(robprg.vprg);
}

canonical_original_code:
void free_robprg(int n)
{
  for(int i = 0;i<n;i++)
    free(robprg.vprg[i].pol);
  free(robprg.vprg);
}


decompiled_code:
void *__fastcall init_mprg(int a1, int a2, int a3, int a4)
{
int v6; // er13
__int64 v7; // r13
__int64 v8; // rbx
void *result; // rax
__int64 v10; // rbx

mprg = 0;
v6 = a4 - 1;
*((_QWORD *)&mprg + 1) = malloc(24LL * (a4 - 1));
if ( v6 > 0 )
{
v7 = 8 * (3LL * (unsigned int)(a4 - 2) + 3);
v8 = 0LL;
do
{
init_prg_p(*((_QWORD *)&mprg + 1) + v8, a1);
v8 += 24LL;
}
while ( v8 != v7 );
}
result = malloc(24LL * a2);
*((_QWORD *)&mprg + 2) = result;
if ( a2 > 0 )
{
v10 = 0LL;
do
{
result = init_prg_p(*((_QWORD *)&mprg + 2) + v10, a3);
v10 += 24LL;
}
while ( v10 != 24LL * (unsigned int)a2 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func14(int a1, int a2, int a3, int a4)
{
int v6; // er13
__int64 v7; // r13
__int64 v8; // rbx
void *result; // rax
__int64 v10; // rbx

mprg = 0;
v6 = a4 - 1;
*((_QWORD *)&mprg + 1) = malloc(24LL * (a4 - 1));
if ( v6 > 0 )
{
v7 = 8 * (3LL * (unsigned int)(a4 - 2) + 3);
v8 = 0LL;
do
{
func3(*((_QWORD *)&mprg + 1) + v8, a1);
v8 += 24LL;
}
while ( v8 != v7 );
}
result = malloc(24LL * a2);
*((_QWORD *)&mprg + 2) = result;
if ( a2 > 0 )
{
v10 = 0LL;
do
{
result = func3(*((_QWORD *)&mprg + 2) + v10, a3);
v10 += 24LL;
}
while ( v10 != 24LL * (unsigned int)a2 );
}
return result;
}

original_code:
void init_mprg(int rc,int ni,int ri,int n)
{
  mprg.prgcount=0;
  mprg.vprgc=malloc((n-1)*sizeof(tprg));
  for(int i=0;i<n-1;i++)
    init_prg_p(&mprg.vprgc[i],rc);
  mprg.vprgi=malloc(ni*sizeof(tprg));
  for(int i=0;i<ni;i++)
    init_prg_p(&mprg.vprgi[i],ri);
}

canonical_original_code:
void init_mprg(int rc, int ni, int ri, int n)
{
  mprg.prgcount=0;
  mprg.vprgc=malloc((n-1)*sizeof(tprg));
  for(int i = 0;i<n-1;i++)
    init_prg_p(&mprg.vprgc[i],rc);
  mprg.vprgi=malloc(ni*sizeof(tprg));
  for(int i = 0;i<ni;i++)
    init_prg_p(&mprg.vprgi[i],ri);
}

variable_types: rc int

variable_types: ni int

variable_types: ri int


original_code:
void free_mprg(int ni,int n)
{
  for(int i=0;i<n-1;i++)
    free(mprg.vprgc[i].pol);
  free(mprg.vprgc);
  for(int i=0;i<ni;i++)
    free(mprg.vprgi[i].pol);
  free(mprg.vprgi);
}

canonical_original_code:
void free_mprg(int ni, int n)
{
  for(int i = 0;i<n-1;i++)
    free(mprg.vprgc[i].pol);
  free(mprg.vprgc);
  for(int i = 0;i<ni;i++)
    free(mprg.vprgi[i].pol);
  free(mprg.vprgi);
}

variable_types: n int

variable_types: i int


decompiled_code:
__int64 __fastcall get_mprgc(int a1)
{
++mprg;
return get_prg_p(*((_QWORD *)&mprg + 1) + 24LL * a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
++mprg;
return func5(*((_QWORD *)&mprg + 1) + 24LL * a1);
}

original_code:
byte get_mprgc(int i)
{
  mprg.prgcount++;
  return get_prg_p(&mprg.vprgc[i]);
}

canonical_original_code:
unsigned char get_mprgc(int i)
{
  mprg.prgcount++;
  return get_prg_p(&mprg.vprgc[i]);
}


decompiled_code:
__int64 __fastcall get_mprgi(int a1)
{
++mprg;
return get_prg_p(*((_QWORD *)&mprg + 2) + 24LL * a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
++mprg;
return func5(*((_QWORD *)&mprg + 2) + 24LL * a1);
}

original_code:
byte get_mprgi(int i)
{
  mprg.prgcount++;
  return get_prg_p(&mprg.vprgi[i]);
}

canonical_original_code:
unsigned char get_mprgi(int i)
{
  mprg.prgcount++;
  return get_prg_p(&mprg.vprgi[i]);
}


decompiled_code:
__int64 get_mprgcount()
{
return (unsigned int)mprg;
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned int)mprg;
}

original_code:
int get_mprgcount()
{
  return mprg.prgcount;
}


printMes

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

printf("%s=", a1);
v2 = a2;
do
printf("%02x", *v2++);
while ( v2 != a2 + 16 );
return putchar(10);
}

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

printf("%s=", a1);
v2 = a2;
do
printf("%02x", *v2++);
while ( v2 != a2 + 16 );
return putchar(10);
}

original_code:
void printMes(char *s,byte *m)
{
  printf("%s=",s);
  int i;
  for(i=0;i<16;i++) printf("%02x",m[i]);
  printf("\n");
}

canonical_original_code:
void printMes(char *s, unsigned char *m)
{
  printf("%s=",s);
  int i;
  for(i=0;i<16;i++) printf("%02x",m[i]);
  printf("\n");
}

variable_types:
s
char *

variable_types:
m
unsigned char *


decompiled_code:
int __fastcall print_share_s(__int64 a1, int a2, int a3)
{
int v4; // er13
int v5; // er12
unsigned __int8 *v6; // rbx
__int64 v8; // [rsp+8h] [rbp-40h]

if ( a2 > 0 )
{
v4 = 0;
v5 = 0;
v8 = a1 + (unsigned int)(a3 - 1) + 1;
do
{
v6 = (unsigned __int8 *)(a1 + v4);
if ( a3 > 0 )
{
do
printf("%02x ", *v6++);
while ( v6 != (unsigned __int8 *)(v8 + v4) );
}
putchar(32);
++v5;
v4 += a3;
}
while ( a2 != v5 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2, int a3)
{
int v4; // er13
int v5; // er12
unsigned __int8 *v6; // rbx
__int64 v8; // [rsp+8h] [rbp-40h]

if ( a2 > 0 )
{
v4 = 0;
v5 = 0;
v8 = a1 + (unsigned int)(a3 - 1) + 1;
do
{
v6 = (unsigned __int8 *)(a1 + v4);
if ( a3 > 0 )
{
do
printf("%02x ", *v6++);
while ( v6 != (unsigned __int8 *)(v8 + v4) );
}
putchar(32);
++v5;
v4 += a3;
}
while ( a2 != v5 );
}
return putchar(10);
}

original_code:
void print_share_s(byte *a,int k,int ell)
{
  for(int i=0;i<k;i++)
  {
    for(int j=0;j<ell;j++)
      printf("%02x ",a[i*ell+j]);
    printf(" ");
  }
  printf("\n");
}

canonical_original_code:
void print_share_s(unsigned char *a, int k, int ell)
{
  for(int i = 0;i<k;i++)
  {
    for(int j = 0;j<ell;j++)
      printf("%02x ",a[i*ell+j]);
    printf(" ");
  }
  printf("\n");
}

variable_types:
a
unsigned char *

variable_types: k int

variable_types: ell int

variable_types: j int


decompiled_code:
__int64 __fastcall multshare_ilr(__int64 a1, __int64 a2, _BYTE *a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
__int64 result; // rax
_BYTE *v8; // r12
__int64 v9; // rbp
char v10; // al
__int64 v11; // rbx
_BYTE *v12; // rbx
char v14; // [rsp+Eh] [rbp-4Ah]
char v15; // [rsp+Fh] [rbp-49h]

if ( (int)a4 > 0 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
a3[i] = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
}
result = a4;
if ( (int)a4 > 1 )
{
v8 = a3 + 1;
result = a4;
v9 = 1LL;
do
{
v11 = 0LL;
if ( (int)v9 > 0 )
{
do
{
v14 = get_robprg(a4);
v15 = v14 ^ multtable(*(unsigned __int8 *)(a1 + v11), *(unsigned __int8 *)(a2 + v9));
v10 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v11));
a3[v11] ^= v14;
*v8 ^= v10 ^ v15;
++v11;
}
while ( v11 != v9 );
v12 = a3;
do
{
result = get_robprg(a4);
*v8 ^= *v12 ^ (unsigned __int8)result;
*v12++ = result;
}
while ( v12 != v8 );
}
++v9;
++v8;
}
while ( v9 != a4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _BYTE *a3, unsigned int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
__int64 result; // rax
_BYTE *v8; // r12
__int64 v9; // rbp
char v10; // al
__int64 v11; // rbx
_BYTE *v12; // rbx
char v14; // [rsp+Eh] [rbp-4Ah]
char v15; // [rsp+Fh] [rbp-49h]

if ( (int)a4 > 0 )
{
v5 = a4;
for ( i = 0LL; i != v5; ++i )
a3[i] = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
}
result = a4;
if ( (int)a4 > 1 )
{
v8 = a3 + 1;
result = a4;
v9 = 1LL;
do
{
v11 = 0LL;
if ( (int)v9 > 0 )
{
do
{
v14 = get_robprg(a4);
v15 = v14 ^ multtable(*(unsigned __int8 *)(a1 + v11), *(unsigned __int8 *)(a2 + v9));
v10 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v11));
a3[v11] ^= v14;
*v8 ^= v10 ^ v15;
++v11;
}
while ( v11 != v9 );
v12 = a3;
do
{
result = get_robprg(a4);
*v8 ^= *v12 ^ (unsigned __int8)result;
*v12++ = result;
}
while ( v12 != v8 );
}
++v9;
++v8;
}
while ( v9 != a4 );
}
return result;
}

original_code:
void multshare_ilr(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(j=1;j<n;j++)
  {
    for(i=0;i<j;i++)
    {
      byte tmp=get_robprg(n);
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
    for(i=0;i<j;i++)
    {
      byte tmp=get_robprg(n);
      c[j]^=c[i]^tmp;
      c[i]=tmp;
    }
  }
}

canonical_original_code:
void multshare_ilr(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(j=1;j<n;j++)
  {
    for(i=0;i<j;i++)
    {
      unsigned char tmp = get_robprg(n);
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
    for(i=0;i<j;i++)
    {
      unsigned char tmp = get_robprg(n);
      c[j]^=c[i]^tmp;
      c[i]=tmp;
    }
  }
}

variable_types:
b
unsigned char *

variable_types:
c
unsigned char *

variable_types:
tmp
unsigned char


original_code:
void multshare_ilr_mprg(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(j=1;j<n;j++)
  {
    for(i=0;i<j;i++)
    {
      byte tmp=get_mprgi(i);
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
    for(i=0;i<j;i++)
    {
      byte tmp=get_mprgc(i);
      c[j]^=c[i]^tmp;
      c[i]=tmp;
    }
  }
}

canonical_original_code:
void multshare_ilr_mprg(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(j=1;j<n;j++)
  {
    for(i=0;i<j;i++)
    {
      unsigned char tmp = get_mprgi(i);
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
    for(i=0;i<j;i++)
    {
      unsigned char tmp = get_mprgc(i);
      c[j]^=c[i]^tmp;
      c[i]=tmp;
    }
  }
}


decompiled_code:
void __fastcall locality_refresh(_BYTE *a1, int a2)
{
_BYTE *v2; // rbx
char v3; // al

if ( a2 > 1 )
{
v2 = a1;
do
{
v3 = get_robprg((unsigned int)a2);
a1[a2 - 1] ^= *v2 ^ v3;
*v2++ = v3;
}
while ( v2 != &a1[a2 - 2 + 1] );
}
}

canonical_decompiled_code:
void __fastcall func2(_BYTE *a1, int a2)
{
_BYTE *v2; // rbx
char v3; // al

if ( a2 > 1 )
{
v2 = a1;
do
{
v3 = get_robprg((unsigned int)a2);
a1[a2 - 1] ^= *v2 ^ v3;
*v2++ = v3;
}
while ( v2 != &a1[a2 - 2 + 1] );
}
}

original_code:
void locality_refresh(byte *a,int n)
{
  for(int i=0;i<n-1;i++)
  {
    byte r=get_robprg(n);
    a[n-1]^=r ^ a[i];
    a[i]=r;
  }
}

canonical_original_code:
void locality_refresh(unsigned char *a, int n)
{
  for(int i = 0;i<n-1;i++)
  {
    unsigned char r = get_robprg(n);
    a[n-1]^=r ^ a[i];
    a[i]=r;
  }
}


decompiled_code:
void __fastcall multshare_ilr2(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
__int64 v5; // rbp
__int64 i; // rbx
_BYTE *v7; // r12
__int64 v8; // rbp
__int64 v9; // rbx
char v10; // [rsp+3h] [rbp-45h]
char v11; // [rsp+3h] [rbp-45h]

if ( a4 > 0 )
{
v5 = (unsigned int)a4;
for ( i = 0LL; i != v5; ++i )
a3[i] = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
}
if ( a4 > 1 )
{
v7 = a3 + 1;
v8 = 1LL;
do
{
v9 = 0LL;
if ( (int)v8 > 0 )
{
do
{
v10 = get_robprg((unsigned int)a4);
*v7 ^= a3[v9] ^ v10;
v11 = v10 ^ multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v8));
a3[v9] = v11 ^ multtable(*(unsigned __int8 *)(a1 + v8), *(unsigned __int8 *)(a2 + v9));
++v9;
}
while ( v8 != v9 );
}
++v8;
++v7;
}
while ( v8 != a4 );
}
locality_refresh(a3, a4);
}

original_code:
void multshare_ilr2(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(j=1;j<n;j++)
  {
    for(i=0;i<j;i++)
    {
      byte tmp=get_robprg(n);
      c[j]^=c[i] ^ tmp;
      c[i]=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
    }
  }
  locality_refresh(c,n);
}

canonical_original_code:
void multshare_ilr2(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(j=1;j<n;j++)
  {
    for(i=0;i<j;i++)
    {
      unsigned char tmp = get_robprg(n);
      c[j]^=c[i] ^ tmp;
      c[i]=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
    }
  }
  locality_refresh(c,n);
}


decompiled_code:
void __fastcall locality_refresh_mprg(__int64 a1, int a2)
{
__int64 v2; // rbx
char v3; // al
__int64 v4; // rax

if ( a2 > 1 )
{
v2 = 0LL;
do
{
v3 = get_mprgc((unsigned int)v2);
*(_BYTE *)(a1 + a2 - 1) ^= *(_BYTE *)(a1 + v2) ^ v3;
*(_BYTE *)(a1 + v2) = v3;
v4 = v2++;
}
while ( v4 != a2 - 2 );
}
}

original_code:
void locality_refresh_mprg(byte *a,int n)
{
  for(int i=0;i<n-1;i++)
  {
    byte r=get_mprgc(i);
    a[n-1]^=r ^ a[i];
    a[i]=r;
  }
}

canonical_original_code:
void locality_refresh_mprg(unsigned char *a, int n)
{
  for(int i = 0;i<n-1;i++)
  {
    unsigned char r = get_mprgc(i);
    a[n-1]^=r ^ a[i];
    a[i]=r;
  }
}


original_code:
void multshare_flr_mprg(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  int co=0;
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      byte tmp=get_mprgi(co);
      co++;
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
  locality_refresh_mprg(c,n);
}

canonical_original_code:
void multshare_flr_mprg(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  int co = 0;
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      unsigned char tmp = get_mprgi(co);
      co++;
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
  locality_refresh_mprg(c,n);
}

variable_types: co int


decompiled_code:
void __fastcall locality_refresh_mprgmatabc(__int64 a1, unsigned int a2, int a3)
{
__int64 v4; // r15
__int64 v5; // rbx
_BYTE *v6; // r12
char v7; // al
__int64 v8; // rax

if ( a3 > 1 )
{
v4 = (unsigned int)(a3 - 2);
v5 = 0LL;
v6 = (_BYTE *)(a1 + a3 - 1);
do
{
v7 = get_mprgmatabc(a2, (unsigned int)v5, (unsigned int)a3);
*v6 ^= *(_BYTE *)(a1 + v5) ^ v7;
*(_BYTE *)(a1 + v5) = v7;
v8 = v5++;
}
while ( v8 != v4 );
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned int a2, int a3)
{
__int64 v4; // r15
__int64 v5; // rbx
_BYTE *v6; // r12
char v7; // al
__int64 v8; // rax

if ( a3 > 1 )
{
v4 = (unsigned int)(a3 - 2);
v5 = 0LL;
v6 = (_BYTE *)(a1 + a3 - 1);
do
{
v7 = get_mprgmatabc(a2, (unsigned int)v5, (unsigned int)a3);
*v6 ^= *(_BYTE *)(a1 + v5) ^ v7;
*(_BYTE *)(a1 + v5) = v7;
v8 = v5++;
}
while ( v8 != v4 );
}
}

original_code:
void locality_refresh_mprgmatabc(byte *a,int type,int n)
{
  for(int i=0;i<n-1;i++)
  {
    byte r=get_mprgmatabc(type,i,n);
    a[n-1]^=r ^ a[i];
    a[i]=r;
  }
}

canonical_original_code:
void locality_refresh_mprgmatabc(unsigned char *a, int type, int n)
{
  for(int i = 0;i<n-1;i++)
  {
    unsigned char r = get_mprgmatabc(type,i,n);
    a[n-1]^=r ^ a[i];
    a[i]=r;
  }
}

variable_types: type int


decompiled_code:
void __fastcall multshare_flr_mprgmat(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v5; // ebx
__int64 v6; // rbp
__int64 i; // rbx
_BYTE *v8; // r13
__int64 v9; // r14
__int64 v10; // rbx
char v11; // bp
char v12; // al
char v13; // [rsp+Bh] [rbp-6Dh]
int v14; // [rsp+Ch] [rbp-6Ch]
__int64 v15; // [rsp+28h] [rbp-50h]
int v16; // [rsp+34h] [rbp-44h]

v5 = a4;
locality_refresh_mprgmatabc(a1, 0, a4);
locality_refresh_mprgmatabc(a2, 1u, v5);
if ( v5 > 0 )
{
v16 = v5 - 1;
v15 = (unsigned int)(v5 - 1);
v6 = (unsigned int)v5;
for ( i = 0LL; i != v6; ++i )
*(_BYTE *)(a3 + i) = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
v8 = (_BYTE *)a3;
v9 = 0LL;
v14 = 0;
while ( v9 != v15 )
{
v10 = v9 + 1;
do
{
v13 = get_mprgmati((unsigned int)(v14 - 1 - v9 + v10));
v11 = v13 ^ multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v10));
v12 = multtable(*(unsigned __int8 *)(a1 + v10), *(unsigned __int8 *)(a2 + v9));
*v8 ^= v13;
*(_BYTE *)(a3 + v10++) ^= v12 ^ v11;
}
while ( v10 != v9 + (unsigned int)(a4 - 2 - v9) + 2 );
v14 = v16 + v14 - v9;
++v8;
++v9;
}
}
locality_refresh_mprgmatabc(a3, 2u, a4);
}

original_code:
void multshare_flr_mprgmat(byte *a,byte *b,byte *c,int n)
{
  locality_refresh_mprgmatabc(a,0,n);
  locality_refresh_mprgmatabc(b,1,n);
  for(int i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  int co=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      byte tmp=get_mprgmati(co);
      co++;
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
  locality_refresh_mprgmatabc(c,2,n);
}

canonical_original_code:
void multshare_flr_mprgmat(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  locality_refresh_mprgmatabc(a,0,n);
  locality_refresh_mprgmatabc(b,1,n);
  for(int i = 0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  int co = 0;
  for(int i = 0;i<n;i++)
  {
    for(int j = i+1;j<n;j++)
    {
      unsigned char tmp = get_mprgmati(co);
      co++;
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
  locality_refresh_mprgmatabc(c,2,n);
}


decompiled_code:
void __fastcall xor_loc(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rax

locality_refresh_mprgmatabc(a1, 0, a4);
locality_refresh_mprgmatabc(a2, 1u, a4);
if ( a4 > 0 )
{
v6 = 0LL;
do
{
*(_BYTE *)(a3 + v6) = *(_BYTE *)(a2 + v6) ^ *(_BYTE *)(a1 + v6);
++v6;
}
while ( v6 != a4 );
}
locality_refresh_mprgmatabc(a3, 2u, a4);
}

original_code:
void xor_loc(byte *a,byte *b,byte *c,int n)
{
  locality_refresh_mprgmatabc(a,0,n);
  locality_refresh_mprgmatabc(b,1,n);
  for(int i=0;i<n;i++)
    c[i]=a[i] ^ b[i];
  locality_refresh_mprgmatabc(c,2,n);
}

canonical_original_code:
void xor_loc(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  locality_refresh_mprgmatabc(a,0,n);
  locality_refresh_mprgmatabc(b,1,n);
  for(int i = 0;i<n;i++)
    c[i]=a[i] ^ b[i];
  locality_refresh_mprgmatabc(c,2,n);
}


decompiled_code:
void __fastcall xor_loc32(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v5; // ebx
__int64 v6; // r15
__int64 i; // rbx
char v8; // r12
char v9; // [rsp+Bh] [rbp-3Dh]

v5 = a4;
locality_refresh_mprgmatabc(a1, 0, a4);
locality_refresh_mprgmatabc(a2, 1u, v5);
if ( v5 > 0 )
{
v6 = (unsigned int)v5;
for ( i = 0LL; i != v6; ++i )
{
v9 = multx(*(unsigned __int8 *)(a1 + i));
v8 = *(_BYTE *)(a1 + i);
*(_BYTE *)(a3 + i) = v9 ^ multx(*(unsigned __int8 *)(a2 + i)) ^ v8;
}
}
locality_refresh_mprgmatabc(a3, 2u, a4);
}

original_code:
void xor_loc32(byte *a,byte *b,byte *c,int n)
{
  locality_refresh_mprgmatabc(a,0,n);
  locality_refresh_mprgmatabc(b,1,n);
  for(int i=0;i<n;i++)
    c[i]=multx(a[i]) ^ a[i] ^ multx(b[i]);
  locality_refresh_mprgmatabc(c,2,n);
}

canonical_original_code:
void xor_loc32(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  locality_refresh_mprgmatabc(a,0,n);
  locality_refresh_mprgmatabc(b,1,n);
  for(int i = 0;i<n;i++)
    c[i]=multx(a[i]) ^ a[i] ^ multx(b[i]);
  locality_refresh_mprgmatabc(c,2,n);
}


decompiled_code:
void __fastcall multshare_prg(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
__int64 i; // rbx
_BYTE *v6; // r12
__int64 j; // rbp
__int64 v8; // rbx
char v9; // al
char v10; // [rsp+6h] [rbp-52h]
char v11; // [rsp+7h] [rbp-51h]
__int64 v12; // [rsp+10h] [rbp-48h]
int v14; // [rsp+1Ch] [rbp-3Ch]

if ( a4 > 0 )
{
v14 = a4 - 1;
v12 = (unsigned int)a4;
for ( i = 0LL; i != v12; ++i )
a3[i] = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
v6 = a3;
for ( j = 1LL; j != v12; ++j )
{
v8 = j;
do
{
v10 = get_robprg((unsigned int)a4);
v11 = v10 ^ multtable(*(unsigned __int8 *)(a1 + j - 1), *(unsigned __int8 *)(a2 + v8));
v9 = multtable(*(unsigned __int8 *)(a1 + v8), *(unsigned __int8 *)(a2 + j - 1));
*v6 ^= v10;
a3[v8++] ^= v11 ^ v9;
}
while ( v8 != j + (unsigned int)(v14 - j) + 1 );
++v6;
}
}
}

original_code:
void multshare_prg(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      byte tmp=get_robprg(n);
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
}

canonical_original_code:
void multshare_prg(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      unsigned char tmp = get_robprg(n);
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
}


decompiled_code:
void __fastcall multshare_flr(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
multshare_prg(a1, a2, a3, a4);
locality_refresh(a3, a4);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
func10(a1, a2, a3, a4);
func2(a3, a4);
}

original_code:
void multshare_flr(byte *a,byte *b,byte *c,int n)
{
  multshare_prg(a,b,c,n);
  locality_refresh(c,n);
}

canonical_original_code:
void multshare_flr(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  multshare_prg(a,b,c,n);
  locality_refresh(c,n);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_flr(_BYTE *a1, unsigned int a2)
{
locality_refresh(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr);
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, unsigned int a2)
{
func2(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr);
}

original_code:
void subbyte_rp_share_flr(byte *a,int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_flr);
}

canonical_original_code:
void subbyte_rp_share_flr(unsigned char *a, int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_flr);
}


max

decompiled_code:
__int64 __fastcall max(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a,int b)
{
  if (a>b) return a;
  return b;
}

canonical_original_code:
int max(int a, int b)
{
  if (a>b) return a;
  return b;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall rprg_ilr(int a1)
{
return (unsigned int)(4 * (a1 - 1) * (a1 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return (unsigned int)(4 * (a1 - 1) * (a1 - 1));
}

original_code:
int rprg_ilr(int n)
{
  int loc=4*(n-1);
  return (n-1)*loc;
}

canonical_original_code:
int rprg_ilr(int n)
{
  int loc = 4*(n-1);
  return (n-1)*loc;
}

variable_types: loc int


decompiled_code:
__int64 __fastcall subbyte_rp_share_ilr(_BYTE *a1, unsigned int a2)
{
locality_refresh(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr);
}

canonical_decompiled_code:
__int64 __fastcall func16(_BYTE *a1, unsigned int a2)
{
func2(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr);
}

original_code:
void subbyte_rp_share_ilr(byte *a,int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr);
}

canonical_original_code:
void subbyte_rp_share_ilr(unsigned char *a, int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_ilr2(_BYTE *a1, unsigned int a2)
{
locality_refresh(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr2);
}

canonical_decompiled_code:
__int64 __fastcall func17(_BYTE *a1, unsigned int a2)
{
func2(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr2);
}

original_code:
void subbyte_rp_share_ilr2(byte *a,int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr2);
}

canonical_original_code:
void subbyte_rp_share_ilr2(unsigned char *a, int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr2);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_flr_mprg(__int64 a1, unsigned int a2)
{
locality_refresh_mprg(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr_mprg);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2)
{
func4(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr_mprg);
}

original_code:
void subbyte_rp_share_flr_mprg(byte *a,int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_flr_mprg);
}

canonical_original_code:
void subbyte_rp_share_flr_mprg(unsigned char *a, int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_flr_mprg);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_ilr_mprg(__int64 a1, unsigned int a2)
{
locality_refresh_mprg(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr_mprg);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2)
{
func4(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr_mprg);
}

original_code:
void subbyte_rp_share_ilr_mprg(byte *a,int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr_mprg);
}

canonical_original_code:
void subbyte_rp_share_ilr_mprg(unsigned char *a, int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr_mprg);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_flr_mprgmat(__int64 a1, __int64 a2)
{
return subbyte_rp_share_func(a1, a2, multshare_flr_mprgmat);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2)
{
return subbyte_rp_share_func(a1, a2, multshare_flr_mprgmat);
}

original_code:
void subbyte_rp_share_flr_mprgmat(byte *a,int n)
{
  subbyte_rp_share_func(a,n,multshare_flr_mprgmat);
}

canonical_original_code:
void subbyte_rp_share_flr_mprgmat(unsigned char *a, int n)
{
  subbyte_rp_share_func(a,n,multshare_flr_mprgmat);
}


original_code:
byte get_prgmat(tprgmat *prgmat)
{
  byte res;
  if(prgmat->flag==0)
    res=prgmat->r[prgmat->x] ^ prgmat->s[prgmat->y];
  else
    res=prgmat->r[prgmat->y] ^ prgmat->s[prgmat->x];
  if((prgmat->flag==0) && (prgmat->x!=prgmat->y))
  {
    prgmat->flag=1;
    return res;
  }
  prgmat->flag=0;
  prgmat->y++;
  if(prgmat->y>prgmat->m)
  {
    prgmat->y=0;
    prgmat->x++;
    prgmat->m++;
    if(prgmat->m>=prgmat->dmax)
    {
      fprintf(stderr,"prgmat: dmax too small\n");
      exit(0);
    }
    prgmat->r[prgmat->m]=xorshf96();
    prgmat->s[prgmat->m]=xorshf96();
  }
  return res;
}

canonical_original_code:
unsigned char get_prgmat(struct tprgmat *prgmat)
{
  unsigned char res;
  if(prgmat->flag==0)
    res=prgmat->r[prgmat->x] ^ prgmat->s[prgmat->y];
  else
    res=prgmat->r[prgmat->y] ^ prgmat->s[prgmat->x];
  if((prgmat->flag==0) && (prgmat->x!=prgmat->y))
  {
    prgmat->flag=1;
    return res;
  }
  prgmat->flag=0;
  prgmat->y++;
  if(prgmat->y>prgmat->m)
  {
    prgmat->y=0;
    prgmat->x++;
    prgmat->m++;
    if(prgmat->m>=prgmat->dmax)
    {
      fprintf(stderr,"prgmat: dmax too small\n");
      exit(0);
    }
    prgmat->r[prgmat->m]=xorshf96();
    prgmat->s[prgmat->m]=xorshf96();
  }
  return res;
}

variable_types: struct tprgmat { int x; unsigned char *r; unsigned char *s; int flag; int m; int dmax; } *

variable_types:
res
unsigned char


decompiled_code:
void __fastcall free_prgmat(__int64 a1)
{
free(*(void **)(a1 + 8));
free(*(void **)(a1 + 16));
}

original_code:
void free_prgmat(tprgmat *prgmat)
{
  free(prgmat->r);
  free(prgmat->s);
}

canonical_original_code:
void free_prgmat(struct tprgmat *prgmat)
{
  free(prgmat->r);
  free(prgmat->s);
}

user_defined_types: struct tprgmat { int x; unsigned char *r; unsigned char *s; int flag; int m; int dmax; }


decompiled_code:
void *__fastcall init_mprgmat(int a1, int a2, int a3)
{
int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbx
void *result; // rax
__int64 v8; // rbx

v4 = 3 * a2 - 3;
mprgmat = malloc(40LL * v4);
if ( v4 > 0 )
{
v5 = 40LL * (unsigned int)v4;
v6 = 0LL;
do
{
init_prgmat((__int64)mprgmat + v6, a3);
v6 += 40LL;
}
while ( v6 != v5 );
}
result = malloc(40LL * a1);
*(&mprgmat + 1) = result;
if ( a1 > 0 )
{
v8 = 0LL;
do
{
result = init_prgmat((__int64)*(&mprgmat + 1) + v8, a3);
v8 += 40LL;
}
while ( v8 != 40LL * (unsigned int)a1 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(int a1, int a2, int a3)
{
int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbx
void *result; // rax
__int64 v8; // rbx

v4 = 3 * a2 - 3;
mprgmat = malloc(40LL * v4);
if ( v4 > 0 )
{
v5 = 40LL * (unsigned int)v4;
v6 = 0LL;
do
{
init_prgmat((__int64)mprgmat + v6, a3);
v6 += 40LL;
}
while ( v6 != v5 );
}
result = malloc(40LL * a1);
*(&mprgmat + 1) = result;
if ( a1 > 0 )
{
v8 = 0LL;
do
{
result = init_prgmat((__int64)*(&mprgmat + 1) + v8, a3);
v8 += 40LL;
}
while ( v8 != 40LL * (unsigned int)a1 );
}
return result;
}

original_code:
void init_mprgmat(int ni,int n,int dmax)
{
  mprgmat.vabc=malloc(3*(n-1)*sizeof(tprgmat));
  for(int i=0;i<3*(n-1);i++)
    init_prgmat(&mprgmat.vabc[i],dmax);
  mprgmat.vi=malloc(ni*sizeof(tprgmat));
  for(int i=0;i<ni;i++)
    init_prgmat(&mprgmat.vi[i],dmax);
}

canonical_original_code:
void init_mprgmat(int ni, int n, int dmax)
{
  mprgmat.vabc=malloc(3*(n-1)*sizeof(tprgmat));
  for(int i = 0;i<3*(n-1);i++)
    init_prgmat(&mprgmat.vabc[i],dmax);
  mprgmat.vi=malloc(ni*sizeof(tprgmat));
  for(int i = 0;i<ni;i++)
    init_prgmat(&mprgmat.vi[i],dmax);
}

variable_types: ni int

variable_types: n int

variable_types: dmax int

variable_types: i int


decompiled_code:
__int64 __fastcall get_mprgmatabc(int a1, int a2, int a3)
{
return get_prgmat((int *)mprgmat + 10 * a2 + 10 * a1 * (a3 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3)
{
return func0((int *)mprgmat + 10 * a2 + 10 * a1 * (a3 - 1));
}

original_code:
byte get_mprgmatabc(int type,int i,int n)
{
  return get_prgmat(&mprgmat.vabc[type*(n-1)+i]);
}

canonical_original_code:
unsigned char get_mprgmatabc(int type, int i, int n)
{
  return get_prgmat(&mprgmat.vabc[type*(n-1)+i]);
}


decompiled_code:
__int64 __fastcall get_mprgmati(int a1)
{
return get_prgmat((int *)*(&mprgmat + 1) + 10 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return func0((int *)*(&mprgmat + 1) + 10 * a1);
}

original_code:
byte get_mprgmati(int i)
{
  return get_prgmat(&mprgmat.vi[i]);
}

canonical_original_code:
unsigned char get_mprgmati(int i)
{
  return get_prgmat(&mprgmat.vi[i]);
}


decompiled_code:
void __fastcall free_mprgmat(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbx

if ( 3 * a2 - 3 > 0 )
{
v2 = 0LL;
do
{
free_prgmat((__int64)mprgmat + v2);
v2 += 40LL;
}
while ( v2 != 40LL * (unsigned int)(3 * a2 - 3) );
}
if ( a1 > 0 )
{
v3 = 0LL;
do
{
free_prgmat((__int64)*(&mprgmat + 1) + v3);
v3 += 40LL;
}
while ( v3 != 40LL * (unsigned int)a1 );
}
free(mprgmat);
free(*(&mprgmat + 1));
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbx

if ( 3 * a2 - 3 > 0 )
{
v2 = 0LL;
do
{
func1((__int64)mprgmat + v2);
v2 += 40LL;
}
while ( v2 != 40LL * (unsigned int)(3 * a2 - 3) );
}
if ( a1 > 0 )
{
v3 = 0LL;
do
{
func1((__int64)*(&mprgmat + 1) + v3);
v3 += 40LL;
}
while ( v3 != 40LL * (unsigned int)a1 );
}
free(mprgmat);
free(*(&mprgmat + 1));
}

original_code:
void free_mprgmat(int ni,int n)
{
  for(int i=0;i<3*(n-1);i++)
    free_prgmat(&mprgmat.vabc[i]);
  for(int i=0;i<ni;i++)
    free_prgmat(&mprgmat.vi[i]);
  free(mprgmat.vabc);
  free(mprgmat.vi);
}

canonical_original_code:
void free_mprgmat(int ni, int n)
{
  for(int i = 0;i<3*(n-1);i++)
    free_prgmat(&mprgmat.vabc[i]);
  for(int i = 0;i<ni;i++)
    free_prgmat(&mprgmat.vi[i]);
  free(mprgmat.vabc);
  free(mprgmat.vi);
}


decompiled_code:
int __fastcall check_ciphertext(const void *a1, const void *a2, int a3)
{
int result; // eax

result = memcmp(a1, a2, a3);
if ( result )
{
fwrite("Error: incorrect ciphertext\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2, int a3)
{
int result; // eax

result = memcmp(a1, a2, a3);
if ( result )
{
fwrite("Error: incorrect ciphertext\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
return result;
}

original_code:
void check_ciphertext(byte *out,byte *outex,int nbyte)
{
  if(memcmp(out,outex,nbyte)!=0)
  {
    fprintf(stderr,"Error: incorrect ciphertext\n");
    exit(1);
  }
}

canonical_original_code:
void check_ciphertext(unsigned char *out, unsigned char *outex, int nbyte)
{
  if(memcmp(out,outex,nbyte)!=0)
  {
    fprintf(stderr,"Error: incorrect ciphertext\n");
    exit(1);
  }
}

variable_types:
out
unsigned char *

variable_types:
outex
unsigned char *

variable_types: nbyte int


decompiled_code:
__int64 xorshf96()
{
unsigned __int64 v0; // rdx
__int64 result; // rax

++randcount;
v0 = (x << 16) ^ x ^ (((x << 16) ^ (unsigned __int64)x) >> 5);
x = y;
y = z;
result = (2 * v0) ^ v0 ^ z ^ x;
z = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // rdx
__int64 result; // rax

++randcount;
v0 = (x << 16) ^ x ^ (((x << 16) ^ (unsigned __int64)x) >> 5);
x = y;
y = z;
result = (2 * v0) ^ v0 ^ z ^ x;
z = result;
return result;
}

original_code:
unsigned long xorshf96(void) {
  unsigned long t;
  randcount++;
  x ^= x << 16;
  x ^= x >> 5;
  x ^= x << 1;
  t = x;
  x = y;
  y = z;
  z = t ^ x ^ y;
  return z;
}

canonical_original_code:
unsigned long xorshf96() {
  unsigned long t;
  randcount++;
  x ^= x << 16;
  x ^= x >> 5;
  x ^= x << 1;
  t = x;
  x = y;
  y = z;
  z = t ^ x ^ y;
  return z;
}

variable_types:
t
unsigned long

return_type: unsigned long


decompiled_code:
void init_randcount()
{
randcount = 0;
}

canonical_decompiled_code:
void func1()
{
randcount = 0;
}

original_code:
void init_randcount()
{
  randcount=0;
}

canonical_original_code:
void init_randcount()
{
  randcount=0;
}


decompiled_code:
__int64 get_randcount()
{
return (unsigned int)randcount;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)randcount;
}

original_code:
unsigned int get_randcount()
{
  return randcount;
}

return_type: unsigned int


decompiled_code:
void __fastcall set_randcount(int a1)
{
randcount = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
randcount = a1;
}

original_code:
void set_randcount(unsigned int randc)
{
  randcount=randc;
}

variable_types:
randc
unsigned int


share

original_code:
void share(byte x,byte a[],int n)
{
  int i;
  a[0]=x;
  for(i=1;i<n;i++)
    a[i]=0;
}

canonical_original_code:
void share(unsigned char x, unsigned char a[], int n)
{
  int i;
  a[0]=x;
  for(i=1;i<n;i++)
    a[i]=0;
}

variable_types:
x
unsigned char

variable_types:
a
unsigned char []


refresh

original_code:
void refresh(byte a[],int n)
{
  int i;
  for(i=1;i<n;i++)
  {
    byte tmp=xorshf96();
    a[0]=a[0] ^ tmp;
    a[i]=a[i] ^ tmp;
  }
}

canonical_original_code:
void refresh(unsigned char a[], int n)
{
  int i;
  for(i=1;i<n;i++)
  {
    unsigned char tmp = xorshf96();
    a[0]=a[0] ^ tmp;
    a[i]=a[i] ^ tmp;
  }
}

variable_types:
tmp
unsigned char


decode

decompiled_code:
__int64 __fastcall decode(_BYTE *a1, int a2)
{
_BYTE *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
LOBYTE(v3) = *v2++ ^ v3;
while ( v2 != &a1[a2 - 1 + 1] );
return v3;
}

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

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
LOBYTE(v3) = *v2++ ^ v3;
while ( v2 != &a1[a2 - 1 + 1] );
return v3;
}

original_code:
byte decode(byte a[],int n)
{
  byte r=0;
  for(int i=0;i<n;i++)
    r^=a[i];
  return r;
}

canonical_original_code:
unsigned char decode(unsigned char a[], int n)
{
  unsigned char r = 0;
  for(int i = 0;i<n;i++)
    r^=a[i];
  return r;
}

variable_types:
r
unsigned char


repo: cosino/modbus-utils

decompiled_code:
__int64 __fastcall parse_not_negative_int(char *s)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

if ( sscanf(s, "0x%x", &v2) > 0 || sscanf(s, "%d", &v2) > 0 )
result = v2;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

if ( sscanf(s, "0x%x", &v2) > 0 || sscanf(s, "%d", &v2) > 0 )
result = v2;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int parse_not_negative_int(char *addr)
{
 int val;
 int ret;
 ret = sscanf(addr, "0x%x", &val);
 if (ret < 1)
  ret = sscanf(addr, "%d", &val);
 if (ret < 1)
  return -1;
 return val;
}

variable_types:
addr
char *

variable_types: val int

variable_types: ret int