decompiled_code:
int *init_gfx_charmap()
{
__int64 v0; // rax
__int64 v1; // rdi
unsigned int v2; // er13
int v3; // eax
__int16 v4; // r15
int *v5; // r14
int *v6; // r12
int v7; // ebx
int *result; // rax
__int16 v9; // [rsp+6h] [rbp-4Ah]
int *v10; // [rsp+8h] [rbp-48h]
__int64 v11; // [rsp+18h] [rbp-38h] BYREF

v11 = 0x1000100000000LL;
v0 = SDL_CreateRGBSurface(0LL, 336LL, 8LL, 8LL, 255LL, 255LL, 255LL, 0LL);
v1 = *(_QWORD *)(v0 + 8);
charmapsurface = v0;
v10 = (int *)&unk_500;
v9 = 0;
v2 = SDL_MapRGB(v1, 255LL, 255LL, 255LL);
v3 = 0;
while ( 2 )
{
v4 = v9;
v5 = v10 - 8;
while ( 2 )
{
v6 = v5;
v7 = 0;
while ( v3 != 1 )
{
if ( ++v7 == 8 )
goto LABEL_8;
LABEL_5:
v3 = *v6;
v6 += 8;
}
WORD1(v11) = v7++;
LOWORD(v11) = v4;
SDL_FillRect(charmapsurface, &v11, v2);
if ( v7 != 8 )
goto LABEL_5;
LABEL_8:
++v4;
if ( ++v5 != v10 )
{
v3 = *(v5 - 8);
continue;
}
break;
}
v10 += 64;
result = v10;
v9 += 8;
if ( v10 != (int *)&unk_2F00 )
{
v3 = *(v10 - 16);
continue;
}
break;
}
++charmap_inited;
return result;
}

original_code:
static void init_gfx_charmap(void) {
    int i, x, y;
    uint32_t color;
    SDL_Rect pixel = { 0, 0, 1, 1 };
    charmapsurface = SDL_CreateRGBSurface(0x00000000, 8*42, 8, 8, 255, 255, 255, 0);
    color = SDL_MapRGB(charmapsurface->format, 255,255,255);
    for (i=0;i<42;i++) {
        for (x=0;x<8;x++) {
            for (y=0;y<8;y++) {
                if ( charmap[i][y][x] == 1 ) {
                    pixel.x = x+(i*8);
                    pixel.y = y;
                    SDL_FillRect(charmapsurface,&pixel,color);
                }
            }
        }
    }
    charmap_inited++;
}

canonical_original_code:
static void init_gfx_charmap() {
    int i; int x; int y;
    unsigned int color;
    struct SDL_Rect pixel = { 0, 0, 1, 1 };
    charmapsurface = SDL_CreateRGBSurface(0x00000000, 8*42, 8, 8, 255, 255, 255, 0);
    color = SDL_MapRGB(charmapsurface->format, 255,255,255);
    for (i=0;i<42;i++) {
        for (x=0;x<8;x++) {
            for (y=0;y<8;y++) {
                if ( charmap[i][y][x] == 1 ) {
                    pixel.x = x+(i*8);
                    pixel.y = y;
                    SDL_FillRect(charmapsurface,&pixel,color);
                }
            }
        }
    }
    charmap_inited++;
}

variable_types:
color
unsigned int


repo: kvisle/awesometd

decompiled_code:
__int64 init_timers()
{
render_t = 24;
dword_194 = 3;
SDL_AddTimer(16LL, timedrenderevent, &render_t);
report_fps_t = 24;
dword_174 = 1;
SDL_AddTimer(1000LL, timeduserevent, &report_fps_t);
game_cycle_t = 24;
dword_154 = 2;
return SDL_AddTimer(10LL, timeduserevent, &game_cycle_t);
}

canonical_decompiled_code:
__int64 func2()
{
render_t = 24;
dword_194 = 3;
SDL_AddTimer(16LL, timedrenderevent, &render_t);
report_fps_t = 24;
dword_174 = 1;
SDL_AddTimer(1000LL, timeduserevent, &report_fps_t);
game_cycle_t = 24;
dword_154 = 2;
return SDL_AddTimer(10LL, timeduserevent, &game_cycle_t);
}

original_code:
void init_timers(void) {
    render_t.type = SDL_USEREVENT;
    render_t.user.code = 3;
    render_id = SDL_AddTimer(1000/60, timedrenderevent, &render_t);
    report_fps_t.type = SDL_USEREVENT;
    report_fps_t.user.code = 1;
    report_fps_id = SDL_AddTimer(1000, timeduserevent, &report_fps_t);
    game_cycle_t.type = SDL_USEREVENT;
    game_cycle_t.user.code = 2;
    game_cycle_id = SDL_AddTimer(10, timeduserevent, &game_cycle_t);
}

