vectorFind

decompiled_code:
__int64 __fastcall vectorFind(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 v3; // rdi
__int64 v4; // rax
unsigned int v5; // ecx

v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
return (unsigned int)-1;
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( *(_QWORD *)(v3 + 8 * v4) == a2 )
break;
if ( ++v4 == v2 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 v3; // rdi
__int64 v4; // rax
unsigned int v5; // ecx

v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
return (unsigned int)-1;
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( *(_QWORD *)(v3 + 8 * v4) == a2 )
break;
if ( ++v4 == v2 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int vectorFind (vector* v, void* item) {
    for (int i = 0; i < v->length; i++) {
        if (v->buffer[i] == item)
            return i;
    }
    return -1;
}

canonical_original_code:
int vectorFind(struct vector *v, void *item) {
    for (int i = 0; i < v->length; i++) {
        if (v->buffer[i] == item)
            return i;
    }
    return -1;
}


vectorGet

repo: Fedjmike/fcc

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

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

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

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

original_code:
void* vectorGet (const vector* v, int n) {
    if (n < v->length && n >= 0)
        return v->buffer[n];
    else
        return 0;
}

canonical_original_code:
void *vectorGet(struct vector *v, int n) {
    if (n < v->length && n >= 0)
        return v->buffer[n];
    else
        return 0;
}

variable_types: struct vector { int length; void **buffer; } *

variable_types: n int

return_type: void *


vectorRemoveReorder

decompiled_code:
__int64 __fastcall vectorRemoveReorder(int *a1, int a2)
{
__int64 v2; // rbp

v2 = 0LL;
if ( *a1 > a2 )
{
v2 = vectorPop((__int64)a1);
vectorSet((__int64)a1, a2, v2);
}
return v2;
}

original_code:
void* vectorRemoveReorder (vector* v, int n) {
    if (v->length <= n)
        return 0;
    void* last = vectorPop(v);
    vectorSet(v, n, last);
    return last;
}

canonical_original_code:
void *vectorRemoveReorder(struct vector *v, int n) {
    if (v->length <= n)
        return 0;
    void *last = vectorPop(v);
    vectorSet(v, n, last);
    return last;
}

variable_types:
last
void *

user_defined_types: struct vector { int length; void **buffer; }


vectorMap

decompiled_code:
__int64 __fastcall vectorMap(__int64 a1, __int64 (__fastcall *a2)(_QWORD), __int64 a3)
{
int v3; // eax
__int64 v5; // r15
__int64 v6; // rbx
_QWORD *v7; // rbp
__int64 result; // rax
unsigned int v9; // [rsp+Ch] [rbp-3Ch]

v3 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)a3 <= v3 )
v3 = *(_DWORD *)a3;
v9 = v3;
if ( v3 > 0 )
{
v5 = 8LL * (unsigned int)v3;
v6 = 0LL;
do
{
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + v6);
*v7 = a2(*(_QWORD *)(*(_QWORD *)(a3 + 8) + v6));
v6 += 8LL;
}
while ( v6 != v5 );
}
result = v9;
*(_DWORD *)a1 = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 (__fastcall *a2)(_QWORD), __int64 a3)
{
int v3; // eax
__int64 v5; // r15
__int64 v6; // rbx
_QWORD *v7; // rbp
__int64 result; // rax
unsigned int v9; // [rsp+Ch] [rbp-3Ch]

v3 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)a3 <= v3 )
v3 = *(_DWORD *)a3;
v9 = v3;
if ( v3 > 0 )
{
v5 = 8LL * (unsigned int)v3;
v6 = 0LL;
do
{
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + v6);
*v7 = a2(*(_QWORD *)(*(_QWORD *)(a3 + 8) + v6));
v6 += 8LL;
}
while ( v6 != v5 );
}
result = v9;
*(_DWORD *)a1 = v9;
return result;
}

original_code:
void vectorMap (vector* dest, vectorMapper f, vector* src) {
    int upto = src->length > dest->capacity ? dest->capacity : src->length;
    for (int n = 0; n < upto; n++)
        dest->buffer[n] = f(src->buffer[n]);
    dest->length = upto;
}

canonical_original_code:
void vectorMap(struct vector *dest, void *(*f)(void *), struct vector *src) {
    int upto = src->length > dest->capacity ? dest->capacity : src->length;
    for (int n = 0; n < upto; n++)
        dest->buffer[n] = f(src->buffer[n]);
    dest->length = upto;
}

variable_types:
f
void *(*)(void *)

variable_types:
src
struct vector *

variable_types: upto int

return_type: void


vectorFreeObjs

decompiled_code:
void __fastcall vectorFreeObjs(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
vectorMap(a1, a2, a1);
vectorFree(a1);
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
func11(a1, a2, a1);
func2(a1);
}

original_code:
void vectorFreeObjs (vector* v, vectorDtor dtor) {
    vectorMap(v, (vectorMapper) dtor, v);
    vectorFree(v);
}

canonical_original_code:
void vectorFreeObjs(struct vector *v, void (*dtor)(void *)) {
    vectorMap(v, (void *(*)(void *)) dtor, v);
    vectorFree(v);
}

variable_types:
dtor
void (*)(void *)


bitarrayInit

original_code:
bitarray* bitarrayInit (bitarray* bits, int bitno) {
    int size = (bitno-1)/bitsPerWord + 1;
    bits->array = calloc(size, sizeof(bitarrayWord));
    bits->bitno = bitno;
    return bits;
}

canonical_original_code:
struct bitarray *bitarrayInit(struct bitarray *bits, int bitno) {
    int size = (bitno-1)/bitsPerWord + 1;
    bits->array = calloc(size, sizeof(bitarrayWord));
    bits->bitno = bitno;
    return bits;
}

variable_types:
bits
struct bitarray *

variable_types: bitno int

variable_types: size int

return_type: struct bitarray { long *array; int bitno; } *


bitarrayFree

decompiled_code:
void __fastcall bitarrayFree(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void bitarrayFree (bitarray* bits) {
    free(bits->array);
    bits->array = 0;
    bits->bitno = 0;
}

canonical_original_code:
void bitarrayFree(struct bitarray *bits) {
    free(bits->array);
    bits->array = 0;
    bits->bitno = 0;
}

variable_types: struct bitarray { long *array; int bitno; } *


bitarrayTest

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

result = 0LL;
if ( *(_DWORD *)(a1 + 8) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (a2 / 64)) & (1 << (a2 % 64));
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 8) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (a2 / 64)) & (1 << (a2 % 64));
return result;
}

original_code:
bitarrayWord bitarrayTest (const bitarray* bits, int index) {
    if (index >= bits->bitno)
        return 0;
    int word = index / bitsPerWord,
        bit = index % bitsPerWord;
    return bits->array[word] & (1 << bit);
}

canonical_original_code:
long bitarrayTest(struct bitarray *bits, int index) {
    if (index >= bits->bitno)
        return 0;
    int word = index / bitsPerWord; int bit = index % bitsPerWord;
    return bits->array[word] & (1 << bit);
}

variable_types: index int

variable_types: word int

variable_types: bit int

return_type: long

user_defined_types: struct bitarray { long *array; int bitno; }


operandTagGetStr

