decompiled_code:
void __fastcall gc_set_dtor(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 - 48) = a2;
}

original_code:
void gc_set_dtor(void *p, gc_function dtor) {
 GcObj *r;
 ((void) (0));
 r = (GcObj *)((char *)p - sizeof *r);
 r->dtor = dtor;
}

canonical_original_code:
void gc_set_dtor(void *p, void (*dtor)(void *)) {
 struct gc_object *r;
 ((void) (0));
 r = (struct gc_object *)((char *)p - sizeof *r);
 r->dtor = dtor;
}

variable_types:
dtor
void (*)(void *)


repo: wernsey/miscsrc

decompiled_code:
void __fastcall gc_set_marker(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 - 56) = a2;
}

original_code:
void gc_set_marker(void *p, gc_function marker) {
 GcObj *r;
 ((void) (0));
 r = (GcObj *)((char *)p - sizeof *r);
 r->marker = marker;
}

canonical_original_code:
void gc_set_marker(void *p, void (*marker)(void *)) {
 struct gc_object *r;
 ((void) (0));
 r = (struct gc_object *)((char *)p - sizeof *r);
 r->marker = marker;
}

variable_types:
p
void *

variable_types:
marker
void (*)(void *)

variable_types: struct gc_object { int mark; void (*marker)(void *); void (*dtor)(void *); int retcount; struct gc_object *next; struct gc_object *rnext; } *

return_type: void


decompiled_code:
int gc_dump()
{
__int64 v0; // rbx
int result; // eax
unsigned int *v2; // rbx

v0 = gc_roots;
if ( gc_roots )
{
puts("Roots:");
do
{
result = printf(" - %p (%d)\n", (const void *)(v0 + 64), *(unsigned int *)(v0 + 24));
v0 = *(_QWORD *)(v0 + 48);
}
while ( v0 );
}
v2 = (unsigned int *)gc_objs;
if ( gc_objs )
{
puts("Garbage:");
do
{
result = printf(" - %p (%d)\n", v2 + 16, *v2);
v2 = (unsigned int *)*((_QWORD *)v2 + 4);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int func8()
{
__int64 v0; // rbx
int result; // eax
unsigned int *v2; // rbx

v0 = gc_roots;
if ( gc_roots )
{
puts("Roots:");
do
{
result = printf(" - %p (%d)\n", (const void *)(v0 + 64), *(unsigned int *)(v0 + 24));
v0 = *(_QWORD *)(v0 + 48);
}
while ( v0 );
}
v2 = (unsigned int *)gc_objs;
if ( gc_objs )
{
puts("Garbage:");
do
{
result = printf(" - %p (%d)\n", v2 + 16, *v2);
v2 = (unsigned int *)*((_QWORD *)v2 + 4);
}
while ( v2 );
}
return result;
}

original_code:
void gc_dump() {
 GcObj *gc = gc_roots;
 if(gc) {
  printf("Roots:\n");
  while(gc) {
   void *data = (char*)gc + sizeof *gc;
   printf("    - %p (%d)\n", data, gc->retcount);
   gc = gc->rnext;
  }
 }
 gc = gc_objs;
 if(gc) {
  printf("Garbage:\n");
  while(gc) {
   void *data = (char*)gc + sizeof *gc;
   printf("    - %p (%d)\n", data, gc->mark);
   gc = gc->next;
  }
 }
}

canonical_original_code:
void gc_dump() {
 struct gc_object *gc = gc_roots;
 if(gc) {
  printf("Roots:\n");
  while(gc) {
   void *data = (char*)gc + sizeof *gc;
   printf("    - %p (%d)\n", data, gc->retcount);
   gc = gc->rnext;
  }
 }
 gc = gc_objs;
 if(gc) {
  printf("Garbage:\n");
  while(gc) {
   void *data = (char*)gc + sizeof *gc;
   printf("    - %p (%d)\n", data, gc->mark);
   gc = gc->next;
  }
 }
}

variable_types:
data
void *

user_defined_types: struct gc_object { int mark; void (*marker)(void *); void (*dtor)(void *); int retcount; struct gc_object *next; struct gc_object *rnext; }


decompiled_code:
void gc_init()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void gc_init() {
}

canonical_original_code:
void gc_init() {
}


atom

original_code:
static int
atom (const char *text, const char *re, struct mstruct *m)
{
  const char *set;
  if (re[0] == '[')
    {
      int f = 0;
      if (re[1] == '!')
        re++;
      for (set = re + 1; set[0] != ']'; set++)
        {
          if (set[0] == '\0')
            return 0;
          if (set[0] == '\\')
            set++;
          else if (set[1] == '-')
            {
              if (set[2] == '\0')
                return 0;
     else if(set[2] == ']')
      goto check1;
              if (m->flags & 1)
                {
                  if (tolower (text[0]) >= tolower (set[0]) &&
                      tolower (text[0]) <= tolower (set[2]))
                    f = 1;
                }
              else if (text[0] >= set[0] && text[0] <= set[2])
                f = 1;
              set += 2;
              continue;
            }
check1:
          if (m->flags & 1)
            {
              if (tolower (set[0]) == tolower (text[0]))
                f = 1;
            }
          else if (set[0] == text[0])
            f = 1;
        }
      return (re[0] == '!') ? (!f) : (f);
    }
  else if (re[0] == '\\')
    {
      switch (re[1])
        {
        case 'a':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISalpha);
        case 'w':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISalnum);
        case 'd':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISdigit);
        case 'u':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISupper);
        case 'l':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISlower);
        case 'x':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISxdigit);
        case 's':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISspace);
        case 'A':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISalpha);
        case 'W':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISalnum);
        case 'D':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISdigit);
        case 'U':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISupper);
        case 'L':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISlower);
        case 'X':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISxdigit);
        case 'S':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short int) _ISspace);
        default:
          re++;
          break;
        }
    }
  if (m->flags & 1)
    return tolower (re[0]) == tolower (text[0]) || re[0] == '.';
  return re[0] == text[0] || re[0] == '.';
}

canonical_original_code:
static int atom(char *text, char *re, struct mstruct *m)
{
  char *set;
  if (re[0] == '[')
    {
      int f = 0;
      if (re[1] == '!')
        re++;
      for (set = re + 1; set[0] != ']'; set++)
        {
          if (set[0] == '\0')
            return 0;
          if (set[0] == '\\')
            set++;
          else if (set[1] == '-')
            {
              if (set[2] == '\0')
                return 0;
     else if(set[2] == ']')
      goto check1;
              if (m->flags & 1)
                {
                  if (tolower (text[0]) >= tolower (set[0]) &&
                      tolower (text[0]) <= tolower (set[2]))
                    f = 1;
                }
              else if (text[0] >= set[0] && text[0] <= set[2])
                f = 1;
              set += 2;
              continue;
            }
check1:
          if (m->flags & 1)
            {
              if (tolower (set[0]) == tolower (text[0]))
                f = 1;
            }
          else if (set[0] == text[0])
            f = 1;
        }
      return (re[0] == '!') ? (!f) : (f);
    }
  else if (re[0] == '\\')
    {
      switch (re[1])
        {
        case 'a':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISalpha);
        case 'w':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISalnum);
        case 'd':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISdigit);
        case 'u':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISupper);
        case 'l':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISlower);
        case 'x':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISxdigit);
        case 's':
          return ((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISspace);
        case 'A':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISalpha);
        case 'W':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISalnum);
        case 'D':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISdigit);
        case 'U':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISupper);
        case 'L':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISlower);
        case 'X':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISxdigit);
        case 'S':
          return !((*__ctype_b_loc ())[(int) ((text[0]))] & (unsigned short) _ISspace);
        default:
          re++;
          break;
        }
    }
  if (m->flags & 1)
    return tolower (re[0]) == tolower (text[0]) || re[0] == '.';
  return re[0] == text[0] || re[0] == '.';
}

variable_types:
text
char *

variable_types:
re
char *

variable_types: struct mstruct { char flags; char *start; char *end; } *

variable_types:
set
char *

variable_types: f int

return_type: int


star