canonical_original_code:
void init_timers() {
    render_t.type = SDL_USEREVENT;
    render_t.user.code = 3;
    render_id = SDL_AddTimer(1000/60, timedrenderevent, &render_t);
    report_fps_t.type = SDL_USEREVENT;
    report_fps_t.user.code = 1;
    report_fps_id = SDL_AddTimer(1000, timeduserevent, &report_fps_t);
    game_cycle_t.type = SDL_USEREVENT;
    game_cycle_t.user.code = 2;
    game_cycle_id = SDL_AddTimer(10, timeduserevent, &game_cycle_t);
}

return_type: void


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

result = waitingforrender;
if ( waitingforrender )
{
waitingforrender = 0;
}
else
{
result = puts("WTF? waitingforrender == 0?!");
waitingforrender = 1;
}
return result;
}

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

result = waitingforrender;
if ( waitingforrender )
{
waitingforrender = 0;
}
else
{
result = puts("WTF? waitingforrender == 0?!");
waitingforrender = 1;
}
return result;
}

original_code:
void mark_rendered(void) {
    if ( waitingforrender == 0 ) {
        printf("WTF? waitingforrender == 0?!\n");
        waitingforrender = 1;
        return;
    }
    waitingforrender = 0;
}

canonical_original_code:
void mark_rendered() {
    if ( waitingforrender == 0 ) {
        printf("WTF? waitingforrender == 0?!\n");
        waitingforrender = 1;
        return;
    }
    waitingforrender = 0;
}


decompiled_code:
__int64 draw_menu()
{
char *v0; // r12
int v1; // ebx
__int64 v2; // rcx
char *v3; // rsi
__int64 result; // rax
__int64 v5; // [rsp-10h] [rbp-20h]

v0 = options;
v1 = 0;
do
{
v2 = (unsigned int)(16 * v1 + 200);
if ( selected == v1 )
v5 = 0LL;
else
v5 = 255LL;
v3 = v0;
++v1;
v0 += 12;
draw_text_color(screen, v3, 400LL, v2, 255LL, 255LL);
result = v5;
}
while ( v1 != 5 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // r12
int v1; // ebx
__int64 v2; // rcx
char *v3; // rsi
__int64 result; // rax
__int64 v5; // [rsp-10h] [rbp-20h]

v0 = options;
v1 = 0;
do
{
v2 = (unsigned int)(16 * v1 + 200);
if ( selected == v1 )
v5 = 0LL;
else
v5 = 255LL;
v3 = v0;
++v1;
v0 += 12;
draw_text_color(screen, v3, 400LL, v2, 255LL, 255LL);
result = v5;
}
while ( v1 != 5 );
return result;
}

original_code:
void draw_menu(void) {
    int i;
    int ypos = 200;
    for (i=0;i<5;i++) {
        if ( i == selected )
            draw_text_color(screen,options[i],400,ypos,255,255,0);
        else
            draw_text_color(screen,options[i],400,ypos,255,255,255);
        ypos += 16;
    }
}

canonical_original_code:
void draw_menu() {
    int i;
    int ypos = 200;
    for (i=0;i<5;i++) {
        if ( i == selected )
            draw_text_color(screen,options[i],400,ypos,255,255,0);
        else
            draw_text_color(screen,options[i],400,ypos,255,255,255);
        ypos += 16;
    }
}

variable_types: i int

variable_types: ypos int


decompiled_code:
__int64 click_menu()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-4h]

switch ( selected )
{
case 0:
v1 = selected;
new_game();
result = v1;
break;
case 1:
show_highscores(0LL);
result = 0LL;
break;
case 2:
show_tutorial();
goto LABEL_7;
case 3:
show_credits();
result = 0LL;
break;
case 4:
result = 1LL;
break;
default:
LABEL_7:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-4h]

switch ( selected )
{
case 0:
v1 = selected;
new_game();
result = v1;
break;
case 1:
show_highscores(0LL);
result = 0LL;
break;
case 2:
show_tutorial();
goto LABEL_7;
case 3:
show_credits();
result = 0LL;
break;
case 4:
result = 1LL;
break;
default:
LABEL_7:
result = 0LL;
break;
}
return result;
}

original_code:
int click_menu(void) {
    switch (selected) {
        case 0:
            new_game();
        break;
        case 1:
            show_highscores(0);
        break;
        case 2:
            show_tutorial();
        break;
        case 3:
            show_credits();
        break;
        case 4:
            return 1;
        break;
    }
    return 0;
}

canonical_original_code:
int click_menu() {
    switch (selected) {
        case 0:
            new_game();
        break;
        case 1:
            show_highscores(0);
        break;
        case 2:
            show_tutorial();
        break;
        case 3:
            show_credits();
        break;
        case 4:
            return 1;
        break;
    }
    return 0;
}

return_type: int


