repo: cooljc/rpi-eve

decompiled_code:
__int64 __fastcall tmp10x_read_temp(int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
unsigned __int16 v3; // bx
unsigned __int16 v5[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v1 = ioctl(a1, 0x80022301uLL, v5);
v2 = v1;
if ( v1 )
{
fprintf(stderr, "Error: ioctl(TMP10X_IOC_GETTEMP) failed (err=%d)\n", v1);
}
else
{
v3 = v5[0];
fprintf(stderr, "temp.m_temp = 0x%02x -> ", v5[0]);
fprintf(stderr, "Temperature: %d.%04d C\n", v3 >> 4, 625 * (v3 & 0xFu));
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
unsigned __int16 v3; // bx
unsigned __int16 v5[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v1 = ioctl(a1, 0x80022301uLL, v5);
v2 = v1;
if ( v1 )
{
fprintf(stderr, "Error: ioctl(TMP10X_IOC_GETTEMP) failed (err=%d)\n", v1);
}
else
{
v3 = v5[0];
fprintf(stderr, "temp.m_temp = 0x%02x -> ", v5[0]);
fprintf(stderr, "Temperature: %d.%04d C\n", v3 >> 4, 625 * (v3 & 0xFu));
}
return v2;
}

original_code:
int tmp10x_read_temp (int fd)
{
  int ret = -1;
  tmp10x_temp_t temp;
  ret = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((0x23)) << (0 +8)) | (((1)) << 0) | ((((sizeof(tmp10x_temp_t)))) << ((0 +8)+8))), &temp);
  if (ret == 0) {
    int tmp1 = (temp.m_temp >> 4);
    int tmp2 = (temp.m_temp & 0x0f) * 625;
    fprintf (stderr, "temp.m_temp   = 0x%02x -> ", temp.m_temp);
    fprintf (stderr, "Temperature: %d.%04d C\n", tmp1, tmp2);
  }
  else {
    fprintf (stderr, "Error: ioctl(TMP10X_IOC_GETTEMP) failed (err=%d)\n", ret);
  }
  return ret;
}

canonical_original_code:
int tmp10x_read_temp(int fd)
{
  int ret = -1;
  struct _tmp10x_temp_s temp;
  ret = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((0x23)) << (0 +8)) | (((1)) << 0) | ((((sizeof(tmp10x_temp_t)))) << ((0 +8)+8))), &temp);
  if (ret == 0) {
    int tmp1 = (temp.m_temp >> 4);
    int tmp2 = (temp.m_temp & 0x0f) * 625;
    fprintf (stderr, "temp.m_temp   = 0x%02x -> ", temp.m_temp);
    fprintf (stderr, "Temperature: %d.%04d C\n", tmp1, tmp2);
  }
  else {
    fprintf (stderr, "Error: ioctl(TMP10X_IOC_GETTEMP) failed (err=%d)\n", ret);
  }
  return ret;
}

variable_types: fd int

variable_types: ret int

variable_types: struct _tmp10x_temp_s { unsigned short m_temp; }


decompiled_code:
__int64 __fastcall tmp10x_read_config(int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
char v4[14]; // [rsp+Ah] [rbp-Eh] BYREF

v1 = ioctl(a1, 0x80062302uLL, v4);
v2 = v1;
if ( v1 )
{
fprintf(stderr, "Error: ioctl(TMP10X_IOC_GETCONFIG) failed (err=%d)\n", v1);
}
else
{
fprintf(stderr, "c.m_sd = 0x%02x\n", (unsigned __int8)v4[0]);
fprintf(stderr, "c.m_tm = 0x%02x\n", (unsigned __int8)v4[1]);
fprintf(stderr, "c.m_pol = 0x%02x\n", (unsigned __int8)v4[2]);
fprintf(stderr, "c.m_fq = 0x%02x\n", (unsigned __int8)v4[3]);
fprintf(stderr, "c.m_cr = 0x%02x\n", (unsigned __int8)v4[4]);
fprintf(stderr, "c.m_os = 0x%02x\n", (unsigned __int8)v4[5]);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
char v4[14]; // [rsp+Ah] [rbp-Eh] BYREF

v1 = ioctl(a1, 0x80062302uLL, v4);
v2 = v1;
if ( v1 )
{
fprintf(stderr, "Error: ioctl(TMP10X_IOC_GETCONFIG) failed (err=%d)\n", v1);
}
else
{
fprintf(stderr, "c.m_sd = 0x%02x\n", (unsigned __int8)v4[0]);
fprintf(stderr, "c.m_tm = 0x%02x\n", (unsigned __int8)v4[1]);
fprintf(stderr, "c.m_pol = 0x%02x\n", (unsigned __int8)v4[2]);
fprintf(stderr, "c.m_fq = 0x%02x\n", (unsigned __int8)v4[3]);
fprintf(stderr, "c.m_cr = 0x%02x\n", (unsigned __int8)v4[4]);
fprintf(stderr, "c.m_os = 0x%02x\n", (unsigned __int8)v4[5]);
}
return v2;
}

original_code:
int tmp10x_read_config (int fd)
{
  int ret = -1;
  tmp10x_config_t c;
  ret = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((0x23)) << (0 +8)) | (((2)) << 0) | ((((sizeof(tmp10x_config_t)))) << ((0 +8)+8))), &c);
  if (ret == 0) {
    fprintf (stderr, "c.m_sd   = 0x%02x\n", c.m_sd);
    fprintf (stderr, "c.m_tm   = 0x%02x\n", c.m_tm);
    fprintf (stderr, "c.m_pol  = 0x%02x\n", c.m_pol);
    fprintf (stderr, "c.m_fq   = 0x%02x\n", c.m_fq);
    fprintf (stderr, "c.m_cr   = 0x%02x\n", c.m_cr);
    fprintf (stderr, "c.m_os   = 0x%02x\n", c.m_os);
  }
  else {
    fprintf (stderr, "Error: ioctl(TMP10X_IOC_GETCONFIG) failed (err=%d)\n", ret);
  }
  return ret;
}

canonical_original_code:
int tmp10x_read_config(int fd)
{
  int ret = -1;
  struct _tmp10x_config_s c;
  ret = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((0x23)) << (0 +8)) | (((2)) << 0) | ((((sizeof(tmp10x_config_t)))) << ((0 +8)+8))), &c);
  if (ret == 0) {
    fprintf (stderr, "c.m_sd   = 0x%02x\n", c.m_sd);
    fprintf (stderr, "c.m_tm   = 0x%02x\n", c.m_tm);
    fprintf (stderr, "c.m_pol  = 0x%02x\n", c.m_pol);
    fprintf (stderr, "c.m_fq   = 0x%02x\n", c.m_fq);
    fprintf (stderr, "c.m_cr   = 0x%02x\n", c.m_cr);
    fprintf (stderr, "c.m_os   = 0x%02x\n", c.m_os);
  }
  else {
    fprintf (stderr, "Error: ioctl(TMP10X_IOC_GETCONFIG) failed (err=%d)\n", ret);
  }
  return ret;
}