decompiled_code:
__int64 __fastcall star(unsigned __int64 a1, _BYTE *a2, __int64 a3, _BYTE *a4)
{
char *v4; // rbx
char *i; // r14
__int64 result; // rax

v4 = (char *)a1;
if ( (*a4 & 2) != 0 )
{
for ( i = (char *)a1; *i; ++i )
{
if ( !(unsigned int)atom(i, a2, a4) )
break;
}
while ( 1 )
{
result = expr(i, a3, a4);
if ( (_DWORD)result )
break;
if ( a1 >= (unsigned __int64)i-- )
return result;
}
result = 1LL;
}
else
{
while ( 1 )
{
result = expr(v4, a3, a4);
if ( (_DWORD)result )
break;
if ( !*v4 )
return result;
result = atom(v4, a2, a4);
if ( !(_DWORD)result )
return result;
++v4;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, _BYTE *a2, __int64 a3, _BYTE *a4)
{
char *v4; // rbx
char *i; // r14
__int64 result; // rax

v4 = (char *)a1;
if ( (*a4 & 2) != 0 )
{
for ( i = (char *)a1; *i; ++i )
{
if ( !(unsigned int)func0(i, a2, a4) )
break;
}
while ( 1 )
{
result = func2(i, a3, a4);
if ( (_DWORD)result )
break;
if ( a1 >= (unsigned __int64)i-- )
return result;
}
result = 1LL;
}
else
{
while ( 1 )
{
result = func2(v4, a3, a4);
if ( (_DWORD)result )
break;
if ( !*v4 )
return result;
result = func0(v4, a2, a4);
if ( !(_DWORD)result )
return result;
++v4;
}
result = 1LL;
}
return result;
}

original_code:
static int
star (const char *text, const char *s, const char *re, struct mstruct *m)
{
  if (m->flags & 2)
    {
      const char *t;
      for (t = text; t[0] && atom (t, s, m); t++);
      do
        {
          if (expr (t, re, m))
            return 1;
        }
      while (t-- > text);
    }
  else
    {
      do
        {
          if (expr (text, re, m))
            return 1;
        }
      while (text[0] != '\0' && atom (text++, s, m));
    }
  return 0;
}

canonical_original_code:
static int star(char *text, char *s, char *re, struct mstruct *m)
{
  if (m->flags & 2)
    {
      char *t;
      for (t = text; t[0] && atom (t, s, m); t++);
      do
        {
          if (expr (t, re, m))
            return 1;
        }
      while (t-- > text);
    }
  else
    {
      do
        {
          if (expr (text, re, m))
            return 1;
        }
      while (text[0] != '\0' && atom (text++, s, m));
    }
  return 0;
}

variable_types:
s
char *

variable_types:
t
char *

user_defined_types: struct mstruct { char flags; char *start; char *end; }


plus

decompiled_code:
__int64 __fastcall plus(char *a1, _BYTE *a2, char *a3, _BYTE *a4)
{
char *v4; // r14
char *v7; // rbp
__int64 result; // rax

v4 = a1;
if ( (*a4 & 2) != 0 )
{
v7 = a1;
result = 0LL;
if ( *a1 )
{
do
{
if ( !(unsigned int)atom(v7, a2, a4) )
break;
++v7;
}
while ( *v7 );
if ( a1 >= v7 )
{
result = 0LL;
}
else
{
while ( 1 )
{
result = expr(v7, a3, (__int64)a4);
if ( (_DWORD)result )
break;
if ( a1 == --v7 )
return result;
}
result = 1LL;
}
}
}
else
{
while ( *v4 )
{
result = atom(v4, a2, a4);
if ( !(_DWORD)result )
return result;
if ( (unsigned int)expr(v4 + 1, a3, (__int64)a4) )
return 1LL;
++v4;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _BYTE *a2, char *a3, _BYTE *a4)
{
char *v4; // r14
char *v7; // rbp
__int64 result; // rax

v4 = a1;
if ( (*a4 & 2) != 0 )
{
v7 = a1;
result = 0LL;
if ( *a1 )
{
do
{
if ( !(unsigned int)func0(v7, a2, a4) )
break;
++v7;
}
while ( *v7 );
if ( a1 >= v7 )
{
result = 0LL;
}
else
{
while ( 1 )
{
result = func2(v7, a3, (__int64)a4);
if ( (_DWORD)result )
break;
if ( a1 == --v7 )
return result;
}
result = 1LL;
}
}
}
else
{
while ( *v4 )
{
result = func0(v4, a2, a4);
if ( !(_DWORD)result )
return result;
if ( (unsigned int)func2(v4 + 1, a3, (__int64)a4) )
return 1LL;
++v4;
}
result = 0LL;
}
return result;
}

original_code:
static int
plus (const char *text, const char *s, const char *re, struct mstruct *m)
{
  if (m->flags & 2)
    {
      const char *t;
      for (t = text; t[0] && atom (t, s, m); t++);
      while (t > text)
        {
          if (expr (t, re, m))
            return 1;
          t--;
        }
    }
  else
    {
      while (text[0] != '\0' && atom (text++, s, m))
        if (expr (text, re, m))
          return 1;
    }
  return 0;
}

canonical_original_code:
static int plus(char *text, char *s, char *re, struct mstruct *m)
{
  if (m->flags & 2)
    {
      char *t;
      for (t = text; t[0] && atom (t, s, m); t++);
      while (t > text)
        {
          if (expr (t, re, m))
            return 1;
          t--;
        }
    }
  else
    {
      while (text[0] != '\0' && atom (text++, s, m))
        if (expr (text, re, m))
          return 1;
    }
  return 0;
}


ques

decompiled_code:
__int64 __fastcall ques(char *a1, _BYTE *a2, char *a3, _BYTE *a4)
{
__int64 result; // rax
int v7; // edx

if ( (*a4 & 2) != 0 )
{
if ( !*a1 || !(unsigned int)atom(a1, a2, a4) || (v7 = expr(a1 + 1, a3, (__int64)a4), result = 1LL, !v7) )
result = (unsigned int)expr(a1, a3, (__int64)a4) != 0;
}
else
{
result = expr(a1, a3, (__int64)a4);
if ( (_DWORD)result )
{
result = 1LL;
}
else if ( *a1 )
{
result = atom(a1, a2, a4);
if ( (_DWORD)result )
result = (unsigned int)expr(a1 + 1, a3, (__int64)a4) != 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, _BYTE *a2, char *a3, _BYTE *a4)
{
__int64 result; // rax
int v7; // edx

if ( (*a4 & 2) != 0 )
{
if ( !*a1 || !(unsigned int)func0(a1, a2, a4) || (v7 = func2(a1 + 1, a3, (__int64)a4), result = 1LL, !v7) )
result = (unsigned int)func2(a1, a3, (__int64)a4) != 0;
}
else
{
result = func2(a1, a3, (__int64)a4);
if ( (_DWORD)result )
{
result = 1LL;
}
else if ( *a1 )
{
result = func0(a1, a2, a4);
if ( (_DWORD)result )
result = (unsigned int)func2(a1 + 1, a3, (__int64)a4) != 0;
}
}
return result;
}

original_code:
static int
ques (const char *text, const char *s, const char *re, struct mstruct *m)
{
  if (m->flags & 2)
    {
      if (text[0] != '\0' && atom (text, s, m))
        if (expr (text + 1, re, m))
          return 1;
      if (expr (text, re, m))
        return 1;
    }
  else
    {
      if (expr (text, re, m))
        return 1;
      if (text[0] != '\0' && atom (text++, s, m))
        if (expr (text, re, m))
          return 1;
    }
  return 0;
}

canonical_original_code:
static int ques(char *text, char *s, char *re, struct mstruct *m)
{
  if (m->flags & 2)
    {
      if (text[0] != '\0' && atom (text, s, m))
        if (expr (text + 1, re, m))
          return 1;
      if (expr (text, re, m))
        return 1;
    }
  else
    {
      if (expr (text, re, m))
        return 1;
      if (text[0] != '\0' && atom (text++, s, m))
        if (expr (text, re, m))
          return 1;
    }
  return 0;
}


decompiled_code:
__int64 __fastcall re_match(char *a1, char *a2, __int64 a3)
{
char *v3; // rbx
__int64 result; // rax

v3 = a1;
if ( *a2 == 94 )
{
*(_QWORD *)(a3 + 8) = a1;
result = expr(a1, a2 + 1, a3);
}
else
{
while ( 1 )
{
*(_QWORD *)(a3 + 8) = v3;
result = expr(v3, a2, a3);
if ( (_DWORD)result )
break;
if ( !*v3++ )
return result;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, char *a2, __int64 a3)
{
char *v3; // rbx
__int64 result; // rax

v3 = a1;
if ( *a2 == 94 )
{
*(_QWORD *)(a3 + 8) = a1;
result = func2(a1, a2 + 1, a3);
}
else
{
while ( 1 )
{
*(_QWORD *)(a3 + 8) = v3;
result = func2(v3, a2, a3);
if ( (_DWORD)result )
break;
if ( !*v3++ )
return result;
}
result = 1LL;
}
return result;
}

original_code:
static int
re_match (const char *text, const char *re, struct mstruct *m)
{
  if (re[0] == '^')
    {
      m->start = text;
      return expr (text, re + 1, m);
    }
  else
    do
      {
        m->start = text;
        if (expr (text, re, m))
          return 1;
      }
    while ((text++)[0] != '\0');
  return 0;
}

canonical_original_code:
static int re_match(char *text, char *re, struct mstruct *m)
{
  if (re[0] == '^')
    {
      m->start = text;
      return expr (text, re + 1, m);
    }
  else
    do
      {
        m->start = text;
        if (expr (text, re, m))
          return 1;
      }
    while ((text++)[0] != '\0');
  return 0;
}


decompiled_code:
__int64 __fastcall rx_match(char *a1, char *a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = 0;
return re_match(a1, a2, (__int64)v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, char *a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = 0;
return func5(a1, a2, (__int64)v3);
}

original_code:
int
rx_match (const char *text, const char *re)
{
  struct mstruct m;
  m.flags = 0;
  return re_match (text, re, &m);
}

canonical_original_code:
int rx_match(char *text, char *re)
{
  struct mstruct m;
  m.flags = 0;
  return re_match (text, re, &m);
}

variable_types: struct mstruct { char flags; char *start; char *end; }


decompiled_code:
__int64 __fastcall rx_search(char *a1, char *a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax
char v7[8]; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]
__int64 v9; // [rsp+10h] [rbp-28h]

v7[0] = 2;
v8 = 0LL;
v9 = 0LL;
result = re_match(a1, a2, (__int64)v7);
if ( (_DWORD)result )
{
if ( a3 )
*a3 = v8;
result = 1LL;
if ( a4 )
{
*a4 = v9;
result = 1LL;
}
}
else
{
if ( a3 )
*a3 = 0LL;
if ( a4 )
*a4 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax
char v7[8]; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]
__int64 v9; // [rsp+10h] [rbp-28h]

v7[0] = 2;
v8 = 0LL;
v9 = 0LL;
result = func5(a1, a2, (__int64)v7);
if ( (_DWORD)result )
{
if ( a3 )
*a3 = v8;
result = 1LL;
if ( a4 )
{
*a4 = v9;
result = 1LL;
}
}
else
{
if ( a3 )
*a3 = 0LL;
if ( a4 )
*a4 = 0LL;
}
return result;
}

original_code:
int
rx_search (const char *text, const char *re, const char **beg,
           const char **end)
{
  struct mstruct m;
  m.flags = 2;
  m.start = 0;
  m.end = 0;
  if (re_match (text, re, &m))
    {
      if (beg)
        *beg = m.start;
      if (end)
        *end = m.end;
      return 1;
    }
  if (beg)
    *beg = 0;
  if (end)
    *end = 0;
  return 0;
}

canonical_original_code:
int rx_search(char *text, char *re, char **beg, char **end)
{
  struct mstruct m;
  m.flags = 2;
  m.start = 0;
  m.end = 0;
  if (re_match (text, re, &m))
    {
      if (beg)
        *beg = m.start;
      if (end)
        *end = m.end;
      return 1;
    }
  if (beg)
    *beg = 0;
  if (end)
    *end = 0;
  return 0;
}

variable_types:
beg
char **

variable_types:
end
char **


original_code:
static char *
int_match_sub (const char *text, const char *re, const char *sub, char once)
{
  const char *beg, *end, *p = text, *r, *u;
  char *o, *q;
  size_t len;
  if (!rx_search (text, re, &beg, &end))
    {
      char *a;
      size_t len = strlen (text);
      a = malloc (len + 1);
      if (!a)
        return ((void *)0);
      memcpy (a, text, len + 1);
      return a;
    }
  ((void) (0));
  len = strlen (text);
  o = malloc (len + 1);
  if (!o)
    return ((void *)0);
  q = o;
  do
    {
      for (; p < beg && p[0]; p++, q++)
        {
          do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
          q[0] = p[0];
        }
      for (r = sub; r[0]; r++, q++)
        {
          do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
          if (r[0] == '/')
            {
              r++;
              q[0] = r[0];
            }
          else if (r[0] == '&')
            {
              for (u = beg; u < end; u++, q++)
                {
                  do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
                  q[0] = u[0];
                }
              q--;
            }
          else
            q[0] = r[0];
        }
      p = end;
    }
  while (rx_search (end, re, &beg, &end) && !once);
  for (; p[0]; p++, q++)
    {
      do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
      q[0] = p[0];
    }
  q[0] = '\0';
  ((void) (0));
  return o;
}

canonical_original_code:
static char *int_match_sub(char *text, char *re, char *sub, char once)
{
  char *beg; char *end; char *p = text; char *r; char *u;
  char *o; char *q;
  unsigned long len;
  if (!rx_search (text, re, &beg, &end))
    {
      char *a;
      unsigned long len = strlen (text);
      a = malloc (len + 1);
      if (!a)
        return ((void *)0);
      memcpy (a, text, len + 1);
      return a;
    }
  ((void) (0));
  len = strlen (text);
  o = malloc (len + 1);
  if (!o)
    return ((void *)0);
  q = o;
  do
    {
      for (; p < beg && p[0]; p++, q++)
        {
          do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
          q[0] = p[0];
        }
      for (r = sub; r[0]; r++, q++)
        {
          do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
          if (r[0] == '/')
            {
              r++;
              q[0] = r[0];
            }
          else if (r[0] == '&')
            {
              for (u = beg; u < end; u++, q++)
                {
                  do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
                  q[0] = u[0];
                }
              q--;
            }
          else
            q[0] = r[0];
        }
      p = end;
    }
  while (rx_search (end, re, &beg, &end) && !once);
  for (; p[0]; p++, q++)
    {
      do{ if(q - o >= (int)len) { char *t; len += (len>2)?len >> 1:2; t = realloc(o, len + 1); if(!t) { free(o); return ((void *)0); } q = t + (q - o); o = t; } } while(0);
      q[0] = p[0];
    }
  q[0] = '\0';
  ((void) (0));
  return o;
}

variable_types:
sub
char *

variable_types: once char

variable_types:
beg
char *

variable_types:
end
char *

variable_types:
p
char *

variable_types:
r
char *

variable_types:
u
char *

variable_types:
o
char *

variable_types:
q
char *

variable_types:
len
unsigned long

variable_types:
a
char *

return_type: char *


decompiled_code:
void *__fastcall rx_sub(void *a1, char *a2, _BYTE *a3)
{
return int_match_sub(a1, a2, a3, 1);
}

canonical_decompiled_code:
void *__fastcall func9(void *a1, char *a2, _BYTE *a3)
{
return func8(a1, a2, a3, 1);
}

original_code:
char *
rx_sub (const char *text, const char *re, const char *sub)
{
  return int_match_sub (text, re, sub, 1);
}

canonical_original_code:
char *rx_sub(char *text, char *re, char *sub)
{
  return int_match_sub (text, re, sub, 1);
}

variable_types:
text
char *

variable_types:
re
char *


decompiled_code:
void *__fastcall rx_gsub(void *a1, char *a2, _BYTE *a3)
{
return int_match_sub(a1, a2, a3, 0);
}

canonical_decompiled_code:
void *__fastcall func10(void *a1, char *a2, _BYTE *a3)
{
return func8(a1, a2, a3, 0);
}

original_code:
char *
rx_gsub (const char *text, const char *re, const char *sub)
{
  return int_match_sub (text, re, sub, 0);
}

canonical_original_code:
char *rx_gsub(char *text, char *re, char *sub)
{
  return int_match_sub (text, re, sub, 0);
}


expr

original_code:
static int
expr (const char *text, const char *re, struct mstruct *m)
{
  int i = 0;
  if (re[0] == '\0')
    {
      m->end = text;
      return 1;
    }
  if (re[0] == '$' && re[1] == '\0')
    {
      m->end = text;
      return text[0] == '\0';
    }
  if (re[0] == '\\')
    {
      if (re[1] == 'i')
        {
          m->flags |= 1;
          return expr (text, re + 2, m);
        }
      else if (re[1] == 'I')
        {
          m->flags &= ~1;
          return expr (text, re + 2, m);
        }
      i++;
    }
  else if (re[0] == '[' && ++i)
    while (re[i] != ']')
      {
        if (re[i] == '\0')
          return 0;
        if (re[i] == '\\')
          i++;
        i++;
      }
  if (re[i + 1] == '*')
    return star (text, re, re + i + 2, m);
  if (re[i + 1] == '+')
    return plus (text, re, re + i + 2, m);
  if (re[i + 1] == '?')
    return ques (text, re, re + i + 2, m);
  if (text[0] && atom (text, re, m))
    return expr (text + 1, re + i + 1, m);
  return 0;
}

canonical_original_code:
static int expr(char *text, char *re, struct mstruct *m)
{
  int i = 0;
  if (re[0] == '\0')
    {
      m->end = text;
      return 1;
    }
  if (re[0] == '$' && re[1] == '\0')
    {
      m->end = text;
      return text[0] == '\0';
    }
  if (re[0] == '\\')
    {
      if (re[1] == 'i')
        {
          m->flags |= 1;
          return expr (text, re + 2, m);
        }
      else if (re[1] == 'I')
        {
          m->flags &= ~1;
          return expr (text, re + 2, m);
        }
      i++;
    }
  else if (re[0] == '[' && ++i)
    while (re[i] != ']')
      {
        if (re[i] == '\0')
          return 0;
        if (re[i] == '\\')
          i++;
        i++;
      }
  if (re[i + 1] == '*')
    return star (text, re, re + i + 2, m);
  if (re[i + 1] == '+')
    return plus (text, re, re + i + 2, m);
  if (re[i + 1] == '?')
    return ques (text, re, re + i + 2, m);
  if (text[0] && atom (text, re, m))
    return expr (text + 1, re + i + 1, m);
  return 0;
}

variable_types: struct mstruct { char flags; char *start; char *end; } *

variable_types: i int


printfun

decompiled_code:
__int64 __fastcall printfun(const char *a1, const char *a2)
{
printf("%s -> %s\n", a1, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
printf("%s -> %s\n", a1, a2);
return 1LL;
}

original_code:
static int printfun (const char *key, void *value, void *data) {
  printf ("%s -> %s\n", key, (char *) value);
  return 1;
}

canonical_original_code:
static int printfun(char *key, void *value, void *data) {
  printf ("%s -> %s\n", key, (char *) value);
  return 1;
}

variable_types:
key
char *

variable_types:
value
void *

variable_types:
data
void *


iterate

decompiled_code:
__int64 __fastcall iterate(__int64 a1)
{
const char *i; // rbx
const char *v2; // rax
__int64 result; // rax

for ( i = 0LL; ; printf("%s %s\n", i, v2) )
{
result = ht_next(a1, i);
i = (const char *)result;
if ( !result )
break;
v2 = (const char *)ht_find(a1, result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
const char *i; // rbx
const char *v2; // rax
__int64 result; // rax

for ( i = 0LL; ; printf("%s %s\n", i, v2) )
{
result = ht_next(a1, i);
i = (const char *)result;
if ( !result )
break;
v2 = (const char *)ht_find(a1, result);
}
return result;
}

original_code:
static void iterate (struct hash_tbl *h) {
  const char *key = ((void *)0);
  while ((key = ht_next (h, key)) != ((void *)0))
    printf ("%s %s\n", key, (char *) ht_find (h, key));
}

canonical_original_code:
static void iterate(struct hash_tbl *h) {
  char *key = ((void *)0);
  while ((key = ht_next (h, key)) != ((void *)0))
    printf ("%s %s\n", key, (char *) ht_find (h, key));
}

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 hash_tbl { struct hash_el **buckets; int size; int cnt; }


dtor

decompiled_code:
void __fastcall dtor(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, void *a2)
{
free(a2);
}

original_code:
static void dtor(const char *key, void *val) {
  free(val);
}

canonical_original_code:
static void dtor(char *key, void *val) {
  free(val);
}

variable_types:
val
void *


show

original_code:
void
show (struct hash_tbl *h)
{
  struct hash_el *e;
  int i;
  for (i = 0; i < h->size; i++)
    if (h->buckets[i])
      for (e = h->buckets[i]; e; e = e->next)
        printf ("%s %s\n", e->key, (char *) e->value);
}

canonical_original_code:
void show(struct hash_tbl *h)
{
  struct hash_el *e;
  int i;
  for (i = 0; i < h->size; i++)
    if (h->buckets[i])
      for (e = h->buckets[i]; e; e = e->next)
        printf ("%s %s\n", e->key, (char *) e->value);
}

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
size_t v5; // r12
_DWORD *v6; // rdx
unsigned int v7; // er12
unsigned int v8; // er12
unsigned int v9; // eax
int *v10; // rax
char *v11; // rax
const char *v12; // rdx
__int64 v13; // rax
const char *v14; // r12
const char *v15; // rax
void *v16; // rdi
_DWORD v17[8]; // [rsp+0h] [rbp-78h] BYREF
char v18[32]; // [rsp+20h] [rbp-58h] BYREF
char v19[56]; // [rsp+40h] [rbp-38h] BYREF

v3 = (__int64 *)ht_create(8LL, argv, envp);
if ( !v3 )
{
fwrite("error: ht_create() failed\n", 1uLL, 0x1AuLL, stderr);
return 1;
}
while ( 1 )
{
do
{
putchar(62);
fflush(stdout);
}
while ( (unsigned int)_isoc99_scanf("%s", v19) != 1 );
if ( !strcmp(v19, "end") || !strcmp(v19, "quit") || !strcmp(v19, "exit") )
break;
if ( !strcmp(v19, "add") )
{
if ( (unsigned int)_isoc99_scanf("%s %s", v18, v17) == 2 )
{
v5 = strlen((const char *)v17) + 1;
v6 = malloc(v5);
if ( v6 )
{
if ( (unsigned int)v5 >= 8 )
{
*(_QWORD *)((char *)v6 + (unsigned int)v5 - 8) = *(_QWORD *)((char *)&v17[-2] + (unsigned int)v5);
v7 = v5 - 1;
if ( v7 >= 8 )
{
v8 = v7 & 0xFFFFFFF8;
v9 = 0;
do
{
*(_QWORD *)&v6[v9 / 4] = *(_QWORD *)&v17[v9 / 4];
v9 += 8;
}
while ( v9 < v8 );
}
}
else if ( (v5 & 4) != 0 )
{
*v6 = v17[0];
*(_DWORD *)((char *)v6 + (unsigned int)v5 - 4) = *(_DWORD *)((char *)&v17[-1] + (unsigned int)v5);
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)v6 = v17[0];
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)v6 + (unsigned int)v5 - 2) = *(_WORD *)((char *)v17 + (unsigned int)v5 - 2);
}
ht_insert(v3, v18, v6);
}
else
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "error: %s\n", v11);
}
goto LABEL_15;
}
}
else if ( !strcmp(v19, "find") )
{
if ( (unsigned int)_isoc99_scanf("%s", v18) == 1 )
{
v12 = (const char *)ht_find(v3, v18);
if ( v12 )
{
printf("%s ~> %s\n", v18, v12);
goto LABEL_15;
}
LABEL_32:
printf("%s not found\n", v18);
goto LABEL_15;
}
}
else if ( !strcmp(v19, "next") )
{
if ( (unsigned int)_isoc99_scanf("%s", v18) == 1 )
{
v13 = ht_next(v3, v18);
v14 = (const char *)v13;
if ( v13 )
{
v15 = (const char *)ht_find(v3, v13);
printf("%s => %s %s\n", v18, v14, v15);
}
else
{
printf("%s does not have a next element\n", v18);
}
goto LABEL_15;
}
}
else
{
if ( strcmp(v19, "delete") )
{
if ( !strcmp(v19, "foreach") )
{
ht_foreach(v3, printfun, 0LL);
}
else if ( !strcmp(v19, "show") )
{
show(v3);
}
else if ( !strcmp(v19, "iterate") )
{
iterate((__int64)v3);
}
else
{
fwrite("error: unknown command\n", 1uLL, 0x17uLL, stderr);
}
goto LABEL_15;
}
if ( !(unsigned int)_isoc99_scanf("%s", v18) )
{
v16 = (void *)ht_delete(v3, v18);
if ( !v16 )
goto LABEL_32;
free(v16);
printf("%s deleted\n", v18);
LABEL_15:
fflush(stdout);
}
}
}
ht_free(v3, dtor);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
size_t v5; // r12
_DWORD *v6; // rdx
unsigned int v7; // er12
unsigned int v8; // er12
unsigned int v9; // eax
int *v10; // rax
char *v11; // rax
const char *v12; // rdx
__int64 v13; // rax
const char *v14; // r12
const char *v15; // rax
void *v16; // rdi
_DWORD v17[8]; // [rsp+0h] [rbp-78h] BYREF
char v18[32]; // [rsp+20h] [rbp-58h] BYREF
char v19[56]; // [rsp+40h] [rbp-38h] BYREF

v3 = (__int64 *)ht_create(8LL, argv, envp);
if ( !v3 )
{
fwrite("error: ht_create() failed\n", 1uLL, 0x1AuLL, stderr);
return 1;
}
while ( 1 )
{
do
{
putchar(62);
fflush(stdout);
}
while ( (unsigned int)_isoc99_scanf("%s", v19) != 1 );
if ( !strcmp(v19, "end") || !strcmp(v19, "quit") || !strcmp(v19, "exit") )
break;
if ( !strcmp(v19, "add") )
{
if ( (unsigned int)_isoc99_scanf("%s %s", v18, v17) == 2 )
{
v5 = strlen((const char *)v17) + 1;
v6 = malloc(v5);
if ( v6 )
{
if ( (unsigned int)v5 >= 8 )
{
*(_QWORD *)((char *)v6 + (unsigned int)v5 - 8) = *(_QWORD *)((char *)&v17[-2] + (unsigned int)v5);
v7 = v5 - 1;
if ( v7 >= 8 )
{
v8 = v7 & 0xFFFFFFF8;
v9 = 0;
do
{
*(_QWORD *)&v6[v9 / 4] = *(_QWORD *)&v17[v9 / 4];
v9 += 8;
}
while ( v9 < v8 );
}
}
else if ( (v5 & 4) != 0 )
{
*v6 = v17[0];
*(_DWORD *)((char *)v6 + (unsigned int)v5 - 4) = *(_DWORD *)((char *)&v17[-1] + (unsigned int)v5);
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)v6 = v17[0];
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)v6 + (unsigned int)v5 - 2) = *(_WORD *)((char *)v17 + (unsigned int)v5 - 2);
}
ht_insert(v3, v18, v6);
}
else
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "error: %s\n", v11);
}
goto LABEL_15;
}
}
else if ( !strcmp(v19, "find") )
{
if ( (unsigned int)_isoc99_scanf("%s", v18) == 1 )
{
v12 = (const char *)ht_find(v3, v18);
if ( v12 )
{
printf("%s ~> %s\n", v18, v12);
goto LABEL_15;
}
LABEL_32:
printf("%s not found\n", v18);
goto LABEL_15;
}
}
else if ( !strcmp(v19, "next") )
{
if ( (unsigned int)_isoc99_scanf("%s", v18) == 1 )
{
v13 = ht_next(v3, v18);
v14 = (const char *)v13;
if ( v13 )
{
v15 = (const char *)ht_find(v3, v13);
printf("%s => %s %s\n", v18, v14, v15);
}
else
{
printf("%s does not have a next element\n", v18);
}
goto LABEL_15;
}
}
else
{
if ( strcmp(v19, "delete") )
{
if ( !strcmp(v19, "foreach") )
{
ht_foreach(v3, printfun, 0LL);
}
else if ( !strcmp(v19, "show") )
{
func3(v3);
}
else if ( !strcmp(v19, "iterate") )
{
func1((__int64)v3);
}
else
{
fwrite("error: unknown command\n", 1uLL, 0x17uLL, stderr);
}
goto LABEL_15;
}
if ( !(unsigned int)_isoc99_scanf("%s", v18) )
{
v16 = (void *)ht_delete(v3, v18);
if ( !v16 )
goto LABEL_32;
free(v16);
printf("%s deleted\n", v18);
LABEL_15:
fflush(stdout);
}
}
}
ht_free(v3, dtor);
return 0;
}

