decompiled_code:
__int64 __fastcall wav_add_samples(__int64 a1, size_t a2, int a3)
{
const void *v3; // r12
unsigned int v5; // ebp
__int64 v6; // rdx
char *v7; // rdi
unsigned int v8; // ebp
char *v9; // rax

v3 = (const void *)a2;
LODWORD(a2) = *(_DWORD *)(a1 + 12);
v5 = a3 * *(unsigned __int16 *)(a1 + 8);
v6 = *(unsigned int *)(a1 + 16);
v7 = *(char **)(a1 + 24);
v8 = v5 >> 3;
if ( (unsigned int)v6 + v8 <= (unsigned int)a2 )
goto LABEL_5;
do
a2 = (unsigned int)(2 * a2);
while ( (unsigned int)v6 + v8 > (unsigned int)a2 );
*(_DWORD *)(a1 + 12) = a2;
v9 = (char *)realloc(v7, a2);
*(_QWORD *)(a1 + 24) = v9;
v7 = v9;
if ( v9 )
{
v6 = *(unsigned int *)(a1 + 16);
LABEL_5:
memcpy(&v7[v6], v3, v8);
*(_DWORD *)(a1 + 16) += v8;
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, size_t a2, int a3)
{
const void *v3; // r12
unsigned int v5; // ebp
__int64 v6; // rdx
char *v7; // rdi
unsigned int v8; // ebp
char *v9; // rax

v3 = (const void *)a2;
LODWORD(a2) = *(_DWORD *)(a1 + 12);
v5 = a3 * *(unsigned __int16 *)(a1 + 8);
v6 = *(unsigned int *)(a1 + 16);
v7 = *(char **)(a1 + 24);
v8 = v5 >> 3;
if ( (unsigned int)v6 + v8 <= (unsigned int)a2 )
goto LABEL_5;
do
a2 = (unsigned int)(2 * a2);
while ( (unsigned int)v6 + v8 > (unsigned int)a2 );
*(_DWORD *)(a1 + 12) = a2;
v9 = (char *)realloc(v7, a2);
*(_QWORD *)(a1 + 24) = v9;
v7 = v9;
if ( v9 )
{
v6 = *(unsigned int *)(a1 + 16);
LABEL_5:
memcpy(&v7[v6], v3, v8);
*(_DWORD *)(a1 + 16) += v8;
return 1LL;
}
return 0LL;
}

original_code:
int wav_add_samples(wav_t *w, void *samples, uint32_t nsamples) {
 uint32_t nbytes = nsamples * w->bits_per_sample / 8;
 if(w->nbytes + nbytes > w->abytes) {
  while(w->nbytes + nbytes > w->abytes)
   w->abytes <<= 1;
  w->bytes = realloc(w->bytes, w->abytes);
  if(!w->bytes)
   return 0;
 }
 memcpy(w->bytes + w->nbytes, samples, nbytes);
 w->nbytes += nbytes;
 return 1;
}

canonical_original_code:
int wav_add_samples(struct wav_t *w, void *samples, unsigned int nsamples) {
 unsigned int nbytes = nsamples * w->bits_per_sample / 8;
 if(w->nbytes + nbytes > w->abytes) {
  while(w->nbytes + nbytes > w->abytes)
   w->abytes <<= 1;
  w->bytes = realloc(w->bytes, w->abytes);
  if(!w->bytes)
   return 0;
 }
 memcpy(w->bytes + w->nbytes, samples, nbytes);
 w->nbytes += nbytes;
 return 1;
}

variable_types:
samples
void *

variable_types:
nsamples
unsigned int

variable_types:
nbytes
unsigned int

user_defined_types: struct wav_t { unsigned short num_channels; unsigned int sample_rate; unsigned short bits_per_sample; unsigned int abytes; unsigned int nbytes; char *bytes; }


getarg

repo: wernsey/miscsrc

decompiled_code:
__int64 __fastcall getarg(int a1, __int64 a2, char *a3)
{
char *v5; // rdi
unsigned int v6; // er12
__int64 v7; // rax
_BYTE *v8; // rax
char v9; // si
char v10; // al
char v11; // cl
__int64 v12; // rdx
int v13; // eax
__int64 result; // rax
_BYTE *v15; // rax

argopt = 0;
argarg = 0LL;
if ( !a3 || !a2 )
return (unsigned int)-1;
v5 = (char *)a_0;
if ( a_0 )
{
v6 = *(unsigned __int8 *)a_0;
if ( (_BYTE)v6 )
goto LABEL_9;
LODWORD(v7) = argind + 1;
argind = v7;
if ( (int)v7 >= a1 )
return (unsigned int)-1;
v7 = (int)v7;
}
else
{
v7 = argind;
if ( argind >= a1 )
return (unsigned int)-1;
}
v8 = *(_BYTE **)(a2 + 8 * v7);
a_0 = (__int64)v8;
if ( *v8 != 45 )
return (unsigned int)-1;
v5 = v8 + 1;
a_0 = (__int64)(v8 + 1);
v6 = (unsigned __int8)v8[1];
LABEL_9:
argopt = (char)v6;
v9 = *v5;
if ( *v5 == 45 )
{
++argind;
return (unsigned int)-1;
}
v10 = *a3;
if ( *a3 )
{
while ( 1 )
{
v11 = v10;
v10 = a3[1];
if ( v9 == v11 )
break;
++a3;
if ( !v10 )
goto LABEL_18;
}
v12 = (__int64)(v5 + 1);
if ( v10 == 58 )
{
if ( !v5[1] )
{
a_0 = (__int64)(v5 + 1);
v13 = argind + 1;
argind = v13;
if ( v13 < a1 )
{
argarg = *(_QWORD *)(a2 + 8LL * v13);
return v6;
}
v6 = 58;
if ( argerr )
fprintf(stderr, "argument '-%c' missing a value\n", (unsigned int)v5[1]);
return v6;
}
argarg = (__int64)(v5 + 1);
if ( !*v5 )
return v6;
v15 = v5 + 1;
do
v12 = (__int64)v15++;
while ( *(v15 - 1) );
}
result = v6;
a_0 = v12;
}
else
{
LABEL_18:
v6 = 63;
if ( !argerr )
return v6;
fprintf(stderr, "unknown option '-%c'\n", (unsigned int)v9);
result = 63LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, char *a3)
{
char *v5; // rdi
unsigned int v6; // er12
__int64 v7; // rax
_BYTE *v8; // rax
char v9; // si
char v10; // al
char v11; // cl
__int64 v12; // rdx
int v13; // eax
__int64 result; // rax
_BYTE *v15; // rax

argopt = 0;
argarg = 0LL;
if ( !a3 || !a2 )
return (unsigned int)-1;
v5 = (char *)a_0;
if ( a_0 )
{
v6 = *(unsigned __int8 *)a_0;
if ( (_BYTE)v6 )
goto LABEL_9;
LODWORD(v7) = argind + 1;
argind = v7;
if ( (int)v7 >= a1 )
return (unsigned int)-1;
v7 = (int)v7;
}
else
{
v7 = argind;
if ( argind >= a1 )
return (unsigned int)-1;
}
v8 = *(_BYTE **)(a2 + 8 * v7);
a_0 = (__int64)v8;
if ( *v8 != 45 )
return (unsigned int)-1;
v5 = v8 + 1;
a_0 = (__int64)(v8 + 1);
v6 = (unsigned __int8)v8[1];
LABEL_9:
argopt = (char)v6;
v9 = *v5;
if ( *v5 == 45 )
{
++argind;
return (unsigned int)-1;
}
v10 = *a3;
if ( *a3 )
{
while ( 1 )
{
v11 = v10;
v10 = a3[1];
if ( v9 == v11 )
break;
++a3;
if ( !v10 )
goto LABEL_18;
}
v12 = (__int64)(v5 + 1);
if ( v10 == 58 )
{
if ( !v5[1] )
{
a_0 = (__int64)(v5 + 1);
v13 = argind + 1;
argind = v13;
if ( v13 < a1 )
{
argarg = *(_QWORD *)(a2 + 8LL * v13);
return v6;
}
v6 = 58;
if ( argerr )
fprintf(stderr, "argument '-%c' missing a value\n", (unsigned int)v5[1]);
return v6;
}
argarg = (__int64)(v5 + 1);
if ( !*v5 )
return v6;
v15 = v5 + 1;
do
v12 = (__int64)v15++;
while ( *(v15 - 1) );
}
result = v6;
a_0 = v12;
}
else
{
LABEL_18:
v6 = 63;
if ( !argerr )
return v6;
fprintf(stderr, "unknown option '-%c'\n", (unsigned int)v9);
result = 63LL;
}
return result;
}

original_code:
char getarg(int argc, char * const argv[], const char *opts)
{
 static char *a = 0;
 const char *c;
 argopt = 0;
 argarg = 0;
 if(!opts || !argv) return -1;
 if(!a)
 {
  if(argind >= argc) return -1;
  a = argv[argind];
  if(a[0] != '-')
   return -1;
  else
   a++;
 }
 else if(a[0] == '\0')
 {
  if(++argind >= argc) return -1;
  a = argv[argind];
  if(a[0] != '-')
   return -1;
  else
   a++;
 }
 argopt = a[0];
 if(a[0] == '-')
 {
  argind++;
  return -1;
 }
 for(c = opts; c[0]; c++)
 {
  if(c[0] == a[0])
  {
   if(c[1] == ':')
   {
    if(a[1] != '\0')
    {
     argarg = a + 1;
     while(a[0]) a++;
     return argopt;
    }
    else
    {
     a++;
     if(++argind >= argc)
     {
      if(argerr) fprintf(stderr, "argument '-%c' missing a value\n", a[0]);
      return ':';
     }
     argarg = argv[argind];
     return argopt;
    }
   }
   else
   {
    a++;
    return argopt;
   }
  }
 }
 if(argerr) fprintf(stderr, "unknown option '-%c'\n", a[0]);
 return '?';
}

canonical_original_code:
char getarg(int argc, char *argv[], char *opts)
{
 static char *a = 0;
 char *c;
 argopt = 0;
 argarg = 0;
 if(!opts || !argv) return -1;
 if(!a)
 {
  if(argind >= argc) return -1;
  a = argv[argind];
  if(a[0] != '-')
   return -1;
  else
   a++;
 }
 else if(a[0] == '\0')
 {
  if(++argind >= argc) return -1;
  a = argv[argind];
  if(a[0] != '-')
   return -1;
  else
   a++;
 }
 argopt = a[0];
 if(a[0] == '-')
 {
  argind++;
  return -1;
 }
 for(c = opts; c[0]; c++)
 {
  if(c[0] == a[0])
  {
   if(c[1] == ':')
   {
    if(a[1] != '\0')
    {
     argarg = a + 1;
     while(a[0]) a++;
     return argopt;
    }
    else
    {
     a++;
     if(++argind >= argc)
     {
      if(argerr) fprintf(stderr, "argument '-%c' missing a value\n", a[0]);
      return ':';
     }
     argarg = argv[argind];
     return argopt;
    }
   }
   else
   {
    a++;
    return argopt;
   }
  }
 }
 if(argerr) fprintf(stderr, "unknown option '-%c'\n", a[0]);
 return '?';
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
opts
char *

variable_types:
a
char *

variable_types:
c
char *

return_type: char


repo: wernsey/rengine

decompiled_code:
_BOOL8 gdb_new()
{
ini_free(gamedb);
gamedb = ini_read(0LL, 0LL, 0LL);
return gamedb != 0;
}

canonical_decompiled_code:
_BOOL8 func0()
{
ini_free(gamedb);
gamedb = ini_read(0LL, 0LL, 0LL);
return gamedb != 0;
}

original_code:
int gdb_new() {
 ini_free(gamedb);
 gamedb = ini_read(((void *)0), ((void *)0), ((void *)0));
 return gamedb != ((void *)0);
}

return_type: int


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

result = ini_free(gamedb);
gamedb = 0LL;
return result;
}

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

result = ini_free(gamedb);
gamedb = 0LL;
return result;
}

original_code:
void gdb_close() {
 ini_free(gamedb);
 gamedb = ((void *)0);
}

return_type: void


decompiled_code:
__int64 __fastcall gdb_save(const char *a1)
{
__int64 result; // rax
const char *v2; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v3, 0x100uLL, "%s/%s", (const char *)&initial_dir, a1);
result = ini_write(gamedb, v3);
if ( (_DWORD)result != 1 )
{
v2 = (const char *)ini_errstr((unsigned int)result);
rerror("Unable to save Game DataBase: %s", v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 result; // rax
const char *v2; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v3, 0x100uLL, "%s/%s", (const char *)&initial_dir, a1);
result = ini_write(gamedb, v3);
if ( (_DWORD)result != 1 )
{
v2 = (const char *)ini_errstr((unsigned int)result);
rerror("Unable to save Game DataBase: %s", v2);
result = 0LL;
}
return result;
}

original_code:
int gdb_save(const char *filename) {
    char buffer[256];
    snprintf(buffer, sizeof buffer, "%s/%s", initial_dir, filename);
 ((void) (0));
 int result = ini_write(gamedb, buffer);
 if(result != 1) {
  rerror("Unable to save Game DataBase: %s", ini_errstr(result));
  return 0;
 }
 return 1;
}

canonical_original_code:
int gdb_save(char *filename) {
    char buffer[256];
    snprintf(buffer, sizeof buffer, "%s/%s", initial_dir, filename);
 ((void) (0));
 int result = ini_write(gamedb, buffer);
 if(result != 1) {
  rerror("Unable to save Game DataBase: %s", ini_errstr(result));
  return 0;
 }
 return 1;
}

variable_types:
filename
char *

variable_types:
buffer
char [256]

variable_types: result int


decompiled_code:
__int64 __fastcall gdb_load(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
const char *v4; // rax
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

ini_free(gamedb);
v1 = ini_read(a1, &v5, v6);
v2 = 1;
gamedb = v1;
if ( !v1 )
{
v4 = (const char *)ini_errstr(v5);
rerror("Unable to load Game database: line %d: %s", v6[0], v4);
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
const char *v4; // rax
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

ini_free(gamedb);
v1 = ini_read(a1, &v5, v6);
v2 = 1;
gamedb = v1;
if ( !v1 )
{
v4 = (const char *)ini_errstr(v5);
rerror("Unable to load Game database: line %d: %s", v6[0], v4);
v2 = 0;
}
return v2;
}

original_code:
int gdb_load(const char *filename) {
 int err, line;
 ini_free(gamedb);
 gamedb = ini_read(filename, &err, &line);
 if(!gamedb) {
  rerror("Unable to load Game database: line %d: %s", line, ini_errstr(err));
  return 0;
 }
 return 1;
}

canonical_original_code:
int gdb_load(char *filename) {
 int err; int line;
 ini_free(gamedb);
 gamedb = ini_read(filename, &err, &line);
 if(!gamedb) {
  rerror("Unable to load Game database: line %d: %s", line, ini_errstr(err));
  return 0;
 }
 return 1;
}

variable_types: err int

variable_types: line int


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

result = ini_put(gamedb, 0LL, a1, a2);
if ( !(_DWORD)result )
result = rerror("Unable to insert '%s' = '%s' into game database", a1, a2);
return result;
}

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

result = ini_put(gamedb, 0LL, a1, a2);
if ( !(_DWORD)result )
result = rerror("Unable to insert '%s' = '%s' into game database", a1, a2);
return result;
}

