decompiled_code:
__int64 g_frame()
{
return g_zawarudo_frame();
}

canonical_decompiled_code:
__int64 func0()
{
return g_zawarudo_frame();
}

original_code:
void g_frame(struct game* g, unsigned long dt)
{
 g_zawarudo_frame(&g->zawarudo, dt);
}

canonical_original_code:
void g_frame(struct game *g, unsigned long dt)
{
 g_zawarudo_frame(&g->zawarudo, dt);
}

variable_types: struct game { struct g_zawarudo { struct llist { struct llist_node { void *ptr; struct llist_node *next; } *root; unsigned int len; } entl; unsigned int next_id; } zawarudo; struct g_player { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned long walk_dt; float walk_v[2]; struct llist inventory; } *player; } *

user_defined_types: struct game { struct g_zawarudo zawarudo; struct g_player *player; }

user_defined_types: struct g_zawarudo { struct llist entl; unsigned int next_id; }

user_defined_types: struct llist { struct llist_node *root; unsigned int len; }


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

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

original_code:
int g_fini(struct game* g)
{
 return 0;
}

canonical_original_code:
int g_fini(struct game *g)
{
 return 0;
}

return_type: int

user_defined_types: struct g_player { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned long walk_dt; float walk_v[2]; struct llist inventory; }

user_defined_types: struct llist_node { void *ptr; struct llist_node *next; }


decompiled_code:
__int64 __fastcall g_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
return 0LL;
}

original_code:
int g_init(struct game* g)
{
 memset(g, 0, sizeof (struct game));
 return 0;
}

canonical_original_code:
int g_init(struct game *g)
{
 memset(g, 0, sizeof (struct game));
 return 0;
}