original_code:
int main (int argc, char *argv[]) {
  struct hash_tbl *h;
  char cmd[20], key[20], data[20], *res;
  h = ht_create (8);
  if (!h) {
    fprintf(stderr, "error: ht_create() failed\n");
    return 1;
  }
  while (1) {
      printf (">");
      fflush (stdout);
      if(scanf ("%s", cmd) != 1) continue;
      if (!strcmp (cmd, "end") || !strcmp (cmd, "quit") || !strcmp (cmd, "exit"))
        break;
      else if (!strcmp (cmd, "add"))
        {
          char *d;
          size_t len;
          if(scanf ("%s %s", key, data) != 2) continue;
          len = strlen (data);
          d = malloc (len + 1);
          if (d)
            {
              memcpy (d, data, len + 1);
              ht_insert (h, key, d);
            }
          else
            fprintf (stderr, "error: %s\n", strerror ((*__errno_location ())));
        }
      else if (!strcmp (cmd, "find"))
        {
          if(scanf ("%s", key) != 1) continue;
          res = ht_find (h, key);
          if (res)
            printf ("%s ~> %s\n", key, res);
          else
            printf ("%s not found\n", key);
        }
      else if (!strcmp (cmd, "next"))
        {
          const char *next;
          if(scanf ("%s", key) != 1) continue;
          next = ht_next (h, key);
          if (next)
            printf ("%s => %s %s\n", key, next, (char *) ht_find (h, next));
          else
            printf ("%s does not have a next element\n", key);
        }
      else if (!strcmp (cmd, "delete"))
        {
          if(scanf ("%s", key)) continue;
          res = ht_delete (h, key);
          if (res)
            {
              free (res);
              printf ("%s deleted\n", key);
            }
          else
            printf ("%s not found\n", key);
        }
      else if (!strcmp (cmd, "foreach"))
        {
          ht_foreach (h, printfun, ((void *)0));
        }
      else if (!strcmp (cmd, "show"))
        show (h);
      else if (!strcmp (cmd, "iterate"))
        iterate (h);
      else
        fprintf (stderr, "error: unknown command\n");
      fflush (stdout);
    }
  ht_free (h, dtor);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct hash_tbl *h;
  char cmd[20]; char key[20]; char data[20]; char *res;
  h = ht_create (8);
  if (!h) {
    fprintf(stderr, "error: ht_create() failed\n");
    return 1;
  }
  while (1) {
      printf (">");
      fflush (stdout);
      if(scanf ("%s", cmd) != 1) continue;
      if (!strcmp (cmd, "end") || !strcmp (cmd, "quit") || !strcmp (cmd, "exit"))
        break;
      else if (!strcmp (cmd, "add"))
        {
          char *d;
          unsigned long len;
          if(scanf ("%s %s", key, data) != 2) continue;
          len = strlen (data);
          d = malloc (len + 1);
          if (d)
            {
              memcpy (d, data, len + 1);
              ht_insert (h, key, d);
            }
          else
            fprintf (stderr, "error: %s\n", strerror ((*__errno_location ())));
        }
      else if (!strcmp (cmd, "find"))
        {
          if(scanf ("%s", key) != 1) continue;
          res = ht_find (h, key);
          if (res)
            printf ("%s ~> %s\n", key, res);
          else
            printf ("%s not found\n", key);
        }
      else if (!strcmp (cmd, "next"))
        {
          char *next;
          if(scanf ("%s", key) != 1) continue;
          next = ht_next (h, key);
          if (next)
            printf ("%s => %s %s\n", key, next, (char *) ht_find (h, next));
          else
            printf ("%s does not have a next element\n", key);
        }
      else if (!strcmp (cmd, "delete"))
        {
          if(scanf ("%s", key)) continue;
          res = ht_delete (h, key);
          if (res)
            {
              free (res);
              printf ("%s deleted\n", key);
            }
          else
            printf ("%s not found\n", key);
        }
      else if (!strcmp (cmd, "foreach"))
        {
          ht_foreach (h, printfun, ((void *)0));
        }
      else if (!strcmp (cmd, "show"))
        show (h);
      else if (!strcmp (cmd, "iterate"))
        iterate (h);
      else
        fprintf (stderr, "error: unknown command\n");
      fflush (stdout);
    }
  ht_free (h, dtor);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
cmd
char [20]

variable_types:
key
char [20]

variable_types:
data
char [20]

variable_types:
res
char *

variable_types:
d
char *

variable_types:
next
char *

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


decompiled_code:
void rc_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void rc_init() {
}

canonical_original_code:
void rc_init() {
}


decompiled_code:
char *__fastcall rc_alloc(__int64 a1)
{
_QWORD *v1; // rax
char *v2; // rdx

v1 = malloc(a1 + 16);
if ( !v1 )
return 0LL;
v2 = (char *)(v1 + 2);
*(_DWORD *)v1 = 1;
v1[1] = 0LL;
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1)
{
_QWORD *v1; // rax
char *v2; // rdx

v1 = malloc(a1 + 16);
if ( !v1 )
return 0LL;
v2 = (char *)(v1 + 2);
*(_DWORD *)v1 = 1;
v1[1] = 0LL;
return v2;
}

original_code:
void *rc_alloc(size_t size) {
    void *data;
    RefObj *r = malloc((sizeof *r) + size);
    if(!r)
        return ((void *)0);
    data = (char*)r + sizeof *r;
    r->refcnt = 1;
    r->dtor = ((void *)0);
    return data;
}

canonical_original_code:
void *rc_alloc(unsigned long size) {
    void *data;
    struct refobj *r = malloc((sizeof *r) + size);
    if(!r)
        return ((void *)0);
    data = (char *)r + sizeof *r;
    r->refcnt = 1;
    r->dtor = ((void *)0);
    return data;
}

variable_types:
size
unsigned long

variable_types: struct refobj { unsigned int refcnt; void (*dtor)(void *); } *

return_type: void *


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

if ( a1 )
result = (char *)realloc((void *)(a1 - 16), a2 + 16) + 16;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = (char *)realloc((void *)(a1 - 16), a2 + 16) + 16;
else
result = 0LL;
return result;
}