decompiled_code:
void __fastcall update_menu_selection(int a1, int a2)
{
int v2; // esi

if ( (unsigned int)(a1 - 400) <= 0x58 )
{
v2 = a2 - 200;
if ( (unsigned int)v2 <= 0x4F )
selected = v2 >> 4;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
int v2; // esi

if ( (unsigned int)(a1 - 400) <= 0x58 )
{
v2 = a2 - 200;
if ( (unsigned int)v2 <= 0x4F )
selected = v2 >> 4;
}
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 show_menu()
{
current_screen = 1;
game_paused = 0;
return update_all();
}

canonical_decompiled_code:
__int64 func3()
{
current_screen = 1;
game_paused = 0;
return update_all();
}

original_code:
void show_menu(void) {
    current_screen = 1;
    game_paused = 0;
    update_all();
}

canonical_original_code:
void show_menu() {
    current_screen = 1;
    game_paused = 0;
    update_all();
}


main

canonical_name: main

repo: kwingmei/softTV

decompiled_code:
// attributes: thunk
int __cdecl main(int argc, const char **argv, const char **envp)
{
return get_soft_tv(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func6(argc, argv, envp);
}

original_code:
int main( void )
{
 get_soft_tv();
 return 0;
}

canonical_original_code:
int main()
{
 get_soft_tv();
 return 0;
}


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

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

original_code:
int get_soft_tv(void)
{
 return 0;
}

canonical_original_code:
int get_soft_tv()
{
 return 0;
}


repo: kwiskia/chinnu

decompiled_code:
void __fastcall free_scope(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

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

original_code:
void free_scope(Scope *scope) {
    free(scope->locals);
    free(scope->upvars);
    free(scope->children);
    free(scope);
}

canonical_original_code:
void free_scope(struct Scope *scope) {
    free(scope->locals);
    free(scope->upvars);
    free(scope->children);
    free(scope);
}

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

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 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:
__int64 __fastcall add_local(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12

result = *(unsigned int *)(a1 + 40);
v3 = *(_QWORD **)(a1 + 16);
if ( (result & 7) == 0 )
{
v3 = realloc(*(void **)(a1 + 16), 24LL * ((int)result + 8));
if ( !v3 )
fatal("Out of memory.");
*(_QWORD *)(a1 + 16) = v3;
result = *(unsigned int *)(a1 + 40);
}
v3[(int)result] = a2;
*(_DWORD *)(a1 + 40) = result + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12

result = *(unsigned int *)(a1 + 40);
v3 = *(_QWORD **)(a1 + 16);
if ( (result & 7) == 0 )
{
v3 = realloc(*(void **)(a1 + 16), 24LL * ((int)result + 8));
if ( !v3 )
fatal("Out of memory.");
*(_QWORD *)(a1 + 16) = v3;
result = *(unsigned int *)(a1 + 40);
}
v3[(int)result] = a2;
*(_DWORD *)(a1 + 40) = result + 1;
return result;
}

original_code:
int add_local(Scope *scope, Symbol *local) {
    if (scope->numlocals % 8 == 0) {
        Symbol **resize = realloc(scope->locals, (scope->numlocals + 8) * sizeof **resize);
        if (!resize) {
            fatal("Out of memory.");
        }
        scope->locals = resize;
    }
    scope->locals[scope->numlocals] = local;
    return scope->numlocals++;
}

canonical_original_code:
int add_local(struct Scope *scope, struct Symbol *local) {
    if (scope->numlocals % 8 == 0) {
        struct Symbol **resize = realloc(scope->locals, (scope->numlocals + 8) * sizeof **resize);
        if (!resize) {
            fatal("Out of memory.");
        }
        scope->locals = resize;
    }
    scope->locals[scope->numlocals] = local;
    return scope->numlocals++;
}

variable_types:
local
struct Symbol *

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

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


decompiled_code:
__int64 __fastcall add_upvar(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12

result = *(unsigned int *)(a1 + 48);
v3 = *(_QWORD **)(a1 + 24);
if ( (result & 7) == 0 )
{
v3 = realloc(*(void **)(a1 + 24), 24LL * ((int)result + 8));
if ( !v3 )
fatal("Out of memory.");
*(_QWORD *)(a1 + 24) = v3;
result = *(unsigned int *)(a1 + 48);
}
v3[(int)result] = a2;
*(_DWORD *)(a1 + 48) = result + 1;
return result;
}

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

result = *(unsigned int *)(a1 + 48);
v3 = *(_QWORD **)(a1 + 24);
if ( (result & 7) == 0 )
{
v3 = realloc(*(void **)(a1 + 24), 24LL * ((int)result + 8));
if ( !v3 )
fatal("Out of memory.");
*(_QWORD *)(a1 + 24) = v3;
result = *(unsigned int *)(a1 + 48);
}
v3[(int)result] = a2;
*(_DWORD *)(a1 + 48) = result + 1;
return result;
}

original_code:
int add_upvar(Scope *scope, Symbol *upvar) {
    if (scope->numupvars % 8 == 0) {
        Symbol **resize = realloc(scope->upvars, (scope->numupvars + 8) * sizeof **resize);
        if (!resize) {
            fatal("Out of memory.");
        }
        scope->upvars = resize;
    }
    scope->upvars[scope->numupvars] = upvar;
    return scope->numupvars++;
}

canonical_original_code:
int add_upvar(struct Scope *scope, struct Symbol *upvar) {
    if (scope->numupvars % 8 == 0) {
        struct Symbol **resize = realloc(scope->upvars, (scope->numupvars + 8) * sizeof **resize);
        if (!resize) {
            fatal("Out of memory.");
        }
        scope->upvars = resize;
    }
    scope->upvars[scope->numupvars] = upvar;
    return scope->numupvars++;
}

variable_types:
upvar
struct Symbol *

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 ExpressionNode { struct Expression *expr; struct ExpressionNode *next; struct ExpressionNode *prev; }


decompiled_code:
__int64 __fastcall add_child(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12

result = *(unsigned int *)(a1 + 52);
v3 = *(_QWORD **)(a1 + 32);
if ( (result & 7) == 0 )
{
v3 = realloc(*(void **)(a1 + 32), 56LL * ((int)result + 8));
if ( !v3 )
fatal("Out of memory.");
*(_QWORD *)(a1 + 32) = v3;
result = *(unsigned int *)(a1 + 52);
}
v3[(int)result] = a2;
*(_DWORD *)(a1 + 52) = result + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12

result = *(unsigned int *)(a1 + 52);
v3 = *(_QWORD **)(a1 + 32);
if ( (result & 7) == 0 )
{
v3 = realloc(*(void **)(a1 + 32), 56LL * ((int)result + 8));
if ( !v3 )
fatal("Out of memory.");
*(_QWORD *)(a1 + 32) = v3;
result = *(unsigned int *)(a1 + 52);
}
v3[(int)result] = a2;
*(_DWORD *)(a1 + 52) = result + 1;
return result;
}

original_code:
int add_child(Scope *scope, Scope *child) {
    if (scope->numchildren % 8 == 0) {
        Scope **resize = realloc(scope->children, (scope->numchildren + 8) * sizeof **resize);
        if (!resize) {
            fatal("Out of memory.");
        }
        scope->children = resize;
    }
    scope->children[scope->numchildren] = child;
    return scope->numchildren++;
}

canonical_original_code:
int add_child(struct Scope *scope, struct Scope *child) {
    if (scope->numchildren % 8 == 0) {
        struct Scope **resize = realloc(scope->children, (scope->numchildren + 8) * sizeof **resize);
        if (!resize) {
            fatal("Out of memory.");
        }
        scope->children = resize;
    }
    scope->children[scope->numchildren] = child;
    return scope->numchildren++;
}

variable_types:
child
struct Scope *

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


decompiled_code:
__int64 __fastcall local_index(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 40);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 40);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int local_index(Scope *scope, Symbol *symbol) {
    int i;
    for (i = 0; i < scope->numlocals; i++) {
        if (scope->locals[i] == symbol) {
            return i;
        }
    }
    return -1;
}

canonical_original_code:
int local_index(struct Scope *scope, struct Symbol *symbol) {
    int i;
    for (i = 0; i < scope->numlocals; i++) {
        if (scope->locals[i] == symbol) {
            return i;
        }
    }
    return -1;
}

variable_types:
symbol
struct Symbol *


decompiled_code:
__int64 __fastcall upvar_index(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 48);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

v2 = *(int *)(a1 + 48);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int upvar_index(Scope *scope, Symbol *symbol) {
    int i;
    for (i = 0; i < scope->numupvars; i++) {
        if (scope->upvars[i] == symbol) {
            return i;
        }
    }
    return -1;
}

canonical_original_code:
int upvar_index(struct Scope *scope, struct Symbol *symbol) {
    int i;
    for (i = 0; i < scope->numupvars; i++) {
        if (scope->upvars[i] == symbol) {
            return i;
        }
    }
    return -1;
}


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

result = upvar_index(a1, a2);
if ( (_DWORD)result == -1 )
{
if ( (unsigned int)local_index(*(_QWORD *)(a1 + 8), a2) == -1 )
register_upvar();
result = add_upvar(a1, a2);
}
return result;
}

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

result = func5(a1, a2);
if ( (_DWORD)result == -1 )
{
if ( (unsigned int)func4(*(_QWORD *)(a1 + 8), a2) == -1 )
func6();
result = func2(a1, a2);
}
return result;
}