decompiled_code:
const char *__fastcall j0g(const char *a1, _WORD *a2, unsigned int a3)
{
size_t v4; // rax

if ( a1 )
{
v4 = strlen(a1);
if ( (unsigned int)js0n(a1, v4, a2, a3) )
*a2 = 0;
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1, _WORD *a2, unsigned int a3)
{
size_t v4; // rax

if ( a1 )
{
v4 = strlen(a1);
if ( (unsigned int)js0n(a1, v4, a2, a3) )
*a2 = 0;
}
return a1;
}

original_code:
char *j0g(const char *json, unsigned short *index, int ilen)
{
  int ret, len;
  if(!json) return ((void *)0);
  len = strlen(json);
  ret = js0n((unsigned char*)json, len, index, ilen);
  if(ret) *index = 0;
  return (char*)json;
}

canonical_original_code:
char *j0g(char *json, unsigned short *index, int ilen)
{
  int ret; int len;
  if(!json) return ((void *)0);
  len = strlen(json);
  ret = js0n((unsigned char *)json, len, index, ilen);
  if(ret) *index = 0;
  return (char *)json;
}

variable_types:
json
char *

variable_types:
index
unsigned short *

variable_types: ilen int

variable_types: ret int

variable_types: len int

return_type: char *


original_code:
char *j0g_safe(int val, char *json, const unsigned short *index)
{
  char *str, *cursor;
  *(json+(index[val]+index[val+1])) = 0;
  for(cursor=str=json+index[val]; *cursor; cursor++,str++)
  {
    if(*cursor == '\\' && *(cursor+1) == 'n')
    {
      *str = '\n';
      cursor++;
    }else if(*cursor == '\\' && *(cursor+1) == '"'){
      *str = '"';
      cursor++;
    }else{
      *str = *cursor;
    }
  }
  *str = *cursor;
  return (char*)json+index[val];
}

canonical_original_code:
char *j0g_safe(int val, char *json, unsigned short *index)
{
  char *str; char *cursor;
  *(json+(index[val]+index[val+1])) = 0;
  for(cursor=str=json+index[val]; *cursor; cursor++,str++)
  {
    if(*cursor == '\\' && *(cursor+1) == 'n')
    {
      *str = '\n';
      cursor++;
    }else if(*cursor == '\\' && *(cursor+1) == '"'){
      *str = '"';
      cursor++;
    }else{
      *str = *cursor;
    }
  }
  *str = *cursor;
  return (char *)json+index[val];
}

variable_types: val int

variable_types:
str
char *

variable_types:
cursor
char *


decompiled_code:
__int64 __fastcall j0g_val(char *s1, __int64 a2, unsigned __int16 *a3)
{
int v4; // eax
int v5; // er12
unsigned __int16 v6; // si
__int64 v7; // rbx
size_t v8; // r15

if ( !s1 || !a2 )
return 0LL;
v4 = strlen(s1);
v5 = v4;
v6 = *a3;
if ( !*a3 )
return 0LL;
v7 = 0LL;
v8 = v4;
do
{
if ( a3[v7 + 1] == v5 && !strncmp(s1, (const char *)(a2 + v6), v8) )
return (unsigned int)(v7 + 2);
v7 += 4LL;
v6 = a3[v7];
}
while ( v6 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1, __int64 a2, unsigned __int16 *a3)
{
int v4; // eax
int v5; // er12
unsigned __int16 v6; // si
__int64 v7; // rbx
size_t v8; // r15

if ( !s1 || !a2 )
return 0LL;
v4 = strlen(s1);
v5 = v4;
v6 = *a3;
if ( !*a3 )
return 0LL;
v7 = 0LL;
v8 = v4;
do
{
if ( a3[v7 + 1] == v5 && !strncmp(s1, (const char *)(a2 + v6), v8) )
return (unsigned int)(v7 + 2);
v7 += 4LL;
v6 = a3[v7];
}
while ( v6 );
return 0LL;
}

original_code:
int j0g_val(const char *key, const char *json, const unsigned short *index)
{
  if(!key || !json) return 0;
  int i, klen = strlen(key);
 for(i=0;index[i];i+=4)
 {
    if(klen == index[i+1] && strncmp(key,(char*)json+index[i],klen) == 0) return i+2;
 }
  return 0;
}

canonical_original_code:
int j0g_val(char *key, char *json, unsigned short *index)
{
  if(!key || !json) return 0;
  int i; int klen = strlen(key);
 for(i=0;index[i];i+=4)
 {
    if(klen == index[i+1] && strncmp(key,(char *)json+index[i],klen) == 0) return i+2;
 }
  return 0;
}

variable_types:
key
char *

variable_types: i int

variable_types: klen int


decompiled_code:
__int64 __fastcall j0g_str(char *a1, __int64 a2, unsigned __int16 *a3)
{
int v4; // edi
__int64 result; // rax

v4 = j0g_val(a1, a2, a3);
result = 0LL;
if ( v4 )
result = j0g_safe(v4, a2, (__int64)a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, __int64 a2, unsigned __int16 *a3)
{
int v4; // edi
__int64 result; // rax

v4 = func2(a1, a2, a3);
result = 0LL;
if ( v4 )
result = func1(v4, a2, (__int64)a3);
return result;
}

original_code:
char *j0g_str(const char *key, char *json, const unsigned short *index)
{
  int val = j0g_val(key, json, index);
  if(!val) return ((void *)0);
  return j0g_safe(val, json, index);
}

canonical_original_code:
char *j0g_str(char *key, char *json, unsigned short *index)
{
  int val = j0g_val(key, json, index);
  if(!val) return ((void *)0);
  return j0g_safe(val, json, index);
}


decompiled_code:
_BOOL8 __fastcall j0g_test(char *a1, __int64 a2, unsigned __int16 *a3)
{
const char *v3; // rax
_BOOL4 v4; // ecx

v3 = (const char *)j0g_str(a1, a2, a3);
if ( !v3 )
return 0;
v4 = 1;
if ( strcmp(v3, "true") )
v4 = strcmp(v3, "1") == 0;
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *a1, __int64 a2, unsigned __int16 *a3)
{
const char *v3; // rax
_BOOL4 v4; // ecx

v3 = (const char *)func3(a1, a2, a3);
if ( !v3 )
return 0;
v4 = 1;
if ( strcmp(v3, "true") )
v4 = strcmp(v3, "1") == 0;
return v4;
}

original_code:
int j0g_test(const char *key, char *json, const unsigned short *index)
{
  char *val = j0g_str(key, json, index);
  if(!val) return 0;
  if(strcmp(val, "true") == 0) return 1;
  if(strcmp(val, "1") == 0) return 1;
  return 0;
}

canonical_original_code:
int j0g_test(char *key, char *json, unsigned short *index)
{
  char *val = j0g_str(key, json, index);
  if(!val) return 0;
  if(strcmp(val, "true") == 0) return 1;
  if(strcmp(val, "1") == 0) return 1;
  return 0;
}

variable_types:
val
char *


decompiled_code:
__int64 __fastcall g_zawarudo_entl(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1;
}

original_code:
struct llist* g_zawarudo_entl(struct g_zawarudo* z)
{
 return &z->entl;
}

canonical_original_code:
struct llist *g_zawarudo_entl(struct g_zawarudo *z)
{
 return &z->entl;
}

variable_types: struct g_zawarudo { struct llist entl; unsigned int next_id; } *

return_type: struct llist { struct llist_node { void *ptr; struct llist_node *next; } *root; unsigned int len; } *


decompiled_code:
__int64 __fastcall g_zawarudo_add(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a2 + 4) = v2;
*(_DWORD *)(a1 + 16) = v2 + 1;
return llist_add(a1, *(unsigned int *)(a1 + 8), a2);
}

original_code:
void g_zawarudo_add(struct g_zawarudo* z, struct g_entity* e)
{
 e->id = z->next_id;
 ++z->next_id;
 llist_add((&z->entl), (&z->entl)->len, (e));;
}

canonical_original_code:
void g_zawarudo_add(struct g_zawarudo *z, struct g_entity *e)
{
 e->id = z->next_id;
 ++z->next_id;
 llist_add((&z->entl), (&z->entl)->len, (e));;
}

variable_types: struct g_zawarudo { struct llist { struct llist_node { void *ptr; struct llist_node *next; } *root; unsigned int len; } entl; unsigned int next_id; } *

variable_types: struct g_entity { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; } *

return_type: void


decompiled_code:
void g_zawarudo_remove()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void g_zawarudo_remove(struct g_zawarudo* z, struct g_entity* e)
{
}

canonical_original_code:
void g_zawarudo_remove(struct g_zawarudo *z, struct g_entity *e)
{
}

user_defined_types: struct g_entity { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; }


decompiled_code:
__int64 __fastcall g_zawarudo_find(_QWORD **a1, unsigned int a2)
{
_QWORD *v2; // rax
__int64 v3; // rcx
unsigned int v4; // edx

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *v2;
v4 = *(_DWORD *)(*v2 + 4LL);
if ( v4 == a2 )
break;
if ( v4 > a2 )
return 0LL;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD **a1, unsigned int a2)
{
_QWORD *v2; // rax
__int64 v3; // rcx
unsigned int v4; // edx

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *v2;
v4 = *(_DWORD *)(*v2 + 4LL);
if ( v4 == a2 )
break;
if ( v4 > a2 )
return 0LL;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
struct g_entity* g_zawarudo_find(struct g_zawarudo* z, unsigned id)
{
 struct llist_node* n;
 for (n = z->entl.root; n != ((void *)0); n = n->next)
 {
  if (((struct g_entity*) n->ptr)->id == id)
   return ((struct g_entity*) n->ptr);
  if (((struct g_entity*) n->ptr)->id > id)
   return ((void *)0);
 }
 return ((void *)0);
}

canonical_original_code:
struct g_entity *g_zawarudo_find(struct g_zawarudo *z, unsigned int id)
{
 struct llist_node *n;
 for (n = z->entl.root; n != ((void *)0); n = n->next)
 {
  if (((struct g_entity *) n->ptr)->id == id)
   return ((struct g_entity *) n->ptr);
  if (((struct g_entity *) n->ptr)->id > id)
   return ((void *)0);
 }
 return ((void *)0);
}

variable_types:
id
unsigned int

variable_types: struct llist_node { void *ptr; struct llist_node *next; } *

return_type: struct g_entity { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; } *


decompiled_code:
__int64 __fastcall intersect3(float *a1, float *a2, float *a3, float *a4, float *a5, float *a6)
{
float v6; // xmm0_4
__int64 result; // rax
float v8; // xmm3_4

if ( a3 > a4 )
_assert_fail("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 0x3Du, "intersect3");
if ( a5 > a6 )
_assert_fail("!(b1 > b2)", "sauce/game/g_entity/g_entity.c", 0x3Eu, "intersect3");
v6 = *a4;
result = 0LL;
if ( *a5 < *a4 )
{
v8 = *a6;
if ( *a3 < *a6 )
{
*a1 = fmaxf(*a3, *a5);
*a2 = fminf(v6, v8);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(float *a1, float *a2, float *a3, float *a4, float *a5, float *a6)
{
float v6; // xmm0_4
__int64 result; // rax
float v8; // xmm3_4

if ( a3 > a4 )
_assert_fail("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 0x3Du, "intersect3");
if ( a5 > a6 )
_assert_fail("!(b1 > b2)", "sauce/game/g_entity/g_entity.c", 0x3Eu, "intersect3");
v6 = *a4;
result = 0LL;
if ( *a5 < *a4 )
{
v8 = *a6;
if ( *a3 < *a6 )
{
*a1 = fmaxf(*a3, *a5);
*a2 = fminf(v6, v8);
result = 1LL;
}
}
return result;
}

original_code:
static inline _Bool intersect3(
  float* restrict c1, float* restrict c2,
  float* restrict a1, float* restrict a2,
  float* restrict b1, float* restrict b2)
{
 ((!(a1 > a2)) ? (void) (0) : __assert_fail ("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 61, __extension__ __PRETTY_FUNCTION__));
 ((!(b1 > b2)) ? (void) (0) : __assert_fail ("!(b1 > b2)", "sauce/game/g_entity/g_entity.c", 62, __extension__ __PRETTY_FUNCTION__));
 if ((*a2) <= (*b1))
  return 0;
 if ((*b2) <= (*a1))
  return 0;
 (*c1) = (((*a1)) > ((*b1)) ? ((*a1)) : ((*b1)));
 (*c2) = (((*a2)) < ((*b2)) ? ((*a2)) : ((*b2)));
 return 1;
}


decompiled_code:
__int64 __fastcall intersect2(float *a1, float *a2, float *a3, float *a4, float *a5, float *a6)
{
float v6; // xmm0_4

if ( a3 > a4 )
_assert_fail("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 0x54u, "intersect2");
v6 = *a5;
if ( *a5 > *a6 )
{
*a5 = *a6;
*a6 = v6;
}
return intersect3(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1, float *a2, float *a3, float *a4, float *a5, float *a6)
{
float v6; // xmm0_4

if ( a3 > a4 )
_assert_fail("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 0x54u, "intersect2");
v6 = *a5;
if ( *a5 > *a6 )
{
*a5 = *a6;
*a6 = v6;
}
return func0(a1, a2, a3, a4, a5, a6);
}

original_code:
static inline _Bool intersect2(
  float* restrict c1, float* restrict c2,
  float* restrict a1, float* restrict a2,
  float* restrict b1, float* restrict b2)
{
 ((!(a1 > a2)) ? (void) (0) : __assert_fail ("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 84, __extension__ __PRETTY_FUNCTION__));
 if ((*b1) > (*b2))
 {
  float tmp;
  tmp = (*b1);
  (*b1) = (*b2);
  (*b2) = tmp;
 }
 return intersect3(c1, c2, a1, a2, b1, b2);
}

canonical_original_code:
static inline _Bool intersect2(float *c1, float *c2, float *a1, float *a2, float *b1, float *b2)
{
 ((!(a1 > a2)) ? (void) (0) : __assert_fail ("!(a1 > a2)", "sauce/game/g_entity/g_entity.c", 84, __extension__ __PRETTY_FUNCTION__));
 if ((*b1) > (*b2))
 {
  float tmp;
  tmp = (*b1);
  (*b1) = (*b2);
  (*b2) = tmp;
 }
 return intersect3(c1, c2, a1, a2, b1, b2);
}

variable_types: tmp float


intersect

decompiled_code:
__int64 __fastcall intersect(float *a1, float *a2, float *a3, float *a4, float *a5, float *a6)
{
float v6; // xmm0_4

v6 = *a3;
if ( *a3 > *a4 )
{
*a3 = *a4;
*a4 = v6;
}
return intersect2(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func2(float *a1, float *a2, float *a3, float *a4, float *a5, float *a6)
{
float v6; // xmm0_4

v6 = *a3;
if ( *a3 > *a4 )
{
*a3 = *a4;
*a4 = v6;
}
return func1(a1, a2, a3, a4, a5, a6);
}

original_code:
static inline _Bool intersect(
  float* restrict c1, float* restrict c2,
  float* restrict a1, float* restrict a2,
  float* restrict b1, float* restrict b2)
{
 if ((*a1) > (*a2))
 {
  float tmp;
  tmp = (*a1);
  (*a1) = (*a2);
  (*a2) = tmp;
 }
 return intersect2(c1, c2, a1, a2, b1, b2);
}

canonical_original_code:
static inline _Bool intersect(float *c1, float *c2, float *a1, float *a2, float *b1, float *b2)
{
 if ((*a1) > (*a2))
 {
  float tmp;
  tmp = (*a1);
  (*a1) = (*a2);
  (*a2) = tmp;
 }
 return intersect2(c1, c2, a1, a2, b1, b2);
}


decompiled_code:
__int64 __fastcall sweep_aabb(float *a1, __int64 a2, __int64 a3, __int64 a4, _DWORD *a5)
{
unsigned int v8; // ebx
float v10; // [rsp+0h] [rbp-48h] BYREF
float v11; // [rsp+4h] [rbp-44h] BYREF
float v12; // [rsp+8h] [rbp-40h] BYREF
float v13[3]; // [rsp+Ch] [rbp-3Ch] BYREF
float v14; // [rsp+18h] [rbp-30h] BYREF
float v15[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v2sub(&v10, a4, a3 + 8);
v2sub(&v12, a4 + 8, a3);
v2div(&v10, &v10, a5);
v2div(&v12, &v12, a5);
v8 = intersect(v15, &v14, &v10, &v12, &v11, v13);
if ( (_BYTE)v8 )
{
v2set(a2, 1.0);
if ( v15[0] > v11 )
{
v2set(a2, COERCE_FLOAT((*a5 & LC4 | LC5) ^ LC4));
}
else if ( v15[0] <= v10 )
{
v2set(a2, COERCE_FLOAT((*a5 & LC4 | LC7) ^ LC4));
}
else
{
v2set(a2, 0.0);
}
*a1 = v15[0];
}
return v8;
}

variable_types:
n
float *

variable_types:
a
float (*)[2]

variable_types:
b
float (*)[2]

variable_types:
v
float *

variable_types:
t
float [2][2]


original_code:
_Bool g_entity_collide(
  float* restrict t,
  float* restrict n,
  struct g_entity* e1,
  struct g_entity* e2
  )
{
 float a[2][2], b[2][2], v[2];
 v2add(a[0], e1->p, e1->boxxy[0]);
 v2add(a[1], a[0], e1->boxxy[1]);
 v2add(b[0], e2->p, e2->boxxy[0]);
 v2add(b[1], b[0], e2->boxxy[1]);
 memcpy(v, e1->v, sizeof(float[2]));
 v2sub(v, v, e2->v);
 return sweep_aabb(t, n, a, b, v);
}

canonical_original_code:
_Bool g_entity_collide(float *t, float *n, struct g_entity *e1, struct g_entity *e2)
{
 float a[2][2]; float b[2][2]; float v[2];
 v2add(a[0], e1->p, e1->boxxy[0]);
 v2add(a[1], a[0], e1->boxxy[1]);
 v2add(b[0], e2->p, e2->boxxy[0]);
 v2add(b[1], b[0], e2->boxxy[1]);
 memcpy(v, e1->v, sizeof(float [2]));
 v2sub(v, v, e2->v);
 return sweep_aabb(t, n, a, b, v);
}

variable_types:
t
float *

variable_types:
a
float [2][2]

variable_types:
b
float [2][2]

variable_types:
v
float [2]


decompiled_code:
__int64 __fastcall g_entity_frame(_DWORD *a1, __int64 a2, __int64 a3)
{
if ( *a1 == 2 )
return g_player_frame(a1, a3);
if ( (unsigned int)(*a1 - 3) > 2 )
_assert_fail("false", "sauce/game/g_entity/g_entity.c", 0xC7u, "g_entity_frame");
return g_terrain_frame(a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, __int64 a2, __int64 a3)
{
if ( *a1 == 2 )
return g_player_frame(a1, a3);
if ( (unsigned int)(*a1 - 3) > 2 )
_assert_fail("false", "sauce/game/g_entity/g_entity.c", 0xC7u, "g_entity_frame");
return g_terrain_frame(a1, a3);
}

original_code:
void g_entity_frame(struct g_entity* e, struct g_zawarudo* z, unsigned long dt)
{
 switch (e->type)
 {
 case G_PLAYER:
  g_player_frame((struct g_player*) e, dt);
  break;
 case G_TERRAIN:
 case G_DIRT:
 case G_BRICKS:
  g_terrain_frame((struct g_terrain*) e, dt);
  break;
 default:
  ((0) ? (void) (0) : __assert_fail ("false", "sauce/game/g_entity/g_entity.c", 199, __extension__ __PRETTY_FUNCTION__));
 }
}

canonical_original_code:
void g_entity_frame(struct g_entity *e, struct g_zawarudo *z, unsigned long dt)
{
 switch (e->type)
 {
 case G_PLAYER:
  g_player_frame((struct g_player *) e, dt);
  break;
 case G_TERRAIN:
 case G_DIRT:
 case G_BRICKS:
  g_terrain_frame((struct g_terrain *) e, dt);
  break;
 default:
  ((0) ? (void) (0) : __assert_fail ("false", "sauce/game/g_entity/g_entity.c", 199, __extension__ __PRETTY_FUNCTION__));
 }
}

variable_types:
dt
unsigned long

user_defined_types: struct g_terrain { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned int vertc; float (*vertv)[2]; }


original_code:
int g_entity_from_jason(
  struct g_entity* e,
  char* jason,
  unsigned short* index
  )
{
 { int val = j0g_val("p", jason, index); { char* sjason; unsigned slen; sjason = jason + index[val]; slen = index[val+1]; unsigned short sindex[slen]; int js0n_r = js0n((const unsigned char*) (sjason), (slen), (sindex), (slen)); (void) js0n_r;;
 j0g2_vec(e->p, 2, sjason, sindex);
 }; };
 fprintf(stderr, "p: %G, %G\n", e->p[0], e->p[1]);
 { int val = j0g_val("boxxy", jason, index); { char* sjason; unsigned slen; sjason = jason + index[val]; slen = index[val+1]; unsigned short sindex[slen]; int js0n_r = js0n((const unsigned char*) (sjason), (slen), (sindex), (slen)); (void) js0n_r;;
 j0g2_vec(e->boxxy[0], 4, sjason, sindex);
 }; };
 fprintf(stderr, "boxxy: %G, %G, %G, %G\n",
   e->boxxy[0][0],
   e->boxxy[0][1],
   e->boxxy[1][0],
   e->boxxy[1][1]);
 return 0;
}

canonical_original_code:
int g_entity_from_jason(struct g_entity *e, char *jason, unsigned short *index)
{
 { int val = j0g_val("p", jason, index); { char *sjason; unsigned int slen; sjason = jason + index[val]; slen = index[val+1]; unsigned short sindex[-1]; int js0n_r = js0n((const unsigned char*) (sjason), (slen), (sindex), (slen)); (void) js0n_r;;
 j0g2_vec(e->p, 2, sjason, sindex);
 }; };
 fprintf(stderr, "p: %G, %G\n", e->p[0], e->p[1]);
 { int val = j0g_val("boxxy", jason, index); { char *sjason; unsigned int slen; sjason = jason + index[val]; slen = index[val+1]; unsigned short sindex[-1]; int js0n_r = js0n((const unsigned char*) (sjason), (slen), (sindex), (slen)); (void) js0n_r;;
 j0g2_vec(e->boxxy[0], 4, sjason, sindex);
 }; };
 fprintf(stderr, "boxxy: %G, %G, %G, %G\n",
   e->boxxy[0][0],
   e->boxxy[0][1],
   e->boxxy[1][0],
   e->boxxy[1][1]);
 return 0;
}

variable_types:
jason
char *

variable_types:
index
unsigned short *

variable_types: val int

variable_types:
sjason
char *

variable_types:
slen
unsigned int

variable_types:
sindex
unsigned short [-1]


decompiled_code:
void __fastcall g_entity_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
a1[4] = 0LL;
}

original_code:
void g_entity_init(struct g_entity* e)
{
 memset(e, 0, sizeof (struct g_entity));
}

canonical_original_code:
void g_entity_init(struct g_entity *e)
{
 memset(e, 0, sizeof (struct g_entity));
}

variable_types: struct g_entity { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; } *


decompiled_code:
__int64 __fastcall dir_map(int a1)
{
__int64 result; // rax

if ( a1 == 1073741905 )
return 3LL;
if ( a1 > 1073741905 )
{
if ( a1 != 1073741906 )
goto LABEL_8;
result = 1LL;
}
else
{
if ( a1 != 1073741903 )
{
if ( a1 == 1073741904 )
return 2LL;
LABEL_8:
_assert_fail("false", "sauce/ui/ui_game.c", 0x45u, "dir_map");
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax

if ( a1 == 1073741905 )
return 3LL;
if ( a1 > 1073741905 )
{
if ( a1 != 1073741906 )
goto LABEL_8;
result = 1LL;
}
else
{
if ( a1 != 1073741903 )
{
if ( a1 == 1073741904 )
return 2LL;
LABEL_8:
_assert_fail("false", "sauce/ui/ui_game.c", 0x45u, "dir_map");
}
result = 0LL;
}
return result;
}

original_code:
static int dir_map(SDL_Keycode k)
{
 switch (k)
 {
 case SDLK_RIGHT:
  return 0;
 case SDLK_UP:
  return 1;
 case SDLK_LEFT:
  return 2;
 case SDLK_DOWN:
  return 3;
 }
 ((0) ? (void) (0) : __assert_fail ("false", "sauce/ui/ui_game.c", 69, __extension__ __PRETTY_FUNCTION__));
 return -1;
}

canonical_original_code:
static int dir_map(int k)
{
 switch (k)
 {
 case SDLK_RIGHT:
  return 0;
 case SDLK_UP:
  return 1;
 case SDLK_LEFT:
  return 2;
 case SDLK_DOWN:
  return 3;
 }
 ((0) ? (void) (0) : __assert_fail ("false", "sauce/ui/ui_game.c", 69, __extension__ __PRETTY_FUNCTION__));
 return -1;
}

variable_types: k int


decompiled_code:
__int64 __fastcall draw_entity(__int64 a1)
{
__int64 result; // rax

glUniform2fv(r_pos_loc, 1LL, a1 + 8);
if ( *(_DWORD *)a1 == 2 )
{
glUniform4fv(r_color_loc, 1LL, &r_red);
result = r_boxxy(a1 + 24);
}
else if ( *(_DWORD *)a1 == 3 )
{
glUniform4fv(r_color_loc, 1LL, &r_blue);
r_boxxy(a1 + 24);
glUniform4fv(r_color_loc, 1LL, &r_green);
result = r_poly(*(unsigned int *)(a1 + 40), *(_QWORD *)(a1 + 48));
}
else
{
glUniform4fv(r_color_loc, 1LL, &r_green);
result = r_boxxy(a1 + 24);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

glUniform2fv(r_pos_loc, 1LL, a1 + 8);
if ( *(_DWORD *)a1 == 2 )
{
glUniform4fv(r_color_loc, 1LL, &r_red);
result = r_boxxy(a1 + 24);
}
else if ( *(_DWORD *)a1 == 3 )
{
glUniform4fv(r_color_loc, 1LL, &r_blue);
r_boxxy(a1 + 24);
glUniform4fv(r_color_loc, 1LL, &r_green);
result = r_poly(*(unsigned int *)(a1 + 40), *(_QWORD *)(a1 + 48));
}
else
{
glUniform4fv(r_color_loc, 1LL, &r_green);
result = r_boxxy(a1 + 24);
}
return result;
}

original_code:
static void draw_entity(struct g_entity* e)
{
 struct g_terrain* terr;
 terr = (struct g_terrain*) e;
 glUniform2fv(r_pos_loc, 1, (e->p));
 switch (e->type)
 {
 case G_PLAYER:
  glUniform4fv(r_color_loc, 1, (r_red));
  r_boxxy(e->boxxy);
  break;
 case G_TERRAIN:
  glUniform4fv(r_color_loc, 1, (r_blue));
  r_boxxy(e->boxxy);
  glUniform4fv(r_color_loc, 1, (r_green));
  r_poly(terr->vertc, terr->vertv);
  break;
 case G_DIRT:
 case G_BRICKS:
 default:
  glUniform4fv(r_color_loc, 1, (r_green));
  r_boxxy(e->boxxy);
 }
}

canonical_original_code:
static void draw_entity(struct g_entity *e)
{
 struct g_terrain *terr;
 terr = (struct g_terrain *) e;
 glUniform2fv(r_pos_loc, 1, (e->p));
 switch (e->type)
 {
 case G_PLAYER:
  glUniform4fv(r_color_loc, 1, (r_red));
  r_boxxy(e->boxxy);
  break;
 case G_TERRAIN:
  glUniform4fv(r_color_loc, 1, (r_blue));
  r_boxxy(e->boxxy);
  glUniform4fv(r_color_loc, 1, (r_green));
  r_poly(terr->vertc, terr->vertv);
  break;
 case G_DIRT:
 case G_BRICKS:
 default:
  glUniform4fv(r_color_loc, 1, (r_green));
  r_boxxy(e->boxxy);
 }
}

variable_types: struct g_terrain { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned int vertc; float (*vertv)[2]; } *


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

result = (unsigned int)(a2 - 1073741903);
if ( (unsigned int)result <= 3 )
{
result = (int)dir_map(a2);
*(_BYTE *)(a1 + (int)result + 8) = 1;
}
return result;
}

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

result = (unsigned int)(a2 - 1073741903);
if ( (unsigned int)result <= 3 )
{
result = (int)func0(a2);
*(_BYTE *)(a1 + (int)result + 8) = 1;
}
return result;
}

original_code:
void ui_game_keydown(struct ui_game* ui_g, SDL_Keycode k)
{
 switch (k)
 {
 case SDLK_RIGHT:
 case SDLK_LEFT:
 case SDLK_UP:
 case SDLK_DOWN:
  ui_g->player_walk[dir_map(k)] = 1;
  break;
 }
}

canonical_original_code:
void ui_game_keydown(struct ui_game *ui_g, int k)
{
 switch (k)
 {
 case SDLK_RIGHT:
 case SDLK_LEFT:
 case SDLK_UP:
 case SDLK_DOWN:
  ui_g->player_walk[dir_map(k)] = 1;
  break;
 }
}

variable_types: struct ui_game { struct game { struct g_zawarudo { struct llist { struct llist_node { void *ptr; struct llist_node *next; } *root; unsigned int len; } entl; unsigned int next_id; } zawarudo; struct g_player { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned long walk_dt; float walk_v[2]; struct llist inventory; } *player; } *g; _Bool player_walk[4]; } *

user_defined_types: struct ui_game { struct game *g; _Bool player_walk[4]; }


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

result = (unsigned int)(a2 - 1073741903);
if ( (unsigned int)result <= 3 )
{
result = (int)dir_map(a2);
*(_BYTE *)(a1 + (int)result + 8) = 0;
}
return result;
}

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

result = (unsigned int)(a2 - 1073741903);
if ( (unsigned int)result <= 3 )
{
result = (int)func0(a2);
*(_BYTE *)(a1 + (int)result + 8) = 0;
}
return result;
}

original_code:
void ui_game_keyup(struct ui_game* ui_g, SDL_Keycode k)
{
 switch (k)
 {
 case SDLK_RIGHT:
 case SDLK_LEFT:
 case SDLK_UP:
 case SDLK_DOWN:
  ui_g->player_walk[dir_map(k)] = 0;
  break;
 }
}

canonical_original_code:
void ui_game_keyup(struct ui_game *ui_g, int k)
{
 switch (k)
 {
 case SDLK_RIGHT:
 case SDLK_LEFT:
 case SDLK_UP:
 case SDLK_DOWN:
  ui_g->player_walk[dir_map(k)] = 0;
  break;
 }
}


decompiled_code:
void __fastcall v2set(float *a1, float a2, float a3)
{
*a1 = a2;
a1[1] = a3;
}

canonical_decompiled_code:
void __fastcall func0(float *a1, float a2, float a3)
{
*a1 = a2;
a1[1] = a3;
}

original_code:
void v2set(float *a, float x, float y)
{
 a[0] = x;
 a[1] = y;
}

variable_types:
a
float *

variable_types: x float

variable_types: y float


decompiled_code:
void __fastcall v2sprod(float *a1, float *a2, float a3)
{
*a1 = a3 * *a2;
a1[1] = a3 * a2[1];
}

canonical_decompiled_code:
void __fastcall func1(float *a1, float *a2, float a3)
{
*a1 = a3 * *a2;
a1[1] = a3 * a2[1];
}

original_code:
void v2sprod(float* restrict a, const float* b, float c)
{
 a[0] = b[0] * c;
 a[1] = b[1] * c;
}

canonical_original_code:
void v2sprod(float *a, float *b, float c)
{
 a[0] = b[0] * c;
 a[1] = b[1] * c;
}

variable_types:
b
float *

variable_types: c float


decompiled_code:
float __fastcall v2dprod(float *a1, float *a2)
{
return (float)(*a1 * *a2) + (float)(a1[1] * a2[1]);
}

canonical_decompiled_code:
float __fastcall func2(float *a1, float *a2)
{
return (float)(*a1 * *a2) + (float)(a1[1] * a2[1]);
}

original_code:
float v2dprod(const float* a, const float* b)
{
 return a[0] * b[0] + a[1] * b[1];
}

canonical_original_code:
float v2dprod(float *a, float *b)
{
 return a[0] * b[0] + a[1] * b[1];
}

return_type: float


decompiled_code:
void __fastcall v2add(float *a1, float *a2, float *a3)
{
*a1 = *a2 + *a3;
a1[1] = a2[1] + a3[1];
}

canonical_decompiled_code:
void __fastcall func3(float *a1, float *a2, float *a3)
{
*a1 = *a2 + *a3;
a1[1] = a2[1] + a3[1];
}

original_code:
void v2add(float* restrict a, const float* b, const float* c)
{
 a[0] = b[0] + c[0];
 a[1] = b[1] + c[1];
}

variable_types:
c
float *


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

canonical_decompiled_code:
void __fastcall func4(float *a1, float *a2, float *a3)
{
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
}

original_code:
void v2sub(float* restrict a, const float* b, const float* c)
{
 a[0] = b[0] - c[0];
 a[1] = b[1] - c[1];
}


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

canonical_decompiled_code:
void __fastcall func5(float *a1, float *a2, float *a3)
{
*a1 = *a2 / *a3;
a1[1] = a2[1] / a3[1];
}

original_code:
void v2div(float* restrict a, const float* b, const float* c)
{
 a[0] = b[0] / c[0];
 a[1] = b[1] / c[1];
}


decompiled_code:
void __fastcall v2lin(float *a1, float *a2, float *a3, float a4, float a5)
{
*a1 = (float)(a4 * *a2) + (float)(a5 * *a3);
a1[1] = (float)(a4 * a2[1]) + (float)(a5 * a3[1]);
}

canonical_decompiled_code:
void __fastcall func6(float *a1, float *a2, float *a3, float a4, float a5)
{
*a1 = (float)(a4 * *a2) + (float)(a5 * *a3);
a1[1] = (float)(a4 * a2[1]) + (float)(a5 * a3[1]);
}

original_code:
void v2lin(float* restrict a, const float* b, const float c, const float* d, const float e)
{
 a[0] = b[0] * c + d[0] * e;
 a[1] = b[1] * c + d[1] * e;
}

canonical_original_code:
void v2lin(float *a, float *b, float c, float *d, float e)
{
 a[0] = b[0] * c + d[0] * e;
 a[1] = b[1] * c + d[1] * e;
}

variable_types:
d
float *

variable_types: e float


decompiled_code:
float *__fastcall m4sprod(float *a1, float *a2, float a3)
{
float *result; // rax
float *v4; // rsi

result = a2;
v4 = a2 + 16;
do
{
*a1 = a3 * *result;
a1[1] = a3 * result[1];
a1[2] = a3 * result[2];
a1[3] = a3 * result[3];
result += 4;
a1 += 4;
}
while ( result != v4 );
return result;
}

canonical_decompiled_code:
float *__fastcall func7(float *a1, float *a2, float a3)
{
float *result; // rax
float *v4; // rsi

result = a2;
v4 = a2 + 16;
do
{
*a1 = a3 * *result;
a1[1] = a3 * result[1];
a1[2] = a3 * result[2];
a1[3] = a3 * result[3];
result += 4;
a1 += 4;
}
while ( result != v4 );
return result;
}

variable_types:
A
float *

variable_types:
B
float *

variable_types:
j
unsigned int


variable_types:
C
float *


decompiled_code:
float *__fastcall m4lerp(float *a1, float *a2, float *a3, float a4)
{
int v5[5]; // [rsp+8h] [rbp-50h] BYREF
float v6; // [rsp+1Ch] [rbp-3Ch]
float v7; // [rsp+30h] [rbp-28h]
float v8; // [rsp+44h] [rbp-14h]

m4sprod((float *)v5, a3, a4);
*(float *)v5 = (float)(1.0 - a4) + *(float *)v5;
v6 = (float)(1.0 - a4) + v6;
v7 = (float)(1.0 - a4) + v7;
v8 = (float)(1.0 - a4) + v8;
return m4prod(a1, (float *)v5, a2);
}

canonical_decompiled_code:
float *__fastcall func11(float *a1, float *a2, float *a3, float a4)
{
int v5[5]; // [rsp+8h] [rbp-50h] BYREF
float v6; // [rsp+1Ch] [rbp-3Ch]
float v7; // [rsp+30h] [rbp-28h]
float v8; // [rsp+44h] [rbp-14h]

func7((float *)v5, a3, a4);
*(float *)v5 = (float)(1.0 - a4) + *(float *)v5;
v6 = (float)(1.0 - a4) + v6;
v7 = (float)(1.0 - a4) + v7;
v8 = (float)(1.0 - a4) + v8;
return func10(a1, (float *)v5, a2);
}

original_code:
void m4lerp(float* restrict R, const float* T, const float* dT, float t)
{
 float tmp[16], one_minus_t;
 m4sprod(tmp, dT, t);
 one_minus_t = 1 - t;
 (tmp)[(0) + (0)*(4)] += one_minus_t;
 (tmp)[(1) + (1)*(4)] += one_minus_t;
 (tmp)[(2) + (2)*(4)] += one_minus_t;
 (tmp)[(3) + (3)*(4)] += one_minus_t;
 m4prod(R, tmp, T);
}

canonical_original_code:
void m4lerp(float *R, float *T, float *dT, float t)
{
 float tmp[16]; float one_minus_t;
 m4sprod(tmp, dT, t);
 one_minus_t = 1 - t;
 (tmp)[(0) + (0)*(4)] += one_minus_t;
 (tmp)[(1) + (1)*(4)] += one_minus_t;
 (tmp)[(2) + (2)*(4)] += one_minus_t;
 (tmp)[(3) + (3)*(4)] += one_minus_t;
 m4prod(R, tmp, T);
}

variable_types:
R
float *

variable_types:
T
float *

variable_types:
dT
float *

variable_types: t float

variable_types:
tmp
float [16]


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

v2 = *(_QWORD **)a1;
if ( *(_DWORD *)(a1 + 8) <= a2 )
_assert_fail("i < list->len", "sauce/misc/list.c", 0x2Eu, "llist_find");
v3 = a2 - 1;
if ( a2 )
{
if ( !v2 )
LABEL_6:
_assert_fail("node", "sauce/misc/list.c", 0x32u, "llist_find");
while ( 1 )
{
v2 = (_QWORD *)v2[1];
if ( --v3 == -1 )
break;
if ( !v2 )
goto LABEL_6;
}
}
if ( !v2 )
_assert_fail("node", "sauce/misc/list.c", 0x36u, "llist_find");
return *v2;
}

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

v2 = *(_QWORD **)a1;
if ( *(_DWORD *)(a1 + 8) <= a2 )
_assert_fail("i < list->len", "sauce/misc/list.c", 0x2Eu, "llist_find");
v3 = a2 - 1;
if ( a2 )
{
if ( !v2 )
LABEL_6:
_assert_fail("node", "sauce/misc/list.c", 0x32u, "llist_find");
while ( 1 )
{
v2 = (_QWORD *)v2[1];
if ( --v3 == -1 )
break;
if ( !v2 )
goto LABEL_6;
}
}
if ( !v2 )
_assert_fail("node", "sauce/misc/list.c", 0x36u, "llist_find");
return *v2;
}

original_code:
void* llist_find(struct llist* list, unsigned i)
{
 struct llist_node* node = list->root;
 ((i < list->len) ? (void) (0) : __assert_fail ("i < list->len", "sauce/misc/list.c", 46, __extension__ __PRETTY_FUNCTION__));
 while (i--)
 {
  ((node) ? (void) (0) : __assert_fail ("node", "sauce/misc/list.c", 50, __extension__ __PRETTY_FUNCTION__));
  node = node->next;
 }
 ((node) ? (void) (0) : __assert_fail ("node", "sauce/misc/list.c", 54, __extension__ __PRETTY_FUNCTION__));
 return node->ptr;
}

canonical_original_code:
void *llist_find(struct llist *list, unsigned int i)
{
 struct llist_node *node = list->root;
 ((i < list->len) ? (void) (0) : __assert_fail ("i < list->len", "sauce/misc/list.c", 46, __extension__ __PRETTY_FUNCTION__));
 while (i--)
 {
  ((node) ? (void) (0) : __assert_fail ("node", "sauce/misc/list.c", 50, __extension__ __PRETTY_FUNCTION__));
  node = node->next;
 }
 ((node) ? (void) (0) : __assert_fail ("node", "sauce/misc/list.c", 54, __extension__ __PRETTY_FUNCTION__));
 return node->ptr;
}

variable_types: struct llist { struct llist_node { void *ptr; struct llist_node *next; } *root; unsigned int len; } *

variable_types:
i
unsigned int

return_type: void *


decompiled_code:
__int64 __fastcall alist_find(__int64 a1, unsigned int a2)
{
if ( *(_DWORD *)(a1 + 8) <= a2 )
_assert_fail("i < list->len", "sauce/misc/list.c", 0x3Cu, "alist_find");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
if ( *(_DWORD *)(a1 + 8) <= a2 )
_assert_fail("i < list->len", "sauce/misc/list.c", 0x3Cu, "alist_find");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

original_code:
void* alist_find(struct alist* list, unsigned i)
{
 ((i < list->len) ? (void) (0) : __assert_fail ("i < list->len", "sauce/misc/list.c", 60, __extension__ __PRETTY_FUNCTION__));
 return list->ary[i];
}

canonical_original_code:
void *alist_find(struct alist *list, unsigned int i)
{
 ((i < list->len) ? (void) (0) : __assert_fail ("i < list->len", "sauce/misc/list.c", 60, __extension__ __PRETTY_FUNCTION__));
 return list->ary[i];
}

variable_types: struct alist { void **ary; unsigned int len; } *


decompiled_code:
void *__fastcall alist_add(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // eax
char *v5; // rax
void *result; // rax

v3 = *(_DWORD *)(a1 + 8);
if ( v3 < a2 )
_assert_fail("i <= list->len", "sauce/misc/list.c", 0x65u, "alist_add");
v5 = (char *)realloc(*(void **)a1, 8LL * (v3 + 1));
*(_QWORD *)a1 = v5;
if ( !v5 )
_assert_fail("list->ary", "sauce/misc/list.c", 0x68u, "alist_add");
memmove(&v5[8 * a2 + 8], &v5[8 * a2], *(_DWORD *)(a1 + 8) - a2);
result = *(void **)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // eax
char *v5; // rax
void *result; // rax

v3 = *(_DWORD *)(a1 + 8);
if ( v3 < a2 )
_assert_fail("i <= list->len", "sauce/misc/list.c", 0x65u, "alist_add");
v5 = (char *)realloc(*(void **)a1, 8LL * (v3 + 1));
*(_QWORD *)a1 = v5;
if ( !v5 )
_assert_fail("list->ary", "sauce/misc/list.c", 0x68u, "alist_add");
memmove(&v5[8 * a2 + 8], &v5[8 * a2], *(_DWORD *)(a1 + 8) - a2);
result = *(void **)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void alist_add(struct alist* list, unsigned i, void* ptr)
{
 ((i <= list->len) ? (void) (0) : __assert_fail ("i <= list->len", "sauce/misc/list.c", 101, __extension__ __PRETTY_FUNCTION__));
 list->ary = realloc(list->ary, sizeof (void*) * (list->len + 1));
 ((list->ary) ? (void) (0) : __assert_fail ("list->ary", "sauce/misc/list.c", 104, __extension__ __PRETTY_FUNCTION__));
 memmove(&list->ary[i+1], &list->ary[i], list->len - i);
 list->ary[i] = ptr;
 ++list->len;
}

canonical_original_code:
void alist_add(struct alist *list, unsigned int i, void *ptr)
{
 ((i <= list->len) ? (void) (0) : __assert_fail ("i <= list->len", "sauce/misc/list.c", 101, __extension__ __PRETTY_FUNCTION__));
 list->ary = realloc(list->ary, sizeof (void *) * (list->len + 1));
 ((list->ary) ? (void) (0) : __assert_fail ("list->ary", "sauce/misc/list.c", 104, __extension__ __PRETTY_FUNCTION__));
 memmove(&list->ary[i+1], &list->ary[i], list->len - i);
 list->ary[i] = ptr;
 ++list->len;
}

variable_types:
ptr
void *

user_defined_types: struct alist { void **ary; unsigned int len; }


decompiled_code:
void *__fastcall alist_remove(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
void *result; // rax
unsigned int v4; // edx

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= a2 )
_assert_fail("i < list->len", "sauce/misc/list.c", 0x96u, "alist_remove");
memmove((void *)(*(_QWORD *)a1 + 8LL * a2), (const void *)(*(_QWORD *)a1 + 8LL * (a2 + 1)), v2 + ~a2);
result = realloc(*(void **)a1, 8LL * (unsigned int)(*(_DWORD *)(a1 + 8) - 1));
*(_QWORD *)a1 = result;
v4 = *(_DWORD *)(a1 + 8);
if ( !result && v4 > 1 )
_assert_fail("list->ary", "sauce/misc/list.c", 0x9Cu, "alist_remove");
*(_DWORD *)(a1 + 8) = v4 - 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
void *result; // rax
unsigned int v4; // edx

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= a2 )
_assert_fail("i < list->len", "sauce/misc/list.c", 0x96u, "alist_remove");
memmove((void *)(*(_QWORD *)a1 + 8LL * a2), (const void *)(*(_QWORD *)a1 + 8LL * (a2 + 1)), v2 + ~a2);
result = realloc(*(void **)a1, 8LL * (unsigned int)(*(_DWORD *)(a1 + 8) - 1));
*(_QWORD *)a1 = result;
v4 = *(_DWORD *)(a1 + 8);
if ( !result && v4 > 1 )
_assert_fail("list->ary", "sauce/misc/list.c", 0x9Cu, "alist_remove");
*(_DWORD *)(a1 + 8) = v4 - 1;
return result;
}

original_code:
void alist_remove(struct alist* list, unsigned i)
{
 ((i < list->len) ? (void) (0) : __assert_fail ("i < list->len", "sauce/misc/list.c", 150, __extension__ __PRETTY_FUNCTION__));
 memmove(&list->ary[i], &list->ary[i+1], list->len - i - 1);
 list->ary = realloc(list->ary, sizeof (void*) * (list->len - 1));
 if (list->len > 1)
  ((list->ary) ? (void) (0) : __assert_fail ("list->ary", "sauce/misc/list.c", 156, __extension__ __PRETTY_FUNCTION__));
 --list->len;
}

canonical_original_code:
void alist_remove(struct alist *list, unsigned int i)
{
 ((i < list->len) ? (void) (0) : __assert_fail ("i < list->len", "sauce/misc/list.c", 150, __extension__ __PRETTY_FUNCTION__));
 memmove(&list->ary[i], &list->ary[i+1], list->len - i - 1);
 list->ary = realloc(list->ary, sizeof (void *) * (list->len - 1));
 if (list->len > 1)
  ((list->ary) ? (void) (0) : __assert_fail ("list->ary", "sauce/misc/list.c", 156, __extension__ __PRETTY_FUNCTION__));
 --list->len;
}


decompiled_code:
__int64 __fastcall g_player_walk(__int64 a1, __int64 *a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
__int64 result; // rax
double v5; // xmm0_8
double v6; // xmm0_8
float v7; // xmm0_4

v2 = v2dprod(a2);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
if ( v3 > 1.0 )
{
v5 = v2dprod(a2);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = 1.0 / v6;
v2sprod(a2, a2, v7);
}
result = *a2;
*(_QWORD *)(a1 + 48) = *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 *a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
__int64 result; // rax
double v5; // xmm0_8
double v6; // xmm0_8
float v7; // xmm0_4

v2 = v2dprod(a2);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
if ( v3 > 1.0 )
{
v5 = v2dprod(a2);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = 1.0 / v6;
v2sprod(a2, a2, v7);
}
result = *a2;
*(_QWORD *)(a1 + 48) = *a2;
return result;
}

original_code:
void g_player_walk(struct g_player* e, float v[2])
{
 if (sqrt(v2dprod(v, v)) > 1)
  v2sprod(v, v, 1.0/sqrt(v2dprod(v, v)));
 memcpy(e->walk_v, v, sizeof(float[2]));
}

canonical_original_code:
void g_player_walk(struct g_player *e, float v[2])
{
 if (sqrt(v2dprod(v, v)) > 1)
  v2sprod(v, v, 1.0/sqrt(v2dprod(v, v)));
 memcpy(e->walk_v, v, sizeof(float [2]));
}

variable_types: struct g_player { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned long walk_dt; float walk_v[2]; struct llist { struct llist_node { void *ptr; struct llist_node *next; } *root; unsigned int len; } inventory; } *

variable_types:
v
float [2]


original_code:
void g_player_frame(struct g_player* e, unsigned long dt)
{
 if (sqrt(v2dprod(e->walk_v, e->walk_v)) == 0)
  e->walk_dt = 0;
 else
  e->walk_dt += dt;
}

canonical_original_code:
void g_player_frame(struct g_player *e, unsigned long dt)
{
 if (sqrt(v2dprod(e->walk_v, e->walk_v)) == 0)
  e->walk_dt = 0;
 else
  e->walk_dt += dt;
}

variable_types:
dt
unsigned long


decompiled_code:
__int64 __fastcall g_player_from_jason(_DWORD *a1)
{
__int64 result; // rax

result = g_entity_from_jason();
if ( !(_DWORD)result )
*a1 = 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
__int64 result; // rax

result = g_entity_from_jason();
if ( !(_DWORD)result )
*a1 = 2;
return result;
}

original_code:
int g_player_from_jason(
  struct g_player* e,
  char* jason,
  unsigned short* index
  )
{
 int r;
 r = g_entity_from_jason((struct g_entity*) e, jason, index);
 if (r)
  return r;
 e->type = G_PLAYER;
 return 0;
}

canonical_original_code:
int g_player_from_jason(struct g_player *e, char *jason, unsigned short *index)
{
 int r;
 r = g_entity_from_jason((struct g_entity *) e, jason, index);
 if (r)
  return r;
 e->type = G_PLAYER;
 return 0;
}

variable_types:
jason
char *

variable_types:
index
unsigned short *

variable_types: r int


decompiled_code:
__int64 __fastcall init_shader(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
void *v5; // rsp
char v6[8]; // [rsp+0h] [rbp-30h] BYREF
__int64 v7; // [rsp+8h] [rbp-28h] BYREF
unsigned int v8; // [rsp+18h] [rbp-18h] BYREF
int v9[5]; // [rsp+1Ch] [rbp-14h] BYREF

v7 = a2;
v2 = glCreateShader();
v3 = v2;
if ( v2 )
{
glShaderSource(v2, 1LL, &v7, 0LL);
glCompileShader(v3);
glGetShaderiv(v3, 35713LL, v9);
if ( !v9[0] )
{
v8 = 0;
glGetShaderiv(v3, 35716LL, &v8);
if ( (int)v8 > 1 )
{
v5 = alloca((int)v8);
glGetShaderInfoLog(v3, v8, 0LL, v6);
fprintf(stderr, "%s:%d: init_shader(): \n%s\n", "sauce/renderer/renderer.c", 87LL, v6);
}
glDeleteShader(v3);
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
void *v5; // rsp
char v6[8]; // [rsp+0h] [rbp-30h] BYREF
__int64 v7; // [rsp+8h] [rbp-28h] BYREF
unsigned int v8; // [rsp+18h] [rbp-18h] BYREF
int v9[5]; // [rsp+1Ch] [rbp-14h] BYREF

v7 = a2;
v2 = glCreateShader();
v3 = v2;
if ( v2 )
{
glShaderSource(v2, 1LL, &v7, 0LL);
glCompileShader(v3);
glGetShaderiv(v3, 35713LL, v9);
if ( !v9[0] )
{
v8 = 0;
glGetShaderiv(v3, 35716LL, &v8);
if ( (int)v8 > 1 )
{
v5 = alloca((int)v8);
glGetShaderInfoLog(v3, v8, 0LL, v6);
fprintf(stderr, "%s:%d: init_shader(): \n%s\n", "sauce/renderer/renderer.c", 87LL, v6);
}
glDeleteShader(v3);
v3 = 0;
}
}
return v3;
}

original_code:
static GLuint init_shader(GLenum type, GLchar* sauce)
{
 GLuint shader_id;
 GLint compiled;
 shader_id = glCreateShader(type);
 if (shader_id == 0)
  return 0;
 glShaderSource(shader_id, 1, (const GLchar**) &sauce, ((void *)0));
 glCompileShader(shader_id);
 glGetShaderiv(shader_id, 0x8B81, &compiled);
 if (!compiled)
 {
  GLint len = 0;
  glGetShaderiv(shader_id, 0x8B84, &len);
  if (len > 1)
  {
   char log[len];
   glGetShaderInfoLog(shader_id, len, ((void *)0), log);
   fprintf(stderr, "%s:%d: init_shader(): \n%s\n",
     "sauce/renderer/renderer.c", 87, log);
  }
  glDeleteShader(shader_id);
  shader_id = 0;
 }
 return shader_id;
}

canonical_original_code:
static unsigned int init_shader(unsigned int type, char *sauce)
{
 unsigned int shader_id;
 int compiled;
 shader_id = glCreateShader(type);
 if (shader_id == 0)
  return 0;
 glShaderSource(shader_id, 1, (char **) &sauce, ((void *)0));
 glCompileShader(shader_id);
 glGetShaderiv(shader_id, 0x8B81, &compiled);
 if (!compiled)
 {
  int len = 0;
  glGetShaderiv(shader_id, 0x8B84, &len);
  if (len > 1)
  {
   char log[-1];
   glGetShaderInfoLog(shader_id, len, ((void *)0), log);
   fprintf(stderr, "%s:%d: init_shader(): \n%s\n",
     "sauce/renderer/renderer.c", 87, log);
  }
  glDeleteShader(shader_id);
  shader_id = 0;
 }
 return shader_id;
}

variable_types:
type
unsigned int

variable_types:
sauce
char *

variable_types: compiled int

variable_types: len int

variable_types:
log
char [-1]

return_type: unsigned int


decompiled_code:
__int64 r_fini()
{
glDeleteProgram((unsigned int)r_program_id);
glDeleteShader((unsigned int)r_fshader_id);
glDeleteShader((unsigned int)r_vshader_id);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
glDeleteProgram((unsigned int)r_program_id);
glDeleteShader((unsigned int)r_fshader_id);
glDeleteShader((unsigned int)r_vshader_id);
return 0LL;
}

original_code:
int r_fini()
{
 glDeleteProgram(r_program_id);
 glDeleteShader(r_fshader_id);
 glDeleteShader(r_vshader_id);
 return 0;
}


decompiled_code:
__int64 r_init()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v3[4]; // [rsp+8h] [rbp-10h] BYREF

r_vshader_id = init_shader(35633LL, (__int64)vshader_sauce);
if ( !r_vshader_id )
return 0xFFFFFFFFLL;
v0 = init_shader(35632LL, (__int64)fshader_sauce);
r_fshader_id = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
v3[0] = r_vshader_id;
v3[1] = v0;
v1 = init_program(2, v3);
r_program_id = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
glUseProgram(v1);
r_pos_loc = glGetUniformLocation((unsigned int)r_program_id, "pos");
r_color_loc = glGetUniformLocation((unsigned int)r_program_id, "color");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v3[4]; // [rsp+8h] [rbp-10h] BYREF

r_vshader_id = func0(35633LL, (__int64)vshader_sauce);
if ( !r_vshader_id )
return 0xFFFFFFFFLL;
v0 = func0(35632LL, (__int64)fshader_sauce);
r_fshader_id = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
v3[0] = r_vshader_id;
v3[1] = v0;
v1 = func1(2, v3);
r_program_id = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
glUseProgram(v1);
r_pos_loc = glGetUniformLocation((unsigned int)r_program_id, "pos");
r_color_loc = glGetUniformLocation((unsigned int)r_program_id, "color");
return 0LL;
}

original_code:
int r_init()
{
 GLuint shaderv[2];
 r_vshader_id = init_shader(0x8B31, vshader_sauce);
 if (r_vshader_id == 0)
  return -1;
 r_fshader_id = init_shader(0x8B30, fshader_sauce);
 if (r_fshader_id == 0)
  return -1;
 shaderv[0] = r_vshader_id;
 shaderv[1] = r_fshader_id;
 r_program_id = init_program(2, shaderv);
 if (r_program_id == 0)
  return -1;
 glUseProgram(r_program_id);
 r_pos_loc = glGetUniformLocation(r_program_id, "pos");
 r_color_loc = glGetUniformLocation(r_program_id, "color");
 return 0;
}

canonical_original_code:
int r_init()
{
 unsigned int shaderv[2];
 r_vshader_id = init_shader(0x8B31, vshader_sauce);
 if (r_vshader_id == 0)
  return -1;
 r_fshader_id = init_shader(0x8B30, fshader_sauce);
 if (r_fshader_id == 0)
  return -1;
 shaderv[0] = r_vshader_id;
 shaderv[1] = r_fshader_id;
 r_program_id = init_program(2, shaderv);
 if (r_program_id == 0)
  return -1;
 glUseProgram(r_program_id);
 r_pos_loc = glGetUniformLocation(r_program_id, "pos");
 r_color_loc = glGetUniformLocation(r_program_id, "color");
 return 0;
}

variable_types:
shaderv
unsigned int [2]


decompiled_code:
__int64 __fastcall r_boxxy(__int64 *a1)
{
__int64 v2; // [rsp+0h] [rbp-28h] BYREF
char v3[8]; // [rsp+8h] [rbp-20h] BYREF
int v4[2]; // [rsp+10h] [rbp-18h] BYREF
char v5[16]; // [rsp+18h] [rbp-10h] BYREF

v2 = *a1;
v2add(v4, a1, a1 + 1);
v2set(v3, *(float *)v4, *((float *)&v2 + 1));
v2set(v5, *(float *)&v2, *(float *)&v4[1]);
glEnableVertexAttribArray(0LL);
glVertexAttribPointer(0LL, 2LL, 5126LL, 0LL, 0LL, &v2);
return glDrawArrays(6LL, 0LL, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
__int64 v2; // [rsp+0h] [rbp-28h] BYREF
char v3[8]; // [rsp+8h] [rbp-20h] BYREF
int v4[2]; // [rsp+10h] [rbp-18h] BYREF
char v5[16]; // [rsp+18h] [rbp-10h] BYREF

v2 = *a1;
v2add(v4, a1, a1 + 1);
v2set(v3, *(float *)v4, *((float *)&v2 + 1));
v2set(v5, *(float *)&v2, *(float *)&v4[1]);
glEnableVertexAttribArray(0LL);
glVertexAttribPointer(0LL, 2LL, 5126LL, 0LL, 0LL, &v2);
return glDrawArrays(6LL, 0LL, 4LL);
}

original_code:
void r_boxxy(float (*boxxy)[2])
{
 float v[4][2];
 memcpy(v[0], boxxy[0], sizeof(float[2]));
 v2add(v[2], boxxy[0], boxxy[1]);
 v2set(v[1], v[2][0], v[0][1]);
 v2set(v[3], v[0][0], v[2][1]);
 glEnableVertexAttribArray(0);
 glVertexAttribPointer(0, 2, 0x1406, 0, 0, v);
 glDrawArrays(0x0006, 0, 4);
}

canonical_original_code:
void r_boxxy(float (*boxxy)[2])
{
 float v[4][2];
 memcpy(v[0], boxxy[0], sizeof(float [2]));
 v2add(v[2], boxxy[0], boxxy[1]);
 v2set(v[1], v[2][0], v[0][1]);
 v2set(v[3], v[0][0], v[2][1]);
 glEnableVertexAttribArray(0);
 glVertexAttribPointer(0, 2, 0x1406, 0, 0, v);
 glDrawArrays(0x0006, 0, 4);
}

variable_types:
boxxy
float (*)[2]

variable_types:
v
float [4][2]


decompiled_code:
__int64 __fastcall j0g2_vec(__int64 a1, unsigned int a2, __int64 a3, _WORD *a4)
{
unsigned int i; // ebx

for ( i = a2; i; --i )
{
if ( !*a4 )
break;
a1 += 4LL;
*(float *)(a1 - 4) = strtof((const char *)(a3 + (unsigned __int16)*a4), 0LL);
a4 += 2;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3, _WORD *a4)
{
unsigned int i; // ebx

for ( i = a2; i; --i )
{
if ( !*a4 )
break;
a1 += 4LL;
*(float *)(a1 - 4) = strtof((const char *)(a3 + (unsigned __int16)*a4), 0LL);
a4 += 2;
}
return i;
}

original_code:
int j0g2_vec(
  float* v,
  unsigned n,
  const char* jason,
  unsigned short* index
  )
{
 unsigned short* i;
 for (i = index; n > 0 && (*i); --n, i += 2)
  (*(v++)) = strtof(jason + (*i), ((void *)0));
 return n;
}

canonical_original_code:
int j0g2_vec(float *v, unsigned int n, char *jason, unsigned short *index)
{
 unsigned short *i;
 for (i = index; n > 0 && (*i); --n, i += 2)
  (*(v++)) = strtof(jason + (*i), ((void *)0));
 return n;
}

variable_types:
v
float *

variable_types:
n
unsigned int

variable_types:
i
unsigned short *


decompiled_code:
__int64 __fastcall j0g2_vec_malloc(unsigned int *a1, _QWORD *a2, __int64 a3, _WORD *a4)
{
_WORD *v5; // rbp
_WORD *v6; // rax
void *v7; // rax

v5 = a4;
if ( *a4 )
{
v6 = a4;
do
{
++*a1;
v6 += 2;
}
while ( *v6 );
}
v7 = malloc(4LL * *a1);
*a2 = v7;
return j0g2_vec((__int64)v7, *a1, a3, v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, _QWORD *a2, __int64 a3, _WORD *a4)
{
_WORD *v5; // rbp
_WORD *v6; // rax
void *v7; // rax

v5 = a4;
if ( *a4 )
{
v6 = a4;
do
{
++*a1;
v6 += 2;
}
while ( *v6 );
}
v7 = malloc(4LL * *a1);
*a2 = v7;
return func0((__int64)v7, *a1, a3, v5);
}

original_code:
int j0g2_vec_malloc(
  unsigned* c,
  float** v,
  const char* jason,
  unsigned short* index
  )
{
 unsigned short* i;
 for (i = index; (*i); ++(*c), i += 2);
 (*v) = malloc(sizeof (float) * (*c));
 return j0g2_vec((*v), (*c), jason, index);
}

canonical_original_code:
int j0g2_vec_malloc(unsigned int *c, float **v, char *jason, unsigned short *index)
{
 unsigned short *i;
 for (i = index; (*i); ++(*c), i += 2);
 (*v) = malloc(sizeof (float) * (*c));
 return j0g2_vec((*v), (*c), jason, index);
}

variable_types:
c
unsigned int *

variable_types:
v
float **


decompiled_code:
void g_terrain_frame()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void g_terrain_frame(struct g_terrain* ter, unsigned long dt)
{
}

canonical_original_code:
void g_terrain_frame(struct g_terrain *ter, unsigned long dt)
{
}

variable_types: struct g_terrain { unsigned int type; unsigned int id; float p[2]; float v[2]; float boxxy[2][2]; unsigned int vertc; float (*vertv)[2]; } *

variable_types:
dt
unsigned long


decompiled_code:
__int64 __fastcall g_terrain_from_jason(_DWORD *a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er14
int v6; // eax
__int64 v7; // r12
__int64 v8; // rsi
void *v9; // rsp
_BYTE v10[48]; // [rsp+0h] [rbp-30h] BYREF

v4 = g_entity_from_jason();
if ( !v4 )
{
v6 = j0g_val("verts", a2, a3);
v7 = *(unsigned __int16 *)(a3 + 2LL * v6) + a2;
v8 = *(unsigned __int16 *)(a3 + 2LL * v6 + 2);
v9 = alloca((2 * *(unsigned __int16 *)(a3 + 2LL * v6 + 2) + 15) & 0x3FFF0);
js0n(v7, v8, v10, (unsigned int)v8);
j0g2_vec_malloc(a1 + 10, a1 + 12, v7, v10);
a1[10] >>= 1;
*a1 = 3;
}
return v4;
}

original_code:
int g_terrain_from_jason(
  struct g_terrain* e,
  char* jason,
  unsigned short* index
  )
{
 int r;
 r = g_entity_from_jason((struct g_entity*) e, jason, index);
 if (r)
  return r;
 { int val = j0g_val("verts", jason, index); { char* sjason; unsigned slen; sjason = jason + index[val]; slen = index[val+1]; unsigned short sindex[slen]; int js0n_r = js0n((const unsigned char*) (sjason), (slen), (sindex), (slen)); (void) js0n_r;;
 j0g2_vec_malloc(&e->vertc, (float**) &e->vertv, sjason, sindex);
 e->vertc /= 2;
 }; };
 e->type = G_TERRAIN;
 return 0;
}

canonical_original_code:
int g_terrain_from_jason(struct g_terrain *e, char *jason, unsigned short *index)
{
 int r;
 r = g_entity_from_jason((struct g_entity *) e, jason, index);
 if (r)
  return r;
 { int val = j0g_val("verts", jason, index); { char *sjason; unsigned int slen; sjason = jason + index[val]; slen = index[val+1]; unsigned short sindex[-1]; int js0n_r = js0n((const unsigned char*) (sjason), (slen), (sindex), (slen)); (void) js0n_r;;
 j0g2_vec_malloc(&e->vertc, (float **) &e->vertv, sjason, sindex);
 e->vertc /= 2;
 }; };
 e->type = G_TERRAIN;
 return 0;
}

variable_types:
jason
char *

variable_types:
index
unsigned short *

variable_types: val int

variable_types:
sjason
char *

variable_types:
slen
unsigned int

variable_types:
sindex
unsigned short [-1]


sbrk

decompiled_code:
__int64 __fastcall sbrk(int a1)
{
int v1; // eax

v1 = sbrk2(0LL);
return (int)sbrk2((unsigned int)(v1 + a1));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax

v1 = sbrk2(0LL);
return (int)sbrk2((unsigned int)(v1 + a1));
}

original_code:
void* sbrk(intptr_t increment)
{
 intptr_t end=(intptr_t) sbrk2((intptr_t) 0);
 return (void*) sbrk2(increment+end);
}

canonical_original_code:
void *sbrk(int increment)
{
 int end = (intptr_t) sbrk2((intptr_t) 0);
 return (void *) sbrk2(increment+end);
}

variable_types: increment int

variable_types: end int


decompiled_code:
ssize_t __fastcall low_print(void *buf)
{
__int64 v1; // rax
size_t v2; // rdx

if ( *(_BYTE *)buf )
{
v1 = 1LL;
do
v2 = (unsigned int)v1++;
while ( *((char *)buf + v1 - 1) );
}
else
{
v2 = 0LL;
}
return write(1, buf, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf)
{
__int64 v1; // rax
size_t v2; // rdx

if ( *(_BYTE *)buf )
{
v1 = 1LL;
do
v2 = (unsigned int)v1++;
while ( *((char *)buf + v1 - 1) );
}
else
{
v2 = 0LL;
}
return write(1, buf, v2);
}

original_code:
int low_print(char *msg)
{
 int x;
 for (x=0; msg[x]!='\0'; x++) {
 }
 return write(1, msg, x);
}

variable_types:
msg
char *

variable_types: x int


decompiled_code:
ssize_t __fastcall low_error(void *buf)
{
__int64 v1; // rax
size_t v2; // rdx

if ( *(_BYTE *)buf )
{
v1 = 1LL;
do
v2 = (unsigned int)v1++;
while ( *((char *)buf + v1 - 1) );
}
else
{
v2 = 0LL;
}
return write(2, buf, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func1(void *buf)
{
__int64 v1; // rax
size_t v2; // rdx

if ( *(_BYTE *)buf )
{
v1 = 1LL;
do
v2 = (unsigned int)v1++;
while ( *((char *)buf + v1 - 1) );
}
else
{
v2 = 0LL;
}
return write(2, buf, v2);
}

original_code:
int low_error(char *msg)
{
 int x;
 for (x=0; msg[x]!='\0'; x++) {
 }
 return write(2, msg, x);
}


lower

repo: skynjupt/TCPL

decompiled_code:
__int64 __fastcall lower(int c)
{
char *v1; // rdx
__int64 result; // rax

v1 = strchr("ABCDEFGHIJKLNMOPQRSTUVWXYZ", c);
result = (unsigned int)c;
if ( v1 )
result = (unsigned int)byte_40201F[v1 - "ABCDEFGHIJKLNMOPQRSTUVWXYZ"];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int c)
{
char *v1; // rdx
__int64 result; // rax

v1 = strchr("ABCDEFGHIJKLNMOPQRSTUVWXYZ", c);
result = (unsigned int)c;
if ( v1 )
result = (unsigned int)byte_40201F[v1 - "ABCDEFGHIJKLNMOPQRSTUVWXYZ"];
return result;
}

original_code:
int lower(int c)
{
 char *Uppercase = "ABCDEFGHIJKLNMOPQRSTUVWXYZ";
 char *Lowercase = "abcdefghijklnmopqrstuvwxyz";
 char *p = ((void *)0);
 return (((void *)0) == (p = strchr(Uppercase, c)) ? c:*(Lowercase+(p-Uppercase))) ;
}

variable_types: c int

variable_types:
Uppercase
char *

variable_types:
Lowercase
char *

variable_types:
p
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char v4; // al
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

v3 = "AaBb32CcdD3e2EfFGghHii2IJjK32kL32lMmNnOopPQqRrSsTtUuVvWwXx23yYzZ";
v4 = 65;
do
{
v5 = v4;
v6 = lower(v4);
printf("%c ==> %c\n", v5, v6);
v4 = *++v3;
}
while ( *v3 );
v7 = lower(0);
printf("\\0 ==> %d\n", v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char v4; // al
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

v3 = "AaBb32CcdD3e2EfFGghHii2IJjK32kL32lMmNnOopPQqRrSsTtUuVvWwXx23yYzZ";
v4 = 65;
do
{
v5 = v4;
v6 = func7(v4);
printf("%c ==> %c\n", v5, v6);
v4 = *++v3;
}
while ( *v3 );
v7 = func7(0);
printf("\\0 ==> %d\n", v7);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *Tests="AaBb32CcdD3e2EfFGghHii2IJjK32kL32lMmNnOopPQqRrSsTtUuVvWwXx23yYzZ";
 char *p = Tests;
 while('\0' != *p)
 {
  printf("%c ==> %c\n", *p, lower(*p));
  p++;
 }
 printf("\\0 ==> %d\n", lower(0));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *Tests = "AaBb32CcdD3e2EfFGghHii2IJjK32kL32lMmNnOopPQqRrSsTtUuVvWwXx23yYzZ";
 char *p = Tests;
 while('\0' != *p)
 {
  printf("%c ==> %c\n", *p, lower(*p));
  p++;
 }
 printf("\\0 ==> %d\n", lower(0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
Tests
char *


repo: skytee/orchidarium

decompiled_code:
void __noreturn die_errno(const char *a1, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, ": %s\n", v2);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, ...)
{
int *v1; // rax
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, ": %s\n", v2);
exit(1);
}

original_code:
static void die_errno(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 fprintf(stderr, ": %s\n", strerror((*__errno_location ())));
 exit(1);
}

canonical_original_code:
static void die_errno(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 fprintf(stderr, ": %s\n", strerror((*__errno_location ())));
 exit(1);
}

variable_types:
fmt
char *


die

decompiled_code:
void __noreturn die(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(1);
}

original_code:
static void die(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
static void die(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 fprintf(stderr, "\n");
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // ebx
int v6; // eax
int v7; // eax
unsigned int v8; // ebp
int v9; // er13
int v10; // er12
unsigned __int8 v11; // r15
unsigned int v12; // ecx
unsigned int v13; // er15
unsigned int v14; // er14
unsigned int v15; // eax
int v16; // er12
float v17; // xmm1_4
float v18; // xmm0_4
unsigned __int8 v20; // [rsp+Fh] [rbp-129h]
char v21; // [rsp+1Fh] [rbp-119h] BYREF
char v22[8]; // [rsp+20h] [rbp-118h] BYREF
char *v23; // [rsp+28h] [rbp-110h]
__int16 v24; // [rsp+30h] [rbp-108h]
unsigned __int8 v25; // [rsp+3Bh] [rbp-FDh] BYREF
unsigned __int8 v26; // [rsp+3Ch] [rbp-FCh]
unsigned __int8 v27; // [rsp+3Dh] [rbp-FBh]
unsigned __int8 v28; // [rsp+3Eh] [rbp-FAh]
struct termios termios_p; // [rsp+40h] [rbp-F8h] BYREF
char dest[16]; // [rsp+80h] [rbp-B8h] BYREF
__int64 v31; // [rsp+90h] [rbp-A8h]
__int64 v32; // [rsp+98h] [rbp-A0h]
__int64 v33; // [rsp+A0h] [rbp-98h]
__int64 v34; // [rsp+A8h] [rbp-90h]
__int64 v35; // [rsp+B0h] [rbp-88h]
__int64 v36; // [rsp+B8h] [rbp-80h]
__int64 v37; // [rsp+C0h] [rbp-78h]
__int64 v38; // [rsp+C8h] [rbp-70h]
__int64 v39; // [rsp+D0h] [rbp-68h]
__int64 v40; // [rsp+D8h] [rbp-60h]
__int64 v41; // [rsp+E0h] [rbp-58h]
__int64 v42; // [rsp+E8h] [rbp-50h]
__int64 v43; // [rsp+F0h] [rbp-48h]
__int64 v44; // [rsp+F8h] [rbp-40h]

strcpy(dest, "/dev/ttyUSB0");
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
v34 = 0LL;
v35 = 0LL;
v36 = 0LL;
v37 = 0LL;
v38 = 0LL;
v39 = 0LL;
v40 = 0LL;
v41 = 0LL;
v42 = 0LL;
v43 = 0LL;
v44 = 0LL;
v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "p:vi");
if ( v6 == -1 )
break;
if ( v6 == 112 )
{
strncpy(dest, optarg, 0x7FuLL);
HIBYTE(v44) = 0;
}
else if ( v6 > 112 )
{
v5 += v6 == 118;
}
else if ( v6 == 63 )
{
++v4;
}
else if ( v6 == 105 )
{
++v3;
}
}
if ( v4 || optind < argc )
{
fprintf(
stderr,
"Usage:\n"
"%s [options]\n"
"\t-p <port> use this device, default: /dev/ttyUSB0\n"
"\t-v increase verbosity level\n"
"\t-i wake up TSL2561 from sleep mode\n",
*argv);
exit(2);
}
v7 = open(dest, 2306);
v8 = v7;
if ( v7 < 0 )
die_errno("opening port %s", dest);
tcgetattr(v7, &termios_p);
v9 = setterm(v8, 14LL);
v10 = v9;
if ( v9 )
{
tcsetattr(v8, 0, &termios_p);
if ( v9 >= 0 )
die("setterm(), maybe the device is not available?");
die_errno("setterm(), maybe the device is not available?");
}
while ( (int)usb_i2c_write_byte(v8, 57LL, 172LL) < 0 )
{
if ( v5 )
goto LABEL_21;
LABEL_22:
if ( ++v10 == 3 )
die("Cannot read TSL2561");
}
if ( (int)usb_i2c_read_byte_data(v8, 57LL, &v25, 2LL, 40000LL) <= 1 )
{
if ( v5 )
goto LABEL_34;
goto LABEL_22;
}
v11 = v26;
v20 = v25;
if ( (int)usb_i2c_write_byte(v8, 57LL, 174LL) < 0 )
{
if ( !v5 )
goto LABEL_22;
LABEL_21:
fwrite("usb_i2c_write_byte()\n", 1uLL, 0x15uLL, stderr);
goto LABEL_22;
}
if ( (int)usb_i2c_read_byte_data(v8, 57LL, &v25, 2LL, 40000LL) <= 1 )
{
if ( !v5 )
goto LABEL_22;
LABEL_34:
fwrite("usb_i2c_read_byte_data()\n", 1uLL, 0x19uLL, stderr);
goto LABEL_22;
}
v12 = (v11 << 8) + v20;
v13 = v25 + (v26 << 8);
if ( ((v10 | v13 | v12) == 0) + v3 )
{
v22[0] = 0x80;
v21 = 3;
v23 = &v21;
v24 = 1;
if ( (int)usb_i2c_write_reg_data(v8, 57LL, v22) < 0 && v5 )
fwrite("usb_i2c_write_reg_data()\n", 1uLL, 0x19uLL, stderr);
if ( (int)usb_i2c_read_byte_data(v8, 57LL, &v25, 1LL, 0LL) <= 0 && v5 )
fwrite("usb_i2c_read_byte_data()\n", 1uLL, 0x19uLL, stderr);
usleep(0x6DDD0u);
v3 = v9;
goto LABEL_22;
}
v14 = v12;
v15 = calculate_lux(v12, v13);
printf("%d\n%d\n%d\n", v14, v13, v15);
v16 = 3;
while ( (int)usb_i2c_write_byte(v8, 40LL, 0LL) < 0 )
{
if ( v5 )
fwrite("usb_i2c_write_byte()\n", 1uLL, 0x15uLL, stderr);
LABEL_49:
if ( !--v16 )
die("Cannot read HYT221");
}
if ( (int)usb_i2c_read_byte_data(v8, 40LL, &v25, 4LL, 65000LL) <= 3 )
{
if ( v5 )
fwrite("usb_i2c_read_byte_data()\n", 1uLL, 0x19uLL, stderr);
goto LABEL_49;
}
if ( (v28 & (unsigned __int8)(v27 & v26 & v25)) == 0xFF )
goto LABEL_49;
v17 = (double)(v28 & 0xFC | (v27 << 8)) * 0.002517853872917048 - 40.0;
v18 = (double)(v26 | (v25 << 8) & 0x3F00u) * 0.006103888176768602;
printf("%.1f\n%.1f\n", v18, v17);
tcsetattr(v8, 0, &termios_p);
close(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // ebx
int v6; // eax
int v7; // eax
unsigned int v8; // ebp
int v9; // er13
int v10; // er12
unsigned __int8 v11; // r15
unsigned int v12; // ecx
unsigned int v13; // er15
unsigned int v14; // er14
unsigned int v15; // eax
int v16; // er12
float v17; // xmm1_4
float v18; // xmm0_4
unsigned __int8 v20; // [rsp+Fh] [rbp-129h]
char v21; // [rsp+1Fh] [rbp-119h] BYREF
char v22[8]; // [rsp+20h] [rbp-118h] BYREF
char *v23; // [rsp+28h] [rbp-110h]
__int16 v24; // [rsp+30h] [rbp-108h]
unsigned __int8 v25; // [rsp+3Bh] [rbp-FDh] BYREF
unsigned __int8 v26; // [rsp+3Ch] [rbp-FCh]
unsigned __int8 v27; // [rsp+3Dh] [rbp-FBh]
unsigned __int8 v28; // [rsp+3Eh] [rbp-FAh]
struct termios termios_p; // [rsp+40h] [rbp-F8h] BYREF
char dest[16]; // [rsp+80h] [rbp-B8h] BYREF
__int64 v31; // [rsp+90h] [rbp-A8h]
__int64 v32; // [rsp+98h] [rbp-A0h]
__int64 v33; // [rsp+A0h] [rbp-98h]
__int64 v34; // [rsp+A8h] [rbp-90h]
__int64 v35; // [rsp+B0h] [rbp-88h]
__int64 v36; // [rsp+B8h] [rbp-80h]
__int64 v37; // [rsp+C0h] [rbp-78h]
__int64 v38; // [rsp+C8h] [rbp-70h]
__int64 v39; // [rsp+D0h] [rbp-68h]
__int64 v40; // [rsp+D8h] [rbp-60h]
__int64 v41; // [rsp+E0h] [rbp-58h]
__int64 v42; // [rsp+E8h] [rbp-50h]
__int64 v43; // [rsp+F0h] [rbp-48h]
__int64 v44; // [rsp+F8h] [rbp-40h]

strcpy(dest, "/dev/ttyUSB0");
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
v34 = 0LL;
v35 = 0LL;
v36 = 0LL;
v37 = 0LL;
v38 = 0LL;
v39 = 0LL;
v40 = 0LL;
v41 = 0LL;
v42 = 0LL;
v43 = 0LL;
v44 = 0LL;
v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "p:vi");
if ( v6 == -1 )
break;
if ( v6 == 112 )
{
strncpy(dest, optarg, 0x7FuLL);
HIBYTE(v44) = 0;
}
else if ( v6 > 112 )
{
v5 += v6 == 118;
}
else if ( v6 == 63 )
{
++v4;
}
else if ( v6 == 105 )
{
++v3;
}
}
if ( v4 || optind < argc )
{
fprintf(
stderr,
"Usage:\n"
"%s [options]\n"
"\t-p <port> use this device, default: /dev/ttyUSB0\n"
"\t-v increase verbosity level\n"
"\t-i wake up TSL2561 from sleep mode\n",
*argv);
exit(2);
}
v7 = open(dest, 2306);
v8 = v7;
if ( v7 < 0 )
func0("opening port %s", dest);
tcgetattr(v7, &termios_p);
v9 = setterm(v8, 14LL);
v10 = v9;
if ( v9 )
{
tcsetattr(v8, 0, &termios_p);
if ( v9 >= 0 )
func1("setterm(), maybe the device is not available?");
func0("setterm(), maybe the device is not available?");
}
while ( (int)usb_i2c_write_byte(v8, 57LL, 172LL) < 0 )
{
if ( v5 )
goto LABEL_21;
LABEL_22:
if ( ++v10 == 3 )
func1("Cannot read TSL2561");
}
if ( (int)usb_i2c_read_byte_data(v8, 57LL, &v25, 2LL, 40000LL) <= 1 )
{
if ( v5 )
goto LABEL_34;
goto LABEL_22;
}
v11 = v26;
v20 = v25;
if ( (int)usb_i2c_write_byte(v8, 57LL, 174LL) < 0 )
{
if ( !v5 )
goto LABEL_22;
LABEL_21:
fwrite("usb_i2c_write_byte()\n", 1uLL, 0x15uLL, stderr);
goto LABEL_22;
}
if ( (int)usb_i2c_read_byte_data(v8, 57LL, &v25, 2LL, 40000LL) <= 1 )
{
if ( !v5 )
goto LABEL_22;
LABEL_34:
fwrite("usb_i2c_read_byte_data()\n", 1uLL, 0x19uLL, stderr);
goto LABEL_22;
}
v12 = (v11 << 8) + v20;
v13 = v25 + (v26 << 8);
if ( ((v10 | v13 | v12) == 0) + v3 )
{
v22[0] = 0x80;
v21 = 3;
v23 = &v21;
v24 = 1;
if ( (int)usb_i2c_write_reg_data(v8, 57LL, v22) < 0 && v5 )
fwrite("usb_i2c_write_reg_data()\n", 1uLL, 0x19uLL, stderr);
if ( (int)usb_i2c_read_byte_data(v8, 57LL, &v25, 1LL, 0LL) <= 0 && v5 )
fwrite("usb_i2c_read_byte_data()\n", 1uLL, 0x19uLL, stderr);
usleep(0x6DDD0u);
v3 = v9;
goto LABEL_22;
}
v14 = v12;
v15 = calculate_lux(v12, v13);
printf("%d\n%d\n%d\n", v14, v13, v15);
v16 = 3;
while ( (int)usb_i2c_write_byte(v8, 40LL, 0LL) < 0 )
{
if ( v5 )
fwrite("usb_i2c_write_byte()\n", 1uLL, 0x15uLL, stderr);
LABEL_49:
if ( !--v16 )
func1("Cannot read HYT221");
}
if ( (int)usb_i2c_read_byte_data(v8, 40LL, &v25, 4LL, 65000LL) <= 3 )
{
if ( v5 )
fwrite("usb_i2c_read_byte_data()\n", 1uLL, 0x19uLL, stderr);
goto LABEL_49;
}
if ( (v28 & (unsigned __int8)(v27 & v26 & v25)) == 0xFF )
goto LABEL_49;
v17 = (double)(v28 & 0xFC | (v27 << 8)) * 0.002517853872917048 - 40.0;
v18 = (double)(v26 | (v25 << 8) & 0x3F00u) * 0.006103888176768602;
printf("%.1f\n%.1f\n", v18, v17);
tcsetattr(v8, 0, &termios_p);
close(v8);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fd, ret, c, verbosity = 0, errflag = 0, try, success, wake_tsl2561 = 0;
 char port[128] = "/dev/ttyUSB0";
 struct termios oldtio;
 speed_t baudrate = 0000016;
 unsigned int ch0, ch1;
 unsigned char data[5];
 float humidity, temp, lux;
 humidity = temp = lux = 0.0;
 while(( c = getopt( argc, argv, "p:vi" )) != -1 )
 {
  switch( c ) {
   case 'p':
    strncpy(port, optarg, 128);
    port[128 -1] = '\0';
    break;
   case 'v':
    verbosity++;
    break;
   case 'i':
    wake_tsl2561++;
    break;
   case '?': ++errflag;
    break;
  }
 }
 if ( errflag || optind < argc ) {
  fprintf (stderr,"Usage:\n%s [options]\n"
    "\t-p <port>   use this device, default: " "/dev/ttyUSB0" "\n"
    "\t-v          increase verbosity level\n"
    "\t-i          wake up TSL2561 from sleep mode\n"
    , *argv);
  exit (2);
 }
 fd = open(port, 02 | 0400 | 04000);
 if (fd < 0)
  die_errno("opening port %s", port);
 tcgetattr(fd, &oldtio);
 ret = setterm(fd, baudrate);
 if (ret != 0) {
  tcsetattr(fd,0,&oldtio);
  if (ret < 0)
   die_errno("setterm(), maybe the device is not available?");
  if (ret > 0)
   die("setterm(), maybe the device is not available?");
 }
 for (success = 0, try = 0; try < 3; try++) {
  if (usb_i2c_write_byte(fd, 0x39, 0xac) < 0) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_write_byte()\n");
   continue;
  }
  if (usb_i2c_read_byte_data(fd, 0x39, data, 2, 40000) < 2) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_read_byte_data()\n");
   continue;
  }
  ch0 = 256 * data[1] + data[0];
  if (usb_i2c_write_byte(fd, 0x39, 0xae) < 0) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_write_byte()\n");
   continue;
  }
  if (usb_i2c_read_byte_data(fd, 0x39, data, 2, 40000) < 2) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_read_byte_data()\n");
   continue;
  }
  ch1 = 256 * data[1] + data[0];
  if ((ch1 == 0) && (ch0 == 0) && (try == 0))
  {
   ++wake_tsl2561;
  }
  if (wake_tsl2561)
  {
   struct usb_i2c_data payload;
   payload.reg = ((0x80) | (0x00));
   unsigned char a = (0x03);
   payload.buf = &a;
   payload.len = 1;
   if (usb_i2c_write_reg_data(fd, 0x39, &payload) < 0)
    if (verbosity) fprintf(stderr, "usb_i2c_write_reg_data()\n");
   if (usb_i2c_read_byte_data(fd, 0x39, data, 1, 0) < 1)
    if (verbosity) fprintf(stderr, "usb_i2c_read_byte_data()\n");
   usleep(450 * 1000);
   wake_tsl2561 = 0;
   continue;
  }
  printf("%d\n%d\n%d\n", ch0, ch1, calculate_lux(ch0, ch1));
  ++success;
  break;
 }
 if (!success)
  die("Cannot read TSL2561");
 for (success = 0, try = 0; try < 3; try++) {
  if (usb_i2c_write_byte(fd, 0x28, 0x0) < 0) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_write_byte()\n");
   continue;
  }
  if (usb_i2c_read_byte_data(fd, 0x28, data, 4, 65000) < 4) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_read_byte_data()\n");
   continue;
  }
  if ((data[0] == 0xff) && (data[1] == 0xff) && (data[2] == 0xff) && (data[3] == 0xff))
   continue;
  humidity = ((data[0] & 0x3f) << 8 | data[1]) * (100.0 / 0x3fff);
  temp = (data[2] << 8 | (data[3] & 0xfc)) * (165.0 / 0xfffc) - 40;
  printf("%.1f\n%.1f\n", humidity, temp);
  ++success;
  break;
 }
 if (!success)
  die("Cannot read HYT221");
 tcsetattr(fd, 0, &oldtio);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd; int ret; int c; int verbosity = 0; int errflag = 0; int try; int success; int wake_tsl2561 = 0;
 char port[128] = "/dev/ttyUSB0";
 struct termios oldtio;
 unsigned int baudrate = 0000016;
 unsigned int ch0; unsigned int ch1;
 unsigned char data[5];
 float humidity; float temp; float lux;
 humidity = temp = lux = 0.0;
 while(( c = getopt( argc, argv, "p:vi" )) != -1 )
 {
  switch( c ) {
   case 'p':
    strncpy(port, optarg, 128);
    port[128 -1] = '\0';
    break;
   case 'v':
    verbosity++;
    break;
   case 'i':
    wake_tsl2561++;
    break;
   case '?': ++errflag;
    break;
  }
 }
 if ( errflag || optind < argc ) {
  fprintf (stderr,"Usage:\n%s [options]\n"
    "\t-p <port>   use this device, default: " "/dev/ttyUSB0" "\n"
    "\t-v          increase verbosity level\n"
    "\t-i          wake up TSL2561 from sleep mode\n"
    , *argv);
  exit (2);
 }
 fd = open(port, 02 | 0400 | 04000);
 if (fd < 0)
  die_errno("opening port %s", port);
 tcgetattr(fd, &oldtio);
 ret = setterm(fd, baudrate);
 if (ret != 0) {
  tcsetattr(fd,0,&oldtio);
  if (ret < 0)
   die_errno("setterm(), maybe the device is not available?");
  if (ret > 0)
   die("setterm(), maybe the device is not available?");
 }
 for (success = 0, try = 0; try < 3; try++) {
  if (usb_i2c_write_byte(fd, 0x39, 0xac) < 0) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_write_byte()\n");
   continue;
  }
  if (usb_i2c_read_byte_data(fd, 0x39, data, 2, 40000) < 2) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_read_byte_data()\n");
   continue;
  }
  ch0 = 256 * data[1] + data[0];
  if (usb_i2c_write_byte(fd, 0x39, 0xae) < 0) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_write_byte()\n");
   continue;
  }
  if (usb_i2c_read_byte_data(fd, 0x39, data, 2, 40000) < 2) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_read_byte_data()\n");
   continue;
  }
  ch1 = 256 * data[1] + data[0];
  if ((ch1 == 0) && (ch0 == 0) && (try == 0))
  {
   ++wake_tsl2561;
  }
  if (wake_tsl2561)
  {
   struct usb_i2c_data payload;
   payload.reg = ((0x80) | (0x00));
   unsigned char a = (0x03);
   payload.buf = &a;
   payload.len = 1;
   if (usb_i2c_write_reg_data(fd, 0x39, &payload) < 0)
    if (verbosity) fprintf(stderr, "usb_i2c_write_reg_data()\n");
   if (usb_i2c_read_byte_data(fd, 0x39, data, 1, 0) < 1)
    if (verbosity) fprintf(stderr, "usb_i2c_read_byte_data()\n");
   usleep(450 * 1000);
   wake_tsl2561 = 0;
   continue;
  }
  printf("%d\n%d\n%d\n", ch0, ch1, calculate_lux(ch0, ch1));
  ++success;
  break;
 }
 if (!success)
  die("Cannot read TSL2561");
 for (success = 0, try = 0; try < 3; try++) {
  if (usb_i2c_write_byte(fd, 0x28, 0x0) < 0) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_write_byte()\n");
   continue;
  }
  if (usb_i2c_read_byte_data(fd, 0x28, data, 4, 65000) < 4) {
   if (verbosity)
    fprintf(stderr, "usb_i2c_read_byte_data()\n");
   continue;
  }
  if ((data[0] == 0xff) && (data[1] == 0xff) && (data[2] == 0xff) && (data[3] == 0xff))
   continue;
  humidity = ((data[0] & 0x3f) << 8 | data[1]) * (100.0 / 0x3fff);
  temp = (data[2] << 8 | (data[3] & 0xfc)) * (165.0 / 0xfffc) - 40;
  printf("%.1f\n%.1f\n", humidity, temp);
  ++success;
  break;
 }
 if (!success)
  die("Cannot read HYT221");
 tcsetattr(fd, 0, &oldtio);
 close(fd);
 return 0;
}

variable_types: fd int

variable_types: ret int

variable_types: verbosity int

variable_types: errflag int

variable_types: try int

variable_types: success int

variable_types:
port
char [128]

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types:
baudrate
unsigned int

variable_types:
data
unsigned char [5]

variable_types: humidity float

variable_types: temp float

variable_types: lux float

variable_types: struct usb_i2c_data { unsigned char reg; unsigned char *buf; short len; }

variable_types:
a
unsigned char


decompiled_code:
__int64 __fastcall usb_i2c_write_byte(int fd, char a2, char a3)
{
struct timeval v4; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF
char buf[11]; // [rsp+9Dh] [rbp-Bh] BYREF

buf[0] = 83;
buf[1] = 2 * a2;
buf[2] = a3;
if ( write(fd, buf, 3uLL) <= 2 )
return 0xFFFFFFFFLL;
tcdrain(fd);
v4.tv_usec = 500000LL;
v4.tv_sec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( !select(1024, &readfds, 0LL, 0LL, &v4) )
return 0xFFFFFFFFLL;
if ( read(fd, buf, 1uLL) <= 0 )
return 0xFFFFFFFFLL;
return (unsigned int)-(buf[0] == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, char a2, char a3)
{
struct timeval v4; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF
char buf[11]; // [rsp+9Dh] [rbp-Bh] BYREF

buf[0] = 83;
buf[1] = 2 * a2;
buf[2] = a3;
if ( write(fd, buf, 3uLL) <= 2 )
return 0xFFFFFFFFLL;
tcdrain(fd);
v4.tv_usec = 500000LL;
v4.tv_sec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( !select(1024, &readfds, 0LL, 0LL, &v4) )
return 0xFFFFFFFFLL;
if ( read(fd, buf, 1uLL) <= 0 )
return 0xFFFFFFFFLL;
return (unsigned int)-(buf[0] == 0);
}

original_code:
int usb_i2c_write_byte(int fd, unsigned char addr, unsigned char value)
{
 ssize_t sz;
 unsigned char data[3];
 fd_set set;
 struct timeval timeout;
 data[0] = 0x53;
 data[1] = (addr << 1);
 data[2] = value;
 sz = (write(fd, data, 3 * sizeof(unsigned char)));
 if (sz < 3)
  return -1;
 tcdrain(fd);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 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)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, data, 1);
 if (sz < 1)
  return -1;
 if (data[0] == 0)
  return -1;
 return 0;
}

canonical_original_code:
int usb_i2c_write_byte(int fd, unsigned char addr, unsigned char value)
{
 long sz;
 unsigned char data[3];
 struct fd_set set;
 struct timeval timeout;
 data[0] = 0x53;
 data[1] = (addr << 1);
 data[2] = value;
 sz = (write(fd, data, 3 * sizeof(unsigned char)));
 if (sz < 3)
  return -1;
 tcdrain(fd);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 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)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, data, 1);
 if (sz < 1)
  return -1;
 if (data[0] == 0)
  return -1;
 return 0;
}

variable_types:
addr
unsigned char

variable_types:
value
unsigned char

variable_types: sz long

variable_types:
data
unsigned char [3]

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

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


decompiled_code:
__int64 __fastcall usb_i2c_read_byte_data(int fd, char a2, void *a3, signed __int64 a4, __useconds_t a5)
{
signed __int64 v8; // rax
unsigned int v9; // ebx
struct timeval v11; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF
char buf[43]; // [rsp+9Dh] [rbp-2Bh] BYREF

buf[0] = 84;
buf[1] = 2 * a2 + 1;
buf[2] = a4;
if ( write(fd, buf, 3uLL) <= 2 )
return 0xFFFFFFFFLL;
tcdrain(fd);
usleep(a5);
v11.tv_usec = 500000LL;
v11.tv_sec = 0LL;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( !select(1024, &readfds, 0LL, 0LL, &v11) )
return 0xFFFFFFFFLL;
v8 = read(fd, buf, a4);
v9 = v8;
if ( a4 > v8 )
return 0xFFFFFFFFLL;
memcpy(a3, buf, v8);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, char a2, void *a3, signed __int64 a4, __useconds_t a5)
{
signed __int64 v8; // rax
unsigned int v9; // ebx
struct timeval v11; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF
char buf[43]; // [rsp+9Dh] [rbp-2Bh] BYREF

buf[0] = 84;
buf[1] = 2 * a2 + 1;
buf[2] = a4;
if ( write(fd, buf, 3uLL) <= 2 )
return 0xFFFFFFFFLL;
tcdrain(fd);
usleep(a5);
v11.tv_usec = 500000LL;
v11.tv_sec = 0LL;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( !select(1024, &readfds, 0LL, 0LL, &v11) )
return 0xFFFFFFFFLL;
v8 = read(fd, buf, a4);
v9 = v8;
if ( a4 > v8 )
return 0xFFFFFFFFLL;
memcpy(a3, buf, v8);
return v9;
}

original_code:
int usb_i2c_read_byte_data(int fd, unsigned char addr, unsigned char* values, ssize_t size, int usecs)
{
 ssize_t sz;
 unsigned char data[3];
 fd_set set;
 struct timeval timeout;
 data[0] = 0x54;
 data[1] = (addr << 1) | 1;
 data[2] = size;
 sz = (write(fd, data, 3 * sizeof(unsigned char)));
 if (sz < 3)
  return -1;
 tcdrain(fd);
 usleep(usecs);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, data, size);
 if (sz < size)
  return -1;
 memcpy(values, data, sz);
 return sz;
}

canonical_original_code:
int usb_i2c_read_byte_data(int fd, unsigned char addr, unsigned char *values, long size, int usecs)
{
 long sz;
 unsigned char data[3];
 struct fd_set set;
 struct timeval timeout;
 data[0] = 0x54;
 data[1] = (addr << 1) | 1;
 data[2] = size;
 sz = (write(fd, data, 3 * sizeof(unsigned char)));
 if (sz < 3)
  return -1;
 tcdrain(fd);
 usleep(usecs);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, data, size);
 if (sz < size)
  return -1;
 memcpy(values, data, sz);
 return sz;
}

variable_types: fd int

variable_types:
values
unsigned char *

variable_types: size long

variable_types: usecs int

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


decompiled_code:
__int64 __fastcall usb_i2c_read_reg_data(int fd, char a2, __int64 a3)
{
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF
char buf[28]; // [rsp+9Ch] [rbp-1Ch] BYREF

buf[0] = 85;
buf[1] = 2 * a2 + 1;
buf[2] = *(_BYTE *)a3;
buf[3] = *(_WORD *)(a3 + 16);
if ( (unsigned __int64)write(fd, buf, 4uLL) <= 3 )
return 0xFFFFFFFFLL;
tcdrain(fd);
memset(*(void **)(a3 + 8), 0, *(__int16 *)(a3 + 16));
v5.tv_usec = 500000LL;
v5.tv_sec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( select(1024, &readfds, 0LL, 0LL, &v5) )
result = (unsigned int)-(*(__int16 *)(a3 + 16) > read(fd, *(void **)(a3 + 8), *(__int16 *)(a3 + 16)));
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, char a2, __int64 a3)
{
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF
char buf[28]; // [rsp+9Ch] [rbp-1Ch] BYREF

buf[0] = 85;
buf[1] = 2 * a2 + 1;
buf[2] = *(_BYTE *)a3;
buf[3] = *(_WORD *)(a3 + 16);
if ( (unsigned __int64)write(fd, buf, 4uLL) <= 3 )
return 0xFFFFFFFFLL;
tcdrain(fd);
memset(*(void **)(a3 + 8), 0, *(__int16 *)(a3 + 16));
v5.tv_usec = 500000LL;
v5.tv_sec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( select(1024, &readfds, 0LL, 0LL, &v5) )
result = (unsigned int)-(*(__int16 *)(a3 + 16) > read(fd, *(void **)(a3 + 8), *(__int16 *)(a3 + 16)));
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int usb_i2c_read_reg_data(int fd, unsigned char addr, struct usb_i2c_data *data)
{
 ssize_t sz;
 size_t msg_size = 4;
 unsigned char msg[msg_size];
 fd_set set;
 struct timeval timeout;
 bzero(msg, msg_size);
 msg[0] = 0x55;
 msg[1] = (addr << 1) | 1;
 msg[2] = data->reg;
 msg[3] = data->len;
 sz = write(fd, msg, msg_size);
 if (sz < msg_size)
  return -1;
 tcdrain(fd);
 bzero(data->buf, data->len);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 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)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, data->buf, data->len);
 if (sz < data->len)
  return -1;
 return 0;
}

canonical_original_code:
int usb_i2c_read_reg_data(int fd, unsigned char addr, struct usb_i2c_data *data)
{
 long sz;
 unsigned long msg_size = 4;
 unsigned char msg[-1];
 struct fd_set set;
 struct timeval timeout;
 bzero(msg, msg_size);
 msg[0] = 0x55;
 msg[1] = (addr << 1) | 1;
 msg[2] = data->reg;
 msg[3] = data->len;
 sz = write(fd, msg, msg_size);
 if (sz < msg_size)
  return -1;
 tcdrain(fd);
 bzero(data->buf, data->len);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 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)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, data->buf, data->len);
 if (sz < data->len)
  return -1;
 return 0;
}

variable_types: struct usb_i2c_data { unsigned char reg; unsigned char *buf; short len; } *

variable_types:
msg
unsigned char [-1]


decompiled_code:
__int64 __fastcall usb_i2c_write_reg_data(int fd, char a2, __int64 a3)
{
__int16 v4; // r15
_BYTE *v5; // rax
_BYTE *v6; // rbx
struct timeval v8; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

v4 = *(_WORD *)(a3 + 16);
v5 = malloc(v4 + 4);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = v5;
memset(v5, 0, v4 + 4);
*v6 = 85;
v6[1] = 2 * a2;
v6[2] = *(_BYTE *)a3;
v6[3] = v4;
memcpy(v6 + 4, *(const void **)(a3 + 8), v4);
if ( write(fd, v6, v4 + 4) < (unsigned __int64)(v4 + 4) )
return 0xFFFFFFFFLL;
tcdrain(fd);
v8.tv_usec = 500000LL;
v8.tv_sec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( !select(1024, &readfds, 0LL, 0LL, &v8) )
return 0xFFFFFFFFLL;
if ( read(fd, v6, 1uLL) <= 0 )
return 0xFFFFFFFFLL;
return (unsigned int)-(*v6 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, char a2, __int64 a3)
{
__int16 v4; // r15
_BYTE *v5; // rax
_BYTE *v6; // rbx
struct timeval v8; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

v4 = *(_WORD *)(a3 + 16);
v5 = malloc(v4 + 4);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = v5;
memset(v5, 0, v4 + 4);
*v6 = 85;
v6[1] = 2 * a2;
v6[2] = *(_BYTE *)a3;
v6[3] = v4;
memcpy(v6 + 4, *(const void **)(a3 + 8), v4);
if ( write(fd, v6, v4 + 4) < (unsigned __int64)(v4 + 4) )
return 0xFFFFFFFFLL;
tcdrain(fd);
v8.tv_usec = 500000LL;
v8.tv_sec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( !select(1024, &readfds, 0LL, 0LL, &v8) )
return 0xFFFFFFFFLL;
if ( read(fd, v6, 1uLL) <= 0 )
return 0xFFFFFFFFLL;
return (unsigned int)-(*v6 == 0);
}

original_code:
int usb_i2c_write_reg_data(int fd, unsigned char addr, struct usb_i2c_data *data)
{
 ssize_t sz;
 unsigned char *msg;
 size_t msg_size = 4 + data->len;
 fd_set set;
 struct timeval timeout;
 msg = malloc(msg_size);
 if (msg == ((void *)0))
  return -1;
 bzero(msg, msg_size);
 msg[0] = 0x55;
 msg[1] = (addr << 1);
 msg[2] = data->reg;
 msg[3] = data->len;
 memcpy((msg+4), data->buf, data->len);
 sz = write(fd, msg, msg_size);
 if (sz < msg_size)
  return -1;
 tcdrain(fd);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 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)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, msg, 1);
 if (sz < 1)
  return -1;
 if (msg[0] == 0)
  return -1;
 return 0;
}

canonical_original_code:
int usb_i2c_write_reg_data(int fd, unsigned char addr, struct usb_i2c_data *data)
{
 long sz;
 unsigned char *msg;
 unsigned long msg_size = 4 + data->len;
 struct fd_set set;
 struct timeval timeout;
 msg = malloc(msg_size);
 if (msg == ((void *)0))
  return -1;
 bzero(msg, msg_size);
 msg[0] = 0x55;
 msg[1] = (addr << 1);
 msg[2] = data->reg;
 msg[3] = data->len;
 memcpy((msg+4), data->buf, data->len);
 sz = write(fd, msg, msg_size);
 if (sz < msg_size)
  return -1;
 tcdrain(fd);
 timeout.tv_usec=500000;
 timeout.tv_sec=0;
 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)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if ( select((1024), &set, ((void *)0), ((void *)0), &timeout) == 0 )
  return -1;
 sz = read(fd, msg, 1);
 if (sz < 1)
  return -1;
 if (msg[0] == 0)
  return -1;
 return 0;
}

