wrenStringEqualsCString

decompiled_code:
bool __fastcall wrenStringEqualsCString(__int64 a1, const void *a2, __int64 a3)
{
size_t v4; // rdx
bool result; // al

v4 = *(unsigned int *)(a1 + 24);
if ( v4 == a3 )
result = memcmp((const void *)(a1 + 32), a2, v4) == 0;
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, const void *a2, __int64 a3)
{
size_t v4; // rdx
bool result; // al

v4 = *(unsigned int *)(a1 + 24);
if ( v4 == a3 )
result = memcmp((const void *)(a1 + 32), a2, v4) == 0;
else
result = 0;
return result;
}

original_code:
static inline _Bool wrenStringEqualsCString(const ObjString* a,
                                           const char* b, size_t length)
{
  return a->length == length && memcmp(a->value, b, length) == 0;
}

canonical_original_code:
static inline _Bool wrenStringEqualsCString(struct sObjString *a, char *b, unsigned long length)
{
  return a->length == length && memcmp(a->value, b, length) == 0;
}

variable_types: struct sObjString { 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 **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; } obj; unsigned int length; unsigned int hash; char value[]; } *

variable_types:
b
char *

variable_types:
length
unsigned long

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

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

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: struct Signature { char *name; int length; enum SignatureType type; int arity; }

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 ObjModule { struct sObj obj; struct ValueBuffer variables; struct StringBuffer variableNames; struct sObjString *name; }

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


wrenByteBufferInit

repo: munificent/wren

decompiled_code:
void __fastcall wrenByteBufferInit(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code: void wrenByteBufferInit(ByteBuffer* buffer) { buffer->data = ((void *)0); buffer->capacity = 0; buffer->count = 0; }

canonical_original_code: void wrenByteBufferInit(struct ByteBuffer *buffer) { buffer->data = ((void *)0); buffer->capacity = 0; buffer->count = 0; }

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

return_type: void


wrenIntBufferInit

decompiled_code:
void __fastcall wrenIntBufferInit(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code: void wrenIntBufferInit(IntBuffer* buffer) { buffer->data = ((void *)0); buffer->capacity = 0; buffer->count = 0; }

canonical_original_code: void wrenIntBufferInit(struct IntBuffer *buffer) { buffer->data = ((void *)0); buffer->capacity = 0; buffer->count = 0; }

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


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

result = 1LL;
if ( a1 > 127 )
{
result = 2LL;
if ( a1 > 2047 )
{
result = 3LL;
if ( a1 > 0xFFFF )
result = 4 * (unsigned int)(a1 < 1114112);
}
}
return result;
}

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

result = 1LL;
if ( a1 > 127 )
{
result = 2LL;
if ( a1 > 2047 )
{
result = 3LL;
if ( a1 > 0xFFFF )
result = 4 * (unsigned int)(a1 < 1114112);
}
}
return result;
}

original_code:
int wrenUtf8EncodeNumBytes(int value)
{
  do { } while (0);
  if (value <= 0x7f) return 1;
  if (value <= 0x7ff) return 2;
  if (value <= 0xffff) return 3;
  if (value <= 0x10ffff) return 4;
  return 0;
}

variable_types: value int

return_type: int


original_code:
int wrenUtf8Encode(int value, uint8_t* bytes)
{
  if (value <= 0x7f)
  {
    *bytes = value & 0x7f;
    return 1;
  }
  else if (value <= 0x7ff)
  {
    *bytes = 0xc0 | ((value & 0x7c0) >> 6);
    bytes++;
    *bytes = 0x80 | (value & 0x3f);
    return 2;
  }
  else if (value <= 0xffff)
  {
    *bytes = 0xe0 | ((value & 0xf000) >> 12);
    bytes++;
    *bytes = 0x80 | ((value & 0xfc0) >> 6);
    bytes++;
    *bytes = 0x80 | (value & 0x3f);
    return 3;
  }
  else if (value <= 0x10ffff)
  {
    *bytes = 0xf0 | ((value & 0x1c0000) >> 18);
    bytes++;
    *bytes = 0x80 | ((value & 0x3f000) >> 12);
    bytes++;
    *bytes = 0x80 | ((value & 0xfc0) >> 6);
    bytes++;
    *bytes = 0x80 | (value & 0x3f);
    return 4;
  }
  __builtin_unreachable();
  return 0;
}

