decompiled_code:
__int64 __fastcall enter_contour(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // rbp
_QWORD *v4; // rax
__int64 result; // rax

v1 = malloc(0x10uLL);
v2 = malloc(0x200uLL);
v3 = v2;
if ( !v1 || !v2 )
fatal("Out of memory.");
v4 = v3;
do
*v4++ = 0LL;
while ( v4 != v3 + 32 );
*v1 = v3;
result = *(_QWORD *)(a1 + 8);
v1[1] = result;
*(_QWORD *)(a1 + 8) = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // rbp
_QWORD *v4; // rax
__int64 result; // rax

v1 = malloc(0x10uLL);
v2 = malloc(0x200uLL);
v3 = v2;
if ( !v1 || !v2 )
fatal("Out of memory.");
v4 = v3;
do
*v4++ = 0LL;
while ( v4 != v3 + 32 );
*v1 = v3;
result = *(_QWORD *)(a1 + 8);
v1[1] = result;
*(_QWORD *)(a1 + 8) = v1;
return result;
}

original_code:
void enter_contour(SymbolTable *table) {
    Contour *contour = malloc(sizeof *contour);
    HashItem **buckets = malloc(MAP_SIZE * sizeof **buckets);
    if (!contour || !buckets) {
        fatal("Out of memory.");
    }
    int i;
    for (i = 0; i < MAP_SIZE; i++) {
        buckets[i] = ((void *)0);
    }
    contour->buckets = buckets;
    contour->next = table->top;
    table->top = contour;
}

canonical_original_code:
void enter_contour(struct SymbolTable *table) {
    struct Contour *contour = malloc(sizeof *contour);
    struct HashItem **buckets = malloc(MAP_SIZE * sizeof **buckets);
    if (!contour || !buckets) {
        fatal("Out of memory.");
    }
    int i;
    for (i = 0; i < MAP_SIZE; i++) {
        buckets[i] = ((void *)0);
    }
    contour->buckets = buckets;
    contour->next = table->top;
    table->top = contour;
}

variable_types: struct SymbolTable { int level; struct Contour { struct HashItem { struct Symbol { int level; char *name; struct Expression { enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 } type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList { struct ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; } *head; struct ExpressionNode *tail; } *llist; struct ExpressionList *rlist; struct Symbol *symbol; struct Scope { struct Expression *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; } *scope; struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; } pos; union { int i; double d; char *s; } value; } *declaration; } *symbol; struct HashItem *next; } **buckets; struct Contour *next; } *top; struct Scope *scope; } *

variable_types: i int

user_defined_types: struct HashItem { struct Symbol *symbol; struct HashItem *next; }


repo: kwiskia/chinnu

decompiled_code:
void __fastcall free_contour(void *ptr)
{
__int64 i; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

for ( i = 0LL; i != 256; i += 8LL )
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + i);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
__int64 i; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

for ( i = 0LL; i != 256; i += 8LL )
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + i);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_contour(Contour *contour) {
    int i;
    for (i = 0; i < MAP_SIZE; i++) {
        HashItem *head = contour->buckets[i];
        while (head != ((void *)0)) {
            HashItem *temp = head->next;
            free(head);
            head = temp;
        }
    }
    free(contour->buckets);
    free(contour);
}

canonical_original_code:
void free_contour(struct Contour *contour) {
    int i;
    for (i = 0; i < MAP_SIZE; i++) {
        struct HashItem *head = contour->buckets[i];
        while (head != ((void *)0)) {
            struct HashItem *temp = head->next;
            free(head);
            head = temp;
        }
    }
    free(contour->buckets);
    free(contour);
}

variable_types: struct Contour { struct HashItem { struct Symbol { int level; char *name; struct Expression { enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 } type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList { struct ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; } *head; struct ExpressionNode *tail; } *llist; struct ExpressionList *rlist; struct Symbol *symbol; struct Scope { struct Expression *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; } *scope; struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; } pos; union { int i; double d; char *s; } value; } *declaration; } *symbol; struct HashItem *next; } **buckets; struct Contour *next; } *

return_type: void

user_defined_types: struct Contour { struct HashItem **buckets; struct Contour *next; }

user_defined_types: struct Symbol { int level; char *name; struct Expression *declaration; }

user_defined_types: struct Expression { enum ExpressionType type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList *llist; struct ExpressionList *rlist; struct Symbol *symbol; struct Scope *scope; struct SourcePos pos; union { int i; double d; char *s; } value; }

user_defined_types: struct ExpressionList { struct ExpressionNode *head; struct ExpressionNode *tail; }


decompiled_code:
void __fastcall leave_contour(__int64 a1)
{
_QWORD *v2; // rdi

if ( !*(_QWORD *)(a1 + 8) )
fatal("Empty contour.");
v2 = *(_QWORD **)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2[1];
free_contour(v2);
}

original_code:
void leave_contour(SymbolTable *table) {
    if (!table->top) {
        fatal("Empty contour.");
    }
    Contour *temp = table->top;
    table->top = table->top->next;
    free_contour(temp);
}

canonical_original_code:
void leave_contour(struct SymbolTable *table) {
    if (!table->top) {
        fatal("Empty contour.");
    }
    struct Contour *temp = table->top;
    table->top = table->top->next;
    free_contour(temp);
}

user_defined_types: struct SymbolTable { int level; struct Contour *top; struct Scope *scope; }

user_defined_types: enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 }

user_defined_types: struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; }

user_defined_types: struct Scope { struct Expression *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; }

user_defined_types: struct ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; }


