decompiled_code:
__int64 __fastcall re_get_ini(const char *a1)
{
__int64 v1; // rax
void *v2; // rbp
__int64 v3; // rbx
const char *v5; // rax
const char *v6; // rax
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( game_pak )
{
v1 = pak_get_text(game_pak, a1);
v2 = (void *)v1;
if ( v1 )
{
v3 = ini_parse(v1, v8, &v7);
if ( !v3 )
{
v5 = (const char *)ini_errstr((unsigned int)v8[0]);
rerror("Unable to parse %s:%d %s", a1, v7, v5);
}
free(v2);
}
else
{
rerror("Unable to find %s in %s", a1, (const char *)pak_file_name);
v3 = 0LL;
}
}
else
{
v3 = ini_read(a1, v8, &v7);
if ( !v3 )
{
v6 = (const char *)ini_errstr((unsigned int)v8[0]);
rerror("Unable to read %s:%d %s", a1, v7, v6);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
__int64 v1; // rax
void *v2; // rbp
__int64 v3; // rbx
const char *v5; // rax
const char *v6; // rax
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( game_pak )
{
v1 = pak_get_text(game_pak, a1);
v2 = (void *)v1;
if ( v1 )
{
v3 = ini_parse(v1, v8, &v7);
if ( !v3 )
{
v5 = (const char *)ini_errstr((unsigned int)v8[0]);
rerror("Unable to parse %s:%d %s", a1, v7, v5);
}
free(v2);
}
else
{
rerror("Unable to find %s in %s", a1, (const char *)pak_file_name);
v3 = 0LL;
}
}
else
{
v3 = ini_read(a1, v8, &v7);
if ( !v3 )
{
v6 = (const char *)ini_errstr((unsigned int)v8[0]);
rerror("Unable to read %s:%d %s", a1, v7, v6);
}
}
return v3;
}

original_code:
struct ini_file *re_get_ini(const char *filename) {
 int err, line;
 struct ini_file *ini;
 if(game_pak) {
  char *text = pak_get_text(game_pak, filename);
  if(!text) {
   rerror("Unable to find %s in %s", filename, pak_file_name);
   return ((void *)0);
  }
  ini = ini_parse(text, &err, &line);
  if(!ini) {
   rerror("Unable to parse %s:%d %s", filename, line, ini_errstr(err));
  }
  free(text);
 } else {
  ini = ini_read(filename, &err, &line);
  if(!ini) {
   rerror("Unable to read %s:%d %s", filename, line, ini_errstr(err));
  }
 }
 return ini;
}

canonical_original_code:
struct ini_file *re_get_ini(char *filename) {
 int err; int line;
 struct ini_file *ini;
 if(game_pak) {
  char *text = pak_get_text(game_pak, filename);
  if(!text) {
   rerror("Unable to find %s in %s", filename, pak_file_name);
   return ((void *)0);
  }
  ini = ini_parse(text, &err, &line);
  if(!ini) {
   rerror("Unable to parse %s:%d %s", filename, line, ini_errstr(err));
  }
  free(text);
 } else {
  ini = ini_read(filename, &err, &line);
  if(!ini) {
   rerror("Unable to read %s:%d %s", filename, line, ini_errstr(err));
  }
 }
 return ini;
}

variable_types: err int

variable_types: line int

variable_types: struct ini_file { struct INI_PAIR { char *param; char *value; struct INI_PAIR *left; } *globals; struct INI_SECTION { char *name; struct INI_PAIR *fields; struct INI_SECTION *left; } *sections; } *

variable_types:
text
char *

user_defined_types: struct ini_file { struct INI_PAIR *globals; struct INI_SECTION *sections; }


repo: wernsey/rengine

decompiled_code:
__int64 __fastcall re_clone_bmp(__int64 a1, const char *a2)
{
__int64 v2; // rbp

if ( ht_get(*(_QWORD *)re_cache, a2) )
{
rerror("Attempt to clone bitmap with an existing name %s", a2);
v2 = 0LL;
}
else
{
v2 = bm_copy(a1);
ht_put(*(_QWORD *)re_cache, a2, v2);
rlog("Cached cloned bitmap as '%s'", a2);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2)
{
__int64 v2; // rbp

if ( ht_get(*(_QWORD *)re_cache, a2) )
{
rerror("Attempt to clone bitmap with an existing name %s", a2);
v2 = 0LL;
}
else
{
v2 = bm_copy(a1);
ht_put(*(_QWORD *)re_cache, a2, v2);
rlog("Cached cloned bitmap as '%s'", a2);
}
return v2;
}

original_code:
struct bitmap *re_clone_bmp(struct bitmap *b, const char *newname) {
 struct resource_cache *rc = re_cache;
 struct bitmap *clone = ht_get(rc->bmp_cache, newname);
 if(clone) {
  rerror("Attempt to clone bitmap with an existing name %s", newname);
  return ((void *)0);
 }
 clone = bm_copy(b);
 ht_put(re_cache->bmp_cache, newname, clone);
 rlog("Cached cloned bitmap as '%s'", newname);
 return clone;
}

canonical_original_code:
struct bitmap *re_clone_bmp(struct bitmap *b, char *newname) {
 struct resource_cache *rc = re_cache;
 struct bitmap *clone = ht_get(rc->bmp_cache, newname);
 if(clone) {
  rerror("Attempt to clone bitmap with an existing name %s", newname);
  return ((void *)0);
 }
 clone = bm_copy(b);
 ht_put(re_cache->bmp_cache, newname, clone);
 rlog("Cached cloned bitmap as '%s'", newname);
 return clone;
}

variable_types:
b
struct bitmap *

variable_types:
newname
char *

variable_types: struct resource_cache { struct hash_tbl { struct hash_el { char *key; void *value; struct hash_el *next; } **buckets; int size; int cnt; } *bmp_cache; struct hash_tbl *wav_cache; struct hash_tbl *mus_cache; struct resource_cache *parent; } *

variable_types: struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; } *font; struct { int x0; int x1; } clip; } *

user_defined_types: struct resource_cache { struct hash_tbl *bmp_cache; struct hash_tbl *wav_cache; struct hash_tbl *mus_cache; struct resource_cache *parent; }

user_defined_types: struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font *font; struct { int x0; int x1; } clip; }

user_defined_types: struct hash_tbl { struct hash_el **buckets; int size; int cnt; }


decompiled_code:
__int64 __fastcall re_get_script(const char *a1)
{
__int64 v1; // rbx

if ( game_pak )
{
v1 = pak_get_text(game_pak, a1);
if ( !v1 )
rerror("Unable to load script '%s' from %s", a1, (const char *)pak_file_name);
}
else
{
v1 = my_readfile(a1);
if ( !v1 )
rerror("Couldn't load script '%s'", a1);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1)
{
__int64 v1; // rbx

if ( game_pak )
{
v1 = pak_get_text(game_pak, a1);
if ( !v1 )
rerror("Unable to load script '%s' from %s", a1, (const char *)pak_file_name);
}
else
{
v1 = my_readfile(a1);
if ( !v1 )
rerror("Couldn't load script '%s'", a1);
}
return v1;
}

original_code:
char *re_get_script(const char *filename) {
 char *txt;
 if(game_pak) {
  txt = pak_get_text(game_pak, filename);
  if(!txt) {
   rerror("Unable to load script '%s' from %s", filename, pak_file_name);
  }
 } else {
  txt = my_readfile(filename);
  if(!txt) {
   rerror("Couldn't load script '%s'", filename);
   return 0;
  }
 }
 return txt;
}

canonical_original_code:
char *re_get_script(char *filename) {
 char *txt;
 if(game_pak) {
  txt = pak_get_text(game_pak, filename);
  if(!txt) {
   rerror("Unable to load script '%s' from %s", filename, pak_file_name);
  }
 } else {
  txt = my_readfile(filename);
  if(!txt) {
   rerror("Couldn't load script '%s'", filename);
   return 0;
  }
 }
 return txt;
}

variable_types:
filename
char *

variable_types:
txt
char *

return_type: char *


original_code:
void ts_init(struct tile_collection *tc, int tw, int th) {
 tc->tilesets = ((void *)0);
 tc->ntilesets = 0;
 tc->tw = tw;
 tc->th = th;
}

variable_types: struct tile_collection { int tw; struct tileset { struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; } *font; struct { int x0; int x1; } clip; } *bm; char *name; int border; int nmeta; struct tile_meta { int ti; char *clas; int flags; } *meta; } **tilesets; int ntilesets; } *

variable_types: tw int

variable_types: th int

return_type: void

user_defined_types: struct tile_collection { int tw; struct tileset **tilesets; int ntilesets; }

user_defined_types: struct tileset { struct bitmap *bm; char *name; int border; int nmeta; struct tile_meta *meta; }


original_code:
void ts_deinit(struct tile_collection *tc) {
 int i;
 if(!tc->tilesets)
  return;
 for(i = 0; i < tc->ntilesets; i++) {
  ts_free(tc->tilesets[i]);
 }
 free(tc->tilesets);
 tc->tilesets = ((void *)0);
 tc->ntilesets = 0;
}

variable_types: i int

user_defined_types: struct tile_meta { int ti; char *clas; int flags; }

user_defined_types: struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; }


decompiled_code:
__int64 __fastcall ts_add(__int64 a1, char *a2)
{
char *v2; // rax
char *v3; // r12
__int64 result; // rax

v2 = (char *)realloc(*(void **)(a1 + 8), 8LL * (*(_DWORD *)(a1 + 16) + 1));
*(_QWORD *)(a1 + 8) = v2;
if ( v2 )
{
v3 = &v2[8 * *(int *)(a1 + 16)];
*(_QWORD *)v3 = ts_make(a2);
result = *(unsigned int *)(a1 + 16);
if ( *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)result) )
*(_DWORD *)(a1 + 16) = result + 1;
else
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a1 + 16) = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
char *v2; // rax
char *v3; // r12
__int64 result; // rax

v2 = (char *)realloc(*(void **)(a1 + 8), 8LL * (*(_DWORD *)(a1 + 16) + 1));
*(_QWORD *)(a1 + 8) = v2;
if ( v2 )
{
v3 = &v2[8 * *(int *)(a1 + 16)];
*(_QWORD *)v3 = ts_make(a2);
result = *(unsigned int *)(a1 + 16);
if ( *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)result) )
*(_DWORD *)(a1 + 16) = result + 1;
else
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a1 + 16) = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int ts_add(struct tile_collection *tc, const char *filename) {
 tc->tilesets = realloc(tc->tilesets, (tc->ntilesets + 1) * sizeof *tc->tilesets);
 if(!tc->tilesets) {
  tc->ntilesets = 0;
  return -1;
 }
 tc->tilesets[tc->ntilesets] = ts_make(filename);
 if(!tc->tilesets[tc->ntilesets]) {
  return -1;
 }
 return tc->ntilesets++;
}

canonical_original_code:
int ts_add(struct tile_collection *tc, char *filename) {
 tc->tilesets = realloc(tc->tilesets, (tc->ntilesets + 1) * sizeof *tc->tilesets);
 if(!tc->tilesets) {
  tc->ntilesets = 0;
  return -1;
 }
 tc->tilesets[tc->ntilesets] = ts_make(filename);
 if(!tc->tilesets[tc->ntilesets]) {
  return -1;
 }
 return tc->ntilesets++;
}

return_type: int


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

if ( *(_DWORD *)(a1 + 16) <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 16) <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
struct tileset *ts_get(struct tile_collection *tc, int i) {
 if(i >= tc->ntilesets || i < 0)
  return ((void *)0);
 return tc->tilesets[i];
}

variable_types: struct tile_collection { int tw; struct tileset **tilesets; int ntilesets; } *

return_type: struct tileset { struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; } *font; struct { int x0; int x1; } clip; } *bm; char *name; int border; int nmeta; struct tile_meta { int ti; char *clas; int flags; } *meta; } *


decompiled_code:
__int64 __fastcall ts_get_num(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int ts_get_num(struct tile_collection *tc) {
 return tc->ntilesets;
}


decompiled_code:
__int64 __fastcall ts_find(__int64 a1, const char *a2)
{
int v2; // eax
__int64 *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbp

if ( !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 16);
if ( v2 <= 0 )
{
LABEL_6:
rerror("Couldn't find tileset %s", a2);
v5 = 0LL;
}
else
{
v3 = *(__int64 **)(a1 + 8);
v4 = (__int64)&v3[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(*(const char **)(*v3 + 8), a2) )
break;
if ( ++v3 == (__int64 *)v4 )
goto LABEL_6;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
int v2; // eax
__int64 *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbp

if ( !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 16);
if ( v2 <= 0 )
{
LABEL_6:
rerror("Couldn't find tileset %s", a2);
v5 = 0LL;
}
else
{
v3 = *(__int64 **)(a1 + 8);
v4 = (__int64)&v3[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(*(const char **)(*v3 + 8), a2) )
break;
if ( ++v3 == (__int64 *)v4 )
goto LABEL_6;
}
}
return v5;
}

original_code:
struct tileset *ts_find(struct tile_collection *tc, const char *name) {
 int i;
 if(!name) return ((void *)0);
 for(i = 0; i < tc->ntilesets; i++) {
  if(!strcmp(tc->tilesets[i]->name, name))
   return tc->tilesets[i];
 }
 rerror("Couldn't find tileset %s", name);
 return ((void *)0);
}

canonical_original_code:
struct tileset *ts_find(struct tile_collection *tc, char *name) {
 int i;
 if(!name) return ((void *)0);
 for(i = 0; i < tc->ntilesets; i++) {
  if(!strcmp(tc->tilesets[i]->name, name))
   return tc->tilesets[i];
 }
 rerror("Couldn't find tileset %s", name);
 return ((void *)0);
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall ts_index_of(__int64 a1, const char *a2)
{
int v2; // er12
__int64 v3; // r14
__int64 v4; // rbx
unsigned int v5; // er13

if ( !a2 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a1 + 16);
if ( v2 <= 0 )
{
LABEL_6:
rerror("Couldn't find tileset %s", a2);
v5 = -1;
}
else
{
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !strcmp(*(const char **)(*(_QWORD *)(v3 + 8 * v4) + 8LL), a2) )
break;
if ( ++v4 == v2 )
goto LABEL_6;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
int v2; // er12
__int64 v3; // r14
__int64 v4; // rbx
unsigned int v5; // er13

if ( !a2 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a1 + 16);
if ( v2 <= 0 )
{
LABEL_6:
rerror("Couldn't find tileset %s", a2);
v5 = -1;
}
else
{
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !strcmp(*(const char **)(*(_QWORD *)(v3 + 8 * v4) + 8LL), a2) )
break;
if ( ++v4 == v2 )
goto LABEL_6;
}
}
return v5;
}