canonical_original_code:
int wrenUtf8Encode(int value, unsigned char *bytes)
{
  if (value <= 0x7f)
  {
    *bytes = value & 0x7f;
    return 1;
  }
  else if (value <= 0x7ff)
  {
    *bytes = 0xc0 | ((value & 0x7c0) >> 6);
    bytes++;
    *bytes = 0x80 | (value & 0x3f);
    return 2;
  }
  else if (value <= 0xffff)
  {
    *bytes = 0xe0 | ((value & 0xf000) >> 12);
    bytes++;
    *bytes = 0x80 | ((value & 0xfc0) >> 6);
    bytes++;
    *bytes = 0x80 | (value & 0x3f);
    return 3;
  }
  else if (value <= 0x10ffff)
  {
    *bytes = 0xf0 | ((value & 0x1c0000) >> 18);
    bytes++;
    *bytes = 0x80 | ((value & 0x3f000) >> 12);
    bytes++;
    *bytes = 0x80 | ((value & 0xfc0) >> 6);
    bytes++;
    *bytes = 0x80 | (value & 0x3f);
    return 4;
  }
  __builtin_unreachable();
  return 0;
}

variable_types:
bytes
unsigned char *


decompiled_code:
__int64 __fastcall wrenUtf8Decode(unsigned __int8 *a1, int a2)
{
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 *v5; // rsi
char v6; // dl

result = *a1;
if ( (result & 0x80u) != 0LL )
{
if ( (result & 0xE0) == 0xC0 )
{
LODWORD(result) = result & 0x1F;
v4 = 1LL;
}
else if ( (result & 0xF0) == 0xE0 )
{
LODWORD(result) = result & 0xF;
v4 = 2LL;
}
else
{
if ( (result & 0xF8) != 0xF0 )
return 0xFFFFFFFFLL;
LODWORD(result) = result & 7;
v4 = 3LL;
}
if ( a2 - 1 >= (unsigned int)v4 )
{
v5 = &a1[v4];
while ( 1 )
{
v6 = *++a1;
if ( (v6 & 0xC0) != 0x80 )
break;
result = v6 & 0x3Fu | ((_DWORD)result << 6);
if ( a1 == v5 )
return result;
}
}
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 *a1, int a2)
{
__int64 result; // rax
__int64 v4; // rsi
unsigned __int8 *v5; // rsi
char v6; // dl

result = *a1;
if ( (result & 0x80u) != 0LL )
{
if ( (result & 0xE0) == 0xC0 )
{
LODWORD(result) = result & 0x1F;
v4 = 1LL;
}
else if ( (result & 0xF0) == 0xE0 )
{
LODWORD(result) = result & 0xF;
v4 = 2LL;
}
else
{
if ( (result & 0xF8) != 0xF0 )
return 0xFFFFFFFFLL;
LODWORD(result) = result & 7;
v4 = 3LL;
}
if ( a2 - 1 >= (unsigned int)v4 )
{
v5 = &a1[v4];
while ( 1 )
{
v6 = *++a1;
if ( (v6 & 0xC0) != 0x80 )
break;
result = v6 & 0x3Fu | ((_DWORD)result << 6);
if ( a1 == v5 )
return result;
}
}
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int wrenUtf8Decode(const uint8_t* bytes, uint32_t length)
{
  if (*bytes <= 0x7f) return *bytes;
  int value;
  uint32_t remainingBytes;
  if ((*bytes & 0xe0) == 0xc0)
  {
    value = *bytes & 0x1f;
    remainingBytes = 1;
  }
  else if ((*bytes & 0xf0) == 0xe0)
  {
    value = *bytes & 0x0f;
    remainingBytes = 2;
  }
  else if ((*bytes & 0xf8) == 0xf0)
  {
    value = *bytes & 0x07;
    remainingBytes = 3;
  }
  else
  {
    return -1;
  }
  if (remainingBytes > length - 1) return -1;
  while (remainingBytes > 0)
  {
    bytes++;
    remainingBytes--;
    if ((*bytes & 0xc0) != 0x80) return -1;
    value = value << 6 | (*bytes & 0x3f);
  }
  return value;
}

canonical_original_code:
int wrenUtf8Decode(unsigned char *bytes, unsigned int length)
{
  if (*bytes <= 0x7f) return *bytes;
  int value;
  unsigned int remainingBytes;
  if ((*bytes & 0xe0) == 0xc0)
  {
    value = *bytes & 0x1f;
    remainingBytes = 1;
  }
  else if ((*bytes & 0xf0) == 0xe0)
  {
    value = *bytes & 0x0f;
    remainingBytes = 2;
  }
  else if ((*bytes & 0xf8) == 0xf0)
  {
    value = *bytes & 0x07;
    remainingBytes = 3;
  }
  else
  {
    return -1;
  }
  if (remainingBytes > length - 1) return -1;
  while (remainingBytes > 0)
  {
    bytes++;
    remainingBytes--;
    if ((*bytes & 0xc0) != 0x80) return -1;
    value = value << 6 | (*bytes & 0x3f);
  }
  return value;
}

variable_types:
length
unsigned int

variable_types:
remainingBytes
unsigned int


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

result = 0LL;
if ( (a1 & 0xC0) != 0x80 )
{
if ( (a1 & 0xF8) == 0xF0 )
{
result = 4LL;
}
else if ( (a1 & 0xF0) == 0xE0 )
{
result = 3LL;
}
else
{
result = (unsigned int)((a1 & 0xE0) == 0xC0) + 1;
}
}
return result;
}

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

result = 0LL;
if ( (a1 & 0xC0) != 0x80 )
{
if ( (a1 & 0xF8) == 0xF0 )
{
result = 4LL;
}
else if ( (a1 & 0xF0) == 0xE0 )
{
result = 3LL;
}
else
{
result = (unsigned int)((a1 & 0xE0) == 0xC0) + 1;
}
}
return result;
}

original_code:
int wrenUtf8DecodeNumBytes(uint8_t byte)
{
  if ((byte & 0xc0) == 0x80) return 0;
  if ((byte & 0xf8) == 0xf0) return 4;
  if ((byte & 0xf0) == 0xe0) return 3;
  if ((byte & 0xe0) == 0xc0) return 2;
  return 1;
}

canonical_original_code:
int wrenUtf8DecodeNumBytes(unsigned char byte)
{
  if ((byte & 0xc0) == 0x80) return 0;
  if ((byte & 0xf8) == 0xf0) return 4;
  if ((byte & 0xf0) == 0xe0) return 3;
  if ((byte & 0xe0) == 0xc0) return 2;
  return 1;
}

variable_types:
byte
unsigned char


wrenValidateIndex

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

if ( a2 >= 0 || (result = 0xFFFFFFFFLL, a2 += a1, a2 >= 0) )
{
result = 0xFFFFFFFFLL;
if ( a1 > a2 )
result = (unsigned int)a2;
}
return result;
}

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