original_code:
int register_upvar(Scope *scope, Symbol *symbol) {
    int index = upvar_index(scope, symbol);
    if (index != -1) {
        return index;
    }
    if (local_index(scope->parent, symbol) == -1) {
        register_upvar(scope->parent, symbol);
    }
    return add_upvar(scope, symbol);
}

canonical_original_code:
int register_upvar(struct Scope *scope, struct Symbol *symbol) {
    int index = upvar_index(scope, symbol);
    if (index != -1) {
        return index;
    }
    if (local_index(scope->parent, symbol) == -1) {
        register_upvar(scope->parent, symbol);
    }
    return add_upvar(scope, symbol);
}

variable_types: index int


hash

original_code:
int hash(char *str) {
    int hash = 5381;
    int c;
    while ((c = *str++)) {
        hash = ((hash << 5) + hash) ^ c;
    }
    return hash % MAP_SIZE;
}

variable_types:
str
char *

variable_types: hash int

variable_types: c int


decompiled_code:
__int64 __fastcall contour_search(__int64 a1, char *a2)
{
int v2; // eax
_QWORD *v3; // r8
_QWORD *v4; // rbx
__int64 v5; // r12

v2 = hash(a2);
v4 = *(_QWORD **)(*v3 + 8LL * v2);
if ( !v4 )
return 0LL;
while ( 1 )
{
v5 = *v4;
if ( !strcmp(*(const char **)(*v4 + 8LL), a2) )
break;
v4 = (_QWORD *)v4[1];
if ( !v4 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char *a2)
{
int v2; // eax
_QWORD *v3; // r8
_QWORD *v4; // rbx
__int64 v5; // r12

v2 = func7(a2);
v4 = *(_QWORD **)(*v3 + 8LL * v2);
if ( !v4 )
return 0LL;
while ( 1 )
{
v5 = *v4;
if ( !strcmp(*(const char **)(*v4 + 8LL), a2) )
break;
v4 = (_QWORD *)v4[1];
if ( !v4 )
return 0LL;
}
return v5;
}

original_code:
Symbol *contour_search(Contour *contour, char *name) {
    HashItem *head;
    for (head = contour->buckets[hash(name)]; head != ((void *)0); head = head->next) {
        if (strcmp(head->symbol->name, name) == 0) {
            return head->symbol;
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct Symbol *contour_search(struct Contour *contour, char *name) {
    struct HashItem *head;
    for (head = contour->buckets[hash(name)]; head != ((void *)0); head = head->next) {
        if (strcmp(head->symbol->name, name) == 0) {
            return head->symbol;
        }
    }
    return ((void *)0);
}

variable_types: struct Contour { struct HashItem { struct Symbol *symbol; struct HashItem *next; } **buckets; struct Contour *next; } *

variable_types:
name
char *

variable_types: 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; } *

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


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

v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
{
fatal("Empty contour.");
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
return 0LL;
}
while ( 1 )
{
result = contour_search(v2, a2);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return result;
}

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

v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
{
fatal("Empty contour.");
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
return 0LL;
}
while ( 1 )
{
result = func9(v2, a2);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return result;
}

original_code:
Symbol *find_symbol(SymbolTable *table, char *name) {
    if (!table->top) {
        fatal("Empty contour.");
    }
    Contour *head;
    for (head = table->top; head != ((void *)0); head = head->next) {
        Symbol *s;
        if ((s = contour_search(head, name)) != ((void *)0)) {
            return s;
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct Symbol *find_symbol(struct SymbolTable *table, char *name) {
    if (!table->top) {
        fatal("Empty contour.");
    }
    struct Contour *head;
    for (head = table->top; head != ((void *)0); head = head->next) {
        struct Symbol *s;
        if ((s = contour_search(head, name)) != ((void *)0)) {
            return s;
        }
    }
    return ((void *)0);
}

variable_types: struct SymbolTable { int level; struct Contour { struct HashItem { struct Symbol *symbol; struct HashItem *next; } **buckets; struct Contour *next; } *top; struct Scope *scope; } *

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

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


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

v1 = malloc(0x10uLL);
v2 = malloc(0x200uLL);
v3 = v2;
if ( !v1 || !v2 )
fatal("Out of memory.");
*v1 = v3;
memset(v3, 0, 0x100uLL);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v1;
v1[1] = result;
return result;
}

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

v1 = malloc(0x10uLL);
v2 = malloc(0x200uLL);
v3 = v2;
if ( !v1 || !v2 )
fatal("Out of memory.");
*v1 = v3;
memset(v3, 0, 0x100uLL);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v1;
v1[1] = result;
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; }


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

v2 = 0LL;
v3 = *(char **)ptr;
do
{
v4 = *(_QWORD **)&v3[v2];
if ( v4 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[1];
free(v5);
}
while ( v4 );
v3 = *(char **)ptr;
}
v2 += 8LL;
}
while ( v2 != 256 );
free(v3);
free(ptr);
}

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

v2 = 0LL;
v3 = *(char **)ptr;
do
{
v4 = *(_QWORD **)&v3[v2];
if ( v4 )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[1];
free(v5);
}
while ( v4 );
v3 = *(char **)ptr;
}
v2 += 8LL;
}
while ( v2 != 256 );
free(v3);
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);
}


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