original_code:
int ts_index_of(struct tile_collection *tc, const char *name) {
 int i;
 if(!name) return -1;
 for(i = 0; i < tc->ntilesets; i++) {
  if(!strcmp(tc->tilesets[i]->name, name))
   return i;
 }
 rerror("Couldn't find tileset %s", name);
 return -1;
}

canonical_original_code:
int ts_index_of(struct tile_collection *tc, char *name) {
 int i;
 if(!name) return -1;
 for(i = 0; i < tc->ntilesets; i++) {
  if(!strcmp(tc->tilesets[i]->name, name))
   return i;
 }
 rerror("Couldn't find tileset %s", name);
 return -1;
}


decompiled_code:
__int64 __fastcall ts_valid_class(const char *a1)
{
const char *v1; // rbp
size_t v2; // rdx
__int64 result; // rax
char v4; // bl
const unsigned __int16 *v5; // rdx

v1 = a1;
v2 = strlen(a1);
result = 0LL;
if ( v2 <= 0x14 )
{
v4 = *a1;
if ( *a1 )
{
v5 = *_ctype_b_loc();
do
{
if ( (v5[v4] & 8) == 0 && v4 != 95 )
return 0LL;
v4 = *++v1;
}
while ( *v1 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
const char *v1; // rbp
size_t v2; // rdx
__int64 result; // rax
char v4; // bl
const unsigned __int16 *v5; // rdx

v1 = a1;
v2 = strlen(a1);
result = 0LL;
if ( v2 <= 0x14 )
{
v4 = *a1;
if ( *a1 )
{
v5 = *_ctype_b_loc();
do
{
if ( (v5[v4] & 8) == 0 && v4 != 95 )
return 0LL;
v4 = *++v1;
}
while ( *v1 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int ts_valid_class(const char *clas) {
 if(strlen(clas) > 20)
  return 0;
 while(*clas) {
  if(!((*__ctype_b_loc ())[(int) ((*clas))] & (unsigned short int) _ISalnum) && *clas != '_')
   return 0;
  clas++;
 }
 return 1;
}

canonical_original_code:
int ts_valid_class(char *clas) {
 if(strlen(clas) > 20)
  return 0;
 while(*clas) {
  if(!((*__ctype_b_loc ())[(int) ((*clas))] & (unsigned short) _ISalnum) && *clas != '_')
   return 0;
  clas++;
 }
 return 1;
}

variable_types:
clas
char *


decompiled_code:
_BOOL8 __fastcall ts_load_all(_DWORD *a1, const char *a2)
{
__int64 v2; // rax
void *v3; // rbx
__int64 v4; // r12
_BOOL4 v5; // ebp

v2 = my_readfile(a2);
if ( v2 )
{
v3 = (void *)v2;
v4 = json_parse(v2);
if ( v4 )
{
rlog("Loading tileset from %s", a2);
v5 = ts_read_all(a1, v4);
free(v3);
json_free(v4);
}
else
{
rerror("Unable to parse JSON: %s", a2);
v5 = 0;
}
}
else
{
rerror("Unable to read tileset from %s", a2);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1, const char *a2)
{
__int64 v2; // rax
void *v3; // rbx
__int64 v4; // r12
_BOOL4 v5; // ebp

v2 = my_readfile(a2);
if ( v2 )
{
v3 = (void *)v2;
v4 = json_parse(v2);
if ( v4 )
{
rlog("Loading tileset from %s", a2);
v5 = func12(a1, v4);
free(v3);
json_free(v4);
}
else
{
rerror("Unable to parse JSON: %s", a2);
v5 = 0;
}
}
else
{
rerror("Unable to read tileset from %s", a2);
v5 = 0;
}
return v5;
}

original_code:
int ts_load_all(struct tile_collection *tc, const char *filename) {
 int r;
 struct json *j;
 char *text = my_readfile (filename);
 if(!text) {
  rerror("Unable to read tileset from %s", filename);
  return 0;
 }
 j = json_parse(text);
 if(!j) {
  rerror("Unable to parse JSON: %s", filename);
  return 0;
 }
 rlog("Loading tileset from %s", filename);
 r = ts_read_all(tc, j);
 free(text);
 json_free(j);
 return r;
}

canonical_original_code:
int ts_load_all(struct tile_collection *tc, char *filename) {
 int r;
 struct json *j;
 char *text = my_readfile (filename);
 if(!text) {
  rerror("Unable to read tileset from %s", filename);
  return 0;
 }
 j = json_parse(text);
 if(!j) {
  rerror("Unable to parse JSON: %s", filename);
  return 0;
 }
 rlog("Loading tileset from %s", filename);
 r = ts_read_all(tc, j);
 free(text);
 json_free(j);
 return r;
}

variable_types: r int

variable_types: struct json { enum json_type { j_string=0, j_number=1, j_object=2, j_array=3, j_true=4, j_false=5, j_null=6 } type; void *value; struct json *next; } *

user_defined_types: struct json { enum json_type type; void *value; struct json *next; }


handleSpecialKeys

decompiled_code:
__int64 __fastcall handleSpecialKeys(int a1)
{
__int64 result; // rax
const char *v2; // rdx
int v3; // edx
const char *v4; // rax
int v5; // edx
const char *v6; // rax
char v7[264]; // [rsp-108h] [rbp-108h] BYREF

if ( a1 == 41 )
{
result = 0LL;
if ( (unsigned __int8)keys[229] | (unsigned __int8)keys[225] )
{
quit = 1;
result = 1LL;
}
}
else if ( a1 == 68 )
{
if ( (SDL_GetWindowFlags(win) & 0x1001) != 0 )
{
v5 = SDL_SetWindowFullscreen(win, 0LL);
result = 1LL;
if ( v5 < 0 )
{
v6 = (const char *)SDL_GetError();
rerror("Unable to set window to windowed: %s", v6);
result = 1LL;
}
}
else
{
v3 = SDL_SetWindowFullscreen(win, "dow to fullscreen: %s", v2);
result = 1LL;
if ( v3 < 0 )
{
v4 = (const char *)SDL_GetError();
rerror("Unable to set window to fullscreen: %s", v4);
result = 1LL;
}
}
}
else
{
result = 0LL;
if ( a1 == 69 )
{
snprintf(v7, 0x100uLL, "%s/save.png", initial_dir);
bm_save(bmp, v7);
rlog("Screenshot saved as %s", v7);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
const char *v2; // rdx
int v3; // edx
const char *v4; // rax
int v5; // edx
const char *v6; // rax
char v7[264]; // [rsp-108h] [rbp-108h] BYREF

if ( a1 == 41 )
{
result = 0LL;
if ( (unsigned __int8)keys[229] | (unsigned __int8)keys[225] )
{
quit = 1;
result = 1LL;
}
}
else if ( a1 == 68 )
{
if ( (SDL_GetWindowFlags(win) & 0x1001) != 0 )
{
v5 = SDL_SetWindowFullscreen(win, 0LL);
result = 1LL;
if ( v5 < 0 )
{
v6 = (const char *)SDL_GetError();
rerror("Unable to set window to windowed: %s", v6);
result = 1LL;
}
}
else
{
v3 = SDL_SetWindowFullscreen(win, "dow to fullscreen: %s", v2);
result = 1LL;
if ( v3 < 0 )
{
v4 = (const char *)SDL_GetError();
rerror("Unable to set window to fullscreen: %s", v4);
result = 1LL;
}
}
}
else
{
result = 0LL;
if ( a1 == 69 )
{
snprintf(v7, 0x100uLL, "%s/save.png", initial_dir);
bm_save(bmp, v7);
rlog("Screenshot saved as %s", v7);
result = 1LL;
}
}
return result;
}

original_code:
int handleSpecialKeys(SDL_Scancode key) {
 if(key == SDL_SCANCODE_ESCAPE && (keys[SDL_SCANCODE_LSHIFT] || keys[SDL_SCANCODE_RSHIFT])) {
  quit = 1;
  return 1;
 } else if (key == SDL_SCANCODE_F11) {
  if(!(SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN_DESKTOP)) {
   if(SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP) < 0)
    rerror("Unable to set window to fullscreen: %s", SDL_GetError());
  } else if(SDL_SetWindowFullscreen(win, 0) < 0) {
   rerror("Unable to set window to windowed: %s", SDL_GetError());
  }
  return 1;
 } else if(key == SDL_SCANCODE_F12) {
        char filename[256];
        snprintf(filename, sizeof filename, "%s/save.png", initial_dir);
  bm_save(bmp, filename);
  rlog("Screenshot saved as %s", filename);
  return 1;
 }
 return 0;
}

canonical_original_code:
int handleSpecialKeys(enum SDL_Scancode key) {
 if(key == SDL_SCANCODE_ESCAPE && (keys[SDL_SCANCODE_LSHIFT] || keys[SDL_SCANCODE_RSHIFT])) {
  quit = 1;
  return 1;
 } else if (key == SDL_SCANCODE_F11) {
  if(!(SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN_DESKTOP)) {
   if(SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP) < 0)
    rerror("Unable to set window to fullscreen: %s", SDL_GetError());
  } else if(SDL_SetWindowFullscreen(win, 0) < 0) {
   rerror("Unable to set window to windowed: %s", SDL_GetError());
  }
  return 1;
 } else if(key == SDL_SCANCODE_F12) {
        char filename[256];
        snprintf(filename, sizeof filename, "%s/save.png", initial_dir);
  bm_save(bmp, filename);
  rlog("Screenshot saved as %s", filename);
  return 1;
 }
 return 0;
}

variable_types: enum SDL_Scancode { SDL_SCANCODE_UNKNOWN=0, SDL_SCANCODE_A=4, SDL_SCANCODE_B=5, SDL_SCANCODE_C=6, SDL_SCANCODE_D=7, SDL_SCANCODE_E=8, SDL_SCANCODE_F=9, SDL_SCANCODE_G=10, SDL_SCANCODE_H=11, SDL_SCANCODE_I=12, SDL_SCANCODE_J=13, SDL_SCANCODE_K=14, SDL_SCANCODE_L=15, SDL_SCANCODE_M=16, SDL_SCANCODE_N=17, SDL_SCANCODE_O=18, SDL_SCANCODE_P=19, SDL_SCANCODE_Q=20, SDL_SCANCODE_R=21, SDL_SCANCODE_S=22, SDL_SCANCODE_T=23, SDL_SCANCODE_U=24, SDL_SCANCODE_V=25, SDL_SCANCODE_W=26, SDL_SCANCODE_X=27, SDL_SCANCODE_Y=28, SDL_SCANCODE_Z=29, SDL_SCANCODE_1=30, SDL_SCANCODE_2=31, SDL_SCANCODE_3=32, SDL_SCANCODE_4=33, SDL_SCANCODE_5=34, SDL_SCANCODE_6=35, SDL_SCANCODE_7=36, SDL_SCANCODE_8=37, SDL_SCANCODE_9=38, SDL_SCANCODE_0=39, SDL_SCANCODE_RETURN=40, SDL_SCANCODE_ESCAPE=41, SDL_SCANCODE_BACKSPACE=42, SDL_SCANCODE_TAB=43, SDL_SCANCODE_SPACE=44, SDL_SCANCODE_MINUS=45, SDL_SCANCODE_EQUALS=46, SDL_SCANCODE_LEFTBRACKET=47, SDL_SCANCODE_RIGHTBRACKET=48, SDL_SCANCODE_BACKSLASH=49, SDL_SCANCODE_NONUSHASH=50, SDL_SCANCODE_SEMICOLON=51, SDL_SCANCODE_APOSTROPHE=52, SDL_SCANCODE_GRAVE=53, SDL_SCANCODE_COMMA=54, SDL_SCANCODE_PERIOD=55, SDL_SCANCODE_SLASH=56, SDL_SCANCODE_CAPSLOCK=57, SDL_SCANCODE_F1=58, SDL_SCANCODE_F2=59, SDL_SCANCODE_F3=60, SDL_SCANCODE_F4=61, SDL_SCANCODE_F5=62, SDL_SCANCODE_F6=63, SDL_SCANCODE_F7=64, SDL_SCANCODE_F8=65, SDL_SCANCODE_F9=66, SDL_SCANCODE_F10=67, SDL_SCANCODE_F11=68, SDL_SCANCODE_F12=69, SDL_SCANCODE_PRINTSCREEN=70, SDL_SCANCODE_SCROLLLOCK=71, SDL_SCANCODE_PAUSE=72, SDL_SCANCODE_INSERT=73, SDL_SCANCODE_HOME=74, SDL_SCANCODE_PAGEUP=75, SDL_SCANCODE_DELETE=76, SDL_SCANCODE_END=77, SDL_SCANCODE_PAGEDOWN=78, SDL_SCANCODE_RIGHT=79, SDL_SCANCODE_LEFT=80, SDL_SCANCODE_DOWN=81, SDL_SCANCODE_UP=82, SDL_SCANCODE_NUMLOCKCLEAR=83, SDL_SCANCODE_KP_DIVIDE=84, SDL_SCANCODE_KP_MULTIPLY=85, SDL_SCANCODE_KP_MINUS=86, SDL_SCANCODE_KP_PLUS=87, SDL_SCANCODE_KP_ENTER=88, SDL_SCANCODE_KP_1=89, SDL_SCANCODE_KP_2=90, SDL_SCANCODE_KP_3=91, SDL_SCANCODE_KP_4=92, SDL_SCANCODE_KP_5=93, SDL_SCANCODE_KP_6=94, SDL_SCANCODE_KP_7=95, SDL_SCANCODE_KP_8=96, SDL_SCANCODE_KP_9=97, SDL_SCANCODE_KP_0=98, SDL_SCANCODE_KP_PERIOD=99, SDL_SCANCODE_NONUSBACKSLASH=100, SDL_SCANCODE_APPLICATION=101, SDL_SCANCODE_POWER=102, SDL_SCANCODE_KP_EQUALS=103, SDL_SCANCODE_F13=104, SDL_SCANCODE_F14=105, SDL_SCANCODE_F15=106, SDL_SCANCODE_F16=107, SDL_SCANCODE_F17=108, SDL_SCANCODE_F18=109, SDL_SCANCODE_F19=110, SDL_SCANCODE_F20=111, SDL_SCANCODE_F21=112, SDL_SCANCODE_F22=113, SDL_SCANCODE_F23=114, SDL_SCANCODE_F24=115, SDL_SCANCODE_EXECUTE=116, SDL_SCANCODE_HELP=117, SDL_SCANCODE_MENU=118, SDL_SCANCODE_SELECT=119, SDL_SCANCODE_STOP=120, SDL_SCANCODE_AGAIN=121, SDL_SCANCODE_UNDO=122, SDL_SCANCODE_CUT=123, SDL_SCANCODE_COPY=124, SDL_SCANCODE_PASTE=125, SDL_SCANCODE_FIND=126, SDL_SCANCODE_MUTE=127, SDL_SCANCODE_VOLUMEUP=128, SDL_SCANCODE_VOLUMEDOWN=129, SDL_SCANCODE_KP_COMMA=133, SDL_SCANCODE_KP_EQUALSAS400=134, SDL_SCANCODE_INTERNATIONAL1=135, SDL_SCANCODE_INTERNATIONAL2=136, SDL_SCANCODE_INTERNATIONAL3=137, SDL_SCANCODE_INTERNATIONAL4=138, SDL_SCANCODE_INTERNATIONAL5=139, SDL_SCANCODE_INTERNATIONAL6=140, SDL_SCANCODE_INTERNATIONAL7=141, SDL_SCANCODE_INTERNATIONAL8=142, SDL_SCANCODE_INTERNATIONAL9=143, SDL_SCANCODE_LANG1=144, SDL_SCANCODE_LANG2=145, SDL_SCANCODE_LANG3=146, SDL_SCANCODE_LANG4=147, SDL_SCANCODE_LANG5=148, SDL_SCANCODE_LANG6=149, SDL_SCANCODE_LANG7=150, SDL_SCANCODE_LANG8=151, SDL_SCANCODE_LANG9=152, SDL_SCANCODE_ALTERASE=153, SDL_SCANCODE_SYSREQ=154, SDL_SCANCODE_CANCEL=155, SDL_SCANCODE_CLEAR=156, SDL_SCANCODE_PRIOR=157, SDL_SCANCODE_RETURN2=158, SDL_SCANCODE_SEPARATOR=159, SDL_SCANCODE_OUT=160, SDL_SCANCODE_OPER=161, SDL_SCANCODE_CLEARAGAIN=162, SDL_SCANCODE_CRSEL=163, SDL_SCANCODE_EXSEL=164, SDL_SCANCODE_KP_00=176, SDL_SCANCODE_KP_000=177, SDL_SCANCODE_THOUSANDSSEPARATOR=178, SDL_SCANCODE_DECIMALSEPARATOR=179, SDL_SCANCODE_CURRENCYUNIT=180, SDL_SCANCODE_CURRENCYSUBUNIT=181, SDL_SCANCODE_KP_LEFTPAREN=182, SDL_SCANCODE_KP_RIGHTPAREN=183, SDL_SCANCODE_KP_LEFTBRACE=184, SDL_SCANCODE_KP_RIGHTBRACE=185, SDL_SCANCODE_KP_TAB=186, SDL_SCANCODE_KP_BACKSPACE=187, SDL_SCANCODE_KP_A=188, SDL_SCANCODE_KP_B=189, SDL_SCANCODE_KP_C=190, SDL_SCANCODE_KP_D=191, SDL_SCANCODE_KP_E=192, SDL_SCANCODE_KP_F=193, SDL_SCANCODE_KP_XOR=194, SDL_SCANCODE_KP_POWER=195, SDL_SCANCODE_KP_PERCENT=196, SDL_SCANCODE_KP_LESS=197, SDL_SCANCODE_KP_GREATER=198, SDL_SCANCODE_KP_AMPERSAND=199, SDL_SCANCODE_KP_DBLAMPERSAND=200, SDL_SCANCODE_KP_VERTICALBAR=201, SDL_SCANCODE_KP_DBLVERTICALBAR=202, SDL_SCANCODE_KP_COLON=203, SDL_SCANCODE_KP_HASH=204, SDL_SCANCODE_KP_SPACE=205, SDL_SCANCODE_KP_AT=206, SDL_SCANCODE_KP_EXCLAM=207, SDL_SCANCODE_KP_MEMSTORE=208, SDL_SCANCODE_KP_MEMRECALL=209, SDL_SCANCODE_KP_MEMCLEAR=210, SDL_SCANCODE_KP_MEMADD=211, SDL_SCANCODE_KP_MEMSUBTRACT=212, SDL_SCANCODE_KP_MEMMULTIPLY=213, SDL_SCANCODE_KP_MEMDIVIDE=214, SDL_SCANCODE_KP_PLUSMINUS=215, SDL_SCANCODE_KP_CLEAR=216, SDL_SCANCODE_KP_CLEARENTRY=217, SDL_SCANCODE_KP_BINARY=218, SDL_SCANCODE_KP_OCTAL=219, SDL_SCANCODE_KP_DECIMAL=220, SDL_SCANCODE_KP_HEXADECIMAL=221, SDL_SCANCODE_LCTRL=224, SDL_SCANCODE_LSHIFT=225, SDL_SCANCODE_LALT=226, SDL_SCANCODE_LGUI=227, SDL_SCANCODE_RCTRL=228, SDL_SCANCODE_RSHIFT=229, SDL_SCANCODE_RALT=230, SDL_SCANCODE_RGUI=231, SDL_SCANCODE_MODE=257, SDL_SCANCODE_AUDIONEXT=258, SDL_SCANCODE_AUDIOPREV=259, SDL_SCANCODE_AUDIOSTOP=260, SDL_SCANCODE_AUDIOPLAY=261, SDL_SCANCODE_AUDIOMUTE=262, SDL_SCANCODE_MEDIASELECT=263, SDL_SCANCODE_WWW=264, SDL_SCANCODE_MAIL=265, SDL_SCANCODE_CALCULATOR=266, SDL_SCANCODE_COMPUTER=267, SDL_SCANCODE_AC_SEARCH=268, SDL_SCANCODE_AC_HOME=269, SDL_SCANCODE_AC_BACK=270, SDL_SCANCODE_AC_FORWARD=271, SDL_SCANCODE_AC_STOP=272, SDL_SCANCODE_AC_REFRESH=273, SDL_SCANCODE_AC_BOOKMARKS=274, SDL_SCANCODE_BRIGHTNESSDOWN=275, SDL_SCANCODE_BRIGHTNESSUP=276, SDL_SCANCODE_DISPLAYSWITCH=277, SDL_SCANCODE_KBDILLUMTOGGLE=278, SDL_SCANCODE_KBDILLUMDOWN=279, SDL_SCANCODE_KBDILLUMUP=280, SDL_SCANCODE_EJECT=281, SDL_SCANCODE_SLEEP=282, SDL_SCANCODE_APP1=283, SDL_SCANCODE_APP2=284, SDL_SCANCODE_AUDIOREWIND=285, SDL_SCANCODE_AUDIOFASTFORWARD=286, SDL_NUM_SCANCODES=512 }

variable_types:
filename
char [256]


decompiled_code:
__int64 get_screen()
{
return bmp;
}

canonical_decompiled_code:
__int64 func1()
{
return bmp;
}

original_code:
struct bitmap *get_screen() {
    return bmp;
}

return_type: struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; } *font; struct { int x0; int x1; } clip; } *


decompiled_code:
__int64 __fastcall screen_to_virt_x(int a1)
{
return (unsigned int)(*(_DWORD *)bmp * a1 / screenWidth);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(*(_DWORD *)bmp * a1 / screenWidth);
}

original_code:
int screen_to_virt_x(int in) {
 return in * bmp->w / screenWidth;
}

variable_types: in int


decompiled_code:
__int64 __fastcall screen_to_virt_y(int a1)
{
return (unsigned int)(*(_DWORD *)(bmp + 4) * a1 / screenHeight);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned int)(*(_DWORD *)(bmp + 4) * a1 / screenHeight);
}

original_code:
int screen_to_virt_y(int in) {
 return in * bmp->h / screenHeight;
}


render

decompiled_code:
__int64 render()
{
SDL_UpdateTexture(tex, 0LL, *(_QWORD *)(bmp + 8), (unsigned int)(4 * *(_DWORD *)bmp));
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, 0LL, 0LL);
return SDL_RenderPresent(ren);
}

canonical_decompiled_code:
__int64 func4()
{
SDL_UpdateTexture(tex, 0LL, *(_QWORD *)(bmp + 8), (unsigned int)(4 * *(_DWORD *)bmp));
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, 0LL, 0LL);
return SDL_RenderPresent(ren);
}

original_code:
void render() {
 SDL_UpdateTexture(tex, ((void *)0), bmp->data, bmp->w*4);
 SDL_RenderClear(ren);
 SDL_RenderCopy(ren, tex, ((void *)0), ((void *)0));
 SDL_RenderPresent(ren);
}


decompiled_code:
_BOOL8 kb_hit()
{
return last_key != 0;
}

canonical_decompiled_code:
_BOOL8 func5()
{
return last_key != 0;
}

original_code:
int kb_hit() {
 return last_key != SDL_SCANCODE_UNKNOWN;
}


readkey

decompiled_code:
__int64 readkey()
{
return (unsigned int)last_key;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)last_key;
}

original_code:
int readkey() {
 return last_key;
}

canonical_original_code:
int readkey() {
 return last_key;
}


decompiled_code:
char *reset_keys()
{
char *result; // rax

result = keys;
do
*result++ = 0;
while ( result != (char *)(unsigned int)((_DWORD)keys + 512) );
return result;
}

canonical_decompiled_code:
char *func8()
{
char *result; // rax

result = keys;
do
*result++ = 0;
while ( result != (char *)(unsigned int)((_DWORD)keys + 512) );
return result;
}

original_code:
void reset_keys() {
 int i;
 for(i = 0; i < SDL_NUM_SCANCODES; i++) {
  keys[i] = 0;
 }
}


init

decompiled_code:
__int64 __fastcall init(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 result; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

rlog("Creating Window.");
v2 = SDL_CreateWindow(a1, 805240832LL, 805240832LL, (unsigned int)screenWidth, (unsigned int)screenHeight, a2 | 4u);
win = v2;
if ( v2 )
{
ren = SDL_CreateRenderer(v2, 0xFFFFFFFFLL, 6LL);
if ( ren )
{
SDL_SetHint("SDL_RENDER_SCALE_QUALITY", filter);
rlog("Window Created.");
if ( (int)SDL_ShowCursor((unsigned int)show_cursor) < 0 )
{
v6 = (const char *)SDL_GetError();
rerror("SDL_ShowCursor: %s", v6);
}
bmp = bm_create((unsigned int)virt_width, (unsigned int)virt_height);
tex = SDL_CreateTexture(ren, 372645892LL, 1LL, *(unsigned int *)bmp, *(unsigned int *)(bmp + 4));
if ( tex )
{
rlog("Texture Created.");
reset_keys();
result = 1LL;
}
else
{
v7 = (const char *)SDL_GetError();
rerror("SDL_CreateTexture: %s", v7);
result = 0LL;
}
}
else
{
v5 = (const char *)SDL_GetError();
rerror("SDL_CreateRenderer: %s", v5);
result = 0LL;
}
}
else
{
v4 = (const char *)SDL_GetError();
rerror("SDL_CreateWindow: %s", v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 result; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

rlog("Creating Window.");
v2 = SDL_CreateWindow(a1, 805240832LL, 805240832LL, (unsigned int)screenWidth, (unsigned int)screenHeight, a2 | 4u);
win = v2;
if ( v2 )
{
ren = SDL_CreateRenderer(v2, 0xFFFFFFFFLL, 6LL);
if ( ren )
{
SDL_SetHint("SDL_RENDER_SCALE_QUALITY", filter);
rlog("Window Created.");
if ( (int)SDL_ShowCursor((unsigned int)show_cursor) < 0 )
{
v6 = (const char *)SDL_GetError();
rerror("SDL_ShowCursor: %s", v6);
}
bmp = bm_create((unsigned int)virt_width, (unsigned int)virt_height);
tex = SDL_CreateTexture(ren, 372645892LL, 1LL, *(unsigned int *)bmp, *(unsigned int *)(bmp + 4));
if ( tex )
{
rlog("Texture Created.");
func8();
result = 1LL;
}
else
{
v7 = (const char *)SDL_GetError();
rerror("SDL_CreateTexture: %s", v7);
result = 0LL;
}
}
else
{
v5 = (const char *)SDL_GetError();
rerror("SDL_CreateRenderer: %s", v5);
result = 0LL;
}
}
else
{
v4 = (const char *)SDL_GetError();
rerror("SDL_CreateWindow: %s", v4);
result = 0LL;
}
return result;
}

original_code:
int init(const char *appTitle, int flags) {
 flags |= SDL_WINDOW_SHOWN;
 rlog("Creating Window.");
 win = SDL_CreateWindow(appTitle, (0x2FFF0000u|(0)), (0x2FFF0000u|(0)), screenWidth, screenHeight, flags);
 if(!win) {
  rerror("SDL_CreateWindow: %s", SDL_GetError());
  return 0;
 }
 ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
 if(!ren) {
  rerror("SDL_CreateRenderer: %s", SDL_GetError());
  return 0;
 }
    SDL_SetHint("SDL_RENDER_SCALE_QUALITY", filter);
 rlog("Window Created.");
    if(SDL_ShowCursor(show_cursor) < 0) {
        rerror("SDL_ShowCursor: %s", SDL_GetError());
    }
 bmp = bm_create(virt_width, virt_height);
 tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, bmp->w, bmp->h);
 if(!tex) {
  rerror("SDL_CreateTexture: %s", SDL_GetError());
  return 0;
 }
 rlog("Texture Created.");
 reset_keys();
 return 1;
}

canonical_original_code:
int init(char *appTitle, int flags) {
 flags |= SDL_WINDOW_SHOWN;
 rlog("Creating Window.");
 win = SDL_CreateWindow(appTitle, (0x2FFF0000u|(0)), (0x2FFF0000u|(0)), screenWidth, screenHeight, flags);
 if(!win) {
  rerror("SDL_CreateWindow: %s", SDL_GetError());
  return 0;
 }
 ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
 if(!ren) {
  rerror("SDL_CreateRenderer: %s", SDL_GetError());
  return 0;
 }
    SDL_SetHint("SDL_RENDER_SCALE_QUALITY", filter);
 rlog("Window Created.");
    if(SDL_ShowCursor(show_cursor) < 0) {
        rerror("SDL_ShowCursor: %s", SDL_GetError());
    }
 bmp = bm_create(virt_width, virt_height);
 tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, bmp->w, bmp->h);
 if(!tex) {
  rerror("SDL_CreateTexture: %s", SDL_GetError());
  return 0;
 }
 rlog("Texture Created.");
 reset_keys();
 return 1;
}

variable_types:
appTitle
char *

variable_types: flags int


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stderr, "Usage: %s [options]\n", a1);
fwrite("where options:\n", 1uLL, 0xFuLL, stderr);
fwrite(" -p pakfile : Load game from PAK file.\n", 1uLL, 0x28uLL, stderr);
fwrite(" -g dir : Use a directory containing a game.ini\n", 1uLL, 0x35uLL, stderr);
fwrite(" file instead of a pak file.\n", 1uLL, 0x2BuLL, stderr);
return fwrite(" -l logfile : Use specific log file.\n", 1uLL, 0x26uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func10(const char *a1)
{
fprintf(stderr, "Usage: %s [options]\n", a1);
fwrite("where options:\n", 1uLL, 0xFuLL, stderr);
fwrite(" -p pakfile : Load game from PAK file.\n", 1uLL, 0x28uLL, stderr);
fwrite(" -g dir : Use a directory containing a game.ini\n", 1uLL, 0x35uLL, stderr);
fwrite(" file instead of a pak file.\n", 1uLL, 0x2BuLL, stderr);
return fwrite(" -l logfile : Use specific log file.\n", 1uLL, 0x26uLL, stderr);
}

original_code:
void usage(const char *name) {
 fprintf(stderr, "Usage: %s [options]\n", name);
 fprintf(stderr, "where options:\n");
 fprintf(stderr, " -p pakfile  : Load game from PAK file.\n");
 fprintf(stderr, " -g dir      : Use a directory containing a game.ini\n");
 fprintf(stderr, "               file instead of a pak file.\n");
 fprintf(stderr, " -l logfile  : Use specific log file.\n");
}

canonical_original_code:
void usage(char *name) {
 fprintf(stderr, "Usage: %s [options]\n", name);
 fprintf(stderr, "where options:\n");
 fprintf(stderr, " -p pakfile  : Load game from PAK file.\n");
 fprintf(stderr, " -g dir      : Use a directory containing a game.ini\n");
 fprintf(stderr, "               file instead of a pak file.\n");
 fprintf(stderr, " -l logfile  : Use specific log file.\n");
}


decompiled_code:
__int64 __fastcall mkdir_tree(const char *a1)
{
char *v1; // r12
const char *v2; // rbx
size_t v3; // rbp
int v5; // edi
char *v6; // rax
char v7[136]; // [rsp+0h] [rbp-B8h] BYREF
char v8[48]; // [rsp+88h] [rbp-30h] BYREF

v1 = strdup(a1);
v7[0] = 0;
v2 = (const char *)my_strtok_r(v1, "/\\", v8);
v3 = 128LL;
if ( v2 )
{
while ( *v2 )
{
if ( v7[0] )
strncat(v7, "/", v3--);
strncat(v7, v2, v3);
v3 -= strlen(v2);
if ( mkdir(v7, 0x1FFu) )
{
v5 = *_errno_location();
if ( v5 != 17 )
{
v6 = strerror(v5);
fprintf(stderr, "error: mkdir(%s): %s\n", v7, v6);
return 0xFFFFFFFFLL;
}
}
v2 = (const char *)my_strtok_r(0LL, "/\\", v8);
if ( !v2 )
break;
}
}
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
char *v1; // r12
const char *v2; // rbx
size_t v3; // rbp
int v5; // edi
char *v6; // rax
char v7[136]; // [rsp+0h] [rbp-B8h] BYREF
char v8[48]; // [rsp+88h] [rbp-30h] BYREF

v1 = strdup(a1);
v7[0] = 0;
v2 = (const char *)my_strtok_r(v1, "/\\", v8);
v3 = 128LL;
if ( v2 )
{
while ( *v2 )
{
if ( v7[0] )
strncat(v7, "/", v3--);
strncat(v7, v2, v3);
v3 -= strlen(v2);
if ( mkdir(v7, 0x1FFu) )
{
v5 = *_errno_location();
if ( v5 != 17 )
{
v6 = strerror(v5);
fprintf(stderr, "error: mkdir(%s): %s\n", v7, v6);
return 0xFFFFFFFFLL;
}
}
v2 = (const char *)my_strtok_r(0LL, "/\\", v8);
if ( !v2 )
break;
}
}
free(v1);
return 0LL;
}

original_code:
int mkdir_tree(const char *path) {
 char *p = strdup(path), *start = p, *rest;
 char buffer[128];
 size_t s = sizeof buffer;
 buffer[0] = '\0';
 p = my_strtok_r(p, "/\\", &rest);
 while(p && p[0]) {
  if(buffer[0])
   strncat(buffer, "/", s--);
  strncat(buffer, p, s);
  s -= strlen(p);
  if(mkdir(buffer, 0777) && (*__errno_location ()) != 17) {
   fprintf(stderr, "error: mkdir(%s): %s\n", buffer, strerror((*__errno_location ())));
   return -1;
  }
  p = my_strtok_r(((void *)0), "/\\", &rest);
 }
 free(start);
 return 0;
}

canonical_original_code:
int mkdir_tree(char *path) {
 char *p = strdup(path); char *start = p; char *rest;
 char buffer[128];
 unsigned long s = sizeof buffer;
 buffer[0] = '\0';
 p = my_strtok_r(p, "/\\", &rest);
 while(p && p[0]) {
  if(buffer[0])
   strncat(buffer, "/", s--);
  strncat(buffer, p, s);
  s -= strlen(p);
  if(mkdir(buffer, 0777) && (*__errno_location ()) != 17) {
   fprintf(stderr, "error: mkdir(%s): %s\n", buffer, strerror((*__errno_location ())));
   return -1;
  }
  p = my_strtok_r(((void *)0), "/\\", &rest);
 }
 free(start);
 return 0;
}

variable_types:
path
char *

variable_types:
p
char *

variable_types:
start
char *

variable_types:
rest
char *

variable_types:
buffer
char [128]

variable_types:
s
unsigned long


decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stderr, "Usage: %s [options] pakfile [files...]\n", a1);
fwrite("where options:\n", 1uLL, 0xFuLL, stderr);
fwrite(" -c dir : Create/Overwrite pakfile from directory dir.\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -x dir : Extract pakfile into directory dir.\n", 1uLL, 0x33uLL, stderr);
fwrite(" -a : Append files to pakfile.\n", 1uLL, 0x28uLL, stderr);
fwrite(" Creates the pakfile if it doesn't exist.\n", 1uLL, 0x38uLL, stderr);
fwrite(" -d : Dumps the contents of a file.\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -t : Dumps the contents of a text file.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -o file : Set the output file for -d and -t.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -h : Include hidden files when using the -c option.\n", 1uLL, 0x3EuLL, stderr);
fwrite(" -v : Verbose mode. Each -v increase verbosity.\n", 1uLL, 0x39uLL, stderr);
fputc(10, stderr);
fwrite("If no options are specified, the file is just listed.\n", 1uLL, 0x36uLL, stderr);
return fwrite("If the -o option is not used, files are written to stdout.\n", 1uLL, 0x3BuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "Usage: %s [options] pakfile [files...]\n", a1);
fwrite("where options:\n", 1uLL, 0xFuLL, stderr);
fwrite(" -c dir : Create/Overwrite pakfile from directory dir.\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -x dir : Extract pakfile into directory dir.\n", 1uLL, 0x33uLL, stderr);
fwrite(" -a : Append files to pakfile.\n", 1uLL, 0x28uLL, stderr);
fwrite(" Creates the pakfile if it doesn't exist.\n", 1uLL, 0x38uLL, stderr);
fwrite(" -d : Dumps the contents of a file.\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -t : Dumps the contents of a text file.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -o file : Set the output file for -d and -t.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -h : Include hidden files when using the -c option.\n", 1uLL, 0x3EuLL, stderr);
fwrite(" -v : Verbose mode. Each -v increase verbosity.\n", 1uLL, 0x39uLL, stderr);
fputc(10, stderr);
fwrite("If no options are specified, the file is just listed.\n", 1uLL, 0x36uLL, stderr);
return fwrite("If the -o option is not used, files are written to stdout.\n", 1uLL, 0x3BuLL, stderr);
}