original_code:
void *rc_realloc(void *p, size_t size) {
    RefObj *r;
    if(!p)
        return ((void *)0);
    r = (RefObj *)((char *)p - sizeof *r);
    ((void) (0));
    r = realloc(r, (sizeof *r) + size);
    return (char*)r + sizeof *r;
}

canonical_original_code:
void *rc_realloc(void *p, unsigned long size) {
    struct refobj *r;
    if(!p)
        return ((void *)0);
    r = (struct refobj *)((char *)p - sizeof *r);
    ((void) (0));
    r = realloc(r, (sizeof *r) + size);
    return (char *)r + sizeof *r;
}

variable_types:
p
void *

user_defined_types: struct refobj { unsigned int refcnt; void (*dtor)(void *); }


decompiled_code:
char *__fastcall rc_strdup(void *src)
{
size_t v1; // r12
char *v2; // rax
char *v3; // rbx

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

canonical_decompiled_code:
char *__fastcall func3(void *src)
{
size_t v1; // r12
char *v2; // rax
char *v3; // rbx

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

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

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

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
n
char *


decompiled_code:
char *__fastcall rc_memdup(void *src, size_t n)
{
char *v2; // rax
char *v3; // rbx

v2 = rc_alloc(n);
v3 = v2;
if ( v2 )
memcpy(v2, src, n);
return v3;
}

canonical_decompiled_code:
char *__fastcall func4(void *src, size_t n)
{
char *v2; // rax
char *v3; // rbx

v2 = func1(n);
v3 = v2;
if ( v2 )
memcpy(v2, src, n);
return v3;
}

original_code:
void *rc_memdup(const void *p, size_t size) {
    char *n = rc_alloc(size);
    if(!n)
        return ((void *)0);
    memcpy(n, p, size);
    return n;
}

canonical_original_code:
void *rc_memdup(void *p, unsigned long size) {
    char *n = rc_alloc(size);
    if(!n)
        return ((void *)0);
    memcpy(n, p, size);
    return n;
}


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

result = a1;
if ( a1 )
++*(_DWORD *)(a1 - 16);
return result;
}

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

result = a1;
if ( a1 )
++*(_DWORD *)(a1 - 16);
return result;
}

original_code:
void *rc_retain(void *p) {
    RefObj *r;
    if(!p)
        return ((void *)0);
    r = (RefObj *)((char *)p - sizeof *r);
    r->refcnt++;
    return p;
}

canonical_original_code:
void *rc_retain(void *p) {
    struct refobj *r;
    if(!p)
        return ((void *)0);
    r = (struct refobj *)((char *)p - sizeof *r);
    r->refcnt++;
    return p;
}


original_code:
void rc_release(void *p) {
    RefObj *r;
    if(!p)
        return;
    r = (RefObj *)((char *)p - sizeof *r);
    r->refcnt--;
    if(r->refcnt == 0) {
        if(r->dtor != ((void *)0)) {
            r->dtor(p);
        }
        free(r);
    }
}

canonical_original_code:
void rc_release(void *p) {
    struct refobj *r;
    if(!p)
        return;
    r = (struct refobj *)((char *)p - sizeof *r);
    r->refcnt--;
    if(r->refcnt == 0) {
        if(r->dtor != ((void *)0)) {
            r->dtor(p);
        }
        free(r);
    }
}


decompiled_code:
void __fastcall rc_set_dtor(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 - 8) = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 - 8) = a2;
}

original_code:
void rc_set_dtor(void *p, ref_dtor dtor) {
    RefObj *r;
    if(!p) return;
    r = (RefObj *)((char *)p - sizeof *r);
    r->dtor = dtor;
}