v2 = *(_QWORD **)(a1 + 8);
if ( !v2 )
{
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);
}


decompiled_code:
void __fastcall resolve_expr(__int64 a1, __int64 a2)
{
char *v3; // rsi
const char *v4; // rdx
_DWORD *v5; // r12
_QWORD *v6; // rax
__int64 v7; // r12
__int64 v8; // r12
_QWORD *v9; // rax
_QWORD *v10; // r13
__int64 *v11; // rax
__int64 v12; // rdx
int v13; // eax
int v14; // ecx
const char *v15; // rdx
_DWORD *v16; // r12
__int64 v17; // rsi
_QWORD *v18; // rax
__int64 v19; // r12
_QWORD *v20; // rsi
const char *v21; // rdx
_DWORD *v22; // r12
__int64 v23; // rsi
const char *v24; // rdx

while ( 2 )
{
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) )
return;
enter_contour(a1);
resolve_expr(a1, *(_QWORD *)(a2 + 24));
break;
case 1:
resolve_expr(a1, *(_QWORD *)(a2 + 8));
enter_contour(a1);
resolve_expr(a1, *(_QWORD *)(a2 + 16));
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));
a2 = *(_QWORD *)(a2 + 24);
continue;
case 8:
case 9:
case 0x1D:
case 0x1E:
a2 = *(_QWORD *)(a2 + 16);
continue;
case 0xA:
resolve_expr(a1, *(_QWORD *)(a2 + 16));
v23 = *(_QWORD *)(a2 + 24);
resolve_expr(a1, v23);
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 16) + 48LL) + 16LL) + 4LL) == 1 )
{
error((int)"Assignment to a single-assignment variable.", v23, v24);
message("Variable is defined here.");
}
return;
case 0x13:
v22 = (_DWORD *)find_symbol(a1, *(char **)(a2 + 88));
if ( v22 )
{
if ( *v22 != *(_DWORD *)a1 )
register_upvar(*(_QWORD *)(a1 + 16), (__int64)v22);
*(_QWORD *)(a2 + 48) = v22;
}
else
{
error((int)"Use of undeclared identifier '%s'.", *(_QWORD *)(a2 + 88), v21);
}
return;
case 0x19:
resolve_expr(a1, *(_QWORD *)(a2 + 16));
enter_contour(a1);
v20 = *(_QWORD **)(a2 + 32);
goto LABEL_23;
case 0x1A:
v3 = *(char **)(a2 + 88);
if ( v3 )
{
v5 = (_DWORD *)find_symbol(a1, v3);
if ( v5 )
{
if ( *v5 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v4);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v6 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v6;
v7 = (__int64)v6;
add_symbol(a1, (__int64)v6);
add_local(*(_QWORD *)(a1 + 16), v7);
}
v8 = *(_QWORD *)(a1 + 16);
v9 = make_scope(a2);
*(_QWORD *)(a2 + 56) = v9;
v10 = v9;
v9[1] = v8;
add_child(v8, (__int64)v9);
v11 = *(__int64 **)(a2 + 32);
*(_QWORD *)(a1 + 16) = v10;
v12 = *v11;
if ( *v11 )
{
v13 = *((_DWORD *)v10 + 11) + 1;
do
{
v12 = *(_QWORD *)(v12 + 8);
v14 = v13++;
}
while ( v12 );
*((_DWORD *)v10 + 11) = v14;
}
++*(_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) = v8;
return;
case 0x1B:
v16 = (_DWORD *)find_symbol(a1, *(char **)(a2 + 88));
if ( v16 )
{
if ( *v16 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v15);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v17 = *(_QWORD *)(a2 + 24);
if ( v17 )
resolve_expr(a1, v17);
v18 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v18;
v19 = (__int64)v18;
add_symbol(a1, (__int64)v18);
add_local(*(_QWORD *)(a1 + 16), v19);
return;
case 0x1C:
enter_contour(a1);
resolve_list(a1, *(_QWORD **)(a2 + 32));
leave_contour(a1);
if ( !*(_QWORD *)(a2 + 40) )
return;
enter_contour(a1);
v20 = *(_QWORD **)(a2 + 40);
LABEL_23:
resolve_list(a1, v20);
break;
default:
return;
}
break;
}
leave_contour(a1);
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, __int64 a2)
{
char *v3; // rsi
const char *v4; // rdx
_DWORD *v5; // r12
_QWORD *v6; // rax
__int64 v7; // r12
__int64 v8; // r12
_QWORD *v9; // rax
_QWORD *v10; // r13
__int64 *v11; // rax
__int64 v12; // rdx
int v13; // eax
int v14; // ecx
const char *v15; // rdx
_DWORD *v16; // r12
__int64 v17; // rsi
_QWORD *v18; // rax
__int64 v19; // r12
_QWORD *v20; // rsi
const char *v21; // rdx
_DWORD *v22; // r12
__int64 v23; // rsi
const char *v24; // rdx

while ( 2 )
{
switch ( *(_DWORD *)a2 )
{
case 0:
func15(a1, *(_QWORD *)(a2 + 8));
func11(a1);
func15(a1, *(_QWORD *)(a2 + 16));
func13(a1);
if ( !*(_QWORD *)(a2 + 24) )
return;
func11(a1);
func15(a1, *(_QWORD *)(a2 + 24));
break;
case 1:
func15(a1, *(_QWORD *)(a2 + 8));
func11(a1);
func15(a1, *(_QWORD *)(a2 + 16));
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));
a2 = *(_QWORD *)(a2 + 24);
continue;
case 8:
case 9:
case 0x1D:
case 0x1E:
a2 = *(_QWORD *)(a2 + 16);
continue;
case 0xA:
func15(a1, *(_QWORD *)(a2 + 16));
v23 = *(_QWORD *)(a2 + 24);
func15(a1, v23);
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 16) + 48LL) + 16LL) + 4LL) == 1 )
{
error((int)"Assignment to a single-assignment variable.", v23, v24);
message("Variable is defined here.");
}
return;
case 0x13:
v22 = (_DWORD *)func10(a1, *(char **)(a2 + 88));
if ( v22 )
{
if ( *v22 != *(_DWORD *)a1 )
func6(*(_QWORD *)(a1 + 16), (__int64)v22);
*(_QWORD *)(a2 + 48) = v22;
}
else
{
error((int)"Use of undeclared identifier '%s'.", *(_QWORD *)(a2 + 88), v21);
}
return;
case 0x19:
func15(a1, *(_QWORD *)(a2 + 16));
func11(a1);
v20 = *(_QWORD **)(a2 + 32);
goto LABEL_23;
case 0x1A:
v3 = *(char **)(a2 + 88);
if ( v3 )
{
v5 = (_DWORD *)func10(a1, v3);
if ( v5 )
{
if ( *v5 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v4);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v6 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v6;
v7 = (__int64)v6;
func8(a1, (__int64)v6);
func1(*(_QWORD *)(a1 + 16), v7);
}
v8 = *(_QWORD *)(a1 + 16);
v9 = make_scope(a2);
*(_QWORD *)(a2 + 56) = v9;
v10 = v9;
v9[1] = v8;
func3(v8, (__int64)v9);
v11 = *(__int64 **)(a2 + 32);
*(_QWORD *)(a1 + 16) = v10;
v12 = *v11;
if ( *v11 )
{
v13 = *((_DWORD *)v10 + 11) + 1;
do
{
v12 = *(_QWORD *)(v12 + 8);
v14 = v13++;
}
while ( v12 );
*((_DWORD *)v10 + 11) = v14;
}
++*(_DWORD *)a1;
func11(a1);
func14(a1, *(_QWORD **)(a2 + 32));
func15(a1, *(_QWORD *)(a2 + 24));
func13(a1);
--*(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = v8;
return;
case 0x1B:
v16 = (_DWORD *)func10(a1, *(char **)(a2 + 88));
if ( v16 )
{
if ( *v16 == *(_DWORD *)a1 )
{
error((int)"Redefinition of '%s'.", *(_QWORD *)(a2 + 88), v15);
message("Previous definition is here.");
}
if ( warning_flags )
{
warning("Shadowing declaration of '%s'.", *(const char **)(a2 + 88));
message("Previous definition is here.");
}
}
v17 = *(_QWORD *)(a2 + 24);
if ( v17 )
func15(a1, v17);
v18 = make_symbol(*(char **)(a2 + 88), *(_DWORD *)a1, a2);
*(_QWORD *)(a2 + 48) = v18;
v19 = (__int64)v18;
func8(a1, (__int64)v18);
func1(*(_QWORD *)(a1 + 16), v19);
return;
case 0x1C:
func11(a1);
func14(a1, *(_QWORD **)(a2 + 32));
func13(a1);
if ( !*(_QWORD *)(a2 + 40) )
return;
func11(a1);
v20 = *(_QWORD **)(a2 + 40);
LABEL_23:
func14(a1, v20);
break;
default:
return;
}
break;
}
func13(a1);
}

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; // rbp
_QWORD *v2; // rax