decompiled_code:
void __fastcall resolve_expr(__int64 a1, __int64 a2)
{
const char *v3; // rdx
_DWORD *v4; // r12
__int64 v5; // rsi
_QWORD *v6; // r12
char *v7; // rsi
const char *v8; // rdx
_DWORD *v9; // r12
_QWORD *v10; // r12
__int64 v11; // r13
_QWORD *v12; // r12
__int64 i; // rax
const char *v14; // rdx
_DWORD *v15; // r12
__int64 v16; // rsi
const char *v17; // rdx

switch ( *(_DWORD *)a2 )
{
case 0:
resolve_expr(a1, *(_QWORD *)(a2 + 8));
enter_contour(a1);
resolve_expr(a1, *(_QWORD *)(a2 + 16));
leave_contour(a1);
if ( *(_QWORD *)(a2 + 24) )
{
enter_contour(a1);
resolve_expr(a1, *(_QWORD *)(a2 + 24));
leave_contour(a1);
}
break;
case 1:
resolve_expr(a1, *(_QWORD *)(a2 + 8));
enter_contour(a1);
resolve_expr(a1, *(_QWORD *)(a2 + 16));
leave_contour(a1);
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 0xB:
case 0xC:
case 0xD:
case 0xE:
case 0xF:
case 0x10:
case 0x11:
case 0x12:
resolve_expr(a1, *(_QWORD *)(a2 + 16));
resolve_expr(a1, *(_QWORD *)(a2 + 24));
break;
case 8:
case 9:
case 0x1D:
case 0x1E:
resolve_expr(a1, *(_QWORD *)(a2 + 16));
break;
case 0xA:
resolve_expr(a1, *(_QWORD *)(a2 + 16));
v16 = *(_QWORD *)(a2 + 24);
resolve_expr(a1, v16);
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 16) + 48LL) + 16LL) + 4LL) == 1 )
{
error((int)"Assignment to a single-assignment variable.", v16, v17);
message("Variable is defined here.");
}
break;
case 0x13:
v15 = (_DWORD *)find_symbol(a1, *(char **)(a2 + 88));
if ( v15 )
{
if ( *v15 != *(_DWORD *)a1 )
register_upvar(*(_QWORD *)(a1 + 16), (__int64)v15);
*(_QWORD *)(a2 + 48) = v15;
}
else
{
error((int)"Use of undeclared identifier '%s'.", *(_QWORD *)(a2 + 88), v14);
}
break;
case 0x19:
resolve_expr(a1, *(_QWORD *)(a2 + 16));
enter_contour(a1);
resolve_list(a1, *(_QWORD **)(a2 + 32));
leave_contour(a1);
break;
case 0x1A:
v7 = *(char **)(a2 + 88);
if ( v7 )
{
v9 = (_DWORD *)find_symbol(a1, v7);
if ( v9 )
{
if ( *v9 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v8);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v10 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v10;
add_symbol(a1, (__int64)v10);
add_local(*(_QWORD *)(a1 + 16), (__int64)v10);
}
v11 = *(_QWORD *)(a1 + 16);
v12 = make_scope(a2);
*(_QWORD *)(a2 + 56) = v12;
v12[1] = v11;
add_child(v11, (__int64)v12);
*(_QWORD *)(a1 + 16) = v12;
for ( i = **(_QWORD **)(a2 + 32); i; i = *(_QWORD *)(i + 8) )
++*((_DWORD *)v12 + 11);
++*(_DWORD *)a1;
enter_contour(a1);
resolve_list(a1, *(_QWORD **)(a2 + 32));
resolve_expr(a1, *(_QWORD *)(a2 + 24));
leave_contour(a1);
--*(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = v11;
break;
case 0x1B:
v4 = (_DWORD *)find_symbol(a1, *(char **)(a2 + 88));
if ( v4 )
{
if ( *v4 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v3);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v5 = *(_QWORD *)(a2 + 24);
if ( v5 )
resolve_expr(a1, v5);
v6 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v6;
add_symbol(a1, (__int64)v6);
add_local(*(_QWORD *)(a1 + 16), (__int64)v6);
break;
case 0x1C:
enter_contour(a1);
resolve_list(a1, *(_QWORD **)(a2 + 32));
leave_contour(a1);
if ( *(_QWORD *)(a2 + 40) )
{
enter_contour(a1);
resolve_list(a1, *(_QWORD **)(a2 + 40));
leave_contour(a1);
}
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, __int64 a2)
{
const char *v3; // rdx
_DWORD *v4; // r12
__int64 v5; // rsi
_QWORD *v6; // r12
char *v7; // rsi
const char *v8; // rdx
_DWORD *v9; // r12
_QWORD *v10; // r12
__int64 v11; // r13
_QWORD *v12; // r12
__int64 i; // rax
const char *v14; // rdx
_DWORD *v15; // r12
__int64 v16; // rsi
const char *v17; // rdx

switch ( *(_DWORD *)a2 )
{
case 0:
func15(a1, *(_QWORD *)(a2 + 8));
func11(a1);
func15(a1, *(_QWORD *)(a2 + 16));
func13(a1);
if ( *(_QWORD *)(a2 + 24) )
{
func11(a1);
func15(a1, *(_QWORD *)(a2 + 24));
func13(a1);
}
break;
case 1:
func15(a1, *(_QWORD *)(a2 + 8));
func11(a1);
func15(a1, *(_QWORD *)(a2 + 16));
func13(a1);
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 0xB:
case 0xC:
case 0xD:
case 0xE:
case 0xF:
case 0x10:
case 0x11:
case 0x12:
func15(a1, *(_QWORD *)(a2 + 16));
func15(a1, *(_QWORD *)(a2 + 24));
break;
case 8:
case 9:
case 0x1D:
case 0x1E:
func15(a1, *(_QWORD *)(a2 + 16));
break;
case 0xA:
func15(a1, *(_QWORD *)(a2 + 16));
v16 = *(_QWORD *)(a2 + 24);
func15(a1, v16);
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 16) + 48LL) + 16LL) + 4LL) == 1 )
{
error((int)"Assignment to a single-assignment variable.", v16, v17);
message("Variable is defined here.");
}
break;
case 0x13:
v15 = (_DWORD *)func10(a1, *(char **)(a2 + 88));
if ( v15 )
{
if ( *v15 != *(_DWORD *)a1 )
func6(*(_QWORD *)(a1 + 16), (__int64)v15);
*(_QWORD *)(a2 + 48) = v15;
}
else
{
error((int)"Use of undeclared identifier '%s'.", *(_QWORD *)(a2 + 88), v14);
}
break;
case 0x19:
func15(a1, *(_QWORD *)(a2 + 16));
func11(a1);
func14(a1, *(_QWORD **)(a2 + 32));
func13(a1);
break;
case 0x1A:
v7 = *(char **)(a2 + 88);
if ( v7 )
{
v9 = (_DWORD *)func10(a1, v7);
if ( v9 )
{
if ( *v9 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v8);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v10 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v10;
func8(a1, (__int64)v10);
func1(*(_QWORD *)(a1 + 16), (__int64)v10);
}
v11 = *(_QWORD *)(a1 + 16);
v12 = make_scope(a2);
*(_QWORD *)(a2 + 56) = v12;
v12[1] = v11;
func3(v11, (__int64)v12);
*(_QWORD *)(a1 + 16) = v12;
for ( i = **(_QWORD **)(a2 + 32); i; i = *(_QWORD *)(i + 8) )
++*((_DWORD *)v12 + 11);
++*(_DWORD *)a1;
func11(a1);
func14(a1, *(_QWORD **)(a2 + 32));
func15(a1, *(_QWORD *)(a2 + 24));
func13(a1);
--*(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = v11;
break;
case 0x1B:
v4 = (_DWORD *)func10(a1, *(char **)(a2 + 88));
if ( v4 )
{
if ( *v4 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v3);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v5 = *(_QWORD *)(a2 + 24);
if ( v5 )
func15(a1, v5);
v6 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v6;
func8(a1, (__int64)v6);
func1(*(_QWORD *)(a1 + 16), (__int64)v6);
break;
case 0x1C:
func11(a1);
func14(a1, *(_QWORD **)(a2 + 32));
func13(a1);
if ( *(_QWORD *)(a2 + 40) )
{
func11(a1);
func14(a1, *(_QWORD **)(a2 + 40));
func13(a1);
}
break;
default:
return;
}
}

original_code:
void resolve_expr(SymbolTable *table, Expression *expr) {
    switch (expr->type) {
        case TYPE_MODULE:
            resolve_expr(table, expr->lexpr);
            break;
        case TYPE_DECLARATION:
        {
            Symbol *symbol = find_symbol(table, expr->value.s);
            if (symbol && symbol->level == table->level) {
                error(expr->pos, "Redefinition of '%s'.", expr->value.s);
                message(symbol->declaration->pos, "Previous definition is here.");
            }
            if (symbol && warning_flags[WARNING_SHADOW]) {
                warning(expr->pos, "Shadowing declaration of '%s'.", expr->value.s);
                message(symbol->declaration->pos, "Previous definition is here.");
            }
            if (expr->rexpr) {
                resolve_expr(table, expr->rexpr);
            }
            symbol = make_symbol(expr->value.s, table->level, expr);
            expr->symbol = symbol;
            add_symbol(table, symbol);
            add_local(table->scope, symbol);
        } break;
        case TYPE_FUNC:
        {
            if (expr->value.s) {
                Symbol *symbol = find_symbol(table, expr->value.s);
                if (symbol && symbol->level == table->level) {
                    error(expr->pos, "Redefinition of '%s'.", expr->value.s);
                    message(symbol->declaration->pos, "Previous definition is here.");
                }
                if (symbol && warning_flags[WARNING_SHADOW]) {
                    warning(expr->pos, "Shadowing declaration of '%s'.", expr->value.s);
                    message(symbol->declaration->pos, "Previous definition is here.");
                }
                symbol = make_symbol(expr->value.s, table->level, expr);
                expr->symbol = symbol;
                add_symbol(table, symbol);
                add_local(table->scope, symbol);
            }
            Scope *temp = table->scope;
            Scope *scope = make_scope(expr);
            expr->scope = scope;
            scope->parent = temp;
            add_child(temp, scope);
            table->scope = scope;
            ExpressionNode *head;
            for (head = expr->llist->head; head != ((void *)0); head = head->next) {
                scope->numparams++;
            }
            table->level++;
            enter_contour(table);
            resolve_list(table, expr->llist);
            resolve_expr(table, expr->rexpr);
            leave_contour(table);
            table->level--;
            table->scope = temp;
        } break;
        case TYPE_VARREF:
        {
            Symbol *symbol = find_symbol(table, expr->value.s);
            if (!symbol) {
                error(expr->pos, "Use of undeclared identifier '%s'.", expr->value.s);
            } else {
                if (symbol->level != table->level) {
                    register_upvar(table->scope, symbol);
                }
                expr->symbol = symbol;
            }
        } break;
        case TYPE_IF:
            resolve_expr(table, expr->cond);
            enter_contour(table);
            resolve_expr(table, expr->lexpr);
            leave_contour(table);
            if (expr->rexpr) {
                enter_contour(table);
                resolve_expr(table, expr->rexpr);
                leave_contour(table);
            }
            break;
        case TYPE_WHILE:
            resolve_expr(table, expr->cond);
            enter_contour(table);
            resolve_expr(table, expr->lexpr);
            leave_contour(table);
            break;
        case TYPE_CALL:
            resolve_expr(table, expr->lexpr);
            enter_contour(table);
            resolve_list(table, expr->llist);
            leave_contour(table);
            break;
        case TYPE_ASSIGN:
            resolve_expr(table, expr->lexpr);
            resolve_expr(table, expr->rexpr);
            if (expr->lexpr->symbol->declaration->immutable == 1) {
                error(expr->pos, "Assignment to a single-assignment variable.");
                message(expr->lexpr->symbol->declaration->pos, "Variable is defined here.");
            }
            break;
        case TYPE_ADD:
        case TYPE_SUB:
        case TYPE_MUL:
        case TYPE_DIV:
        case TYPE_MOD:
        case TYPE_POW:
        case TYPE_EQEQ:
        case TYPE_NEQ:
        case TYPE_LT:
        case TYPE_LEQ:
        case TYPE_GT:
        case TYPE_GEQ:
        case TYPE_AND:
        case TYPE_OR:
            resolve_expr(table, expr->lexpr);
            resolve_expr(table, expr->rexpr);
            break;
        case TYPE_NEG:
        case TYPE_NOT:
            resolve_expr(table, expr->lexpr);
            break;
        case TYPE_INT:
        case TYPE_REAL:
        case TYPE_BOOL:
        case TYPE_NULL:
        case TYPE_STRING:
            break;
        case TYPE_BLOCK:
            enter_contour(table);
            resolve_list(table, expr->llist);
            leave_contour(table);
            if (expr->rlist) {
                enter_contour(table);
                resolve_list(table, expr->rlist);
                leave_contour(table);
            }
            break;
        case TYPE_THROW:
            resolve_expr(table, expr->lexpr);
            break;
    }
}

canonical_original_code:
void resolve_expr(struct SymbolTable *table, struct Expression *expr) {
    switch (expr->type) {
        case TYPE_MODULE:
            resolve_expr(table, expr->lexpr);
            break;
        case TYPE_DECLARATION:
        {
            struct Symbol *symbol = find_symbol(table, expr->value.s);
            if (symbol && symbol->level == table->level) {
                error(expr->pos, "Redefinition of '%s'.", expr->value.s);
                message(symbol->declaration->pos, "Previous definition is here.");
            }
            if (symbol && warning_flags[WARNING_SHADOW]) {
                warning(expr->pos, "Shadowing declaration of '%s'.", expr->value.s);
                message(symbol->declaration->pos, "Previous definition is here.");
            }
            if (expr->rexpr) {
                resolve_expr(table, expr->rexpr);
            }
            symbol = make_symbol(expr->value.s, table->level, expr);
            expr->symbol = symbol;
            add_symbol(table, symbol);
            add_local(table->scope, symbol);
        } break;
        case TYPE_FUNC:
        {
            if (expr->value.s) {
                struct Symbol *symbol = find_symbol(table, expr->value.s);
                if (symbol && symbol->level == table->level) {
                    error(expr->pos, "Redefinition of '%s'.", expr->value.s);
                    message(symbol->declaration->pos, "Previous definition is here.");
                }
                if (symbol && warning_flags[WARNING_SHADOW]) {
                    warning(expr->pos, "Shadowing declaration of '%s'.", expr->value.s);
                    message(symbol->declaration->pos, "Previous definition is here.");
                }
                symbol = make_symbol(expr->value.s, table->level, expr);
                expr->symbol = symbol;
                add_symbol(table, symbol);
                add_local(table->scope, symbol);
            }
            struct Scope *temp = table->scope;
            struct Scope *scope = make_scope(expr);
            expr->scope = scope;
            scope->parent = temp;
            add_child(temp, scope);
            table->scope = scope;
            struct ExpressionNode *head;
            for (head = expr->llist->head; head != ((void *)0); head = head->next) {
                scope->numparams++;
            }
            table->level++;
            enter_contour(table);
            resolve_list(table, expr->llist);
            resolve_expr(table, expr->rexpr);
            leave_contour(table);
            table->level--;
            table->scope = temp;
        } break;
        case TYPE_VARREF:
        {
            struct Symbol *symbol = find_symbol(table, expr->value.s);
            if (!symbol) {
                error(expr->pos, "Use of undeclared identifier '%s'.", expr->value.s);
            } else {
                if (symbol->level != table->level) {
                    register_upvar(table->scope, symbol);
                }
                expr->symbol = symbol;
            }
        } break;
        case TYPE_IF:
            resolve_expr(table, expr->cond);
            enter_contour(table);
            resolve_expr(table, expr->lexpr);
            leave_contour(table);
            if (expr->rexpr) {
                enter_contour(table);
                resolve_expr(table, expr->rexpr);
                leave_contour(table);
            }
            break;
        case TYPE_WHILE:
            resolve_expr(table, expr->cond);
            enter_contour(table);
            resolve_expr(table, expr->lexpr);
            leave_contour(table);
            break;
        case TYPE_CALL:
            resolve_expr(table, expr->lexpr);
            enter_contour(table);
            resolve_list(table, expr->llist);
            leave_contour(table);
            break;
        case TYPE_ASSIGN:
            resolve_expr(table, expr->lexpr);
            resolve_expr(table, expr->rexpr);
            if (expr->lexpr->symbol->declaration->immutable == 1) {
                error(expr->pos, "Assignment to a single-assignment variable.");
                message(expr->lexpr->symbol->declaration->pos, "Variable is defined here.");
            }
            break;
        case TYPE_ADD:
        case TYPE_SUB:
        case TYPE_MUL:
        case TYPE_DIV:
        case TYPE_MOD:
        case TYPE_POW:
        case TYPE_EQEQ:
        case TYPE_NEQ:
        case TYPE_LT:
        case TYPE_LEQ:
        case TYPE_GT:
        case TYPE_GEQ:
        case TYPE_AND:
        case TYPE_OR:
            resolve_expr(table, expr->lexpr);
            resolve_expr(table, expr->rexpr);
            break;
        case TYPE_NEG:
        case TYPE_NOT:
            resolve_expr(table, expr->lexpr);
            break;
        case TYPE_INT:
        case TYPE_REAL:
        case TYPE_BOOL:
        case TYPE_NULL:
        case TYPE_STRING:
            break;
        case TYPE_BLOCK:
            enter_contour(table);
            resolve_list(table, expr->llist);
            leave_contour(table);
            if (expr->rlist) {
                enter_contour(table);
                resolve_list(table, expr->rlist);
                leave_contour(table);
            }
            break;
        case TYPE_THROW:
            resolve_expr(table, expr->lexpr);
            break;
    }
}

variable_types:
expr
struct Expression *

variable_types: struct Symbol { int level; char *name; struct Expression { enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 } type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList { struct ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; } *head; struct ExpressionNode *tail; } *llist; struct ExpressionList *rlist; struct Symbol *symbol; struct Scope { struct Expression *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; } *scope; struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; } pos; union { int i; double d; char *s; } value; } *declaration; } *