variable_types: struct _tmp10x_config_s { unsigned char m_sd; unsigned char m_tm; unsigned char m_pol; unsigned char m_fq; unsigned char m_cr; unsigned char m_os; }

return_type: int


decompiled_code:
__int64 __fastcall tmp10x_write_config(int fd)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
unsigned int v5; // er12
char v6[30]; // [rsp+Ah] [rbp-1Eh] BYREF

v1 = ioctl(fd, 0x80062302uLL, v6);
if ( v1 )
{
v5 = v1;
fprintf(stderr, "Error: ioctl(TMP10X_IOC_GETCONFIG) failed (err=%d)\n", v1);
result = v5;
}
else
{
v6[4] = 3;
v2 = ioctl(fd, 0x80062303uLL, v6);
v3 = v2;
if ( v2 )
fprintf(stderr, "Error: ioctl(TMP10X_IOC_SETCONFIG) failed (err=%d)\n", v2);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // er12
__int64 result; // rax
unsigned int v5; // er12
char v6[30]; // [rsp+Ah] [rbp-1Eh] BYREF

v1 = ioctl(fd, 0x80062302uLL, v6);
if ( v1 )
{
v5 = v1;
fprintf(stderr, "Error: ioctl(TMP10X_IOC_GETCONFIG) failed (err=%d)\n", v1);
result = v5;
}
else
{
v6[4] = 3;
v2 = ioctl(fd, 0x80062303uLL, v6);
v3 = v2;
if ( v2 )
fprintf(stderr, "Error: ioctl(TMP10X_IOC_SETCONFIG) failed (err=%d)\n", v2);
result = v3;
}
return result;
}

user_defined_types: struct _tmp10x_config_s { unsigned char m_sd; unsigned char m_tm; unsigned char m_pol; unsigned char m_fq; unsigned char m_cr; unsigned char m_os; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebp
int result; // eax

v3 = open("/dev/tmp10x", 2, envp);
if ( v3 < 0 )
{
fwrite("Error: Failed to open /dev/tmp10x!!\n", 1uLL, 0x24uLL, stderr);
result = 1;
}
else
{
v4 = v3;
tmp10x_read_config((unsigned int)v3);
tmp10x_write_config(v4);
tmp10x_read_config(v4);
tmp10x_read_temp(v4);
close(v4);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebp
int result; // eax

v3 = open("/dev/tmp10x", 2, envp);
if ( v3 < 0 )
{
fwrite("Error: Failed to open /dev/tmp10x!!\n", 1uLL, 0x24uLL, stderr);
result = 1;
}
else
{
v4 = v3;
func8((unsigned int)v3);
func9(v4);
func8(v4);
func7(v4);
close(v4);
result = 0;
}
return result;
}

original_code:
int main (int argc, char *argv[])
{
  int fd = -1;
  fd = open("/dev/tmp10x", 02);
  if (fd < 0) {
    fprintf (stderr, "Error: Failed to open /dev/tmp10x!!\n");
    return 1;
  }
  tmp10x_read_config (fd);
  tmp10x_write_config (fd);
  tmp10x_read_config (fd);
  tmp10x_read_temp (fd);
  close (fd);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int fd = -1;
  fd = open("/dev/tmp10x", 02);
  if (fd < 0) {
    fprintf (stderr, "Error: Failed to open /dev/tmp10x!!\n");
    return 1;
  }
  tmp10x_read_config (fd);
  tmp10x_write_config (fd);
  tmp10x_read_config (fd);
  tmp10x_read_temp (fd);
  close (fd);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


reader

decompiled_code:
__int64 __fastcall reader(void *a1)
{
int v1; // ebx
int v2; // eax
size_t v3; // r12
void *v4; // rbp
size_t v5; // r12
char *v6; // rax
char *v7; // rbp
int v9; // [rsp+8h] [rbp-20h] BYREF
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(_DWORD *)a1;
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock(&mutex);
if ( !status )
goto LABEL_16;
pthread_mutex_unlock(&mutex);
v2 = read(v1, buf, 4uLL);
if ( !v2 )
return 0LL;
if ( v2 == -1 )
{
puts("Read failed.");
LABEL_16:
pthread_mutex_unlock(&mutex);
return 1LL;
}
if ( buf[0] == 4 )
break;
if ( buf[0] == 8 )
{
if ( !read(v1, &v9, 4uLL) )
return 0LL;
v3 = v9;
v4 = malloc(v9);
if ( status )
read(v1, v4, v3);
printf("User Name - %s\n", (const char *)v4);
free(v4);
}
}
if ( !read(v1, &v9, 4uLL) )
return 0LL;
v5 = v9;
v6 = (char *)malloc(v9);
v7 = v6;
if ( status )
read(v1, v6, v5);
puts(v7);
free(v7);
}
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
int v1; // ebx
int v2; // eax
size_t v3; // r12
void *v4; // rbp
size_t v5; // r12
char *v6; // rax
char *v7; // rbp
int v9; // [rsp+8h] [rbp-20h] BYREF
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(_DWORD *)a1;
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock(&mutex);
if ( !status )
goto LABEL_16;
pthread_mutex_unlock(&mutex);
v2 = read(v1, buf, 4uLL);
if ( !v2 )
return 0LL;
if ( v2 == -1 )
{
puts("Read failed.");
LABEL_16:
pthread_mutex_unlock(&mutex);
return 1LL;
}
if ( buf[0] == 4 )
break;
if ( buf[0] == 8 )
{
if ( !read(v1, &v9, 4uLL) )
return 0LL;
v3 = v9;
v4 = malloc(v9);
if ( status )
read(v1, v4, v3);
printf("User Name - %s\n", (const char *)v4);
free(v4);
}
}
if ( !read(v1, &v9, 4uLL) )
return 0LL;
v5 = v9;
v6 = (char *)malloc(v9);
v7 = v6;
if ( status )
read(v1, v6, v5);
puts(v7);
free(v7);
}
}

original_code:
void * reader (void *arg)
{
 int client_socket = *(int *)arg;
 pthread_mutex_lock(&mutex);
 while (status) {
  pthread_mutex_unlock(&mutex);
  int length;
  char* text;
  int header;
  int ret;
  if (ret = read (client_socket, &header, sizeof(header)), ret == 0)
   return 0;
  else if(ret == -1)
  {
   printf("Read failed.\n");
   break;
  }
  else
  {
   switch(header)
   {
    case 0x04:
     if (read (client_socket, &length, sizeof(length)) == 0)
      return 0;
     text = (char*) malloc (length);
     if(status)
     {
      read (client_socket, text, length);
     }
     printf("%s\n",text);;
     free (text);
     break;
    case 0x08:
                  if (read (client_socket, &length, sizeof(length)) == 0)
                         return 0;
                     text = (char*) malloc (length);
                     if(status)
                     {
                        read (client_socket, text, length);
                     }
                     printf ("User Name - %s\n", text);
                     free (text);
                     break;
   }
  }
  pthread_mutex_lock(&mutex);
 }
 pthread_mutex_unlock(&mutex);
 return (void *)1;
}

