ensureCapacity

decompiled_code:
void __fastcall ensureCapacity(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
size_t i; // rbx

v2 = a2 + 1;
if ( *(_QWORD *)(a1 + 16) < v2 )
{
if ( v2 <= 0x10 )
{
i = 16LL;
}
else
{
for ( i = 16LL; i < v2; i *= 2LL )
;
}
*(_QWORD *)a1 = realloc(*(void **)a1, i);
*(_QWORD *)(a1 + 16) = i;
}
}

original_code:
void ensureCapacity(Path* path, size_t capacity)
  {
    capacity++;
    if (path->capacity >= capacity) return;
    size_t newCapacity = 16;
    while (newCapacity < capacity) newCapacity *= 2;
    path->chars = (char*)realloc(path->chars, newCapacity);
    path->capacity = newCapacity;
  }

canonical_original_code:
void ensureCapacity(struct Path *path, unsigned long capacity)
  {
    capacity++;
    if (path->capacity >= capacity) return;
    unsigned long newCapacity = 16;
    while (newCapacity < capacity) newCapacity *= 2;
    path->chars = (char *)realloc(path->chars, newCapacity);
    path->capacity = newCapacity;
  }

variable_types: struct Path { char *chars; unsigned long length; unsigned long capacity; } *

variable_types:
capacity
unsigned long

variable_types:
newCapacity
unsigned long


pathType

repo: munificent/wren