variable_types: struct Scope { struct Expression { enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 } type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList { struct ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; } *head; struct ExpressionNode *tail; } *llist; struct ExpressionList *rlist; struct Symbol { int level; char *name; struct Expression *declaration; } *symbol; struct Scope *scope; struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; } pos; union { int i; double d; char *s; } value; } *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; } *

variable_types: struct ExpressionNode { struct Expression { enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 } type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList { struct ExpressionNode *head; struct ExpressionNode *tail; } *llist; struct ExpressionList *rlist; struct Symbol { int level; char *name; struct Expression *declaration; } *symbol; struct Scope { struct Expression *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; } *scope; struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; } pos; union { int i; double d; char *s; } value; } *expr; struct ExpressionNode *next; struct ExpressionNode *prev; } *


resolve

decompiled_code:
void __fastcall resolve(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

v1 = malloc(0x18uLL);
if ( !v1 )
fatal("Out of memory.");
v2 = make_scope(a1);
*(_QWORD *)(a1 + 56) = v2;
v1[1] = 0LL;
*(_DWORD *)v1 = 0;
v1[2] = v2;
enter_contour((__int64)v1);
resolve_expr((__int64)v1, a1);
leave_contour((__int64)v1);
free(v1);
}

original_code:
void resolve(Expression *expr) {
    SymbolTable *table = malloc(sizeof *table);
    if (!table) {
        fatal("Out of memory.");
    }
    Scope *scope = make_scope(expr);
    expr->scope = scope;
    table->top = ((void *)0);
    table->level = 0;
    table->scope = scope;
    enter_contour(table);
    resolve_expr(table, expr);
    leave_contour(table);
    free(table);
}

canonical_original_code:
void resolve(struct Expression *expr) {
    struct SymbolTable *table = malloc(sizeof *table);
    if (!table) {
        fatal("Out of memory.");
    }
    struct Scope *scope = make_scope(expr);
    expr->scope = scope;
    table->top = ((void *)0);
    table->level = 0;
    table->scope = scope;
    enter_contour(table);
    resolve_expr(table, expr);
    leave_contour(table);
    free(table);
}

variable_types: struct Expression { enum ExpressionType { TYPE_IF=0, TYPE_WHILE=1, TYPE_ADD=2, TYPE_SUB=3, TYPE_MUL=4, TYPE_DIV=5, TYPE_MOD=6, TYPE_POW=7, TYPE_NEG=8, TYPE_NOT=9, TYPE_ASSIGN=10, TYPE_EQEQ=11, TYPE_NEQ=12, TYPE_LT=13, TYPE_LEQ=14, TYPE_GT=15, TYPE_GEQ=16, TYPE_AND=17, TYPE_OR=18, TYPE_VARREF=19, TYPE_INT=20, TYPE_REAL=21, TYPE_BOOL=22, TYPE_NULL=23, TYPE_STRING=24, TYPE_CALL=25, TYPE_FUNC=26, TYPE_DECLARATION=27, TYPE_BLOCK=28, TYPE_MODULE=29, TYPE_THROW=30 } type; unsigned int immutable; struct Expression *cond; struct Expression *lexpr; struct Expression *rexpr; struct ExpressionList { struct ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; } *head; struct ExpressionNode *tail; } *llist; struct ExpressionList *rlist; struct Symbol { int level; char *name; struct Expression *declaration; } *symbol; struct Scope { struct Expression *expr; struct Scope *parent; struct Symbol **locals; struct Symbol **upvars; struct Scope **children; int numlocals; int numparams; int numupvars; int numchildren; } *scope; struct SourcePos { int first_line; int first_column; int last_line; int last_column; char *filename; } pos; union { int i; double d; char *s; } value; } *


GetHostAttribsFromStr

repo: kwolekr/netgraph

decompiled_code:
__int64 __fastcall GetHostAttribsFromStr(_BYTE *a1)
{
char v1; // si
_BYTE *v2; // rbx
unsigned int v3; // ebp

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = 0;
do
{
switch ( v1 )
{
case 'b':
LOBYTE(v3) = v3 | 0x80;
break;
case 'd':
v3 |= 0x100u;
break;
case 'e':
v3 |= 0x10u;
break;
case 'f':
v3 |= 1u;
break;
case 'g':
v3 |= 0x400u;
break;
case 'l':
v3 |= 0x40u;
break;
case 'n':
v3 = 0;
break;
case 'p':
v3 |= 0x20u;
break;
case 'r':
v3 |= 2u;
break;
case 's':
v3 |= 4u;
break;
case 'u':
v3 |= 0x200u;
break;
case 'v':
v3 |= 8u;
break;
default:
printf("WARNING: unknown host attribute '%c'\n", (unsigned int)v1);
break;
}
v1 = *++v2;
}
while ( *v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
char v1; // si
_BYTE *v2; // rbx
unsigned int v3; // ebp

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = 0;
do
{
switch ( v1 )
{
case 'b':
LOBYTE(v3) = v3 | 0x80;
break;
case 'd':
v3 |= 0x100u;
break;
case 'e':
v3 |= 0x10u;
break;
case 'f':
v3 |= 1u;
break;
case 'g':
v3 |= 0x400u;
break;
case 'l':
v3 |= 0x40u;
break;
case 'n':
v3 = 0;
break;
case 'p':
v3 |= 0x20u;
break;
case 'r':
v3 |= 2u;
break;
case 's':
v3 |= 4u;
break;
case 'u':
v3 |= 0x200u;
break;
case 'v':
v3 |= 8u;
break;
default:
printf("WARNING: unknown host attribute '%c'\n", (unsigned int)v1);
break;
}
v1 = *++v2;
}
while ( *v2 );
return v3;
}

original_code:
int GetHostAttribsFromStr(const char *str) {
 int itmp = 0;
 while (*str) {
  switch (*str) {
   case 'b':
    itmp |= 0x00000080;
    break;
   case 'd':
    itmp |= 0x00000100;
    break;
   case 'e':
    itmp |= 0x00000010;
    break;
   case 'f':
    itmp |= 0x00000001;
    break;
   case 'l':
    itmp |= 0x00000040;
    break;
   case 'n':
    itmp = 0x00000000;
    break;
   case 'p':
    itmp |= 0x00000020;
    break;
   case 'r':
    itmp |= 0x00000002;
    break;
   case 's':
    itmp |= 0x00000004;
    break;
   case 'v':
    itmp |= 0x00000008;
    break;
   case 'u':
    itmp |= 0x00000200;
    break;
   case 'g':
    itmp |= 0x00000400;
    break;
   default:
    printf("WARNING: unknown host attribute \'%c\'\n", *str);
  }
  str++;
 }
 return itmp;
}

canonical_original_code:
int GetHostAttribsFromStr(char *str) {
 int itmp = 0;
 while (*str) {
  switch (*str) {
   case 'b':
    itmp |= 0x00000080;
    break;
   case 'd':
    itmp |= 0x00000100;
    break;
   case 'e':
    itmp |= 0x00000010;
    break;
   case 'f':
    itmp |= 0x00000001;
    break;
   case 'l':
    itmp |= 0x00000040;
    break;
   case 'n':
    itmp = 0x00000000;
    break;
   case 'p':
    itmp |= 0x00000020;
    break;
   case 'r':
    itmp |= 0x00000002;
    break;
   case 's':
    itmp |= 0x00000004;
    break;
   case 'v':
    itmp |= 0x00000008;
    break;
   case 'u':
    itmp |= 0x00000200;
    break;
   case 'g':
    itmp |= 0x00000400;
    break;
   default:
    printf("WARNING: unknown host attribute \'%c\'\n", *str);
  }
  str++;
 }
 return itmp;
}

variable_types:
str
char *

variable_types: itmp int

return_type: int


GetConnAttribsFromStr

decompiled_code:
__int64 __fastcall GetConnAttribsFromStr(_BYTE *a1)
{
char v1; // si
_BYTE *v2; // rbx
unsigned int v3; // ebp

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = 0;
do
{
switch ( v1 )
{
case 'e':
v3 |= 1u;
break;
case 'f':
v3 |= 2u;
break;
case 'g':
v3 |= 4u;
break;
case 't':
v3 |= 8u;
break;
case 'v':
v3 |= 0x10u;
break;
case 'w':
v3 |= 0x20u;
break;
default:
printf("WARNING: unknown connection attribute '%c'\n", (unsigned int)v1);
break;
}
v1 = *++v2;
}
while ( *v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char v1; // si
_BYTE *v2; // rbx
unsigned int v3; // ebp

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = 0;
do
{
switch ( v1 )
{
case 'e':
v3 |= 1u;
break;
case 'f':
v3 |= 2u;
break;
case 'g':
v3 |= 4u;
break;
case 't':
v3 |= 8u;
break;
case 'v':
v3 |= 0x10u;
break;
case 'w':
v3 |= 0x20u;
break;
default:
printf("WARNING: unknown connection attribute '%c'\n", (unsigned int)v1);
break;
}
v1 = *++v2;
}
while ( *v2 );
return v3;
}

original_code:
int GetConnAttribsFromStr(const char *str) {
 int itmp = 0;
 while (*str) {
  switch (*str) {
   case 't':
    itmp |= 0x008;
    break;
   case 'g':
    itmp |= 0x004;
    break;
   case 'f':
    itmp |= 0x002;
    break;
   case 'e':
    itmp |= 0x001;
    break;
   case 'v':
    itmp |= 0x010;
    break;
   case 'w':
    itmp |= 0x020;
    break;
   default:
    printf("WARNING: unknown connection attribute \'%c\'\n", *str);
  }
  str++;
 }
 return itmp;
}

canonical_original_code:
int GetConnAttribsFromStr(char *str) {
 int itmp = 0;
 while (*str) {
  switch (*str) {
   case 't':
    itmp |= 0x008;
    break;
   case 'g':
    itmp |= 0x004;
    break;
   case 'f':
    itmp |= 0x002;
    break;
   case 'e':
    itmp |= 0x001;
    break;
   case 'v':
    itmp |= 0x010;
    break;
   case 'w':
    itmp |= 0x020;
    break;
   default:
    printf("WARNING: unknown connection attribute \'%c\'\n", *str);
  }
  str++;
 }
 return itmp;
}


GetHostColor

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

if ( a1 )
{
if ( (a1 & 0x20) != 0 )
hostattribsused |= 0x20u;
result = 15LL;
if ( (a1 & 0x40) != 0 )
{
hostattribsused |= 0x40u;
result = 17LL;
}
if ( (a1 & 0x10) != 0 )
{
hostattribsused |= 0x10u;
result = 14LL;
}
if ( (a1 & 8) != 0 )
{
hostattribsused |= 8u;
result = 16LL;
}
if ( (a1 & 1) != 0 )
{
hostattribsused |= 1u;
result = 11LL;
}
if ( (a1 & 4) != 0 )
{
hostattribsused |= 4u;
result = 13LL;
}
if ( (a1 & 2) != 0 )
{
hostattribsused |= 2u;
result = 12LL;
}
}
else
{
hostattribsused |= 0x80000000;
result = 9LL;
}
return result;
}

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

if ( a1 )
{
if ( (a1 & 0x20) != 0 )
hostattribsused |= 0x20u;
result = 15LL;
if ( (a1 & 0x40) != 0 )
{
hostattribsused |= 0x40u;
result = 17LL;
}
if ( (a1 & 0x10) != 0 )
{
hostattribsused |= 0x10u;
result = 14LL;
}
if ( (a1 & 8) != 0 )
{
hostattribsused |= 8u;
result = 16LL;
}
if ( (a1 & 1) != 0 )
{
hostattribsused |= 1u;
result = 11LL;
}
if ( (a1 & 4) != 0 )
{
hostattribsused |= 4u;
result = 13LL;
}
if ( (a1 & 2) != 0 )
{
hostattribsused |= 2u;
result = 12LL;
}
}
else
{
hostattribsused |= 0x80000000;
result = 9LL;
}
return result;
}