canonical_original_code:
void *reader(void *arg)
{
 int client_socket = *(int *)arg;
 pthread_mutex_lock(&mutex);
 while (status) {
  pthread_mutex_unlock(&mutex);
  int length;
  char *text;
  int header;
  int ret;
  if (ret = read (client_socket, &header, sizeof(header)), ret == 0)
   return 0;
  else if(ret == -1)
  {
   printf("Read failed.\n");
   break;
  }
  else
  {
   switch(header)
   {
    case 0x04:
     if (read (client_socket, &length, sizeof(length)) == 0)
      return 0;
     text = (char *) malloc (length);
     if(status)
     {
      read (client_socket, text, length);
     }
     printf("%s\n",text);;
     free (text);
     break;
    case 0x08:
                  if (read (client_socket, &length, sizeof(length)) == 0)
                         return 0;
                     text = (char *) malloc (length);
                     if(status)
                     {
                        read (client_socket, text, length);
                     }
                     printf ("User Name - %s\n", text);
                     free (text);
                     break;
   }
  }
  pthread_mutex_lock(&mutex);
 }
 pthread_mutex_unlock(&mutex);
 return (void *)1;
}

variable_types:
arg
void *

variable_types: length int

variable_types:
text
char *

variable_types: header int

return_type: void *


decompiled_code:
size_t __fastcall get_home_page(int fd)
{
size_t v1; // rax
size_t result; // rax
char v3[10008]; // [rsp+0h] [rbp-2718h] BYREF

strcpy(v3, "GET /\n");
v1 = strlen(v3);
write(fd, v3, v1);
while ( 1 )
{
result = read(fd, v3, 0x2710uLL);
if ( !result )
break;
fwrite(v3, 1uLL, result, stdout);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(int fd)
{
size_t v1; // rax
size_t result; // rax
char v3[10008]; // [rsp+0h] [rbp-2718h] BYREF

strcpy(v3, "GET /\n");
v1 = strlen(v3);
write(fd, v3, v1);
while ( 1 )
{
result = read(fd, v3, 0x2710uLL);
if ( !result )
break;
fwrite(v3, 1uLL, result, stdout);
}
return result;
}

original_code:
void get_home_page (int socket_fd)
{
 char buffer[10000];
 ssize_t number_characters_read;
 sprintf (buffer, "GET /\n");
 write (socket_fd, buffer, strlen (buffer));
 while (1) {
  number_characters_read = read (socket_fd, buffer, 10000);
  if (number_characters_read == 0)
   return;
   fwrite (buffer, sizeof (char), number_characters_read, stdout);
 }
}

canonical_original_code:
void get_home_page(int socket_fd)
{
 char buffer[10000];
 long number_characters_read;
 sprintf (buffer, "GET /\n");
 write (socket_fd, buffer, strlen (buffer));
 while (1) {
  number_characters_read = read (socket_fd, buffer, 10000);
  if (number_characters_read == 0)
   return;
   fwrite (buffer, sizeof (char), number_characters_read, stdout);
 }
}

variable_types:
buffer
char [10000]

return_type: void


decompiled_code:
__int64 __fastcall send_text(__int64 a1, const char *a2, int a3)
{
int buf[4]; // [rsp+Ch] [rbp-1Ch] BYREF
int v5[3]; // [rsp+1Ch] [rbp-Ch] BYREF

buf[0] = a3;
v5[0] = strlen(a2) + 1;
write(1, buf, 4uLL);
write(1, v5, 4uLL);
write(1, a2, v5[0]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, int a3)
{
int buf[4]; // [rsp+Ch] [rbp-1Ch] BYREF
int v5[3]; // [rsp+1Ch] [rbp-Ch] BYREF

buf[0] = a3;
v5[0] = strlen(a2) + 1;
write(1, buf, 4uLL);
write(1, v5, 4uLL);
write(1, a2, v5[0]);
return 1LL;
}

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

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


writer

decompiled_code:
__int64 __fastcall writer(void *a1)
{
unsigned int v2; // eax
const struct sockaddr *v3; // rsi
int v4; // edi
__m128i *v5; // rbx
unsigned int v6; // eax
__m128i v8; // [rsp+0h] [rbp-218h] BYREF
char v9[496]; // [rsp+10h] [rbp-208h] BYREF

v2 = fcntl(0, 3, 0LL);
BYTE1(v2) |= 8u;
fcntl(0, 4, v2);
v3 = (const struct sockaddr *)((char *)a1 + 4);
memset(v9, 0, sizeof(v9));
v4 = *(_DWORD *)a1;
v8 = _mm_load_si128((const __m128i *)&LC13);
connect(v4, v3, 0x10u);
while ( 1 )
{
printf("Socket id : %d : msg : %s \n", *(unsigned int *)a1, v8.m128i_i8);
if ( (unsigned int)send_text(*(unsigned int *)a1, v8.m128i_i8, 4) == -1 )
break;
v5 = &v8;
do
{
v6 = read(0, v5, 1uLL);
if ( v6 != -1 )
{
if ( v5->m128i_i8[0] == 10 )
break;
v5 = (__m128i *)((char *)v5 + 1);
}
}
while ( status );
v5->m128i_i8[0] = 0;
printf("out of writer : %d\n", v6);
if ( !status )
return 1LL;
}
perror("Write failed.\n");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *a1)
{
unsigned int v2; // eax
const struct sockaddr *v3; // rsi
int v4; // edi
__m128i *v5; // rbx
unsigned int v6; // eax
__m128i v8; // [rsp+0h] [rbp-218h] BYREF
char v9[496]; // [rsp+10h] [rbp-208h] BYREF

v2 = fcntl(0, 3, 0LL);
BYTE1(v2) |= 8u;
fcntl(0, 4, v2);
v3 = (const struct sockaddr *)((char *)a1 + 4);
memset(v9, 0, sizeof(v9));
v4 = *(_DWORD *)a1;
v8 = _mm_load_si128((const __m128i *)&LC13);
connect(v4, v3, 0x10u);
while ( 1 )
{
printf("Socket id : %d : msg : %s \n", *(unsigned int *)a1, v8.m128i_i8);
if ( (unsigned int)func5(*(unsigned int *)a1, v8.m128i_i8, 4) == -1 )
break;
v5 = &v8;
do
{
v6 = read(0, v5, 1uLL);
if ( v6 != -1 )
{
if ( v5->m128i_i8[0] == 10 )
break;
v5 = (__m128i *)((char *)v5 + 1);
}
}
while ( status );
v5->m128i_i8[0] = 0;
printf("out of writer : %d\n", v6);
if ( !status )
return 1LL;
}
perror("Write failed.\n");
return 1LL;
}

original_code:
void * writer (void *arg)
{
 packet *data = (packet *)arg;
 int ret;
 int flags = fcntl(0, 3, 0);
 fcntl(0, 4, flags | 04000);
    char message[512] = {"Ratnesh :"};
    char *pmsg;
 ret = connect (data->socket_fd,(struct sockaddr *) &data->client_name, sizeof(data->client_name));
    do{
  pmsg = message;
     printf("Socket id : %d : msg : %s \n",data->socket_fd,message);
     ret = send_text(data->socket_fd, message,0x04);
     if(ret == -1)
     {
      perror("Write failed.\n");
      break;
  }
        do{
         ret = read(0,pmsg,1);
            if(ret != -1)
            {
                if(*pmsg == '\n')
                    break;
                pmsg++;
            }
        }while( status );
  *pmsg = '\0';
  printf("out of writer : %d\n",ret);
 }while(status);
 return (void *)1;
}

canonical_original_code:
void *writer(void *arg)
{
 struct packet *data = (packet *)arg;
 int ret;
 int flags = fcntl(0, 3, 0);
 fcntl(0, 4, flags | 04000);
    char message[512] = {"Ratnesh :"};
    char *pmsg;
 ret = connect (data->socket_fd,(struct sockaddr *) &data->client_name, sizeof(data->client_name));
    do{
  pmsg = message;
     printf("Socket id : %d : msg : %s \n",data->socket_fd,message);
     ret = send_text(data->socket_fd, message,0x04);
     if(ret == -1)
     {
      perror("Write failed.\n");
      break;
  }
        do{
         ret = read(0,pmsg,1);
            if(ret != -1)
            {
                if(*pmsg == '\n')
                    break;
                pmsg++;
            }
        }while( status );
  *pmsg = '\0';
  printf("out of writer : %d\n",ret);
 }while(status);
 return (void *)1;
}

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

variable_types: flags int

variable_types:
message
char [512]

variable_types:
pmsg
char *

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


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned __int16 v5; // ax
__int64 v6; // rsi
int v7; // eax
__m128i v8; // xmm1
unsigned int v9; // eax
struct hostent *v10; // rax
struct hostent *v11; // r12
const char *v12; // rsi
__int64 v13; // rbx
struct in_addr **v14; // rbx
struct in_addr *v15; // rax
struct in_addr **v16; // rbx
char *v17; // rax
socklen_t addr_len; // [rsp+8h] [rbp-1C0h] BYREF
unsigned int arg; // [rsp+Ch] [rbp-1BCh] BYREF
pthread_t newthread; // [rsp+10h] [rbp-1B8h] BYREF
pthread_t th; // [rsp+18h] [rbp-1B0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-1A8h] BYREF
struct sockaddr v23; // [rsp+30h] [rbp-198h] BYREF
int v24; // [rsp+40h] [rbp-188h] BYREF
__m128i v25; // [rsp+44h] [rbp-184h]
struct sigaction v26; // [rsp+60h] [rbp-168h] BYREF
struct sigaction v27; // [rsp+100h] [rbp-C8h] BYREF

v26.sa_handler = (__sighandler_t)handler;
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_flags = 4;
if ( sigaction(3, &v26, &v27) < 0 )
{
perror("Sigaction quit fail.\n");
goto LABEL_26;
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
perror("Socket not created.\n");
addr = 0LL;
pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, 1);
pthread_mutex_init(&mutex, &Attr);
addr.sa_family = 2;
v5 = _bswap_16_constprop_0("htons : %d\n", &Attr);
v6 = v5;
*(_WORD *)addr.sa_data = v5;
*(_DWORD *)&addr.sa_data[2] = _bswap_32_constprop_0();
printf("htons : %d\n", v6);
printf("htonl : %d\n", *(unsigned int *)&addr.sa_data[2]);
if ( argc == 2 )
{
v10 = gethostbyname(argv[1]);
v11 = v10;
if ( !v10 )
{
perror("Gethostbyname, NULL returned.\n");
goto LABEL_26;
}
printf("Hostinfo->h_name : %s\n", v10->h_name);
v12 = *v11->h_aliases;
if ( v12 )
{
v13 = 1LL;
do
{
printf("Hostinfo->aliases : %s\n", v12);
v12 = v11->h_aliases[v13++];
}
while ( v12 );
}
printf("Hostinfo->h_addrtype : %d\n", (unsigned int)v11->h_addrtype);
printf("Hostinfo->length : %d\n", (unsigned int)v11->h_length);
putchar(10);
v14 = (struct in_addr **)v11->h_addr_list;
v15 = *v14;
if ( *v14 )
{
v16 = v14 + 1;
do
{
++v16;
v17 = inet_ntoa((struct in_addr)v15->s_addr);
printf("hostinfo->addr_list : %s \n", v17);
v15 = *(v16 - 1);
}
while ( v15 );
}
}
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.");
v7 = accept(v3, &v23, &addr_len);
v8 = _mm_loadu_si128((const __m128i *)&v23);
arg = v7;
v24 = v7;
v25 = v8;
if ( v7 == -1 )
perror("accept error.\n");
printf("client accept address : %d \n", v23.sa_family);
printf("after accept ID is: %d.\n", arg);
pthread_mutex_lock(&mutex);
if ( status )
{
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, (void *(*)(void *))reader, &arg);
pthread_create(&th, 0LL, (void *(*)(void *))writer, &v24);
}
if ( (pthread_mutex_unlock(&mutex) & 1) != 0 )
puts("Mutex not locked.");
v9 = getpid();
printf("In parent. pid : %d\n", v9);
pthread_mutex_lock(&mutex);
}
while ( status );
pthread_mutex_unlock(&mutex);
pthread_join(newthread, 0LL);
pthread_join(th, 0LL);
}
LABEL_26:
close(v3);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned __int16 v5; // ax
__int64 v6; // rsi
int v7; // eax
__m128i v8; // xmm1
unsigned int v9; // eax
struct hostent *v10; // rax
struct hostent *v11; // r12
const char *v12; // rsi
__int64 v13; // rbx
struct in_addr **v14; // rbx
struct in_addr *v15; // rax
struct in_addr **v16; // rbx
char *v17; // rax
socklen_t addr_len; // [rsp+8h] [rbp-1C0h] BYREF
unsigned int arg; // [rsp+Ch] [rbp-1BCh] BYREF
pthread_t newthread; // [rsp+10h] [rbp-1B8h] BYREF
pthread_t th; // [rsp+18h] [rbp-1B0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-1A8h] BYREF
struct sockaddr v23; // [rsp+30h] [rbp-198h] BYREF
int v24; // [rsp+40h] [rbp-188h] BYREF
__m128i v25; // [rsp+44h] [rbp-184h]
struct sigaction v26; // [rsp+60h] [rbp-168h] BYREF
struct sigaction v27; // [rsp+100h] [rbp-C8h] BYREF