original_code:
void usage(const char *name) {
 fprintf(stderr, "Usage: %s [options] pakfile [files...]\n", name);
 fprintf(stderr, "where options:\n");
 fprintf(stderr, " -c dir      : Create/Overwrite pakfile from directory dir.\n");
 fprintf(stderr, " -x dir      : Extract pakfile into directory dir.\n");
 fprintf(stderr, " -a          : Append files to pakfile.\n");
 fprintf(stderr, "               Creates the pakfile if it doesn't exist.\n");
 fprintf(stderr, " -d          : Dumps the contents of a file.\n");
 fprintf(stderr, " -t          : Dumps the contents of a text file.\n");
 fprintf(stderr, " -o file     : Set the output file for -d and -t.\n");
 fprintf(stderr, " -h          : Include hidden files when using the -c option.\n");
 fprintf(stderr, " -v          : Verbose mode. Each -v increase verbosity.\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "If no options are specified, the file is just listed.\n");
 fprintf(stderr, "If the -o option is not used, files are written to stdout.\n");
}

canonical_original_code:
void usage(char *name) {
 fprintf(stderr, "Usage: %s [options] pakfile [files...]\n", name);
 fprintf(stderr, "where options:\n");
 fprintf(stderr, " -c dir      : Create/Overwrite pakfile from directory dir.\n");
 fprintf(stderr, " -x dir      : Extract pakfile into directory dir.\n");
 fprintf(stderr, " -a          : Append files to pakfile.\n");
 fprintf(stderr, "               Creates the pakfile if it doesn't exist.\n");
 fprintf(stderr, " -d          : Dumps the contents of a file.\n");
 fprintf(stderr, " -t          : Dumps the contents of a text file.\n");
 fprintf(stderr, " -o file     : Set the output file for -d and -t.\n");
 fprintf(stderr, " -h          : Include hidden files when using the -c option.\n");
 fprintf(stderr, " -v          : Verbose mode. Each -v increase verbosity.\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "If no options are specified, the file is just listed.\n");
 fprintf(stderr, "If the -o option is not used, files are written to stdout.\n");
}


decompiled_code:
__int64 snd_init()
{
int v0; // edx
__int64 result; // rax
const char *v2; // rax

rlog("Opening Audio.");
v0 = Mix_OpenAudio(22050LL, 32784LL, 2LL, 4096LL);
result = 1LL;
if ( v0 )
{
v2 = (const char *)SDL_GetError();
rerror("Unable to open audio: %s", v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
__int64 result; // rax
const char *v2; // rax

rlog("Opening Audio.");
v0 = Mix_OpenAudio(22050LL, 32784LL, 2LL, 4096LL);
result = 1LL;
if ( v0 )
{
v2 = (const char *)SDL_GetError();
rerror("Unable to open audio: %s", v2);
result = 0LL;
}
return result;
}

original_code:
int snd_init() {
 int audio_rate = 22050;
 Uint16 audio_format = 0x8010;
 int audio_channels = 2;
 int audio_buffers = 4096;
 rlog("Opening Audio.");
 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
  rerror("Unable to open audio: %s", SDL_GetError());
  return 0;
 }
 return 1;
}

canonical_original_code:
int snd_init() {
 int audio_rate = 22050;
 unsigned short audio_format = 0x8010;
 int audio_channels = 2;
 int audio_buffers = 4096;
 rlog("Opening Audio.");
 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
  rerror("Unable to open audio: %s", SDL_GetError());
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 snd_deinit()
{
rlog("Closing Audio.");
return Mix_CloseAudio();
}

canonical_decompiled_code:
__int64 func1()
{
rlog("Closing Audio.");
return Mix_CloseAudio();
}

original_code:
void snd_deinit() {
 rlog("Closing Audio.");
 Mix_CloseAudio();
}


decompiled_code:
void log_deinit(void)
{
if ( log_file != stdout )
fclose(log_file);
}

canonical_decompiled_code:
void func0(void)
{
if ( log_file != stdout )
fclose(log_file);
}

original_code:
static void log_deinit() {
 if(log_file != stdout)
  fclose(log_file);
}


inlog

decompiled_code:
int __fastcall inlog(const char *a1, const char *a2, void *a3)
{
fputs(a1, log_file);
fwrite(&unk_340, 1uLL, 2uLL, log_file);
vfprintf(log_file, a2, a3);
fputc(10, log_file);
return fflush(log_file);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2, void *a3)
{
fputs(a1, log_file);
fwrite(&unk_340, 1uLL, 2uLL, log_file);
vfprintf(log_file, a2, a3);
fputc(10, log_file);
return fflush(log_file);
}

original_code:
static void inlog(const char *subsys, const char *fmt, va_list arg) {
 fputs(subsys, log_file);
 fputs(": ", log_file);
 vfprintf(log_file, fmt, arg);
 fputs("\n", log_file);
 fflush(log_file);
}

canonical_original_code:
static void inlog(char *subsys, char *fmt, __builtin_va_list arg) {
 fputs(subsys, log_file);
 fputs(": ", log_file);
 vfprintf(log_file, fmt, arg);
 fputs("\n", log_file);
 fflush(log_file);
}

variable_types:
subsys
char *

variable_types:
fmt
char *


sublog

decompiled_code:
int sublog(const char *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return inlog(a1, a2, va);
}

canonical_decompiled_code:
int func3(const char *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func1(a1, a2, va);
}

original_code:
void sublog(const char *subsys, const char *fmt, ...) {
 va_list arg;
 __builtin_va_start(arg,fmt);
 inlog(subsys, fmt, arg);
 __builtin_va_end(arg);
}

canonical_original_code:
void sublog(char *subsys, char *fmt, ...) {
 __builtin_va_list arg;
 __builtin_va_start(arg,fmt);
 inlog(subsys, fmt, arg);
 __builtin_va_end(arg);
}


original_code:
int
ht_rehash (Hash_Tbl *ht, int new_size)
{
  struct hash_el **buckets, *j, *e, *k;
  int i, h;
  if (new_size >= 100000)
    {
      if (ht->size < 100000)
        new_size = 100000;
      else
        return 0;
    }
  buckets = calloc (new_size, sizeof *buckets);
  if (!buckets)
    return 0;
  for (i = 0; i < ht->size; i++)
    for (j = ht->buckets[i]; j;)
      {
        h = hash (j->key, new_size);
        e = j;
        j = j->next;
        e->next = ((void *)0);
        if (buckets[h])
          {
            for (k = buckets[h]; k->next; k = k->next);
            k->next = e;
          }
        else
          buckets[h] = e;
      }
  free (ht->buckets);
  ht->buckets = buckets;
  ht->size = new_size;
  return 1;
}

canonical_original_code:
int ht_rehash(struct hash_tbl *ht, int new_size)
{
  struct hash_el **buckets; struct hash_el *j; struct hash_el *e; struct hash_el *k;
  int i; int h;
  if (new_size >= 100000)
    {
      if (ht->size < 100000)
        new_size = 100000;
      else
        return 0;
    }
  buckets = calloc (new_size, sizeof *buckets);
  if (!buckets)
    return 0;
  for (i = 0; i < ht->size; i++)
    for (j = ht->buckets[i]; j;)
      {
        h = hash (j->key, new_size);
        e = j;
        j = j->next;
        e->next = ((void *)0);
        if (buckets[h])
          {
            for (k = buckets[h]; k->next; k = k->next);
            k->next = e;
          }
        else
          buckets[h] = e;
      }
  free (ht->buckets);
  ht->buckets = buckets;
  ht->size = new_size;
  return 1;
}

variable_types: struct hash_tbl { struct hash_el { char *key; void *value; struct hash_el *next; } **buckets; int size; int cnt; } *

variable_types: i int

variable_types: h int


decompiled_code:
__int64 __fastcall ht_get(__int64 a1, char *a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = search(a1, a2, v3);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = func1(a1, a2, v3);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
void *
ht_get (Hash_Tbl *h, const char *key)
{
  int f;
  struct hash_el *i = search (h, key, &f);
  if (i)
    return i->value;
  return ((void *)0);
}

canonical_original_code:
void *ht_get(struct hash_tbl *h, char *key)
{
  int f;
  struct hash_el *i = search (h, key, &f);
  if (i)
    return i->value;
  return ((void *)0);
}

variable_types:
key
char *

variable_types: f int

variable_types: struct hash_el { char *key; void *value; struct hash_el *next; } *

return_type: void *


original_code:
void *
ht_delete (Hash_Tbl *h, const char *key)
{
  struct hash_el *i, *p = ((void *)0);
  void *d = ((void *)0);
  int f;
  f = hash (key, h->size);
  if (h->buckets[f])
    {
      for (i = h->buckets[f]; i; i = i->next)
        {
          if (!strcmp (i->key, key))
            {
              if (p)
                p->next = i->next;
              else
                h->buckets[f] = i->next;
              d = i->value;
              free (i->key);
              free (i);
              h->cnt--;
              break;
            }
          p = i;
        }
    }
  return d;
}

canonical_original_code:
void *ht_delete(struct hash_tbl *h, char *key)
{
  struct hash_el *i; struct hash_el *p = ((void *)0);
  void *d = ((void *)0);
  int f;
  f = hash (key, h->size);
  if (h->buckets[f])
    {
      for (i = h->buckets[f]; i; i = i->next)
        {
          if (!strcmp (i->key, key))
            {
              if (p)
                p->next = i->next;
              else
                h->buckets[f] = i->next;
              d = i->value;
              free (i->key);
              free (i);
              h->cnt--;
              break;
            }
          p = i;
        }
    }
  return d;
}

variable_types:
d
void *

user_defined_types: struct hash_el { char *key; void *value; struct hash_el *next; }


decompiled_code:
void __fastcall ht_free(void *ptr, void (__fastcall *a2)(void *, void *))
{
__int64 v2; // r14
void **i; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
for ( i = *(void ***)(*(_QWORD *)ptr + 8 * v2); i; i = *(void ***)(*(_QWORD *)ptr + 8 * v2) )
{
*(_QWORD *)(*(_QWORD *)ptr + 8 * v2) = i[2];
if ( a2 )
a2(*i, i[1]);
free(*i);
free(i);
}
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr, void (__fastcall *a2)(void *, void *))
{
__int64 v2; // r14
void **i; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
for ( i = *(void ***)(*(_QWORD *)ptr + 8 * v2); i; i = *(void ***)(*(_QWORD *)ptr + 8 * v2) )
{
*(_QWORD *)(*(_QWORD *)ptr + 8 * v2) = i[2];
if ( a2 )
a2(*i, i[1]);
free(*i);
free(i);
}
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void
ht_free (Hash_Tbl *h, clear_all_dtor dtor)
{
  struct hash_el *e;
  int i;
  for (i = 0; i < h->size; i++)
    if (h->buckets[i])
      {
        e = h->buckets[i];
        while (e)
          {
            h->buckets[i] = e->next;
            if (dtor)
              dtor (e->key, e->value);
            free (e->key);
            free (e);
            e = h->buckets[i];
          }
      }
  free (h->buckets);
  free (h);
}

canonical_original_code:
void ht_free(struct hash_tbl *h, void (*dtor)(char *key, void *val))
{
  struct hash_el *e;
  int i;
  for (i = 0; i < h->size; i++)
    if (h->buckets[i])
      {
        e = h->buckets[i];
        while (e)
          {
            h->buckets[i] = e->next;
            if (dtor)
              dtor (e->key, e->value);
            free (e->key);
            free (e);
            e = h->buckets[i];
          }
      }
  free (h->buckets);
  free (h);
}

variable_types:
dtor
void (*)(char *key, void *val)


decompiled_code:
void __fastcall ht_foreach(__int64 a1, unsigned int (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 v4; // r13
_QWORD *v5; // rbx

if ( *(int *)(a1 + 8) > 0 )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*(_QWORD *)a1 + 8 * v4);
if ( v5 )
break;
LABEL_3:
if ( *(_DWORD *)(a1 + 8) <= (int)++v4 )
return;
}
while ( a2(*v5, v5[1], a3) )
{
v5 = (_QWORD *)v5[2];
if ( !v5 )
goto LABEL_3;
}
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, unsigned int (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 v4; // r13
_QWORD *v5; // rbx

if ( *(int *)(a1 + 8) > 0 )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*(_QWORD *)a1 + 8 * v4);
if ( v5 )
break;
LABEL_3:
if ( *(_DWORD *)(a1 + 8) <= (int)++v4 )
return;
}
while ( a2(*v5, v5[1], a3) )
{
v5 = (_QWORD *)v5[2];
if ( !v5 )
goto LABEL_3;
}
}
}

original_code:
void
ht_foreach (Hash_Tbl *h,
            int (*f) (const char *key, void *value, void *data), void *data)
{
  struct hash_el *e;
  int i;
  for (i = 0; i < h->size; i++)
    if (h->buckets[i])
      {
        e = h->buckets[i];
        while (e)
          {
            if (!f (e->key, e->value, data))
              return;
            e = e->next;
          }
      }
}

canonical_original_code:
void ht_foreach(struct hash_tbl *h, int (*f)(char *key, void *value, void *data), void *data)
{
  struct hash_el *e;
  int i;
  for (i = 0; i < h->size; i++)
    if (h->buckets[i])
      {
        e = h->buckets[i];
        while (e)
          {
            if (!f (e->key, e->value, data))
              return;
            e = e->next;
          }
      }
}

variable_types: int (*)(char *key, void *value, void *data)

variable_types:
data
void *


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

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

original_code:
void lx_free(struct lexer *lx) {
 free(lx);
}

variable_types: struct lexer { char *in; int sym; int lineno; char *opers; struct lx_keywords { char *word; int value; } *keywds; char text[512]; } *

user_defined_types: struct lexer { char *in; int sym; int lineno; char *opers; struct lx_keywords *keywds; char text[512]; }


decompiled_code:
__int64 __fastcall lx_sym(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

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

original_code:
int lx_sym(struct lexer *lx) {
 return lx->sym;
}

user_defined_types: struct lx_keywords { char *word; int value; }


decompiled_code:
__int64 __fastcall lx_text(__int64 a1)
{
return a1 + 32;
}

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

original_code:
const char *lx_text(struct lexer *lx) {
 return lx->text;
}


decompiled_code:
__int64 __fastcall lx_lineno(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int lx_lineno(struct lexer *lx) {
 return lx->lineno;
}


original_code:
int lx_getsym(struct lexer *lx) {
start:
 if(lx->in[0] == '\0')
  return (lx->sym = 0);
 while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISspace)) {
  if(lx->in[0] == '\n')
   lx->lineno++;
  lx->in++;
 }
 if(lx->in[0] == '#') {
  while(lx->in[0] != '\n' && lx->in[0] != '\0')
   lx->in++;
  goto start;
 }
 if(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISalpha) || lx->in[0] == '_') {
  int i = 0;
  lx->sym = 1;
  while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISalnum) || lx->in[0] == '_') {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "identifier too long");
    return (lx->sym = -1);
   }
  }
  lx->text[i] = '\0';
  if(lx->keywds) {
   int i = 0;
   while(lx->keywds[i].word != ((void *)0)) {
    if(!strcmp(lx->text, lx->keywds[i].word)) {
     lx->sym = lx->keywds[i].value;
     break;
    }
    i++;
   }
  }
 } else if(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISdigit)) {
  int i = 0;
  lx->sym = 2;
  while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISdigit)) {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "number too long");
    return (lx->sym = -1);
   }
  }
  if(lx->in[0] == '.') {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "number too long");
    return (lx->sym = -1);
   }
   while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISdigit)) {
    lx->text[i++] = *lx->in++;
    if(i == 512 - 1) {
     snprintf(lx->text, 512, "number too long");
     return (lx->sym = -1);
    }
   }
  }
  if(tolower(lx->in[0]) == 'e') {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "number too long");
    return (lx->sym = -1);
   }
   if(strchr("+-", lx->in[0])) {
    lx->text[i++] = *lx->in++;
    if(i == 512 - 1) {
     snprintf(lx->text, 512, "number too long");
     return (lx->sym = -1);
    }
   }
   while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short int) _ISdigit)) {
    lx->text[i++] = *lx->in++;
    if(i == 512 - 1) {
     snprintf(lx->text, 512, "number too long");
     return (lx->sym = -1);
    }
   }
  }
  lx->text[i] = '\0';
 } else if(lx->in[0] == '"') {
  int i = 0;
  lx->in++;
  while(lx->in[0] != '"') {
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "string literal too long");
    return (lx->sym = -1);
   }
   switch(lx->in[0]) {
    case '\0' : {
      snprintf(lx->text, 512, "unterminated string literal");
      return (lx->sym = -1);
     }
    case '\\' : {
      lx->in++;
      switch(lx->in[0]) {
       case '\0' : {
         snprintf(lx->text, 512, "unterminated string literal");
         return (lx->sym = -1);
        }
       case '/' : lx->text[i++] = '/'; break;
       case '\\' : lx->text[i++] = '\\'; break;
       case 'b' : lx->text[i++] = '\b'; break;
       case 'f' : lx->text[i++] = '\f'; break;
       case 'n' : lx->text[i++] = '\n'; break;
       case 'r' : lx->text[i++] = '\r'; break;
       case 't' : lx->text[i++] = '\t'; break;
       case '"' : lx->text[i++] = '"'; break;
       default: {
         snprintf(lx->text, 512, "bad escape sequence \\%c", lx->in[0]);
         return (lx->sym = -1);
        }
      }
     } break;
    default : {
      lx->text[i++] = lx->in[0];
      if(lx->in[0] == '\n') {
       lx->lineno++;
      }
     } break;
   }
   lx->in++;
  }
  lx->text[i] = '\0';
  lx->sym = 3;
  lx->in++;
 } else if(strchr(lx->opers, lx->in[0])) {
  return (lx->sym = *lx->in++);
 } else {
  snprintf(lx->text, 512, "Unexpected token '%c'", lx->in[0]);
  return (lx->sym = -1);
 }
 return lx->sym;
}