variable_types:
msg
unsigned char *

user_defined_types: struct usb_i2c_data { unsigned char reg; unsigned char *buf; short len; }


setterm

decompiled_code:
int __fastcall setterm(int fd, int a2)
{
int result; // eax
struct termios v3; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

*(_QWORD *)&termios_p.c_iflag = 6LL;
termios_p.c_lflag = 0;
*(_QWORD *)&termios_p.c_line = 0x100000000000000LL;
*(_QWORD *)&termios_p.c_cc[7] = 0LL;
*(_QWORD *)&termios_p.c_cc[15] = 0LL;
*(_QWORD *)&termios_p.c_cc[23] = 0LL;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
termios_p.c_cflag = a2 & 0x7FFFFFFF | 0x8B0;
result = tcflush(fd, 2);
if ( result != -1 )
{
result = tcsetattr(fd, 0, &termios_p);
if ( result != -1 )
{
result = tcgetattr(fd, &v3);
if ( result != -1 )
result = memcmp(&termios_p, &v3, 0x3CuLL) == 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int fd, int a2)
{
int result; // eax
struct termios v3; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

*(_QWORD *)&termios_p.c_iflag = 6LL;
termios_p.c_lflag = 0;
*(_QWORD *)&termios_p.c_line = 0x100000000000000LL;
*(_QWORD *)&termios_p.c_cc[7] = 0LL;
*(_QWORD *)&termios_p.c_cc[15] = 0LL;
*(_QWORD *)&termios_p.c_cc[23] = 0LL;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
termios_p.c_cflag = a2 & 0x7FFFFFFF | 0x8B0;
result = tcflush(fd, 2);
if ( result != -1 )
{
result = tcsetattr(fd, 0, &termios_p);
if ( result != -1 )
{
result = tcgetattr(fd, &v3);
if ( result != -1 )
result = memcmp(&termios_p, &v3, 0x3CuLL) == 0;
}
}
return result;
}

variable_types:
baudrate
unsigned int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *


menu

repo: slacknux/cSnake

decompiled_code:
int menu()
{
int result; // eax

mvprintw(LINES / 2 - 8, COLS / 2 - 18, " **** ** * *** * * ****");
mvprintw(LINES / 2 - 7, COLS / 2 - 18, "*** **** * * * ***** ** ***");
mvprintw(LINES / 2 - 6, COLS / 2 - 18, "*** ***** * ** * * * * ****");
mvprintw(LINES / 2 - 4, COLS / 2 - 6, "by slacknux");
mvprintw(LINES / 2 - 1, COLS / 2 - 25, "LEVEL");
mvprintw(LINES / 2 + 1, COLS / 2 - 25, "1. easy");
mvprintw(LINES / 2 + 2, COLS / 2 - 25, "2. normal");
mvprintw(LINES / 2 + 3, COLS / 2 - 25, "3. hard");
mvprintw(LINES / 2 - 1, COLS / 2 + 17, "CONTROLS");
mvprintw(LINES / 2 + 1, COLS / 2 + 7, "arrow keys to move");
mvprintw(LINES / 2 + 2, COLS / 2 + 7, "space bar to pause");
mvprintw(LINES / 2 + 3, COLS / 2 + 7, "esc to exit");
mvprintw(LINES / 2 + 6, COLS / 2 - 9, "(choice a number)");
do
result = wgetch(stdscr);
while ( (unsigned int)(result - 49) > 2 );
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

mvprintw(LINES / 2 - 8, COLS / 2 - 18, " **** ** * *** * * ****");
mvprintw(LINES / 2 - 7, COLS / 2 - 18, "*** **** * * * ***** ** ***");
mvprintw(LINES / 2 - 6, COLS / 2 - 18, "*** ***** * ** * * * * ****");
mvprintw(LINES / 2 - 4, COLS / 2 - 6, "by slacknux");
mvprintw(LINES / 2 - 1, COLS / 2 - 25, "LEVEL");
mvprintw(LINES / 2 + 1, COLS / 2 - 25, "1. easy");
mvprintw(LINES / 2 + 2, COLS / 2 - 25, "2. normal");
mvprintw(LINES / 2 + 3, COLS / 2 - 25, "3. hard");
mvprintw(LINES / 2 - 1, COLS / 2 + 17, "CONTROLS");
mvprintw(LINES / 2 + 1, COLS / 2 + 7, "arrow keys to move");
mvprintw(LINES / 2 + 2, COLS / 2 + 7, "space bar to pause");
mvprintw(LINES / 2 + 3, COLS / 2 + 7, "esc to exit");
mvprintw(LINES / 2 + 6, COLS / 2 - 9, "(choice a number)");
do
result = wgetch(stdscr);
while ( (unsigned int)(result - 49) > 2 );
return result;
}

original_code:
int menu() {
 int level;
 mvprintw(LINES/2-8, COLS/2-18, "      ****  **  *   ***   *  *  ****");
 mvprintw(LINES/2-7, COLS/2-18, "***   ****  * * *  *****  **    ***");
 mvprintw(LINES/2-6, COLS/2-18, "***  *****  *  **  *   *  *  *  ****");
 mvprintw(LINES/2-4, COLS/2-6, "by slacknux");
 mvprintw(LINES/2-1, COLS/2-25, "LEVEL");
 mvprintw(LINES/2+1, COLS/2-25, "1. easy");
 mvprintw(LINES/2+2, COLS/2-25, "2. normal");
 mvprintw(LINES/2+3, COLS/2-25, "3. hard");
 mvprintw(LINES/2-1, COLS/2+17, "CONTROLS");
 mvprintw(LINES/2+1, COLS/2+7, "arrow keys to move");
 mvprintw(LINES/2+2, COLS/2+7, "space bar to pause");
 mvprintw(LINES/2+3, COLS/2+7, "esc to exit");
 mvprintw(LINES/2+6, COLS/2-9, "(choice a number)");
 do
  level = wgetch(stdscr);
 while(level<49 || level>51);
 return level;
}

variable_types: level int


food

decompiled_code:
int __fastcall food(int a1, _DWORD *a2)
{
__int64 v3; // rbx
_DWORD *v4; // rax
int v5; // esi
int result; // eax

v3 = (__int64)&a2[2 * (a1 - 1) + 2];
while ( 1 )
{
foodx = rand() % (COLS - 2) + 1;
v5 = rand() % (LINES - 3) + 2;
foody = v5;
if ( a1 <= 0 )
break;
v4 = a2;
while ( *v4 != foodx || v5 != v4[1] )
{
v4 += 2;
if ( v4 == (_DWORD *)v3 )
goto LABEL_7;
}
}
LABEL_7:
result = wmove(stdscr, v5, foodx);
if ( result != -1 )
result = waddch(stdscr, 0x40uLL);
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, _DWORD *a2)
{
__int64 v3; // rbx
_DWORD *v4; // rax
int v5; // esi
int result; // eax

v3 = (__int64)&a2[2 * (a1 - 1) + 2];
while ( 1 )
{
foodx = rand() % (COLS - 2) + 1;
v5 = rand() % (LINES - 3) + 2;
foody = v5;
if ( a1 <= 0 )
break;
v4 = a2;
while ( *v4 != foodx || v5 != v4[1] )
{
v4 += 2;
if ( v4 == (_DWORD *)v3 )
goto LABEL_7;
}
}
LABEL_7:
result = wmove(stdscr, v5, foodx);
if ( result != -1 )
result = waddch(stdscr, 0x40uLL);
return result;
}

original_code:
void food(int count, snake *s) {
 int i;
 int flag;
 char food_body = '@';
 while(1) {
  flag = 0;
  foodx = rand() % (COLS-2) + 1;
  foody = rand() % (LINES-3) + 2;
  for(i=0; i<count; i++) {
   if(s[i].x==foodx && s[i].y==foody) {
    flag = 1;
    break;
   }
  }
  if(!flag) break;
 }
 (wmove((stdscr),((foody)),((foodx))) == (-1) ? (-1) : waddch((stdscr),((food_body))));
}

canonical_original_code:
void food(int count, struct snake *s) {
 int i;
 int flag;
 char food_body = '@';
 while(1) {
  flag = 0;
  foodx = rand() % (COLS-2) + 1;
  foody = rand() % (LINES-3) + 2;
  for(i=0; i<count; i++) {
   if(s[i].x==foodx && s[i].y==foody) {
    flag = 1;
    break;
   }
  }
  if(!flag) break;
 }
 (wmove((stdscr),((foody)),((foodx))) == (-1) ? (-1) : waddch((stdscr),((food_body))));
}

variable_types: count int

variable_types:
s
struct snake { int x; int y; } *

variable_types: i int

variable_types: flag int