v26.sa_handler = (__sighandler_t)handler;
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_flags = 4;
if ( sigaction(3, &v26, &v27) < 0 )
{
perror("Sigaction quit fail.\n");
goto LABEL_26;
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
perror("Socket not created.\n");
addr = 0LL;
pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, 1);
pthread_mutex_init(&mutex, &Attr);
addr.sa_family = 2;
v5 = func3("htons : %d\n", &Attr);
v6 = v5;
*(_WORD *)addr.sa_data = v5;
*(_DWORD *)&addr.sa_data[2] = func2();
printf("htons : %d\n", v6);
printf("htonl : %d\n", *(unsigned int *)&addr.sa_data[2]);
if ( argc == 2 )
{
v10 = gethostbyname(argv[1]);
v11 = v10;
if ( !v10 )
{
perror("Gethostbyname, NULL returned.\n");
goto LABEL_26;
}
printf("Hostinfo->h_name : %s\n", v10->h_name);
v12 = *v11->h_aliases;
if ( v12 )
{
v13 = 1LL;
do
{
printf("Hostinfo->aliases : %s\n", v12);
v12 = v11->h_aliases[v13++];
}
while ( v12 );
}
printf("Hostinfo->h_addrtype : %d\n", (unsigned int)v11->h_addrtype);
printf("Hostinfo->length : %d\n", (unsigned int)v11->h_length);
putchar(10);
v14 = (struct in_addr **)v11->h_addr_list;
v15 = *v14;
if ( *v14 )
{
v16 = v14 + 1;
do
{
++v16;
v17 = inet_ntoa((struct in_addr)v15->s_addr);
printf("hostinfo->addr_list : %s \n", v17);
v15 = *(v16 - 1);
}
while ( v15 );
}
}
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.");
v7 = accept(v3, &v23, &addr_len);
v8 = _mm_loadu_si128((const __m128i *)&v23);
arg = v7;
v24 = v7;
v25 = v8;
if ( v7 == -1 )
perror("accept error.\n");
printf("client accept address : %d \n", v23.sa_family);
printf("after accept ID is: %d.\n", arg);
pthread_mutex_lock(&mutex);
if ( status )
{
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, (void *(*)(void *))reader, &arg);
pthread_create(&th, 0LL, (void *(*)(void *))writer, &v24);
}
if ( (pthread_mutex_unlock(&mutex) & 1) != 0 )
puts("Mutex not locked.");
v9 = getpid();
printf("In parent. pid : %d\n", v9);
pthread_mutex_lock(&mutex);
}
while ( status );
pthread_mutex_unlock(&mutex);
pthread_join(newthread, 0LL);
pthread_join(th, 0LL);
}
LABEL_26:
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: 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]; }

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


handler

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

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

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

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


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // rdx
struct in_addr inp[4]; // [rsp+0h] [rbp-368h] BYREF
struct sigaction v6; // [rsp+10h] [rbp-358h] BYREF
struct sigaction v7; // [rsp+B0h] [rbp-2B8h] BYREF
__m128i buf; // [rsp+150h] [rbp-218h] BYREF
char v9[496]; // [rsp+160h] [rbp-208h] BYREF

v6.sa_handler = (__sighandler_t)handler;
memset(&v6.sa_mask, 0, 0x90uLL);
v6.sa_flags = 4;
if ( sigaction(3, &v6, &v7) < 0 )
{
perror("Sigaction quit fail.\n");
}
else if ( sigaction(2, &v6, &v7) < 0 )
{
perror("Sigaction int fail.\n");
}
else
{
*(_OWORD *)&inp[0].s_addr = 0LL;
v3 = socket(2, 1, 0);
LOWORD(inp[0].s_addr) = 2;
HIWORD(inp[0].s_addr) = _bswap_16_constprop_0(2LL, 1LL, v4);
if ( argc == 2 )
{
if ( !inet_aton(argv[1], &inp[1]) )
perror("Address is not valid.\n");
}
else
{
inp[1].s_addr = _bswap_32_constprop_0();
}
printf("ip : %u\n", inp[1].s_addr);
if ( connect(v3, (const struct sockaddr *)inp, 0x10u) == -1 )
puts("Connect error.");
memset(v9, 0, sizeof(v9));
buf = _mm_load_si128((const __m128i *)&xmmword_4020D0);
while ( 1 )
{
printf("Socket id : %d : msg : %s \n", v3, buf.m128i_i8);
if ( (unsigned int)write_text(v3, &buf) == -1 )
break;
__isoc99_scanf();
if ( !status )
goto LABEL_11;
}
perror("Write failed.\n");
LABEL_11:
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; // ebp
__int64 v4; // rdx
struct in_addr inp[4]; // [rsp+0h] [rbp-368h] BYREF
struct sigaction v6; // [rsp+10h] [rbp-358h] BYREF
struct sigaction v7; // [rsp+B0h] [rbp-2B8h] BYREF
__m128i buf; // [rsp+150h] [rbp-218h] BYREF
char v9[496]; // [rsp+160h] [rbp-208h] BYREF

v6.sa_handler = (__sighandler_t)handler;
memset(&v6.sa_mask, 0, 0x90uLL);
v6.sa_flags = 4;
if ( sigaction(3, &v6, &v7) < 0 )
{
perror("Sigaction quit fail.\n");
}
else if ( sigaction(2, &v6, &v7) < 0 )
{
perror("Sigaction int fail.\n");
}
else
{
*(_OWORD *)&inp[0].s_addr = 0LL;
v3 = socket(2, 1, 0);
LOWORD(inp[0].s_addr) = 2;
HIWORD(inp[0].s_addr) = func9(2LL, 1LL, v4);
if ( argc == 2 )
{
if ( !inet_aton(argv[1], &inp[1]) )
perror("Address is not valid.\n");
}
else
{
inp[1].s_addr = func8();
}
printf("ip : %u\n", inp[1].s_addr);
if ( connect(v3, (const struct sockaddr *)inp, 0x10u) == -1 )
puts("Connect error.");
memset(v9, 0, sizeof(v9));
buf = _mm_load_si128((const __m128i *)&xmmword_4020D0);
while ( 1 )
{
printf("Socket id : %d : msg : %s \n", v3, buf.m128i_i8);
if ( (unsigned int)func10(v3, &buf) == -1 )
break;
__isoc99_scanf();
if ( !status )
goto LABEL_11;
}
perror("Write failed.\n");
LABEL_11:
puts("Existing main.");
close(v3);
}
exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

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

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


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


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
__int64 v2; // rdx

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

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

if ( *((_WORD *)ptr + 5) )
{
v1 = 0;
do
{
v2 = (unsigned __int16)v1++;
free(*(void **)(*(_QWORD *)ptr + 8 * v2));
}
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;
}


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 *


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:
// attributes: thunk
void void_stack_iterator_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func6(void *ptr)
{
free(ptr);
}

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


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


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:
info
char **

variable_types: i int


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

variable_types:
argv
char *[]


decompiled_code:
char *__fastcall get_value(char *s)
{
char *v1; // rbp
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; // rbp
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; // r12
char *v2; // rax
char *v3; // rax
char *v4; // rbx
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 )
return v1;
v6 = strlen(v3);
memcpy(v1, v4 + 1, v6 + 1);
return v1;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
char *v1; // r12
char *v2; // rax
char *v3; // rax
char *v4; // rbx
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 )
return v1;
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 **v2; // rbx
void *v3; // rax
void *v4; // r13
_QWORD *v5; // rbp
char *v6; // rax
char *v7; // rdi
char *v8; // r12
char *v9; // rax
__int64 result; // rax