decompiled_code:
__int64 __fastcall pathType(char *a1)
{
_BOOL8 v1; // rdx
__int64 result; // rax
char v3; // bp
bool v4; // dl

v1 = absolutePrefixLength(a1);
result = 0LL;
if ( !v1 )
{
result = 2LL;
if ( *a1 == 46 )
{
v3 = a1[1];
v4 = isSeparator(v3);
result = 1LL;
if ( !v4 )
{
result = 2LL;
if ( v3 == 46 )
result = (unsigned int)!isSeparator(a1[2]) + 1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
_BOOL8 v1; // rdx
__int64 result; // rax
char v3; // bp
bool v4; // dl

v1 = func1(a1);
result = 0LL;
if ( !v1 )
{
result = 2LL;
if ( *a1 == 46 )
{
v3 = a1[1];
v4 = func0(v3);
result = 1LL;
if ( !v4 )
{
result = 2LL;
if ( v3 == 46 )
result = (unsigned int)!func0(a1[2]) + 1;
}
}
}
return result;
}

original_code:
PathType pathType(const char* path)
  {
    if (absolutePrefixLength(path) > 0) return PATH_TYPE_ABSOLUTE;
    if ((path[0] == '.' && isSeparator(path[1])) ||
        (path[0] == '.' && path[1] == '.' && isSeparator(path[2])))
    {
      return PATH_TYPE_RELATIVE;
    }
    return PATH_TYPE_SIMPLE;
  }

canonical_original_code:
enum PathType pathType(char *path)
  {
    if (absolutePrefixLength(path) > 0) return PATH_TYPE_ABSOLUTE;
    if ((path[0] == '.' && isSeparator(path[1])) ||
        (path[0] == '.' && path[1] == '.' && isSeparator(path[2])))
    {
      return PATH_TYPE_RELATIVE;
    }
    return PATH_TYPE_SIMPLE;
  }

variable_types:
path
char *

return_type: enum PathType { PATH_TYPE_ABSOLUTE=0, PATH_TYPE_RELATIVE=1, PATH_TYPE_SIMPLE=2 }


pathFree

decompiled_code:
void __fastcall pathFree(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void pathFree(Path* path)
  {
    if (path->chars) free(path->chars);
    free(path);
  }

canonical_original_code:
void pathFree(struct Path *path)
  {
    if (path->chars) free(path->chars);
    free(path);
  }

return_type: void

user_defined_types: struct Path { char *chars; unsigned long length; unsigned long capacity; }


pathRemoveExtension

decompiled_code:
char __fastcall pathRemoveExtension(_QWORD *a1)
{
__int64 v1; // rax
unsigned __int64 v2; // rbx
char *v3; // r13
char v4; // bp

v1 = a1[1];
v2 = v1 - 1;
if ( v1 )
{
do
{
v3 = (char *)(*a1 + v2);
v4 = *v3;
LOBYTE(v1) = isSeparator(*v3);
if ( (_BYTE)v1 )
break;
if ( v4 == 46 )
{
a1[1] = v2;
*v3 = 0;
}
--v2;
}
while ( a1[1] > v2 );
}
return v1;
}

original_code:
void pathRemoveExtension(Path* path)
  {
    for (size_t i = path->length - 1; i < path->length; i--)
    {
      if (isSeparator(path->chars[i])) return;
      if (path->chars[i] == '.')
      {
        path->length = i;
        path->chars[path->length] = '\0';
      }
    }
  }

canonical_original_code:
void pathRemoveExtension(struct Path *path)
  {
    for (unsigned long i = path->length - 1; i < path->length; i--)
    {
      if (isSeparator(path->chars[i])) return;
      if (path->chars[i] == '.')
      {
        path->length = i;
        path->chars[path->length] = '\0';
      }
    }
  }

variable_types:
i
unsigned long


pathNormalize

decompiled_code:
void __fastcall pathNormalize(__int64 a1)
{
char *v1; // r15
char *v2; // rbx
int v3; // er14
int v4; // er12
__int64 v5; // rax
char v6; // bp
__int64 *v7; // rbp
char *v8; // rbx
_BOOL8 v9; // rax
int v10; // er15
bool v11; // r15
int i; // ebx
__int64 v13[4103]; // [rsp+0h] [rbp-8038h]

v1 = *(char **)a1;
v2 = *(char **)a1;
v3 = 0;
v4 = 0;
while ( 1 )
{
v6 = *v2;
if ( !*v2 )
{
if ( v1 == v2 )
goto LABEL_8;
goto LABEL_35;
}
if ( isSeparator(v6) )
break;
LABEL_17:
++v2;
}
if ( v1 == v2 )
goto LABEL_5;
LABEL_35:
if ( v2 - v1 == 1 )
{
if ( *v1 == 46 )
goto LABEL_5;
goto LABEL_3;
}
if ( v2 - v1 != 2 || *v1 != 46 || v1[1] != 46 )
{
LABEL_3:
if ( v4 > 2047 )
{
fprintf(stderr, "Path cannot have more than %d path components.\n", 2048LL);
exit(1);
}
v5 = 2LL * v4;
v13[v5] = (__int64)v1;
v13[v5 + 1] = (__int64)v2;
++v4;
goto LABEL_5;
}
if ( v4 <= 0 )
++v3;
else
--v4;
LABEL_5:
if ( v6 )
{
while ( isSeparator(v6) )
{
v6 = *++v2;
if ( !*v2 )
goto LABEL_8;
}
if ( v6 )
{
v1 = v2;
goto LABEL_17;
}
}
LABEL_8:
v7 = pathNew((const char *)&unk_941);
v8 = *(char **)a1;
v9 = absolutePrefixLength(*(char **)a1);
if ( v9 )
{
appendSlice(v7, v8, (__int64)&v8[v9]);
v11 = 0;
}
else
{
v10 = 0;
if ( v3 > 0 )
{
while ( 1 )
{
pathAppendString(v7, "..");
if ( v3 == ++v10 )
break;
pathAppendChar(v7, 47);
}
v11 = 1;
}
else
{
v11 = 0;
if ( *v8 == 46 )
{
v11 = isSeparator(v8[1]);
if ( v11 )
pathAppendChar(v7, 46);
}
}
}
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
{
if ( v11 )
pathAppendChar(v7, 47);
appendSlice(v7, (const void *)v13[2 * i], v13[2 * i + 1]);
v11 = 1;
}
}
if ( !v7[1] )
pathAppendChar(v7, 46);
free(*(void **)a1);
*(_QWORD *)(a1 + 16) = v7[2];
*(_QWORD *)a1 = *v7;
*(_QWORD *)(a1 + 8) = v7[1];
free(v7);
}

original_code:
void pathNormalize(Path* path)
  {
    Slice components[2048];
    int numComponents = 0;
    char* start = path->chars;
    char* end = path->chars;
    int leadingDoubles = 0;
    for (;;)
    {
      if (*end == '\0' || isSeparator(*end))
      {
        if (start != end)
        {
          size_t length = end - start;
          if (length == 1 && start[0] == '.')
          {
          }
          else if (length == 2 && start[0] == '.' && start[1] == '.')
          {
            if (numComponents > 0)
            {
              numComponents--;
            }
            else
            {
              leadingDoubles++;
            }
          }
          else
          {
            if (numComponents >= 2048)
            {
              fprintf(stderr, "Path cannot have more than %d path components.\n",
                2048);
              exit(1);
            }
            components[numComponents].start = start;
            components[numComponents].end = end;
            numComponents++;
          }
        }
        while (*end != '\0' && isSeparator(*end)) end++;
        start = end;
        if (*end == '\0') break;
      }
      end++;
    }
    _Bool needsSeparator = 0;
    Path* result = pathNew("");
    size_t prefixLength = absolutePrefixLength(path->chars);
    if (prefixLength > 0)
    {
      Slice slice;
      slice.start = path->chars;
      slice.end = path->chars + prefixLength;
      appendSlice(result, slice);
    }
    else if (leadingDoubles > 0)
    {
      for (int i = 0; i < leadingDoubles; i++)
      {
        if (needsSeparator) pathAppendChar(result, '/');
        pathAppendString(result, "..");
        needsSeparator = 1;
      }
    }
    else if (path->chars[0] == '.' && isSeparator(path->chars[1]))
    {
      pathAppendChar(result, '.');
      needsSeparator = 1;
    }
    for (int i = 0; i < numComponents; i++)
    {
      if (needsSeparator) pathAppendChar(result, '/');
      appendSlice(result, components[i]);
      needsSeparator = 1;
    }
    if (result->length == 0) pathAppendChar(result, '.');
    free(path->chars);
    path->capacity = result->capacity;
    path->chars = result->chars;
    path->length = result->length;
    free(result);
  }

canonical_original_code:
void pathNormalize(struct Path *path)
  {
    struct Slice components[2048];
    int numComponents = 0;
    char *start = path->chars;
    char *end = path->chars;
    int leadingDoubles = 0;
    for (;;)
    {
      if (*end == '\0' || isSeparator(*end))
      {
        if (start != end)
        {
          unsigned long length = end - start;
          if (length == 1 && start[0] == '.')
          {
          }
          else if (length == 2 && start[0] == '.' && start[1] == '.')
          {
            if (numComponents > 0)
            {
              numComponents--;
            }
            else
            {
              leadingDoubles++;
            }
          }
          else
          {
            if (numComponents >= 2048)
            {
              fprintf(stderr, "Path cannot have more than %d path components.\n",
                2048);
              exit(1);
            }
            components[numComponents].start = start;
            components[numComponents].end = end;
            numComponents++;
          }
        }
        while (*end != '\0' && isSeparator(*end)) end++;
        start = end;
        if (*end == '\0') break;
      }
      end++;
    }
    _Bool needsSeparator = 0;
    struct Path *result = pathNew("");
    unsigned long prefixLength = absolutePrefixLength(path->chars);
    if (prefixLength > 0)
    {
      struct Slice slice;
      slice.start = path->chars;
      slice.end = path->chars + prefixLength;
      appendSlice(result, slice);
    }
    else if (leadingDoubles > 0)
    {
      for (int i = 0; i < leadingDoubles; i++)
      {
        if (needsSeparator) pathAppendChar(result, '/');
        pathAppendString(result, "..");
        needsSeparator = 1;
      }
    }
    else if (path->chars[0] == '.' && isSeparator(path->chars[1]))
    {
      pathAppendChar(result, '.');
      needsSeparator = 1;
    }
    for (int i = 0; i < numComponents; i++)
    {
      if (needsSeparator) pathAppendChar(result, '/');
      appendSlice(result, components[i]);
      needsSeparator = 1;
    }
    if (result->length == 0) pathAppendChar(result, '.');
    free(path->chars);
    path->capacity = result->capacity;
    path->chars = result->chars;
    path->length = result->length;
    free(result);
  }

variable_types: struct Slice { char *start; char *end; } [2048]

variable_types: numComponents int

variable_types:
start
char *

variable_types:
end
char *

variable_types: leadingDoubles int

variable_types:
length
unsigned long

variable_types:
prefixLength
unsigned long

variable_types: i int


isModuleAnAPITest

decompiled_code:
__int64 __fastcall isModuleAnAPITest(const void *a1)
{
bool v2; // dl
__int64 v3; // rcx
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
const char *v7; // rsi

v2 = memcmp(a1, "test/api", 8uLL) != 0;
LODWORD(v3) = 1;
v4 = 0;
v5 = !v2;
if ( v2 )
{
v6 = "test/benchmark";
v3 = 14LL;
v7 = (const char *)a1;
do
{
if ( !v3 )
break;
v4 = *v7 < (unsigned int)*v6;
v5 = *v7++ == *v6++;
--v3;
}
while ( v5 );
LOBYTE(v3) = (!v4 && !v5) == v4;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func17(const void *a1)
{
bool v2; // dl
__int64 v3; // rcx
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
const char *v7; // rsi

v2 = memcmp(a1, "test/api", 8uLL) != 0;
LODWORD(v3) = 1;
v4 = 0;
v5 = !v2;
if ( v2 )
{
v6 = "test/benchmark";
v3 = 14LL;
v7 = (const char *)a1;
do
{
if ( !v3 )
break;
v4 = *v7 < (unsigned int)*v6;
v5 = *v7++ == *v6++;
--v3;
}
while ( v5 );
LOBYTE(v3) = (!v4 && !v5) == v4;
}
return (unsigned int)v3;
}

original_code:
_Bool isModuleAnAPITest(const char* module)
  {
    if(strncmp(module, "test/api", 8) == 0) return 1;
    if(strncmp(module, "test/benchmark", 14) == 0) return 1;
    return 0;
  }

canonical_original_code:
_Bool isModuleAnAPITest(char *module)
  {
    if(strncmp(module, "test/api", 8) == 0) return 1;
    if(strncmp(module, "test/benchmark", 14) == 0) return 1;
    return 0;
  }

variable_types:
module
char *


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

if ( a1 <= 1 )
{
puts("This is a Wren test runner.\nUsage: wren_test [file]");
result = 64LL;
}
else
{
result = 0LL;
if ( a1 == 2 && !strcmp(*(const char **)(a2 + 8), "--version") )
{
printf("wren_test is running on Wren version %s\n", "0.4.0");
result = 1LL;
}
}
return result;
}

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

if ( a1 <= 1 )
{
puts("This is a Wren test runner.\nUsage: wren_test [file]");
result = 64LL;
}
else
{
result = 0LL;
if ( a1 == 2 && !strcmp(*(const char **)(a2 + 8), "--version") )
{
printf("wren_test is running on Wren version %s\n", "0.4.0");
result = 1LL;
}
}
return result;
}

original_code:
int handle_args(int argc, const char* argv[])
  {
    if (argc < 2)
    {
      printf("This is a Wren test runner.\nUsage: wren_test [file]\n");
      return 64;
    }
    if (argc == 2 && strcmp(argv[1], "--version") == 0)
    {
      printf("wren_test is running on Wren version %s\n", "0.4.0");
      return 1;
    }
    return 0;
  }

canonical_original_code:
int handle_args(int argc, char *argv[])
  {
    if (argc < 2)
    {
      printf("This is a Wren test runner.\nUsage: wren_test [file]\n");
      return 64;
    }
    if (argc == 2 && strcmp(argv[1], "--version") == 0)
    {
      printf("wren_test is running on Wren version %s\n", "0.4.0");
      return 1;
    }
    return 0;
  }

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


wrenDoubleFromBits

decompiled_code:
double __fastcall wrenDoubleFromBits(__int64 a1)
{
return *(double *)&a1;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
return *(double *)&a1;
}

original_code:
static inline double wrenDoubleFromBits(uint64_t bits)
{
  WrenDoubleBits data;
  data.bits64 = bits;
  return data.num;
}

canonical_original_code:
static inline double wrenDoubleFromBits(unsigned long bits)
{
  union WrenDoubleBits data;
  data.bits64 = bits;
  return data.num;
}

variable_types:
bits
unsigned long

variable_types: union WrenDoubleBits { unsigned long bits64; unsigned int bits32[2]; double num; }

return_type: double


wrenIsBool

decompiled_code:
bool __fastcall wrenIsBool(__int64 a1)
{
return (unsigned __int64)(a1 - 0x7FFC000000000002LL) <= 1;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return (unsigned __int64)(a1 - 0x7FFC000000000002LL) <= 1;
}

original_code:
static inline _Bool wrenIsBool(Value value)
{
  return value == ((Value)(uint64_t)(((uint64_t)0x7ffc000000000000) | (3))) || value == ((Value)(uint64_t)(((uint64_t)0x7ffc000000000000) | (2)));
}

canonical_original_code:
static inline _Bool wrenIsBool(unsigned long value)
{
  return value == ((Value)(uint64_t)(((unsigned long)0x7ffc000000000000) | (3))) || value == ((Value)(uint64_t)(((unsigned long)0x7ffc000000000000) | (2)));
}

variable_types:
value
unsigned long


wrenIsObjType

decompiled_code:
_BOOL8 __fastcall wrenIsObjType(__int64 a1, int a2)
{
bool v2; // al

v2 = 0;
if ( (a1 & 0xFFFC000000000000LL) == 0xFFFC000000000000LL )
v2 = *(_DWORD *)(a1 & 0x3FFFFFFFFFFFFLL) == a2;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, int a2)
{
bool v2; // al

v2 = 0;
if ( (a1 & 0xFFFC000000000000LL) == 0xFFFC000000000000LL )
v2 = *(_DWORD *)(a1 & 0x3FFFFFFFFFFFFLL) == a2;
return v2;
}

canonical_original_code:
static inline _Bool wrenIsObjType(unsigned long value, enum ObjType type)
{
  return (((value) & (((unsigned long)0x7ffc000000000000) | ((unsigned long)1 << 63))) == (((unsigned long)0x7ffc000000000000) | ((unsigned long)1 << 63))) && ((struct sObj *)(unsigned long)((value) & ~(((unsigned long)1 << 63) | ((unsigned long)0x7ffc000000000000))))->type == type;
}

variable_types: enum ObjType { OBJ_CLASS=0, OBJ_CLOSURE=1, OBJ_FIBER=2, OBJ_FN=3, OBJ_FOREIGN=4, OBJ_INSTANCE=5, OBJ_LIST=6, OBJ_MAP=7, OBJ_MODULE=8, OBJ_RANGE=9, OBJ_STRING=10, OBJ_UPVALUE=11 }

user_defined_types: struct sObj { enum ObjType type; _Bool isDark; struct sObjClass *classObj; struct sObj *next; }

user_defined_types: struct sObjClass { struct sObj obj; struct sObjClass *superclass; int numFields; struct MethodBuffer methods; struct sObjString *name; unsigned long attributes; }

user_defined_types: struct MethodBuffer { struct Method *data; int count; int capacity; }

user_defined_types: struct Method { enum MethodType type; union { _Bool (*primitive)(struct WrenVM *vm, unsigned long *args); void (*foreign)(struct WrenVM *vm); struct ObjClosure *closure; } as; }

user_defined_types: enum MethodType { METHOD_PRIMITIVE=0, METHOD_FUNCTION_CALL=1, METHOD_FOREIGN=2, METHOD_BLOCK=3, METHOD_NONE=4 }

user_defined_types: struct WrenVM { struct sObjClass *boolClass; struct sObjClass *classClass; struct sObjClass *fiberClass; struct sObjClass *fnClass; struct sObjClass *listClass; struct sObjClass *mapClass; struct sObjClass *nullClass; struct sObjClass *numClass; struct sObjClass *objectClass; struct sObjClass *rangeClass; struct sObjClass *stringClass; struct sObjFiber *fiber; struct ObjMap *modules; struct ObjModule *lastModule; unsigned long bytesAllocated; unsigned long nextGC; struct sObj *first; struct sObj **gray; int grayCount; int grayCapacity; struct sObj *tempRoots[8]; int numTempRoots; struct WrenHandle *handles; unsigned long *apiStack; struct WrenConfiguration config; struct sCompiler *compiler; struct StringBuffer methodNames; }

user_defined_types: struct WrenConfiguration { void *(*reallocateFn)(void *memory, unsigned long newSize, void *userData); char *(*resolveModuleFn)(struct WrenVM *vm, char *importer, char *name); struct WrenLoadModuleResult (*loadModuleFn)(struct WrenVM *vm, char *name); void (*(*bindForeignMethodFn)(struct WrenVM *vm, char *module, char *className, _Bool isStatic, char *signature))(struct WrenVM *vm); struct WrenForeignClassMethods (*bindForeignClassFn)(struct WrenVM *vm, char *module, char *className); void (*writeFn)(struct WrenVM *vm, char *text); void (*errorFn)(struct WrenVM *vm, enum WrenErrorType type, char *module, int line, char *message); unsigned long initialHeapSize; unsigned long minHeapSize; int heapGrowthPercent; void *userData; }

user_defined_types: struct sObjFiber { struct sObj obj; unsigned long *stack; unsigned long *stackTop; int stackCapacity; struct CallFrame *frames; int numFrames; int frameCapacity; struct sObjUpvalue *openUpvalues; struct sObjFiber *caller; unsigned long error; enum FiberState state; }

user_defined_types: struct ObjMap { struct sObj obj; unsigned int capacity; unsigned int count; struct MapEntry *entries; }

user_defined_types: struct WrenHandle { unsigned long value; struct WrenHandle *prev; struct WrenHandle *next; }

user_defined_types: struct sCompiler { struct Parser *parser; struct sCompiler *parent; struct Local locals[256]; int numLocals; struct CompilerUpvalue upvalues[256]; int scopeDepth; int numSlots; struct sLoop *loop; struct ClassInfo *enclosingClass; struct ObjFn *fn; struct ObjMap *constants; _Bool isInitializer; int numAttributes; struct ObjMap *attributes; }

user_defined_types: enum FiberState { FIBER_TRY=0, FIBER_ROOT=1, FIBER_OTHER=2 }

user_defined_types: struct CallFrame { unsigned char *ip; struct ObjClosure *closure; unsigned long *stackStart; }

user_defined_types: struct MapEntry { unsigned long key; unsigned long value; }

user_defined_types: struct WrenLoadModuleResult { char *source; void (*onComplete)(struct WrenVM *vm, char *name, struct WrenLoadModuleResult result); void *userData; }

user_defined_types: struct WrenForeignClassMethods { void (*allocate)(struct WrenVM *vm); void (*finalize)(void *data); }

user_defined_types: enum WrenErrorType { WREN_ERROR_COMPILE=0, WREN_ERROR_RUNTIME=1, WREN_ERROR_STACK_TRACE=2 }

user_defined_types: struct Parser { struct WrenVM *vm; struct ObjModule *module; char *source; char *tokenStart; char *currentChar; int currentLine; struct Token next; struct Token current; struct Token previous; int parens[8]; int numParens; _Bool printErrors; _Bool hasError; }

user_defined_types: struct Local { char *name; int length; int depth; _Bool isUpvalue; }

user_defined_types: struct CompilerUpvalue { _Bool isLocal; int index; }

user_defined_types: struct sLoop { int start; int exitJump; int body; int scopeDepth; struct sLoop *enclosing; }

user_defined_types: struct ClassInfo { struct sObjString *name; struct ObjMap *classAttributes; struct ObjMap *methodAttributes; struct StringBuffer fields; struct IntBuffer methods; struct IntBuffer staticMethods; _Bool isForeign; _Bool inStatic; struct Signature *signature; }

user_defined_types: struct Token { enum TokenType type; char *start; int length; int line; unsigned long value; }

user_defined_types: struct ObjClosure { struct sObj obj; struct ObjFn *fn; struct sObjUpvalue *upvalues[]; }

user_defined_types: enum TokenType { TOKEN_LEFT_PAREN=0, TOKEN_RIGHT_PAREN=1, TOKEN_LEFT_BRACKET=2, TOKEN_RIGHT_BRACKET=3, TOKEN_LEFT_BRACE=4, TOKEN_RIGHT_BRACE=5, TOKEN_COLON=6, TOKEN_DOT=7, TOKEN_DOTDOT=8, TOKEN_DOTDOTDOT=9, TOKEN_COMMA=10, TOKEN_STAR=11, TOKEN_SLASH=12, TOKEN_PERCENT=13, TOKEN_HASH=14, TOKEN_PLUS=15, TOKEN_MINUS=16, TOKEN_LTLT=17, TOKEN_GTGT=18, TOKEN_PIPE=19, TOKEN_PIPEPIPE=20, TOKEN_CARET=21, TOKEN_AMP=22, TOKEN_AMPAMP=23, TOKEN_BANG=24, TOKEN_TILDE=25, TOKEN_QUESTION=26, TOKEN_EQ=27, TOKEN_LT=28, TOKEN_GT=29, TOKEN_LTEQ=30, TOKEN_GTEQ=31, TOKEN_EQEQ=32, TOKEN_BANGEQ=33, TOKEN_BREAK=34, TOKEN_CONTINUE=35, TOKEN_CLASS=36, TOKEN_CONSTRUCT=37, TOKEN_ELSE=38, TOKEN_FALSE=39, TOKEN_FOR=40, TOKEN_FOREIGN=41, TOKEN_IF=42, TOKEN_IMPORT=43, TOKEN_AS=44, TOKEN_IN=45, TOKEN_IS=46, TOKEN_NULL=47, TOKEN_RETURN=48, TOKEN_STATIC=49, TOKEN_SUPER=50, TOKEN_THIS=51, TOKEN_TRUE=52, TOKEN_VAR=53, TOKEN_WHILE=54, TOKEN_FIELD=55, TOKEN_STATIC_FIELD=56, TOKEN_NAME=57, TOKEN_NUMBER=58, TOKEN_STRING=59, TOKEN_INTERPOLATION=60, TOKEN_LINE=61, TOKEN_ERROR=62, TOKEN_EOF=63 }

user_defined_types: struct Signature { char *name; int length; enum SignatureType type; int arity; }

user_defined_types: enum SignatureType { SIG_METHOD=0, SIG_GETTER=1, SIG_SETTER=2, SIG_SUBSCRIPT=3, SIG_SUBSCRIPT_SETTER=4, SIG_INITIALIZER=5 }

user_defined_types: struct ObjFn { struct sObj obj; struct ByteBuffer code; struct ValueBuffer constants; struct ObjModule *module; int maxSlots; int numUpvalues; int arity; struct FnDebug *debug; }

user_defined_types: struct ByteBuffer { unsigned char *data; int count; int capacity; }

user_defined_types: struct ValueBuffer { unsigned long *data; int count; int capacity; }

user_defined_types: struct sObjUpvalue { struct sObj obj; unsigned long *value; unsigned long closed; struct sObjUpvalue *next; }

user_defined_types: struct ObjModule { struct sObj obj; struct ValueBuffer variables; struct StringBuffer variableNames; struct sObjString *name; }

user_defined_types: struct FnDebug { char *name; struct IntBuffer sourceLines; }

user_defined_types: struct StringBuffer { struct sObjString **data; int count; int capacity; }

user_defined_types: struct IntBuffer { int *data; int count; int capacity; }

user_defined_types: struct sObjString { struct sObj obj; unsigned int length; unsigned int hash; char value[]; }


wrenValueToNum

decompiled_code:
// attributes: thunk
double __fastcall wrenValueToNum(__int64 a1)
{
return wrenDoubleFromBits(a1);
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1)
{
return func0(a1);
}

original_code:
static inline double wrenValueToNum(Value value)
{
  return wrenDoubleFromBits(value);
}

canonical_original_code:
static inline double wrenValueToNum(unsigned long value)
{
  return wrenDoubleFromBits(value);
}


wrenMapIsValidKey

decompiled_code:
_BOOL8 __fastcall wrenMapIsValidKey(__int64 a1)
{
bool v1; // dl
bool v2; // al
bool v3; // al
bool v5; // dl

v1 = wrenIsBool(a1);
v2 = 1;
if ( !v1 )
{
v3 = wrenIsObjType(a1, 0);
if ( a1 == 0x7FFC000000000001LL || v3 )
{
v2 = 1;
}
else
{
v2 = 1;
if ( (a1 & 0x7FFC000000000000LL) == 0x7FFC000000000000LL )
{
v5 = wrenIsObjType(a1, 9);
v2 = 1;
if ( !v5 )
v2 = wrenIsObjType(a1, 10);
}
}
}
return v2;
}

original_code:
static inline _Bool wrenMapIsValidKey(Value arg)
{
  return (wrenIsBool(arg))
      || (wrenIsObjType(arg, OBJ_CLASS))
      || ((arg) == ((Value)(uint64_t)(((uint64_t)0x7ffc000000000000) | (1))))
      || (((arg) & ((uint64_t)0x7ffc000000000000)) != ((uint64_t)0x7ffc000000000000))
      || (wrenIsObjType(arg, OBJ_RANGE))
      || (wrenIsObjType(arg, OBJ_STRING));
}

canonical_original_code:
static inline _Bool wrenMapIsValidKey(unsigned long arg)
{
  return (wrenIsBool(arg))
      || (wrenIsObjType(arg, OBJ_CLASS))
      || ((arg) == ((Value)(uint64_t)(((unsigned long)0x7ffc000000000000) | (1))))
      || (((arg) & ((unsigned long)0x7ffc000000000000)) != ((unsigned long)0x7ffc000000000000))
      || (wrenIsObjType(arg, OBJ_RANGE))
      || (wrenIsObjType(arg, OBJ_STRING));
}

variable_types:
arg
unsigned long


advanceState

original_code:
static uint32_t advanceState(Well512* well)
{
  uint32_t a, b, c, d;
  a = well->state[well->index];
  c = well->state[(well->index + 13) & 15];
  b = a ^ c ^ (a << 16) ^ (c << 15);
  c = well->state[(well->index + 9) & 15];
  c ^= (c >> 11);
  a = well->state[well->index] = b ^ c;
  d = a ^ ((a << 5) & 0xda442d24U);
  well->index = (well->index + 15) & 15;
  a = well->state[well->index];
  well->state[well->index] = a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28);
  return well->state[well->index];
}

canonical_original_code:
static unsigned int advanceState(struct Well512 *well)
{
  unsigned int a; unsigned int b; unsigned int c; unsigned int d;
  a = well->state[well->index];
  c = well->state[(well->index + 13) & 15];
  b = a ^ c ^ (a << 16) ^ (c << 15);
  c = well->state[(well->index + 9) & 15];
  c ^= (c >> 11);
  a = well->state[well->index] = b ^ c;
  d = a ^ ((a << 5) & 0xda442d24U);
  well->index = (well->index + 15) & 15;
  a = well->state[well->index];
  well->state[well->index] = a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28);
  return well->state[well->index];
}

variable_types: struct Well512 { unsigned int state[16]; unsigned int index; } *

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

return_type: unsigned int


wrenRandomSource

decompiled_code:
const char *wrenRandomSource()
{
return "foreign class Random {\n"
" construct new() {\n"
" seed_()\n"
" }\n"
"\n"
" construct new(seed) {\n"
" if (seed is Num) {\n"
" seed_(seed)\n"
" } else if (seed is Sequence) {\n"
" if (seed.isEmpty) Fiber.abort(\"Sequence cannot be empty.\")\n"
"\n"
" // TODO: Empty sequence.\n"
" var seeds = []\n"
" for (element in seed) {\n"
" if (!(element is Num)) Fiber.abort(\"Sequence elements must all be numbers.\")\n"
"\n"
" seeds.add(element)\n"
" if (seeds.count == 16) break\n"
" }\n"
"\n"
" // Cycle the values to fill in any missing slots.\n"
" var i = 0\n"
" while (seeds.count < 16) {\n"
" seeds.add(seeds[i])\n"
" i = i + 1\n"
" }\n"
"\n"
" seed_(\n"
" seeds[0], seeds[1], seeds[2], seeds[3],\n"
" seeds[4], seeds[5], seeds[6], seeds[7],\n"
" seeds[8], seeds[9], seeds[10], seeds[11],\n"
" seeds[12], seeds[13], seeds[14], seeds[15])\n"
" } else {\n"
" Fiber.abort(\"Seed must be a number or a sequence of numbers.\")\n"
" }\n"
" }\n"
"\n"
" foreign seed_()\n"
" foreign seed_(seed)\n"
" foreign seed_(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)\n"
"\n"
" foreign float()\n"
" float(end) { float() * end }\n"
" float(start, end) { float() * (end - start) + start }\n"
"\n"
" foreign int()\n"
" int(end) { (float() * end).floor }\n"
" int(start, end) { (float() * (end - start)).floor + start }\n"
"\n"
" sample(list) {\n"
" if (list.count == 0) Fiber.abort(\"Not enough elements to sample.\")\n"
" return list[int(list.count)]\n"
" }\n"
" sample(list, count) {\n"
" if (count > list.count) Fiber.abort(\"Not enough elements to sample.\")\n"
"\n"
" var result = []\n"
"\n"
" // The algorithm described in \"Programming pearls: a sample of brilliance\".\n"
" // Use a hash map for sample sizes less than 1/4 of the population size and\n"
" // an array of booleans for larger samples. This simple heuristic improves\n"
" // performance for large sample sizes as well as reduces memory usage.\n"
" if (count * 4 < list.count) {\n"
" var picked = {}\n"
" for (i in list.count - count...list.count) {\n"
" var index = int(i + 1)\n"
" if (picked.containsKey(index)) index = i\n"
" picked[index] = true\n"
" result.add(list[index])\n"
" }\n"
" } else {\n"
" var picked = List.filled(list.count, false)\n"
" for (i in list.count - count...list.count) {\n"
" var index = int(i + 1)\n"
" if (picked[index]) index = i\n"
" picked[index] = true\n"
" result.add(list[index])\n"
" }\n"
" }\n"
"\n"
" return result\n"
" }\n"
"\n"
" shuffle(list) {\n"
" if (list.isEmpty) return\n"
"\n"
" // Fisher-Yates shuffle.\n"
" for (i in 0...list.count - 1) {\n"
" var from = int(i, list.count)\n"
" var temp = list[from]\n"
" list[from] = list[i]\n"
" list[i] = temp\n"
" }\n"
" }\n"
"}\n";
}

canonical_decompiled_code:
const char *func7()
{
return "foreign class Random {\n"
" construct new() {\n"
" seed_()\n"
" }\n"
"\n"
" construct new(seed) {\n"
" if (seed is Num) {\n"
" seed_(seed)\n"
" } else if (seed is Sequence) {\n"
" if (seed.isEmpty) Fiber.abort(\"Sequence cannot be empty.\")\n"
"\n"
" // TODO: Empty sequence.\n"
" var seeds = []\n"
" for (element in seed) {\n"
" if (!(element is Num)) Fiber.abort(\"Sequence elements must all be numbers.\")\n"
"\n"
" seeds.add(element)\n"
" if (seeds.count == 16) break\n"
" }\n"
"\n"
" // Cycle the values to fill in any missing slots.\n"
" var i = 0\n"
" while (seeds.count < 16) {\n"
" seeds.add(seeds[i])\n"
" i = i + 1\n"
" }\n"
"\n"
" seed_(\n"
" seeds[0], seeds[1], seeds[2], seeds[3],\n"
" seeds[4], seeds[5], seeds[6], seeds[7],\n"
" seeds[8], seeds[9], seeds[10], seeds[11],\n"
" seeds[12], seeds[13], seeds[14], seeds[15])\n"
" } else {\n"
" Fiber.abort(\"Seed must be a number or a sequence of numbers.\")\n"
" }\n"
" }\n"
"\n"
" foreign seed_()\n"
" foreign seed_(seed)\n"
" foreign seed_(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)\n"
"\n"
" foreign float()\n"
" float(end) { float() * end }\n"
" float(start, end) { float() * (end - start) + start }\n"
"\n"
" foreign int()\n"
" int(end) { (float() * end).floor }\n"
" int(start, end) { (float() * (end - start)).floor + start }\n"
"\n"
" sample(list) {\n"
" if (list.count == 0) Fiber.abort(\"Not enough elements to sample.\")\n"
" return list[int(list.count)]\n"
" }\n"
" sample(list, count) {\n"
" if (count > list.count) Fiber.abort(\"Not enough elements to sample.\")\n"
"\n"
" var result = []\n"
"\n"
" // The algorithm described in \"Programming pearls: a sample of brilliance\".\n"
" // Use a hash map for sample sizes less than 1/4 of the population size and\n"
" // an array of booleans for larger samples. This simple heuristic improves\n"
" // performance for large sample sizes as well as reduces memory usage.\n"
" if (count * 4 < list.count) {\n"
" var picked = {}\n"
" for (i in list.count - count...list.count) {\n"
" var index = int(i + 1)\n"
" if (picked.containsKey(index)) index = i\n"
" picked[index] = true\n"
" result.add(list[index])\n"
" }\n"
" } else {\n"
" var picked = List.filled(list.count, false)\n"
" for (i in list.count - count...list.count) {\n"
" var index = int(i + 1)\n"
" if (picked[index]) index = i\n"
" picked[index] = true\n"
" result.add(list[index])\n"
" }\n"
" }\n"
"\n"
" return result\n"
" }\n"
"\n"
" shuffle(list) {\n"
" if (list.isEmpty) return\n"
"\n"
" // Fisher-Yates shuffle.\n"
" for (i in 0...list.count - 1) {\n"
" var from = int(i, list.count)\n"
" var temp = list[from]\n"
" list[from] = list[i]\n"
" list[i] = temp\n"
" }\n"
" }\n"
"}\n";
}

original_code:
const char* wrenRandomSource()
{
  return randomModuleSource;
}

canonical_original_code:
char *wrenRandomSource()
{
  return randomModuleSource;
}

return_type: char *


resourceFinalize

decompiled_code:
void __fastcall resourceFinalize(_DWORD *a1)
{
if ( *a1 != 123 )
exit(1);
++finalized;
}

canonical_decompiled_code:
void __fastcall func6(_DWORD *a1)
{
if ( *a1 != 123 )
exit(1);
++finalized;
}

original_code:
static void resourceFinalize(void* data)
{
  int* value = (int*)data;
  if (*value != 123) exit(1);
  finalized++;
}

canonical_original_code:
static void resourceFinalize(void *data)
{
  int *value = (int*)data;
  if (*value != 123) exit(1);
  finalized++;
}

variable_types:
data
void *

variable_types:
value
int *


wrenObjectToValue

decompiled_code:
unsigned __int64 __fastcall wrenObjectToValue(__int64 a1)
{
return a1 | 0xFFFC000000000000LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
return a1 | 0xFFFC000000000000LL;
}

original_code:
static inline Value wrenObjectToValue(Obj* obj)
{
  return (Value)(((uint64_t)1 << 63) | ((uint64_t)0x7ffc000000000000) | (uint64_t)(uintptr_t)(obj));
}

canonical_original_code:
static inline unsigned long wrenObjectToValue(struct sObj *obj)
{
  return (Value)(((unsigned long)1 << 63) | ((unsigned long)0x7ffc000000000000) | (unsigned long)(unsigned long)(obj));
}

variable_types: struct sObj { enum ObjType { OBJ_CLASS=0, OBJ_CLOSURE=1, OBJ_FIBER=2, OBJ_FN=3, OBJ_FOREIGN=4, OBJ_INSTANCE=5, OBJ_LIST=6, OBJ_MAP=7, OBJ_MODULE=8, OBJ_RANGE=9, OBJ_STRING=10, OBJ_UPVALUE=11 } type; _Bool isDark; struct sObjClass { struct sObj obj; struct sObjClass *superclass; int numFields; struct MethodBuffer { struct Method { enum MethodType { METHOD_PRIMITIVE=0, METHOD_FUNCTION_CALL=1, METHOD_FOREIGN=2, METHOD_BLOCK=3, METHOD_NONE=4 } type; union { _Bool (*primitive)(struct WrenVM { struct sObjClass *boolClass; struct sObjClass *classClass; struct sObjClass *fiberClass; struct sObjClass *fnClass; struct sObjClass *listClass; struct sObjClass *mapClass; struct sObjClass *nullClass; struct sObjClass *numClass; struct sObjClass *objectClass; struct sObjClass *rangeClass; struct sObjClass *stringClass; struct sObjFiber { struct sObj obj; unsigned long *stack; unsigned long *stackTop; int stackCapacity; struct CallFrame { unsigned char *ip; struct ObjClosure { struct sObj obj; struct ObjFn { struct sObj obj; struct ByteBuffer { unsigned char *data; int count; int capacity; } code; struct ValueBuffer { unsigned long *data; int count; int capacity; } constants; struct ObjModule { struct sObj obj; struct ValueBuffer variables; struct StringBuffer { struct sObjString { struct sObj obj; unsigned int length; unsigned int hash; char value[]; } **data; int count; int capacity; } variableNames; struct sObjString *name; } *module; int maxSlots; int numUpvalues; int arity; struct FnDebug { char *name; struct IntBuffer { int *data; int count; int capacity; } sourceLines; } *debug; } *fn; struct sObjUpvalue { struct sObj obj; unsigned long *value; unsigned long closed; struct sObjUpvalue *next; } *upvalues[]; } *closure; unsigned long *stackStart; } *frames; int numFrames; int frameCapacity; struct sObjUpvalue *openUpvalues; struct sObjFiber *caller; unsigned long error; enum FiberState { FIBER_TRY=0, FIBER_ROOT=1, FIBER_OTHER=2 } state; } *fiber; struct ObjMap { struct sObj obj; unsigned int capacity; unsigned int count; struct MapEntry { unsigned long key; unsigned long value; } *entries; } *modules; struct ObjModule *lastModule; unsigned long bytesAllocated; unsigned long nextGC; struct sObj *first; struct sObj **gray; int grayCount; int grayCapacity; struct sObj *tempRoots[8]; int numTempRoots; struct WrenHandle { unsigned long value; struct WrenHandle *prev; struct WrenHandle *next; } *handles; unsigned long *apiStack; struct WrenConfiguration { void *(*reallocateFn)(void *memory, unsigned long newSize, void *userData); char *(*resolveModuleFn)(struct WrenVM *vm, char *importer, char *name); struct WrenLoadModuleResult { char *source; void (*onComplete)(struct WrenVM *vm, char *name, struct WrenLoadModuleResult result); void *userData; } (*loadModuleFn)(struct WrenVM *vm, char *name); void (*(*bindForeignMethodFn)(struct WrenVM *vm, char *module, char *className, _Bool isStatic, char *signature))(struct WrenVM *vm); struct WrenForeignClassMethods { void (*allocate)(struct WrenVM *vm); void (*finalize)(void *data); } (*bindForeignClassFn)(struct WrenVM *vm, char *module, char *className); void (*writeFn)(struct WrenVM *vm, char *text); void (*errorFn)(struct WrenVM *vm, enum WrenErrorType { WREN_ERROR_COMPILE=0, WREN_ERROR_RUNTIME=1, WREN_ERROR_STACK_TRACE=2 } type, char *module, int line, char *message); unsigned long initialHeapSize; unsigned long minHeapSize; int heapGrowthPercent; void *userData; } config; struct sCompiler { struct Parser { struct WrenVM *vm; struct ObjModule *module; char *source; char *tokenStart; char *currentChar; int currentLine; struct Token { enum TokenType { TOKEN_LEFT_PAREN=0, TOKEN_RIGHT_PAREN=1, TOKEN_LEFT_BRACKET=2, TOKEN_RIGHT_BRACKET=3, TOKEN_LEFT_BRACE=4, TOKEN_RIGHT_BRACE=5, TOKEN_COLON=6, TOKEN_DOT=7, TOKEN_DOTDOT=8, TOKEN_DOTDOTDOT=9, TOKEN_COMMA=10, TOKEN_STAR=11, TOKEN_SLASH=12, TOKEN_PERCENT=13, TOKEN_HASH=14, TOKEN_PLUS=15, TOKEN_MINUS=16, TOKEN_LTLT=17, TOKEN_GTGT=18, TOKEN_PIPE=19, TOKEN_PIPEPIPE=20, TOKEN_CARET=21, TOKEN_AMP=22, TOKEN_AMPAMP=23, TOKEN_BANG=24, TOKEN_TILDE=25, TOKEN_QUESTION=26, TOKEN_EQ=27, TOKEN_LT=28, TOKEN_GT=29, TOKEN_LTEQ=30, TOKEN_GTEQ=31, TOKEN_EQEQ=32, TOKEN_BANGEQ=33, TOKEN_BREAK=34, TOKEN_CONTINUE=35, TOKEN_CLASS=36, TOKEN_CONSTRUCT=37, TOKEN_ELSE=38, TOKEN_FALSE=39, TOKEN_FOR=40, TOKEN_FOREIGN=41, TOKEN_IF=42, TOKEN_IMPORT=43, TOKEN_AS=44, TOKEN_IN=45, TOKEN_IS=46, TOKEN_NULL=47, TOKEN_RETURN=48, TOKEN_STATIC=49, TOKEN_SUPER=50, TOKEN_THIS=51, TOKEN_TRUE=52, TOKEN_VAR=53, TOKEN_WHILE=54, TOKEN_FIELD=55, TOKEN_STATIC_FIELD=56, TOKEN_NAME=57, TOKEN_NUMBER=58, TOKEN_STRING=59, TOKEN_INTERPOLATION=60, TOKEN_LINE=61, TOKEN_ERROR=62, TOKEN_EOF=63 } type; char *start; int length; int line; unsigned long value; } next; struct Token current; struct Token previous; int parens[8]; int numParens; _Bool printErrors; _Bool hasError; } *parser; struct sCompiler *parent; struct Local { char *name; int length; int depth; _Bool isUpvalue; } locals[256]; int numLocals; struct CompilerUpvalue { _Bool isLocal; int index; } upvalues[256]; int scopeDepth; int numSlots; struct sLoop { int start; int exitJump; int body; int scopeDepth; struct sLoop *enclosing; } *loop; struct ClassInfo { struct sObjString *name; struct ObjMap *classAttributes; struct ObjMap *methodAttributes; struct StringBuffer fields; struct IntBuffer methods; struct IntBuffer staticMethods; _Bool isForeign; _Bool inStatic; struct Signature { char *name; int length; enum SignatureType { SIG_METHOD=0, SIG_GETTER=1, SIG_SETTER=2, SIG_SUBSCRIPT=3, SIG_SUBSCRIPT_SETTER=4, SIG_INITIALIZER=5 } type; int arity; } *signature; } *enclosingClass; struct ObjFn *fn; struct ObjMap *constants; _Bool isInitializer; int numAttributes; struct ObjMap *attributes; } *compiler; struct StringBuffer methodNames; } *vm, unsigned long *args); void (*foreign)(struct WrenVM *vm); struct ObjClosure *closure; } as; } *data; int count; int capacity; } methods; struct sObjString *name; unsigned long attributes; } *classObj; struct sObj *next; } *

return_type: unsigned long

user_defined_types: struct sObj { enum ObjType type; _Bool isDark; struct sObjClass *classObj; struct sObj *next; }

user_defined_types: struct sObjClass { struct sObj obj; struct sObjClass *superclass; int numFields; struct MethodBuffer methods; struct sObjString *name; unsigned long attributes; }

user_defined_types: struct MethodBuffer { struct Method *data; int count; int capacity; }

user_defined_types: struct Method { enum MethodType type; union { _Bool (*primitive)(struct WrenVM *vm, unsigned long *args); void (*foreign)(struct WrenVM *vm); struct ObjClosure *closure; } as; }

user_defined_types: struct WrenVM { struct sObjClass *boolClass; struct sObjClass *classClass; struct sObjClass *fiberClass; struct sObjClass *fnClass; struct sObjClass *listClass; struct sObjClass *mapClass; struct sObjClass *nullClass; struct sObjClass *numClass; struct sObjClass *objectClass; struct sObjClass *rangeClass; struct sObjClass *stringClass; struct sObjFiber *fiber; struct ObjMap *modules; struct ObjModule *lastModule; unsigned long bytesAllocated; unsigned long nextGC; struct sObj *first; struct sObj **gray; int grayCount; int grayCapacity; struct sObj *tempRoots[8]; int numTempRoots; struct WrenHandle *handles; unsigned long *apiStack; struct WrenConfiguration config; struct sCompiler *compiler; struct StringBuffer methodNames; }

user_defined_types: struct WrenConfiguration { void *(*reallocateFn)(void *memory, unsigned long newSize, void *userData); char *(*resolveModuleFn)(struct WrenVM *vm, char *importer, char *name); struct WrenLoadModuleResult (*loadModuleFn)(struct WrenVM *vm, char *name); void (*(*bindForeignMethodFn)(struct WrenVM *vm, char *module, char *className, _Bool isStatic, char *signature))(struct WrenVM *vm); struct WrenForeignClassMethods (*bindForeignClassFn)(struct WrenVM *vm, char *module, char *className); void (*writeFn)(struct WrenVM *vm, char *text); void (*errorFn)(struct WrenVM *vm, enum WrenErrorType type, char *module, int line, char *message); unsigned long initialHeapSize; unsigned long minHeapSize; int heapGrowthPercent; void *userData; }

user_defined_types: struct sObjFiber { struct sObj obj; unsigned long *stack; unsigned long *stackTop; int stackCapacity; struct CallFrame *frames; int numFrames; int frameCapacity; struct sObjUpvalue *openUpvalues; struct sObjFiber *caller; unsigned long error; enum FiberState state; }

user_defined_types: struct ObjMap { struct sObj obj; unsigned int capacity; unsigned int count; struct MapEntry *entries; }

user_defined_types: struct sCompiler { struct Parser *parser; struct sCompiler *parent; struct Local locals[256]; int numLocals; struct CompilerUpvalue upvalues[256]; int scopeDepth; int numSlots; struct sLoop *loop; struct ClassInfo *enclosingClass; struct ObjFn *fn; struct ObjMap *constants; _Bool isInitializer; int numAttributes; struct ObjMap *attributes; }

user_defined_types: struct CallFrame { unsigned char *ip; struct ObjClosure *closure; unsigned long *stackStart; }

user_defined_types: struct Parser { struct WrenVM *vm; struct ObjModule *module; char *source; char *tokenStart; char *currentChar; int currentLine; struct Token next; struct Token current; struct Token previous; int parens[8]; int numParens; _Bool printErrors; _Bool hasError; }


wrenMetaSource

decompiled_code:
const char *wrenMetaSource()
{
return "class Meta {\n"
" static getModuleVariables(module) {\n"
" if (!(module is String)) Fiber.abort(\"Module name must be a string.\")\n"
" var result = getModuleVariables_(module)\n"
" if (result != null) return result\n"
"\n"
" Fiber.abort(\"Could not find a module named '%(module)'.\")\n"
" }\n"
"\n"
" static eval(source) {\n"
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
"\n"
" var closure = compile_(source, false, false)\n"
" // TODO: Include compile errors.\n"
" if (closure == null) Fiber.abort(\"Could not compile source code.\")\n"
"\n"
" closure.call()\n"
" }\n"
"\n"
" static compileExpression(source) {\n"
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
" return compile_(source, true, true)\n"
" }\n"
"\n"
" static compile(source) {\n"
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
" return compile_(source, false, true)\n"
" }\n"
"\n"
" foreign static compile_(source, isExpression, printErrors)\n"
" foreign static getModuleVariables_(module)\n"
"}\n";
}

canonical_decompiled_code:
const char *func2()
{
return "class Meta {\n"
" static getModuleVariables(module) {\n"
" if (!(module is String)) Fiber.abort(\"Module name must be a string.\")\n"
" var result = getModuleVariables_(module)\n"
" if (result != null) return result\n"
"\n"
" Fiber.abort(\"Could not find a module named '%(module)'.\")\n"
" }\n"
"\n"
" static eval(source) {\n"
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
"\n"
" var closure = compile_(source, false, false)\n"
" // TODO: Include compile errors.\n"
" if (closure == null) Fiber.abort(\"Could not compile source code.\")\n"
"\n"
" closure.call()\n"
" }\n"
"\n"
" static compileExpression(source) {\n"
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
" return compile_(source, true, true)\n"
" }\n"
"\n"
" static compile(source) {\n"
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
" return compile_(source, false, true)\n"
" }\n"
"\n"
" foreign static compile_(source, isExpression, printErrors)\n"
" foreign static getModuleVariables_(module)\n"
"}\n";
}

original_code:
const char* wrenMetaSource()
{
  return metaModuleSource;
}

canonical_original_code:
char *wrenMetaSource()
{
  return metaModuleSource;
}


wrenDoubleFromBits

user_defined_types: union WrenDoubleBits { unsigned long bits64; unsigned int bits32[2]; double num; }


wrenValueToNum

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


compFunc

repo: muquit/mailsend

decompiled_code:
int __fastcall compFunc(const char **a1, const char **a2)
{
return strcasecmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char **a2)
{
return strcasecmp(*a1, *a2);
}

original_code:
static int compFunc(void *a1,void *a2)
{
    Addr
        *addr1=(Addr *) a1,
        *addr2=(Addr *) a2;
    return (strcasecmp(addr1->name,addr2->name));
}

canonical_original_code:
static int compFunc(void *a1, void *a2)
{
    struct _addr *addr1 = (Addr *) a1; struct _addr *addr2 = (Addr *) a2;
    return (strcasecmp(addr1->name,addr2->name));
}


freeData

decompiled_code:
void __fastcall freeData(void ***a1)
{
void **v1; // rax
const char *v2; // rdx
const char *v3; // rdx

++n_0;
v1 = *a1;
if ( *a1 )
{
if ( *v1 )
{
fprintf(stderr, " Freeing: %s\n", (const char *)*v1);
free(**a1);
}
v2 = (const char *)(*a1)[1];
if ( v2 )
{
fprintf(stderr, " Freeing: %s\n", v2);
free((*a1)[1]);
}
v3 = (const char *)(*a1)[2];
if ( v3 )
{
fprintf(stderr, " Freeing: %s\n", v3);
free((*a1)[2]);
}
fprintf(stderr, "Freeing the node %d itself\n\n", (unsigned int)n_0);
free(*a1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(void ***a1)
{
void **v1; // rax
const char *v2; // rdx
const char *v3; // rdx

++n_0;
v1 = *a1;
if ( *a1 )
{
if ( *v1 )
{
fprintf(stderr, " Freeing: %s\n", (const char *)*v1);
free(**a1);
}
v2 = (const char *)(*a1)[1];
if ( v2 )
{
fprintf(stderr, " Freeing: %s\n", v2);
free((*a1)[1]);
}
v3 = (const char *)(*a1)[2];
if ( v3 )
{
fprintf(stderr, " Freeing: %s\n", v3);
free((*a1)[2]);
}
fprintf(stderr, "Freeing the node %d itself\n\n", (unsigned int)n_0);
free(*a1);
*a1 = 0LL;
}
}

original_code:
static void freeData(void **data)
{
    Addr
        **addr=(Addr **) data;
    static int
        n=0;
    n++;
    if (*addr)
    {
        if ((*addr)->name)
        {
            (void) fprintf(stderr," Freeing: %s\n",(*addr)->name);
            (void) free((char *) (*addr)->name);
        }
        if ((*addr)->city)
        {
            (void) fprintf(stderr," Freeing: %s\n",(*addr)->city);
            (void) free ((char *) (*addr)->city);
        }
        if ((*addr)->state)
        {
            (void) fprintf(stderr," Freeing: %s\n",(*addr)->state);
            (void) free ((char *) (*addr)->state);
        }
        (void) fprintf(stderr,"Freeing the node %d itself\n\n",n);
        (void) free((char *) (*addr));
        (*addr)=((void *)0);
    }
}

canonical_original_code:
static void freeData(void **data)
{
    struct _addr **addr = (Addr **) data;
    static int n = 0;
    n++;
    if (*addr)
    {
        if ((*addr)->name)
        {
            (void) fprintf(stderr," Freeing: %s\n",(*addr)->name);
            (void) free((char *) (*addr)->name);
        }
        if ((*addr)->city)
        {
            (void) fprintf(stderr," Freeing: %s\n",(*addr)->city);
            (void) free ((char *) (*addr)->city);
        }
        if ((*addr)->state)
        {
            (void) fprintf(stderr," Freeing: %s\n",(*addr)->state);
            (void) free ((char *) (*addr)->state);
        }
        (void) fprintf(stderr,"Freeing the node %d itself\n\n",n);
        (void) free((char *) (*addr));
        (*addr)=((void *)0);
    }
}

variable_types:
data
void **

variable_types:
addr
struct _addr { char *name; } **

variable_types: n int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rax
const char **v4; // rbx
char *v5; // rbp
char *v6; // r12
char *v7; // rax
const char **v8; // rbx
char *v9; // rbp
char *v10; // r12
char *v11; // rax
const char **v12; // rbx
char *v13; // rbp
char *v14; // r12
char *v15; // rax
const char ***v16; // rbx
int v17; // er12
const char **v18; // rbp
__int64 v19; // [rsp+0h] [rbp-28h] BYREF
__int64 v20[4]; // [rsp+8h] [rbp-20h] BYREF

v20[0] = 0LL;
v19 = 0LL;
fwrite("=========================================================================\n", 1uLL, 0x4AuLL, stderr);
fwrite(" Testing Append a node at the beginning of a list\n", 1uLL, 0x32uLL, stderr);
fwrite("=========================================================================\n", 1uLL, 0x4AuLL, stderr);
v3 = (const char **)malloc(0x18uLL);
if ( v3 )
{
v4 = v3;
fwrite("\n---------------[ appending ]----------\n", 1uLL, 0x28uLL, stderr);
v5 = strdup("Cindy Muquit");
*v4 = v5;
v6 = strdup("Philadelphia");
v4[1] = v6;
v7 = strdup("PA");
v4[2] = v7;
if ( v5 != 0LL && v6 != 0LL && v7 )
{
v19 = allocateNode(v4);
appendNodeSorted(v20, &v19, compFunc);
fprintf(stderr, "Appending Node: %d\n", 1LL);
fprintf(stderr, " %s\n", *v4);
fprintf(stderr, " %s\n", v4[1]);
fprintf(stderr, " %s\n", v4[2]);
v8 = (const char **)malloc(0x18uLL);
if ( v8 )
{
v9 = strdup("Janet Hunter");
*v8 = v9;
v10 = strdup("Santa Clara");
v8[1] = v10;
v11 = strdup("CA");
v8[2] = v11;
if ( v9 != 0LL && v10 != 0LL && v11 )
{
v19 = allocateNode(v8);
appendNodeSorted(v20, &v19, compFunc);
fprintf(stderr, "Appending Node: %d\n", 2LL);
fprintf(stderr, " %s\n", *v8);
fprintf(stderr, " %s\n", v8[1]);
fprintf(stderr, " %s\n", v8[2]);
v12 = (const char **)malloc(0x18uLL);
if ( v12 )
{
v13 = strdup("Babs Jensen");
*v12 = v13;
v14 = strdup("Cupertino");
v12[1] = v14;
v15 = strdup("CA");
v12[2] = v15;
if ( v13 != 0LL && v14 != 0LL && v15 )
{
v19 = allocateNode(v12);
appendNodeSorted(v20, &v19, compFunc);
fprintf(stderr, "Appending Node: %d\n", 3LL);
fprintf(stderr, " %s\n", *v12);
fprintf(stderr, " %s\n", v12[1]);
fprintf(stderr, " %s\n", v12[2]);
fwrite("\n---------------[ printing ]----------\n", 1uLL, 0x27uLL, stderr);
v16 = (const char ***)v20[0];
if ( v20[0] )
{
v17 = 0;
do
{
v18 = *v16;
fprintf(stderr, "Node: %d\n", (unsigned int)++v17);
fprintf(stderr, " %s\n", *v18);
fprintf(stderr, " %s\n", v18[1]);
fprintf(stderr, " %s\n", v18[2]);
v16 = (const char ***)v16[1];
}
while ( v16 );
}
fwrite("\n---------------[ freeing ]----------\n", 1uLL, 0x26uLL, stderr);
destroyNodes(v20, freeData);
exit(0);
}
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(-1);
}
fwrite(" malloc failed\n", 1uLL, 0xFuLL, stderr);
exit(-1);
}
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(-1);
}
fwrite(" malloc failed\n", 1uLL, 0xFuLL, stderr);
exit(-1);
}
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(-1);
}
fwrite(" malloc failed\n", 1uLL, 0xFuLL, stderr);
exit(-1);
}

original_code:
int main (int argc,char **argv)
{
    Sll
        *l,
        *head=((void *)0),
        *new=((void *)0);
    Addr
        *addr;
    int
        n=0;
    (void) fprintf(stderr,
"=========================================================================\n");
    (void) fprintf(stderr," Testing Append a node at the beginning of a list\n");
    (void) fprintf(stderr,
"=========================================================================\n");
    addr=(Addr *) malloc(sizeof(Addr));
    if (addr == ((void *)0))
    {
        (void) fprintf(stderr," malloc failed\n");
        exit(-1);
    }
    (void) fprintf(stderr,"\n---------------[ appending ]----------\n");
    addr->name=strdup("Cindy Muquit");
    addr->city=strdup("Philadelphia");
    addr->state=strdup("PA");
    if ((addr->name == ((void *)0)) ||
        (addr->city == ((void *)0)) ||
        (addr->state == ((void *)0)))
    {
        (void) fprintf(stderr,"malloc failed\n");
        exit(-1);
    }
    new=allocateNode((void *) addr);
    appendNodeSorted(&head,&new,compFunc);
    (void) fprintf(stderr,"Appending Node: %d\n", ++n);
    (void) fprintf(stderr,"  %s\n",addr->name);
    (void) fprintf(stderr,"  %s\n",addr->city);
    (void) fprintf(stderr,"  %s\n",addr->state);
    addr=(Addr *) malloc(sizeof(Addr));
    if (addr == ((void *)0))
    {
        (void) fprintf(stderr," malloc failed\n");
        exit(-1);
    }
    addr->name=strdup("Janet Hunter");
    addr->city=strdup("Santa Clara");
    addr->state=strdup("CA");
    if ((addr->name == ((void *)0)) ||
        (addr->city == ((void *)0)) ||
        (addr->state == ((void *)0)))
    {
        (void) fprintf(stderr,"malloc failed\n");
        exit(-1);
    }
    new=allocateNode((void *) addr);
    appendNodeSorted(&head,&new,compFunc);
    (void) fprintf(stderr,"Appending Node: %d\n", ++n);
    (void) fprintf(stderr,"  %s\n",addr->name);
    (void) fprintf(stderr,"  %s\n",addr->city);
    (void) fprintf(stderr,"  %s\n",addr->state);
    addr=(Addr *) malloc(sizeof(Addr));
    if (addr == ((void *)0))
    {
        (void) fprintf(stderr," malloc failed\n");
        exit(-1);
    }
    addr->name=strdup("Babs Jensen");
    addr->city=strdup("Cupertino");
    addr->state=strdup("CA");
    if ((addr->name == ((void *)0)) ||
        (addr->city == ((void *)0)) ||
        (addr->state == ((void *)0)))
    {
        (void) fprintf(stderr,"malloc failed\n");
        exit(-1);
    }
    new=allocateNode((void *) addr);
    appendNodeSorted(&head,&new,compFunc);
    (void) fprintf(stderr,"Appending Node: %d\n", ++n);
    (void) fprintf(stderr,"  %s\n",addr->name);
    (void) fprintf(stderr,"  %s\n",addr->city);
    (void) fprintf(stderr,"  %s\n",addr->state);
    (void) fprintf(stderr,"\n---------------[ printing ]----------\n");
    n=0;
    for (l=head; l; l=l->next)
    {
        addr=(Addr *) l->data;
        (void) fprintf(stderr,"Node: %d\n",++n);
        (void) fprintf(stderr,"  %s\n",addr->name);
        (void) fprintf(stderr,"  %s\n",addr->city);
        (void) fprintf(stderr,"  %s\n",addr->state);
    }
    (void) fprintf(stderr,"\n---------------[ freeing ]----------\n");
    destroyNodes(&head,freeData);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct _Sll *l; struct _Sll *head = ((void *)0); struct _Sll *new = ((void *)0);
    struct _addr *addr;
    int n = 0;
    (void) fprintf(stderr,
"=========================================================================\n");
    (void) fprintf(stderr," Testing Append a node at the beginning of a list\n");
    (void) fprintf(stderr,
"=========================================================================\n");
    addr=(struct _addr *) malloc(sizeof(Addr));
    if (addr == ((void *)0))
    {
        (void) fprintf(stderr," malloc failed\n");
        exit(-1);
    }
    (void) fprintf(stderr,"\n---------------[ appending ]----------\n");
    addr->name=strdup("Cindy Muquit");
    addr->city=strdup("Philadelphia");
    addr->state=strdup("PA");
    if ((addr->name == ((void *)0)) ||
        (addr->city == ((void *)0)) ||
        (addr->state == ((void *)0)))
    {
        (void) fprintf(stderr,"malloc failed\n");
        exit(-1);
    }
    new=allocateNode((void *) addr);
    appendNodeSorted(&head,&new,compFunc);
    (void) fprintf(stderr,"Appending Node: %d\n", ++n);
    (void) fprintf(stderr,"  %s\n",addr->name);
    (void) fprintf(stderr,"  %s\n",addr->city);
    (void) fprintf(stderr,"  %s\n",addr->state);
    addr=(struct _addr *) malloc(sizeof(Addr));
    if (addr == ((void *)0))
    {
        (void) fprintf(stderr," malloc failed\n");
        exit(-1);
    }
    addr->name=strdup("Janet Hunter");
    addr->city=strdup("Santa Clara");
    addr->state=strdup("CA");
    if ((addr->name == ((void *)0)) ||
        (addr->city == ((void *)0)) ||
        (addr->state == ((void *)0)))
    {
        (void) fprintf(stderr,"malloc failed\n");
        exit(-1);
    }
    new=allocateNode((void *) addr);
    appendNodeSorted(&head,&new,compFunc);
    (void) fprintf(stderr,"Appending Node: %d\n", ++n);
    (void) fprintf(stderr,"  %s\n",addr->name);
    (void) fprintf(stderr,"  %s\n",addr->city);
    (void) fprintf(stderr,"  %s\n",addr->state);
    addr=(struct _addr *) malloc(sizeof(Addr));
    if (addr == ((void *)0))
    {
        (void) fprintf(stderr," malloc failed\n");
        exit(-1);
    }
    addr->name=strdup("Babs Jensen");
    addr->city=strdup("Cupertino");
    addr->state=strdup("CA");
    if ((addr->name == ((void *)0)) ||
        (addr->city == ((void *)0)) ||
        (addr->state == ((void *)0)))
    {
        (void) fprintf(stderr,"malloc failed\n");
        exit(-1);
    }
    new=allocateNode((void *) addr);
    appendNodeSorted(&head,&new,compFunc);
    (void) fprintf(stderr,"Appending Node: %d\n", ++n);
    (void) fprintf(stderr,"  %s\n",addr->name);
    (void) fprintf(stderr,"  %s\n",addr->city);
    (void) fprintf(stderr,"  %s\n",addr->state);
    (void) fprintf(stderr,"\n---------------[ printing ]----------\n");
    n=0;
    for (l=head; l; l=l->next)
    {
        addr=(struct _addr *) l->data;
        (void) fprintf(stderr,"Node: %d\n",++n);
        (void) fprintf(stderr,"  %s\n",addr->name);
        (void) fprintf(stderr,"  %s\n",addr->city);
        (void) fprintf(stderr,"  %s\n",addr->state);
    }
    (void) fprintf(stderr,"\n---------------[ freeing ]----------\n");
    destroyNodes(&head,freeData);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct _Sll { void *data; struct _Sll *next; } *

variable_types:
addr
struct _addr { char *name; } *


repo: murasesyuka/misc-lang-snippet

decompiled_code:
__int64 __fastcall cnd_init(pthread_cond_t *a1)
{
if ( !a1 )
return 2LL;
pthread_cond_init(a1, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(pthread_cond_t *a1)
{
if ( !a1 )
return 2LL;
pthread_cond_init(a1, 0LL);
return 0LL;
}

original_code:
static __inline__ int
cnd_init(cnd_t *cond)
{
    if (!cond) return thrd_error;
    pthread_cond_init(cond, ((void *)0));
    return thrd_success;
}

canonical_original_code:
static __inline__ int cnd_init(union pthread_cond_t *cond)
{
    if (!cond) return thrd_error;
    pthread_cond_init(cond, ((void *)0));
    return thrd_success;
}

variable_types: union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


decompiled_code:
int __fastcall mtx_destroy(pthread_mutex_t *a1)
{
if ( !a1 )
__assert_fail("mtx", "c11/threads_posix.h", 0xA4u, "mtx_destroy");
return pthread_mutex_destroy(a1);
}

canonical_decompiled_code:
int __fastcall func9(pthread_mutex_t *a1)
{
if ( !a1 )
__assert_fail("mtx", "c11/threads_posix.h", 0xA4u, "mtx_destroy");
return pthread_mutex_destroy(a1);
}

original_code:
static __inline__ void
mtx_destroy(mtx_t *mtx)
{
    ((void) sizeof ((mtx) ? 1 : 0), __extension__ ({ if (mtx) ; else __assert_fail ("mtx", "c11/threads_posix.h", 164, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_destroy(mtx);
}

canonical_original_code:
static __inline__ void mtx_destroy(union pthread_mutex_t *mtx)
{
    ((void) sizeof ((mtx) ? 1 : 0), __extension__ ({ if (mtx) ; else __assert_fail ("mtx", "c11/threads_posix.h", 164, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_destroy(mtx);
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall cnd_destroy(pthread_cond_t *a1)
{
if ( !a1 )
__assert_fail("cond", "c11/threads_posix.h", 0x72u, "cnd_destroy");
return pthread_cond_destroy(a1);
}

canonical_decompiled_code:
int __fastcall func10(pthread_cond_t *a1)
{
if ( !a1 )
__assert_fail("cond", "c11/threads_posix.h", 0x72u, "cnd_destroy");
return pthread_cond_destroy(a1);
}

original_code:
static __inline__ void
cnd_destroy(cnd_t *cond)
{
    ((void) sizeof ((cond) ? 1 : 0), __extension__ ({ if (cond) ; else __assert_fail ("cond", "c11/threads_posix.h", 114, __extension__ __PRETTY_FUNCTION__); }));
    pthread_cond_destroy(cond);
}

canonical_original_code:
static __inline__ void cnd_destroy(union pthread_cond_t *cond)
{
    ((void) sizeof ((cond) ? 1 : 0), __extension__ ({ if (cond) ; else __assert_fail ("cond", "c11/threads_posix.h", 114, __extension__ __PRETTY_FUNCTION__); }));
    pthread_cond_destroy(cond);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


decompiled_code:
pthread_t thrd_current()
{
return pthread_self();
}

canonical_decompiled_code:
pthread_t func15()
{
return pthread_self();
}

original_code:
static __inline__ thrd_t
thrd_current(void)
{
    return pthread_self();
}

canonical_original_code:
static __inline__ unsigned long thrd_current()
{
    return pthread_self();
}


decompiled_code:
__int64 __fastcall impl_thrd_routine(void *a1)
{
int (__fastcall *v1)(__int64); // rbx
__int64 v2; // rbp

v1 = *(int (__fastcall **)(__int64))a1;
v2 = *((_QWORD *)a1 + 1);
free(a1);
return v1(v2);
}

canonical_decompiled_code:
__int64 __fastcall func17(void *a1)
{
int (__fastcall *v1)(__int64); // rbx
__int64 v2; // rbp

v1 = *(int (__fastcall **)(__int64))a1;
v2 = *((_QWORD *)a1 + 1);
free(a1);
return v1(v2);
}

original_code:
static __inline__ void *
impl_thrd_routine(void *p)
{
    struct impl_thrd_param pack = *((struct impl_thrd_param *)p);
    free(p);
    return (void*)(intptr_t)pack.func(pack.arg);
}

canonical_original_code:
static __inline__ void *impl_thrd_routine(void *p)
{
    struct impl_thrd_param pack = *((struct impl_thrd_param *)p);
    free(p);
    return (void *)(long)pack.func(pack.arg);
}

variable_types:
p
void *

variable_types: struct impl_thrd_param { int (*func)(void *); void *arg; }

return_type: void *


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

result = mtx_init((pthread_mutex_t *)(a1 + 48), 0);
if ( !(_DWORD)result )
{
result = cnd_init((pthread_cond_t *)(a1 + 88));
if ( !(_DWORD)result )
result = cnd_init((pthread_cond_t *)(a1 + 136));
}
return result;
}

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

result = func7((pthread_mutex_t *)(a1 + 48), 0);
if ( !(_DWORD)result )
{
result = func8((pthread_cond_t *)(a1 + 88));
if ( !(_DWORD)result )
result = func8((pthread_cond_t *)(a1 + 136));
}
return result;
}

original_code:
int stack10_Constructor(Stack10 *s){
 int ret;
 ret = mtx_init(&s->mtx_, mtx_plain);
 if(ret != thrd_success){
  return ret;
 }
 ret = cnd_init(&s->cnd_push_);
 if(ret != thrd_success){
  return ret;
 }
 ret = cnd_init(&s->cnd_pop_);
 if(ret != thrd_success){
  return ret;
 }
 return 0;
}

canonical_original_code:
int stack10_Constructor(struct Stack *s){
 int ret;
 ret = mtx_init(&s->mtx_, mtx_plain);
 if(ret != thrd_success){
  return ret;
 }
 ret = cnd_init(&s->cnd_push_);
 if(ret != thrd_success){
  return ret;
 }
 ret = cnd_init(&s->cnd_pop_);
 if(ret != thrd_success){
  return ret;
 }
 return 0;
}

variable_types: struct Stack { int v_[-1]; int vused_; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mtx_; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cnd_push_; union pthread_cond_t cnd_pop_; } *

variable_types: ret int

user_defined_types: struct Stack { int v_[-1]; int vused_; union pthread_mutex_t mtx_; union pthread_cond_t cnd_push_; union pthread_cond_t cnd_pop_; }


decompiled_code:
int __fastcall stack10_Destructor(__int64 a1)
{
mtx_destroy((pthread_mutex_t *)(a1 + 48));
cnd_destroy((pthread_cond_t *)(a1 + 88));
return cnd_destroy((pthread_cond_t *)(a1 + 136));
}

canonical_decompiled_code:
int __fastcall func20(__int64 a1)
{
func9((pthread_mutex_t *)(a1 + 48));
func10((pthread_cond_t *)(a1 + 88));
return func10((pthread_cond_t *)(a1 + 136));
}

original_code:
void stack10_Destructor(Stack10 *s){
 mtx_destroy(&s->mtx_);
 cnd_destroy(&s->cnd_push_);
 cnd_destroy(&s->cnd_pop_);
}

canonical_original_code:
void stack10_Destructor(struct Stack *s){
 mtx_destroy(&s->mtx_);
 cnd_destroy(&s->cnd_push_);
 cnd_destroy(&s->cnd_pop_);
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall stack10_push(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
int i; // eax

v2 = (pthread_mutex_t *)(a1 + 48);
mtx_lock((pthread_mutex_t *)(a1 + 48));
for ( i = *(_DWORD *)(a1 + 40); i > 9; i = *(_DWORD *)(a1 + 40) )
cnd_wait((pthread_cond_t *)(a1 + 88), v2);
*(_DWORD *)(a1 + 40) = i + 1;
*(_DWORD *)(a1 + 4LL * i) = a2;
cnd_signal((pthread_cond_t *)(a1 + 136));
mtx_unlock(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
int i; // eax

v2 = (pthread_mutex_t *)(a1 + 48);
func11((pthread_mutex_t *)(a1 + 48));
for ( i = *(_DWORD *)(a1 + 40); i > 9; i = *(_DWORD *)(a1 + 40) )
func12((pthread_cond_t *)(a1 + 88), v2);
*(_DWORD *)(a1 + 40) = i + 1;
*(_DWORD *)(a1 + 4LL * i) = a2;
func13((pthread_cond_t *)(a1 + 136));
func14(v2);
return 0LL;
}

original_code:
int stack10_push(Stack10 *s, int x){
 mtx_lock(&s->mtx_);
 while(s->vused_ >= S_SIZE){
  cnd_wait(&s->cnd_push_, &s->mtx_);
 }
 s->v_[s->vused_++] = x;
 cnd_signal(&s->cnd_pop_);
 mtx_unlock(&s->mtx_);
 return 0;
}

canonical_original_code:
int stack10_push(struct Stack *s, int x){
 mtx_lock(&s->mtx_);
 while(s->vused_ >= S_SIZE){
  cnd_wait(&s->cnd_push_, &s->mtx_);
 }
 s->v_[s->vused_++] = x;
 cnd_signal(&s->cnd_pop_);
 mtx_unlock(&s->mtx_);
 return 0;
}

variable_types: x int


func

decompiled_code:
__int64 __fastcall func(__int64 a1)
{
pthread_t v1; // rax

v1 = thrd_current();
printf("thrd_current()vim is %ld\n", v1);
stack10_push(a1, 0);
stack10_push(a1, 1);
stack10_push(a1, 2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
pthread_t v1; // rax

v1 = func15();
printf("thrd_current()vim is %ld\n", v1);
func21(a1, 0);
func21(a1, 1);
func21(a1, 2);
return 0LL;
}

original_code:
int func(void *arg)
{
 int i;
 Stack10 *s =(Stack10*)arg;
 printf("thrd_current()vim is %ld\n", (unsigned long int)thrd_current());
 for(i = 0; i<3; ++i){
  stack10_push(s, i);
 }
 return 0;
}

canonical_original_code:
int func(void *arg)
{
 int i;
 struct Stack *s = (Stack10*)arg;
 printf("thrd_current()vim is %ld\n", (unsigned long)thrd_current());
 for(i = 0; i<3; ++i){
  stack10_push(s, i);
 }
 return 0;
}

variable_types:
arg
void *

variable_types: i int


decompiled_code:
__int64 __fastcall stack10_pop(__int64 a1, _DWORD *a2)
{
pthread_mutex_t *v2; // rbp
int i; // eax
int v4; // eax

v2 = (pthread_mutex_t *)(a1 + 48);
mtx_lock((pthread_mutex_t *)(a1 + 48));
for ( i = *(_DWORD *)(a1 + 40); !i; i = *(_DWORD *)(a1 + 40) )
cnd_wait((pthread_cond_t *)(a1 + 136), v2);
v4 = i - 1;
*(_DWORD *)(a1 + 40) = v4;
*a2 = *(_DWORD *)(a1 + 4LL * v4);
cnd_signal((pthread_cond_t *)(a1 + 88));
mtx_unlock(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, _DWORD *a2)
{
pthread_mutex_t *v2; // rbp
int i; // eax
int v4; // eax

v2 = (pthread_mutex_t *)(a1 + 48);
func11((pthread_mutex_t *)(a1 + 48));
for ( i = *(_DWORD *)(a1 + 40); !i; i = *(_DWORD *)(a1 + 40) )
func12((pthread_cond_t *)(a1 + 136), v2);
v4 = i - 1;
*(_DWORD *)(a1 + 40) = v4;
*a2 = *(_DWORD *)(a1 + 4LL * v4);
func13((pthread_cond_t *)(a1 + 88));
func14(v2);
return 0LL;
}

original_code:
int stack10_pop(Stack10 *s, int *x){
 mtx_lock(&s->mtx_);
 while(s->vused_ == 0){
  cnd_wait(&s->cnd_pop_, &s->mtx_);
 }
 *x = s->v_[--s->vused_];
 cnd_signal(&s->cnd_push_);
 mtx_unlock(&s->mtx_);
 return 0;
}

canonical_original_code:
int stack10_pop(struct Stack *s, int *x){
 mtx_lock(&s->mtx_);
 while(s->vused_ == 0){
  cnd_wait(&s->cnd_pop_, &s->mtx_);
 }
 *x = s->v_[--s->vused_];
 cnd_signal(&s->cnd_push_);
 mtx_unlock(&s->mtx_);
 return 0;
}

variable_types:
x
int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbp
pthread_t *v4; // rbx
unsigned int i; // ebx
_BYTE v7[32]; // [rsp+0h] [rbp-F8h] BYREF
char v8[188]; // [rsp+20h] [rbp-D8h] BYREF
unsigned int v9[7]; // [rsp+DCh] [rbp-1Ch] BYREF

memset(v8, 0, 0xB8uLL);
stack10_Constructor((__int64)v8);
v3 = (pthread_t *)v7;
v4 = (pthread_t *)v7;
do
thrd_create(v4++, (__int64)func, (__int64)v8);
while ( v4 != (pthread_t *)v8 );
for ( i = 0; i != 12; ++i )
{
stack10_pop((__int64)v8, v9);
printf("%d : %d\n", i, v9[0]);
}
do
thrd_join(*v3++, 0LL);
while ( v3 != (pthread_t *)v8 );
stack10_Destructor((__int64)v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbp
pthread_t *v4; // rbx
unsigned int i; // ebx
_BYTE v7[32]; // [rsp+0h] [rbp-F8h] BYREF
char v8[188]; // [rsp+20h] [rbp-D8h] BYREF
unsigned int v9[7]; // [rsp+DCh] [rbp-1Ch] BYREF

memset(v8, 0, 0xB8uLL);
func19((__int64)v8);
v3 = (pthread_t *)v7;
v4 = (pthread_t *)v7;
do
func16(v4++, (__int64)func, (__int64)v8);
while ( v4 != (pthread_t *)v8 );
for ( i = 0; i != 12; ++i )
{
func23((__int64)v8, v9);
printf("%d : %d\n", i, v9[0]);
}
do
func18(*v3++, 0LL);
while ( v3 != (pthread_t *)v8 );
func20((__int64)v8);
return 0;
}

original_code:
int main()
{
 int i, n;
 Stack10 s = {{0},0};
 enum {SIZE = 4};
 thrd_t thr_s[SIZE];
 stack10_Constructor(&s);
 for(i=0; i<SIZE; i++) {
  thrd_create(&thr_s[i], func, (void*)(Stack10*)&s);
 }
 for(i=0; i<(SIZE*3); i++){
  stack10_pop(&s, &n);
  printf("%d : %d\n",i,n);
 }
 for(i=0; i<SIZE; i++) {
  thrd_join(thr_s[i], 0);
 }
 stack10_Destructor(&s);
 return 0;
}

canonical_original_code:
int main()
{
 int i; int n;
 struct Stack s = {{0},0};
 enum {SIZE = 4};
 unsigned long thr_s[-1];
 stack10_Constructor(&s);
 for(i=0; i<SIZE; i++) {
  thrd_create(&thr_s[i], func, (void *)(struct Stack *)&s);
 }
 for(i=0; i<(SIZE*3); i++){
  stack10_pop(&s, &n);
  printf("%d : %d\n",i,n);
 }
 for(i=0; i<SIZE; i++) {
  thrd_join(thr_s[i], 0);
 }
 stack10_Destructor(&s);
 return 0;
}

variable_types: struct Stack { int v_[-1]; int vused_; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mtx_; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cnd_push_; union pthread_cond_t cnd_pop_; }


run

decompiled_code:
void __fastcall __noreturn run(void *a1)
{
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
pthread_exit(0LL);
}

original_code:
void* run() {
   pthread_exit(0);
}

canonical_original_code:
void *run() {
   pthread_exit(0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
unsigned int v4; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

for ( i = 0LL; ; ++i )
{
v4 = pthread_create(newthread, 0LL, (void *(*)(void *))run, 0LL);
if ( v4 )
break;
}
printf("ERROR, rc is %d, so far %ld threads created\n", v4, i);
perror("Fail:");
return -1;
}

original_code:
int main () {
   pthread_t thread;
   int rc;
   long count = 0;
   while(1) {
    rc = pthread_create(&thread, 0, run, 0);
      if ( rc ) {
         printf("ERROR, rc is %d, so far %ld threads created\n", rc, count);
         perror("Fail:");
         return -1;
      }
      count++;
   }
   return 0;
}

canonical_original_code:
int main() {
   unsigned long thread;
   int rc;
   long count = 0;
   while(1) {
    rc = pthread_create(&thread, 0, run, 0);
      if ( rc ) {
         printf("ERROR, rc is %d, so far %ld threads created\n", rc, count);
         perror("Fail:");
         return -1;
      }
      count++;
   }
   return 0;
}

variable_types:
thread
unsigned long

variable_types: rc int

variable_types: count long


decompiled_code:
int __fastcall print_bytes(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int result; // eax

for ( i = a1; a2 != i; result = putc(*(char *)(i - 1), stdout) )
++i;
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int result; // eax

for ( i = a1; a2 != i; result = putc(*(char *)(i - 1), stdout) )
++i;
return result;
}

original_code:
void print_bytes(char *start, char *end) {
 while (start != end) {
  putc(*start++, stdout);
 }
}

variable_types:
start
char *

variable_types:
end
char *


decompiled_code:
int __fastcall print_token(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned int a7, __int64 a8, __int64 a9)
{
size_t v9; // rax

switch ( a7 )
{
case 1u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s<", indent);
print_bytes(a8, a9);
putc(62, stdout);
v9 = strlen(indent);
*(_WORD *)&indent[v9] = 8224;
indent[v9 + 2] = 0;
break;
case 2u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s</", indent);
print_bytes(a8, a9);
putc(62, stdout);
v9 = strlen(indent);
*(_WORD *)&indent[v9] = 8224;
indent[v9 + 2] = 0;
break;
case 4u:
printf("\n%s", indent);
LODWORD(v9) = print_bytes(a8, a9);
break;
case 5u:
putc(61, stdout);
LODWORD(v9) = print_bytes(a8, a9);
break;
case 6u:
printf("\n%s<!-- ", indent);
print_bytes(a8, a9);
LODWORD(v9) = printf(" -->");
break;
default:
LODWORD(v9) = printf("\nhere %d, %d\n", a7, a9 - a8);
break;
}
return v9;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned int a7, __int64 a8, __int64 a9)
{
size_t v9; // rax

switch ( a7 )
{
case 1u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s<", indent);
func0(a8, a9);
putc(62, stdout);
v9 = strlen(indent);
*(_WORD *)&indent[v9] = 8224;
indent[v9 + 2] = 0;
break;
case 2u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s</", indent);
func0(a8, a9);
putc(62, stdout);
v9 = strlen(indent);
*(_WORD *)&indent[v9] = 8224;
indent[v9 + 2] = 0;
break;
case 4u:
printf("\n%s", indent);
LODWORD(v9) = func0(a8, a9);
break;
case 5u:
putc(61, stdout);
LODWORD(v9) = func0(a8, a9);
break;
case 6u:
printf("\n%s<!-- ", indent);
func0(a8, a9);
LODWORD(v9) = printf(" -->");
break;
default:
LODWORD(v9) = printf("\nhere %d, %d\n", a7, a9 - a8);
break;
}
return v9;
}

original_code:
void print_token(html5token token) {
 switch (token.type) {
 case 1:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s<", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 2:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s</", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 4:
  printf("\n%s", indent);
  print_bytes(token.start, token.end);
  break;
 case 5:
  putc('=', stdout);
  print_bytes(token.start, token.end);
  break;
 case 6:
  printf("\n%s<!-- ", indent);
  print_bytes(token.start, token.end);
  printf(" -->");
  break;
 default:
  printf("\nhere %d, %d\n", token.type, token.end - token.start);
  break;
 }
}

canonical_original_code:
void print_token(struct html5token token) {
 switch (token.type) {
 case 1:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s<", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 2:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s</", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 4:
  printf("\n%s", indent);
  print_bytes(token.start, token.end);
  break;
 case 5:
  putc('=', stdout);
  print_bytes(token.start, token.end);
  break;
 case 6:
  printf("\n%s<!-- ", indent);
  print_bytes(token.start, token.end);
  printf(" -->");
  break;
 default:
  printf("\nhere %d, %d\n", token.type, token.end - token.start);
  break;
 }
}

variable_types: struct html5token { int type; int complete; char *start; char *end; }


original_code:
int main(int argc, char** argv) {
 static const int BUFSIZE = 1024;
 char buffer[BUFSIZE];
 char *start;
 char *end;
 size_t count;
 rlstate s;
 html5token token;
 html5rl_init(&s);
 int done = 0;
 while (!done) {
  count = fread(buffer, sizeof(char), BUFSIZE, stdin);
  if (count <= 0) {
   html5rl_exec(&s, ((void *)0), ((void *)0));
   done = 1;
  } else {
   start = buffer;
   end = buffer + count;
   do
   {
    token = html5rl_exec(&s, start, end);
    start = s.p;
    print_token(token);
   }
   while (token.end != end);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 static int BUFSIZE = 1024;
 char buffer[-1];
 char *start;
 char *end;
 unsigned long count;
 struct rlstate s;
 struct html5token token;
 html5rl_init(&s);
 int done = 0;
 while (!done) {
  count = fread(buffer, sizeof(char), BUFSIZE, stdin);
  if (count <= 0) {
   html5rl_exec(&s, ((void *)0), ((void *)0));
   done = 1;
  } else {
   start = buffer;
   end = buffer + count;
   do
   {
    token = html5rl_exec(&s, start, end);
    start = s.p;
    print_token(token);
   }
   while (token.end != end);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: BUFSIZE int

variable_types:
buffer
char [-1]

variable_types:
count
unsigned long

variable_types: struct rlstate { int cs; int act; char *p; char *pe; char *eof; char *ts; char *te; }

variable_types: done int

user_defined_types: struct html5token { int type; int complete; char *start; char *end; }


repo: mustafakaraca/mkap

decompiled_code:
void __fastcall signal_handler(int a1)
{
if ( a1 == 2 )
{
signal_interrupt = 1;
signal(2, signal_handler);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
{
signal_interrupt = 1;
signal(2, signal_handler);
}
}

original_code:
static void signal_handler(int s)
{
 switch(s){
 case 2:
  signal_interrupt = 1;
  signal(2, signal_handler);
  break;
 default:
  break;
 }
 return;
}

variable_types: s int


decompiled_code:
__int64 __fastcall get_arptype(char *src, int fd)
{
__int64 result; // rax
char v3; // [rsp-8h] [rbp-38h] BYREF
__int64 v4; // [rsp+0h] [rbp-30h]
__int64 v5; // [rsp+8h] [rbp-28h]
__int64 v6; // [rsp+10h] [rbp-20h]
__int64 v7; // [rsp+18h] [rbp-18h]

result = 1LL;
if ( src )
{
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
strncpy(&v3, src, 0xFuLL);
if ( ioctl(fd, 0x8927uLL, &v3) < 0 )
{
perror("get_arptype: ioctl (SIOCGIFHWADDR):");
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned __int16)v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, int fd)
{
__int64 result; // rax
char v3; // [rsp-8h] [rbp-38h] BYREF
__int64 v4; // [rsp+0h] [rbp-30h]
__int64 v5; // [rsp+8h] [rbp-28h]
__int64 v6; // [rsp+10h] [rbp-20h]
__int64 v7; // [rsp+18h] [rbp-18h]

result = 1LL;
if ( src )
{
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
strncpy(&v3, src, 0xFuLL);
if ( ioctl(fd, 0x8927uLL, &v3) < 0 )
{
perror("get_arptype: ioctl (SIOCGIFHWADDR):");
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned __int16)v5;
}
}
return result;
}

original_code:
static int get_arptype(char *ifname, int sockfd)
{
 struct ifreq ifr;
 if (!ifname)
  return 1;
 memset(&ifr, 0, sizeof(ifr));
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, 16 - 1);
 if (ioctl(sockfd, 0x8927, &ifr) < 0){
  perror("get_arptype: ioctl (SIOCGIFHWADDR):");
  return -1;
 }
 return ifr.ifr_ifru.ifru_hwaddr.sa_family;
}

variable_types:
ifname
char *

variable_types: sockfd int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
__int64 __fastcall create_capture_socket(char *src)
{
unsigned __int16 v1; // r12
int v2; // eax
unsigned int v3; // ebx
__int64 v4; // rcx
char *v5; // rdi
int v6; // eax
struct sockaddr v8[2]; // [rsp+0h] [rbp-68h] BYREF
char dest[8]; // [rsp+20h] [rbp-48h] BYREF
__int64 v10; // [rsp+28h] [rbp-40h]
__int64 v11; // [rsp+30h] [rbp-38h]
__int64 v12; // [rsp+38h] [rbp-30h]
__int64 v13; // [rsp+40h] [rbp-28h]

v1 = _bswap_16(3);
v2 = socket(17, 3, v1);
if ( v2 < 0 )
{
perror("create_capture_socket: socket : ");
v3 = -1;
}
else
{
v3 = v2;
if ( src )
{
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
strncpy(dest, src, 0xFuLL);
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("create_capture_socket: ioctl(SIOCGIFINDEX) :");
goto LABEL_13;
}
v4 = 3LL;
v5 = &v8[0].sa_data[6];
while ( v4 )
{
*(_DWORD *)v5 = 0;
v5 += 4;
--v4;
}
v8[0].sa_family = 17;
*(_DWORD *)&v8[0].sa_data[2] = v11;
*(_WORD *)v8[0].sa_data = v1;
if ( bind(v3, v8, 0x14u) < 0 )
{
perror("create_capture_socket: bind()");
goto LABEL_13;
}
v6 = fcntl(v3, 3);
if ( v6 < 0 )
{
perror("create_capture_socket: fcntl(F_GETFL):");
LABEL_13:
while ( close(v3) <= 0 )
{
if ( *_errno_location() != 4 )
return (unsigned int)-1;
}
v3 = -1;
}
else
{
BYTE1(v6) |= 8u;
if ( fcntl(v3, 4, (unsigned int)v6) < 0 )
perror("create_capture_socket: fcntl(F_SETFL)");
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
unsigned __int16 v1; // r12
int v2; // eax
unsigned int v3; // ebx
__int64 v4; // rcx
char *v5; // rdi
int v6; // eax
struct sockaddr v8[2]; // [rsp+0h] [rbp-68h] BYREF
char dest[8]; // [rsp+20h] [rbp-48h] BYREF
__int64 v10; // [rsp+28h] [rbp-40h]
__int64 v11; // [rsp+30h] [rbp-38h]
__int64 v12; // [rsp+38h] [rbp-30h]
__int64 v13; // [rsp+40h] [rbp-28h]

v1 = func2(3);
v2 = socket(17, 3, v1);
if ( v2 < 0 )
{
perror("create_capture_socket: socket : ");
v3 = -1;
}
else
{
v3 = v2;
if ( src )
{
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
strncpy(dest, src, 0xFuLL);
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("create_capture_socket: ioctl(SIOCGIFINDEX) :");
goto LABEL_13;
}
v4 = 3LL;
v5 = &v8[0].sa_data[6];
while ( v4 )
{
*(_DWORD *)v5 = 0;
v5 += 4;
--v4;
}
v8[0].sa_family = 17;
*(_DWORD *)&v8[0].sa_data[2] = v11;
*(_WORD *)v8[0].sa_data = v1;
if ( bind(v3, v8, 0x14u) < 0 )
{
perror("create_capture_socket: bind()");
goto LABEL_13;
}
v6 = fcntl(v3, 3);
if ( v6 < 0 )
{
perror("create_capture_socket: fcntl(F_GETFL):");
LABEL_13:
while ( close(v3) <= 0 )
{
if ( *_errno_location() != 4 )
return (unsigned int)-1;
}
v3 = -1;
}
else
{
BYTE1(v6) |= 8u;
if ( fcntl(v3, 4, (unsigned int)v6) < 0 )
perror("create_capture_socket: fcntl(F_SETFL)");
}
}
}
return v3;
}

original_code:
static int create_capture_socket(char *ifname)
{
 int sock_raw;
 struct ifreq ifr;
 struct sockaddr_ll sll;
 struct packet_mreq mrq;
 int fdflags;
 sock_raw = socket(17, SOCK_RAW, htons(0x0003));
 if (sock_raw < 0){
  perror("create_capture_socket: socket : ");
  return -1;
 }
 if (!ifname)
  return sock_raw;
 memset(&ifr, 0, sizeof(ifr));
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, 16 - 1);
 if (ioctl(sock_raw, 0x8933, &ifr) < 0){
  perror("create_capture_socket: ioctl(SIOCGIFINDEX) :");
  goto err1;
 }
 memset(&sll, 0, sizeof(sll));
 sll.sll_family = 17;
 sll.sll_ifindex = ifr.ifr_ifru.ifru_ivalue;
 sll.sll_protocol = htons(0x0003);
 if (bind(sock_raw, (struct sockaddr *)&sll, sizeof(sll)) < 0){
  perror("create_capture_socket: bind()");
  goto err1;
 }
 fdflags = fcntl(sock_raw, 3);
 if (fdflags < 0){
  perror("create_capture_socket: fcntl(F_GETFL):");
  goto err1;
 }
 if (fcntl(sock_raw, 4, fdflags | 04000) < 0){
  perror("create_capture_socket: fcntl(F_SETFL)");
 }
 return sock_raw;
err1:
 while((close(sock_raw) < 1) && ((*__errno_location ()) == 4));
 return -1;
}

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

variable_types: struct packet_mreq { int mr_ifindex; unsigned short mr_type; unsigned short mr_alen; unsigned char mr_address[8]; }

variable_types: fdflags int

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


decompiled_code:
_BOOL8 __fastcall check_mkap_conn(__int64 a1, signed int a2, int a3)
{
int v3; // er12
_BYTE *v4; // rcx
_BOOL8 result; // rax
int v6; // edx
_WORD *v7; // rbx
__int16 v8; // dx
__int16 v9; // r14
__int16 v10; // dx

if ( a3 == 1 )
{
result = 0LL;
if ( (unsigned __int64)a2 <= 0x21 )
return result;
v9 = *(_WORD *)(a1 + 12);
v3 = 14;
if ( _bswap_16(33024) == v9 )
{
result = 0LL;
if ( (unsigned __int64)a2 <= 0x25 )
return result;
v9 = *(_WORD *)(a1 + 16);
v3 = 18;
}
v10 = _bswap_16(2048);
result = 0LL;
if ( v10 != v9 )
return result;
}
else
{
v3 = 0;
if ( a3 == 12 )
{
result = 0LL;
if ( (unsigned int)a2 <= 0x13 )
return result;
}
}
v4 = (_BYTE *)(a1 + v3);
result = 0LL;
if ( v4[9] == 6 )
{
v6 = 4 * (*v4 & 0xF);
if ( a2 >= (unsigned __int64)(v6 + v3 + 20) )
{
v7 = (_WORD *)(v3 + (__int64)v6 + a1);
v8 = _bswap_16(54321);
result = 1LL;
if ( v7[1] != v8 )
result = *v7 == (unsigned __int16)v8;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, signed int a2, int a3)
{
int v3; // er12
_BYTE *v4; // rcx
_BOOL8 result; // rax
int v6; // edx
_WORD *v7; // rbx
__int16 v8; // dx
__int16 v9; // r14
__int16 v10; // dx

if ( a3 == 1 )
{
result = 0LL;
if ( (unsigned __int64)a2 <= 0x21 )
return result;
v9 = *(_WORD *)(a1 + 12);
v3 = 14;
if ( func2(33024) == v9 )
{
result = 0LL;
if ( (unsigned __int64)a2 <= 0x25 )
return result;
v9 = *(_WORD *)(a1 + 16);
v3 = 18;
}
v10 = func2(2048);
result = 0LL;
if ( v10 != v9 )
return result;
}
else
{
v3 = 0;
if ( a3 == 12 )
{
result = 0LL;
if ( (unsigned int)a2 <= 0x13 )
return result;
}
}
v4 = (_BYTE *)(a1 + v3);
result = 0LL;
if ( v4[9] == 6 )
{
v6 = 4 * (*v4 & 0xF);
if ( a2 >= (unsigned __int64)(v6 + v3 + 20) )
{
v7 = (_WORD *)(v3 + (__int64)v6 + a1);
v8 = func2(54321);
result = 1LL;
if ( v7[1] != v8 )
result = *v7 == (unsigned __int16)v8;
}
}
return result;
}

original_code:
static int check_mkap_conn(unsigned char *buffer, int len, unsigned int linktype)
{
 struct ether_header *ethh;
 struct iphdr *iph;
 struct tcphdr *tcph;
 int ipoffset = 0;
 unsigned short ether_type;
 if (linktype == 1) {
  ipoffset += sizeof(*ethh);
  if (len < (ipoffset + sizeof(*iph)))
   return 0;
  ethh = (struct ether_header *)buffer;
  ether_type = ethh->ether_type;
  if (ether_type == htons(0x8100)) {
   ipoffset += 4;
   if (len < (ipoffset + sizeof(*iph)))
    return 0;
   ether_type = *(unsigned short *)(buffer + sizeof(*ethh) + 2);
  }
  if (ether_type != htons(0x0800))
   return 0;
 } else if (linktype == 12) {
  if (len < sizeof(*iph))
   return 0;
 }
 iph = (struct iphdr *)(buffer + ipoffset);
 if (iph->protocol != IPPROTO_TCP)
  return 0;
 if (len < (ipoffset + iph->ihl * 4 + sizeof(*tcph)))
  return 0;
 tcph = (struct tcphdr *)(buffer + ipoffset + iph->ihl * 4);
 if (tcph->dest != htons(54321) && tcph->source != htons(54321))
  return 0;
 return 1;
}

variable_types:
buffer
unsigned char *

variable_types: len int

variable_types:
linktype
unsigned int

variable_types: struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

variable_types: ipoffset int


decompiled_code:
__int64 get_tcp_sock()
{
int v0; // eax
int v1; // ebx
unsigned int v2; // ebp
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v0 = socket(2, 1, 6);
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
optval[0] = 1;
setsockopt(v0, 1, 2, optval, 4u);
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_WORD *)v4.sa_data = _bswap_16(54321);
if ( bind(v1, &v4, 0x10u) || listen(v1, 3) )
{
close(v1);
v2 = -1;
}
else
{
v2 = accept(v1, 0LL, 0LL);
close(v1);
}
return v2;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
int v1; // ebx
unsigned int v2; // ebp
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v0 = socket(2, 1, 6);
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
optval[0] = 1;
setsockopt(v0, 1, 2, optval, 4u);
*(_QWORD *)&v4.sa_family = 2LL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
*(_WORD *)v4.sa_data = func2(54321);
if ( bind(v1, &v4, 0x10u) || listen(v1, 3) )
{
close(v1);
v2 = -1;
}
else
{
v2 = accept(v1, 0LL, 0LL);
close(v1);
}
return v2;
}

original_code:
static int get_tcp_sock()
{
 int serversock, clientsock, yes;
 struct sockaddr_in addr;
 serversock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (serversock < 0)
  return -1;
 yes = 1;
 setsockopt(serversock, 1, 2, &yes, sizeof(yes));
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(54321);
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if (bind(serversock, (struct sockaddr *)&addr, sizeof(addr)))
  goto err;
 if (listen(serversock, 3))
  goto err;
 clientsock = accept(serversock, ((void *)0), ((void *)0));
 close(serversock);
 return clientsock;
err:
 close(serversock);
 return -1;
}

canonical_original_code:
static int get_tcp_sock()
{
 int serversock; int clientsock; int yes;
 struct sockaddr_in addr;
 serversock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (serversock < 0)
  return -1;
 yes = 1;
 setsockopt(serversock, 1, 2, &yes, sizeof(yes));
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(54321);
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if (bind(serversock, (struct sockaddr *)&addr, sizeof(addr)))
  goto err;
 if (listen(serversock, 3))
  goto err;
 clientsock = accept(serversock, ((void *)0), ((void *)0));
 close(serversock);
 return clientsock;
err:
 close(serversock);
 return -1;
}

variable_types: serversock int

variable_types: clientsock int

variable_types: yes int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }