original_code:
int32 adrift_treaty(int32 selector,
                   void *story_file, int32 extent,
                   void *output, int32 output_extent)
{
 int32 ll, csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((signed) strlen("http://www.adrift.org.uk")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.adrift.org.uk");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"adrift",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".taf")+1) < 512 ? (strlen(".taf")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".taf", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

canonical_original_code:
int adrift_treaty(int selector, void *story_file, int extent, void *output, int output_extent)
{
 int ll; int csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((int) strlen("http://www.adrift.org.uk")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.adrift.org.uk");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"adrift",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".taf")+1) < 512 ? (strlen(".taf")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".taf", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

variable_types: selector int

variable_types: extent int

variable_types: csf int


repo: ricpelo/elcirculo

decompiled_code:
__int64 __fastcall claim_story_file(__int64 a1, int a2)
{
__int64 i; // rcx
char v4; // al
__int64 v5; // rcx
__int64 result; // rax
char v7[8]; // [rsp+8h] [rbp-8h] BYREF

vbr_state = 10526342;
v7[7] = 0;
if ( a2 <= 11 )
goto LABEL_6;
for ( i = 0LL; i != 7; i = v5 + 1 )
{
v4 = taf_translate(*(unsigned __int8 *)(a1 + i));
v7[v5] = v4;
}
if ( !strcmp(v7, "Version") )
result = 1LL;
else
LABEL_6:
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 i; // rcx
char v4; // al
__int64 v5; // rcx
__int64 result; // rax
char v7[8]; // [rsp+8h] [rbp-8h] BYREF

vbr_state = 10526342;
v7[7] = 0;
if ( a2 <= 11 )
goto LABEL_6;
for ( i = 0LL; i != 7; i = v5 + 1 )
{
v4 = func0(*(unsigned __int8 *)(a1 + i));
v7[v5] = v4;
}
if ( !strcmp(v7, "Version") )
result = 1LL;
else
LABEL_6:
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int32 claim_story_file(void *story_file, int32 extent)
{
 unsigned char buf[8];
 int i;
 unsigned char *sf=(unsigned char *)story_file;
 buf[7]=0;
 vbr_state=0x00A09E86;
 if (extent<12) return -1;
 for(i=0;i<7;i++) buf[i]=taf_translate(sf[i]);
 if (strcmp((char *)buf,"Version")) return -1;
 return 1;
}

canonical_original_code:
static int claim_story_file(void *story_file, int extent)
{
 unsigned char buf[8];
 int i;
 unsigned char *sf = (unsigned char *)story_file;
 buf[7]=0;
 vbr_state=0x00A09E86;
 if (extent<12) return -1;
 for(i=0;i<7;i++) buf[i]=taf_translate(sf[i]);
 if (strcmp((char *)buf,"Version")) return -1;
 return 1;
}

variable_types:
buf
unsigned char [8]

variable_types: i int

variable_types:
sf
unsigned char *

return_type: int


decompiled_code:
__int64 __fastcall get_story_file_IFID(__int64 a1, int a2, char *a3, int a4)
{
__int64 result; // rax
__int64 v7; // r8
int v8; // ecx
__int64 v9; // r8
char v10; // al
__int64 v11; // r8
int v12; // edi
unsigned int v13; // eax
char nptr[12]; // [rsp+0h] [rbp-Ch] BYREF

vbr_state = 10526342;
result = 0xFFFFFFFFLL;
if ( a2 > 11 )
{
nptr[3] = 0;
do
taf_translate(0);
while ( v8 != 1 );
nptr[0] = taf_translate(*(unsigned __int8 *)(v7 + 8));
taf_translate(0);
v10 = taf_translate(*(unsigned __int8 *)(v9 + 10));
v12 = *(unsigned __int8 *)(v11 + 11);
nptr[1] = v10;
nptr[2] = taf_translate(v12);
result = 4294967293LL;
if ( a4 > 11 )
{
v13 = atoi(nptr);
sprintf(a3, "ADRIFT-%03d-", v13);
result = 4294967292LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, char *a3, int a4)
{
__int64 result; // rax
__int64 v7; // r8
int v8; // ecx
__int64 v9; // r8
char v10; // al
__int64 v11; // r8
int v12; // edi
unsigned int v13; // eax
char nptr[12]; // [rsp+0h] [rbp-Ch] BYREF

vbr_state = 10526342;
result = 0xFFFFFFFFLL;
if ( a2 > 11 )
{
nptr[3] = 0;
do
func0(0);
while ( v8 != 1 );
nptr[0] = func0(*(unsigned __int8 *)(v7 + 8));
func0(0);
v10 = func0(*(unsigned __int8 *)(v9 + 10));
v12 = *(unsigned __int8 *)(v11 + 11);
nptr[1] = v10;
nptr[2] = func0(v12);
result = 4294967293LL;
if ( a4 > 11 )
{
v13 = atoi(nptr);
sprintf(a3, "ADRIFT-%03d-", v13);
result = 4294967292LL;
}
}
return result;
}

original_code:
static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
{
 int adv;
 unsigned char buf[4];
 unsigned char *sf=(unsigned char *)story_file;
 vbr_state=0x00A09E86;
 if (extent <12) return -1;
 buf[3]=0;
 for(adv=0;adv<8;adv++) taf_translate(0);
 buf[0]=taf_translate(sf[8]);
 taf_translate(0);
 buf[1]=taf_translate(sf[10]);
 buf[2]=taf_translate(sf[11]);
 adv=atoi((char *) buf);
 do { if (output_extent < (12)) return -3; } while (0);
 sprintf(output,"ADRIFT-%03d-",adv);
 return -4;
}

canonical_original_code:
static int get_story_file_IFID(void *story_file, int extent, char *output, int output_extent)
{
 int adv;
 unsigned char buf[4];
 unsigned char *sf = (unsigned char *)story_file;
 vbr_state=0x00A09E86;
 if (extent <12) return -1;
 buf[3]=0;
 for(adv=0;adv<8;adv++) taf_translate(0);
 buf[0]=taf_translate(sf[8]);
 taf_translate(0);
 buf[1]=taf_translate(sf[10]);
 buf[2]=taf_translate(sf[11]);
 adv=atoi((char *) buf);
 do { if (output_extent < (12)) return -3; } while (0);
 sprintf(output,"ADRIFT-%03d-",adv);
 return -4;
}

variable_types:
output
char *

variable_types: adv int

variable_types:
buf
unsigned char [4]


decompiled_code:
size_t __fastcall get_story_file_extension(__int64 a1, int a2, const char *a3, int a4)
{
char v5; // dl
int v7; // ecx
__int64 v8; // rax
unsigned int i; // eax
__int64 v10; // rdx

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v5 = 116;
v7 = 1;
v8 = 2LL;
do
{
if ( v5 == 44 )
break;
v5 = byte_3B9[v8];
v7 = v8++;
}
while ( v5 );
if ( a4 <= v7 )
return 4294967293LL;
if ( v7 )
{
for ( i = 0; i < v7; ++i )
{
v10 = i;
a3[v10] = byte_3B9[v10];
}
}
a3[v7] = 0;
return strlen(a3);
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1, int a2, const char *a3, int a4)
{
char v5; // dl
int v7; // ecx
__int64 v8; // rax
unsigned int i; // eax
__int64 v10; // rdx

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v5 = 116;
v7 = 1;
v8 = 2LL;
do
{
if ( v5 == 44 )
break;
v5 = byte_3B9[v8];
v7 = v8++;
}
while ( v5 );
if ( a4 <= v7 )
return 4294967293LL;
if ( v7 )
{
for ( i = 0; i < v7; ++i )
{
v10 = i;
a3[v10] = byte_3B9[v10];
}
}
a3[v7] = 0;
return strlen(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;".taf"[i] && ".taf"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".taf",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;".taf"[i] && ".taf"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".taf",i);
 out[i]=0;
 return strlen(out);
}

variable_types:
sf
void *

variable_types:
out
char *


decompiled_code:
const char *__fastcall get_url(const char *a1, const char *a2)
{
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

sprintf(v3, "curl --silent --fail %s/metadata/%s", a2, a1);
system(v3);
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1, const char *a2)
{
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

sprintf(v3, "curl --silent --fail %s/metadata/%s", a2, a1);
system(v3);
return a1;
}

original_code:
char *get_url(char *ifid, char *from)
{
 char cmdbuf[1024];
 sprintf(cmdbuf, "curl --silent --fail %s/metadata/%s",from,ifid);
 system(cmdbuf);
 return ifid;
}

variable_types:
ifid
char *

variable_types:
from
char *

variable_types:
cmdbuf
char [1024]

return_type: char *


decompiled_code:
const char *__fastcall get_url_cover(const char *a1, const char *a2)
{
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

sprintf(v3, "curl --silent --fail %s/cover/%s > %s.jpg", a2, a1, a1);
system(v3);
return a1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1, const char *a2)
{
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

sprintf(v3, "curl --silent --fail %s/cover/%s > %s.jpg", a2, a1, a1);
system(v3);
return a1;
}

original_code:
char *get_url_cover(char *ifid, char *from)
{
 char cmdbuf[1024];
 sprintf(cmdbuf, "curl --silent --fail %s/cover/%s > %s.jpg",from,ifid, ifid);
 system(cmdbuf);
 return ifid;
}


decompiled_code:
char __fastcall verify_eh(const char *a1, int *a2)
{
int v2; // eax
bool v4; // zf

v2 = *a2;
if ( *a2 >= 0 )
{
if ( v2 || (v4 = memcmp(a1, "Warning", 7uLL) == 0, (LOBYTE(v2) = !v4) != 0) )
{
isok = 0;
LOBYTE(v2) = fprintf(stderr, "%s\n", a1);
}
}
return v2;
}

canonical_decompiled_code:
char __fastcall func0(const char *a1, int *a2)
{
int v2; // eax
bool v4; // zf

v2 = *a2;
if ( *a2 >= 0 )
{
if ( v2 || (v4 = memcmp(a1, "Warning", 7uLL) == 0, (LOBYTE(v2) = !v4) != 0) )
{
isok = 0;
LOBYTE(v2) = fprintf(stderr, "%s\n", a1);
}
}
return v2;
}

original_code:
static void verify_eh(char *e, void *ctx)
{
 if (*((int *)ctx) < 0) return;
 if (*((int *)ctx) || strncmp(e,"Warning",7))
  { isok=0;
   fprintf(stderr, "%s\n",e);
  }
}

variable_types:
e
char *

variable_types:
ctx
void *

return_type: void


original_code:
static void examine_tag(struct XMLTag *xtg, void *ctx)
{
 struct IFiction_Info *xti=(struct IFiction_Info *)ctx;
 if (strcmp("ifid",xtg->tag)==0 && strcmp(xti->ifid,"UNKNOWN")==0)
 {
 memcpy(xti->ifid,xtg->begin,xtg->end-xtg->begin);
 xti->ifid[xtg->end-xtg->begin]=0;
 }
}

canonical_original_code:
static void examine_tag(struct XMLTag *xtg, void *ctx)
{
 struct IFiction_Info *xti = (struct IFiction_Info *)ctx;
 if (strcmp("ifid",xtg->tag)==0 && strcmp(xti->ifid,"UNKNOWN")==0)
 {
 memcpy(xti->ifid,xtg->begin,xtg->end-xtg->begin);
 xti->ifid[xtg->end-xtg->begin]=0;
 }
}

variable_types: struct XMLTag { int beginl; char tag[256]; char fulltag[256]; char *begin; char *end; char occurences[256]; char rocurrences[256]; struct XMLTag *next; } *

variable_types: struct IFiction_Info { char ifid[256]; int wmode; } *


decompiled_code:
char *__fastcall babel_ifiction_ifid(__int64 a1)
{
char *result; // rax
const char *i; // rsi
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

if ( !(unsigned int)ifiction_get_IFID(a1, v3, 512LL) )
return (char *)fwrite("Error: No IFIDs found in iFiction file\n", 1uLL, 0x27uLL, stderr);
result = strtok(v3, ",");
for ( i = result; result; i = result )
{
printf("IFID: %s\n", i);
result = strtok(0LL, ",");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1)
{
char *result; // rax
const char *i; // rsi
char v3[520]; // [rsp+0h] [rbp-208h] BYREF

if ( !(unsigned int)ifiction_get_IFID(a1, v3, 512LL) )
return (char *)fwrite("Error: No IFIDs found in iFiction file\n", 1uLL, 0x27uLL, stderr);
result = strtok(v3, ",");
for ( i = result; result; i = result )
{
printf("IFID: %s\n", i);
result = strtok(0LL, ",");
}
return result;
}

original_code:
void babel_ifiction_ifid(char *md)
{
 char output[512];
 int i;
 char *ep;
 i=ifiction_get_IFID(md,output,512);
 if (!i)
 {
  fprintf(stderr,"Error: No IFIDs found in iFiction file\n");
  return;
 }
 ep=strtok(output,",");
 while(ep)
 {
  printf("IFID: %s\n",ep);
  ep=strtok(((void *)0),",");
 }
}

variable_types:
md
char *

variable_types:
output
char [512]

variable_types:
ep
char *


decompiled_code:
__int64 __fastcall babel_ifiction_fish(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -1;
return ifiction_parse(a1, write_story_to_disk, 0LL, verify_eh, v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = -1;
return ifiction_parse(a1, write_story_to_disk, 0LL, verify_eh, v2);
}

original_code:
void babel_ifiction_fish(char *md)
{
 int i=-1;
 ifiction_parse(md,write_story_to_disk,((void *)0),verify_eh,&i);
}

canonical_original_code:
void babel_ifiction_fish(char *md)
{
 int i = -1;
 ifiction_parse(md,write_story_to_disk,((void *)0),verify_eh,&i);
}

variable_types: i int


decompiled_code:
int __fastcall deep_ifiction_verify(__int64 a1, int a2)
{
int result; // eax
int v3; // [rsp+Ch] [rbp-11Ch] BYREF
__int64 v4[32]; // [rsp+10h] [rbp-118h] BYREF
int v5; // [rsp+110h] [rbp-18h]

isok = 1;
v3 = 0;
v5 = 0;
v4[0] = 0x4E574F4E4B4E55LL;
result = ifiction_parse(a1, examine_tag, v4, verify_eh, &v3);
if ( a2 )
{
if ( isok )
result = printf("Verified %s\n", (const char *)v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
int result; // eax
int v3; // [rsp+Ch] [rbp-11Ch] BYREF
__int64 v4[32]; // [rsp+10h] [rbp-118h] BYREF
int v5; // [rsp+110h] [rbp-18h]

isok = 1;
v3 = 0;
v5 = 0;
v4[0] = 0x4E574F4E4B4E55LL;
result = ifiction_parse(a1, examine_tag, v4, verify_eh, &v3);
if ( a2 )
{
if ( isok )
result = printf("Verified %s\n", (const char *)v4);
}
return result;
}

original_code:
void deep_ifiction_verify(char *md, int f)
{
 struct IFiction_Info ii;
 int i=0;
 ii.wmode=0;
 isok=1;
 strcpy(ii.ifid,"UNKNOWN");
 ifiction_parse(md,examine_tag,&ii,verify_eh,&i);
 if (f&& isok) printf("Verified %s\n",ii.ifid);
}

canonical_original_code:
void deep_ifiction_verify(char *md, int f)
{
 struct IFiction_Info ii;
 int i = 0;
 ii.wmode=0;
 isok=1;
 strcpy(ii.ifid,"UNKNOWN");
 ifiction_parse(md,examine_tag,&ii,verify_eh,&i);
 if (f&& isok) printf("Verified %s\n",ii.ifid);
}

variable_types: f int

variable_types: struct IFiction_Info { char ifid[256]; int wmode; }


decompiled_code:
int __fastcall babel_ifiction_verify(__int64 a1)
{
return deep_ifiction_verify(a1, 1);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
return func5(a1, 1);
}

original_code:
void babel_ifiction_verify(char *md)
{
 deep_ifiction_verify(md,1);
}


decompiled_code:
int __fastcall babel_ifiction_lint(__int64 a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-11Ch] BYREF
__int64 v3[32]; // [rsp+10h] [rbp-118h] BYREF
int v4; // [rsp+110h] [rbp-18h]

v2 = 1;
v4 = 1;
isok = 1;
v3[0] = 0x4E574F4E4B4E55LL;
result = ifiction_parse(a1, examine_tag, v3, verify_eh, &v2);
if ( isok )
result = printf("%s conforms to iFiction style guidelines\n", (const char *)v3);
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-11Ch] BYREF
__int64 v3[32]; // [rsp+10h] [rbp-118h] BYREF
int v4; // [rsp+110h] [rbp-18h]

v2 = 1;
v4 = 1;
isok = 1;
v3[0] = 0x4E574F4E4B4E55LL;
result = ifiction_parse(a1, examine_tag, v3, verify_eh, &v2);
if ( isok )
result = printf("%s conforms to iFiction style guidelines\n", (const char *)v3);
return result;
}

original_code:
void babel_ifiction_lint(char *md)
{
 struct IFiction_Info ii;
 int i=1;
 ii.wmode=1;
 isok=1;
 strcpy(ii.ifid,"UNKNOWN");
 ifiction_parse(md,examine_tag,&ii,verify_eh,&i);
 if (isok) printf("%s conforms to iFiction style guidelines\n",ii.ifid);
}

canonical_original_code:
void babel_ifiction_lint(char *md)
{
 struct IFiction_Info ii;
 int i = 1;
 ii.wmode=1;
 isok=1;
 strcpy(ii.ifid,"UNKNOWN");
 ifiction_parse(md,examine_tag,&ii,verify_eh,&i);
 if (isok) printf("%s conforms to iFiction style guidelines\n",ii.ifid);
}

user_defined_types: struct IFiction_Info { char ifid[256]; int wmode; }


decompiled_code:
void __fastcall tads2_treaty(int a1, __int64 a2, unsigned int a3, __int64 a4, int a5)
{
__m128i v8; // xmm0

if ( ((a1 & 0x100) == 0 || (int)claim_story_file(a2, a3) >= 0) && ((a1 & 0x200) == 0 || a5 && a4) )
{
if ( a1 == 514 )
{
if ( a5 > 511 )
strncpy((char *)a4, "tads2", a5 - 1);
}
else if ( a1 <= 514 )
{
if ( a1 == 262 )
{
get_story_file_cover_extent(a2, a3);
}
else if ( a1 <= 262 )
{
if ( a1 != 260 && a1 == 261 )
get_story_file_metadata_extent(a2, a3);
}
else if ( a1 == 263 )
{
get_story_file_cover_format(a2, a3);
}
else if ( a1 == 513 && a5 > 19 )
{
v8 = _mm_load_si128((const __m128i *)&LC3);
*(_DWORD *)(a4 + 16) = 6779503;
*(__m128i *)a4 = v8;
}
}
else if ( a1 == 777 )
{
get_story_file_metadata(a2, a3, a4, (unsigned int)a5);
}
else if ( a1 <= 777 )
{
if ( a1 == 515 )
{
if ( a5 > 4 )
strncpy((char *)a4, src, a5);
}
else if ( a1 == 776 )
{
get_story_file_IFID(a2, a3, a4, (unsigned int)a5);
}
}
else if ( a1 == 778 )
{
get_story_file_cover(a2, a3, a4, (unsigned int)a5);
}
else if ( a1 == 779 )
{
get_story_file_extension(a2, a3, (const char *)a4, a5);
}
}
}

original_code:
int32 tads2_treaty(int32 selector,
                   void *story_file, int32 extent,
                   void *output, int32 output_extent)
{
 int32 ll, csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((signed) strlen("http://www.tads.org")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.tads.org");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"tads2",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".gam")+1) < 512 ? (strlen(".gam")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".gam", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
                return get_story_file_metadata_extent(story_file, extent);
  case 0x309:
                return get_story_file_metadata(story_file, extent, (char *)output, output_extent);
  case 0x106:
                return get_story_file_cover_extent(story_file, extent);
  case 0x107:
                return get_story_file_cover_format(story_file, extent);
  case 0x30A:
                return get_story_file_cover(story_file, extent, output, output_extent);
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

canonical_original_code:
int tads2_treaty(int selector, void *story_file, int extent, void *output, int output_extent)
{
 int ll; int csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((int) strlen("http://www.tads.org")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.tads.org");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"tads2",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".gam")+1) < 512 ? (strlen(".gam")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".gam", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
                return get_story_file_metadata_extent(story_file, extent);
  case 0x309:
                return get_story_file_metadata(story_file, extent, (char *)output, output_extent);
  case 0x106:
                return get_story_file_cover_extent(story_file, extent);
  case 0x107:
                return get_story_file_cover_format(story_file, extent);
  case 0x30A:
                return get_story_file_cover(story_file, extent, output, output_extent);
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

variable_types: selector int

variable_types: extent int

variable_types:
output
void *

variable_types: ll int

variable_types: csf int


decompiled_code:
__int64 __fastcall claim_story_file(__int64 a1, __int64 a2)
{
return (unsigned int)tads_match_sig(a1, a2, &unk_336) == 0 ? -1 : 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return (unsigned int)tads_match_sig(a1, a2, &unk_336) == 0 ? -1 : 1;
}

original_code:
static int32 claim_story_file(void *story_file, int32 extent)
{
    if (tads_match_sig(story_file, extent, "TADS2 bin\012\015\032"))
        return 1;
    return -1;
}

canonical_original_code:
static int claim_story_file(void *story_file, int extent)
{
    if (tads_match_sig(story_file, extent, "TADS2 bin\012\015\032"))
        return 1;
    return -1;
}


decompiled_code:
// attributes: thunk
__int64 get_story_file_metadata_extent()
{
return tads_get_story_file_metadata_extent();
}

canonical_decompiled_code:
__int64 func1()
{
return tads_get_story_file_metadata_extent();
}

original_code:
static int32 get_story_file_metadata_extent(void *story_file, int32 extent)
{
    return tads_get_story_file_metadata_extent(story_file, extent);
}

canonical_original_code:
static int get_story_file_metadata_extent(void *story_file, int extent)
{
    return tads_get_story_file_metadata_extent(story_file, extent);
}


decompiled_code:
// attributes: thunk
__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


decompiled_code:
// attributes: thunk
__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);
}


decompiled_code:
// attributes: thunk
__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:
// attributes: thunk
__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:
// attributes: thunk
__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:
output
char *


decompiled_code:
size_t __fastcall get_story_file_extension(__int64 a1, int a2, const char *a3, int a4)
{
char v5; // dl
int v7; // ecx
__int64 v8; // rax
unsigned int i; // eax
__int64 v10; // rdx

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v5 = 103;
v7 = 1;
v8 = 2LL;
do
{
if ( v5 == 44 )
break;
v5 = src[v8];
v7 = v8++;
}
while ( v5 );
if ( a4 <= v7 )
return 4294967293LL;
if ( v7 )
{
for ( i = 0; i < v7; ++i )
{
v10 = i;
a3[v10] = src[v10];
}
}
a3[v7] = 0;
return strlen(a3);
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, int a2, const char *a3, int a4)
{
char v5; // dl
int v7; // ecx
__int64 v8; // rax
unsigned int i; // eax
__int64 v10; // rdx

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v5 = 103;
v7 = 1;
v8 = 2LL;
do
{
if ( v5 == 44 )
break;
v5 = src[v8];
v7 = v8++;
}
while ( v5 );
if ( a4 <= v7 )
return 4294967293LL;
if ( v7 )
{
for ( i = 0; i < v7; ++i )
{
v10 = i;
a3[v10] = src[v10];
}
}
a3[v7] = 0;
return strlen(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 *


ShortProgramName

decompiled_code:
char *__fastcall ShortProgramName(const char *a1)
{
const char *v1; // rbp
char *v2; // rax
char *v3; // r12
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; // rbp
char *v2; // rax
char *v3; // r12
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 *


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


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

result = puts("Usage:");
v1 = info;
if ( info )
{
v2 = (unsigned int)((_DWORD)&info + 8);
do
{
v3 = (const char *)&unk_174;
v4 = *(_QWORD *)v2;
if ( v1[1] == 99 )
v3 = " [-to <directory>]";
v5 = "<ifid>";
if ( !*(_BYTE *)(v2 + 16) )
v5 = "[<ifid>]";
v2 += 32LL;
result = printf(" babel-get %s %s %s <source>%s\n", v1, v5, v4, v3);
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
__int64 v4; // rcx
const char *v5; // rdx

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

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v4; // zf
__int64 v5; // rax
const char *v6; // rsi
const char *v7; // rbp
__int64 v8; // r13
const char **v9; // r14
const char *v10; // r15
int v11; // er8
int v12; // er8
__int64 v14; // rax
int v15; // er8
int v16; // eax
_BOOL4 v17; // [rsp+Ch] [rbp-25Ch]
int v18; // [rsp+Ch] [rbp-25Ch]
int v19; // [rsp+Ch] [rbp-25Ch]
int v20; // [rsp+Ch] [rbp-25Ch]
const char *v21; // [rsp+10h] [rbp-258h]
const char **v22; // [rsp+18h] [rbp-250h]
__int64 v23; // [rsp+28h] [rbp-240h]
char path[568]; // [rsp+30h] [rbp-238h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v4; // zf
__int64 v5; // rax
const char *v6; // rsi
const char *v7; // rbp
__int64 v8; // r13
const char **v9; // r14
const char *v10; // r15
int v11; // er8
int v12; // er8
__int64 v14; // rax
int v15; // er8
int v16; // eax
_BOOL4 v17; // [rsp+Ch] [rbp-25Ch]
int v18; // [rsp+Ch] [rbp-25Ch]
int v19; // [rsp+Ch] [rbp-25Ch]
int v20; // [rsp+Ch] [rbp-25Ch]
const char *v21; // [rsp+10h] [rbp-258h]
const char **v22; // [rsp+18h] [rbp-250h]
__int64 v23; // [rsp+28h] [rbp-240h]
char path[568]; // [rsp+30h] [rbp-238h] BYREF

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

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; // r12
char v4[512]; // [rsp+0h] [rbp-428h] BYREF
char s[552]; // [rsp+200h] [rbp-228h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
__int64 v2; // r12
char v4[512]; // [rsp+0h] [rbp-428h] BYREF
char s[552]; // [rsp+200h] [rbp-228h] BYREF

if ( !a1 )
return 0LL;
getcwd(v4, 0x200uLL);
sprintf(s, "%s.iFiction", a1);
chdir(a2);
v2 = get_ifiction(a1, s);
chdir(v4);
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:
char *__fastcall getDirectionString(unsigned int a1)
{
char *result; // rax

result = (char *)&unk_205;
if ( a1 <= 3 )
result = CSWTCH_7[a1];
return result;
}

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

result = (char *)&unk_205;
if ( a1 <= 3 )
result = CSWTCH_7[a1];
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 i; // er8

v2 = *a1;
for ( i = 0; v2; v2 = a1[i] )
{
while ( a2 != v2 )
{
v2 = (++a1)[i];
if ( !v2 )
return i;
}
++i;
}
return i;
}

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

v2 = *a1;
for ( i = 0; v2; v2 = a1[i] )
{
while ( a2 != v2 )
{
v2 = (++a1)[i];
if ( !v2 )
return i;
}
++i;
}
return i;
}

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


listShiftLeftAdd

decompiled_code:
void __fastcall listShiftLeftAdd(char *a1, int a2, float a3)
{
if ( a2 > 1 )
a1 = (char *)memmove(a1, a1 + 4, 4LL * (unsigned int)(a2 - 2) + 4);
*(float *)&a1[4 * a2 - 4] = a3;
}

canonical_decompiled_code:
void __fastcall func3(char *a1, int a2, float a3)
{
if ( a2 > 1 )
a1 = (char *)memmove(a1, a1 + 4, 4LL * (unsigned int)(a2 - 2) + 4);
*(float *)&a1[4 * a2 - 4] = 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)
{
void *result; // rax

if ( a2 - 1 > 0 )
result = memmove(
(char *)a1 + 4LL * (a2 - 1) - 4LL * (unsigned int)(a2 - 2),
(char *)a1 + 4LL * (a2 - 1) - 4LL * (unsigned int)(a2 - 2) - 4,
4LL * (unsigned int)(a2 - 2) + 4);
*a1 = a3;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(float *a1, int a2, float a3)
{
void *result; // rax

if ( a2 - 1 > 0 )
result = memmove(
(char *)a1 + 4LL * (a2 - 1) - 4LL * (unsigned int)(a2 - 2),
(char *)a1 + 4LL * (a2 - 1) - 4LL * (unsigned int)(a2 - 2) - 4,
4LL * (unsigned int)(a2 - 2) + 4);
*a1 = a3;
return result;
}

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

variable_types: i int


parseMemLine

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


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


main

repo: rjrodger/sdc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rsi
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]
__int64 v8; // [rsp+10h] [rbp-18h]
unsigned int v9; // [rsp+18h] [rbp-10h]

v3 = 0;
v6 = 0x900000000LL;
v7 = 0x600000003LL;
v8 = 0x100000001LL;
v9 = 6;
do
{
v4 = v3++;
decrement(&v6, v4, envp);
printf(
"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
v4,
(unsigned int)v6,
HIDWORD(v6),
(unsigned int)v7,
HIDWORD(v7),
(unsigned int)v8,
HIDWORD(v8),
v9);
sleep(1u);
}
while ( v3 != 70 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rsi
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]
__int64 v8; // [rsp+10h] [rbp-18h]
unsigned int v9; // [rsp+18h] [rbp-10h]

v3 = 0;
v6 = 0x900000000LL;
v7 = 0x600000003LL;
v8 = 0x100000001LL;
v9 = 6;
do
{
v4 = v3++;
func7(&v6, v4, envp);
printf(
"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
v4,
(unsigned int)v6,
HIDWORD(v6),
(unsigned int)v7,
HIDWORD(v7),
(unsigned int)v8,
HIDWORD(v8),
v9);
sleep(1u);
}
while ( v3 != 70 );
return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
c
int []

variable_types: i int


decrement

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 *


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


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(__int64 *a1, _QWORD *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx

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

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

v2 = 0;
if ( *a2 )
{
v2 = *(unsigned __int8 *)*a1;
v3 = *a1 + 1;
--*a2;
*a1 = v3;
}
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 v2; // r13
const char *v3; // rbp
__int64 v4; // rbx
const unsigned __int16 *v5; // rcx
__int64 v6; // rax
const char *v7; // rdx
__int64 v8; // r12
const char *v9; // rbx
__int64 result; // rax
__int64 v11; // rax

v2 = *a2;
v3 = *a1;
if ( *a2 )
{
v4 = 0LL;
v5 = *_ctype_b_loc();
while ( 1 )
{
v6 = v3[v4];
v7 = &v3[v4];
v8 = v4++;
if ( (v5[v6] & 0x800) == 0 )
break;
if ( v2 == v4 )
{
v11 = v8 + 2;
v7 = &v3[v4];
v8 = v4;
v4 = v11;
break;
}
}
}
else
{
v7 = *a1;
v8 = 0LL;
v4 = 1LL;
}
*v7 = 0;
v9 = &(*a1)[v4];
LODWORD(result) = atoi(*a1);
*a2 += ~v8;
*a1 = v9;
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_518,
*(double *)&qword_520,
1.0);
return cairo_paint(cairo_context);
}

canonical_decompiled_code:
__int64 func3()
{
cairo_set_source_rgba(
cairo_context,
*(double *)&default_background,
*(double *)&qword_518,
*(double *)&qword_520,
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; // ebp
int v3; // er12
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; // ebp
int v3; // er12
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[8201]; // [rsp+1h] [rbp-2011h]
char v1[8200]; // [rsp+2h] [rbp-2010h] BYREF

if ( fgets(v1, 0x2000, stdin) )
{
v0[strlen(v1)] = 0;
engine_update(v1, 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; // r12

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

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

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

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; // r12
int v3; // eax
void **v4; // rdi
struct option v6; // [rsp+0h] [rbp-D8h] BYREF
const char *v7; // [rsp+20h] [rbp-B8h]
int v8; // [rsp+28h] [rbp-B0h]
__int64 v9; // [rsp+30h] [rbp-A8h]
int v10; // [rsp+38h] [rbp-A0h]
const char *v11; // [rsp+40h] [rbp-98h]
int v12; // [rsp+48h] [rbp-90h]
__int64 v13; // [rsp+50h] [rbp-88h]
int v14; // [rsp+58h] [rbp-80h]
const char *v15; // [rsp+60h] [rbp-78h]
int v16; // [rsp+68h] [rbp-70h]
__int64 v17; // [rsp+70h] [rbp-68h]
int v18; // [rsp+78h] [rbp-60h]
const char *v19; // [rsp+80h] [rbp-58h]
int v20; // [rsp+88h] [rbp-50h]
__int64 v21; // [rsp+90h] [rbp-48h]
int v22; // [rsp+98h] [rbp-40h]
const char *v23; // [rsp+A0h] [rbp-38h]
int v24; // [rsp+A8h] [rbp-30h]
__int64 v25; // [rsp+B0h] [rbp-28h]
int v26; // [rsp+B8h] [rbp-20h]

v2 = (void **)options_allocate();
if ( v2 )
{
v6.name = "help";
v6.has_arg = 0;
v6.flag = 0LL;
v6.val = 104;
v7 = "height";
v8 = 1;
v9 = 0LL;
v10 = 103;
v11 = "bottom";
v12 = 0;
v13 = 0LL;
v14 = 109;
v15 = "font";
v16 = 1;
v17 = 0LL;
v18 = 116;
v19 = "foreground";
v20 = 1;
v21 = 0LL;
v22 = 102;
v23 = "background";
v24 = 1;
v25 = 0LL;
v26 = 98;
while ( 2 )
{
v3 = getopt_long(argc, argv, "hmg:t:f:b:", &v6, 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);
v4 = v2;
v2 = 0LL;
options_destroy(v4);
break;
}
}
break;
}
}
return v2;
}

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

v2 = (void **)func0();
if ( v2 )
{
v6.name = "help";
v6.has_arg = 0;
v6.flag = 0LL;
v6.val = 104;
v7 = "height";
v8 = 1;
v9 = 0LL;
v10 = 103;
v11 = "bottom";
v12 = 0;
v13 = 0LL;
v14 = 109;
v15 = "font";
v16 = 1;
v17 = 0LL;
v18 = 116;
v19 = "foreground";
v20 = 1;
v21 = 0LL;
v22 = 102;
v23 = "background";
v24 = 1;
v25 = 0LL;
v26 = 98;
while ( 2 )
{
v3 = getopt_long(argc, argv, "hmg:t:f:b:", &v6, 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);
v4 = v2;
v2 = 0LL;
func1(v4);
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:
void *__fastcall strdup(void *src)
{
size_t v1; // rbx
void *v2; // rax

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

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

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

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 *


decompiled_code:
__int64 __fastcall parse_color(__int64 a1, double *a2)
{
int v2; // eax
double v3; // xmm0_8
__int64 result; // rax
__int16 v5; // [rsp+Eh] [rbp-1Ah] BYREF
__int16 v6; // [rsp+10h] [rbp-18h] BYREF
__int16 v7; // [rsp+12h] [rbp-16h] BYREF
int v8; // [rsp+14h] [rbp-14h] BYREF
int v9; // [rsp+18h] [rbp-10h] BYREF
unsigned int v10; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = *(_WORD *)(a1 + 1);
v6 = *(_WORD *)(a1 + 3);
v7 = *(_WORD *)(a1 + 5);
_isoc99_sscanf(&v5, "%02x", &v8);
_isoc99_sscanf(&v6, "%02x", &v9);
_isoc99_sscanf(&v7, "%02x", &v10);
v2 = v9;
*a2 = (double)v8 / 255.0;
v3 = (double)v2;
result = v10;
a2[1] = v3 / 255.0;
a2[2] = (double)(int)result / 255.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, double *a2)
{
int v2; // eax
double v3; // xmm0_8
__int64 result; // rax
__int16 v5; // [rsp+Eh] [rbp-1Ah] BYREF
__int16 v6; // [rsp+10h] [rbp-18h] BYREF
__int16 v7; // [rsp+12h] [rbp-16h] BYREF
int v8; // [rsp+14h] [rbp-14h] BYREF
int v9; // [rsp+18h] [rbp-10h] BYREF
unsigned int v10; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = *(_WORD *)(a1 + 1);
v6 = *(_WORD *)(a1 + 3);
v7 = *(_WORD *)(a1 + 5);
_isoc99_sscanf(&v5, "%02x", &v8);
_isoc99_sscanf(&v6, "%02x", &v9);
_isoc99_sscanf(&v7, "%02x", &v10);
v2 = v9;
*a2 = (double)v8 / 255.0;
v3 = (double)v2;
result = v10;
a2[1] = v3 / 255.0;
a2[2] = (double)(int)result / 255.0;
return result;
}

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, __int64 a2, int a3)
{
int v3; // xmm0_4
__int64 v4; // rax
__int64 result; // rax
float v6; // xmm1_4
int v7[3]; // [rsp+0h] [rbp-28h] BYREF
float v8; // [rsp+Ch] [rbp-1Ch]
__int64 v9; // [rsp+10h] [rbp-18h] BYREF
int v10; // [rsp+18h] [rbp-10h]
int v11; // [rsp+1Ch] [rbp-Ch]

v3 = *(_DWORD *)(a2 + 8);
v4 = *(_QWORD *)a2;
v11 = 1065353216;
v10 = v3;
v9 = v4;
result = mult_mat_vec(v7, (char *)transform + 140 * a3, &v9);
v6 = v8;
*a1 = *(float *)v7 / v8;
a1[1] = *(float *)&v7[1] / v6;
a1[2] = *(float *)&v7[2] / v6;
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 func5(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 func6(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; // edi
unsigned int *v6; // rax
__int64 v8; // rdx
__int64 v9; // rcx
__int16 v10; // ax
unsigned int v11; // er8
__int64 v12; // rdi
socklen_t v13; // edx
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
int v17; // eax
const char *v18; // rdx
const char *v19; // rax
struct sockaddr v20[2]; // [rsp+0h] [rbp-28h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(key_t a1, key_t a2, int a3)
{
int v4; // eax
int v5; // edi
unsigned int *v6; // rax
__int64 v8; // rdx
__int64 v9; // rcx
__int16 v10; // ax
unsigned int v11; // er8
__int64 v12; // rdi
socklen_t v13; // edx
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
int v17; // eax
const char *v18; // rdx
const char *v19; // rax
struct sockaddr v20[2]; // [rsp+0h] [rbp-28h] BYREF

v4 = shmget(a1, 0x1CuLL, 0);
if ( v4 >= 0 )
tracker = shmat(v4, 0LL, 0);
v5 = shmget(a2, 0x20uLL, 0);
v6 = (unsigned int *)control;
if ( v5 >= 0 )
{
v6 = (unsigned int *)shmat(v5, 0LL, 0);
control = v6;
}
if ( v6 != (unsigned int *)-1LL )
buttons = calloc(v6[3], 4uLL);
if ( a3 )
{
sock = socket(2, 2, 0);
if ( sock < 0 )
{
v17 = system_error(2LL, 2LL, v8, v9, (unsigned int)sock);
error((int)"socket : %s", v17, v18);
}
else
{
v20[0].sa_family = 2;
v10 = func0(a3);
v12 = v11;
*(_WORD *)v20[0].sa_data = v10;
*(_DWORD *)&v20[0].sa_data[2] = func3(v11, v20);
if ( bind(v12, v20, v13) < 0 )
{
v19 = (const char *)system_error(v12, v20, v14, v15, v16);
error((int)"bind %d : %s", a3, v19);
}
else
{
transforms = 1;
}
}
}
if ( tracker != (void *)-1LL )
func4(*((_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 func8()
{
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 func9()
{
_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; // edi
int v5; // ebx
unsigned int v6; // er14
__int64 result; // rax
char *v8; // rbp
__int64 v9; // [rsp+4h] [rbp-E4h] BYREF
float v10; // [rsp+Ch] [rbp-DCh]
struct timeval timeout; // [rsp+10h] [rbp-D8h] BYREF
__int64 buf; // [rsp+20h] [rbp-C8h] BYREF
int v13; // [rsp+28h] [rbp-C0h]
fd_set readfds; // [rsp+40h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, float *a2, __m128i *a3)
{
int v4; // edi
int v5; // ebx
unsigned int v6; // er14
__int64 result; // rax
char *v8; // rbp
__int64 v9; // [rsp+4h] [rbp-E4h] BYREF
float v10; // [rsp+Ch] [rbp-DCh]
struct timeval timeout; // [rsp+10h] [rbp-D8h] BYREF
__int64 buf; // [rsp+20h] [rbp-C8h] BYREF
int v13; // [rsp+28h] [rbp-C0h]
fd_set readfds; // [rsp+40h] [rbp-A8h] BYREF

if ( tracker == (void *)-1LL || *((_DWORD *)tracker + 1) <= a1 )
{
if ( a1 || sock == -1 )
goto LABEL_13;
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v4 = sock;
v5 = 0;
readfds.fds_bits[sock / 64] |= 1LL << (sock % 64);
while ( select(v4 + 1, &readfds, 0LL, 0LL, &timeout) > 0 )
{
if ( (readfds.fds_bits[sock / 64] & (1LL << (sock % 64))) != 0 )
{
v6 = recv(sock, &buf, 0x18uLL, 0);
if ( v6 > 0xB )
{
v9 = buf;
LODWORD(v10) = v13 ^ LC3;
func2(a2, (__int64)&v9, 0);
*((float *)&v9 + 1) = *((float *)&v9 + 1) + 3.0;
printf("%+8.3f %+8.3f %+8.3f ", *(float *)&v9, *((float *)&v9 + 1), v10);
printf("%+8.3f %+8.3f %+8.3f\n", *a2, a2[1], a2[2]);
last_p_1 = *(_QWORD *)a2;
dword_928 = *((_DWORD *)a2 + 2);
if ( v6 > 0x17 )
{
load_idt(a3);
last_R_0 = (__int128)_mm_loadu_si128(a3);
xmmword_8F0 = (__int128)_mm_loadu_si128(a3 + 1);
xmmword_900 = (__int128)_mm_loadu_si128(a3 + 2);
xmmword_910 = (__int128)_mm_loadu_si128(a3 + 3);
}
}
}
++v5;
memset(&readfds, 0, sizeof(readfds));
v4 = sock;
readfds.fds_bits[sock / 64] |= 1LL << (sock % 64);
}
result = 1LL;
if ( !v5 )
{
LABEL_13:
*(_QWORD *)a2 = last_p_1;
*((_DWORD *)a2 + 2) = dword_928;
result = 0LL;
*a3 = _mm_load_si128((const __m128i *)&last_R_0);
a3[1] = _mm_load_si128((const __m128i *)&xmmword_8F0);
a3[2] = _mm_load_si128((const __m128i *)&xmmword_900);
a3[3] = _mm_load_si128((const __m128i *)&xmmword_910);
}
}
else
{
v8 = (char *)tracker + *((unsigned int *)tracker + 2) + (unsigned __int64)(*((_DWORD *)tracker + 3) * a1);
func1((__int64)a3, (__int64)(v8 + 12), a1);
func2(a2, (__int64)v8, 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)
{
__int64 result; // rax
char *v3; // rax
int v4; // xmm0_4

if ( control == (void *)-1LL || *((_DWORD *)control + 4) - 1 <= a1 )
return 0LL;
v3 = (char *)control + *((unsigned int *)control + 2);
*a2 = *(_DWORD *)&v3[4 * a1];
v4 = *(_DWORD *)&v3[4 * a1 + 4];
result = 1LL;
a2[1] = v4 ^ LC3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, _DWORD *a2)
{
__int64 result; // rax
char *v3; // rax
int v4; // xmm0_4

if ( control == (void *)-1LL || *((_DWORD *)control + 4) - 1 <= a1 )
return 0LL;
v3 = (char *)control + *((unsigned int *)control + 2);
*a2 = *(_DWORD *)&v3[4 * a1];
v4 = *(_DWORD *)&v3[4 * a1 + 4];
result = 1LL;
a2[1] = v4 ^ LC3;
return result;
}

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 *