original_code:
int GetHostColor(int attribs) {
 int ci;
 if (attribs == 0x00000000) {
  ci = 0 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  hostattribsused |= 0x80000000;
 } else {
  if (attribs & 0x00000020) {
   hostattribsused |= 0x00000020;
   ci = 6 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
  if (attribs & 0x00000040) {
   hostattribsused |= 0x00000040;
   ci = 8 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
  if (attribs & 0x00000010) {
   hostattribsused |= 0x00000010;
   ci = 5 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
  if (attribs & 0x00000008) {
   hostattribsused |= 0x00000008;
   ci = 7 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
  if (attribs & 0x00000001) {
   hostattribsused |= 0x00000001;
   ci = 2 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
  if (attribs & 0x00000004) {
   hostattribsused |= 0x00000004;
   ci = 4 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
  if (attribs & 0x00000002) {
   hostattribsused |= 0x00000002;
   ci = 3 + ((sizeof(colordescs) / sizeof(colordescs[0])));
  }
 }
 return ci;
}

variable_types: attribs int

variable_types: ci int


GetConnColor

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

if ( (a1 & 8) != 0 )
connattribsused |= 8u;
result = 2LL;
if ( (a1 & 4) != 0 )
{
connattribsused |= 4u;
result = 3LL;
}
if ( (a1 & 2) != 0 )
{
connattribsused |= 2u;
result = 4LL;
}
if ( (a1 & 1) != 0 )
{
connattribsused |= 1u;
result = 5LL;
}
if ( (a1 & 0x10) != 0 )
{
connattribsused |= 0x10u;
result = 7LL;
}
if ( (a1 & 0x20) != 0 )
{
connattribsused |= 0x20u;
result = 6LL;
}
return result;
}

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

if ( (a1 & 8) != 0 )
connattribsused |= 8u;
result = 2LL;
if ( (a1 & 4) != 0 )
{
connattribsused |= 4u;
result = 3LL;
}
if ( (a1 & 2) != 0 )
{
connattribsused |= 2u;
result = 4LL;
}
if ( (a1 & 1) != 0 )
{
connattribsused |= 1u;
result = 5LL;
}
if ( (a1 & 0x10) != 0 )
{
connattribsused |= 0x10u;
result = 7LL;
}
if ( (a1 & 0x20) != 0 )
{
connattribsused |= 0x20u;
result = 6LL;
}
return result;
}

original_code:
int GetConnColor(int attribs) {
 int ci;
 if (attribs & 0x008) {
  connattribsused |= 0x008;
  ci = 2;
 }
 if (attribs & 0x004) {
  connattribsused |= 0x004;
  ci = 3;
 }
 if (attribs & 0x002) {
  connattribsused |= 0x002;
  ci = 4;
 }
 if (attribs & 0x001) {
  connattribsused |= 0x001;
  ci = 5;
 }
 if (attribs & 0x010) {
  connattribsused |= 0x010;
  ci = 7;
 }
 if (attribs & 0x020) {
  connattribsused |= 0x020;
  ci = 6;
 }
 return ci;
}


lcase

decompiled_code:
void __fastcall lcase(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void lcase(char *str) {
 while (*str) {
  *str = tolower(*str);
  str++;
 }
}


popcount

decompiled_code:
__int64 __fastcall popcount(int a1)
{
unsigned int v1; // edx
int i; // ecx

v1 = 0;
for ( i = 0; i != 32; ++i )
v1 -= (((a1 >> i) & 1) == 0) - 1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned int v1; // edx
int i; // ecx

v1 = 0;
for ( i = 0; i != 32; ++i )
v1 -= (((a1 >> i) & 1) == 0) - 1;
return v1;
}

original_code:
int popcount(int n) {
 int i, count;
 count = 0;
 for (i = 0; i != sizeof(n) * 8; i++) {
  if (n & (1 << i))
   count++;
 }
 return count;
}

canonical_original_code:
int popcount(int n) {
 int i; int count;
 count = 0;
 for (i = 0; i != sizeof(n) * 8; i++) {
  if (n & (1 << i))
   count++;
 }
 return count;
}

variable_types: n int

variable_types: count int


decompiled_code:
void test_get_list_len()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void test_get_list_len(void)
{
}

canonical_original_code:
static void test_get_list_len()
{
}


decompiled_code:
void test_cleanup_list()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static void test_cleanup_list(void)
{
}

canonical_original_code:
static void test_cleanup_list()
{
}


decompiled_code:
void test_insert_list_element()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void test_insert_list_element(void)
{
}

canonical_original_code:
static void test_insert_list_element()
{
}


decompiled_code:
void test_delete_list_element()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
static void test_delete_list_element(void)
{
}

canonical_original_code:
static void test_delete_list_element()
{
}


decompiled_code:
void test_fetch_list_element()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
static void test_fetch_list_element(void)
{
}

canonical_original_code:
static void test_fetch_list_element()
{
}


decompiled_code:
void test_destory_list()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
static void test_destory_list(void)
{
}

canonical_original_code:
static void test_destory_list()
{
}


decompiled_code:
__int64 init_suite()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 0LL;
}

original_code:
static int init_suite(void)
{
        return CUE_SUCCESS;
}

canonical_original_code:
static int init_suite()
{
        return CUE_SUCCESS;
}


decompiled_code:
__int64 test_init_list()
{
ps_list = init_list(0LL);
CU_assertImplementation(ps_list == 0, 26LL, "CU_ASSERT_PTR_NULL(ps_list)", "suite_seq_list.c", &unk_308, 0LL);
ps_list = init_list(0xFFFFFFFFLL);
CU_assertImplementation(ps_list == 0, 31LL, "CU_ASSERT_PTR_NULL(ps_list)", "suite_seq_list.c", &unk_308, 0LL);
ps_list = init_list(1LL);
CU_assertImplementation(ps_list != 0, 36LL, "CU_ASSERT_PTR_NOT_NULL(ps_list)", "suite_seq_list.c", &unk_308, 0LL);
CU_assertImplementation(
*(_DWORD *)(ps_list + 8) == 1,
37LL,
"CU_ASSERT_EQUAL(ps_list->element_size,element_size)",
"suite_seq_list.c",
&unk_308,
0LL);
return CU_assertImplementation(
*(_DWORD *)(ps_list + 12) == 0,
38LL,
"CU_ASSERT_EQUAL(ps_list->length,0)",
"suite_seq_list.c",
&unk_308,
0LL);
}

canonical_decompiled_code:
__int64 func7()
{
ps_list = init_list(0LL);
CU_assertImplementation(ps_list == 0, 26LL, "CU_ASSERT_PTR_NULL(ps_list)", "suite_seq_list.c", &unk_308, 0LL);
ps_list = init_list(0xFFFFFFFFLL);
CU_assertImplementation(ps_list == 0, 31LL, "CU_ASSERT_PTR_NULL(ps_list)", "suite_seq_list.c", &unk_308, 0LL);
ps_list = init_list(1LL);
CU_assertImplementation(ps_list != 0, 36LL, "CU_ASSERT_PTR_NOT_NULL(ps_list)", "suite_seq_list.c", &unk_308, 0LL);
CU_assertImplementation(
*(_DWORD *)(ps_list + 8) == 1,
37LL,
"CU_ASSERT_EQUAL(ps_list->element_size,element_size)",
"suite_seq_list.c",
&unk_308,
0LL);
return CU_assertImplementation(
*(_DWORD *)(ps_list + 12) == 0,
38LL,
"CU_ASSERT_EQUAL(ps_list->length,0)",
"suite_seq_list.c",
&unk_308,
0LL);
}

original_code:
static void test_init_list(void)
{
        int element_size = 0;
        element_size = 0;
        ps_list = init_list(element_size);
        { CU_assertImplementation((((void *)0) == (const void*)(ps_list)), 26, ("CU_ASSERT_PTR_NULL(" "ps_list"")"), "suite_seq_list.c", "", 0); };
        element_size = -1;
        ps_list = init_list(element_size);
        { CU_assertImplementation((((void *)0) == (const void*)(ps_list)), 31, ("CU_ASSERT_PTR_NULL(" "ps_list"")"), "suite_seq_list.c", "", 0); };
        element_size = 1;
        ps_list = init_list(element_size);
        { CU_assertImplementation((((void *)0) != (const void*)(ps_list)), 36, ("CU_ASSERT_PTR_NOT_NULL(" "ps_list"")"), "suite_seq_list.c", "", 0); };
        { CU_assertImplementation(((ps_list->element_size) == (element_size)), 37, ("CU_ASSERT_EQUAL(" "ps_list->element_size" "," "element_size" ")"), "suite_seq_list.c", "", 0); };
        { CU_assertImplementation(((ps_list->length) == (0)), 38, ("CU_ASSERT_EQUAL(" "ps_list->length" "," "0" ")"), "suite_seq_list.c", "", 0); };
}

canonical_original_code:
static void test_init_list()
{
        int element_size = 0;
        element_size = 0;
        ps_list = init_list(element_size);
        { CU_assertImplementation((((void *)0) == (void *)(ps_list)), 26, ("CU_ASSERT_PTR_NULL(" "ps_list"")"), "suite_seq_list.c", "", 0); };
        element_size = -1;
        ps_list = init_list(element_size);
        { CU_assertImplementation((((void *)0) == (void *)(ps_list)), 31, ("CU_ASSERT_PTR_NULL(" "ps_list"")"), "suite_seq_list.c", "", 0); };
        element_size = 1;
        ps_list = init_list(element_size);
        { CU_assertImplementation((((void *)0) != (void *)(ps_list)), 36, ("CU_ASSERT_PTR_NOT_NULL(" "ps_list"")"), "suite_seq_list.c", "", 0); };
        { CU_assertImplementation(((ps_list->element_size) == (element_size)), 37, ("CU_ASSERT_EQUAL(" "ps_list->element_size" "," "element_size" ")"), "suite_seq_list.c", "", 0); };
        { CU_assertImplementation(((ps_list->length) == (0)), 38, ("CU_ASSERT_EQUAL(" "ps_list->length" "," "0" ")"), "suite_seq_list.c", "", 0); };
}


decompiled_code:
__int64 cleanup_suite()
{
destory_list(ps_list);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
destory_list(ps_list);
return 0LL;
}

original_code:
static int cleanup_suite(void)
{
        destory_list(ps_list);
        return CUE_SUCCESS;
}

canonical_original_code:
static int cleanup_suite()
{
        destory_list(ps_list);
        return CUE_SUCCESS;
}


decompiled_code:
int add_seq_list_suite()
{
int result; // eax

result = CU_register_suites(&suites);
if ( result )
result = report_suite_reg_error(result, "add_seq_list_suite");
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax

result = CU_register_suites(&suites);
if ( result )
result = func9(result, "add_seq_list_suite");
return result;
}

original_code:
void add_seq_list_suite(void)
{
        CU_ErrorCode error = CU_register_suites(suites);
        if (error != CUE_SUCCESS)
                report_suite_reg_error(error, __func__);
        return ;
}

canonical_original_code:
void add_seq_list_suite()
{
        enum CU_ErrorCode error = CU_register_suites(suites);
        if (error != CUE_SUCCESS)
                report_suite_reg_error(error, __func__);
        return ;
}

variable_types: enum CU_ErrorCode { CUE_SUCCESS=0, CUE_NOMEMORY=1, CUE_NOREGISTRY=10, CUE_REGISTRY_EXISTS=11, CUE_NOSUITE=20, CUE_NO_SUITENAME=21, CUE_SINIT_FAILED=22, CUE_SCLEAN_FAILED=23, CUE_DUP_SUITE=24, CUE_SUITE_INACTIVE=25, CUE_NOTEST=30, CUE_NO_TESTNAME=31, CUE_DUP_TEST=32, CUE_TEST_NOT_IN_SUITE=33, CUE_TEST_INACTIVE=34, CUE_FOPEN_FAILED=40, CUE_FCLOSE_FAILED=41, CUE_BAD_FILENAME=42, CUE_WRITE_ERROR=43 }


decompiled_code:
bool __fastcall check_ins_del_func_param(__int64 a1, __int64 a2, unsigned int a3)
{
bool result; // al

result = a2 == 0 || a1 == 0;
if ( result )
return 0;
if ( a3 <= 0xFFF && *(_QWORD *)a1 && *(int *)(a1 + 8) > 0 )
result = *(_DWORD *)(a1 + 12) >= (int)a3 && *(_DWORD *)(a1 + 12) <= 4095;
return result;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1, __int64 a2, unsigned int a3)
{
bool result; // al

result = a2 == 0 || a1 == 0;
if ( result )
return 0;
if ( a3 <= 0xFFF && *(_QWORD *)a1 && *(int *)(a1 + 8) > 0 )
result = *(_DWORD *)(a1 + 12) >= (int)a3 && *(_DWORD *)(a1 + 12) <= 4095;
return result;
}

original_code:
static _Bool check_ins_del_func_param(seq_list *const s_list,
                                const void *const element,
                                const int location)
{
        if (s_list == ((void *)0) || element == ((void *)0))
                return 0;
        if (location < 0 || location >= (4096))
                return 0;
        if (s_list->data == ((void *)0))
                return 0;
        if (s_list->element_size <= 0)
                return 0;
        if (s_list->length < location || s_list->length >= (4096))
                return 0;
        return 1;
}

canonical_original_code:
static _Bool check_ins_del_func_param(struct seq_list *s_list, void *element, int location)
{
        if (s_list == ((void *)0) || element == ((void *)0))
                return 0;
        if (location < 0 || location >= (4096))
                return 0;
        if (s_list->data == ((void *)0))
                return 0;
        if (s_list->element_size <= 0)
                return 0;
        if (s_list->length < location || s_list->length >= (4096))
                return 0;
        return 1;
}

variable_types: struct seq_list { unsigned char *data; int element_size; int length; } *

variable_types:
element
void *

variable_types: location int


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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_list_len(seq_list *const s_list)
{
        if (s_list == ((void *)0))
                return -1;
        return s_list->length;
}

canonical_original_code:
int get_list_len(struct seq_list *s_list)
{
        if (s_list == ((void *)0))
                return -1;
        return s_list->length;
}

user_defined_types: struct seq_list { unsigned char *data; int element_size; int length; }


decompiled_code:
void *__fastcall cleanup_list(__int64 a1)
{
void *v2; // rdi
void *result; // rax

if ( a1 )
{
v2 = *(void **)a1;
if ( v2 )
{
result = memset(v2, 0, *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 12));
*(_DWORD *)(a1 + 12) = 0;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
void *v2; // rdi
void *result; // rax

if ( a1 )
{
v2 = *(void **)a1;
if ( v2 )
{
result = memset(v2, 0, *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 12));
*(_DWORD *)(a1 + 12) = 0;
}
}
return result;
}

original_code:
void cleanup_list(seq_list *const s_list)
{
        if (s_list == ((void *)0) || s_list->data == ((void *)0))
                return ;
        memset(s_list->data, 0, s_list->length * s_list->element_size);
        s_list->length = 0;
        return ;
}

canonical_original_code:
void cleanup_list(struct seq_list *s_list)
{
        if (s_list == ((void *)0) || s_list->data == ((void *)0))
                return ;
        memset(s_list->data, 0, s_list->length * s_list->element_size);
        s_list->length = 0;
        return ;
}


decompiled_code:
__int64 __fastcall insert_list_element(__int64 a1, const void *a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // ebp
char *v7; // r14

LOBYTE(v4) = check_ins_del_func_param(a1, (__int64)a2, a3);
v5 = v4;
if ( (_BYTE)v4 )
{
v7 = (char *)(*(_QWORD *)a1 + (int)(a3 * *(_DWORD *)(a1 + 8)));
memcpy(&v7[*(int *)(a1 + 8)], v7, (int)(*(_DWORD *)(a1 + 8) * (*(_DWORD *)(a1 + 12) - a3)));
memcpy(v7, a2, *(int *)(a1 + 8));
++*(_DWORD *)(a1 + 12);
}
return v5;
}

original_code:
_Bool insert_list_element(seq_list *const s_list,
                        const void *const element,
                        const int location)
{
        if (check_ins_del_func_param(s_list, element, location) == 0)
                return 0;
        char *p_insert = (char *) (s_list->data + (s_list->element_size * location));
        memcpy( p_insert + s_list->element_size,
                p_insert,
                (s_list->length - location) * s_list->element_size);
        memcpy(p_insert, element, s_list->element_size);
        s_list->length++;
        return 1;
}

canonical_original_code:
_Bool insert_list_element(struct seq_list *s_list, void *element, int location)
{
        if (check_ins_del_func_param(s_list, element, location) == 0)
                return 0;
        char *p_insert = (char *) (s_list->data + (s_list->element_size * location));
        memcpy( p_insert + s_list->element_size,
                p_insert,
                (s_list->length - location) * s_list->element_size);
        memcpy(p_insert, element, s_list->element_size);
        s_list->length++;
        return 1;
}


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 <= 0x1000 )
{
v3 = *(_DWORD *)(a1 + 8);
memcpy(
(void *)(*(_QWORD *)a1 + (int)(a2 * v3)),
(const void *)(*(_QWORD *)a1 + (int)(a2 * v3) + v3),
(int)(v3 * (*(_DWORD *)(a1 + 12) + ~a2)));
--*(_DWORD *)(a1 + 12);
result = 1LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 <= 0x1000 )
{
v3 = *(_DWORD *)(a1 + 8);
memcpy(
(void *)(*(_QWORD *)a1 + (int)(a2 * v3)),
(const void *)(*(_QWORD *)a1 + (int)(a2 * v3) + v3),
(int)(v3 * (*(_DWORD *)(a1 + 12) + ~a2)));
--*(_DWORD *)(a1 + 12);
result = 1LL;
}
return result;
}

original_code:
_Bool delete_list_element(seq_list *const s_list,
                        const int location)
{
        if (s_list == ((void *)0))
                return 0;
        if (location < 0 || location > (4096))
                return 0;
        char *element = (char *) (s_list->data + (s_list->element_size * location));
        memcpy( element,
                element + s_list->element_size,
                (s_list->length - location - 1) * s_list->element_size);
        s_list->length--;
        return 1;
}

canonical_original_code:
_Bool delete_list_element(struct seq_list *s_list, int location)
{
        if (s_list == ((void *)0))
                return 0;
        if (location < 0 || location > (4096))
                return 0;
        char *element = (char *) (s_list->data + (s_list->element_size * location));
        memcpy( element,
                element + s_list->element_size,
                (s_list->length - location - 1) * s_list->element_size);
        s_list->length--;
        return 1;
}

variable_types:
element
char *


decompiled_code:
bool __fastcall fetch_list_element(__int64 a1, __int64 a2, unsigned int a3)
{
bool result; // al

if ( a1 )
result = a3 <= 0x1000;
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func11(__int64 a1, __int64 a2, unsigned int a3)
{
bool result; // al

if ( a1 )
result = a3 <= 0x1000;
else
result = 0;
return result;
}

original_code:
_Bool fetch_list_element(seq_list *const s_list,
                        void *element,
                        const int location)
{
        if (s_list == ((void *)0))
                return 0;
        if (location < 0 || location > (4096))
                return 0;
        element = (void *) (s_list->data + location * s_list->element_size);
        return 1;
}

canonical_original_code:
_Bool fetch_list_element(struct seq_list *s_list, void *element, int location)
{
        if (s_list == ((void *)0))
                return 0;
        if (location < 0 || location > (4096))
                return 0;
        element = (void *) (s_list->data + location * s_list->element_size);
        return 1;
}


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

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

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

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

original_code:
void destory_list(seq_list *const s_list)
{
        if (s_list != ((void *)0)) {
                if (s_list->data != ((void *)0))
                        free(s_list->data);
                free(s_list);
        }
}

canonical_original_code:
void destory_list(struct seq_list *s_list)
{
        if (s_list != ((void *)0)) {
                if (s_list->data != ((void *)0))
                        free(s_list->data);
                free(s_list);
        }
}


repo: kylelol/MIPS-Assembler-Final-Project

decompiled_code:
_DWORD *vector_string_create()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax
_QWORD *v3; // rbx
_QWORD *v4; // rbp
void *v5; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector_string_t\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
v1 = v0;
*v0 = 4;
v2 = malloc(0x20uLL);
*((_QWORD *)v1 + 1) = v2;
v1[4] = 0;
if ( !v2 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector->elements\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
v3 = v2;
v4 = v2 + 4;
do
{
v5 = malloc(0x400uLL);
*v3 = v5;
if ( !v5 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector->elements[i]\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
++v3;
}
while ( v3 != v4 );
return v1;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax
_QWORD *v3; // rbx
_QWORD *v4; // rbp
void *v5; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector_string_t\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
v1 = v0;
*v0 = 4;
v2 = malloc(0x20uLL);
*((_QWORD *)v1 + 1) = v2;
v1[4] = 0;
if ( !v2 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector->elements\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
v3 = v2;
v4 = v2 + 4;
do
{
v5 = malloc(0x400uLL);
*v3 = v5;
if ( !v5 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector->elements[i]\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
++v3;
}
while ( v3 != v4 );
return v1;
}

original_code:
vector_string_t *
vector_string_create()
{
    vector_string_t * v;
    int i;
    if (!(v = malloc(sizeof(vector_string_t))))
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_string_create vector_string_t\n");
        exit(1);
    }
    v->capacity = 4;
    v->elements = malloc(4 * sizeof(char *));
    v->size = 0;
    if (!v->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_string_create vector->elements\n");
        exit(1);
    }
    for (i = 0; i < 4; i++)
    {
        if (!(v->elements[i] = malloc(1024 * sizeof(char))))
        {
            fprintf(stderr, "*** malloc failed ***\n");
            fprintf(stderr, "vector_string_create vector->elements[i]\n");
            exit(1);
        }
    }
    return v;
}

canonical_original_code:
struct vector_string *vector_string_create()
{
    struct vector_string *v;
    int i;
    if (!(v = malloc(sizeof(vector_string_t))))
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_string_create vector_string_t\n");
        exit(1);
    }
    v->capacity = 4;
    v->elements = malloc(4 * sizeof(char *));
    v->size = 0;
    if (!v->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_string_create vector->elements\n");
        exit(1);
    }
    for (i = 0; i < 4; i++)
    {
        if (!(v->elements[i] = malloc(1024 * sizeof(char))))
        {
            fprintf(stderr, "*** malloc failed ***\n");
            fprintf(stderr, "vector_string_create vector->elements[i]\n");
            exit(1);
        }
    }
    return v;
}

variable_types: struct vector_string { int capacity; char **elements; int size; } *

variable_types: i int


decompiled_code:
void __fastcall vector_string_destroy(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((_QWORD *)ptr + 1) )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((_QWORD *)ptr + 1) )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
}
free(ptr);
}

original_code:
void
vector_string_destroy(vector_string_t * vector)
{
    int i;
    if (vector->elements)
    {
        for (i = 0; i < vector->capacity; i++)
        {
            if (vector->elements[i])
            {
                free(vector->elements[i]);
            }
        }
        free(vector->elements);
    }
    free(vector);
}

canonical_original_code:
void vector_string_destroy(struct vector_string *vector)
{
    int i;
    if (vector->elements)
    {
        for (i = 0; i < vector->capacity; i++)
        {
            if (vector->elements[i])
            {
                free(vector->elements[i]);
            }
        }
        free(vector->elements);
    }
    free(vector);
}

user_defined_types: struct vector_string { int capacity; char **elements; int size; }


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

result = 0LL;
if ( a3 >= 0 && *(_DWORD *)(a1 + 16) > a3 )
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + 8LL * a3), a2);
result = *(unsigned int *)(a1 + 16);
}
return result;
}

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

