decompiled_code:
__int64 get_story_file_metadata()
{
return tads_get_story_file_metadata();
}

canonical_decompiled_code:
__int64 func2()
{
return tads_get_story_file_metadata();
}

original_code:
static int32 get_story_file_metadata(void *story_file, int32 extent,
                                     char *buf, int32 bufsize)
{
    return tads_get_story_file_metadata(story_file, extent, buf, bufsize);
}

canonical_original_code:
static int get_story_file_metadata(void *story_file, int extent, char *buf, int bufsize)
{
    return tads_get_story_file_metadata(story_file, extent, buf, bufsize);
}

variable_types:
buf
char *

variable_types: bufsize int


repo: ricpelo/elcirculo

decompiled_code:
__int64 get_story_file_cover_extent()
{
return tads_get_story_file_cover_extent();
}

canonical_decompiled_code:
__int64 func3()
{
return tads_get_story_file_cover_extent();
}

original_code:
static int32 get_story_file_cover_extent(void *story_file, int32 story_len)
{
    return tads_get_story_file_cover_extent(story_file, story_len);
}

canonical_original_code:
static int get_story_file_cover_extent(void *story_file, int story_len)
{
    return tads_get_story_file_cover_extent(story_file, story_len);
}

return_type: int


decompiled_code:
__int64 get_story_file_cover_format()
{
return tads_get_story_file_cover_format();
}

canonical_decompiled_code:
__int64 func4()
{
return tads_get_story_file_cover_format();
}

original_code:
static int32 get_story_file_cover_format(void *story_file, int32 story_len)
{
    return tads_get_story_file_cover_format(story_file, story_len);
}

canonical_original_code:
static int get_story_file_cover_format(void *story_file, int story_len)
{
    return tads_get_story_file_cover_format(story_file, story_len);
}


decompiled_code:
__int64 get_story_file_cover()
{
return tads_get_story_file_cover();
}

canonical_decompiled_code:
__int64 func5()
{
return tads_get_story_file_cover();
}

original_code:
static int32 get_story_file_cover(void *story_file, int32 story_len,
                                  void *outbuf, int32 output_extent)
{
    return tads_get_story_file_cover(story_file, story_len,
                                     outbuf, output_extent);
}

canonical_original_code:
static int get_story_file_cover(void *story_file, int story_len, void *outbuf, int output_extent)
{
    return tads_get_story_file_cover(story_file, story_len,
                                     outbuf, output_extent);
}

variable_types:
outbuf
void *


decompiled_code:
__int64 get_story_file_IFID()
{
return tads_get_story_file_IFID();
}

canonical_decompiled_code:
__int64 func6()
{
return tads_get_story_file_IFID();
}

original_code:
static int32 get_story_file_IFID(void *story_file, int32 extent,
                                 char *output, int32 output_extent)
{
    return tads_get_story_file_IFID(story_file, extent,
                                    output, output_extent);
}

canonical_original_code:
static int get_story_file_IFID(void *story_file, int extent, char *output, int output_extent)
{
    return tads_get_story_file_IFID(story_file, extent,
                                    output, output_extent);
}

variable_types: extent int

variable_types:
output
char *


decompiled_code:
size_t __fastcall get_story_file_extension(__int64 a1, int a2, void *a3, int a4)
{
__int64 v6; // rax
int v7; // ecx
char v8; // dl
__int64 v9; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v6 = 1LL;
do
{
v7 = v6;
v8 = byte_2F1[v6++];
}
while ( v8 && v8 != 44 );
if ( a4 <= v7 )
return 4294967293LL;
v9 = v7;
memcpy(a3, byte_2F1, v7);
*((_BYTE *)a3 + v9) = 0;
return strlen((const char *)a3);
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, int a2, void *a3, int a4)
{
__int64 v6; // rax
int v7; // ecx
char v8; // dl
__int64 v9; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v6 = 1LL;
do
{
v7 = v6;
v8 = byte_2F1[v6++];
}
while ( v8 && v8 != 44 );
if ( a4 <= v7 )
return 4294967293LL;
v9 = v7;
memcpy(a3, byte_2F1, v7);
*((_BYTE *)a3 + v9) = 0;
return strlen((const char *)a3);
}

original_code:
static int32 get_story_file_extension(void *sf, int32 extent, char *out, int32 output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".gam"[i] && ".gam"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".gam",i);
 out[i]=0;
 return strlen(out);
}

canonical_original_code:
static int get_story_file_extension(void *sf, int extent, char *out, int output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".gam"[i] && ".gam"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".gam",i);
 out[i]=0;
 return strlen(out);
}

variable_types:
sf
void *

variable_types:
out
char *

variable_types: i int


ShortProgramName

decompiled_code:
char *__fastcall ShortProgramName(const char *a1)
{
const char *v1; // rbx
char *v2; // rax
char *v3; // rbx
char *v4; // rax

v1 = a1;
v2 = strrchr(a1, 47);
if ( v2 )
v1 = v2 + 1;
v3 = strdup(v1);
v4 = strrchr(v3, 46);
if ( v4 )
*v4 = 0;
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
const char *v1; // rbx
char *v2; // rax
char *v3; // rbx
char *v4; // rax

v1 = a1;
v2 = strrchr(a1, 47);
if ( v2 )
v1 = v2 + 1;
v3 = strdup(v1);
v4 = strrchr(v3, 46);
if ( v4 )
*v4 = 0;
return v3;
}

original_code:
char *ShortProgramName(char *argv)
{
  char *MyName;
  MyName=strrchr(argv,'/');
  if (MyName) MyName++;
  else MyName=argv;
  MyName=strdup(MyName);
  if (strrchr(MyName,'.')) *(strrchr(MyName,'.'))=0;
  return MyName;
}

variable_types:
argv
char *

variable_types:
MyName
char *

return_type: char *


original_code:
void
md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
{
    const md5_byte_t *p = data;
    int left = nbytes;
    int offset = (pms->count[0] >> 3) & 63;
    md5_word_t nbits = (md5_word_t)(nbytes << 3);
    if (nbytes <= 0)
 return;
    pms->count[1] += nbytes >> 29;
    pms->count[0] += nbits;
    if (pms->count[0] < nbits)
 pms->count[1]++;
    if (offset) {
 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 memcpy(pms->buf + offset, p, copy);
 if (offset + copy < 64)
     return;
 p += copy;
 left -= copy;
 md5_process(pms, pms->buf);
    }
    for (; left >= 64; p += 64, left -= 64)
 md5_process(pms, p);
    if (left)
 memcpy(pms->buf, p, left);
}

canonical_original_code:
void md5_append(struct md5_state_s *pms, unsigned char *data, int nbytes)
{
    unsigned char *p = data;
    int left = nbytes;
    int offset = (pms->count[0] >> 3) & 63;
    unsigned int nbits = (md5_word_t)(nbytes << 3);
    if (nbytes <= 0)
 return;
    pms->count[1] += nbytes >> 29;
    pms->count[0] += nbits;
    if (pms->count[0] < nbits)
 pms->count[1]++;
    if (offset) {
 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 memcpy(pms->buf + offset, p, copy);
 if (offset + copy < 64)
     return;
 p += copy;
 left -= copy;
 md5_process(pms, pms->buf);
    }
    for (; left >= 64; p += 64, left -= 64)
 md5_process(pms, p);
    if (left)
 memcpy(pms->buf, p, left);
}

variable_types: struct md5_state_s { unsigned int count[2]; unsigned int abcd[4]; unsigned char buf[64]; } *

variable_types:
data
unsigned char *

variable_types: nbytes int

variable_types:
p
unsigned char *

variable_types: left int

variable_types: offset int

variable_types:
nbits
unsigned int

variable_types: copy int

return_type: void