original_code:
void gdb_put(const char *key, const char *value) {
 if(!ini_put(gamedb, ((void *)0), key, value)) {
  rerror("Unable to insert '%s' = '%s' into game database", key, value);
 }
}

canonical_original_code:
void gdb_put(char *key, char *value) {
 if(!ini_put(gamedb, ((void *)0), key, value)) {
  rerror("Unable to insert '%s' = '%s' into game database", key, value);
 }
}

variable_types:
key
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall gdb_get(__int64 a1)
{
return ini_get(gamedb, 0LL, a1, &unk_2D6);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return ini_get(gamedb, 0LL, a1, &unk_2D6);
}

original_code:
const char *gdb_get(const char *key) {
 return ini_get(gamedb, ((void *)0), key, "");
}

canonical_original_code:
char *gdb_get(char *key) {
 return ini_get(gamedb, ((void *)0), key, "");
}

return_type: char *


decompiled_code:
__int64 __fastcall gdb_get_null(__int64 a1)
{
return ini_get(gamedb, 0LL, a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return ini_get(gamedb, 0LL, a1, 0LL);
}

original_code:
const char *gdb_get_null(const char *key) {
 return ini_get(gamedb, ((void *)0), key, ((void *)0));
}

canonical_original_code:
char *gdb_get_null(char *key) {
 return ini_get(gamedb, ((void *)0), key, ((void *)0));
}


decompiled_code:
_BOOL8 __fastcall gdb_has(__int64 a1)
{
return ini_get(gamedb, 0LL, a1, 0LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return ini_get(gamedb, 0LL, a1, 0LL) != 0;
}

original_code:
int gdb_has(const char *key) {
 return ini_get(gamedb, ((void *)0), key, ((void *)0)) != ((void *)0);
}

canonical_original_code:
int gdb_has(char *key) {
 return ini_get(gamedb, ((void *)0), key, ((void *)0)) != ((void *)0);
}


decompiled_code:
__int64 __fastcall gdb_local_put(const char *a1, const char *a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = (_QWORD *)current_state();
result = ini_put(gamedb, *v2, a1, a2);
if ( !(_DWORD)result )
result = rerror("Unable to insert '%s' = '%s' into game database", a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = (_QWORD *)current_state();
result = ini_put(gamedb, *v2, a1, a2);
if ( !(_DWORD)result )
result = rerror("Unable to insert '%s' = '%s' into game database", a1, a2);
return result;
}

original_code:
void gdb_local_put(const char *key, const char *value) {
 const char *name = current_state()->name;
 if(!ini_put(gamedb, name, key, value)) {
  rerror("Unable to insert '%s' = '%s' into game database", key, value);
 }
}

canonical_original_code:
void gdb_local_put(char *key, char *value) {
 char *name = current_state()->name;
 if(!ini_put(gamedb, name, key, value)) {
  rerror("Unable to insert '%s' = '%s' into game database", key, value);
 }
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall gdb_local_get(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)current_state();
return ini_get(gamedb, *v1, a1, &unk_2D6);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)current_state();
return ini_get(gamedb, *v1, a1, &unk_2D6);
}

original_code:
const char *gdb_local_get(const char *key){
 const char *name = current_state()->name;
 return ini_get(gamedb, name, key, "");
}

canonical_original_code:
char *gdb_local_get(char *key){
 char *name = current_state()->name;
 return ini_get(gamedb, name, key, "");
}


decompiled_code:
__int64 __fastcall gdb_local_get_null(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)current_state();
return ini_get(gamedb, *v1, a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)current_state();
return ini_get(gamedb, *v1, a1, 0LL);
}

original_code:
const char *gdb_local_get_null(const char *key){
 const char *name = current_state()->name;
 return ini_get(gamedb, name, key, ((void *)0));
}

canonical_original_code:
char *gdb_local_get_null(char *key){
 char *name = current_state()->name;
 return ini_get(gamedb, name, key, ((void *)0));
}


decompiled_code:
_BOOL8 __fastcall gdb_local_has(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)current_state();
return ini_get(gamedb, *v1, a1, 0LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)current_state();
return ini_get(gamedb, *v1, a1, 0LL) != 0;
}