canonical_original_code:
int lx_getsym(struct lexer *lx) {
start:
 if(lx->in[0] == '\0')
  return (lx->sym = 0);
 while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISspace)) {
  if(lx->in[0] == '\n')
   lx->lineno++;
  lx->in++;
 }
 if(lx->in[0] == '#') {
  while(lx->in[0] != '\n' && lx->in[0] != '\0')
   lx->in++;
  goto start;
 }
 if(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISalpha) || lx->in[0] == '_') {
  int i = 0;
  lx->sym = 1;
  while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISalnum) || lx->in[0] == '_') {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "identifier too long");
    return (lx->sym = -1);
   }
  }
  lx->text[i] = '\0';
  if(lx->keywds) {
   int i = 0;
   while(lx->keywds[i].word != ((void *)0)) {
    if(!strcmp(lx->text, lx->keywds[i].word)) {
     lx->sym = lx->keywds[i].value;
     break;
    }
    i++;
   }
  }
 } else if(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISdigit)) {
  int i = 0;
  lx->sym = 2;
  while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISdigit)) {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "number too long");
    return (lx->sym = -1);
   }
  }
  if(lx->in[0] == '.') {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "number too long");
    return (lx->sym = -1);
   }
   while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISdigit)) {
    lx->text[i++] = *lx->in++;
    if(i == 512 - 1) {
     snprintf(lx->text, 512, "number too long");
     return (lx->sym = -1);
    }
   }
  }
  if(tolower(lx->in[0]) == 'e') {
   lx->text[i++] = *lx->in++;
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "number too long");
    return (lx->sym = -1);
   }
   if(strchr("+-", lx->in[0])) {
    lx->text[i++] = *lx->in++;
    if(i == 512 - 1) {
     snprintf(lx->text, 512, "number too long");
     return (lx->sym = -1);
    }
   }
   while(((*__ctype_b_loc ())[(int) ((lx->in[0]))] & (unsigned short) _ISdigit)) {
    lx->text[i++] = *lx->in++;
    if(i == 512 - 1) {
     snprintf(lx->text, 512, "number too long");
     return (lx->sym = -1);
    }
   }
  }
  lx->text[i] = '\0';
 } else if(lx->in[0] == '"') {
  int i = 0;
  lx->in++;
  while(lx->in[0] != '"') {
   if(i == 512 - 1) {
    snprintf(lx->text, 512, "string literal too long");
    return (lx->sym = -1);
   }
   switch(lx->in[0]) {
    case '\0' : {
      snprintf(lx->text, 512, "unterminated string literal");
      return (lx->sym = -1);
     }
    case '\\' : {
      lx->in++;
      switch(lx->in[0]) {
       case '\0' : {
         snprintf(lx->text, 512, "unterminated string literal");
         return (lx->sym = -1);
        }
       case '/' : lx->text[i++] = '/'; break;
       case '\\' : lx->text[i++] = '\\'; break;
       case 'b' : lx->text[i++] = '\b'; break;
       case 'f' : lx->text[i++] = '\f'; break;
       case 'n' : lx->text[i++] = '\n'; break;
       case 'r' : lx->text[i++] = '\r'; break;
       case 't' : lx->text[i++] = '\t'; break;
       case '"' : lx->text[i++] = '"'; break;
       default: {
         snprintf(lx->text, 512, "bad escape sequence \\%c", lx->in[0]);
         return (lx->sym = -1);
        }
      }
     } break;
    default : {
      lx->text[i++] = lx->in[0];
      if(lx->in[0] == '\n') {
       lx->lineno++;
      }
     } break;
   }
   lx->in++;
  }
  lx->text[i] = '\0';
  lx->sym = 3;
  lx->in++;
 } else if(strchr(lx->opers, lx->in[0])) {
  return (lx->sym = *lx->in++);
 } else {
  snprintf(lx->text, 512, "Unexpected token '%c'", lx->in[0]);
  return (lx->sym = -1);
 }
 return lx->sym;
}


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