v2 = (const char **)rll_get_value_strings();
v3 = calloc(0x100uLL, 8uLL);
v4 = v3;
if ( v2 )
{
v5 = v3;
while ( *v2 )
{
v6 = get_base_key(*v2);
v7 = (char *)*v2;
v5 += 2;
++v2;
v8 = v6;
v9 = get_value(v7);
*(v5 - 2) = v8;
*(v5 - 1) = v9;
}
}
result = 0LL;
*a1 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
const char **v2; // rbx
void *v3; // rax
void *v4; // r13
_QWORD *v5; // rbp
char *v6; // rax
char *v7; // rdi
char *v8; // r12
char *v9; // rax
__int64 result; // rax

v2 = (const char **)rll_get_value_strings();
v3 = calloc(0x100uLL, 8uLL);
v4 = v3;
if ( v2 )
{
v5 = v3;
while ( *v2 )
{
v6 = func7(*v2);
v7 = (char *)*v2;
v5 += 2;
++v2;
v8 = v6;
v9 = func6(v7);
*(v5 - 2) = v8;
*(v5 - 1) = v9;
}
}
result = 0LL;
*a1 = v4;
return result;
}

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 result; // rax
__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);
}
result = 0LL;
}
else
{
fwrite("Invalid parameters\n", 1uLL, 0x13uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
__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);
}
result = 0LL;
}
else
{
fwrite("Invalid parameters\n", 1uLL, 0x13uLL, stderr);
result = 0LL;
}
return result;
}

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

variable_types: i int

variable_types:
info
char **


gensquare

repo: coron/htable

decompiled_code:
int gensquare()
{
unsigned int v0; // ebx
unsigned __int8 v1; // al

v0 = 0;
printf("byte sq[256]={");
LABEL_4:
putchar(10);
while ( 1 )
{
v1 = mult(v0, v0);
printf("0x%02x", v1);
if ( v0 == 255 )
return puts("};");
++v0;
putchar(44);
if ( (v0 & 7) == 0 )
goto LABEL_4;
}
}

canonical_decompiled_code:
int func0()
{
unsigned int v0; // ebx
unsigned __int8 v1; // al

v0 = 0;
printf("byte sq[256]={");
LABEL_4:
putchar(10);
while ( 1 )
{
v1 = mult(v0, v0);
printf("0x%02x", v1);
if ( v0 == 255 )
return puts("};");
++v0;
putchar(44);
if ( (v0 & 7) == 0 )
goto LABEL_4;
}
}

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()
{
unsigned int v0; // ebx
unsigned __int8 v1; // al

v0 = 0;
printf("byte taffine[256]={");
LABEL_4:
putchar(10);
while ( 1 )
{
v1 = affine(v0);
printf("0x%02x", v1);
if ( v0 == 255 )
return puts("};");
++v0;
putchar(44);
if ( (v0 & 7) == 0 )
goto LABEL_4;
}
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // ebx
unsigned __int8 v1; // al

v0 = 0;
printf("byte taffine[256]={");
LABEL_4:
putchar(10);
while ( 1 )
{
v1 = affine(v0);
printf("0x%02x", v1);
if ( v0 == 255 )
return puts("};");
++v0;
putchar(44);
if ( (v0 & 7) == 0 )
goto LABEL_4;
}
}

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)
{
char v4; // di
char v5; // cl
unsigned __int8 v6; // si
int v7; // eax
__int64 v8; // rdx

v4 = a1 & 0xF0;
v5 = 16 * a1;
v6 = a2 >> 4;
a2 &= 0xFu;
v7 = a2;
v8 = (unsigned __int8)(v4 | a2);
BYTE1(v8) = 2;
return tsmult[v5 & 0xF0 | v6 | 0x100] ^ tsmult[(unsigned __int8)(v6 | v4) | 0x300LL] ^ tsmult[v5 & 0xF0 | v7] ^ tsmult[v8];
}

canonical_decompiled_code:
char __fastcall func4(char a1, unsigned __int8 a2)
{
char v4; // di
char v5; // cl
unsigned __int8 v6; // si
int v7; // eax
__int64 v8; // rdx

v4 = a1 & 0xF0;
v5 = 16 * a1;
v6 = a2 >> 4;
a2 &= 0xFu;
v7 = a2;
v8 = (unsigned __int8)(v4 | a2);
BYTE1(v8) = 2;
return tsmult[v5 & 0xF0 | v6 | 0x100] ^ tsmult[(unsigned __int8)(v6 | v4) | 0x300LL] ^ tsmult[v5 & 0xF0 | v7] ^ tsmult[v8];
}


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:
tmp
unsigned char


decompiled_code:
__int64 __fastcall subbyte_rp(unsigned __int8 a1)
{
char v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // r8
unsigned __int8 v4; // si
char v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // r8
unsigned __int8 v8; // si
char v9; // al
unsigned __int8 v10; // al
unsigned __int8 v11; // r9
unsigned __int8 v12; // si
unsigned __int8 v13; // al
unsigned __int8 v14; // al
unsigned __int8 v15; // al
char v16; // al

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

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
char v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // r8
unsigned __int8 v4; // si
char v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // r8
unsigned __int8 v8; // si
char v9; // al
unsigned __int8 v10; // al
unsigned __int8 v11; // r9
unsigned __int8 v12; // si
unsigned __int8 v13; // al
unsigned __int8 v14; // al
unsigned __int8 v15; // al
char v16; // al

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

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 v3; // al
unsigned __int8 *v4; // rcx

if ( a2 > 0 )
{
do
{
v3 = square(*a1);
*(a1 - 1) = v3;
}
while ( a1 != v4 );
}
}