v1 = malloc(0x18uLL);
if ( !v1 )
fatal("Out of memory.");
v2 = make_scope(a1);
v1[1] = 0LL;
*(_QWORD *)(a1 + 56) = v2;
v1[2] = v2;
*(_DWORD *)v1 = 0;
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)
{
__int64 v1; // rsi
_BYTE *v2; // rbx
unsigned int v3; // er12

v1 = (unsigned int)(char)*a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
switch ( (char)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", v1);
break;
}
v1 = (unsigned int)(char)*++v2;
}
while ( (_BYTE)v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rsi
_BYTE *v2; // rbx
unsigned int v3; // er12

v1 = (unsigned int)(char)*a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
switch ( (char)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", v1);
break;
}
v1 = (unsigned int)(char)*++v2;
}
while ( (_BYTE)v1 );
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: itmp int


GetConnAttribsFromStr

decompiled_code:
__int64 __fastcall GetConnAttribsFromStr(_BYTE *a1)
{
__int64 v1; // rsi
_BYTE *v2; // rbx
unsigned int v3; // er12

v1 = (unsigned int)(char)*a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
switch ( (char)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", v1);
break;
}
v1 = (unsigned int)(char)*++v2;
}
while ( (_BYTE)v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 v1; // rsi
_BYTE *v2; // rbx
unsigned int v3; // er12

v1 = (unsigned int)(char)*a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
switch ( (char)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", v1);
break;
}
v1 = (unsigned int)(char)*++v2;
}
while ( (_BYTE)v1 );
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)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // rdx

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

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

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

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