result = 0LL;
if ( *(_DWORD *)(a1 + 8) == a2 )
{
lx_getsym((char **)a1);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 8) == a2 )
{
func4((char **)a1);
result = 1LL;
}
return result;
}

original_code:
int lx_accept(struct lexer *lx, int sym) {
 if(lx->sym == sym) {
  lx_getsym(lx);
  return 1;
 }
 return 0;
}

variable_types: sym int


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

result = lx_accept(a1, a2);
if ( (_DWORD)result )
return 1LL;
strcpy((char *)(a1 + 32), "unexpected symbol");
return result;
}

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

result = func5(a1, a2);
if ( (_DWORD)result )
return 1LL;
strcpy((char *)(a1 + 32), "unexpected symbol");
return result;
}

original_code:
int lx_expect(struct lexer *lx, int sym) {
 if(lx_accept(lx, sym))
  return 1;
 snprintf(lx->text, 512, "unexpected symbol");
 return 0;
}


decompiled_code:
__int64 __fastcall map_get_cell(__int64 a1, int a2, int a3)
{
return *(_QWORD *)(a1 + 16) + 32LL * (*(_DWORD *)(a1 + 4) * a3 + a2);
}

original_code:
struct map_cell *map_get_cell(struct map *m, int x, int y) {
 return &m->cells[y * m->nc + x];
}

variable_types: struct map { int nr; char dirty; int nl; struct map_cell *cells; struct tile_collection { int tw; struct tileset { struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; } *font; struct { int x0; int x1; } clip; } *bm; char *name; int border; int nmeta; struct tile_meta { int ti; char *clas; int flags; } *meta; } **tilesets; int ntilesets; } tiles; } *

variable_types: x int

variable_types: y int

return_type: struct map_cell { struct map_tile { short si; short ti; } *tiles; char *id; char *clas; int flags; } *

user_defined_types: struct map { int nr; char dirty; int nl; struct map_cell *cells; struct tile_collection tiles; }

user_defined_types: struct map_cell { struct map_tile *tiles; char *id; char *clas; int flags; }


original_code:
void map_free(struct map *m) {
 int i;
 if(!m) return;
 for(i = 0; i < m->nr * m->nc; i++) {
  free(m->cells[i].tiles);
  free(m->cells[i].id);
  free(m->cells[i].clas);
 }
 ts_deinit(&m->tiles);
 free(m->cells);
 free(m);
}

variable_types: struct map { int nr; char dirty; int nl; struct map_cell { struct map_tile { short si; short ti; } *tiles; char *id; char *clas; int flags; } *cells; struct tile_collection { int tw; struct tileset { struct bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font { char *type; int (*puts)(struct bitmap *b, int x, int y, char *text); void (*dtor)(struct bitmap_font *font); int (*width)(struct bitmap_font *font); int (*height)(struct bitmap_font *font); void *data; } *font; struct { int x0; int x1; } clip; } *bm; char *name; int border; int nmeta; struct tile_meta { int ti; char *clas; int flags; } *meta; } **tilesets; int ntilesets; } tiles; } *