result = 0LL;
if ( a3 >= 0 && *(_DWORD *)(a1 + 16) > a3 )
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + 8LL * a3), a2);
result = *(unsigned int *)(a1 + 16);
}
return result;
}

original_code:
int
vector_string_set(
                  vector_string_t * vector,
                  char * string,
                  int index
                 )
{
    if (index < 0 || vector->size <= index)
    {
        return 0;
    }
    strcpy(vector->elements[index], string);
    return vector->size;
}

canonical_original_code:
int vector_string_set(struct vector_string *vector, char *string, int index)
{
    if (index < 0 || vector->size <= index)
    {
        return 0;
    }
    strcpy(vector->elements[index], string);
    return vector->size;
}

variable_types:
string
char *

variable_types: index int


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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 16) > a2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 16) > a2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
char *
vector_string_get(
                  vector_string_t * vector,
                  int index
                 )
{
    return (0 <= index && index < vector->size)
           ? vector->elements[index]
           : ((void *)0);
}

canonical_original_code:
char *vector_string_get(struct vector_string *vector, int index)
{
    return (0 <= index && index < vector->size)
           ? vector->elements[index]
           : ((void *)0);
}

return_type: char *


decompiled_code:
__int64 __fastcall vector_string_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int
vector_string_size(vector_string_t * vector)
{
    return vector->size;
}