if ( a2 >= 0 || (result = 0xFFFFFFFFLL, a2 += a1, a2 >= 0) )
{
result = 0xFFFFFFFFLL;
if ( a1 > a2 )
result = (unsigned int)a2;
}
return result;
}

original_code:
uint32_t wrenValidateIndex(uint32_t count, int64_t value)
{
  if (value < 0) value = count + value;
  if (value >= 0 && value < count) return (uint32_t)value;
  return (4294967295U);
}

canonical_original_code:
unsigned int wrenValidateIndex(unsigned int count, long value)
{
  if (value < 0) value = count + value;
  if (value >= 0 && value < count) return (unsigned int)value;
  return (4294967295U);
}

variable_types:
count
unsigned int

variable_types: value long

return_type: unsigned int


call

decompiled_code:
__int64 __fastcall call(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // r13
int v5; // er15
int v6; // er15
__int64 result; // rax
double v8; // [rsp+0h] [rbp-A8h]
int v9; // [rsp+8h] [rbp-A0h]
char v10[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = (int)wrenGetSlotDouble(a1, 1LL);
wrenInitConfiguration(v10);
v2 = wrenNewVM(v10);
wrenInterpret(v2, "main", testScript);
v3 = wrenMakeCallHandle(v2, "method(_,_,_,_)");
wrenEnsureSlots(v2, 1LL);
wrenGetVariable(v2, "main", "Test", 0LL);
v4 = wrenGetSlotHandle(v2, 0LL);
v9 = clock();
if ( v1 <= 0 )
{
v8 = 0.0;
}
else
{
v5 = 0;
v8 = 0.0;
do
{
++v5;
wrenEnsureSlots(v2, 5LL);
wrenSetSlotHandle(v2, 0LL, v4);
wrenSetSlotDouble(v2, 1LL, 1.0);
wrenSetSlotDouble(v2, 2LL, 2.0);
wrenSetSlotDouble(v2, 3LL, 3.0);
wrenSetSlotDouble(v2, 4LL, 4.0);
wrenCall(v2, v3);
v8 = wrenGetSlotDouble(v2, 0LL) + v8;
}
while ( v1 != v5 );
}
v6 = clock();
wrenReleaseHandle(v2, v4);
wrenReleaseHandle(v2, v3);
wrenFreeVM(v2);
if ( (double)v1 * 10.0 == v8 )
result = wrenSetSlotDouble(a1, 0LL, (double)v6 / 1000000.0 - (double)v9 / 1000000.0);
else
result = wrenSetSlotBool(a1, 0LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // r13
int v5; // er15
int v6; // er15
__int64 result; // rax
double v8; // [rsp+0h] [rbp-A8h]
int v9; // [rsp+8h] [rbp-A0h]
char v10[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = (int)wrenGetSlotDouble(a1, 1LL);
wrenInitConfiguration(v10);
v2 = wrenNewVM(v10);
wrenInterpret(v2, "main", testScript);
v3 = wrenMakeCallHandle(v2, "method(_,_,_,_)");
wrenEnsureSlots(v2, 1LL);
wrenGetVariable(v2, "main", "Test", 0LL);
v4 = wrenGetSlotHandle(v2, 0LL);
v9 = clock();
if ( v1 <= 0 )
{
v8 = 0.0;
}
else
{
v5 = 0;
v8 = 0.0;
do
{
++v5;
wrenEnsureSlots(v2, 5LL);
wrenSetSlotHandle(v2, 0LL, v4);
wrenSetSlotDouble(v2, 1LL, 1.0);
wrenSetSlotDouble(v2, 2LL, 2.0);
wrenSetSlotDouble(v2, 3LL, 3.0);
wrenSetSlotDouble(v2, 4LL, 4.0);
wrenCall(v2, v3);
v8 = wrenGetSlotDouble(v2, 0LL) + v8;
}
while ( v1 != v5 );
}
v6 = clock();
wrenReleaseHandle(v2, v4);
wrenReleaseHandle(v2, v3);
wrenFreeVM(v2);
if ( (double)v1 * 10.0 == v8 )
result = wrenSetSlotDouble(a1, 0LL, (double)v6 / 1000000.0 - (double)v9 / 1000000.0);
else
result = wrenSetSlotBool(a1, 0LL, 0LL);
return result;
}

original_code:
static void call(Compiler* compiler, _Bool canAssign)
{
  ignoreNewlines(compiler);
  consume(compiler, TOKEN_NAME, "Expect method name after '.'.");
  namedCall(compiler, canAssign, CODE_CALL_0);
}

canonical_original_code:
static void call(struct sCompiler *compiler, _Bool canAssign)
{
  ignoreNewlines(compiler);
  consume(compiler, TOKEN_NAME, "Expect method name after '.'.");
  namedCall(compiler, canAssign, CODE_CALL_0);
}

variable_types: struct sCompiler { struct Parser { struct WrenVM { struct sObjClass { 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 *classObj; struct sObj *next; } 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 *vm, unsigned long *args); void (*foreign)(struct WrenVM *vm); 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; } as; } *data; int count; int capacity; } methods; struct sObjString *name; unsigned long attributes; } *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 *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 *compiler; struct StringBuffer methodNames; } *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; } *

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 sObj { enum ObjType type; _Bool isDark; struct sObjClass *classObj; struct sObj *next; }

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