decompiled_code:
__int64 __fastcall scancode_to_ascii(unsigned int a1, int a2, int a3, int a4)
{
__int64 result; // rax
unsigned int v5; // edi

if ( a1 - 4 > 0x19 )
{
if ( a1 - 89 <= 9 && a4 )
{
result = a1 - 40;
if ( a1 == 98 )
result = 48LL;
}
else
{
switch ( a1 )
{
case 0x1Eu:
result = a2 == 0 ? 49 : 33;
break;
case 0x1Fu:
result = a2 == 0 ? 50 : 64;
break;
case 0x20u:
result = a2 == 0 ? 51 : 35;
break;
case 0x21u:
result = a2 == 0 ? 52 : 36;
break;
case 0x22u:
result = a2 == 0 ? 53 : 37;
break;
case 0x23u:
result = a2 == 0 ? 54 : 94;
break;
case 0x24u:
result = a2 == 0 ? 55 : 38;
break;
case 0x25u:
result = a2 == 0 ? 56 : 42;
break;
case 0x26u:
result = a2 == 0 ? 57 : 40;
break;
case 0x27u:
result = a2 == 0 ? 48 : 41;
break;
case 0x28u:
case 0x58u:
result = 10LL;
break;
case 0x29u:
result = 27LL;
break;
case 0x2Au:
result = 8LL;
break;
case 0x2Bu:
result = 9LL;
break;
case 0x2Cu:
result = 32LL;
break;
case 0x2Du:
result = 95LL;
if ( !a2 )
result = a1;
break;
case 0x2Eu:
result = a2 == 0 ? 61 : 43;
break;
case 0x2Fu:
result = a2 == 0 ? 91 : 123;
break;
case 0x30u:
result = a2 == 0 ? 93 : 125;
break;
case 0x31u:
result = a2 == 0 ? 92 : 124;
break;
case 0x33u:
result = (unsigned int)(a2 == 0) + 58;
break;
case 0x34u:
result = a2 == 0 ? 39 : 34;
break;
case 0x35u:
result = a2 == 0 ? 96 : 126;
break;
case 0x36u:
result = a2 == 0 ? 44 : 60;
break;
case 0x37u:
result = a2 == 0 ? 46 : 62;
break;
case 0x38u:
result = a2 == 0 ? 47 : 63;
break;
case 0x4Cu:
result = 127LL;
break;
case 0x54u:
result = 47LL;
break;
case 0x55u:
result = 42LL;
break;
case 0x56u:
result = 45LL;
break;
case 0x57u:
result = 43LL;
break;
case 0x63u:
result = 46LL;
break;
default:
result = 0LL;
break;
}
}
}
else
{
result = a1 + 61;
v5 = a1 + 93;
if ( a2 == a3 )
result = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, int a3, int a4)
{
__int64 result; // rax
unsigned int v5; // edi

if ( a1 - 4 > 0x19 )
{
if ( a1 - 89 <= 9 && a4 )
{
result = a1 - 40;
if ( a1 == 98 )
result = 48LL;
}
else
{
switch ( a1 )
{
case 0x1Eu:
result = a2 == 0 ? 49 : 33;
break;
case 0x1Fu:
result = a2 == 0 ? 50 : 64;
break;
case 0x20u:
result = a2 == 0 ? 51 : 35;
break;
case 0x21u:
result = a2 == 0 ? 52 : 36;
break;
case 0x22u:
result = a2 == 0 ? 53 : 37;
break;
case 0x23u:
result = a2 == 0 ? 54 : 94;
break;
case 0x24u:
result = a2 == 0 ? 55 : 38;
break;
case 0x25u:
result = a2 == 0 ? 56 : 42;
break;
case 0x26u:
result = a2 == 0 ? 57 : 40;
break;
case 0x27u:
result = a2 == 0 ? 48 : 41;
break;
case 0x28u:
case 0x58u:
result = 10LL;
break;
case 0x29u:
result = 27LL;
break;
case 0x2Au:
result = 8LL;
break;
case 0x2Bu:
result = 9LL;
break;
case 0x2Cu:
result = 32LL;
break;
case 0x2Du:
result = 95LL;
if ( !a2 )
result = a1;
break;
case 0x2Eu:
result = a2 == 0 ? 61 : 43;
break;
case 0x2Fu:
result = a2 == 0 ? 91 : 123;
break;
case 0x30u:
result = a2 == 0 ? 93 : 125;
break;
case 0x31u:
result = a2 == 0 ? 92 : 124;
break;
case 0x33u:
result = (unsigned int)(a2 == 0) + 58;
break;
case 0x34u:
result = a2 == 0 ? 39 : 34;
break;
case 0x35u:
result = a2 == 0 ? 96 : 126;
break;
case 0x36u:
result = a2 == 0 ? 44 : 60;
break;
case 0x37u:
result = a2 == 0 ? 46 : 62;
break;
case 0x38u:
result = a2 == 0 ? 47 : 63;
break;
case 0x4Cu:
result = 127LL;
break;
case 0x54u:
result = 47LL;
break;
case 0x55u:
result = 42LL;
break;
case 0x56u:
result = 45LL;
break;
case 0x57u:
result = 43LL;
break;
case 0x63u:
result = 46LL;
break;
default:
result = 0LL;
break;
}
}
}
else
{
result = a1 + 61;
v5 = a1 + 93;
if ( a2 == a3 )
result = v5;
}
return result;
}

original_code:
int scancode_to_ascii(int code, int shift, int caps, int numl) {
 if(code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) {
  if(shift ^ caps)
   return code - SDL_SCANCODE_A + 'A';
  return code - SDL_SCANCODE_A + 'a';
 }
    if(numl && code >= SDL_SCANCODE_KP_1 && code <= SDL_SCANCODE_KP_0) {
        if(code == SDL_SCANCODE_KP_0)
            return '0';
        return code - SDL_SCANCODE_KP_1 + '1';
    }
 switch(code) {
  case SDL_SCANCODE_1 : return shift?'!':'1';
  case SDL_SCANCODE_2 : return shift?'@':'2';
  case SDL_SCANCODE_3 : return shift?'#':'3';
  case SDL_SCANCODE_4 : return shift?'$':'4';
  case SDL_SCANCODE_5 : return shift?'%':'5';
  case SDL_SCANCODE_6 : return shift?'^':'6';
  case SDL_SCANCODE_7 : return shift?'&':'7';
  case SDL_SCANCODE_8 : return shift?'*':'8';
  case SDL_SCANCODE_9 : return shift?'(':'9';
  case SDL_SCANCODE_0 : return shift?')':'0';
  case SDL_SCANCODE_SLASH : return shift?'?':'/';
  case SDL_SCANCODE_SEMICOLON : return shift?':':';';
  case SDL_SCANCODE_LEFTBRACKET : return shift?'{':'[';
  case SDL_SCANCODE_RIGHTBRACKET : return shift?'}':']';
  case SDL_SCANCODE_COMMA : return shift?'<':',';
  case SDL_SCANCODE_PERIOD : return shift?'>':'.';
  case SDL_SCANCODE_MINUS : return shift?'_':'-';
  case SDL_SCANCODE_EQUALS : return shift?'+':'=';
  case SDL_SCANCODE_APOSTROPHE : return shift?'"':'\'';
  case SDL_SCANCODE_BACKSLASH : return shift?'|':'\\';
  case SDL_SCANCODE_GRAVE : return shift?'~':'`';
  case SDL_SCANCODE_SPACE : return ' ';
  case SDL_SCANCODE_RETURN :
  case SDL_SCANCODE_KP_ENTER : return '\n';
  case SDL_SCANCODE_TAB : return '\t';
  case SDL_SCANCODE_BACKSPACE : return '\b';
  case SDL_SCANCODE_DELETE : return 0x7F;
  case SDL_SCANCODE_ESCAPE : return 0x1B;
  case SDL_SCANCODE_KP_PLUS : return '+';
  case SDL_SCANCODE_KP_MINUS : return '-';
  case SDL_SCANCODE_KP_MULTIPLY : return '*';
  case SDL_SCANCODE_KP_DIVIDE : return '/';
  case SDL_SCANCODE_KP_PERIOD : return '.';
  default: return '\0';
 }
}

variable_types: code int

variable_types: shift int

variable_types: caps int

variable_types: numl int


relpath

decompiled_code:
char *__fastcall relpath(const char *a1, const char *a2, char *a3, size_t a4)
{
char *v4; // r13
size_t v5; // rbp
char *v6; // r15
char *v7; // r14
const char *v8; // r12
__int64 v9; // rax
const char *v10; // rbx
__int64 v11; // rax
__int64 v13; // [rsp+0h] [rbp-48h] BYREF
char v14[64]; // [rsp+8h] [rbp-40h] BYREF

if ( !a4 )
{
v7 = 0LL;
v6 = 0LL;
v4 = 0LL;
goto LABEL_11;
}
v4 = a3;
v5 = a4;
*a3 = 0;
v6 = strdup(a1);
v7 = strdup(a2);
v8 = (const char *)my_strtok_r(v6, &unk_164, v14);
v9 = my_strtok_r(v7, &unk_164, &v13);
v10 = (const char *)v9;
if ( v8 && v9 )
{
while ( !strcmp(v8, v10) )
{
v8 = (const char *)my_strtok_r(0LL, &unk_164, v14);
v11 = my_strtok_r(0LL, &unk_164, &v13);
v10 = (const char *)v11;
if ( !v8 || !v11 )
goto LABEL_7;
}
}
else
{
LABEL_7:
if ( !v8 )
goto LABEL_9;
}
do
{
strncat(v4, "../", v5 - 1);
v5 -= 3LL;
}
while ( my_strtok_r(0LL, &unk_164, v14) );
LABEL_9:
while ( v10 )
{
strncat(v4, v10, v5 - 1);
v5 += ~strlen(v10);
strncat(v4, "/", v5);
v10 = (const char *)my_strtok_r(0LL, &unk_164, &v13);
}
LABEL_11:
free(v6);
free(v7);
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, const char *a2, char *a3, size_t a4)
{
char *v4; // r13
size_t v5; // rbp
char *v6; // r15
char *v7; // r14
const char *v8; // r12
__int64 v9; // rax
const char *v10; // rbx
__int64 v11; // rax
__int64 v13; // [rsp+0h] [rbp-48h] BYREF
char v14[64]; // [rsp+8h] [rbp-40h] BYREF

if ( !a4 )
{
v7 = 0LL;
v6 = 0LL;
v4 = 0LL;
goto LABEL_11;
}
v4 = a3;
v5 = a4;
*a3 = 0;
v6 = strdup(a1);
v7 = strdup(a2);
v8 = (const char *)my_strtok_r(v6, &unk_164, v14);
v9 = my_strtok_r(v7, &unk_164, &v13);
v10 = (const char *)v9;
if ( v8 && v9 )
{
while ( !strcmp(v8, v10) )
{
v8 = (const char *)my_strtok_r(0LL, &unk_164, v14);
v11 = my_strtok_r(0LL, &unk_164, &v13);
v10 = (const char *)v11;
if ( !v8 || !v11 )
goto LABEL_7;
}
}
else
{
LABEL_7:
if ( !v8 )
goto LABEL_9;
}
do
{
strncat(v4, "../", v5 - 1);
v5 -= 3LL;
}
while ( my_strtok_r(0LL, &unk_164, v14) );
LABEL_9:
while ( v10 )
{
strncat(v4, v10, v5 - 1);
v5 += ~strlen(v10);
strncat(v4, "/", v5);
v10 = (const char *)my_strtok_r(0LL, &unk_164, &v13);
}
LABEL_11:
free(v6);
free(v7);
return v4;
}

original_code:
char *relpath(const char *from, const char *to, char *rel, size_t rellen) {
 char *rv = ((void *)0);
 char *from_path = ((void *)0), *to_path = ((void *)0);
 char *from_start = ((void *)0), *to_start = ((void *)0);
 char *from_ptr, *to_ptr;
 if(rellen < 1)
  goto error;
 rel[0] = '\0';
 from_path = strdup(from);
 from_start = from_path;
 to_path = strdup(to);
 to_start = to_path;
 from_path = my_strtok_r(from_path, "\\/", &from_ptr);
 to_path = my_strtok_r(to_path, "\\/", &to_ptr);
 while(from_path && to_path && !strcmp(from_path, to_path)) {
  from_path = my_strtok_r(((void *)0), "\\/", &from_ptr);
  to_path = my_strtok_r(((void *)0), "\\/", &to_ptr);
 }
 while(from_path) {
  strncat(rel, "../", rellen - 1);
  rellen -= 3;
  from_path = my_strtok_r(((void *)0), "\\/", &from_ptr);
 }
 while(to_path) {
  strncat(rel, to_path, rellen - 1);
  rellen -= strlen(to_path);
  strncat(rel, "/", rellen - 1);
  rellen--;
  to_path = my_strtok_r(((void *)0), "\\/", &to_ptr);
 }
 rv = rel;
error:
 free(from_start);
 free(to_start);
 return rv;
}

canonical_original_code:
char *relpath(char *from, char *to, char *rel, unsigned long rellen) {
 char *rv = ((void *)0);
 char *from_path = ((void *)0); char *to_path = ((void *)0);
 char *from_start = ((void *)0); char *to_start = ((void *)0);
 char *from_ptr; char *to_ptr;
 if(rellen < 1)
  goto error;
 rel[0] = '\0';
 from_path = strdup(from);
 from_start = from_path;
 to_path = strdup(to);
 to_start = to_path;
 from_path = my_strtok_r(from_path, "\\/", &from_ptr);
 to_path = my_strtok_r(to_path, "\\/", &to_ptr);
 while(from_path && to_path && !strcmp(from_path, to_path)) {
  from_path = my_strtok_r(((void *)0), "\\/", &from_ptr);
  to_path = my_strtok_r(((void *)0), "\\/", &to_ptr);
 }
 while(from_path) {
  strncat(rel, "../", rellen - 1);
  rellen -= 3;
  from_path = my_strtok_r(((void *)0), "\\/", &from_ptr);
 }
 while(to_path) {
  strncat(rel, to_path, rellen - 1);
  rellen -= strlen(to_path);
  strncat(rel, "/", rellen - 1);
  rellen--;
  to_path = my_strtok_r(((void *)0), "\\/", &to_ptr);
 }
 rv = rel;
error:
 free(from_start);
 free(to_start);
 return rv;
}

variable_types:
from
char *

variable_types:
to
char *

variable_types:
rel
char *

variable_types:
rellen
unsigned long

variable_types:
rv
char *


repo: wertarbyte/triggerhappy

decompiled_code:
__int64 __fastcall lookup_index(__int64 a1, const char *a2, int a3)
{
__int64 v5; // rbx
unsigned int v6; // er13
const char *v7; // rsi

if ( a3 < 0 )
return (unsigned int)-1;
v5 = 0LL;
while ( 1 )
{
v6 = v5;
v7 = *(const char **)(a1 + 8 * v5);
if ( v7 )
{
if ( !strcmp(a2, v7) )
break;
}
if ( a3 < (int)++v5 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, int a3)
{
__int64 v5; // rbx
unsigned int v6; // er13
const char *v7; // rsi

if ( a3 < 0 )
return (unsigned int)-1;
v5 = 0LL;
while ( 1 )
{
v6 = v5;
v7 = *(const char **)(a1 + 8 * v5);
if ( v7 )
{
if ( !strcmp(a2, v7) )
break;
}
if ( a3 < (int)++v5 )
return (unsigned int)-1;
}
return v6;
}

original_code:
static int lookup_index(const char **map, const char *value, int max) {
 int i = 0;
 while (i <= max) {
  if (map[i] != ((void *)0) &&
      strcmp(value, map[i]) == 0) {
   return i;
  }
  i++;
 }
 return -1;
}

canonical_original_code:
static int lookup_index(char **map, char *value, int max) {
 int i = 0;
 while (i <= max) {
  if (map[i] != ((void *)0) &&
      strcmp(value, map[i]) == 0) {
   return i;
  }
  i++;
 }
 return -1;
}

variable_types:
map
char **

variable_types:
value
char *

variable_types: max int

variable_types: i int


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

if ( a1 == 3 )
{
result = 0LL;
if ( a2 <= 63 )
result = ABS_NAME[a2];
}
else if ( a1 > 3 )
{
if ( a1 == 5 )
{
result = 0LL;
if ( a2 <= 16 )
result = SW_NAME[a2];
}
else
{
result = 0LL;
}
}
else if ( a1 == 1 )
{
result = 0LL;
if ( a2 <= 767 )
result = KEY_NAME[a2];
}
else if ( a1 == 2 )
{
result = 0LL;
if ( a2 <= 15 )
result = REL_NAME[a2];
}
else
{
result = 0LL;
}
return result;
}

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

if ( a1 == 3 )
{
result = 0LL;
if ( a2 <= 63 )
result = ABS_NAME[a2];
}
else if ( a1 > 3 )
{
if ( a1 == 5 )
{
result = 0LL;
if ( a2 <= 16 )
result = SW_NAME[a2];
}
else
{
result = 0LL;
}
}
else if ( a1 == 1 )
{
result = 0LL;
if ( a2 <= 767 )
result = KEY_NAME[a2];
}
else if ( a1 == 2 )
{
result = 0LL;
if ( a2 <= 15 )
result = REL_NAME[a2];
}
else
{
result = 0LL;
}
return result;
}

original_code:
const char *lookup_event_name_i( const int evtype, const int evcode ) {
 switch(evtype) {
  case 0x01:
   return (0x2ff >= evcode ? KEY_NAME[ evcode ] : ((void *)0));
  case 0x05:
   return (0x10 >= evcode ? SW_NAME[ evcode ] : ((void *)0));
  case 0x02:
   return (0x0f >= evcode ? REL_NAME[ evcode ] : ((void *)0));
  case 0x03:
   return (0x3f >= evcode ? ABS_NAME[ evcode ] : ((void *)0));
  default:
   return ((void *)0);
 }
}

canonical_original_code:
char *lookup_event_name_i(int evtype, int evcode) {
 switch(evtype) {
  case 0x01:
   return (0x2ff >= evcode ? KEY_NAME[ evcode ] : ((void *)0));
  case 0x05:
   return (0x10 >= evcode ? SW_NAME[ evcode ] : ((void *)0));
  case 0x02:
   return (0x0f >= evcode ? REL_NAME[ evcode ] : ((void *)0));
  case 0x03:
   return (0x3f >= evcode ? ABS_NAME[ evcode ] : ((void *)0));
  default:
   return ((void *)0);
 }
}

variable_types: evtype int

variable_types: evcode int


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

result = 0LL;
if ( a1 <= 31 )
result = EV_NAME[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 31 )
result = EV_NAME[a1];
return result;
}

original_code:
const char *lookup_type_name_i( const int evtype ) {
 return (0x1f >= evtype ? EV_NAME[ evtype ] : ((void *)0));
}

canonical_original_code:
char *lookup_type_name_i(int evtype) {
 return (0x1f >= evtype ? EV_NAME[ evtype ] : ((void *)0));
}