canonical_original_code:
int vector_string_size(struct vector_string *vector)
{
    return vector->size;
}


decompiled_code:
bool __fastcall vector_string_is_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 16) == 0;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 16) == 0;
}

original_code:
char
vector_string_is_empty(vector_string_t * vector)
{
    return vector->size == 0;
}

canonical_original_code:
char vector_string_is_empty(struct vector_string *vector)
{
    return vector->size == 0;
}

return_type: char


decompiled_code:
__int64 __fastcall vector_string_change_capacity(unsigned int *a1, int a2)
{
int v2; // ebx
_QWORD *v3; // r15
__int64 v4; // rbx
char *v5; // rax
char *v6; // r12
void *v7; // rax
__int64 v8; // rbx
__int64 result; // rax
_QWORD *v10; // r13
void *v11; // rax
char *v12; // r13

v2 = a1[4];
v3 = malloc(8LL * v2);
if ( v2 > 0 )
{
v4 = 0LL;
do
{
v5 = (char *)malloc(0x400uLL);
v3[v4] = v5;
v6 = *(char **)(*((_QWORD *)a1 + 1) + 8 * v4);
strcpy(v5, v6);
free(v6);
++v4;
}
while ( (int)a1[4] > (int)v4 );
}
free(*((void **)a1 + 1));
v7 = malloc(8LL * a2);
*((_QWORD *)a1 + 1) = v7;
if ( !v7 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_string_change_capacity from %i to %i\n", *a1, (unsigned int)a2);
exit(1);
}
v8 = 0LL;
if ( a2 > 0 )
{
do
{
v10 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v8);
v11 = malloc(0x400uLL);
*v10 = v11;
if ( !v11 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_string_change_capacity from %i to %i\n", *a1, (unsigned int)a2);
exit(1);
}
if ( (int)a1[4] > (int)v8 )
{
v12 = (char *)v3[v8];
strcpy(*(char **)(*((_QWORD *)a1 + 1) + 8 * v8), v12);
free(v12);
}
++v8;
}
while ( v8 != a2 );
}
free(v3);
result = (unsigned int)a2;
*a1 = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, int a2)
{
int v2; // ebx
_QWORD *v3; // r15
__int64 v4; // rbx
char *v5; // rax
char *v6; // r12
void *v7; // rax
__int64 v8; // rbx
__int64 result; // rax
_QWORD *v10; // r13
void *v11; // rax
char *v12; // r13

v2 = a1[4];
v3 = malloc(8LL * v2);
if ( v2 > 0 )
{
v4 = 0LL;
do
{
v5 = (char *)malloc(0x400uLL);
v3[v4] = v5;
v6 = *(char **)(*((_QWORD *)a1 + 1) + 8 * v4);
strcpy(v5, v6);
free(v6);
++v4;
}
while ( (int)a1[4] > (int)v4 );
}
free(*((void **)a1 + 1));
v7 = malloc(8LL * a2);
*((_QWORD *)a1 + 1) = v7;
if ( !v7 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_string_change_capacity from %i to %i\n", *a1, (unsigned int)a2);
exit(1);
}
v8 = 0LL;
if ( a2 > 0 )
{
do
{
v10 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v8);
v11 = malloc(0x400uLL);
*v10 = v11;
if ( !v11 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_string_change_capacity from %i to %i\n", *a1, (unsigned int)a2);
exit(1);
}
if ( (int)a1[4] > (int)v8 )
{
v12 = (char *)v3[v8];
strcpy(*(char **)(*((_QWORD *)a1 + 1) + 8 * v8), v12);
free(v12);
}
++v8;
}
while ( v8 != a2 );
}
free(v3);
result = (unsigned int)a2;
*a1 = a2;
return result;
}

original_code:
void
vector_string_change_capacity(
                              vector_string_t * vector,
                              int new_capacity
                             )
{
    char ** tmp;
    int tmp_size;
    int i;
    tmp = malloc(vector->size * sizeof(char *));
    for (i = 0; i < vector->size; i++)
    {
        tmp[i] = malloc(1024 * sizeof(char));
        strcpy(tmp[i], vector->elements[i]);
        free(vector->elements[i]);
    }
    free(vector->elements);
    vector->elements = malloc(new_capacity * sizeof(char *));
    if (!vector->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(
                stderr,
                "vector_string_change_capacity from %i to %i\n",
                vector->capacity,
                new_capacity
               );
        exit(1);
    }
    for (i = 0; i < new_capacity; i++)
    {
        if (!(vector->elements[i] = malloc(1024 * sizeof(char))))
        {
            fprintf(stderr, "*** malloc failed ***\n");
            fprintf(
                    stderr,
                    "vector_string_change_capacity from %i to %i\n",
                    vector->capacity,
                    new_capacity
                   );
            exit(1);
        }
        if (i < vector->size)
        {
            strcpy(vector->elements[i], tmp[i]);
            free(tmp[i]);
        }
    }
    free(tmp);
    vector->capacity = new_capacity;
}

canonical_original_code:
void vector_string_change_capacity(struct vector_string *vector, int new_capacity)
{
    char **tmp;
    int tmp_size;
    int i;
    tmp = malloc(vector->size * sizeof(char *));
    for (i = 0; i < vector->size; i++)
    {
        tmp[i] = malloc(1024 * sizeof(char));
        strcpy(tmp[i], vector->elements[i]);
        free(vector->elements[i]);
    }
    free(vector->elements);
    vector->elements = malloc(new_capacity * sizeof(char *));
    if (!vector->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(
                stderr,
                "vector_string_change_capacity from %i to %i\n",
                vector->capacity,
                new_capacity
               );
        exit(1);
    }
    for (i = 0; i < new_capacity; i++)
    {
        if (!(vector->elements[i] = malloc(1024 * sizeof(char))))
        {
            fprintf(stderr, "*** malloc failed ***\n");
            fprintf(
                    stderr,
                    "vector_string_change_capacity from %i to %i\n",
                    vector->capacity,
                    new_capacity
                   );
            exit(1);
        }
        if (i < vector->size)
        {
            strcpy(vector->elements[i], tmp[i]);
            free(tmp[i]);
        }
    }
    free(tmp);
    vector->capacity = new_capacity;
}

variable_types:
tmp
char **


decompiled_code:
__int64 __fastcall vector_string_add(__int64 a1, const char *a2, int a3)
{
int v4; // eax
__int64 v5; // rbx
unsigned __int64 v6; // r13
__int64 result; // rax

if ( a3 < 0 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 16) + 1 >= *(_DWORD *)a1 )
vector_string_change_capacity((unsigned int *)a1, 2 * *(_DWORD *)a1);
v4 = *(_DWORD *)(a1 + 16);
if ( v4 <= a3 )
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + 8LL * v4), a2);
}
else
{
v5 = 8LL * v4 - 8;
v6 = 8 * (v4 - (unsigned __int64)(unsigned int)(v4 - 1 - a3)) - 16;
do
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + v5 + 8), *(const char **)(*(_QWORD *)(a1 + 8) + v5));
v5 -= 8LL;
}
while ( v5 != v6 );
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + 8LL * a3), a2);
}
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, int a3)
{
int v4; // eax
__int64 v5; // rbx
unsigned __int64 v6; // r13
__int64 result; // rax

if ( a3 < 0 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 16) + 1 >= *(_DWORD *)a1 )
func7((unsigned int *)a1, 2 * *(_DWORD *)a1);
v4 = *(_DWORD *)(a1 + 16);
if ( v4 <= a3 )
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + 8LL * v4), a2);
}
else
{
v5 = 8LL * v4 - 8;
v6 = 8 * (v4 - (unsigned __int64)(unsigned int)(v4 - 1 - a3)) - 16;
do
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + v5 + 8), *(const char **)(*(_QWORD *)(a1 + 8) + v5));
v5 -= 8LL;
}
while ( v5 != v6 );
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + 8LL * a3), a2);
}
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
return result;
}

original_code:
int
vector_string_add(
                  vector_string_t * vector,
                  char * string,
                  int index
                 )
{
    int i;
    if (index < 0)
    {
        return -1;
    }
    if (vector->size + 1 >= vector->capacity)
    {
        vector_string_change_capacity(vector, vector->capacity << 1);
    }
    if (index < vector->size)
    {
        for (i = vector->size; index < i; i--)
        {
            strcpy(vector->elements[i], vector->elements[i - 1]);
        }
        strcpy(vector->elements[index], string);
    }
    else
    {
        strcpy(vector->elements[vector->size], string);
    }
    return ++vector->size;
}

canonical_original_code:
int vector_string_add(struct vector_string *vector, char *string, int index)
{
    int i;
    if (index < 0)
    {
        return -1;
    }
    if (vector->size + 1 >= vector->capacity)
    {
        vector_string_change_capacity(vector, vector->capacity << 1);
    }
    if (index < vector->size)
    {
        for (i = vector->size; index < i; i--)
        {
            strcpy(vector->elements[i], vector->elements[i - 1]);
        }
        strcpy(vector->elements[index], string);
    }
    else
    {
        strcpy(vector->elements[vector->size], string);
    }
    return ++vector->size;
}