decompiled_code:
int show_usage()
{
int result; // eax
char *v1; // rsi
__int64 v2; // rbx
const char *v3; // r8
const char *v4; // rdx

result = puts("Usage:");
v1 = info[0];
if ( info[0] )
{
v2 = (unsigned int)((_DWORD)info + 8);
do
{
v3 = (const char *)&unk_3B4;
if ( v1[1] == 99 )
v3 = " [-to <directory>]";
v4 = "<ifid>";
if ( !*(_BYTE *)(v2 + 16) )
v4 = "[<ifid>]";
result = printf(" babel-get %s %s %s <source>%s\n", v1, v4, *(const char **)v2, v3);
v2 += 32LL;
v1 = *(char **)(v2 - 8);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
char *v1; // rsi
__int64 v2; // rbx
const char *v3; // r8
const char *v4; // rdx

result = puts("Usage:");
v1 = info[0];
if ( info[0] )
{
v2 = (unsigned int)((_DWORD)info + 8);
do
{
v3 = (const char *)&unk_3B4;
if ( v1[1] == 99 )
v3 = " [-to <directory>]";
v4 = "<ifid>";
if ( !*(_BYTE *)(v2 + 16) )
v4 = "[<ifid>]";
result = printf(" babel-get %s %s %s <source>%s\n", v1, v4, *(const char **)v2, v3);
v2 += 32LL;
v1 = *(char **)(v2 - 8);
}
while ( v1 );
}
return result;
}

original_code:
void show_usage(void)
{
 int i;
 printf("Usage:\n");
 for(i=0;info[i].cmd;i++)
  printf(" babel-get %s %s %s <source>%s\n",
           info[i].cmd, info[i].nonull ? "<ifid>": "[<ifid>]", info[i].source,
           info[i].cmd[1]=='c' ? " [-to <directory>]":"");
}

canonical_original_code:
void show_usage()
{
 int i;
 printf("Usage:\n");
 for(i=0;info[i].cmd;i++)
  printf(" babel-get %s %s %s <source>%s\n",
           info[i].cmd, info[i].nonull ? "<ifid>": "[<ifid>]", info[i].source,
           info[i].cmd[1]=='c' ? " [-to <directory>]":"");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int v6; // eax
const char *v7; // rsi
const char *v8; // r12
const char **v9; // r15
__int64 v10; // rbx
const char *v11; // r13
int v12; // [rsp+Ch] [rbp-25Ch]
__int64 v13; // [rsp+10h] [rbp-258h]
const char *v14; // [rsp+18h] [rbp-250h]
const char **v15; // [rsp+20h] [rbp-248h]
__int64 v16; // [rsp+28h] [rbp-240h]
char buf[568]; // [rsp+30h] [rbp-238h] BYREF

if ( (unsigned int)(argc - 4) > 3 )
goto LABEL_6;
if ( argc <= 5 )
{
v13 = argc;
v15 = &argv[v13 - 2];
v12 = strcmp(*v15, "-to");
if ( v12 )
goto LABEL_9;
}
else
{
v13 = argc;
if ( strcmp(argv[v13 - 2], "-to") )
{
LABEL_6:
show_usage();
return 1;
}
v15 = &argv[v13 - 2];
v12 = strcmp(*v15, "-to");
}
if ( !strcmp(argv[1], "-ifiction") )
goto LABEL_6;
LABEL_9:
v14 = argv[2];
if ( *v14 == 45 )
{
v14 = 0LL;
v6 = 2;
}
else
{
v6 = 3;
}
v7 = info[0];
if ( info[0] )
{
v8 = argv[1];
v16 = v6;
v9 = &argv[v16];
v10 = 0LL;
while ( 1 )
{
if ( !strcmp(v8, v7) )
{
v11 = *v9;
v4 = strcmp(*v9, info[4 * v10 + 1]);
if ( !v4 )
break;
}
++v10;
v7 = info[4 * v10];
if ( !v7 )
goto LABEL_26;
}
if ( v14 || !LOBYTE(info[4 * (int)v10 + 3]) )
{
if ( !v12 )
{
getcwd(buf, 0x200uLL);
chdir(argv[v13 - 1]);
}
if ( !((__int64 (__fastcall *)(const char *, const char *))info[4 * (int)v10 + 2])(v14, argv[v16 + 1]) )
puts("Requested information not found.");
if ( !strcmp(*v15, "-to") )
{
chdir(buf);
v4 = 0;
}
}
else
{
printf("%s %s requires an explicit IFID.\n", v8, v11);
v4 = 1;
}
}
else
{
LABEL_26:
if ( !v12 )
chdir(buf);
show_usage();
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int v6; // eax
const char *v7; // rsi
const char *v8; // r12
const char **v9; // r15
__int64 v10; // rbx
const char *v11; // r13
int v12; // [rsp+Ch] [rbp-25Ch]
__int64 v13; // [rsp+10h] [rbp-258h]
const char *v14; // [rsp+18h] [rbp-250h]
const char **v15; // [rsp+20h] [rbp-248h]
__int64 v16; // [rsp+28h] [rbp-240h]
char buf[568]; // [rsp+30h] [rbp-238h] BYREF

if ( (unsigned int)(argc - 4) > 3 )
goto LABEL_6;
if ( argc <= 5 )
{
v13 = argc;
v15 = &argv[v13 - 2];
v12 = strcmp(*v15, "-to");
if ( v12 )
goto LABEL_9;
}
else
{
v13 = argc;
if ( strcmp(argv[v13 - 2], "-to") )
{
LABEL_6:
func0();
return 1;
}
v15 = &argv[v13 - 2];
v12 = strcmp(*v15, "-to");
}
if ( !strcmp(argv[1], "-ifiction") )
goto LABEL_6;
LABEL_9:
v14 = argv[2];
if ( *v14 == 45 )
{
v14 = 0LL;
v6 = 2;
}
else
{
v6 = 3;
}
v7 = info[0];
if ( info[0] )
{
v8 = argv[1];
v16 = v6;
v9 = &argv[v16];
v10 = 0LL;
while ( 1 )
{
if ( !strcmp(v8, v7) )
{
v11 = *v9;
v4 = strcmp(*v9, info[4 * v10 + 1]);
if ( !v4 )
break;
}
++v10;
v7 = info[4 * v10];
if ( !v7 )
goto LABEL_26;
}
if ( v14 || !LOBYTE(info[4 * (int)v10 + 3]) )
{
if ( !v12 )
{
getcwd(buf, 0x200uLL);
chdir(argv[v13 - 1]);
}
if ( !((__int64 (__fastcall *)(const char *, const char *))info[4 * (int)v10 + 2])(v14, argv[v16 + 1]) )
puts("Requested information not found.");
if ( !strcmp(*v15, "-to") )
{
chdir(buf);
v4 = 0;
}
}
else
{
printf("%s %s requires an explicit IFID.\n", v8, v11);
v4 = 1;
}
}
else
{
LABEL_26:
if ( !v12 )
chdir(buf);
func0();
v4 = 1;
}
return v4;
}

original_code:
int main(int argc, char **argv)
{
 int srcc=2;
 char *ifid=((void *)0);
 int i;
 char cwd[512];
 if (argc<4 || argc > 7 || (argc >5 && strcmp(argv[argc-2],"-to")) ||
   (strcmp(argv[argc-2],"-to")==0 && strcmp(argv[1],"-ifiction")==0))
 {
  show_usage();
  return 1;
 }
 if (argv[2][0]!='-') { srcc=3; ifid=argv[2]; }
 for(i=0;info[i].cmd;i++)
  if (strcmp(argv[1],info[i].cmd)==0 &&
      strcmp(argv[srcc],info[i].source)==0)
  { if (ifid==((void *)0) && info[i].nonull)
    {
     printf("%s %s requires an explicit IFID.\n",argv[1],argv[srcc]);
     return 1;
    }
    else
    {
     if (strcmp(argv[argc-2],"-to")==0)
     {
      getcwd(cwd,512);
      chdir(argv[argc-1]);
     }
     if (!info[i].func(ifid,argv[srcc+1])) printf("Requested information not found.\n");
     if (strcmp(argv[argc-2],"-to")==0) chdir(cwd);
     return 0;
    }
  }
 if (strcmp(argv[argc-2],"-to")==0) chdir(cwd);
 show_usage();
 return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int srcc = 2;
 char *ifid = ((void *)0);
 int i;
 char cwd[512];
 if (argc<4 || argc > 7 || (argc >5 && strcmp(argv[argc-2],"-to")) ||
   (strcmp(argv[argc-2],"-to")==0 && strcmp(argv[1],"-ifiction")==0))
 {
  show_usage();
  return 1;
 }
 if (argv[2][0]!='-') { srcc=3; ifid=argv[2]; }
 for(i=0;info[i].cmd;i++)
  if (strcmp(argv[1],info[i].cmd)==0 &&
      strcmp(argv[srcc],info[i].source)==0)
  { if (ifid==((void *)0) && info[i].nonull)
    {
     printf("%s %s requires an explicit IFID.\n",argv[1],argv[srcc]);
     return 1;
    }
    else
    {
     if (strcmp(argv[argc-2],"-to")==0)
     {
      getcwd(cwd,512);
      chdir(argv[argc-1]);
     }
     if (!info[i].func(ifid,argv[srcc+1])) printf("Requested information not found.\n");
     if (strcmp(argv[argc-2],"-to")==0) chdir(cwd);
     return 0;
    }
  }
 if (strcmp(argv[argc-2],"-to")==0) chdir(cwd);
 show_usage();
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: srcc int

variable_types:
ifid
char *

variable_types:
cwd
char [512]


decompiled_code:
__int64 __fastcall get_dir(const char *a1, const char *a2)
{
__int64 v2; // rbx
char v4[528]; // [rsp+0h] [rbp-428h] BYREF
char buf[536]; // [rsp+210h] [rbp-218h] BYREF

v2 = (__int64)a1;
if ( a1 )
{
getcwd(buf, 0x200uLL);
sprintf(v4, "%s.iFiction", a1);
chdir(a2);
v2 = get_ifiction(a1, v4);
chdir(buf);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
__int64 v2; // rbx
char v4[528]; // [rsp+0h] [rbp-428h] BYREF
char buf[536]; // [rsp+210h] [rbp-218h] BYREF

v2 = (__int64)a1;
if ( a1 )
{
getcwd(buf, 0x200uLL);
sprintf(v4, "%s.iFiction", a1);
chdir(a2);
v2 = get_ifiction(a1, v4);
chdir(buf);
}
return v2;
}

original_code:
char *get_dir(char *ifid, char *from)
{
char cwd[512];
char buff[520];
char *md;
if (!ifid) return ((void *)0);
getcwd(cwd,512);
sprintf(buff,"%s.iFiction",ifid);
chdir(from);
md=get_ifiction(ifid,buff);
chdir(cwd);
return md;
}

variable_types:
from
char *

variable_types:
buff
char [520]

variable_types:
md
char *


decompiled_code:
__int64 __fastcall read_int(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

original_code:
unsigned int read_int(unsigned char *from)
{
 unsigned int l;
 l = ((unsigned int) from[0]) << 24;
 l |= ((unsigned int) from[1]) << 16;
 l |= ((unsigned int) from[2]) << 8;
 l |= ((unsigned int) from[3]);
 return l;
}

variable_types:
from
unsigned char *

variable_types:
l
unsigned int

return_type: unsigned int


getDirectionString

decompiled_code:
const char *__fastcall getDirectionString(int a1)
{
const char *result; // rax

if ( a1 == 2 )
return "Up";
if ( a1 > 2 )
{
result = (const char *)&unk_1CB;
if ( a1 == 3 )
result = "Down";
}
else
{
result = "Left";
if ( a1 )
{
result = (const char *)&unk_1CB;
if ( a1 == 1 )
result = "Right";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
const char *result; // rax

if ( a1 == 2 )
return "Up";
if ( a1 > 2 )
{
result = (const char *)&unk_1CB;
if ( a1 == 3 )
result = "Down";
}
else
{
result = "Left";
if ( a1 )
{
result = (const char *)&unk_1CB;
if ( a1 == 1 )
result = "Right";
}
}
return result;
}

original_code:
char* getDirectionString(int num)
{
 switch(num)
 {
  case 0:
   return "Left";
  case 1:
   return "Right";
  case 2:
   return "Up";
  case 3:
   return "Down";
  default:
   return "";
 }
}

canonical_original_code:
char *getDirectionString(int num)
{
 switch(num)
 {
  case 0:
   return "Left";
  case 1:
   return "Right";
  case 2:
   return "Up";
  case 3:
   return "Down";
  default:
   return "";
 }
}

variable_types: num int


strchrCount

decompiled_code:
__int64 __fastcall strchrCount(char *a1, char a2)
{
char v2; // al
unsigned int v3; // edx

v2 = *a1;
if ( !*a1 )
return 0;
v3 = 0;
do
{
if ( a2 == v2 )
++v3;
else
++a1;
v2 = a1[v3];
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char a2)
{
char v2; // al
unsigned int v3; // edx

v2 = *a1;
if ( !*a1 )
return 0;
v3 = 0;
do
{
if ( a2 == v2 )
++v3;
else
++a1;
v2 = a1[v3];
}
while ( v2 );
return v3;
}

original_code:
int strchrCount(char* s, char c)
{
 int i;
 for (i = 0; s[i]; (s[i] == c) ? (void) i++ : (void) s++);
 return i;
}

canonical_original_code:
int strchrCount(char *s, char c)
{
 int i;
 for (i = 0; s[i]; (s[i] == c) ? (void) i++ : (void) s++);
 return i;
}

variable_types:
s
char *

variable_types: c char

variable_types: i int


listShiftLeftAdd

decompiled_code:
void __fastcall listShiftLeftAdd(_DWORD *a1, int a2, float a3)
{
_DWORD *v3; // rax

if ( a2 > 1 )
{
v3 = a1;
do
{
*v3 = v3[1];
++v3;
}
while ( v3 != &a1[a2 - 2 + 1] );
}
*(float *)&a1[a2 - 1] = a3;
}

original_code:
void listShiftLeftAdd(float* list, int len, float new)
{
 for(int i = 0; i < len-1; i++)
 {
  list[i] = list[i+1];
 }
 list[len-1] = new;
}

canonical_original_code:
void listShiftLeftAdd(float *list, int len, float new)
{
 for(int i = 0; i < len-1; i++)
 {
  list[i] = list[i+1];
 }
 list[len-1] = new;
}

variable_types:
list
float *

variable_types: len int

variable_types: new float


listShiftRightAdd

decompiled_code:
void __fastcall listShiftRightAdd(float *a1, int a2, float a3)
{
__int64 v3; // rsi

LODWORD(v3) = a2 - 1;
if ( (int)v3 > 0 )
{
v3 = (int)v3;
do
{
a1[v3] = a1[v3 - 1];
--v3;
}
while ( (int)v3 > 0 );
}
*a1 = a3;
}

canonical_decompiled_code:
void __fastcall func4(float *a1, int a2, float a3)
{
__int64 v3; // rsi

LODWORD(v3) = a2 - 1;
if ( (int)v3 > 0 )
{
v3 = (int)v3;
do
{
a1[v3] = a1[v3 - 1];
--v3;
}
while ( (int)v3 > 0 );
}
*a1 = a3;
}

original_code:
void listShiftRightAdd(float* list, int len, float new)
{
 for(int i = len - 1; i > 0; i--)
 {
  list[i] = list[i-1];
 }
 list[0] = new;
}

canonical_original_code:
void listShiftRightAdd(float *list, int len, float new)
{
 for(int i = len - 1; i > 0; i--)
 {
  list[i] = list[i-1];
 }
 list[0] = new;
}


parseMemLine

decompiled_code:
__int64 __fastcall parseMemLine(void *src, int a2)
{
void *v2; // rsp
char *v3; // rdx
int v4; // edi
int v5; // edx
char *v6; // rcx
char v8[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = alloca(a2 + 1);
memcpy(v8, src, a2);
v8[a2] = 0;
if ( a2 <= 0 )
{
v4 = 0;
LABEL_5:
v5 = v4;
}
else
{
v3 = v8;
v4 = 0;
while ( (unsigned __int8)(*v3 - 48) > 9u )
{
++v4;
++v3;
if ( a2 == v4 )
goto LABEL_5;
}
if ( a2 <= v4 )
{
v5 = v4;
}
else
{
v6 = &v8[v4];
v5 = v4;
do
{
if ( (unsigned __int8)(*v6 - 48) > 9u )
break;
++v5;
++v6;
}
while ( a2 != v5 );
}
}
v8[v5] = 0;
return atol(&v8[v4]);
}

original_code:
long parseMemLine(char* str, int len)
{
 int i, j;
 char copy[len+1];
 memcpy(copy, str, len);
 copy[len] = '\0';
 for(i = 0; i < len && !(copy[i] >= '0' && copy[i] <= '9'); i++);
 for(j = i; j < len && copy[j] >= '0' && copy[j] <= '9'; j++);
 copy[j] = '\0';
 return atol(copy + i);
}

canonical_original_code:
long parseMemLine(char *str, int len)
{
 int i; int j;
 char copy[-1];
 memcpy(copy, str, len);
 copy[len] = '\0';
 for(i = 0; i < len && !(copy[i] >= '0' && copy[i] <= '9'); i++);
 for(j = i; j < len && copy[j] >= '0' && copy[j] <= '9'; j++);
 copy[j] = '\0';
 return atol(copy + i);
}

variable_types:
str
char *

variable_types: j int

variable_types:
copy
char [-1]

return_type: long


getMemInfo

original_code:
void getMemInfo(struct memPercent* mem)
{
 struct memNow now = readMem();
 if(now.ramTotal == 0)
  mem->ram = 0;
 else
  mem->ram = (float) (now.ramTotal - (now.ramFree + now.ramBuffered + now.ramCached)) / (float) now.ramTotal * 100.0;
 if(now.swapTotal == 0)
  mem->swap = 0;
 else
  mem->swap = (float) (now.swapTotal - now.swapFree) / (float) now.swapTotal * 100.0;
 mem->now = now;
}

canonical_original_code:
void getMemInfo(struct memPercent *mem)
{
 struct memNow now = readMem();
 if(now.ramTotal == 0)
  mem->ram = 0;
 else
  mem->ram = (float) (now.ramTotal - (now.ramFree + now.ramBuffered + now.ramCached)) / (float) now.ramTotal * 100.0;
 if(now.swapTotal == 0)
  mem->swap = 0;
 else
  mem->swap = (float) (now.swapTotal - now.swapFree) / (float) now.swapTotal * 100.0;
 mem->now = now;
}

variable_types: struct memPercent { struct memNow { long ramTotal; long ramFree; long ramBuffered; long ramCached; long swapTotal; long swapFree; } now; float ram; float swap; } *

user_defined_types: struct memPercent { struct memNow now; float ram; float swap; }


getCPUtime

original_code:
int getCPUtime(struct cpuPercent* cpu, int numCPUs, struct cpuTime* first, struct cpuTime* second)
{
 struct timeval wait = {.tv_sec = 1, .tv_usec = 0};
 fd_set set;
 long numEvents;
 readCPUs(numCPUs, first);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 select(1, &set, ((void *)0), ((void *)0), &wait);
 if(((((&set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  return 1;
 readCPUs(numCPUs, second);
 for(int i = 0; i < numCPUs + 1; i++)
 {
  numEvents = second[i].total - first[i].total;
  if(numEvents == 0)
   continue;
  cpu[i].user = (float) (second[i].user - first[i].user) / (float) numEvents * 100.0;
  cpu[i].sys = (float) (second[i].sys - first[i].sys) / (float) numEvents * 100.0;
  cpu[i].total = cpu[i].user + cpu[i].sys;
 }
 return 0;
}

canonical_original_code:
int getCPUtime(struct cpuPercent *cpu, int numCPUs, struct cpuTime *first, struct cpuTime *second)
{
 struct timeval wait = {.tv_sec = 1, .tv_usec = 0};
 struct fd_set set;
 long numEvents;
 readCPUs(numCPUs, first);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 select(1, &set, ((void *)0), ((void *)0), &wait);
 if(((((&set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  return 1;
 readCPUs(numCPUs, second);
 for(int i = 0; i < numCPUs + 1; i++)
 {
  numEvents = second[i].total - first[i].total;
  if(numEvents == 0)
   continue;
  cpu[i].user = (float) (second[i].user - first[i].user) / (float) numEvents * 100.0;
  cpu[i].sys = (float) (second[i].sys - first[i].sys) / (float) numEvents * 100.0;
  cpu[i].total = cpu[i].user + cpu[i].sys;
 }
 return 0;
}

variable_types: struct cpuPercent { float total; float user; float sys; } *

variable_types: numCPUs int

variable_types: struct cpuTime { unsigned long long total; long user; long sys; } *

variable_types:
second
struct cpuTime *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
set
struct fd_set { long __fds_bits[-1]; }

variable_types: numEvents long


repo: rillian/vtfoo

decompiled_code:
int __fastcall dump_box(const char *a1)
{
dump_box_helper(a1);
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
func0(a1);
return fputc(10, stdout);
}

original_code:
void dump_box(box *box)
{
  _dump_box_helper(box);
  fprintf(stdout, "\n");
}

canonical_original_code:
void dump_box(struct box *box)
{
  _dump_box_helper(box);
  fprintf(stdout, "\n");
}

variable_types: struct box { unsigned int size; unsigned char type[5]; int level; } *


decompiled_code:
int __fastcall dump_fullbox(const char *a1, unsigned __int8 *a2)
{
dump_box_helper(a1);
return fprintf(stdout, "\tVersion %d flags 0x%06x\n", *a2, *((unsigned int *)a2 + 1));
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, unsigned __int8 *a2)
{
func0(a1);
return fprintf(stdout, "\tVersion %d flags 0x%06x\n", *a2, *((unsigned int *)a2 + 1));
}

original_code:
void dump_fullbox(box *box, fullbox *header)
{
  _dump_box_helper(box);
  fprintf(stdout, "\tVersion %d flags 0x%06x\n",
      header->version, header->flags);
}

canonical_original_code:
void dump_fullbox(struct box *box, struct fullbox *header)
{
  _dump_box_helper(box);
  fprintf(stdout, "\tVersion %d flags 0x%06x\n",
      header->version, header->flags);
}

variable_types: struct fullbox { unsigned char version; unsigned int flags; } *

user_defined_types: struct box { unsigned int size; unsigned char type[5]; int level; }


repo: rioki/ciphersaber

decompiled_code:
int print_usage()
{
return printf(
"Usage: \n"
" cyphersaber [mode] [key] [input file] [output file]\n"
"\n"
"Options: \n"
" mode: encrypt / decrypt\n"
" key: encryption key, may be up to 245 chars long\n"
" input file: the input to read\n"
" output file: the input to write");
}

canonical_decompiled_code:
int func7()
{
return printf(
"Usage: \n"
" cyphersaber [mode] [key] [input file] [output file]\n"
"\n"
"Options: \n"
" mode: encrypt / decrypt\n"
" key: encryption key, may be up to 245 chars long\n"
" input file: the input to read\n"
" output file: the input to write");
}

original_code:
void print_usage()
{
    printf("Usage: \n"
           "  cyphersaber [mode] [key] [input file] [output file]\n"
           "\n"
           "Options: \n"
           "  mode: encrypt / decrypt\n"
           "  key: encryption key, may be up to 245 chars long\n"
           "  input file: the input to read\n"
           "  output file: the input to write");
}


swap

decompiled_code:
__int64 __fastcall swap(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(rc4_byte* a, rc4_byte* b)
{
    rc4_byte t = *a;
    *a = *b;
    *b = t;
}

canonical_original_code:
void swap(unsigned char *a, unsigned char *b)
{
    unsigned char t = *a;
    *a = *b;
    *b = t;
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
t
unsigned char


decompiled_code:
__int64 __fastcall rc4(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl
unsigned int v4; // ecx

v2 = *a1 + 1;
*a1 = v2;
v3 = a1[1] + a1[v2 + 2];
a1[1] = v3;
swap(&a1[v2 + 2], &a1[v3 + 2]);
v4 = a2;
LOBYTE(v4) = a1[(unsigned __int8)(a1[*a1 + 2] + a1[a1[1] + 2]) + 2] ^ a2;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl
unsigned int v4; // ecx

v2 = *a1 + 1;
*a1 = v2;
v3 = a1[1] + a1[v2 + 2];
a1[1] = v3;
func8(&a1[v2 + 2], &a1[v3 + 2]);
v4 = a2;
LOBYTE(v4) = a1[(unsigned __int8)(a1[*a1 + 2] + a1[a1[1] + 2]) + 2] ^ a2;
return v4;
}

original_code:
rc4_byte rc4(rc4_state* state, rc4_byte in)
{
    rc4_byte n;
    state->i++;
    state->j += state->state[state->i];
    swap(&state->state[state->i], &state->state[state->j]);
    n = state->state[state->i] + state->state[state->j];
    return in ^ state->state[n];
}

canonical_original_code:
unsigned char rc4(struct rc4_state_ *state, unsigned char in)
{
    unsigned char n;
    state->i++;
    state->j += state->state[state->i];
    swap(&state->state[state->i], &state->state[state->j]);
    n = state->state[state->i] + state->state[state->j];
    return in ^ state->state[n];
}

variable_types: struct rc4_state_ { unsigned char i; unsigned char j; unsigned char state[256]; } *

variable_types:
in
unsigned char

variable_types:
n
unsigned char

return_type: unsigned char


decrement

repo: rjrodger/sdc

original_code:
void decrement( int *counts ) {
  counts[6]--;
  if( counts[6] < 0 ) {
    counts[6] = 59;
    counts[5]--;
  }
  if( counts[5] < 0 ) {
    counts[5] = 59;
    counts[4]--;
  }
  if( counts[4] < 0 ) {
    counts[4] = 23;
    counts[3]--;
  }
  if( counts[3] < 0 ) {
    counts[3] = 0;
  }
}

canonical_original_code:
void decrement(int *counts) {
  counts[6]--;
  if( counts[6] < 0 ) {
    counts[6] = 59;
    counts[5]--;
  }
  if( counts[5] < 0 ) {
    counts[5] = 59;
    counts[4]--;
  }
  if( counts[4] < 0 ) {
    counts[4] = 23;
    counts[3]--;
  }
  if( counts[3] < 0 ) {
    counts[3] = 0;
  }
}

variable_types:
counts
int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v5; // [rsp+0h] [rbp-28h] BYREF
unsigned int v6; // [rsp+4h] [rbp-24h]
unsigned int v7; // [rsp+8h] [rbp-20h]
unsigned int v8; // [rsp+Ch] [rbp-1Ch]
unsigned int v9; // [rsp+10h] [rbp-18h]
unsigned int v10; // [rsp+14h] [rbp-14h]
unsigned int v11; // [rsp+18h] [rbp-10h]

v5 = 0;
v6 = 9;
v7 = 3;
v8 = 6;
v9 = 1;
v10 = 1;
v11 = 6;
for ( i = 0; i != 70; ++i )
{
decrement(&v5);
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i, v5, v6, v7, v8, v9, v10, v11);
sleep(1u);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v5; // [rsp+0h] [rbp-28h] BYREF
unsigned int v6; // [rsp+4h] [rbp-24h]
unsigned int v7; // [rsp+8h] [rbp-20h]
unsigned int v8; // [rsp+Ch] [rbp-1Ch]
unsigned int v9; // [rsp+10h] [rbp-18h]
unsigned int v10; // [rsp+14h] [rbp-14h]
unsigned int v11; // [rsp+18h] [rbp-10h]

v5 = 0;
v6 = 9;
v7 = 3;
v8 = 6;
v9 = 1;
v10 = 1;
v11 = 6;
for ( i = 0; i != 70; ++i )
{
func7(&v5);
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i, v5, v6, v7, v8, v9, v10, v11);
sleep(1u);
}
return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
c
int []

variable_types: i int


terminate

repo: rliang/cpbar

decompiled_code:
void terminate(void)
{
engine_terminate();
window_terminate();
}

canonical_decompiled_code:
void func0(void)
{
engine_terminate();
window_terminate();
}

original_code:
static void terminate()
{
 engine_terminate();
 window_terminate();
}


decompiled_code:
void __noreturn main_loop()
{
struct pollfd v0; // [rsp+0h] [rbp-18h] BYREF
int v1; // [rsp+8h] [rbp-10h]
__int16 v2; // [rsp+Ch] [rbp-Ch]
__int16 v3; // [rsp+Eh] [rbp-Ah]

v0.fd = 0;
v0.events = 1;
v0.revents = 0;
v1 = window[5];
v2 = 1;
v3 = 0;
while ( 1 )
{
while ( !poll(&v0, 2uLL, -1) )
;
if ( (v0.revents & 0x10) != 0 )
v0.fd = -1;
if ( (v0.revents & 1) != 0 )
engine_input_wait(&v0, 2LL);
if ( (v3 & 1) != 0 )
window_event_wait(&v0, 2LL);
window_flush(&v0, 2LL);
}
}

canonical_decompiled_code:
void __noreturn func2()
{
struct pollfd v0; // [rsp+0h] [rbp-18h] BYREF
int v1; // [rsp+8h] [rbp-10h]
__int16 v2; // [rsp+Ch] [rbp-Ch]
__int16 v3; // [rsp+Eh] [rbp-Ah]

v0.fd = 0;
v0.events = 1;
v0.revents = 0;
v1 = window[5];
v2 = 1;
v3 = 0;
while ( 1 )
{
while ( !poll(&v0, 2uLL, -1) )
;
if ( (v0.revents & 0x10) != 0 )
v0.fd = -1;
if ( (v0.revents & 1) != 0 )
engine_input_wait(&v0, 2LL);
if ( (v3 & 1) != 0 )
window_event_wait(&v0, 2LL);
window_flush(&v0, 2LL);
}
}

original_code:
static void main_loop()
{
 struct pollfd polls[2] = {
  { 0, 0x001, 0 },
  { window.xcb_file_descriptor, 0x001, 0 }
 };
 for (;;) {
  if (!poll(polls, 2, -1))
   continue;
  if (polls[0].revents & 0x010)
   polls[0].fd = -1;
  if (polls[0].revents & 0x001)
   engine_input_wait();
  if (polls[1].revents & 0x001)
   window_event_wait();
  window_flush();
 }
}

variable_types: struct pollfd { int fd; short events; short revents; } [2]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
atexit(terminate);
if ( (unsigned __int8)init((unsigned int)argc, argv) )
main_loop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
atexit(terminate);
if ( (unsigned __int8)func1((unsigned int)argc, argv) )
func2();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 atexit(terminate);
 if (init(argc, argv))
  main_loop();
}


decompiled_code:
__int64 __fastcall engine_parse_position(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // edx

v2 = 0;
if ( *a2 )
{
v2 = *(unsigned __int8 *)*a1;
--*a2;
++*a1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // edx

v2 = 0;
if ( *a2 )
{
v2 = *(unsigned __int8 *)*a1;
--*a2;
++*a1;
}
return v2;
}

original_code:
static char engine_parse_position(char **input, size_t *length)
{
 if (*length < 1)
  return '\0';
 char position = (*input)[0];
 *length -= 1;
 *input += 1;
 return position;
}

canonical_original_code:
static char engine_parse_position(char **input, unsigned long *length)
{
 if (*length < 1)
  return '\0';
 char position = (*input)[0];
 *length -= 1;
 *input += 1;
 return position;
}

variable_types:
input
char **

variable_types:
length
unsigned long *

variable_types: position char

return_type: char


decompiled_code:
__int64 __fastcall engine_parse_index(const char **a1, __int64 *a2)
{
__int64 v3; // rbx
const unsigned __int16 *v4; // rsi
__int64 v5; // rax
__int64 result; // rax

v3 = *a2;
if ( *a2 )
{
v4 = *_ctype_b_loc();
v5 = 0LL;
while ( (v4[(*a1)[v5]] & 0x800) != 0 )
{
if ( ++v5 == v3 )
goto LABEL_7;
}
v3 = v5;
}
LABEL_7:
(*a1)[v3] = 0;
LODWORD(result) = atoi(*a1);
*a2 += ~v3;
*a1 += v3 + 1;
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1, __int64 *a2)
{
__int64 v3; // rbx
const unsigned __int16 *v4; // rsi
__int64 v5; // rax
__int64 result; // rax

v3 = *a2;
if ( *a2 )
{
v4 = *_ctype_b_loc();
v5 = 0LL;
while ( (v4[(*a1)[v5]] & 0x800) != 0 )
{
if ( ++v5 == v3 )
goto LABEL_7;
}
v3 = v5;
}
LABEL_7:
(*a1)[v3] = 0;
LODWORD(result) = atoi(*a1);
*a2 += ~v3;
*a1 += v3 + 1;
return (int)result;
}

original_code:
static size_t engine_parse_index(char **input, size_t *length)
{
 size_t i = 0;
 while (i < *length && ((*__ctype_b_loc ())[(int) (((*input)[i]))] & (unsigned short int) _ISdigit))
  i += 1;
 (*input)[i] = '\0';
 size_t index = atoi(*input);
 *length -= i + 1;
 *input += i + 1;
 return index;
}

canonical_original_code:
static unsigned long engine_parse_index(char **input, unsigned long *length)
{
 unsigned long i = 0;
 while (i < *length && ((*__ctype_b_loc ())[(int) (((*input)[i]))] & (unsigned short) _ISdigit))
  i += 1;
 (*input)[i] = '\0';
 unsigned long index = atoi(*input);
 *length -= i + 1;
 *input += i + 1;
 return index;
}

variable_types:
i
unsigned long

variable_types:
index
unsigned long

return_type: unsigned long


decompiled_code:
__int64 engine_clean_canvas()
{
cairo_set_source_rgba(
cairo_context,
*(double *)&default_background,
*(double *)&qword_498,
*(double *)&qword_4A0,
1.0);
return cairo_paint(cairo_context);
}

canonical_decompiled_code:
__int64 func3()
{
cairo_set_source_rgba(
cairo_context,
*(double *)&default_background,
*(double *)&qword_498,
*(double *)&qword_4A0,
1.0);
return cairo_paint(cairo_context);
}

original_code:
static void engine_clean_canvas()
{
 cairo_set_source_rgba(cairo_context,
    default_background[0],
    default_background[1],
    default_background[2], 1);
 cairo_paint(cairo_context);
}


decompiled_code:
void engine_draw_sets()
{
int v0; // ebx
int v1; // er13
int v2; // er12
int v3; // ebp
int v4; // esi

v0 = layout_set_get_pixel_width(left_set);
v1 = layout_set_get_pixel_width(right_set);
v2 = layout_set_get_pixel_width(center_set);
v3 = canvas_width - v1;
engine_draw_set(right_set, canvas_width - v1, canvas_width);
if ( v3 <= v0 )
v0 = v3;
engine_draw_set(left_set, 0, v0);
v4 = (unsigned int)(canvas_width - v2) >> 1;
if ( v0 >= v4 )
v4 = v0;
engine_draw_set(center_set, v4, v3);
}

canonical_decompiled_code:
void func6()
{
int v0; // ebx
int v1; // er13
int v2; // er12
int v3; // ebp
int v4; // esi

v0 = layout_set_get_pixel_width(left_set);
v1 = layout_set_get_pixel_width(right_set);
v2 = layout_set_get_pixel_width(center_set);
v3 = canvas_width - v1;
func5(right_set, canvas_width - v1, canvas_width);
if ( v3 <= v0 )
v0 = v3;
func5(left_set, 0, v0);
v4 = (unsigned int)(canvas_width - v2) >> 1;
if ( v0 >= v4 )
v4 = v0;
func5(center_set, v4, v3);
}

original_code:
static void engine_draw_sets()
{
 unsigned int left_width = layout_set_get_pixel_width(left_set);
 unsigned int right_width = layout_set_get_pixel_width(right_set);
 unsigned int center_width = layout_set_get_pixel_width(center_set);
 int right_begin = canvas_width - right_width;
 int right_end = canvas_width;
 engine_draw_set(right_set, right_begin, right_end);
 int left_begin = 0;
 int left_end = left_width;
 if (left_end > right_begin)
  left_end = right_begin;
 engine_draw_set(left_set, left_begin, left_end);
 int center_begin = (canvas_width - center_width) / 2;
 if (center_begin < left_end)
  center_begin = left_end;
 int center_end = right_begin;
 engine_draw_set(center_set, center_begin, center_end);
}


decompiled_code:
void engine_refresh()
{
engine_clean_canvas();
engine_draw_sets();
}

canonical_decompiled_code:
void func9()
{
func3();
func6();
}


decompiled_code:
void engine_input_wait()
{
char v0[8208]; // [rsp+0h] [rbp-2010h] BYREF

if ( fgets(v0, 0x2000, stdin) )
{
v0[strlen(v0) - 1] = 0;
engine_update(v0, 0x2000uLL);
}
}

original_code:
void engine_input_wait()
{
 size_t length = 8192;
 char buffer[length];
 if (fgets(buffer, length, stdin) == ((void *)0))
  return;
 buffer[strlen(buffer) - 1] = '\0';
 engine_update(buffer, length);
}

canonical_original_code:
void engine_input_wait()
{
 unsigned long length = 8192;
 char buffer[-1];
 if (fgets(buffer, length, stdin) == ((void *)0))
  return;
 buffer[strlen(buffer) - 1] = '\0';
 engine_update(buffer, length);
}

variable_types:
length
unsigned long

variable_types:
buffer
char [-1]


decompiled_code:
__int64 engine_terminate()
{
cairo_destroy(cairo_context);
layout_set_destroy(left_set);
layout_set_destroy(right_set);
return layout_set_destroy(center_set);
}

canonical_decompiled_code:
__int64 func12()
{
cairo_destroy(cairo_context);
layout_set_destroy(left_set);
layout_set_destroy(right_set);
return layout_set_destroy(center_set);
}

original_code:
void engine_terminate()
{
 cairo_destroy(cairo_context);
 layout_set_destroy(left_set);
 layout_set_destroy(right_set);
 layout_set_destroy(center_set);
}


decompiled_code:
_BYTE *options_allocate()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
*(_WORD *)v0 = 16;
v0[2] = 0;
*((_QWORD *)v0 + 1) = strdup("Sans-Serif Bold 9");
*((_QWORD *)v1 + 2) = strdup("#ffffff");
*((_QWORD *)v1 + 3) = strdup("#000000");
}
return v1;
}

original_code:
static struct options *options_allocate()
{
 struct options *new = malloc(sizeof(struct options));
 if (new == ((void *)0))
  return ((void *)0);
 new->bar_height = 16;
 new->bar_on_bottom = 0;
 new->default_font = strdup("Sans-Serif Bold 9");
 new->default_foreground = strdup("#ffffff");
 new->default_background = strdup("#000000");
 return new;
}

variable_types: struct options { unsigned short bar_height; _Bool bar_on_bottom; char *default_font; char *default_foreground; char *default_background; } *


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

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

original_code:
void options_destroy(struct options *options)
{
 char *strings[] = {
  options->default_font,
  options->default_foreground,
  options->default_background
 };
 free(options);
}

variable_types:
strings
char *[]

user_defined_types: struct options { unsigned short bar_height; _Bool bar_on_bottom; char *default_font; char *default_foreground; char *default_background; }


decompiled_code:
void **__fastcall options_new(int argc, char **argv)
{
void **v2; // rbx
int v3; // eax
struct option v5; // [rsp+0h] [rbp-D8h] BYREF
const char *v6; // [rsp+20h] [rbp-B8h]
int v7; // [rsp+28h] [rbp-B0h]
__int64 v8; // [rsp+30h] [rbp-A8h]
int v9; // [rsp+38h] [rbp-A0h]
const char *v10; // [rsp+40h] [rbp-98h]
int v11; // [rsp+48h] [rbp-90h]
__int64 v12; // [rsp+50h] [rbp-88h]
int v13; // [rsp+58h] [rbp-80h]
const char *v14; // [rsp+60h] [rbp-78h]
int v15; // [rsp+68h] [rbp-70h]
__int64 v16; // [rsp+70h] [rbp-68h]
int v17; // [rsp+78h] [rbp-60h]
const char *v18; // [rsp+80h] [rbp-58h]
int v19; // [rsp+88h] [rbp-50h]
__int64 v20; // [rsp+90h] [rbp-48h]
int v21; // [rsp+98h] [rbp-40h]
const char *v22; // [rsp+A0h] [rbp-38h]
int v23; // [rsp+A8h] [rbp-30h]
__int64 v24; // [rsp+B0h] [rbp-28h]
int v25; // [rsp+B8h] [rbp-20h]

v2 = (void **)options_allocate();
if ( v2 )
{
v5.name = "help";
v5.has_arg = 0;
v5.flag = 0LL;
v5.val = 104;
v6 = "height";
v7 = 1;
v8 = 0LL;
v9 = 103;
v10 = "bottom";
v11 = 0;
v12 = 0LL;
v13 = 109;
v14 = "font";
v15 = 1;
v16 = 0LL;
v17 = 116;
v18 = "foreground";
v19 = 1;
v20 = 0LL;
v21 = 102;
v22 = "background";
v23 = 1;
v24 = 0LL;
v25 = 98;
while ( 2 )
{
v3 = getopt_long(argc, argv, "hmg:t:f:b:", &v5, 0LL);
if ( v3 != -1 )
{
switch ( v3 )
{
case 'b':
free(v2[3]);
v2[3] = strdup(optarg);
continue;
case 'f':
free(v2[2]);
v2[2] = strdup(optarg);
continue;
case 'g':
*(_WORD *)v2 = atoi(optarg);
continue;
case 'm':
*((_BYTE *)v2 + 2) = 1;
continue;
case 't':
free(v2[1]);
v2[1] = strdup(optarg);
continue;
default:
printf(
"Usage: %s pbar [-h] [-m] [-g HEIGHT] [-t FONT] [-f FOREGROUND] [-b BACKGROUND]\n"
"\t-h --help\t\t\tDisplay this help\n"
"\t-m --bottom\t\t\tPlace bar on the bottom of the screen\n"
"\t-g --height HEIGHT\t\tSet bar height to HEIGHT. Default 16\n"
"\t-t --font FONT\t\t\tSet the default font to FONT. Default Sans-Serif Bold 9\n"
"\t-f --foreground FOREGROUND\tSet the default foreground color to FOREGROUND. Default #FFFFFF\n"
"\t-b --background BACKGROUND\tSet the default background color to BACKGROUND. Default #000000\n"
"\n"
"This program displays three sets of textual information, on the left of the bar,right and center. Input mu"
"st start with the position -- 'l', 'r' or 'c'; theindex, and a non-digit separator character before the te"
"xtual information.e.g.:\n"
"\t$ %s\n"
"\tl0 my info\n"
"\tr1 info on right\n"
"\tr2 more on right\n"
"\tc0 center info\n"
"\tr2 updated info\n"
"Result: [my info][]\t\t\t\t[center info]\t\t[][info on right][updated info]\n",
*argv,
*argv);
options_destroy(v2);
v2 = 0LL;
break;
}
}
break;
}
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func2(int argc, char **argv)
{
void **v2; // rbx
int v3; // eax
struct option v5; // [rsp+0h] [rbp-D8h] BYREF
const char *v6; // [rsp+20h] [rbp-B8h]
int v7; // [rsp+28h] [rbp-B0h]
__int64 v8; // [rsp+30h] [rbp-A8h]
int v9; // [rsp+38h] [rbp-A0h]
const char *v10; // [rsp+40h] [rbp-98h]
int v11; // [rsp+48h] [rbp-90h]
__int64 v12; // [rsp+50h] [rbp-88h]
int v13; // [rsp+58h] [rbp-80h]
const char *v14; // [rsp+60h] [rbp-78h]
int v15; // [rsp+68h] [rbp-70h]
__int64 v16; // [rsp+70h] [rbp-68h]
int v17; // [rsp+78h] [rbp-60h]
const char *v18; // [rsp+80h] [rbp-58h]
int v19; // [rsp+88h] [rbp-50h]
__int64 v20; // [rsp+90h] [rbp-48h]
int v21; // [rsp+98h] [rbp-40h]
const char *v22; // [rsp+A0h] [rbp-38h]
int v23; // [rsp+A8h] [rbp-30h]
__int64 v24; // [rsp+B0h] [rbp-28h]
int v25; // [rsp+B8h] [rbp-20h]

v2 = (void **)func0();
if ( v2 )
{
v5.name = "help";
v5.has_arg = 0;
v5.flag = 0LL;
v5.val = 104;
v6 = "height";
v7 = 1;
v8 = 0LL;
v9 = 103;
v10 = "bottom";
v11 = 0;
v12 = 0LL;
v13 = 109;
v14 = "font";
v15 = 1;
v16 = 0LL;
v17 = 116;
v18 = "foreground";
v19 = 1;
v20 = 0LL;
v21 = 102;
v22 = "background";
v23 = 1;
v24 = 0LL;
v25 = 98;
while ( 2 )
{
v3 = getopt_long(argc, argv, "hmg:t:f:b:", &v5, 0LL);
if ( v3 != -1 )
{
switch ( v3 )
{
case 'b':
free(v2[3]);
v2[3] = strdup(optarg);
continue;
case 'f':
free(v2[2]);
v2[2] = strdup(optarg);
continue;
case 'g':
*(_WORD *)v2 = atoi(optarg);
continue;
case 'm':
*((_BYTE *)v2 + 2) = 1;
continue;
case 't':
free(v2[1]);
v2[1] = strdup(optarg);
continue;
default:
printf(
"Usage: %s pbar [-h] [-m] [-g HEIGHT] [-t FONT] [-f FOREGROUND] [-b BACKGROUND]\n"
"\t-h --help\t\t\tDisplay this help\n"
"\t-m --bottom\t\t\tPlace bar on the bottom of the screen\n"
"\t-g --height HEIGHT\t\tSet bar height to HEIGHT. Default 16\n"
"\t-t --font FONT\t\t\tSet the default font to FONT. Default Sans-Serif Bold 9\n"
"\t-f --foreground FOREGROUND\tSet the default foreground color to FOREGROUND. Default #FFFFFF\n"
"\t-b --background BACKGROUND\tSet the default background color to BACKGROUND. Default #000000\n"
"\n"
"This program displays three sets of textual information, on the left of the bar,right and center. Input mu"
"st start with the position -- 'l', 'r' or 'c'; theindex, and a non-digit separator character before the te"
"xtual information.e.g.:\n"
"\t$ %s\n"
"\tl0 my info\n"
"\tr1 info on right\n"
"\tr2 more on right\n"
"\tc0 center info\n"
"\tr2 updated info\n"
"Result: [my info][]\t\t\t\t[center info]\t\t[][info on right][updated info]\n",
*argv,
*argv);
func1(v2);
v2 = 0LL;
break;
}
}
break;
}
}
return v2;
}

original_code:
struct options *options_new(int argc, char **argv)
{
 struct options *options = options_allocate();
 if (options == ((void *)0))
  return ((void *)0);
 struct option long_options[] = {
  { "help", 0, 0, 'h' },
  { "height", 1, 0, 'g' },
  { "bottom", 0, 0, 'm' },
  { "font", 1, 0, 't' },
  { "foreground", 1, 0, 'f' },
  { "background", 1, 0, 'b' }
 };
 while (1) {
  int arg = getopt_long(argc, argv, "hmg:t:f:b:",
    long_options, ((void *)0));
  if (arg == -1)
   break;
  switch (arg) {
  case 'g':
   options->bar_height = atoi(optarg);
   break;
  case 'm':
   options->bar_on_bottom = 1;
   break;
  case 't':
   free(options->default_font);
   options->default_font = strdup(optarg);
   break;
  case 'f':
   free(options->default_foreground);
   options->default_foreground = strdup(optarg);
   break;
  case 'b':
   free(options->default_background);
   options->default_background = strdup(optarg);
   break;
  default:
   printf("Usage: %s pbar [-h] [-m] [-g HEIGHT] [-t FONT] [-f FOREGROUND] [-b BACKGROUND]\n\t-h --help\t\t\tDisplay this help\n\t-m --bottom\t\t\tPlace bar on the bottom of the screen\n\t-g --height HEIGHT\t\tSet bar height to HEIGHT. Default 16\n\t-t --font FONT\t\t\tSet the default font to FONT. Default Sans-Serif Bold 9\n\t-f --foreground FOREGROUND\tSet the default foreground color to FOREGROUND. Default #FFFFFF\n\t-b --background BACKGROUND\tSet the default background color to BACKGROUND. Default #000000\n\nThis program displays three sets of textual information, on the left of the bar,right and center. Input must start with the position -- 'l', 'r' or 'c'; theindex, and a non-digit separator character before the textual information.e.g.:\n\t$ %s\n\tl0 my info\n\tr1 info on right\n\tr2 more on right\n\tc0 center info\n\tr2 updated info\nResult: [my info][]				[center info]		[][info on right][updated info]\n", argv[0], argv[0]);
   options_destroy(options);
   return ((void *)0);
  }
 }
 return options;
}

variable_types:
argv
char **

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: arg int

return_type: struct options { unsigned short bar_height; _Bool bar_on_bottom; char *default_font; char *default_foreground; char *default_background; } *


strdup

decompiled_code:
char *__fastcall strdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)calloc(v1, 1uLL);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)calloc(v1, 1uLL);
return strcpy(v2, src);
}

original_code:
char *strdup(const char *arg)
{
 char *buffer = calloc(strlen(arg), sizeof(char));
 strcpy(buffer, arg);
 return buffer;
}

canonical_original_code:
char *strdup(char *arg)
{
 char *buffer = calloc(strlen(arg), sizeof(char));
 strcpy(buffer, arg);
 return buffer;
}

variable_types:
arg
char *

variable_types:
buffer
char *


original_code:
void parse_color(const char *string, double output[3])
{
 char r[2] = { string[1], string[2] };
 char g[2] = { string[3], string[4] };
 char b[2] = { string[5], string[6] };
 unsigned a[3];
 sscanf(r, "%02x", a);
 sscanf(g, "%02x", a+1);
 sscanf(b, "%02x", a+2);
 output[0] = a[0] / 255.0;
 output[1] = a[1] / 255.0;
 output[2] = a[2] / 255.0;
}

canonical_original_code:
void parse_color(char *string, double output[3])
{
 char r[2] = { string[1], string[2] };
 char g[2] = { string[3], string[4] };
 char b[2] = { string[5], string[6] };
 unsigned int a[3];
 sscanf(r, "%02x", a);
 sscanf(g, "%02x", a+1);
 sscanf(b, "%02x", a+2);
 output[0] = a[0] / 255.0;
 output[1] = a[1] / 255.0;
 output[2] = a[2] / 255.0;
}

variable_types:
string
char *

variable_types:
output
double [3]

variable_types:
r
char [2]

variable_types:
g
char [2]

variable_types:
b
char [2]

variable_types:
a
unsigned int [3]


decompiled_code:
xcb_generic_event_t *window_event_wait()
{
xcb_generic_event_t *result; // rax

while ( 1 )
{
result = xcb_poll_for_event(window);
if ( !result )
break;
if ( (result->response_type & 0x7F) == 12 && !LOWORD(result->pad[3]) )
((void (*)(void))*(&window + 4))();
}
return result;
}

canonical_decompiled_code:
xcb_generic_event_t *func2()
{
xcb_generic_event_t *result; // rax

while ( 1 )
{
result = xcb_poll_for_event(window);
if ( !result )
break;
if ( (result->response_type & 0x7F) == 12 && !LOWORD(result->pad[3]) )
((void (*)(void))*(&window + 4))();
}
return result;
}

original_code:
void window_event_wait()
{
 xcb_generic_event_t *xcb_event;
 xcb_expose_event_t *xcb_expose_event;
 while ((xcb_event = xcb_poll_for_event(window.xcb_connection))) {
  xcb_expose_event = (xcb_expose_event_t *)xcb_event;
  switch (xcb_event->response_type & 0x7F) {
  case 12:
   if (xcb_expose_event->count == 0)
    window.redraw();
  }
 }
}

canonical_original_code:
void window_event_wait()
{
 struct xcb_generic_event_t *xcb_event;
 struct xcb_expose_event_t *xcb_expose_event;
 while ((xcb_event = xcb_poll_for_event(window.xcb_connection))) {
  xcb_expose_event = (struct xcb_expose_event_t *)xcb_event;
  switch (xcb_event->response_type & 0x7F) {
  case 12:
   if (xcb_expose_event->count == 0)
    window.redraw();
  }
 }
}

variable_types: struct xcb_generic_event_t { unsigned char response_type; unsigned char pad0; unsigned short sequence; unsigned int pad[7]; unsigned int full_sequence; } *

variable_types: struct xcb_expose_event_t { unsigned char response_type; unsigned char pad0; unsigned short sequence; unsigned int window; unsigned short x; unsigned short y; unsigned short width; unsigned short height; unsigned short count; unsigned char pad1[2]; } *


decompiled_code:
int window_flush()
{
return xcb_flush(window);
}

canonical_decompiled_code:
int func3()
{
return xcb_flush(window);
}

original_code:
void window_flush()
{
 xcb_flush(window.xcb_connection);
}


decompiled_code:
void window_terminate()
{
xcb_destroy_window(window, *((_DWORD *)&window + 4));
xcb_disconnect(window);
}

canonical_decompiled_code:
void func4()
{
xcb_destroy_window(window, *((_DWORD *)&window + 4));
xcb_disconnect(window);
}

original_code:
void window_terminate()
{
 xcb_destroy_window(window.xcb_connection, window.xcb_window);
 xcb_disconnect(window.xcb_connection);
}


repo: rlk/electro

original_code:
static void transform_rotation(float R[16], float r[3], int id)
{
    float axis[3][3] = {
        { 0, 1, 0 },
        { 1, 0, 0 },
        { 0, 0, 1 },
    };
    int a0 = transform[id].a[0];
    int a1 = transform[id].a[1];
    int a2 = transform[id].a[2];
    load_rot_mat(R, axis[a0][0], axis[a0][1], axis[a0][2], r[a0]);
    mult_rot_mat(R, axis[a1][0], axis[a1][1], axis[a1][2], r[a1]);
    mult_rot_mat(R, axis[a2][0], axis[a2][1], axis[a2][2], r[a2]);
    mult_mat_mat(R, transform[id].M, R);
}

variable_types:
R
float [16]

variable_types:
r
float [3]

variable_types: id int

variable_types:
axis
float [3][3]


decompiled_code:
__int64 __fastcall transform_position(float *a1, int *a2, int a3)
{
__int64 result; // rax
float v4; // xmm1_4
int v5[4]; // [rsp+0h] [rbp-28h] BYREF
int v6[3]; // [rsp+10h] [rbp-18h] BYREF
float v7; // [rsp+1Ch] [rbp-Ch]

v5[0] = *a2;
v5[1] = a2[1];
v5[2] = a2[2];
v5[3] = 1065353216;
result = mult_mat_vec(v6, (char *)transform + 140 * a3, v5);
v4 = v7;
*a1 = *(float *)v6 / v7;
a1[1] = *(float *)&v6[1] / v4;
a1[2] = *(float *)&v6[2] / v4;
return result;
}

variable_types:
P
float [3]

variable_types:
p
float [3]

variable_types:
t
float [4]

variable_types:
q
float [4]


decompiled_code:
const __m128i *__fastcall set_tracker_transform(int a1, const __m128i *a2, __int64 a3)
{
const __m128i *result; // rax
__m128i *v4; // rsi

result = a2;
if ( transform )
{
if ( a1 < transforms )
{
v4 = (__m128i *)((char *)transform + 140 * (unsigned int)a1);
*v4 = _mm_loadu_si128(result);
v4[1] = _mm_loadu_si128(result + 1);
v4[2] = _mm_loadu_si128(result + 2);
v4[3] = _mm_loadu_si128(result + 3);
v4[8].m128i_i64[0] = *(_QWORD *)a3;
v4[8].m128i_i32[2] = *(_DWORD *)(a3 + 8);
result = (const __m128i *)load_inv(&v4[4]);
}
}
return result;
}

canonical_decompiled_code:
const __m128i *__fastcall func4(int a1, const __m128i *a2, __int64 a3)
{
const __m128i *result; // rax
__m128i *v4; // rsi

result = a2;
if ( transform )
{
if ( a1 < transforms )
{
v4 = (__m128i *)((char *)transform + 140 * (unsigned int)a1);
*v4 = _mm_loadu_si128(result);
v4[1] = _mm_loadu_si128(result + 1);
v4[2] = _mm_loadu_si128(result + 2);
v4[3] = _mm_loadu_si128(result + 3);
v4[8].m128i_i64[0] = *(_QWORD *)a3;
v4[8].m128i_i32[2] = *(_DWORD *)(a3 + 8);
result = (const __m128i *)load_inv(&v4[4]);
}
}
return result;
}

original_code:
void set_tracker_transform(unsigned int id, float M[16], int a[3])
{
    if (transform && (int) id < transforms)
    {
        memcpy(transform[id].M, M, 16 * sizeof (float));
        memcpy(transform[id].a, a, 3 * sizeof (int));
        load_inv(transform[id].I, transform[id].M);
    }
}

variable_types:
id
unsigned int

variable_types:
M
float [16]

variable_types:
a
int [3]


decompiled_code:
void *__fastcall get_tracker_transform(int a1, __m128i *a2, __int64 a3)
{
void *result; // rax
const __m128i *v4; // rdi

result = transform;
if ( transform )
{
if ( a1 < transforms )
{
v4 = (const __m128i *)((char *)transform + 140 * (unsigned int)a1);
*a2 = _mm_loadu_si128(v4);
a2[1] = _mm_loadu_si128(v4 + 1);
a2[2] = _mm_loadu_si128(v4 + 2);
a2[3] = _mm_loadu_si128(v4 + 3);
*(_QWORD *)a3 = v4[8].m128i_i64[0];
result = (void *)v4[8].m128i_u32[2];
*(_DWORD *)(a3 + 8) = (_DWORD)result;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(int a1, __m128i *a2, __int64 a3)
{
void *result; // rax
const __m128i *v4; // rdi

result = transform;
if ( transform )
{
if ( a1 < transforms )
{
v4 = (const __m128i *)((char *)transform + 140 * (unsigned int)a1);
*a2 = _mm_loadu_si128(v4);
a2[1] = _mm_loadu_si128(v4 + 1);
a2[2] = _mm_loadu_si128(v4 + 2);
a2[3] = _mm_loadu_si128(v4 + 3);
*(_QWORD *)a3 = v4[8].m128i_i64[0];
result = (void *)v4[8].m128i_u32[2];
*(_DWORD *)(a3 + 8) = (_DWORD)result;
}
}
return result;
}

original_code:
void get_tracker_transform(unsigned int id, float M[16], int a[3])
{
    if (transform && (int) id < transforms)
    {
        memcpy(M, transform[id].M, 16 * sizeof (float));
        memcpy(a, transform[id].a, 3 * sizeof (int));
    }
}


decompiled_code:
__int64 __fastcall acquire_tracker(key_t a1, key_t a2, int a3)
{
int v4; // eax
int v5; // eax
int v7; // ebp
const char *v8; // rax
int v9; // eax
const char *v10; // rdx
struct sockaddr v11; // [rsp+0h] [rbp-28h] BYREF

v4 = shmget(a1, 0x1CuLL, 0);
if ( v4 >= 0 )
tracker = shmat(v4, 0LL, 0);
v5 = shmget(a2, 0x20uLL, 0);
if ( v5 >= 0 )
control = shmat(v5, 0LL, 0);
if ( control != (void *)-1LL )
buttons = calloc(*((unsigned int *)control + 3), 4uLL);
if ( a3 )
{
v7 = socket(2, 2, 0);
sock = v7;
if ( v7 < 0 )
{
v9 = ((__int64 (*)(void))system_error)();
error((int)"socket : %s", v9, v10);
}
else
{
v11.sa_family = 2;
*(_WORD *)v11.sa_data = _bswap_16(a3);
*(_DWORD *)&v11.sa_data[2] = _bswap_32(0);
if ( bind(v7, &v11, 0x10u) < 0 )
{
v8 = (const char *)system_error((unsigned int)v7);
error((int)"bind %d : %s", a3, v8);
}
else
{
transforms = 1;
}
}
}
if ( tracker != (void *)-1LL )
new_tracker_transforms(*((_DWORD *)tracker + 1));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(key_t a1, key_t a2, int a3)
{
int v4; // eax
int v5; // eax
int v7; // ebp
const char *v8; // rax
int v9; // eax
const char *v10; // rdx
struct sockaddr v11; // [rsp+0h] [rbp-28h] BYREF

v4 = shmget(a1, 0x1CuLL, 0);
if ( v4 >= 0 )
tracker = shmat(v4, 0LL, 0);
v5 = shmget(a2, 0x20uLL, 0);
if ( v5 >= 0 )
control = shmat(v5, 0LL, 0);
if ( control != (void *)-1LL )
buttons = calloc(*((unsigned int *)control + 3), 4uLL);
if ( a3 )
{
v7 = socket(2, 2, 0);
sock = v7;
if ( v7 < 0 )
{
v9 = ((__int64 (*)(void))system_error)();
error((int)"socket : %s", v9, v10);
}
else
{
v11.sa_family = 2;
*(_WORD *)v11.sa_data = func0(a3);
*(_DWORD *)&v11.sa_data[2] = func1(0);
if ( bind(v7, &v11, 0x10u) < 0 )
{
v8 = (const char *)system_error((unsigned int)v7);
error((int)"bind %d : %s", a3, v8);
}
else
{
transforms = 1;
}
}
}
if ( tracker != (void *)-1LL )
new_tracker_transforms(*((_DWORD *)tracker + 1));
return 1LL;
}

original_code:
int acquire_tracker(int t_key, int c_key, int port)
{
    if ((tracker_id = shmget(t_key, sizeof (struct tracker_header), 0)) >= 0)
        tracker = (struct tracker_header *) shmat(tracker_id, 0, 0);
    if ((control_id = shmget(c_key, sizeof (struct control_header), 0)) >= 0)
        control = (struct control_header *) shmat(control_id, 0, 0);
    if (control != (struct control_header *) (-1))
        buttons = (uint32_t *) calloc(control->but_count, sizeof (uint32_t));
    if (port)
    {
        if ((sock = socket(2, SOCK_DGRAM, 0)) >= 0)
        {
            sockaddr_t addr;
            addr.sin_family = 2;
            addr.sin_port = htons((short) port);
            addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
            if (bind(sock, (struct sockaddr *) &addr, sizeof (sockaddr_t))>= 0)
            {
                transforms = 1;
            }
            else error("bind %d : %s", port, system_error());
        }
        else error("socket : %s", system_error());
    }
    if (tracker != (struct tracker_header *) (-1))
        new_tracker_transforms((int) tracker->count);
    return 1;
}

canonical_original_code:
int acquire_tracker(int t_key, int c_key, int port)
{
    if ((tracker_id = shmget(t_key, sizeof (struct tracker_header), 0)) >= 0)
        tracker = (struct tracker_header *) shmat(tracker_id, 0, 0);
    if ((control_id = shmget(c_key, sizeof (struct control_header), 0)) >= 0)
        control = (struct control_header *) shmat(control_id, 0, 0);
    if (control != (struct control_header *) (-1))
        buttons = (unsigned int *) calloc(control->but_count, sizeof (unsigned int));
    if (port)
    {
        if ((sock = socket(2, SOCK_DGRAM, 0)) >= 0)
        {
            struct sockaddr_in addr;
            addr.sin_family = 2;
            addr.sin_port = htons((short) port);
            addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
            if (bind(sock, (struct sockaddr *) &addr, sizeof (sockaddr_t))>= 0)
            {
                transforms = 1;
            }
            else error("bind %d : %s", port, system_error());
        }
        else error("socket : %s", system_error());
    }
    if (tracker != (struct tracker_header *) (-1))
        new_tracker_transforms((int) tracker->count);
    return 1;
}

variable_types: port int

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

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 tracker_header { unsigned int version; unsigned int count; unsigned int offset; unsigned int size; unsigned int time[2]; unsigned int command; }

user_defined_types: struct control_header { unsigned int version; unsigned int but_offset; unsigned int val_offset; unsigned int but_count; unsigned int val_count; unsigned int time[2]; unsigned int command; }

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


decompiled_code:
void release_tracker()
{
if ( control != (void *)-1LL )
shmdt(control);
if ( tracker != (void *)-1LL )
shmdt(tracker);
if ( sock != -1 )
close(sock);
if ( buttons )
free(buttons);
if ( transform )
free(transform);
sock = -1;
control = (void *)-1LL;
tracker = (void *)-1LL;
buttons = 0LL;
transform = 0LL;
transforms = 0;
}

canonical_decompiled_code:
void func7()
{
if ( control != (void *)-1LL )
shmdt(control);
if ( tracker != (void *)-1LL )
shmdt(tracker);
if ( sock != -1 )
close(sock);
if ( buttons )
free(buttons);
if ( transform )
free(transform);
sock = -1;
control = (void *)-1LL;
tracker = (void *)-1LL;
buttons = 0LL;
transform = 0LL;
transforms = 0;
}

original_code:
void release_tracker(void)
{
    if (control != (struct control_header *) (-1)) shmdt(control);
    if (tracker != (struct tracker_header *) (-1)) shmdt(tracker);
    control_id = -1;
    tracker_id = -1;
    if (sock != -1) close(sock);
    if (buttons) free(buttons);
    if (transform) free(transform);
    sock = -1;
    control = (struct control_header *) (-1);
    tracker = (struct tracker_header *) (-1);
    buttons = ((void *)0);
    transform = ((void *)0);
    transforms = 0;
}

canonical_original_code:
void release_tracker()
{
    if (control != (struct control_header *) (-1)) shmdt(control);
    if (tracker != (struct tracker_header *) (-1)) shmdt(tracker);
    control_id = -1;
    tracker_id = -1;
    if (sock != -1) close(sock);
    if (buttons) free(buttons);
    if (transform) free(transform);
    sock = -1;
    control = (struct control_header *) (-1);
    tracker = (struct tracker_header *) (-1);
    buttons = ((void *)0);
    transform = ((void *)0);
    transforms = 0;
}


decompiled_code:
_BOOL8 get_tracker_status()
{
_BOOL8 result; // rax

result = 1LL;
if ( sock == -1 )
result = (char *)tracker + 1 != 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 func8()
{
_BOOL8 result; // rax

result = 1LL;
if ( sock == -1 )
result = (char *)tracker + 1 != 0LL;
return result;
}

original_code:
int get_tracker_status(void)
{
    return ((sock != -1) ||
            (tracker != (struct tracker_header *) (-1)));
}

canonical_original_code:
int get_tracker_status()
{
    return ((sock != -1) ||
            (tracker != (struct tracker_header *) (-1)));
}


decompiled_code:
__int64 __fastcall get_tracker_sensor(unsigned int a1, float *a2, __m128i *a3)
{
int v4; // ebp
int *v5; // rbp
__int64 result; // rax
unsigned int v7; // er13
float v8; // [rsp+4h] [rbp-E4h] BYREF
float v9; // [rsp+8h] [rbp-E0h]
float v10; // [rsp+Ch] [rbp-DCh]
struct timeval timeout; // [rsp+10h] [rbp-D8h] BYREF
int buf[8]; // [rsp+20h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+40h] [rbp-A8h] BYREF

if ( tracker == (void *)-1LL || *((_DWORD *)tracker + 1) <= a1 )
{
if ( a1 || sock == -1 )
goto LABEL_15;
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[sock / 64] |= 1LL << (sock % 64);
v4 = 0;
while ( select(sock + 1, &readfds, 0LL, 0LL, &timeout) > 0 )
{
if ( (readfds.fds_bits[sock / 64] & (1LL << (sock % 64))) != 0 )
{
v7 = recv(sock, buf, 0x18uLL, 0);
if ( v7 > 0xB )
{
v8 = *(float *)buf;
v9 = *(float *)&buf[1];
LODWORD(v10) = buf[2] ^ LC4;
transform_position(a2, (int *)&v8, 0);
v9 = v9 + 3.0;
printf("%+8.3f %+8.3f %+8.3f ", v8, v9, v10);
printf("%+8.3f %+8.3f %+8.3f\n", *a2, a2[1], a2[2]);
last_p_1 = *(_QWORD *)a2;
dword_948 = *((_DWORD *)a2 + 2);
}
if ( v7 > 0x17 )
{
load_idt(a3);
last_R_0 = (__int128)_mm_loadu_si128(a3);
xmmword_910 = (__int128)_mm_loadu_si128(a3 + 1);
xmmword_920 = (__int128)_mm_loadu_si128(a3 + 2);
xmmword_930 = (__int128)_mm_loadu_si128(a3 + 3);
}
}
++v4;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[sock / 64] |= 1LL << (sock % 64);
}
result = 1LL;
if ( !v4 )
{
LABEL_15:
*(_QWORD *)a2 = last_p_1;
*((_DWORD *)a2 + 2) = dword_948;
*a3 = _mm_load_si128((const __m128i *)&last_R_0);
a3[1] = _mm_load_si128((const __m128i *)&xmmword_910);
a3[2] = _mm_load_si128((const __m128i *)&xmmword_920);
a3[3] = _mm_load_si128((const __m128i *)&xmmword_930);
result = 0LL;
}
}
else
{
v5 = (int *)((char *)tracker + *((unsigned int *)tracker + 2) + (unsigned __int64)(*((_DWORD *)tracker + 3) * a1));
transform_rotation((__int64)a3, (__int64)(v5 + 3), a1);
transform_position(a2, v5, a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, float *a2, __m128i *a3)
{
int v4; // ebp
int *v5; // rbp
__int64 result; // rax
unsigned int v7; // er13
float v8; // [rsp+4h] [rbp-E4h] BYREF
float v9; // [rsp+8h] [rbp-E0h]
float v10; // [rsp+Ch] [rbp-DCh]
struct timeval timeout; // [rsp+10h] [rbp-D8h] BYREF
int buf[8]; // [rsp+20h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+40h] [rbp-A8h] BYREF

if ( tracker == (void *)-1LL || *((_DWORD *)tracker + 1) <= a1 )
{
if ( a1 || sock == -1 )
goto LABEL_15;
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[sock / 64] |= 1LL << (sock % 64);
v4 = 0;
while ( select(sock + 1, &readfds, 0LL, 0LL, &timeout) > 0 )
{
if ( (readfds.fds_bits[sock / 64] & (1LL << (sock % 64))) != 0 )
{
v7 = recv(sock, buf, 0x18uLL, 0);
if ( v7 > 0xB )
{
v8 = *(float *)buf;
v9 = *(float *)&buf[1];
LODWORD(v10) = buf[2] ^ LC4;
func3(a2, (int *)&v8, 0);
v9 = v9 + 3.0;
printf("%+8.3f %+8.3f %+8.3f ", v8, v9, v10);
printf("%+8.3f %+8.3f %+8.3f\n", *a2, a2[1], a2[2]);
last_p_1 = *(_QWORD *)a2;
dword_948 = *((_DWORD *)a2 + 2);
}
if ( v7 > 0x17 )
{
load_idt(a3);
last_R_0 = (__int128)_mm_loadu_si128(a3);
xmmword_910 = (__int128)_mm_loadu_si128(a3 + 1);
xmmword_920 = (__int128)_mm_loadu_si128(a3 + 2);
xmmword_930 = (__int128)_mm_loadu_si128(a3 + 3);
}
}
++v4;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[sock / 64] |= 1LL << (sock % 64);
}
result = 1LL;
if ( !v4 )
{
LABEL_15:
*(_QWORD *)a2 = last_p_1;
*((_DWORD *)a2 + 2) = dword_948;
*a3 = _mm_load_si128((const __m128i *)&last_R_0);
a3[1] = _mm_load_si128((const __m128i *)&xmmword_910);
a3[2] = _mm_load_si128((const __m128i *)&xmmword_920);
a3[3] = _mm_load_si128((const __m128i *)&xmmword_930);
result = 0LL;
}
}
else
{
v5 = (int *)((char *)tracker + *((unsigned int *)tracker + 2) + (unsigned __int64)(*((_DWORD *)tracker + 3) * a1));
func2((__int64)a3, (__int64)(v5 + 3), a1);
func3(a2, v5, a1);
result = 1LL;
}
return result;
}

original_code:
int get_tracker_sensor(unsigned int id, float p[3], float R[16])
{
    static float last_p[ 3];
    static float last_R[16];
    if (tracker != (struct tracker_header *) (-1))
    {
        if (id < tracker->count)
        {
            struct sensor *S =
                (struct sensor *)((unsigned char *) tracker
                                                  + tracker->offset
                                                  + tracker->size * id);
            transform_rotation(R, S->r, id);
            transform_position(p, S->p, id);
            return 1;
        }
    }
    if (id == 0 && sock != -1)
    {
        struct message mesg;
        struct timeval zero = { 0, 0 };
        int count = 0;
        fd_set fds;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
        while (select(sock + 1, &fds, ((void *)0), ((void *)0), &zero) > 0)
        {
            if (((((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            {
                int s = recv(sock, (void *) &mesg, sizeof (struct message), 0);
                if ((s >= 3 * sizeof (float)))
                {
                    float q[3];
                    q[0] = mesg.x;
                    q[1] = mesg.y;
                    q[2] = -mesg.z;
                    transform_position(p, q, id);
                    q[1] += 3.0;
                    printf("%+8.3f %+8.3f %+8.3f  ", q[0], q[1], q[2]);
                    printf("%+8.3f %+8.3f %+8.3f\n", p[0], p[1], p[2]);
                    memcpy(last_p, p, 3 * sizeof (float));
                }
                if ((s >= 6 * sizeof (float)))
                {
                    load_idt(R);
                    memcpy(last_R, R, 16 * sizeof (float));
                }
            }
            count++;
            do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
            ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
        }
        if (count) return 1;
    }
    memcpy(p, last_p, 3 * sizeof (float));
    memcpy(R, last_R, 16 * sizeof (float));
    return 0;
}

canonical_original_code:
int get_tracker_sensor(unsigned int id, float p[3], float R[16])
{
    static float last_p[3];
    static float last_R[16];
    if (tracker != (struct tracker_header *) (-1))
    {
        if (id < tracker->count)
        {
            struct sensor *S = (struct sensor *)((unsigned char *) tracker
                                                  + tracker->offset
                                                  + tracker->size * id);
            transform_rotation(R, S->r, id);
            transform_position(p, S->p, id);
            return 1;
        }
    }
    if (id == 0 && sock != -1)
    {
        struct message mesg;
        struct timeval zero = { 0, 0 };
        int count = 0;
        struct fd_set fds;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
        while (select(sock + 1, &fds, ((void *)0), ((void *)0), &zero) > 0)
        {
            if (((((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            {
                int s = recv(sock, (void *) &mesg, sizeof (struct message), 0);
                if ((s >= 3 * sizeof (float)))
                {
                    float q[3];
                    q[0] = mesg.x;
                    q[1] = mesg.y;
                    q[2] = -mesg.z;
                    transform_position(p, q, id);
                    q[1] += 3.0;
                    printf("%+8.3f %+8.3f %+8.3f  ", q[0], q[1], q[2]);
                    printf("%+8.3f %+8.3f %+8.3f\n", p[0], p[1], p[2]);
                    memcpy(last_p, p, 3 * sizeof (float));
                }
                if ((s >= 6 * sizeof (float)))
                {
                    load_idt(R);
                    memcpy(last_R, R, 16 * sizeof (float));
                }
            }
            count++;
            do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
            ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
        }
        if (count) return 1;
    }
    memcpy(p, last_p, 3 * sizeof (float));
    memcpy(R, last_R, 16 * sizeof (float));
    return 0;
}

variable_types: struct sensor { float p[3]; float r[3]; unsigned int t[2]; unsigned int calib; unsigned int frame; } *

variable_types: struct message { float x; float y; float z; float rx; float ry; float rz; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: count int

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

variable_types: s int

variable_types:
q
float [3]


decompiled_code:
__int64 __fastcall get_tracker_joystick(unsigned int a1, _DWORD *a2)
{
unsigned int v2; // edx
char *v4; // rax

v2 = 0;
if ( control != (void *)-1LL && *((_DWORD *)control + 4) - 1 > a1 )
{
v4 = (char *)control + *((unsigned int *)control + 2);
*a2 = *(_DWORD *)&v4[4 * a1];
a2[1] = *(_DWORD *)&v4[4 * a1 + 4] ^ LC4;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, _DWORD *a2)
{
unsigned int v2; // edx
char *v4; // rax

v2 = 0;
if ( control != (void *)-1LL && *((_DWORD *)control + 4) - 1 > a1 )
{
v4 = (char *)control + *((unsigned int *)control + 2);
*a2 = *(_DWORD *)&v4[4 * a1];
a2[1] = *(_DWORD *)&v4[4 * a1 + 4] ^ LC4;
v2 = 1;
}
return v2;
}

original_code:
int get_tracker_joystick(unsigned int id, float a[2])
{
    if (control != (struct control_header *) (-1))
    {
        float *p = (float *) ((unsigned char *) control + control->val_offset);
        if (id < control->val_count - 1)
        {
            a[0] = +(*(p + id + 0));
            a[1] = -(*(p + id + 1));
            return 1;
        }
    }
    return 0;
}

variable_types:
a
float [2]

variable_types:
p
float *


decompiled_code:
__int64 __fastcall get_tracker_buttons(_DWORD *a1, _DWORD *a2)
{
_DWORD *v3; // rax
unsigned int v4; // edx
_DWORD *v5; // rdx
int v6; // edi
int v7; // ecx

v3 = buttons;
v4 = 0;
if ( buttons && control != (void *)-1LL )
{
v5 = (char *)control + *((unsigned int *)control + 1);
v6 = *((_DWORD *)control + 3);
if ( v6 )
{
v7 = 0;
while ( *v3 == *v5 )
{
++v7;
++v5;
++v3;
if ( v7 == v6 )
return 0;
}
*v3 = *v5;
*a1 = v7 + 1;
*a2 = *v5;
v4 = 1;
}
else
{
v4 = 0;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, _DWORD *a2)
{
_DWORD *v3; // rax
unsigned int v4; // edx
_DWORD *v5; // rdx
int v6; // edi
int v7; // ecx

v3 = buttons;
v4 = 0;
if ( buttons && control != (void *)-1LL )
{
v5 = (char *)control + *((unsigned int *)control + 1);
v6 = *((_DWORD *)control + 3);
if ( v6 )
{
v7 = 0;
while ( *v3 == *v5 )
{
++v7;
++v5;
++v3;
if ( v7 == v6 )
return 0;
}
*v3 = *v5;
*a1 = v7 + 1;
*a2 = *v5;
v4 = 1;
}
else
{
v4 = 0;
}
}
return v4;
}

original_code:
int get_tracker_buttons(unsigned int *id, unsigned int *st)
{
    uint32_t i;
    uint32_t *p;
    if (buttons && control != (struct control_header *) (-1))
    {
        p = (uint32_t *) ((unsigned char *) control + control->but_offset);
        for (i = 0; i < control->but_count; ++i, ++p)
            if (buttons[i] != *p)
            {
                buttons[i] = *p;
                *id = i + 1;
                *st = *p;
                return 1;
            }
    }
    return 0;
}

canonical_original_code:
int get_tracker_buttons(unsigned int *id, unsigned int *st)
{
    unsigned int i;
    unsigned int *p;
    if (buttons && control != (struct control_header *) (-1))
    {
        p = (unsigned int *) ((unsigned char *) control + control->but_offset);
        for (i = 0; i < control->but_count; ++i, ++p)
            if (buttons[i] != *p)
            {
                buttons[i] = *p;
                *id = i + 1;
                *st = *p;
                return 1;
            }
    }
    return 0;
}

variable_types:
id
unsigned int *

variable_types:
st
unsigned int *

variable_types:
i
unsigned int

variable_types:
p
unsigned int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
server(argc, argv, envp);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    server(argc, argv);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void *__fastcall recv_data(void *a1, size_t a2)
{
return memset(a1, 0, a2);
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, size_t a2)
{
return memset(a1, 0, a2);
}

original_code:
static void recv_data(void *buf, size_t len)
{
    memset(buf, 0, len);
}

canonical_original_code:
static void recv_data(void *buf, unsigned long len)
{
    memset(buf, 0, len);
}

variable_types:
buf
void *

variable_types:
len
unsigned long


decompiled_code:
__int64 startup_buffer()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
int startup_buffer(void)
{
    return 1;
}

canonical_original_code:
int startup_buffer()
{
    return 1;
}


decompiled_code:
void sync_buffer()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void sync_buffer(void)
{
}

canonical_original_code:
void sync_buffer()
{
}


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

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

original_code:
int get_rank(void)
{
    return 0;
}

canonical_original_code:
int get_rank()
{
    return 0;
}


decompiled_code:
void send_array()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void send_array(const void *p, size_t n, size_t s)
{
    send_data(p, n * s);
}

canonical_original_code:
void send_array(void *p, unsigned long n, unsigned long s)
{
    send_data(p, n * s);
}

variable_types:
p
void *

variable_types:
n
unsigned long

variable_types:
s
unsigned long


decompiled_code:
void send_value()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void send_value(int i)
{
    send_data(&i, sizeof (int));
}

variable_types: i int


decompiled_code:
void send_event()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void send_event(char c)
{
    send_data(&c, sizeof (char));
}

variable_types: c char


decompiled_code:
void send_float()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void send_float(float f)
{
    send_data(&f, sizeof (float));
}

variable_types: f float


decompiled_code:
void send_index()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void send_index(unsigned int i)
{
    send_data(&i, sizeof (unsigned int));
}


decompiled_code:
void *__fastcall recv_array(void *a1, __int64 a2, __int64 a3)
{
return recv_data(a1, a3 * a2);
}

canonical_decompiled_code:
void *__fastcall func9(void *a1, __int64 a2, __int64 a3)
{
return func0(a1, a3 * a2);
}

original_code:
void recv_array(void *p, size_t n, size_t s)
{
    recv_data(p, n * s);
}

canonical_original_code:
void recv_array(void *p, unsigned long n, unsigned long s)
{
    recv_data(p, n * s);
}


decompiled_code:
__int64 recv_value()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

recv_data(v1, 4uLL);
return v1[0];
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

func0(v1, 4uLL);
return v1[0];
}

original_code:
int recv_value(void)
{
    int i;
    recv_data(&i, sizeof (int));
    return i;
}

canonical_original_code:
int recv_value()
{
    int i;
    recv_data(&i, sizeof (int));
    return i;
}


decompiled_code:
__int64 recv_event()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

recv_data(v1, 1uLL);
return (unsigned __int8)v1[0];
}

canonical_decompiled_code:
__int64 func11()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

func0(v1, 1uLL);
return (unsigned __int8)v1[0];
}

original_code:
char recv_event(void)
{
    char c;
    recv_data(&c, sizeof (char));
    return c;
}

canonical_original_code:
char recv_event()
{
    char c;
    recv_data(&c, sizeof (char));
    return c;
}


decompiled_code:
float recv_float()
{
float v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

recv_data(v1, 4uLL);
return v1[0];
}

canonical_decompiled_code:
float func12()
{
float v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

func0(v1, 4uLL);
return v1[0];
}

original_code:
float recv_float(void)
{
    float f;
    recv_data(&f, sizeof (float));
    return f;
}

canonical_original_code:
float recv_float()
{
    float f;
    recv_data(&f, sizeof (float));
    return f;
}

return_type: float


decompiled_code:
__int64 recv_index()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

recv_data(v1, 4uLL);
return v1[0];
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

func0(v1, 4uLL);
return v1[0];
}

original_code:
unsigned int recv_index(void)
{
    unsigned int i;
    recv_data(&i, sizeof (unsigned int));
    return i;
}

canonical_original_code:
unsigned int recv_index()
{
    unsigned int i;
    recv_data(&i, sizeof (unsigned int));
    return i;
}


decompiled_code:
void send_vector()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void send_vector(vector_t V)
{
    send_index(((V)->num));
    send_index(((V)->siz));
    send_array(((V)->buf), ((V)->num), ((V)->siz));
}

canonical_original_code:
void send_vector(struct vector *V)
{
    send_index(((V)->num));
    send_index(((V)->siz));
    send_array(((V)->buf), ((V)->num), ((V)->siz));
}

variable_types: struct vector { int num; int max; int siz; void *buf; } *


decompiled_code:
__int64 recv_vector()
{
unsigned int v0; // ebx
__int64 v1; // rbp
__int64 v2; // r12

v0 = recv_index();
v1 = (unsigned int)recv_index();
v2 = vecnew(v0, v1);
*(_DWORD *)v2 = v0;
recv_array(*(void **)(v2 + 16), (int)v0, (int)v1);
return v2;
}

canonical_decompiled_code:
__int64 func15()
{
unsigned int v0; // ebx
__int64 v1; // rbp
__int64 v2; // r12

v0 = func13();
v1 = (unsigned int)func13();
v2 = vecnew(v0, v1);
*(_DWORD *)v2 = v0;
func9(*(void **)(v2 + 16), (int)v0, (int)v1);
return v2;
}

original_code:
vector_t recv_vector(void)
{
    vector_t V;
    int num = recv_index();
    int siz = recv_index();
    V = vecnew(num, siz);
    V->num = num;
    recv_array(((V)->buf), num, siz);
    return V;
}

canonical_original_code:
struct vector *recv_vector()
{
    struct vector *V;
    int num = recv_index();
    int siz = recv_index();
    V = vecnew(num, siz);
    V->num = num;
    recv_array(((V)->buf), num, siz);
    return V;
}

variable_types: num int

variable_types: siz int

return_type: struct vector { int num; int max; int siz; void *buf; } *


decompiled_code:
__int64 __fastcall host_to_net(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 v2; // dl
unsigned __int8 v3; // cl

result = *a1;
v2 = a1[1];
v3 = a1[2];
*a1 = a1[3];
a1[1] = v3;
a1[2] = v2;
a1[3] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 v2; // dl
unsigned __int8 v3; // cl

result = *a1;
v2 = a1[1];
v3 = a1[2];
*a1 = a1[3];
a1[1] = v3;
a1[2] = v2;
a1[3] = result;
return result;
}

original_code:
static void host_to_net(union swapper *s)
{
    union swapper t = *s;
    s->b[0] = t.b[swapmap[0]];
    s->b[1] = t.b[swapmap[1]];
    s->b[2] = t.b[swapmap[2]];
    s->b[3] = t.b[swapmap[3]];
}

variable_types: union swapper { float f; int d; unsigned char b[4]; } *


decompiled_code:
__int64 __fastcall net_to_host(_BYTE *a1)
{
char v1; // cl
char v2; // dl
__int64 result; // rax

v1 = a1[1];
v2 = a1[2];
result = (unsigned __int8)a1[3];
a1[3] = *a1;
a1[2] = v1;
a1[1] = v2;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char v1; // cl
char v2; // dl
__int64 result; // rax

v1 = a1[1];
v2 = a1[2];
result = (unsigned __int8)a1[3];
a1[3] = *a1;
a1[2] = v1;
a1[1] = v2;
*a1 = result;
return result;
}

original_code:
static void net_to_host(union swapper *s)
{
    union swapper t = *s;
    s->b[swapmap[0]] = t.b[0];
    s->b[swapmap[1]] = t.b[1];
    s->b[swapmap[2]] = t.b[2];
    s->b[swapmap[3]] = t.b[3];
}

variable_types: union swapper { float f; int d; unsigned char b[4]; }


decompiled_code:
size_t __fastcall get_file_split(const char *a1)
{
size_t result; // rax
const char *v2; // rdi

result = strlen(a1);
if ( (result & 0x80000000) == 0LL )
{
v2 = &a1[(int)result];
do
{
if ( *v2 == 47 )
break;
result = (unsigned int)(result - 1);
--v2;
}
while ( (_DWORD)result != -1 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(const char *a1)
{
size_t result; // rax
const char *v2; // rdi

result = strlen(a1);
if ( (result & 0x80000000) == 0LL )
{
v2 = &a1[(int)result];
do
{
if ( *v2 == 47 )
break;
result = (unsigned int)(result - 1);
--v2;
}
while ( (_DWORD)result != -1 );
}
return result;
}

original_code:
static int get_file_split(const char *path)
{
    int l = strlen(path);
    while (l >= 0 && !((path[l]) == '/'))
        l--;
    return l;
}

canonical_original_code:
static int get_file_split(char *path)
{
    int l = strlen(path);
    while (l >= 0 && !((path[l]) == '/'))
        l--;
    return l;
}

variable_types:
path
char *

variable_types: l int


decompiled_code:
char *system_error()
{
int *v0; // rax

v0 = _errno_location();
return strerror(*v0);
}

canonical_decompiled_code:
char *func3()
{
int *v0; // rax

v0 = _errno_location();
return strerror(*v0);
}

original_code:
const char *system_error(void)
{
    return strerror((*__errno_location ()));
}

canonical_original_code:
char *system_error()
{
    return strerror((*__errno_location ()));
}


memdup

decompiled_code:
void *__fastcall memdup(void *src, __int64 a2, __int64 a3)
{
size_t v3; // rbx
void *v4; // r12
void *v5; // rax

if ( !src )
return 0LL;
v3 = a3 * a2;
v4 = 0LL;
if ( a3 * a2 )
{
v5 = malloc(a3 * a2);
v4 = v5;
if ( v5 )
memcpy(v5, src, v3);
}
return v4;
}

canonical_decompiled_code:
void *__fastcall func4(void *src, __int64 a2, __int64 a3)
{
size_t v3; // rbx
void *v4; // r12
void *v5; // rax

if ( !src )
return 0LL;
v3 = a3 * a2;
v4 = 0LL;
if ( a3 * a2 )
{
v5 = malloc(a3 * a2);
v4 = v5;
if ( v5 )
memcpy(v5, src, v3);
}
return v4;
}

original_code:
void *memdup(const void *src, size_t num, size_t len)
{
    void *dst = ((void *)0);
    if (src && (num * len > 0) && (dst = malloc(num * len)))
        memcpy(dst, src, num * len);
    return dst;
}

canonical_original_code:
void *memdup(void *src, unsigned long num, unsigned long len)
{
    void *dst = ((void *)0);
    if (src && (num * len > 0) && (dst = malloc(num * len)))
        memcpy(dst, src, num * len);
    return dst;
}

variable_types:
src
void *

variable_types:
num
unsigned long

variable_types:
dst
void *

return_type: void *


decompiled_code:
char *__fastcall get_file_path(char *src)
{
int v1; // eax

memset(path_1, 0, 0x400uLL);
v1 = get_file_split(src);
if ( v1 < 0 )
strcpy(path_1, "./");
else
strncpy(path_1, src, v1 + 1);
return path_1;
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
int v1; // eax

memset(path_1, 0, 0x400uLL);
v1 = func2(src);
if ( v1 < 0 )
strcpy(path_1, "./");
else
strncpy(path_1, src, v1 + 1);
return path_1;
}

original_code:
const char *get_file_path(const char *file)
{
    static char path[1024];
    int l;
    memset(path, 0, 1024);
    if ((l = get_file_split(file)) >= 0)
        strncpy(path, file, l + 1);
    else
        strcpy(path, "./");
    return path;
}

canonical_original_code:
char *get_file_path(char *file)
{
    static char path[1024];
    int l;
    memset(path, 0, 1024);
    if ((l = get_file_split(file)) >= 0)
        strncpy(path, file, l + 1);
    else
        strcpy(path, "./");
    return path;
}

variable_types:
file
char *

variable_types:
path
char [1024]


decompiled_code:
char *__fastcall get_file_name(char *src)
{
int v1; // eax

memset(name_0, 0, sizeof(name_0));
v1 = get_file_split(src);
if ( v1 < 0 )
strncpy(name_0, src, 0x400uLL);
else
strncpy(name_0, &src[v1 + 1], 0x400uLL);
return name_0;
}

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
int v1; // eax

memset(name_0, 0, sizeof(name_0));
v1 = func2(src);
if ( v1 < 0 )
strncpy(name_0, src, 0x400uLL);
else
strncpy(name_0, &src[v1 + 1], 0x400uLL);
return name_0;
}

original_code:
const char *get_file_name(const char *file)
{
    static char name[1024];
    int l;
    memset(name, 0, 1024);
    if ((l = get_file_split(file)) >= 0)
        strncpy(name, file + l + 1, 1024);
    else
        strncpy(name, file, 1024);
    return name;
}

canonical_original_code:
char *get_file_name(char *file)
{
    static char name[1024];
    int l;
    memset(name, 0, 1024);
    if ((l = get_file_split(file)) >= 0)
        strncpy(name, file + l + 1, 1024);
    else
        strncpy(name, file, 1024);
    return name;
}

variable_types:
name
char [1024]


decompiled_code:
int __fastcall stat_file(const char *a1, struct stat *a2)
{
return stat(a1, a2);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, struct stat *a2)
{
return stat(a1, a2);
}

original_code:
int stat_file(const char *filename, struct stat *buf)
{
    int r;
    if ((r = stat(filename, buf)) == 0)
        return 0;
    return r;
}

canonical_original_code:
int stat_file(char *filename, struct stat *buf)
{
    int r;
    if ((r = stat(filename, buf)) == 0)
        return 0;
    return r;
}

variable_types:
filename
char *

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

variable_types: r int

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


decompiled_code:
float __fastcall host_to_net_float(float a1)
{
float v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
host_to_net((unsigned __int8 *)&v2);
return v2;
}

canonical_decompiled_code:
float __fastcall func8(float a1)
{
float v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
func0((unsigned __int8 *)&v2);
return v2;
}

original_code:
float host_to_net_float(float f)
{
    union swapper s;
    s.f = f;
    host_to_net(&s);
    return s.f;
}

variable_types: f float

user_defined_types: union swapper { float f; int d; unsigned char b[4]; }


decompiled_code:
float __fastcall net_to_host_float(float a1)
{
float v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
net_to_host(&v2);
return v2;
}

canonical_decompiled_code:
float __fastcall func9(float a1)
{
float v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
func1(&v2);
return v2;
}

original_code:
float net_to_host_float(float f)
{
    union swapper s;
    s.f = f;
    net_to_host(&s);
    return s.f;
}


decompiled_code:
__int64 __fastcall host_to_net_int(unsigned int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
host_to_net((unsigned __int8 *)&v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
func0((unsigned __int8 *)&v2);
return v2;
}

original_code:
int host_to_net_int(int d)
{
    union swapper s;
    s.d = d;
    host_to_net(&s);
    return s.d;
}

variable_types: d int


decompiled_code:
__int64 __fastcall net_to_host_int(unsigned int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
net_to_host(&v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-4h] BYREF

v2 = a1;
func1(&v2);
return v2;
}

original_code:
int net_to_host_int(int d)
{
    union swapper s;
    s.d = d;
    net_to_host(&s);
    return s.d;
}


error

decompiled_code:
__int64 error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
error_console(s);
return 0LL;
}

canonical_decompiled_code:
__int64 func12(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
error_console(s);
return 0LL;
}

original_code:
void *error(char *format, ...)
{
    char string[1024];
    va_list args;
    __builtin_va_start(args,format);
    vsprintf(string, format, args);
    __builtin_va_end(args);
    error_console(string);
    return ((void *)0);
}

canonical_original_code:
void *error(char *format, ...)
{
    char string[1024];
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vsprintf(string, format, args);
    __builtin_va_end(args);
    error_console(string);
    return ((void *)0);
}

variable_types:
format
char *

variable_types:
string
char [1024]


decompiled_code:
int __fastcall path_push(char *path)
{
int v1; // ebx
char *v2; // rax

v1 = path_index;
if ( path_index > 31 )
{
LODWORD(v2) = error("Directory stack overflow");
}
else
{
v2 = getcwd(&path_stack[1024 * (__int64)path_index], 0x400uLL);
if ( v2 )
{
path_index = v1 + 1;
LODWORD(v2) = chdir(path);
if ( (_DWORD)v2 )
LODWORD(v2) = error("Change to '%s' failed", path);
}
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func13(char *path)
{
int v1; // ebx
char *v2; // rax

v1 = path_index;
if ( path_index > 31 )
{
LODWORD(v2) = func12("Directory stack overflow");
}
else
{
v2 = getcwd(&path_stack[1024 * (__int64)path_index], 0x400uLL);
if ( v2 )
{
path_index = v1 + 1;
LODWORD(v2) = chdir(path);
if ( (_DWORD)v2 )
LODWORD(v2) = func12("Change to '%s' failed", path);
}
}
return (int)v2;
}

original_code:
void path_push(const char *path)
{
    if (path_index < 32)
    {
        if (getcwd(path_stack[path_index], 1024))
        {
            path_index++;
            if (chdir(path))
                error("Change to '%s' failed", path);
        }
    }
    else error("Directory stack overflow");
}

canonical_original_code:
void path_push(char *path)
{
    if (path_index < 32)
    {
        if (getcwd(path_stack[path_index], 1024))
        {
            path_index++;
            if (chdir(path))
                error("Change to '%s' failed", path);
        }
    }
    else error("Directory stack overflow");
}


decompiled_code:
int path_pop()
{
int v0; // eax
const char *v1; // rbx
int result; // eax

v0 = path_index;
if ( path_index <= 0 )
return error("Directory stack underflow");
--path_index;
v1 = &path_stack[1024 * (__int64)(v0 - 1)];
result = chdir(v1);
if ( result )
result = error("Change to '%s' failed", v1);
return result;
}

canonical_decompiled_code:
int func14()
{
int v0; // eax
const char *v1; // rbx
int result; // eax

v0 = path_index;
if ( path_index <= 0 )
return func12("Directory stack underflow");
--path_index;
v1 = &path_stack[1024 * (__int64)(v0 - 1)];
result = chdir(v1);
if ( result )
result = func12("Change to '%s' failed", v1);
return result;
}

original_code:
void path_pop(void)
{
    if (path_index > 0)
    {
        path_index--;
        if (chdir(path_stack[path_index]))
            error("Change to '%s' failed", path_stack[path_index]);
    }
    else
        error("Directory stack underflow");
}

canonical_original_code:
void path_pop()
{
    if (path_index > 0)
    {
        path_index--;
        if (chdir(path_stack[path_index]))
            error("Change to '%s' failed", path_stack[path_index]);
    }
    else
        error("Directory stack underflow");
}


debug

decompiled_code:
__int64 debug(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
debug_console(s);
return 0LL;
}

canonical_decompiled_code:
__int64 func16(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
debug_console(s);
return 0LL;
}

original_code:
void *debug(char *format, ...)
{
    char string[1024];
    va_list args;
    __builtin_va_start(args,format);
    vsprintf(string, format, args);
    __builtin_va_end(args);
    debug_console(string);
    return ((void *)0);
}

canonical_original_code:
void *debug(char *format, ...)
{
    char string[1024];
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vsprintf(string, format, args);
    __builtin_va_end(args);
    debug_console(string);
    return ((void *)0);
}


print

decompiled_code:
__int64 print(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
print_console(s);
return 0LL;
}

canonical_decompiled_code:
__int64 func17(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
print_console(s);
return 0LL;
}

original_code:
void *print(char *format, ...)
{
    char string[1024];
    va_list args;
    __builtin_va_start(args,format);
    vsprintf(string, format, args);
    __builtin_va_end(args);
    print_console(string);
    return ((void *)0);
}

canonical_original_code:
void *print(char *format, ...)
{
    char string[1024];
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vsprintf(string, format, args);
    __builtin_va_end(args);
    print_console(string);
    return ((void *)0);
}


vecdel

decompiled_code:
void __fastcall vecdel(void *ptr)
{
if ( !ptr )
_assert_fail("V", "src/vector.c", 0x2Bu, "vecdel");
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( !ptr )
_assert_fail("V", "src/vector.c", 0x2Bu, "vecdel");
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void vecdel(vector_t V)
{
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    free(V->buf);
    free(V);
}

canonical_original_code:
void vecdel(struct vector *V)
{
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    free(V->buf);
    free(V);
}

variable_types: struct vector { int num; int max; int siz; void *buf; } *