original_code:
int gdb_local_has(const char *key) {
 const char *name = current_state()->name;
 return ini_get(gamedb, name, key, ((void *)0)) != ((void *)0);
}

canonical_original_code:
int gdb_local_has(char *key) {
 char *name = current_state()->name;
 return ini_get(gamedb, name, key, ((void *)0)) != ((void *)0);
}


decompiled_code:
int __fastcall json_dump_L(__int64 a1, int a2)
{
__int64 v2; // rbx
int result; // eax
const char *v4; // rdi
const char *v5; // rax
__int64 v6; // r12
char *v7; // rbp
const char *v8; // rax
__int64 v9; // rax
__int64 v10; // rbp
_BYTE v11[264]; // [rsp-128h] [rbp-128h] BYREF
__int64 v12; // [rsp-20h] [rbp-20h]

v12 = v2;
result = *(_DWORD *)a1;
switch ( *(_DWORD *)a1 )
{
case 0:
v5 = json_escape(*(char **)(a1 + 8), v11, 256LL);
return printf("\"%s\"", v5);
case 1:
return printf("%s", *(const char **)(a1 + 8));
case 2:
v6 = *(_QWORD *)(a1 + 8);
v7 = (char *)ht_next(v6, 0LL);
puts("{");
if ( v7 )
{
while ( 1 )
{
v8 = json_escape(v7, v11, 256LL);
printf("%*c\"%s\" : ", 2 * a2 + 1, 32LL, v8);
v9 = ht_get(v6, v7);
json_dump_L(v9, (unsigned int)(a2 + 1));
v7 = (char *)ht_next(v6, v7);
if ( !v7 )
break;
puts(",");
}
}
return putchar(125);
case 3:
v10 = *(_QWORD *)(a1 + 8);
puts("[");
if ( v10 )
{
while ( 1 )
{
printf("%*c", 2 * a2, 32LL);
json_dump_L(v10, (unsigned int)(a2 + 1));
v10 = *(_QWORD *)(v10 + 16);
if ( !v10 )
break;
puts(",");
}
}
return putchar(93);
case 4:
v4 = "true";
goto LABEL_3;
case 5:
v4 = "false";
goto LABEL_3;
case 6:
v4 = "null";
LABEL_3:
result = printf(v4);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, int a2)
{
__int64 v2; // rbx
int result; // eax
const char *v4; // rdi
const char *v5; // rax
__int64 v6; // r12
char *v7; // rbp
const char *v8; // rax
__int64 v9; // rax
__int64 v10; // rbp
_BYTE v11[264]; // [rsp-128h] [rbp-128h] BYREF
__int64 v12; // [rsp-20h] [rbp-20h]

v12 = v2;
result = *(_DWORD *)a1;
switch ( *(_DWORD *)a1 )
{
case 0:
v5 = json_escape(*(char **)(a1 + 8), v11, 256LL);
return printf("\"%s\"", v5);
case 1:
return printf("%s", *(const char **)(a1 + 8));
case 2:
v6 = *(_QWORD *)(a1 + 8);
v7 = (char *)ht_next(v6, 0LL);
puts("{");
if ( v7 )
{
while ( 1 )
{
v8 = json_escape(v7, v11, 256LL);
printf("%*c\"%s\" : ", 2 * a2 + 1, 32LL, v8);
v9 = ht_get(v6, v7);
func3(v9, (unsigned int)(a2 + 1));
v7 = (char *)ht_next(v6, v7);
if ( !v7 )
break;
puts(",");
}
}
return putchar(125);
case 3:
v10 = *(_QWORD *)(a1 + 8);
puts("[");
if ( v10 )
{
while ( 1 )
{
printf("%*c", 2 * a2, 32LL);
func3(v10, (unsigned int)(a2 + 1));
v10 = *(_QWORD *)(v10 + 16);
if ( !v10 )
break;
puts(",");
}
}
return putchar(93);
case 4:
v4 = "true";
goto LABEL_3;
case 5:
v4 = "false";
goto LABEL_3;
case 6:
v4 = "null";
LABEL_3:
result = printf(v4);
break;
default:
return result;
}
return result;
}

original_code:
static void json_dump_L(JSON *v, int L) {
 char buffer[256];
 switch(v->type) {
  case j_string: {
   printf("\"%s\"", json_escape(v->value, buffer, sizeof buffer));
  } break;
  case j_number: printf("%s", (const char *)v->value); break;
  case j_object: {
   Hash_Tbl *h = v->value;
   const char *key = ht_next (h, ((void *)0));
   puts("{");
   while(key) {
    printf("%*c\"%s\" : ", L*2 + 1, ' ', json_escape(key, buffer, sizeof buffer));
    json_dump_L(ht_get(h, key), L + 1);
    key = ht_next(h, key);
    if(key)
     puts(",");
   }
   printf("}");
  } break;
  case j_array: {
   JSON *m = v->value;
   puts("[");
   while(m) {
    printf("%*c", L*2, ' ');
    json_dump_L(m, L + 1);
    m = m->next;
    if(m)
     puts(",");
   }
   printf("]");
  } break;
  case j_true: {
   printf("true");
  } break;
  case j_false: {
   printf("false");
  } break;
  case j_null: {
   printf("null");
  } break;
  default: break;
 }
}

canonical_original_code:
static void json_dump_L(struct json *v, int L) {
 char buffer[256];
 switch(v->type) {
  case j_string: {
   printf("\"%s\"", json_escape(v->value, buffer, sizeof buffer));
  } break;
  case j_number: printf("%s", (char *)v->value); break;
  case j_object: {
   struct hash_tbl *h = v->value;
   char *key = ht_next (h, ((void *)0));
   puts("{");
   while(key) {
    printf("%*c\"%s\" : ", L*2 + 1, ' ', json_escape(key, buffer, sizeof buffer));
    json_dump_L(ht_get(h, key), L + 1);
    key = ht_next(h, key);
    if(key)
     puts(",");
   }
   printf("}");
  } break;
  case j_array: {
   struct json *m = v->value;
   puts("[");
   while(m) {
    printf("%*c", L*2, ' ');
    json_dump_L(m, L + 1);
    m = m->next;
    if(m)
     puts(",");
   }
   printf("]");
  } break;
  case j_true: {
   printf("true");
  } break;
  case j_false: {
   printf("false");
  } break;
  case j_null: {
   printf("null");
  } break;
  default: break;
 }
}

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

variable_types: L int

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

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

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


decompiled_code:
void __fastcall json_free(void *ptr)
{
unsigned int v1; // eax
_QWORD *i; // rdi

v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 2 )
{
ht_free(*((_QWORD *)ptr + 1), &json_free_member);
free(ptr);
}
else
{
if ( v1 > 2 )
{
if ( v1 == 3 )
{
for ( i = (_QWORD *)*((_QWORD *)ptr + 1); i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = i[2];
json_free(i);
}
}
}
else
{
free(*((void **)ptr + 1));
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
unsigned int v1; // eax
_QWORD *i; // rdi

v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 2 )
{
ht_free(*((_QWORD *)ptr + 1), &json_free_member);
free(ptr);
}
else
{
if ( v1 > 2 )
{
if ( v1 == 3 )
{
for ( i = (_QWORD *)*((_QWORD *)ptr + 1); i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = i[2];
func4(i);
}
}
}
else
{
free(*((void **)ptr + 1));
}
free(ptr);
}
}

original_code:
void json_free(JSON *v) {
 switch(v->type) {
  case j_string:
  case j_number: free(v->value); break;
  case j_object: {
   Hash_Tbl *h = v->value;
    ht_free(h, json_free_member);
  } break;
  case j_array: {
   while(v->value) {
    JSON *t = v->value;
    v->value = t->next;
    json_free(t);
   }
  }
  default: break;
 }
 free(v);
}

canonical_original_code:
void json_free(struct json *v) {
 switch(v->type) {
  case j_string:
  case j_number: free(v->value); break;
  case j_object: {
   struct hash_tbl *h = v->value;
    ht_free(h, json_free_member);
  } break;
  case j_array: {
   while(v->value) {
    struct json *t = v->value;
    v->value = t->next;
    json_free(t);
   }
  }
  default: break;
 }
 free(v);
}

user_defined_types: enum json_type { j_string=0, j_number=1, j_object=2, j_array=3, j_true=4, j_false=5, j_null=6 }

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


decompiled_code:
void __fastcall json_free_member(__int64 a1, void *a2)
{
json_free(a2);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, void *a2)
{
func4(a2);
}

original_code:
static void json_free_member(const char *key, void *val) {
 json_free(val);
}

canonical_original_code:
static void json_free_member(char *key, void *val) {
 json_free(val);
}

variable_types:
val
void *


decompiled_code:
void *json_read()
{
__int64 v0; // rax
void *v1; // rbp
void *v2; // r12

v0 = my_readfile();
if ( !v0 )
return 0LL;
v1 = (void *)v0;
v2 = json_parse(v0);
free(v1);
return v2;
}

canonical_decompiled_code:
void *func7()
{
__int64 v0; // rax
void *v1; // rbp
void *v2; // r12

v0 = my_readfile();
if ( !v0 )
return 0LL;
v1 = (void *)v0;
v2 = func6(v0);
free(v1);
return v2;
}

original_code:
JSON *json_read(const char *filename) {
 JSON *v = ((void *)0);
 char *text = my_readfile(filename);
 if(!text)
  return ((void *)0);
 v = json_parse(text);
 free(text);
 return v;
}

canonical_original_code:
struct json *json_read(char *filename) {
 struct json *v = ((void *)0);
 char *text = my_readfile(filename);
 if(!text)
  return ((void *)0);
 v = json_parse(text);
 free(text);
 return v;
}

variable_types:
text
char *

return_type: 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; } *