canonical_original_code:
void rc_set_dtor(void *p, void (*dtor)(void *)) {
    struct refobj *r;
    if(!p) return;
    r = (struct refobj *)((char *)p - sizeof *r);
    r->dtor = dtor;
}

variable_types:
dtor
void (*)(void *)


decompiled_code:
__int64 __fastcall rc_assign(__int64 *a1, __int64 a2)
{
__int64 v3; // rdi

v3 = *a1;
if ( v3 )
rc_release(v3);
*a1 = a2;
return a2;
}

original_code:
void *rc_assign(void **p, void *val) {
    if(*p) {
        rc_release(*p);
    }
    *p = val;
    return val;
}

variable_types:
p
void **

variable_types:
val
void *


simil

decompiled_code:
__int64 __fastcall simil(const char *a1, const char *a2)
{
int v2; // ebp
int v3; // eax
__int64 result; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 && v3 )
result = (unsigned int)((int)(200 * rsimil((__int64)a1, v2, (__int64)a2, v3, 1u)) / (v2 + v3));
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
int v2; // ebp
int v3; // eax
__int64 result; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 && v3 )
result = (unsigned int)((int)(200 * func0((__int64)a1, v2, (__int64)a2, v3, 1u)) / (v2 + v3));
else
result = 0LL;
return result;
}

original_code:
int
simil (const char *a, const char *b)
{
  int alen, blen;
  alen = strlen (a);
  blen = strlen (b);
  if (alen == 0 || blen == 0)
    return 0;
  return (rsimil (a, alen, b, blen, 1) * 200) / (alen + blen);
}

canonical_original_code:
int simil(char *a, char *b)
{
  int alen; int blen;
  alen = strlen (a);
  blen = strlen (b);
  if (alen == 0 || blen == 0)
    return 0;
  return (rsimil (a, alen, b, blen, 1) * 200) / (alen + blen);
}

variable_types:
a
char *

variable_types:
b
char *

variable_types: alen int

variable_types: blen int


isimil

decompiled_code:
__int64 __fastcall isimil(const char *a1, const char *a2)
{
int v2; // ebp
int v3; // eax
__int64 result; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 && v3 )
result = (unsigned int)((int)(200 * rsimil((__int64)a1, v2, (__int64)a2, v3, 0)) / (v2 + v3));
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
int v2; // ebp
int v3; // eax
__int64 result; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 && v3 )
result = (unsigned int)((int)(200 * func0((__int64)a1, v2, (__int64)a2, v3, 0)) / (v2 + v3));
else
result = 0LL;
return result;
}

original_code:
int
isimil (const char *a, const char *b)
{
  int alen, blen;
  alen = strlen (a);
  blen = strlen (b);
  if (alen == 0 || blen == 0)
    return 0;
  return (rsimil (a, alen, b, blen, 0) * 200) / (alen + blen);
}

canonical_original_code:
int isimil(char *a, char *b)
{
  int alen; int blen;
  alen = strlen (a);
  blen = strlen (b);
  if (alen == 0 || blen == 0)
    return 0;
  return (rsimil (a, alen, b, blen, 0) * 200) / (alen + blen);
}