isSeparator

decompiled_code:
bool __fastcall isSeparator(char a1)
{
return a1 == 47;
}

canonical_decompiled_code:
bool __fastcall func0(char a1)
{
return a1 == 47;
}

original_code:
inline static _Bool isSeparator(char c)
  {
    if (c == '/') return 1;
    return 0;
  }

variable_types: c char


ensureCapacity

decompiled_code:
void __fastcall ensureCapacity(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
size_t v3; // rbx
void *v4; // rax

v2 = a2 + 1;
if ( *(_QWORD *)(a1 + 16) < v2 )
{
v3 = 16LL;
if ( v2 > 0x10 )
{
do
v3 *= 2LL;
while ( v2 > v3 );
}
v4 = realloc(*(void **)a1, v3);
*(_QWORD *)(a1 + 16) = v3;
*(_QWORD *)a1 = v4;
}
}

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

decompiled_code:
__int64 __fastcall pathType(char *a1)
{
__int64 v1; // rdx
char v2; // cl
_BOOL8 v3; // r8
__int64 result; // rax
char v5; // di
__int64 v6; // rdx
bool v7; // r8

v3 = absolutePrefixLength_isra_0(*a1);
result = 0LL;
if ( !v3 )
{
result = 2LL;
if ( v2 == 46 )
{
v5 = *(_BYTE *)(v1 + 1);
v7 = isSeparator(v5);
result = 1LL;
if ( !v7 )
{
result = 2LL;
if ( v5 == 46 )
result = (unsigned int)!isSeparator(*(_BYTE *)(v6 + 2)) + 1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
__int64 v1; // rdx
char v2; // cl
_BOOL8 v3; // r8
__int64 result; // rax
char v5; // di
__int64 v6; // rdx
bool v7; // r8

v3 = func2(*a1);
result = 0LL;
if ( !v3 )
{
result = 2LL;
if ( v2 == 46 )
{
v5 = *(_BYTE *)(v1 + 1);
v7 = func0(v5);
result = 1LL;
if ( !v7 )
{
result = 2LL;
if ( v5 == 46 )
result = (unsigned int)!func0(*(_BYTE *)(v6 + 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);
  }

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


pathRemoveExtension

decompiled_code:
void __fastcall pathRemoveExtension(_QWORD *a1)
{
__int64 v1; // rdx
bool v3; // cf
unsigned __int64 v4; // rdx
char v5; // di
__int64 v6; // rdx
_BYTE *v7; // r8

v1 = a1[1];
v3 = v1 != 0;
v4 = v1 - 1;
if ( v3 )
{
do
{
v5 = *(_BYTE *)(v4 + *a1);
if ( isSeparator(v5) )
break;
if ( v5 == 46 )
{
a1[1] = v6;
*v7 = 0;
}
v4 = v6 - 1;
}
while ( a1[1] > v4 );
}
}

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)
{
int v1; // er12
int v3; // ebx
char *v4; // rsi
char *i; // rdx
bool v6; // al
char v7; // cl
char *v8; // rcx
signed __int64 v9; // rax
__int64 v10; // rax
char *v11; // rcx
char v12; // di
__int64 *v13; // rax
char *v14; // rsi
__int64 *v15; // r13
_BOOL8 v16; // rax
char v17; // dl
int v18; // er14
int v19; // er12
__int64 v20; // rax
int v21; // er14
__int64 v22[4101]; // [rsp+0h] [rbp-8028h]

v1 = 0;
v3 = 0;
v4 = *(char **)a1;
for ( i = *(char **)a1; ; i = v8 )
{
v7 = *i;
if ( !*i )
break;
v6 = isSeparator(v7);
if ( v6 )
{
if ( v4 != i )
{
v9 = i - v4;
if ( i - v4 == 1 )
goto LABEL_21;
goto LABEL_8;
}
LABEL_17:
while ( 1 )
{
v12 = i[1];
v8 = i + 1;
if ( !v6 )
break;
if ( !v12 )
goto LABEL_25;
v6 = isSeparator(v12);
i = v11;
}
v4 = i;
}
else
{
v8 = i + 1;
}
}
if ( v4 == i )
goto LABEL_25;
v9 = i - v4;
if ( i - v4 == 1 )
{
LABEL_21:
if ( *v4 == 46 )
goto LABEL_13;
goto LABEL_11;
}
LABEL_8:
if ( v9 == 2 && *v4 == 46 && v4[1] == 46 )
{
if ( v3 )
--v3;
else
++v1;
goto LABEL_13;
}
LABEL_11:
if ( v3 > 2047 )
{
fprintf(stderr, "Path cannot have more than %d path components.\n", 2048LL);
exit(1);
}
v10 = v3++;
v10 *= 16LL;
*(__int64 *)((char *)v22 + v10) = (__int64)v4;
*(__int64 *)((char *)&v22[1] + v10) = (__int64)i;
LABEL_13:
if ( v7 )
{
v6 = isSeparator(v7);
goto LABEL_17;
}
LABEL_25:
v13 = pathNew((const char *)&unk_96C);
v14 = *(char **)a1;
v15 = v13;
v16 = absolutePrefixLength_isra_0(**(_BYTE **)a1);
if ( v16 )
{
appendSlice(v15, v14, (__int64)&v14[v16]);
}
else
{
v18 = 0;
if ( v1 )
{
while ( 1 )
{
++v18;
pathAppendString(v15, "..");
if ( v18 == v1 )
break;
pathAppendChar(v15, 47);
}
LABEL_37:
if ( v3 )
{
v21 = 1;
v19 = 0;
do
{
pathAppendChar(v15, 47);
v20 = v19;
v19 = v21;
LABEL_33:
v21 = v19 + 1;
appendSlice(v15, (const void *)v22[2 * v20], v22[2 * v20 + 1]);
}
while ( v3 > v19 );
}
goto LABEL_38;
}
if ( v17 == 46 && isSeparator(v14[1]) )
{
pathAppendChar(v15, 46);
goto LABEL_37;
}
}
if ( v3 )
{
v19 = 1;
v20 = 0LL;
goto LABEL_33;
}
LABEL_38:
if ( !v15[1] )
pathAppendChar(v15, 46);
free(*(void **)a1);
*(_QWORD *)(a1 + 16) = v15[2];
*(_QWORD *)a1 = *v15;
*(_QWORD *)(a1 + 8) = v15[1];
free(v15);
}

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)
{
unsigned int v2; // er8

v2 = 1;
if ( memcmp(a1, "test/api", 8uLL) )
LOBYTE(v2) = memcmp(a1, "test/benchmark", 0xEuLL) == 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(const void *a1)
{
unsigned int v2; // er8

v2 = 1;
if ( memcmp(a1, "test/api", 8uLL) )
LOBYTE(v2) = memcmp(a1, "test/benchmark", 0xEuLL) == 0;
return v2;
}

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 func18(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 *[]


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:
__int64 __fastcall wrenIsObjType(__int64 a1, int a2)
{
unsigned int v2; // er8

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // er8

v2 = 0;
if ( (a1 & 0xFFFC000000000000LL) == 0xFFFC000000000000LL )
LOBYTE(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 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 WrenHandle { unsigned long value; struct WrenHandle *prev; struct WrenHandle *next; }

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

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 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: 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: 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 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 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:
char __fastcall wrenMapIsValidKey(__int64 a1)
{
char result; // al
__int64 v2; // r9
char v3; // r8
__int64 v4; // r9
__int64 v5; // r9

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

canonical_decompiled_code:
char __fastcall func4(__int64 a1)
{
char result; // al
__int64 v2; // r9
char v3; // r8
__int64 v4; // r9
__int64 v5; // r9

result = func1(a1);
if ( !result )
{
v3 = func2(v2, 0);
result = v3 | (v4 == 0x7FFC000000000001LL);
if ( !result )
{
result = 1;
if ( (v4 & 0x7FFC000000000000LL) == 0x7FFC000000000000LL )
{
result = func2(v4, 9);
if ( !result )
result = func2(v5, 10);
}
}
}
return result;
}

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


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

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: struct Signature { char *name; int length; enum SignatureType type; int arity; }

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


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 func1(__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

v1 = *a1;
++n_0;
if ( v1 )
{
if ( *v1 )
{
fprintf(stderr, " Freeing: %s\n", (const char *)*v1);
free(**a1);
v1 = *a1;
}
v2 = (const char *)v1[1];
if ( v2 )
{
fprintf(stderr, " Freeing: %s\n", v2);
free((*a1)[1]);
v1 = *a1;
}
v3 = (const char *)v1[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

v1 = *a1;
++n_0;
if ( v1 )
{
if ( *v1 )
{
fprintf(stderr, " Freeing: %s\n", (const char *)*v1);
free(**a1);
v1 = *a1;
}
v2 = (const char *)v1[1];
if ( v2 )
{
fprintf(stderr, " Freeing: %s\n", v2);
free((*a1)[1]);
v1 = *a1;
}
v3 = (const char *)v1[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; // rax
char *v6; // r12
char *v7; // rax
char *v8; // rbp
char *v9; // rax
const char **v10; // rbx
char *v11; // rax
char *v12; // rbp
char *v13; // rax
char *v14; // r12
char *v15; // rax
const char **v16; // rbx
char *v17; // rax
char *v18; // rbp
char *v19; // rax
char *v20; // r12
char *v21; // rax
const char ***v22; // rbx
int v23; // er12
const char **v24; // rbp
const char ***v25; // [rsp+0h] [rbp-28h] BYREF
__int64 v26[4]; // [rsp+8h] [rbp-20h] BYREF

v25 = 0LL;
v26[0] = 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 = v5;
v7 = strdup("Philadelphia");
v4[1] = v7;
v8 = v7;
v9 = strdup("PA");
v4[2] = v9;
if ( v8 == 0LL || v6 == 0LL || !v9 )
goto LABEL_14;
v26[0] = allocateNode(v4);
appendNodeSorted(&v25, v26, 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]);
v10 = (const char **)malloc(0x18uLL);
if ( v10 )
{
v11 = strdup("Janet Hunter");
*v10 = v11;
v12 = v11;
v13 = strdup("Santa Clara");
v10[1] = v13;
v14 = v13;
v15 = strdup("CA");
v10[2] = v15;
if ( v12 == 0LL || v14 == 0LL || !v15 )
goto LABEL_14;
v26[0] = allocateNode(v10);
appendNodeSorted(&v25, v26, compFunc);
fprintf(stderr, "Appending Node: %d\n", 2LL);
fprintf(stderr, " %s\n", *v10);
fprintf(stderr, " %s\n", v10[1]);
fprintf(stderr, " %s\n", v10[2]);
v16 = (const char **)malloc(0x18uLL);
if ( v16 )
{
v17 = strdup("Babs Jensen");
*v16 = v17;
v18 = v17;
v19 = strdup("Cupertino");
v16[1] = v19;
v20 = v19;
v21 = strdup("CA");
v16[2] = v21;
if ( v18 != 0LL && v20 != 0LL && v21 )
{
v26[0] = allocateNode(v16);
appendNodeSorted(&v25, v26, compFunc);
fprintf(stderr, "Appending Node: %d\n", 3LL);
fprintf(stderr, " %s\n", *v16);
fprintf(stderr, " %s\n", v16[1]);
fprintf(stderr, " %s\n", v16[2]);
fwrite("\n---------------[ printing ]----------\n", 1uLL, 0x27uLL, stderr);
v22 = v25;
if ( v25 )
{
v23 = 0;
do
{
v24 = *v22;
fprintf(stderr, "Node: %d\n", (unsigned int)++v23);
fprintf(stderr, " %s\n", *v24);
fprintf(stderr, " %s\n", v24[1]);
fprintf(stderr, " %s\n", v24[2]);
v22 = (const char ***)v22[1];
}
while ( v22 );
}
fwrite("\n---------------[ freeing ]----------\n", 1uLL, 0x26uLL, stderr);
destroyNodes(&v25, freeData);
exit(0);
}
LABEL_14:
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)
{
pthread_cond_init(a1, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(pthread_cond_t *a1)
{
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:
// attributes: thunk
int mtx_destroy(pthread_mutex_t *mutex)
{
return pthread_mutex_destroy(mutex);
}

canonical_decompiled_code:
int func8(pthread_mutex_t *mutex)
{
return pthread_mutex_destroy(mutex);
}

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:
// attributes: thunk
int cnd_destroy(pthread_cond_t *cond)
{
return pthread_cond_destroy(cond);
}

canonical_decompiled_code:
int func9(pthread_cond_t *cond)
{
return pthread_cond_destroy(cond);
}

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:
// attributes: thunk
pthread_t thrd_current(void)
{
return pthread_self();
}

canonical_decompiled_code:
pthread_t func10(void)
{
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)
{
__int64 v1; // rbp
int (__fastcall *v2)(__int64); // rbx

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

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

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

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_constprop_0((pthread_mutex_t *)(a1 + 48));
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 = func12((pthread_mutex_t *)(a1 + 48));
if ( !(_DWORD)result )
{
result = func7((pthread_cond_t *)(a1 + 88));
if ( !(_DWORD)result )
result = func7((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)
{
func8((pthread_mutex_t *)(a1 + 48));
func9((pthread_cond_t *)(a1 + 88));
return func9((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
__int64 i; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
mtx_lock_isra_0((pthread_mutex_t *)(a1 + 48));
for ( i = *(int *)(a1 + 40); (int)i > 9; i = *(int *)(a1 + 40) )
cnd_wait_isra_0((pthread_cond_t *)(a1 + 88), v2);
*(_DWORD *)(a1 + 40) = i + 1;
*(_DWORD *)(a1 + 4 * i) = a2;
cnd_signal_isra_0((pthread_cond_t *)(a1 + 136));
mtx_unlock_isra_0(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 = func10();
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_isra_0((pthread_mutex_t *)(a1 + 48));
for ( i = *(_DWORD *)(a1 + 40); !i; i = *(_DWORD *)(a1 + 40) )
cnd_wait_isra_0((pthread_cond_t *)(a1 + 136), v2);
v4 = i - 1;
*(_DWORD *)(a1 + 40) = v4;
*a2 = *(_DWORD *)(a1 + 4LL * v4);
cnd_signal_isra_0((pthread_cond_t *)(a1 + 88));
mtx_unlock_isra_0(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);
func16((pthread_mutex_t *)(a1 + 48));
for ( i = *(_DWORD *)(a1 + 40); !i; i = *(_DWORD *)(a1 + 40) )
func17((pthread_cond_t *)(a1 + 136), v2);
v4 = i - 1;
*(_DWORD *)(a1 + 40) = v4;
*a2 = *(_DWORD *)(a1 + 4LL * v4);
func18((pthread_cond_t *)(a1 + 88));
func15(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 *