variable_types:
str
char *


popcount

decompiled_code:
__int64 __fastcall popcount(int a1)
{
unsigned int v1; // er8
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_368, 0LL);
ps_list = init_list(0xFFFFFFFFLL);
CU_assertImplementation(ps_list == 0, 31LL, "CU_ASSERT_PTR_NULL(ps_list)", "suite_seq_list.c", &unk_368, 0LL);
ps_list = init_list(1LL);
CU_assertImplementation(ps_list != 0, 36LL, "CU_ASSERT_PTR_NOT_NULL(ps_list)", "suite_seq_list.c", &unk_368, 0LL);
CU_assertImplementation(
*(_DWORD *)(ps_list + 8) == 1,
37LL,
"CU_ASSERT_EQUAL(ps_list->element_size,element_size)",
"suite_seq_list.c",
&unk_368,
0LL);
return CU_assertImplementation(
*(_DWORD *)(ps_list + 12) == 0,
38LL,
"CU_ASSERT_EQUAL(ps_list->length,0)",
"suite_seq_list.c",
&unk_368,
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_368, 0LL);
ps_list = init_list(0xFFFFFFFFLL);
CU_assertImplementation(ps_list == 0, 31LL, "CU_ASSERT_PTR_NULL(ps_list)", "suite_seq_list.c", &unk_368, 0LL);
ps_list = init_list(1LL);
CU_assertImplementation(ps_list != 0, 36LL, "CU_ASSERT_PTR_NOT_NULL(ps_list)", "suite_seq_list.c", &unk_368, 0LL);
CU_assertImplementation(
*(_DWORD *)(ps_list + 8) == 1,
37LL,
"CU_ASSERT_EQUAL(ps_list->element_size,element_size)",
"suite_seq_list.c",
&unk_368,
0LL);
return CU_assertImplementation(
*(_DWORD *)(ps_list + 12) == 0,
38LL,
"CU_ASSERT_EQUAL(ps_list->length,0)",
"suite_seq_list.c",
&unk_368,
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_constprop_0(result);
return result;
}

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