decompiled_code:
__int64 __fastcall lookup_event_code(const char *a1)
{
__int64 result; // rax

result = lookup_index((__int64)KEY_NAME, a1, 767);
if ( (_DWORD)result == -1 )
{
result = lookup_index((__int64)SW_NAME, a1, 16);
if ( (_DWORD)result == -1 )
{
result = lookup_index((__int64)REL_NAME, a1, 15);
if ( (_DWORD)result == -1 )
result = lookup_index((__int64)ABS_NAME, a1, 63);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
__int64 result; // rax

result = func0((__int64)KEY_NAME, a1, 767);
if ( (_DWORD)result == -1 )
{
result = func0((__int64)SW_NAME, a1, 16);
if ( (_DWORD)result == -1 )
{
result = func0((__int64)REL_NAME, a1, 15);
if ( (_DWORD)result == -1 )
result = func0((__int64)ABS_NAME, a1, 63);
}
}
return result;
}

original_code:
int lookup_event_code( const char *eventname ) {
 int res = -1;
 if (res == -1) res = lookup_index(KEY_NAME, eventname, 0x2ff);
 if (res == -1) res = lookup_index(SW_NAME, eventname, 0x10);
 if (res == -1) res = lookup_index(REL_NAME, eventname, 0x0f);
 if (res == -1) res = lookup_index(ABS_NAME, eventname, 0x3f);
 return res;
}

canonical_original_code:
int lookup_event_code(char *eventname) {
 int res = -1;
 if (res == -1) res = lookup_index(KEY_NAME, eventname, 0x2ff);
 if (res == -1) res = lookup_index(SW_NAME, eventname, 0x10);
 if (res == -1) res = lookup_index(REL_NAME, eventname, 0x0f);
 if (res == -1) res = lookup_index(ABS_NAME, eventname, 0x3f);
 return res;
}

variable_types:
eventname
char *

variable_types: res int


decompiled_code:
__int64 __fastcall lookup_event_type(const char *a1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx

v1 = lookup_index((__int64)KEY_NAME, a1, 767);
result = 1LL;
if ( v1 == -1 )
{
v3 = lookup_index((__int64)SW_NAME, a1, 16);
result = 5LL;
if ( v3 == -1 )
{
v4 = lookup_index((__int64)REL_NAME, a1, 15);
result = 2LL;
if ( v4 == -1 )
{
result = lookup_index((__int64)ABS_NAME, a1, 63);
if ( (_DWORD)result != -1 )
result = 3LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx

v1 = func0((__int64)KEY_NAME, a1, 767);
result = 1LL;
if ( v1 == -1 )
{
v3 = func0((__int64)SW_NAME, a1, 16);
result = 5LL;
if ( v3 == -1 )
{
v4 = func0((__int64)REL_NAME, a1, 15);
result = 2LL;
if ( v4 == -1 )
{
result = func0((__int64)ABS_NAME, a1, 63);
if ( (_DWORD)result != -1 )
result = 3LL;
}
}
}
return result;
}

original_code:
int lookup_event_type( const char *eventname ) {
 if (lookup_index(KEY_NAME, eventname, 0x2ff) != -1) {
  return 0x01;
 }
 if (lookup_index(SW_NAME, eventname, 0x10) != -1) {
  return 0x05;
 }
 if (lookup_index(REL_NAME, eventname, 0x0f) != -1) {
  return 0x02;
 }
 if (lookup_index(ABS_NAME, eventname, 0x3f) != -1) {
  return 0x03;
 }
 return -1;
}

canonical_original_code:
int lookup_event_type(char *eventname) {
 if (lookup_index(KEY_NAME, eventname, 0x2ff) != -1) {
  return 0x01;
 }
 if (lookup_index(SW_NAME, eventname, 0x10) != -1) {
  return 0x05;
 }
 if (lookup_index(REL_NAME, eventname, 0x0f) != -1) {
  return 0x02;
 }
 if (lookup_index(ABS_NAME, eventname, 0x3f) != -1) {
  return 0x03;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall bind_cmdsocket(char *name)
{
unsigned int v1; // ebp
int v2; // eax
struct stat v4; // [rsp+0h] [rbp-118h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-88h] BYREF

if ( (unsigned int)sd_listen_fds(0LL) == 1 )
{
fwrite("<7>Found socket passed from systemd\n", 1uLL, 0x24uLL, stderr);
v1 = 3;
}
else
{
if ( !stat(name, &v4) && (v4.st_mode & 0xF000) == 49152 )
unlink(name);
v1 = socket(1, 2, 0);
strcpy(addr.sa_data, name);
addr.sa_family = 1;
v2 = strlen(addr.sa_data);
bind(v1, &addr, v2 + 2);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name)
{
unsigned int v1; // ebp
int v2; // eax
struct stat v4; // [rsp+0h] [rbp-118h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-88h] BYREF

if ( (unsigned int)sd_listen_fds(0LL) == 1 )
{
fwrite("<7>Found socket passed from systemd\n", 1uLL, 0x24uLL, stderr);
v1 = 3;
}
else
{
if ( !stat(name, &v4) && (v4.st_mode & 0xF000) == 49152 )
unlink(name);
v1 = socket(1, 2, 0);
strcpy(addr.sa_data, name);
addr.sa_family = 1;
v2 = strlen(addr.sa_data);
bind(v1, &addr, v2 + 2);
}
return v1;
}

original_code:
int bind_cmdsocket( char *name ) {
 int cmd_fd;
 if (sd_listen_fds(0) == 1) {
  fprintf(stderr, "<7>" "Found socket passed from systemd\n");
  return 3 + 0;
 }
 struct sockaddr_un addr;
 struct stat sb;
 int serr = stat(name, &sb);
 if ( !serr && ((((sb.st_mode)) & 0170000) == (0140000))) {
  unlink(name);
 }
 cmd_fd = socket(1, SOCK_DGRAM, 0);
 strcpy(addr.sun_path, name);
 addr.sun_family = 1;
 bind (cmd_fd, (struct sockaddr *) &addr,
  strlen(addr.sun_path) + sizeof (addr.sun_family));
 return cmd_fd;
}

canonical_original_code:
int bind_cmdsocket(char *name) {
 int cmd_fd;
 if (sd_listen_fds(0) == 1) {
  fprintf(stderr, "<7>" "Found socket passed from systemd\n");
  return 3 + 0;
 }
 struct sockaddr_un addr;
 struct stat sb;
 int serr = stat(name, &sb);
 if ( !serr && ((((sb.st_mode)) & 0170000) == (0140000))) {
  unlink(name);
 }
 cmd_fd = socket(1, SOCK_DGRAM, 0);
 strcpy(addr.sun_path, name);
 addr.sun_family = 1;
 bind (cmd_fd, (struct sockaddr *) &addr,
  strlen(addr.sun_path) + sizeof (addr.sun_family));
 return cmd_fd;
}

variable_types:
name
char *

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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

variable_types: serr int

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

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


decompiled_code:
__int64 __fastcall connect_cmdsocket(char *src)
{
unsigned int v1; // ebx
int v2; // eax
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 2, 0);
strcpy(v4[0].sa_data, src);
v4[0].sa_family = 1;
v2 = strlen(v4[0].sa_data);
connect(v1, v4, v2 + 2);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
unsigned int v1; // ebx
int v2; // eax
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 2, 0);
strcpy(v4[0].sa_data, src);
v4[0].sa_family = 1;
v2 = strlen(v4[0].sa_data);
connect(v1, v4, v2 + 2);
return v1;
}

original_code:
int connect_cmdsocket( char *name ) {
 int fd;
 struct sockaddr_un server;
 fd = socket(1, SOCK_DGRAM, 0);
 strcpy(server.sun_path, name);
 server.sun_family = 1;
 connect(fd, (struct sockaddr *) &server,
  strlen(server.sun_path) + sizeof (server.sun_family));
 return fd;
}

canonical_original_code:
int connect_cmdsocket(char *name) {
 int fd;
 struct sockaddr_un server;
 fd = socket(1, SOCK_DGRAM, 0);
 strcpy(server.sun_path, name);
 server.sun_family = 1;
 connect(fd, (struct sockaddr *) &server,
  strlen(server.sun_path) + sizeof (server.sun_family));
 return fd;
}

variable_types: fd int

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


original_code:
int send_command( int cmd_fd, enum command_type type, char *param, int passfd, int exclusive, char *tag ) {
 if (type == CMD_ADD && passfd == 1) {
  type = CMD_PASSFD;
 }
 struct command cmd = {
  .fd = -1,
  .exclusive = exclusive,
  .type = type,
  .param = {0},
  .tag = {0}
 };
 if (param != ((void *)0)) {
  strncpy(cmd.param, param, 256);
  cmd.param[256 -1] = '\0';
 }
 if (tag != ((void *)0)) {
  strncpy(cmd.tag, tag, 256);
  cmd.tag[256 -1] = '\0';
 }
 struct iovec v = {
  .iov_base = &cmd,
  .iov_len = sizeof(cmd)
 };
 struct msghdr m = {
  .msg_iov = &v,
  .msg_iovlen = 1
 };
 int dev_fd[1] = { -1 };
 char buffer[((((sizeof(dev_fd)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
 if (passfd) {
  int fd = open( param, 00 );
  if (fd < 0) {
   perror("open");
   return 1;
  }
  dev_fd[0] = fd ;
  m.msg_control = buffer;
  m.msg_controllen = sizeof(buffer);
  struct cmsghdr *cmessage = ((size_t) (&m)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&m)->msg_control : (struct cmsghdr *) 0);
  cmessage->cmsg_level = 1;
  cmessage->cmsg_type = SCM_RIGHTS;
  cmessage->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(dev_fd)));
  m.msg_controllen = cmessage->cmsg_len;
  memcpy(((cmessage)->__cmsg_data), dev_fd, sizeof dev_fd);
 }
 int done = sendmsg( cmd_fd, &m, 0 );
 return (done == -1);
}

canonical_original_code:
int send_command(int cmd_fd, enum command_type type, char *param, int passfd, int exclusive, char *tag) {
 if (type == CMD_ADD && passfd == 1) {
  type = CMD_PASSFD;
 }
 struct command cmd = {
  .fd = -1,
  .exclusive = exclusive,
  .type = type,
  .param = {0},
  .tag = {0}
 };
 if (param != ((void *)0)) {
  strncpy(cmd.param, param, 256);
  cmd.param[256 -1] = '\0';
 }
 if (tag != ((void *)0)) {
  strncpy(cmd.tag, tag, 256);
  cmd.tag[256 -1] = '\0';
 }
 struct iovec v = {
  .iov_base = &cmd,
  .iov_len = sizeof(cmd)
 };
 struct msghdr m = {
  .msg_iov = &v,
  .msg_iovlen = 1
 };
 int dev_fd[1] = { -1 };
 char buffer[-1];
 if (passfd) {
  int fd = open( param, 00 );
  if (fd < 0) {
   perror("open");
   return 1;
  }
  dev_fd[0] = fd ;
  m.msg_control = buffer;
  m.msg_controllen = sizeof(buffer);
  struct cmsghdr *cmessage = ((size_t) (&m)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&m)->msg_control : (struct cmsghdr *) 0);
  cmessage->cmsg_level = 1;
  cmessage->cmsg_type = SCM_RIGHTS;
  cmessage->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(dev_fd)));
  m.msg_controllen = cmessage->cmsg_len;
  memcpy(((cmessage)->__cmsg_data), dev_fd, sizeof dev_fd);
 }
 int done = sendmsg( cmd_fd, &m, 0 );
 return (done == -1);
}

variable_types:
param
char *

variable_types: passfd int

variable_types: exclusive int

variable_types:
tag
char *

variable_types: struct command { enum command_type { CMD_NOP=0, CMD_ADD=1, CMD_REMOVE=2, CMD_QUIT=3, CMD_DISABLE=4, CMD_ENABLE=5, CMD_PASSFD=6, CMD_CLEARDEVS=7, CMD_CHANGEMODE=8 } type; char param[256]; int fd; int exclusive; char tag[256]; }

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types:
buffer
char [-1]

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: done int

user_defined_types: struct command { enum command_type type; char param[256]; int fd; int exclusive; char tag[256]; }

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
__int64 __fastcall add_device_to_fdset(int *a1)
{
int v1; // ecx
__int64 result; // rax

v1 = *a1;
if ( max_fd < *a1 )
max_fd = *a1;
result = v1 / 64;
rfds.fds_bits[result] |= 1LL << (v1 % 64);
return result;
}

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

v1 = *a1;
if ( max_fd < *a1 )
max_fd = *a1;
result = v1 / 64;
rfds.fds_bits[result] |= 1LL << (v1 % 64);
return result;
}

original_code:
static void add_device_to_fdset( device *d ) {
 int fd = d->fd;
 if (fd > max_fd) {
  max_fd = fd;
 }
 ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
}

canonical_original_code:
static void add_device_to_fdset(struct device *d) {
 int fd = d->fd;
 if (fd > max_fd) {
  max_fd = fd;
 }
 ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
}

variable_types: struct device { int fd; char *devname; int exclusive; char tag[256]; struct device *next; } *


decompiled_code:
void __fastcall handle_signal(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
exiting = 1;
}
else if ( a1 == 1 )
{
reload_conf = 1;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
exiting = 1;
}
else if ( a1 == 1 )
{
reload_conf = 1;
}
}

original_code:
static void handle_signal(int sig) {
 switch (sig) {
  case 2:
  case 15:
   exiting = 1;
   break;
  case 1:
   reload_conf = 1;
   break;
 }
}

variable_types: sig int


decompiled_code:
__int64 process_devices()
{
return for_each_device(check_device);
}

canonical_decompiled_code:
__int64 func3()
{
return for_each_device(check_device);
}

original_code:
static void process_devices(void) {
 for_each_device( &check_device );
}

canonical_original_code:
static void process_devices() {
 for_each_device( &check_device );
}


decompiled_code:
__int64 reload_triggerfile()
{
__int64 result; // rax

clear_triggers();
result = 0LL;
if ( triggerfile )
{
result = read_triggers();
if ( (_DWORD)result )
{
fprintf(stderr, "Error loading triggerfile '%s'\n", (const char *)triggerfile);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

clear_triggers();
result = 0LL;
if ( triggerfile )
{
result = read_triggers();
if ( (_DWORD)result )
{
fprintf(stderr, "Error loading triggerfile '%s'\n", (const char *)triggerfile);
result = 1LL;
}
}
return result;
}

original_code:
static int reload_triggerfile(void) {
 clear_triggers();
 if (triggerfile) {
  int err = read_triggers(triggerfile);
  if (err) {
   fprintf(stderr, "Error loading triggerfile '%s'\n", triggerfile);
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
static int reload_triggerfile() {
 clear_triggers();
 if (triggerfile) {
  int err = read_triggers(triggerfile);
  if (err) {
   fprintf(stderr, "Error loading triggerfile '%s'\n", triggerfile);
   return 1;
  }
 }
 return 0;
}

variable_types: err int