decompiled_code:
__int64 __fastcall vector_string_add_first(__int64 a1, const char *a2)
{
return vector_string_add(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
return func8(a1, a2, 0);
}

original_code:
int
vector_string_add_first(
                        vector_string_t * vector,
                        char * string
                       )
{
    return vector_string_add(vector, string, 0);
}

canonical_original_code:
int vector_string_add_first(struct vector_string *vector, char *string)
{
    return vector_string_add(vector, string, 0);
}


decompiled_code:
__int64 __fastcall vector_string_add_last(__int64 a1, const char *a2)
{
return vector_string_add(a1, a2, *(_DWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
return func8(a1, a2, *(_DWORD *)(a1 + 16));
}

original_code:
int
vector_string_add_last(
                       vector_string_t * vector,
                       char * string
                      )
{
    return vector_string_add(vector, string, vector->size);
}

canonical_original_code:
int vector_string_add_last(struct vector_string *vector, char *string)
{
    return vector_string_add(vector, string, vector->size);
}


decompiled_code:
__int64 __fastcall vector_string_remove(__int64 a1, int a2)
{
int v2; // ebx
int v3; // eax
__int64 v4; // r12
int v5; // eax
int v6; // esi

if ( a2 < 0 )
return 0xFFFFFFFFLL;
v2 = a2;
v3 = *(_DWORD *)(a1 + 16);
if ( v3 <= a2 )
return 0xFFFFFFFFLL;
if ( v3 > 1 && v3 - 1 > a2 )
{
v4 = 8LL * a2 + 8;
do
{
strcpy(*(char **)(*(_QWORD *)(a1 + 8) + v4 - 8), *(const char **)(*(_QWORD *)(a1 + 8) + v4));
++v2;
v4 += 8LL;
}
while ( *(_DWORD *)(a1 + 16) > v2 );
}
v5 = *(_DWORD *)(a1 + 16) - 1;
*(_DWORD *)(a1 + 16) = v5;
if ( *(int *)a1 > 4 )
{
v6 = *(int *)a1 >> 1;
if ( v5 < v6 )
vector_string_change_capacity((unsigned int *)a1, v6);
}
return *(unsigned int *)(a1 + 16);
}

original_code:
int
vector_string_remove(
                     vector_string_t * vector,
                     int index
                    )
{
    int i;
    if (index < 0 || vector->size <= index)
    {
        return -1;
    }
    if (1 < vector->size && index < vector->size - 1)
    {
        for (i = index; i < vector->size; i++)
        {
            strcpy(vector->elements[i], vector->elements[i + 1]);
        }
    }
    vector->size--;
    if (4 < vector->capacity
            && vector->size < vector->capacity >> 1)
    {
       vector_string_change_capacity(vector, vector->capacity >> 1);
    }
    return vector->size;
}

canonical_original_code:
int vector_string_remove(struct vector_string *vector, int index)
{
    int i;
    if (index < 0 || vector->size <= index)
    {
        return -1;
    }
    if (1 < vector->size && index < vector->size - 1)
    {
        for (i = index; i < vector->size; i++)
        {
            strcpy(vector->elements[i], vector->elements[i + 1]);
        }
    }
    vector->size--;
    if (4 < vector->capacity
            && vector->size < vector->capacity >> 1)
    {
       vector_string_change_capacity(vector, vector->capacity >> 1);
    }
    return vector->size;
}


decompiled_code:
__int64 __fastcall vector_string_remove_first(__int64 a1)
{
return vector_string_remove(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func11(a1, 0);
}

original_code:
int
vector_string_remove_first(vector_string_t * vector)
{
    return vector_string_remove(vector, 0);
}

canonical_original_code:
int vector_string_remove_first(struct vector_string *vector)
{
    return vector_string_remove(vector, 0);
}


decompiled_code:
__int64 __fastcall vector_string_remove_last(__int64 a1)
{
return vector_string_remove(a1, *(_DWORD *)(a1 + 16) - 1);
}

original_code:
int
vector_string_remove_last(vector_string_t * vector)
{
    return vector_string_remove(vector, vector->size - 1);
}

canonical_original_code:
int vector_string_remove_last(struct vector_string *vector)
{
    return vector_string_remove(vector, vector->size - 1);
}


decompiled_code:
_DWORD *vector_uint_create()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
void *v2; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_uint_create vector_uint_t\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v1 = v0;
*v0 = 4;
v2 = malloc(0x10uLL);
*((_QWORD *)v1 + 1) = v2;
v1[4] = 0;
if ( !v2 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_uint_create vector->elements\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
return v1;
}

canonical_decompiled_code:
_DWORD *func14()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
void *v2; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_uint_create vector_uint_t\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v1 = v0;
*v0 = 4;
v2 = malloc(0x10uLL);
*((_QWORD *)v1 + 1) = v2;
v1[4] = 0;
if ( !v2 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_uint_create vector->elements\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
return v1;
}

original_code:
vector_uint_t *
vector_uint_create()
{
    vector_uint_t * v;
    int i;
    if (!(v = malloc(sizeof(vector_uint_t))))
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_uint_create vector_uint_t\n");
        exit(1);
    }
    v->capacity = 4;
    v->elements = malloc(4 * sizeof(unsigned int));
    v->size = 0;
    if (!v->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_uint_create vector->elements\n");
        exit(1);
    }
    return v;
}

canonical_original_code:
struct vector_uint *vector_uint_create()
{
    struct vector_uint *v;
    int i;
    if (!(v = malloc(sizeof(vector_uint_t))))
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_uint_create vector_uint_t\n");
        exit(1);
    }
    v->capacity = 4;
    v->elements = malloc(4 * sizeof(unsigned int));
    v->size = 0;
    if (!v->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(stderr, "vector_uint_create vector->elements\n");
        exit(1);
    }
    return v;
}

variable_types: struct vector_uint { int capacity; unsigned int *elements; int size; } *


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

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
vector_uint_destroy(vector_uint_t * vector)
{
    if (vector->elements)
    {
        free(vector->elements);
    }
    free(vector);
}

canonical_original_code:
void vector_uint_destroy(struct vector_uint *vector)
{
    if (vector->elements)
    {
        free(vector->elements);
    }
    free(vector);
}

user_defined_types: struct vector_uint { int capacity; unsigned int *elements; int size; }


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

result = 0LL;
if ( a3 >= 0 && *(_DWORD *)(a1 + 16) > a3 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a3) = a2;
result = *(unsigned int *)(a1 + 16);
}
return result;
}

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

result = 0LL;
if ( a3 >= 0 && *(_DWORD *)(a1 + 16) > a3 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a3) = a2;
result = *(unsigned int *)(a1 + 16);
}
return result;
}

original_code:
int
vector_uint_set(
                vector_uint_t * vector,
                unsigned int number,
                int index
               )
{
    if (index < 0 || vector->size <= index)
    {
        return 0;
    }
    vector->elements[index] = number;
    return vector->size;
}

canonical_original_code:
int vector_uint_set(struct vector_uint *vector, unsigned int number, int index)
{
    if (index < 0 || vector->size <= index)
    {
        return 0;
    }
    vector->elements[index] = number;
    return vector->size;
}

variable_types:
number
unsigned int


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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 16) > a2 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * a2);
return result;
}

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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)(a1 + 16) > a2 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * a2);
return result;
}

original_code:
unsigned int
vector_uint_get(
                vector_uint_t * vector,
                int index
               )
{
    return (0 <= index && index < vector->size)
           ? vector->elements[index]
           : 0;
}

canonical_original_code:
unsigned int vector_uint_get(struct vector_uint *vector, int index)
{
    return (0 <= index && index < vector->size)
           ? vector->elements[index]
           : 0;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall vector_uint_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int
vector_uint_size(vector_uint_t * vector)
{
    return vector->size;
}

canonical_original_code:
int vector_uint_size(struct vector_uint *vector)
{
    return vector->size;
}


decompiled_code:
bool __fastcall vector_uint_is_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 16) == 0;
}

canonical_decompiled_code:
bool __fastcall func20(__int64 a1)
{
return *(_DWORD *)(a1 + 16) == 0;
}

original_code:
char
vector_uint_is_empty(vector_uint_t * vector)
{
    return vector->size == 0;
}

canonical_original_code:
char vector_uint_is_empty(struct vector_uint *vector)
{
    return vector->size == 0;
}


decompiled_code:
void __fastcall vector_uint_change_capacity(int *a1, int a2)
{
int v3; // er13
_DWORD *v4; // rbp
__int64 v5; // rsi
__int64 i; // rax
void *v7; // rax
__int64 v8; // rax

v3 = a1[4];
v4 = malloc(4LL * v3);
if ( v3 > 0 )
{
v5 = *((_QWORD *)a1 + 1);
for ( i = 0LL; i != v3; ++i )
v4[i] = *(_DWORD *)(v5 + 4 * i);
}
free(*((void **)a1 + 1));
v7 = malloc(4LL * a2);
*((_QWORD *)a1 + 1) = v7;
if ( !v7 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_uint_change_capacity from %i to %i\n", (unsigned int)*a1, (unsigned int)a2);
exit(1);
}
v8 = 0LL;
if ( a2 > 0 )
{
do
{
if ( a1[4] > (int)v8 )
*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v8) = v4[v8];
++v8;
}
while ( v8 != a2 );
}
free(v4);
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func21(int *a1, int a2)
{
int v3; // er13
_DWORD *v4; // rbp
__int64 v5; // rsi
__int64 i; // rax
void *v7; // rax
__int64 v8; // rax

v3 = a1[4];
v4 = malloc(4LL * v3);
if ( v3 > 0 )
{
v5 = *((_QWORD *)a1 + 1);
for ( i = 0LL; i != v3; ++i )
v4[i] = *(_DWORD *)(v5 + 4 * i);
}
free(*((void **)a1 + 1));
v7 = malloc(4LL * a2);
*((_QWORD *)a1 + 1) = v7;
if ( !v7 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_uint_change_capacity from %i to %i\n", (unsigned int)*a1, (unsigned int)a2);
exit(1);
}
v8 = 0LL;
if ( a2 > 0 )
{
do
{
if ( a1[4] > (int)v8 )
*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v8) = v4[v8];
++v8;
}
while ( v8 != a2 );
}
free(v4);
*a1 = a2;
}

original_code:
void
vector_uint_change_capacity(
                            vector_uint_t * vector,
                            int new_capacity
                           )
{
    unsigned int * tmp;
    int tmp_size;
    int i;
    tmp = malloc(vector->size * sizeof(unsigned));
    for (i = 0; i < vector->size; i++)
    {
        tmp[i] = vector->elements[i];
    }
    free(vector->elements);
    vector->elements = malloc(new_capacity * sizeof(unsigned));
    if (!vector->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(
                stderr,
                "vector_uint_change_capacity from %i to %i\n",
                vector->capacity,
                new_capacity
               );
        exit(1);
    }
    for (i = 0; i < new_capacity; i++)
    {
        if (i < vector->size)
        {
            vector->elements[i] = tmp[i];
        }
    }
    free(tmp);
    vector->capacity = new_capacity;
}