result = CU_register_suites(&suites);
if ( result )
result = func9(result);
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 v3; // eax
int v4; // er8
unsigned int v5; // er12
__int64 v6; // rax
char *v7; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const void *a2, unsigned int a3)
{
unsigned int v3; // eax
int v4; // er8
unsigned int v5; // er12
__int64 v6; // rax
char *v7; // rbp

LOBYTE(v3) = func6(a1, (__int64)a2, a3);
v5 = v3;
if ( (_BYTE)v3 )
{
v6 = *(int *)(a1 + 8);
v7 = (char *)(*(_QWORD *)a1 + v4 * (int)v6);
memcpy(&v7[v6], v7, (int)v6 * (*(_DWORD *)(a1 + 12) - v4));
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

result = 0LL;
if ( a1 )
{
if ( a2 <= 0x1000 )
{
memcpy(
(void *)(*(_QWORD *)a1 + (int)(a2 * *(_DWORD *)(a1 + 8))),
(const void *)(*(_QWORD *)a1 + (int)(a2 * *(_DWORD *)(a1 + 8)) + *(int *)(a1 + 8)),
(int)(*(_DWORD *)(a1 + 8) * (*(_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);
}
*v0 = 4;
v1 = v0;
v2 = malloc(0x20uLL);
v1[4] = 0;
*((_QWORD *)v1 + 1) = v2;
v3 = v2;
if ( !v2 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector->elements\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
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);
}
*v0 = 4;
v1 = v0;
v2 = malloc(0x20uLL);
v1[4] = 0;
*((_QWORD *)v1 + 1) = v2;
v3 = v2;
if ( !v2 )
{
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fwrite("vector_string_create vector->elements\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
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)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

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

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

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(int *)ptr > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
free(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
}
++v3;
}
while ( *(_DWORD *)ptr > (int)v3 );
}
free(v2);
}
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(int *a1, int a2)
{
__int64 v2; // rbx
_QWORD *v3; // r14
__int64 v4; // rbx
char *v5; // rax
char *v6; // r12
_QWORD *v7; // rax
_QWORD *v8; // r12
__int64 v9; // rbx
char *v10; // rax
char *v11; // r15
__int64 result; // rax

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

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

v2 = a1[4];
v3 = malloc(8 * v2);
if ( (int)v2 > 0 )
{
v4 = 0LL;
do
{
v5 = (char *)malloc(0x400uLL);
v3[v4] = v5;
v6 = *(char **)(*((_QWORD *)a1 + 1) + 8 * v4++);
strcpy(v5, v6);
free(v6);
}
while ( a1[4] > (int)v4 );
}
free(*((void **)a1 + 1));
v7 = malloc(8LL * a2);
*((_QWORD *)a1 + 1) = v7;
v8 = v7;
if ( !v7 )
goto LABEL_12;
v9 = 0LL;
if ( a2 > 0 )
{
while ( 1 )
{
v10 = (char *)malloc(0x400uLL);
v8[v9] = v10;
if ( !v10 )
break;
if ( a1[4] <= (int)v9 )
{
if ( a2 == ++v9 )
goto LABEL_11;
}
else
{
v11 = (char *)v3[v9++];
strcpy(v10, v11);
free(v11);
if ( a2 == v9 )
goto LABEL_11;
}
}
LABEL_12:
fwrite("*** malloc failed ***\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "vector_string_change_capacity from %i to %i\n", (unsigned int)*a1, (unsigned int)a2);
exit(1);
}
LABEL_11:
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 **