decompiled_code:
const char *__fastcall operandTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "operandUndefined";
if ( (_DWORD)a1 )
{
result = "operandInvalid";
if ( (_DWORD)a1 != 1 )
{
result = "operandVoid";
if ( (_DWORD)a1 != 2 )
{
result = "operandFlags";
if ( (_DWORD)a1 != 3 )
{
result = "operandReg";
if ( (_DWORD)a1 != 4 )
{
result = "operandMem";
if ( (_DWORD)a1 != 5 )
{
result = "operandLiteral";
if ( (_DWORD)a1 != 6 )
{
result = "operandLabel";
if ( (_DWORD)a1 != 7 )
{
result = "operandLabelMem";
if ( (_DWORD)a1 != 8 )
{
result = "operandLabelOffset";
if ( (_DWORD)a1 != 9 )
{
result = "operandStack";
if ( (_DWORD)a1 != 10 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("operandTagGetStr", "operand tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "operandUndefined";
if ( (_DWORD)a1 )
{
result = "operandInvalid";
if ( (_DWORD)a1 != 1 )
{
result = "operandVoid";
if ( (_DWORD)a1 != 2 )
{
result = "operandFlags";
if ( (_DWORD)a1 != 3 )
{
result = "operandReg";
if ( (_DWORD)a1 != 4 )
{
result = "operandMem";
if ( (_DWORD)a1 != 5 )
{
result = "operandLiteral";
if ( (_DWORD)a1 != 6 )
{
result = "operandLabel";
if ( (_DWORD)a1 != 7 )
{
result = "operandLabelMem";
if ( (_DWORD)a1 != 8 )
{
result = "operandLabelOffset";
if ( (_DWORD)a1 != 9 )
{
result = "operandStack";
if ( (_DWORD)a1 != 10 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("operandTagGetStr", "operand tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
const char* operandTagGetStr (operandTag tag) {
    if (tag == operandUndefined) return "operandUndefined";
    else if (tag == operandInvalid) return "operandInvalid";
    else if (tag == operandVoid) return "operandVoid";
    else if (tag == operandFlags) return "operandFlags";
    else if (tag == operandReg) return "operandReg";
    else if (tag == operandMem) return "operandMem";
    else if (tag == operandLiteral) return "operandLiteral";
    else if (tag == operandLabel) return "operandLabel";
    else if (tag == operandLabelMem) return "operandLabelMem";
    else if (tag == operandLabelOffset) return "operandLabelOffset";
    else if (tag == operandStack) return "operandStack";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("operandTagGetStr", "operand tag", str);
        free(str);
        return "<unhandled>";
    }
}

canonical_original_code:
char *operandTagGetStr(enum operandTag tag) {
    if (tag == operandUndefined) return "operandUndefined";
    else if (tag == operandInvalid) return "operandInvalid";
    else if (tag == operandVoid) return "operandVoid";
    else if (tag == operandFlags) return "operandFlags";
    else if (tag == operandReg) return "operandReg";
    else if (tag == operandMem) return "operandMem";
    else if (tag == operandLiteral) return "operandLiteral";
    else if (tag == operandLabel) return "operandLabel";
    else if (tag == operandLabelMem) return "operandLabelMem";
    else if (tag == operandLabelOffset) return "operandLabelOffset";
    else if (tag == operandStack) return "operandStack";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("operandTagGetStr", "operand tag", str);
        free(str);
        return "<unhandled>";
    }
}

variable_types: enum operandTag { operandUndefined=0, operandInvalid=1, operandVoid=2, operandFlags=3, operandReg=4, operandMem=5, operandLiteral=6, operandLabel=7, operandLabelMem=8, operandLabelOffset=9, operandStack=10 }

variable_types:
str
char *

return_type: char *


conditionFromOp

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

result = 1LL;
if ( a1 != 19 )
{
switch ( a1 )
{
case 20:
result = 2LL;
break;
case 21:
result = 3LL;
break;
case 22:
result = 4LL;
break;
case 23:
result = 5LL;
break;
default:
result = 6LL;
if ( a1 != 24 )
result = 0LL;
break;
}
}
return result;
}

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

result = 1LL;
if ( a1 != 19 )
{
switch ( a1 )
{
case 20:
result = 2LL;
break;
case 21:
result = 3LL;
break;
case 22:
result = 4LL;
break;
case 23:
result = 5LL;
break;
default:
result = 6LL;
if ( a1 != 24 )
result = 0LL;
break;
}
}
return result;
}

original_code:
conditionTag conditionFromOp (opTag cond) {
    if (cond == opEqual) return conditionEqual;
    else if (cond == opNotEqual) return conditionNotEqual;
    else if (cond == opGreater) return conditionGreater;
    else if (cond == opGreaterEqual) return conditionGreaterEqual;
    else if (cond == opLess) return conditionLess;
    else if (cond == opLessEqual) return conditionLessEqual;
    else return conditionUndefined;
}

canonical_original_code:
enum conditionTag conditionFromOp(enum opTag cond) {
    if (cond == opEqual) return conditionEqual;
    else if (cond == opNotEqual) return conditionNotEqual;
    else if (cond == opGreater) return conditionGreater;
    else if (cond == opGreaterEqual) return conditionGreaterEqual;
    else if (cond == opLess) return conditionLess;
    else if (cond == opLessEqual) return conditionLessEqual;
    else return conditionUndefined;
}

variable_types: enum opTag { opUndefined=0, opComma=1, opAssign=2, opBitwiseAndAssign=3, opBitwiseOrAssign=4, opBitwiseXorAssign=5, opTernary=6, opShrAssign=7, opShlAssign=8, opAddAssign=9, opSubtractAssign=10, opMultiplyAssign=11, opDivideAssign=12, opModuloAssign=13, opLogicalAnd=14, opLogicalOr=15, opBitwiseAnd=16, opBitwiseOr=17, opBitwiseXor=18, opEqual=19, opNotEqual=20, opGreater=21, opGreaterEqual=22, opLess=23, opLessEqual=24, opShr=25, opShl=26, opAdd=27, opSubtract=28, opMultiply=29, opDivide=30, opModulo=31, opLogicalNot=32, opBitwiseNot=33, opUnaryPlus=34, opNegate=35, opDeref=36, opAddressOf=37, opIndex=38, opCall=39, opPreIncrement=40, opPreDecrement=41, opPostIncrement=42, opPostDecrement=43, opMember=44, opMemberDeref=45, opAssert=46 }

return_type: enum conditionTag { conditionUndefined=0, conditionEqual=1, conditionNotEqual=2, conditionGreater=3, conditionGreaterEqual=4, conditionLess=5, conditionLessEqual=6 }


conditionNegate

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

if ( a1 == 1 )
return 2LL;
result = 1LL;
if ( a1 != 2 )
{
switch ( a1 )
{
case 3:
result = 6LL;
break;
case 4:
result = 5LL;
break;
case 5:
result = 4LL;
break;
default:
result = 3 * (unsigned int)(a1 == 6);
break;
}
}
return result;
}

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

if ( a1 == 1 )
return 2LL;
result = 1LL;
if ( a1 != 2 )
{
switch ( a1 )
{
case 3:
result = 6LL;
break;
case 4:
result = 5LL;
break;
case 5:
result = 4LL;
break;
default:
result = 3 * (unsigned int)(a1 == 6);
break;
}
}
return result;
}

original_code:
conditionTag conditionNegate (conditionTag cond) {
    if (cond == conditionEqual) return conditionNotEqual;
    else if (cond == conditionNotEqual) return conditionEqual;
    else if (cond == conditionGreater) return conditionLessEqual;
    else if (cond == conditionGreaterEqual) return conditionLess;
    else if (cond == conditionLess) return conditionGreaterEqual;
    else if (cond == conditionLessEqual) return conditionGreater;
    else return conditionUndefined;
}

canonical_original_code:
enum conditionTag conditionNegate(enum conditionTag cond) {
    if (cond == conditionEqual) return conditionNotEqual;
    else if (cond == conditionNotEqual) return conditionEqual;
    else if (cond == conditionGreater) return conditionLessEqual;
    else if (cond == conditionGreaterEqual) return conditionLess;
    else if (cond == conditionLess) return conditionGreaterEqual;
    else if (cond == conditionLessEqual) return conditionGreater;
    else return conditionUndefined;
}

variable_types: enum conditionTag { conditionUndefined=0, conditionEqual=1, conditionNotEqual=2, conditionGreater=3, conditionGreaterEqual=4, conditionLess=5, conditionLessEqual=6 }


symTagGetStr

decompiled_code:
const char *__fastcall symTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "undefined";
if ( (_DWORD)a1 )
{
result = "scope";
if ( (_DWORD)a1 != 1 )
{
result = "module link";
if ( (_DWORD)a1 != 2 )
{
result = "sym link";
if ( (_DWORD)a1 != 3 )
{
result = "type";
if ( (_DWORD)a1 != 4 )
{
result = "typedef";
if ( (_DWORD)a1 != 5 )
{
result = "struct";
if ( (_DWORD)a1 != 6 )
{
result = "union";
if ( (_DWORD)a1 != 7 )
{
result = "enum";
if ( (_DWORD)a1 != 8 )
{
result = "enum constant";
if ( (_DWORD)a1 != 9 )
{
result = "id";
if ( (_DWORD)a1 != 10 )
{
result = "parameter";
if ( (_DWORD)a1 != 11 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("symTagGetStr", "symbol tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "undefined";
if ( (_DWORD)a1 )
{
result = "scope";
if ( (_DWORD)a1 != 1 )
{
result = "module link";
if ( (_DWORD)a1 != 2 )
{
result = "sym link";
if ( (_DWORD)a1 != 3 )
{
result = "type";
if ( (_DWORD)a1 != 4 )
{
result = "typedef";
if ( (_DWORD)a1 != 5 )
{
result = "struct";
if ( (_DWORD)a1 != 6 )
{
result = "union";
if ( (_DWORD)a1 != 7 )
{
result = "enum";
if ( (_DWORD)a1 != 8 )
{
result = "enum constant";
if ( (_DWORD)a1 != 9 )
{
result = "id";
if ( (_DWORD)a1 != 10 )
{
result = "parameter";
if ( (_DWORD)a1 != 11 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("symTagGetStr", "symbol tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
const char* symTagGetStr (symTag tag) {
    if (tag == symUndefined) return "undefined";
    else if (tag == symScope) return "scope";
    else if (tag == symModuleLink) return "module link";
    else if (tag == symLink) return "sym link";
    else if (tag == symType) return "type";
    else if (tag == symTypedef) return "typedef";
    else if (tag == symStruct) return "struct";
    else if (tag == symUnion) return "union";
    else if (tag == symEnum) return "enum";
    else if (tag == symEnumConstant) return "enum constant";
    else if (tag == symId) return "id";
    else if (tag == symParam) return "parameter";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("symTagGetStr", "symbol tag", str);
        free(str);
        return "<unhandled>";
    }
}

canonical_original_code:
char *symTagGetStr(enum symTag tag) {
    if (tag == symUndefined) return "undefined";
    else if (tag == symScope) return "scope";
    else if (tag == symModuleLink) return "module link";
    else if (tag == symLink) return "sym link";
    else if (tag == symType) return "type";
    else if (tag == symTypedef) return "typedef";
    else if (tag == symStruct) return "struct";
    else if (tag == symUnion) return "union";
    else if (tag == symEnum) return "enum";
    else if (tag == symEnumConstant) return "enum constant";
    else if (tag == symId) return "id";
    else if (tag == symParam) return "parameter";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("symTagGetStr", "symbol tag", str);
        free(str);
        return "<unhandled>";
    }
}

variable_types: enum symTag { symUndefined=0, symScope=1, symModuleLink=2, symLink=3, symType=4, symTypedef=5, symStruct=6, symUnion=7, symEnum=8, symEnumConstant=9, symId=10, symParam=11 }


storageTagGetStr

decompiled_code:
const char *__fastcall storageTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "storageUndefined";
if ( (_DWORD)a1 )
{
result = "storageAuto";
if ( (_DWORD)a1 != 1 )
{
result = "storageStatic";
if ( (_DWORD)a1 != 2 )
{
result = "storageExtern";
if ( (_DWORD)a1 != 3 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("storageTagGetStr", "storage tag", v3);
free(v3);
result = "<undefined>";
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func10(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "storageUndefined";
if ( (_DWORD)a1 )
{
result = "storageAuto";
if ( (_DWORD)a1 != 1 )
{
result = "storageStatic";
if ( (_DWORD)a1 != 2 )
{
result = "storageExtern";
if ( (_DWORD)a1 != 3 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("storageTagGetStr", "storage tag", v3);
free(v3);
result = "<undefined>";
}
}
}
}
return result;
}

original_code:
const char* storageTagGetStr (storageTag tag) {
    if (tag == storageUndefined) return "storageUndefined";
    else if (tag == storageAuto) return "storageAuto";
    else if (tag == storageStatic) return "storageStatic";
    else if (tag == storageExtern) return "storageExtern";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("storageTagGetStr", "storage tag", str);
        free(str);
        return "<undefined>";
    }
}

canonical_original_code:
char *storageTagGetStr(enum storageTag tag) {
    if (tag == storageUndefined) return "storageUndefined";
    else if (tag == storageAuto) return "storageAuto";
    else if (tag == storageStatic) return "storageStatic";
    else if (tag == storageExtern) return "storageExtern";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("storageTagGetStr", "storage tag", str);
        free(str);
        return "<undefined>";
    }
}

variable_types: enum storageTag { storageUndefined=0, storageAuto=1, storageStatic=2, storageExtern=3 }


filext

decompiled_code:
char *__fastcall filext(char *s, char *a2, __int64 (__fastcall *a3)(size_t))
{
signed __int64 v4; // r13
size_t v5; // r14
size_t v6; // rax
char *v7; // rax
char *v8; // r12

v4 = strrchr(s, 46) - s;
v5 = strlen(s);
v6 = strlen(a2);
v7 = (char *)a3(v5 + v6 + 2);
v8 = v7;
if ( *a2 )
{
if ( (int)v4 < 0 )
sprintf(v7, "%s.%s", s, a2);
else
sprintf(v7, "%.*s.%s", v4, s, a2);
}
else
{
sprintf(v7, "%.*s", v4, s);
}
return v8;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, char *a2, __int64 (__fastcall *a3)(size_t))
{
signed __int64 v4; // r13
size_t v5; // r14
size_t v6; // rax
char *v7; // rax
char *v8; // r12

v4 = strrchr(s, 46) - s;
v5 = strlen(s);
v6 = strlen(a2);
v7 = (char *)a3(v5 + v6 + 2);
v8 = v7;
if ( *a2 )
{
if ( (int)v4 < 0 )
sprintf(v7, "%s.%s", s, a2);
else
sprintf(v7, "%.*s.%s", v4, s, a2);
}
else
{
sprintf(v7, "%.*s", v4, s);
}
return v8;
}

original_code:
char* filext (const char* name, const char* extension, void* (*allocator)(size_t)) {
    int index = (int)(strrchr(name, (int) '.') - name);
    char* ret = allocator(strlen(name)+strlen(extension)+2);
    if (extension[0] != 0) {
        if (index < 0)
            sprintf(ret, "%s.%s", name, extension);
        else
            sprintf(ret, "%.*s.%s", index, name, extension);
    } else
        sprintf(ret, "%.*s", index, name);
    return ret;
}

canonical_original_code:
char *filext(char *name, char *extension, void *(*allocator)(unsigned long)) {
    int index = (int)(strrchr(name, (int) '.') - name);
    char *ret = allocator(strlen(name)+strlen(extension)+2);
    if (extension[0] != 0) {
        if (index < 0)
            sprintf(ret, "%s.%s", name, extension);
        else
            sprintf(ret, "%.*s.%s", index, name, extension);
    } else
        sprintf(ret, "%.*s", index, name);
    return ret;
}

variable_types:
name
char *

variable_types:
extension
char *

variable_types:
allocator
void *(*)(unsigned long)

variable_types:
ret
char *


logi

decompiled_code:
__int64 __fastcall logi(int a1, int a2)
{
unsigned int v2; // ecx

if ( a1 < a2 )
return 0;
v2 = 0;
do
{
a1 /= a2;
++v2;
}
while ( a2 <= a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
unsigned int v2; // ecx

if ( a1 < a2 )
return 0;
v2 = 0;
do
{
a1 /= a2;
++v2;
}
while ( a2 <= a1 );
return v2;
}

original_code:
int logi (int x, int base) {
    int n = 0;
    while (x >= base) {
        x /= base;
        n++;
    }
    return n;
}

canonical_original_code:
int logi(int x, int base) {
    int n = 0;
    while (x >= base) {
        x /= base;
        n++;
    }
    return n;
}

variable_types: x int

variable_types: base int

variable_types: n int

return_type: int


fgetpath

decompiled_code:
char *__fastcall fgetpath(char *s, __int64 (__fastcall *a2)(_QWORD))
{
char *v2; // rax
int v3; // eax
size_t v4; // r12
char *v5; // rax
char *v6; // rdx

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (_DWORD)v2 - (_DWORD)s;
v4 = v3;
v5 = (char *)a2(v3 + 1);
v6 = strncpy(v5, s, v4);
v6[v4] = 0;
return v6;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, __int64 (__fastcall *a2)(_QWORD))
{
char *v2; // rax
int v3; // eax
size_t v4; // r12
char *v5; // rax
char *v6; // rdx

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (_DWORD)v2 - (_DWORD)s;
v4 = v3;
v5 = (char *)a2(v3 + 1);
v6 = strncpy(v5, s, v4);
v6[v4] = 0;
return v6;
}

original_code:
char* fgetpath (const char* fullname, void* (*allocator)(size_t)) {
    const char* found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char* ret = strncpy(allocator(index+1), fullname, index);
        ret[index] = 0;
        return ret;
    } else
        return strdup(fullname);
}

canonical_original_code:
char *fgetpath(char *fullname, void *(*allocator)(unsigned long)) {
    char *found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char *ret = strncpy(allocator(index+1), fullname, index);
        ret[index] = 0;
        return ret;
    } else
        return strdup(fullname);
}

variable_types:
fullname
char *

variable_types:
found
char *


fgetname

decompiled_code:
char *__fastcall fgetname(char *s, __int64 (__fastcall *a2)(size_t))
{
char *v2; // rax
__int64 v3; // rbx
size_t v4; // rax
char *v5; // rax

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (int)v2 - (int)s;
v4 = strlen(s);
v5 = (char *)a2(v4 - v3);
return strcpy(v5, &s[v3 + 1]);
}

canonical_decompiled_code:
char *__fastcall func4(char *s, __int64 (__fastcall *a2)(size_t))
{
char *v2; // rax
__int64 v3; // rbx
size_t v4; // rax
char *v5; // rax

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (int)v2 - (int)s;
v4 = strlen(s);
v5 = (char *)a2(v4 - v3);
return strcpy(v5, &s[v3 + 1]);
}

original_code:
char* fgetname (const char* fullname, void* (*allocator)(size_t)) {
    const char* found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char* ret = strcpy(allocator(strlen(fullname)-index), fullname+index+1);
        return ret;
    } else
        return strdup(fullname);
}

canonical_original_code:
char *fgetname(char *fullname, void *(*allocator)(unsigned long)) {
    char *found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char *ret = strcpy(allocator(strlen(fullname)-index), fullname+index+1);
        return ret;
    } else
        return strdup(fullname);
}

variable_types: index int


fstripname

original_code:
char* fstripname (const char* fullname, void* (*allocator)(size_t)) {
    char* stripped = allocator(strlen(fullname)+1);
    int copied = 0;
    for (const char *slash = fullname-1, *nextslash = strchr(fullname, '/');
         fullname;
         fullname = slash ? slash+1 : 0, slash = nextslash) {
        if (!slash) {
            strcpy(stripped+copied, fullname);
            copied += strlen(fullname);
        } else {
            nextslash = strchr(slash+1, '/');
            if ( slash[1] == '.' && slash[2] == '.'
                && (nextslash ? nextslash-slash == 3
                              : slash[3] == 0)) {
                fullname = slash+1;
                slash = nextslash;
            } else {
                int segmentLength = (int)(slash-fullname) + 1;
                strncpy(stripped+copied, fullname, segmentLength);
                copied += segmentLength;
            }
        }
    }
    stripped[copied] = 0;
    return stripped;
}

canonical_original_code:
char *fstripname(char *fullname, void *(*allocator)(unsigned long)) {
    char *stripped = allocator(strlen(fullname)+1);
    int copied = 0;
    for (char *slash = fullname-1; char *nextslash = strchr(fullname, '/');
         fullname;
         fullname = slash ? slash+1 : 0, slash = nextslash) {
        if (!slash) {
            strcpy(stripped+copied, fullname);
            copied += strlen(fullname);
        } else {
            nextslash = strchr(slash+1, '/');
            if ( slash[1] == '.' && slash[2] == '.'
                && (nextslash ? nextslash-slash == 3
                              : slash[3] == 0)) {
                fullname = slash+1;
                slash = nextslash;
            } else {
                int segmentLength = (int)(slash-fullname) + 1;
                strncpy(stripped+copied, fullname, segmentLength);
                copied += segmentLength;
            }
        }
    }
    stripped[copied] = 0;
    return stripped;
}

variable_types:
stripped
char *

variable_types: copied int

variable_types:
slash
char *

variable_types:
nextslash
char *

variable_types: segmentLength int


strjoinwith

decompiled_code:
char *__fastcall strjoinwith(const char **a1, int a2, const char *a3, __int64 (__fastcall *a4)(_QWORD))
{
int v5; // ebx
int v6; // er12
int v7; // er13
const char **v8; // rbx
__int64 v9; // r14
const char **v10; // rbp
char *v11; // rax
char *v12; // rbp
char *v14; // rax
char *src; // [rsp+8h] [rbp-40h]

if ( a2 <= 0 )
return (char *)calloc(1uLL, 1uLL);
v5 = strlen(a3);
src = (char *)*a1;
v6 = strlen(*a1);
v7 = (a2 - 1) * v5 + v6 + 1;
if ( a2 <= 1 )
{
v14 = (char *)a4(v7);
v12 = strcpy(v14, src);
}
else
{
v8 = a1 + 1;
v9 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
v10 = a1 + 1;
do
v7 += strlen(*v10++);
while ( v10 != (const char **)v9 );
v11 = (char *)a4(v7);
v12 = strcpy(v11, src);
do
v6 += sprintf(&v12[v6], "%s%s", a3, *v8++);
while ( v8 != (const char **)v9 );
}
return v12;
}

canonical_decompiled_code:
char *__fastcall func7(const char **a1, int a2, const char *a3, __int64 (__fastcall *a4)(_QWORD))
{
int v5; // ebx
int v6; // er12
int v7; // er13
const char **v8; // rbx
__int64 v9; // r14
const char **v10; // rbp
char *v11; // rax
char *v12; // rbp
char *v14; // rax
char *src; // [rsp+8h] [rbp-40h]

if ( a2 <= 0 )
return (char *)calloc(1uLL, 1uLL);
v5 = strlen(a3);
src = (char *)*a1;
v6 = strlen(*a1);
v7 = (a2 - 1) * v5 + v6 + 1;
if ( a2 <= 1 )
{
v14 = (char *)a4(v7);
v12 = strcpy(v14, src);
}
else
{
v8 = a1 + 1;
v9 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
v10 = a1 + 1;
do
v7 += strlen(*v10++);
while ( v10 != (const char **)v9 );
v11 = (char *)a4(v7);
v12 = strcpy(v11, src);
do
v6 += sprintf(&v12[v6], "%s%s", a3, *v8++);
while ( v8 != (const char **)v9 );
}
return v12;
}

original_code:
char* strjoinwith (char** strs, int n, const char* separator, void* (*allocator)(size_t)) {
    if (n <= 0)
        return calloc(1, sizeof(char));
    int seplen = strlen(separator),
        firstlen = strlen(strs[0]),
        length = firstlen + seplen*(n-1) + 1;
    for (int i = 1; i < n; i++)
        length += strlen(strs[i]);
    char* joined = strcpy(allocator(length), strs[0]);
    int charno = firstlen;
    for (int i = 1; i < n; i++)
        charno += sprintf(joined+charno, "%s%s", separator, strs[i]);
    return joined;
}

canonical_original_code:
char *strjoinwith(char **strs, int n, char *separator, void *(*allocator)(unsigned long)) {
    if (n <= 0)
        return calloc(1, sizeof(char));
    int seplen = strlen(separator); int firstlen = strlen(strs[0]); int length = firstlen + seplen*(n-1) + 1;
    for (int i = 1; i < n; i++)
        length += strlen(strs[i]);
    char *joined = strcpy(allocator(length), strs[0]);
    int charno = firstlen;
    for (int i = 1; i < n; i++)
        charno += sprintf(joined+charno, "%s%s", separator, strs[i]);
    return joined;
}

variable_types:
strs
char **

variable_types:
separator
char *

variable_types: seplen int

variable_types: firstlen int

variable_types: length int

variable_types: i int

variable_types:
joined
char *

variable_types: charno int


strjoin

decompiled_code:
char *__fastcall strjoin(const char **a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
return strjoinwith(a1, a2, (const char *)&unk_4E2, a3);
}

canonical_decompiled_code:
char *__fastcall func8(const char **a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
return func7(a1, a2, (const char *)&unk_4E2, a3);
}

original_code:
char* strjoin (char** strs, int n, void* (*allocator)(size_t)) {
    return strjoinwith(strs, n, "", allocator);
}

canonical_original_code:
char *strjoin(char **strs, int n, void *(*allocator)(unsigned long)) {
    return strjoinwith(strs, n, "", allocator);
}

variable_types: n int

variable_types:
allocator
void *(*)(unsigned long)


systemf

decompiled_code:
__int64 systemf(char *format, ...)
{
char *v1; // rbx
unsigned int v2; // ebp
unsigned int v3; // ebp
size_t v5; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = (char *)malloc(0x80uLL);
v2 = vsnprintf(v1, 0x80uLL, format, arg);
if ( v2 > 0x7F )
{
free(v1);
v5 = (int)(v2 + 1);
v1 = (char *)malloc(v5);
va_end(arg);
va_start(arg, format);
vsnprintf(v1, v5, format, arg);
}
v3 = system(v1);
free(v1);
return v3;
}

canonical_decompiled_code:
__int64 func9(char *format, ...)
{
char *v1; // rbx
unsigned int v2; // ebp
unsigned int v3; // ebp
size_t v5; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = (char *)malloc(0x80uLL);
v2 = vsnprintf(v1, 0x80uLL, format, arg);
if ( v2 > 0x7F )
{
free(v1);
v5 = (int)(v2 + 1);
v1 = (char *)malloc(v5);
va_end(arg);
va_start(arg, format);
vsnprintf(v1, v5, format, arg);
}
v3 = system(v1);
free(v1);
return v3;
}

original_code:
int systemf (const char* format, ...) {
    int size = 128;
    char* command = malloc(size);
    va_list args;
    __builtin_va_start(args,format);
    int length = vsnprintf(command, size, format, args);
    __builtin_va_end(args);
    if (length < 0 || length >= size) {
        free(command);
        command = malloc(size = length+1);
        __builtin_va_start(args,format);
        vsnprintf(command, size, format, args);
        __builtin_va_end(args);
    }
    int ret = system(command);
    free(command);
    return ret;
}

canonical_original_code:
int systemf(char *format, ...) {
    int size = 128;
    char *command = malloc(size);
    __builtin_va_list args;
    __builtin_va_start(args,format);
    int length = vsnprintf(command, size, format, args);
    __builtin_va_end(args);
    if (length < 0 || length >= size) {
        free(command);
        command = malloc(size = length+1);
        __builtin_va_start(args,format);
        vsnprintf(command, size, format, args);
        __builtin_va_end(args);
    }
    int ret = system(command);
    free(command);
    return ret;
}

variable_types:
format
char *

variable_types: size int

variable_types:
command
char *

variable_types: ret int


plural

decompiled_code:
void *__fastcall plural(int a1)
{
void *result; // rax

result = &unk_36F;
if ( a1 != 1 )
result = &unk_370;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = &unk_36F;
if ( a1 != 1 )
result = &unk_370;
return result;
}

original_code:
static const char* plural (int n) {
    return n == 1 ? "" : "s";
}

canonical_original_code:
static char *plural(int n) {
    return n == 1 ? "" : "s";
}


tokenTagGetStr

decompiled_code:
const char *__fastcall tokenTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "<undefined>";
if ( (_DWORD)a1 )
{
result = "other";
if ( (_DWORD)a1 != 1 )
{
result = "end of file";
if ( (_DWORD)a1 != 2 )
{
result = "keyword";
if ( (_DWORD)a1 != 3 )
{
result = "identifier";
if ( (_DWORD)a1 != 5 )
{
result = "integer";
if ( (_DWORD)a1 != 6 )
{
result = "string";
if ( (_DWORD)a1 != 7 )
{
result = "character";
if ( (_DWORD)a1 != 8 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("tokenTagGetStr", "token tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "<undefined>";
if ( (_DWORD)a1 )
{
result = "other";
if ( (_DWORD)a1 != 1 )
{
result = "end of file";
if ( (_DWORD)a1 != 2 )
{
result = "keyword";
if ( (_DWORD)a1 != 3 )
{
result = "identifier";
if ( (_DWORD)a1 != 5 )
{
result = "integer";
if ( (_DWORD)a1 != 6 )
{
result = "string";
if ( (_DWORD)a1 != 7 )
{
result = "character";
if ( (_DWORD)a1 != 8 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("tokenTagGetStr", "token tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
return result;
}

original_code:
static char* tokenTagGetStr (tokenTag tag) {
    if (tag == tokenUndefined) return "<undefined>";
    else if (tag == tokenOther) return "other";
    else if (tag == tokenEOF) return "end of file";
    else if (tag == tokenKeyword) return "keyword";
    else if (tag == tokenIdent) return "identifier";
    else if (tag == tokenInt) return "integer";
    else if (tag == tokenStr) return "string";
    else if (tag == tokenChar) return "character";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("tokenTagGetStr", "token tag", str);
        free(str);
        return "<unhandled>";
    }
}

canonical_original_code:
static char *tokenTagGetStr(enum tokenTag tag) {
    if (tag == tokenUndefined) return "<undefined>";
    else if (tag == tokenOther) return "other";
    else if (tag == tokenEOF) return "end of file";
    else if (tag == tokenKeyword) return "keyword";
    else if (tag == tokenIdent) return "identifier";
    else if (tag == tokenInt) return "integer";
    else if (tag == tokenStr) return "string";
    else if (tag == tokenChar) return "character";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("tokenTagGetStr", "token tag", str);
        free(str);
        return "<unhandled>";
    }
}

variable_types: enum tokenTag { tokenUndefined=0, tokenOther=1, tokenEOF=2, tokenKeyword=3, tokenPunct=4, tokenIdent=5, tokenInt=6, tokenStr=7, tokenChar=8 }

variable_types:
str
char *


parserFindFile

decompiled_code:
char *__fastcall parserFindFile(char *s, char *a2, _DWORD *a3)
{
int v4; // er15
int v5; // er12
size_t v6; // rax
char *v7; // rbx
const char *v8; // rax
const char *v9; // rbp
size_t v10; // rax

v4 = strlen(s);
if ( a2 && *a2 )
{
v6 = strlen(a2);
v7 = (char *)malloc(v4 + v6 + 2);
sprintf(v7, "%s/%s", a2, s);
if ( (unsigned int)fexists(v7) )
return v7;
free(v7);
}
v5 = *a3 - 1;
if ( v5 < 0 )
return 0LL;
while ( 1 )
{
v8 = (const char *)vectorGet(a3, (unsigned int)v5);
v9 = v8;
if ( *v8 )
{
v10 = strlen(v8);
v7 = (char *)malloc(v4 + v10 + 2);
sprintf(v7, "%s/%s", v9, s);
}
else
{
v7 = strdup(s);
}
if ( (unsigned int)fexists(v7) )
break;
free(v7);
if ( --v5 == -1 )
return 0LL;
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, char *a2, _DWORD *a3)
{
int v4; // er15
int v5; // er12
size_t v6; // rax
char *v7; // rbx
const char *v8; // rax
const char *v9; // rbp
size_t v10; // rax

v4 = strlen(s);
if ( a2 && *a2 )
{
v6 = strlen(a2);
v7 = (char *)malloc(v4 + v6 + 2);
sprintf(v7, "%s/%s", a2, s);
if ( (unsigned int)fexists(v7) )
return v7;
free(v7);
}
v5 = *a3 - 1;
if ( v5 < 0 )
return 0LL;
while ( 1 )
{
v8 = (const char *)vectorGet(a3, (unsigned int)v5);
v9 = v8;
if ( *v8 )
{
v10 = strlen(v8);
v7 = (char *)malloc(v4 + v10 + 2);
sprintf(v7, "%s/%s", v9, s);
}
else
{
v7 = strdup(s);
}
if ( (unsigned int)fexists(v7) )
break;
free(v7);
if ( --v5 == -1 )
return 0LL;
}
return v7;
}

original_code:
static char* parserFindFile (const char* filename, const char* initialPath, const vector * searchPaths) {
    int filenameLength = strlen(filename);
    if (initialPath && initialPath[0]) {
        char* fullname = malloc(strlen(initialPath)+1+filenameLength+1);
        sprintf(fullname, "%s/%s", initialPath, filename);
        if (fexists(fullname))
            return fullname;
        else
            free(fullname);
    }
    for (int i = searchPaths->length-1; i >= 0; i--) {
        const char* path = vectorGet(searchPaths, i);
        char* fullname;
        if (path[0]) {
            fullname = malloc(strlen(path)+1+filenameLength+1);
            sprintf(fullname, "%s/%s", path, filename);
        } else
            fullname = strdup(filename);
        if (fexists(fullname))
            return fullname;
        else
            free(fullname);
    }
    return 0;
}

canonical_original_code:
static char *parserFindFile(char *filename, char *initialPath, struct vector *searchPaths) {
    int filenameLength = strlen(filename);
    if (initialPath && initialPath[0]) {
        char *fullname = malloc(strlen(initialPath)+1+filenameLength+1);
        sprintf(fullname, "%s/%s", initialPath, filename);
        if (fexists(fullname))
            return fullname;
        else
            free(fullname);
    }
    for (int i = searchPaths->length-1; i >= 0; i--) {
        char *path = vectorGet(searchPaths, i);
        char *fullname;
        if (path[0]) {
            fullname = malloc(strlen(path)+1+filenameLength+1);
            sprintf(fullname, "%s/%s", path, filename);
        } else
            fullname = strdup(filename);
        if (fexists(fullname))
            return fullname;
        else
            free(fullname);
    }
    return 0;
}

variable_types:
filename
char *

variable_types:
initialPath
char *

variable_types: struct vector { int length; void **buffer; } *

variable_types: filenameLength int

variable_types:
fullname
char *

variable_types:
path
char *


main

canonical_name: main

repo: FelipeEcker/touch

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
const char *v5; // rdi
struct utimbuf v7; // [rsp+0h] [rbp-28h] BYREF

if ( argc <= 1 )
{
fwrite("\nTouch v0.3 - Felipe Ecker (Khun)\n", 1uLL, 0x22uLL, stderr);
fprintf(stderr, "Use: \n%s <file>\n%s *\n%s dir/*\n\n", *argv, *argv, *argv);
}
else
{
v4 = argv + 1;
v5 = argv[1];
if ( v5 )
{
do
{
fopen(v5, "a+");
v7.modtime = time(0LL);
utime(*v4++, &v7);
v5 = *v4;
}
while ( *v4 );
}
}
return argc;
}

original_code:
int main (signed int index, char **__files) {
 if ((index | 0x00) < 0x02) {
  fprintf(stderr,"\nTouch v0.3 - Felipe Ecker (Khun)\n");
  fprintf(stderr,"Use: \n%s <file>\n%s *\n%s dir/*\n\n", *__files, *__files, *__files);
  goto __END;
 } else __files++;
 struct utimbuf _utbuff;
 while (*__files) {
  fopen(*__files, "a+");
  _utbuff.modtime = time(((void *)0));
  utime(*__files++, &_utbuff);
 }
__END:
 return index;
}

canonical_original_code:
int main(int index, char **__files) {
 if ((index | 0x00) < 0x02) {
  fprintf(stderr,"\nTouch v0.3 - Felipe Ecker (Khun)\n");
  fprintf(stderr,"Use: \n%s <file>\n%s *\n%s dir/*\n\n", *__files, *__files, *__files);
  goto __END;
 } else __files++;
 struct utimbuf _utbuff;
 while (*__files) {
  fopen(*__files, "a+");
  _utbuff.modtime = time(((void *)0));
  utime(*__files++, &_utbuff);
 }
__END:
 return index;
}

variable_types: index int

variable_types: struct utimbuf { long actime; long modtime; }


repo: Felttrip/Compilers

decompiled_code:
int __fastcall Stack_Push(__int64 a1, int a2)
{
int result; // eax

result = *(_DWORD *)(a1 + 400);
if ( result > 99 )
return puts("Error, stack is full");
*(_DWORD *)(a1 + 400) = result + 1;
*(_DWORD *)(a1 + 4LL * result) = a2;
return result;
}

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

result = *(_DWORD *)(a1 + 400);
if ( result > 99 )
return puts("Error, stack is full");
*(_DWORD *)(a1 + 400) = result + 1;
*(_DWORD *)(a1 + 4LL * result) = a2;
return result;
}

original_code:
void Stack_Push(Stack *s, int d)
{
      if(s->size < 100)
            s->data[s->size++] = d;
      else
            printf("Error, stack is full\n");
}

canonical_original_code:
void Stack_Push(struct _Stack *s, int d)
{
      if(s->size < 100)
            s->data[s->size++] = d;
      else
            printf("Error, stack is full\n");
}

variable_types: struct _Stack { int data[100]; int size; } *

variable_types: d int


original_code:
int Stack_Pop(Stack *s, int d)
{
      if(s->size<=0)
      {
            printf("Error, attempting to pop an empty stack\n");
            return -1;
      }
      switch(d)
      {
            case RPAREN:
            {
                  if(s->data[s->size-1]==LPAREN)
                  {
                        s->size--;
                        return 0;
                  }
                  else
                        return 1;
            }
            case RCURLY:
            {
                  if(s->data[s->size-1]==LCURLY)
                  {
                        s->size--;
                        return 0;
                  }
                  else
                        return 1;
            }
            case RSQUARE:
            {
                  if(s->data[s->size-1]==LSQUARE)
                  {
                        s->size--;
                        return 0;
                  }
                  else
                        return 1;
            }
            default:
                  return -1;
      }
}

canonical_original_code:
int Stack_Pop(struct _Stack *s, int d)
{
      if(s->size<=0)
      {
            printf("Error, attempting to pop an empty stack\n");
            return -1;
      }
      switch(d)
      {
            case RPAREN:
            {
                  if(s->data[s->size-1]==LPAREN)
                  {
                        s->size--;
                        return 0;
                  }
                  else
                        return 1;
            }
            case RCURLY:
            {
                  if(s->data[s->size-1]==LCURLY)
                  {
                        s->size--;
                        return 0;
                  }
                  else
                        return 1;
            }
            case RSQUARE:
            {
                  if(s->data[s->size-1]==LSQUARE)
                  {
                        s->size--;
                        return 0;
                  }
                  else
                        return 1;
            }
            default:
                  return -1;
      }
}

user_defined_types: struct _Stack { int data[100]; int size; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
__int64 v5; // r13
unsigned int v6; // er12
int v7; // er14
int v8; // er15
unsigned int i; // ebx
int v10; // eax
unsigned int v11; // ebp
int v12; // eax
const char *v13; // rsi
const char *v14; // rsi
int v15; // [rsp+4h] [rbp-44h]
const char *v16; // [rsp+8h] [rbp-40h]
const char *v17; // [rsp+8h] [rbp-40h]

v3 = malloc(0x194uLL);
v3[100] = 0;
if ( argc == 2 )
{
v5 = (__int64)v3;
yyin = fopen(argv[1], "r");
if ( yyin )
{
v15 = -1;
v6 = 1;
v7 = 0;
v8 = 0;
for ( i = 0; ; i = v11 )
{
v10 = yylex();
if ( !v10 )
break;
v11 = i + 1;
switch ( v10 )
{
case 256:
v16 = yytext;
if ( strlen(yytext) > 0x20 )
{
printf("ID %s too long, ID not counted\n", v16);
v11 = i;
}
break;
case 257:
if ( atoi(yytext) < 0 )
{
puts("Error invalid number");
v11 = i;
}
break;
case 258:
v17 = yytext;
if ( strlen(yytext) > 0xFF )
{
printf("String Literal %s too long, String Literal not counted\n", v17);
v11 = i;
}
break;
case 264:
Stack_Push(v5, 264);
break;
case 265:
if ( !v7 )
v7 = Stack_Pop(v5, 265);
break;
case 266:
Stack_Push(v5, 266);
break;
case 267:
if ( !v7 )
v7 = Stack_Pop(v5, 267);
break;
case 268:
Stack_Push(v5, 268);
break;
case 269:
if ( !v7 )
v7 = Stack_Pop(v5, 269);
break;
case 287:
while ( 1 )
{
v12 = yylex();
if ( v12 == 288 )
break;
v6 += v12 == 302;
}
v11 = i;
break;
case 299:
if ( i == v15 )
v8 = 1;
break;
case 300:
v15 = i + 1;
break;
case 302:
++v6;
v11 = i;
break;
case 303:
printf(" on line %d\n", v6);
v11 = i;
break;
default:
continue;
}
}
printf("Total tokens: %d\n", i);
v13 = "yes";
if ( !v8 )
v13 = "no";
printf("Main declared: %s\n", v13);
v14 = "no";
if ( !v7 )
v14 = "yes";
printf("All brackets match: %s\n", v14);
}
else
{
printf("file unreadable");
}
}
else
{
puts("Error, incorrect usage, pa1 <FILE.lig>");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
__int64 v5; // r13
unsigned int v6; // er12
int v7; // er14
int v8; // er15
unsigned int i; // ebx
int v10; // eax
unsigned int v11; // ebp
int v12; // eax
const char *v13; // rsi
const char *v14; // rsi
int v15; // [rsp+4h] [rbp-44h]
const char *v16; // [rsp+8h] [rbp-40h]
const char *v17; // [rsp+8h] [rbp-40h]

v3 = malloc(0x194uLL);
v3[100] = 0;
if ( argc == 2 )
{
v5 = (__int64)v3;
yyin = fopen(argv[1], "r");
if ( yyin )
{
v15 = -1;
v6 = 1;
v7 = 0;
v8 = 0;
for ( i = 0; ; i = v11 )
{
v10 = yylex();
if ( !v10 )
break;
v11 = i + 1;
switch ( v10 )
{
case 256:
v16 = yytext;
if ( strlen(yytext) > 0x20 )
{
printf("ID %s too long, ID not counted\n", v16);
v11 = i;
}
break;
case 257:
if ( atoi(yytext) < 0 )
{
puts("Error invalid number");
v11 = i;
}
break;
case 258:
v17 = yytext;
if ( strlen(yytext) > 0xFF )
{
printf("String Literal %s too long, String Literal not counted\n", v17);
v11 = i;
}
break;
case 264:
func0(v5, 264);
break;
case 265:
if ( !v7 )
v7 = func1(v5, 265);
break;
case 266:
func0(v5, 266);
break;
case 267:
if ( !v7 )
v7 = func1(v5, 267);
break;
case 268:
func0(v5, 268);
break;
case 269:
if ( !v7 )
v7 = func1(v5, 269);
break;
case 287:
while ( 1 )
{
v12 = yylex();
if ( v12 == 288 )
break;
v6 += v12 == 302;
}
v11 = i;
break;
case 299:
if ( i == v15 )
v8 = 1;
break;
case 300:
v15 = i + 1;
break;
case 302:
++v6;
v11 = i;
break;
case 303:
printf(" on line %d\n", v6);
v11 = i;
break;
default:
continue;
}
}
printf("Total tokens: %d\n", i);
v13 = "yes";
if ( !v8 )
v13 = "no";
printf("Main declared: %s\n", v13);
v14 = "no";
if ( !v7 )
v14 = "yes";
printf("All brackets match: %s\n", v14);
}
else
{
printf("file unreadable");
}
}
else
{
puts("Error, incorrect usage, pa1 <FILE.lig>");
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
      char *fname;
      int tok;
      int numTok = 0;
      int mainFlag = 0;
      int brackFlag = 0;
      int lineNum = 1;
      int lastTok = -1;
      Stack *bracketStack = malloc(sizeof(Stack));
      bracketStack->size = 0;
      if(argc != 2)
      {
       printf("Error, incorrect usage, pa1 <FILE.lig>\n");
       return 0;
      }
      fname = argv[1];
      yyin = fopen(fname,"r");
      if(yyin == ((void *)0))
      {
       printf("file unreadable");
       return 0;
      }
      for(;;)
      {
            tok = yylex();
            if(tok==0)
                  break;
            numTok++;
            switch(tok)
            {
                  case FUNCTION:
                  {
                        lastTok = numTok;
                        break;
                  }
                  case MAIN:
                  {
                        if(lastTok == (numTok-1))
                        {
                              mainFlag = 1;
                        }
                        break;
                  }
                  case LPAREN:
                  {
                        Stack_Push(bracketStack,LPAREN);
                        break;
                  }
                  case RPAREN:
                  {
                        if(!brackFlag)
                              brackFlag = Stack_Pop(bracketStack,RPAREN);
                        break;
                  }
                  case LCURLY:
                  {
                        Stack_Push(bracketStack,LCURLY);
                        break;
                  }
                  case RCURLY:
                  {
                        if(!brackFlag)
                              brackFlag = Stack_Pop(bracketStack,RCURLY);
                        break;
                  }
                  case LSQUARE:
                  {
                        Stack_Push(bracketStack,LSQUARE);
                        break;
                  }
                  case RSQUARE:
                  {
                        if(!brackFlag)
                              brackFlag = Stack_Pop(bracketStack,RSQUARE);
                        break;
                  }
                  case LMULTICOMMENT:
                  {
                        numTok--;
                        while(RMULTICOMMENT != (tok = yylex()))
                        {
                              if(tok==NEWLINE)
                                    lineNum++;
                        }
                        break;
                  }
                  case NEWLINE:
                  {
                        numTok--;
                        lineNum++;
                        break;
                  }
                  case BADTOKEN:
                  {
                        numTok--;
                        printf(" on line %d\n",lineNum);
                        break;
                  }
                  case ID:
                  {
                        if(strlen(yytext)>32)
                        {
                              numTok--;
                              printf("ID %s too long, ID not counted\n",yytext);
                        }
                        break;
                  }
                  case STR:
                  {
                        if(strlen(yytext)>255)
                        {
                              numTok--;
                              printf("String Literal %s too long, String Literal not counted\n",yytext);
                        }
                        break;
                  }
                  case NUM:
                  {
                        if((atoi(yytext)<0)||(atoi(yytext)>(pow(2,32)-1)))
                        {
                              numTok--;
                              printf("Error invalid number\n");
                        }
                  }
            }
      }
      printf("Total tokens: %d\n",numTok);
      printf("Main declared: %s\n",mainFlag?"yes":"no");
      printf("All brackets match: %s\n",brackFlag?"no":"yes");
      return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
      char *fname;
      int tok;
      int numTok = 0;
      int mainFlag = 0;
      int brackFlag = 0;
      int lineNum = 1;
      int lastTok = -1;
      struct _Stack *bracketStack = malloc(sizeof(Stack));
      bracketStack->size = 0;
      if(argc != 2)
      {
       printf("Error, incorrect usage, pa1 <FILE.lig>\n");
       return 0;
      }
      fname = argv[1];
      yyin = fopen(fname,"r");
      if(yyin == ((void *)0))
      {
       printf("file unreadable");
       return 0;
      }
      for(;;)
      {
            tok = yylex();
            if(tok==0)
                  break;
            numTok++;
            switch(tok)
            {
                  case FUNCTION:
                  {
                        lastTok = numTok;
                        break;
                  }
                  case MAIN:
                  {
                        if(lastTok == (numTok-1))
                        {
                              mainFlag = 1;
                        }
                        break;
                  }
                  case LPAREN:
                  {
                        Stack_Push(bracketStack,LPAREN);
                        break;
                  }
                  case RPAREN:
                  {
                        if(!brackFlag)
                              brackFlag = Stack_Pop(bracketStack,RPAREN);
                        break;
                  }
                  case LCURLY:
                  {
                        Stack_Push(bracketStack,LCURLY);
                        break;
                  }
                  case RCURLY:
                  {
                        if(!brackFlag)
                              brackFlag = Stack_Pop(bracketStack,RCURLY);
                        break;
                  }
                  case LSQUARE:
                  {
                        Stack_Push(bracketStack,LSQUARE);
                        break;
                  }
                  case RSQUARE:
                  {
                        if(!brackFlag)
                              brackFlag = Stack_Pop(bracketStack,RSQUARE);
                        break;
                  }
                  case LMULTICOMMENT:
                  {
                        numTok--;
                        while(RMULTICOMMENT != (tok = yylex()))
                        {
                              if(tok==NEWLINE)
                                    lineNum++;
                        }
                        break;
                  }
                  case NEWLINE:
                  {
                        numTok--;
                        lineNum++;
                        break;
                  }
                  case BADTOKEN:
                  {
                        numTok--;
                        printf(" on line %d\n",lineNum);
                        break;
                  }
                  case ID:
                  {
                        if(strlen(yytext)>32)
                        {
                              numTok--;
                              printf("ID %s too long, ID not counted\n",yytext);
                        }
                        break;
                  }
                  case STR:
                  {
                        if(strlen(yytext)>255)
                        {
                              numTok--;
                              printf("String Literal %s too long, String Literal not counted\n",yytext);
                        }
                        break;
                  }
                  case NUM:
                  {
                        if((atoi(yytext)<0)||(atoi(yytext)>(pow(2,32)-1)))
                        {
                              numTok--;
                              printf("Error invalid number\n");
                        }
                  }
            }
      }
      printf("Total tokens: %d\n",numTok);
      printf("Main declared: %s\n",mainFlag?"yes":"no");
      printf("All brackets match: %s\n",brackFlag?"no":"yes");
      return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fname
char *

variable_types: tok int

variable_types: numTok int

variable_types: mainFlag int

variable_types: brackFlag int

variable_types: lineNum int

variable_types: lastTok int


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void yyerror(const char* p) {
      fprintf(stderr, "%s\n", p);
}

canonical_original_code:
void yyerror(char *p) {
      fprintf(stderr, "%s\n", p);
}

variable_types:
p
char *


yyparse

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 5)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-26))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 280 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 5 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 29;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 5 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 280 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-26))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 5 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 280 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 5)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-26))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 280 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 5 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 29;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 5 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 280 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-26))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 5 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 280 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types:
yyvsa
union YYSTYPE { int val; } [200]

variable_types:
yyvs
union YYSTYPE { int val; } *

variable_types:
yyvsp
union YYSTYPE { int val; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types:
yyval
union YYSTYPE { int val; }

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { int val; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }


repo: Femaref/emerald

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

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
return result;
}

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

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
return result;
}

original_code:
matrix4* malloc_matrix() {
  matrix4 *output = malloc(16*sizeof(float));
  memset(output, 0, 16*sizeof(float));
  return output;
}

canonical_original_code:
struct matrix4 *malloc_matrix() {
  struct matrix4 *output = malloc(16*sizeof(float));
  memset(output, 0, 16*sizeof(float));
  return output;
}

variable_types:
output
struct matrix4 { float data[16]; } *

return_type: struct matrix4 { float data[16]; } *


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
vector* malloc_vector() {
  vector *output = malloc(4*sizeof(float));
  memset(output, 0, 4*sizeof(float));
  return output;
}

canonical_original_code:
struct vector *malloc_vector() {
  struct vector *output = malloc(4*sizeof(float));
  memset(output, 0, 4*sizeof(float));
  return output;
}

variable_types:
output
struct vector { float data[4]; } *

return_type: struct vector { float data[4]; } *


original_code:
void copy_matrix(matrix4 *dst, matrix4 *src) {
  memcpy(dst, src, 16*sizeof(float));
}

canonical_original_code:
void copy_matrix(struct matrix4 *dst, struct matrix4 *src) {
  memcpy(dst, src, 16*sizeof(float));
}

variable_types:
dst
struct matrix4 { float data[16]; } *

variable_types:
src
struct matrix4 *


decompiled_code:
void __fastcall copy_vector(__m128i *a1, const __m128i *a2)
{
*a1 = _mm_loadu_si128(a2);
}

canonical_decompiled_code:
void __fastcall func3(__m128i *a1, const __m128i *a2)
{
*a1 = _mm_loadu_si128(a2);
}

original_code:
void copy_vector(vector *dst, vector *src) {
  memcpy(dst, src, 4*sizeof(float));
}

canonical_original_code:
void copy_vector(struct vector *dst, struct vector *src) {
  memcpy(dst, src, 4*sizeof(float));
}

variable_types:
dst
struct vector { float data[4]; } *

variable_types:
src
struct vector *


decompiled_code:
void __fastcall translate4(float *a1, float a2, float a3, float a4)
{
a1[3] = a2 + a1[3];
a1[7] = a3 + a1[7];
a1[11] = a4 + a1[11];
}

original_code:
void translate4(matrix4 *matrix, float x, float y, float z) {
  matrix->data[3] += x;
  matrix->data[7] += y;
  matrix->data[11] += z;
}

canonical_original_code:
void translate4(struct matrix4 *matrix, float x, float y, float z) {
  matrix->data[3] += x;
  matrix->data[7] += y;
  matrix->data[11] += z;
}

variable_types:
matrix
struct matrix4 { float data[16]; } *

variable_types: x float

variable_types: y float

variable_types: z float


normalize

decompiled_code:
void __fastcall normalize(__int64 a1)
{
float v1; // xmm3_4
float v2; // xmm2_4
float v3; // xmm0_4

v1 = *(float *)(a1 + 4);
v2 = *(float *)(a1 + 8);
v3 = COERCE_FLOAT(*(_DWORD *)a1 & LC1) + COERCE_FLOAT(*(_DWORD *)(a1 + 4) & LC1) + COERCE_FLOAT(LC1 & LODWORD(v2));
*(float *)a1 = *(float *)a1 / v3;
*(float *)(a1 + 4) = v1 / v3;
*(float *)(a1 + 8) = v2 / v3;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
float v1; // xmm3_4
float v2; // xmm2_4
float v3; // xmm0_4

v1 = *(float *)(a1 + 4);
v2 = *(float *)(a1 + 8);
v3 = COERCE_FLOAT(*(_DWORD *)a1 & LC1) + COERCE_FLOAT(*(_DWORD *)(a1 + 4) & LC1) + COERCE_FLOAT(LC1 & LODWORD(v2));
*(float *)a1 = *(float *)a1 / v3;
*(float *)(a1 + 4) = v1 / v3;
*(float *)(a1 + 8) = v2 / v3;
}

original_code:
void normalize(vector *vec) {
  float total = fabs(vec->data[0]) + fabs(vec->data[1]) + fabs(vec->data[2]);
  vec->data[0] /= total;
  vec->data[1] /= total;
  vec->data[2] /= total;
}

canonical_original_code:
void normalize(struct vector *vec) {
  float total = fabs(vec->data[0]) + fabs(vec->data[1]) + fabs(vec->data[2]);
  vec->data[0] /= total;
  vec->data[1] /= total;
  vec->data[2] /= total;
}

variable_types:
vec
struct vector { float data[4]; } *

variable_types: total float


scale

original_code:
void scale(vector *vec, float scalar) {
  vec->data[0] *= scalar;
  vec->data[1] *= scalar;
  vec->data[2] *= scalar;
}

canonical_original_code:
void scale(struct vector *vec, float scalar) {
  vec->data[0] *= scalar;
  vec->data[1] *= scalar;
  vec->data[2] *= scalar;
}

variable_types: scalar float


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

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

original_code:
void free4(matrix4 *matrix) {
  free(matrix);
}

canonical_original_code:
void free4(struct matrix4 *matrix) {
  free(matrix);
}


multiply

decompiled_code:
float *__fastcall multiply(void *a1, float *a2, __int64 a3)
{
float *v4; // rax
float *v6; // r9
int i; // er10
float *v8; // rsi
float *v9; // rcx
int j; // edi
float *result; // rax
float *v12; // rdx

free4(a1);
v4 = (float *)malloc_matrix();
v6 = v4;
for ( i = 0; i != 16; i += 4 )
{
v8 = (float *)(a3 + 64);
v9 = v6;
for ( j = 0; j != 4; ++j )
{
result = v8 - 16;
v12 = a2;
do
{
*v9 = (float)(*v12++ * *result) + *v9;
result += 4;
}
while ( result != v8 );
++v9;
++v8;
}
a2 += 4;
v6 += 4;
}
return result;
}

canonical_decompiled_code:
float *__fastcall func9(void *a1, float *a2, __int64 a3)
{
float *v4; // rax
float *v6; // r9
int i; // er10
float *v8; // rsi
float *v9; // rcx
int j; // edi
float *result; // rax
float *v12; // rdx

func8(a1);
v4 = (float *)func0();
v6 = v4;
for ( i = 0; i != 16; i += 4 )
{
v8 = (float *)(a3 + 64);
v9 = v6;
for ( j = 0; j != 4; ++j )
{
result = v8 - 16;
v12 = a2;
do
{
*v9 = (float)(*v12++ * *result) + *v9;
result += 4;
}
while ( result != v8 );
++v9;
++v8;
}
a2 += 4;
v6 += 4;
}
return result;
}

original_code:
void multiply(matrix4 *output, matrix4 *a, matrix4 *b) {
  free4(output);
  output = malloc_matrix();
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 4; j++) {
      for(int k = 0; k < 4; k++) {
        output->data[i*4 + j] += a->data[i*4 + k]*b->data[k*4 + j];
      }
    }
  }
}

canonical_original_code:
void multiply(struct matrix4 *output, struct matrix4 *a, struct matrix4 *b) {
  free4(output);
  output = malloc_matrix();
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 4; j++) {
      for(int k = 0; k < 4; k++) {
        output->data[i*4 + j] += a->data[i*4 + k]*b->data[k*4 + j];
      }
    }
  }
}

variable_types:
a
struct matrix4 *

variable_types:
b
struct matrix4 *

variable_types: i int

variable_types: j int

variable_types: k int


original_code:
void rotate4x(matrix4 *matrix, float degree) {
  float rad = degree*(3.14125/180);
  matrix4 rot = {{
    1.0, 0.0, 0.0, 0.0,
    0.0, cos(rad), -sin(rad), 0.0,
    0.0, sin(rad), cos(rad), 0.0,
    0.0, 0.0, 0.0, 1.0
  }};
  matrix4 *temp = malloc_matrix();
  memcpy(temp, matrix, 16*sizeof(float));
  multiply(matrix, &rot, temp);
  free4(temp);
}

canonical_original_code:
void rotate4x(struct matrix4 *matrix, float degree) {
  float rad = degree*(3.14125/180);
  struct matrix4 rot = {{
    1.0, 0.0, 0.0, 0.0,
    0.0, cos(rad), -sin(rad), 0.0,
    0.0, sin(rad), cos(rad), 0.0,
    0.0, 0.0, 0.0, 1.0
  }};
  struct matrix4 *temp = malloc_matrix();
  memcpy(temp, matrix, 16*sizeof(float));
  multiply(matrix, &rot, temp);
  free4(temp);
}

variable_types: degree float

variable_types: rad float

variable_types:
rot
struct matrix4 { float data[16]; }

variable_types:
temp
struct matrix4 { float data[16]; } *


original_code:
void rotate4y(matrix4 *matrix, float degree) {
  float rad = degree*(3.14125/180);
  matrix4 rot = {{
    cos(rad), 0.0, sin(rad), 0.0,
    0.0, 1.0, 0.0, 0.0,
    -sin(rad), 0.0, cos(rad), 0.0,
    0.0, 0.0, 0.0, 1.0
  }};
  matrix4 *temp = malloc_matrix();
  memcpy(temp, matrix, 16*sizeof(float));
  multiply(matrix, &rot, temp);
  free4(temp);
}

canonical_original_code:
void rotate4y(struct matrix4 *matrix, float degree) {
  float rad = degree*(3.14125/180);
  struct matrix4 rot = {{
    cos(rad), 0.0, sin(rad), 0.0,
    0.0, 1.0, 0.0, 0.0,
    -sin(rad), 0.0, cos(rad), 0.0,
    0.0, 0.0, 0.0, 1.0
  }};
  struct matrix4 *temp = malloc_matrix();
  memcpy(temp, matrix, 16*sizeof(float));
  multiply(matrix, &rot, temp);
  free4(temp);
}


original_code:
void rotate4z(matrix4 *matrix, float degree) {
  float rad = degree*(3.14125/180);
  matrix4 rot = {{
    cos(rad), -sin(rad), 0.0, 0.0,
    sin(rad), cos(rad), 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0
  }};
  matrix4 *temp = malloc_matrix();
  memcpy(temp, matrix, 16*sizeof(float));
  multiply(matrix, &rot, temp);
  free4(temp);
}

canonical_original_code:
void rotate4z(struct matrix4 *matrix, float degree) {
  float rad = degree*(3.14125/180);
  struct matrix4 rot = {{
    cos(rad), -sin(rad), 0.0, 0.0,
    sin(rad), cos(rad), 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0
  }};
  struct matrix4 *temp = malloc_matrix();
  memcpy(temp, matrix, 16*sizeof(float));
  multiply(matrix, &rot, temp);
  free4(temp);
}


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

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

original_code:
void free_vector(vector *vec) {
  free(vec);
}

canonical_original_code:
void free_vector(struct vector *vec) {
  free(vec);
}


apply

original_code:
void apply(vector *vec, matrix4 *matrix) {
  vector *output = malloc_vector();
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 1; j++) {
      for(int k = 0; k < 4; k++) {
        output->data[i] += (matrix->data[i*4 + k])*(vec->data[k]);
      }
    }
  }
  copy_vector(vec, output);
  free_vector(output);
}

canonical_original_code:
void apply(struct vector *vec, struct matrix4 *matrix) {
  struct vector *output = malloc_vector();
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 1; j++) {
      for(int k = 0; k < 4; k++) {
        output->data[i] += (matrix->data[i*4 + k])*(vec->data[k]);
      }
    }
  }
  copy_vector(vec, output);
  free_vector(output);
}

variable_types:
output
struct vector { float data[4]; } *

user_defined_types:
struct vector { float data[4]; }
struct matrix4 { float data[16]; }


rotate

decompiled_code:
void __fastcall rotate(__m128i *a1, float a2, float a3, float a4)
{
__m128i *v4; // rbx

v4 = (__m128i *)malloc_matrix();
identity4(v4);
rotate4z(v4, a4);
rotate4y(v4, a3);
rotate4x(v4, a2);
apply(a1, (__int64)v4);
normalize((__int64)a1);
free4(v4);
}

original_code:
void rotate(vector *vector, float pitch, float yaw, float roll) {
  matrix4 *matrix = malloc_matrix();
  identity4(matrix);
  rotate4z(matrix, roll);
  rotate4y(matrix, yaw);
  rotate4x(matrix, pitch);
  apply(vector, matrix);
  normalize(vector);
  free4(matrix);
}

canonical_original_code:
void rotate(struct vector *vector, float pitch, float yaw, float roll) {
  struct matrix4 *matrix = malloc_matrix();
  identity4(matrix);
  rotate4z(matrix, roll);
  rotate4y(matrix, yaw);
  rotate4x(matrix, pitch);
  apply(vector, matrix);
  normalize(vector);
  free4(matrix);
}

variable_types:
vector
struct vector { float data[4]; } *

variable_types: pitch float

variable_types: yaw float

variable_types: roll float

variable_types:
matrix
struct matrix4 { float data[16]; } *


decompiled_code:
int __fastcall print_matrix(__int64 a1)
{
unsigned int i; // ebx
float *v2; // rbp
unsigned int j; // er12
float *v4; // rbx
int result; // eax

printf(" |");
for ( i = 0; i != 4; ++i )
printf(" %d|", i);
putchar(10);
v2 = (float *)(a1 + 16);
for ( j = 0; j != 4; ++j )
{
printf("%d|", j);
v4 = v2 - 4;
do
printf("%+3.8f|", *v4++);
while ( v4 != v2 );
result = putchar(10);
v2 += 4;
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1)
{
unsigned int i; // ebx
float *v2; // rbp
unsigned int j; // er12
float *v4; // rbx
int result; // eax

printf(" |");
for ( i = 0; i != 4; ++i )
printf(" %d|", i);
putchar(10);
v2 = (float *)(a1 + 16);
for ( j = 0; j != 4; ++j )
{
printf("%d|", j);
v4 = v2 - 4;
do
printf("%+3.8f|", *v4++);
while ( v4 != v2 );
result = putchar(10);
v2 += 4;
}
return result;
}

original_code:
void print_matrix(matrix4 *matrix) {
  printf(" |");
  for(int i = 0; i < 4; i++) {
    printf("          %d|", i);
  }
  printf("\n");
  for(int i = 0; i < 4; i++) {
    printf("%d|", i);
    for(int j = 0; j < 4; j++) {
      printf("%+3.8f|", matrix->data[i*4 + j]);
    }
    printf("\n");
  }
}

canonical_original_code:
void print_matrix(struct matrix4 *matrix) {
  printf(" |");
  for(int i = 0; i < 4; i++) {
    printf("          %d|", i);
  }
  printf("\n");
  for(int i = 0; i < 4; i++) {
    printf("%d|", i);
    for(int j = 0; j < 4; j++) {
      printf("%+3.8f|", matrix->data[i*4 + j]);
    }
    printf("\n");
  }
}


decompiled_code:
int __fastcall print_vector(__int64 a1)
{
__int64 i; // rbx
int result; // eax

printf(" |");
putchar(10);
for ( i = 0LL; i != 4; ++i )
{
printf("%d|", (unsigned int)i);
printf("%+3.8f|", *(float *)(a1 + 4 * i));
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1)
{
__int64 i; // rbx
int result; // eax

printf(" |");
putchar(10);
for ( i = 0LL; i != 4; ++i )
{
printf("%d|", (unsigned int)i);
printf("%+3.8f|", *(float *)(a1 + 4 * i));
result = putchar(10);
}
return result;
}

original_code:
void print_vector(vector *vec) {
  printf(" |");
  printf("\n");
  for(int i = 0; i < 4; i++) {
    printf("%d|", i);
    printf("%+3.8f|", vec->data[i]);
    printf("\n");
  }
}

canonical_original_code:
void print_vector(struct vector *vec) {
  printf(" |");
  printf("\n");
  for(int i = 0; i < 4; i++) {
    printf("%d|", i);
    printf("%+3.8f|", vec->data[i]);
    printf("\n");
  }
}

variable_types:
vec
struct vector { float data[4]; } *


variable_types: struct model_type { struct vertex_type { float x; } vertex[2000]; struct polygon_type { int a; } polygon[2000]; }

variable_types: struct camera_type { float pitch; float x; }

user_defined_types: struct model_type { struct vertex_type vertex[2000]; struct polygon_type polygon[2000]; }


decompiled_code:
size_t __fastcall elog_get_time(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
return strftime(s, 0x1EuLL, "[%Y-%m-%d %H:%M:%S %z]", v1);
}

canonical_decompiled_code:
size_t __fastcall func0(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
return strftime(s, 0x1EuLL, "[%Y-%m-%d %H:%M:%S %z]", v1);
}

original_code:
void elog_get_time(char *s) {
    time_t t;
    struct tm *tm;
    t = time(((void *)0));
    tm = localtime(&t);
    strftime(s, 30, "[%Y-%m-%d %H:%M:%S %z]", tm);
}

canonical_original_code:
void elog_get_time(char *s) {
    long t;
    struct tm *tm;
    t = time(((void *)0));
    tm = localtime(&t);
    strftime(s, 30, "[%Y-%m-%d %H:%M:%S %z]", tm);
}

variable_types:
s
char *

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
__int64 __fastcall dataframe_neptr(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 - 8) + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 - 8) + 8LL);
}

original_code:
static int dataframe_neptr(int **df)
{
    return df[-1][2];
}

variable_types:
df
int **


decompiled_code:
__int64 __fastcall dataframe_elmcnt(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 - 8) + 12LL);
}

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

original_code:
static int dataframe_elmcnt(int **df)
{
    return df[-1][3];
}


decompiled_code:
int __fastcall array_print(__int64 a1)
{
__int64 v1; // rbx

putchar(91);
if ( *(int *)(a1 - 4) > 0 )
{
v1 = 0LL;
do
printf("%d ", *(unsigned int *)(a1 + 4 * v1++));
while ( *(_DWORD *)(a1 - 4) > (int)v1 );
}
return puts("\b]");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rbx

putchar(91);
if ( *(int *)(a1 - 4) > 0 )
{
v1 = 0LL;
do
printf("%d ", *(unsigned int *)(a1 + 4 * v1++));
while ( *(_DWORD *)(a1 - 4) > (int)v1 );
}
return puts("\b]");
}

original_code:
static void array_print(int *arr)
{
    int i;
    printf("[");
    for (i = 0; i < arr[-1]; i++) printf("%d ", arr[i]);
    printf("\b]\n");
}

variable_types:
arr
int *

variable_types: i int


decompiled_code:
void __fastcall array_free(__int64 a1)
{
free((void *)(a1 - 8));
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
free((void *)(a1 - 8));
}

original_code:
static void array_free(int *arr)
{
    free(arr-2);
    return;
}


decompiled_code:
void __fastcall dataframe_free(_QWORD *a1)
{
int *v2; // rdi
int v3; // er12
_QWORD *v4; // rbx
__int64 v5; // r12

v2 = (int *)*(a1 - 1);
v3 = *v2;
free(v2);
if ( v3 > 0 )
{
v4 = a1;
v5 = (__int64)&a1[(unsigned int)(v3 - 1) + 1];
do
free((void *)(*v4++ - 8LL));
while ( v4 != (_QWORD *)v5 );
}
free(a1 - 1);
}

original_code:
static void dataframe_free(int **df)
{
    int i, dim_one = df[-1][0];
    free(df[-1]);
    for (i = 0; i < dim_one; i++) {
        free(df[i]-2);
    }
    free(df-1);
    return;
}

canonical_original_code:
static void dataframe_free(int **df)
{
    int i; int dim_one = df[-1][0];
    free(df[-1]);
    for (i = 0; i < dim_one; i++) {
        free(df[i]-2);
    }
    free(df-1);
    return;
}


original_code:
static void dataframe_copy(int **dest, int **src)
{
    int i;
    if (dest[-1][0] < src[-1][1]) {
       dest = (int **)realloc(dest-1, (src[-1][1]+1)*sizeof(int *)) + 1;
       ((void) sizeof ((dest) ? 1 : 0), __extension__ ({ if (dest) ; else __assert_fail ("dest", "arrlib.c", 251, __extension__ __PRETTY_FUNCTION__); }));
       dest[-1][0] = src[-1][1];
    }
    memmove(dest[-1]+1, src[-1]+1, 3*sizeof(int));
    for (i = 0; i < src[-1][1]; i++) {
        if (dest[i][-2] < src[i][-1]) {
            dest[i] = (int *)realloc(dest[i]-2, (src[i][-1]+2)) + 2;
            ((void) sizeof ((dest[i]) ? 1 : 0), __extension__ ({ if (dest[i]) ; else __assert_fail ("dest[i]", "arrlib.c", 258, __extension__ __PRETTY_FUNCTION__); }));
            dest[i][-2] = src[i][-1];
        }
        memmove(dest[i]-1, src[i]-1, (src[i][-1]+1)*sizeof(int));
    }
}

variable_types:
dest
int **

variable_types:
src
int **


original_code:
static void dataframe_remove(int **df, char *arg, ...)
{
    va_list arg_ptr;
    size_t nrow, ncol, start, end;
    __builtin_va_start(arg_ptr,arg);
    if (0 == strcmp(arg, "arr")) {
        nrow = __builtin_va_arg(arg_ptr,size_t);
        start = __builtin_va_arg(arg_ptr,size_t);
        end = __builtin_va_arg(arg_ptr,size_t);
        ((void) sizeof ((nrow < df[-1][1]) ? 1 : 0), __extension__ ({ if (nrow < df[-1][1]) ; else __assert_fail ("nrow < df[-1][1]", "arrlib.c", 221, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((start >= 0 && start < df[nrow][-1]) ? 1 : 0), __extension__ ({ if (start >= 0 && start < df[nrow][-1]) ; else __assert_fail ("start >= 0 && start < df[nrow][-1]", "arrlib.c", 222, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((start <= end && end < df[nrow][-1]) ? 1 : 0), __extension__ ({ if (start <= end && end < df[nrow][-1]) ; else __assert_fail ("start <= end && end < df[nrow][-1]", "arrlib.c", 223, __extension__ __PRETTY_FUNCTION__); }));
        if (end < df[nrow][-1]-1) {
            memmove(df[nrow]+start, df[nrow]+end+1, (df[nrow][-1]-end)*sizeof(int));
        }
        df[nrow][-1] -= end - start + 1;
        df[-1][3] -= end - start + 1;
        if (df[nrow][-1] == 0) df[-1][2] += 1;
    }else if (0 == strcmp(arg, "elm")) {
        nrow = __builtin_va_arg(arg_ptr,size_t);
        ncol = __builtin_va_arg(arg_ptr,size_t);
        ((void) sizeof ((nrow < df[-1][1]) ? 1 : 0), __extension__ ({ if (nrow < df[-1][1]) ; else __assert_fail ("nrow < df[-1][1]", "arrlib.c", 234, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((ncol < df[nrow][-1]) ? 1 : 0), __extension__ ({ if (ncol < df[nrow][-1]) ; else __assert_fail ("ncol < df[nrow][-1]", "arrlib.c", 235, __extension__ __PRETTY_FUNCTION__); }));
        if (ncol < df[nrow][-1]-1) {
            memmove(df[nrow]+ncol, df[nrow]+ncol+1, (df[nrow][-1]-ncol-1)*sizeof(int));
        }
        df[nrow][-1] -= 1;
        df[-1][3] -=1;
        if (df[nrow][-1] == 0 ) df[-1][2] += 1;
    }
}

canonical_original_code:
static void dataframe_remove(int **df, char *arg, ...)
{
    __builtin_va_list arg_ptr;
    unsigned long nrow; unsigned long ncol; unsigned long start; unsigned long end;
    __builtin_va_start(arg_ptr,arg);
    if (0 == strcmp(arg, "arr")) {
        nrow = __builtin_va_arg(arg_ptr,size_t);
        start = __builtin_va_arg(arg_ptr,size_t);
        end = __builtin_va_arg(arg_ptr,size_t);
        ((void) sizeof ((nrow < df[-1][1]) ? 1 : 0), __extension__ ({ if (nrow < df[-1][1]) ; else __assert_fail ("nrow < df[-1][1]", "arrlib.c", 221, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((start >= 0 && start < df[nrow][-1]) ? 1 : 0), __extension__ ({ if (start >= 0 && start < df[nrow][-1]) ; else __assert_fail ("start >= 0 && start < df[nrow][-1]", "arrlib.c", 222, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((start <= end && end < df[nrow][-1]) ? 1 : 0), __extension__ ({ if (start <= end && end < df[nrow][-1]) ; else __assert_fail ("start <= end && end < df[nrow][-1]", "arrlib.c", 223, __extension__ __PRETTY_FUNCTION__); }));
        if (end < df[nrow][-1]-1) {
            memmove(df[nrow]+start, df[nrow]+end+1, (df[nrow][-1]-end)*sizeof(int));
        }
        df[nrow][-1] -= end - start + 1;
        df[-1][3] -= end - start + 1;
        if (df[nrow][-1] == 0) df[-1][2] += 1;
    }else if (0 == strcmp(arg, "elm")) {
        nrow = __builtin_va_arg(arg_ptr,size_t);
        ncol = __builtin_va_arg(arg_ptr,size_t);
        ((void) sizeof ((nrow < df[-1][1]) ? 1 : 0), __extension__ ({ if (nrow < df[-1][1]) ; else __assert_fail ("nrow < df[-1][1]", "arrlib.c", 234, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((ncol < df[nrow][-1]) ? 1 : 0), __extension__ ({ if (ncol < df[nrow][-1]) ; else __assert_fail ("ncol < df[nrow][-1]", "arrlib.c", 235, __extension__ __PRETTY_FUNCTION__); }));
        if (ncol < df[nrow][-1]-1) {
            memmove(df[nrow]+ncol, df[nrow]+ncol+1, (df[nrow][-1]-ncol-1)*sizeof(int));
        }
        df[nrow][-1] -= 1;
        df[-1][3] -=1;
        if (df[nrow][-1] == 0 ) df[-1][2] += 1;
    }
}

variable_types:
arg
char *

variable_types:
nrow
unsigned long

variable_types:
ncol
unsigned long

variable_types:
start
unsigned long

variable_types:
end
unsigned long


kargerMinCut

original_code:
int kargerMinCut(int **origin_graph)
{
    const DATAFRAME_METHOD df = Dataframe;
    int **graph;
    int node1=0, node2=0, i, j, k, m, nrow, min_cut;
    size_t nonempty_row;
    graph = df.init("copy", origin_graph);
    min_cut = graph[-1][1]-1;
    nonempty_row = df.neptr(graph);
    for (m = 0; m < 220000; m++) {
        srand((unsigned int)(m*time(0)));
        while(nonempty_row > 2) {
            k = rand()%(df.elmcnt(graph)-graph[-1][1]);
            k += 1;
            node1 = 0;
            while (1) {
                nrow = graph[node1][-1]-1;
                if (k > nrow) {
                    k -= nrow;
                    node1 += 1;
                }else break;
            }
            node2 = graph[node1][k]-1;
            for (i = 0; i < graph[-1][1]; i++) {
                for (j = 1; j < graph[i][-1]; j++) {
                    if (graph[i][j] == node2+1) {
                        graph[i][j] = node1+1;
                    }
                }
            }
            df.append(graph, "arr", node1, graph[node2][-1]-1, graph[node2]+1);
            df.remove(graph, "arr", node2, 1, graph[node2][-1]-1);
            nonempty_row -= 1;
            for(j = 1; j < graph[node1][-1]; ) {
                if(graph[node1][j] == node1+1) {
                    df.remove(graph, "elm", node1, j);
                }else j++;
            }
        }
        if (graph[node1][-1]-1 < min_cut) {
            min_cut = graph[node1][-1]-1;
        }
        df.copy(graph, origin_graph);
        nonempty_row = df.neptr(graph);
    }
    df.free(graph);
    return min_cut;
}

canonical_original_code:
int kargerMinCut(int **origin_graph)
{
    struct DATAFRAME_METHOD df = Dataframe;
    int **graph;
    int node1 = 0; int node2 = 0; int i; int j; int k; int m; int nrow; int min_cut;
    unsigned long nonempty_row;
    graph = df.init("copy", origin_graph);
    min_cut = graph[-1][1]-1;
    nonempty_row = df.neptr(graph);
    for (m = 0; m < 220000; m++) {
        srand((unsigned int)(m*time(0)));
        while(nonempty_row > 2) {
            k = rand()%(df.elmcnt(graph)-graph[-1][1]);
            k += 1;
            node1 = 0;
            while (1) {
                nrow = graph[node1][-1]-1;
                if (k > nrow) {
                    k -= nrow;
                    node1 += 1;
                }else break;
            }
            node2 = graph[node1][k]-1;
            for (i = 0; i < graph[-1][1]; i++) {
                for (j = 1; j < graph[i][-1]; j++) {
                    if (graph[i][j] == node2+1) {
                        graph[i][j] = node1+1;
                    }
                }
            }
            df.append(graph, "arr", node1, graph[node2][-1]-1, graph[node2]+1);
            df.remove(graph, "arr", node2, 1, graph[node2][-1]-1);
            nonempty_row -= 1;
            for(j = 1; j < graph[node1][-1]; ) {
                if(graph[node1][j] == node1+1) {
                    df.remove(graph, "elm", node1, j);
                }else j++;
            }
        }
        if (graph[node1][-1]-1 < min_cut) {
            min_cut = graph[node1][-1]-1;
        }
        df.copy(graph, origin_graph);
        nonempty_row = df.neptr(graph);
    }
    df.free(graph);
    return min_cut;
}

variable_types: struct DATAFRAME_METHOD { int **(*init)(char *arg, ...); void (*free)(int **df); void (*print)(int **df); int (*neptr)(int **df); int (*elmcnt)(int **df); void (*remove)(int **df, char *arg, ...); void (*append)(int **df, char *arg, ...); void (*copy)(int **dest, int **src); }

variable_types:
graph
int **

variable_types: j int

variable_types: k int

variable_types: m int

variable_types: nrow int


addToEdgeList

repo: FireArrow/traveling-salesman

decompiled_code:
void __fastcall addToEdgeList(char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( *((_DWORD *)a1 + 1) )
{
if ( verbosity > 2 )
fprintf(stdout, "Adding another edge to node %c\n", (unsigned int)*a1);
v2 = *((_QWORD *)a1 + 1);
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
*(_QWORD *)(v3 + 16) = a2;
}
else
{
if ( verbosity > 2 )
fprintf(stdout, "Setting first edge on %c\n", (unsigned int)*a1);
*((_QWORD *)a1 + 1) = a2;
}
++*((_DWORD *)a1 + 1);
}

canonical_decompiled_code:
void __fastcall func0(char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( *((_DWORD *)a1 + 1) )
{
if ( verbosity > 2 )
fprintf(stdout, "Adding another edge to node %c\n", (unsigned int)*a1);
v2 = *((_QWORD *)a1 + 1);
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
*(_QWORD *)(v3 + 16) = a2;
}
else
{
if ( verbosity > 2 )
fprintf(stdout, "Setting first edge on %c\n", (unsigned int)*a1);
*((_QWORD *)a1 + 1) = a2;
}
++*((_DWORD *)a1 + 1);
}

original_code:
void addToEdgeList(node * n, edge * e) {
 if(n->noEdges==0) {
  if(verbosity >= 3) fprintf(stdout,"Setting first edge on %c\n", n->id);
  n->edges = e;
 }
 else {
  if(verbosity >= 3) fprintf(stdout,"Adding another edge to node %c\n",n->id);
  edge * edgeptr = n->edges;
  while(edgeptr->next) edgeptr = edgeptr->next;
  edgeptr->next = e;
 }
 n->noEdges++;
}

canonical_original_code:
void addToEdgeList(struct struct_node *n, struct struct_edge *e) {
 if(n->noEdges==0) {
  if(verbosity >= 3) fprintf(stdout,"Setting first edge on %c\n", n->id);
  n->edges = e;
 }
 else {
  if(verbosity >= 3) fprintf(stdout,"Adding another edge to node %c\n",n->id);
  struct struct_edge *edgeptr = n->edges;
  while(edgeptr->next) edgeptr = edgeptr->next;
  edgeptr->next = e;
 }
 n->noEdges++;
}

variable_types: struct struct_node { char id; int noEdges; struct struct_edge { int id; int weight; struct struct_node *endpoint; struct struct_edge *next; } *edges; struct struct_node *next; } *

variable_types:
e
struct struct_edge *

variable_types: struct struct_edge { int id; int weight; struct struct_node { char id; int noEdges; struct struct_edge *edges; struct struct_node *next; } *endpoint; struct struct_edge *next; } *