decompiled_code:
__int64 __fastcall print_node(const char *a1)
{
printf("- %s\n", a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
printf("- %s\n", a1);
return 1LL;
}

original_code:
static int print_node(void *data)
{
 char *s = data;
 printf("- %s\n", s);
 return 1;
}

variable_types:
data
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned int v4; // eax
__int64 v5; // rax
__int64 v6; // rax
void *v7; // rax
void *v8; // rax
char *v9; // r12
char *v10; // r12
const char *v11; // rsi
char v13[48]; // [rsp+0h] [rbp-68h] BYREF
char s1[56]; // [rsp+30h] [rbp-38h] BYREF

puts("Type 'help' for help");
v3 = list_create("Type 'help' for help", argv);
while ( 1 )
{
do
{
printf(">>");
fflush(stdout);
}
while ( (unsigned int)_isoc99_scanf("%10s", s1) != 1 );
if ( !strcmp(s1, "quit") )
break;
if ( !strcmp(s1, "help") )
{
puts("help - Shows this message");
puts("quit - exits the test program");
puts("add <item> - Add item (at the end)");
puts("addf <item> - Add item to the front.");
puts("show - shows all items.");
puts("showr - shows items in revers order.");
puts("find <item> - Searches for an item in the list.");
puts("findi <item> - Case insensitive find.");
puts("rem <item> - removes an item in the list.");
puts("remi <item> - Case insensitive remove.");
puts("popf - Pops the front of the list.");
puts("popb - Pops the back of the list.");
puts("empty - Determines whether the list is empty");
puts("count - Counts the number of elements in the list");
}
else if ( !strcmp(s1, "add") )
{
if ( (unsigned int)_isoc99_scanf("%40s", v13) == 1 )
{
v5 = my_strdup(v13);
list_append(v3, v5);
}
}
else if ( !strcmp(s1, "addf") )
{
if ( (unsigned int)_isoc99_scanf("%40s", v13) == 1 )
{
v6 = my_strdup(v13);
list_prepend(v3, v6);
}
}
else if ( !strcmp(s1, "show") )
{
list_iterate(v3, print_node);
}
else if ( !strcmp(s1, "showr") )
{
list_iterate_reverse(v3, print_node);
}
else if ( !strcmp(s1, "find") )
{
if ( (unsigned int)_isoc99_scanf("%40s", v13) == 1 )
{
if ( list_find(v3, v13, &list_strcmp) )
goto LABEL_27;
LABEL_31:
printf("%s is not in the list\n", v13);
}
}
else if ( !strcmp(s1, "findi") )
{
if ( (unsigned int)_isoc99_scanf("%40s", v13) == 1 )
{
if ( !list_find(v3, v13, &list_stricmp) )
goto LABEL_31;
LABEL_27:
printf("%s is in the list\n", v13);
}
}
else if ( !strcmp(s1, "rem") )
{
if ( (unsigned int)_isoc99_scanf("%40s", v13) == 1 )
{
v7 = (void *)list_remove(v3, v13, &list_strcmp);
free(v7);
}
}
else if ( !strcmp(s1, "remi") )
{
if ( (unsigned int)_isoc99_scanf("%40s", v13) == 1 )
{
v8 = (void *)list_remove(v3, v13, &list_stricmp);
free(v8);
}
}
else if ( !strcmp(s1, "popf") )
{
v9 = (char *)list_pop_front(v3);
printf("Popped %s\n", v9);
free(v9);
}
else if ( !strcmp(s1, "popb") )
{
v10 = (char *)list_pop_back(v3);
printf("Popped %s\n", v10);
free(v10);
}
else if ( !strcmp(s1, "empty") )
{
v11 = "empty";
if ( !(unsigned int)list_isempty(v3) )
v11 = "not empty";
printf("List is %s\n", v11);
}
else if ( !strcmp(s1, "count") )
{
v4 = list_count(v3);
printf("List has %d items\n", v4);
}
else
{
fprintf(stderr, "Unknown command %s\n", s1);
fflush(stdout);
}
}
list_destroy(v3, &free);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 link_list *list;
 char cmd[21], arg[41];
 printf("Type 'help' for help\n");
 list = list_create();
 for(;;)
 {
  printf(">>");
  fflush(stdout);
  if(scanf("%10s", cmd) != 1) continue;
  if(!strcmp(cmd, "quit")) break;
  else if(!strcmp(cmd, "help"))
  {
   printf("help - Shows this message\n");
   printf("quit - exits the test program\n");
   printf("add <item> - Add item (at the end)\n");
   printf("addf <item> - Add item to the front.\n");
   printf("show - shows all items.\n");
   printf("showr - shows items in revers order.\n");
   printf("find <item> - Searches for an item in the list.\n");
   printf("findi <item> - Case insensitive find.\n");
   printf("rem <item> - removes an item in the list.\n");
   printf("remi <item> - Case insensitive remove.\n");
   printf("popf - Pops the front of the list.\n");
   printf("popb - Pops the back of the list.\n");
   printf("empty - Determines whether the list is empty\n");
   printf("count - Counts the number of elements in the list\n");
  }
  else if(!strcmp(cmd, "add"))
  {
   if(scanf("%40s", arg) != 1) continue;
   list_append(list, my_strdup(arg));
  }
  else if(!strcmp(cmd, "addf"))
  {
   if(scanf("%40s", arg) != 1) continue;
   list_prepend(list, my_strdup(arg));
  }
  else if(!strcmp(cmd, "show"))
  {
   list_iterate(list, print_node);
  }
  else if(!strcmp(cmd, "showr"))
  {
   list_iterate_reverse(list, print_node);
  }
  else if(!strcmp(cmd, "find"))
  {
   if(scanf("%40s", arg) != 1) continue;
   if(list_find(list, arg, list_strcmp))
    printf("%s is in the list\n", arg);
   else
    printf("%s is not in the list\n", arg);
  }
  else if(!strcmp(cmd, "findi"))
  {
   if(scanf("%40s", arg) != 1) continue;
   if(list_find(list, arg, list_stricmp))
    printf("%s is in the list\n", arg);
   else
    printf("%s is not in the list\n", arg);
  }
  else if(!strcmp(cmd, "rem"))
  {
   char *c;
   if(scanf("%40s", arg) != 1) continue;
   c = list_remove(list, arg, list_strcmp);
   free(c);
  }
  else if(!strcmp(cmd, "remi"))
  {
   char *c;
   if(scanf("%40s", arg) != 1) continue;
   c = list_remove(list, arg, list_stricmp);
   free(c);
  }
  else if(!strcmp(cmd, "popf"))
  {
   char *c;
   c = list_pop_front(list);
   printf("Popped %s\n", c);
   free(c);
  }
  else if(!strcmp(cmd, "popb"))
  {
   char *c;
   c = list_pop_back(list);
   printf("Popped %s\n", c);
   free(c);
  }
  else if(!strcmp(cmd, "empty"))
  {
   printf("List is %s\n", list_isempty(list)?"empty":"not empty");
  }
  else if(!strcmp(cmd, "count"))
  {
   printf("List has %d items\n", list_count(list));
  }
  else
  {
   fprintf(stderr, "Unknown command %s\n", cmd);
   fflush(stdout);
  }
 }
 list_destroy(list, free);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct link_list *list;
 char cmd[21]; char arg[41];
 printf("Type 'help' for help\n");
 list = list_create();
 for(;;)
 {
  printf(">>");
  fflush(stdout);
  if(scanf("%10s", cmd) != 1) continue;
  if(!strcmp(cmd, "quit")) break;
  else if(!strcmp(cmd, "help"))
  {
   printf("help - Shows this message\n");
   printf("quit - exits the test program\n");
   printf("add <item> - Add item (at the end)\n");
   printf("addf <item> - Add item to the front.\n");
   printf("show - shows all items.\n");
   printf("showr - shows items in revers order.\n");
   printf("find <item> - Searches for an item in the list.\n");
   printf("findi <item> - Case insensitive find.\n");
   printf("rem <item> - removes an item in the list.\n");
   printf("remi <item> - Case insensitive remove.\n");
   printf("popf - Pops the front of the list.\n");
   printf("popb - Pops the back of the list.\n");
   printf("empty - Determines whether the list is empty\n");
   printf("count - Counts the number of elements in the list\n");
  }
  else if(!strcmp(cmd, "add"))
  {
   if(scanf("%40s", arg) != 1) continue;
   list_append(list, my_strdup(arg));
  }
  else if(!strcmp(cmd, "addf"))
  {
   if(scanf("%40s", arg) != 1) continue;
   list_prepend(list, my_strdup(arg));
  }
  else if(!strcmp(cmd, "show"))
  {
   list_iterate(list, print_node);
  }
  else if(!strcmp(cmd, "showr"))
  {
   list_iterate_reverse(list, print_node);
  }
  else if(!strcmp(cmd, "find"))
  {
   if(scanf("%40s", arg) != 1) continue;
   if(list_find(list, arg, list_strcmp))
    printf("%s is in the list\n", arg);
   else
    printf("%s is not in the list\n", arg);
  }
  else if(!strcmp(cmd, "findi"))
  {
   if(scanf("%40s", arg) != 1) continue;
   if(list_find(list, arg, list_stricmp))
    printf("%s is in the list\n", arg);
   else
    printf("%s is not in the list\n", arg);
  }
  else if(!strcmp(cmd, "rem"))
  {
   char *c;
   if(scanf("%40s", arg) != 1) continue;
   c = list_remove(list, arg, list_strcmp);
   free(c);
  }
  else if(!strcmp(cmd, "remi"))
  {
   char *c;
   if(scanf("%40s", arg) != 1) continue;
   c = list_remove(list, arg, list_stricmp);
   free(c);
  }
  else if(!strcmp(cmd, "popf"))
  {
   char *c;
   c = list_pop_front(list);
   printf("Popped %s\n", c);
   free(c);
  }
  else if(!strcmp(cmd, "popb"))
  {
   char *c;
   c = list_pop_back(list);
   printf("Popped %s\n", c);
   free(c);
  }
  else if(!strcmp(cmd, "empty"))
  {
   printf("List is %s\n", list_isempty(list)?"empty":"not empty");
  }
  else if(!strcmp(cmd, "count"))
  {
   printf("List has %d items\n", list_count(list));
  }
  else
  {
   fprintf(stderr, "Unknown command %s\n", cmd);
   fflush(stdout);
  }
 }
 list_destroy(list, free);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct link_list { struct list_element { struct list_element *next; void *data; } *first; } *

variable_types:
cmd
char [21]

variable_types:
arg
char [41]

variable_types:
c
char *

user_defined_types: struct link_list { struct list_element *first; }


decompiled_code:
void __fastcall wav_free(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

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

original_code:
void wav_free(wav_t *w) {
 free(w->bytes);
 free(w);
}

canonical_original_code:
void wav_free(struct wav_t *w) {
 free(w->bytes);
 free(w);
}

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


decompiled_code:
__int64 __fastcall wav_add_samples(__int64 a1, const void *a2, int a3)
{
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // esi
void *v7; // rax

v4 = (a3 * (unsigned int)*(unsigned __int16 *)(a1 + 8)) >> 3;
v5 = *(_DWORD *)(a1 + 16) + v4;
v6 = *(_DWORD *)(a1 + 12);
if ( v5 > v6 )
{
do
v6 *= 2;
while ( v5 > v6 );
*(_DWORD *)(a1 + 12) = v6;
v7 = realloc(*(void **)(a1 + 24), v6);
*(_QWORD *)(a1 + 24) = v7;
if ( !v7 )
return 0LL;
}
memcpy((void *)(*(_QWORD *)(a1 + 24) + *(unsigned int *)(a1 + 16)), a2, v4);
*(_DWORD *)(a1 + 16) += v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2, int a3)
{
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // esi
void *v7; // rax

v4 = (a3 * (unsigned int)*(unsigned __int16 *)(a1 + 8)) >> 3;
v5 = *(_DWORD *)(a1 + 16) + v4;
v6 = *(_DWORD *)(a1 + 12);
if ( v5 > v6 )
{
do
v6 *= 2;
while ( v5 > v6 );
*(_DWORD *)(a1 + 12) = v6;
v7 = realloc(*(void **)(a1 + 24), v6);
*(_QWORD *)(a1 + 24) = v7;
if ( !v7 )
return 0LL;
}
memcpy((void *)(*(_QWORD *)(a1 + 24) + *(unsigned int *)(a1 + 16)), a2, v4);
*(_DWORD *)(a1 + 16) += v4;
return 1LL;
}

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

decompiled_code:
__int64 __fastcall getarg(int a1, __int64 a2, char *a3)
{
int v5; // eax
_BYTE *v6; // rax
__int64 v7; // rsi
unsigned int v8; // edi
char v9; // cl
char v10; // al
_BYTE *v12; // rax
unsigned int v13; // ebx
int v14; // eax
__int64 v15; // rax
__int64 v16; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, char *a3)
{
int v5; // eax
_BYTE *v6; // rax
__int64 v7; // rsi
unsigned int v8; // edi
char v9; // cl
char v10; // al
_BYTE *v12; // rax
unsigned int v13; // ebx
int v14; // eax
__int64 v15; // rax
__int64 v16; // rdx

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

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:
opts
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);
}


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


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)
{
unsigned int v1; // edx
const char *v3; // rax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

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

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

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

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, "");
}


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

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

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

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; // r12
int result; // eax
const char *v4; // rax
__int64 v5; // rbp
char *v6; // rbx
const char *v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
_QWORD v10[37]; // [rsp-128h] [rbp-128h] BYREF

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

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // r12
int result; // eax
const char *v4; // rax
__int64 v5; // rbp
char *v6; // rbx
const char *v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
_QWORD v10[37]; // [rsp-128h] [rbp-128h] BYREF