canonical_decompiled_code:
void __fastcall func7(unsigned __int8 *a1, int a2)
{
unsigned __int8 v3; // al
unsigned __int8 *v4; // rcx

if ( a2 > 0 )
{
do
{
v3 = func1(*a1);
*(a1 - 1) = v3;
}
while ( a1 != v4 );
}
}

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)
{
__int64 result; // rax
unsigned __int8 *v3; // r11

do
{
result = subbyte_rp(*a1);
*(a1 - 1) = result;
}
while ( a1 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 *v3; // r11

do
{
result = func6(*a1);
*(a1 - 1) = result;
}
while ( a1 != v3 );
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(const __m128i *a1, __m128i *a2, __int64 a3)
{
unsigned int v3; // ebx
__int64 result; // rax
__m128i v5; // [rsp+0h] [rbp-D8h] BYREF
char v6[200]; // [rsp+10h] [rbp-C8h] BYREF

keyexpansion(a3, v6);
v3 = 1;
v5 = _mm_loadu_si128(a1);
addroundkey(&v5, v6, 0LL);
do
{
subbytestate_rp((unsigned __int8 *)&v5);
shiftrows(&v5);
mixcolumns(&v5);
addroundkey(&v5, v6, v3++);
}
while ( v3 != 10 );
subbytestate(&v5);
shiftrows(&v5);
result = addroundkey(&v5, v6, 10LL);
*a2 = _mm_load_si128(&v5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const __m128i *a1, __m128i *a2, __int64 a3)
{
unsigned int v3; // ebx
__int64 result; // rax
__m128i v5; // [rsp+0h] [rbp-D8h] BYREF
char v6[200]; // [rsp+10h] [rbp-C8h] BYREF

keyexpansion(a3, v6);
v3 = 1;
v5 = _mm_loadu_si128(a1);
addroundkey(&v5, v6, 0LL);
do
{
func10((unsigned __int8 *)&v5);
shiftrows(&v5);
mixcolumns(&v5);
addroundkey(&v5, v6, v3++);
}
while ( v3 != 10 );
subbytestate(&v5);
shiftrows(&v5);
result = addroundkey(&v5, v6, 10LL);
*a2 = _mm_load_si128(&v5);
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:
__int64 test_mult_gf16()
{
__int64 result; // rax
char v1; // [rsp+Eh] [rbp-Ah] BYREF
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

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

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

result = func0(0x81u, 0x25u, 0x17u, 0xDu, &v1, v2);
if ( v1 != -119 )
_assert_fail("c0==137", "prg.c", 0x1Bu, "test_mult_gf16");
if ( v2[0] != -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 v8; // r13
unsigned __int8 v9; // si
unsigned __int8 result; // al
char v14; // si
char v15; // [rsp+0h] [rbp-3Ah] BYREF
char v16[57]; // [rsp+1h] [rbp-39h] BYREF

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

canonical_decompiled_code:
unsigned __int8 __fastcall func2(__int64 a1, int a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 *a5, unsigned __int8 *a6)
{
int v6; // esi
__int64 v8; // r13
unsigned __int8 v9; // si
unsigned __int8 result; // al
char v14; // si
char v15; // [rsp+0h] [rbp-3Ah] BYREF
char v16[57]; // [rsp+1h] [rbp-39h] BYREF

*a5 = 0;
*a6 = 0;
v6 = a2 - 1;
if ( v6 >= 0 )
{
v8 = v6;
v9 = 0;
do
{
func0(*a5, v9, a3, a4, &v15, v16);
result = v15 ^ *(_BYTE *)(a1 + 2 * v8);
*a5 = result;
v14 = *(_BYTE *)(a1 + 2 * v8-- + 1);
v9 = v16[0] ^ v14;
*a6 = v9;
}
while ( (int)v8 >= 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

variable_types: i 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, &v1, &v2);
if ( v1 != 0xB4 )
_assert_fail("r0==180", "prg.c", 0x33u, "test_eval_poly_gf16");
if ( v2 != 113 )
_assert_fail("r1==113", "prg.c", 0x34u, "test_eval_poly_gf16");
return result;
}

canonical_decompiled_code:
unsigned __int8 func3()
{
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 = func2((__int64)&v3, 2, 0x43u, 0xCu, &v1, &v2);
if ( v1 != 0xB4 )
_assert_fail("r0==180", "prg.c", 0x33u, "test_eval_poly_gf16");
if ( v2 != 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);
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = result;
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 func4(__int64 a1, int a2)
{
void *result; // rax
__int64 v3; // rbx

*(_DWORD *)(a1 + 4) = a2;
result = malloc(2 * a2);
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = result;
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 func5(int a1)
{
return func4((__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 func7()
{
return func6((__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 func8()
{
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 func9()
{
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

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

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

v0 = 100;
func5(10);
do
{
v1 = func7();
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 v4; // rbx
__int64 v5; // rdi

result = malloc(24LL * a2);
robprg = result;
if ( a2 > 0 )
{
v4 = 0LL;
while ( 1 )
{
v5 = (__int64)result + v4;
v4 += 24LL;
result = init_prg_p(v5, a1);
if ( v4 == 24LL * a2 )
break;
result = robprg;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func11(int a1, int a2)
{
void *result; // rax
__int64 v4; // rbx
__int64 v5; // rdi

result = malloc(24LL * a2);
robprg = result;
if ( a2 > 0 )
{
v4 = 0LL;
while ( 1 )
{
v5 = (__int64)result + v4;
v4 += 24LL;
result = func4(v5, a1);
if ( v4 == 24LL * a2 )
break;
result = robprg;
}
}
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; // er12
__int64 v3; // rbp
char *v4; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 v1; // rbx
unsigned int v2; // er12
__int64 v3; // rbp
char *v4; // rdi

if ( a1 <= 0 )
return 0LL;
v1 = 0LL;
v2 = 0;
v3 = 24LL * a1;
do
{
v4 = (char *)robprg + v1;
v1 += 24LL;
v2 ^= func6((__int64)v4);
}
while ( v1 != v3 );
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 func13()
{
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
__int64 v2; // rbp
void *v3; // rdi

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

canonical_decompiled_code:
void __fastcall func14(int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
void *v3; // rdi

if ( a1 > 0 )
{
v1 = 0LL;
v2 = 24LL * a1;
do
{
v3 = *(void **)((char *)robprg + v1 + 8);
v1 += 24LL;
free(v3);
}
while ( v1 != v2 );
}
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 v4; // er14
void *v8; // rax
__int64 v9; // r14
__int64 v10; // r13
__int64 v11; // rdi
void *result; // rax
__int64 v13; // rbp
__int64 v14; // rdi

v4 = a4 - 1;
mprg = 0;
v8 = malloc(24LL * (a4 - 1));
*((_QWORD *)&mprg + 1) = v8;
if ( v4 > 0 )
{
v9 = 0LL;
v10 = 8 * (3LL * (unsigned int)(a4 - 2) + 3);
while ( 1 )
{
v11 = (__int64)v8 + v9;
v9 += 24LL;
init_prg_p(v11, a1);
if ( v10 == v9 )
break;
v8 = (void *)*((_QWORD *)&mprg + 1);
}
}
result = malloc(24LL * a2);
*((_QWORD *)&mprg + 2) = result;
if ( a2 > 0 )
{
v13 = 0LL;
while ( 1 )
{
v14 = (__int64)result + v13;
v13 += 24LL;
result = init_prg_p(v14, a3);
if ( 24LL * a2 == v13 )
break;
result = (void *)*((_QWORD *)&mprg + 2);
}
}
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


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

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
++mprg;
return func6(*((_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 func18(int a1)
{
++mprg;
return func6(*((_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 func19()
{
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
unsigned __int8 *v3; // rbp
__int64 v4; // rsi

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

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

v2 = a2;
v3 = a2 + 16;
printf("%s=", a1);
do
{
v4 = *v2++;
printf("%02x", v4);
}
while ( v2 != v3 );
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 *


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, int a4)
{
__int64 result; // rax
__int64 v7; // rbx
_BYTE *v8; // r13
__int64 v9; // rbp
__int64 v10; // r14
char v11; // bl
char v12; // al
_BYTE *v13; // rbx
char v14; // [rsp+17h] [rbp-41h]
__int64 v15; // [rsp+18h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
__int64 result; // rax
__int64 v7; // rbx
_BYTE *v8; // r13
__int64 v9; // rbp
__int64 v10; // r14
char v11; // bl
char v12; // al
_BYTE *v13; // rbx
char v14; // [rsp+17h] [rbp-41h]
__int64 v15; // [rsp+18h] [rbp-40h]

result = a4;
v7 = 0LL;
v15 = a4;
if ( a4 > 0 )
{
do
{
result = multtable(*(unsigned __int8 *)(a1 + v7), *(unsigned __int8 *)(a2 + v7));
a3[v7++] = result;
}
while ( v7 != v15 );
if ( a4 > 1 )
{
v8 = a3 + 1;
v9 = 1LL;
do
{
v10 = 0LL;
do
{
v11 = get_robprg((unsigned int)a4);
v14 = v11 ^ multtable(*(unsigned __int8 *)(a1 + v10), *(unsigned __int8 *)(a2 + v9));
v12 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v10));
a3[v10++] ^= v11;
*v8 ^= v12 ^ v14;
}
while ( v9 != v10 );
v13 = a3;
do
{
++v13;
result = get_robprg((unsigned int)a4);
*v8 ^= *(v13 - 1) ^ (unsigned __int8)result;
*(v13 - 1) = result;
}
while ( v13 != v8 );
++v9;
++v8;
}
while ( v15 != v9 );
}
}
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


decompiled_code:
__int64 __fastcall multshare_ilr_mprg(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax
__int64 v7; // rbx
_BYTE *v8; // r14
__int64 v9; // r12
__int64 v10; // r15
int v11; // ebp
int v12; // ebx
char v13; // al
__int64 v14; // rbx
__int64 v15; // [rsp+18h] [rbp-40h]

result = a4;
v7 = 0LL;
v15 = a4;
if ( a4 > 0 )
{
do
{
result = multtable(*(unsigned __int8 *)(a1 + v7), *(unsigned __int8 *)(a2 + v7));
*(_BYTE *)(a3 + v7++) = result;
}
while ( v7 != v15 );
if ( a4 > 1 )
{
v8 = (_BYTE *)(a3 + 1);
v9 = 1LL;
do
{
v10 = 0LL;
do
{
v11 = get_mprgi((unsigned int)v10);
v12 = v11 ^ multtable(*(unsigned __int8 *)(a1 + v10), *(unsigned __int8 *)(a2 + v9));
v13 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v10));
*(_BYTE *)(a3 + v10++) ^= v11;
*v8 ^= v13 ^ (unsigned __int8)v12;
}
while ( v10 != v9 );
v14 = 0LL;
do
{
result = get_mprgc((unsigned int)v14);
*v8 ^= *(_BYTE *)(a3 + v14) ^ (unsigned __int8)result;
*(_BYTE *)(a3 + v14++) = result;
}
while ( v14 != v9 );
++v9;
++v8;
}
while ( v15 != v9 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax
__int64 v7; // rbx
_BYTE *v8; // r14
__int64 v9; // r12
__int64 v10; // r15
int v11; // ebp
int v12; // ebx
char v13; // al
__int64 v14; // rbx
__int64 v15; // [rsp+18h] [rbp-40h]

result = a4;
v7 = 0LL;
v15 = a4;
if ( a4 > 0 )
{
do
{
result = multtable(*(unsigned __int8 *)(a1 + v7), *(unsigned __int8 *)(a2 + v7));
*(_BYTE *)(a3 + v7++) = result;
}
while ( v7 != v15 );
if ( a4 > 1 )
{
v8 = (_BYTE *)(a3 + 1);
v9 = 1LL;
do
{
v10 = 0LL;
do
{
v11 = get_mprgi((unsigned int)v10);
v12 = v11 ^ multtable(*(unsigned __int8 *)(a1 + v10), *(unsigned __int8 *)(a2 + v9));
v13 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v10));
*(_BYTE *)(a3 + v10++) ^= v11;
*v8 ^= v13 ^ (unsigned __int8)v12;
}
while ( v10 != v9 );
v14 = 0LL;
do
{
result = get_mprgc((unsigned int)v14);
*v8 ^= *(_BYTE *)(a3 + v14) ^ (unsigned __int8)result;
*(_BYTE *)(a3 + v14++) = result;
}
while ( v14 != v9 );
++v9;
++v8;
}
while ( v15 != v9 );
}
}
return result;
}

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

variable_types: i int


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

if ( a2 > 1 )
{
v2 = a1;
do
{
++v2;
v3 = get_robprg((unsigned int)a2);
*(_BYTE *)(a1 + a2 - 1) ^= *(_BYTE *)(v2 - 1) ^ v3;
*(_BYTE *)(v2 - 1) = v3;
}
while ( v2 != a1 + (unsigned int)(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;
  }
}


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 ( a2 - 2 != v4 );
}
}

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)
{
_BYTE *v4; // r14
__int64 v5; // r12
__int64 v6; // rbx
char v7; // al
__int64 v8; // rax

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

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

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

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


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 ( a4 != v6 );
}
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 i; // r15
char v7; // al
char v8; // r12

v5 = a4;
locality_refresh_mprgmatabc(a1, 0, a4);
locality_refresh_mprgmatabc(a2, 1u, v5);
if ( v5 > 0 )
{
for ( i = 0LL; i != v5; ++i )
{
v7 = multx(*(unsigned __int8 *)(a1 + i));
v8 = *(_BYTE *)(a1 + i);
*(_BYTE *)(a3 + i) = multx(*(unsigned __int8 *)(a2 + i)) ^ v7 ^ 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);
}