decompiled_code:
int __fastcall json_dump(__int64 a1)
{
return json_dump_L(a1, 0);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
return func3(a1, 0);
}

original_code:
void json_dump(JSON *v) {
 json_dump_L(v, 0);
}

canonical_original_code:
void json_dump(struct json *v) {
 json_dump_L(v, 0);
}


decompiled_code:
void __fastcall json_as_number(__int64 a1)
{
if ( *(_DWORD *)a1 == 1 )
atof(*(const char **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
if ( *(_DWORD *)a1 == 1 )
atof(*(const char **)(a1 + 8));
}

original_code:
double json_as_number(JSON *j) {
 if(j->type == j_number)
  return atof(j->value);
 return 0.0;
}

canonical_original_code:
double json_as_number(struct json *j) {
 if(j->type == j_number)
  return atof(j->value);
 return 0.0;
}

return_type: double


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

result = 0LL;
if ( !*(_DWORD *)a1 )
result = *(_QWORD *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( !*(_DWORD *)a1 )
result = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
const char *json_as_string(JSON *j) {
 if(j->type == j_string)
  return j->value;
 return ((void *)0);
}

canonical_original_code:
char *json_as_string(struct json *j) {
 if(j->type == j_string)
  return j->value;
 return ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall json_is_number(_DWORD *a1)
{
return *a1 == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(_DWORD *a1)
{
return *a1 == 1;
}

original_code:
int json_is_number(JSON *j) {
 return j->type == j_number;
}

canonical_original_code:
int json_is_number(struct json *j) {
 return j->type == j_number;
}


decompiled_code:
_BOOL8 __fastcall json_is_string(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int json_is_string(JSON *j) {
 return j->type == j_string;
}

canonical_original_code:
int json_is_string(struct json *j) {
 return j->type == j_string;
}


decompiled_code:
_BOOL8 __fastcall json_is_object(_DWORD *a1)
{
return *a1 == 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1)
{
return *a1 == 2;
}

original_code:
int json_is_object(JSON *j) {
 return j->type == j_object;
}

canonical_original_code:
int json_is_object(struct json *j) {
 return j->type == j_object;
}


decompiled_code:
_BOOL8 __fastcall json_is_array(_DWORD *a1)
{
return *a1 == 3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(_DWORD *a1)
{
return *a1 == 3;
}

original_code:
int json_is_array(JSON *j) {
 return j->type == j_array;
}

canonical_original_code:
int json_is_array(struct json *j) {
 return j->type == j_array;
}


decompiled_code:
__int64 __fastcall json_get_member(__int64 a1, __int64 a2)
{
return ht_get(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return ht_get(*(_QWORD *)(a1 + 8), a2);
}

original_code:
JSON *json_get_member(JSON *j, const char *name) {
 Hash_Tbl *h = j->value;
 return ht_get(h, name);
}

canonical_original_code:
struct json *json_get_member(struct json *j, char *name) {
 struct hash_tbl *h = j->value;
 return ht_get(h, name);
}

variable_types:
j
struct json *


decompiled_code:
void __fastcall json_get_number(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = json_get_member(a1, a2);
if ( v2 )
json_as_number(v2);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = func15(a1, a2);
if ( v2 )
func9(v2);
}

original_code:
double json_get_number(JSON *j, const char *name) {
 JSON *v = json_get_member(j, name);
 if(v)
  return json_as_number(v);
 return 0.0;
}

canonical_original_code:
double json_get_number(struct json *j, char *name) {
 struct json *v = json_get_member(j, name);
 if(v)
  return json_as_number(v);
 return 0.0;
}


decompiled_code:
__int64 __fastcall json_get_string(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = json_get_member(a1, a2);
if ( v2 )
result = json_as_string(v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = func15(a1, a2);
if ( v2 )
result = func10(v2);
else
result = 0LL;
return result;
}

original_code:
const char *json_get_string(JSON *j, const char *name) {
 JSON *v = json_get_member(j, name);
 if(v)
  return json_as_string(v);
 return ((void *)0);
}

canonical_original_code:
char *json_get_string(struct json *j, char *name) {
 struct json *v = json_get_member(j, name);
 if(v)
  return json_as_string(v);
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall json_array_len(__int64 a1)
{
unsigned int v1; // er8
__int64 i; // rax

v1 = 0;
if ( *(_DWORD *)a1 == 3 )
{
for ( i = *(_QWORD *)(a1 + 8); i; ++v1 )
i = *(_QWORD *)(i + 16);
}
return v1;
}

original_code:
int json_array_len(JSON *j) {
 int c = 0;
 if(j->type != j_array)
  return 0;
 j = j->value;
 while(j) {
  c++;
  j = j->next;
 }
 return c;
}

canonical_original_code:
int json_array_len(struct json *j) {
 int c = 0;
 if(j->type != j_array)
  return 0;
 j = j->value;
 while(j) {
  c++;
  j = j->next;
 }
 return c;
}

variable_types: c int


decompiled_code:
__int64 __fastcall json_array_nth(__int64 a1, int a2)
{
__int64 result; // rax
int i; // edx

result = 0LL;
if ( *(_DWORD *)a1 == 3 )
{
result = *(_QWORD *)(a1 + 8);
if ( result )
{
if ( a2 )
{
for ( i = 0; i != a2; ++i )
{
result = *(_QWORD *)(result + 16);
if ( !result )
break;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2)
{
__int64 result; // rax
int i; // edx

result = 0LL;
if ( *(_DWORD *)a1 == 3 )
{
result = *(_QWORD *)(a1 + 8);
if ( result )
{
if ( a2 )
{
for ( i = 0; i != a2; ++i )
{
result = *(_QWORD *)(result + 16);
if ( !result )
break;
}
}
}
}
return result;
}

original_code:
JSON *json_array_nth(JSON *j, int n) {
 int c = 0;
 if(j->type != j_array)
  return 0;
 j = j->value;
 while(j) {
  if(c++ == n)
   return j;
  j = j->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct json *json_array_nth(struct json *j, int n) {
 int c = 0;
 if(j->type != j_array)
  return 0;
 j = j->value;
 while(j) {
  if(c++ == n)
   return j;
  j = j->next;
 }
 return ((void *)0);
}

variable_types: n int


decompiled_code:
__int64 __fastcall my_stricmp(char *a1, char *a2)
{
char *v2; // r12
char *v3; // rbp
__int64 v4; // rbx
const __int32_t *v5; // rdx
__int32_t v7; // ecx
__int32_t v8; // eax

v2 = a2;
v3 = a1;
v4 = *a1;
v5 = *_ctype_tolower_loc();
if ( (_BYTE)v4 )
{
while ( 1 )
{
v8 = v5[v4];
v7 = v5[*v2];
if ( v7 != v8 )
break;
v4 = *++v3;
if ( !(_BYTE)v4 )
return (unsigned int)(*v5 - v5[v2[1]]);
++v2;
}
}
else
{
v7 = v5[*a2];
v8 = *v5;
}
return (unsigned int)(v8 - v7);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char *a2)
{
char *v2; // r12
char *v3; // rbp
__int64 v4; // rbx
const __int32_t *v5; // rdx
__int32_t v7; // ecx
__int32_t v8; // eax

v2 = a2;
v3 = a1;
v4 = *a1;
v5 = *_ctype_tolower_loc();
if ( (_BYTE)v4 )
{
while ( 1 )
{
v8 = v5[v4];
v7 = v5[*v2];
if ( v7 != v8 )
break;
v4 = *++v3;
if ( !(_BYTE)v4 )
return (unsigned int)(*v5 - v5[v2[1]]);
++v2;
}
}
else
{
v7 = v5[*a2];
v8 = *v5;
}
return (unsigned int)(v8 - v7);
}

original_code:
int my_stricmp(const char *p, const char *q) {
 for(;*p && tolower(*p) == tolower(*q); p++, q++);
 return tolower(*p) - tolower(*q);
}

canonical_original_code:
int my_stricmp(char *p, char *q) {
 for(;*p && tolower(*p) == tolower(*q); p++, q++);
 return tolower(*p) - tolower(*q);
}

variable_types:
p
char *

variable_types:
q
char *


decompiled_code:
void *__fastcall my_strdup(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func1(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
char *my_strdup(const char *s) {
 char *a;
 size_t len = strlen(s);
 a = malloc(len + 1);
 if(!a) return ((void *)0);
 memcpy(a, s, len + 1);
 return a;
}

canonical_original_code:
char *my_strdup(char *s) {
 char *a;
 unsigned long len = strlen(s);
 a = malloc(len + 1);
 if(!a) return ((void *)0);
 memcpy(a, s, len + 1);
 return a;
}

variable_types:
s
char *

variable_types:
a
char *

variable_types:
len
unsigned long


decompiled_code:
char *__fastcall my_strtok_r(char *s, const char *a2, char **a3)
{
char *v3; // r12
char *v5; // rax
char *v7; // rax

v3 = s;
if ( !s )
{
v3 = *a3;
if ( **a3 )
goto LABEL_3;
LABEL_7:
*a3 = v3;
return 0LL;
}
if ( !*s )
goto LABEL_7;
LABEL_3:
v5 = strpbrk(v3, a2);
if ( v5 )
{
*v5 = 0;
*a3 = v5 + 1;
return v3;
}
*a3 = v3;
if ( !*v3 )
return v3;
v7 = v3 + 1;
do
*a3 = v7++;
while ( *(v7 - 1) );
return v3;
}

canonical_decompiled_code:
char *__fastcall func4(char *s, const char *a2, char **a3)
{
char *v3; // r12
char *v5; // rax
char *v7; // rax

v3 = s;
if ( !s )
{
v3 = *a3;
if ( **a3 )
goto LABEL_3;
LABEL_7:
*a3 = v3;
return 0LL;
}
if ( !*s )
goto LABEL_7;
LABEL_3:
v5 = strpbrk(v3, a2);
if ( v5 )
{
*v5 = 0;
*a3 = v5 + 1;
return v3;
}
*a3 = v3;
if ( !*v3 )
return v3;
v7 = v3 + 1;
do
*a3 = v7++;
while ( *(v7 - 1) );
return v3;
}

original_code:
char *my_strtok_r(char *str, const char *delim, char **saveptr) {
 if(!str)
  str = *saveptr;
 if(!str[0]) {
  *saveptr = str;
  return ((void *)0);
 }
 char *s = strpbrk(str, delim);
 if(s) {
  s[0] = '\0';
  *saveptr = s + 1;
 } else
  for(*saveptr = str; (*saveptr)[0]; (*saveptr)++);
 return str;
}

canonical_original_code:
char *my_strtok_r(char *str, char *delim, char **saveptr) {
 if(!str)
  str = *saveptr;
 if(!str[0]) {
  *saveptr = str;
  return ((void *)0);
 }
 char *s = strpbrk(str, delim);
 if(s) {
  s[0] = '\0';
  *saveptr = s + 1;
 } else
  for(*saveptr = str; (*saveptr)[0]; (*saveptr)++);
 return str;
}

variable_types:
str
char *

variable_types:
delim
char *

variable_types:
saveptr
char **


decompiled_code:
_QWORD *re_cache_create()
{
_QWORD *v0; // r12
__int64 v1; // rax

v0 = malloc(0x20uLL);
*v0 = ht_create(128LL);
v0[1] = ht_create(128LL);
v1 = ht_create(128LL);
v0[3] = 0LL;
v0[2] = v1;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
__int64 v1; // rax

v0 = malloc(0x20uLL);
*v0 = ht_create(128LL);
v0[1] = ht_create(128LL);
v1 = ht_create(128LL);
v0[3] = 0LL;
v0[2] = v1;
return v0;
}

original_code:
static struct resource_cache *re_cache_create() {
 struct resource_cache *rc = malloc(sizeof *rc);
 rc->bmp_cache = ht_create(128);
 rc->wav_cache = ht_create(128);
 rc->mus_cache = ht_create(128);
 rc->parent = ((void *)0);
 return rc;
}

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

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


decompiled_code:
void __fastcall re_cache_destroy(void *ptr)
{
ht_free(*(_QWORD *)ptr, bmp_cache_cleanup);
ht_free(*((_QWORD *)ptr + 1), wav_cache_cleanup);
ht_free(*((_QWORD *)ptr + 2), mus_cache_cleanup);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
ht_free(*(_QWORD *)ptr, bmp_cache_cleanup);
ht_free(*((_QWORD *)ptr + 1), wav_cache_cleanup);
ht_free(*((_QWORD *)ptr + 2), mus_cache_cleanup);
free(ptr);
}

original_code:
static void re_cache_destroy(struct resource_cache *rc) {
 ht_free(rc->bmp_cache, bmp_cache_cleanup);
 ht_free(rc->wav_cache, wav_cache_cleanup);
 ht_free(rc->mus_cache, mus_cache_cleanup);
 free(rc);
}


decompiled_code:
__int64 __fastcall wav_cache_cleanup(const char *a1, __int64 a2)
{
rlog("Freeing '%s'", a1);
return Mix_FreeChunk(a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2)
{
rlog("Freeing '%s'", a1);
return Mix_FreeChunk(a2);
}

original_code:
static void wav_cache_cleanup(const char *key, void *vb) {
 Mix_Chunk *sound = vb;
 rlog("Freeing '%s'", key);
 Mix_FreeChunk(sound);
}

canonical_original_code:
static void wav_cache_cleanup(char *key, void *vb) {
 struct Mix_Chunk *sound = vb;
 rlog("Freeing '%s'", key);
 Mix_FreeChunk(sound);
}

variable_types:
key
char *

variable_types:
vb
void *

variable_types: struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; } *


decompiled_code:
__int64 __fastcall bmp_cache_cleanup(const char *a1, __int64 a2)
{
rlog("Freeing '%s'", a1);
return bm_free(a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2)
{
rlog("Freeing '%s'", a1);
return bm_free(a2);
}

original_code:
static void bmp_cache_cleanup(const char *key, void *vb) {
 struct bitmap *bmp = vb;
 rlog("Freeing '%s'", key);
 bm_free(bmp);
}

canonical_original_code:
static void bmp_cache_cleanup(char *key, void *vb) {
 struct bitmap *bmp = vb;
 rlog("Freeing '%s'", key);
 bm_free(bmp);
}

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 bitmap { int w; unsigned char *data; unsigned int color; struct bitmap_font *font; struct { int x0; int x1; } clip; }


decompiled_code:
_QWORD *re_initialize()
{
_QWORD *result; // rax

rlog("Initializing resources.");
result = re_cache_create();
re_cache = result;
return result;
}

canonical_decompiled_code:
_QWORD *func6()
{
_QWORD *result; // rax

rlog("Initializing resources.");
result = func0();
re_cache = result;
return result;
}

original_code:
void re_initialize() {
 rlog("Initializing resources.");
 re_cache = re_cache_create();
}


decompiled_code:
void re_clean_up()
{
_QWORD *i; // rdi

rlog("Cleaning up resources");
for ( i = re_cache; re_cache; i = re_cache )
{
re_cache = (void *)i[3];
re_cache_destroy(i);
}
}

canonical_decompiled_code:
void func7()
{
_QWORD *i; // rdi

rlog("Cleaning up resources");
for ( i = re_cache; re_cache; i = re_cache )
{
re_cache = (void *)i[3];
func1(i);
}
}

original_code:
void re_clean_up() {
 rlog("Cleaning up resources");
 while(re_cache) {
  struct resource_cache *t = re_cache;
  re_cache = re_cache->parent;
  re_cache_destroy(t);
 }
}


decompiled_code:
__int64 __fastcall rs_read_pak(void *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = pak_open();
v2 = 0;
game_pak = v1;
if ( v1 )
{
pak_file_name = a1;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = pak_open();
v2 = 0;
game_pak = v1;
if ( v1 )
{
pak_file_name = a1;
v2 = 1;
}
return v2;
}

original_code:
int rs_read_pak(const char *filename) {
 game_pak = pak_open(filename);
 if(game_pak) {
  pak_file_name = filename;
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
int rs_read_pak(char *filename) {
 game_pak = pak_open(filename);
 if(game_pak) {
  pak_file_name = filename;
  return 1;
 } else {
  return 0;
 }
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall re_get_ini(const char *a1)
{
__int64 v1; // rax
void *v2; // r13
__int64 v3; // r12
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, &v7, v8);
if ( !v3 )
{
v6 = (const char *)ini_errstr(v7);
rerror("Unable to parse %s:%d %s", a1, (unsigned int)v8[0], v6);
}
free(v2);
}
else
{
v3 = 0LL;
rerror("Unable to find %s in %s", a1, (const char *)pak_file_name);
}
}
else
{
v3 = ini_read(a1, &v7, v8);
if ( !v3 )
{
v5 = (const char *)ini_errstr(v7);
rerror("Unable to read %s:%d %s", a1, (unsigned int)v8[0], v5);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
__int64 v1; // rax
void *v2; // r13
__int64 v3; // r12
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, &v7, v8);
if ( !v3 )
{
v6 = (const char *)ini_errstr(v7);
rerror("Unable to parse %s:%d %s", a1, (unsigned int)v8[0], v6);
}
free(v2);
}
else
{
v3 = 0LL;
rerror("Unable to find %s in %s", a1, (const char *)pak_file_name);
}
}
else
{
v3 = ini_read(a1, &v7, v8);
if ( !v3 )
{
v5 = (const char *)ini_errstr(v7);
rerror("Unable to read %s:%d %s", a1, (unsigned int)v8[0], v5);
}
}
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; }


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

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

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

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

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 *

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 re_get_script(const char *a1)
{
__int64 v1; // r12

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; // r12

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:
txt
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

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


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


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


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)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rbx
unsigned int v5; // er12

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

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

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

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; // r8
__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();
while ( (v5[v4] & 8) != 0 || v4 == 95 )
{
v4 = *++v1;
if ( !v4 )
goto LABEL_7;
}
result = 0LL;
}
else
{
LABEL_7:
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
const char *v1; // rbp
size_t v2; // r8
__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();
while ( (v5[v4] & 8) != 0 || v4 == 95 )
{
v4 = *++v1;
if ( !v4 )
goto LABEL_7;
}
result = 0LL;
}
else
{
LABEL_7:
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; // rbp
__int64 v4; // r13
_BOOL4 v5; // er12
_BOOL8 result; // rax

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);
result = v5;
}
else
{
rerror("Unable to parse JSON: %s", a2);
result = 0LL;
}
}
else
{
rerror("Unable to read tileset from %s", a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1, const char *a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r13
_BOOL4 v5; // er12
_BOOL8 result; // rax

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);
result = v5;
}
else
{
rerror("Unable to parse JSON: %s", a2);
result = 0LL;
}
}
else
{
rerror("Unable to read tileset from %s", a2);
result = 0LL;
}
return result;
}

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


handleSpecialKeys

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

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

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

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


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:
__int64 reset_keys()
{
__int64 result; // rax

result = 0LL;
memset(keys, 0, sizeof(keys));
return result;
}

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

result = 0LL;
memset(keys, 0, sizeof(keys));
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
unsigned int *v3; // rax
__int64 v4; // r8
__int64 v5; // rcx
__int64 result; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
const char *v10; // 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 )
{
v7 = (const char *)SDL_GetError();
rerror("SDL_ShowCursor: %s", v7);
}
v3 = (unsigned int *)bm_create((unsigned int)virt_width, (unsigned int)virt_height);
v4 = v3[1];
v5 = *v3;
bmp = (__int64)v3;
tex = SDL_CreateTexture(ren, 372645892LL, 1LL, v5, v4);
if ( tex )
{
rlog("Texture Created.");
reset_keys();
result = 1LL;
}
else
{
v10 = (const char *)SDL_GetError();
rerror("SDL_CreateTexture: %s", v10);
result = 0LL;
}
}
else
{
v9 = (const char *)SDL_GetError();
rerror("SDL_CreateRenderer: %s", v9);
result = 0LL;
}
}
else
{
v8 = (const char *)SDL_GetError();
rerror("SDL_CreateWindow: %s", v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned int *v3; // rax
__int64 v4; // r8
__int64 v5; // rcx
__int64 result; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
const char *v10; // 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 )
{
v7 = (const char *)SDL_GetError();
rerror("SDL_ShowCursor: %s", v7);
}
v3 = (unsigned int *)bm_create((unsigned int)virt_width, (unsigned int)virt_height);
v4 = v3[1];
v5 = *v3;
bmp = (__int64)v3;
tex = SDL_CreateTexture(ren, 372645892LL, 1LL, v5, v4);
if ( tex )
{
rlog("Texture Created.");
func8();
result = 1LL;
}
else
{
v10 = (const char *)SDL_GetError();
rerror("SDL_CreateTexture: %s", v10);
result = 0LL;
}
}
else
{
v9 = (const char *)SDL_GetError();
rerror("SDL_CreateRenderer: %s", v9);
result = 0LL;
}
}
else
{
v8 = (const char *)SDL_GetError();
rerror("SDL_CreateWindow: %s", v8);
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)
{
size_t v1; // r12
char *v2; // r13
const char *v3; // rbp
int v4; // edi
size_t v5; // rdx
char *v7; // rax
char v8[8]; // [rsp+8h] [rbp-B0h] BYREF
char dest[168]; // [rsp+10h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
size_t v1; // r12
char *v2; // r13
const char *v3; // rbp
int v4; // edi
size_t v5; // rdx
char *v7; // rax
char v8[8]; // [rsp+8h] [rbp-B0h] BYREF
char dest[168]; // [rsp+10h] [rbp-A8h] BYREF

v1 = 128LL;
dest[0] = 0;
v2 = strdup(a1);
v3 = (const char *)my_strtok_r(v2, "/\\", v8);
if ( v3 )
{
while ( *v3 )
{
if ( dest[0] )
{
v5 = v1--;
strncat(dest, "/", v5);
}
strncat(dest, v3, v1);
v1 -= strlen(v3);
if ( mkdir(dest, 0x1FFu) )
{
v4 = *_errno_location();
if ( v4 != 17 )
{
v7 = strerror(v4);
fprintf(stderr, "error: mkdir(%s): %s\n", dest, v7);
return 0xFFFFFFFFLL;
}
}
v3 = (const char *)my_strtok_r(0LL, "/\\", v8);
if ( !v3 )
break;
}
}
free(v2);
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; // er8
__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; // er8
__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_368, 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_368, 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

result = search_isra_0(*(_QWORD *)a1, *(_DWORD *)(a1 + 8), a2);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

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

result = func1(*(_QWORD *)a1, *(_DWORD *)(a1 + 8), a2);
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 *


decompiled_code:
void __fastcall ht_free(void *ptr, void (__fastcall *a2)(void *, void *))
{
int v3; // eax
_QWORD *v4; // rdi
__int64 v5; // r14
void **v6; // rbp

v3 = *((_DWORD *)ptr + 2);
v4 = *(_QWORD **)ptr;
if ( v3 > 0 )
{
v5 = 0LL;
do
{
while ( 1 )
{
v6 = (void **)v4[v5];
if ( v6 )
break;
if ( *((_DWORD *)ptr + 2) <= (int)++v5 )
goto LABEL_9;
}
do
{
v4[v5] = v6[2];
if ( a2 )
a2(*v6, v6[1]);
free(*v6);
free(v6);
v4 = *(_QWORD **)ptr;
v6 = *(void ***)(*(_QWORD *)ptr + 8 * v5);
}
while ( v6 );
++v5;
}
while ( *((_DWORD *)ptr + 2) > (int)v5 );
}
LABEL_9:
free(v4);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr, void (__fastcall *a2)(void *, void *))
{
int v3; // eax
_QWORD *v4; // rdi
__int64 v5; // r14
void **v6; // rbp

v3 = *((_DWORD *)ptr + 2);
v4 = *(_QWORD **)ptr;
if ( v3 > 0 )
{
v5 = 0LL;
do
{
while ( 1 )
{
v6 = (void **)v4[v5];
if ( v6 )
break;
if ( *((_DWORD *)ptr + 2) <= (int)++v5 )
goto LABEL_9;
}
do
{
v4[v5] = v6[2];
if ( a2 )
a2(*v6, v6[1]);
free(*v6);
free(v6);
v4 = *(_QWORD **)ptr;
v6 = *(void ***)(*(_QWORD *)ptr + 8 * v5);
}
while ( v6 );
++v5;
}
while ( *((_DWORD *)ptr + 2) > (int)v5 );
}
LABEL_9:
free(v4);
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:
__int64 __fastcall ht_foreach(__int64 a1, __int64 (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 result; // rax
__int64 v4; // r13
_QWORD *v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 result; // rax
__int64 v4; // r13
_QWORD *v6; // rbx

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

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

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

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