canonical_original_code:
void vector_uint_change_capacity(struct vector_uint *vector, int new_capacity)
{
    unsigned int *tmp;
    int tmp_size;
    int i;
    tmp = malloc(vector->size * sizeof(unsigned int));
    for (i = 0; i < vector->size; i++)
    {
        tmp[i] = vector->elements[i];
    }
    free(vector->elements);
    vector->elements = malloc(new_capacity * sizeof(unsigned int));
    if (!vector->elements)
    {
        fprintf(stderr, "*** malloc failed ***\n");
        fprintf(
                stderr,
                "vector_uint_change_capacity from %i to %i\n",
                vector->capacity,
                new_capacity
               );
        exit(1);
    }
    for (i = 0; i < new_capacity; i++)
    {
        if (i < vector->size)
        {
            vector->elements[i] = tmp[i];
        }
    }
    free(tmp);
    vector->capacity = new_capacity;
}

variable_types:
tmp
unsigned int *


decompiled_code:
__int64 __fastcall vector_uint_add(__int64 a1, int a2, int a3)
{
int v4; // edx
__int64 v5; // rax
__int64 result; // rax

if ( a3 < 0 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 16) + 1 >= *(_DWORD *)a1 )
vector_uint_change_capacity((int *)a1, 2 * *(_DWORD *)a1);
v4 = *(_DWORD *)(a1 + 16);
if ( v4 <= a3 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * v4) = a2;
}
else
{
v5 = 4LL * v4 - 4;
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + v5 + 4) = *(_DWORD *)(*(_QWORD *)(a1 + 8) + v5);
v5 -= 4LL;
}
while ( v5 != 4 * (v4 - (unsigned __int64)(unsigned int)(v4 - 1 - a3)) - 8 );
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a3) = a2;
}
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
return result;
}

original_code:
int
vector_uint_add(
                vector_uint_t * vector,
                unsigned int number,
                int index
               )
{
    int i;
    if (index < 0)
    {
        return -1;
    }
    if (vector->size + 1 >= vector->capacity)
    {
        vector_uint_change_capacity(vector, vector->capacity << 1);
    }
    if (index < vector->size)
    {
        for (i = vector->size; index < i; i--)
        {
            vector->elements[i] = vector->elements[i - 1];
        }
        vector->elements[index] = number;
    }
    else
    {
        vector->elements[vector->size] = number;
    }
    return ++vector->size;
}

canonical_original_code:
int vector_uint_add(struct vector_uint *vector, unsigned int number, int index)
{
    int i;
    if (index < 0)
    {
        return -1;
    }
    if (vector->size + 1 >= vector->capacity)
    {
        vector_uint_change_capacity(vector, vector->capacity << 1);
    }
    if (index < vector->size)
    {
        for (i = vector->size; index < i; i--)
        {
            vector->elements[i] = vector->elements[i - 1];
        }
        vector->elements[index] = number;
    }
    else
    {
        vector->elements[vector->size] = number;
    }
    return ++vector->size;
}


decompiled_code:
__int64 __fastcall vector_uint_add_first(__int64 a1, int a2)
{
return vector_uint_add(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, int a2)
{
return func22(a1, a2, 0);
}

original_code:
int
vector_uint_add_first(
                      vector_uint_t * vector,
                      unsigned int number
                     )
{
    return vector_uint_add(vector, number, 0);
}

canonical_original_code:
int vector_uint_add_first(struct vector_uint *vector, unsigned int number)
{
    return vector_uint_add(vector, number, 0);
}


decompiled_code:
__int64 __fastcall vector_uint_add_last(__int64 a1, int a2)
{
return vector_uint_add(a1, a2, *(_DWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, int a2)
{
return func22(a1, a2, *(_DWORD *)(a1 + 16));
}

original_code:
int
vector_uint_add_last(
                     vector_uint_t * vector,
                     unsigned int number
                    )
{
    return vector_uint_add(vector, number, vector->size);
}

canonical_original_code:
int vector_uint_add_last(struct vector_uint *vector, unsigned int number)
{
    return vector_uint_add(vector, number, vector->size);
}


original_code:
int
vector_uint_remove(
                   vector_uint_t * vector,
                   int index
                  )
{
    int i;
    if (index < 0 || vector->size <= index)
    {
        return -1;
    }
    if (1 < vector->size && index < vector->size - 1)
    {
        for (i = index; i < vector->size; i++)
        {
            vector->elements[i] = vector->elements[i + 1];
        }
    }
    vector->size--;
    if (4 < vector->capacity
            && vector->size < vector->capacity >> 1)
    {
       vector_uint_change_capacity(vector, vector->capacity >> 1);
    }
    return vector->size;
}

canonical_original_code:
int vector_uint_remove(struct vector_uint *vector, int index)
{
    int i;
    if (index < 0 || vector->size <= index)
    {
        return -1;
    }
    if (1 < vector->size && index < vector->size - 1)
    {
        for (i = index; i < vector->size; i++)
        {
            vector->elements[i] = vector->elements[i + 1];
        }
    }
    vector->size--;
    if (4 < vector->capacity
            && vector->size < vector->capacity >> 1)
    {
       vector_uint_change_capacity(vector, vector->capacity >> 1);
    }
    return vector->size;
}


decompiled_code:
__int64 __fastcall vector_uint_remove_first(__int64 a1)
{
return vector_uint_remove(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
return func25(a1, 0);
}

original_code:
int
vector_uint_remove_first(vector_uint_t * vector)
{
    return vector_uint_remove(vector, 0);
}

canonical_original_code:
int vector_uint_remove_first(struct vector_uint *vector)
{
    return vector_uint_remove(vector, 0);
}


decompiled_code:
__int64 __fastcall vector_uint_remove_last(__int64 a1)
{
return vector_uint_remove(a1, *(_DWORD *)(a1 + 16) - 1);
}

original_code:
int
vector_uint_remove_last(vector_uint_t * vector)
{
    return vector_uint_remove(vector, vector->size - 1);
}

canonical_original_code:
int vector_uint_remove_last(struct vector_uint *vector)
{
    return vector_uint_remove(vector, vector->size - 1);
}


original_code:
char *
string_trim(char * string)
{
    int i, j, k, l;
    i = 0;
    while (string[i] <= ' ' && string[i] != '\0')
    {
        i++;
    }
    j = strlen(string) - 1;
    while (0 < j && string[j] <= ' ')
    {
        j--;
    }
    for (k = 0, l = i; l <= j; k++, l++)
    {
        string[k] = string[l];
    }
    string[k] = '\0';
    return string;
}

canonical_original_code:
char *string_trim(char *string)
{
    int i; int j; int k; int l;
    i = 0;
    while (string[i] <= ' ' && string[i] != '\0')
    {
        i++;
    }
    j = strlen(string) - 1;
    while (0 < j && string[j] <= ' ')
    {
        j--;
    }
    for (k = 0, l = i; l <= j; k++, l++)
    {
        string[k] = string[l];
    }
    string[k] = '\0';
    return string;
}

variable_types: j int

variable_types: k int

variable_types: l int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
size_t v5; // rbx
double *v6; // r12
double *v7; // r13
double *v8; // r14
double *v9; // r15
__int64 v10; // rbx
__int64 v11; // rbx

if ( argc == 2 )
{
v3 = atoi(argv[1]);
v4 = v3;
if ( !v3 )
{
puts("Error in command line argument, should be a single nonzero integer.");
exit(1);
}
v5 = v3;
v6 = (double *)calloc(v3, 8uLL);
v7 = (double *)calloc(v5, 8uLL);
v8 = (double *)calloc(v5, 8uLL);
v9 = (double *)calloc(v5, 8uLL);
nullsub_1((unsigned int)v4, v6, v7, v8, v9);
printf(
"Type (%i, %i) best rational function approximant to matrix exponential.\n",
(unsigned int)v4,
(unsigned int)v4);
puts("poles: ");
if ( v4 <= 0 )
{
putchar(10);
puts("residuals: ");
goto LABEL_11;
}
}
else
{
v6 = (double *)calloc(0xAuLL, 8uLL);
v7 = (double *)calloc(0xAuLL, 8uLL);
v8 = (double *)calloc(0xAuLL, 8uLL);
v9 = (double *)calloc(0xAuLL, 8uLL);
nullsub_1(10LL, v6, v7, v8, v9);
printf("Type (%i, %i) best rational function approximant to matrix exponential.\n", 10LL, 10LL);
puts("poles: ");
v4 = 10;
}
v10 = 0LL;
do
{
printf("%.15e + %.15e i\n", v6[v10], v7[v10]);
++v10;
}
while ( v4 > (int)v10 );
putchar(10);
puts("residuals: ");
v11 = 0LL;
do
{
printf("%.15e + %.15e i\n", v8[v11], v9[v11]);
++v11;
}
while ( v4 > (int)v11 );
LABEL_11:
putchar(10);
free(v6);
free(v7);
free(v8);
free(v9);
return 0;
}

original_code:
int main (int argc, char *argv[]) {
 int n = 10;
 if (argc == 2) {
  n = atoi (argv[1]);
  if (n == 0) {
   printf ("Error in command line argument, should be a single nonzero integer.\n");
   exit (1);
  }
 }
 double *poles_r = (double*) calloc (n, sizeof(double));
 double *poles_i = (double*) calloc (n, sizeof(double));
 double *res_r = (double*) calloc (n, sizeof(double));
 double *res_i = (double*) calloc (n, sizeof(double));
 cf ( n, poles_r, poles_i, res_r, res_i );
 printf("Type (%i, %i) best rational function approximant to matrix exponential.\n", n, n);
 printf("poles: \n");
 for (int i = 0; i < n; ++i) {
  printf("%.15e + %.15e i\n", poles_r[i], poles_i[i]);
 }
 printf("\n");
 printf("residuals: \n");
 for (int i = 0; i < n; ++i) {
  printf("%.15e + %.15e i\n", res_r[i], res_i[i]);
 }
 printf("\n");
 free (poles_r);
 free (poles_i);
 free (res_r);
 free (res_i);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int n = 10;
 if (argc == 2) {
  n = atoi (argv[1]);
  if (n == 0) {
   printf ("Error in command line argument, should be a single nonzero integer.\n");
   exit (1);
  }
 }
 double *poles_r = (double*) calloc (n, sizeof(double));
 double *poles_i = (double*) calloc (n, sizeof(double));
 double *res_r = (double*) calloc (n, sizeof(double));
 double *res_i = (double*) calloc (n, sizeof(double));
 cf ( n, poles_r, poles_i, res_r, res_i );
 printf("Type (%i, %i) best rational function approximant to matrix exponential.\n", n, n);
 printf("poles: \n");
 for (int i = 0; i < n; ++i) {
  printf("%.15e + %.15e i\n", poles_r[i], poles_i[i]);
 }
 printf("\n");
 printf("residuals: \n");
 for (int i = 0; i < n; ++i) {
  printf("%.15e + %.15e i\n", res_r[i], res_i[i]);
 }
 printf("\n");
 free (poles_r);
 free (poles_i);
 free (res_r);
 free (res_i);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n int


SetSeed

decompiled_code:
void __fastcall SetSeed(unsigned int a1)
{
srand(a1);
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
srand(a1);
}

original_code:
void SetSeed (int seed)
{
 srand(seed);
}

canonical_original_code:
void SetSeed(int seed)
{
 srand(seed);
}

variable_types: seed int


RandomNumber

decompiled_code:
__int64 __fastcall RandomNumber(int a1, int a2)
{
return (unsigned int)(rand() % (a2 - a1 + 1) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)(rand() % (a2 - a1 + 1) + a1);
}

original_code:
int RandomNumber (int min, int max)
{
 return min + (rand() % ((max - min) + 1));
}

canonical_original_code:
int RandomNumber(int min, int max)
{
 return min + (rand() % ((max - min) + 1));
}

variable_types: min int

variable_types: max int