variable_types:
vec
float [3]

variable_types: sz float

variable_types: c float

variable_types: d float


SendFileData

decompiled_code:
__int64 __fastcall SendFileData(int fd)
{
int v1; // eax
int v2; // er15
int v3; // eax
int v4; // ebp
int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // er14
int v8; // eax
_BYTE v10[4152]; // [rsp+0h] [rbp-1038h] BYREF

v1 = open(compressedfilename, 0);
if ( v1 < 0 )
{
ErrorReport(1008LL);
v7 = -1;
}
else
{
v2 = v1;
memset(v10, 0, 0x1000uLL);
v3 = read(v1, v10, 0x1000uLL);
v4 = v3;
if ( v3 )
{
if ( v3 == -1 )
{
LABEL_9:
ErrorReport(1009LL);
close(v2);
v7 = -1;
}
else
{
while ( 1 )
{
v5 = 0;
if ( v4 > 0 )
break;
LABEL_7:
memset(v10, 0, 0x1000uLL);
v8 = read(v2, v10, 0x1000uLL);
v4 = v8;
if ( !v8 )
goto LABEL_13;
if ( v8 == -1 )
goto LABEL_9;
}
while ( 1 )
{
v6 = send(fd, &v10[v5], v4 - v5, 0);
v7 = v6;
if ( v6 == -1 )
break;
v5 += v6;
if ( v5 >= v4 )
goto LABEL_7;
}
ErrorReport(1010LL);
close(v2);
}
}
else
{
LABEL_13:
close(v2);
v7 = 0;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
int v1; // eax
int v2; // er15
int v3; // eax
int v4; // ebp
int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // er14
int v8; // eax
_BYTE v10[4152]; // [rsp+0h] [rbp-1038h] BYREF

v1 = open(compressedfilename, 0);
if ( v1 < 0 )
{
ErrorReport(1008LL);
v7 = -1;
}
else
{
v2 = v1;
memset(v10, 0, 0x1000uLL);
v3 = read(v1, v10, 0x1000uLL);
v4 = v3;
if ( v3 )
{
if ( v3 == -1 )
{
LABEL_9:
ErrorReport(1009LL);
close(v2);
v7 = -1;
}
else
{
while ( 1 )
{
v5 = 0;
if ( v4 > 0 )
break;
LABEL_7:
memset(v10, 0, 0x1000uLL);
v8 = read(v2, v10, 0x1000uLL);
v4 = v8;
if ( !v8 )
goto LABEL_13;
if ( v8 == -1 )
goto LABEL_9;
}
while ( 1 )
{
v6 = send(fd, &v10[v5], v4 - v5, 0);
v7 = v6;
if ( v6 == -1 )
break;
v5 += v6;
if ( v5 >= v4 )
goto LABEL_7;
}
ErrorReport(1010LL);
close(v2);
}
}
else
{
LABEL_13:
close(v2);
v7 = 0;
}
}
return v7;
}

original_code:
int SendFileData(int socket)
{
 int fd;
 int sendlength = 0;
 int i;
 int filechunklength = 0;
 char buf[4096];
 fd = open(compressedfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  return -1;
 }
 bzero(buf, 4096);
 filechunklength = read(fd, buf, 4096);
 while(filechunklength)
    {
        if(-1 == filechunklength)
        {
            ErrorReport(1009);
   close(fd);
   return -1;
        }
        for(i = 0; i < filechunklength; i += sendlength)
        {
            sendlength = send(socket, buf + i, filechunklength - i, 0);
         if(-1 == sendlength)
         {
             ErrorReport(1010);
    close(fd);
    return -1;
         }
        }
  bzero(buf, 4096);
     filechunklength = read(fd, buf, 4096);
    }
    close(fd);
   return 0;
}

variable_types: socket int

variable_types: fd int

variable_types: sendlength int

variable_types: i int

variable_types: filechunklength int

variable_types:
buf
char [4096]

return_type: int


FileCompress

decompiled_code:
__int64 FileCompress()
{
int v0; // er12
__int64 v1; // r13
unsigned int v2; // eax
__int64 v3; // rdx
unsigned int v4; // ebx
unsigned int v5; // eax
_BYTE v7[4136]; // [rsp+0h] [rbp-1028h] BYREF

v0 = open(originalfilename, 0);
v1 = gzopen(compressedfilename, &unk_808);
memset(v7, 0, 0x1000uLL);
v2 = read(v0, v7, 0x1000uLL);
if ( v2 )
{
v3 = v2;
if ( v2 == -1 )
{
LABEL_6:
ErrorReport(1009LL);
close(v0);
gzclose(v1);
v4 = -1;
}
else
{
while ( 1 )
{
v4 = gzwrite(v1, v7, v3);
if ( v4 == -1 )
break;
memset(v7, 0, 0x1000uLL);
v5 = read(v0, v7, 0x1000uLL);
v3 = v5;
if ( !v5 )
goto LABEL_8;
if ( v5 == -1 )
goto LABEL_6;
}
ErrorReport(1011LL);
close(v0);
gzclose(v1);
}
}
else
{
LABEL_8:
close(v0);
gzclose(v1);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er12
__int64 v1; // r13
unsigned int v2; // eax
__int64 v3; // rdx
unsigned int v4; // ebx
unsigned int v5; // eax
_BYTE v7[4136]; // [rsp+0h] [rbp-1028h] BYREF

v0 = open(originalfilename, 0);
v1 = gzopen(compressedfilename, &unk_808);
memset(v7, 0, 0x1000uLL);
v2 = read(v0, v7, 0x1000uLL);
if ( v2 )
{
v3 = v2;
if ( v2 == -1 )
{
LABEL_6:
ErrorReport(1009LL);
close(v0);
gzclose(v1);
v4 = -1;
}
else
{
while ( 1 )
{
v4 = gzwrite(v1, v7, v3);
if ( v4 == -1 )
break;
memset(v7, 0, 0x1000uLL);
v5 = read(v0, v7, 0x1000uLL);
v3 = v5;
if ( !v5 )
goto LABEL_8;
if ( v5 == -1 )
goto LABEL_6;
}
ErrorReport(1011LL);
close(v0);
gzclose(v1);
}
}
else
{
LABEL_8:
close(v0);
gzclose(v1);
v4 = 0;
}
return v4;
}

original_code:
int FileCompress(void)
{
 int fd;
 gzFile fc;
 char compressedbuf[4096];
 int compresslength;
 int writelength;
 fd = open(originalfilename, 00);
    fc = gzopen(compressedfilename, "wb");
 bzero(compressedbuf, 4096);
 compresslength = read(fd, compressedbuf, 4096);
 while(compresslength)
    {
        if(-1 == compresslength)
        {
            ErrorReport(1009);
   close(fd);
   gzclose(fc);
   return -1;
        }
        writelength = gzwrite(fc, compressedbuf, compresslength);
        if(-1 == writelength)
        {
            ErrorReport(1011);
   close(fd);
   gzclose(fc);
   return -1;
        }
  bzero(compressedbuf, 4096);
     compresslength = read(fd, compressedbuf, 4096);
    }
    close(fd);
 gzclose(fc);
 return 0;
}

canonical_original_code:
int FileCompress()
{
 int fd;
 struct gzFile_s *fc;
 char compressedbuf[4096];
 int compresslength;
 int writelength;
 fd = open(originalfilename, 00);
    fc = gzopen(compressedfilename, "wb");
 bzero(compressedbuf, 4096);
 compresslength = read(fd, compressedbuf, 4096);
 while(compresslength)
    {
        if(-1 == compresslength)
        {
            ErrorReport(1009);
   close(fd);
   gzclose(fc);
   return -1;
        }
        writelength = gzwrite(fc, compressedbuf, compresslength);
        if(-1 == writelength)
        {
            ErrorReport(1011);
   close(fd);
   gzclose(fc);
   return -1;
        }
  bzero(compressedbuf, 4096);
     compresslength = read(fd, compressedbuf, 4096);
    }
    close(fd);
 gzclose(fc);
 return 0;
}

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *

variable_types:
compressedbuf
char [4096]

variable_types: compresslength int

variable_types: writelength int


GetFileSize

decompiled_code:
__int64 __fastcall GetFileSize(const char *a1)
{
bool v1; // zf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = LODWORD(v3.st_size);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
bool v1; // zf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = LODWORD(v3.st_size);
return result;
}

original_code:
int GetFileSize(const char *file_name)
{
       struct stat buf;
       if (stat(file_name, &buf) != 0 )
         return 0;
       return( buf.st_size );
}

canonical_original_code:
int GetFileSize(char *file_name)
{
       struct stat buf;
       if (stat(file_name, &buf) != 0 )
         return 0;
       return( buf.st_size );
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


ReceiveFileStatus

decompiled_code:
__int64 __fastcall ReceiveFileStatus(int a1)
{
int v1; // eax
unsigned __int64 v2; // rbx
size_t v3; // rbx
int v4; // eax
int v5; // er13
size_t v7; // rax
int v8; // eax
int v9; // ebp
int v10; // er14
char *v11; // rbx
int v12; // er12
int v13; // eax
signed int v14; // eax
__int64 v15; // rax
int v16; // edx
unsigned int v17; // [rsp+4h] [rbp-2064h]
unsigned __int64 v18; // [rsp+8h] [rbp-2060h]
int v19; // [rsp+14h] [rbp-2054h]
int v20; // [rsp+18h] [rbp-2050h]
int v21; // [rsp+1Ch] [rbp-204Ch]
char v22[16]; // [rsp+20h] [rbp-2048h] BYREF
char buf[4096]; // [rsp+30h] [rbp-2038h] BYREF
char s[4152]; // [rsp+1030h] [rbp-1038h] BYREF

v1 = GetFileSize(originalfilename);
v2 = v1;
v18 = v1;
printf("File size = %llu\n", v1);
bitmaplength = (v2 >> 15) + 1;
v3 = bitmaplength;
bitmap_buf = malloc(bitmaplength);
memset(bitmap_buf, 0, v3);
v4 = open(originalfilename, 0);
if ( v4 < 0 )
{
ErrorReport(1008LL);
free(bitmap_buf);
v17 = -1;
}
else
{
v5 = v4;
memset(buf, 0, sizeof(buf));
recv(a1, buf, 0x1000uLL, 0);
if ( !strcmp(buf, no_file) )
{
puts("Send the whole file...");
v17 = SendFileData(a1);
if ( v17 == -1 )
free(bitmap_buf);
else
v17 = 1;
}
else
{
v20 = atoi(buf);
puts("Send file size....");
sprintf(s, "%llu", v18);
v7 = strlen(s);
v17 = send(a1, s, v7 + 1, 0);
if ( v17 == -1 )
{
ErrorReport(1005LL);
free(bitmap_buf);
}
else
{
puts("Begin to receive MD5 data....");
memset(buf, 0, sizeof(buf));
v8 = recv(a1, buf, 0x1000uLL, 0);
v19 = v8;
if ( v8 )
{
if ( v8 == -1 )
{
LABEL_16:
ErrorReport(1004LL);
close(v5);
free(bitmap_buf);
v17 = -1;
}
else
{
v21 = v20;
v9 = 7;
v10 = 0;
while ( 1 )
{
v11 = buf;
v12 = 0;
if ( v19 > 15 )
break;
LABEL_13:
memset(buf, 0, sizeof(buf));
v21 -= v19;
if ( !v21 )
{
puts("Receive enough MD5 Data");
goto LABEL_30;
}
v13 = recv(a1, buf, 0x1000uLL, 0);
v19 = v13;
if ( !v13 )
goto LABEL_30;
if ( v13 == -1 )
goto LABEL_16;
}
while ( 1 )
{
v14 = read(v5, s, 0x1000uLL);
v17 = v14;
if ( v14 == -1 )
break;
MD5(s, v14, v22);
v15 = 0LL;
while ( v22[v15] == v11[v15] )
{
if ( ++v15 == 16 )
goto LABEL_20;
}
*((_BYTE *)bitmap_buf + v10) |= 1 << v9;
LABEL_20:
if ( --v9 == -1 )
{
++v10;
v9 = 7;
}
++v12;
v11 += 16;
if ( v12 >= v19 / 16 )
goto LABEL_13;
}
ErrorReport(1009LL);
close(v5);
free(bitmap_buf);
}
}
else
{
v10 = 0;
v9 = 7;
LABEL_30:
v16 = v20 / 16 + 1;
if ( (int)((v18 >> 12) + 1) >= v16 )
{
do
{
*((_BYTE *)bitmap_buf + v10) |= 1 << v9--;
if ( v9 == -1 )
{
++v10;
v9 = 7;
}
++v16;
}
while ( v16 != (unsigned int)(v18 >> 12) + 2 );
}
puts("Send bitmap information....");
v17 = send(a1, bitmap_buf, bitmaplength, 0);
if ( v17 == -1 )
{
ErrorReport(1005LL);
close(v5);
free(bitmap_buf);
}
else
{
close(v5);
v17 = 0;
}
}
}
}
}
return v17;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // eax
unsigned __int64 v2; // rbx
size_t v3; // rbx
int v4; // eax
int v5; // er13
size_t v7; // rax
int v8; // eax
int v9; // ebp
int v10; // er14
char *v11; // rbx
int v12; // er12
int v13; // eax
signed int v14; // eax
__int64 v15; // rax
int v16; // edx
unsigned int v17; // [rsp+4h] [rbp-2064h]
unsigned __int64 v18; // [rsp+8h] [rbp-2060h]
int v19; // [rsp+14h] [rbp-2054h]
int v20; // [rsp+18h] [rbp-2050h]
int v21; // [rsp+1Ch] [rbp-204Ch]
char v22[16]; // [rsp+20h] [rbp-2048h] BYREF
char buf[4096]; // [rsp+30h] [rbp-2038h] BYREF
char s[4152]; // [rsp+1030h] [rbp-1038h] BYREF

v1 = func2(originalfilename);
v2 = v1;
v18 = v1;
printf("File size = %llu\n", v1);
bitmaplength = (v2 >> 15) + 1;
v3 = bitmaplength;
bitmap_buf = malloc(bitmaplength);
memset(bitmap_buf, 0, v3);
v4 = open(originalfilename, 0);
if ( v4 < 0 )
{
ErrorReport(1008LL);
free(bitmap_buf);
v17 = -1;
}
else
{
v5 = v4;
memset(buf, 0, sizeof(buf));
recv(a1, buf, 0x1000uLL, 0);
if ( !strcmp(buf, no_file) )
{
puts("Send the whole file...");
v17 = func0(a1);
if ( v17 == -1 )
free(bitmap_buf);
else
v17 = 1;
}
else
{
v20 = atoi(buf);
puts("Send file size....");
sprintf(s, "%llu", v18);
v7 = strlen(s);
v17 = send(a1, s, v7 + 1, 0);
if ( v17 == -1 )
{
ErrorReport(1005LL);
free(bitmap_buf);
}
else
{
puts("Begin to receive MD5 data....");
memset(buf, 0, sizeof(buf));
v8 = recv(a1, buf, 0x1000uLL, 0);
v19 = v8;
if ( v8 )
{
if ( v8 == -1 )
{
LABEL_16:
ErrorReport(1004LL);
close(v5);
free(bitmap_buf);
v17 = -1;
}
else
{
v21 = v20;
v9 = 7;
v10 = 0;
while ( 1 )
{
v11 = buf;
v12 = 0;
if ( v19 > 15 )
break;
LABEL_13:
memset(buf, 0, sizeof(buf));
v21 -= v19;
if ( !v21 )
{
puts("Receive enough MD5 Data");
goto LABEL_30;
}
v13 = recv(a1, buf, 0x1000uLL, 0);
v19 = v13;
if ( !v13 )
goto LABEL_30;
if ( v13 == -1 )
goto LABEL_16;
}
while ( 1 )
{
v14 = read(v5, s, 0x1000uLL);
v17 = v14;
if ( v14 == -1 )
break;
MD5(s, v14, v22);
v15 = 0LL;
while ( v22[v15] == v11[v15] )
{
if ( ++v15 == 16 )
goto LABEL_20;
}
*((_BYTE *)bitmap_buf + v10) |= 1 << v9;
LABEL_20:
if ( --v9 == -1 )
{
++v10;
v9 = 7;
}
++v12;
v11 += 16;
if ( v12 >= v19 / 16 )
goto LABEL_13;
}
ErrorReport(1009LL);
close(v5);
free(bitmap_buf);
}
}
else
{
v10 = 0;
v9 = 7;
LABEL_30:
v16 = v20 / 16 + 1;
if ( (int)((v18 >> 12) + 1) >= v16 )
{
do
{
*((_BYTE *)bitmap_buf + v10) |= 1 << v9--;
if ( v9 == -1 )
{
++v10;
v9 = 7;
}
++v16;
}
while ( v16 != (unsigned int)(v18 >> 12) + 2 );
}
puts("Send bitmap information....");
v17 = send(a1, bitmap_buf, bitmaplength, 0);
if ( v17 == -1 )
{
ErrorReport(1005LL);
close(v5);
free(bitmap_buf);
}
else
{
close(v5);
v17 = 0;
}
}
}
}
}
return v17;
}

original_code:
int ReceiveFileStatus(int socket)
{
 int fd;
 int i,j;
 int readlength, recvlength, sendlength;
 char buf[4096];
 char recvbuf[4096];
 unsigned long long file_size;
 char md5buf[16];
 int bitmapindex = 0;
 int bitindex = 7;
 int result;
 int clientmd5length, restmd5length;
 int serverchunknum;
 file_size = GetFileSize(originalfilename);
 printf("File size = %llu\n", file_size);
 serverchunknum = (file_size / 4096) + 1;
 bitmaplength = ((file_size / 4096) / 8) + 1;
 bitmap_buf = malloc(bitmaplength);
 bzero(bitmap_buf, bitmaplength);
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 bzero(recvbuf, 4096);
 recvlength = recv(socket, recvbuf, 4096, 0);
 if(0== (strcmp(recvbuf, no_file)))
 {
  printf("Send the whole file...\n");
  result = SendFileData(socket);
  if(-1 == result)
  {
   free(bitmap_buf);
   return -1;
  }
  return 1;
 }
 else
 {
  clientmd5length = atoi(recvbuf);
  restmd5length = clientmd5length;
  printf("Send file size....\n");
  sprintf(buf, "%llu", file_size);
  sendlength = send(socket, buf, strlen(buf) + 1, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   free(bitmap_buf);
   return -1;
  }
  printf("Begin to receive MD5 data....\n");
  bzero(recvbuf, 4096);
  recvlength = recv(socket, recvbuf, 4096, 0);
  while(recvlength)
  {
   if(-1 == recvlength)
   {
    ErrorReport(1004);
    close(fd);
    free(bitmap_buf);
    return -1;
   }
   for( i = 0; i < (recvlength / 16); i++)
   {
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    MD5((unsigned char*)buf, readlength, (unsigned char*)md5buf);
    for(j = 0; j < 16; j++)
    {
     if(md5buf[j] != recvbuf[j + (i * 16)])
     {
      *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
      break;
     }
    }
    bitindex -= 1;
    if(-1 == bitindex)
    {
     bitindex = 7;
     bitmapindex++;
    }
   }
   bzero(recvbuf, 4096);
   restmd5length -= recvlength;
   if(restmd5length == 0)
   {
    printf("Receive enough MD5 Data\n");
    break;
   }
   recvlength = recv(socket, recvbuf, 4096, 0);
  }
  for(i = ((clientmd5length / 16) + 1); i <= serverchunknum; i++)
  {
   *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
   bitindex -= 1;
   if(-1 == bitindex)
   {
    bitindex = 7;
    bitmapindex++;
   }
  }
  printf("Send bitmap information....\n");
  sendlength = send(socket, bitmap_buf, bitmaplength, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   close(fd);
   free(bitmap_buf);
   return -1;
  }
  close(fd);
  return 0;
 }
}

canonical_original_code:
int ReceiveFileStatus(int socket)
{
 int fd;
 int i; int j;
 int readlength; int recvlength; int sendlength;
 char buf[4096];
 char recvbuf[4096];
 unsigned long long file_size;
 char md5buf[16];
 int bitmapindex = 0;
 int bitindex = 7;
 int result;
 int clientmd5length; int restmd5length;
 int serverchunknum;
 file_size = GetFileSize(originalfilename);
 printf("File size = %llu\n", file_size);
 serverchunknum = (file_size / 4096) + 1;
 bitmaplength = ((file_size / 4096) / 8) + 1;
 bitmap_buf = malloc(bitmaplength);
 bzero(bitmap_buf, bitmaplength);
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 bzero(recvbuf, 4096);
 recvlength = recv(socket, recvbuf, 4096, 0);
 if(0== (strcmp(recvbuf, no_file)))
 {
  printf("Send the whole file...\n");
  result = SendFileData(socket);
  if(-1 == result)
  {
   free(bitmap_buf);
   return -1;
  }
  return 1;
 }
 else
 {
  clientmd5length = atoi(recvbuf);
  restmd5length = clientmd5length;
  printf("Send file size....\n");
  sprintf(buf, "%llu", file_size);
  sendlength = send(socket, buf, strlen(buf) + 1, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   free(bitmap_buf);
   return -1;
  }
  printf("Begin to receive MD5 data....\n");
  bzero(recvbuf, 4096);
  recvlength = recv(socket, recvbuf, 4096, 0);
  while(recvlength)
  {
   if(-1 == recvlength)
   {
    ErrorReport(1004);
    close(fd);
    free(bitmap_buf);
    return -1;
   }
   for( i = 0; i < (recvlength / 16); i++)
   {
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    MD5((unsigned char *)buf, readlength, (unsigned char *)md5buf);
    for(j = 0; j < 16; j++)
    {
     if(md5buf[j] != recvbuf[j + (i * 16)])
     {
      *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
      break;
     }
    }
    bitindex -= 1;
    if(-1 == bitindex)
    {
     bitindex = 7;
     bitmapindex++;
    }
   }
   bzero(recvbuf, 4096);
   restmd5length -= recvlength;
   if(restmd5length == 0)
   {
    printf("Receive enough MD5 Data\n");
    break;
   }
   recvlength = recv(socket, recvbuf, 4096, 0);
  }
  for(i = ((clientmd5length / 16) + 1); i <= serverchunknum; i++)
  {
   *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
   bitindex -= 1;
   if(-1 == bitindex)
   {
    bitindex = 7;
    bitmapindex++;
   }
  }
  printf("Send bitmap information....\n");
  sendlength = send(socket, bitmap_buf, bitmaplength, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   close(fd);
   free(bitmap_buf);
   return -1;
  }
  close(fd);
  return 0;
 }
}

variable_types: j int

variable_types: readlength int

variable_types: recvlength int

variable_types:
recvbuf
char [4096]

variable_types: bitmapindex int

variable_types: bitindex int

variable_types: result int

variable_types: serverchunknum int


SendUpdateData

decompiled_code:
__int64 __fastcall SendUpdateData(int a1)
{
int v1; // eax
int v2; // er13
__int64 i; // r12
unsigned int v4; // er14
unsigned int j; // ebx
int v7; // ebp
int v8; // eax
signed int v9; // eax
_BYTE v10[4152]; // [rsp+0h] [rbp-1038h] BYREF

v1 = open(originalfilename, 0);
if ( v1 < 0 )
{
ErrorReport(1008LL);
free(bitmap_buf);
v4 = -1;
}
else
{
v2 = v1;
puts("Send update data....");
for ( i = 0LL; bitmaplength > (int)i; ++i )
{
v7 = (_DWORD)i << 15;
for ( j = 7; j != -1; --j )
{
v8 = *((unsigned __int8 *)bitmap_buf + i);
if ( _bittest(&v8, j) )
{
lseek(v2, v7, 0);
v9 = read(v2, v10, 0x1000uLL);
v4 = v9;
if ( v9 == -1 )
{
ErrorReport(1009LL);
close(v2);
free(bitmap_buf);
return v4;
}
v4 = send(a1, v10, v9, 0);
if ( v4 == -1 )
{
ErrorReport(1005LL);
close(v2);
free(bitmap_buf);
return v4;
}
}
v7 += 4096;
}
}
free(bitmap_buf);
close(v2);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // eax
int v2; // er13
__int64 i; // r12
unsigned int v4; // er14
unsigned int j; // ebx
int v7; // ebp
int v8; // eax
signed int v9; // eax
_BYTE v10[4152]; // [rsp+0h] [rbp-1038h] BYREF

v1 = open(originalfilename, 0);
if ( v1 < 0 )
{
ErrorReport(1008LL);
free(bitmap_buf);
v4 = -1;
}
else
{
v2 = v1;
puts("Send update data....");
for ( i = 0LL; bitmaplength > (int)i; ++i )
{
v7 = (_DWORD)i << 15;
for ( j = 7; j != -1; --j )
{
v8 = *((unsigned __int8 *)bitmap_buf + i);
if ( _bittest(&v8, j) )
{
lseek(v2, v7, 0);
v9 = read(v2, v10, 0x1000uLL);
v4 = v9;
if ( v9 == -1 )
{
ErrorReport(1009LL);
close(v2);
free(bitmap_buf);
return v4;
}
v4 = send(a1, v10, v9, 0);
if ( v4 == -1 )
{
ErrorReport(1005LL);
close(v2);
free(bitmap_buf);
return v4;
}
}
v7 += 4096;
}
}
free(bitmap_buf);
close(v2);
v4 = 0;
}
return v4;
}

original_code:
int SendUpdateData(int socket)
{
 int fd;
 int i,j;
 int readlength, sendlength;
 char buf[4096];
 char updatestatus = 0;
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 printf("Send update data....\n");
 for(i = 0; i < bitmaplength; i++)
 {
  for(j = 7; j >= 0; j--)
  {
   updatestatus = (*(bitmap_buf + i)>>j) & 0x1;
   if(updatestatus == 1)
   {
    lseek(fd, ((i * 8) + (7 - j))* 4096, 0);
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    sendlength = send(socket, buf, readlength, 0);
    if(-1 == sendlength)
    {
     ErrorReport(1005);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
   }
  }
 }
 free(bitmap_buf);
 close(fd);
 return 0;
}

canonical_original_code:
int SendUpdateData(int socket)
{
 int fd;
 int i; int j;
 int readlength; int sendlength;
 char buf[4096];
 char updatestatus = 0;
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 printf("Send update data....\n");
 for(i = 0; i < bitmaplength; i++)
 {
  for(j = 7; j >= 0; j--)
  {
   updatestatus = (*(bitmap_buf + i)>>j) & 0x1;
   if(updatestatus == 1)
   {
    lseek(fd, ((i * 8) + (7 - j))* 4096, 0);
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    sendlength = send(socket, buf, readlength, 0);
    if(-1 == sendlength)
    {
     ErrorReport(1005);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
   }
  }
 }
 free(bitmap_buf);
 close(fd);
 return 0;
}

variable_types: socket int

variable_types: fd int

variable_types: sendlength int

variable_types: updatestatus char


repo: kgabis/brainfuck-c

decompiled_code:
__int64 execute_bf()
{
__int16 *v0; // rax
__int16 v1; // ax
unsigned int v2; // ebp
int v3; // ebx
int v4; // edx
__int16 v6[65534]; // [rsp+0h] [rbp-20018h] BYREF
char v7; // [rsp+1FFFCh] [rbp-1Ch] BYREF

v0 = (__int16 *)&v7;
do
*v0-- = 0;
while ( v6 != v0 );
v1 = PROGRAM[0];
if ( PROGRAM[0] )
{
v2 = 0;
v3 = 0;
v4 = 0;
while ( 2 )
{
switch ( v1 )
{
case 1:
++v2;
goto LABEL_6;
case 2:
--v2;
goto LABEL_6;
case 3:
++v6[v2];
goto LABEL_6;
case 4:
--v6[v2];
goto LABEL_6;
case 5:
putchar((unsigned __int16)v6[v2]);
goto LABEL_6;
case 6:
v6[v2] = getchar();
goto LABEL_6;
case 7:
if ( !v6[v2] )
v3 = (unsigned __int16)word_4044A2[2 * v4];
goto LABEL_6;
case 8:
if ( v6[v2] )
v3 = (unsigned __int16)word_4044A2[2 * v4];
LABEL_6:
v4 = (unsigned __int16)++v3;
v1 = PROGRAM[2 * (unsigned __int16)v3];
if ( v2 <= 0xFFFE && v1 )
continue;
return v2 == 0xFFFF;
default:
return 1LL;
}
}
}
v2 = 0;
return v2 == 0xFFFF;
}

canonical_decompiled_code:
__int64 func8()
{
__int16 *v0; // rax
__int16 v1; // ax
unsigned int v2; // ebp
int v3; // ebx
int v4; // edx
__int16 v6[65534]; // [rsp+0h] [rbp-20018h] BYREF
char v7; // [rsp+1FFFCh] [rbp-1Ch] BYREF

v0 = (__int16 *)&v7;
do
*v0-- = 0;
while ( v6 != v0 );
v1 = PROGRAM[0];
if ( PROGRAM[0] )
{
v2 = 0;
v3 = 0;
v4 = 0;
while ( 2 )
{
switch ( v1 )
{
case 1:
++v2;
goto LABEL_6;
case 2:
--v2;
goto LABEL_6;
case 3:
++v6[v2];
goto LABEL_6;
case 4:
--v6[v2];
goto LABEL_6;
case 5:
putchar((unsigned __int16)v6[v2]);
goto LABEL_6;
case 6:
v6[v2] = getchar();
goto LABEL_6;
case 7:
if ( !v6[v2] )
v3 = (unsigned __int16)word_4044A2[2 * v4];
goto LABEL_6;
case 8:
if ( v6[v2] )
v3 = (unsigned __int16)word_4044A2[2 * v4];
LABEL_6:
v4 = (unsigned __int16)++v3;
v1 = PROGRAM[2 * (unsigned __int16)v3];
if ( v2 <= 0xFFFE && v1 )
continue;
return v2 == 0xFFFF;
default:
return 1LL;
}
}
}
v2 = 0;
return v2 == 0xFFFF;
}

original_code:
int execute_bf() {
    unsigned short data[65535], pc = 0;
    unsigned int ptr = 65535;
    while (--ptr) { data[ptr] = 0; }
    while (PROGRAM[pc].operator != 0 && ptr < 65535) {
        switch (PROGRAM[pc].operator) {
            case 1: ptr++; break;
            case 2: ptr--; break;
            case 3: data[ptr]++; break;
            case 4: data[ptr]--; break;
            case 5: putchar(data[ptr]); break;
            case 6: data[ptr] = (unsigned int)getchar(); break;
            case 7: if(!data[ptr]) { pc = PROGRAM[pc].operand; } break;
            case 8: if(data[ptr]) { pc = PROGRAM[pc].operand; } break;
            default: return 1;
        }
        pc++;
    }
    return ptr != 65535 ? 0 : 1;
}

canonical_original_code:
int execute_bf() {
    unsigned short data[65535]; unsigned short pc = 0;
    unsigned int ptr = 65535;
    while (--ptr) { data[ptr] = 0; }
    while (PROGRAM[pc].operator != 0 && ptr < 65535) {
        switch (PROGRAM[pc].operator) {
            case 1: ptr++; break;
            case 2: ptr--; break;
            case 3: data[ptr]++; break;
            case 4: data[ptr]--; break;
            case 5: putchar(data[ptr]); break;
            case 6: data[ptr] = (unsigned int)getchar(); break;
            case 7: if(!data[ptr]) { pc = PROGRAM[pc].operand; } break;
            case 8: if(data[ptr]) { pc = PROGRAM[pc].operand; } break;
            default: return 1;
        }
        pc++;
    }
    return ptr != 65535 ? 0 : 1;
}

variable_types:
data
unsigned short [65535]

variable_types:
pc
unsigned short

variable_types:
ptr
unsigned int


main

canonical_name: main

repo: kgamiel/dxf

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
unsigned int v4; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s <dxf_filename>\n", *argv);
exit(1);
}
v3 = argv + 1;
do
{
v4 = dxf_load(v6, *v3, envp);
if ( v4 )
{
dxf_print_error(v4, stderr);
}
else
{
dxf_print(v6[0], stdout);
dxf_unload(v6[0]);
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
return 0;
}

original_code:
int main(int argc, char **argv) {
    int i;
    if(argc < 2) {
        fprintf(stderr, "Usage: %s <dxf_filename>\n", argv[0]);
        exit(1);
    }
    for(i = 1;i < argc; i++) {
        dxf_handle_t dxf;
        dxf_error_t err;
        if((err = dxf_load(&dxf, argv[i])) != dxfErrorOk) {
            (void)dxf_print_error(err, stderr);
        } else {
            dxf_print(dxf, stdout);
            dxf_unload(dxf);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int i;
    if(argc < 2) {
        fprintf(stderr, "Usage: %s <dxf_filename>\n", argv[0]);
        exit(1);
    }
    for(i = 1;i < argc; i++) {
        unsigned int dxf;
        enum dxf_error_t err;
        if((err = dxf_load(&dxf, argv[i])) != dxfErrorOk) {
            (void)dxf_print_error(err, stderr);
        } else {
            dxf_print(dxf, stdout);
            dxf_unload(dxf);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types:
dxf
unsigned int

variable_types: enum dxf_error_t { dxfErrorOk=0, dxfErrorBadFd=1, dxfErrorInvalidFormat=2, dxfErrorEOF=3, dxfErrorFgets=4, dxfErrorLineTooLong=5, dxfErrorNonASCII=6, dxfErrorDigitExpected=7, dxfErrorInvalidFile=8, dxfErrorOpenFailed=9, dxfErrorCloseFailed=10, dxfErrorSnprintfFailed=11, dxfErrorTooManyOpen=12, dxfErrorInvalidHandle=13, dxfErrorInvalidVariable=14 }


repo: kgamiel/seewaves

decompiled_code:
__int64 __fastcall cfg_open(char *s, char *format, __int64 a3)
{
__int64 result; // rax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

*(_QWORD *)s = 0LL;
*((_QWORD *)s + 512) = 0LL;
memset(
(void *)((unsigned __int64)(s + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)s - (((_DWORD)s + 8) & 0xFFFFFFF8) + 4104) >> 3));
snprintf(s, 0x1000uLL, format, "%s");
if ( stat(s, &v5) )
{
perror(s);
result = 1LL;
}
else
{
*((_QWORD *)s + 512) = a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, char *format, __int64 a3)
{
__int64 result; // rax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

*(_QWORD *)s = 0LL;
*((_QWORD *)s + 512) = 0LL;
memset(
(void *)((unsigned __int64)(s + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)s - (((_DWORD)s + 8) & 0xFFFFFFF8) + 4104) >> 3));
snprintf(s, 0x1000uLL, format, "%s");
if ( stat(s, &v5) )
{
perror(s);
result = 1LL;
}
else
{
*((_QWORD *)s + 512) = a3;
result = 0LL;
}
return result;
}

original_code:
cfg_error_t cfg_open(cfg_t *cfg, const char *filename, cfg_option_t *options) {
 struct stat status;
 memset(cfg, 0, sizeof(cfg_t));
 snprintf(cfg->filename, 4096, filename, "%s");
 if(stat(cfg->filename, &status)) {
  perror(cfg->filename);
  return (CFG_ERROR);
 }
 cfg->options = options;
 return(CFG_OK);
}

canonical_original_code:
enum cfg_error_t cfg_open(struct cfg_t *cfg, char *filename, struct cfg_option_t *options) {
 struct stat status;
 memset(cfg, 0, sizeof(cfg_t));
 snprintf(cfg->filename, 4096, filename, "%s");
 if(stat(cfg->filename, &status)) {
  perror(cfg->filename);
  return (CFG_ERROR);
 }
 cfg->options = options;
 return(CFG_OK);
}

variable_types: struct cfg_t { char filename[4096]; struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *options; } *

variable_types:
filename
char *

variable_types:
options
struct cfg_option_t *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: enum cfg_error_t { CFG_OK=0, CFG_ERROR=1 }

user_defined_types: struct cfg_t { char filename[4096]; struct cfg_option_t *options; }

user_defined_types: struct cfg_option_t { char *name; char *description; enum cfg_option_which_t which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; }


decompiled_code:
int __fastcall cfg_get_int(char *a1, char *a2, int a3)
{
int result; // eax
_BYTE savedregs[88]; // [rsp+0h] [rbp+0h] BYREF

cfg_get_string(a1, a2, savedregs, 64, "xxx");
result = a3;
if ( strcmp(savedregs, "xxx") )
result = atoi(savedregs);
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *a1, char *a2, int a3)
{
int result; // eax
_BYTE savedregs[88]; // [rsp+0h] [rbp+0h] BYREF

func2(a1, a2, savedregs, 64, "xxx");
result = a3;
if ( strcmp(savedregs, "xxx") )
result = atoi(savedregs);
return result;
}

original_code:
int cfg_get_int(cfg_t *cfg, const char *name, int default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atoi(buf));
}

canonical_original_code:
int cfg_get_int(struct cfg_t *cfg, char *name, int default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atoi(buf));
}

variable_types:
name
char *

variable_types:
buf
char [64]

user_defined_types: enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 }


decompiled_code:
float __fastcall cfg_get_float(char *a1, char *a2)
{
float result; // xmm0_4
char nptr[72]; // [rsp+10h] [rbp-48h] BYREF

cfg_get_string(a1, a2, nptr, 64, "xxx");
if ( strcmp(nptr, "xxx") )
result = atof(nptr);
return result;
}

canonical_decompiled_code:
float __fastcall func4(char *a1, char *a2)
{
float result; // xmm0_4
char nptr[72]; // [rsp+10h] [rbp-48h] BYREF

func2(a1, a2, nptr, 64, "xxx");
if ( strcmp(nptr, "xxx") )
result = atof(nptr);
return result;
}

original_code:
float cfg_get_float(cfg_t *cfg, const char *name, float default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atof(buf));
}

canonical_original_code:
float cfg_get_float(struct cfg_t *cfg, char *name, float default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atof(buf));
}

return_type: float


decompiled_code:
const char **__fastcall cfg_get(__int64 a1, const char *a2)
{
const char **v3; // rbx
const char *v4; // rsi

if ( !a2 || !*a2 )
_assert_fail("name != NULL && *name != '\\0'", "cfg.c", 0x91u, "cfg_get");
v3 = *(const char ***)(a1 + 4096);
v4 = *v3;
if ( !*v3 )
return 0LL;
while ( strcmp(a2, v4) )
{
v3 += 69;
v4 = *v3;
if ( !*v3 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
const char **__fastcall func5(__int64 a1, const char *a2)
{
const char **v3; // rbx
const char *v4; // rsi

if ( !a2 || !*a2 )
_assert_fail("name != NULL && *name != '\\0'", "cfg.c", 0x91u, "cfg_get");
v3 = *(const char ***)(a1 + 4096);
v4 = *v3;
if ( !*v3 )
return 0LL;
while ( strcmp(a2, v4) )
{
v3 += 69;
v4 = *v3;
if ( !*v3 )
return 0LL;
}
return v3;
}

original_code:
cfg_option_t *cfg_get(cfg_t *cfg, const char *name) {
 cfg_option_t *option;
 int i;
 ((name != ((void *)0) && *name != '\0') ? (void) (0) : __assert_fail ("name != NULL && *name != '\\0'", "cfg.c", 145, __extension__ __PRETTY_FUNCTION__));
 for( i = 0; ; i++) {
  option = &(cfg->options[i]);
  if(option->name == ((void *)0)) {
   break;
  }
  if(!strcmp(name, option->name)) {
   return(option);
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct cfg_option_t *cfg_get(struct cfg_t *cfg, char *name) {
 struct cfg_option_t *option;
 int i;
 ((name != ((void *)0) && *name != '\0') ? (void) (0) : __assert_fail ("name != NULL && *name != '\\0'", "cfg.c", 145, __extension__ __PRETTY_FUNCTION__));
 for( i = 0; ; i++) {
  option = &(cfg->options[i]);
  if(option->name == ((void *)0)) {
   break;
  }
  if(!strcmp(name, option->name)) {
   return(option);
  }
 }
 return ((void *)0);
}

variable_types: struct cfg_t { char filename[4096]; struct cfg_option_t *options; } *

variable_types: struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *


decompiled_code:
const char **__fastcall cfg_set_int(__int64 a1, const char *a2, int a3)
{
const char **result; // rax

result = cfg_get(a1, a2);
if ( result )
{
if ( *((_DWORD *)result + 4) == 1 )
*((_DWORD *)result + 5) = a3;
}
return result;
}

canonical_decompiled_code:
const char **__fastcall func6(__int64 a1, const char *a2, int a3)
{
const char **result; // rax

result = func5(a1, a2);
if ( result )
{
if ( *((_DWORD *)result + 4) == 1 )
*((_DWORD *)result + 5) = a3;
}
return result;
}

original_code:
void cfg_set_int(cfg_t *cfg, char *name, int value) {
 cfg_option_t *option = cfg_get(cfg, name);
 if(option && option->which == INTEGER) {
  option->u.ival = value;
 }
}

canonical_original_code:
void cfg_set_int(struct cfg_t *cfg, char *name, int value) {
 struct cfg_option_t *option = cfg_get(cfg, name);
 if(option && option->which == INTEGER) {
  option->u.ival = value;
 }
}

variable_types: value int

return_type: void


decompiled_code:
__int64 cfg_close()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
cfg_error_t cfg_close(cfg_t *cfg) {
 (void)cfg;
 return(CFG_OK);
}

canonical_original_code:
enum cfg_error_t cfg_close(struct cfg_t *cfg) {
 (void)cfg;
 return(CFG_OK);
}

user_defined_types: enum cfg_error_t { CFG_OK=0, CFG_ERROR=1 }


decompiled_code:
__m128i __fastcall Vector_withValues(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
Vector Vector_withValues(float x, float y, float z) {
 Vector vector;
 vector.x = x;
 vector.y = y;
 vector.z = z;
 return vector;
}

canonical_original_code:
struct Vector Vector_withValues(float x, float y, float z) {
 struct Vector vector;
 vector.x = x;
 vector.y = y;
 vector.z = z;
 return vector;
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: struct Vector { float x; float y; float z; }


original_code:
void Vector_normalize(Vector * vector) {
 float magnitude;
 magnitude = sqrt((vector->x * vector->x) + (vector->y * vector->y) + (vector->z * vector->z));
 vector->x /= magnitude;
 vector->y /= magnitude;
 vector->z /= magnitude;
}

canonical_original_code:
void Vector_normalize(struct Vector *vector) {
 float magnitude;
 magnitude = sqrt((vector->x * vector->x) + (vector->y * vector->y) + (vector->z * vector->z));
 vector->x /= magnitude;
 vector->y /= magnitude;
 vector->z /= magnitude;
}

variable_types: struct Vector { float x; float y; float z; } *

variable_types: magnitude float


decompiled_code:
__m128i __fastcall Vector_normalized(double a1, float a2)
{
__m128i v3; // [rsp+10h] [rbp-28h] BYREF
int v4; // [rsp+2Ch] [rbp-Ch]

*(double *)v3.m128i_i64 = a1;
*(float *)&v3.m128i_i32[2] = a2;
Vector_normalize((float *)v3.m128i_i32);
v4 = v3.m128i_i32[2];
return _mm_loadl_epi64(&v3);
}

original_code:
Vector Vector_normalized(Vector vector) {
 Vector_normalize(&vector);
 return vector;
}

canonical_original_code:
struct Vector Vector_normalized(struct Vector vector) {
 Vector_normalize(&vector);
 return vector;
}

variable_types:
vector
struct Vector

return_type: struct Vector { float x; float y; float z; }


decompiled_code:
float __fastcall Vector_magnitude(double a1, float a2)
{
float v2; // xmm0_4
float result; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
result = sqrtf(v2);
else
result = fsqrt(v2);
return result;
}

canonical_decompiled_code:
float __fastcall func3(double a1, float a2)
{
float v2; // xmm0_4
float result; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
result = sqrtf(v2);
else
result = fsqrt(v2);
return result;
}

original_code:
float Vector_magnitude(Vector vector) {
 return sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}

canonical_original_code:
float Vector_magnitude(struct Vector vector) {
 return sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}

user_defined_types: struct Vector { float x; float y; float z; }


decompiled_code:
float __fastcall Vector_magnitudeSquared(double a1, float a2)
{
return (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
}

canonical_decompiled_code:
float __fastcall func4(double a1, float a2)
{
return (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
}

original_code:
float Vector_magnitudeSquared(Vector vector) {
 return ((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}

canonical_original_code:
float Vector_magnitudeSquared(struct Vector vector) {
 return ((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}


decompiled_code:
__m128i __fastcall Vector_add(double a1, double a2, double a3)
{
return Vector_withValues(*(float *)&a1 + *(float *)&a3, *((float *)&a1 + 1) + *((float *)&a3 + 1));
}

canonical_decompiled_code:
__m128i __fastcall func5(double a1, double a2, double a3)
{
return func0(*(float *)&a1 + *(float *)&a3, *((float *)&a1 + 1) + *((float *)&a3 + 1));
}

original_code:
Vector Vector_add(Vector vector1, Vector vector2) {
 return Vector_withValues((vector1.x + vector2.x), (vector1.y + vector2.y), (vector1.z + vector2.z));
}

canonical_original_code:
struct Vector Vector_add(struct Vector vector1, struct Vector vector2) {
 return Vector_withValues((vector1.x + vector2.x), (vector1.y + vector2.y), (vector1.z + vector2.z));
}


decompiled_code:
__m128i __fastcall Vector_subtract(double a1, double a2, double a3)
{
return Vector_withValues(*(float *)&a1 - *(float *)&a3, *((float *)&a1 + 1) - *((float *)&a3 + 1));
}

canonical_decompiled_code:
__m128i __fastcall func6(double a1, double a2, double a3)
{
return func0(*(float *)&a1 - *(float *)&a3, *((float *)&a1 + 1) - *((float *)&a3 + 1));
}

original_code:
Vector Vector_subtract(Vector vector1, Vector vector2) {
 return Vector_withValues((vector1.x - vector2.x), (vector1.y - vector2.y), (vector1.z - vector2.z));
}

canonical_original_code:
struct Vector Vector_subtract(struct Vector vector1, struct Vector vector2) {
 return Vector_withValues((vector1.x - vector2.x), (vector1.y - vector2.y), (vector1.z - vector2.z));
}


decompiled_code:
float __fastcall Vector_dot(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

canonical_decompiled_code:
float __fastcall func7(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

original_code:
float Vector_dot(Vector vector1, Vector vector2) {
 return ((vector1.x * vector2.x) + (vector1.y * vector2.y) + (vector1.z * vector2.z));
}

canonical_original_code:
float Vector_dot(struct Vector vector1, struct Vector vector2) {
 return ((vector1.x * vector2.x) + (vector1.y * vector2.y) + (vector1.z * vector2.z));
}


decompiled_code:
__m128i __fastcall Vector_cross(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
return _mm_loadl_epi64(&v5);
}

canonical_decompiled_code:
__m128i __fastcall func8(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
return _mm_loadl_epi64(&v5);
}

original_code:
Vector Vector_cross(Vector vector1, Vector vector2) {
 Vector result;
 result.x = ((vector1.y * vector2.z) - (vector1.z * vector2.y));
 result.y = ((vector1.z * vector2.x) - (vector1.x * vector2.z));
 result.z = ((vector1.x * vector2.y) - (vector1.y * vector2.x));
 return result;
}

canonical_original_code:
struct Vector Vector_cross(struct Vector vector1, struct Vector vector2) {
 struct Vector result;
 result.x = ((vector1.y * vector2.z) - (vector1.z * vector2.y));
 result.y = ((vector1.z * vector2.x) - (vector1.x * vector2.z));
 result.z = ((vector1.x * vector2.y) - (vector1.y * vector2.x));
 return result;
}


decompiled_code:
void __fastcall arcball_set_bounds(float *a1, float a2, float a3)
{
*a1 = 1.0 / (float)((float)(a2 - 1.0) * 0.5);
a1[1] = 1.0 / (float)((float)(a3 - 1.0) * 0.5);
}

original_code:
void arcball_set_bounds(arcball_t *a, float width, float height) {
 a->adjust_width = 1.0f / ((width - 1.0f) * 0.5f);
 a->adjust_height = 1.0f / ((height - 1.0f) * 0.5f);
}

canonical_original_code:
void arcball_set_bounds(struct arcball_t *a, float width, float height) {
 a->adjust_width = 1.0f / ((width - 1.0f) * 0.5f);
 a->adjust_height = 1.0f / ((height - 1.0f) * 0.5f);
}

variable_types: struct arcball_t { float adjust_width; float adjust_height; struct Vector { float x; float y; float z; } saved_click_vector; struct Vector saved_drag_vector; } *

variable_types: width float

variable_types: height float

user_defined_types: struct arcball_t { float adjust_width; float adjust_height; struct Vector saved_click_vector; struct Vector saved_drag_vector; }


decompiled_code:
void __fastcall arcball_init(__int64 a1, float a2, float a3)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
arcball_set_bounds((float *)a1, a2, a3);
}

original_code:
void arcball_init(arcball_t *a, float width, float height) {
 memset(a, 0, sizeof(arcball_t));
 arcball_set_bounds(a, width, height);
}

canonical_original_code:
void arcball_init(struct arcball_t *a, float width, float height) {
 memset(a, 0, sizeof(arcball_t));
 arcball_set_bounds(a, width, height);
}


decompiled_code:
void __fastcall arcball_click(float *a1, float a2, float a3)
{
arcball_map_to_sphere(a1, a1 + 2, a2, a3);
}

canonical_decompiled_code:
void __fastcall func3(float *a1, float a2, float a3)
{
func0(a1, a1 + 2, a2, a3);
}

original_code:
void arcball_click(arcball_t *a, float x, float y) {
 arcball_map_to_sphere(a, x, y, &a->saved_click_vector);
}

canonical_original_code:
void arcball_click(struct arcball_t *a, float x, float y) {
 arcball_map_to_sphere(a, x, y, &a->saved_click_vector);
}


original_code:
void arcball_drag(arcball_t *a, float x, float y, Quaternion *new_rotation) {
 arcball_map_to_sphere(a, x, y, &a->saved_drag_vector);
 if(!new_rotation) {
  return;
 }
 Vector perpendicular = Vector_cross(a->saved_click_vector, a->saved_drag_vector);
 if(Vector_magnitude(perpendicular) > 1.0e-5) {
  new_rotation->x = perpendicular.x;
  new_rotation->y = perpendicular.y;
  new_rotation->z = perpendicular.z;
  new_rotation->w = Vector_dot(a->saved_click_vector, a->saved_drag_vector);
 } else {
  new_rotation->x = 0.0f;
  new_rotation->y = 0.0f;
  new_rotation->z = 0.0f;
  new_rotation->w = 0.0f;
 }
}

canonical_original_code:
void arcball_drag(struct arcball_t *a, float x, float y, struct Quaternion *new_rotation) {
 arcball_map_to_sphere(a, x, y, &a->saved_drag_vector);
 if(!new_rotation) {
  return;
 }
 struct Vector perpendicular = Vector_cross(a->saved_click_vector, a->saved_drag_vector);
 if(Vector_magnitude(perpendicular) > 1.0e-5) {
  new_rotation->x = perpendicular.x;
  new_rotation->y = perpendicular.y;
  new_rotation->z = perpendicular.z;
  new_rotation->w = Vector_dot(a->saved_click_vector, a->saved_drag_vector);
 } else {
  new_rotation->x = 0.0f;
  new_rotation->y = 0.0f;
  new_rotation->z = 0.0f;
  new_rotation->w = 0.0f;
 }
}

variable_types: struct Quaternion { float x; float y; float z; float w; } *


decompiled_code:
__int64 __fastcall heartbeat_thread_main(__int64 a1)
{
int v1; // eax
int v2; // eax
int v3; // er12
struct addrinfo *v4; // rax
socklen_t v5; // er13
const char *v6; // rax
const __m128i *v7; // roff
ssize_t v8; // rax
int v9; // ebp
int v10; // eax
__int64 v12; // [rsp+0h] [rbp-E8h] BYREF
time_t timer; // [rsp+48h] [rbp-A0h] BYREF
time_t time1; // [rsp+50h] [rbp-98h] BYREF
int buf; // [rsp+5Ch] [rbp-8Ch] BYREF
char s[24]; // [rsp+60h] [rbp-88h] BYREF
struct addrinfo *pai; // [rsp+78h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+80h] [rbp-68h] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-38h] BYREF

v1 = socket(2, 2, 17);
*(_DWORD *)(a1 + 4120) = v1;
if ( v1 == -1 )
{
perror("socket");
pthread_exit(0LL);
}
fcntl(v1, 4, 2048LL);
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
sprintf(s, "%i", *(unsigned __int16 *)(a1 + 4350));
v2 = getaddrinfo((const char *)(a1 + 4304), s, &req, &pai);
v3 = v2;
if ( v2 )
{
v6 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo() failed: %s", v6);
close(*(_DWORD *)(a1 + 4120));
pthread_exit(0LL);
}
v4 = pai;
if ( pai )
{
while ( v4->ai_family != 2 )
{
v4 = v4->ai_next;
if ( !v4 )
{
v5 = 16;
goto LABEL_10;
}
}
v7 = (const __m128i *)v4->ai_addr;
addr = (struct sockaddr)_mm_loadu_si128(v7);
v5 = v4->ai_addrlen;
inet_ntop(v4->ai_family, (char *)v7->m128i_i64 + 4, (char *)(a1 + 4304), 0x2Eu);
}
else
{
v5 = 16;
}
LABEL_10:
freeaddrinfo(pai);
buf = 0;
timer = 0LL;
do
{
time(&time1);
v9 = v3;
if ( difftime(time1, timer) > 1.0 )
{
v8 = sendto(*(_DWORD *)(a1 + 4120), &buf, 4uLL, 0, &addr, v5);
if ( v8 == -1 )
{
if ( *_errno_location() != 9 )
perror("sendto()");
}
else
{
v9 = 1;
if ( v8 )
{
++*(_DWORD *)(a1 + 4124);
v9 = v3;
}
}
time(&timer);
}
if ( !recvfrom(*(_DWORD *)(a1 + 4120), &v12, 0x40uLL, 0, 0LL, 0LL) )
break;
v10 = *_errno_location();
if ( v10 != 4 && v10 != 11 )
{
if ( v10 == 9 )
break;
if ( v10 != 110 )
{
perror("heartbeat recvfrom");
break;
}
}
}
while ( !v9 );
if ( *(_DWORD *)(a1 + 4104) )
{
fwrite("Heartbeat thread exiting\n", 1uLL, 0x19uLL, stdout);
fflush(stdout);
}
close(*(_DWORD *)(a1 + 4120));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
int v2; // eax
int v3; // er12
struct addrinfo *v4; // rax
socklen_t v5; // er13
const char *v6; // rax
const __m128i *v7; // roff
ssize_t v8; // rax
int v9; // ebp
int v10; // eax
__int64 v12; // [rsp+0h] [rbp-E8h] BYREF
time_t timer; // [rsp+48h] [rbp-A0h] BYREF
time_t time1; // [rsp+50h] [rbp-98h] BYREF
int buf; // [rsp+5Ch] [rbp-8Ch] BYREF
char s[24]; // [rsp+60h] [rbp-88h] BYREF
struct addrinfo *pai; // [rsp+78h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+80h] [rbp-68h] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-38h] BYREF

v1 = socket(2, 2, 17);
*(_DWORD *)(a1 + 4120) = v1;
if ( v1 == -1 )
{
perror("socket");
pthread_exit(0LL);
}
fcntl(v1, 4, 2048LL);
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
sprintf(s, "%i", *(unsigned __int16 *)(a1 + 4350));
v2 = getaddrinfo((const char *)(a1 + 4304), s, &req, &pai);
v3 = v2;
if ( v2 )
{
v6 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo() failed: %s", v6);
close(*(_DWORD *)(a1 + 4120));
pthread_exit(0LL);
}
v4 = pai;
if ( pai )
{
while ( v4->ai_family != 2 )
{
v4 = v4->ai_next;
if ( !v4 )
{
v5 = 16;
goto LABEL_10;
}
}
v7 = (const __m128i *)v4->ai_addr;
addr = (struct sockaddr)_mm_loadu_si128(v7);
v5 = v4->ai_addrlen;
inet_ntop(v4->ai_family, (char *)v7->m128i_i64 + 4, (char *)(a1 + 4304), 0x2Eu);
}
else
{
v5 = 16;
}
LABEL_10:
freeaddrinfo(pai);
buf = 0;
timer = 0LL;
do
{
time(&time1);
v9 = v3;
if ( difftime(time1, timer) > 1.0 )
{
v8 = sendto(*(_DWORD *)(a1 + 4120), &buf, 4uLL, 0, &addr, v5);
if ( v8 == -1 )
{
if ( *_errno_location() != 9 )
perror("sendto()");
}
else
{
v9 = 1;
if ( v8 )
{
++*(_DWORD *)(a1 + 4124);
v9 = v3;
}
}
time(&timer);
}
if ( !recvfrom(*(_DWORD *)(a1 + 4120), &v12, 0x40uLL, 0, 0LL, 0LL) )
break;
v10 = *_errno_location();
if ( v10 != 4 && v10 != 11 )
{
if ( v10 == 9 )
break;
if ( v10 != 110 )
{
perror("heartbeat recvfrom");
break;
}
}
}
while ( !v9 );
if ( *(_DWORD *)(a1 + 4104) )
{
fwrite("Heartbeat thread exiting\n", 1uLL, 0x19uLL, stdout);
fflush(stdout);
}
close(*(_DWORD *)(a1 + 4120));
return 0LL;
}

original_code:
void *heartbeat_thread_main(void *seewaves_data) {
    struct sockaddr_in heartbeat_socket_remote_address;
    socklen_t heartbeat_socket_remote_address_len = sizeof(
                heartbeat_socket_remote_address);
    struct addrinfo address_hints;
    struct addrinfo *address_p;
    struct addrinfo *server_address_info;
    char port_as_string[16];
    long err;
    ptp_heartbeat_packet_t hb;
    time_t now;
    time_t last_heartbeat_sent;
    int done = 0;
    seewaves_t *sw = (seewaves_t*)seewaves_data;
    if ((sw->heartbeat_socket_fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) ==
        -1) {
        perror("socket");
        pthread_exit(((void *)0));
    }
    fcntl(sw->heartbeat_socket_fd, 4, 04000);
    memset(&address_hints, 0, sizeof address_hints);
    address_hints.ai_family = 0;
    address_hints.ai_socktype = SOCK_DGRAM;
    sprintf(port_as_string, "%i", sw->gpusph_port);
    if ((err = getaddrinfo(sw->gpusph_host, port_as_string,
        &address_hints, &server_address_info))) {
        fprintf(stderr, "getaddrinfo() failed: %s", gai_strerror((int)err));
        close(sw->heartbeat_socket_fd);
        pthread_exit(((void *)0));
    }
    for (address_p = server_address_info; address_p != ((void *)0);
        address_p = address_p->ai_next) {
        void *addr;
        if (address_p->ai_family == 2) {
            struct sockaddr_in *ipv4 = (struct sockaddr_in *)address_p->ai_addr;
            addr = &(ipv4->sin_addr);
            memcpy(&heartbeat_socket_remote_address, address_p->ai_addr,
                (size_t)heartbeat_socket_remote_address_len);
            heartbeat_socket_remote_address_len = address_p->ai_addrlen;
            inet_ntop(address_p->ai_family, addr, sw->gpusph_host,
                sizeof(sw->gpusph_host));
            break;
        } else {
            struct sockaddr_in6 *ipv6 =
                (struct sockaddr_in6 *)address_p->ai_addr;
            addr = &(ipv6->sin6_addr);
        }
    }
    freeaddrinfo(server_address_info);
    memset(&hb, 0, sizeof(ptp_heartbeat_packet_t));
    last_heartbeat_sent = 0;
    while(!done) {
        unsigned char b[64];
        time(&now);
        if (difftime(now, last_heartbeat_sent) > 1) {
            ssize_t bytes_sent;
            bytes_sent = sendto(sw->heartbeat_socket_fd, &hb,
                sizeof(ptp_heartbeat_packet_t), 0,
                (const struct sockaddr *)(&heartbeat_socket_remote_address),
                heartbeat_socket_remote_address_len);
            if (bytes_sent == -1) {
                if ((*__errno_location ()) != 9) {
                    perror("sendto()");
                }
            } else if(bytes_sent == 0) {
                done = 1;
            } else {
                sw->heartbeats_sent++;
            }
            time(&last_heartbeat_sent);
        }
        err = recvfrom(sw->heartbeat_socket_fd, &b, sizeof(b), 0, ((void *)0), ((void *)0));
        if (err == 0) {
            done = 1;
        } else {
            if((*__errno_location ()) == 11) {
            } else if((*__errno_location ()) == 4) {
            } else if ((*__errno_location ()) == 9) {
                done = 1;
            } else if ((*__errno_location ()) == 110) {
            } else {
                perror("heartbeat recvfrom");
                done = 1;
            }
        }
    }
    if(sw->verbosity) {
        fprintf(stdout, "Heartbeat thread exiting\n");
        fflush(stdout);
    }
    close(sw->heartbeat_socket_fd);
    return(((void *)0));
}

canonical_original_code:
void *heartbeat_thread_main(void *seewaves_data) {
    struct sockaddr_in heartbeat_socket_remote_address;
    unsigned int heartbeat_socket_remote_address_len = sizeof(
                heartbeat_socket_remote_address);
    struct addrinfo address_hints;
    struct addrinfo *address_p;
    struct addrinfo *server_address_info;
    char port_as_string[16];
    long err;
    struct ptp_heartbeat_packet_t hb;
    long now;
    long last_heartbeat_sent;
    int done = 0;
    struct seewaves_t *sw = (seewaves_t*)seewaves_data;
    if ((sw->heartbeat_socket_fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) ==
        -1) {
        perror("socket");
        pthread_exit(((void *)0));
    }
    fcntl(sw->heartbeat_socket_fd, 4, 04000);
    memset(&address_hints, 0, sizeof address_hints);
    address_hints.ai_family = 0;
    address_hints.ai_socktype = SOCK_DGRAM;
    sprintf(port_as_string, "%i", sw->gpusph_port);
    if ((err = getaddrinfo(sw->gpusph_host, port_as_string,
        &address_hints, &server_address_info))) {
        fprintf(stderr, "getaddrinfo() failed: %s", gai_strerror((int)err));
        close(sw->heartbeat_socket_fd);
        pthread_exit(((void *)0));
    }
    for (address_p = server_address_info; address_p != ((void *)0);
        address_p = address_p->ai_next) {
        void *addr;
        if (address_p->ai_family == 2) {
            struct sockaddr_in *ipv4 = (struct sockaddr_in *)address_p->ai_addr;
            addr = &(ipv4->sin_addr);
            memcpy(&heartbeat_socket_remote_address, address_p->ai_addr,
                (unsigned long)heartbeat_socket_remote_address_len);
            heartbeat_socket_remote_address_len = address_p->ai_addrlen;
            inet_ntop(address_p->ai_family, addr, sw->gpusph_host,
                sizeof(sw->gpusph_host));
            break;
        } else {
            struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)address_p->ai_addr;
            addr = &(ipv6->sin6_addr);
        }
    }
    freeaddrinfo(server_address_info);
    memset(&hb, 0, sizeof(ptp_heartbeat_packet_t));
    last_heartbeat_sent = 0;
    while(!done) {
        unsigned char b[64];
        time(&now);
        if (difftime(now, last_heartbeat_sent) > 1) {
            long bytes_sent;
            bytes_sent = sendto(sw->heartbeat_socket_fd, &hb,
                sizeof(ptp_heartbeat_packet_t), 0,
                (struct sockaddr *)(&heartbeat_socket_remote_address),
                heartbeat_socket_remote_address_len);
            if (bytes_sent == -1) {
                if ((*__errno_location ()) != 9) {
                    perror("sendto()");
                }
            } else if(bytes_sent == 0) {
                done = 1;
            } else {
                sw->heartbeats_sent++;
            }
            time(&last_heartbeat_sent);
        }
        err = recvfrom(sw->heartbeat_socket_fd, &b, sizeof(b), 0, ((void *)0), ((void *)0));
        if (err == 0) {
            done = 1;
        } else {
            if((*__errno_location ()) == 11) {
            } else if((*__errno_location ()) == 4) {
            } else if ((*__errno_location ()) == 9) {
                done = 1;
            } else if ((*__errno_location ()) == 110) {
            } else {
                perror("heartbeat recvfrom");
                done = 1;
            }
        }
    }
    if(sw->verbosity) {
        fprintf(stdout, "Heartbeat thread exiting\n");
        fflush(stdout);
    }
    close(sw->heartbeat_socket_fd);
    return(((void *)0));
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: err long

variable_types: struct ptp_heartbeat_packet_t { unsigned int count; }

variable_types: now long

variable_types: done int

variable_types: struct seewaves_t { struct cfg_t { char filename[4096]; struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *options; } config; int verbosity; unsigned long heartbeat_thread; int heartbeat_socket_fd; int heartbeats_sent; unsigned long data_thread; int data_socket_fd; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int total_particle_count; double *x; double *y; double *z; double *w; short *particle_type; float *t; unsigned int *flag; int packets_received; int flag_exit_main_loop; char data_host[46]; unsigned short data_port; char gpusph_host[46]; unsigned short gpusph_port; int red_bits; int green_bits; int blue_bits; int alpha_bits; int depth_bits; int stencil_bits; int display_mode; float background_color[4]; int window[4]; float most_recent_timestamp; int total_timesteps; int udp_buffer_size; unsigned char view_options; float mouse_x; float mouse_y; int mouse_button; int mouse_button_action; int mouse_wheel_pos; unsigned char key_options; char *fade_text; long fade_start; double fade_duration; float fade_position[3]; float line_width_range[2]; float line_width_step; float point_size_range[2]; float point_size_step; float viewport_toolbar[4]; float viewport_main[4]; float rotation_center[3]; float world_origin[3]; float world_size[3]; int mouse_pressed_at[2]; float model_rotation[3]; float model_pan[3]; struct arcball_t { float adjust_width; float adjust_height; struct Vector { float x; float y; float z; } saved_click_vector; struct Vector saved_drag_vector; } arcball; struct Quaternion { float x; float y; float z; float w; } arcball_rotation; struct Matrix { float m[16]; } arcball_transform; struct Matrix arcball_last_rotation; struct Matrix arcball_this_rotation; short show_help; int model_id; } *

variable_types:
addr
void *

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 sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

variable_types:
b
unsigned char [64]

return_type: void *

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 addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct seewaves_t { struct cfg_t config; int verbosity; unsigned long heartbeat_thread; int heartbeat_socket_fd; int heartbeats_sent; unsigned long data_thread; int data_socket_fd; union pthread_mutex_t lock; unsigned int total_particle_count; double *x; double *y; double *z; double *w; short *particle_type; float *t; unsigned int *flag; int packets_received; int flag_exit_main_loop; char data_host[46]; unsigned short data_port; char gpusph_host[46]; unsigned short gpusph_port; int red_bits; int green_bits; int blue_bits; int alpha_bits; int depth_bits; int stencil_bits; int display_mode; float background_color[4]; int window[4]; float most_recent_timestamp; int total_timesteps; int udp_buffer_size; unsigned char view_options; float mouse_x; float mouse_y; int mouse_button; int mouse_button_action; int mouse_wheel_pos; unsigned char key_options; char *fade_text; long fade_start; double fade_duration; float fade_position[3]; float line_width_range[2]; float line_width_step; float point_size_range[2]; float point_size_step; float viewport_toolbar[4]; float viewport_main[4]; float rotation_center[3]; float world_origin[3]; float world_size[3]; int mouse_pressed_at[2]; float model_rotation[3]; float model_pan[3]; struct arcball_t arcball; struct Quaternion arcball_rotation; struct Matrix arcball_transform; struct Matrix arcball_last_rotation; struct Matrix arcball_this_rotation; short show_help; int model_id; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall util_get_udp_buffer_size(int a1)
{
__int64 result; // rax
int v2; // eax
int v3; // ebx
socklen_t optlen; // [rsp+8h] [rbp-10h] BYREF
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen = 4;
if ( a1 == -1 )
{
v2 = socket(2, 2, 17);
v3 = v2;
if ( v2 == -1 )
{
perror("socket");
result = 0LL;
}
else
{
if ( getsockopt(v2, 1, 8, optval, &optlen) == -1 )
{
perror("getsockopt(bufsize)");
close(v3);
}
result = (unsigned int)optval[0];
}
}
else
{
if ( getsockopt(a1, 1, 8, optval, &optlen) == -1 )
perror("getsockopt(bufsize)");
result = (unsigned int)optval[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
int v2; // eax
int v3; // ebx
socklen_t optlen; // [rsp+8h] [rbp-10h] BYREF
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen = 4;
if ( a1 == -1 )
{
v2 = socket(2, 2, 17);
v3 = v2;
if ( v2 == -1 )
{
perror("socket");
result = 0LL;
}
else
{
if ( getsockopt(v2, 1, 8, optval, &optlen) == -1 )
{
perror("getsockopt(bufsize)");
close(v3);
}
result = (unsigned int)optval[0];
}
}
else
{
if ( getsockopt(a1, 1, 8, optval, &optlen) == -1 )
perror("getsockopt(bufsize)");
result = (unsigned int)optval[0];
}
return result;
}

original_code:
int util_get_udp_buffer_size(int sd) {
 int size;
 int len = sizeof(int);
 if(sd == -1) {
  int fd;
  if ((fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
   perror("socket");
   return(0);
  }
  if (getsockopt(fd, 1, 8, &size, (socklen_t*)&len) == -1) {
   perror("getsockopt(bufsize)");
   close(fd);
  }
  return(size);
 }
 if (getsockopt(sd, 1, 8, &size, (socklen_t*)&len) == -1) {
  perror("getsockopt(bufsize)");
 }
 return(size);
}

canonical_original_code:
int util_get_udp_buffer_size(int sd) {
 int size;
 int len = sizeof(int);
 if(sd == -1) {
  int fd;
  if ((fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
   perror("socket");
   return(0);
  }
  if (getsockopt(fd, 1, 8, &size, (unsigned int *)&len) == -1) {
   perror("getsockopt(bufsize)");
   close(fd);
  }
  return(size);
 }
 if (getsockopt(sd, 1, 8, &size, (unsigned int *)&len) == -1) {
  perror("getsockopt(bufsize)");
 }
 return(size);
}

variable_types: sd int

variable_types: size int

variable_types: len int

variable_types: fd int


decompiled_code:
size_t __fastcall util_get_current_time_string(char *s, size_t maxsize)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
v2 = localtime(&timer);
return strftime(s, maxsize, "%m-%d-%Y_%X", v2);
}

canonical_decompiled_code:
size_t __fastcall func1(char *s, size_t maxsize)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
v2 = localtime(&timer);
return strftime(s, maxsize, "%m-%d-%Y_%X", v2);
}

original_code:
void util_get_current_time_string(char *buf, ssize_t max_len) {
 time_t now;
 struct tm * timeinfo;
 time(&now);
 timeinfo = localtime(&now);
 strftime(buf, max_len, "%m-%d-%Y_%X", timeinfo);
}

canonical_original_code:
void util_get_current_time_string(char *buf, long max_len) {
 long now;
 struct tm *timeinfo;
 time(&now);
 timeinfo = localtime(&now);
 strftime(buf, max_len, "%m-%d-%Y_%X", timeinfo);
}

variable_types:
buf
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


makeFileH

repo: kgeorgiou/bmpengine

original_code:
int makeFileH(byte t1, byte t2, BITMAPFILEHEADER *ret) {
 ret->bfType1 = t1;
 ret->bfType2 = t2;
 ret->bfSize = 0;
 ret->bfReserved1 = 0;
 ret->bfReserved2 = 0;
 ret->bfOffBits = 54;
 return 0;
}

canonical_original_code:
int makeFileH(unsigned char t1, unsigned char t2, struct BITMAPFILEHEADER *ret) {
 ret->bfType1 = t1;
 ret->bfType2 = t2;
 ret->bfSize = 0;
 ret->bfReserved1 = 0;
 ret->bfReserved2 = 0;
 ret->bfOffBits = 54;
 return 0;
}

variable_types: struct BITMAPFILEHEADER { unsigned char bfType1; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; } *


makeInfoH

original_code:
int makeInfoH(dword w, dword h, word bitc, dword comp,
  BITMAPINFOHEADER *ret) {
 ret->biSize = 40;
 ret->biWidth = w;
 ret->biHeight = h;
 ret->biPlanes = 0;
 ret->biBitCount = bitc;
 ret->biCompression = comp;
 ret->biSizeImage = 0;
 ret->biXPelsPerMeter = 0;
 ret->biYPelsPerMeter = 0;
 ret->biClrUsed = 0;
 ret->biClrImportant = 0;
 return 0;
}

canonical_original_code:
int makeInfoH(unsigned int w, unsigned int h, unsigned short bitc, unsigned int comp, struct BITMAPINFOHEADER *ret) {
 ret->biSize = 40;
 ret->biWidth = w;
 ret->biHeight = h;
 ret->biPlanes = 0;
 ret->biBitCount = bitc;
 ret->biCompression = comp;
 ret->biSizeImage = 0;
 ret->biXPelsPerMeter = 0;
 ret->biYPelsPerMeter = 0;
 ret->biClrUsed = 0;
 ret->biClrImportant = 0;
 return 0;
}

variable_types:
w
unsigned int

variable_types:
h
unsigned int

variable_types:
bitc
unsigned short

variable_types:
comp
unsigned int

variable_types: struct BITMAPINFOHEADER { unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
bool v4; // zf
int v5; // ebx
const char **v6; // rbp
const char **v8; // rbp
const char **v9; // rbp
const char **v10; // rbp
const char **v11; // rbp
const char **v12; // rbp

puts("\n######################################################################");
puts(
"# bmpengine Copyright (C) 2012 Kyriakos Georgiou & Athina Paphitou #\n"
"# This program comes with ABSOLUTELY NO WARRANTY. #\n"
"# This is free software, and you are welcome to redistribute it #\n"
"# under certain conditions. #");
puts("######################################################################");
if ( argc <= 1 )
{
puts("\nPlease type ./bmpengine --help to see the available options");
v5 = 0;
}
else
{
v3 = argv[1];
v4 = strcmp(v3, "--help") == 0;
v5 = !v4;
if ( v4 )
{
puts("\n======================================================================");
puts("HELP MENU");
puts("---------");
puts("- List of available options:");
puts("1.To view a picture's metadata please type -list [image(s)]");
puts("2.To flip a picture horizontally please type -hflip [image(s)]");
puts("3.To flip a picture verically please type -vflip [image(s)]");
puts("4.To rotate a picture 90 degrees left please type -left90 [image(s)]");
puts("5.To rotate a picture 90 degrees right please type -right90 [image(s)]");
puts("6.To turn a picture into grayscale please type -gray [image(s)]");
puts("-----------------------------------------------------------------");
puts("- Please note that the correct way to use the program is:");
puts("./bmpengine <option> <image1> <image2> etc.");
puts("- Warning: You have to input ONLY ONE option and AT LEAST ONE image.");
puts("- e.g ./bmpengine -list image1.bmp image2.bmp");
puts("======================================================================");
}
else if ( argc <= 2 )
{
puts("Error: Give one option and at least one image.\nPlease type ./bmpengine --help to see the available options.");
v5 = 1;
}
else
{
v5 = strcmp(argv[1], "-list");
if ( v5 )
{
v5 = strcmp(v3, "-hflip");
if ( v5 )
{
v5 = strcmp(v3, "-vflip");
if ( v5 )
{
v5 = strcmp(v3, "-right90");
if ( v5 )
{
v5 = strcmp(v3, "-left90");
if ( v5 )
{
v5 = strcmp(v3, "-gray");
if ( v5 )
{
puts("Error: Invalid command given.\nPlease type ./bmpengine --help to see the available options.");
v5 = 1;
}
else
{
v6 = argv + 2;
do
gray(*v6++);
while ( v6 != &argv[(unsigned int)(argc - 3) + 3] );
}
}
else
{
v12 = argv + 2;
do
left90(*v12++);
while ( v12 != &argv[(unsigned int)(argc - 3) + 3] );
}
}
else
{
v11 = argv + 2;
do
right90(*v11++);
while ( v11 != &argv[(unsigned int)(argc - 3) + 3] );
}
}
else
{
v10 = argv + 2;
do
vflip(*v10++);
while ( v10 != &argv[(unsigned int)(argc - 3) + 3] );
}
}
else
{
v9 = argv + 2;
do
hflip(*v9++);
while ( v9 != &argv[(unsigned int)(argc - 3) + 3] );
}
}
else
{
v8 = argv + 2;
do
list(*v8++);
while ( v8 != &argv[(unsigned int)(argc - 3) + 3] );
}
}
}
return v5;
}

original_code:
int main(int argc, char *argv[]) {
 int i = 0;
 printf(
   "\n######################################################################\n");
 printf(
   "# bmpengine  Copyright (C) 2012  Kyriakos Georgiou & Athina Paphitou #\n"
   "# This program comes with ABSOLUTELY NO WARRANTY.                    #\n"
   "# This is free software, and you are welcome to redistribute it      #\n"
   "# under certain conditions.                                          #\n");
 printf(
   "######################################################################\n");
 if (argc < 2) {
  printf("\nPlease type ./bmpengine --help to see the available options\n");
  return 0;
 }
 if (strcmp(argv[1], "--help") == 0) {
  printf(
    "\n======================================================================\n");
  printf("HELP MENU\n");
  printf("---------\n");
  printf("- List of available options:\n");
  printf("1.To view a picture's metadata please type -list [image(s)]\n");
  printf(
    "2.To flip a picture horizontally please type -hflip [image(s)]\n");
  printf("3.To flip a picture verically please type -vflip [image(s)]\n");
  printf(
    "4.To rotate a picture 90 degrees left please type -left90 [image(s)]\n");
  printf(
    "5.To rotate a picture 90 degrees right please type -right90 [image(s)]\n");
  printf(
    "6.To turn a picture into grayscale please type -gray [image(s)]\n");
  printf(
    "-----------------------------------------------------------------\n");
  printf("- Please note that the correct way to use the program is:\n");
  printf("./bmpengine <option> <image1> <image2> etc.\n");
  printf(
    "- Warning: You have to input ONLY ONE option and AT LEAST ONE image.\n");
  printf("- e.g ./bmpengine -list image1.bmp image2.bmp\n");
  printf(
    "======================================================================\n");
  return 0;
 }
 if (argc < 3) {
  printf(
    "Error: Give one option and at least one image.\n"
    "Please type ./bmpengine --help to see the available options.\n");
  return 1;
 }
 if (strcmp(argv[1], "-list") == 0) {
  for (i = 2; i < argc; i++) {
   list(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-hflip") == 0) {
  for (i = 2; i < argc; i++) {
   hflip(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-vflip") == 0) {
  for (i = 2; i < argc; i++) {
   vflip(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-right90") == 0) {
  for (i = 2; i < argc; i++) {
   right90(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-left90") == 0) {
  for (i = 2; i < argc; i++) {
   left90(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-gray") == 0) {
  for (i = 2; i < argc; i++) {
   gray(argv[i]);
  }
  return 0;
 }
 else {
  printf("Error: Invalid command given.\n"
      "Please type ./bmpengine --help to see the available options.\n");
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


printPreamble

repo: kgeorgiou/wavengine

decompiled_code:
int printPreamble()
{
puts("\n####################################################");
puts(
"# wavengine Copyright (C) 2013 Kyriakos Georgiou #\n"
"# This program comes with ABSOLUTELY NO WARRANTY. #\n"
"# This is free software, and you are welcome to #\n"
"# redistribute it under certain conditions. #");
return puts("####################################################\n");
}

canonical_decompiled_code:
int func0()
{
puts("\n####################################################");
puts(
"# wavengine Copyright (C) 2013 Kyriakos Georgiou #\n"
"# This program comes with ABSOLUTELY NO WARRANTY. #\n"
"# This is free software, and you are welcome to #\n"
"# redistribute it under certain conditions. #");
return puts("####################################################\n");
}

original_code:
static void printPreamble() {
 printf("\n####################################################\n");
 printf("# wavengine  Copyright (C) 2013  Kyriakos Georgiou #\n"
   "# This program comes with ABSOLUTELY NO WARRANTY.  #\n"
   "# This is free software, and you are welcome to    #\n"
   "# redistribute it under certain conditions.        #\n");
 printf("####################################################\n\n");
}


printMenu

decompiled_code:
int printMenu()
{
puts("List of available commands:");
puts("./wavengine -list audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -mono audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -chop audio1.wav Xs Ys audio2.wav Xs Ys ... audioN.wav Xs Ys");
return puts("./wavengine -reverse audio1.wav audio2.wav ... audioN.wav");
}

canonical_decompiled_code:
int func1()
{
puts("List of available commands:");
puts("./wavengine -list audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -mono audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -chop audio1.wav Xs Ys audio2.wav Xs Ys ... audioN.wav Xs Ys");
return puts("./wavengine -reverse audio1.wav audio2.wav ... audioN.wav");
}

original_code:
static void printMenu() {
 printf("List of available commands:\n");
 printf("./wavengine -list audio1.wav audio2.wav ... audioN.wav\n");
 printf("./wavengine -mono audio1.wav audio2.wav ... audioN.wav\n");
 printf("./wavengine -chop audio1.wav Xs Ys audio2.wav Xs Ys ... audioN.wav Xs Ys\n");
 printf("./wavengine -reverse audio1.wav audio2.wav ... audioN.wav\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // rbx
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
int v11; // ebp
const char **v12; // rbx
const char **v13; // r12
const char **v15; // rbx
const char **v16; // r12
const char **v17; // rbx
const char **v18; // r12
__int64 v19; // rbx
int v20; // er14
const char *v21; // r15
unsigned int v22; // er13
const char *v23; // r15
unsigned int v24; // eax
__int64 v25; // rdx
unsigned int v26; // eax

printPreamble();
v5 = argc == 0;
v6 = argc == 1;
if ( argc <= 1 )
{
printMenu();
v11 = 1;
}
else
{
v7 = argv[1];
v8 = "-list";
v9 = 6LL;
v10 = v7;
do
{
if ( !v9 )
break;
v5 = *v10 < (unsigned int)*v8;
v6 = *v10++ == *v8++;
--v9;
}
while ( v6 );
v11 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
if ( argc > 2 )
{
v12 = argv + 2;
v13 = &argv[(unsigned int)(argc - 3) + 3];
do
list(*v12++, v10);
while ( v13 != v12 );
}
}
else
{
v11 = strcmp(argv[1], "-mono");
if ( v11 )
{
v11 = strcmp(v7, "-reverse");
if ( v11 )
{
v11 = strcmp(v7, "-chop");
v19 = 2LL;
v20 = argc - 2;
if ( v11 )
{
printMenu();
v11 = 0;
}
else
{
while ( v20 > (int)v19 )
{
v21 = argv[v19 + 1];
if ( strlen(v21) > 8 || strlen(argv[v19 + 2]) > 8 )
{
puts("Extremely big numbers given for start or end chop points.");
}
else
{
v22 = strcmp(v21, "0");
if ( v22 && (v22 = strtol(v21, 0LL, 10)) == 0
|| (v23 = argv[v19 + 2], v24 = strcmp(v23, "0"), (v25 = v24) != 0)
&& (v26 = strtol(v23, 0LL, 10), (v25 = v26) == 0) )
{
puts("Invalid number format for chop start point.");
}
else
{
chop(argv[v19], v22, v25);
}
}
v19 += 3LL;
}
}
}
else if ( argc > 2 )
{
v17 = argv + 2;
v18 = &argv[(unsigned int)(argc - 3) + 3];
do
reverse(*v17++);
while ( v17 != v18 );
}
}
else if ( argc > 2 )
{
v15 = argv + 2;
v16 = &argv[(unsigned int)(argc - 3) + 3];
do
mono(*v15++);
while ( v15 != v16 );
}
}
}
return v11;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // rbx
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
int v11; // ebp
const char **v12; // rbx
const char **v13; // r12
const char **v15; // rbx
const char **v16; // r12
const char **v17; // rbx
const char **v18; // r12
__int64 v19; // rbx
int v20; // er14
const char *v21; // r15
unsigned int v22; // er13
const char *v23; // r15
unsigned int v24; // eax
__int64 v25; // rdx
unsigned int v26; // eax

func0();
v5 = argc == 0;
v6 = argc == 1;
if ( argc <= 1 )
{
func1();
v11 = 1;
}
else
{
v7 = argv[1];
v8 = "-list";
v9 = 6LL;
v10 = v7;
do
{
if ( !v9 )
break;
v5 = *v10 < (unsigned int)*v8;
v6 = *v10++ == *v8++;
--v9;
}
while ( v6 );
v11 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
if ( argc > 2 )
{
v12 = argv + 2;
v13 = &argv[(unsigned int)(argc - 3) + 3];
do
list(*v12++, v10);
while ( v13 != v12 );
}
}
else
{
v11 = strcmp(argv[1], "-mono");
if ( v11 )
{
v11 = strcmp(v7, "-reverse");
if ( v11 )
{
v11 = strcmp(v7, "-chop");
v19 = 2LL;
v20 = argc - 2;
if ( v11 )
{
func1();
v11 = 0;
}
else
{
while ( v20 > (int)v19 )
{
v21 = argv[v19 + 1];
if ( strlen(v21) > 8 || strlen(argv[v19 + 2]) > 8 )
{
puts("Extremely big numbers given for start or end chop points.");
}
else
{
v22 = strcmp(v21, "0");
if ( v22 && (v22 = strtol(v21, 0LL, 10)) == 0
|| (v23 = argv[v19 + 2], v24 = strcmp(v23, "0"), (v25 = v24) != 0)
&& (v26 = strtol(v23, 0LL, 10), (v25 = v26) == 0) )
{
puts("Invalid number format for chop start point.");
}
else
{
chop(argv[v19], v22, v25);
}
}
v19 += 3LL;
}
}
}
else if ( argc > 2 )
{
v17 = argv + 2;
v18 = &argv[(unsigned int)(argc - 3) + 3];
do
reverse(*v17++);
while ( v17 != v18 );
}
}
else if ( argc > 2 )
{
v15 = argv + 2;
v16 = &argv[(unsigned int)(argc - 3) + 3];
do
mono(*v15++);
while ( v15 != v16 );
}
}
}
return v11;
}

original_code:
int main(int argc, char *argv[]) {
 int i;
 printPreamble();
 if (argc < 2) {
  printMenu();
  return 1;
 }
 if (strcmp(argv[1], "-list") == 0) {
  for (i = 2; i < argc; i++) {
   list(argv[i]);
  }
 } else if (strcmp(argv[1], "-mono") == 0) {
  for (i = 2; i < argc; i++) {
   mono(argv[i]);
  }
 } else if (strcmp(argv[1], "-reverse") == 0) {
  for (i = 2; i < argc; i++) {
   reverse(argv[i]);
  }
 } else if (strcmp(argv[1], "-chop") == 0) {
  for (i = 2; i < argc - 2; i += 3) {
   if (strlen(argv[i + 1]) > 8 || strlen(argv[i + 2]) > 8) {
    printf(
      "Extremely big numbers given for start or end chop points.\n");
    continue;
   }
   int start;
   int end;
   if (strcmp(argv[i + 1], "0") == 0) {
    start = 0;
   } else if ((start = strtol(argv[i + 1], ((void *)0), 10)) == 0L) {
    printf("Invalid number format for chop start point.\n");
    continue;
   }
   if (strcmp(argv[i + 2], "0") == 0) {
    end = 0;
   } else if ((end = strtol(argv[i + 2], ((void *)0), 10)) == 0L) {
    printf("Invalid number format for chop start point.\n");
    continue;
   }
   chop(argv[i], start, end);
  }
 } else {
  printMenu();
 }
 return 0;
}

variable_types: start int

variable_types: end int


min

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

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

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

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

original_code:
static int min(int a, int b) {
 if(a < b) {
  return a;
 }
 return b;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall parse_redirection(_QWORD *a1, _QWORD *a2, const char *a3)
{
__int64 v4; // r12
unsigned int v5; // er13
char *v6; // rbx
bool v7; // dl
char *v8; // r14
char *v9; // r12
void *v10; // rbx
size_t v11; // rax

v4 = 0LL;
do
{
v5 = v4;
v6 = strstr(a3, (&REDIRECT_OPERATORS)[v4]);
v7 = (int)v4++ + 1 <= 4;
}
while ( v6 == 0LL && v7 );
if ( !v6 )
return (unsigned int)-1;
v8 = (char *)malloc((int)v6 - (int)a3 + 1);
*a1 = v8;
memcpy(v8, a3, (int)v6 - (int)a3);
v8[(int)v6 - (int)a3 - 1] = 0;
LODWORD(v8) = strlen(a3);
v9 = strtok((char *)&a3[(int)v6 - (int)a3], " >&<");
v10 = malloc((int)a3 - (int)v6 + (int)v8);
*a2 = v10;
v11 = strlen(v9);
memcpy(v10, v9, v11 + 1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2, const char *a3)
{
__int64 v4; // r12
unsigned int v5; // er13
char *v6; // rbx
bool v7; // dl
char *v8; // r14
char *v9; // r12
void *v10; // rbx
size_t v11; // rax

v4 = 0LL;
do
{
v5 = v4;
v6 = strstr(a3, (&REDIRECT_OPERATORS)[v4]);
v7 = (int)v4++ + 1 <= 4;
}
while ( v6 == 0LL && v7 );
if ( !v6 )
return (unsigned int)-1;
v8 = (char *)malloc((int)v6 - (int)a3 + 1);
*a1 = v8;
memcpy(v8, a3, (int)v6 - (int)a3);
v8[(int)v6 - (int)a3 - 1] = 0;
LODWORD(v8) = strlen(a3);
v9 = strtok((char *)&a3[(int)v6 - (int)a3], " >&<");
v10 = malloc((int)a3 - (int)v6 + (int)v8);
*a2 = v10;
v11 = strlen(v9);
memcpy(v10, v9, v11 + 1);
return v5;
}

original_code:
enum redirect_opcodes parse_redirection(char** command, char** file,
        char* line){
    char* rd_stdout = ((void *)0);
    enum redirect_opcodes redirect_code;
    for(int i=0; i < NUM_REDIRECT_OPERATORS && rd_stdout == ((void *)0); i++){
        rd_stdout = strstr(line, REDIRECT_OPERATORS[i]);
        redirect_code = i;
    }
    if(rd_stdout == ((void *)0)){
        return RD_NONE;
    }
    int command_length = (int)rd_stdout - (int)line;
    *command = (char*)malloc(command_length + 1);
    memcpy(*command, line, command_length);
    (*command)[command_length - 1] = '\0';
    int file_length = strlen(line) - (int)rd_stdout + (int)line;
    char* ptr = strtok(line + command_length, " >&<");
    *file = (char*)malloc(file_length);
    memcpy(*file, ptr, strlen(ptr) + 1);
    return redirect_code;
}

canonical_original_code:
enum redirect_opcodes parse_redirection(char **command, char **file, char *line){
    char *rd_stdout = ((void *)0);
    enum redirect_opcodes redirect_code;
    for(int i = 0; i < NUM_REDIRECT_OPERATORS && rd_stdout == ((void *)0); i++){
        rd_stdout = strstr(line, REDIRECT_OPERATORS[i]);
        redirect_code = i;
    }
    if(rd_stdout == ((void *)0)){
        return RD_NONE;
    }
    int command_length = (int)rd_stdout - (int)line;
    *command = (char *)malloc(command_length + 1);
    memcpy(*command, line, command_length);
    (*command)[command_length - 1] = '\0';
    int file_length = strlen(line) - (int)rd_stdout + (int)line;
    char *ptr = strtok(line + command_length, " >&<");
    *file = (char *)malloc(file_length);
    memcpy(*file, ptr, strlen(ptr) + 1);
    return redirect_code;
}

variable_types:
command
char **

variable_types:
file
char **

variable_types:
line
char *

variable_types: enum redirect_opcodes { RD_ALL_APPEND=0, RD_STDOUT_APPEND=1, RD_ALL=2, RD_STDOUT=3, RD_STDIN=4, RD_NONE=-1 }

variable_types:
ptr
char *


decompiled_code:
int __fastcall perform_redirection(int *a1, const char *a2, unsigned int a3)
{
int v6; // esi
int result; // eax

v6 = 64;
if ( a3 <= 3 )
v6 = a3 < 2 ? 1089 : 65;
result = open(a2, v6, 438LL);
*a1 = result;
switch ( a3 )
{
case 0u:
case 2u:
close(2);
dup(*a1);
goto LABEL_5;
case 1u:
case 3u:
LABEL_5:
close(1);
dup(*a1);
result = close(*a1);
break;
case 4u:
close(0);
dup(*a1);
result = close(*a1);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int *a1, const char *a2, unsigned int a3)
{
int v6; // esi
int result; // eax

v6 = 64;
if ( a3 <= 3 )
v6 = a3 < 2 ? 1089 : 65;
result = open(a2, v6, 438LL);
*a1 = result;
switch ( a3 )
{
case 0u:
case 2u:
close(2);
dup(*a1);
goto LABEL_5;
case 1u:
case 3u:
LABEL_5:
close(1);
dup(*a1);
result = close(*a1);
break;
case 4u:
close(0);
dup(*a1);
result = close(*a1);
break;
default:
return result;
}
return result;
}

original_code:
void perform_redirection(int* fid, char* redirect_file,
        enum redirect_opcodes rt){
    int open_flags = 0100;
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
        case RD_ALL:
        case RD_STDOUT:
            open_flags |= 01;
            break;
        case RD_STDIN:
            open_flags |= 00;
            break;
    }
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
            open_flags |= 02000;
            break;
        case RD_ALL:
        case RD_STDOUT:
        case RD_STDIN:
            break;
        default:
            break;
    }
    *fid = open(redirect_file, open_flags, 0666);
    switch(rt){
        case RD_ALL_APPEND:
        case RD_ALL:
            close(2);
            dup(*fid);
        case RD_STDOUT_APPEND:
        case RD_STDOUT:
            close(1);
            dup(*fid);
            close(*fid);
            break;
        case RD_STDIN:
            close(0);
            dup(*fid);
            close(*fid);
            break;
        default:
            break;
    }
}

canonical_original_code:
void perform_redirection(int *fid, char *redirect_file, enum redirect_opcodes rt){
    int open_flags = 0100;
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
        case RD_ALL:
        case RD_STDOUT:
            open_flags |= 01;
            break;
        case RD_STDIN:
            open_flags |= 00;
            break;
    }
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
            open_flags |= 02000;
            break;
        case RD_ALL:
        case RD_STDOUT:
        case RD_STDIN:
            break;
        default:
            break;
    }
    *fid = open(redirect_file, open_flags, 0666);
    switch(rt){
        case RD_ALL_APPEND:
        case RD_ALL:
            close(2);
            dup(*fid);
        case RD_STDOUT_APPEND:
        case RD_STDOUT:
            close(1);
            dup(*fid);
            close(*fid);
            break;
        case RD_STDIN:
            close(0);
            dup(*fid);
            close(*fid);
            break;
        default:
            break;
    }
}

variable_types:
fid
int *

user_defined_types: enum redirect_opcodes { RD_ALL_APPEND=0, RD_STDOUT_APPEND=1, RD_ALL=2, RD_STDOUT=3, RD_STDIN=4, RD_NONE=-1 }


decompiled_code:
void __fastcall reset_redirection(int *a1, int a2)
{
if ( a2 == -1 || a2 == 4 )
{
if ( a2 == 4 )
{
*a1 = open("/dev/tty", 0);
close(0);
dup(*a1);
close(*a1);
}
}
else
{
*a1 = open("/dev/tty", 1);
close(2);
dup(*a1);
close(*a1);
*a1 = open("/dev/tty", 1);
close(1);
dup(*a1);
close(*a1);
}
}

original_code:
void reset_redirection(int* fid, enum redirect_opcodes redirection_type){
    if(redirection_type != RD_NONE && redirection_type != RD_STDIN){
        *fid = open("/dev/tty", 01);
        close(2);
        dup(*fid);
        close(*fid);
        *fid = open("/dev/tty", 01);
        close(1);
        dup(*fid);
        close(*fid);
    } else if(redirection_type == RD_STDIN){
        *fid = open("/dev/tty", 00);
        close(0);
        dup(*fid);
        close(*fid);
    }
}

canonical_original_code:
void reset_redirection(int *fid, enum redirect_opcodes redirection_type){
    if(redirection_type != RD_NONE && redirection_type != RD_STDIN){
        *fid = open("/dev/tty", 01);
        close(2);
        dup(*fid);
        close(*fid);
        *fid = open("/dev/tty", 01);
        close(1);
        dup(*fid);
        close(*fid);
    } else if(redirection_type == RD_STDIN){
        *fid = open("/dev/tty", 00);
        close(0);
        dup(*fid);
        close(*fid);
    }
}


getRange

repo: khalily/C-utils

decompiled_code:
__int64 __fastcall getRange(int a1, char a2)
{
__int64 v2; // rbp
long double v4; // [rsp-10h] [rbp-58h]
long double v5; // [rsp-10h] [rbp-58h]
long double x; // [rsp+10h] [rbp-38h]
long double xa; // [rsp+10h] [rbp-38h]

if ( a2 )
{
v2 = (unsigned int)(int)-pow(2.0, (double)(a1 - 1));
x = 2.0;
*((_QWORD *)&v4 + 1) = DWORD2(x);
*(_QWORD *)&v4 = *(_QWORD *)&x;
powl(v4, (long double)(a1 - 1));
}
else
{
xa = 2.0;
*((_QWORD *)&v5 + 1) = DWORD2(xa);
*(_QWORD *)&v5 = *(_QWORD *)&xa;
powl(v5, (long double)a1);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
__int64 v2; // rbp
long double v4; // [rsp-10h] [rbp-58h]
long double v5; // [rsp-10h] [rbp-58h]
long double x; // [rsp+10h] [rbp-38h]
long double xa; // [rsp+10h] [rbp-38h]

if ( a2 )
{
v2 = (unsigned int)(int)-pow(2.0, (double)(a1 - 1));
x = 2.0;
*((_QWORD *)&v4 + 1) = DWORD2(x);
*(_QWORD *)&v4 = *(_QWORD *)&x;
powl(v4, (long double)(a1 - 1));
}
else
{
xa = 2.0;
*((_QWORD *)&v5 + 1) = DWORD2(xa);
*(_QWORD *)&v5 = *(_QWORD *)&xa;
powl(v5, (long double)a1);
v2 = 0LL;
}
return v2;
}

original_code:
Range getRange(int bytes, bool isSigned) {
  Range r;
  if (isSigned) {
    r.start = -pow(2, bytes - 1);
    r.end = powl(2, bytes - 1) - 1;
  } else {
    r.start = 0;
    r.end = powl(2, bytes) - 1;
  }
  return r;
}

canonical_original_code:
struct Range getRange(int bytes, unsigned char isSigned) {
  struct Range r;
  if (isSigned) {
    r.start = -pow(2, bytes - 1);
    r.end = powl(2, bytes - 1) - 1;
  } else {
    r.start = 0;
    r.end = powl(2, bytes) - 1;
  }
  return r;
}

variable_types: bytes int

variable_types:
isSigned
unsigned char

variable_types: struct Range { long start; unsigned long end; }


printValueRange

decompiled_code:
int __fastcall printValueRange(int a1)
{
int result; // eax
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx

result = a1;
switch ( a1 )
{
case 0:
v2 = getRange(8, 1);
v4 = v3;
goto LABEL_3;
case 1:
v2 = getRange(8, 0);
v4 = v5;
goto LABEL_3;
case 2:
v2 = getRange(16, 1);
v4 = v6;
goto LABEL_3;
case 3:
v2 = getRange(16, 0);
v4 = v7;
goto LABEL_3;
case 4:
v2 = getRange(32, 1);
v4 = v8;
goto LABEL_3;
case 5:
v2 = getRange(32, 0);
v4 = v9;
goto LABEL_3;
case 6:
v2 = getRange(64, 1);
v4 = v10;
goto LABEL_3;
case 7:
v2 = getRange(64, 0);
v4 = v11;
LABEL_3:
result = printf("%s:\n\t\t%ld \t\t-\t%lu\n", (&g_type_str)[a1], v2, v4);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int result; // eax
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx

result = a1;
switch ( a1 )
{
case 0:
v2 = func7(8, 1);
v4 = v3;
goto LABEL_3;
case 1:
v2 = func7(8, 0);
v4 = v5;
goto LABEL_3;
case 2:
v2 = func7(16, 1);
v4 = v6;
goto LABEL_3;
case 3:
v2 = func7(16, 0);
v4 = v7;
goto LABEL_3;
case 4:
v2 = func7(32, 1);
v4 = v8;
goto LABEL_3;
case 5:
v2 = func7(32, 0);
v4 = v9;
goto LABEL_3;
case 6:
v2 = func7(64, 1);
v4 = v10;
goto LABEL_3;
case 7:
v2 = func7(64, 0);
v4 = v11;
LABEL_3:
result = printf("%s:\n\t\t%ld \t\t-\t%lu\n", (&g_type_str)[a1], v2, v4);
break;
default:
return result;
}
return result;
}

original_code:
void printValueRange(kType t) {
  Range r;
  switch(t) {
    case kChar:
      r = getRange(sizeof(char) * 8, 1);
      break;
    case kUnsignedChar:
      r = getRange(sizeof(char) * 8, 0);
      break;
    case kShort:
      r = getRange(sizeof(short) * 8, 1);
      break;
    case kUnsignedShort:
      r = getRange(sizeof(short) * 8, 0);
      break;
    case kInt:
      r = getRange(sizeof(int) * 8, 1);
      break;
    case kUnsignedInt:
      r = getRange(sizeof(int) * 8, 0);
      break;
    case kLong:
      r = getRange(sizeof(long) * 8, 1);
      break;
    case kUnsignedLong:
      r = getRange(sizeof(long) * 8, 0);
      break;
    default:
      return;
  }
  printf("%s:\n\t\t%ld \t\t-\t%lu\n", g_type_str[t], r.start, r.end);
}

canonical_original_code:
void printValueRange(enum kType t) {
  struct Range r;
  switch(t) {
    case kChar:
      r = getRange(sizeof(char) * 8, 1);
      break;
    case kUnsignedChar:
      r = getRange(sizeof(char) * 8, 0);
      break;
    case kShort:
      r = getRange(sizeof(short) * 8, 1);
      break;
    case kUnsignedShort:
      r = getRange(sizeof(short) * 8, 0);
      break;
    case kInt:
      r = getRange(sizeof(int) * 8, 1);
      break;
    case kUnsignedInt:
      r = getRange(sizeof(int) * 8, 0);
      break;
    case kLong:
      r = getRange(sizeof(long) * 8, 1);
      break;
    case kUnsignedLong:
      r = getRange(sizeof(long) * 8, 0);
      break;
    default:
      return;
  }
  printf("%s:\n\t\t%ld \t\t-\t%lu\n", g_type_str[t], r.start, r.end);
}

variable_types: enum kType { kChar=0, kUnsignedChar=1, kShort=2, kUnsignedShort=3, kInt=4, kUnsignedInt=5, kLong=6, kUnsignedLong=7, kUnknow=8 }

user_defined_types: struct Range { long start; unsigned long end; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx

for ( i = 0; i != 8; ++i )
printValueRange(i);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx

for ( i = 0; i != 8; ++i )
func8(i);
return 0;
}

original_code:
int main(int argc, char const *argv[])
{
  kType t = kChar;
  for( ;t < kUnknow; t++)
    printValueRange(t);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  enum kType t = kChar;
  for( ;t < kUnknow; t++)
    printValueRange(t);
  return 0;
}

variable_types: argc int

user_defined_types: enum kType { kChar=0, kUnsignedChar=1, kShort=2, kUnsignedShort=3, kInt=4, kUnsignedInt=5, kLong=6, kUnsignedLong=7, kUnknow=8 }


draw

repo: khile/asciitennis

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

result = BOARD;
*(_WORD *)(BOARD + 2LL * (a2 + WIDTH * a3) + 8) = a1;
return result;
}

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

result = BOARD;
*(_WORD *)(BOARD + 2LL * (a2 + WIDTH * a3) + 8) = a1;
return result;
}

original_code:
void draw(short int c, int x, int y)
{
    int index = y*WIDTH+x;
    BOARD->board[index] = c;
}

canonical_original_code:
void draw(short c, int x, int y)
{
    int index = y*WIDTH+x;
    BOARD->board[index] = c;
}

variable_types: c short

variable_types: x int

variable_types: y int

variable_types: index int


drawpieces

original_code:
void drawpieces(void)
{
    int i;
    int x, y;
    struct piece *p;
    for (i = 4 -1; i > -1; i--) {
        p = PIECE_PTR[i];
        for (y = p->y; y < (p->y)+(p->h); y++) {
            for (x = p->x; x < (p->x)+(p->w); x++) {
                if (0 <= y && y <= HEIGHT-1 &&
                    0 <= x && x <= WIDTH-1)
                    draw((p->c), x, y);
            }
        }
    }
}

canonical_original_code:
void drawpieces()
{
    int i;
    int x; int y;
    struct piece *p;
    for (i = 4 -1; i > -1; i--) {
        p = PIECE_PTR[i];
        for (y = p->y; y < (p->y)+(p->h); y++) {
            for (x = p->x; x < (p->x)+(p->w); x++) {
                if (0 <= y && y <= HEIGHT-1 &&
                    0 <= x && x <= WIDTH-1)
                    draw((p->c), x, y);
            }
        }
    }
}

variable_types: i int

variable_types: struct piece { int x; int y; int w; int h; short d; short c; } *