v10[35] = v2;
result = *(_DWORD *)a1;
switch ( *(_DWORD *)a1 )
{
case 0:
v4 = json_escape(*(char **)(a1 + 8), (__int64)v10, 256LL);
result = printf("\"%s\"", v4);
break;
case 1:
result = printf("%s", *(const char **)(a1 + 8));
break;
case 2:
v5 = *(_QWORD *)(a1 + 8);
v6 = (char *)ht_next(v5, 0LL);
puts("{");
if ( v6 )
{
while ( 1 )
{
v7 = json_escape(v6, (__int64)v10, 256LL);
printf("%*c\"%s\" : ", 2 * a2 + 1, 32LL, v7);
v8 = ht_get(v5, v6);
func2(v8, (unsigned int)(a2 + 1));
v6 = (char *)ht_next(v5, v6);
if ( !v6 )
break;
puts(",");
}
}
result = putchar(125);
break;
case 3:
v9 = *(_QWORD *)(a1 + 8);
puts("[");
if ( v9 )
{
while ( 1 )
{
printf("%*c", 2 * a2, 32LL);
func2(v9, (unsigned int)(a2 + 1));
v9 = *(_QWORD *)(v9 + 16);
if ( !v9 )
break;
puts(",");
}
}
result = putchar(93);
break;
case 4:
result = printf("true");
break;
case 5:
result = printf("false");
break;
case 6:
result = printf("null");
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; }


decompiled_code:
void __fastcall json_free(void *a1)
{
unsigned int v2; // eax
__int64 i; // rdi

v2 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 2 )
{
ht_free(*((_QWORD *)a1 + 1), json_free_member);
}
else if ( v2 <= 2 )
{
free(*((void **)a1 + 1));
}
else if ( v2 == 3 )
{
for ( i = *((_QWORD *)a1 + 1); i; i = *((_QWORD *)a1 + 1) )
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(i + 16);
json_free();
}
}
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
unsigned int v2; // eax
__int64 i; // rdi

v2 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 2 )
{
ht_free(*((_QWORD *)a1 + 1), json_free_member);
}
else if ( v2 <= 2 )
{
free(*((void **)a1 + 1));
}
else if ( v2 == 3 )
{
for ( i = *((_QWORD *)a1 + 1); i; i = *((_QWORD *)a1 + 1) )
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(i + 16);
func3();
}
}
free(a1);
}

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 }


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

canonical_decompiled_code:
void __fastcall func4(__int64 a1, void *a2)
{
func3(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:
_QWORD *json_read()
{
__int64 v0; // rax
void *v1; // rbx
_QWORD *v2; // rbp

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

canonical_decompiled_code:
_QWORD *func5()
{
__int64 v0; // rax
void *v1; // rbx
_QWORD *v2; // rbp

v0 = my_readfile();
v1 = (void *)v0;
if ( !v0 )
return 0LL;
v2 = json_parse(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 func6(__int64 a1)
{
return func2(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:
double __fastcall json_as_number(__int64 a1)
{
double result; // xmm0_8

result = 0.0;
if ( *(_DWORD *)a1 == 1 )
result = atof(*(const char **)(a1 + 8));
return result;
}

canonical_decompiled_code:
double __fastcall func7(__int64 a1)
{
double result; // xmm0_8

result = 0.0;
if ( *(_DWORD *)a1 == 1 )
result = atof(*(const char **)(a1 + 8));
return result;
}

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 func8(__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 func9(_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 func10(_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 func11(_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 func12(_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 func13(__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:
double __fastcall json_get_number(__int64 a1, __int64 a2)
{
__int64 v2; // rax
double result; // xmm0_8

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

canonical_decompiled_code:
double __fastcall func14(__int64 a1, __int64 a2)
{
__int64 v2; // rax
double result; // xmm0_8

v2 = func13(a1, a2);
result = 0.0;
if ( v2 )
result = func7(v2);
return result;
}

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 result; // rax

result = json_get_member(a1, a2);
if ( result )
result = json_as_string(result);
return result;
}

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

result = func13(a1, a2);
if ( result )
result = func8(result);
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; // edx
__int64 v2; // rax

v1 = 0;
if ( *(_DWORD *)a1 == 3 )
{
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
do
{
++v1;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
else
{
v1 = 0;
}
}
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 func17(__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 v3; // bl
char *v4; // r12
const __int32_t *v5; // rax
const __int32_t **v6; // rax

v3 = *a1;
if ( *a1 )
{
v4 = a1;
v5 = *_ctype_tolower_loc();
do
{
if ( v5[*a2] != v5[v3] )
break;
++v4;
++a2;
v3 = *v4;
}
while ( *v4 );
}
v6 = _ctype_tolower_loc();
return (unsigned int)((*v6)[v3] - (*v6)[*a2]);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char *a2)
{
char v3; // bl
char *v4; // r12
const __int32_t *v5; // rax
const __int32_t **v6; // rax

v3 = *a1;
if ( *a1 )
{
v4 = a1;
v5 = *_ctype_tolower_loc();
do
{
if ( v5[*a2] != v5[v3] )
break;
++v4;
++a2;
v3 = *v4;
}
while ( *v4 );
}
v6 = _ctype_tolower_loc();
return (unsigned int)((*v6)[v3] - (*v6)[*a2]);
}

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

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

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

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
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; // rbx
char *v5; // rax
char *v7; // rax

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

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

v3 = s;
if ( !s )
v3 = *a3;
if ( *v3 )
{
v5 = strpbrk(v3, a2);
if ( v5 )
{
*v5 = 0;
*a3 = v5 + 1;
}
else
{
*a3 = v3;
if ( *v3 )
{
v7 = v3 + 1;
do
*a3 = v7++;
while ( *(v7 - 1) );
}
}
}
else
{
*a3 = v3;
v3 = 0LL;
}
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; // rbx

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

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
*v0 = ht_create(128LL);
v0[1] = ht_create(128LL);
v0[2] = ht_create(128LL);
v0[3] = 0LL;
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)
{
unsigned int v1; // edx

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

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

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

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 *